Re: [PATCH v10 015/108] x86/cpu: Add helper functions to allocate/free TDX private host key id
From: Isaku Yamahata
Date: Thu Nov 17 2022 - 12:35:01 EST
On Tue, Nov 08, 2022 at 09:16:57AM +0000,
"Huang, Kai" <kai.huang@xxxxxxxxx> wrote:
> On Sat, 2022-10-29 at 23:22 -0700, isaku.yamahata@xxxxxxxxx wrote:
> > From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
> >
> > TDX private host key id is assigned to guest TD. The memory controller
> > encrypts guest TD memory with the assigned TDX private host key id (HIKD).
> ^
> HKID.
>
> And since you already mentioned in the first sentence, you can put (HKID) part
> there. And I think you can just use HKID in the rest places to save some typing
> as this is the purpose of using (HKID) I suppose.
>
> [...]
>
> >
> > +/* TDX KeyID pool */
> > +static DEFINE_IDA(tdx_keyid_pool);
> > +
> > +int tdx_keyid_alloc(void)
> > +{
> > + if (WARN_ON_ONCE(!tdx_keyid_start || !tdx_keyid_num))
> > + return -EINVAL;
> > +
> > + /* The first keyID is reserved for the global key. */
> > + return ida_alloc_range(&tdx_keyid_pool, tdx_keyid_start + 1,
> > + tdx_keyid_start + tdx_keyid_num - 1,
> > + GFP_KERNEL);
> > +}
> > +EXPORT_SYMBOL_GPL(tdx_keyid_alloc);
> > +
> > +void tdx_keyid_free(int keyid)
> > +{
> > + /* keyid = 0 is reserved. */
> > + if (!keyid || keyid <= 0)
> > + return;
>
> Double check of keyid == 0.
>
> I think you can just use:
>
> if (keyid <= tdx_keyid_start)
> return;
>
> And/or add a WARN() as it's a bug if above happens.
Ok. Will fix it with WARN().
--
Isaku Yamahata <isaku.yamahata@xxxxxxxxx>