mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>, kvm@vger.kernel.org
Cc: Wanpeng Li <wanpengli@tencent.com>,
	Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org,
	Sean Christopherson <seanjc@google.com>,
	Joerg Roedel <joro@8bytes.org>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, Thomas Gleixner <tglx@linutronix.de>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Jim Mattson <jmattson@google.com>
Subject: Re: [PATCH 3/3] KVM: x86/mmu: don't skip mmu initialization when mmu root level changes
Date: Wed, 10 Nov 2021 17:00:45 +0200	[thread overview]
Message-ID: <18d77c7a10f283848c4efe0370401c436869f3a2.camel@redhat.com> (raw)
In-Reply-To: <87r1bom5h3.fsf@vitty.brq.redhat.com>

On Wed, 2021-11-10 at 15:48 +0100, Vitaly Kuznetsov wrote:
> Maxim Levitsky <mlevitsk@redhat.com> writes:
> 
> > When running mix of 32 and 64 bit guests, it is possible to have mmu
> > reset with same mmu role but different root level (32 bit vs 64 bit paging)
> > 
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> > ---
> >  arch/x86/kvm/mmu/mmu.c | 14 ++++++++++----
> >  1 file changed, 10 insertions(+), 4 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > index 354d2ca92df4d..763867475860f 100644
> > --- a/arch/x86/kvm/mmu/mmu.c
> > +++ b/arch/x86/kvm/mmu/mmu.c
> > @@ -4745,7 +4745,10 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
> >  	union kvm_mmu_role new_role =
> >  		kvm_calc_tdp_mmu_root_page_role(vcpu, &regs, false);
> >  
> > -	if (new_role.as_u64 == context->mmu_role.as_u64)
> > +	u8 new_root_level = role_regs_to_root_level(&regs);
> > +
> > +	if (new_role.as_u64 == context->mmu_role.as_u64 &&
> > +	    context->root_level == new_root_level)
> >  		return;
> 
> role_regs_to_root_level() uses 3 things: CR0.PG, EFER.LMA and CR4.PAE
> and two of these three are already encoded into extended mmu role
> (kvm_calc_mmu_role_ext()). Could we achieve the same result by adding
> EFER.LMA there?

Absolutely. I just wanted your feedback on this to see if there is any reason to not
do this.

Also it seems that only basic role is compared here.

I don't 100% know the reason why we have basic and extended roles - there is a
comment about basic/extended mmu role to minimize the size of arch.gfn_track,
but I haven't yet studied in depth why.

Best regards,
	Maxim Levitsky

> 
> >  
> >  	context->mmu_role.as_u64 = new_role.as_u64;
> > @@ -4757,7 +4760,7 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
> >  	context->get_guest_pgd = get_cr3;
> >  	context->get_pdptr = kvm_pdptr_read;
> >  	context->inject_page_fault = kvm_inject_page_fault;
> > -	context->root_level = role_regs_to_root_level(&regs);
> > +	context->root_level = new_root_level;
> >  
> >  	if (!is_cr0_pg(context))
> >  		context->gva_to_gpa = nonpaging_gva_to_gpa;
> > @@ -4806,7 +4809,10 @@ static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *conte
> >  				    struct kvm_mmu_role_regs *regs,
> >  				    union kvm_mmu_role new_role)
> >  {
> > -	if (new_role.as_u64 == context->mmu_role.as_u64)
> > +	u8 new_root_level = role_regs_to_root_level(regs);
> > +
> > +	if (new_role.as_u64 == context->mmu_role.as_u64 &&
> > +	    context->root_level == new_root_level)
> >  		return;
> >  
> >  	context->mmu_role.as_u64 = new_role.as_u64;
> > @@ -4817,8 +4823,8 @@ static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *conte
> >  		paging64_init_context(context);
> >  	else
> >  		paging32_init_context(context);
> > -	context->root_level = role_regs_to_root_level(regs);
> >  
> > +	context->root_level = new_root_level;
> >  	reset_guest_paging_metadata(vcpu, context);
> >  	context->shadow_root_level = new_role.base.level;



  reply	other threads:[~2021-11-10 15:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 10:00 [PATCH 0/3] VMX: nested migration fixes for 32 bit nested guests Maxim Levitsky
2021-11-10 10:00 ` [PATCH 1/3] KVM: nVMX: extract calculation of the L1's EFER Maxim Levitsky
2021-11-10 14:43   ` Vitaly Kuznetsov
2021-11-10 10:00 ` [PATCH 2/3] KVM: nVMX: restore L1's EFER prior to setting the nested state Maxim Levitsky
2021-11-10 15:01   ` Paolo Bonzini
2021-11-10 15:08     ` Maxim Levitsky
2021-11-10 10:00 ` [PATCH 3/3] KVM: x86/mmu: don't skip mmu initialization when mmu root level changes Maxim Levitsky
2021-11-10 14:48   ` Vitaly Kuznetsov
2021-11-10 15:00     ` Maxim Levitsky [this message]
2021-11-10 17:21       ` Sean Christopherson
2021-11-15 12:14         ` Maxim Levitsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18d77c7a10f283848c4efe0370401c436869f3a2.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®