Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp674750pxb; Wed, 15 Sep 2021 10:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+Tf4OMRWRVmOq7WTWQi0U9jyB4UFbN+5jCsB+qZ+UKtLc7Lofgg4O38s39Po8VJUIXOHh X-Received: by 2002:a5e:9603:: with SMTP id a3mr971556ioq.158.1631726829423; Wed, 15 Sep 2021 10:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631726829; cv=none; d=google.com; s=arc-20160816; b=RX0VCfGV4ud+Oq5V6vpsEIL1JjxQ1qtSry0rHZKG6ZE/Jsj765ZLajHbutdnolAWCP IhPlnxvtv/6zYxs7F+cOfqdYDNhKyzNPeU1oxKOjrAgzLFxUMPvnvGL/4X/C00/w+dF2 3I0/m5fnfQAyq568MUActy8BUU0h9zZKoozE6JXTdQfGY7zgmv9lfg6uFkse9v9DSgq+ B4uRSjcliCZVwsl3Hyxun4OW9qBn3WmB7NlFPcbrxOnWMZzKyTwlAdxNUp+VO+RhRhd0 nu9QxuQNTnxGOxk1IYXacGPP/s7+7KjEthFTa6qL9qD6bVGPPS65DLyvpRxyLlFx7b4A A+ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PsBjzA7RBIk+R4Kf/hmJ3omOu2xdUULYIzFNb0Of6TM=; b=P9Ezy3UPofQKzmti2DRXmAJ3XknsHSTX77i9oQEdbbsmCnRQJqT9+yuw9pkJd7D2wS K6LxZnRjz5/I54YzRCyAjOG+MwSgUZ8lBhJK7Nj75wBcskY1N2gK01d2t55dozCSloyb ybrQUqLAOKdHoJTiQ8Rq+ZeLll6kYAnVRVdfxIE08R4yYRCLpKMYhhWMKTo69NdDN51P ENSAn/raSeKBLHu8NhvzL29G+hIrHRE19ohfpzKMlI8SQUK5hPUoGhtEHyyGAEBait0p QuDe2OK2axW5BdLyX66zSEP7MrjK2UKObWnsBBeDhe5tSfRbE/whB/+/DmL08k9vxUYX jb/g== 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 h15si528316ili.51.2021.09.15.10.26.57; Wed, 15 Sep 2021 10:27:09 -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 S230180AbhIOR1c (ORCPT + 99 others); Wed, 15 Sep 2021 13:27:32 -0400 Received: from mga17.intel.com ([192.55.52.151]:49715 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhIOR1b (ORCPT ); Wed, 15 Sep 2021 13:27:31 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10108"; a="202548433" X-IronPort-AV: E=Sophos;i="5.85,296,1624345200"; d="scan'208";a="202548433" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 10:26:11 -0700 X-IronPort-AV: E=Sophos;i="5.85,296,1624345200"; d="scan'208";a="434215304" Received: from rlad-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.212.118.184]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 10:26:08 -0700 Subject: Re: [PATCH v3 0/8] Implement generic cc_platform_has() helper function To: Borislav Petkov , Tom Lendacky Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-graphics-maintainer@vmware.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, Brijesh Singh , Joerg Roedel , Andi Kleen , Tianyu Lan , Christoph Hellwig , Andy Lutomirski , Ard Biesheuvel , Baoquan He , Benjamin Herrenschmidt , Christian Borntraeger , Daniel Vetter , Dave Hansen , Dave Young , David Airlie , Heiko Carstens , Ingo Molnar , Maarten Lankhorst , Maxime Ripard , Michael Ellerman , Paul Mackerras , Peter Zijlstra , Thomas Gleixner , Thomas Zimmermann , Vasily Gorbik , Will Deacon References: From: "Kuppuswamy, Sathyanarayanan" Message-ID: Date: Wed, 15 Sep 2021 10:26:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/15/21 9:46 AM, Borislav Petkov wrote: > Sathya, > > if you want to prepare the Intel variant intel_cc_platform_has() ontop > of those and send it to me, that would be good because then I can > integrate it all in one branch which can be used to base future work > ontop. I have a Intel variant patch (please check following patch). But it includes TDX changes as well. Shall I move TDX changes to different patch and just create a separate patch for adding intel_cc_platform_has()? commit fc5f98a0ed94629d903827c5b44ee9295f835831 Author: Kuppuswamy Sathyanarayanan Date: Wed May 12 11:35:13 2021 -0700 x86/tdx: Add confidential guest support for TDX guest TDX architecture provides a way for VM guests to be highly secure and isolated (from untrusted VMM). To achieve this requirement, any data coming from VMM cannot be completely trusted. TDX guest fixes this issue by hardening the IO drivers against the attack from the VMM. So, when adding hardening fixes to the generic drivers, to protect custom fixes use cc_platform_has() API. Also add TDX guest support to cc_platform_has() API to protect the TDX specific fixes. Signed-off-by: Kuppuswamy Sathyanarayanan diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index a5b14de03458..2e78358923a1 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -871,6 +871,7 @@ config INTEL_TDX_GUEST depends on SECURITY select X86_X2APIC select SECURITY_LOCKDOWN_LSM + select ARCH_HAS_CC_PLATFORM help Provide support for running in a trusted domain on Intel processors equipped with Trusted Domain eXtensions. TDX is a new Intel diff --git a/arch/x86/include/asm/intel_cc_platform.h b/arch/x86/include/asm/intel_cc_platform.h new file mode 100644 index 000000000000..472c3174beac --- /dev/null +++ b/arch/x86/include/asm/intel_cc_platform.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2021 Intel Corporation */ +#ifndef _ASM_X86_INTEL_CC_PLATFORM_H +#define _ASM_X86_INTEL_CC_PLATFORM_H + +#if defined(CONFIG_CPU_SUP_INTEL) && defined(CONFIG_ARCH_HAS_CC_PLATFORM) +bool intel_cc_platform_has(unsigned int flag); +#else +static inline bool intel_cc_platform_has(unsigned int flag) { return false; } +#endif + +#endif /* _ASM_X86_INTEL_CC_PLATFORM_H */ + diff --git a/arch/x86/kernel/cc_platform.c b/arch/x86/kernel/cc_platform.c index 3c9bacd3c3f3..e83bc2f48efe 100644 --- a/arch/x86/kernel/cc_platform.c +++ b/arch/x86/kernel/cc_platform.c @@ -10,11 +10,16 @@ #include #include #include +#include + +#include bool cc_platform_has(enum cc_attr attr) { if (sme_me_mask) return amd_cc_platform_has(attr); + else if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) + return intel_cc_platform_has(attr); return false; } diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 8321c43554a1..ab486a3b1eb0 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,21 @@ static u64 msr_test_ctrl_cache __ro_after_init; */ static bool cpu_model_supports_sld __ro_after_init; +#ifdef CONFIG_ARCH_HAS_CC_PLATFORM +bool intel_cc_platform_has(enum cc_attr attr) +{ + switch (attr) { + case CC_ATTR_GUEST_TDX: + return cpu_feature_enabled(X86_FEATURE_TDX_GUEST); + default: + return false; + } + + return false; +} +EXPORT_SYMBOL_GPL(intel_cc_platform_has); +#endif + /* * Processors which have self-snooping capability can handle conflicting * memory type across CPUs by snooping its own cache. However, there exists diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index 253f3ea66cd8..e38430e6e396 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -61,6 +61,15 @@ enum cc_attr { * Examples include SEV-ES. */ CC_ATTR_GUEST_STATE_ENCRYPT, + + /** + * @CC_ATTR_GUEST_TDX: Trusted Domain Extension Support + * + * The platform/OS is running as a TDX guest/virtual machine. + * + * Examples include SEV-ES. + */ + CC_ATTR_GUEST_TDX, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM -- Sathyanarayanan Kuppuswamy Linux Kernel Developer