All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Su <tao1.su@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, chao.gao@intel.com,
	xiaoyao.li@intel.com
Subject: Re: [PATCH] KVM: x86: Fix the condition of #PF interception caused by MKTME
Date: Wed, 10 Apr 2024 09:20:52 +0800	[thread overview]
Message-ID: <ZhXpdAdGsghYduDt@linux.bj.intel.com> (raw)
In-Reply-To: <ZhWRaMtsMXfHTFTH@google.com>

On Tue, Apr 09, 2024 at 12:05:12PM -0700, Sean Christopherson wrote:
> On Tue, Mar 19, 2024, Tao Su wrote:
> > Intel MKTME repurposes several high bits of physical address as 'keyID',
> > so boot_cpu_data.x86_phys_bits doesn't hold physical address bits reported
> > by CPUID anymore.
> > 
> > If guest.MAXPHYADDR < host.MAXPHYADDR, the bit field of ‘keyID’ belongs
> > to reserved bits in guest’s view, so intercepting #PF to fix error code
> > is necessary, just replace boot_cpu_data.x86_phys_bits with
> > kvm_get_shadow_phys_bits() to fix.
> > 
> > Signed-off-by: Tao Su <tao1.su@linux.intel.com>
> > ---
> >  arch/x86/kvm/vmx/vmx.h | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> > index 65786dbe7d60..79b1757df74a 100644
> > --- a/arch/x86/kvm/vmx/vmx.h
> > +++ b/arch/x86/kvm/vmx/vmx.h
> > @@ -15,6 +15,7 @@
> >  #include "vmx_ops.h"
> >  #include "../cpuid.h"
> >  #include "run_flags.h"
> > +#include "../mmu.h"
> >  
> >  #define MSR_TYPE_R	1
> >  #define MSR_TYPE_W	2
> > @@ -719,7 +720,8 @@ static inline bool vmx_need_pf_intercept(struct kvm_vcpu *vcpu)
> >  	if (!enable_ept)
> >  		return true;
> >  
> > -	return allow_smaller_maxphyaddr && cpuid_maxphyaddr(vcpu) < boot_cpu_data.x86_phys_bits;
> > +	return allow_smaller_maxphyaddr &&
> > +		cpuid_maxphyaddr(vcpu) < kvm_get_shadow_phys_bits();
> 
> For posterity, because I had a brief moment where I thought we done messed up:
> 
> No change is needed in the reporting of MAXPHYADDR in KVM_GET_SUPPORTED_CPUID,
> as reporting boot_cpu_data.x86_phys_bits as MAXPHYADDR when TDP is disabled is ok
> because KVM always intercepts #PF when TDP is disabled, and KVM already reports
> the full/raw MAXPHYADDR when TDP is enabled.

You are right, but userspace can fully control guest.MAXPHYADDR when TDP is enabled.
Please see the unit-test[*], I think this issue could show up earlier if phys-bits
is set larger, such as 46-bits.

[*] https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/blob/master/x86/unittests.cfg?ref_type=heads#L156

      reply	other threads:[~2024-04-10  1:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19  3:11 [PATCH] KVM: x86: Fix the condition of #PF interception caused by MKTME Tao Su
2024-04-09  2:01 ` Sean Christopherson
2024-04-09  3:54   ` Xiaoyao Li
2024-04-09 19:05 ` Sean Christopherson
2024-04-10  1:20   ` Tao Su [this message]

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=ZhXpdAdGsghYduDt@linux.bj.intel.com \
    --to=tao1.su@linux.intel.com \
    --cc=chao.gao@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=xiaoyao.li@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.