[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dfb59553-2777-15ed-d523-6a7cc5b68e53@redhat.com>
Date: Mon, 19 Jun 2023 15:00:11 +0200
From: David Hildenbrand <david@...hat.com>
To: Kai Huang <kai.huang@...el.com>, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org
Cc: linux-mm@...ck.org, dave.hansen@...el.com,
kirill.shutemov@...ux.intel.com, tony.luck@...el.com,
peterz@...radead.org, tglx@...utronix.de, seanjc@...gle.com,
pbonzini@...hat.com, dan.j.williams@...el.com,
rafael.j.wysocki@...el.com, ying.huang@...el.com,
reinette.chatre@...el.com, len.brown@...el.com, ak@...ux.intel.com,
isaku.yamahata@...el.com, chao.gao@...el.com,
sathyanarayanan.kuppuswamy@...ux.intel.com, bagasdotme@...il.com,
sagis@...gle.com, imammedo@...hat.com
Subject: Re: [PATCH v11 06/20] x86/virt/tdx: Handle SEAMCALL running out of
entropy error
On 04.06.23 16:27, Kai Huang wrote:
> Certain SEAMCALL leaf functions may return error due to running out of
> entropy, in which case the SEAMCALL should be retried as suggested by
> the TDX spec.
>
> Handle this case in SEAMCALL common function. Mimic the existing
> rdrand_long() to retry RDRAND_RETRY_LOOPS times.
>
> Signed-off-by: Kai Huang <kai.huang@...el.com>
> ---
>
> v10 -> v11:
> - New patch
>
> ---
> arch/x86/virt/vmx/tdx/tdx.c | 15 ++++++++++++++-
> arch/x86/virt/vmx/tdx/tdx.h | 17 +++++++++++++++++
> 2 files changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> index e82713dd5d54..e62e978eba1b 100644
> --- a/arch/x86/virt/vmx/tdx/tdx.c
> +++ b/arch/x86/virt/vmx/tdx/tdx.c
> @@ -15,6 +15,7 @@
> #include <linux/smp.h>
> #include <asm/msr-index.h>
> #include <asm/msr.h>
> +#include <asm/archrandom.h>
> #include <asm/tdx.h>
> #include "tdx.h"
>
> @@ -33,12 +34,24 @@ static int __always_unused seamcall(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
> struct tdx_module_output *out)
> {
> int cpu, ret = 0;
> + int retry;
> u64 sret;
>
> /* Need a stable CPU id for printing error message */
> cpu = get_cpu();
>
> - sret = __seamcall(fn, rcx, rdx, r8, r9, out);
> + /*
> + * Certain SEAMCALL leaf functions may return error due to
> + * running out of entropy, in which case the SEAMCALL should
> + * be retried. Handle this in SEAMCALL common function.
> + *
> + * Mimic the existing rdrand_long() to retry
> + * RDRAND_RETRY_LOOPS times.
> + */
> + retry = RDRAND_RETRY_LOOPS;
Nit: I'd just do a "int retry = RDRAND_RETRY_LOOPS" and simplify this
comment to "Mimic rdrand_long() retry behavior."
> + do {
> + sret = __seamcall(fn, rcx, rdx, r8, r9, out);
> + } while (sret == TDX_RND_NO_ENTROPY && --retry);
>
> /* Save SEAMCALL return code if the caller wants it */
> if (seamcall_ret)
> diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
> index 48ad1a1ba737..55dbb1b8c971 100644
> --- a/arch/x86/virt/vmx/tdx/tdx.h
> +++ b/arch/x86/virt/vmx/tdx/tdx.h
> @@ -4,6 +4,23 @@
>
> #include <linux/types.h>
>
> +/*
> + * This file contains both macros and data structures defined by the TDX
> + * architecture and Linux defined software data structures and functions.
> + * The two should not be mixed together for better readability. The
> + * architectural definitions come first.
> + */
> +
> +/*
> + * TDX SEAMCALL error codes
> + */
> +#define TDX_RND_NO_ENTROPY 0x8000020300000000ULL
> +
> +/*
> + * Do not put any hardware-defined TDX structure representations below
> + * this comment!
> + */
> +
> struct tdx_module_output;
> u64 __seamcall(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
> struct tdx_module_output *out);
In general, LGTM
Reviewed-by: David Hildenbrand <david@...hat.com>
--
Cheers,
David / dhildenb
Powered by blists - more mailing lists