From: Yang Weijiang <weijiang.yang@intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Yang Weijiang <weijiang.yang@intel.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
pbonzini@redhat.com, jmattson@google.com,
yu.c.zhang@linux.intel.com
Subject: Re: [PATCH v9 7/7] KVM: X86: Add user-space access interface for CET MSRs
Date: Thu, 5 Mar 2020 20:31:31 +0800 [thread overview]
Message-ID: <20200305123130.GA17242@local-michael-cet-test.sh.intel.com> (raw)
In-Reply-To: <20200304154538.GB21662@linux.intel.com>
On Wed, Mar 04, 2020 at 07:45:38AM -0800, Sean Christopherson wrote:
> On Wed, Mar 04, 2020 at 11:18:15PM +0800, Yang Weijiang wrote:
> > On Tue, Mar 03, 2020 at 02:28:27PM -0800, Sean Christopherson wrote:
> > > > @@ -1886,6 +1976,26 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> > > > else
> > > > msr_info->data = vmx->pt_desc.guest.addr_a[index / 2];
> > > > break;
> > > > + case MSR_IA32_S_CET:
> > > > + if (!cet_ctl_access_allowed(vcpu, msr_info))
> > > > + return 1;
> > > > + msr_info->data = vmcs_readl(GUEST_S_CET);
> > > > + break;
> > > > + case MSR_IA32_INT_SSP_TAB:
> > > > + if (!cet_ssp_access_allowed(vcpu, msr_info))
> > > > + return 1;
> > > > + msr_info->data = vmcs_readl(GUEST_INTR_SSP_TABLE);
> > > > + break;
> > > > + case MSR_IA32_U_CET:
> > > > + if (!cet_ctl_access_allowed(vcpu, msr_info))
> > > > + return 1;
> > > > + rdmsrl(MSR_IA32_U_CET, msr_info->data);
> > > > + break;
> > > > + case MSR_IA32_PL0_SSP ... MSR_IA32_PL3_SSP:
> > > > + if (!cet_ssp_access_allowed(vcpu, msr_info))
> > > > + return 1;
> > > > + rdmsrl(msr_info->index, msr_info->data);
> > >
> > > Ugh, thought of another problem. If a SoftIRQ runs after an IRQ it can
> > > load the kernel FPU state. So for all the XSAVES MSRs we'll need a helper
> > > similar to vmx_write_guest_kernel_gs_base(), except XSAVES has to be even
> > > more restrictive and disable IRQs entirely. E.g.
> > >
> > > static void vmx_get_xsave_msr(struct msr_data *msr_info)
> > > {
> > > local_irq_disable();
> > > if (test_thread_flag(TIF_NEED_FPU_LOAD))
> > > switch_fpu_return();
> > > rdmsrl(msr_info->index, msr_info->data);
> > > local_irq_enable();
> > In this case, would SoftIRQ destroy vcpu->arch.guest.fpu states which
> > had been restored to XSAVES MSRs that we were accessing?
>
> Doing kernel_fpu_begin() from a softirq would swap guest.fpu out of the
> CPUs registers. It sets TIF_NEED_FPU_LOAD to mark the tasks has needing to
> reload its FPU state prior to returning to userspace. So it doesn't
> destroy it per se. The result is that KVM would read/write the CET MSRs
> after they're loaded from the kernel's FPU state instead of reading the
> MSRs loaded from the guest's FPU state.
>
OK, will wrap the access code with a helper, thank you!
> > So should we restore
> > guest.fpu or? In previous patch, we have restored guest.fpu before
> > access the XSAVES MSRs.
>
> There are three different FPU states:
>
> - kernel
> - userspace
> - guest
>
> RDMSR/WRMSR for CET MSRs need to run while the guest.fpu state is loaded
> into the CPU registers[1]. At the beginning of the syscall from userspace,
> i.e. the vCPU ioctl(), the task's FPU state[2] holds userspace FPU state.
> Patch 6/7 swaps out the userspace state and loads the guest state.
>
> But, if a softirq runs between kvm_load_guest_fpu() and now, and executes
> kernel_fpu_begin(), it will swap the guest state (out of CPU registers)
> and load the kernel state (into PCU registers). The actual RDMSR/WRMSR
> needs to ensure the guest state is still loaded by checking and handling
> TIF_NEED_FPU_LOAD.
>
> [1] An alternative to doing switch_fpu_return() on TIF_NEED_FPU_LOAD would
> be to calculate the offset into the xsave and read/write directly
> to/from memory. But IMO that's unnecessary complexity as the guest's
> fpu state still needs to be reloaded before re-entering the guest, e.g.
> if vmx_{g,s}et_msr() is invoked on {RD,WR}MSR intercept, while loading
> or saving MSR state from userspace isn't a hot path.
>
> [2] I worded this to say "task's FPU state" because it's also possible the
> CPU registers hold kernel state at the beginning of the vCPU ioctl(),
> e.g. because of softirq.
It's clear to me, thanks for the explanation.
prev parent reply other threads:[~2020-03-05 12:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-27 2:11 [PATCH v9 0/7] Introduce support for guest CET feature Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 1/7] KVM: CPUID: Fix IA32_XSS support in CPUID(0xd,i) enumeration Yang Weijiang
2020-03-05 14:51 ` Paolo Bonzini
2020-03-06 0:38 ` Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 2/7] KVM: VMX: Define CET VMCS fields and #CP flag Yang Weijiang
2020-03-03 21:42 ` Sean Christopherson
2020-03-04 8:44 ` Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 3/7] KVM: VMX: Pass through CET related MSRs Yang Weijiang
2020-03-03 21:51 ` Sean Christopherson
2020-03-04 8:46 ` Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 4/7] KVM: VMX: Load CET states on vmentry/vmexit Yang Weijiang
2020-03-03 22:06 ` Sean Christopherson
2020-03-04 8:55 ` Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 5/7] KVM: X86: Enable CET bits update in IA32_XSS Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 6/7] KVM: X86: Load guest fpu state when accessing MSRs managed by XSAVES Yang Weijiang
2019-12-27 2:11 ` [PATCH v9 7/7] KVM: X86: Add user-space access interface for CET MSRs Yang Weijiang
2020-03-03 22:28 ` Sean Christopherson
2020-03-04 15:18 ` Yang Weijiang
2020-03-04 15:45 ` Sean Christopherson
2020-03-05 12:31 ` Yang Weijiang [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=20200305123130.GA17242@local-michael-cet-test.sh.intel.com \
--to=weijiang.yang@intel.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=yu.c.zhang@linux.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 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®