From patchwork Thu Apr 18 19:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13635382 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 47790C4345F for ; Thu, 18 Apr 2024 19:51:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CED9C6B00BF; Thu, 18 Apr 2024 15:51:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9D8B6B00C1; Thu, 18 Apr 2024 15:51:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF04E6B00C2; Thu, 18 Apr 2024 15:51:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8FFA96B00BF for ; Thu, 18 Apr 2024 15:51:42 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 487281611E7 for ; Thu, 18 Apr 2024 19:51:42 +0000 (UTC) X-FDA: 82023697644.06.AC2DB51 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2053.outbound.protection.outlook.com [40.107.94.53]) by imf30.hostedemail.com (Postfix) with ESMTP id 1AD498000B for ; Thu, 18 Apr 2024 19:51:38 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=J9pRdm54; spf=pass (imf30.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.53 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713469899; 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=yfnBRerh84lX79KgDu1QivG4zQ+WNBvzqc2nelqJ+IQ=; b=5MYW5WGg71I25IuT1Pqq/mhyOo3zYMbNXL/1k0bpgSFQvkYk1L2qRfNuLfiDmcj9MJyXHw 1U6H2HZInI/UZXH2nkg+ou4HduWU/7974OOm720oM1Z/eNbSzv0+/ISRRcuEdsS94gPisz o750UUcalxe1NltXG81C1qDxx0RR1Lo= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1713469899; a=rsa-sha256; cv=pass; b=y9X2CXDPDj4Sq6UFkVlKWznvrcRaNRsOGyDAiwfVG71VJxjN4P0Ak9Krr6d8j1jAiJ4sRY IlrSx1v/GVm0RhqzxoFFJybqUkuM/4E0/YqDeshId3IHDwZhl05QekdIWEpuytP9GXt/0H wvqwqGGgHWvKwoA4swC8w1Xb2SjP3wE= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=J9pRdm54; spf=pass (imf30.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.53 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F4WStGftB21mQdIaj1tOK+tJoQTUvToPlbCC765iuedj4tfEAZxh96cF/FRIEzHXQKRmk8Y8tzcnWj+N6XK34w5hFFhXeNcrKt4rIlpSkhe705oNP8rKht8izOtXCLVUBhVfOtkRI6xMhH3DejSOG1D8V2q7YanLa5L0wAq+lTnn8/og019Dv39LKRjv4Uqq3JQnTAsBvQSuUeNWsPKxfdbqe2nB9KsRZDUQ8EeC1388dx2y0viFGu41YWCkNhTE41IBSjhzXHmzL87Ve0qVt5cQoyRY2Y5TySf7qeO64F0Bs2XIIFS4PLXJ5JEAa/8GjO8AQchUrrccCKOTpDxaXw== 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=yfnBRerh84lX79KgDu1QivG4zQ+WNBvzqc2nelqJ+IQ=; b=A/+5sABa9CrpGVnrEYiV1BnngkEK+qWv8cn3AnCw8yAGVEWEX2pZtmF7OJ/qURKL8hGZo/NXLoRWJ+sb4m7sVUNtNFdqSKi2IAhpTWlalkXwXWCLfUut8tlBSN8LVu6BA+HFVaMOr/jhWOyLpUgrF4lh9MkaHOCY5NaTT+LK9FyrClp7i+6noffC8UCjmJNki10RBTyf7UdM7Mkeu3ESVYzTL5XyhdqNa6cIW/ChEn0Vr6eaxnRoqez8X2Azfttq+S6DWoWPBi9gMDf/ZX2Wqqz28FETMD0hc0Jr63/VFCKMyfcISIKJw4m1KsJPjbMDuqa3BB6in4i1xCLBmKg8rw== 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=yfnBRerh84lX79KgDu1QivG4zQ+WNBvzqc2nelqJ+IQ=; b=J9pRdm54CXaFQ3RUr9iEStZD2jyk5A0Gojdp4D56gujDxMvUJ5ztp0iArf+afPtqal8omQPiYHXrVRyyMoeMPzCh2VXlObg+PyQL2oLfw2VKVhVz5sSx2V4lErQtRS3UPCkuc3qafzAucew/Z0+D47RfNrRvbKaRqqfkRsRM/aE= Received: from PH7PR17CA0012.namprd17.prod.outlook.com (2603:10b6:510:324::12) by SN7PR12MB7156.namprd12.prod.outlook.com (2603:10b6:806:2a7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.55; Thu, 18 Apr 2024 19:51:32 +0000 Received: from CY4PEPF0000E9D1.namprd03.prod.outlook.com (2603:10b6:510:324:cafe::c0) by PH7PR17CA0012.outlook.office365.com (2603:10b6:510:324::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.28 via Frontend Transport; Thu, 18 Apr 2024 19:51:32 +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 CY4PEPF0000E9D1.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Thu, 18 Apr 2024 19:51:32 +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; Thu, 18 Apr 2024 14:51:31 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH v13 08/26] KVM: SEV: Add initial SEV-SNP support Date: Thu, 18 Apr 2024 14:41:15 -0500 Message-ID: <20240418194133.1452059-9-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240418194133.1452059-1-michael.roth@amd.com> References: <20240418194133.1452059-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: CY4PEPF0000E9D1:EE_|SN7PR12MB7156:EE_ X-MS-Office365-Filtering-Correlation-Id: 4733027a-16a7-4247-2244-08dc5fe0f281 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q0ASSbb30cX/sFZDhkAr9Y/F1hNBZpqwMT9k1NRYuAhFCWZmnvYEfagWFQtoAoNmculwugkLL260hVRW4k9zfnuTrE6dU4UwEyDnKMbDxBncea+o7QqnC4+iRiNUX2UeiikxwLaS+oRMYYriiYmEUfSg79PtfF0eiVa+SvOlSAkJa6bwhBY0ipkyiJrQcjLArhUW3+PdkU+shfwUCSUPSVnCm+++0LOo3rr+giaR0InqV/iLVuGefe2CvjUVcyFTesN91DG5xrT/yNvbljkJnIJG3Et2docpE+ZQz3Z1of4MtsSWhIvgh1QoXXUhn7jfMM4+OHz6nQcKeL8CyV2pLvMZaAw5v8/esMmZVmyZeNxEkU3D7frtkdWp250lvmGziF50h87YIM19/Bh0JV0FiN24DZLRmKkl9zShP1GFcrCK3cQ3rW0GpVHf7y0/x10IEZ9HJZJ8nmcwkJKJxvlaOr3XEWQUpenJHglPs1ojIL8O+9qWb3FFo2SWLjQLlb3ZJIycsF/fcDzTRQ/qKQ8qeTlhz6hlnvcw2TnReAhK0cyDSRCwLQ+08AS1emIdIWzAW9oQYN6P4yT8EGBxknhxxnN3TXNVELsKofPAtjs/M5iTG/DR3DWpBYKOLbG5SoCleQz3tYCoG1EN0GvcTWUFuL54XLrMwhd5a6hGIDug/w0SzeeE5nn+KJf1kEEsd1KOKGIa5kJ2TIgbvuBIT3dy6ZJqx5BVaNatxOrkJ2JPd7yL8vlkAIHNKMa935hAhgf5 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)(36860700004)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2024 19:51:32.4692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4733027a-16a7-4247-2244-08dc5fe0f281 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: CY4PEPF0000E9D1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7156 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1AD498000B X-Stat-Signature: cw5b6jyxpbzgujrcmyjkjsga6zfc4k4d X-Rspam-User: X-HE-Tag: 1713469898-811131 X-HE-Meta: U2FsdGVkX1924c/pTxDN44OoH60xSH09qZm7FQkuljQ+c/86JM6RX+BGedQd8Z+PdxlyAqr0TCNUlZvRg9bNQNBCxYk9QLVF/pl2AqYJWDcB8Ew8IzXdbYJUQrDcHVOm18DQEWQBW4u8lXBKIS99l2CU7SXc1G7Fx3zfOcRGsRVtoSM85CZdycOEJm6vZJnfAj5gsgEdH6zXV6lTtlNH2t+zsm1b01vdLMKUSmSOcDC7G9GrGW0nQ98VWAoxUxPLqVdV6wSIzejVdfrn+gE/YukqN2LsrjJaPdx8GGS8SzCSBT/iUzFEidIDwb9f7UaiXlaSPECmzqPdUsobc6txn0mxbE5B/00QZGfL6XFCBmueLU/EwKCECCuTQRMUw4klBzTxliRppdrPUlvjvY9FDZTQpLK3sf+RPKCmo9V17DEUtpAqAQr6pMum/pPwUwYT9ORJ8WB3wCZG+6JUBuQRY8xQDDfZigGfg2Mggd40uEPUyGaKhSGKFFu1bzI7KLswb9Deiu43k1AnwECuCdb8jsucwDm2P3csimObTuj9WZpBN6wdQUoeSF1Mbwu5ytEFDxzg56eM7i7RVNHBThTvI/wir5gCLm+OkAQhI01cgTqomn43YMDgtfpnowRSwUjWgDlyGqIyWtluq3gfH+KO7opwhLGTmOi7/p2q9fz/PeZ2JxBPQmJiDH9pebgbnyoplpKeOXlRpzQfxXRU3KlUq4E1gyXnieI6hA88Z2aLUljYTzrlhBMkDM57sXlbfR+2nYLO8zi1DhXFLZjQNZoYrjn75cVD/g3U+VZH9Jg61O+4jKANJyootw5qVEhTohYmZj4Z0I8Lg5Ud6R15lN/eGj5fy8DytLXPbKvOFI8RQKGX3HreQuCrxh9aOyITVNJgzGySvDJR9Mxm+mEkB4XWNyKKH6ZPUu/rTZh/dn6iJplCMfN6Ri0F3UHTJAMF5zQnAhxJz6cgINdCd1OJkFc B8L8MJlw pu1Mmu7MbwZnHaVxG7gqG1flJJJwr7/dz5O+NrxzBCzP5eh4xZePh8ikfm6dxupgrLxEURYZTg61Sq30Ne2HXlMOnJ6lgiEGE8IHYFpMRmMlVWhWkAM9ghHGpBNI2cHaB812fIVY9n/LA4u834Qd4WoVFtCCGUwW0qYMChftbte4PT1uC7nEGiq/FNm9wedHxI3Q3rvAEuran1H9kpxrATgBWuxcC7fpuw5PQmB3CWQPPntyAzQZ9wdEXULgjBflqzg4RJZHkSdG5vNyqy79pRZWb3hJvr2wPgNCR5HeLrgvi8X4GN88Yz6hUMuTKNDfBFor13kuwJHBdQS+pOCWnW91K+8+W6xg7YpoQ0GDz/snV/qk= 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: 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. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Paolo Bonzini [mdr: commit fixups, use similar ASID reporting as with SEV/SEV-ES] Signed-off-by: Michael Roth --- 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 | 3 ++- arch/x86/kvm/svm/svm.h | 12 ++++++++++++ arch/x86/kvm/x86.c | 2 +- 6 files changed, 38 insertions(+), 4 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..d31404953bf1 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4899,7 +4899,8 @@ 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; } 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; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 83b8260443a3..9923921904a2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12598,7 +12598,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm->arch.vm_type = type; kvm->arch.has_private_mem = - (type == KVM_X86_SW_PROTECTED_VM); + (type == KVM_X86_SW_PROTECTED_VM || type == KVM_X86_SNP_VM); ret = kvm_page_track_init(kvm); if (ret)