From patchwork Wed Dec 14 19:40:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13073429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 279A5C4332F for ; Wed, 14 Dec 2022 19:57:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C08448E0007; Wed, 14 Dec 2022 14:57:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB8918E0002; Wed, 14 Dec 2022 14:57:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0B778E0007; Wed, 14 Dec 2022 14:57:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 912468E0002 for ; Wed, 14 Dec 2022 14:57:21 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 68944A0FA9 for ; Wed, 14 Dec 2022 19:57:21 +0000 (UTC) X-FDA: 80241971082.26.D84EB72 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2085.outbound.protection.outlook.com [40.107.94.85]) by imf13.hostedemail.com (Postfix) with ESMTP id 6B92C2000D for ; Wed, 14 Dec 2022 19:57:18 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=EIa3CCEk; spf=pass (imf13.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.85 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671047838; h=from:from:sender: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:dkim-signature; bh=b3oFK5H6oMp/qtECE/tp0Qc0iKoUNBA67OdiIc9I814=; b=7jh0nx+ZNox6UmrUMeI8EB8+W9oZ5Dhm7BqczEKf7ggNX9/4P6ehOLE/i4lnrJRCJGeyLl +7rfdsskcZPe5CTfPignnTFDuCkw0tak13eHL3LvUJpmKwOOTfsyXgf3AnJvZhRtTgr2oW ANnZIxEX0v1fkGOv4ixQj2VgFgrgajE= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=EIa3CCEk; spf=pass (imf13.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.85 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1671047838; a=rsa-sha256; cv=pass; b=M6SzEs3584drPXpYzUfQcjTiU3V7ZtFhK1sta7xIXuk2nxHJkzskKJslHTvWW8QxK0L1G7 cZYMb1pmhatSTOo2CR5/4OwSEDKNjVPPs7UE2egcJJdyJOutcfWj2uBh7EamFqvEy8vJrR +bw/vpBJEYuAw3i+4wC/xzjOOv0ew+E= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jC63+ppZ9dPdWNHB9gmHX/CMvEh1hvSTN6i6mjeIajEBQE0AEe16MpSOsRpicKBQDwsy7W/t56QczcMIl8QPLcb8EYPflTi2gyu0jwgDq57HMTQAwTFomE/lAX+pOm8IIrrQIBozPRcJ2wOEczHjs8rKjjhuj/pJe++GTS4g2/0Fliu9gdkhQ+Yr7+3Z57iIB7dz9WZGKeN7FyOaR9BgkzlOHACHA+D+rDzp6UbpVyYcCTN29aHp/NxwwrbzqDoCH82US0kjU7oim1njsnANm3EMv/nygiqIwXkL/l+gSd2NXYppK2FHYrdtzf2UQkTsj+FR+8/hGg/56/dN+aRkOA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=b3oFK5H6oMp/qtECE/tp0Qc0iKoUNBA67OdiIc9I814=; b=j4Cp5lHBvd9gsQDzIuXuT0kzNO+ZEFBnTUk66Mk61BnUN4Dv+8UBIp4OkkeFREDN2i2AQ7wfPTtPgTPdEQpWtGjYDkuDz3qx+lwXRpM9ueztCG3iYyeAV9WB1HAOIfAAdTEd1Rs37tOQpitg/urMU39Ug8sQ8JiXjwkwUDtEMdTN0uCVs6SZt2TfEyqz6GtG8paHRwtyPUYPg13HYC7oqQpJEbCfbY3zYQe6bGpF/fQju23SmW/e21Wuog/Y+VWFjiAf1GWA/DWLCx0Gwi9FRwY6WFFmB7wgUBz2Ng6kyYVqI250a8OaCuCnAyKNsBS9JGP1pW1b4q8QDQdb63ChAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=b3oFK5H6oMp/qtECE/tp0Qc0iKoUNBA67OdiIc9I814=; b=EIa3CCEkgmSapx+POOE6WCgpcpK9/7XYfWyUU7H9ANOgllZzkGegBdfDDL8xe4KQUDDpjZV3xI9K9j0nResujnMm6v0oBYfgb82z9Kd6zzb76f2hR6YFOZ3GZ7s/feaEmJuKt8J3ut3FuVxYlQurL9IEhGWNjUubYFvoLBNXXCY= Received: from MW4PR04CA0032.namprd04.prod.outlook.com (2603:10b6:303:6a::7) by MN0PR12MB6247.namprd12.prod.outlook.com (2603:10b6:208:3c1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Wed, 14 Dec 2022 19:57:15 +0000 Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::d9) by MW4PR04CA0032.outlook.office365.com (2603:10b6:303:6a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 19:57:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 19:57:14 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 14 Dec 2022 13:57:13 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v7 36/64] KVM: SVM: Add initial SEV-SNP support Date: Wed, 14 Dec 2022 13:40:28 -0600 Message-ID: <20221214194056.161492-37-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214194056.161492-1-michael.roth@amd.com> References: <20221214194056.161492-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|MN0PR12MB6247:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a5b99e5-40ab-43a8-bd7d-08dade0d65c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l8aTcKZg+y88+cZMNS2xwhwnqoAkNwcsiQCD9BTGzvYDpshnlINFJN3NundMLD2mdIrmhEFXKC8aQfHIiGDHNEze94QcjkPdyOoNMVAQZtUrgfReA4Mf86N5O+DrYuhZV1gmZXAK+z6bnhOBwYqFEPD21ziPSQaZX6NLeaYtIwa/3oQLvNFWyV/Ar+FPCXvbOs0s+zzqzoXDQiTRDIi77WVIakAXKTo23sFlpSEw1W4WGJlbv6ssI89j7AwJgkLd8dF8H9t5kJM+kzarLUVqJ72ESo+Z8/iGVEFKT54db+A4j585Wv32FDJtGO0ZxJIr4sm0EOtPrZE+wrAhz8t62/HHvrt3xpIpF+t2XIx8fxtxfs/YQwdcyfNpVQfy+6rxZ6A/teNMhWxWCZsxloB9NNo+zmceL3ocJ5LVBbw4jAPhGoYdMUMgr4KRLQnBufQl1qyblYo/jgR3bsBjmG8vkqwe6D1ScJY+Kw97KHjkTBo3IVrEfCBjx+ypYptOYV4QFgWqqTwwyFx9HZJpv/qhWYhLyS4MvsbEpOS4rid4/oPPvqqKfGidNVk5/pthZkeHSeQOwekYOGqwvJexYcC+bRD3XPGK1jukiMqBm/b6DzuwSXXV5QQVQIsI9MJ22TQpNBGaVn3AKkEM+PXBCRpcVXRc//lTcGjv3bKNj6cdZ9JOUI91mIPW5k5fpXafppzDrnej7A5RhD1xj48wtVb/7RJDW9xsJVMzR7wLVjnf1rI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(396003)(346002)(376002)(451199015)(36840700001)(40470700004)(46966006)(316002)(36860700001)(36756003)(40480700001)(40460700003)(81166007)(356005)(82310400005)(26005)(82740400003)(86362001)(478600001)(54906003)(8936002)(6916009)(6666004)(47076005)(83380400001)(44832011)(426003)(7406005)(7416002)(5660300002)(2906002)(336012)(4326008)(41300700001)(70206006)(186003)(16526019)(8676002)(2616005)(1076003)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 19:57:14.8470 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a5b99e5-40ab-43a8-bd7d-08dade0d65c7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6247 X-Rspamd-Queue-Id: 6B92C2000D X-Stat-Signature: ss35h4dsep1bkd6cj7bwki8aojetbcq6 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1671047838-111947 X-HE-Meta: U2FsdGVkX19uJOfRkMkS8qMn6QP1UZsYaY6dZapghYjxIVHRaGMIXylandQyYrzqtE50SYjMR/qwsD0U2Wx/FElJ/ZUN7bmn189KZTNZyI2Pz2rRYp5OmCLzQWxc6bA5ssobdTz7IJCfGr65jwtxRCJueeBXjEPFzvP9Qvh/R9rWtV/AjfQleuxygsjbbEhC+UEFqMFHZrcUT1DMJY0+G5TCEaMQOitz/aDIzq4miTKUHaOu3PVoK25I1XJ41OIcuyMiRd34PT06vN4bItsm7w6ZCW82bfhbDOq5TqDccEzSz5x6eCRgjlnnK6TEiZRVFL3e5cqso9woLOmZLs/vpxJIVqUOX/rW3wdRgrbSnYTQYxtWv0IL9f8Hz1QxQEfuPF1LJe38FfnETXVYPgyUm/Q/a6d0s5BCYJVqLLUgm/6nz1uWBwDgQnRGrnqnbRTNDbi4qqHbLwDKpprZU3mZI5L/y07jkLQFwypIReQJ815xLy89dmfxnouLD4x5i7avPcxTRnlnbhshPz7CReaxgmEpXFJd/Zfk2VuLnQydwA3UjZo6YUrYJAx10HiDK1FjyH/9kJ5+i0xUDreD6YU5BEJ4Uwhp16E93jAsFGBqapSe1DqRLlU8cRxmLPnTxWk6pzJUXD3VZTl/ZfK/jF8ikcS3XmY5JhNAUhtrD6gdEJVoirSkk+TUfWASm9FcKiViptQd/QuQ5sSTqnKLT8yFNCaltYqsPj565syvJk09mc1R4bQ4jun3Kmz3clwFtZNh15ZPt2yPwdt7bWcKep+aeaLnWKazGeGDz/y3f+kxIsiPNOYXVA46W1bQEUz3LkKgqVXQPosvt64fIb7UZxDkhhHG+YnIRLMT3zsa9E62Lc/6biS0LQLzDSWU1E7cAP89zLgV7yphIRLRhJkknyQHREnOIljypKrjNF0cfe6OEvZyyBcOzQh3XA6wbz2J47CiaC/FATtPitRoX7T5nT/ V/ykmCSt Wz/Rk X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Brijesh Singh The next generation of SEV is called SEV-SNP (Secure Nested Paging). SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware based security protection. SEV-SNP adds strong memory encryption integrity protection to help prevent malicious hypervisor-based attacks such as data replay, memory re-mapping, and more, to create an isolated execution environment. The SNP feature is added incrementally, the later patches adds a new module parameters that can be used to enabled SEV-SNP in the KVM. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Signed-off-by: Michael Roth --- arch/x86/kvm/svm/sev.c | 10 +++++++++- arch/x86/kvm/svm/svm.h | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 0e93b536dc34..f34da1203e09 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -57,6 +57,9 @@ module_param_named(sev_es, sev_es_enabled, bool, 0444); #define sev_es_enabled false #endif /* CONFIG_KVM_AMD_SEV */ +/* enable/disable SEV-SNP support */ +static bool sev_snp_enabled; + #define AP_RESET_HOLD_NONE 0 #define AP_RESET_HOLD_NAE_EVENT 1 #define AP_RESET_HOLD_MSR_PROTO 2 @@ -2298,6 +2301,7 @@ void __init sev_hardware_setup(void) { #ifdef CONFIG_KVM_AMD_SEV unsigned int eax, ebx, ecx, edx, sev_asid_count, sev_es_asid_count; + bool sev_snp_supported = false; bool sev_es_supported = false; bool sev_supported = false; @@ -2377,12 +2381,16 @@ void __init sev_hardware_setup(void) if (misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)) goto out; - pr_info("SEV-ES supported: %u ASIDs\n", sev_es_asid_count); sev_es_supported = true; + sev_snp_supported = sev_snp_enabled && cpu_feature_enabled(X86_FEATURE_SEV_SNP); + + pr_info("SEV-ES %ssupported: %u ASIDs\n", + sev_snp_supported ? "and SEV-SNP " : "", sev_es_asid_count); out: sev_enabled = sev_supported; sev_es_enabled = sev_es_supported; + sev_snp_enabled = sev_snp_supported; #endif } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index ea9844546e8a..a48fe5d2bea5 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -83,6 +83,7 @@ enum { struct kvm_sev_info { bool active; /* SEV enabled guest */ bool es_active; /* SEV-ES enabled guest */ + bool snp_active; /* SEV-SNP enabled guest */ unsigned int asid; /* ASID used for this guest */ unsigned int handle; /* SEV firmware handle */ int fd; /* SEV device fd */ @@ -330,6 +331,13 @@ static __always_inline bool sev_es_guest(struct kvm *kvm) #endif } +static inline bool sev_snp_guest(struct kvm *kvm) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + + return sev_es_guest(kvm) && sev->snp_active; +} + static inline void vmcb_mark_all_dirty(struct vmcb *vmcb) { vmcb->control.clean = 0;