Commit f417e145 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: x86/mmu: cleanup computation of MMU roles for shadow paging

Pass the already-computed CPU role, instead of redoing it.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2ba67677
...@@ -4846,15 +4846,14 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu, ...@@ -4846,15 +4846,14 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu,
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu, kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu,
const struct kvm_mmu_role_regs *regs) union kvm_mmu_role cpu_role)
{ {
union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, regs);
union kvm_mmu_role role; union kvm_mmu_role role;
role = cpu_role; role = cpu_role;
if (!____is_efer_lma(regs)) if (!cpu_role.ext.efer_lma)
role.base.level = PT32E_ROOT_LEVEL; role.base.level = PT32E_ROOT_LEVEL;
else if (____is_cr4_la57(regs)) else if (cpu_role.ext.cr4_la57)
role.base.level = PT64_ROOT_5LEVEL; role.base.level = PT64_ROOT_5LEVEL;
else else
role.base.level = PT64_ROOT_4LEVEL; role.base.level = PT64_ROOT_4LEVEL;
...@@ -4893,16 +4892,15 @@ static void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, ...@@ -4893,16 +4892,15 @@ static void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu,
struct kvm_mmu *context = &vcpu->arch.root_mmu; struct kvm_mmu *context = &vcpu->arch.root_mmu;
union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, regs); union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, regs);
union kvm_mmu_role mmu_role = union kvm_mmu_role mmu_role =
kvm_calc_shadow_mmu_root_page_role(vcpu, regs); kvm_calc_shadow_mmu_root_page_role(vcpu, cpu_role);
shadow_mmu_init_context(vcpu, context, cpu_role, mmu_role); shadow_mmu_init_context(vcpu, context, cpu_role, mmu_role);
} }
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_shadow_npt_root_page_role(struct kvm_vcpu *vcpu, kvm_calc_shadow_npt_root_page_role(struct kvm_vcpu *vcpu,
const struct kvm_mmu_role_regs *regs) union kvm_mmu_role cpu_role)
{ {
union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, regs);
union kvm_mmu_role role; union kvm_mmu_role role;
WARN_ON_ONCE(cpu_role.base.direct); WARN_ON_ONCE(cpu_role.base.direct);
...@@ -4922,7 +4920,7 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, unsigned long cr0, ...@@ -4922,7 +4920,7 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, unsigned long cr0,
.efer = efer, .efer = efer,
}; };
union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, &regs); union kvm_mmu_role cpu_role = kvm_calc_cpu_role(vcpu, &regs);
union kvm_mmu_role mmu_role = kvm_calc_shadow_npt_root_page_role(vcpu, &regs); union kvm_mmu_role mmu_role = kvm_calc_shadow_npt_root_page_role(vcpu, cpu_role);
shadow_mmu_init_context(vcpu, context, cpu_role, mmu_role); shadow_mmu_init_context(vcpu, context, cpu_role, mmu_role);
kvm_mmu_new_pgd(vcpu, nested_cr3); kvm_mmu_new_pgd(vcpu, nested_cr3);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment