Re: [PATCH v1 04/11] x86/x86: Add is_tdx_guest() interface

From: Kuppuswamy, Sathyanarayanan
Date: Thu Jun 10 2021 - 17:02:16 EST




On 6/10/21 12:59 PM, Borislav Petkov wrote:
On Tue, Jun 01, 2021 at 07:21:29PM -0700, Kuppuswamy Sathyanarayanan wrote:

+ if (memcmp("IntelTDX ", signature, 12))
+ return false;
+
+ return true;

As before,

return !memcmp(...

and then that function can return simply an int.

I will make the above change in next version.



+}
+
+bool is_tdx_guest(void)

If anything, this should be early_is_tdx_guest().

If this is the recommendation, I am fine with it. It is
only used by __in/__out macros in decompression code.


+{
+ if (tdx_guest < 0)
+ tdx_guest = native_cpuid_has_tdx_guest();
+
+ return !!tdx_guest;
+}
+

Applying: x86/x86: Add is_tdx_guest() interface
.git/rebase-apply/patch:58: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

I will fix it in next version.



diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c
index 5b14b72e41c5..5e70617e9877 100644
--- a/arch/x86/kernel/tdx.c
+++ b/arch/x86/kernel/tdx.c
@@ -19,6 +19,12 @@ static inline bool cpuid_has_tdx_guest(void)
return true;
}
+bool is_tdx_guest(void)
+{
+ return static_cpu_has(X86_FEATURE_TDX_GUEST);
+}
+EXPORT_SYMBOL_GPL(is_tdx_guest);

I don't like this is_tdx_guest() thing in kernel proper - what's wrong
with

prot_guest_has(PR_GUEST_TDX)

Is it alright to use vendor name in prot_guest_has() flag? I thought
we want to keep them generic. If this is acceptable, we can replace
is_tdx_guest() with prot_guest_has() calls. Currently it is not used
in many places.


?

Also, why is it exported, for kvm?

Yes. It is used in exported KVM functions.


Thx.


--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer