From: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@linux.intel.com>
To: Kai Huang <kai.huang@intel.com>,
Isaku Yamahata <isaku.yamahata@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Tony Luck <tony.luck@intel.com>, Andi Kleen <ak@linux.intel.com>,
Wander Lairson Costa <wander@redhat.com>,
marcelo.cerri@canonical.com, tim.gardner@canonical.com,
khalid.elmously@canonical.com, philip.cox@canonical.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 5/5] x86/tdx: Add Quote generation support
Date: Tue, 17 May 2022 16:32:02 -0700 [thread overview]
Message-ID: <5e22f88f-fbef-0031-067f-1abd5cdaecb8@linux.intel.com> (raw)
In-Reply-To: <40caabe4c708b35844c246ec6a01b4ee03cbfa63.camel@intel.com>
On 5/17/22 4:06 PM, Kai Huang wrote:
> On Tue, 2022-05-17 at 13:08 -0700, Sathyanarayanan Kuppuswamy wrote:
>>
>> On 5/16/22 7:58 PM, Kai Huang wrote:
>>> On Fri, 2022-05-13 at 12:29 -0700, Sathyanarayanan Kuppuswamy wrote:
>>>>>
>>>>>
>>>>>> +
>>>>>> + /* Wait for attestation completion */
>>>>>> + ret = wait_for_completion_interruptible(&entry->compl);
>>>>>> + if (ret < 0) {
>>>>>> + /*
>>>>>> + * For premature termination, since VMM still owns the
>>>>>> + * shared buffer, mark the request invalid to let
>>>>>> + * quote_callback_handler() handle the memory cleanup
>>>>>> + * function.
>>>>>> + */
>>>>>> + invalidate_quote_request(entry);
>>>>>
>>>>> Interrupt can arrive after signal interrupt. So invalidate_quote_request()
>>>>> should check if the request is already processed, and return 0 or -EINTR.
>>>>> Probably check the state always and del_list under single lock/unlock pair.
>>>>
>>>> Agree. But I think we should return -EINTR for the interrupted case
>>>> irrespective of the processed status (so no return 0).
>>>>
>>>> I will hold the lock and handle the cleanup for the processed
>>>> status.
>>>
>>> Even if we check the buffer status in invalidate_quote_request(), there's no
>>> guarantee the VMM won't change the buffer status _after_ we do the check, so
>>> looks such check isn't necessary.
>>>
>>
>> Consider the case where we get a callback interrupt, and before we
>> complete the processing for it, user terminates the request. In this
>> scenario, quote_callback_handler() will consider the request is
>> still valid and no do the memory cleanup. To handle this case,
>> we need to check the status in invalidate_quote_request() and do
>> the cleanup if required.
>>
>> /* Handles early termination of GetQuote requests */
>> void invalidate_quote_request(struct quote_entry *entry)
>> {
>> struct tdx_quote_hdr *quote_hdr;
>>
>> /*
>> * For early termination, if the request is not yet
>> * processed by VMM (GET_QUOTE_IN_FLIGHT), the VMM
>> * still owns the shared buffer, so mark the request
>> * invalid to let quote_callback_handler() handle the
>> * memory cleanup function. If the request is already
>> * processed, then do the cleanup and return.
>> */
>>
>> mutex_lock("e_lock);
>> quote_hdr = (struct tdx_quote_hdr *)entry->buf->vmaddr;
>> if (quote_hdr->status == GET_QUOTE_IN_FLIGHT) {
>
> What prevents VMM from updating quote_hdr->status from IN_FLIGHT to DONE _after_
> this check?
If IN_FLIGHT -> DONE happens at this point, you will get a separate
callback interrupt for it after this change. Since we hold quote_lock
here, processing of that callback work will wait till we make the
request invalid. For invalid requests, quote_callback_handler() will
handle the cleanup.
This logic is mainly for the case where quote_callback_handler() in
process and user terminates the request. In this case,
quote_callback_handler() will not do the cleanup, and we should add
logic here to handle it.
>
> If you want to add such check, you should check against GET_QUOTE_DONE, but not
> IN_FLIGHT. Only after status is DONE, VMM will not update the buffer. Perhaps
> something like below:
>
> mutex_lock("e_lock);
> /* Skip invalidate the buffer if VMM has done with the buffer */
> if (quote_hdr->status == GET_QUOTE_DONE) {
> mutex_unlock("e_lock);
> return 0;
> }
There is no DONE status. Status can be either one of the following values.
GET_QUOTE_ERROR
GET_QUOTE_SUCCESS
GET_QUOTE_SERVICE_UNAVAILABLE
GET_QUOTE_IN_FLIGHT
>
> And in the IOCTL, you can perhaps to choose to return 0, instead of -EINTR in
> this case, as the Quote has been finished already.
I think your logic above is to return 0 for the completed request even
if it is interrupted. But IMO, since the user already interrupted the
request, then I think it is more appropriate to just return -EINTR for
this case.
>
> But I am not sure whether this is necessary. The worst case is one finished
> Quote is wasted I guess.
>
>> entry->valid = false;
>> mutex_unlock("e_lock);
>> return;
>> }
>> _del_quote_entry(entry);
>> mutex_unlock("e_lock);
>> }
>>
>>
>
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
prev parent reply other threads:[~2022-05-17 23:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 22:19 [PATCH v6 0/5] Add TDX Guest Attestation support Kuppuswamy Sathyanarayanan
2022-05-12 22:19 ` [PATCH v6 1/5] x86/tdx: Add TDX Guest attestation interface driver Kuppuswamy Sathyanarayanan
2022-05-16 18:08 ` Wander Lairson Costa
2022-05-16 21:06 ` Sathyanarayanan Kuppuswamy
2022-05-17 2:54 ` Kai Huang
2022-05-17 14:54 ` Sathyanarayanan Kuppuswamy
2022-05-23 2:52 ` Kai Huang
2022-05-23 3:41 ` Sathyanarayanan Kuppuswamy
2022-05-12 22:19 ` [PATCH v6 2/5] x86/tdx: Add TDX Guest event notify interrupt support Kuppuswamy Sathyanarayanan
2022-05-12 22:19 ` [PATCH v6 3/5] x86/mm: Make tdx_enc_status_changed() vmalloc address compatible Kuppuswamy Sathyanarayanan
2022-05-12 22:19 ` [PATCH v6 4/5] x86/mm: Add noalias variants of set_memory_*crypted() functions Kuppuswamy Sathyanarayanan
2022-05-12 22:19 ` [PATCH v6 5/5] x86/tdx: Add Quote generation support Kuppuswamy Sathyanarayanan
2022-05-13 18:58 ` Isaku Yamahata
2022-05-13 19:29 ` Sathyanarayanan Kuppuswamy
2022-05-17 2:58 ` Kai Huang
2022-05-17 20:08 ` Sathyanarayanan Kuppuswamy
2022-05-17 23:06 ` Kai Huang
2022-05-17 23:32 ` Sathyanarayanan Kuppuswamy [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=5e22f88f-fbef-0031-067f-1abd5cdaecb8@linux.intel.com \
--to=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=ak@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@gmail.com \
--cc=kai.huang@intel.com \
--cc=khalid.elmously@canonical.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.cerri@canonical.com \
--cc=mingo@redhat.com \
--cc=philip.cox@canonical.com \
--cc=tglx@linutronix.de \
--cc=tim.gardner@canonical.com \
--cc=tony.luck@intel.com \
--cc=wander@redhat.com \
--cc=x86@kernel.org \
/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