From patchwork Wed May 1 08:51:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13650348 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 E0140C4345F for ; Wed, 1 May 2024 09:08:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 717086B00B5; Wed, 1 May 2024 05:08:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EE086B00B7; Wed, 1 May 2024 05:08:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5407F6B00B8; Wed, 1 May 2024 05:08:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 318076B00B5 for ; Wed, 1 May 2024 05:08:09 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E2BDD1A0A32 for ; Wed, 1 May 2024 09:08:08 +0000 (UTC) X-FDA: 82069250256.16.6345CE0 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2071.outbound.protection.outlook.com [40.107.220.71]) by imf11.hostedemail.com (Postfix) with ESMTP id DC6AC40002 for ; Wed, 1 May 2024 09:08:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lg3SOjLc; spf=pass (imf11.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.220.71 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=1714554486; 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=JoBb4Rvwn2Q5aMHC/+7SFu3Ry/fPDAnvq/GxIbd4pvU=; b=mitCE8xWNAn7aTyzjDnBnn7uUO655AKy0J77hvRzatRLq00OeDpex0l3UiAKYSn4Rc8HnQ 0XSh25rnwaQ8+9Nx0TSN21DhM6swOIYqCwG3rloQrFN2ONuf61vmv+C5v5mhx/N9G9wN2x Ci0KKN9DHG7o7Gz15ITT3nC21s25tNg= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lg3SOjLc; spf=pass (imf11.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.220.71 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=1714554486; a=rsa-sha256; cv=pass; b=cCQPIGvJbZ8aD/LqL2Pq1VNGxiKdj8EMWtkuQ+jjcbKczLxkRqD+/HAXQ/8QkmQvauUzzO RbbJrc+2vNVpRF9ZIpi5ergeZoovgcZFnQA5BwKe2/TYckzm92lKLnbuMIRNF/K6Y2ZkOi vb8Ks+CR4x3JyXMmk5sgTzrepIIxuMw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZiC5Tm8kFPvajn6mGnrcvyRYSagm42VsJqJZwwZQEAbWa1kFKbQ8aRWrxlDiHYyt0F/f1afQYXEa2Eg50iIFMruyBgjf71fMMaFrg/kCvBKldpXyNjF8w4fVng5h8Wne6lw2Xmp/bRzIsdR53ZuAqbW8Pt/NyVa0v+7DNEgbnH2KEatYbUdPNwBQmwB80yATRamoEGs9Ki4earNwNqsmyBrky6ToTmTw3vABsMmp85rZkKuseHIP0SiOxTX7fmXRD6aJjqiGmnDDCuSxjhjFk3QDOlJ9CY6aquU3O1oXKsyNsjrUtxpmVx/9hMoBnfqxjAw8hgxH6ufsvbQasX/jBw== 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=JoBb4Rvwn2Q5aMHC/+7SFu3Ry/fPDAnvq/GxIbd4pvU=; b=IKKMngiGJtjlFIa72Zxim5hcC44HcgbWcIVYlvGycXfnQepBeywuGazyZbEz3JgKs2f8vn/e8RH3ZLxjadWkX7GGquciRih11a4VNQNmBS9O6+9AnVewanSyoGKCgdbj3Z+2D61hmFkBRIvwHVPATfk5v26Hnmu4mHOBlNFQ5Bg2264r9UCZb43bVl48YLqucRAz3Iuxe3AWGSSQJjliIoXP1vBY530nl3gEIx+YgmEmrcEqto9ZBeUQtwnVnm4a8TEDmG0Ok+5m4Qj/wkXzxKV10AgVxX12gj1hZiri9G46TGndkHf0B+1/sk55wiz+4tSpuX8ej93Y/S5GBCGZng== 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 (0) 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=JoBb4Rvwn2Q5aMHC/+7SFu3Ry/fPDAnvq/GxIbd4pvU=; b=lg3SOjLcWCB6T8m9VFOQCDaqYzg4Jk5RoKC9DMn8ctQ60A8XJ6D2g+Zm8TdLJlMVBhpcQEyWXKpdfCFYs21Y0ofH+3B7jJsOoMN31XJaWe8PFLfzZA4FyCVsY+g92CChSw4GcQohE+wgC0/DyUIF6CHtWj2BixmesUpuauTypOg= Received: from BN9PR03CA0650.namprd03.prod.outlook.com (2603:10b6:408:13b::25) by DM4PR12MB7768.namprd12.prod.outlook.com (2603:10b6:8:102::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Wed, 1 May 2024 09:07:59 +0000 Received: from BN2PEPF000044A0.namprd02.prod.outlook.com (2603:10b6:408:13b:cafe::e0) by BN9PR03CA0650.outlook.office365.com (2603:10b6:408:13b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.27 via Frontend Transport; Wed, 1 May 2024 09:07:59 +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 BN2PEPF000044A0.mail.protection.outlook.com (10.167.243.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7544.18 via Frontend Transport; Wed, 1 May 2024 09:07:59 +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.2507.35; Wed, 1 May 2024 04:07:58 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH v15 04/20] KVM: SEV: Add initial SEV-SNP support Date: Wed, 1 May 2024 03:51:54 -0500 Message-ID: <20240501085210.2213060-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240501085210.2213060-1-michael.roth@amd.com> References: <20240501085210.2213060-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A0:EE_|DM4PR12MB7768:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e49441f-61cd-4171-1ec6-08dc69be32a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|7416005|376005|82310400014|36860700004; X-Microsoft-Antispam-Message-Info: TVgMncpKV5z4L41/HScfFsZNk/okUuRy1J17QvGZRbgk36mh97fBpxLhS1pnZheiSe0z5eAQZTxZTfw17vEvBPsWecoFAJYliUMBYpkk7qOh5SAyufH93uXiG0LXQc06WFF6QDM+BFiSDPiMEdH6+U0cLZILOTUvuvPnLLrEGS7qnBRiGMzbKPlO2quOa19J9+LSO0y1SbX9ZEPq6A15I1U89PWQMXRJiVGbjJkehqGi1sXoEELaKsiYriXo0nxSJ2QdX3K9/2snHOmOhepNVdtRjoGXn7pBY0N/MsuRt3JstoE58KmhgPzUOF19fiN8XFX36gzkTMHarDTWE505bNNUNYRAOjacXvg8A1tDR4b9+IAl/xuQAJdkPjwzMYOpclV9t2CGgL1WkjqzWedZ7oZMe6aBDrVL3UTfwsGvva52jEirCIgxw181BuYFLddjqb55+h4jieTGEsAaPvDBKVDD6BP5Aq/cys14QtefPByjWoXMrK8DfM3QnVcy7CaSlAcx3ua0wiWdC2BIXu31cJ3OEYHawCPmo3pCAsuBqnUc0AlU1lxbNwDvc2ZaQ3D6cYasrJh+4mUEH2iUjrKdSv7SCdFZhMOXafVK2/J7oJ6mdWHG/E33O85untbH/iQM2PXrfEsGIYZZ5mlctxM0pEHi1KW+n2XFIkFeabg0nYhq0/XPmXhuIlmf9XcZ+NGC0gy1y0Ye9YXuSXZheiLBj/ZCDc6fROhFdCK3Bcyb3kZo4CgwOG3WD58beZ2zBHV1qdfOBWe0OCgYgeH4HxDVRpr2iK05pFyvNkn07gCaUrM1lkchIeBvBe+LFoEhDqZ7/iaIkd/oV0Hc6/dOEsLDL3F6PMupYcFOz+YkFIww87GBVLd1kuglLrKsqVwMtrFwVyMLEyHewdETCvAAzVwTbgqXJorsgwPbtsANlCv0Y9Xpcz4PA7Lq3mymK5XTr44tA4nP3PFhCL1iOss9iPQqvN9eSoBKEqsp2WlTz9ojJpKbKfWlKsX3YXhlcUSg1iz4a5/gQ/Cr1hlL08gC9xAjJHnxTVPRPT4DtJZmWuOADoqjJrzrxRgKCmIYSpE16w8jKi38axEu0dclSD6PGbFd/xlKGz72Djg3ABVrjbeEt50GnifVI2rPHgR/8Kf4TZ8fFfL45O9dP+LDj6ni5m1jOMIolciTCaRhHxSafUO0SlnBahaB6agHo+0U8nAAPF7VdaKXE7zhKV1KGDPYi5I3SzyPpJFriOA1g34O3bLQeUQZwB8aRyIZG40rmdFzlOQddQ6FuFX9x7GHQXbbGwrUiDKslS0+yuEK6zcmN5q6CoUGKD8cnS/V938zGcQqYbI49SCklzPnuJaPilY8pNnPUre5MP/EjOiukrKLs9hBFYP248lUHli6bzbtphknisDJ X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(7416005)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 09:07:59.3043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e49441f-61cd-4171-1ec6-08dc69be32a0 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: BN2PEPF000044A0.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7768 X-Rspamd-Queue-Id: DC6AC40002 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 8fzqx6rxxgjhidqt1uwbz6ebpnk5ttu1 X-HE-Tag: 1714554485-733236 X-HE-Meta: U2FsdGVkX19YtIcDbHzcTwGZ4xJkfdDkHrELqtD+oCfBtYRpICoD9LBfZ+Ia6NIMxhXG2Z6Lqs0F8iUlMC8hij7ekQ2XOFf0aV13ZXos7KgTU69i4GL+NAA2UyendfnBRrKo9kz8PqrtKFaUW00IPJn6VmC4+uU9WGFle0uT8uEszIzPl72qSB94GJfH1AXMAr6+cNZ/F2YgEqH8gLM0QKGCD+2y1VrCPWLgV5g0MoILbf365Zrbvb4XFdYHMpZvvyYR+PX2xNi/ftBlHbYXNFdYyvi2IU97/5bc4ND5plnULK4omY5gePE6XWuEnnP2ryz+pY+q8s1vdWjR5/kvWb8Oi/IJYTHgbo7h0kv9neGt+OlBr8tjQnn3/iAqbT67G61UynsbuhScO297N6DeAPUwXt0su1AJjj7kvBCOuFEfIIHVBPi2jmpTCd4GIuYWurEX4+DZwX28zzfVM5cnemdDEvZ7I3O/1BaWA3i6gqYYkQ+y6WbgRwN42Cy7wRQzVTtfn1Z3pLGOqoKjlu6/EAUNoTI94GyPELk0LQn0kBZyM6S+KXI8OOKojl7V2eF2xd7eV8CkCzECfxqeIZseV37hxiwZrFIdZFOjg04of8QvzJ0w6BtzEDjD6dfJqBJ+dqRkC1Ma/BnFALQwD3ckk3G5ZPWnWIeSyaU511u6l1hmy4c3K1/IURhiKZ4DKtIDF2HRQKBHWQZ6Iy/XHp+bgyA0aZgkQOMLRnWFD1PYr/sij27eLNpnl/8yVSUYJlFFeeHWeiyEY3hjZ57C9Y4dpMuTn3a/ebxQTAT4Qdz3SvTbBCWmRDDyNPYjT3dGIztg5TxbppBpbnFfx0xt8gSHKagKRU/JsDhVkhh7EhZjPqz+ZRDBJwRXIq6lTEUAaZgEZvEn5E0obMY1f74/PWFJ+fWlQ6XYyrvq2cjnbICVK8Ko2E5+xaeS4fiTiooJnUuQBclrffKsSybCl6+Zi5l KzMX5aWF Rig+jmXscCqHpysiyeFjs635aaxxh6MIWW35G/pu0kw+XSsIrIpYOPkpMmTM63bpommFcNzWP8ciwq/4n2ZOUaC8UmFgPLk1DkNVUwF03iP8pwxDOBlqz93W9I9m3t8t8QPA5S1X0Av73W6tmT64tmWkG4tOFVnPfuJekI3al9idNoTkFWTLMHneLbEQRI9jKn6CwnLjwNvsisO8bFLtVUmJU/ZSYQ1dEjFrv7gK6LBVgxYE5jBvh1ngQT1irkdsN3ZmqCL7rjaxq0vB+N/uyzdT7N1E+rUrQ3WQQgGFKfybiw6FwAdqNfhUMEbKg8PYS5pSljKSMZRAJB4F+NLGEH3JhxLceO7/MYeJCM/FA4stdeuw= 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: List-Subscribe: List-Unsubscribe: From: Brijesh Singh SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware-based security protection. SEV-SNP adds strong memory encryption and integrity protection to help prevent malicious hypervisor-based attacks such as data replay, memory re-mapping, and more, to create an isolated execution environment. Define a new KVM_X86_SNP_VM type which makes use of these capabilities and extend the KVM_SEV_INIT2 ioctl to support it. Also add a basic helper to check whether SNP is enabled and set PFERR_PRIVATE_ACCESS for private #NPFs so they are handled appropriately by KVM MMU. Signed-off-by: Brijesh Singh Co-developed-by: Michael Roth Signed-off-by: Michael Roth Signed-off-by: Ashish Kalra Reviewed-by: Paolo Bonzini --- arch/x86/include/asm/svm.h | 3 ++- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/svm/sev.c | 21 ++++++++++++++++++++- arch/x86/kvm/svm/svm.c | 8 +++++++- arch/x86/kvm/svm/svm.h | 12 ++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 728c98175b9c..544a43c1cf11 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -285,7 +285,8 @@ static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_ #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) -#define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) +#define SVM_SEV_FEAT_SNP_ACTIVE BIT(0) +#define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) struct vmcb_seg { u16 selector; diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index 9fae1b73b529..d2ae5fcc0275 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -874,5 +874,6 @@ struct kvm_hyperv_eventfd { #define KVM_X86_SW_PROTECTED_VM 1 #define KVM_X86_SEV_VM 2 #define KVM_X86_SEV_ES_VM 3 +#define KVM_X86_SNP_VM 4 #endif /* _ASM_X86_KVM_H */ diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index a4bde1193b92..be831e2c06eb 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -47,6 +47,9 @@ module_param_named(sev, sev_enabled, bool, 0444); static bool sev_es_enabled = true; module_param_named(sev_es, sev_es_enabled, bool, 0444); +/* enable/disable SEV-SNP support */ +static bool sev_snp_enabled; + /* enable/disable SEV-ES DebugSwap support */ static bool sev_es_debug_swap_enabled = true; module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444); @@ -288,6 +291,9 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, if (sev->es_active && !sev->ghcb_version) sev->ghcb_version = GHCB_VERSION_DEFAULT; + if (vm_type == KVM_X86_SNP_VM) + sev->vmsa_features |= SVM_SEV_FEAT_SNP_ACTIVE; + ret = sev_asid_new(sev); if (ret) goto e_no_asid; @@ -348,7 +354,8 @@ static int sev_guest_init2(struct kvm *kvm, struct kvm_sev_cmd *argp) return -EINVAL; if (kvm->arch.vm_type != KVM_X86_SEV_VM && - kvm->arch.vm_type != KVM_X86_SEV_ES_VM) + kvm->arch.vm_type != KVM_X86_SEV_ES_VM && + kvm->arch.vm_type != KVM_X86_SNP_VM) return -EINVAL; if (copy_from_user(&data, u64_to_user_ptr(argp->data), sizeof(data))) @@ -2328,11 +2335,16 @@ void __init sev_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SEV_ES); kvm_caps.supported_vm_types |= BIT(KVM_X86_SEV_ES_VM); } + if (sev_snp_enabled) { + kvm_cpu_cap_set(X86_FEATURE_SEV_SNP); + kvm_caps.supported_vm_types |= BIT(KVM_X86_SNP_VM); + } } void __init sev_hardware_setup(void) { 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; @@ -2413,6 +2425,7 @@ void __init sev_hardware_setup(void) sev_es_asid_count = min_sev_asid - 1; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)); sev_es_supported = true; + sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP); out: if (boot_cpu_has(X86_FEATURE_SEV)) @@ -2425,9 +2438,15 @@ void __init sev_hardware_setup(void) pr_info("SEV-ES %s (ASIDs %u - %u)\n", sev_es_supported ? "enabled" : "disabled", min_sev_asid > 1 ? 1 : 0, min_sev_asid - 1); + if (boot_cpu_has(X86_FEATURE_SEV_SNP)) + pr_info("SEV-SNP %s (ASIDs %u - %u)\n", + sev_snp_supported ? "enabled" : "disabled", + min_sev_asid > 1 ? 1 : 0, min_sev_asid - 1); sev_enabled = sev_supported; sev_es_enabled = sev_es_supported; + sev_snp_enabled = sev_snp_supported; + if (!sev_es_enabled || !cpu_feature_enabled(X86_FEATURE_DEBUG_SWAP) || !cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP)) sev_es_debug_swap_enabled = false; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 535018f152a3..422b452fbc3b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2056,6 +2056,9 @@ static int npf_interception(struct kvm_vcpu *vcpu) if (WARN_ON_ONCE(error_code & PFERR_SYNTHETIC_MASK)) error_code &= ~PFERR_SYNTHETIC_MASK; + if (sev_snp_guest(vcpu->kvm) && (error_code & PFERR_GUEST_ENC_MASK)) + error_code |= PFERR_PRIVATE_ACCESS; + trace_kvm_page_fault(vcpu, fault_address, error_code); return kvm_mmu_page_fault(vcpu, fault_address, error_code, static_cpu_has(X86_FEATURE_DECODEASSISTS) ? @@ -4899,8 +4902,11 @@ static int svm_vm_init(struct kvm *kvm) if (type != KVM_X86_DEFAULT_VM && type != KVM_X86_SW_PROTECTED_VM) { - kvm->arch.has_protected_state = (type == KVM_X86_SEV_ES_VM); + kvm->arch.has_protected_state = + (type == KVM_X86_SEV_ES_VM || type == KVM_X86_SNP_VM); to_kvm_sev_info(kvm)->need_init = true; + + kvm->arch.has_private_mem = (type == KVM_X86_SNP_VM); } if (!pause_filter_count || !pause_filter_thresh) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 9ae0c57c7d20..1407acf45a23 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -349,6 +349,18 @@ static __always_inline bool sev_es_guest(struct kvm *kvm) #endif } +static __always_inline bool sev_snp_guest(struct kvm *kvm) +{ +#ifdef CONFIG_KVM_AMD_SEV + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + + return (sev->vmsa_features & SVM_SEV_FEAT_SNP_ACTIVE) && + !WARN_ON_ONCE(!sev_es_guest(kvm)); +#else + return false; +#endif +} + static inline void vmcb_mark_all_dirty(struct vmcb *vmcb) { vmcb->control.clean = 0;