Re: [PATCH v4 1/3] x86/tdx: Add TDX Guest attestation interface driver

Sathyanarayanan Kuppuswamy
2022-04-28T18:19:04Z

On 4/28/22 11:04 AM, Dave Hansen wrote:
> On 4/28/22 10:56, Sathyanarayanan Kuppuswamy wrote:
>> On 4/28/22 10:45 AM, Wander Lairson Costa wrote:
>>> On Fri, Apr 22, 2022 at 04:34:16PM -0700, Kuppuswamy Sathyanarayanan
>>> wrote:
>>>> +static long tdx_get_tdreport(void __user *argp)
>>>> +{
>>>> +    void *report_buf = NULL, *tdreport_buf = NULL;
>>>> +    long ret = 0, err;
>>>> +
>>>> +    /* Allocate space for report data */
>>>> +    report_buf = kmalloc(TDX_REPORT_DATA_LEN, GFP_KERNEL);
>>>> +    if (!report_buf)
>>>> +        return -ENOMEM;
>>>> +
>>>> +    /*
>>>> +     * Allocate space for TDREPORT buffer (1024-byte aligned).
>>>> +     * Full page alignment is more than enough.
>>>> +     */
>>>> +    tdreport_buf = (void *)get_zeroed_page(GFP_KERNEL);
>>>
>>> Maybe we should add BUILD_BUG_ON(TDX_TDREPORT_LEN > PAGE_SIZE)
>>
>> Currently, it is a constant value < PAGE_SIZE. But I can add the
>> BUILD_BUG_ON check for it.
>
> That's kinda silly. If it might ever be bigger than a page, you just do:
>
> tdreport_buf = alloc_pages();
>
> But, seriously, TDX_TDREPORT_LEN is part of the ABI and can't change.
> kmalloc() would work too since TDX_TDREPORT_LEN is a power of 2.

Agree. For our current requirement, kmalloc will just work fine. If the
length changes in the future, I can start using alloc_pages.

>

--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer