Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp289553pxb; Thu, 9 Sep 2021 00:36:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9DRWB3VE34z2o2lGZiF2B9+ZYjNBE1RExjW1VSfqle2AVg0GjVyZVV49YaYql/lXyxUmD X-Received: by 2002:a6b:b4ce:: with SMTP id d197mr1519689iof.69.1631173007822; Thu, 09 Sep 2021 00:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631173007; cv=none; d=google.com; s=arc-20160816; b=03kp97k3H+14K/T4ZX4VGjQHXxF9iVGX3NsYknGBdV8ywPAB8GYF2Q+hRcJCcdtAuZ 6bCBYTD77oD0resq3LK15e20mXa1rCQRKLe7LTjocccITLmIFjspn/fPFTHbDpH/PGm0 UfJadH0qBq+1faKCI58OGho7g07UblwiCVE3F9FiWRpXidiy8fGp7NtZa/7i3+5TcdWE dKJzEAvVYCXbi0aqMux6s+4yO7AwoXyck69ZOLSE32V52iDoDhgbeb6AogY0DsI0gktf 3HGp8H2kXwnvUvCCT9peZoNRrUXSh/0aEVgdHRM6njUpbG0RDGFGfnsjQ51DxgixyEYE EJeA== 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=/WukMSLEGCNcuhHvVFyz+9X/AcKkwDrSw2u8rz1xWJY=; b=MjG7mEsEgsyntJ0KiXFV572CQeuJkE4LmhCwA8jdWZS2RL/Lb3nUwo9+RlUUTCn2VF 7Qyh2ytx7FaUtdJUM7SP6YdoPlo4sATPdddIMjW0DKNwWI9FPNgN+AIR1C7XNIPyDATR z9x2IOPRgSaq9To9P4W+8Uy2J+zGs4f8no9oBYJbc7fcFzos1EtYjcd1lCyG74kRZWW4 UMRBJBa7rn0Ymi200PmKjjLnXY7bvZ6RfGF0H5/uK8Um0GEozC104Dhq4oqvEPp9qhvx UNyI0/r4CzEiczqEPVRz6kcAfYvuu8mOZgXJndYjoSZJ8FN5b/tE4QLfNFOP8Gou3foI JrEw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si1408690jag.18.2021.09.09.00.36.36; Thu, 09 Sep 2021 00:36:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352671AbhIIHgg (ORCPT + 99 others); Thu, 9 Sep 2021 03:36:36 -0400 Received: from pegase2.c-s.fr ([93.17.235.10]:50099 "EHLO pegase2.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232549AbhIIHgg (ORCPT ); Thu, 9 Sep 2021 03:36:36 -0400 Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4H4rQ51qzmz9sWf; Thu, 9 Sep 2021 09:35:25 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id URKDW8TFRsBc; Thu, 9 Sep 2021 09:35:25 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4H4rQ50Vdgz9sWd; Thu, 9 Sep 2021 09:35:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E92F38B77E; Thu, 9 Sep 2021 09:35:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ouyCwfPnJfe2; Thu, 9 Sep 2021 09:35:24 +0200 (CEST) Received: from po9476vm.idsi0.si.c-s.fr (po22017.idsi0.si.c-s.fr [192.168.7.20]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C29B88B77D; Thu, 9 Sep 2021 09:35:23 +0200 (CEST) Subject: Re: [PATCH v3 2/8] mm: Introduce a function to check for confidential computing features To: Tom Lendacky , 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 Cc: Sathyanarayanan Kuppuswamy , Andi Kleen , Tianyu Lan , Joerg Roedel , Christoph Hellwig , Borislav Petkov , Brijesh Singh References: <0a7618d54e7e954ee56c22ad1b94af2ffe69543a.1631141919.git.thomas.lendacky@amd.com> From: Christophe Leroy Message-ID: <96aa160a-e35e-452e-b785-24410265b0f6@csgroup.eu> Date: Thu, 9 Sep 2021 07:35:21 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <0a7618d54e7e954ee56c22ad1b94af2ffe69543a.1631141919.git.thomas.lendacky@amd.com> 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/8/21 10:58 PM, Tom Lendacky wrote: > In prep for other confidential computing technologies, introduce a generic > helper function, cc_platform_has(), that can be used to check for specific I have little problem with that naming. For me CC has always meant Compiler Collection. > active confidential computing attributes, like memory encryption. This is > intended to eliminate having to add multiple technology-specific checks to > the code (e.g. if (sev_active() || tdx_active())). > > Co-developed-by: Andi Kleen > Signed-off-by: Andi Kleen > Co-developed-by: Kuppuswamy Sathyanarayanan > Signed-off-by: Kuppuswamy Sathyanarayanan > Signed-off-by: Tom Lendacky > --- > arch/Kconfig | 3 ++ > include/linux/cc_platform.h | 88 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 91 insertions(+) > create mode 100644 include/linux/cc_platform.h > > diff --git a/arch/Kconfig b/arch/Kconfig > index 3743174da870..ca7c359e5da8 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -1234,6 +1234,9 @@ config RELR > config ARCH_HAS_MEM_ENCRYPT > bool > > +config ARCH_HAS_CC_PLATFORM > + bool > + > config HAVE_SPARSE_SYSCALL_NR > bool > help > diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h > new file mode 100644 > index 000000000000..253f3ea66cd8 > --- /dev/null > +++ b/include/linux/cc_platform.h > @@ -0,0 +1,88 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Confidential Computing Platform Capability checks > + * > + * Copyright (C) 2021 Advanced Micro Devices, Inc. > + * > + * Author: Tom Lendacky > + */ > + > +#ifndef _CC_PLATFORM_H > +#define _CC_PLATFORM_H > + > +#include > +#include > + > +/** > + * enum cc_attr - Confidential computing attributes > + * > + * These attributes represent confidential computing features that are > + * currently active. > + */ > +enum cc_attr { > + /** > + * @CC_ATTR_MEM_ENCRYPT: Memory encryption is active > + * > + * The platform/OS is running with active memory encryption. This > + * includes running either as a bare-metal system or a hypervisor > + * and actively using memory encryption or as a guest/virtual machine > + * and actively using memory encryption. > + * > + * Examples include SME, SEV and SEV-ES. > + */ > + CC_ATTR_MEM_ENCRYPT, > + > + /** > + * @CC_ATTR_HOST_MEM_ENCRYPT: Host memory encryption is active > + * > + * The platform/OS is running as a bare-metal system or a hypervisor > + * and actively using memory encryption. > + * > + * Examples include SME. > + */ > + CC_ATTR_HOST_MEM_ENCRYPT, > + > + /** > + * @CC_ATTR_GUEST_MEM_ENCRYPT: Guest memory encryption is active > + * > + * The platform/OS is running as a guest/virtual machine and actively > + * using memory encryption. > + * > + * Examples include SEV and SEV-ES. > + */ > + CC_ATTR_GUEST_MEM_ENCRYPT, > + > + /** > + * @CC_ATTR_GUEST_STATE_ENCRYPT: Guest state encryption is active > + * > + * The platform/OS is running as a guest/virtual machine and actively > + * using memory encryption and register state encryption. > + * > + * Examples include SEV-ES. > + */ > + CC_ATTR_GUEST_STATE_ENCRYPT, > +}; > + > +#ifdef CONFIG_ARCH_HAS_CC_PLATFORM > + > +/** > + * cc_platform_has() - Checks if the specified cc_attr attribute is active > + * @attr: Confidential computing attribute to check > + * > + * The cc_platform_has() function will return an indicator as to whether the > + * specified Confidential Computing attribute is currently active. > + * > + * Context: Any context > + * Return: > + * * TRUE - Specified Confidential Computing attribute is active > + * * FALSE - Specified Confidential Computing attribute is not active > + */ > +bool cc_platform_has(enum cc_attr attr); This declaration make it impossible for architectures to define this function inline. For such function, having it inline would make more sense as it would allow GCC to perform constant folding and avoid the overhead of calling a sub-function. > + > +#else /* !CONFIG_ARCH_HAS_CC_PLATFORM */ > + > +static inline bool cc_platform_has(enum cc_attr attr) { return false; } > + > +#endif /* CONFIG_ARCH_HAS_CC_PLATFORM */ > + > +#endif /* _CC_PLATFORM_H */ >