From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?h1P2Xe3kMig6/Z5AnCrQQCnEy5kONU/lTHvvShkXJji95FgGFrbh8Bj+u+5r?= =?us-ascii?Q?CHI4wY68RucmkRk18w72TBYvFmgtJNhN3iSyoghZpgSMiG4v9Lu6XKWZqW+2?= =?us-ascii?Q?GLNqz2BqmtcmnAxTfkNieuq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us-ascii?Q?aufyAAUBBIto9CnF2BFvNdxe0yVbZV1UywK1TjHMWDLUdmLfZ3JNvcQOF+yb?= =?us-ascii?Q?DdXfyT70BJDC4FvJC7n4uJbErrn7rOpkm6hWr4kdQpGHkLekfMJip8uu+ePm?= =?us-ascii?Q?H39ql0DDJ07x94v3viDFnUrQp/rGs9gnIaHksQrSacUeszdouyTKcHDGdYLV?= =?us-ascii?Q?cKz6D81TGTrn3PRxH3hrTRJlVVRXBbfezrkvi4gesYd21kOOir9HGlVX3Y5I?= =?us-ascii?Q?npRGdI209DvqgxYlnZEQCXRhZTzIJBrMAEyBVG4euWIMB2lVNuzb/e8L5h2Q?= =?us-ascii?Q?uSg00kFXsd0NVe2l18gVl5BKrjIEI0w9qAXoV9K58rSsLcGaFRqY/65n7As5?= =?us-ascii?Q?vG6AH5bZl5THdbGRDQgNTQnDFv125z3AUOzIA8xxA5Pu8vRFJg=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- 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 =3D min_sev_asid - 1; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)); sev_es_supported =3D true; - sev_snp_supported =3D sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV= _SNP); + sev_snp_supported =3D (sev_snp_enabled && + cc_platform_has(CC_ATTR_HOST_SEV_SNP) && + snp_fw_valid()); =20 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; } =20 +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 =3D 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); =20 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */ =20 @@ -979,6 +980,8 @@ static inline void *snp_alloc_firmware_page(gfp_t mask) =20 static inline void snp_free_firmware_page(void *addr) { } =20 +static inline bool snp_fw_valid(void) { return false; } + #endif /* CONFIG_CRYPTO_DEV_SP_PSP */ =20 #endif /* __PSP_SEV_H__ */ --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?48tZCFVnveGOQ23zuxMpwtUGpAKBK02E6r5ZztssPj0a6yrDOEPzS7gxzSJr?= =?us-ascii?Q?YTmozaEXwhWz8udsOu3Ar1QrWNiv0U3GkLsWc8SF3ksiIlCVoVh8MU/l8YSS?= =?us-ascii?Q?NvxOgfysJahuW0prfJYWJxN3Ob6sCZ1m6nI0AX9O5XjnHpnRrSF4D1RmaOlI?= =?us-ascii?Q?xsJeSnoKInA/ot/axvjWXtoetTCjJusaZT77FSA2vAVEWj4V3p9ld7mMcA1E?= =?us-ascii?Q?LYsWr8CSaN+aKml31jbRuvYsIofCBuO9vlj1oYbw0AE1D9DiZy5beIo6U+Js?= =?us-ascii?Q?WVE3BoKChxSmtPKZr4f4zEtdt5w16HJ0vCeMWsn1I/WiyhDDxmWH7pP8Jwsf?= =?us-ascii?Q?2srUw4VSRN2VxW74lS07F6zppdMo7wMsoTRWAS3LAy4HKm1B8TcdgPfFVnit?= =?us-ascii?Q?mKxCCjJBM5ThbDJbb0CRujTA1ZbsEEB/VQiw/Hk+glrWaaKgho4ZnIsbepn4?= =?us-ascii?Q?gQ3twEQWH01vdPtbhfbVaQzJKOJvSq4+0B9kAf1Ls1eUwNh04zWqA+wdb8q0?= =?us-ascii?Q?LEyCah5IT5yBYT54rKQXRrBpFTMr7MOlDYdZqyLhnVOe+YGp4G+sp4EVoZ3I?= =?us-ascii?Q?DHVnm5mUHIL2SiEKowHU3EFNvlymzGv48nLFold1z0qdtF3FS7ZG275AxTd5?= =?us-ascii?Q?dBN7FcZlJkPmpEXhLcs3PY5c8bYszLp7SBx5f5JFBhnIDEJ5RJh7uDvzRWeL?= =?us-ascii?Q?QJ+K6h/Q5MbwJjv8tyWgyjZ17kV9MmwCBOXyqq/PpxVuQuVCoI5+YXtnr2A0?= =?us-ascii?Q?oxff31svNZfHIuojScZ11u+tRPcLkEBTQOPTpzHZUGG4V/fBN316kPi9WPbI?= =?us-ascii?Q?cQwNwdiPssHYIsohGmynDF2CJyrvIwvMxttq58bMSJsd2YH0z5uAFvVbaYJl?= =?us-ascii?Q?fO3IRKCOaPGmpAMjFuBkQyryUUnOgbBrs+QKh24NcyYpg2IImncMUzMijTZF?= =?us-ascii?Q?heDqLaFqo15MXSavyrexJ0FOn7Q2WmZ7d4trrsscVTsPqlwVgZFveqfihQFF?= =?us-ascii?Q?jye8NI9vKCFJpJE6/txhjVkFyrADQONhWVNRKW6gcSZuVeNnKatzFI9OI3vK?= =?us-ascii?Q?h/H+69Ms/TjM4jix54c7FHfxE8QwBrm1RmioAks8mSG/cug1xXgyUoU+35b0?= =?us-ascii?Q?0x7WZ73OI5iD1kQfhv8tfQKDoet02iwkaAOMeKxQOKENHpjNahZaoDY5kM3w?= =?us-ascii?Q?TZBA57Af4HcGJajwBLNbOVqOSeZQwseTzufwib0/0Hjs65nIs5Yl+4Ew5wBh?= =?us-ascii?Q?r18739x6PZvUdTV3pn5VYva0G/zATC6yIW+0/pZyUXsjLNSbPR/qHXZt9Fju?= =?us-ascii?Q?s1sdmPiXiMTUk58xdFQdKCjfTrX4EeBh/1AiOL7ZHv3z9y6l916t/d3Vfhd5?= =?us-ascii?Q?ldvsY7gfvOVJBslU12hqZoRSqNvjz3ZGAvUhXeyU4nM5To+RVg=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- .../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) =20 /* * KVM defined paravirt features. diff --git a/tools/testing/selftests/kvm/x86_64/sev_init2_tests.c b/tools/t= esting/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; =20 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){}); =20 + 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); =20 + have_snp =3D 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(); =20 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); =20 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); =20 return 0; } --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?UJl4owoDp2E4VwLiUjM411/LAw3qIlovZxZ5RnkNkFXgZTKIaIh6BwrZcr4A?= =?us-ascii?Q?bU1DKeZgC+4dn6RGq47vgdgqXHQUzD1fMWur+7XzEBvPeyUns807mNSxT81C?= =?us-ascii?Q?N0PSfMVVxxcEoccKt/ghAQRQnnuwsbf2ljMdqDHTU2NXch7RzcFB1MxnlN1J?= =?us-ascii?Q?H7ptfUDeRTTXvpLwMkE8mKMQo3UyY03fUgODRhj7GjPcub59RHThxH79BCYW?= =?us-ascii?Q?eFC7FEnXleTCfHPVelWRggA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?Q?aPhF5yvZTyNleq1Tp2YjqLqZopSwJa+S/yo2EZAfXeJ0WFeuqYoGX3YkjLYY?= =?us-ascii?Q?cAOj7B9KVKqzKaIJvSu9sPTGUsh1Xz6X9YM9G9t5pAHwi/Ltw89IA9itiXAU?= =?us-ascii?Q?fSNTSf6EC3vpDt9415qNhdxx6desPCXaIzqwW4uBx+OTkKoJMdhlJEOQPLgb?= =?us-ascii?Q?urYouMfHV34y349GqIWrabR9GKLxp3trtrwx2k4MeMgkNPWUHXVCriehpS6n?= =?us-ascii?Q?0DfF3tWShPs08mPq4R3ZeB7vJV+WB4C1ye/6IV4PQHsI+Kbg5g=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" Abstract rep vmmcall coded into the VMGEXIT helper for the sev library. No functional change intended. Signed-off-by: Pratik R. Sampat Tested-by: Srikanth Aithal --- 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/testi= ng/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 { =20 #define GHCB_MSR_TERM_REQ 0x100 =20 +#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/te= sting/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(); } =20 static void guest_sev_code(void) --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?VQXyZBsKu6Y8JgnxXkgyqStt09/7M2SrhLNGeVl9yyNKdO7d/Wp0ZuT/5nHP?= =?us-ascii?Q?MB6X3RslpUGCYV1/zDLFzix65beg5S3Vs+FVJKKRhcA/W4K8i0YdSiw0nYN4?= =?us-ascii?Q?dgW/ufEeBJnGNSR3n1bCc6pniPGOdexXRXBCeVa5Jt2MzGzw096Zbs99w/yn?= =?us-ascii?Q?3sRY8B5M3dxA09CbWGKYbVoPChFafL+jEc/h9ChFXveFYcf7UPFG1A2ljI5x?= =?us-ascii?Q?W9u/t81b0N3TlLh5vZR5PrTcTxcHXl2kGVYzClRbUmQp2Fns9twix7iED7MR?= =?us-ascii?Q?IrQXNqjbZXvjc6O/8rfqHuRBezeCN1nMqxdWBv2dd1NlhwisgPJhdCEVCjsX?= =?us-ascii?Q?jf2xH21V47S6RQMZ0ZglJkNQGoS+2iMvom7R56OlAy5AYDtFIqO0A8x6bOAy?= =?us-ascii?Q?svz4rna6JXSGqC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?us-ascii?Q?hc92w4EejmQfWINz7+wO+RDpCB9R1c1rFIq/d64ntFXesK7WwMHeZSoFp8w6?= =?us-ascii?Q?BcwBSVxZPrN1ReO2tT+rCub8Ep4xw2kmKLFCF5+FNtMX1Awvfg=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- .../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/testi= ng/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 { =20 #define VMGEXIT() { __asm__ __volatile__("rep; vmmcall"); } =20 +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/tes= ting/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); =20 - if (vm->type =3D=3D KVM_X86_SEV_VM || vm->type =3D=3D KVM_X86_SEV_ES_VM) { + if (is_sev_vm(vm)) { struct kvm_sev_init init =3D { 0 }; =20 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) =20 void kvm_init_vm_address_properties(struct kvm_vm *vm) { - if (vm->type =3D=3D KVM_X86_SEV_VM || vm->type =3D=3D KVM_X86_SEV_ES_VM) { + if (is_sev_vm(vm)) { vm->arch.sev_fd =3D open_sev_dev_path_or_exit(); vm->arch.c_bit =3D BIT_ULL(this_cpu_property(X86_PROPERTY_SEV_C_BIT)); vm->gpa_tag_mask =3D vm->arch.c_bit; diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/s= elftests/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 @@ =20 #include "sev.h" =20 +bool is_sev_snp_vm(struct kvm_vm *vm) +{ + return vm->type =3D=3D 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 =3D=3D 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 =3D=3D KVM_X86_S= EV_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/te= sting/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); =20 - if (policy & SEV_POLICY_ES) { + if (is_sev_es_vm(vm)) { TEST_ASSERT(vcpu->run->exit_reason =3D=3D KVM_EXIT_SYSTEM_EVENT, "Wanted SYSTEM_EVENT, got %s", exit_reason_str(vcpu->run->exit_reason)); --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?DSRc7zDnkl22EmNC2/WKfi1Vur0cTmOCp2ZmKXD09BTe9thCr7dO5KR5xdqe?= =?us-ascii?Q?bS00wNPspYXbnxiVsRC/iqJ1e4H7IVUQUSRkRAB8ojHyBaM16WsbSxALd7EF?= =?us-ascii?Q?ImKu6Kxh1+LwUF10QnbxMXaE4P2oUESnJ6ghaPzbucsoe08E4B/0m1Be5e/E?= =?us-ascii?Q?JlJWbfcrE6bH/Oocvds8oPfepRRRCRw55LkVhyuMp97HQMm7uYNfAj2ncrVS?= =?us-ascii?Q?ABGlIx2II0TbjltP7atjTaY325Zzeb++GtpqUjPCD1tqTIvrT6FjKcI3Xbdt?= =?us-ascii?Q?0L+1bUxbvBhlLv+V//43dmTSfIrC1qH8qh4vqgy7PF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1CnoZmfk6jL+B6r12q8ktJmu0vxszrl/mS/wDYJbZO6t?= =?us-ascii?Q?JCRp/J/JagzlET7H4hbGUTHYbYW1JzkrSmxZS6SEYynYv4Vyy26XwirsLN7x?= =?us-ascii?Q?KgBrV/ZE27JICxTR3F0ff0QvIHuDQVxtQ1pcLhRA3mI2h9OEZNHGY1NECsRX?= =?us-ascii?Q?/NnMdoz5uqsYUb6MvU9OIVYPezqOK9S8/9XI0dzRs2MQz6C2rQ=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- .../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/testi= ng/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, }; =20 +/* 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) =20 +#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 =20 #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); =20 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 *measuremen= t); +void vm_sev_launch(struct kvm_vm *vm, uint64_t policy, uint8_t *measuremen= t); =20 kvm_static_assert(SEV_RET_SUCCESS =3D=3D 0); =20 +/* + * 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 =3D false; + FILE *f; + + f =3D fopen("/sys/devices/system/cpu/smt/active", "r"); + if (f) { + smt_active =3D 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 t= he @@ -76,6 +109,7 @@ kvm_static_assert(SEV_RET_SUCCESS =3D=3D 0); =20 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); =20 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); } =20 +static inline void snp_launch_update_data(struct kvm_vm *vm, vm_paddr_t gp= a, + uint64_t hva, uint64_t size, uint8_t type) +{ + struct kvm_sev_snp_launch_update update_data =3D { + .uaddr =3D hva, + .gfn_start =3D gpa >> PAGE_SHIFT, + .len =3D size, + .type =3D 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/s= elftests/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 =3D region->protected_phy_pag= es; const vm_paddr_t gpa_base =3D region->region.guest_phys_addr; @@ -41,16 +42,39 @@ static void encrypt_region(struct kvm_vm *vm, struct us= erspace_mem_region *regio if (!sparsebit_any_set(protected_phy_pages)) return; =20 - sev_register_encrypted_memory(vm, region); + if (!is_sev_snp_vm(vm)) + sev_register_encrypted_memory(vm, region); =20 sparsebit_for_each_set_range(protected_phy_pages, i, j) { const uint64_t size =3D (j - i + 1) * vm->page_size; const uint64_t offset =3D (i - lowest_page_in_region) * vm->page_size; =20 + 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); } } =20 +static void privatize_region(struct kvm_vm *vm, struct userspace_mem_regio= n *region) +{ + const struct sparsebit *protected_phy_pages =3D region->protected_phy_pag= es; + const vm_paddr_t gpa_base =3D region->region.guest_phys_addr; + const sparsebit_idx_t lowest_page_in_region =3D gpa_base >> vm->page_shif= t; + sparsebit_idx_t i, j; + + sparsebit_for_each_set_range(protected_phy_pages, i, j) { + const uint64_t size =3D (j - i + 1) * vm->page_size; + const uint64_t offset =3D (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 =3D=3D KVM_X86_DEFAULT_VM) { @@ -77,6 +101,14 @@ void sev_es_vm_init(struct kvm_vm *vm) } } =20 +void snp_vm_init(struct kvm_vm *vm) +{ + struct kvm_sev_init init =3D { 0 }; + + assert(vm->type =3D=3D 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 =3D { @@ -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); =20 hash_for_each(vm->regions.slot_hash, ctr, region, slot_node) - encrypt_region(vm, region); + encrypt_region(vm, region, 0); =20 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); } =20 +void snp_vm_launch_start(struct kvm_vm *vm, uint64_t policy) +{ + struct kvm_sev_snp_launch_start launch_start =3D { + .policy =3D 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 =3D true; +} + +void snp_vm_launch_finish(struct kvm_vm *vm) +{ + struct kvm_sev_snp_launch_finish launch_finish =3D { 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 ty= pe, void *guest_code, return vm; } =20 -void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measuremen= t) +void vm_sev_launch(struct kvm_vm *vm, uint64_t policy, uint8_t *measuremen= t) { + 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); =20 if (!measurement) --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?AOpjWPE7p3ehCh5WhQ9Pa17qnGtc0P0EoJ1QllZeuxQGV+x5gxH8n9UjgIUz?= =?us-ascii?Q?Kw3kp2lweUYNf5oe4pwCGVlA/JApJXOBMP4o77FZkj5xPwKa4uCdn1RsZkO3?= =?us-ascii?Q?WniRCTwtx7IyLDZifV3erNhX5oj5/SDvHbgyE5Cw3ZNV5ztgznSlTg0ULDin?= =?us-ascii?Q?bJuvtircSdB9oH1/hCF0tRvWII+DmlvXl2Pnj5rPz80XbqT4cvkRjTJgopKT?= =?us-ascii?Q?4cAar42rl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v/8VDnu+CmySMGG/BWvW?= =?us-ascii?Q?BcveX/eWDE/v+a9Epam5BlbRHxzzTMt7HMtgAFE9n/UQCHgdlQ664PzP245f?= =?us-ascii?Q?eoTULFXIrqQdCFwNIHweMQEFkGQZOVy3n8ZWPOGpfR380pik4FAnaNvhYHsQ?= =?us-ascii?Q?8/Ss/lqht5NRgqXlVuYMbXRRqoTxYw5g+MlPQxe2M6wvmZhFlXHiWVLc8DDe?= =?us-ascii?Q?/RgukvFHDWX54pNjYKK4mNgNh7OF6XSJz9xKYvtk8OVG1xXEtF8rONC6skWB?= =?us-ascii?Q?re5tc9ycr+xeIue933WsqynwZ/IT1c5YEmZDzVzel19PY9CaSw=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- 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/sel= ftests/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, uin= t32_t nr_runnable_vcpus, nr_extra_pages); struct userspace_mem_region *slot0; struct kvm_vm *vm; - int i; + int i, flags =3D 0; =20 pr_debug("%s: mode=3D'%s' type=3D'%d', pages=3D'%ld'\n", __func__, vm_guest_mode_string(shape.mode), shape.type, nr_pages); =20 vm =3D ____vm_create(shape); =20 - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, nr_pages, 0); + if (shape.type =3D=3D KVM_X86_SNP_VM) + flags |=3D KVM_MEM_GUEST_MEMFD; + + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, nr_pages, fla= gs); for (i =3D 0; i < NR_MEM_REGIONS; i++) vm->memslots[i] =3D 0; =20 --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?S1YAs6oISW0AMDWpOKtD0B9FmeMb43dwtVflnYgmy9Y8r0NAMaGIZjFbYj07?= =?us-ascii?Q?Xbka+3Sl16IubqqpcSkWC90mMJfvgICfj6VQ2r7BrDY7lGbBAE2UyTEoko0O?= =?us-ascii?Q?M4CuPaHHSjeY6o7evLDHfGGwN3ponoEZjUq8IRVkJHWhBPFhKqk/V8gODAob?= =?us-ascii?Q?Vt1UEar9o7jo/v+RWTjaaXgvD78Rcr4apXabSsGJ7Q9NdxTKUQnUGIu42VYY?= =?us-ascii?Q?qczTupgUKv+bVpnXqO2QEiM+R5qQ1cHqdFrT3QzCJAEp6TLM8t36C+oGypV3?= =?us-ascii?Q?/TjXx0mUB3epfrfG6vpHdpfmBZ4r5waqPNk6HwtdjgQmfi6tHMYO9g9U74ow?= =?us-ascii?Q?BHGn5yZe1g56MegFvp0n1S6JpdK5zARKrVVgiMtsmhy2toQK49Ne+hThYIB8?= =?us-ascii?Q?B8hpnsVbK4vpQrpSrp7MT6l4MfieBJI9XeD7G/LJDRW6VeKo/YTATR4PgR2S?= =?us-ascii?Q?E4lrsKci59iMiwAfFrL1itxx6+BbKQ0B1qAmDmiVCrSV/CeskaXHY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ucYslQIL4jbbudmjiM00UEhWWtPZjxl3Q=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- .../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/te= sting/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(); } =20 -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 =3D M_PI; struct kvm_xsave __attribute__((aligned(64))) xsave =3D { 0 }; =20 - vm =3D vm_sev_create_with_one_vcpu(KVM_X86_SEV_ES_VM, guest_code_xsave, &= vcpu); + vm =3D vm_sev_create_with_one_vcpu(type, guest_code_xsave, &vcpu); gva =3D vm_vaddr_alloc_shared(vm, PAGE_SIZE, KVM_UTIL_MIN_VADDR, MEM_REGION_TEST_DATA); hva =3D 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); =20 - vm_sev_launch(vm, SEV_POLICY_ES | policy, NULL); + vm_sev_launch(vm, policy, NULL); =20 /* 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); } =20 -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; =20 - uint32_t type =3D policy & SEV_POLICY_ES ? KVM_X86_SEV_ES_VM : KVM_X86_SE= V_VM; - vm =3D vm_sev_create_with_one_vcpu(type, guest_code, &vcpu); =20 /* 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); } =20 +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"); } =20 -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; =20 - uint32_t type =3D KVM_X86_SEV_ES_VM; - vm =3D vm_sev_create_with_one_vcpu(type, guest_shutdown_code, &vcpu); =20 - vm_sev_launch(vm, SEV_POLICY_ES, NULL); + vm_sev_launch(vm, policy, NULL); =20 vcpu_run(vcpu); TEST_ASSERT(vcpu->run->exit_reason =3D=3D KVM_EXIT_SHUTDOWN, @@ -179,25 +190,30 @@ static void test_sev_es_shutdown(void) kvm_vm_free(vm); } =20 +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 =3D XFEATURE_MASK_X87_AVX; =20 TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV)); =20 - test_sev(guest_sev_code, SEV_POLICY_NO_DBG); - test_sev(guest_sev_code, 0); + test_sev(SEV_POLICY_NO_DBG); + test_sev(0); =20 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); =20 - test_sev_es_shutdown(); + test_sev_es_shutdown(SEV_POLICY_ES); =20 if (kvm_has_cap(KVM_CAP_XCRS) && (xgetbv(0) & kvm_cpu_supported_xcr0() & xf_mask) =3D=3D 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); } } =20 --=20 2.43.0 From nobody Sat Nov 23 01:28:35 2024 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: =?us-ascii?Q?Ig7O1uZFI5JEWl/2IEwnKzSWAEOsL4cUWUdCRnFIBp+oNAY7R0aym2y/UKI+?= =?us-ascii?Q?L+NTzwYUWGXvZyhvM5g+fPcGnM52bvP583AsrrTl5V0kuAgUH4KCCmqUTfry?= =?us-ascii?Q?vu8z1qeFhI00k71wAUGvijWcu5SsgyP/dkyt6uMtJwhFTq5xg8V6G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mc1XeaXpzCfr9KdWuy/lWmz3yQkVqtklifxKas?= =?us-ascii?Q?rnEPiNSlNthct0lTKutKwnkGfM48z6YA6+gblk1PIEwlB4ioZd6ajKhZNbj7?= =?us-ascii?Q?Oqdm4Kto+WTtyQ/vjBwlZIZew23ACi5VnQhGJaIL40oW6fwFlExbJO8y9biY?= =?us-ascii?Q?P2wUteJ2L04op038KuX6EdL0Ob6xo0MvoO/njLM0aiDn0brC7lZNlariOFjh?= =?us-ascii?Q?PgQ2VhPY/zWeTM/26YAW74iPLPFU8HmBIVXGYfXOVRSH5Xw1kglys/w3Zk10?= =?us-ascii?Q?FEfRFQG1ahlPfbJ/8B3a6fdh+kAYKO0mmd2YDpvTC6nYqCoQOLDlNWogkSui?= =?us-ascii?Q?sJaxC47IUDc/qYp29xZp6TkdwwiPKmYl1dCc+JjQhP+CIJKvFg=3D=3D?= 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 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Srikanth Aithal --- .../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/te= sting/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 @@ =20 #define XFEATURE_MASK_X87_AVX (XFEATURE_MASK_FP | XFEATURE_MASK_SSE | XFEA= TURE_MASK_YMM) =20 +static void guest_snp_code(void) +{ + uint64_t sev_msr =3D 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); } =20 +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); } =20 +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); } =20 +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 =3D XFEATURE_MASK_X87_AVX; @@ -217,5 +244,20 @@ int main(int argc, char *argv[]) } } =20 + if (kvm_cpu_has(X86_FEATURE_SNP)) { + uint64_t snp_policy =3D 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) =3D=3D xf_mask) + test_sync_vmsa_snp(snp_policy); + } + return 0; } --=20 2.43.0