All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tian, Kevin" <kevin.tian@intel.com>
To: "Christopherson,, Sean" <seanjc@google.com>,
	"Liu, Jing2" <jing2.liu@intel.com>
Cc: "x86@kernel.org" <x86@kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"bp@alien8.de" <bp@alien8.de>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"Nakajima, Jun" <jun.nakajima@intel.com>,
	"jing2.liu@linux.intel.com" <jing2.liu@linux.intel.com>,
	"Zeng, Guang" <guang.zeng@intel.com>,
	"Wang, Wei W" <wei.w.wang@intel.com>,
	"Zhong, Yang" <yang.zhong@intel.com>
Subject: RE: [PATCH v3 22/22] kvm: x86: Disable interception for IA32_XFD on demand
Date: Wed, 29 Dec 2021 03:35:27 +0000	[thread overview]
Message-ID: <BN9PR11MB527653AF0BEC5BBA007B72408C449@BN9PR11MB5276.namprd11.prod.outlook.com> (raw)
In-Reply-To: <Ycu0KVq9PfuygKKx@google.com>

> From: Sean Christopherson <seanjc@google.com>
> Sent: Wednesday, December 29, 2021 9:05 AM
> 
> On Wed, Dec 22, 2021, Jing Liu wrote:
> > @@ -1968,6 +1969,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu,
> struct msr_data *msr_info)
> >  	case MSR_IA32_XFD:
> >  		ret = kvm_set_msr_common(vcpu, msr_info);
> >  		if (!ret && data) {
> > +			vmx_disable_intercept_for_msr(vcpu,
> MSR_IA32_XFD, MSR_TYPE_RW);
> > +			vcpu->arch.xfd_out_of_sync = true;
> 
> xfd_out_of_sync is a poor name, as XFD _may_ be out of sync, or it may not.
> It's
> also confusing that it's kept set after XFD is explicitly synchronized in
> vcpu_enter_guest().

yes, sync_xfd_after_exit might be more accurate.

> 
> > +
> >  			vcpu->arch.trap_nm = true;
> >  			vmx_update_exception_bitmap(vcpu);
> 
> Ah, this is why #NM interception was made sticky many patches ago.  More
> at the end.
> 
> >  		}
> > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> > index bf9d3051cd6c..0a00242a91e7 100644
> > --- a/arch/x86/kvm/vmx/vmx.h
> > +++ b/arch/x86/kvm/vmx/vmx.h
> > @@ -340,7 +340,7 @@ struct vcpu_vmx {
> >  	struct lbr_desc lbr_desc;
> >
> >  	/* Save desired MSR intercept (read: pass-through) state */
> > -#define MAX_POSSIBLE_PASSTHROUGH_MSRS	14
> > +#define MAX_POSSIBLE_PASSTHROUGH_MSRS	15
> >  	struct {
> >  		DECLARE_BITMAP(read,
> MAX_POSSIBLE_PASSTHROUGH_MSRS);
> >  		DECLARE_BITMAP(write,
> MAX_POSSIBLE_PASSTHROUGH_MSRS);
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 3b756ff13103..10a08aa2aa45 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -10024,6 +10024,9 @@ static int vcpu_enter_guest(struct kvm_vcpu
> *vcpu)
> >  	if (vcpu->arch.guest_fpu.xfd_err)
> >  		wrmsrl(MSR_IA32_XFD_ERR, 0);
> >
> > +	if (vcpu->arch.xfd_out_of_sync)
> 
> Rather than adding a flag that tracks whether or not the MSR can be written
> by
> the guest, can't this be:
> 
> 	if (!vmx_test_msr_bitmap_write(vcpu->loaded_vmcs->msr_bitmap))
> 		fpu_sync_guest_vmexit_xfd_state();
> 

We can use this

> That might be marginally slower than checking a dedicated flag?  But is has
> the
> advantage of doing the correct thing for nested guests instead of penalizing
> them
> with an unnecessary sync on every exit.  If performance of the check is an
> issue,
> we could add a static key to skip the code unless at least one vCPU has
> triggered
> the XFD crud, a la kvm_has_noapic_vcpu (which may or may not provide any
> real
> performance benefits).
> 
> Speaking of nested, interception of #NM in vmx_update_exception_bitmap()
> is wrong
> with respect to nested guests.  Until XFD is supported for L2, which I didn't
> see
> in this series, #NM should not be intercepted while L2 is running.

Can you remind what additional thing is required to support XFD for L2?
If only about performance I prefer to the current conservative approach
as the first step. As explained earlier, #NM should be rare if the guest 
doesn't run AMX applications at all. Adding nested into this picture doesn't 
make things a lot worser.

> 
> For the earlier patch that introduced arch.trap_nm, if it's not too gross and
> not
> racy, the code could be:
> 
> 	if (is_guest_mode(vcpu))
> 		eb |= get_vmcs12(vcpu)->exception_bitmap;
>         else {
> 		...
> 
> 		if (vcpu->arch.guest_fpu.fpstate.xfd)
> 			eb |= (1u << NM_VECTOR);
> 	}
> 
> Though I'm ok with a semi-temporary flag if that's gross/racy.
> 
> Then this patch can change it to:
> 
> 	if (is_guest_mode(vcpu))
> 		eb |= get_vmcs12(vcpu)->exception_bitmap;
>         else {
> 		...
> 
> 		if (!vmx_test_msr_bitmap_write(vcpu->vmcs01.msr_bitmap))
> 			eb |= (1u << NM_VECTOR);
> 	}
> 
> > +		fpu_sync_guest_vmexit_xfd_state();
> > +
> >  	/*
> >  	 * Consume any pending interrupts, including the possible source of
> >  	 * VM-Exit on SVM and any ticks that occur between VM-Exit and
> now.
> > --
> > 2.27.0
> >

Thanks
Kevin

  reply	other threads:[~2021-12-29  3:35 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22 12:40 [PATCH v3 00/22] AMX Support in KVM Jing Liu
2021-12-22 12:40 ` [PATCH v3 01/22] x86/fpu: Extend fpu_xstate_prctl() with guest permissions Jing Liu
2021-12-22 12:40 ` [PATCH v3 02/22] x86/fpu: Prepare guest FPU for dynamically enabled FPU features Jing Liu
2021-12-22 12:40 ` [PATCH v3 03/22] kvm: x86: Fix xstate_required_size() to follow XSTATE alignment rule Jing Liu
2021-12-22 12:40 ` [PATCH v3 04/22] kvm: x86: Exclude unpermitted xfeatures at KVM_GET_SUPPORTED_CPUID Jing Liu
2021-12-22 12:40 ` [PATCH v3 05/22] kvm: x86: Check permitted dynamic xfeatures at KVM_SET_CPUID2 Jing Liu
2021-12-28 23:38   ` Sean Christopherson
2021-12-29  2:18     ` Tian, Kevin
2021-12-22 12:40 ` [PATCH v3 06/22] x86/fpu: Make XFD initialization in __fpstate_reset() a function argument Jing Liu
2021-12-22 12:40 ` [PATCH v3 07/22] x86/fpu: Add guest support to xfd_enable_feature() Jing Liu
2021-12-22 12:40 ` [PATCH v3 08/22] x86/fpu: Provide fpu_update_guest_perm_features() for guest Jing Liu
2021-12-22 12:40 ` [PATCH v3 09/22] kvm: x86: Enable dynamic XSAVE features at KVM_SET_CPUID2 Jing Liu
2021-12-28 23:54   ` Sean Christopherson
2021-12-29  2:23     ` Tian, Kevin
2021-12-22 12:40 ` [PATCH v3 10/22] x86/fpu: Provide fpu_update_guest_xfd() for IA32_XFD emulation Jing Liu
2021-12-22 12:40 ` [PATCH v3 11/22] kvm: x86: Add emulation for IA32_XFD Jing Liu
2021-12-22 12:40 ` [PATCH v3 12/22] x86/fpu: Prepare xfd_err in struct fpu_guest Jing Liu
2021-12-22 12:40 ` [PATCH v3 13/22] kvm: x86: Intercept #NM for saving IA32_XFD_ERR Jing Liu
2021-12-29  0:09   ` Sean Christopherson
2021-12-29  2:52     ` Tian, Kevin
2021-12-29 17:37       ` Sean Christopherson
2021-12-29  6:50     ` Tian, Kevin
2021-12-29  8:13     ` Tian, Kevin
2021-12-22 12:40 ` [PATCH v3 14/22] kvm: x86: Emulate IA32_XFD_ERR for guest Jing Liu
2021-12-22 12:40 ` [PATCH v3 15/22] kvm: x86: Disable RDMSR interception of IA32_XFD_ERR Jing Liu
2021-12-22 12:40 ` [PATCH v3 16/22] kvm: x86: Add XCR0 support for Intel AMX Jing Liu
2021-12-29  0:21   ` Sean Christopherson
2021-12-29  3:01     ` Tian, Kevin
2021-12-22 12:40 ` [PATCH v3 17/22] kvm: x86: Add CPUID " Jing Liu
2021-12-22 12:40 ` [PATCH v3 18/22] x86/fpu: Add uabi_size to guest_fpu Jing Liu
2021-12-22 12:40 ` [PATCH v3 19/22] kvm: x86: Get/set expanded xstate buffer Jing Liu
2021-12-29  0:38   ` Sean Christopherson
2021-12-29  2:57     ` Wang, Wei W
2021-12-29  6:36       ` Tian, Kevin
2021-12-22 12:40 ` [PATCH v3 20/22] kvm: selftests: Add support for KVM_CAP_XSAVE2 Jing Liu
2021-12-22 12:40 ` [PATCH v3 21/22] x86/fpu: Provide fpu_sync_guest_vmexit_xfd_state() Jing Liu
2021-12-22 12:40 ` [PATCH v3 22/22] kvm: x86: Disable interception for IA32_XFD on demand Jing Liu
2021-12-29  1:04   ` Sean Christopherson
2021-12-29  3:35     ` Tian, Kevin [this message]
2021-12-29  7:16     ` Tian, Kevin
2021-12-29 17:26       ` Sean Christopherson
2021-12-30  1:28         ` Tian, Kevin
2021-12-30  7:04         ` Tian, Kevin
2021-12-31  9:42         ` Tian, Kevin
2021-12-29  7:37     ` Tian, Kevin
2022-01-04 18:32     ` Paolo Bonzini
2022-01-04 18:58       ` Sean Christopherson

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=BN9PR11MB527653AF0BEC5BBA007B72408C449@BN9PR11MB5276.namprd11.prod.outlook.com \
    --to=kevin.tian@intel.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=guang.zeng@intel.com \
    --cc=jing2.liu@intel.com \
    --cc=jing2.liu@linux.intel.com \
    --cc=jun.nakajima@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wei.w.wang@intel.com \
    --cc=x86@kernel.org \
    --cc=yang.zhong@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.