Re: [PATCH v2 08/25] KVM: x86/mmu: split cpu_mode from mmu_role

Sean Christopherson
2022-03-09T15:38:47Z

On Wed, Mar 09, 2022, Paolo Bonzini wrote:
> On 3/8/22 19:55, Sean Christopherson wrote:
> > > static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *context,
> > > - const struct kvm_mmu_role_regs *regs,
> > > - union kvm_mmu_role new_role)
> > > + union kvm_mmu_role cpu_mode,
> > Can you give all helpers this treatment (rename "role" => "cpu_mode")? I got
> > tripped up a few times reading patches because the ones where it wasn't necessary,
> > i.e. where there's only a single kvm_mmu_role paramenter, were left as-is.
> >
> > I think kvm_calc_shadow_npt_root_page_role() and kvm_calc_shadow_mmu_root_page_role()
> > are the only offenders.
>
> These take struct kvm_mmu_role_regs; they *return* union kvm_mmu_role but
> that is changed later in the series to the base part only.

Doh, sorry, a later patch is what confused me. Lost track of things when moving
around in the series.

Patch 12, "KVM: x86/mmu: cleanup computation of MMU roles for shadow paging", is
where we end up with

static union kvm_mmu_role
kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu,
union kvm_mmu_role role)
{
if (!role.ext.efer_lma)
role.base.level = PT32E_ROOT_LEVEL;
else if (role.ext.cr4_la57)
role.base.level = PT64_ROOT_5LEVEL;
else
role.base.level = PT64_ROOT_4LEVEL;

return role;
}

Can we instead tweak that patch to make it and kvm_calc_shadow_npt_root_page_role() be

static union kvm_mmu_role
kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu,
union kvm_mmu_role cpu_role)
{
union kvm_mmu_role root_role = cpu_role;

if (!cpu_role.ext.efer_lma)
root_role.base.level = PT32E_ROOT_LEVEL;
else if (cpu_role.ext.cr4_la57)
root_role.base.level = PT64_ROOT_5LEVEL;
else
root_role.base.level = PT64_ROOT_4LEVEL;

return root_role;
}

This is effectively the same feedback I gave in Patch 15[*], I messed up when
trying to track back where the "union kvm_mmu_role role" param was introduced.