[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f56b6e51-d2b6-49b3-a3e0-a9d9c90019c5@linux.intel.com>
Date: Wed, 20 Sep 2023 11:08:49 -0700
From: Kuppuswamy Sathyanarayanan
<sathyanarayanan.kuppuswamy@...ux.intel.com>
To: "Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Dan Williams <dan.j.williams@...el.com>,
"H . Peter Anvin" <hpa@...or.com>, Tony Luck <tony.luck@...el.com>,
Wander Lairson Costa <wander@...hat.com>,
Erdem Aktas <erdemaktas@...gle.com>,
Dionna Amalie Glaze <dionnaglaze@...gle.com>,
Qinkun Bao <qinkun@...che.org>,
Guorui Yu <GuoRui.Yu@...ux.alibaba.com>,
linux-coco@...ts.linux.dev, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] virt: tdx-guest: Add Quote generation support using
TSM_REPORTS
On 9/20/2023 10:52 AM, Kirill A . Shutemov wrote:
> On Wed, Sep 20, 2023 at 08:27:39AM -0700, Kuppuswamy Sathyanarayanan wrote:
>>
>>
>> On 9/20/2023 6:16 AM, Kirill A . Shutemov wrote:
>>>> +static u8 *tdx_report_new(const struct tsm_desc *desc, void *data, size_t *outblob_len)
>>>> +{
>>>> + struct tdx_quote_buf *quote_buf = quote_data;
>>>> + int ret;
>>>> + u8 *buf;
>>>> + u64 err;
>>>> +
>>>> + if (mutex_lock_interruptible("e_lock))
>>>> + return ERR_PTR(-EINTR);
>>>> +
>>>> + /*
>>>> + * If the previous request is timedout or interrupted, and the
>>>> + * Quote buf status is still in GET_QUOTE_IN_FLIGHT (owned by
>>>> + * VMM), don't permit any new request.
>>>> + */
>>>> + if (quote_buf->status == GET_QUOTE_IN_FLIGHT) {
>>>> + ret = -EBUSY;
>>>> + goto done;
>>>> + }
>>>> +
>>>> + if (desc->inblob_len != TDX_REPORTDATA_LEN) {
>>>> + ret = -EINVAL;
>>>> + goto done;
>>>> + }
>>>> +
>>>> + /* TDX attestation only supports default format request */
>>>> + if (desc->outblob_format != TSM_FORMAT_DEFAULT) {
>>>> + ret = -EINVAL;
>>>> + goto done;
>>>> + }
>>>> +
>>>> + u8 *reportdata __free(kfree) = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL);
>>> __free() is new to me. Good to know.
>>>
>>> But are we okay now with declaring variables in the middle of the
>>> function? Any reason we can't do at the top?
>>
>> Declaring variables at the top is no longer a hard requirement. The main reason
>> for declaring it here is to use __free cleanup function. If we use top
>> declaration, then we have free it manually.
>
> What's wrong with allocating it it there too?
My thinking is to allocate it when we really need it. We only need this memory if the
GetQuote hypercall is successful. We can also allocate it at the top and there is
nothing wrong with it, but it will not be used in failure cases. Since top declarations
are not a requirement, why allocate it early?
>
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Powered by blists - more mailing lists