Re: [PATCH v4 1/4] x86/tdx: Add helper to query maximum TD Quote size
From: Dave Hansen
Date: Mon Sep 21 2026 - 18:15:04 EST
On 9/15/26 02:26, Peter Fang wrote:
> +/**
> + * tdx_get_max_quote_size() - Get the maximum TD Quote size
> + *
> + * Read the maximum size of a TD Quote from a 4-byte TD metadata field. The TDX
> + * guest driver uses it to size the buffer for Quotes. Older TDX modules do not
> + * support this field and return an error.
> + *
> + * The reported size covers every Quote type supported by the platform,
> + * including SGX-based Quotes.
> + *
> + * A runtime TDX module update does not change the reported size.
> + *
> + * Return: Maximum Quote size in bytes on success, or 0 on failure.
> + */
> +u32 tdx_get_max_quote_size(void)
> +{
> + u64 val, ret;
> +
> + ret = tdg_vm_rd(TDCS_QUOTE_MAX_SIZE, &val);
> +
> + return ret ? 0 : (u32)val;
> +}
> +EXPORT_SYMBOL_GPL(tdx_get_max_quote_size);
This is an awful lot of stuff I'm not fond of like packed in very few
lines of code.
1. An unscoped, unmentioned, uncommented export
2. Ternary form
3. Casting
4. A kerneldoc comment that is quite verbose and restates the TDX specs
5. kerneldocs for something that's not a widely-used API
6. Comments that say the same thing as the function name
7. Multiple variables declared on one line
Rather than start trying to cram failure codes into the return code,
just do:
/*
* Ask the TDX module what the largest possible quote might be.
*/
int tdx_get_max_quote_size(u64 *max_quote_size)
{
int ret = tdg_vm_rd(TDCS_QUOTE_MAX_SIZE, max_quote_size);
/* Old modules do not support this. Tell the caller. */
if (ret)
return -EINVAL;
return 0;
}
That's the normal pattern. Or, heck, just return a long and return
-errnos in there.