From: Yan Zhao <yan.y.zhao@intel.com>
To: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"Kirill A. Shutemov" <kas@kernel.org>, <kvm@vger.kernel.org>,
<x86@kernel.org>, <linux-coco@lists.linux.dev>,
<linux-kernel@vger.kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Hou Wenlong <houwenlong.hwl@antgroup.com>
Subject: Re: [PATCH v5 1/4] KVM: TDX: Explicitly set user-return MSRs that *may* be clobbered by the TDX-Module
Date: Thu, 6 Nov 2025 10:22:17 +0800 [thread overview]
Message-ID: <aQwGWXmu0a72m1RE@yzhao56-desk.sh.intel.com> (raw)
In-Reply-To: <6ca6f19e-0bdd-4ad8-aaca-93a1247d2588@intel.com>
On Wed, Nov 05, 2025 at 05:16:56PM +0800, Xiaoyao Li wrote:
> On 11/5/2025 9:52 AM, Yan Zhao wrote:
> > On Tue, Nov 04, 2025 at 09:55:54AM -0800, Sean Christopherson wrote:
> > > On Tue, Nov 04, 2025, Yan Zhao wrote:
> > > > On Tue, Nov 04, 2025 at 04:40:44PM +0800, Xiaoyao Li wrote:
> > > > > On 11/4/2025 3:06 PM, Yan Zhao wrote:
> > > > > > Another nit:
> > > > > > Remove the tdx_user_return_msr_update_cache() in the comment of __tdx_bringup().
> > > > > >
> > > > > > Or could we just invoke tdx_user_return_msr_update_cache() in
> > > > > > tdx_prepare_switch_to_guest()?
> > > > >
> > > > > No. It lacks the WRMSR operation to update the hardware value, which is the
> > > > > key of this patch.
> > > > As [1], I don't think the WRMSR operation to update the hardware value is
> > > > necessary. The value will be updated to guest value soon any way if
> > > > tdh_vp_enter() succeeds, or the hardware value remains to be the host value or
> > > > the default value.
> > >
> > > As explained in the original thread:
> > >
> > > : > If the MSR's do not get clobbered, does it matter whether or not they get
> > > : > restored.
> > > :
> > > : It matters because KVM needs to know the actual value in hardware. If KVM thinks
> > > : an MSR is 'X', but it's actually 'Y', then KVM could fail to write the correct
> > > : value into hardware when returning to userspace and/or when running a different
> > > : vCPU.
> > >
> > > I.e. updating the cache effectively corrupts state if the TDX-Module doesn't
> > > clobber MSRs as expected, i.e. if the current value is preserved in hardware.
> > I'm not against this patch. But I think the above explanation is not that
> > convincing, (or somewhat confusing).
> >
> >
> > By "if the TDX-Module doesn't clobber MSRs as expected",
> > - if it occurs due to tdh_vp_enter() failure, I think it's fine.
> > Though KVM thinks the MSR is 'X', the actual value in hardware should be
> > either 'Y' (the host value) or 'X' (the expected clobbered value).
> > It's benign to preserving value 'Y', no?
>
> For example, after tdh_vp_enter() failure, the state becomes
>
> .curr == 'X'
> hardware == 'Y'
>
> and the TD vcpu thread is preempted and the pcpu is scheduled to run another
> VM's vcpu, which is a normal VMX vcpu and it happens to have the MSR value
> of 'X'. So in
>
> vmx_prepare_switch_to_guest()
> -> kvm_set_user_return_msr()
>
> it will skip the WRMSR because written_value == .curr == 'X', but the
> hardware value is 'Y'. Then KVM fails to load the expected value 'X' for the
> VMX vcpu.
Oh. Thanks! I overlooked that there's another checking of .curr in
kvm_set_user_return_msr(). It explains why .curr must be equal to the hardware
value when outside guest mode.
> > - if it occurs due to TDX module bugs, e.g., if after a successful
> > tdh_vp_enter() and VM exits, the TDX module clobbers the MSR to 'Z', while
> > the host value for the MSR is 'Y' and KVM thinks the actual value is 'X'.
> > Then the hardware state will be incorrect after returning to userspace if
> > 'X' == 'Y'. But this patch can't guard against this condition as well, right?
> >
> >
> > > > But I think invoking tdx_user_return_msr_update_cache() in
> > > > tdx_prepare_switch_to_guest() is better than in
> > > > tdx_prepare_switch_to_host().
> > > >
> > > > [1] https://lore.kernel.org/kvm/aQhJol0CvT6bNCJQ@yzhao56-desk.sh.intel.com/
>
next prev parent reply other threads:[~2025-11-06 2:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 19:15 [PATCH v5 0/4] KVM: x86: User-return MSR fix+cleanups Sean Christopherson
2025-10-30 19:15 ` [PATCH v5 1/4] KVM: TDX: Explicitly set user-return MSRs that *may* be clobbered by the TDX-Module Sean Christopherson
2025-11-03 6:20 ` Yan Zhao
2025-11-04 7:06 ` Yan Zhao
2025-11-04 8:40 ` Xiaoyao Li
2025-11-04 9:31 ` Yan Zhao
2025-11-04 17:55 ` Sean Christopherson
2025-11-05 1:52 ` Yan Zhao
2025-11-05 9:16 ` Xiaoyao Li
2025-11-06 2:22 ` Yan Zhao [this message]
2025-11-03 7:42 ` Xiaoyao Li
2025-10-30 19:15 ` [PATCH v5 2/4] KVM: x86: WARN if user-return MSR notifier is registered on exit Sean Christopherson
2025-10-30 19:15 ` [PATCH v5 3/4] KVM: x86: Leave user-return notifier registered on reboot/shutdown Sean Christopherson
2025-11-07 8:18 ` Chao Gao
2025-11-08 1:37 ` Sean Christopherson
2025-10-30 19:15 ` [PATCH v5 4/4] KVM: x86: Don't disable IRQs when unregistering user-return notifier Sean Christopherson
2025-11-04 10:34 ` Huang, Kai
2025-11-10 15:37 ` [PATCH v5 0/4] KVM: x86: User-return MSR fix+cleanups 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=aQwGWXmu0a72m1RE@yzhao56-desk.sh.intel.com \
--to=yan.y.zhao@intel.com \
--cc=houwenlong.hwl@antgroup.com \
--cc=kas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=x86@kernel.org \
--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 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®