From patchwork Thu Nov 14 23:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875768 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2059.outbound.protection.outlook.com [40.107.237.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8BCA1B85C2; Thu, 14 Nov 2024 23:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627688; cv=fail; b=FMrtfYYu4tsruZiJL+/dhVl0P90Bc2jX3fFZ0VL6r2jKkJ/FlY8YRtVpHHWLyF1TroKx0Ni8qasWFXmXm4GHLTmsYb6Vd3saQYv+/gp6mHi69CbAkBxLoIqIjCJm5nKjDj4PcLGrRpnWJYe6vG4LdGo2JJy35BU32Yy3bTEeLlo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627688; c=relaxed/simple; bh=yHY3EDgDUdTmYX3YgFxmZGHuQqMpDnoRBky5uCUH1YA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DNLuiEgZ3ufLkUw9kBwUx0EoSVQD8X7HCrcalw2OGnXWvrlqgPyu36PcOSj1zZdeYzbF1moRO+ZtU7N/+wYPfq51iAKt799llOsJwj7Ti/Xbh7k2hHER3UtGmV78PXfOVVQykpsvVKPQ+W3BiaGfw2Stp6J4nK28IFYlPUkVUeo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=xq8oFTVF; arc=fail smtp.client-ip=40.107.237.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="xq8oFTVF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q4CGupI9vd8d4PwCgSeXs4gXsYq8Bn3Cj382H8Oa/VY64ypY/5xDFhhnAlhe9F+GAdD2yWFLI2mKAbwhNySHC9ybzdWCc8CKlJJUawIFURyDS5fXQLUSc74LThNPLCCnfO/Ugx2Eb2dUcN/NDHJpCxaMqYG+Gf0CJ3HNKV9qKViGnopIZrmvkeIpdj2kx5ziZS1NOV0CBvvDw7MfPwzCokTrGM8NG/MDiu9mKvDv4SP/njzS7/4cSJpn8grmkEXhiHpWrojDwLsfISN6cpqBIMVOUlsDe8DDr8DcJWAOAn8PJV0HNB5Ef8Z7w7CYqujqtAqpYdHeai6PBTm5g1iGwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=afyHDxG922NglCp6p2wbKPTnduMg5Jic4JTKLkdAQQc=; b=EMcOmKsNieYZU7I1u+hC+67lze61IYRf570IUNxKpzatPwGUIbxFXEyaPJAK59qdJ1/uOrU47L3VESudeX0pDqGpJ8ylvmV02zMYaApg1BXrjYWwuiUFOvr0W3u6qkLDS3Sq2GrS4n95HfpHbZMl/MuY6WQWOJndBuaxeTCu/E1fliXVbULgc0ZROSSK2dS6tKEZjzPwbij46LA8+F3dlZFjXFp9GfH8HxbxfjTwYBp2rXL9lX5SC7MJy911pCfgdbR0bN67u4ftnMcfCGSuo9gLnjbZbK6A6IIRDn2DpiD3O5+SnfuzkOz36xx83HiRemP64GRehFBdQTMzv53p/g== 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=afyHDxG922NglCp6p2wbKPTnduMg5Jic4JTKLkdAQQc=; b=xq8oFTVFYOByq55BvkiU27LA/Ntu5gt6wQIC+nvJ/CYY0XihVhUQhMXN3HtXm3Wgy7YJM6Bj2MZTr0dRhb8uMdVlZwRKZwDUeG1G8Kq/KXs9fztpbk/doViUIaxXq0vB8PlQvNKdXMCQmtJ8oeb8dtoDWY2jVsLtL6sh2GqOtSs= Received: from BY1P220CA0014.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::9) by DM6PR12MB4370.namprd12.prod.outlook.com (2603:10b6:5:2aa::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.19; Thu, 14 Nov 2024 23:41:22 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:59d:cafe::1d) by BY1P220CA0014.outlook.office365.com (2603:10b6:a03:59d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17 via Frontend Transport; Thu, 14 Nov 2024 23:41:22 +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 CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:41:22 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:41:21 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 1/8] KVM: SEV: Disable SEV-SNP on FW validation failure Date: Thu, 14 Nov 2024 17:40:57 -0600 Message-ID: <20241114234104.128532-2-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044F5:EE_|DM6PR12MB4370:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b2a70cd-673e-48c7-61c4-08dd0505d8a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: h1P2Xe3kMig6/Z5AnCrQQCnEy5kONU/lTHvvShkXJji95FgGFrbh8Bj+u+5rCHI4wY68RucmkRk18w72TBYvFmgtJNhN3iSyoghZpgSMiG4v9Lu6XKWZqW+2GLNqz2BqmtcmnAxTfkNieuqsP1/CeLtog7gmFVkfM4RI0lUvkxkzccJFMczf0TkqgpV0ehuwe6P7O+0V9oqkIdk2v++Q58pnDXXxCLiAPYZxrX6MW8/99zFbw90kRPOt1g43S8PkNCZvgSW2P/PWKEoYnr1Y+wolMXHXby8cyEz+eae2XHWf5ue+G1jSrm/D6YdpsqAOYV+MkUbXgLVIXIjZYDhU0rAx/hUmFrTB/UGUaXug/28fb8pBF3K0yX56TXqFBi4Apk0pWGD5/Rx5tVKKtQRrKRfgGKKpIZLHevd4CELkW/PGjYjmPpOUV9FkGt9t22ZY38U2ASvr1qFlKn3bnXBE1x5AIhgA6TwdMx7SugSKyd5G+BPsBDeFifePhCjtZ3c8pKoXl3Nn5jdyjKrzZgLeNYkJd09g9jSb2RdvSG2MyTavkOfSvPW2/MTRmM/piEYQq/JSyvdT0btbOj75YTeBFMYX3+30ijymLtz7Td+5CsXCds7PpffiyYJCiAA5J3/9gkMlFX8Mcdynvlpzs+h/BF/Qv/bP9LqsajtSstKijhqczKBOlx+Cl5J8TFNe3BayRC07jEcsGspxZtKn5Zc91O77O0HpBSwpspV30f3pq13ZZoJ0Qu7ny4aWZd35zmB7D4l/HY+JfdgUMszNiOfrRfoS/+aaUZ/41HkjS8/1TppgPsaymbUHvkKBskbi8lo1lFcviHQ3Heqoo7XsyAd4GjjAmvWSrvIReY5y+KhA7W7GmqnRvMBaUzn5QqJ93bC+Mx2j+O6AtEHiYphNMqL2c4jc1mWWeNVJU7q+DPjLUn94U108Q6F6EBGTuN3kE2yGqmFzAagoDU8GF5Vp5ommMrIYr3GmlLb1n2uwFhqOnxuQWR0YGF7ieb20TnZhaufyAAUBBIto9CnF2BFvNdxe0yVbZV1UywK1TjHMWDLUdmLfZ3JNvcQOF+ybDdXfyT70BJDC4FvJC7n4uJbErrn7rOpkm6hWr4kdQpGHkLekfMJip8uu+ePmH39ql0DDJ07x94v3viDFnUrQp/rGs9gnIaHksQrSacUeszdouyTKcHDGdYLVcKz6D81TGTrn3PRxH3hrTRJlVVRXBbfezrkvi4gesYd21kOOir9HGlVX3Y5InpRGdI209DvqgxYlnZEQCXRhZTzIJBrMAEyBVG4euWIMB2lVNuzb/e8L5h2QuSg00kFXsd0NVe2l18gVl5BKrjIEI0w9qAXoV9K58rSsLcGaFRqY/65n7As5vG6AH5bZl5THdbGRDQgNTQnDFv125z3AUOzIA8xxA5Pu8vRFJg== 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:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:41:22.2255 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b2a70cd-673e-48c7-61c4-08dd0505d8a2 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4370 On incompatible firmware versions, SEV-SNP support is pulled and the setup is not performed. However, the platform and subsequently the KVM capability may continue to advertize support for it. Disable support for SEV-SNP if the FW version validation fails. Fixes: 1dfe571c12cf ("KVM: SEV: Add initial SEV-SNP support") Signed-off-by: Pratik R. Sampat --- arch/x86/kvm/svm/sev.c | 4 +++- drivers/crypto/ccp/sev-dev.c | 6 ++++++ include/linux/psp-sev.h | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 72674b8825c4..5ced00e54f0e 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3053,7 +3053,9 @@ 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); + sev_snp_supported = (sev_snp_enabled && + cc_platform_has(CC_ATTR_HOST_SEV_SNP) && + snp_fw_valid()); out: if (boot_cpu_has(X86_FEATURE_SEV)) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index af018afd9cd7..b45cd60c19b0 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -122,6 +122,12 @@ static inline bool sev_version_greater_or_equal(u8 maj, u8 min) return false; } +bool snp_fw_valid(void) +{ + return sev_version_greater_or_equal(SNP_MIN_API_MAJOR, SNP_MIN_API_MINOR); +} +EXPORT_SYMBOL_GPL(snp_fw_valid); + static void sev_irq_handler(int irq, void *data, unsigned int status) { struct sev_device *sev = data; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 903ddfea8585..e841a8fbbb15 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -945,6 +945,7 @@ int sev_do_cmd(int cmd, void *data, int *psp_ret); void *psp_copy_user_blob(u64 uaddr, u32 len); void *snp_alloc_firmware_page(gfp_t mask); void snp_free_firmware_page(void *addr); +bool snp_fw_valid(void); #else /* !CONFIG_CRYPTO_DEV_SP_PSP */ @@ -979,6 +980,8 @@ static inline void *snp_alloc_firmware_page(gfp_t mask) static inline void snp_free_firmware_page(void *addr) { } +static inline bool snp_fw_valid(void) { return false; } + #endif /* CONFIG_CRYPTO_DEV_SP_PSP */ #endif /* __PSP_SEV_H__ */ From patchwork Thu Nov 14 23:40:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875769 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B4751B3954; Thu, 14 Nov 2024 23:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627700; cv=fail; b=TXerQAVO/JUPMDihIA6KLSRIXr1rfFGCOT2rNn+OjR5SR7lphOYqEQPSOcGDiffCX3HcLPA/ChfxRo1S7OHwIn7yVX+QeJj6pPFLzbraUYHz0r3K3P1W4cvd2PpopalmFuivUi1LHGoaC8NgnIqdaedB3B+3LXZNz6zYszKebMs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627700; c=relaxed/simple; bh=L0i8oI0Z8goF1p6yqmbrPMSQC/9WxBa4Ko4+iQdRopk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qkTO8jzH+KfxsSLfdRGy/L/YxEQQFGC4gA6cKuwxh+zu53YtxvXDsSZ/rg4T1scSqZduwybUo7zdpSR5ob21rmzQtGbkaUji4Q4euV9eZMWjKPvfAwSCNgL1Kai6m00zf6B+e+Dk5O2r9uys7pfR38ehzH86YxuAJvzHMtuS5UM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ICddO8nG; arc=fail smtp.client-ip=40.107.236.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ICddO8nG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fgo+jO/12na7cRoBdquvzFc/F8/+HQMZ5yFGhKNTyPu3PJPEBWzZjRliH0XVFy/yo5rQKT0K9YBEvbI2RNZh/A0lfwQEJdv4BE8DqxoBx6NGi84ouYPQEjoQoDsk5zyikVwxPT533fJwCrHuG/YGnP8V79grMx9G6ANtyHNskmQbPo1eZ8EVpanLgUcMmAYICp3tD5gGpDeaE0XIGKZCWwA59eWlx2dT8KeLpVLjc+L06xdhoVGTewVMKIUmYKbeHiCpGEcNuzABQzhis3TxiLHC250Sl7eJXCDR8PLPgmxz8ioxvJ6oiuqUvgvOIP4dHaHX4zQc979/QOE7rOYEag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=zLLgD8c9NJWyZ3R9G8OLznuY+bO8mOZsk80XyIH7LTY=; b=Z7fnAbbHimCXb+RbVzWUPIyboICzAhtRCsGwVtpbSY5p2HfeqLX+qfOd6SXljz3JTpbxrXnkOKRFdJL0i8NyLvx7t908sqKU1nPXWfSo3gUELKNLRigMgWQXI8ayfZ3nUeMXqKmWQbBuzKmfZcGafiaW6pLFZ8VjcxfDt9HZR6ztAty1Oha7/DbUDcsVVxo7jgKGa6FaTzrEwS2kGHoXGHEpdw9GCuNehdmxQrpoHIn6pErXSIR7D8iJCoXEkToYCXWId3As4LnpJsbcfpCmczv82Uyg1uY7nds4osJaYSwVUI9cP+EhP5YmPRsxWZdeGQBENxuF0571ZguQ94LK9g== 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=zLLgD8c9NJWyZ3R9G8OLznuY+bO8mOZsk80XyIH7LTY=; b=ICddO8nGRxS9IeiacrnQ+heoAjuglM8hCZBrgNKtSQpe+6Ki7UuRdmS0tGTzsHuJBG4SdPeQ39oqKFxas0F1yxb2eHVpG1AgrpUVQTAcYJ4vZTSMQxV5ceTNc4NVCiZgT4Cwg91021AnYs8tUctbokjyhbg1saTJGn/lxt/IOPo= Received: from BY5PR03CA0005.namprd03.prod.outlook.com (2603:10b6:a03:1e0::15) by IA1PR12MB7640.namprd12.prod.outlook.com (2603:10b6:208:424::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 23:41:34 +0000 Received: from CO1PEPF000044F4.namprd05.prod.outlook.com (2603:10b6:a03:1e0:cafe::7f) by BY5PR03CA0005.outlook.office365.com (2603:10b6:a03:1e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 23:41:33 +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 CO1PEPF000044F4.mail.protection.outlook.com (10.167.241.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:41:33 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:41:32 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 2/8] KVM: selftests: SEV-SNP test for KVM_SEV_INIT2 Date: Thu, 14 Nov 2024 17:40:58 -0600 Message-ID: <20241114234104.128532-3-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044F4:EE_|IA1PR12MB7640:EE_ X-MS-Office365-Filtering-Correlation-Id: 975c1e84-a661-4b34-c065-08dd0505df5a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: 48tZCFVnveGOQ23zuxMpwtUGpAKBK02E6r5ZztssPj0a6yrDOEPzS7gxzSJrYTmozaEXwhWz8udsOu3Ar1QrWNiv0U3GkLsWc8SF3ksiIlCVoVh8MU/l8YSSNvxOgfysJahuW0prfJYWJxN3Ob6sCZ1m6nI0AX9O5XjnHpnRrSF4D1RmaOlIxsJeSnoKInA/ot/axvjWXtoetTCjJusaZT77FSA2vAVEWj4V3p9ld7mMcA1ELYsWr8CSaN+aKml31jbRuvYsIofCBuO9vlj1oYbw0AE1D9DiZy5beIo6U+JsWVE3BoKChxSmtPKZr4f4zEtdt5w16HJ0vCeMWsn1I/WiyhDDxmWH7pP8Jwsf2srUw4VSRN2VxW74lS07F6zppdMo7wMsoTRWAS3LAy4HKm1B8TcdgPfFVnitmKxCCjJBM5ThbDJbb0CRujTA1ZbsEEB/VQiw/Hk+glrWaaKgho4ZnIsbepn4gQ3twEQWH01vdPtbhfbVaQzJKOJvSq4+0B9kAf1Ls1eUwNh04zWqA+wdb8q0LEyCah5IT5yBYT54rKQXRrBpFTMr7MOlDYdZqyLhnVOe+YGp4G+sp4EVoZ3IDHVnm5mUHIL2SiEKowHU3EFNvlymzGv48nLFold1z0qdtF3FS7ZG275AxTd5dBN7FcZlJkPmpEXhLcs3PY5c8bYszLp7SBx5f5JFBhnIDEJ5RJh7uDvzRWeLQJ+K6h/Q5MbwJjv8tyWgyjZ17kV9MmwCBOXyqq/PpxVuQuVCoI5+YXtnr2A0oxff31svNZfHIuojScZ11u+tRPcLkEBTQOPTpzHZUGG4V/fBN316kPi9WPbIcQwNwdiPssHYIsohGmynDF2CJyrvIwvMxttq58bMSJsd2YH0z5uAFvVbaYJlfO3IRKCOaPGmpAMjFuBkQyryUUnOgbBrs+QKh24NcyYpg2IImncMUzMijTZFheDqLaFqo15MXSavyrexJ0FOn7Q2WmZ7d4trrsscVTsPqlwVgZFveqfihQFFjye8NI9vKCFJpJE6/txhjVkFyrADQONhWVNRKW6gcSZuVeNnKatzFI9OI3vKh/H+69Ms/TjM4jix54c7FHfxE8QwBrm1RmioAks8mSG/cug1xXgyUoU+35b00x7WZ73OI5iD1kQfhv8tfQKDoet02iwkaAOMeKxQOKENHpjNahZaoDY5kM3wTZBA57Af4HcGJajwBLNbOVqOSeZQwseTzufwib0/0Hjs65nIs5Yl+4Ew5wBhr18739x6PZvUdTV3pn5VYva0G/zATC6yIW+0/pZyUXsjLNSbPR/qHXZt9Fjus1sdmPiXiMTUk58xdFQdKCjfTrX4EeBh/1AiOL7ZHv3z9y6l916t/d3Vfhd5ldvsY7gfvOVJBslU12hqZoRSqNvjz3ZGAvUhXeyU4nM5To+RVg== 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:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:41:33.4376 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 975c1e84-a661-4b34-c065-08dd0505df5a 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: CO1PEPF000044F4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7640 Add the X86_FEATURE_SNP CPU feature to the architectural definition for the SEV-SNP VM type to exercise the KVM_SEV_INIT2 call. Ensure that the SNP test is skipped in scenarios where CPUID supports it but KVM does not, so that a failure is not reported in such cases. Signed-off-by: Pratik R. Sampat --- .../selftests/kvm/include/x86_64/processor.h | 1 + .../testing/selftests/kvm/x86_64/sev_init2_tests.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 645200e95f89..c18d2405798f 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -199,6 +199,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_VGIF KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 16) #define X86_FEATURE_SEV KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1) #define X86_FEATURE_SEV_ES KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3) +#define X86_FEATURE_SNP KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 4) /* * KVM defined paravirt features. diff --git a/tools/testing/selftests/kvm/x86_64/sev_init2_tests.c b/tools/testing/selftests/kvm/x86_64/sev_init2_tests.c index 3fb967f40c6a..3f8fb2cc3431 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_init2_tests.c +++ b/tools/testing/selftests/kvm/x86_64/sev_init2_tests.c @@ -28,6 +28,7 @@ int kvm_fd; u64 supported_vmsa_features; bool have_sev_es; +bool have_snp; static int __sev_ioctl(int vm_fd, int cmd_id, void *data) { @@ -83,6 +84,9 @@ void test_vm_types(void) if (have_sev_es) test_init2(KVM_X86_SEV_ES_VM, &(struct kvm_sev_init){}); + if (have_snp) + test_init2(KVM_X86_SNP_VM, &(struct kvm_sev_init){}); + test_init2_invalid(0, &(struct kvm_sev_init){}, "VM type is KVM_X86_DEFAULT_VM"); if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM)) @@ -138,15 +142,24 @@ int main(int argc, char *argv[]) "sev-es: KVM_CAP_VM_TYPES (%x) does not match cpuid (checking %x)", kvm_check_cap(KVM_CAP_VM_TYPES), 1 << KVM_X86_SEV_ES_VM); + have_snp = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM); + TEST_ASSERT(!have_snp || kvm_cpu_has(X86_FEATURE_SNP), + "sev-snp: KVM_CAP_VM_TYPES (%x) indicates SNP support (bit %d), but CPUID does not", + kvm_check_cap(KVM_CAP_VM_TYPES), KVM_X86_SNP_VM); + test_vm_types(); test_flags(KVM_X86_SEV_VM); if (have_sev_es) test_flags(KVM_X86_SEV_ES_VM); + if (have_snp) + test_flags(KVM_X86_SNP_VM); test_features(KVM_X86_SEV_VM, 0); if (have_sev_es) test_features(KVM_X86_SEV_ES_VM, supported_vmsa_features); + if (have_snp) + test_features(KVM_X86_SNP_VM, supported_vmsa_features); return 0; } From patchwork Thu Nov 14 23:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875770 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2059.outbound.protection.outlook.com [40.107.102.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29CC3374CC; Thu, 14 Nov 2024 23:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627715; cv=fail; b=dIO76GRqPsT/p4C/L2AlAWOTxZ/9gbIXaG5ei5yStKisEz4H7H5r5uSNFA8czBb0sSFaPFWXiGJAagNf/apCrTQ7dlGsgDueBcACtAWuOnqMwvvPgshWYtyME/vbBatGp1mE+Ij2MxLk58WIBJZiUBETxAH/cwYLN+58TEwSPBM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627715; c=relaxed/simple; bh=zgY2rLcfQeFbqyLUA7CqmjFUE/VqiyQix4+kR/9YWB8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d08S4JTc8R8dMPDRKZNDzF407YDxuTDyvHOtlEwH79mo4UUmX9q6eonlnyELzf7mQOWQlQ6fBUD8FdKF/m8zmYnwpYBeQP/yY6E7eCIRd7mqKJlkSA22Id+5wCWoyZoggX2VHbPU/Z84c2yrVKy3cPlOx9/8GVlGvPhsxH4oBkc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=JEeNag17; arc=fail smtp.client-ip=40.107.102.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="JEeNag17" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XmCAdJCOfuQtv6FUKLGR+lFKpWQLecwl085sc4pcWiyyhtXAD8Gpy/Hs6i81PG/S//INlnnuRitt5YjjuOJwJ1ASYdaeqZBLyOO/QdsVk9vqBpf+xXMqyp+45B6oJrIFIirrKcJ6Gy0cMOxXNk4Vbyz/JPpsio8PWVt0WLwP0+XY9DM0jKdWZ/8ng94uzADZX9xqtiLAExk8ZTr1ekC2Tl0/xjOWLy8dBVR1m/R4B2dctFaR/81PguKiLO/LVRJSKFldiawcvaPt31jywLhZUO2yq1bbuHQAL4xwQgFeCQuP7K5cByYwnDjH2hAwdh8WWHw3YDmwRi8k3JYogSuDgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=JrRHrJ6nFFsjRo85R60cfEKQFmuYnHJ5oxdyVTRZzp4=; b=mOQxZnkycGkYLSCUC6PyGt3DnWIO/0x53E4j6y2zcQT0grsfDMBH0rR76SB6a1UW2gl2y/yHJNqOoZZ4RM5Gf3SNd93QEfnD+sf1Vw8MhAs85cXbhUT73M5gcxz51M/MuKOmv3RedEY4Uh03vJUosgKJAVhO2/DnGa7FtZG0u0rhmcnV4R5WPmioXfshbCwsxyFwwDz82up4WzKzOgAhgcR7Ka0Nojuin1wl7REFWQdoSIS0HbloAVQk5xbXwGYqEIxmH2+0dWwV2rQX1SipAECmOE4DXIS2qI5lCcL1nJR8U4xPprlxyZiyicOptcKHJv0qqQH0OEc58owUYLDtLA== 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=JrRHrJ6nFFsjRo85R60cfEKQFmuYnHJ5oxdyVTRZzp4=; b=JEeNag17ONj7AMFzR77ITKueZKH4ouUHsHfYSMT4hqvKX9UvwL0s9r4nbXd6vGXVT2CCgVlOtykmDNVH2w9z8lYq0CQhCC1E3Xmki/qPTHgteR2OoU8uJJITxmit5zD24oOMBgysZSuT3qaiWYhE9X/LdAnnAIP5UCS4auUS2sc= Received: from BY3PR04CA0011.namprd04.prod.outlook.com (2603:10b6:a03:217::16) by DS7PR12MB6214.namprd12.prod.outlook.com (2603:10b6:8:96::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 23:41:50 +0000 Received: from CO1PEPF000044EF.namprd05.prod.outlook.com (2603:10b6:a03:217:cafe::aa) by BY3PR04CA0011.outlook.office365.com (2603:10b6:a03:217::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17 via Frontend Transport; Thu, 14 Nov 2024 23:41:49 +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 CO1PEPF000044EF.mail.protection.outlook.com (10.167.241.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:41:49 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:41:48 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 3/8] KVM: selftests: Add VMGEXIT helper Date: Thu, 14 Nov 2024 17:40:59 -0600 Message-ID: <20241114234104.128532-4-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044EF:EE_|DS7PR12MB6214:EE_ X-MS-Office365-Filtering-Correlation-Id: b38fcf4f-983d-4c50-d763-08dd0505e8cc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: UJl4owoDp2E4VwLiUjM411/LAw3qIlovZxZ5RnkNkFXgZTKIaIh6BwrZcr4AbU1DKeZgC+4dn6RGq47vgdgqXHQUzD1fMWur+7XzEBvPeyUns807mNSxT81CN0PSfMVVxxcEoccKt/ghAQRQnnuwsbf2ljMdqDHTU2NXch7RzcFB1MxnlN1JH7ptfUDeRTTXvpLwMkE8mKMQo3UyY03fUgODRhj7GjPcub59RHThxH79BCYWeFC7FEnXleTCfHPVelWRggAsR1qXAvLQCrGgNosSorlFAEc6mNmt+7aofrTfFs8/lduGPhr7hYkn3T5Rl/QusIjwk0ir88shWRxFAJ/Y3qWYthsU+R8kiAT8IdEi/5L2tjuDwI2om+OOKmxMb1LsCByNO715cknrEG0pZPJcddQrOYT2WANvPTJM/fchZaqXTTpeoXFc8l+BeeqNrmchDvhOHDxJpS8JlJZM1iScCvv+oxUy8BWMA6qIq55nzLZCt6tN9lnM3byvuH/VomZCzUGf9LP8fFOaPFffFleNfcWoCYs+t1Ss5/IMp4lzZh9e2Bw89392WkXjBNFUjKQc4hsjMmtNMGOeFWKQjWG9uNq4k9tv10x4lX+j6gvhh1pYsDw0Mep1Eg1YZ2BmUsrhaks3vShbfb4EPmAZqsWXuRvFRM3qZvdupbK7q5tawJ0ICSfwo7XI1oNrJcNazWY3z4u4IOsGj5zuZ43W7O+4Cd7guwpusM09WDkzRgQOT3GWILGjXw3a6lX1Vnw56xJgP9OljXbYmcaLYtZxt2P5PnXNItqQHHOZ1pAbbR7YLBwn6SP7hNBHv9daK9gcnpxkr/YuBLqT+6vhZpUGHipNSPHjpJTLVGNopIREsoGFvOh861Fd3etnWXvJPO8GYuEIWZSDX01HMJ8oTxnMWoVnl92pfnuEVdlPLNrX1jmCg/0q1RZF+blNtaix9Q1UtraqkjXjFZdTaF3dt9IczbSvZT6VNvLIouzRIFweKqMUYsAyFdK3fw5xIDuZwJhtEcPoaM5XJR3SVeKMXmndOqEVdYhWhgb23awpTIDoomVXWKGgSAEmzKHDBRS4UXXIn0qr7tjBfJR4XZ57U2LNNUeBcYktF0sPtpRPimA+VS436c4/l+zQaPhF5yvZTyNleq1Tp2YjqLqZopSwJa+S/yo2EZAfXeJ0WFeuqYoGX3YkjLYYcAOj7B9KVKqzKaIJvSu9sPTGUsh1Xz6X9YM9G9t5pAHwi/Ltw89IA9itiXAUfSNTSf6EC3vpDt9415qNhdxx6desPCXaIzqwW4uBx+OTkKoJMdhlJEOQPLgburYouMfHV34y349GqIWrabR9GKLxp3trtrwx2k4MeMgkNPWUHXVCriehpS6n0DfF3tWShPs08mPq4R3ZeB7vJV+WB4C1ye/6IV4PQHsI+Kbg5g== 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:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:41:49.3473 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b38fcf4f-983d-4c50-d763-08dd0505e8cc 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: CO1PEPF000044EF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6214 Abstract rep vmmcall coded into the VMGEXIT helper for the sev library. No functional change intended. Signed-off-by: Pratik R. Sampat --- tools/testing/selftests/kvm/include/x86_64/sev.h | 2 ++ tools/testing/selftests/kvm/x86_64/sev_smoke_test.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/sev.h b/tools/testing/selftests/kvm/include/x86_64/sev.h index 82c11c81a956..e7df5d0987f6 100644 --- a/tools/testing/selftests/kvm/include/x86_64/sev.h +++ b/tools/testing/selftests/kvm/include/x86_64/sev.h @@ -27,6 +27,8 @@ enum sev_guest_state { #define GHCB_MSR_TERM_REQ 0x100 +#define VMGEXIT() { __asm__ __volatile__("rep; vmmcall"); } + void sev_vm_launch(struct kvm_vm *vm, uint32_t policy); void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement); void sev_vm_launch_finish(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c index ae77698e6e97..97d9989c8011 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c @@ -27,7 +27,7 @@ static void guest_sev_es_code(void) * force "termination" to signal "done" via the GHCB MSR protocol. */ wrmsr(MSR_AMD64_SEV_ES_GHCB, GHCB_MSR_TERM_REQ); - __asm__ __volatile__("rep; vmmcall"); + VMGEXIT(); } static void guest_sev_code(void) From patchwork Thu Nov 14 23:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875771 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2064.outbound.protection.outlook.com [40.107.94.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 229621B3925; Thu, 14 Nov 2024 23:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627735; cv=fail; b=ZuTy/6wjkdozoRnGKjKbk9pHBZ9vEAk5Lp9mvo/Ay58QZsZoiN86hpl+fB9zVFkrqG7EJnKWcloY2zH5fcKzpWMNLZn8kPtD6TsPIwl0pBkY/5wwCeMhHDNYy7Y/4gpeENdYBuBmWxl+RqC2m2G1qw548KbzeNSitRUF8fGbDxs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627735; c=relaxed/simple; bh=HxfR3OZsiTl+fWWaGmWoeIImmcYnoFoUXeboVRUWm5k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MPzREr3TQIzhyZHJPG5Lu1Ee3JQPXMz7ceMLUAJxLsWXw1CxKPb3r1H727Epy5TQSO6N9T7gR/01I26CdTW8jNx7UhkBN3PlroqpclHtEc/1HY+ZKp0bgQ1eS9xEWELffRqlb6bpLjQaMEEkvb/pwZSzUwtWPR4CpuL6KjfK0d8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Gk0Gocok; arc=fail smtp.client-ip=40.107.94.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Gk0Gocok" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bhKQn0+gkU2vPMN5szWJmO9+SeO23KSUNErasUk1+i8NvjJ2quKNgjXgttGN9Uu5QvmqI9nKt4hclTLuJvtwtRXZfyZIs9fElN4uJ+F2mIvzvczKol8D10RmBTsVJAVmjXn7LhjcHs8igE4RfZvCATRfYpQc1aTqSeg5uofSFTwvw0Je7AXHPnaXdDmipxKfnGo6nvX6tVXvLhpiowKHWa6YaLdqaAsP9QIMxOzEkqnhl1dOWnhxL35sfM+TXCAvwwFhSA8ISYnZAoWIMFKM4deHJ2KNaopsMQw7koJIuGBNj10Kegq/IRg7zWV3CJukVLqmfVnGdHUPxa0CQkvs9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=v4uAUInR5wQDF32eHx/fVslll2B4JSnf6NenT3BdblA=; b=jF/Cl8K1tlCnQ9zZpkkHWLnMbZBUzRVzKnhrWcP+7f0cR4/4js69SqBQyPoa4nPEi03YoDfh77HsKERuKrbLhgAyoPdNWfLS1PdUBYEWLx7K1bQCOfu+uQJKMVYXw2T+lRO3uU8a1eM7YaJioC4Ok8vxopXwpNhtuoHh7uhxlm+otl8nmEQyOTBKAYcvURBAR9I26QIfLT7Z3ABe2R51Y4DyCGWbRnpE9LWz30odu5hjc/nCXF5rcmKKxvZv4wBorgyz8iM1HS3aD7mvnncjPIDCiJ1Yl2MQiVu5S0gs/zNIA3vHoAGmyGcK8S1T/Ab3feT62T7IMsxiSxxDfkYLGg== 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=v4uAUInR5wQDF32eHx/fVslll2B4JSnf6NenT3BdblA=; b=Gk0Gocok3JPro9E+J8yLK7GjkOw0zkDJWB1u6gZ9sY8mtRfNpi1HmszXNS4OoRljbLrLuOLAP5YyZU5p2yMGw6QJx3dRSn52vhYKKrRCFVSYSxGvifrqNddjqipSLOESi1nM+L/KBCkVk2QmK1c8ZkmXEMBoAMYH8M0ZcdHfesw= Received: from BY5PR03CA0005.namprd03.prod.outlook.com (2603:10b6:a03:1e0::15) by DM4PR12MB6009.namprd12.prod.outlook.com (2603:10b6:8:69::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Thu, 14 Nov 2024 23:42:09 +0000 Received: from CO1PEPF000044F4.namprd05.prod.outlook.com (2603:10b6:a03:1e0::4) by BY5PR03CA0005.outlook.office365.com (2603:10b6:a03:1e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 23:42:08 +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 CO1PEPF000044F4.mail.protection.outlook.com (10.167.241.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:42:08 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:42:04 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 4/8] KVM: selftests: Introduce SEV VM type check Date: Thu, 14 Nov 2024 17:41:00 -0600 Message-ID: <20241114234104.128532-5-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044F4:EE_|DM4PR12MB6009:EE_ X-MS-Office365-Filtering-Correlation-Id: ab2b42b7-aa3c-427f-116b-08dd0505f45b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: VQXyZBsKu6Y8JgnxXkgyqStt09/7M2SrhLNGeVl9yyNKdO7d/Wp0ZuT/5nHPMB6X3RslpUGCYV1/zDLFzix65beg5S3Vs+FVJKKRhcA/W4K8i0YdSiw0nYN4dgW/ufEeBJnGNSR3n1bCc6pniPGOdexXRXBCeVa5Jt2MzGzw096Zbs99w/yn3sRY8B5M3dxA09CbWGKYbVoPChFafL+jEc/h9ChFXveFYcf7UPFG1A2ljI5xW9u/t81b0N3TlLh5vZR5PrTcTxcHXl2kGVYzClRbUmQp2Fns9twix7iED7MRIrQXNqjbZXvjc6O/8rfqHuRBezeCN1nMqxdWBv2dd1NlhwisgPJhdCEVCjsXjf2xH21V47S6RQMZ0ZglJkNQGoS+2iMvom7R56OlAy5AYDtFIqO0A8x6bOAysvz4rna6JXSGqCOYDzfyteTghEzOnEkdkVkbEXFnn2p+RgdIZhbnz5UunLaJhPnaZJgD0HVaIWvDRaU3oJu3Va7T5/n+irJBsY2La03EfKYpHXuv6/djPBQ9BCNafDckLKvnXcyiyXD732a7CwEQFqLSceSph68LDhyVoMi5lJHo8q3rLsEBeoWgycjZ7iz5jjL8Lluqelzl2Unz1aZwjnvSV+SMwQCllCAVI1JH9W+nbRAR0/1wOVWUL1LBL1Shl+7DVUQfv988M/Oq4lyb64pL3VM4WXniYwez5NUQToIm2AzZdS9sCMGMKs4BUKwZcIUjhnWbSVxZH2MzwUEvOKLi4COt41gNZE1dFzHncSISlBQZK6t4xJJFy46XQXrvLKe3ce4a5k2DSj4Kj7bK+zUo1ANowfyYVudwIQ29El0V834uNeTEKNBindu3PqzDjRLhA/eQrmXHh1CiGfLpM16RZUAg0p0iXbug3fWu2vvT1pPSKwOhHhRttnReEj1TVrCkmObjUl/qeSBzHAcvMKKUjbR56w/coROmn4uag4g5wUE1otvgfgB/ahhG51U4xJNbfBUwy4eOhNfzyrqjX6du2lJJoOZhgjmUdfTrKe7S+G0rg2ONoXJ3RaCvpZDJA5CQpoeE0bO/aTTSk1KlmevayOEtPapnSHshWQ8LJgTyUnPO/uBnH2/vM0fmOm2DZ7/ubM2XXdpuFGJ9mVTwLpTMCe9nZSQAd0rBhaU3fnKXyGN289Kk1WDAVjCYyDNPWl8q+ZeryThcJy/KwZoAXrFfzD90TViWtFHftcMGJwejBvOu8ZA5VBG2IvuwlkJcA5AvBwA8lT83uaCaH3tev4qe4MNtn6EX627mRhbJewb6h1WOTMs8w4FU7ozYLiXxT2l0hc92w4EejmQfWINz7+wO+RDpCB9R1c1rFIq/d64ntFXesK7WwMHeZSoFp8w6BcwBSVxZPrN1ReO2tT+rCub8Ep4xw2kmKLFCF5+FNtMX1Awvfg== 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:42:08.7344 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab2b42b7-aa3c-427f-116b-08dd0505f45b 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: CO1PEPF000044F4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6009 In preparation for SNP, declutter the vm type check by introducing a SEV-SNP VM type check as well a transitive set of helper functions. The SNP VM type is the subset of SEV-ES. Similarly, the SEV-ES and SNP types are subset of the SEV VM type check. Signed-off-by: Pratik R. Sampat --- .../testing/selftests/kvm/include/x86_64/sev.h | 4 ++++ .../selftests/kvm/lib/x86_64/processor.c | 4 ++-- tools/testing/selftests/kvm/lib/x86_64/sev.c | 17 +++++++++++++++++ .../selftests/kvm/x86_64/sev_smoke_test.c | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/sev.h b/tools/testing/selftests/kvm/include/x86_64/sev.h index e7df5d0987f6..faed91435963 100644 --- a/tools/testing/selftests/kvm/include/x86_64/sev.h +++ b/tools/testing/selftests/kvm/include/x86_64/sev.h @@ -29,6 +29,10 @@ enum sev_guest_state { #define VMGEXIT() { __asm__ __volatile__("rep; vmmcall"); } +bool is_sev_vm(struct kvm_vm *vm); +bool is_sev_es_vm(struct kvm_vm *vm); +bool is_sev_snp_vm(struct kvm_vm *vm); + void sev_vm_launch(struct kvm_vm *vm, uint32_t policy); void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement); void sev_vm_launch_finish(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 636b29ba8985..13f060748fc2 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -641,7 +641,7 @@ void kvm_arch_vm_post_create(struct kvm_vm *vm) sync_global_to_guest(vm, host_cpu_is_amd); sync_global_to_guest(vm, is_forced_emulation_enabled); - if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) { + if (is_sev_vm(vm)) { struct kvm_sev_init init = { 0 }; vm_sev_ioctl(vm, KVM_SEV_INIT2, &init); @@ -1158,7 +1158,7 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) void kvm_init_vm_address_properties(struct kvm_vm *vm) { - if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) { + if (is_sev_vm(vm)) { vm->arch.sev_fd = open_sev_dev_path_or_exit(); vm->arch.c_bit = BIT_ULL(this_cpu_property(X86_PROPERTY_SEV_C_BIT)); vm->gpa_tag_mask = vm->arch.c_bit; diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c index e9535ee20b7f..d6e7a422b69d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/sev.c +++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c @@ -4,6 +4,23 @@ #include "sev.h" +bool is_sev_snp_vm(struct kvm_vm *vm) +{ + return vm->type == KVM_X86_SNP_VM; +} + +/* A SNP VM is also a SEV-ES VM */ +bool is_sev_es_vm(struct kvm_vm *vm) +{ + return is_sev_snp_vm(vm) || vm->type == KVM_X86_SEV_ES_VM; +} + +/* A SEV-ES and SNP VM is also a SEV VM */ +bool is_sev_vm(struct kvm_vm *vm) +{ + return is_sev_snp_vm(vm) || is_sev_es_vm(vm) || vm->type == KVM_X86_SEV_VM; +} + /* * sparsebit_next_clear() can return 0 if [x, 2**64-1] are all set, and the * -1 would then cause an underflow back to 2**64 - 1. This is expected and diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c index 97d9989c8011..53bc0af62bad 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c @@ -123,7 +123,7 @@ static void test_sev(void *guest_code, uint64_t policy) for (;;) { vcpu_run(vcpu); - if (policy & SEV_POLICY_ES) { + if (is_sev_es_vm(vm)) { TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_SYSTEM_EVENT, "Wanted SYSTEM_EVENT, got %s", exit_reason_str(vcpu->run->exit_reason)); From patchwork Thu Nov 14 23:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875772 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2061.outbound.protection.outlook.com [40.107.236.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4ACE1B3925; Thu, 14 Nov 2024 23:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627749; cv=fail; b=LW5p9obRcHI3C+rVKU4XjxdgqtZqPsEXYZYDyjGXyFuMhS0BK/mH3MEiAVG3CifpYXKYo5uaUVQsgd0KTfb7iaCDtmkQhJkxHZ6aavyGZxJyxLm8yOvOJUx4IvcjnQFnMN9slnTEwUYjz0/UJMQgPbdoT0ZMbjNF5RC8HWscu9k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627749; c=relaxed/simple; bh=JxXiwp1T9t5DyrSe2QVnxgOa15S3GGkuwtgl5AD8S4s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kNdonuH1tHVJNHt95n/R8J+Qy/d04ZzkqmpF+zM7xFLThIhmaxj+GgIB+hdwyT0rTFiTOn8bIvUIsDZkgdCxbCluGQR9mhxaJYzSqEaHutVuQw0BbQrT05BBsEfHQkezw4eFMzCp5glQ7XrkRiEttWuN3RF9zef9O9+WRzLlUXc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=gK7LXqKv; arc=fail smtp.client-ip=40.107.236.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="gK7LXqKv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aIQU1dmDr2N2O7C1mGjq5Ff78+dR+aReVypmZtXRB24+8+4yjFzmzVxPXRLSQktVyBzgkr9SUoj75W2Akx9r0/yoYYS8bhuXE6DijEccii7CUWRbavQuiN1ln3uU9J0+5+RERqXcHJZAoIRa2d/TlES0C6plj9KS8IVoKw/z3EDasi/15uZn6HlG16OK/68utmx379Lb11bY3vpb4rXzT8zbHTa9/FaiaSHLo4vW13h6NQ80ZpyTvpMnnQQFwYLtWtnd4PE6zCQlGxH23r7nJOPXvNk3pQDIKo/fg816rEj5wCaJC8es2ax/TlLnFJyOqNBwE/1jYCC5glu7YIQsJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=vcX6524Vd90dXMBxt5PBGO2qq+B1vS4K6h21naGTWCg=; b=NSevn5UesPZ0742IXSXk2MqZW29nf1SPULMLReZjiqe/Ycwe5GdBmAypX2Z+JcMHoDEE6Z+pSvth2jlTyl0PJJMwrazBUOGJlRmXTc16JZRZ0mme3FRhPLKo3nLSSeNVq75qpRQjHA/zUpYL69qQ1bFXjDinfVYvyN6VwBjx515UeS2JPyoqb5eXqvJYC6OWMwt7gbmb8IrydF0e481k7h0JYD9QNduGod0Oj/ozSq9MKSUHZUVjGzZhpNoZmlevtcCVb3N82D7ilRUhvy0ZuFzstVXmr5gPYNnUPh/MESYiHkSRqeujs1rMxMzlyiYeRqjdl/sNUFshhHEW76JsZA== 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=vcX6524Vd90dXMBxt5PBGO2qq+B1vS4K6h21naGTWCg=; b=gK7LXqKv6+q9bBpxQB1g2rPRDFQP2ioTyyQX7FHmGxzCX2extVPhU4ilileZPVfzvZI6jOHoqneBAiOu15lfnvOGWbabNGIprp+WxETQRfXyKTWCdNI6RBmyJTjtXkjUQrB0t+eDofdTJ1JVWhJHpfZYbjeZvv4a9BSBH6Sk0XQ= Received: from BY1P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::14) by SJ2PR12MB7990.namprd12.prod.outlook.com (2603:10b6:a03:4c3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.28; Thu, 14 Nov 2024 23:42:17 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:59d:cafe::88) by BY1P220CA0001.outlook.office365.com (2603:10b6:a03:59d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18 via Frontend Transport; Thu, 14 Nov 2024 23:42:17 +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 CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:42:16 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:42:15 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 5/8] KVM: selftests: Add library support for interacting with SNP Date: Thu, 14 Nov 2024 17:41:01 -0600 Message-ID: <20241114234104.128532-6-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044F5:EE_|SJ2PR12MB7990:EE_ X-MS-Office365-Filtering-Correlation-Id: ae54cf24-0710-4786-e562-08dd0505f952 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: DSRc7zDnkl22EmNC2/WKfi1Vur0cTmOCp2ZmKXD09BTe9thCr7dO5KR5xdqebS00wNPspYXbnxiVsRC/iqJ1e4H7IVUQUSRkRAB8ojHyBaM16WsbSxALd7EFImKu6Kxh1+LwUF10QnbxMXaE4P2oUESnJ6ghaPzbucsoe08E4B/0m1Be5e/EJlJWbfcrE6bH/Oocvds8oPfepRRRCRw55LkVhyuMp97HQMm7uYNfAj2ncrVSABGlIx2II0TbjltP7atjTaY325Zzeb++GtpqUjPCD1tqTIvrT6FjKcI3Xbdt0L+1bUxbvBhlLv+V//43dmTSfIrC1qH8qh4vqgy7PF5G4p+V96Gzl6jANcosV5FXyUGpB8Ep6GxQz9328sVGQ6/nTYl2Qh+N1yVZ6RtoNaQa7fweZzKZpYrL4rHIkWQOyxcUYJuY3UcgGytjOPshxiiWS7FvAcbP378VHEtKz0QkAh/8LXb/y7vqor7VzcfxIOyO+CObOC+q4fH6YJh9cG975LBnoONO4tP0Gk4rfyCbFJ7aXLjB9E7Im2f5nUxLZaTHxe6WJGA+3nrxgUror5pTIIJFSJOim0uMEeKsQiucR250YsCoJVxvhVkXOibWiNh1uE3eE/A97zyBpDTUjnAT3COZv4ojalm6YxYzC1OisqAa0Pp+U1RdnZJyhJJd+FcG/TjhIhiQ5srZEFg5qlJNSbpOHQb1FRBMhdI2qLycCWNpDVsBcVm6Clup3bS1gORN/NPCSHk51rF38znzjdQOk7Mncl01mKWeSG6pnpcnW3+uurI7inxbLunxKIXJuHwxvVNpx7rBEo0DFUdvpNA5bFJkMyNw0hL7g/wOA2bPAfO4W+bfnYPE2MVaj+ehYerQB9SOG2bgQqBjcTI4c3s/x5s9znwW3Er/f0NTkT4R9FZxvsjjUobqzZ9sxj+q7l4j/a5GtdZcpsWdreSu7steysW9/c+9xTYUQGXL/rmfbA0XuVg3pGqgy/fw4RrfM/W6B56u8q+U3UiXX/1pBFrHl1l/OtdHZViAvjQNFw0qUwTE6NVULK2a5EX2y3C3vhEqmlf68zjLSgTTGu+alm33SsBGcbti6QGuoa+G2N0RD2rpILqoOLeWeluoL7ZQA/EJ3BgfVUWXuf7suvBiDbknw9KtlLu68pxQokFhXHE4KYpuY/xC9xlFaf4PymPEi1vfBM9FXNHCeBHByXCq1CnoZmfk6jL+B6r12q8ktJmu0vxszrl/mS/wDYJbZO6tJCRp/J/JagzlET7H4hbGUTHYbYW1JzkrSmxZS6SEYynYv4Vyy26XwirsLN7xKgBrV/ZE27JICxTR3F0ff0QvIHuDQVxtQ1pcLhRA3mI2h9OEZNHGY1NECsRX/NnMdoz5uqsYUb6MvU9OIVYPezqOK9S8/9XI0dzRs2MQz6C2rQ== 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:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:42:16.9600 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae54cf24-0710-4786-e562-08dd0505f952 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7990 Extend the SEV library to include support for SNP ioctl() wrappers, which aid in launching and interacting with a SEV-SNP guest. Signed-off-by: Pratik R. Sampat --- .../selftests/kvm/include/x86_64/sev.h | 49 ++++++++++- tools/testing/selftests/kvm/lib/x86_64/sev.c | 81 ++++++++++++++++++- 2 files changed, 125 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/sev.h b/tools/testing/selftests/kvm/include/x86_64/sev.h index faed91435963..19454b0e10a6 100644 --- a/tools/testing/selftests/kvm/include/x86_64/sev.h +++ b/tools/testing/selftests/kvm/include/x86_64/sev.h @@ -22,9 +22,20 @@ enum sev_guest_state { SEV_GUEST_STATE_RUNNING, }; +/* Minimum firmware version required for the SEV-SNP support */ +#define SNP_MIN_API_MAJOR 1 +#define SNP_MIN_API_MINOR 51 + #define SEV_POLICY_NO_DBG (1UL << 0) #define SEV_POLICY_ES (1UL << 2) +#define SNP_POLICY_SMT (1ULL << 16) +#define SNP_POLICY_RSVD_MBO (1ULL << 17) +#define SNP_POLICY_DBG (1ULL << 19) + +#define SNP_FW_VER_MINOR(min) ((uint8_t)(min) << 0) +#define SNP_FW_VER_MAJOR(maj) ((uint8_t)(maj) << 8) + #define GHCB_MSR_TERM_REQ 0x100 #define VMGEXIT() { __asm__ __volatile__("rep; vmmcall"); } @@ -36,13 +47,35 @@ bool is_sev_snp_vm(struct kvm_vm *vm); void sev_vm_launch(struct kvm_vm *vm, uint32_t policy); void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement); void sev_vm_launch_finish(struct kvm_vm *vm); +void snp_vm_launch_start(struct kvm_vm *vm, uint64_t policy); +void snp_vm_launch_update(struct kvm_vm *vm); +void snp_vm_launch_finish(struct kvm_vm *vm); struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code, struct kvm_vcpu **cpu); -void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measurement); +void vm_sev_launch(struct kvm_vm *vm, uint64_t policy, uint8_t *measurement); kvm_static_assert(SEV_RET_SUCCESS == 0); +/* + * A SEV-SNP VM requires the policy default bit to always be set. + * The SMT policy bit is also required to be set based on SMT being + * available and active on the system. + */ +static inline u64 snp_default_policy(void) +{ + bool smt_active = false; + FILE *f; + + f = fopen("/sys/devices/system/cpu/smt/active", "r"); + if (f) { + smt_active = fgetc(f) - '0'; + fclose(f); + } + + return SNP_POLICY_RSVD_MBO | (smt_active ? SNP_POLICY_SMT : 0); +} + /* * The KVM_MEMORY_ENCRYPT_OP uAPI is utter garbage and takes an "unsigned long" * instead of a proper struct. The size of the parameter is embedded in the @@ -76,6 +109,7 @@ kvm_static_assert(SEV_RET_SUCCESS == 0); void sev_vm_init(struct kvm_vm *vm); void sev_es_vm_init(struct kvm_vm *vm); +void snp_vm_init(struct kvm_vm *vm); static inline void sev_register_encrypted_memory(struct kvm_vm *vm, struct userspace_mem_region *region) @@ -99,4 +133,17 @@ static inline void sev_launch_update_data(struct kvm_vm *vm, vm_paddr_t gpa, vm_sev_ioctl(vm, KVM_SEV_LAUNCH_UPDATE_DATA, &update_data); } +static inline void snp_launch_update_data(struct kvm_vm *vm, vm_paddr_t gpa, + uint64_t hva, uint64_t size, uint8_t type) +{ + struct kvm_sev_snp_launch_update update_data = { + .uaddr = hva, + .gfn_start = gpa >> PAGE_SHIFT, + .len = size, + .type = type, + }; + + vm_sev_ioctl(vm, KVM_SEV_SNP_LAUNCH_UPDATE, &update_data); +} + #endif /* SELFTEST_KVM_SEV_H */ diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c index d6e7a422b69d..40b90d3a5769 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/sev.c +++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c @@ -31,7 +31,8 @@ bool is_sev_vm(struct kvm_vm *vm) * and find the first range, but that's correct because the condition * expression would cause us to quit the loop. */ -static void encrypt_region(struct kvm_vm *vm, struct userspace_mem_region *region) +static void encrypt_region(struct kvm_vm *vm, struct userspace_mem_region *region, + uint8_t page_type) { const struct sparsebit *protected_phy_pages = region->protected_phy_pages; const vm_paddr_t gpa_base = region->region.guest_phys_addr; @@ -41,16 +42,39 @@ static void encrypt_region(struct kvm_vm *vm, struct userspace_mem_region *regio if (!sparsebit_any_set(protected_phy_pages)) return; - sev_register_encrypted_memory(vm, region); + if (!is_sev_snp_vm(vm)) + sev_register_encrypted_memory(vm, region); sparsebit_for_each_set_range(protected_phy_pages, i, j) { const uint64_t size = (j - i + 1) * vm->page_size; const uint64_t offset = (i - lowest_page_in_region) * vm->page_size; + if (is_sev_snp_vm(vm)) { + snp_launch_update_data(vm, gpa_base + offset, + (uint64_t)addr_gpa2hva(vm, gpa_base + offset), + size, page_type); + continue; + } + sev_launch_update_data(vm, gpa_base + offset, size); } } +static void privatize_region(struct kvm_vm *vm, struct userspace_mem_region *region) +{ + const struct sparsebit *protected_phy_pages = region->protected_phy_pages; + const vm_paddr_t gpa_base = region->region.guest_phys_addr; + const sparsebit_idx_t lowest_page_in_region = gpa_base >> vm->page_shift; + sparsebit_idx_t i, j; + + sparsebit_for_each_set_range(protected_phy_pages, i, j) { + const uint64_t size = (j - i + 1) * vm->page_size; + const uint64_t offset = (i - lowest_page_in_region) * vm->page_size; + + vm_mem_set_private(vm, gpa_base + offset, size); + } +} + void sev_vm_init(struct kvm_vm *vm) { if (vm->type == KVM_X86_DEFAULT_VM) { @@ -77,6 +101,14 @@ void sev_es_vm_init(struct kvm_vm *vm) } } +void snp_vm_init(struct kvm_vm *vm) +{ + struct kvm_sev_init init = { 0 }; + + assert(vm->type == KVM_X86_SNP_VM); + vm_sev_ioctl(vm, KVM_SEV_INIT2, &init); +} + void sev_vm_launch(struct kvm_vm *vm, uint32_t policy) { struct kvm_sev_launch_start launch_start = { @@ -93,7 +125,7 @@ void sev_vm_launch(struct kvm_vm *vm, uint32_t policy) TEST_ASSERT_EQ(status.state, SEV_GUEST_STATE_LAUNCH_UPDATE); hash_for_each(vm->regions.slot_hash, ctr, region, slot_node) - encrypt_region(vm, region); + encrypt_region(vm, region, 0); if (policy & SEV_POLICY_ES) vm_sev_ioctl(vm, KVM_SEV_LAUNCH_UPDATE_VMSA, NULL); @@ -129,6 +161,35 @@ void sev_vm_launch_finish(struct kvm_vm *vm) TEST_ASSERT_EQ(status.state, SEV_GUEST_STATE_RUNNING); } +void snp_vm_launch_start(struct kvm_vm *vm, uint64_t policy) +{ + struct kvm_sev_snp_launch_start launch_start = { + .policy = policy, + }; + + vm_sev_ioctl(vm, KVM_SEV_SNP_LAUNCH_START, &launch_start); +} + +void snp_vm_launch_update(struct kvm_vm *vm) +{ + struct userspace_mem_region *region; + int ctr; + + hash_for_each(vm->regions.slot_hash, ctr, region, slot_node) { + privatize_region(vm, region); + encrypt_region(vm, region, KVM_SEV_SNP_PAGE_TYPE_NORMAL); + } + + vm->arch.is_pt_protected = true; +} + +void snp_vm_launch_finish(struct kvm_vm *vm) +{ + struct kvm_sev_snp_launch_finish launch_finish = { 0 }; + + vm_sev_ioctl(vm, KVM_SEV_SNP_LAUNCH_FINISH, &launch_finish); +} + struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code, struct kvm_vcpu **cpu) { @@ -145,8 +206,20 @@ struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code, return vm; } -void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measurement) +void vm_sev_launch(struct kvm_vm *vm, uint64_t policy, uint8_t *measurement) { + if (is_sev_snp_vm(vm)) { + vm_enable_cap(vm, KVM_CAP_EXIT_HYPERCALL, (1 << KVM_HC_MAP_GPA_RANGE)); + + snp_vm_launch_start(vm, policy); + + snp_vm_launch_update(vm); + + snp_vm_launch_finish(vm); + + return; + } + sev_vm_launch(vm, policy); if (!measurement) From patchwork Thu Nov 14 23:41:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875773 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2067.outbound.protection.outlook.com [40.107.95.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA4CA1B6D17; Thu, 14 Nov 2024 23:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627753; cv=fail; b=C1HPduRsGDexkxU5a1oDdUsB/NoXLxZOOnFthxJOeWDC/oBMW0QaVBAN/VuECEAm1EwqUoC2tsLZTdVoy9JpLCLw0s+2Utwj9nY0Biit3z3ALJtX9DVggCGdgAub/PGX85PJQ3F43ohreMTAubGizd4ipOwW4k0FzFP7/RobXMo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627753; c=relaxed/simple; bh=LtmQd1NXBc/0jbr8sYjc2ji2u/3IgAKe6xgNSiBrrHc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a4CClEPI0KU19i454HN3MTGeumVaw0QvPZmGfxR658bC6xSW4l5n/A6G9ga2hNmVWo/6NERXWEPfURqPDYZrNmAtLs5ysxCCduf3jNx5ZTl5GLHf8IfyEmSinBnyHI3hGa4yn1yWRUsFtbmTE//8q15FXq9lDNoxjRi0PqsieMk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=IQ/0qK79; arc=fail smtp.client-ip=40.107.95.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="IQ/0qK79" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JLQTQS3NF9xpVCeu1u/HhB6w+Gm9iODMpno3S20UOCk7m+GsUfBh2K3tdgzKM8Yr74fc3pGIQj62z59tOkEneMP8cg2qvoPuSwOzFIGBEHy0us2BwhHGTDhNhXOw01HivP+Kgfjo0lPVOhlXT4AFspBmdJFpLmTpUYVJQmWXVLSO024IhbReWercnHOZHHgX08GWm/PqGE1J46js0fsAWkHsvhb3R9lh9uzZHkO3QVmfuv6TSRxmRHa41TEhICIsYmwGDWrtp7aAwJfIQH0D821xKEr4a4k38ctA3TuPqQ39zr6ymyAApuG9PD2Gd4my3J8FRpMDy2338dKiaJ5kDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=/HXd4jTB833Azjve6ljpQvoLFOj1H81YtGXZ38roRgk=; b=Ikjn0+s0vnYZeojw5SdhfF+1Qyd2bswxeE4etnPome/OY6Zy+QYiID6U39lwBklW6YsYxMecEkLqOWCUrN9NRzRR6q77aCQQGX14Etc39eVs1wa1wmwRyfIiZCzXeVzs5iJBc5phd8gXz6LE8i9UWwyMWYNGlAd5CRoRo7spTw41zfLJGMy72t/oT4nUvMAQSch3VN3KiQXbsdJzq6wavYB5NPGtv3Lhwu9PpRpbuw8TRnMZ+9Iqw8gPQaq66kv3PcJ2ZlqtOeNEXhflUL6O50kd4iQcwDpdrkIuDtUeU99kyhJKVTbVLcGLtNTAtPLVDSbq0UsbE9pnSieXj2e4MQ== 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=/HXd4jTB833Azjve6ljpQvoLFOj1H81YtGXZ38roRgk=; b=IQ/0qK790trLj6Oc9VRTqLHnV+997nAzNXp8Io5ExzGOlZ2Qhmo9eEImZ/Zg7v53DDmye6ATwELY1+SgHdkk+GacHCLUnn1tKxZc8XigrxBlB/eFfsuNpDLdBHXTaBzDfJFQ+EW0iOg2f168nNSIBgIjEzu/YQOjukndDFb7iNw= Received: from BY1P220CA0007.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::13) by CH3PR12MB8725.namprd12.prod.outlook.com (2603:10b6:610:170::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Thu, 14 Nov 2024 23:42:28 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:59d:cafe::16) by BY1P220CA0007.outlook.office365.com (2603:10b6:a03:59d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18 via Frontend Transport; Thu, 14 Nov 2024 23:42:27 +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 CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:42:27 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:42:26 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 6/8] KVM: selftests: Force GUEST_MEMFD flag for SNP VM type Date: Thu, 14 Nov 2024 17:41:02 -0600 Message-ID: <20241114234104.128532-7-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044F5:EE_|CH3PR12MB8725:EE_ X-MS-Office365-Filtering-Correlation-Id: be1cff15-7619-4ffc-4e39-08dd0505ff90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: AOpjWPE7p3ehCh5WhQ9Pa17qnGtc0P0EoJ1QllZeuxQGV+x5gxH8n9UjgIUzKw3kp2lweUYNf5oe4pwCGVlA/JApJXOBMP4o77FZkj5xPwKa4uCdn1RsZkO3WniRCTwtx7IyLDZifV3erNhX5oj5/SDvHbgyE5Cw3ZNV5ztgznSlTg0ULDinbJuvtircSdB9oH1/hCF0tRvWII+DmlvXl2Pnj5rPz80XbqT4cvkRjTJgopKT4cAar42rlzDn/d/SbtAUcPgDXyL6GmYXu2+v2l8oVxk1lDVR7rB17vln58Mvsos1cb0ZisiAexwbzKeIeRxvmWhQXrbZ9vFWQbJzWz7DZQAuhg4TJ/ZRN82ZTP7Z2hzGuAMaSy0HksoqmAppok4EYi+wxErJNPhFBI6xL5hLH0K0BeZq9SfmHsaFMDo+etMGbD9fN9jaIMZ6V2X4UzV3QHhuA7fz7DzGBet8NEFDaNUJvCdKrQWbQI0UDwVeY/113i7HBtxrjtGUwYKY8Cg8XKg4fqUC4ZG0ifhG+yNXnMAjcGQK9v/QKt8n1ZAlZZ+mzt7Tb4VBzs6XvljPZCeGFJCUGvXw8X4DOiV2Rf7qEXZIoIwoeb/znr8D6nbwOxi8xXv4F6DApxkMaIk/CeluQQdcrY+bBWYadUr/yKI5eyM8dddXR6g4QTxW8BUjlVUGdR+Uz+KjMmbbTMchCd//t+g92vs+wYVqWPNs6NKnWX0+TIGtIjn3rCV1c+IbPJ55Swb1SwR2jYlKMakrGnbSMzISsNqwqQMlpPGoOXDW7QqXAWctLcNetE26lErNtEXgYjKGAlpMzte4geyZ9trVCwBh60wjfc7p89qabHZHjSAl4PclX6DpNDNrgyKD4enJNnDbdT+FNwVLbr/eB4TPn9K5NGGVfZRxAcoA4oo3s0nGB0Xsx0RAUBBlXEUsyQAKZhHj2qYNiONs8QW9eKH33Q9wtKAgWCXnNxZrUWmpPM2X6bOD4+0Y9gN7aTjtHKU6MKfUIkk1e97Rrv4vE3tEI0tOcn/dDINd9hXYR21mwOi3JQV7tOZAJmVwHm5bVB5W0s1YsPe8TCItc4jR63jMPGm4/b9zHcseqD7m21DIJatXgjirv/8VDnu+CmySMGG/BWvWBcveX/eWDE/v+a9Epam5BlbRHxzzTMt7HMtgAFE9n/UQCHgdlQ664PzP245feoTULFXIrqQdCFwNIHweMQEFkGQZOVy3n8ZWPOGpfR380pik4FAnaNvhYHsQ8/Ss/lqht5NRgqXlVuYMbXRRqoTxYw5g+MlPQxe2M6wvmZhFlXHiWVLc8DDe/RgukvFHDWX54pNjYKK4mNgNh7OF6XSJz9xKYvtk8OVG1xXEtF8rONC6skWBre5tc9ycr+xeIue933WsqynwZ/IT1c5YEmZDzVzel19PY9CaSw== 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:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:42:27.5382 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be1cff15-7619-4ffc-4e39-08dd0505ff90 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8725 Force the SEV-SNP VM type to set the KVM_MEM_GUEST_MEMFD flag for the creation of private memslots. Signed-off-by: Pratik R. Sampat --- tools/testing/selftests/kvm/lib/kvm_util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 480e3a40d197..26179fb2f0e7 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -413,14 +413,17 @@ struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus, nr_extra_pages); struct userspace_mem_region *slot0; struct kvm_vm *vm; - int i; + int i, flags = 0; pr_debug("%s: mode='%s' type='%d', pages='%ld'\n", __func__, vm_guest_mode_string(shape.mode), shape.type, nr_pages); vm = ____vm_create(shape); - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, nr_pages, 0); + if (shape.type == KVM_X86_SNP_VM) + flags |= KVM_MEM_GUEST_MEMFD; + + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, nr_pages, flags); for (i = 0; i < NR_MEM_REGIONS; i++) vm->memslots[i] = 0; From patchwork Thu Nov 14 23:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875774 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2051.outbound.protection.outlook.com [40.107.92.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0881E1B3925; Thu, 14 Nov 2024 23:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627764; cv=fail; b=m1X1ZjV00B1OJ/dvybTQhnt5cyOdbkPIRuutO9v0ki6rrx0ln2D+t8iLZHmEVC9Wx6S35mKlvjgJKTHRWgUCMD9mFex1NWHlqwtB18/7dS32w8ize8CfY55xc+PEFgCr6NMuoRD4zPAPfxzCern4vzORol6D1V6eucR1Hvvfm2M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627764; c=relaxed/simple; bh=K7FCSCB1/UdCGXN0skk7P9qLphpfWoki6WDNPCOhjwM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KGqjdgi60zp6nTXuudiFru7Jt8uu/VUG6Mc52nPiJM9zQ21I4o+Q3XVr0eSWUvU666KdvvMPzDFI60RJ8vMUghADHb9DKJpzez2S+59jQ8is52ajUIOldaDqhvGGhoz7zDvCg/+Muc98AJZ750DKv9xe30WpyMyICryz36FOnmw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Y58dZ3uo; arc=fail smtp.client-ip=40.107.92.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Y58dZ3uo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FJcFagszi0OXrxZEae3/hs8qES/NofTT+Jfv1oFCTEFSKo7A+n1bWqeJrhbU+oGxnEw44/uBhA56PYRrHPqZuKtEPXsaCImbpXv6QsX/JwTryXT0Xy37aBfMSV2lxaLLVz9H66u/Af1AdBFh8xxRiNzULDGpuaQcfSgeZmBylkEeBcz/UdOB9JZtfZ68MetCa5HUe+wTtQDA6iM3vPyVbnOrb/c0LZydEMfc7r5yhGnDe8QdeBLyONIC83FBZ2kukye4Pfn7bt1w84/uPOJtYDDZHBPz8fnDK/tKX5bk5UfJaMJywD/x79mIBcf1rBQDOc54sRGKfCMuX5JMDOXmLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Yx8EBTottlb086y5AJDbfeJB1cpERe97usByQVnBg10=; b=heYHijdp1u9pTBL+tOxTtDvY7CKqcspQ90yUEPFK3lGKMFYfZG/YW2uKTvrvAuWDGzST8Zy8zZ+r8iTfitpaWly3jISzLDM0JgCrbeXGNKJOT//45Czkcpq7PC2ZN4PdD5W5o4yoQYjw7zRXyNcdnZd+2CXRNTSQckiPsQ4leQBoapGLiRv37Hpkm+/2lAPKbpHICGZbsBGcNaE9a3cIht2rHdV0G6cFeRDJivNE1kaJammMKN7/MBkS/NI+OhA0XIvws2/c4ETVFx0ii9sKkKHuklWboLK+b4ppz8iKBff4W+mLN3Rw1ooI3h/slbFjPoFgv7nQ2Shn2laxhjlPJA== 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=Yx8EBTottlb086y5AJDbfeJB1cpERe97usByQVnBg10=; b=Y58dZ3uooRGONFrQBGo1wFrUk1isCR11kln+W1cUjEkAtQWHSF5bNlcUePkjwtHfwizK9qzePUidtlKRwNkNx2ACRd9J9K2vcuLMl4xSxNsCcI/hzqPttz7u9734XBVA50I3UI0Qb+2EMsUkhBIeni/S4tL9SN9yQR1qw++eUEY= Received: from MW4PR04CA0078.namprd04.prod.outlook.com (2603:10b6:303:6b::23) by PH0PR12MB8127.namprd12.prod.outlook.com (2603:10b6:510:292::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 23:42:39 +0000 Received: from CO1PEPF000044F1.namprd05.prod.outlook.com (2603:10b6:303:6b:cafe::71) by MW4PR04CA0078.outlook.office365.com (2603:10b6:303:6b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17 via Frontend Transport; Thu, 14 Nov 2024 23:42:39 +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 CO1PEPF000044F1.mail.protection.outlook.com (10.167.241.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:42:38 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:42:37 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 7/8] KVM: selftests: Abstractions for SEV to decouple policy from type Date: Thu, 14 Nov 2024 17:41:03 -0600 Message-ID: <20241114234104.128532-8-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044F1:EE_|PH0PR12MB8127:EE_ X-MS-Office365-Filtering-Correlation-Id: 79db32d0-cd8b-476c-e39d-08dd0506064e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: S1YAs6oISW0AMDWpOKtD0B9FmeMb43dwtVflnYgmy9Y8r0NAMaGIZjFbYj07Xbka+3Sl16IubqqpcSkWC90mMJfvgICfj6VQ2r7BrDY7lGbBAE2UyTEoko0OM4CuPaHHSjeY6o7evLDHfGGwN3ponoEZjUq8IRVkJHWhBPFhKqk/V8gODAobVt1UEar9o7jo/v+RWTjaaXgvD78Rcr4apXabSsGJ7Q9NdxTKUQnUGIu42VYYqczTupgUKv+bVpnXqO2QEiM+R5qQ1cHqdFrT3QzCJAEp6TLM8t36C+oGypV3/TjXx0mUB3epfrfG6vpHdpfmBZ4r5waqPNk6HwtdjgQmfi6tHMYO9g9U74owBHGn5yZe1g56MegFvp0n1S6JpdK5zARKrVVgiMtsmhy2toQK49Ne+hThYIB8B8hpnsVbK4vpQrpSrp7MT6l4MfieBJI9XeD7G/LJDRW6VeKo/YTATR4PgR2SE4lrsKci59iMiwAfFrL1itxx6+BbKQ0B1qAmDmiVCrSV/CeskaXHYWIqS5Q+ujAQnmQbzWh0imFqCEuGJprllNAda0x6V4KcEae0XmodvKpv6kVyFXCHZDNtdOHYb5eBp8wIJJR0rYY2gaatXYp8oG2IhOKfEzDGxpY2IS6efAf/c8Uluwt3vg5xTop10PeSJqvDTJLzBZ7f0yqJ+6+R/upbbhRA4JwJdZatCQ9YrwavLeentOcwLD47S+vhSiJG03XC2fYSs7lE8b2IQWC6EGmt0gv7rDZ1Y1ys7N7dWBs5HoBBfTlSkEv+KB1W8S2krU8cp6K5J30AcyV1PIhd/7bYuOtSUR9xYpUO8ok28+Y7iYGzP6jj8IgZYgk2ddZJh9qniXbiWEYAlhVxtDR93nars2u+NH1PXogeqSBTnDPPLjHcwHgJEqeqSMHhxbkvQr4dniYFWWK4GfVi9TWHc/cHFk+tI8EUB9dYnc2+uYpc0kZNnnox3+F6AoHASNM6Lv+gnoSoYn7bEfLO67v18wq+LX6r2bgqvEhdg90+gbLdJOa9WhK5WO/fE/xZeufaFaVfnlKhsCd1/CcMKfmRMkXavcJJA3i3bG2bFHkO7kV3fotMkDQFJcb9Tvk1K7vVXyY8yPA15lSJcg3dcly3yywjSI/Noqd4RQIb6RzsnESXQe9D98pHYDvLE6oPY+ODfBFYlvt9nQsxlEMhdVJImnER2le5GvQ9+Ia9OIlNJv+AdsQdWg2PrYM3fpiVjgHvZhF+H7VTx9086x8qIBebG2hT1IyT2kExsppGNdJveIL4GLJ/YOkEa7tcr6Qe+C69eU52dRZUtuTGVnsLaxANMzrBsNq8CqAMORSH4ZRyeUyyZR8fnH/j0uBwzl9uZfatqTKKEPNZXtkiWf+JM+fN+ucYslQIL4jbbudmjiM00UEhWWtPZjxl3Q== 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:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:42:38.8379 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79db32d0-cd8b-476c-e39d-08dd0506064e 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: CO1PEPF000044F1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8127 In preparation for SNP, cleanup the smoke test to decouple deriving type from policy. Introduce, wrappers for SEV and SEV-ES types to abstract the parametrized launch tests calls and reduce verbosity. No functional change intended. Signed-off-by: Pratik R. Sampat --- .../selftests/kvm/x86_64/sev_smoke_test.c | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c index 53bc0af62bad..af1beabbbf8e 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c @@ -61,7 +61,7 @@ static void compare_xsave(u8 *from_host, u8 *from_guest) abort(); } -static void test_sync_vmsa(uint32_t policy) +static void __test_sync_vmsa(uint32_t type, uint64_t policy) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; @@ -71,7 +71,7 @@ static void test_sync_vmsa(uint32_t policy) double x87val = M_PI; struct kvm_xsave __attribute__((aligned(64))) xsave = { 0 }; - vm = vm_sev_create_with_one_vcpu(KVM_X86_SEV_ES_VM, guest_code_xsave, &vcpu); + vm = vm_sev_create_with_one_vcpu(type, guest_code_xsave, &vcpu); gva = vm_vaddr_alloc_shared(vm, PAGE_SIZE, KVM_UTIL_MIN_VADDR, MEM_REGION_TEST_DATA); hva = addr_gva2hva(vm, gva); @@ -88,7 +88,7 @@ static void test_sync_vmsa(uint32_t policy) : "ymm4", "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"); vcpu_xsave_set(vcpu, &xsave); - vm_sev_launch(vm, SEV_POLICY_ES | policy, NULL); + vm_sev_launch(vm, policy, NULL); /* This page is shared, so make it decrypted. */ memset(hva, 0, 4096); @@ -107,14 +107,12 @@ static void test_sync_vmsa(uint32_t policy) kvm_vm_free(vm); } -static void test_sev(void *guest_code, uint64_t policy) +static void __test_sev(void *guest_code, uint32_t type, uint64_t policy) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct ucall uc; - uint32_t type = policy & SEV_POLICY_ES ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM; - vm = vm_sev_create_with_one_vcpu(type, guest_code, &vcpu); /* TODO: Validate the measurement is as expected. */ @@ -149,6 +147,21 @@ static void test_sev(void *guest_code, uint64_t policy) kvm_vm_free(vm); } +static void test_sev(uint64_t policy) +{ + __test_sev(guest_sev_code, KVM_X86_SEV_VM, policy); +} + +static void test_sev_es(uint64_t policy) +{ + __test_sev(guest_sev_es_code, KVM_X86_SEV_ES_VM, policy); +} + +static void test_sync_vmsa_sev_es(uint64_t policy) +{ + __test_sync_vmsa(KVM_X86_SEV_ES_VM, policy); +} + static void guest_shutdown_code(void) { struct desc_ptr idt; @@ -160,16 +173,14 @@ static void guest_shutdown_code(void) __asm__ __volatile__("ud2"); } -static void test_sev_es_shutdown(void) +static void __test_sev_shutdown(uint32_t type, uint64_t policy) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; - uint32_t type = KVM_X86_SEV_ES_VM; - vm = vm_sev_create_with_one_vcpu(type, guest_shutdown_code, &vcpu); - vm_sev_launch(vm, SEV_POLICY_ES, NULL); + vm_sev_launch(vm, policy, NULL); vcpu_run(vcpu); TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_SHUTDOWN, @@ -179,25 +190,30 @@ static void test_sev_es_shutdown(void) kvm_vm_free(vm); } +static void test_sev_es_shutdown(uint64_t policy) +{ + __test_sev_shutdown(KVM_X86_SEV_ES_VM, SEV_POLICY_ES); +} + int main(int argc, char *argv[]) { const u64 xf_mask = XFEATURE_MASK_X87_AVX; TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV)); - test_sev(guest_sev_code, SEV_POLICY_NO_DBG); - test_sev(guest_sev_code, 0); + test_sev(SEV_POLICY_NO_DBG); + test_sev(0); if (kvm_cpu_has(X86_FEATURE_SEV_ES)) { - test_sev(guest_sev_es_code, SEV_POLICY_ES | SEV_POLICY_NO_DBG); - test_sev(guest_sev_es_code, SEV_POLICY_ES); + test_sev_es(SEV_POLICY_ES | SEV_POLICY_NO_DBG); + test_sev_es(SEV_POLICY_ES); - test_sev_es_shutdown(); + test_sev_es_shutdown(SEV_POLICY_ES); if (kvm_has_cap(KVM_CAP_XCRS) && (xgetbv(0) & kvm_cpu_supported_xcr0() & xf_mask) == xf_mask) { - test_sync_vmsa(0); - test_sync_vmsa(SEV_POLICY_NO_DBG); + test_sync_vmsa_sev_es(SEV_POLICY_ES); + test_sync_vmsa_sev_es(SEV_POLICY_NO_DBG | SEV_POLICY_ES); } } From patchwork Thu Nov 14 23:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13875775 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2086.outbound.protection.outlook.com [40.107.244.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E6461B3925; Thu, 14 Nov 2024 23:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627776; cv=fail; b=Y52RbZKhKednnAvO50ot18uABYzBOb8pMfBWRl8gJ7LuckIJsCfWQba1FfKP0+chNuMSfCy18MA4L/9YRxwClo81mPyf9EhhDcX0QqUshBnzVDaMLO3eL4VM4byQccg65JYhfQULPPYXpXJLG7bYLl6kIpQOyeIU1M/3uObz7iA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731627776; c=relaxed/simple; bh=U2yetTn7xna0in3cj+HERP67FskIv+YXqO8+GlPaNrs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mBN02zqB2V3vDJK+AdCaKVTOPnRRND+NnAS7+eWDfxUcU21Io1JyjCjUOjwkS5/5B+oyC5/MeEz+IXlJe48CPhiQ1zIFH1VUcGlgcM9XI3quHRrxGX6H7SdCiILeYQGKjFC7XXGc7k/Hkxr/6Z/88Y6KCfE6UQkgmOXlMh+kRPA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=BarHwoIF; arc=fail smtp.client-ip=40.107.244.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="BarHwoIF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UuBJsIeX5GeG4jCzxx7LqJIZadhyTtLQcLltJBJF8GOTAuCsjUwOOpCChMGYYeWRBesGk9+446c5rhPVkLKHAHxscFNH9cuEcvzr5LDglGTBBREriOJDW6yDDnToD+RbRnFH5f6HKVEn4tP3dcCRztDJ/URbJ5zqiGzMJVmb7/FiXUGqMwwzYYN4xcCOJ+rla4hs4xO93Ih0VMjT0pKawp0itWw+UvLHuy4nAcLDoy6ag8jbIulrGPWQMj4yFRkDBpyjShFMGwXOWd8PXR8ZsAgT6jAgKZmG8BDV/ewbT6FoJF0ejR2feej9TMfdulusOHgYB5Zw7cLpFgKD+DWuZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=RocJK05lm5JfsZ6M9FwgHiIIPV/JxGNnH4PzFecApYA=; b=TUYzcWXZkawB1GaK2LF6ANzffXEHMLsHU0bdpfc9BaX2v/S/kuHZV479M5/G5DwuGt3zT/b6z5c2ot3bkrExJ2i6SqnH0CI+QGqEhYf8M7/lcEUPwzxvb1ab6WW1MMl5/cfZC0IGQHmlQPfyK5MAT+cAWfg4NqzQDQ7+mPwU7DJjPqVObzJWUtonT7KPGEASCFGoxQu26t9FCW581zFZcVRnDNUrGf4lk92gXDLZ48BdlE2PC+h5JbmToBnDyQgGlJYMSy486oEjxKxbmQsytBueBQRwchgwjFPZ7SeIcMIxDJlF3vf/ugXuwdhDNULjyYXaEbdS9msfYlTVL9vr6Q== 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=RocJK05lm5JfsZ6M9FwgHiIIPV/JxGNnH4PzFecApYA=; b=BarHwoIFlKB8mlqfS3OW6Z1MQUsnMbpMUf6RWQPp/Rv/Ekno99+HhQH+myzx1Hi5WX2jsad+N1SsbowmYsgqS+f3Etz5o4mY2Q5/3kSr8C23lyjlwabRJ6d+ySKe0/PwFQ7Ns5F/rCwqjuG7bItp1icJP/NPi9DPmPUm6c5bRjg= Received: from MW4PR04CA0098.namprd04.prod.outlook.com (2603:10b6:303:83::13) by PH7PR12MB7163.namprd12.prod.outlook.com (2603:10b6:510:202::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.28; Thu, 14 Nov 2024 23:42:50 +0000 Received: from CO1PEPF000044EE.namprd05.prod.outlook.com (2603:10b6:303:83:cafe::ce) by MW4PR04CA0098.outlook.office365.com (2603:10b6:303:83::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16 via Frontend Transport; Thu, 14 Nov 2024 23:42:50 +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 CO1PEPF000044EE.mail.protection.outlook.com (10.167.241.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Thu, 14 Nov 2024 23:42:49 +0000 Received: from AUSPRSAMPAT.amd.com (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.39; Thu, 14 Nov 2024 17:42:48 -0600 From: "Pratik R. Sampat" To: CC: , , , , , , , , , Subject: [PATCH v4 8/8] KVM: selftests: Add a basic SEV-SNP smoke test Date: Thu, 14 Nov 2024 17:41:04 -0600 Message-ID: <20241114234104.128532-9-pratikrajesh.sampat@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> References: <20241114234104.128532-1-pratikrajesh.sampat@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: CO1PEPF000044EE:EE_|PH7PR12MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f74f144-34c1-4a09-861e-08dd05060cd0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: Ig7O1uZFI5JEWl/2IEwnKzSWAEOsL4cUWUdCRnFIBp+oNAY7R0aym2y/UKI+L+NTzwYUWGXvZyhvM5g+fPcGnM52bvP583AsrrTl5V0kuAgUH4KCCmqUTfryvu8z1qeFhI00k71wAUGvijWcu5SsgyP/dkyt6uMtJwhFTq5xg8V6GbOvb4v8eo4EIMJ+A1rCkwtnYQGEAhYUW8cf7BI5W2sS0NJk0vLqF7wi9yfDqkwOl8MUOtEnBjaqMNF9Wfj988unHpihQOPzX4n2l2W0Cs55R+e4XRaFd+eMnVJlnQnPk9787lH+VxiCmuK8Wn7cPcm37OucNdCFJWh0dQt4kUtV7JX9OfDBah9IATN4I1PuJcKFd0IjqiXTxX9YwKhugjkrGqj2H5wbu1WdNGaPbn3NrylFdDLJUA2Fs9JaaY7Sa6nAYc92PWUow3FnDY7iGCuNSr8n/BZ6EnTap3xxtpgpskYOTnkeqEHY/0gexvTBvdWwPxt7/v9Fs9mBu5TT1kBZXrT2V41XEzoz/laJfQrPb5dYzfPjcfCszMZOTKAyh7AauxJd46RgeQDM8Tm/WyaeUrejyoGSAx3enQR2Pum7UVRqr4l1nNVmfI+bZvSOFXQNcLi1h17/S2eYiR/iY/AdhoVOoBagYm4myOgoWPeh1Kunb7jqR78bDVM6MqkPJeDcN+T8W1hHNBAEWZ8gAcX7C8IhW7kEbzKfEZOwyAZv65JCms7GYxwimVuvrVBXu+efEXXDCA9sg5JEishjNkloIPk5NRf1Tb7X6BTlscoMxdvHeiV4iCsUW0//pPRWVOu/Ej6o2T9VGlpIwjUEgEKSo+Vcxgh9n/Qo13eWsKiLal2mp4ORUNoNILvXCGlS0sfYfKttI5dM/n/BdEJeVQIIQa/MbIZtCRorzlFYXgv3mL6qdZcotMJjFXefHSkSvG/JrGcgw342CnvmhAz1mmF19m9mIhv/ZzN/BWGPvY9nkzMQONJUDePEZRqoTcdpu6CbPr8NPgarhcErrhLK+r2cskc5Alhfef+YRNmc1XeaXpzCfr9KdWuy/lWmz3yQkVqtklifxKasrnEPiNSlNthct0lTKutKwnkGfM48z6YA6+gblk1PIEwlB4ioZd6ajKhZNbj7Oqdm4Kto+WTtyQ/vjBwlZIZew23ACi5VnQhGJaIL40oW6fwFlExbJO8y9biYP2wUteJ2L04op038KuX6EdL0Ob6xo0MvoO/njLM0aiDn0brC7lZNlariOFjhPgQ2VhPY/zWeTM/26YAW74iPLPFU8HmBIVXGYfXOVRSH5Xw1kglys/w3Zk10FEfRFQG1ahlPfbJ/8B3a6fdh+kAYKO0mmd2YDpvTC6nYqCoQOLDlNWogkSuisJaxC47IUDc/qYp29xZp6TkdwwiPKmYl1dCc+JjQhP+CIJKvFg== 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:(13230040)(36860700013)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 23:42:49.7850 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f74f144-34c1-4a09-861e-08dd05060cd0 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: CO1PEPF000044EE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7163 Extend sev_smoke_test to also run a minimal SEV-SNP smoke test that initializes and sets up private memory regions required to run a simple SEV-SNP guest. Similar to its SEV-ES smoke test counterpart, this also does not support GHCB and ucall yet and uses the GHCB MSR protocol to trigger an exit of the type KVM_EXIT_SYSTEM_EVENT. Signed-off-by: Pratik R. Sampat --- .../selftests/kvm/x86_64/sev_smoke_test.c | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c index af1beabbbf8e..ff508d67377d 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c @@ -16,6 +16,18 @@ #define XFEATURE_MASK_X87_AVX (XFEATURE_MASK_FP | XFEATURE_MASK_SSE | XFEATURE_MASK_YMM) +static void guest_snp_code(void) +{ + uint64_t sev_msr = rdmsr(MSR_AMD64_SEV); + + GUEST_ASSERT(sev_msr & MSR_AMD64_SEV_ENABLED); + GUEST_ASSERT(sev_msr & MSR_AMD64_SEV_ES_ENABLED); + GUEST_ASSERT(sev_msr & MSR_AMD64_SEV_SNP_ENABLED); + + wrmsr(MSR_AMD64_SEV_ES_GHCB, GHCB_MSR_TERM_REQ); + VMGEXIT(); +} + static void guest_sev_es_code(void) { /* TODO: Check CPUID after GHCB-based hypercall support is added. */ @@ -157,11 +169,21 @@ static void test_sev_es(uint64_t policy) __test_sev(guest_sev_es_code, KVM_X86_SEV_ES_VM, policy); } +static void test_snp(uint64_t policy) +{ + __test_sev(guest_snp_code, KVM_X86_SNP_VM, policy); +} + static void test_sync_vmsa_sev_es(uint64_t policy) { __test_sync_vmsa(KVM_X86_SEV_ES_VM, policy); } +static void test_sync_vmsa_snp(uint64_t policy) +{ + __test_sync_vmsa(KVM_X86_SNP_VM, policy); +} + static void guest_shutdown_code(void) { struct desc_ptr idt; @@ -195,6 +217,11 @@ static void test_sev_es_shutdown(uint64_t policy) __test_sev_shutdown(KVM_X86_SEV_ES_VM, SEV_POLICY_ES); } +static void test_snp_shutdown(uint64_t policy) +{ + __test_sev_shutdown(KVM_X86_SNP_VM, policy); +} + int main(int argc, char *argv[]) { const u64 xf_mask = XFEATURE_MASK_X87_AVX; @@ -217,5 +244,20 @@ int main(int argc, char *argv[]) } } + if (kvm_cpu_has(X86_FEATURE_SNP)) { + uint64_t snp_policy = snp_default_policy(); + + test_snp(snp_policy); + /* Test minimum firmware level */ + test_snp(snp_policy | SNP_FW_VER_MAJOR(SNP_MIN_API_MAJOR) | + SNP_FW_VER_MINOR(SNP_MIN_API_MINOR)); + + test_snp_shutdown(snp_policy); + + if (kvm_has_cap(KVM_CAP_XCRS) && + (xgetbv(0) & kvm_cpu_supported_xcr0() & xf_mask) == xf_mask) + test_sync_vmsa_snp(snp_policy); + } + return 0; }