From 570065b9d5a8a00c5c1aab9e13e9e1ad3e35ce7d Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Fri, 8 Jan 2021 16:49:23 +0100 Subject: [PATCH] x86/p2m: avoid unnecessary calls of write_p2m_entry_pre() hook MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When shattering a large page, we first construct the new page table page and only then hook it up. The "pre" hook in this case does nothing, for the page starting out all blank. Avoid 512 calls into shadow code in this case by passing in INVALID_GFN, indicating the page being updated is (not yet) associated with any GFN. (The alternative to this change would be to actually pass in a correct GFN, which can't be all the same on every loop iteration.) Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné --- xen/arch/x86/mm/p2m-pt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index 5fa0d30ce7..848773e1cd 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -134,7 +134,7 @@ static int write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, paging_lock(d); - if ( p2m->write_p2m_entry_pre ) + if ( p2m->write_p2m_entry_pre && gfn != gfn_x(INVALID_GFN) ) p2m->write_p2m_entry_pre(d, gfn, p, new, level); oflags = l1e_get_flags(*p); @@ -290,7 +290,8 @@ p2m_next_level(struct p2m_domain *p2m, void **table, { new_entry = l1e_from_pfn(pfn | (i << ((level - 1) * PAGETABLE_ORDER)), flags); - rc = write_p2m_entry(p2m, gfn, l1_entry + i, new_entry, level); + rc = write_p2m_entry(p2m, gfn_x(INVALID_GFN), l1_entry + i, + new_entry, level); if ( rc ) { unmap_domain_page(l1_entry); -- 2.30.2