Re: [RFC PATCH v2 10/69] KVM: TDX: Print the name of SEAMCALL status code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/07/21 00:04, isaku.yamahata@xxxxxxxxx wrote:
From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>

SEAMCALL error code is not intuitive to tell what's wrong in the
SEAMCALL, print the error code name along with it.

Signed-off-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
---
  arch/x86/kvm/boot/seam/tdx_common.c | 21 +++++++++++++++++++++
  arch/x86/kvm/vmx/seamcall.h         |  7 +++++--
  2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/boot/seam/tdx_common.c b/arch/x86/kvm/boot/seam/tdx_common.c
index d803dbd11693..4fe352fb8586 100644
--- a/arch/x86/kvm/boot/seam/tdx_common.c
+++ b/arch/x86/kvm/boot/seam/tdx_common.c
@@ -9,6 +9,7 @@
  #include <asm/kvm_boot.h>
#include "vmx/tdx_arch.h"
+#include "vmx/tdx_errno.h"
/*
   * TDX system information returned by TDSYSINFO.
@@ -165,3 +166,23 @@ void tdx_keyid_free(int keyid)
  	ida_free(&tdx_keyid_pool, keyid);
  }
  EXPORT_SYMBOL_GPL(tdx_keyid_free);
+
+static struct tdx_seamcall_status {
+	u64 err_code;
+	const char *err_name;
+} tdx_seamcall_status_codes[] = {TDX_SEAMCALL_STATUS_CODES};
+
+const char *tdx_seamcall_error_name(u64 error_code)
+{
+	struct tdx_seamcall_status status;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tdx_seamcall_status_codes); i++) {
+		status = tdx_seamcall_status_codes[i];
+		if ((error_code & TDX_SEAMCALL_STATUS_MASK) == status.err_code)
+			return status.err_name;
+	}
+
+	return "Unknown SEAMCALL status code";
+}
+EXPORT_SYMBOL_GPL(tdx_seamcall_error_name);
diff --git a/arch/x86/kvm/vmx/seamcall.h b/arch/x86/kvm/vmx/seamcall.h
index 2c83ab46eeac..fbb18aea1720 100644
--- a/arch/x86/kvm/vmx/seamcall.h
+++ b/arch/x86/kvm/vmx/seamcall.h
@@ -37,11 +37,14 @@ static inline u64 _seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, u64 r10,
  	_seamcall(SEAMCALL_##op, (rcx), (rdx), (r8), (r9), (r10), (ex))
  #endif
+const char *tdx_seamcall_error_name(u64 error_code);
+
  static inline void __pr_seamcall_error(u64 op, const char *op_str,
  				       u64 err, struct tdx_ex_ret *ex)
  {
-	pr_err_ratelimited("SEAMCALL[%s] failed on cpu %d: 0x%llx\n",
-			   op_str, smp_processor_id(), (err));
+	pr_err_ratelimited("SEAMCALL[%s] failed on cpu %d: %s (0x%llx)\n",
+			   op_str, smp_processor_id(),
+			   tdx_seamcall_error_name(err), err);
  	if (ex)
  		pr_err_ratelimited(
  			"RCX 0x%llx, RDX 0x%llx, R8 0x%llx, R9 0x%llx, R10 0x%llx, R11 0x%llx\n",


You can squash it in the earlier patch that introduced __pr_seamcall_error.

Paolo




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux