[PATCH v2 07/18] KVM: x86/mmu: Do not use guest root level in audit

Paolo Bonzini
2022-02-17T21:04:13Z

From: Lai Jiangshan <laijs@linux.alibaba.com>

Walking from the root page of the shadow page table should start with
the level of the shadow page table: shadow_root_level; do not
consult the level in order to check whether the root has a single
root or uses pae_root, either, and use to_shadow_page instead.

Also tweak audit_mappings(), where the current walking level is more
valuable to print.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/mmu/mmu_audit.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu_audit.c b/arch/x86/kvm/mmu/mmu_audit.c
index 3e5d62a25350..d1c59aed0465 100644
--- a/arch/x86/kvm/mmu/mmu_audit.c
+++ b/arch/x86/kvm/mmu/mmu_audit.c
@@ -53,17 +53,16 @@ static void __mmu_spte_walk(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,

static void mmu_spte_walk(struct kvm_vcpu *vcpu, inspect_spte_fn fn)
{
- int i;
+ hpa_t root = vcpu->arch.mmu->root.hpa;
struct kvm_mmu_page *sp;
+ int i;

- if (!VALID_PAGE(vcpu->arch.mmu->root.hpa))
+ if (!VALID_PAGE(root))
return;

- if (vcpu->arch.mmu->root_level >= PT64_ROOT_4LEVEL) {
- hpa_t root = vcpu->arch.mmu->root.hpa;
-
- sp = to_shadow_page(root);
- __mmu_spte_walk(vcpu, sp, fn, vcpu->arch.mmu->root_level);
+ sp = to_shadow_page(root);
+ if (sp) {
+ __mmu_spte_walk(vcpu, sp, fn, vcpu->arch.mmu->shadow_root_level);
return;
}

@@ -119,8 +118,7 @@ static void audit_mappings(struct kvm_vcpu *vcpu, u64 *sptep, int level)
hpa = pfn << PAGE_SHIFT;
if ((*sptep & PT64_BASE_ADDR_MASK) != hpa)
audit_printk(vcpu->kvm, "levels %d pfn %llx hpa %llx "
- "ent %llxn", vcpu->arch.mmu->root_level, pfn,
- hpa, *sptep);
+ "ent %llxn", level, pfn, hpa, *sptep);
}

static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep)
--
2.31.1