[XEN PATCH v2] xen/page_alloc: scrub each page in unprepare_staticmem_pages

peter kang posted 1 patch 3 weeks, 6 days ago
xen/common/page_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[XEN PATCH v2] xen/page_alloc: scrub each page in unprepare_staticmem_pages
Posted by peter kang 3 weeks, 6 days ago
From: Peter Kang <peter.kang@boeing.com>

unprepare_staticmem_pages() can unprepare multiple pages in a static
memory range. When need_scrub is true, each page must be scrubbed
before it is marked static.

The loop currently passes the base pointer pg to scrub_one_page() on
every iteration. For a multi-page range, this repeatedly scrubs page 0
and leaves the remaining pages unscrubbed, so a guest can later read
stale data from pages 1..nr_mfns-1 of a static or static-shared bank.

Pass &pg[i] to scrub_one_page() so each iteration scrubs the page it
is processing. This ensures every page in the range is scrubbed before
it is marked static.

Fixes: 4a9e73e6e53e ("xen/arm: static memory initialization")
Signed-off-by: Peter Kang <peter.kang@boeing.com>

---
Changes:
v1 -> v2
 - Use Peter Kang's Signed-off-by.
 - no code change
---
 xen/common/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 2682fff9cc..426bd11c2e 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -2941,7 +2941,7 @@ void unprepare_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
         if ( need_scrub )
         {
             /* TODO: asynchronous scrubbing for pages of static memory. */
-            scrub_one_page(pg);
+            scrub_one_page(&pg[i]);
         }
 
         pg[i].count_info |= PGC_static;
-- 
2.43.0
Re: [XEN PATCH v2] xen/page_alloc: scrub each page in unprepare_staticmem_pages
Posted by Jan Beulich 3 weeks, 6 days ago
On 27.10.2026 05:25, peter kang wrote:
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -2941,7 +2941,7 @@ void unprepare_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
>          if ( need_scrub )
>          {
>              /* TODO: asynchronous scrubbing for pages of static memory. */
> -            scrub_one_page(pg);
> +            scrub_one_page(&pg[i]);
>          }
>  
>          pg[i].count_info |= PGC_static;

I had to re-base this change over commit 6ff0cfbfd4f7 ("mm: allow page
scrubbing routine(s) to be arch controlled"), dating back to July last
year. Please can you make sure to submit patches against the tip of
staging, and in particular not against any older (release) branch?

Jan
Re: [XEN PATCH v2] xen/page_alloc: scrub each page in unprepare_staticmem_pages
Posted by Jan Beulich 3 weeks, 6 days ago
On 27.10.2026 05:25, peter kang wrote:
> From: Peter Kang <peter.kang@boeing.com>
> 
> unprepare_staticmem_pages() can unprepare multiple pages in a static
> memory range. When need_scrub is true, each page must be scrubbed
> before it is marked static.
> 
> The loop currently passes the base pointer pg to scrub_one_page() on
> every iteration. For a multi-page range, this repeatedly scrubs page 0
> and leaves the remaining pages unscrubbed, so a guest can later read
> stale data from pages 1..nr_mfns-1 of a static or static-shared bank.
> 
> Pass &pg[i] to scrub_one_page() so each iteration scrubs the page it
> is processing. This ensures every page in the range is scrubbed before
> it is marked static.
> 
> Fixes: 4a9e73e6e53e ("xen/arm: static memory initialization")
> Signed-off-by: Peter Kang <peter.kang@boeing.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>