From: Maxim Levitsky <mlevitsk@redhat.com>
To: "Yang, Weijiang" <weijiang.yang@intel.com>,
"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>, "Christopherson,,
Sean" <seanjc@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "peterz@infradead.org" <peterz@infradead.org>,
"Hansen, Dave" <dave.hansen@intel.com>,
"Gao, Chao" <chao.gao@intel.com>,
"john.allen@amd.com" <john.allen@amd.com>
Subject: Re: [PATCH v6 03/25] x86/fpu/xstate: Add CET supervisor mode state support
Date: Tue, 31 Oct 2023 19:44:08 +0200 [thread overview]
Message-ID: <dc1aa5ca99f56351ad15f6d4158288644ac6a23c.camel@redhat.com> (raw)
In-Reply-To: <c72f3ef9-ee82-84c8-c802-c9593a1dd5d1@intel.com>
On Fri, 2023-09-15 at 14:30 +0800, Yang, Weijiang wrote:
> On 9/15/2023 8:06 AM, Edgecombe, Rick P wrote:
> > On Thu, 2023-09-14 at 02:33 -0400, Yang Weijiang wrote:
> > > Add supervisor mode state support within FPU xstate management
> > > framework.
> > > Although supervisor shadow stack is not enabled/used today in
> > > kernel,KVM
> > ^ Nit: needs a space
> > > requires the support because when KVM advertises shadow stack feature
> > > to
> > > guest, architechturally it claims the support for both user and
> > ^ Spelling: "architecturally"
>
> Thank you!!
>
> > > supervisor
> > > modes for Linux and non-Linux guest OSes.
> > >
> > > With the xstate support, guest supervisor mode shadow stack state can
> > > be
> > > properly saved/restored when 1) guest/host FPU context is swapped
> > > 2) vCPU
> > > thread is sched out/in.
> > (2) is a little bit confusing, because the lazy FPU stuff won't always
> > save/restore while scheduling.
>
> It's true for normal thread, but for vCPU thread, it's a bit different, on the path to
> vm-entry, after host/guest fpu states swapped, preemption is not disabled and
> vCPU thread could be sched out/in, in this case, guest FPU states will be saved/
> restored because TIF_NEED_FPU_LOAD is always cleared after swap.
>
> > But trying to explain the details in
> > this commit log is probably unnecessary. Maybe something like?
> >
> > 2) At the proper times while other tasks are scheduled
>
> I just want to justify that enabling of supervisor xstate is necessary for guest.
> Maybe I need to reword a bit :-)
>
> > I think also a key part of this is that XFEATURE_CET_KERNEL is not
> > *all* of the "guest supervisor mode shadow stack state", at least with
> > respect to the MSRs. It might be worth calling that out a little more
> > loudly.
>
> OK, I will call it out that supervisor mode shadow stack state also includes IA32_S_CET msr.
>
> > > The alternative is to enable it in KVM domain, but KVM maintainers
> > > NAKed
> > > the solution. The external discussion can be found at [*], it ended
> > > up
> > > with adding the support in kernel instead of KVM domain.
> > >
> > > Note, in KVM case, guest CET supervisor state i.e.,
> > > IA32_PL{0,1,2}_MSRs,
> > > are preserved after VM-Exit until host/guest fpstates are swapped,
> > > but
> > > since host supervisor shadow stack is disabled, the preserved MSRs
> > > won't
> > > hurt host.
> > It might beg the question of if this solution will need to be redone by
> > some future Linux supervisor shadow stack effort. I *think* the answer
> > is no.
>
> AFAICT KVM needs to be modified if host shadow stack is implemented, at least
> guest/host CET supervisor MSRs should be swapped at the earliest time after
> vm-exit so that host won't misbehavior on *guest* MSR contents.
I agree.
>
> > Most of the xsave managed features are restored before returning to
> > userspace because they would have userspace effect. But
> > XFEATURE_CET_KERNEL is different. It only effects the kernel. But the
> > IA32_PL{0,1,2}_MSRs are used when transitioning to those rings. So for
> > Linux they would get used when transitioning back from userspace. In
> > order for it to be used when control transfers back *from* userspace,
> > it needs to be restored before returning *to* userspace. So despite
> > being needed only for the kernel, and having no effect on userspace, it
> > might need to be swapped/restored at the same time as the rest of the
> > FPU state that only affects userspace.
>
> You're right, for enabling of supervisor mode shadow stack, we need to take
> it carefully whenever ring/stack is switching. But we still have time to figure out
> the points.
>
> Thanks a lot for bring up such kind of thinking!
>
> > Probably supervisor shadow stack for Linux needs much more analysis,
> > but trying to leave some breadcrumbs on the thinking from internal
> > reviews. I don't know if it might be good to include some of this
> > reasoning in the commit log. It's a bit hand wavy.
>
> IMO, we have put much assumption on the fact that CET supervisor shadow stack is not
> enabled in kernel and this patch itself is straightforward and simple, it's just a small
> brick for enabling supervisor shadow stack, we would revisit whether something is an
> issue based on how SSS is implemented in kernel. So let's not add such kind of reasoning :-)
Overall the patch looks OK to me.
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Best regards,
Maxim Levitsky
>
> Thank you for the enlightenment!
> > > [*]:
> > > https://lore.kernel.org/all/806e26c2-8d21-9cc9-a0b7-7787dd231729@intel.com/
> > >
> > > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
> > Otherwise, the code looked good to me.
next prev parent reply other threads:[~2023-10-31 17:45 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 6:33 [PATCH v6 00/25] Enable CET Virtualization Yang Weijiang
2023-09-14 6:33 ` [PATCH v6 01/25] x86/fpu/xstate: Manually check and add XFEATURE_CET_USER xstate bit Yang Weijiang
2023-09-14 22:39 ` Edgecombe, Rick P
2023-09-15 2:32 ` Yang, Weijiang
2023-09-15 16:35 ` Edgecombe, Rick P
2023-09-18 7:16 ` Yang, Weijiang
2023-10-31 17:43 ` Maxim Levitsky
2023-11-01 9:19 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 02/25] x86/fpu/xstate: Fix guest fpstate allocation size calculation Yang Weijiang
2023-09-14 22:45 ` Edgecombe, Rick P
2023-09-15 2:45 ` Yang, Weijiang
2023-09-15 16:35 ` Edgecombe, Rick P
2023-10-21 0:39 ` Sean Christopherson
2023-10-24 8:50 ` Yang, Weijiang
2023-10-24 16:32 ` Sean Christopherson
2023-10-25 13:49 ` Yang, Weijiang
2023-10-31 17:43 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 03/25] x86/fpu/xstate: Add CET supervisor mode state support Yang Weijiang
2023-09-15 0:06 ` Edgecombe, Rick P
2023-09-15 6:30 ` Yang, Weijiang
2023-10-31 17:44 ` Maxim Levitsky [this message]
2023-09-14 6:33 ` [PATCH v6 04/25] x86/fpu/xstate: Introduce kernel dynamic xfeature set Yang Weijiang
2023-09-15 0:24 ` Edgecombe, Rick P
2023-09-15 6:42 ` Yang, Weijiang
2023-10-31 17:44 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 05/25] x86/fpu/xstate: Remove kernel dynamic xfeatures from kernel default_features Yang Weijiang
2023-09-14 16:22 ` Dave Hansen
2023-09-15 1:52 ` Yang, Weijiang
2023-10-31 17:44 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 06/25] x86/fpu/xstate: Opt-in kernel dynamic bits when calculate guest xstate size Yang Weijiang
2023-09-14 17:40 ` Dave Hansen
2023-09-15 2:22 ` Yang, Weijiang
2023-10-24 17:07 ` Sean Christopherson
2023-10-25 14:49 ` Yang, Weijiang
2023-10-26 17:24 ` Sean Christopherson
2023-10-26 22:06 ` Edgecombe, Rick P
2023-10-31 17:45 ` Maxim Levitsky
2023-11-01 14:16 ` Sean Christopherson
2023-11-02 18:20 ` Maxim Levitsky
2023-11-03 14:33 ` Sean Christopherson
2023-11-07 18:04 ` Maxim Levitsky
2023-11-14 9:13 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 07/25] x86/fpu/xstate: Tweak guest fpstate to support kernel dynamic xfeatures Yang Weijiang
2023-10-31 17:45 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 08/25] x86/fpu/xstate: WARN if normal fpstate contains " Yang Weijiang
2023-10-31 17:45 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 09/25] KVM: x86: Rework cpuid_get_supported_xcr0() to operate on vCPU data Yang Weijiang
2023-10-31 17:46 ` Maxim Levitsky
2023-11-01 14:41 ` Sean Christopherson
2023-11-02 18:25 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 10/25] KVM: x86: Add kvm_msr_{read,write}() helpers Yang Weijiang
2023-10-31 17:47 ` Maxim Levitsky
2023-11-01 19:32 ` Sean Christopherson
2023-11-02 18:26 ` Maxim Levitsky
2023-11-15 9:00 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 11/25] KVM: x86: Report XSS as to-be-saved if there are supported features Yang Weijiang
2023-10-31 17:47 ` Maxim Levitsky
2023-11-01 19:18 ` Sean Christopherson
2023-11-02 18:31 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 12/25] KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS Yang Weijiang
2023-10-08 5:54 ` Chao Gao
2023-10-10 0:49 ` Yang, Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-11-01 17:20 ` Sean Christopherson
2023-11-15 7:18 ` Binbin Wu
2023-09-14 6:33 ` [PATCH v6 13/25] KVM: x86: Initialize kvm_caps.supported_xss Yang Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 14/25] KVM: x86: Load guest FPU state when access XSAVE-managed MSRs Yang Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-11-01 18:05 ` Sean Christopherson
2023-11-02 18:31 ` Maxim Levitsky
2023-11-03 8:46 ` Yang, Weijiang
2023-11-03 14:02 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 15/25] KVM: x86: Add fault checks for guest CR4.CET setting Yang Weijiang
2023-10-31 17:51 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 16/25] KVM: x86: Report KVM supported CET MSRs as to-be-saved Yang Weijiang
2023-10-08 6:19 ` Chao Gao
2023-10-10 0:54 ` Yang, Weijiang
2023-10-31 17:52 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 17/25] KVM: VMX: Introduce CET VMCS fields and control bits Yang Weijiang
2023-10-31 17:52 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 18/25] KVM: x86: Use KVM-governed feature framework to track "SHSTK/IBT enabled" Yang Weijiang
2023-10-31 17:54 ` Maxim Levitsky
2023-11-01 15:46 ` Sean Christopherson
2023-11-02 18:35 ` Maxim Levitsky
2023-11-04 0:07 ` Sean Christopherson
2023-11-07 18:05 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 19/25] KVM: VMX: Emulate read and write to CET MSRs Yang Weijiang
2023-10-31 17:55 ` Maxim Levitsky
2023-11-01 16:31 ` Sean Christopherson
2023-11-02 18:38 ` Maxim Levitsky
2023-11-02 23:58 ` Sean Christopherson
2023-11-07 18:12 ` Maxim Levitsky
2023-11-07 18:39 ` Sean Christopherson
2023-11-03 8:18 ` Yang, Weijiang
2023-11-03 22:26 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 20/25] KVM: x86: Save and reload SSP to/from SMRAM Yang Weijiang
2023-10-31 17:55 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 21/25] KVM: VMX: Set up interception for CET MSRs Yang Weijiang
2023-10-31 17:56 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 22/25] KVM: VMX: Set host constant supervisor states to VMCS fields Yang Weijiang
2023-10-31 17:56 ` Maxim Levitsky
2023-09-14 6:33 ` [PATCH v6 23/25] KVM: x86: Enable CET virtualization for VMX and advertise to userspace Yang Weijiang
2023-09-24 13:38 ` kernel test robot
2023-09-25 0:26 ` Yang, Weijiang
2023-10-31 17:56 ` Maxim Levitsky
2023-11-01 22:14 ` Sean Christopherson
2023-09-14 6:33 ` [PATCH v6 24/25] KVM: nVMX: Introduce new VMX_BASIC bit for event error_code delivery to L1 Yang Weijiang
2023-10-31 17:57 ` Maxim Levitsky
2023-11-01 4:21 ` Chao Gao
2023-11-15 8:31 ` Yang, Weijiang
2023-09-14 6:33 ` [PATCH v6 25/25] KVM: nVMX: Enable CET support for nested guest Yang Weijiang
2023-10-31 17:57 ` Maxim Levitsky
2023-11-01 2:09 ` Chao Gao
2023-11-01 9:22 ` Yang, Weijiang
2023-11-01 9:54 ` Maxim Levitsky
2023-11-15 8:56 ` Yang, Weijiang
2023-11-15 8:23 ` Yang, Weijiang
2023-09-25 0:31 ` [PATCH v6 00/25] Enable CET Virtualization Yang, Weijiang
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=dc1aa5ca99f56351ad15f6d4158288644ac6a23c.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=john.allen@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=weijiang.yang@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®