On Mon, Oct 04, 2021 at 07:51:57PM -0700, Kuppuswamy Sathyanarayanan wrote:
@@ -495,6 +496,13 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
copy_bootdata(__va(real_mode_data));
+ /*
+ * tdx_early_init() has dependency on command line parameters.
+ * So the order of calling it should be after copy_bootdata()
+ * (in which command line parameter is initialized).
+ */
+ tdx_early_init();
Which cmdline parameters are those?
+/*
+ * Allocate it in the data region to avoid zeroing it during
+ * BSS initialization. It is mainly used in cc_platform_has()
+ * call during early boot call.
+ */
+u64 __section(".data") is_tdx_guest = 0;
Or you could just give it a -1 value here to avoid the section
annotation. Not sure why it needs 64 bits, any reason it can't just be
bool?
+
+static void __init is_tdx_guest_init(void)
+{
+ u32 eax, sig[3];
+
+ if (cpuid_eax(0) < TDX_CPUID_LEAF_ID) {
+ is_tdx_guest = 0;
+ return;
+ }
+
+ cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &sig[0], &sig[2], &sig[1]);
+
+ is_tdx_guest = !memcmp("IntelTDX ", sig, 12);
+}
+
+void __init tdx_early_init(void)
+{
+ is_tdx_guest_init();
+
+ if (!is_tdx_guest)
+ return;
+
+ setup_force_cpu_cap(X86_FEATURE_TDX_GUEST);
+
+ pr_info("Guest initialized\n");
+}
What's the point of having both 'is_tdx_guest' and
X86_FEATURE_TDX_GUEST? Are they not redundant?