Re: [PATCH v5 4/6] virt: tdx-guest: Add a helper for the Quote buffer size

From: Peter Fang

Date: Tue Sep 29 2026 - 12:39:36 EST


On Mon, Sep 28, 2026 at 11:23:42AM -0700, Edgecombe, Rick P wrote:
> On Mon, 2026-09-28 at 03:08 -0700, Peter Fang wrote:
> > +static size_t get_quote_buf_size(void)
> > +{
> > + static size_t quote_buf_size;
> > +
> > + if (quote_buf_size)
> > + return quote_buf_size;
> > +
> > + quote_buf_size = PAGE_ALIGN(TDX_DEFAULT_QUOTE_SIZE);
> > +
> > + return quote_buf_size;
> > +}
> > +
>
> This makes no sense, at the point of this patch. It lazily sets a global to a
> constant value. Function scoped static is also weird.
>
> I think you are doing it this way so that later you can plug in the dynamic
> read. But later it still doesn't make sense why to lazily fetch it. Why not just
> read it in the tdx_guest_init() to a global? If the read fails, set to
> TDX_DEFAULT_QUOTE_SIZE. Then you are done. All callers of tdx_guest_init() just
> refer to the global. Why not?

After some offline discussion with Dave and Rick, the conclusion was
that KISS is better. Just read this metadata field each time and assume
the TDX module won't change it (because it shouldn't). That also gets
rid of the static variable.