]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86/mmu: remove kvm_calc_shadow_root_page_role_common
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 10 Feb 2022 12:33:01 +0000 (07:33 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 29 Apr 2022 16:49:54 +0000 (12:49 -0400)
kvm_calc_shadow_root_page_role_common is the same as
kvm_calc_cpu_role except for the level, which is overwritten
afterwards in kvm_calc_shadow_mmu_root_page_role
and kvm_calc_shadow_npt_root_page_role.

role.base.direct is already set correctly for the CPU role,
and CR0.PG=1 is required for VMRUN so it will also be
correct for nested NPT.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c

index 86d4ee6ea0f9c13b8da241376453ee6eecedf2b3..f65b7e1a5758ffad5493a1bb0b3bf8d96e791d25 100644 (file)
@@ -4867,28 +4867,14 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu,
        reset_tdp_shadow_zero_bits_mask(context);
 }
 
-static union kvm_mmu_role
-kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu,
-                                     const struct kvm_mmu_role_regs *regs)
-{
-       union kvm_mmu_role role = kvm_calc_mmu_role_common(vcpu, regs);
-
-       role.base.smep_andnot_wp = role.ext.cr4_smep && !____is_cr0_wp(regs);
-       role.base.smap_andnot_wp = role.ext.cr4_smap && !____is_cr0_wp(regs);
-       role.base.has_4_byte_gpte = ____is_cr0_pg(regs) && !____is_cr4_pae(regs);
-
-       return role;
-}
-
 static union kvm_mmu_role
 kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu,
                                   const struct kvm_mmu_role_regs *regs)
 {
-       union kvm_mmu_role role =
-               kvm_calc_shadow_root_page_role_common(vcpu, regs);
-
-       role.base.direct = !____is_cr0_pg(regs);
+       union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, regs);
+       union kvm_mmu_role role;
 
+       role = cpu_role;
        if (!____is_efer_lma(regs))
                role.base.level = PT32E_ROOT_LEVEL;
        else if (____is_cr4_la57(regs))
@@ -4939,10 +4925,11 @@ static union kvm_mmu_role
 kvm_calc_shadow_npt_root_page_role(struct kvm_vcpu *vcpu,
                                   const struct kvm_mmu_role_regs *regs)
 {
-       union kvm_mmu_role role =
-               kvm_calc_shadow_root_page_role_common(vcpu, regs);
+       union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, regs);
+       union kvm_mmu_role role;
 
-       role.base.direct = false;
+       WARN_ON_ONCE(cpu_role.base.direct);
+       role = cpu_role;
        role.base.level = kvm_mmu_get_tdp_level(vcpu);
 
        return role;