lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <abec59a8e732ecd815723a8f8cee1378ce4d1618.camel@intel.com>
Date: Tue, 19 Dec 2023 10:41:55 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, "Yamahata,
 Isaku" <isaku.yamahata@...el.com>
CC: "Zhang, Tina" <tina.zhang@...el.com>, "seanjc@...gle.com"
	<seanjc@...gle.com>, "Yuan, Hang" <hang.yuan@...el.com>, "Chen, Bo2"
	<chen.bo@...el.com>, "sagis@...gle.com" <sagis@...gle.com>,
	"isaku.yamahata@...il.com" <isaku.yamahata@...il.com>, "Aktas, Erdem"
	<erdemaktas@...gle.com>, "pbonzini@...hat.com" <pbonzini@...hat.com>,
	"dmatlack@...gle.com" <dmatlack@...gle.com>, "zhi.wang.linux@...il.com"
	<zhi.wang.linux@...il.com>
Subject: Re: [PATCH v17 012/116] KVM: TDX: Retry SEAMCALL on the lack of
 entropy error

On Tue, 2023-11-07 at 06:55 -0800, isaku.yamahata@...el.com wrote:
> From: Isaku Yamahata <isaku.yamahata@...el.com>
> 
> Some SEAMCALL may return TDX_RND_NO_ENTROPY error when the entropy is
> lacking.  Retry SEAMCALL on the error following rdrand_long() to retry
> RDRAND_RETRY_LOOPS times.
> 
> Signed-off-by: Isaku Yamahata <isaku.yamahata@...el.com>
> ---
>  arch/x86/kvm/vmx/tdx_errno.h |  1 +
>  arch/x86/kvm/vmx/tdx_ops.h   | 40 +++++++++++++++++++++---------------
>  2 files changed, 24 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/tdx_errno.h b/arch/x86/kvm/vmx/tdx_errno.h
> index 7f96696b8e7c..bb093e292fef 100644
> --- a/arch/x86/kvm/vmx/tdx_errno.h
> +++ b/arch/x86/kvm/vmx/tdx_errno.h
> @@ -14,6 +14,7 @@
>  #define TDX_OPERAND_INVALID			0xC000010000000000ULL
>  #define TDX_OPERAND_BUSY			0x8000020000000000ULL
>  #define TDX_PREVIOUS_TLB_EPOCH_BUSY		0x8000020100000000ULL
> +#define TDX_RND_NO_ENTROPY			0x8000020300000000ULL
>  #define TDX_VCPU_NOT_ASSOCIATED			0x8000070200000000ULL
>  #define TDX_KEY_GENERATION_FAILED		0x8000080000000000ULL
>  #define TDX_KEY_STATE_INCORRECT			0xC000081100000000ULL
> diff --git a/arch/x86/kvm/vmx/tdx_ops.h b/arch/x86/kvm/vmx/tdx_ops.h
> index 12fd6b8d49e0..a55977626ae3 100644
> --- a/arch/x86/kvm/vmx/tdx_ops.h
> +++ b/arch/x86/kvm/vmx/tdx_ops.h
> @@ -6,6 +6,7 @@
>  
>  #include <linux/compiler.h>
>  
> +#include <asm/archrandom.h>
>  #include <asm/cacheflush.h>
>  #include <asm/asm.h>
>  #include <asm/kvm_host.h>
> @@ -17,25 +18,30 @@
>  static inline u64 tdx_seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9,
>  			       struct tdx_module_args *out)
>  {
> +	int retry;
>  	u64 ret;
>  
> -	if (out) {
> -		*out = (struct tdx_module_args) {
> -			.rcx = rcx,
> -			.rdx = rdx,
> -			.r8 = r8,
> -			.r9 = r9,
> -		};
> -		ret = __seamcall_ret(op, out);
> -	} else {
> -		struct tdx_module_args args = {
> -			.rcx = rcx,
> -			.rdx = rdx,
> -			.r8 = r8,
> -			.r9 = r9,
> -		};
> -		ret = __seamcall(op, &args);
> -	}
> +	/* Mimic the existing rdrand_long() to retry RDRAND_RETRY_LOOPS times. */
> +	retry = RDRAND_RETRY_LOOPS;
> +	do {
> +		if (out) {
> +			*out = (struct tdx_module_args) {
> +				.rcx = rcx,
> +				.rdx = rdx,
> +				.r8 = r8,
> +				.r9 = r9,
> +			};
> +			ret = __seamcall_ret(op, out);
> +		} else {
> +			struct tdx_module_args args = {
> +				.rcx = rcx,
> +				.rdx = rdx,
> +				.r8 = r8,
> +				.r9 = r9,
> +			};
> +			ret = __seamcall(op, &args);
> +		}
> +	} while (unlikely(ret == TDX_RND_NO_ENTROPY) && --retry);
>  	if (unlikely(ret == TDX_SEAMCALL_UD)) {
>  		/*
>  		 * SEAMCALLs fail with TDX_SEAMCALL_UD returned when VMX is off.

Why we cannot use seamcall*() variants directly which already handles running
out of entropy error?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ