]> xenbits.xensource.com Git - people/tklengyel/xen.git/commitdiff
xen: unpopulate memory when domain is static
authorPenny Zheng <Penny.Zheng@arm.com>
Tue, 6 Sep 2022 07:39:16 +0000 (15:39 +0800)
committerJulien Grall <jgrall@amazon.com>
Tue, 6 Sep 2022 16:53:35 +0000 (17:53 +0100)
Today when a domain unpopulates the memory on runtime, they will always
hand the memory back to the heap allocator. And it will be a problem if domain
is static.

Pages as guest RAM for static domain shall be reserved to only this domain
and not be used for any other purposes, so they shall never go back to heap
allocator.

This commit puts reserved page on the new list resv_page_list after
it has been freed.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/common/domain.c
xen/common/page_alloc.c
xen/include/xen/sched.h

index 7062393e37970c2f2dc7fb58f1094096e1359436..c23f449451a44995da1aaa4e04497a6e4712d4ba 100644 (file)
@@ -604,6 +604,10 @@ struct domain *domain_create(domid_t domid,
     INIT_PAGE_LIST_HEAD(&d->page_list);
     INIT_PAGE_LIST_HEAD(&d->extra_page_list);
     INIT_PAGE_LIST_HEAD(&d->xenpage_list);
+#ifdef CONFIG_STATIC_MEMORY
+    INIT_PAGE_LIST_HEAD(&d->resv_page_list);
+#endif
+
 
     spin_lock_init(&d->node_affinity_lock);
     d->node_affinity = NODE_MASK_ALL;
index 0c50dee4c59cecc4c01f00feae1726880c76743c..26a2fad4e307b6e79b855367b0ea59f14d6a8bef 100644 (file)
@@ -2741,10 +2741,13 @@ void free_domstatic_page(struct page_info *page)
 
     drop_dom_ref = !domain_adjust_tot_pages(d, -1);
 
-    spin_unlock_recursive(&d->page_alloc_lock);
-
     free_staticmem_pages(page, 1, scrub_debug);
 
+    /* Add page on the resv_page_list *after* it has been freed. */
+    page_list_add_tail(page, &d->resv_page_list);
+
+    spin_unlock_recursive(&d->page_alloc_lock);
+
     if ( drop_dom_ref )
         put_domain(d);
 }
index 81f1fcba2a5db3fe8375d999b9c33cdc6c86e2e7..557b3229f65e6d704e5c247cb78e85f877024471 100644 (file)
@@ -381,6 +381,9 @@ struct domain
     struct page_list_head page_list;  /* linked list */
     struct page_list_head extra_page_list; /* linked list (size extra_pages) */
     struct page_list_head xenpage_list; /* linked list (size xenheap_pages) */
+#ifdef CONFIG_STATIC_MEMORY
+    struct page_list_head resv_page_list; /* linked list */
+#endif
 
     /*
      * This field should only be directly accessed by domain_adjust_tot_pages()