From patchwork Tue Jan 28 12:48:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13952522 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2089.outbound.protection.outlook.com [40.107.243.89]) (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 8E8B019CCEC; Tue, 28 Jan 2025 12:48:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738068529; cv=fail; b=XTZO6GBZGco3do+DDxIlnHY8igk0+cZVBZWaoD9jqqLJyB4RuluVdz0FJY0NHUx8RvpOii0L7uf7K+eXUvDtt2L8sUU4GCZ/htOjk0Y2uuHm3MlhVaJ32KxCFppHrfq4lFdO/tilhF6ctHQM/Bz+QgiHcOnd+JT12sMdykpq6E8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738068529; c=relaxed/simple; bh=tWgY8cTdlv/sJqINWImpRVT8JXFAkyy3xXinPp/CIQs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HxCaBsBmK41YkW3ha7rrS/PQi4BBQOfDswlP7/bHTdYrERWadtQlsUIcx8uIyvhPflStHrIpBCA9n4DTVWCTtwkwpBR794Cgrie3SORNb6ksJcpp+orLmcflcVF7cTLktZiarGK795WYTobE1h8WQk0E2rloUrupMnntL6t+2b4= 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=XEahunC+; arc=fail smtp.client-ip=40.107.243.89 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="XEahunC+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mF8ooNIztllXnKaPDTUwQ+s6oq0Q7sywru13+hW+f58iwlASCbPRfW8Maw6gj9tHirgJnioLJttSNJ/InbHsluuRsQYvbEQmBO4pyVFSOHHlXzSI1NYdAuOzorT0gD/GqGGaDv8nyRgsORALblI6CGp0kZ/GaeD23WjZo1ONoUc6KYGOt64Fxs/z5/wPLasqQozfznl/G0buHgiGSEzUi0EmH4ZA0TnNPnx8H6gSmo0Lu7vy8rom6hxLGvgwwj78YWH8LvLFzOWzJinHFLqornfDQevTSKgvQ3up9075le+mGLbfHcy25LVWTn93pZ5DkKFzjEfNzRKvsDTd2HscfQ== 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=Pp+59hqxTpwyVeLL3P84P3XqtRKn1hzBi6Y5kNfcaF8=; b=HpzmrYBHuuPpNldGAWn5Z6QGBbZEPq8KE4gtXdsLx/r2mxLXwoABfgncrhwhnFM5ZNPpyBiBgI0PQbvhkhJE465cG0tnHsBt6PPOGb0et9OEdmDTmEpdecKLzXuQZVIACmHoRK+/KiLaq4QMHlPhKzFuqypaglcLtHpVIeNFkt1ejtOmm8GE4bg35C0ZZYz5BWdLHHXkOe4S1g4eNKh/Y6Vk3UbCpjiZ2L+Sd9JiVr8Fx0pA11BvulWZztasYnlICPCU396EGObFiJyOf9TbVfFBw1SyV07j3cs37iBLjuuxsVbgpX/WOmVhsAw+WJJMEVBoYdEfbck2pFEp7OBaXg== 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=Pp+59hqxTpwyVeLL3P84P3XqtRKn1hzBi6Y5kNfcaF8=; b=XEahunC+U+ZDkpPTgKGChOsYdHo/BYxbLh0M66w9jqNN8bjXREFKsYYSstpKDkkMkDKgX2lAj11F/ERezkA1dYYLV+ThR9UT1LTWxM5UVn6Q1PU+iBVdFs8C4NvXdBrPjEwWYOJqAtIbYt5K5KnUljaxy1p94jGaqsJuSxdGCPM= Received: from BN9PR03CA0980.namprd03.prod.outlook.com (2603:10b6:408:109::25) by CY8PR12MB8266.namprd12.prod.outlook.com (2603:10b6:930:79::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.23; Tue, 28 Jan 2025 12:48:43 +0000 Received: from BN3PEPF0000B36D.namprd21.prod.outlook.com (2603:10b6:408:109:cafe::d5) by BN9PR03CA0980.outlook.office365.com (2603:10b6:408:109::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.23 via Frontend Transport; Tue, 28 Jan 2025 12:48:43 +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 BN3PEPF0000B36D.mail.protection.outlook.com (10.167.243.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.0 via Frontend Transport; Tue, 28 Jan 2025 12:48:43 +0000 Received: from chalupa-d178host.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; Tue, 28 Jan 2025 06:48:41 -0600 From: Manali Shukla To: , CC: , , , , , , , , , Subject: [PATCH v6 1/3] x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept Date: Tue, 28 Jan 2025 12:48:10 +0000 Message-ID: <20250128124812.7324-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250128124812.7324-1-manali.shukla@amd.com> References: <20250128124812.7324-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@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: BN3PEPF0000B36D:EE_|CY8PR12MB8266:EE_ X-MS-Office365-Filtering-Correlation-Id: 0306e733-2206-4542-eaf6-08dd3f9a1908 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?z20MnlEi94Yzd5UjyON123BP509BWkI?= =?utf-8?q?P89qZDwKp2rjESQi1tQyLOvvQwruL0eRUh+7O/F391GLfM6WGIpsfq6meHOrtE7hB?= =?utf-8?q?sd9/ZMiqbPKVRXt+FFJ4Gp2MebLfFOTFlvxvtoDXF/CHTgcHcSpMPXMAo556c2cQn?= =?utf-8?q?BjGvcfmEfuMI9xSPAg981fD7IW8ZXWXzKLP3qbBdjSWhYaOO4i1gTE25LIUwaIN6Q?= =?utf-8?q?rkBdAyvZ/2CHkGlIY0w7DpLVOuXY0BdkzuPrHDIrSDb1IKM4POAZcG6ygcux3gq9F?= =?utf-8?q?B/vJSTGh3MvG2TI5a9KW4x1w0xVpd9P9jMK6xxddTPXWMxJxx0SarIyzptI8PK1gC?= =?utf-8?q?HKnOND8in1RRrjk7cy+HjLzJVSCWtaiwF1xWSXG1IjF8y0Dot68bAl1VZmswtaxUZ?= =?utf-8?q?z05oi/rULweJvM/MeYNgNc9FFlGmGSlw8n4qaqdnN8E2nll6RPbcAgqyjgzr3CVOh?= =?utf-8?q?/uWDiOEXEuzjoiQl6j6K+7z0AtrTZp9f8YSrZh277+7TEL/ES534+cmkafEnI4+Ww?= =?utf-8?q?Zgk1dGzS3yP+jQOEn1Xhc+bTqzf7Q+gZkVle5NAMa2o/+Abkm9eZDH64snqsKkm5n?= =?utf-8?q?o7rG/J6Sv8/RooHa+nBQbHtf6JL4Gk0o4lcubuUqWshKLuWI2Z7FQQoxpoxrsjS6a?= =?utf-8?q?knyoG/Cs+JlkPJSbowOX1+eMCXOUBwG7eE6fTjCTend2lonyZty3yRBRnTr95cco7?= =?utf-8?q?3b7gm2p7cD1qFfD2aFjyjqqZKs0xk/4VE05xp8skSfgW13a7tYWoJp4skoqW+QJoI?= =?utf-8?q?AXeOBwT0E+ZHFjfBBMlZRaHu5SgS6MM7cW43PtSPnTDhuV1Je/egW8T1REYilvQQy?= =?utf-8?q?Mw5vthIqk0QandXar9TjXrJ4aKQLO0WV70jUDmQeGGNcValNkT4xEqVqnJTILwHje?= =?utf-8?q?8dF9fDpu66OYpz+v5UAxw7I0BMe2uQTR2J+5Msgf2l4P1vW9VliY1BVT7Zazz0/1m?= =?utf-8?q?lP1UFYFStXN7Kd/nFB6cQ95bsSLgT/ioX6u47JyuRNVNmQxqcE3gPHUQ0dQqJsa25?= =?utf-8?q?HHGN99A2ZgzZBnYNH61A3p160hNWcthXcjKsv0Nm45k62xpLdw3omM0UvJEzan7qg?= =?utf-8?q?M7G8E3ok2h+/hTW8KPYlnOmGX8VnO+ORmjJeAaMw5ZJ7L9M1hR4DAed1TIYUfT1ys?= =?utf-8?q?Oz8rvRkp1YXwBnh3rZewjzLE+rf0kyYJ5eYs16XLgdcLgbdx9c2JOOTptqE004dfz?= =?utf-8?q?BvOC9xIduqwTPNG8QVAb4ODvBhUibQRQAVdrrQAipJbCKwIwocFTsRB98AJwcQH2u?= =?utf-8?q?obcHK/qEJSMZKMitPM4cAKKtMIZIY0YyfPoct/TgobylDpspv4FqJujk95ZsjQz0f?= =?utf-8?q?rFJdNLpd9pwjVT1lmE84sY6GYKmqynoy3i0hw7mb9u8FEGMsU2Tcv3ePlQpDHqBL5?= =?utf-8?q?0cW3NIcnd5Fbcu83Ou3wSrqzzVtJEXFdw98pjPYHEizYt1z38qv2Hc=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)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2025 12:48:43.3225 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0306e733-2206-4542-eaf6-08dd3f9a1908 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: BN3PEPF0000B36D.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8266 From: Manali Shukla The Idle HLT Intercept feature allows for the HLT instruction execution by a vCPU to be intercepted by the hypervisor only if there are no pending events (V_INTR and V_NMI) for the vCPU. When the vCPU is expected to service the pending events (V_INTR and V_NMI), the Idle HLT intercept won’t trigger. The feature allows the hypervisor to determine if the vCPU is idle and reduces wasteful VMEXITs. In addition to the aforementioned use case, the Idle HLT intercept feature is also used for enlightened guests who aim to securely manage events without the hypervisor’s awareness. If a HLT occurs while a virtual event is pending and the hypervisor is unaware of this pending event (as could be the case with enlightened guests), the absence of the Idle HLT intercept feature could result in a vCPU being suspended indefinitely. Presence of Idle HLT intercept feature for guests is indicated via CPUID function 0x8000000A_EDX[30]. Signed-off-by: Manali Shukla Acked-by: Borislav Petkov (AMD) --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) base-commit: eb723766b1030a23c38adf2348b7c3d1409d11f0 prerequisite-patch-id: cb345fc0d814a351df2b5788b76eee0eef9de549 prerequisite-patch-id: 71806f400cffe09f47d6231cb072cbdbd540de1b prerequisite-patch-id: 9ea0412aab7ecd8555fcee3e9609dbfe8456d47b prerequisite-patch-id: 3504df50cdd33958456f2e56139d76867273525c prerequisite-patch-id: 674e56729a56cc487cb85be1a64ef561eb7bac8a prerequisite-patch-id: 48e87354f9d6e6bd121ca32ab73cd0d7f1dce74f prerequisite-patch-id: b32c21df6522a7396baa41d62bcad9479041d97a prerequisite-patch-id: 0ff4b504e982db7c1dfa8ec6ac485c92a89f4af8 prerequisite-patch-id: 509018dc2fc1657debc641544e86f5a92d04bc1a diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 645aa360628d..4fef0533f764 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -386,6 +386,7 @@ #define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* "v_spec_ctrl" Virtual SPEC_CTRL */ #define X86_FEATURE_VNMI (15*32+25) /* "vnmi" Virtual NMI */ #define X86_FEATURE_SVME_ADDR_CHK (15*32+28) /* SVME addr check */ +#define X86_FEATURE_IDLE_HLT (15*32+30) /* IDLE HLT intercept */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */ #define X86_FEATURE_AVX512VBMI (16*32+ 1) /* "avx512vbmi" AVX512 Vector Bit Manipulation instructions*/ From patchwork Tue Jan 28 12:48:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13952523 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2079.outbound.protection.outlook.com [40.107.101.79]) (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 BE01219DFA7; Tue, 28 Jan 2025 12:48:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738068529; cv=fail; b=rfvyntyaLNX78jZmb/1tRGWD7VLRom4CVgPsy19uid4OjZ0ipjrNVfSH/TUxAz9Q3AqfqfH2oPc7kuFhRx7eyrdB3vwiuiofQ1fX8PkOMwqGIE+5/8/1v8sRqjpVxJtUdSF0IVuEIoymzvHojGSXgx9qQlFHUd3LEK8xSOgt6Lc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738068529; c=relaxed/simple; bh=gdbrOASGzEgjH3zU2DWHsCB0oQ3s0Hvo3lWShpr184s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mD2mfp/K3aAyH3DyV1dL8Jh9/os/9oB67voPJW3WfX7C6p9dDfp873kRHf4YS8/Mv+HpIDc2q7Tn6zn3OGdLTuJfYfKAJPIjbeb0N+3LAzRnWEFfGKxKJ/nQ/zarBFrsD/Bim9HlZTbH6RIrGqkVOgkkk2uLXxCAICfmWYRvJZg= 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=AkbknGk6; arc=fail smtp.client-ip=40.107.101.79 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="AkbknGk6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C2HOWaUrg5cw02rX9Bm6rBhRZm6bG4J7ann1//89XIfkbJK26iD3Ti5DrarP+RYlFsk9TjZewPhz2xbECB783cssbaubAlXvB/ON3b5RLUrNWsA6m4QOWbDkq2rBjM3ixs7MYyOvIsZ44GzCIp9mx9bL4GKc1R4MnhGBokTgOcmu2muejkC6NkD+N2IBXf5HPkKnZu6Yr09tQ+LFHVS7UYIUYURTZu3ncQ0LiBLA7WxWWliSBv7Y8AeiWJdG6WjraIPnJUQLw9R0NxkH0yL3AQcARcvcRNOFG6JtCfFHskaj9o02XUs29MsmjdgZCGKNp+lUNWdgYVPtMkQwWjPk2w== 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=bpOaFw1RNV7Wa2HGXYwo2f/HUCqUtvxbTncgASLUi4s=; b=KI2ac77jLqMy6dl1UBCfJZcZgOMS8xHxvNty2hkfoXLe9fRGcRuFtckKrH5HDK3NRlhzzeCO69TctLCbRdWap41QederJIh38lfm6uZ3hOqdNQnnmneOUvaJWUD0OOw773Yhe0GJd/GiWSjUtaWN6mQbhG8iqTZGmLA0OQLDv7Axw8mTYomFoZ3OWV3/KrBb24GQLt34GXPjM6H2xNdspQKGtNFvB49IkAEDL19ibSb4ujlZVJUVXaVED8i/+ceudbp0ufe2jfNviUQuEFR5ic0YwWGmkSUeUwsOqfv+IV/pX/2Laf5JXFApWgOQSA2wGKX6P/e/CmmOT7zuSsJhDg== 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=bpOaFw1RNV7Wa2HGXYwo2f/HUCqUtvxbTncgASLUi4s=; b=AkbknGk6a3Cz8+hjsdvtwlgRECYrnoy5zp6FxVaj/uNzuTRD/vhcQ5VFzdDzhWWlAGLm2YvvcCCCNyongdtawFzURrMTc1TrVE6S6xOOm8wCcWg9kRsGE6gXcGtclC4OEQSgSRZpbHcue4+fh8uiwomycQz8ch8gFlNj/F6f070= Received: from BL6PEPF00013DFC.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1001:0:21) by PH7PR12MB9254.namprd12.prod.outlook.com (2603:10b6:510:308::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.22; Tue, 28 Jan 2025 12:48:45 +0000 Received: from BN3PEPF0000B36F.namprd21.prod.outlook.com (2a01:111:f403:f90b::1) by BL6PEPF00013DFC.outlook.office365.com (2603:1036:903:4::4) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.23 via Frontend Transport; Tue, 28 Jan 2025 12:48:44 +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 BN3PEPF0000B36F.mail.protection.outlook.com (10.167.243.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.0 via Frontend Transport; Tue, 28 Jan 2025 12:48:44 +0000 Received: from chalupa-d178host.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; Tue, 28 Jan 2025 06:48:43 -0600 From: Manali Shukla To: , CC: , , , , , , , , , Subject: [PATCH v6 2/3] KVM: SVM: Add Idle HLT intercept support Date: Tue, 28 Jan 2025 12:48:11 +0000 Message-ID: <20250128124812.7324-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250128124812.7324-1-manali.shukla@amd.com> References: <20250128124812.7324-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@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: BN3PEPF0000B36F:EE_|PH7PR12MB9254:EE_ X-MS-Office365-Filtering-Correlation-Id: 483fd466-ae74-46e4-afa0-08dd3f9a19ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?KJA0FLT5vVO8wWqb1du9nCLsLqd8tD8?= =?utf-8?q?s+GrarD/AbRxpnRtGobGW7DuKVdBZgCyUWW6mGf7OMLEblDeA12IXEuR+lguQj7z7?= =?utf-8?q?8uQNqIADCnLyGCfidUrMrlb2+GPdtldx22UWy3lKbS38iVgjexxiT+Ih0GDKoREXj?= =?utf-8?q?LRJNYbfIkitxuAmEdicV3cxSK31iBUej8t5/L5WJk97Xnmd0KNChwJZqj15v0aIBI?= =?utf-8?q?Vq9GvAGbD/sa2eC3l5/UVeAT78MKYTWp1hNAfcVPai2E+NGz3jfCbn0+1JwEc3nEY?= =?utf-8?q?+OtnlUQj2faVv9CHiKMq1uO2GQJO2x7va+UwJ7c1ZTMmSzRwLHtjjnQrN3c5istCE?= =?utf-8?q?3XWNCG35PsgDBKr9JkxfXDqLEZZacHpDL18K6Vhq6QQAYONcymgIzsfb1nqnla7f5?= =?utf-8?q?73rwF1BoDmAyFCyVoPhV8C5iWODLMDvqkqxZk+BXTmpyfBnCbNljvNRh9b8tFcsdJ?= =?utf-8?q?bVD40ADj8YClw6f3Mhs9I+zkNEB8Hx792Kb6PbTSqbCHOOg8z/2n19bdizaME0sCy?= =?utf-8?q?WxYVuy6AXr9PJ1+mXQ1XhAcWhf/A9fEW9CyiPKFrDSF4V7N7/ob88gqnKgXgF9SBj?= =?utf-8?q?8ojQf0CWlsyT4eVwI5OJOn6y6ghLbQ/RsX1dj2qctzCcB9B1N9xCEygWRBHz18Erm?= =?utf-8?q?hSE77/QS68PCAxc3Y0OBIGee1gGcZ4Yl5twXlGV6MDItc0U6FW2fS2k8yBB2TZsYL?= =?utf-8?q?U6vOkyJUVp52RcfOrOnm51tjG64CLWYb1YD6MGp2qstq1/7j6/UnXfhyLXcQzc9tL?= =?utf-8?q?UG+4L2VUGvewZBtEqcb2PgoiVU7YBPc1tWiuKrXy4vP1tCn11s1RpQeRJVFdBXR3y?= =?utf-8?q?yxoUkPcK2lclZrXuRk2Z9b6kGEdAb2JbrS9HdtY49fN/W8NC6ZX8h8KYlysH+sSBT?= =?utf-8?q?zbhWOxUlRJRu+U4Q6EXLbAPIM+BhO3MgqoElN62//px9jill+AOl7MyLC2N5WfiV9?= =?utf-8?q?1lVTPPo9Wen0TGq9PeN1t+Vq1orX3BMPslmQWugyzOrctV1XXQLPseQVDyPMiAeaB?= =?utf-8?q?p73EufU4jxsu8A1P+4L91DFKRBRgNPROhoTDy1pLiVX5c15Fa/DHI8M5i+7tHaoMx?= =?utf-8?q?lwp5six5W9yADWCerQ9QNUipIl9DAs8u2tKn8jTPvN3JI6j6wYxhN8oA4rBEiK/El?= =?utf-8?q?jnJypnfE5UTxmEZ3cuTd1beUb/IHa6zVf9DIWamyqg08qd/eY3Nk5LTAT/TyXxU6E?= =?utf-8?q?TgisaF7HIiUipSkeZWoH3gAjvR2YcIaIs675AV0A2LqTOyUY08eHjr6HLZuYnZMlg?= =?utf-8?q?ST9GqeduyF/yHbIwztukKvw3MywTg8RHx4BP7jiwVgaZ95ndmM5VJ9sgXoIkQ2eXB?= =?utf-8?q?329lZknBpbEcx0xSdy5r7z89pYVmi1md5tEWqcfpdGrgzFbjIGNffvw=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)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2025 12:48:44.4180 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 483fd466-ae74-46e4-afa0-08dd3f9a19ad 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: BN3PEPF0000B36F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9254 From: Manali Shukla The hypervisor can intercept the HLT instruction by setting the HLT-Intercept Bit in VMCB, causing a VMEXIT. This can be wasteful if there are pending V_INTR and V_NMI events, as the hypervisor must then initiate a VMRUN to handle them. If the HLT-Intercept Bit is cleared and the vCPU executes HLT while there are pending V_INTR and V_NMI events, the hypervisor won’t detect them, potentially causing indefinite suspension of the vCPU. This poses a problem for enlightened guests who wish to securely handle the events. For Secure AVIC scenarios, if a guest does a HLT while an interrupt is pending (in IRR), the hypervisor does not have a way to figure out whether the guest needs to be re-entered, as it cannot read the guest backing page. The Idle HLT intercept feature allows the hypervisor to intercept HLT execution only if there are no pending V_INTR and V_NMI events. There are two use cases for the Idle HLT intercept feature: - Secure VMs that wish to handle pending events securely without exiting to the hypervisor on HLT (Secure AVIC). - Optimization for all the VMs to avoid a wasteful VMEXIT during HLT when there are pending events. On discovering the Idle HLT Intercept, the KVM hypervisor, Sets the Idle HLT Intercept bit (bit (6), offset 0x14h) in the VMCB. When the Idle HLT Intercept bit is set, HLT Intercept bit (bit (0), offset 0xFh) should be cleared. Before entering the HLT state, the HLT instruction performs checks in following order: - The HLT intercept check, if set, it unconditionally triggers SVM_EXIT_HLT (0x78). - The Idle HLT intercept check, if set and there are no pending V_INTR or V_NMI events, triggers SVM_EXIT_IDLE_HLT (0xA6). Details about the Idle HLT intercept feature can be found in AMD APM [1]. [1]: AMD64 Architecture Programmer's Manual Pub. 24593, April 2024, Vol 2, 15.9 Instruction Intercepts (Table 15-7: IDLE_HLT). https://bugzilla.kernel.org/attachment.cgi?id=306250 Signed-off-by: Manali Shukla Reviewed-by: Nikunj A Dadhania --- arch/x86/include/asm/svm.h | 1 + arch/x86/include/uapi/asm/svm.h | 2 ++ arch/x86/kvm/svm/svm.c | 13 ++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 2b59b9951c90..992050cb83d0 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -116,6 +116,7 @@ enum { INTERCEPT_INVPCID, INTERCEPT_MCOMMIT, INTERCEPT_TLBSYNC, + INTERCEPT_IDLE_HLT = 166, }; diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h index 1814b413fd57..ec1321248dac 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -95,6 +95,7 @@ #define SVM_EXIT_CR14_WRITE_TRAP 0x09e #define SVM_EXIT_CR15_WRITE_TRAP 0x09f #define SVM_EXIT_INVPCID 0x0a2 +#define SVM_EXIT_IDLE_HLT 0x0a6 #define SVM_EXIT_NPF 0x400 #define SVM_EXIT_AVIC_INCOMPLETE_IPI 0x401 #define SVM_EXIT_AVIC_UNACCELERATED_ACCESS 0x402 @@ -224,6 +225,7 @@ { SVM_EXIT_CR4_WRITE_TRAP, "write_cr4_trap" }, \ { SVM_EXIT_CR8_WRITE_TRAP, "write_cr8_trap" }, \ { SVM_EXIT_INVPCID, "invpcid" }, \ + { SVM_EXIT_IDLE_HLT, "idle-halt" }, \ { SVM_EXIT_NPF, "npf" }, \ { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, \ { SVM_EXIT_AVIC_UNACCELERATED_ACCESS, "avic_unaccelerated_access" }, \ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 7640a84e554a..456d841298f7 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1297,8 +1297,12 @@ static void init_vmcb(struct kvm_vcpu *vcpu) svm_set_intercept(svm, INTERCEPT_MWAIT); } - if (!kvm_hlt_in_guest(vcpu->kvm)) - svm_set_intercept(svm, INTERCEPT_HLT); + if (!kvm_hlt_in_guest(vcpu->kvm)) { + if (cpu_feature_enabled(X86_FEATURE_IDLE_HLT)) + svm_set_intercept(svm, INTERCEPT_IDLE_HLT); + else + svm_set_intercept(svm, INTERCEPT_HLT); + } control->iopm_base_pa = iopm_base; control->msrpm_base_pa = __sme_set(__pa(svm->msrpm)); @@ -3342,6 +3346,7 @@ static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { [SVM_EXIT_CR4_WRITE_TRAP] = cr_trap, [SVM_EXIT_CR8_WRITE_TRAP] = cr_trap, [SVM_EXIT_INVPCID] = invpcid_interception, + [SVM_EXIT_IDLE_HLT] = kvm_emulate_halt, [SVM_EXIT_NPF] = npf_interception, [SVM_EXIT_RSM] = rsm_interception, [SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception, @@ -3504,7 +3509,7 @@ int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 exit_code) return interrupt_window_interception(vcpu); else if (exit_code == SVM_EXIT_INTR) return intr_interception(vcpu); - else if (exit_code == SVM_EXIT_HLT) + else if (exit_code == SVM_EXIT_HLT || exit_code == SVM_EXIT_IDLE_HLT) return kvm_emulate_halt(vcpu); else if (exit_code == SVM_EXIT_NPF) return npf_interception(vcpu); @@ -5225,6 +5230,8 @@ static __init void svm_set_cpu_caps(void) if (vnmi) kvm_cpu_cap_set(X86_FEATURE_VNMI); + kvm_cpu_cap_check_and_set(X86_FEATURE_IDLE_HLT); + /* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK); } From patchwork Tue Jan 28 12:48:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13952524 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2060.outbound.protection.outlook.com [40.107.220.60]) (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 843721A2567; Tue, 28 Jan 2025 12:48:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738068531; cv=fail; b=nNH3+8nKltAe9w9WTRFYbhcY2A3shebzuGhN1YuISq0LPA45ecQ99LQ/aqk1R2dWVZzIjmI4FzoMoENlZPncnRf5akeVZZOaXeYtMm1phq6E7do1rYAPXOjPc6c8qaAC40iZIPdyRpGN90J049M3z3Ilpyc4J9i/PMyoLX9M15Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738068531; c=relaxed/simple; bh=/HMGmhZlwvST967SjZOHgd/cHsdSVuUbPYKRhcm7HPU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ts/9ixHpKzBI6Uz8fH8UP+/qrsDY3XjHLTEF8hVv3Kfu9ePN99EQNc6f/pc1KKUn0N+AI1t8Yi1Bvjt1QLZ3TLDJjtQxLQmMvH0vlsF3AY26MGyqxgD8Z4Mtd8EzmMZts3VvbhWrINS5UvP+CXFf8XQtxkOdG782ev9D4ObyTFA= 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=Gd8nvwH5; arc=fail smtp.client-ip=40.107.220.60 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="Gd8nvwH5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ioU0WUIZK9RTlGD8ffWQXXGo5VtirAYkWRSCnqQA5G9N7ewkk1/33MaCI5u1LrdJE5roE3OcN9c8s61LZJ8DrpJsZphf2KVLLDrmjPE7GAWnIxQ0PVUk+ZVFSvELDhW4e1LxkmaOKnHL+6syLfASNT6VK6BvdroobiGx9KDACo8G1yWQlTORLMznjqf77gBJKSIseOZlm6xHmqGYKpou9W6csn3vKk2IJ7A4wNxvyhBxqYrDa6vJ+V8yWtARkMVmxbrDWkVyBa0mTRzdtqQC3nD/EsNNvHvYUw64uumWVM7YcUHXDz7GpBUo7UOYCjCba5nlCUfU1ateJyjuqW0wzQ== 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=k7w3BkydccKs7oaoi6dIQvArX42Bm3ueWNAnp0/Ow7A=; b=c8jDK1/px0OHVnDiTssPwjG1R7DfHzPi1rFYCkqeMw/c6SrBP9I4NZGk5ZO1Zl0njKnhRrpnnEcTgWItODcJQo++JEJoK6SDRMlpuppsaB5RzH6tiKJLkC5tCtMKlAkSHpcETur+nJ+IjZ+fWD9gXYhzjev1GavfUeh++p+GzUMellD6spP1S81lPRCtZghTUnrFLXE9M/L48ZcH0RD/D7mkayFr1ziR0rEhyng1uvy2B9wCizio8LDAUIlGyoaBBbXlp7id8U3ElWKEoqLXJXnj+1cWMPjf2PXiig39FvGMQqabQ3JViIeSDDZE0HsXmKL7asjSoFdhldPdxdDiSA== 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=k7w3BkydccKs7oaoi6dIQvArX42Bm3ueWNAnp0/Ow7A=; b=Gd8nvwH5xgEAqa6kelfQeCd9qj3DmmTlVKS80SeeTcLv65+D2uU9tMD0KtMKtNE8Uvm/aSkJRN+U4StOWVhSmyx4lqA1fB3wTAVDTnOVCwVYhWSzKackEV/IgfZFVc3O7ICx3BpISbwdaOLPgpx6oPyD+o24+6IOoYuOcXpzlPs= Received: from BL6PEPF00013E05.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1001:0:4) by IA0PR12MB7675.namprd12.prod.outlook.com (2603:10b6:208:433::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.22; Tue, 28 Jan 2025 12:48:45 +0000 Received: from BN3PEPF0000B36F.namprd21.prod.outlook.com (2a01:111:f403:f90b::1) by BL6PEPF00013E05.outlook.office365.com (2603:1036:903:4::4) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Tue, 28 Jan 2025 12:48:45 +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 BN3PEPF0000B36F.mail.protection.outlook.com (10.167.243.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.0 via Frontend Transport; Tue, 28 Jan 2025 12:48:45 +0000 Received: from chalupa-d178host.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; Tue, 28 Jan 2025 06:48:44 -0600 From: Manali Shukla To: , CC: , , , , , , , , , Subject: [PATCH v6 3/3] KVM: selftests: Add self IPI HLT test Date: Tue, 28 Jan 2025 12:48:12 +0000 Message-ID: <20250128124812.7324-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250128124812.7324-1-manali.shukla@amd.com> References: <20250128124812.7324-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@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: BN3PEPF0000B36F:EE_|IA0PR12MB7675:EE_ X-MS-Office365-Filtering-Correlation-Id: 99e606e7-8f0a-45fa-a8ae-08dd3f9a1a48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: zd5O4pNJ1M81N4YEA3hh05CaxTavUd78eE/CrLhPnL/6yMJNICrhYcbUgm3Og4fJ92SWyESaDCBcPzS9jMMqb9zXSSX90hK8Gp7in23BfA1hp9RNePJQJI+/GRCGO13aDHVx+dZErfIQ/InuaATz/1m8PcPZKY9C4N3Ty/JbuYlHP/Ah2M6NS1g68/RXp+tIrKuJiZ7vg7wYCX9IjU8p/WPK8vqp7Kdh2c3bGaQhSOXnYpq4cIuWI4M1bPytRxtcUJfFTeZi32TJao+B7vSxxFIYdCqE2Of1zwt4w7c+98Yyeodk/4C17ECrcRXMi3ZGOLiQBbrc8E/TMn2nlHn7UrTmWY1WYqG2LgKBNDBIH7RVn+7dLPFAouV2FZDjouSUoxs3zCKmMByk8GX4u+x3A7fvu5ijsXWFhMhbhp39QNTY3glRQ/3nkHj6nPLC9ABBrI1INRgFg/iOyrVWpjnYwo/OxypP+tVc0TFiJaSM5MZL1vWpVqUdvef7/tGEro+2dENJkvuAF3C6kpolISmnwMYZFkhsHh1Nl18ShtLUVc8wenJMXu35vqBd13FuffiiVAajg8DsgUDYi+D4BM/21O7Pah0HJgNCb8qKp2rY0R+/wwS4AK40FT9hsjfDJQWMiOHOZWPGQd//vaKJFXVtxY2FZ0IZpGfCNGe1az8leL5JK0oasU+XwDpjLpL2105/9a886wIpIqw+zbMd/1FniwEBAjy6mhKjop+A7f4AJ617xLinWU7hjW2XZ49hDWGUK0YcSay1GoniUKY56la50Vw92p6ZUi2Y6N84j113i60KyPcrUS3JlFKUp9TIk7Cqrc6Pc7GAv7hioD0h1ctRwAG8qJBeTISDCE3iNHq4Hm4KQDCvNGoJWHrS5KEq5qdHGyOlI2EuIedCxncRA0l/Sh7knEaQGj81etR92sFAqcUs+yUYLFW2k/as2+/k2pPyYgqQsrDvbM7c07Kvy9cP0/oA8eCaF9+xMOwKxiOSclWlvhKQnrZAMqkbY0QScwWLrcHUb634p50hKVNkjRdD+pSeadS2C+qYVxipdPwC/5skJb9LTbAqspCCLs6Rb5D8tHZbWEbg9iH/dxCzbMh2WDTSi5C9oxkw8rvls22THDTPzk8G+wT/InQb92JLfAN2I670rZ7neGXtV0YjzuHzqTSFfVCXBtnKd3SkfEIQWAHe4pYLCTEmbW9x9Y8k5Ket2CCEWSQd4E4vivnq+LrwYpx7gAf/zUqmTxothoQIldsw7L3X7O+ZrobCCbiIGsE+xRPhoqnkbeOE5tF31OsxWyYgCbKXygh38bQDDV3wKeRljsdtYVTrjJLkN/TnKYwnUEQM8+bu38JeT6q8pcpBPh+G+2nu5T3bQgzzly3p8ckLaxP9m919VK4+GC+7/bg02ZAbT9+6Ew77O9kFmgPsPGp6WxRyKw8ZWviKX8jrJIZrdssu2pxrgJXu1PAFeB9B2RWQ13oST/FeLYab686jnnRVZ3HuqcK1IbDulFBEVyI= 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)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2025 12:48:45.4336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 99e606e7-8f0a-45fa-a8ae-08dd3f9a1a48 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: BN3PEPF0000B36F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7675 From: Manali Shukla The IPI HLT test simulates a scenario where a pending event is present while the HLT instruction is executed. This test evaluates the idle HLT intercept feature of the AMD architecture, if available. If the feature is not present, the test exercises halt-exits/guest-entry for pending interrupts. It can be extended in the future to include cross-vCPU IPI testing. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla Reviewed-by: Neeraj Upadhyay --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/x86/processor.h | 1 + tools/testing/selftests/kvm/ipi_hlt_test.c | 81 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 tools/testing/selftests/kvm/ipi_hlt_test.c diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm index 4277b983cace..d6eda8c19fed 100644 --- a/tools/testing/selftests/kvm/Makefile.kvm +++ b/tools/testing/selftests/kvm/Makefile.kvm @@ -135,6 +135,7 @@ TEST_GEN_PROGS_x86 += steal_time TEST_GEN_PROGS_x86 += kvm_binary_stats_test TEST_GEN_PROGS_x86 += system_counter_offset_test TEST_GEN_PROGS_x86 += pre_fault_memory_test +TEST_GEN_PROGS_x86 += ipi_hlt_test # Compiled outputs used by test targets TEST_GEN_PROGS_EXTENDED_x86 += x86/nx_huge_pages_test diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h index e28c3e462fa7..fe0ed8d33e37 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -200,6 +200,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_PAUSEFILTER KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 10) #define X86_FEATURE_PFTHRESHOLD KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 12) #define X86_FEATURE_VGIF KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 16) +#define X86_FEATURE_IDLE_HLT KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 30) #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_PERFMON_V2 KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 0) diff --git a/tools/testing/selftests/kvm/ipi_hlt_test.c b/tools/testing/selftests/kvm/ipi_hlt_test.c new file mode 100644 index 000000000000..449845fa2a82 --- /dev/null +++ b/tools/testing/selftests/kvm/ipi_hlt_test.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + * + */ +#include +#include +#include +#include "apic.h" + +#define INTR_VECTOR 0x30 +#define NUM_ITERATIONS 1000 + +static bool irq_received; + +/* + * The guest code instruments the scenario where there is a V_INTR pending + * event available while hlt instruction is executed. + */ + +static void guest_code(void) +{ + uint64_t icr_val; + int i; + + x2apic_enable(); + + icr_val = (APIC_DEST_SELF | APIC_INT_ASSERT | INTR_VECTOR); + + for (i = 0; i < NUM_ITERATIONS; i++) { + cli(); + x2apic_write_reg(APIC_ICR, icr_val); + safe_halt(); + GUEST_ASSERT(READ_ONCE(irq_received)); + WRITE_ONCE(irq_received, false); + } + GUEST_DONE(); +} + +static void guest_intr_handler(struct ex_regs *regs) +{ + WRITE_ONCE(irq_received, true); + x2apic_write_reg(APIC_EOI, 0x00); +} + +int main(int argc, char *argv[]) +{ + struct kvm_vm *vm; + struct kvm_vcpu *vcpu; + struct ucall uc; + uint64_t halt_exits; + + TEST_REQUIRE(kvm_has_cap(KVM_CAP_BINARY_STATS_FD)); + + vm = vm_create_with_one_vcpu(&vcpu, guest_code); + + vm_install_exception_handler(vm, INTR_VECTOR, guest_intr_handler); + + vcpu_run(vcpu); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); + + halt_exits = vcpu_get_stat(vcpu, halt_exits); + + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + /* NOT REACHED */ + case UCALL_DONE: + break; + default: + TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd); + } + + if (kvm_cpu_has(X86_FEATURE_IDLE_HLT)) + TEST_ASSERT_EQ(halt_exits, 0); + else + TEST_ASSERT_EQ(halt_exits, NUM_ITERATIONS); + + kvm_vm_free(vm); + return 0; +}