From patchwork Tue Jul 27 22:26:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12404459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A5DFC4320E for ; Tue, 27 Jul 2021 22:26:54 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50A0060F4F for ; Tue, 27 Jul 2021 22:26:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 50A0060F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8EB26E504; Tue, 27 Jul 2021 22:26:53 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2063.outbound.protection.outlook.com [40.107.237.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id EDFC96E4A7; Tue, 27 Jul 2021 22:26:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WWpmIXFfZFjlBwOabATYwwJnuOXd75mvssDL/+/jCKES8f7p9TqRm4ssX5zcjO29HJg8ZS1ZkryJQvtx70Dsvo73pfRYc4T7Fr9c5sHoKgv0je2yUMz6eEyi55h1Jxbupt0aMoGfpIshdJaIqN25zXBHWwyNITPHTzHbDAnx+t6VoctpwoSQBa5iMzS3Wjmiv/qo3Tp49d+1s3J9RVbOfs8SJqFpj5LEQCvYWdjDqeb32xG9jstTzVHwQ8JlD2BK6wVflvKkgc5aTgQ0o1nsUocCnlyXRZPzjXFvbpezQcxOp3/DJDNItz6pJnk+DoKjB6uWTIi3MINg+PSEsZxW/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D94tUDv6KePt80sethbOGHdYxlwwYHbtwKspSl/dixo=; b=g0HABxWuyEBgPro7+l0ZdMACIon90sR258k0X9RFXeFxv+IN9VJPApFR73UAYrnD661FWynZ+dPTVbLKXOa2i1rqDbI6G7tRZaf2K2wF/YKovFfnoJJYc0tb1fT/j1YR4Y3w+d5dHViubHDHs4pgvgsZx/+fBJgDox3Ouo2Fnm5PHqz7dugDSEm3ul4P6oBNUYLf1CdQPdKL8VXVZ/Da8DT5ruqNF2IX3PGj6Qyhe72kY+45WGubPaFBTLVSevExgX/f9rI5LnVyWQUaHoPigdeQ28xLzT6iJbfa20hy45bPPYqvWfz0sxNwrSDC+4jmCsqKcyFib9W+V7g9FD/L7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D94tUDv6KePt80sethbOGHdYxlwwYHbtwKspSl/dixo=; b=AbRSqNdZs9JUj6YgpzkTt/M46cfbeZBJQTQCoTkM9l/DZ+gfptA/WxVaqyrHVV4WKQzVVXNZyS8mXEjZeY3quh7Z+LOiK1K3u4WNHIxDGrE0fdwSWIMr90ImckeLmqwXHivRJw3qyD7AVhvbgUZC3ppngTDRlxwks6yw2pHBl7s= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by DM8PR12MB5462.namprd12.prod.outlook.com (2603:10b6:8:24::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26; Tue, 27 Jul 2021 22:26:49 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::73:2581:970b:3208]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::73:2581:970b:3208%3]) with mapi id 15.20.4352.031; Tue, 27 Jul 2021 22:26:49 +0000 From: Tom Lendacky To: 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 Subject: [PATCH 01/11] mm: Introduce a function to check for virtualization protection features Date: Tue, 27 Jul 2021 17:26:04 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SN7PR04CA0187.namprd04.prod.outlook.com (2603:10b6:806:126::12) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN7PR04CA0187.namprd04.prod.outlook.com (2603:10b6:806:126::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26 via Frontend Transport; Tue, 27 Jul 2021 22:26:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 717f060a-ce09-4bfd-6ed3-08d9514da04b X-MS-TrafficTypeDiagnostic: DM8PR12MB5462: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QHO+mLE4VdSGkVexmSJilen55jEjTS8GTaqInU8OCZJURUEKKiH6wLoIaBCotonFjYINFSfaDlFQsSnYW9I0GZ9KCHxBtvawV2kGIRLXevyuVYvWux9s3yOTcAiL092P3H+pwGl4BkXVE6tWtDvuiiuKoeogEAkME1G1SyC9lRSp3fk3YQz6fEMEzZsZkKAwttUpxV884TtjkpRBa87KDNb4o/c7sIP14a//tq4j7+XfhvBR3XeVlf97W3RqgwGDK0/PNpwIDhXPvx86QukFSO1PjRKUuCtQVD4719YcZB9WQ+Ywp4j0PF3GgSnfP5G+ksuCBJtw7Z2d+9HA3FoPqqjRWygDEAUOBPPkLgXgokMs6HKEPZncr3OoenxA1fbTrBTkecjQ4/uP39kjFdWu2R1q31+GO0PBI28xL/H5QAnJpd1ukcjMwG4+xJneLFYwuY/cbB6mjWJW3r0jz+zMEyfd+wy229lY6Ivz5WxP9CLKGiZ7nPHnUdDV4gGk0ecKY7BKpQsgz9zwr4Tf3ru7w1/cfMwcR7XC4LhGcXNgj9x9F02gFpBt5Cds8oFNsgLmYsL+jejPlzV8ukZgyRBICMOlzxpwyxZ7dG3jKnvcxSqmzcfKBTVLZklUtNBJhA7UXqtlXbLVLKS015MpVdm2fcvsK6O3/rsnk4w80R1B8s/ipKGPdc1WDhzGUPaDpUZfCPIUT634UBZp4SIjAyT9T8kxaB00RsXYqngdvLitifE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB5229.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(346002)(396003)(376002)(136003)(366004)(86362001)(6666004)(26005)(186003)(478600001)(8936002)(2616005)(2906002)(52116002)(7416002)(4326008)(66476007)(8676002)(7696005)(54906003)(66946007)(5660300002)(316002)(6486002)(66556008)(921005)(38100700002)(38350700002)(36756003)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /PxRIthfUgjSvOzOXFVDfetP3FE+cMWPbcDgoqdodIwAFD2ob5hvbVOx+p7UGodRCOoEAypKQlcTEXj4nDUYsUQUyVceFkfzyCSZiDyCyyVbO9vyKRChEUakVje+poSD35i+VB+IIlDXzqIaa2k2R1GgNEtjqAXm8ApVTXTIGCFxHRSglGkaMk2P1QMka5F9dxvWsDxCsXXh5I6XdoGlONEDNjqcRMENWKtBb7k/31zaaU+8CFjVLIRmFBty7j3lZBQ3NmMmbcXoD2ZsJUCfVy1J99mB8DtN6hJWaVdK/sdPd0WfS+FggVs+1aZrY28fpxF1LMtVCEOZK7JLOtgUudji5y7YfzAbJWjCD+Bi08SI7OOFCzvMsxVGEyoupsIJGCLQ4Kic2W9Z/kXZYu5JcHPWKD3HHdLW1MS8nhYE1mTQuMbqWfHDrFB+stZfD9iQwy7OnYNrZN/4b48/ZobEmrNMsnz6xzCrrtV03rquzdDacDywnjREO2dg61X9+ljzOKG3lojbpQqh7vGgDD5AiWAHsJJ78sZsJvSKkD2HnzqGX/mL915cMocrAIZkzS4HbRPITBHpC9k42r3yGMUlWIyiDeU+soKlXDakAzITsFTn2ddN3llWzbMazDwI908yE4Escazz8y9knSjJSi+3D3VlkgWasR2rJDWAX5kWQcVDuM0vu0n4e7KLb6eL9hpMkRTaTr31j8xRevP6hwD4O1uhoAMyuaPnjmEXerRozpP+/KuVsNgnLHDsCzI1A0Zpe+fwduX8CGfVfXKeIxrEfAG7sgClLwyV8HVTt4oId035LtyR1XH73EZSK8SbGdu56nQLL9K+Qe2eRkoQx7ShwNjLpuacHxVCXndXguia1T8yQ1hhtHu5Gm8gVT1YIE81GvxHPxFmWFcxmH+mPn2UliCeD6mLcRc3XfTqvjTwiEsdrFyvuheGxc0abf4jgPoq1rmvOCXTQucovzVuNnk18cF9LPBXZgeDkBKPtoSpunWipLP5VzYnTIGRglZgKWUSoyHxBhqtS3YT89beN8wYlzprbW+QmPmwJ1wls6ih/0lgjjdomED4MEE/dU1bF44pbLDV9RHW94GAiVzINOtGVnwqrnUrUSNz/SHo8v1RpadyW46sUJ1CmHR2zPDAmyiXwQaaptwEh5LUhfx3HbYz/OLjkNaFAaaLVUgRPSacd/kcfz64MjCQuzYRG8qPlJ5BKR/Je3rMlOgmKR1gNfNK+v2Y9oUeyeIR/ulGtUsUqthOCNUIdaMHX2a3U1cOFtFNzqy+qMwbkXiSMF9E7dhuGl7EMXTsDR/4jqla+2XtV9nQ1yMMceQNr0lMKl++Z/wt X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 717f060a-ce09-4bfd-6ed3-08d9514da04b X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2021 22:26:49.5535 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZAqqFm7MIdcu88eQAlOLDfwrloJneekLcMxN0JUEE1djlRNIG90oeAP9CYDEi2s/1Mvut8ee/ZKd0eCSw5uEow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5462 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sathyanarayanan Kuppuswamy , Andi Kleen , Tianyu Lan , Joerg Roedel , Borislav Petkov , Brijesh Singh Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In prep for other protected virtualization technologies, introduce a generic helper function, prot_guest_has(), that can be used to check for specific protection 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 Reviewed-by: Joerg Roedel --- arch/Kconfig | 3 +++ include/linux/protected_guest.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 include/linux/protected_guest.h diff --git a/arch/Kconfig b/arch/Kconfig index 129df498a8e1..a47cf283f2ff 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1231,6 +1231,9 @@ config RELR config ARCH_HAS_MEM_ENCRYPT bool +config ARCH_HAS_PROTECTED_GUEST + bool + config HAVE_SPARSE_SYSCALL_NR bool help diff --git a/include/linux/protected_guest.h b/include/linux/protected_guest.h new file mode 100644 index 000000000000..f8ed7b72967b --- /dev/null +++ b/include/linux/protected_guest.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Protected Guest (and Host) Capability checks + * + * Copyright (C) 2021 Advanced Micro Devices, Inc. + * + * Author: Tom Lendacky + */ + +#ifndef _PROTECTED_GUEST_H +#define _PROTECTED_GUEST_H + +#ifndef __ASSEMBLY__ + +#define PATTR_MEM_ENCRYPT 0 /* Encrypted memory */ +#define PATTR_HOST_MEM_ENCRYPT 1 /* Host encrypted memory */ +#define PATTR_GUEST_MEM_ENCRYPT 2 /* Guest encrypted memory */ +#define PATTR_GUEST_PROT_STATE 3 /* Guest encrypted state */ + +#ifdef CONFIG_ARCH_HAS_PROTECTED_GUEST + +#include + +#else /* !CONFIG_ARCH_HAS_PROTECTED_GUEST */ + +static inline bool prot_guest_has(unsigned int attr) { return false; } + +#endif /* CONFIG_ARCH_HAS_PROTECTED_GUEST */ + +#endif /* __ASSEMBLY__ */ + +#endif /* _PROTECTED_GUEST_H */