Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp293004pxv; Thu, 24 Jun 2021 08:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF6+KypGSKuUZE+R9sKRG+xsgmZGx05HzE+BAkINoDabshKLoApUQCyLnbI3qv1UUhYkXV X-Received: by 2002:a92:d6cd:: with SMTP id z13mr3863188ilp.175.1624547081806; Thu, 24 Jun 2021 08:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624547081; cv=none; d=google.com; s=arc-20160816; b=0E26+W9MTYCPaBifUG6RGVDiuvzSFKCCZUsamfoELQczpyolmEfk+306tjJg1Bp5Y0 DMV0e/k13vKS2TMpwtcCxGXf1jC/428SnnyaydNcGdnrUjMJazTdH0wESjCcmf8RqQn4 hfgl0NIHphy0S6niXDU8p/Pdnj2TLLwX+MVll7gXXxwRcdvXlM/zIS5SUw4tHC7uARkN 2day151ONCXeag7tmWkXyfnmaUROP9DW4xQnbQhvLm8U5A0VDf+JrXjsYuTcws7ouivt hO745/iH/Ic5m96L/qrpbp+syj6Z857a59mciFtFsD4KdjsHznb8zrlmrYtqh8ZQW4Db qzbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EbmBZjzk/a7b0Wm081210DtHfALq+LTnsgNteTuznT8=; b=QEYZn2nW/leQ9c3Z+voB93OIhsV0dMyKLBFhbDXtT3HUP2Qi6IV24n0hbQWmaTP6nc 1b0wbdfcLvPj2c8wivbcWuyBHa6UjaQv5+valZovpgX+oKr9cMiYxrgmSzR6/uHiVfX1 QTvHDRfXnyv8CMmr288a+vScptQLXZv7tv8phxTAyi4NZzYuG8LZnUV7W5ThxDHtE6Tc LWLdr2VFACs0ojhfGyURDgyG132xVcHHQ52ydrxMzsLhfN8XI2p8Ea2Z/3nFnpBoh1wL AU59b8pnUY8dxiJAFSUuZFniIi1BO+OAcGNM7hSuJlZt4IF9gRIzV9P8HIIN1WGWdbvN Bhog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=OUq89EdU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si2933315iow.13.2021.06.24.08.04.25; Thu, 24 Jun 2021 08:04:41 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=OUq89EdU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232172AbhFXPEZ (ORCPT + 99 others); Thu, 24 Jun 2021 11:04:25 -0400 Received: from mail.skyhub.de ([5.9.137.197]:33018 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230249AbhFXPEY (ORCPT ); Thu, 24 Jun 2021 11:04:24 -0400 Received: from zn.tnic (p200300ec2f0c1e008510e17daa0769aa.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:1e00:8510:e17d:aa07:69aa]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5E6AD1EC0575; Thu, 24 Jun 2021 17:02:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1624546924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EbmBZjzk/a7b0Wm081210DtHfALq+LTnsgNteTuznT8=; b=OUq89EdUmp9BFpAoZNUnVL+SRvmiJbO5jd1eF9IkxLfj3PFWeWyk8MsNR+403PC61u8oZG 9JNXqWZ3tE4cFhFolc40jG3SBcigghUA/wZ440ZWKEQ2qLBMKWreXMCqOWptXTfTwif53O Hr2MuXIdh/hgTgDHPFt+7/6j2zLezOw= Date: Thu, 24 Jun 2021 17:01:58 +0200 From: Borislav Petkov To: Kuppuswamy Sathyanarayanan Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 04/11] x86: Introduce generic protected guest abstraction Message-ID: References: <20210618225755.662725-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20210618225755.662725-5-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210618225755.662725-5-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 18, 2021 at 03:57:48PM -0700, Kuppuswamy Sathyanarayanan wrote: > Add a generic way to check if we run with an encrypted guest, Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood. Also, pls read section "2) Describe your changes" in Documentation/process/submitting-patches.rst for more details. Bottom line is: personal pronouns are ambiguous in text, especially with so many parties/companies/etc developing the kernel so let's avoid them please. > without requiring x86 specific ifdefs. This can then be used in > non architecture specific code.  "... in arch-independent code." or so. > prot_guest_has() is used to check for protected guest feature > flags. > > Originally-by: Andi Kleen > Signed-off-by: Kuppuswamy Sathyanarayanan > --- > > Change since v1: > * Introduced PR_GUEST_TDX and PR_GUEST_SEV vendor flags as per > Boris suggestion. > * Replaced is_tdx_guest() with if (boot_cpu_data.x86_vendor == > X86_VENDOR_INTEL) in prot_guest_has(). > * Modified tdx_protected_guest_has() and sev_protected_guest_has() > to support vendor flags. ... > diff --git a/arch/x86/include/asm/protected_guest.h b/arch/x86/include/asm/protected_guest.h > new file mode 100644 > index 000000000000..d47668dee6c2 > --- /dev/null > +++ b/arch/x86/include/asm/protected_guest.h > @@ -0,0 +1,20 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* Copyright (C) 2020 Intel Corporation */ > +#ifndef _ASM_PROTECTED_GUEST_H > +#define _ASM_PROTECTED_GUEST_H 1 #define _ASM_X86_PROTECTED_GUEST_H > + > +#include > +#include > +#include > + > +static inline bool prot_guest_has(unsigned long flag) > +{ > + if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) > + return tdx_protected_guest_has(flag); > + else if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) > + return sev_protected_guest_has(flag); s/protected/prot/ tdx_prot_guest_has sev_prot_guest_has ... > @@ -18,6 +20,21 @@ static inline bool cpuid_has_tdx_guest(void) > return !memcmp("IntelTDX ", sig, 12); > } > > +bool tdx_protected_guest_has(unsigned long flag) > +{ > + switch (flag) { > + case PR_GUEST_MEM_ENCRYPT: > + case PR_GUEST_MEM_ENCRYPT_ACTIVE: > + case PR_GUEST_UNROLL_STRING_IO: > + case PR_GUEST_SHARED_MAPPING_INIT: > + case PR_GUEST_TDX: > + return static_cpu_has(X86_FEATURE_TDX_GUEST); return cpu_feature_enabled(...) -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette