From: Binbin Wu <binbin.wu@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Kai Huang <kai.huang@intel.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
Chao Gao <chao.gao@intel.com>,
Rick P Edgecombe <rick.p.edgecombe@intel.com>,
"mikko.ylinen@linux.intel.com" <mikko.ylinen@linux.intel.com>,
Xiaoyao Li <xiaoyao.li@intel.com>,
Tony Lindgren <tony.lindgren@intel.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Reinette Chatre <reinette.chatre@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Yan Y Zhao <yan.y.zhao@intel.com>,
Isaku Yamahata <isaku.yamahata@intel.com>
Subject: Re: [PATCH 1/2] KVM: TDX: Handle TDG.VP.VMCALL<GetQuote>
Date: Thu, 10 Apr 2025 08:06:37 +0800 [thread overview]
Message-ID: <dc825cf8-eb78-47ad-8e3e-509183624368@linux.intel.com> (raw)
In-Reply-To: <Z_Z61UlNM1vlEdW1@google.com>
On 4/9/2025 9:49 PM, Sean Christopherson wrote:
> On Wed, Apr 02, 2025, Binbin Wu wrote:
>> On 4/2/2025 8:53 AM, Huang, Kai wrote:
>>>> +static int tdx_get_quote(struct kvm_vcpu *vcpu)
>>>> +{
>>>> + struct vcpu_tdx *tdx = to_tdx(vcpu);
>>>> +
>>>> + u64 gpa = tdx->vp_enter_args.r12;
>>>> + u64 size = tdx->vp_enter_args.r13;
>>>> +
>>>> + /* The buffer must be shared memory. */
>>>> + if (vt_is_tdx_private_gpa(vcpu->kvm, gpa) || size == 0) {
>>>> + tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_INVALID_OPERAND);
>>>> + return 1;
>>>> + }
>>> It is a little bit confusing about the shared buffer check here. There are two
>>> perspectives here:
>>>
>>> 1) the buffer has already been converted to shared, i.e., the attributes are
>>> stored in the Xarray.
>>> 2) the GPA passed in the GetQuote must have the shared bit set.
>>>
>>> The key is we need 1) here. From the spec, we need the 2) as well because it
>>> *seems* that the spec requires GetQuote to provide the GPA with shared bit set,
>>> as it says "Shared GPA as input".
>>>
>>> The above check only does 2). I think we need to check 1) as well, because once
>>> you forward this GetQuote to userspace, userspace is able to access it freely.
> (1) is inherently racy. By the time KVM exits to userspace, the page could have
> already been converted to private in the memory attributes. KVM doesn't control
> shared<=>private conversions, so ultimately it's userspace's responsibility to
> handle this check. E.g. userspace needs to take its lock on conversions across
> the check+access on the buffer. Or if userpsace unmaps its shared mappings when
> a gfn is private, userspace could blindly access the region and handle the
> resulting SIGBUS (or whatever error manifests).
>
> For (2), the driving motiviation for doing the checks (or not) is KVM's ABI.
> I.e. whether nor KVM should handle the check depends on what KVM does for
> similar exits to userspace. Helping userspace is nice-to-have, but not mandatory
> (and helping userspace can also create undesirable ABI).
>
> My preference would be that KVM doesn't bleed the SHARED bit into its exit ABI.
> And at a glance, that's exactly what KVM does for KVM_HC_MAP_GPA_RANGE. In
> __tdx_map_gpa(), the so called "direct" bits are dropped (OMG, who's brilliant
> idea was it to add more use of "direct" in the MMU code):
>
> tdx->vcpu.run->hypercall.args[0] = gpa & ~gfn_to_gpa(kvm_gfn_direct_bits(tdx->vcpu.kvm));
> tdx->vcpu.run->hypercall.args[1] = size / PAGE_SIZE;
> tdx->vcpu.run->hypercall.args[2] = vt_is_tdx_private_gpa(tdx->vcpu.kvm, gpa) ?
> KVM_MAP_GPA_RANGE_ENCRYPTED :
> KVM_MAP_GPA_RANGE_DECRYPTED;
GetQuote is the first TDX specific KVM exit reason, previous TDVMCALLs that
exit to userspace are converted to exist KVM exit ABIs, e.g., TDVMCALL_MAP_GPA
is converted to KVM_EXIT_HYPERCALL with KVM_HC_MAP_GPA_RANGE, so the GPA passed
to userspace must have the shared bit dropped.
>
> So, KVM should keep the vt_is_tdx_private_gpa(), but KVM also needs to strip the
> SHARED bit from the GPA reported to userspace.
It makes sense to make the GPA format consistent to userspace.
Thanks for the suggestion!
next prev parent reply other threads:[~2025-04-10 0:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 0:15 [PATCH 0/2] TDX attestation support Binbin Wu
2025-04-02 0:15 ` [PATCH 1/2] KVM: TDX: Handle TDG.VP.VMCALL<GetQuote> Binbin Wu
2025-04-02 0:53 ` Huang, Kai
2025-04-02 8:58 ` Huang, Kai
2025-04-02 12:53 ` Binbin Wu
2025-04-02 13:16 ` Binbin Wu
2025-04-02 22:05 ` Huang, Kai
2025-04-02 22:00 ` Huang, Kai
2025-04-08 2:35 ` Binbin Wu
2025-04-09 13:49 ` Sean Christopherson
2025-04-10 0:06 ` Binbin Wu [this message]
2025-04-10 0:15 ` Huang, Kai
2025-04-02 22:19 ` Huang, Kai
2025-04-07 1:00 ` Binbin Wu
2025-04-15 1:49 ` Xiaoyao Li
2025-04-15 1:51 ` Edgecombe, Rick P
2025-04-15 1:55 ` Binbin Wu
2025-04-02 0:15 ` [PATCH 2/2] KVM: TDX: Handle TDG.VP.VMCALL<SetupEventNotifyInterrupt> Binbin Wu
2025-04-02 0:20 ` [PATCH 0/2] TDX attestation support Edgecombe, Rick P
2025-04-11 1:42 ` Binbin Wu
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=dc825cf8-eb78-47ad-8e3e-509183624368@linux.intel.com \
--to=binbin.wu@linux.intel.com \
--cc=adrian.hunter@intel.com \
--cc=chao.gao@intel.com \
--cc=isaku.yamahata@intel.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikko.ylinen@linux.intel.com \
--cc=pbonzini@redhat.com \
--cc=reinette.chatre@intel.com \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=tony.lindgren@intel.com \
--cc=xiaoyao.li@intel.com \
--cc=yan.y.zhao@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