From c8e3e39085bf97d1afb775d54884d239387e32cd Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 26 Nov 2024 11:25:45 +0100 Subject: [PATCH] page-alloc: make scrub_one_page() static Before starting to alter its properties, restrict the function's visibility. The only external user is mem-paging, which we can accommodate by different means. Also move the function up in its source file, so we won't need to forward-declare it. Constify its parameter at the same time. Signed-off-by: Jan Beulich Acked-by: Julien Grall --- xen/arch/x86/include/asm/mem_paging.h | 6 ---- xen/arch/x86/mm/mem_paging.c | 3 -- xen/common/page_alloc.c | 40 ++++++++++++++------------- xen/include/xen/mm.h | 2 -- xen/include/xen/sched.h | 6 ++++ 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/include/asm/mem_paging.h b/xen/arch/x86/include/asm/mem_paging.h index 5ae86669fb40..2c618925d01d 100644 --- a/xen/arch/x86/include/asm/mem_paging.h +++ b/xen/arch/x86/include/asm/mem_paging.h @@ -12,12 +12,6 @@ int mem_paging_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_paging_op_t) arg); -#ifdef CONFIG_MEM_PAGING -# define mem_paging_enabled(d) vm_event_check_ring((d)->vm_event_paging) -#else -# define mem_paging_enabled(d) false -#endif - #endif /*__ASM_X86_MEM_PAGING_H__ */ /* diff --git a/xen/arch/x86/mm/mem_paging.c b/xen/arch/x86/mm/mem_paging.c index 541ecbeeb001..ac8d34ffa074 100644 --- a/xen/arch/x86/mm/mem_paging.c +++ b/xen/arch/x86/mm/mem_paging.c @@ -304,9 +304,6 @@ static int evict(struct domain *d, gfn_t gfn) ret = p2m_set_entry(p2m, gfn, INVALID_MFN, PAGE_ORDER_4K, p2m_ram_paged, a); - /* Clear content before returning the page to Xen */ - scrub_one_page(page); - /* Track number of paged gfns */ atomic_inc(&d->paged_pages); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 33c8c917d984..92abed6514b4 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -137,6 +137,7 @@ #include #include #include +#include #include #include @@ -774,6 +775,21 @@ static void page_list_add_scrub(struct page_info *pg, unsigned int node, #endif #define SCRUB_BYTE_PATTERN (SCRUB_PATTERN & 0xff) +static void scrub_one_page(const struct page_info *pg) +{ + if ( unlikely(pg->count_info & PGC_broken) ) + return; + +#ifndef NDEBUG + /* Avoid callers relying on allocations returning zeroed pages. */ + unmap_domain_page(memset(__map_domain_page(pg), + SCRUB_BYTE_PATTERN, PAGE_SIZE)); +#else + /* For a production build, clear_page() is the fastest way to scrub. */ + clear_domain_page(_mfn(page_to_mfn(pg))); +#endif +} + static void poison_one_page(struct page_info *pg) { #ifdef CONFIG_SCRUB_DEBUG @@ -2548,10 +2564,12 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) /* * Normally we expect a domain to clear pages before freeing them, * if it cares about the secrecy of their contents. However, after - * a domain has died we assume responsibility for erasure. We do - * scrub regardless if option scrub_domheap is set. + * a domain has died or if it has mem-paging enabled we assume + * responsibility for erasure. We do scrub regardless if option + * scrub_domheap is set. */ - scrub = d->is_dying || scrub_debug || opt_scrub_domheap; + scrub = d->is_dying || mem_paging_enabled(d) || + scrub_debug || opt_scrub_domheap; } else { @@ -2635,22 +2653,6 @@ static __init int cf_check pagealloc_keyhandler_init(void) } __initcall(pagealloc_keyhandler_init); - -void scrub_one_page(struct page_info *pg) -{ - if ( unlikely(pg->count_info & PGC_broken) ) - return; - -#ifndef NDEBUG - /* Avoid callers relying on allocations returning zeroed pages. */ - unmap_domain_page(memset(__map_domain_page(pg), - SCRUB_BYTE_PATTERN, PAGE_SIZE)); -#else - /* For a production build, clear_page() is the fastest way to scrub. */ - clear_domain_page(_mfn(page_to_mfn(pg))); -#endif -} - static void cf_check dump_heap(unsigned char key) { s_time_t now = NOW(); diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 7561297a7553..d7dcf0f06330 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -532,8 +532,6 @@ static inline unsigned int get_order_from_pages(unsigned long nr_pages) return order; } -void scrub_one_page(struct page_info *pg); - #ifndef arch_free_heap_page #define arch_free_heap_page(d, pg) \ page_list_del(pg, page_to_list(d, pg)) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 90666576c2f8..76e39378b31e 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -1203,6 +1203,12 @@ static always_inline bool is_iommu_enabled(const struct domain *d) return evaluate_nospec(d->options & XEN_DOMCTL_CDF_iommu); } +#ifdef CONFIG_MEM_PAGING +# define mem_paging_enabled(d) vm_event_check_ring((d)->vm_event_paging) +#else +# define mem_paging_enabled(d) false +#endif + extern bool sched_smt_power_savings; extern bool sched_disable_smt_switching;