Re: [PATCH v4 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size

From: Edgecombe, Rick P

Date: Tue Sep 22 2026 - 15:49:53 EST


On Tue, 2026-09-22 at 07:59 -0700, Dave Hansen wrote:
> On 9/22/26 03:05, Xiaoyao Li wrote:
> > > @@ -417,7 +416,8 @@ static int __init tdx_guest_init(void)
> > >    if (ret)
> > >    goto deinit_mr;
> > >  
> > > - quote_data = alloc_quote_buf();
> > > + quote_data_len = PAGE_ALIGN(GET_QUOTE_BUF_SIZE);
> > > + quote_data = alloc_quote_buf(quote_data_len);
> > since quote_data_len is a global variable, it looks no need to pass it around.
> >
> > Same for free_quote_buf()
>
> It's not the end of the world, but... global variable == bad. Plus,
> handing global variables around can actually make the code flow more clear.

We were just talking about a similar pattern on the extension init patches. The
host side uses a lot of global init from the metadata:
https://lore.kernel.org/kvm/9cbc8edd0a2f21e69521a7f2dd9f1a1114f2362d.camel@xxxxxxxxx/

There we have a seamcall wrapper being factored out, and it will refer to some
metadata which is global already. But the existing code also refers to the
selected "global key id" (different meaning of global), which is picked during
TDX initialization and stored as a global variable. This "global key id" is
passed along as a parameter into the spot where the seamcall wrapper is being
factored out.

I was suggesting to make the new seamcall wrapper consistent in how it gets this
data by referring to the global definition for the global key id instead of a
parameter. Seems like it is against this feedback, can you give a quick take on
that case too? I just think mixing global references and global values passed as
arguments it too weird. Should we switch to passing everything as args even when
we need to plumb it through several layers?