[PATCH 01/12] KVM: X86/MMU: Warn if sp->unsync_children > 0 in link_shadow_page()

From: Lai Jiangshan
Date: Sun Jun 05 2022 - 02:43:13 EST


From: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx>

The check for sp->unsync_children in link_shadow_page() can be removed
since FNAME(fetch) ensures it is zero. (@sp is direct when
link_shadow_page() is called from other places, which also means
sp->unsync_children is zero.)

link_shadow_page() is not a fast path, check it and warn instead.

Signed-off-by: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx>
---
arch/x86/kvm/mmu/mmu.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 086f32dffdbe..f61416818116 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2197,7 +2197,13 @@ static void link_shadow_page(struct kvm_vcpu *vcpu, u64 *sptep,

mmu_page_add_parent_pte(vcpu, sp, sptep);

- if (sp->unsync_children || sp->unsync)
+ /*
+ * Propagate the unsync bit when sp->unsync.
+ *
+ * The caller ensures the sp is synced when it has unsync children,
+ * so sp->unsync_children must be zero. See FNAME(fetch).
+ */
+ if (sp->unsync || WARN_ON_ONCE(sp->unsync_children))
mark_unsync(sptep);
}

--
2.19.1.6.gb485710b