From patchwork Sun Apr 21 18:01:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13637455 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 D9477C4345F for ; Sun, 21 Apr 2024 18:09:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71E776B0096; Sun, 21 Apr 2024 14:09:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CEC26B00B5; Sun, 21 Apr 2024 14:09:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 523DC6B00B7; Sun, 21 Apr 2024 14:09:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 38CA66B0096 for ; Sun, 21 Apr 2024 14:09:53 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E9050140A81 for ; Sun, 21 Apr 2024 18:09:52 +0000 (UTC) X-FDA: 82034327424.14.AAE6C62 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2068.outbound.protection.outlook.com [40.107.236.68]) by imf27.hostedemail.com (Postfix) with ESMTP id 0845C40009 for ; Sun, 21 Apr 2024 18:09:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=dw+McJs7; spf=pass (imf27.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.236.68 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=1713722990; 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=jND0rIFSni1fzAPb7rFmVX0m2deMiEZ6Fpm7E+781BE=; b=ScL4oCSeo53+i1qx3VslHyhBADVfaRl75c6lCX535W6vjOf1B5vTcjF9wRwlk6XHz7Ugi7 rbHEpg/0fqDYSsv1GreiCfJrejhuZkcP7QfplVK4z6BVDX+AF8zeRbnc39D7wo35miUcUz HNisMp76mNNc+BPRU8GtDi3XvqhFDJA= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1713722990; a=rsa-sha256; cv=pass; b=wZLOocrXwtbGCCARIJW1MKLAvmsdE+WRi60w+fRrfYHj76yjBVOZp+3fNLI7iXBMDCUGKM ivNLFIMe29THu+Qkim1m7boCy70s8YQx08t3lXPeSbFEa7PVDOX/BQhbTnh7cGNOmcIvPV 4+gjkLxVfUeH3wS2Ex6snSLVxuMHsGA= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=dw+McJs7; spf=pass (imf27.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.236.68 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=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cOkDr7Owd8bltmHWBf/3CsuSG/hpTmZDPN8TfZwcsFNAG+OtPj8nz1PeexcnEowaLsiXvuG2wUpY63wQO9ddQarxTjLaVuXKNraocN51n7xySagJ9xcPrS/5QuiBGj+CXVOnuL6kKAxUXWlaM1Tsa2c25zAVl5pzNlIyl03dUe7IsKwz8/hbuRDp7O4/QSXaQqkwK/L5DnL/iPfPAVCDVgrMenp8irZZwIcX1DW/L0S1tFBSMuzG054dTTzDy7w1Qd7TwNZmG2itf7MAPdrkYeOJb4o/KruHHrtb1tmhwZQ/kG9uyj2MiF2yAQ9ViCR+WQDpDWPbs8fgx90IszpXUw== 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=jND0rIFSni1fzAPb7rFmVX0m2deMiEZ6Fpm7E+781BE=; b=UnDpZUEEAttZL9jOs81v9lBjM9C+VVUprqai/PpV6VI/1wLkfPkFm5VbbjrWEps3Ewm8euNKGbmUVzIZp+u2YMtyJKSXUu4ERFKOqs+WD0v8iTFVnmhSZ8YC7vUVVAjkcgUGerfvLQ01/uPVUStw3mZY5HRD7z0iOCUFw7hWfkcb4vKAB4o7AB0/4hdv4SgGtUsbyipyyp9bY+Bv87rpuheSPtyKcLxZgcq0eqOI/CX8kJhEUy4SpCTuGBfQ8zIcVGMGJvV5X19MT70B+QdIQoRnXp0aOLtIZgl6+q+0ZuYSY+1O1P30KDv+Vk0vboLplHrflr+V4A+JNq9SE41BNQ== 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=jND0rIFSni1fzAPb7rFmVX0m2deMiEZ6Fpm7E+781BE=; b=dw+McJs76Lpvse3/QGtF2piy3q+sKkPjMdMvbKhSabfAOmiETPrUzwltBMa2MRx3LgCOi6rRK0t+djt09kQ22NYsnqyw6fuxcgj1FPg2HosJBJOSpBhkq344xLFP1nOuQVNjwwH0+oXUy7f7D1Zpc2IZHhJzdEKJR48AGIBywPY= Received: from SJ0PR03CA0200.namprd03.prod.outlook.com (2603:10b6:a03:2ef::25) by CY5PR12MB6525.namprd12.prod.outlook.com (2603:10b6:930:32::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Sun, 21 Apr 2024 18:09:46 +0000 Received: from CY4PEPF0000FCC3.namprd03.prod.outlook.com (2603:10b6:a03:2ef:cafe::3e) by SJ0PR03CA0200.outlook.office365.com (2603:10b6:a03:2ef::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.31 via Frontend Transport; Sun, 21 Apr 2024 18:09:46 +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 CY4PEPF0000FCC3.mail.protection.outlook.com (10.167.242.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Sun, 21 Apr 2024 18:09:46 +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; Sun, 21 Apr 2024 13:09:45 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH v14 04/22] KVM: SEV: Add initial SEV-SNP support Date: Sun, 21 Apr 2024 13:01:04 -0500 Message-ID: <20240421180122.1650812-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240421180122.1650812-1-michael.roth@amd.com> References: <20240421180122.1650812-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: CY4PEPF0000FCC3:EE_|CY5PR12MB6525:EE_ X-MS-Office365-Filtering-Correlation-Id: 3bb56b3f-0b07-4dee-9607-08dc622e3a2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N9uJPWQfKD2LksVi60ok3FruV3KGaWo5O4KpE+QDzQZlairD2IKOsUdnQ2FXI9HKc6XQQh+F4TZfz7/C9nStlqBiLQ6XCf9cvP2AQvceYVXN6ua+wxI2UZuvLsnuzV8yo4vSrD5cqjvqJGXmjU5KNTng6sxTcuF5ZFdNhZ+C52ZM31RLfy7/YTdzzMGUFTTMj4iA6wBB7TlzaDLMRtg7TRs9NJ2ih9iWQKcfvveS673WlQt+wlzLMPAp8b4cieYUvRnK2Ch4Z5nbtl+srYjcqiZ8ITsnGfcvRcQPSdNfStyB/g6dC27G617Z4fskoLEnRP37pHpSu9X6kXbKHNny0epl+/YjR1y3DfuFNfknIBvrA+33Odjc640tEUtrwv2aOGU/10OwgymlSWZNHZHlIieZ1VK34NbK25IYoZmc7uLQGQduSXLyQBZKxj1J9XgUTaejYR2xk75WwmfPYQPC6eprSHW4gvgfb9mBSkjmKvCN8YKx9aHJ5fBMW92JIoaN2lXyNaonOc1Vcvgh/e5N07BnB6xZwLyMetvwkieYHIaqlcP+Sd8Av/tt36sMrhBieR6o2WmluiKuyQRnN+qnhktGtpltCuzo2SW0kqEQlGO5CHsCsoGxG8l9jiPoa4jizC0Mn64kpAp35x2DGbjus+WXnpaw1OGCQoK+5RXZifDLTUyS83BZXlUPH87LG4N3Y1msUuVmATfr41gxuzi8WglH2dgDDkoGY/mCICSR1TAhu/HdP1yVEuCo7O2bMWFOWDWjVjG2QZkgrB6BDvuO0TVdg+CbkiT+WScESB7ca3f635MsvDlo0IXeDnw/L7A8PS4AnIect+6kvZKDwVt0xSV7v8r8D5nMK3+CC/FKtdztQisL+5P6JpY/I9bZolMMz3uRNUDOTFlu5YYv7gPaNQd8xBdakoPSFtcj5K/ceFseWv5wKBPDnODnCSIaYy0Z/rBVs9FYWf5T8RDpABfLB7KbJl13qnUTHN9o7CSkIoWxRXRNc0D8lMgpsmhiYtGDGvaS2iTvUPXjazPbZ+VBbMFD7xtPbILN14POoH5gCSS133CshEfs1MJChWcvryFkCYDRRGWQgKQuO5giHVZWq99iIp27ykdVk9G1ZenWn6Evk27M7JZatSRLPruKG8xPmCDkWbjHHDDirb2+ZeODo3GDHWzxM8N9Lz5eCTOddyv8dyvDWY3Btdl9hjylJfBitVOFr4yqoRauUXafyTtzqLLYksHwlZ5HKicGjS1kwJuvoQTUAwwmFl1t4rUjnzxObiS9KpPo06reht1UtSu7/TXXK7HoQ1gkEumIrcHPXaFj3qMSWmnrEjeUM0NPZqFjJgDmpmKSw89c1OK25tbOR/j75Cbmx0dXbdqU9cPssWK4wjEEfOXjbhfAbYUEdDRB 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)(82310400014)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2024 18:09:46.2692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3bb56b3f-0b07-4dee-9607-08dc622e3a2c 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: CY4PEPF0000FCC3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6525 X-Stat-Signature: pwszi36wtmj6q3s6nakmfj7okefb8wtb X-Rspamd-Queue-Id: 0845C40009 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713722989-955813 X-HE-Meta: U2FsdGVkX18hUGVE9vWsAdh/6ygAF4KaYhKmaRHQu4NaM2xANRlse5CmDgv3LbrK0/D488xxajbaquTUOjf6ccOtnNhkLkpDN1LCTsODJ9Hj2Dyw+w4Yh3UNl4v03LfoGzY9LTELccr8SdtinUrMg/1oTNb1sCJotQ8wd6wghsoarG1S82mQuvmd9HfCAHYMeB37cWU2qEXiNGW5nCQPcH0gt5aLf7fvJaXjVMtaKwUa4/vEETTel4c0QeFvJ2tnG0bp5APUDDmk4pyXBjJWiQdq4AYND29Io1NcU+VLG9ia6wEncU1FlS86O7NyNxaJ/B9fdY2i9JfqQhK5K03qqb81JJMk5iyBrjJwfT9fCwYM6yjF4FKS49coI6JsGZozGXTHLjFivjk9A+MtUnYgMAk6vLsh2vp/7+0/gtC+fsIrYCuJVpZ0EJpne3XuUpGOIDPY+EU0qcwoXr4wzt1Dmd/lMG3ihr5pVi3KRVgZgibVPqx6hF4KsrAkDYf+7/hJPNHv83AtbtM3UDeAXs29k9qllYQ/pJKPxbmZd5qOmw1iwl0r7qjwFHbjDLWYSB8zWCSj8xG/gsKO4TlihiIGqSmw6DCA3cTf0L1Q78E4n+8Qbvo7i3RAeLd7pEc9+IjeUEw0XAfmhu1oOh2bB5H3jFdREvXFKhHHp4s7OFGga+q0RfvMwx2Zucb9NY1bZs5MNObqYNn2t13jf/NUnSDcTZW183Hlzml1O+d0+j7+CmKgslOrJoXqatT4D/DNCDO/X2CKCmCGDml4H/UmwXjeQL3jS1VWuholYlAfuYMOGfN0n99u0W4ikY98EbFUxd7K61nBQNT6wEoy97mdxjATuQWJQlfY+5x7Ac/HjoElx7kgL6mzoSin96iwBKGjg42J0xsN13r8SZPorJeywykSq8OnGGY0o3/va7/kVeGRfXFmr4xpsXlC9jd2OCKsliGKhx0itgODmguiAhcIlvh H67zFxUd fkDX/QZGEg0cHJKJ5ogfnMfpPeTM0aT7CH1xxgxzpX4MJqrlcQ1DhkeonbzijlTeKmbMgU5vjl07rajV8WDuWuxnssJKE0WrEA11ZBSPH/DHkG+EpkjLGCBEffiUmyr2dKg98aX471bwi6qj+M8NH+98eDXblPtE4GBd18kDtOGFL9h9qYVoZwcqYc9bh4U3+Rd5JzRIDDqYl9PlBOBqAKnCUvmvIiUDiy1lc4o560T2UZ0kOA36xjaWPGXrTyqF671ABNoKBpAwDX7p3RzuSfTd/ZDyk0mObo7BkbMIn0VRchduMYjk4nTmaraQtMdbL98I50klHLWIg28N8HFuk4l0zyZrc/4r8akyjiT7WHAAZOFM= 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 72ad5ace118d..9a8b81d20314 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -872,5 +872,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 1d2264e93afe..c41cc73a1efe 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -46,6 +46,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); @@ -275,6 +278,9 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp, sev->es_active = es_active; sev->vmsa_features = data->vmsa_features; + 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; @@ -326,7 +332,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))) @@ -2306,11 +2313,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; @@ -2391,6 +2403,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)) @@ -2403,9 +2416,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 6fd0f5862681..7f2e9c7fc4ca 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -348,6 +348,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;