[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <63e9754ec059190cd1734650b8968952cbe00ee9.camel@intel.com>
Date: Wed, 15 Nov 2023 10:41:46 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "isaku.yamahata@...ux.intel.com" <isaku.yamahata@...ux.intel.com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"sathyanarayanan.kuppuswamy@...ux.intel.com"
<sathyanarayanan.kuppuswamy@...ux.intel.com>,
"Hansen, Dave" <dave.hansen@...el.com>,
"david@...hat.com" <david@...hat.com>,
"bagasdotme@...il.com" <bagasdotme@...il.com>,
"Luck, Tony" <tony.luck@...el.com>,
"ak@...ux.intel.com" <ak@...ux.intel.com>,
"kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
"seanjc@...gle.com" <seanjc@...gle.com>,
"mingo@...hat.com" <mingo@...hat.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"Yamahata, Isaku" <isaku.yamahata@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"nik.borisov@...e.com" <nik.borisov@...e.com>,
"hpa@...or.com" <hpa@...or.com>,
"peterz@...radead.org" <peterz@...radead.org>,
"Shahar, Sagi" <sagis@...gle.com>,
"imammedo@...hat.com" <imammedo@...hat.com>,
"bp@...en8.de" <bp@...en8.de>, "Gao, Chao" <chao.gao@...el.com>,
"rafael@...nel.org" <rafael@...nel.org>,
"Brown, Len" <len.brown@...el.com>,
"Huang, Ying" <ying.huang@...el.com>,
"Williams, Dan J" <dan.j.williams@...el.com>,
"x86@...nel.org" <x86@...nel.org>
Subject: Re: [PATCH v15 05/23] x86/virt/tdx: Handle SEAMCALL no entropy error
in common code
> > +#include <asm/archrandom.h>
> > +
> > +typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args *args);
> > +
> > +static inline u64 sc_retry(sc_func_t func, u64 fn,
> > + struct tdx_module_args *args)
> > +{
> > + int retry = RDRAND_RETRY_LOOPS;
> > + u64 ret;
> > +
> > + do {
> > + ret = func(fn, args);
> > + } while (ret == TDX_RND_NO_ENTROPY && --retry);
>
> This loop assumes that args isn't touched when TDX_RND_NO_ENTRYPOY is returned.
> It's not true. TDH.SYS.INIT() and TDH.SYS.LP.INIT() clear RCX, RDX, etc on
> error including TDX_RND_NO_ENTRY. Because TDH.SYS.INIT() takes RCX as input,
> this wrapper doesn't work. TDH.SYS.LP.INIT() doesn't use RCX, RDX ... as
> input. So it doesn't matter.
>
> Other SEAMCALLs doesn't touch registers on the no entropy error.
> TDH.EXPORTS.STATE.IMMUTABLE(), TDH.IMPORTS.STATE.IMMUTABLE(), TDH.MNG.ADDCX(),
> and TDX.MNG.CREATE(). TDH.SYS.INIT() is an exception.
If I am reading the spec (TDX module 1.5 ABI) correctly the TDH.SYS.INIT doesn't
return TDX_RND_NO_ENTROPY. TDH.SYS.LP.INIT indeed can return NO_ENTROPY but as
you said it doesn't take any register as input. So technically the code works
fine. (Even the TDH.SYS.INIT can return NO_ENTROPY the code still works fine
because the RCX must be 0 for TDH.SYS.INIT.)
Also, I can hardly think out of any reason why TDX module needs to clobber input
registers in case of NO_ENTROPY for *ANY* SEAMCALL. But despite that, I am not
opposing the idea that it *MIGHT* be better to "not assume" NO_ENTROPY will
never clobber registers either, e.g., for the sake of future extendibility. In
this case, the below diff should address:
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index a621721f63dd..962a7a6be721 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -97,12 +97,23 @@ typedef u64 (*sc_func_t)(u64 fn, struct tdx_module_args
*args);
static inline u64 sc_retry(sc_func_t func, u64 fn,
struct tdx_module_args *args)
{
+ struct tdx_module_args _args = *args;
int retry = RDRAND_RETRY_LOOPS;
u64 ret;
- do {
- ret = func(fn, args);
- } while (ret == TDX_RND_NO_ENTROPY && --retry);
+again:
+ ret = func(fn, args);
+ if (ret == TDX_RND_NO_ENTROPY && --retry) {
+ /*
+ * Do not assume TDX module will never clobber the input
+ * registers when any SEAMCALL fails with out of entropy.
+ * In this case the original input registers in @args
+ * are clobbered. Always restore the input registers
+ * before retrying the SEAMCALL.
+ */
+ *args = _args;
+ goto again;
+ }
return ret;
}
The downside is we will have an additional memory copy of 'struct
tdx_module_args' for each SEAMCALL, but I don't believe this will have any
difference in practice.
Or, we can go and ask TDX module guys to promise no input registers will be
clobbered in case of NO_ENTROPY.
Hi Dave,
Do you have any opinion?
Powered by blists - more mailing lists