[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <328cc0e7-89e7-a1b2-f798-fe758c2c1f4e@linux.intel.com>
Date: Wed, 6 Oct 2021 08:43:48 -0700
From: "Kuppuswamy, Sathyanarayanan"
<sathyanarayanan.kuppuswamy@...ux.intel.com>
To: Borislav Petkov <bp@...en8.de>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, x86@...nel.org,
Paolo Bonzini <pbonzini@...hat.com>,
David Hildenbrand <david@...hat.com>,
Andrea Arcangeli <aarcange@...hat.com>,
Josh Poimboeuf <jpoimboe@...hat.com>,
Juergen Gross <jgross@...e.com>, Deep Shah <sdeep@...are.com>,
VMware Inc <pv-drivers@...are.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, Peter H Anvin <hpa@...or.com>,
Dave Hansen <dave.hansen@...el.com>,
Tony Luck <tony.luck@...el.com>,
Dan Williams <dan.j.williams@...el.com>,
Andi Kleen <ak@...ux.intel.com>,
Kirill Shutemov <kirill.shutemov@...ux.intel.com>,
Sean Christopherson <seanjc@...gle.com>,
Kuppuswamy Sathyanarayanan <knsathya@...nel.org>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v8 03/11] x86/cpufeatures: Add TDX Guest CPU feature
On 10/6/21 8:26 AM, Borislav Petkov wrote:
> On Mon, Oct 04, 2021 at 07:51:57PM -0700, Kuppuswamy Sathyanarayanan wrote:
>> diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c
>> new file mode 100644
>> index 000000000000..ad3ff5925153
>> --- /dev/null
>> +++ b/arch/x86/kernel/tdx.c
>> @@ -0,0 +1,40 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (C) 2020 Intel Corporation */
>> +
>> +#undef pr_fmt
>> +#define pr_fmt(fmt) "tdx: " fmt
>> +
>> +#include <asm/tdx.h>
>> +
>> +/*
>> + * 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;
>> +
>> +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 I meant was this (untested of course).
>
> is_tdx_guest() is the accessor external code queries and you cache the
> detected value in tdx_guest so that the one after the first one is
> cheap.
Yes. But, Joerg Roedel in his review recommended using variable
similar to sme_me_mask to avoid function call in Intel platform in
cc_platform_has().
"
This causes a function call on every Intel machine this code runs. is
there an easier to check whether TDX is enabled, like the sme_me_mask
check on AMD?
"
That's why I have introduced is_tdx_guest global variable in this
version.
>
> /*
> * 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.
> *
> * States whether the kernel is running as a TDX guest.
> */
> static int tdx_guest __ro_after_init = -1;
>
> bool is_tdx_guest(void)
> {
> u32 eax, sig[3];
>
> if (tdx_guest >= 0)
> return tdx_guest;
>
> if (cpuid_eax(0) < TDX_CPUID_LEAF_ID) {
> tdx_guest = 0;
> return false;
> }
>
> cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &sig[0], &sig[2], &sig[1]);
>
> tdx_guest = !memcmp("IntelTDX ", sig, 12);
>
> return tdx_guest;
> }
>
> void __init tdx_early_init(void)
> {
> if (!is_tdx_guest())
> return;
>
> setup_force_cpu_cap(X86_FEATURE_TDX_GUEST);
>
> pr_info("Guest initialized\n");
> }
>
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Powered by blists - more mailing lists