Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp249352pxj; Tue, 1 Jun 2021 20:59:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLcoRuw19SNmb+g7feKRuVNw7SMlc/KFI7eojTUJ3vdpy+9nPxrDcoZvD9lqr0JvSejVW7 X-Received: by 2002:a02:ccd8:: with SMTP id k24mr16283597jaq.99.1622606374880; Tue, 01 Jun 2021 20:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622606374; cv=none; d=google.com; s=arc-20160816; b=K6PZaazdhr3GFvh3Hj+nMGuD0aHEdGhfK1gJ79dI4nHsePGgZuTRrL9FFGfMp5myPr y5wiR6Njzc5XElj9e5WaQzOxpxV+yTgUfuUPLQoXmF5jNMULU05ejjFFtFWLiXBSnJi2 g1Dy4zbuSKFJtmKJZt1Ar3F7ynT5tMK7w6WZSAW7nyKfvfq01KTouLaA1WGxsxKYNbww Lyrkyv3AEt3WHv8FwS7Rz9pGcqpOic1ED+Cfa6pDnopt5kAOSn4wZCW/6v9rs6L02M0M CnxSPh5ffh6BYnhb+7mv7pertc73ktrfuBp3iIjGSunLs7DaGLiNDtM+9GPZDj0EMtdA 1KoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=V11q4qvMmbDrgVMxxa2YGymQvHJkgmva6y9+9Ja46Fo=; b=Q9EEoOd3yWTSHShCMEMiOf2/SLlL079FC16zFfncVSYrGpCmMnbBrJi9KYF9tVS4tR 9EkuIPk8X0KguzPErp7Df5KeRH6E+lgved6GmDmShitSeQIpCOfKP9FYsYwnCKYWNh3Z B1aEabUhKrM0pzm3lAuwOKgIoUtnZx8jYXttTB/W7LZ1i2dBCySk37m0AIkIhn1EJA9g t1ddx7H8ueVSMd2DS/dNRafA35MuqJ48afjnpzgaFZxOc3dx+8tFw0fmhyMUpg6hdrf6 TWZrvKRfQBj2466E9spV3wxn6C4uLOCCbz6wpAxLk1B9STULNMnMIqj/O4HOaOqXlbwn sXEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p8si18209089ioh.104.2021.06.01.20.59.22; Tue, 01 Jun 2021 20:59:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230415AbhFBCXh (ORCPT + 99 others); Tue, 1 Jun 2021 22:23:37 -0400 Received: from mga06.intel.com ([134.134.136.31]:19493 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230097AbhFBCX2 (ORCPT ); Tue, 1 Jun 2021 22:23:28 -0400 IronPort-SDR: aNs2rQUtfI+g1o8+LkexlOxHfmY/QuRM/RVpYljux8Qo/2o9eDpk/ngMBG02nGMWrlmJkGUYVe 4kG5vDErjnVw== X-IronPort-AV: E=McAfee;i="6200,9189,10002"; a="264865317" X-IronPort-AV: E=Sophos;i="5.83,241,1616482800"; d="scan'208";a="264865317" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 19:21:46 -0700 IronPort-SDR: ToVWT6vDx4YyKauNpjttFL5XBtn0d4OANtr4TwCjnpWtVwOGuXbRkfzw3dZsy3jr4R+jEQw6F6 0qs9ZidAFaIA== X-IronPort-AV: E=Sophos;i="5.83,241,1616482800"; d="scan'208";a="633069191" Received: from mjdelaro-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.3.23]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 19:21:45 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH v1 03/11] x86/cpufeatures: Add TDX Guest CPU feature Date: Tue, 1 Jun 2021 19:21:28 -0700 Message-Id: <20210602022136.2186759-4-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add CPU feature detection for Trusted Domain Extensions support. TDX feature adds capabilities to keep guest register state and memory isolated from hypervisor. For TDX guest platforms, executing CPUID(0x21, 0) will return following values in EAX, EBX, ECX and EDX. EAX: Maximum sub-leaf number: 0 EBX/EDX/ECX: Vendor string: EBX = "Inte" EDX = "lTDX" ECX = " " So when above condition is true, set X86_FEATURE_TDX_GUEST feature cap bit Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andi Kleen Reviewed-by: Tony Luck --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/tdx.h | 20 ++++++++++++++++++++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/head64.c | 3 +++ arch/x86/kernel/tdx.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 arch/x86/include/asm/tdx.h create mode 100644 arch/x86/kernel/tdx.c diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index ac37830ae941..dddc3a27cc8a 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -238,6 +238,7 @@ #define X86_FEATURE_VMW_VMMCALL ( 8*32+19) /* "" VMware prefers VMMCALL hypercall instruction */ #define X86_FEATURE_PVUNLOCK ( 8*32+20) /* "" PV unlock function */ #define X86_FEATURE_VCPUPREEMPT ( 8*32+21) /* "" PV vcpu_is_preempted function */ +#define X86_FEATURE_TDX_GUEST ( 8*32+22) /* Trusted Domain Extensions Guest */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/ diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h new file mode 100644 index 000000000000..679500e807f3 --- /dev/null +++ b/arch/x86/include/asm/tdx.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2020 Intel Corporation */ +#ifndef _ASM_X86_TDX_H +#define _ASM_X86_TDX_H + +#define TDX_CPUID_LEAF_ID 0x21 + +#ifdef CONFIG_INTEL_TDX_GUEST + +#include + +void __init tdx_early_init(void); + +#else // !CONFIG_INTEL_TDX_GUEST + +static inline void tdx_early_init(void) { }; + +#endif /* CONFIG_INTEL_TDX_GUEST */ + +#endif /* _ASM_X86_TDX_H */ diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 0f66682ac02a..af09ce93a641 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -126,6 +126,7 @@ obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o obj-$(CONFIG_X86_PMEM_LEGACY_DEVICE) += pmem.o obj-$(CONFIG_JAILHOUSE_GUEST) += jailhouse.o +obj-$(CONFIG_INTEL_TDX_GUEST) += tdx.o obj-$(CONFIG_EISA) += eisa.o obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index de01903c3735..d1a4942ae160 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -40,6 +40,7 @@ #include #include #include +#include /* * Manage page tables very early on. @@ -491,6 +492,8 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data) kasan_early_init(); + tdx_early_init(); + idt_setup_early_handler(); copy_bootdata(__va(real_mode_data)); diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c new file mode 100644 index 000000000000..5b14b72e41c5 --- /dev/null +++ b/arch/x86/kernel/tdx.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2020 Intel Corporation */ + +#include + +static inline bool cpuid_has_tdx_guest(void) +{ + u32 eax, signature[3]; + + if (cpuid_eax(0) < TDX_CPUID_LEAF_ID) + return false; + + cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &signature[0], + &signature[1], &signature[2]); + + if (memcmp("IntelTDX ", signature, 12)) + return false; + + return true; +} + +void __init tdx_early_init(void) +{ + if (!cpuid_has_tdx_guest()) + return; + + setup_force_cpu_cap(X86_FEATURE_TDX_GUEST); + + pr_info("TDX guest is initialized\n"); +} -- 2.25.1