populate/unpopulate memory when domain on static
v3 cover populate/unpopulate memory when domain on static
Today when a domain unpopulates the memory on runtime, they will always hand the memory over to the heap allocator. And it will be a problem if it is a static domain.
Pages used as guest RAM for static domain shall always be reserved to this domain only, and not be used for any other purposes, so they shall never go back to heap allocator.
This patch serie intends to fix this issue, by adding pages on the new list resv_page_list after having taken them off the "normal" list, when unpopulating memory, and retrieving pages from resv page list(resv_page_list) when populating memory.
---
v3 changes:
- fix possible racy issue in free_staticmem_pages()
- introduce a stub free_staticmem_pages() for the !CONFIG_STATIC_MEMORY case
- move the change to free_heap_pages() to cover other potential call sites
- change fixed width type uint32_t to unsigned int
- change "flags" to a more descriptive name "cdf"
- change name from "is_domain_static()" to "is_domain_using_staticmem"
- have page_list_del() just once out of the if()
- remove resv_pages counter
- make arch_free_heap_page be an expression, not a compound statement.
- move #ifndef is_domain_using_staticmem to the common header file
- remove #ifdef CONFIG_STATIC_MEMORY-ary
- remove meaningless page_to_mfn(page) in error log
---
v2 changes:
- let "flags" live in the struct domain. So other arch can take advantage of it in the future
- change name from "is_domain_on_static_allocation" to "is_domain_static()"
- put reserved pages on resv_page_list after having taken them off the "normal" list
- introduce acquire_reserved_page to retrieve reserved pages from resv_page_list
- forbid non-zero-order requests in populate_physmap
- let is_domain_static return ((void)(d), false) on x86
- fix coding style
Penny Zheng (6):
xen: do not free reserved memory into heap
xen: do not merge reserved pages in free_heap_pages()
xen: add field "flags" to cover all internal CDF_XXX xen/arm: introduce CDF_staticmem
xen: unpopulate memory when domain is static
xen: retrieve reserved pages on populate_physmap
xen/arch/arm/domain.c | 2 -- xen/arch/arm/domain_build.c | 5 ++- xen/arch/arm/include/asm/domain.h | 5 +-- xen/arch/arm/include/asm/mm.h | 12 +++++++ xen/common/domain.c | 7 ++++ xen/common/memory.c | 23 +++++++++++++ xen/common/page_alloc.c | 57 +++++++++++++++++++++++++++++-- xen/include/xen/domain.h | 6 ++++ xen/include/xen/mm.h | 3 +- xen/include/xen/sched.h | 6 ++++ 10 files changed, 116 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 2/6 xen: do not merge reserved pages in free_heap_pages()
There is a slim chance that free_heap_pages() may decide to merge a chunk from the static region(PGC_reserved) with the about-to-be-free chunk.
So in order to avoid the above scenario, this commit updates free_heap_pages() to check whether the predecessor and/or successor has PGC_reserved set, when trying to merge the about-to-be-freed chunk with the predecessor and/or successor.
---
v3 changes:
- no changes
---
v2 changes:
- new commit
--- xen/common/page_alloc.c | 2 ++ 1 file changed, 2 insertions(+)
xen/common/page_alloc.c +2 -0
@@ -1483,6 +1483,7 @@ static void free_heap_pages(/* Merge with predecessor block? */ if ( !mfn_valid (page_to_mfn (predecessor)) || !page_state_is (predecessor, free) || + (predecessor->count_info & PGC_reserved) || (PFN_ORDER (predecessor) != order) || (phys_to_nid (page_to_maddr (predecessor)) != node) )break ;
@@ -1506,6 +1507,7 @@ static void free_heap_pages(/* Merge with successor block? */ if ( !mfn_valid (page_to_mfn (successor)) || !page_state_is (successor, free) || + (successor->count_info & PGC_reserved) || (PFN_ORDER (successor) != order) || (phys_to_nid (page_to_maddr (successor)) != node) )break ;
Signature · 1 line
2.25.1
Re: [PATCH v3 2/6] xen: do not merge reserved pages in free_heap_pages()
Hi,
Quoted 2 lines · Penny Zheng
There is a slim chance that
free_heap_pages()may decide to merge a chunk from the staticregion(PGC_reserved)with the about-to-be-free chunk.
This sentence tells me that the merge can happen but it doesn't tell me the cases. I think the second part is more important to know.
The code in free_heap_Pages() will try to merge with the successor/predecessor if they are suitably aligned. So the issue can only happen if the pages reserved are right next to the pages given to the heap allocator.
Quoted 30 lines
So in order to avoid the above scenario, this commit updates
free_heap_pages()to check whether the predecessor and/or successor hasPGC_reservedset, when trying to merge the about-to-be-freed chunk with the predecessor and/or successor.Signed-off-by Penny Zheng <[email protected]>---
v3 changes:
- no changes
---
v2 changes:
- new commit--- xen/common/page_alloc.c | 2 ++ 1 file changed, 2 insertions(+)xen/common/page_alloc.c +1
-0@@ -1483,6 +1483,7 @@ static void free_heap_pages(/* Merge with predecessor block? */ if ( !mfn_valid (page_to_mfn (predecessor)) || !page_state_is (predecessor, free) || + (predecessor->count_info & PGC_reserved) || (PFN_ORDER (predecessor) != order) || (phys_to_nid (page_to_maddr (predecessor)) != node) )break ;
xen/common/page_alloc.c static void free_heap_pages( · line 1513
Quoted 7 lines
xen/common/page_alloc.c +1
-0@@ -1506,6 +1507,7 @@ static void free_heap_pages(/* Merge with successor block? */ if ( !mfn_valid (page_to_mfn (successor)) || !page_state_is (successor, free) || + (successor->count_info & PGC_reserved) || (PFN_ORDER (successor) != order) || (phys_to_nid (page_to_maddr (successor)) != node) )break ;
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 2/6] xen: do not merge reserved pages in free_heap_pages()
In reply to Penny ZhengQuoted 9 lines · Penny Zheng
There is a slim chance that
free_heap_pages()may decide to merge a chunk from the staticregion(PGC_reserved)with the about-to-be-free chunk.So in order to avoid the above scenario, this commit updates
free_heap_pages()to check whether the predecessor and/or successor hasPGC_reservedset, when trying to merge the about-to-be-freed chunk with the predecessor and/or successor.Signed-off-by Penny Zheng <[email protected]>
I think this also wants a Suggested-by or Reported-by (iirc) Julien?
Jan
RE: [PATCH v3 2/6] xen: do not merge reserved pages in free_heap_pages()
Hi,
Quoted 22 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:30 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 2/6] xen: do not merge reserved pages infree_heap_pages()Quoted 2 lines · Penny Zheng
There is a slim chance that
free_heap_pages()may decide to merge a chunk from the staticregion(PGC_reserved)with the about-to-be-freechunk.
Quoted 6 lines
So in order to avoid the above scenario, this commit updates
free_heap_pages()to check whether the predecessor and/or successor hasPGC_reservedset, when trying to merge the about-to-be-freed chunk with the predecessor and/or successor.
Quoted 6 lines
Quoted 1 line
Signed-off-by Penny Zheng <[email protected]>Reviewed-by Jan Beulich <[email protected]>I think this also wants a Suggested-by or Reported-by (iirc) Julien?
Sure, I'll definitely add-in Suggested-by: Julien Grall <[email protected]>
Quoted 1 line
Jan
PATCH v3 3/6 xen: add field "flags" to cover all internal CDF_XXX
In reply to Penny ZhengWith more and more CDF_xxx internal flags in and to save the space, this commit introduces a new field "flags" in struct domain to store CDF_* internal flags directly.
Another new CDF_xxx will be introduced in the next patch.
---
v3 changes:
- change fixed width type uint32_t to unsigned int
- change "flags" to a more descriptive name "cdf"
---
v2 changes:
- let "flags" live in the struct domain. So other arch can take advantage of it in the future
- fix coding style
--- xen/arch/arm/domain.c | 2 -- xen/arch/arm/include/asm/domain.h | 3 +-- xen/common/domain.c | 3 +++ xen/include/xen/sched.h | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-)
xen/arch/arm/domain.c +0 -2
@@ -709,8 +709,6 @@ int arch_domain_create(struct domain *d,ioreq_domain_init (d);#endif - d->arch.directmap = flags & CDF_directmap; -/* p2m_init relies on some value initialized by the IOMMU subsystem */ if ( (rc =iommu_domain_init (d, config->iommu_opts)) !=0 ) goto fail;
xen/arch/arm/include/asm/domain.h +1 -2
@@ -29,7 +29,7 @@ enum domain_type {#define is_64bit_domain (d) (0)#endif -#define is_domain_direct_mapped (d) (d)->arch.directmap +#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)/* * Is the domain using the host memory layout?
@@ -103,7 +103,6 @@ struct arch_domainvoid *tee;#endif -bool directmap; } __cacheline_aligned;struct arch_vcpu
xen/common/domain.c +3 -0
@@ -567,6 +567,9 @@ struct domain *domain_create(domid_t domid,/* Sort out our idea of is_system_domain(). */ d->domain_id = domid; +/* Holding CDF_* internal flags. */ + d->cdf = flags; +/* Debug sanity. */ ASSERT (is_system_domain (d) ? config ==NULL : config !=NULL );
xen/include/xen/sched.h +3 -0
@@ -591,6 +591,9 @@ struct domainstruct ioreq_server *server[MAX_NR_IOREQ_SERVERS ]; } ioreq_server;#endif + +/* Holding CDF_* constant. Internal flags for domain creation. */ +unsigned int cdf; }; static inline struct page_list_head *page_to_list(
Signature · 1 line
2.25.1
Re: [PATCH v3 3/6] xen: add field "flags" to cover all internal CDF_XXX
Hi,
Quoted 7 lines · Penny Zheng
With more and more
CDF_xxxinternal flags in and to save the space, this commit introduces a new field "flags" in struct domain to store CDF_* internal flags directly.Another new
CDF_xxxwill be introduced in the next patch.Signed-off-by Penny Zheng <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 4/6 xen/arm: introduce CDF_staticmem
In reply to Penny ZhengIn order to have an easy and quick way to find out whether this domain memory is statically configured, this commit introduces a new flag CDF_staticmem and a new helper is_domain_using_staticmem() to tell.
---
v3 changes:
- change name from "is_domain_static()" to "is_domain_using_staticmem"
---
v2 changes:
- change name from "is_domain_on_static_allocation" to "is_domain_static()"
--- xen/arch/arm/domain_build.c | 5 ++++- xen/arch/arm/include/asm/domain.h | 2 ++ xen/include/xen/domain.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)
xen/arch/arm/domain_build.c +4 -1
@@ -3190,9 +3190,12 @@ void __init create_domUs(void)if ( !dt_device_is_compatible (node,"xen,domain" ) )continue ; +if (dt_find_property (node,"xen,static-mem" ,NULL ) ) + flags |= CDF_staticmem; +if (dt_property_read_bool (node,"direct-map" ) ) { -if ( !IS_ENABLED (CONFIG_STATIC_MEMORY ) || !dt_find_property (node,"xen,static-mem" ,NULL ) ) +if ( !IS_ENABLED (CONFIG_STATIC_MEMORY ) || !(flags & CDF_staticmem) )panic ("direct-map is not valid for domain %s without static allocation.\n" ,dt_node_name (node));
xen/arch/arm/include/asm/domain.h +2 -0
@@ -31,6 +31,8 @@ enum domain_type {#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap) +#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem) +/* * Is the domain using the host memory layout? *
xen/include/xen/domain.h +2 -0
@@ -34,6 +34,8 @@ void arch_get_domain_info(const struct domain *d,#ifdef CONFIG_ARM /* Should domain memory be directly mapped? */ #define CDF_directmap (1U << 1) +/* Is domain memory on static allocation? */ +#define CDF_staticmem (1U << 2)#endif /*
Signature · 1 line
2.25.1
Re: [PATCH v3 4/6] xen/arm: introduce CDF_staticmem
Hi Penny,
Quoted 5 lines · Penny Zheng
In order to have an easy and quick way to find out whether this domain memory is statically configured, this commit introduces a new flag
CDF_staticmemand a new helperis_domain_using_staticmem()to tell.Reviewed-by Stefano Stabellini <[email protected]>
The reviewed-by tags should be after signed-off-by tags.
Cheers,
Quoted 57 lines
Signed-off-by Penny Zheng <[email protected]>---
v3 changes:
- change name from "is_domain_static()" to "is_domain_using_staticmem"
---
v2 changes:
- change name from "is_domain_on_static_allocation" to "is_domain_static()"--- xen/arch/arm/domain_build.c | 5 ++++- xen/arch/arm/include/asm/domain.h | 2 ++ xen/include/xen/domain.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)xen/arch/arm/domain_build.c +4
-1@@ -3190,9 +3190,12 @@ void __init create_domUs(void)if ( !dt_device_is_compatible (node,"xen,domain" ) )continue ; +if (dt_find_property (node,"xen,static-mem" ,NULL ) ) + flags |= CDF_staticmem; +if (dt_property_read_bool (node,"direct-map" ) ) { -if ( !IS_ENABLED (CONFIG_STATIC_MEMORY ) || !dt_find_property (node,"xen,static-mem" ,NULL ) ) +if ( !IS_ENABLED (CONFIG_STATIC_MEMORY ) || !(flags & CDF_staticmem) )panic ("direct-map is not valid for domain %s without static allocation.\n" ,dt_node_name (node));xen/arch/arm/include/asm/domain.h +2
-0@@ -31,6 +31,8 @@ enum domain_type {#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap) +#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem) +/* * Is the domain using the host memory layout? * xen/include/xen/domain.h +2
-0@@ -34,6 +34,8 @@ void arch_get_domain_info(const struct domain *d,#ifdef CONFIG_ARM /* Should domain memory be directly mapped? */ #define CDF_directmap (1U << 1) +/* Is domain memory on static allocation? */ +#define CDF_staticmem (1U << 2)#endif /*
Signature · 1 line
Julien Grall
PATCH v3 5/6 xen/arm: unpopulate memory when domain is static
In reply to Penny ZhengToday 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 pages on the new list resv_page_list only after having taken them off the "normal" list, when the last ref dropped.
---
v3 changes:
- have page_list_del() just once out of the if()
- remove resv_pages counter
- make arch_free_heap_page be an expression, not a compound statement.
---
v2 changes:
- put reserved pages on resv_page_list after having taken them off the "normal" list
--- xen/arch/arm/include/asm/mm.h | 12 ++++++++++++ xen/common/domain.c | 4 ++++ xen/include/xen/sched.h | 3 +++ 3 files changed, 19 insertions(+)
xen/arch/arm/include/asm/mm.h +12 -0
@@ -358,6 +358,18 @@ void clear_and_clean_page(struct page_info *page);unsigned int arch_get_dma_bitsize (void ); +/* +* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory +*/ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif +#endif /* __ARCH_ARM_MM__ */ /* * Local variables:
xen/common/domain.c +4 -0
@@ -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 ;
xen/include/xen/sched.h +3 -0
@@ -376,6 +376,9 @@ struct domainstruct 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 (size resv_pages) */ +#endif /* * This field should only be directly accessed by domain_adjust_tot_pages()
Signature · 1 line
2.25.1
Re: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is static
Hi Penny,
Quoted 36 lines · Penny Zheng
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 pages on the new list
resv_page_listonly after having taken them off the "normal" list, when the last ref dropped.Signed-off-by Penny Zheng <[email protected]>---
v3 changes:
- havepage_list_del()just once out of theif()
- removeresv_pagescounter
- makearch_free_heap_pagebe an expression, not a compound statement.
---
v2 changes:
- put reserved pages onresv_page_listafter having taken them off the "normal" list--- xen/arch/arm/include/asm/mm.h | 12 ++++++++++++ xen/common/domain.c | 4 ++++ xen/include/xen/sched.h | 3 +++ 3 files changed, 19 insertions(+)xen/arch/arm/include/asm/mm.h +1
-0@@ -358,6 +358,18 @@ void clear_and_clean_page(struct page_info *page);unsigned int arch_get_dma_bitsize (void ); +/*
xen/arch/arm/include/asm/mm.h void clear_and_clean_page(struct page_info *page); · line 371
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory +*/ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif
I am a bit puzzled how this is meant to work.
Looking at the code, arch_free_heap_page() will be called from free_domheap_pages(). If I am not mistaken, reserved pages are not considered as xen heap pages, so we would go in the else which will end up to call free_heap_pages().
free_heap_pages() will end up to add the page in the heap allocator and corrupt the d->resv_page_list because there are only one link list.
What did I miss?
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is static
Hi julien
Quoted 70 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Wednesday, April 27, 2022 6:11 PM
To: Penny Zheng <[email protected]>; [email protected]
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Stefano Stabellini <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is staticHi Penny,
Quoted 36 lines · Penny Zheng
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 pages on the new list
resv_page_listonly after having taken them off the "normal" list, when the last ref dropped.Signed-off-by Penny Zheng <[email protected]>---
v3 changes:
- havepage_list_del()just once out of theif()
- removeresv_pagescounter
- makearch_free_heap_pagebe an expression, not a compound statement.
---
v2 changes:
- put reserved pages onresv_page_listafter having taken them off the "normal" list--- xen/arch/arm/include/asm/mm.h | 12 ++++++++++++ xen/common/domain.c | 4 ++++ xen/include/xen/sched.h | 3 +++ 3 files changed, 19 insertions(+)(quoted diff) +0
-0
b/xen/arch/arm/include/asm/mm.hindex424aaf2823..c6426c1705100644xen/arch/arm/include/asm/mm.h +0
-0@@ -358,6 +358,18 @@ void clear_and_clean_page(struct page_info *page);unsigned int arch_get_dma_bitsize (void );xen/arch/arm/include/asm/mm.h void clear_and_clean_page(struct page_info · line 371
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+/* +* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory */ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif I am a bit puzzled how this is meant to work.
Looking at the code,
arch_free_heap_page()will be called fromfree_domheap_pages(). If I am not mistaken, reserved pages are not considered as xen heap pages, so we would go in the else which will end up to callfree_heap_pages().
Quoted 5 lines
free_heap_pages()will end up to add the page in the heap allocator and corrupt thed->resv_page_listbecause there are only one link list.What did I miss?
In my first commit "do not free reserved memory into heap", I've changed the behavior for reserved pages in free_heap_pages()
+ if ( pg->count_info & PGC_reserved )
+ /* Reserved page shall not go back to the heap. */
+ return free_staticmem_pages(pg, 1UL << order, need_scrub);
+
Quoted 4 lines
Cheers,
--
Julien Grall
Cheers,
--
Penny Zheng
Re: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is static
Hi Penny,
Quoted 26 lines · Penny Zheng
Quoted 18 lines
xen/arch/arm/include/asm/mm.h void clear_and_clean_page(struct page_info *page); · line 371
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+/* +* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory */ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif I am a bit puzzled how this is meant to work.
Looking at the code,
arch_free_heap_page()will be called fromfree_domheap_pages(). If I am not mistaken, reserved pages are not considered as xen heap pages, so we would go in the else which will end up to callfree_heap_pages().Quoted 5 lines
free_heap_pages()will end up to add the page in the heap allocator and corrupt thed->resv_page_listbecause there are only one link list.What did I miss?
In my first commit "do not free reserved memory into heap", I've changed the behavior for reserved pages in
free_heap_pages()
Review
Quoted 4 lines
(quoted diff) +4
-0+ if ( pg->count_info & PGC_reserved ) + /* Reserved page shall not go back to the heap. */ + return free_staticmem_pages(pg, 1UL << order, need_scrub); +
Hmmm... somehow this e-mail is neither in my inbox nor in the archives on lore.kernel.org.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is static
Hi julien
Quoted 47 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Wednesday, April 27, 2022 6:23 PM
To: Penny Zheng <[email protected]>; [email protected]
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Stefano Stabellini <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is staticHi Penny,
Quoted 26 lines · Penny Zheng
Quoted 18 lines
xen/arch/arm/include/asm/mm.h void clear_and_clean_page(struct page_info *page); · line 371
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+/* +* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory */ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif I am a bit puzzled how this is meant to work.
Looking at the code,
arch_free_heap_page()will be called fromfree_domheap_pages(). If I am not mistaken, reserved pages are not considered as xen heap pages, so we would go in the else which will end up to callfree_heap_pages().Quoted 5 lines
free_heap_pages()will end up to add the page in the heap allocator and corrupt thed->resv_page_listbecause there are only one link list.What did I miss?
In my first commit "do not free reserved memory into heap", I've changed the behavior for reserved pages in
free_heap_pages()Review
Quoted 4 lines
(quoted diff) +4
-0+ if ( pg->count_info & PGC_reserved )that + /* Reserved page shall not go back to the heap. */ + return free_staticmem_pages(pg, 1UL << order, need_scrub); +
Quoted 3 lines
Hmmm... somehow this e-mail is neither in my inbox nor in the archives on lore.kernel.org.
Oh.... I just got email from tessian that they held my first commit, and needed my confirmation to send. So sorry about that!!!
I'll re-send my first commit ASAP.
Quoted 3 lines
Cheers,
--
Julien Grall
RE: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is static
Quoted 34 lines · Penny Zheng
Quoted 34 lines
Hi Penny,
Quoted 30 lines · Penny Zheng
Quoted 18 lines
xen/arch/arm/include/asm/mm.h void clear_and_clean_page(struct page_info *page); · line 371
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+/* +* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory */ +#ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif I am a bit puzzled how this is meant to work.
Looking at the code,
arch_free_heap_page()will be called fromfree_domheap_pages(). If I am not mistaken, reserved pages are not considered as xen heap pages, so we would go in the else which will end up to callfree_heap_pages().Quoted 5 lines
free_heap_pages()will end up to add the page in the heap allocator and corrupt thed->resv_page_listbecause there are only one link list.What did I miss?
In my first commit "do not free reserved memory into heap", I've changed the behavior for reserved pages in
free_heap_pages()(quoted diff) +4
-0+ if ( pg->count_info & PGC_reserved )that + /* Reserved page shall not go back to the heap. */ + return free_staticmem_pages(pg, 1UL << order, need_scrub); +
Quoted 8 lines
Quoted 3 lines
Hmmm... somehow this e-mail is neither in my inbox nor in the archives on lore.kernel.org.
Oh.... I just got email from tessian that they held my first commit, and needed my confirmation to send. So sorry about that!!!
I'll re-send my first commit ASAP.
Just FYI I still cannot see the first patch anywhere in my inbox
RE: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is static
Hi
Quoted 55 lines
-----Original Message-----
From: Stefano Stabellini <[email protected]>
Sent: Thursday, April 28, 2022 6:32 AM
To: Penny Zheng <[email protected]>
Cc: Julien Grall <[email protected]>; [email protected]; Wei Chen <[email protected]>; Henry Wang <[email protected]>; Stefano Stabellini <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>
Subject: RE: [PATCH v3 5/6] xen/arm: unpopulate memory when domain is staticQuoted 16 lines · Penny Zheng
Quoted 16 lines
Hi Penny,
Quoted 13 lines · Penny Zheng
Quoted 13 lines
xen/arch/arm/include/asm/mm.h void clear_and_clean_page(struct page_info *page); · line 371
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+/* +* Put free pages on the resv page list after having taken them +* off the "normal" page list, when pages from static memory +*/ #ifdef CONFIG_STATIC_MEMORY +#define arch_free_heap_page (d, pg) ({ \ + page_list_del(pg, page_to_list(d, pg)); \ + if ( (pg)->count_info & PGC_reserved ) \ + page_list_add_tail(pg, &(d)->resv_page_list); \ +}) +#endif I am a bit puzzled how this is meant to work.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Looking at the code,
arch_free_heap_page()will be called fromfree_domheap_pages(). If I am not mistaken, reserved pages are not considered as xen heap pages, so we would go in the else which will end up to callfree_heap_pages().
free_heap_pages()will end up to add the page in the heap allocator and corrupt thed->resv_page_listbecause there are only onelink list.
Quoted 16 lines
Quoted 15 lines
Review
Quoted 11 lines
Quoted 3 lines
What did I miss?
In my first commit "do not free reserved memory into heap", I've changed the behavior for reserved pages in
free_heap_pages()(quoted diff) +5
-0+ if ( pg->count_info & PGC_reserved )that + /* Reserved page shall not go back to the heap. */ + return free_staticmem_pages(pg, 1UL << order, + need_scrub); +Hmmm... somehow this e-mail is neither in my inbox nor in the archives on lore.kernel.org.
Quoted 6 lines
Quoted 4 lines
Oh.... I just got email from tessian that they held my first commit, and needed my confirmation to send. So sorry about that!!!
I'll re-send my first commit ASAP.
Just FYI I still cannot see the first patch anywhere in my inbox
So sorry about the mess again...
I've resend it just now, PLZ check https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
PATCH v3 6/6 xen: retrieve reserved pages on populate_physmap
In reply to Penny ZhengWhen static domain populates memory through populate_physmap on runtime, other than allocating from heap, it shall retrieve reserved pages from resv_page_list to make sure that guest RAM is still restricted in statically configured memory regions. And this commit introduces a new helper acquire_reserved_page to make it work.
---
v3 changes
- move #ifndef is_domain_using_staticmem to the common header file
- remove #ifdef CONFIG_STATIC_MEMORY-ary
- remove meaningless page_to_mfn(page) in error log
---
v2 changes:
- introduce acquire_reserved_page to retrieve reserved pages from resv_page_list
- forbid non-zero-order requests in populate_physmap
- let is_domain_static return ((void)(d), false) on x86
--- xen/common/memory.c | 23 +++++++++++++++++++++++ xen/common/page_alloc.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/include/xen/domain.h | 4 ++++ xen/include/xen/mm.h | 3 +-- 4 files changed, 66 insertions(+), 2 deletions(-)
xen/common/memory.c +23 -0
@@ -245,6 +245,29 @@ static void populate_physmap(struct memop_args *a) mfn =_mfn (gpfn); } +else if (is_domain_using_staticmem (d) ) + { +/* +* No easy way to guarantee the retreived pages are contiguous, +* so forbid non-zero-order requests here. +*/ +if ( a->extent_order !=0 ) + { +gdprintk (XENLOG_INFO , +"Could not allocate non-zero-order pages for static %pd.\n." , + d); + goto out; + } + + mfn =acquire_reserved_page (d, a->memflags); +if (mfn_eq (mfn,INVALID_MFN ) ) + { +gdprintk (XENLOG_INFO , +"%pd: failed to retrieve a reserved page.\n." , + d); + goto out; + } + }else { page =alloc_domheap_pages (d, a->extent_order, a->memflags);
xen/common/page_alloc.c +38 -0
@@ -2769,12 +2769,50 @@ int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, return 0; } + +/* +* Acquire a page from reserved page list(resv_page_list), when populating +* memory for static domain on runtime. +*/ +mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{ +struct page_info *page; +mfn_t smfn; + +/* Acquire a page from reserved page list(resv_page_list). */ + page =page_list_remove_head (&d->resv_page_list); +if (unlikely (!page) ) + { +printk (XENLOG_ERR +"%pd: failed to acquire a reserved page from resv_page_list.\n" , + d); +return INVALID_MFN ; + } + + smfn =page_to_mfn (page); + +if (acquire_domstatic_pages (d, smfn,1 , memflags) ) +return INVALID_MFN ; + +return smfn; +}#else void free_staticmem_pages (struct page_info *pg,unsigned long nr_mfns,bool need_scrub) {ASSERT_UNREACHABLE (); } + +int __init acquire_domstatic_pages (struct domain *d,mfn_t smfn, +unsigned int nr_mfns,unsigned int memflags) +{ +ASSERT_UNREACHABLE (); +} + +mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{ +ASSERT_UNREACHABLE (); +}#endif /*
xen/include/xen/domain.h +4 -0
@@ -38,6 +38,10 @@ void arch_get_domain_info(const struct domain *d,#define CDF_staticmem (1U << 2)#endif +#ifndef is_domain_using_staticmem +#define is_domain_using_staticmem (d) ((void)(d), false) +#endif +/* * Arch-specifics. */
xen/include/xen/mm.h +1 -2
@@ -88,10 +88,9 @@ bool scrub_free_pages(void);/* These functions are for static memory */ void free_staticmem_pages (struct page_info *pg,unsigned long nr_mfns,bool need_scrub); -#ifdef CONFIG_STATIC_MEMORY int acquire_domstatic_pages (struct domain *d,mfn_t smfn,unsigned int nr_mfns,unsigned int memflags); -#endif +mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags);/* Map machine page range in Xen virtual address space. */ int map_pages_to_xen(
Signature · 1 line
2.25.1
Re: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 251
Quoted 10 lines · Penny Zheng
xen/common/memory.c +4
-0@@ -245,6 +245,29 @@ static void populate_physmap(struct memop_args *a) mfn =_mfn (gpfn); } +else if (is_domain_using_staticmem (d) ) + { +/* +* No easy way to guarantee the retreived pages are contiguous,
Nit: retrieved
xen/common/memory.c static void populate_physmap(struct memop_args *a) · line 257
Quoted 6 lines
xen/common/memory.c +6
-0+* so forbid non-zero-order requests here. +*/ +if ( a->extent_order !=0 ) + { + gdprintk(XENLOG_INFO, + "Could not allocate non-zero-order pages for static %pd.\n.",
Nit: "Could not" reads as if an attempt was made, so maybe better "Cannot"? I'd also pull "static" ahead of "non-zero-order" and, to help observers of the message associate it with a call site, actually log the order (i.e. "order-%u" instead of "non-zero-order").
Also please omit full stops in log messages. They serve no purpose but consume space.
Finally, here as well as below: Is "info" log level really appropriate? You're logging error conditions after all, so imo these want to be at least "warn" level. An alternative would be to omit logging of messages here altogether.
Quoted 13 lines
xen/common/page_alloc.c +7
-0@@ -2769,12 +2769,50 @@ int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn,return 0 ; } + +/* +* Acquire a page from reserved page list(resv_page_list), when populating +* memory for static domain on runtime. +*/ +mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2788
Quoted 10 lines
xen/common/page_alloc.c +10
-0+struct page_info *page; +mfn_t smfn; + +/* Acquire a page from reserved page list(resv_page_list). */ + page =page_list_remove_head (&d->resv_page_list); +if (unlikely (!page) ) + { +printk (XENLOG_ERR +"%pd: failed to acquire a reserved page from resv_page_list.\n" , + d);
A gdprintk() in the caller is acceptable. Two log messages isn't imo, and a XENLOG_ERR message which a guest can trigger is a security concern (log spam) anyway.
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2795
Quoted 7 lines
xen/common/page_alloc.c +7
-0+return INVALID_MFN ; + } + + smfn =page_to_mfn (page); + +if (acquire_domstatic_pages (d, smfn,1 , memflags) ) +return INVALID_MFN ;
Don't you want to add the page back to the reserved list in case of error?
Quoted 4 lines
xen/common/page_alloc.c +2
-0+return smfn; +}#else void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2810
Quoted 10 lines
xen/common/page_alloc.c +6
-0bool need_scrub) {ASSERT_UNREACHABLE (); } + +int __init acquire_domstatic_pages (struct domain *d,mfn_t smfn, +unsigned int nr_mfns,unsigned int memflags) +{ +ASSERT_UNREACHABLE (); +}
I can't spot a caller of this one outside of suitable #ifdef. Also the __init here looks wrong and you look to have missed dropping it from the real function.
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2816
Quoted 5 lines
xen/common/page_alloc.c +4
-0+mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{ +ASSERT_UNREACHABLE (); +}#endif
For this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
Jan
RE: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Hi jan
Quoted 79 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapxen/common/memory.c static void populate_physmap(struct memop_args · line 253
Quoted 12 lines · Penny Zheng
xen/common/memory.c +5
-0@@ -245,6 +245,29 @@ static void populate_physmap(struct memop_args *a) mfn =_mfn (gpfn); } +else if (is_domain_using_staticmem (d) ) + { +/* +* No easy way to guarantee the retreived pages are +contiguous, Nit: retrieved
xen/common/memory.c static void populate_physmap(struct memop_args *a)
Quoted 7 lines
xen/common/memory.c +7
-0+* so forbid non-zero-order requests here. +*/ + if ( a->extent_order != 0 ) + { + gdprintk(XENLOG_INFO, + "Could not allocate non-zero-order pages + for static %pd.\n.",Nit: "Could not" reads as if an attempt was made, so maybe better "Cannot"? I'd also pull "static" ahead of "non-zero-order" and, to help observers of the message associate it with a call site, actually log the order (i.e. "order-%u" instead of "non-zero-order").
Also please omit full stops in log messages. They serve no purpose but consume space.
Finally, here as well as below: Is "info" log level really appropriate? You're logging error conditions after all, so imo these want to be at least "warn" level. An alternative would be to omit logging of messages here altogether.
Quoted 15 lines
xen/common/page_alloc.c +8
-0@@ -2769,12 +2769,50 @@ int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, return 0; } + +/* +* Acquire a page from reserved page list(resv_page_list), when +populating +* memory for static domain on runtime. +*/ +mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{xen/common/page_alloc.c int __init acquire_domstatic_pages(struct · line 2790
Quoted 10 lines
xen/common/page_alloc.c +10
-0+struct page_info *page; +mfn_t smfn; + +/* Acquire a page from reserved page list(resv_page_list). */ + page =page_list_remove_head (&d->resv_page_list); +if (unlikely (!page) ) + { +printk (XENLOG_ERR +"%pd: failed to acquire a reserved page from resv_page_list.\n" , + d);A
gdprintk()in the caller is acceptable. Two log messages isn't imo, and aXENLOG_ERRmessage which a guest can trigger is a security concern (log spam) anyway.
Quoted 10 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2795
Quoted 7 lines
xen/common/page_alloc.c +7
-0+return INVALID_MFN ; + } + + smfn =page_to_mfn (page); + +if (acquire_domstatic_pages (d, smfn,1 , memflags) ) +return INVALID_MFN ;Don't you want to add the page back to the reserved list in case of error?
Oh, thanks for pointing that out.
Quoted 17 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2810
Quoted 13 lines
xen/common/page_alloc.c +8
-0+ return smfn; +}#else void free_staticmem_pages (struct page_info *pg,unsigned long nr_mfns,bool need_scrub) {ASSERT_UNREACHABLE (); } + +int __init acquire_domstatic_pages (struct domain *d,mfn_t smfn, +unsigned int nr_mfns,unsigned int +memflags) { +ASSERT_UNREACHABLE (); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it from the real function.
Quoted 9 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2816
Quoted 5 lines
xen/common/page_alloc.c +4
-0+mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{ +ASSERT_UNREACHABLE (); +}#endif For this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
In acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only variables, like d->resv_page_list, so I'd expect to let acquire_reserved_page guarded by CONFIG_STATIC_MEMORY too and provide the stub function here to avoid compilation error when !CONFIG_STATIC_MEMORY.
Quoted 1 line
Jan
Re: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Quoted 29 lines · Penny Zheng
Quoted 19 lines
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PMxen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2810
Quoted 11 lines · Penny Zheng
#else
void free_staticmem_pages(structpage_info*pg, unsigned longnr_mfns,bool need_scrub) { ASSERT_UNREACHABLE();}
xen/common/page_alloc.c +6
-0+ +int __init acquire_domstatic_pages (struct domain *d,mfn_t smfn, +unsigned int nr_mfns,unsigned int +memflags) { +ASSERT_UNREACHABLE (); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it from the real function.Quoted 9 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2816
Quoted 5 lines
xen/common/page_alloc.c +4
-0+mfn_t acquire_reserved_page (struct domain *d,unsigned int memflags) +{ +ASSERT_UNREACHABLE (); +}#endif For this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
Quoted 3 lines
In
acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only variables, liked->resv_page_list, so I'd expect to letacquire_reserved_pageguarded byCONFIG_STATIC_MEMORYtoo and provide the stub function here to avoid compilation error when !CONFIG_STATIC_MEMORY.
A compilation error should only result if there's no declaration of the function. I didn't suggest to remove that. A missing definition would only be noticed when linking, but CSE should result in no reference to the function in the first place. Just like was suggested for the earlier patch. And as opposed to the call site optimization the compiler can do, with -ffunction-sections there's no way for the linker to eliminate the dead stub function.
Jan
RE: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Hi jan
Quoted 50 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 3:47 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 6 lines · Penny Zheng
Quoted 6 lines
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PMQuoted 2 lines · Penny Zheng
#else
void free_staticmem_pages(structpage_info*pg, unsigned long
nr_mfns,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
bool need_scrub) { ASSERT_UNREACHABLE();}
(quoted diff) +2
-0+ +int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn,Quoted 8 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ unsigned int nr_mfns, unsigned +int +memflags) { + ASSERT_UNREACHABLE(); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it fromthe real function.
Quoted 11 lines
Quoted 10 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2816
Quoted 6 lines
xen/common/page_alloc.c +4
-0+mfn_t acquire_reserved_page (struct domain *d,unsigned int +memflags) { +ASSERT_UNREACHABLE (); +}#endif For this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
Quoted 5 lines
In
acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only variables, liked->resv_page_list, so I'd expect to letacquire_reserved_pageguardedd->byCONFIG_STATIC_MEMORY
too and provide the stub function here to avoid compilation error
Quoted 9 lines
when !CONFIG_STATIC_MEMORY.
A compilation error should only result if there's no declaration of the function. I didn't suggest to remove that. A missing definition would only be noticed when linking, but CSE should result in no reference to the function in the first place. Just like was suggested for the earlier patch. And as opposed to the call site optimization the compiler can do, with -ffunction-sections there's no way for the linker to eliminate the dead stub function.
Sure, plz correct me if I understand wrongly:
Maybe here I should use #define xxx to do the declaration, and it will also
avoid bringing dead stub function. Something like:
#define free_staticmem_pages(pg, nr_mfns, need_scrub) ((void)(pg), (void)(nr_mfns), (void)(need_scrub)) And
#define acquire_reserved_page(d, memflags) (INVALID_MFN)
Quoted 1 line
Jan
Re: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Quoted 62 lines · Penny Zheng
Hi jan
Quoted 50 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 3:47 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 6 lines · Penny Zheng
Quoted 6 lines
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PMQuoted 2 lines · Penny Zheng
#else
void free_staticmem_pages(structpage_info*pg, unsigned long
nr_mfns,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
bool need_scrub) { ASSERT_UNREACHABLE();}
(quoted diff) +2
-0+ +int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn,Quoted 8 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ unsigned int nr_mfns, unsigned +int +memflags) { + ASSERT_UNREACHABLE(); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it fromthe real function.
Quoted 11 lines
Quoted 10 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2816
Quoted 6 lines
xen/common/page_alloc.c +4
-0+mfn_t acquire_reserved_page (struct domain *d,unsigned int +memflags) { +ASSERT_UNREACHABLE (); +}#endif For this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
Quoted 5 lines
In
acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only variables, liked->resv_page_list, so I'd expect to letacquire_reserved_pageguardedd->byCONFIG_STATIC_MEMORY
too and provide the stub function here to avoid compilation errorQuoted 9 lines
when !CONFIG_STATIC_MEMORY.
A compilation error should only result if there's no declaration of the function. I didn't suggest to remove that. A missing definition would only be noticed when linking, but CSE should result in no reference to the function in the first place. Just like was suggested for the earlier patch. And as opposed to the call site optimization the compiler can do, with -ffunction-sections there's no way for the linker to eliminate the dead stub function.
Quoted 6 lines
Sure, plz correct me if I understand wrongly:
Maybe here I should use #define xxx to do the declaration, and it will also
avoid bringing dead stub function. Something like:
#definefree_staticmem_pages(pg, nr_mfns, need_scrub)((void)(pg), (void)(nr_mfns), (void)(need_scrub)) And
#defineacquire_reserved_page(d, memflags)(INVALID_MFN)
No, I don't see why you would need #define-s. You want to have normal declarations, but no definition unless STATIC_MEMORY. If that doesn't work, please point out why (i.e. what I am overlooking).
Jan
RE: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Hi jan
Quoted 85 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 4:51 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 7 lines · Penny Zheng
Hi jan
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 3:47 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry WangQuoted 46 lines
Quoted 46 lines
Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 6 lines · Penny Zheng
Quoted 6 lines
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PMQuoted 2 lines · Penny Zheng
#else
void free_staticmem_pages(structpage_info*pg, unsigned long
nr_mfns,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
bool need_scrub) { ASSERT_UNREACHABLE();}
xen/common/page_alloc.c +3
-0+ +int __init acquire_domstatic_pages (struct domain *d,mfn_t smfn, + unsigned int nr_mfns, unsignedQuoted 8 lines
Quoted 8 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2810
Quoted 4 lines
xen/common/page_alloc.c +4
-0+int +memflags) { +ASSERT_UNREACHABLE (); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it fromthe real function.
Quoted 16 lines
Quoted 10 lines
xen/common/page_alloc.c int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, · line 2816
Quoted 6 lines
xen/common/page_alloc.c +4
-0+mfn_t acquire_reserved_page (struct domain *d,unsigned int +memflags) { +ASSERT_UNREACHABLE (); +}#endif For this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
In
acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only variables, liked->resv_page_list, so I'd expect to letacquire_reserved_paged->guardedbyCONFIG_STATIC_MEMORY
too and provide the stub function here to avoid compilation errorQuoted 8 lines
Quoted 8 lines
when !CONFIG_STATIC_MEMORY.
A compilation error should only result if there's no declaration of the function. I didn't suggest to remove that. A missing definition would only be noticed when linking, but CSE should result in no reference to the function in the first place. Just like was suggested for the earlier patch. And as opposed to the call site optimization the compiler can do, with -ffunction-sections there's no way for the linker
to eliminate the dead stub function.
Quoted 8 lines
Quoted 1 line
Sure, plz correct me if I understand wrongly:
Maybe here I should use #define xxx to do the declaration, and it will also avoid bringing dead stub function. Something like:
#definefree_staticmem_pages(pg, nr_mfns, need_scrub)((void)(pg), (void)(nr_mfns), (void)(need_scrub)) And #defineacquire_reserved_page(d, memflags)(INVALID_MFN)
Quoted 4 lines
No, I don't see why you would need #define-s. You want to have normal declarations, but no definition unless
STATIC_MEMORY. If that doesn't work, please point out why (i.e. what I am overlooking).
I was trying to avoid dead stub function, and I think #define-s is the wrong path... So, I guess If I remove the ASSERT_UNREACHABLE() part and only leave the empty function body there, the CSE could do the optimization and result in no reference.
Quoted 1 line
Jan
Re: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Quoted 66 lines · Penny Zheng
Quoted 66 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 4:51 PMQuoted 43 lines · Penny Zheng
Quoted 43 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 3:47 PMQuoted 6 lines · Penny Zheng
Quoted 6 lines
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PMQuoted 2 lines · Penny Zheng
#else
void free_staticmem_pages(structpage_info*pg, unsigned long
nr_mfns,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
bool need_scrub) { ASSERT_UNREACHABLE();}
(quoted diff) +3
-0+ +int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, + unsigned int nr_mfns, unsignedQuoted 8 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+int +memflags) { + ASSERT_UNREACHABLE(); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it fromthe real function.
Quoted 16 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +4
-0+mfn_t acquire_reserved_page(struct domain *d, unsigned int +memflags) { + ASSERT_UNREACHABLE(); +} #endifFor this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
In
acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only variables, liked->resv_page_list, so I'd expect to letacquire_reserved_paged->guardedbyCONFIG_STATIC_MEMORY
too and provide the stub function here to avoid compilation errorQuoted 8 lines
Quoted 8 lines
when !CONFIG_STATIC_MEMORY.
A compilation error should only result if there's no declaration of the function. I didn't suggest to remove that. A missing definition would only be noticed when linking, but CSE should result in no reference to the function in the first place. Just like was suggested for the earlier patch. And as opposed to the call site optimization the compiler can do, with -ffunction-sections there's no way for the linker
to eliminate the dead stub function.
Quoted 8 lines
Quoted 1 line
Sure, plz correct me if I understand wrongly:
Maybe here I should use #define xxx to do the declaration, and it will also avoid bringing dead stub function. Something like:
#definefree_staticmem_pages(pg, nr_mfns, need_scrub)((void)(pg), (void)(nr_mfns), (void)(need_scrub)) And #defineacquire_reserved_page(d, memflags)(INVALID_MFN)
Quoted 8 lines
Quoted 4 lines
No, I don't see why you would need #define-s. You want to have normal declarations, but no definition unless
STATIC_MEMORY. If that doesn't work, please point out why (i.e. what I am overlooking).I was trying to avoid dead stub function, and I think #define-s is the wrong path... So, I guess If I remove the
ASSERT_UNREACHABLE()part and only leave the empty function body there, the CSE could do the optimization and result in no reference.
No, DCE (I'm sorry for the earlier wrong uses of CSE) cannot eliminate a function, it can only eliminate call sites. Hence it doesn't matter whether a function is empty. And no, if a stub function needs retaining, the ASSERT_UNREACHABLE() should also remain there if the function indeed is supposed to never be called.
Jan
RE: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Hi Jan
Quoted 89 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 8:07 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 43 lines · Penny Zheng
Quoted 43 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 4:51 PMQuoted 38 lines · Penny Zheng
Quoted 38 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 3:47 PMQuoted 6 lines · Penny Zheng
Quoted 6 lines
From: Jan Beulich <[email protected]>
Sent: Wednesday, May 4, 2022 9:45 PMQuoted 2 lines · Penny Zheng
#else
void free_staticmem_pages(structpage_info*pg, unsigned long
nr_mfns,Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
bool need_scrub) { ASSERT_UNREACHABLE();}
(quoted diff) +3
-0+ +int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn, + unsigned int nr_mfns,Quoted 8 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+unsigned int +memflags) { + ASSERT_UNREACHABLE(); +}I can't spot a caller of this one outside of suitable #ifdef. Also the
__inithere looks wrong and you look to have missed dropping it fromthe real function.
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +4
-0+mfn_t acquire_reserved_page(struct domain *d, unsigned int +memflags) { + ASSERT_UNREACHABLE(); +} #endifFor this one I'd again expect CSE to leave no callers, just like in the earlier patch. Or am I overlooking anything?
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
In
acquire_reserved_page, I've use a few CONFIG_STATIC_MEMORY-only
Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
variables, like
d->resv_page_list, so I'd expect to letacquire_reserved_paged->guardedbyCONFIG_STATIC_MEMORY
too and provide the stub function here to avoid compilation errorwhen !CONFIG_STATIC_MEMORY.
Quoted 7 lines
Quoted 7 lines
A compilation error should only result if there's no declaration of the function. I didn't suggest to remove that. A missing definition would only be noticed when linking, but CSE should result in no reference to the function in the first place. Just like was suggested for the earlier patch. And as opposed to the call site optimization the compiler can do, with -ffunction-sections there's no way for the linker
to eliminate the dead stub function.
Quoted 8 lines
Quoted 1 line
Sure, plz correct me if I understand wrongly:
Maybe here I should use #define xxx to do the declaration, and it will also avoid bringing dead stub function. Something like:
#definefree_staticmem_pages(pg, nr_mfns, need_scrub)((void)(pg), (void)(nr_mfns), (void)(need_scrub)) And #defineacquire_reserved_page(d, memflags)(INVALID_MFN)Quoted 6 lines
Quoted 4 lines
No, I don't see why you would need #define-s. You want to have normal declarations, but no definition unless
STATIC_MEMORY. If that doesn't work, please point out why (i.e. what I am overlooking).I was trying to avoid dead stub function, and I think #define-s is the wrong
path...
Quoted 2 lines
So, I guess If I remove the
ASSERT_UNREACHABLE()part and only leave the empty function body there, the CSE could do the optimization and result
Quoted 8 lines
in no reference.
No, DCE (I'm sorry for the earlier wrong uses of CSE) cannot eliminate a function, it can only eliminate call sites. Hence it doesn't matter whether a function is empty. And no, if a stub function needs retaining, the
ASSERT_UNREACHABLE()should also remain there if the function indeed is supposed to never be called.
Ok. Thanks for explanation.
I misunderstand what you suggested here, I thought you were suggesting a way of stub function which could bring some optimization.
The reason I introduced free_staticmem_pages and acquire_reserved_page here is that we now used them in common code, and if they are not defined(using stub) on !CONFIG_STATIC_MEMORY, we will have " hidden symbol `xxx' isn't defined " compilation error.
Quoted 1 line
Jan
Re: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Quoted 5 lines · Penny Zheng
I misunderstand what you suggested here, I thought you were suggesting a way of stub function which could bring some optimization.
The reason I introducedfree_staticmem_pagesandacquire_reserved_pagehere is that we now used them in common code, and if they are not defined(using stub) on !CONFIG_STATIC_MEMORY, we will have " hidden symbol `xxx' isn't defined " compilation error.
This is what I've asked for clarification about: If such errors surface, I'd like to understand why the respective call sites aren't DCE-ed by the compiler.
Jan
RE: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Hi jan
Quoted 17 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 10:23 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 5 lines · Penny Zheng
I misunderstand what you suggested here, I thought you were suggesting a way of stub function which could bring some optimization. The reason I introduced
free_staticmem_pagesandacquire_reserved_pagehere is that we now used them in common code, and if they are not defined(using stub) on !CONFIG_STATIC_MEMORY, we will have " hidden
Quoted 5 lines
symbol `xxx' isn't defined " compilation error.
This is what I've asked for clarification about: If such errors surface, I'd like to understand why the respective call sites aren't DCE-ed by the compiler.
Because both definition of PGC_reserved and is_domain_using_static_memory are not guarded by CONFIG_STATIC_MEMORY in the first place in arm-specific file.
Quoted 1 line
Jan
Re: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Quoted 19 lines · Penny Zheng
Hi jan
Quoted 17 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 10:23 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 5 lines · Penny Zheng
I misunderstand what you suggested here, I thought you were suggesting a way of stub function which could bring some optimization. The reason I introduced
free_staticmem_pagesandacquire_reserved_pagehere is that we now used them in common code, and if they are not defined(using stub) on !CONFIG_STATIC_MEMORY, we will have " hidden
Quoted 8 lines
Quoted 5 lines
symbol `xxx' isn't defined " compilation error.
This is what I've asked for clarification about: If such errors surface, I'd like to understand why the respective call sites aren't DCE-ed by the compiler.
Because both definition of
PGC_reservedandis_domain_using_static_memoryare not guarded byCONFIG_STATIC_MEMORYin the first place in arm-specific file.
So perhaps that's what wants changing (at least for PGC_reserved)?
Jan
RE: [PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap
Hi jan and julien
Quoted 38 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, May 6, 2022 2:14 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry Wang <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 7 lines · Penny Zheng
Hi jan
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 5, 2022 10:23 PM
To: Penny Zheng <[email protected]>
Cc: Wei Chen <[email protected]>; Henry WangQuoted 14 lines
Quoted 14 lines
Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 6/6] xen: retrieve reserved pages onpopulate_physmapQuoted 6 lines · Penny Zheng
I misunderstand what you suggested here, I thought you were suggesting a way of stub function which could bring some optimization. The reason I introduced
free_staticmem_pagesandacquire_reserved_pagehere is that we now used them in common code, and if they are not defined(using stub) on !CONFIG_STATIC_MEMORY, we will have " hiddenQuoted 4 lines
Quoted 4 lines
symbol `xxx' isn't defined " compilation error.
This is what I've asked for clarification about: If such errors surface, I'd like to understand why the respective call sites aren't DCE-ed by
Quoted 9 lines
the compiler.
Quoted 4 lines
Quoted 1 line
Because both definition of
PGC_reservedandis_domain_using_static_memoryare not guarded by
CONFIG_STATIC_MEMORYin the first place in arm-specific file.So perhaps that's what wants changing (at least for
PGC_reserved)?
Hmmm, I remembered that when I firstly introduced PGC_reserved through
"Domain on static allocation", Julien commented that he may like it to be
used for other purpose, not only static memory. And one example is reserved
memory when Live Updating.(https://www.mail-archive.com/[email protected]/msg97829.html )
Quoted 1 line
Jan