From patchwork Fri Jan 3 08:18:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 855093 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2087.outbound.protection.outlook.com [40.107.243.87]) (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 504AF1BD032; Fri, 3 Jan 2025 08:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735892333; cv=fail; b=o9kp0jFg/pBq0cJ83LAZ/YAVDwkSAu/nA1P7tRFOiTNA5aRXiZOfuMut0QxMO0QLVqOCmNOEEItB0zdia6fZOLEaieusXBasFjsYd0HEI9lPyyZMunkkFfqCGoeWrjqBJK1FHUr9Rw7Pp+MjIaziMB1QaaXHqeOaEWBAqWTUfsY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735892333; c=relaxed/simple; bh=kA7GPfQNp1IychYU31YWxUwLV2fDIPZJTzndjrTvihE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J5zV1Mo2pzxVGRgSDWnPPrVg+FT4tRKKCDBkR661wxb03ThcF2QEem5gvrWJjRe0/pygT0iZsrEYA4YjBKQWd9jeD1t2Ac0vDFgKf418Ga0oZdweJ+/Z0oViKNSDLt2foPkxbOFXnlxTQ2mPsXb6ykF8dordsEizdoqDDIgAVF4= 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=pJZhBYlI; arc=fail smtp.client-ip=40.107.243.87 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="pJZhBYlI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bkH8FDBYNJpPk73m6yfVqiHkwIBw2PcL9s6aQBdwfZMl5uATSuqAZM04p/BsaRlQOBnc6Z6TnVQW5RyXMp2+GGyMkNawZTHvke2nULvD2CJLdNCPZRESdHgXpJTI4W+XLgdMLwJHAYA/JsXaOnBcwBHI17NHSckTQB72XoovwBwM7R1L20GNkqTsiJb3e/0kzRcs+8+VgElh/J+SQyrWFC4LtbUbNKCYtx4U2r51E41RFZibCdmsvnTXDj57gb7PKAdsXMAPwd1xXD0YsIMk2YZ95lwyporFAK4Y+k+xj94Ae3hZLu6ymCQHfVI8s/rvse8TI4Oi1snMbMoCnA7AlQ== 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=AIEsdXFDlozR9ou1amcSBTWy5yqNsRgDFe60vxAccVM=; b=Kbk/DTKXul3l5Hfb+nIzWjImfFd15GbsLwAJsq5yuVpSLMlsVK+LiRAV/gVH+1CILS1C8+vuVhuumhatAA8s2D+jeizoSVWHdbWYenUTgm6u6hBve9eQFFnio5bggiwLFP3qdzYpH7sB75uSIGWbYEaTxyw8IHNDyVgI26QeDy6sAAZXf7/n92k2w3srRuPvv1AJ6JZ0GvkHBcXwHe2Gwvx2/rt77wHUpqWqP1Z4QdWcbwzvF49r17SL0oYtvC55nvMlcL/+aAc+GKEFM4QvpUWDsdmWtglm40/IsaDv4g17iNnQxe5oaNJHDKKcEewrSeyCSJ7yaIuciBqBurDFpg== 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=AIEsdXFDlozR9ou1amcSBTWy5yqNsRgDFe60vxAccVM=; b=pJZhBYlInwjTZzBbQzOS0RRJ259iQCv9ENJ8UmE31WmIUSDBva4jJhIHZmo8DdEtoXej6DH0WPB1g0D4PCwKy8BasrAdH3BYBf7/ExF5FLc6I5IiTiQihbetfgHoDRxYzPoz3JUNZ7SB/kyVwJQ/mPWTGCnFE6XE9o4MjSv0ewQ= Received: from DS7PR07CA0014.namprd07.prod.outlook.com (2603:10b6:5:3af::17) by DS0PR12MB8219.namprd12.prod.outlook.com (2603:10b6:8:de::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.12; Fri, 3 Jan 2025 08:18:45 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:3af:cafe::cc) by DS7PR07CA0014.outlook.office365.com (2603:10b6:5:3af::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 08:18: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 CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8314.11 via Frontend Transport; Fri, 3 Jan 2025 08:18: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; Fri, 3 Jan 2025 02:18:43 -0600 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v5 1/3] x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept Date: Fri, 3 Jan 2025 08:18:26 +0000 Message-ID: <20250103081828.7060-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250103081828.7060-1-manali.shukla@amd.com> References: <20250103081828.7060-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|DS0PR12MB8219:EE_ X-MS-Office365-Filtering-Correlation-Id: 994f70dc-6243-4635-b292-08dd2bcf3db2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?hdUNfYBQvvYKPO13p08Rzyu/QGjQTOU?= =?utf-8?q?1PIuBFf4nmkZYIIGZDsSQIrWK4zSCuTJGbOVSPssOjApILnvzJvs14tuOWCIE0UVp?= =?utf-8?q?Z0ZUZutAcej3+7E9GPAVF23kGcLBUGQhHgSaMlpvDOQFT6byKtREpdMPuCRflZ+jR?= =?utf-8?q?OLJvpmT74UwOMzxAfPc9QAMq4HqVlqUw2uownUoS2/XMetMKc0XoosYbLGEim6J7D?= =?utf-8?q?KlCAa40r5MXlc57USzpFYcRYSTKaVlwpXDV4EPLdRrigS3ZIEwdj/eYp6/0TFUb2X?= =?utf-8?q?3XDM0kQIi2FwLnqBzMEOltdXHqH8ItdlcqO+IKRm2U14lwsGyGg9IXZilrN/qVM/C?= =?utf-8?q?TYHR9KM34MMhPChpp1hKjSZlFQEZoTFI/Aluoq1CXHhOhHv2BIVtOyP+6CbiaOpgP?= =?utf-8?q?AekQL6rUZIoxfyu8pPcmGB0eUG2kso/PgPlDmM1jlOF2QYH0woWsPkELYBly8lRAr?= =?utf-8?q?3KpIQng8pcYDwvZ+cvoxnkL20p3LdY1guoDFDWCRP8mtGg/2JXvBqZ7+0vsnLcyMj?= =?utf-8?q?mtLgs/Qvc0PYZO0Zq/f1xvWghSWivLvj0R7yc8PN6PkJZbMWhQBKR2wq6KyqZPe3U?= =?utf-8?q?YTEzIUVJSUFVaMua5aaQLHA6k8A3N5zhKRU7sjG5G7dRH57tnV19DA8diTMTWmKaC?= =?utf-8?q?E0phn0v4FrcPACImO06H9mzxO93MnJaan7gRHN0BoaWXegvt45nRM1FWJqGAbIo6U?= =?utf-8?q?pvBbMi00ZZ8cKkv7w3e66HJdwKweMqXGgLsHgMVlxRq6qGXO2CSBCpIygBLHvB6+M?= =?utf-8?q?OKvm3jJSsb+Y8+nkVNuQ4UR94DML52yghs4Duqvt2dW2X+BYMn40Eegur8pdwnRCA?= =?utf-8?q?mhhSXpN+E8u7NC3AMF31oIw99Fob64oVTaxMZMmMNJQ3MRrPmwM+lBWoQ5QzHovEl?= =?utf-8?q?RTKRisU3bW/QiqhieQTh4f8212cbtMln+of0y93aDOZj+vaem0B5x2bvdTTR8tUBS?= =?utf-8?q?eu/b3gW6+7L7RgyV0f8m0U4F+VmHK4xe6Ix8LCeihxR73rRaWaetqfTeimGoZkEtx?= =?utf-8?q?CDQThSRVzVave9240npRyyeICpkwtgjLsMjLdlFkVNlFAZYZf3rMIewY1IEm1FYPr?= =?utf-8?q?61EmVgN+nrqjgATdqh/CckT6u3LZmmTyRrq9/+4A5F3OrzjB5xmFfvhofofu90f0M?= =?utf-8?q?mhwjuJMO0Yhb7GpVD2iVl4Las6x75z8UjkzVpGyPtiy5ewdL5/T/bAyGR0lkDLfA6?= =?utf-8?q?Ls5Wibtx52JJNntCTUTNE2enrx2gfYbMr7Wut+qJIrDZYrLdAkmAzVwLJvHYJFwk4?= =?utf-8?q?2r6lD0KQHCaXHZA8ZDjbcIn1IXlUpvEKMg3mTbaElnTzIOi6ZiVwqjt9V2ol6u1Hr?= =?utf-8?q?224auAwaJeHfNQdt+/j1OPP9ICrkt51qJtqv3zY1pPQQlqglf7LAWnKUhr3yeuz+q?= =?utf-8?q?B3jBS+H/JvoQUABkLgaRbm8RewBJ56cHSRDW9RhxaX6CISII4NRtNY=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)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 08:18:44.8261 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 994f70dc-6243-4635-b292-08dd2bcf3db2 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: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8219 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: 13e98294d7cec978e31138d16824f50556a62d17 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: 74daffd7677992995f37e5a5cb784b8d4357e342 prerequisite-patch-id: 509018dc2fc1657debc641544e86f5a92d04bc1a prerequisite-patch-id: 4a50c6a4dc3b3c8c8c640a86072faafb7bae4384 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 Fri Jan 3 08:18:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 854962 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2071.outbound.protection.outlook.com [40.107.220.71]) (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 763AE1C5F38; Fri, 3 Jan 2025 08:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735892336; cv=fail; b=SQscFXZBjKa3SZY1nnfvTT4jCt4RiXbb8/Wj7q/x9e8hTyXgvumE9uU/rmRI6nUyqW1+QT4z2AjJ8ObL4Z8vULcVPCTykFc8vZOs+Cj20eNxr0iJku1GbSlUuDDtT7K/7Y9GDWr27O0SerkHcB6nTOYSDKzoT4w34mo27y4oXUk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735892336; c=relaxed/simple; bh=OluUnzRJIt9HxfvzNQ2E+b4trgLt4WEmEmw08MGotVQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gan5m42BBfL+Y+F7RbPc00WgaQapO0rAwz55oGgkK3Z3TnMQsL9gmnbYY9FtZVM++o/sQQ/9t8lAdCWT670zJ2myF/HaoHDm7LNRDamClHhzB0NC/4wrH8h1L/KaQydKzc0eyBBNf+EyKXI0GmLjh0DN/uq/6F8B2AKwYEV8/lI= 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=fDVYiv2w; arc=fail smtp.client-ip=40.107.220.71 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="fDVYiv2w" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=U+ySbTszCtfNQXE1j6ou5M4Z0/clIDCwf/qqj3eHydjliQiTvJ8JMrSu33RYXeekVNg1DRUvBlHDUOimqOG1IA/IPdaI08oHJGkpltwRiU0dGh+vzsbtBnj5QqZNezDeRSVA4EwIikTX27FnZ11S+jOvHlNQipOgXUPAnhv7EobbXhK+6HXdBKrUKCXKiH8OD8Q4ptvqoh53U1bM99lIuizE+eY1HGoNXRlwI55Bh+Gy15nwX/pvgpdd6H9d06sL4/T4kKjhTPqSanFqAq+imlNN5uL1oKdtzJnnD3dx67Gn1NH8r3Zc5ziOg87oN4QtbKvthSRoz2tU0/qxiNPKhw== 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=auOWSh9x6pE0Kir9tlEna/TO7Bk3zjU2GgWIEfQjFmE=; b=LUIUvqHdbJqg3KYSXBO45oMROG/Dz4HiFU9ypyDi/gB5j0pHiXvF8QU/iCnNQ6HuqUXlVDSQonrc1PQ78xj+AJ45fZNSDA9wURoD4ABhdQ0+wNdxs8ux3vKrE+X/O0AsID7CXptoVAWvytqIV3RoUo2tbESay+lPieo5fYuujIi1D7uwLwSv5QlsZ9J6KxGnXVNA3GBephgW3V8n5GcxtHRxb3eHWZP1xUH9be6B+D5Hf4J/x+0Y6GJLC3NquBBCL5lySU+0WSFo7JJ/QvaiWZT+L5nlgGw7WwsmPSUTlrY9H9w1ZwEJ1G0tF9EYnOqtnsLAKX1lt2Nv7fukc7bOHw== 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=auOWSh9x6pE0Kir9tlEna/TO7Bk3zjU2GgWIEfQjFmE=; b=fDVYiv2wr/idv/qa9aBrvOXc0+jAWccJiXxgVPFnl8CkXFsWhOTvXec/Akj3s3qplSeR7Kczi+oTkB0+VNRfQyyfuM4RZOqakb7TyUQkDppioiyNtDK6vZIncDxz8awMjxd+uh5M+DQJsUXXPquOdJF6CaFB95q+4bbQLKFA9gs= Received: from DS7PR07CA0015.namprd07.prod.outlook.com (2603:10b6:5:3af::26) by SJ1PR12MB6363.namprd12.prod.outlook.com (2603:10b6:a03:453::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.12; Fri, 3 Jan 2025 08:18:46 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:3af:cafe::1a) by DS7PR07CA0015.outlook.office365.com (2603:10b6:5:3af::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 08:18:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8314.11 via Frontend Transport; Fri, 3 Jan 2025 08:18: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; Fri, 3 Jan 2025 02:18:44 -0600 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v5 2/3] KVM: SVM: Add Idle HLT intercept support Date: Fri, 3 Jan 2025 08:18:27 +0000 Message-ID: <20250103081828.7060-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250103081828.7060-1-manali.shukla@amd.com> References: <20250103081828.7060-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|SJ1PR12MB6363:EE_ X-MS-Office365-Filtering-Correlation-Id: 483e5510-c37c-45d8-abd0-08dd2bcf3e4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ItifZghW54sW4RcuWJiJkwV8dO4UmEA?= =?utf-8?q?RIvnkC+5EutK4W58iFY0qcajDfTe04tjypS+N5qnf7vaQme+YPxFxw7hkMWZvr4K3?= =?utf-8?q?1lRLvr+u4EUQn9hJjDncR2AXHON7wz39WuSKt230TnEtubOOvtReuzAg/U0AMnatK?= =?utf-8?q?xZjTgcj0vsQKKGyQXBXr0OOKDh/d1qZ9JB2p7aL+ejilCnSz35jL6apQktmbY0J5g?= =?utf-8?q?0V+g/68CgIMxO49OL2D/7JxRkZj46WaJg+tsKuR4jwHOGUnRUeU8ZC2TbC8gET29I?= =?utf-8?q?lSzrSlE+a+bXZ2VYQ6OwVF6ucnaSu9Eb3RgHz0HAgiq/M5YjRdzOSae+6lhYhXTP3?= =?utf-8?q?o0FynrMTZ0Say+IROQPtpYOZQNHALjph0zc/hr4NJ7GMAktutTCH7mXzzYO5ATe/1?= =?utf-8?q?ZBABIA8wFYl357bcADargqGkDUMh7DUOhTyLi5nD0M87pfsBsNWkBX3qGqd80xq2f?= =?utf-8?q?LlR+HL7tzKUvqJXVq7b/roK/B4LhHHGmqVF+GGBCCr7nT1TN5EYaNPGY8krQWzJAH?= =?utf-8?q?F61CU/Fvd7S6BOdkSOJwjmxDSDiNF4MhcEIFfCdGO54k8PWx8uJMk4taePVaPCWXF?= =?utf-8?q?FAqAmLzhQoSUfnJg+0NXmI/GnmVqr8Y9F6BfoZa5IlfPoBXTKWMjB6p3gYo7VpNWJ?= =?utf-8?q?E7rJwJIOkJM2GTijoBdhpqzpdNeP7nKR9Z9XApvtN1mXCsvifiN8OGmbil2wtp8xT?= =?utf-8?q?ngbajV4T6IcNWg76WiE9lZy9k+OwDW8ZO+FhCu6/0VwfQ4UGxAL9BR2U/a4v3bFfr?= =?utf-8?q?TErz85TRfZFWpP5ddj2NWPCU1+UOpWoJrudMlOt65aUtyEp9+5AHquQtGYZBSLw/i?= =?utf-8?q?g/Vnj+Q5f01cVLFlY7dCk7Il7nUH6c4V4zS4l7BRHljhrDQrOF8GK1TY1cXMP5dr4?= =?utf-8?q?G1E9CACCiIrCKvAOPJ96otjFOPx+KVpon3jb/xAUonX1ncG+Q0vyOZScORIRnK/sD?= =?utf-8?q?tT24rSFMk3VQp7iSP72/wwkMfAXr0pHdtxW4hXWhyjtOa0L+nIIX6T4GjWU+HubYQ?= =?utf-8?q?h19qIIIonkVghf4xTv80Pk6RQZl2e5SdKmnPcB76JIQsps9bTaD28S/2pwyJhD9FL?= =?utf-8?q?JTnhyoY4Ort15JxrB7gIZS1Rlm4/cQzpNuQvu5kaf39KjhNzg6+GfRw+7FY/kpkt5?= =?utf-8?q?8mdGvdgMEnQtrxV6ZbLTknu3R7L5QQ+OBZv1xsnlmhzrXkRotrlNu4w8kcpBHoKko?= =?utf-8?q?0L4a0f2bXhhSbrKHVmUJXBB16nk5gABZJ1hWtvBxfTfLEzmPWpF+w82LSHMxHr5Tl?= =?utf-8?q?G8uXxJS1jwEyw8bD4xDHRfHzNs/d3UiVmKaKDNf/jFU4OI+LzIsOXS/zxGZqhI+gi?= =?utf-8?q?A/S8BhmcnPMiqa0qW+TY40L+PcG7q4zMWKa3qAo53sD9VE1Ta/X7UAuPJeRIABe9F?= =?utf-8?q?gW3UiRdaLqEOa8c4ATSHxE7i6A2azW0Ru2kXdrwN3f65vEfGLx/gjw=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)(36860700013)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 08:18:45.8418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 483e5510-c37c-45d8-abd0-08dd2bcf3e4d 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: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6363 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 --- 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 78daedf6697b..36f307e71d5d 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1296,8 +1296,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)); @@ -3341,6 +3345,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, @@ -3503,7 +3508,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); @@ -5224,6 +5229,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 Fri Jan 3 08:18:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 855092 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2056.outbound.protection.outlook.com [40.107.223.56]) (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 E659C14D2B7; Fri, 3 Jan 2025 08:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735892335; cv=fail; b=WYVAR7AHx//qty5x/6FtdwVTWpR/CVPo3bRKNwN7LnrdRcjObtrQWUg8X99GOdmKXBajYDG8pAY3/CsfZGY1idpOZNY3tduJ8K+Uml5U8KQ5zZguHs1yZdQ9L7p8u3AuLguX+oeCC7EivhShJd1Q6lgxKqEvv6xHygLuzls+VA4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735892335; c=relaxed/simple; bh=HzwbGG1QAAjeo53Z6EkrqoIaEGvB2A2HlEbS86j3HnA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f/WIOGzYDgZgv7NVg8+ZUzjBU2i9OzxpeXcvSCxbvZpyvKEU6lKjGaexBSJpx092AN3jmG+9VEjjMvNQea51xwjKGUsWAifIS+808AQ8aJPDZy1nxCAOTFPxRvNT+ejkfgzFCYHb4IgFbixIYmpmP7jcIZhRandxRe3J8ggJSow= 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=fZx4H8Ea; arc=fail smtp.client-ip=40.107.223.56 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="fZx4H8Ea" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hVNJatUM3QHRoDYYGIFmnRyGrCaXq/FrFc7Pd324CU9r1oF9dg/1JFazmBIfmWTDgw7vKXAg5LIgVwOAy+H+RteMkp5GNL5lW3+ldXwp+RpVvea6nio9xljKjoFP48EIACZtGHiKyHIztkjw0gDa8U40XpdtIFoP1udp22KBXqwOBK9qfLmXc/CbP2ldMsT/oVeEC3n9LGaXQxKuO17o6Ofo5KARuuwOUHVM+UCKa6FS7xtxaKPdx9lCW4h2gbBf2k8792Yk/9z9R9Er8XrEPElb5SvQt06N/sgTAydYOV/KzHZH3yB3xZagukJBWYs1waqXqsnNWncl7T1N++EjGg== 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=VwMJUYjU9g5Z8CjWCAYWT0KA2GhAdSD6xbXQ6CfiHuA=; b=hOFACU4C9IXLxU9zqi0+mEUOMYshdafPBfK0rJ0weL3NYjfc/0oGRBP/bX3NuaCpDEqz5fwsZz8sKz2pyGZq0vCrBZJxJyjhfB1/m0dArFhJnRxYesh1d1OhtRioUP2DBcWiEPBtvqOA4+/yPndfvBLSHXRZnYwqcvCGL1TgB7aegWPC3+V7LFPhyyACSyZ/ZJx/Rlm4oKrjHjMT/UBqdXmQeK9ctO32/+X0kuMfFt1bFZOhbUOkp2axQVNrvY2djsmqZKc199DoXFZ0FJZZDynFRbBEZeCWJor4WymbicxduD6txA9rlF+hgs9/a9lPz/e8HcCJGX9cd6yboCwLkA== 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=VwMJUYjU9g5Z8CjWCAYWT0KA2GhAdSD6xbXQ6CfiHuA=; b=fZx4H8Ea/xm3G4Mi9RmsjWzJNVjyrBsbfK1HNQryRucd4UQCGaYYc5GmaQbr8doY9umhMXw48W1GjXEOJRwZGlVoZj1bKUY5skdckZXcipfZ2s40GQZvawtMYVS3/ptRVOX6N+EKrwduLMi0S4/600T96926YxbB6C/fwAyUpd0= Received: from DS7PR07CA0003.namprd07.prod.outlook.com (2603:10b6:5:3af::11) by CY5PR12MB6131.namprd12.prod.outlook.com (2603:10b6:930:25::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.13; Fri, 3 Jan 2025 08:18:46 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:3af:cafe::8b) by DS7PR07CA0003.outlook.office365.com (2603:10b6:5:3af::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.14 via Frontend Transport; Fri, 3 Jan 2025 08:18:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8314.11 via Frontend Transport; Fri, 3 Jan 2025 08:18:46 +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; Fri, 3 Jan 2025 02:18:45 -0600 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v5 3/3] KVM: selftests: Add self IPI HLT test Date: Fri, 3 Jan 2025 08:18:28 +0000 Message-ID: <20250103081828.7060-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250103081828.7060-1-manali.shukla@amd.com> References: <20250103081828.7060-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|CY5PR12MB6131:EE_ X-MS-Office365-Filtering-Correlation-Id: bb54c254-8dd4-49aa-e15b-08dd2bcf3ec4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: w5onVsKRML9fD0Ef/CvIgOGIDtqNtRCATN4ZMYLuRmNbXFMwb1h3FSqoZEmFixAHBnRUDJ++Wk9hxLquPy2r2wHwvVFgQaZyaYBzbbs5Mz+7T2EjFVA2GcG702Zb6TnEglXQaovrNu/AilHAsei1IhHVESGei0IJp5MqukaHX1iK5J7lgaASNkOwfv+N9JUI4Lu72kr1H33jgMyCkV6HsVttKaNotK/H022Zc+kQcB0iFv93qZwA70rrz2yRzkgSTzcDksKBa+Pm/Ls+qQX1Ub05hzZQ1FgN3wckqvXHe5T6ut0JC21qzLAKT4o0rzbhOpQX6k/Gli9rh388lvL67SJGLUNNUCVPwRW5Y2Z49V3u5bp5dl6XNGeyC7/G9vUVzKwIo8hpwDS+eaGg8/Nmn+dw0L2fHgkYI6pAD5IZN6ybZLc9ZtZNryxWd5VXWjKTYrTM8gIbWhJ8eJGTs1qQZt7VEILQyLUVapNI20EM7KAoes/xnoRfNvrEsmqcjF/WR33XdZRMI1d6om6vVh/6EqbAILImIQosJ5ii15OdHSTGm+V2F8As5plfD+pPvD/kzLW8QFfOdZ+Mw2HLZd+MLiTFUgB64uB14cJ0gFxUKF8WfAjmb36O1AY85y3xouy/+2ggS3KcxIBPA3s0ML3JeP8+HemrQpnpEuZJP21q4cqck/j1t8fmgnGf3o7PGVaFmtiEjdROOOZDIzQSzGamT3z7iiTe8xIBGv/GL2G/bKN1sk0FB9rzql1tCBeHzKS6toE5OKaAGrHMmPV3h9FkN+/qi4M/iNlVLdlGDbWAL5v4ko+C1ltCGw/pFLW8Fcwabp+qCVkWUTK6ZydKk9r9tXLzE1uazXTSsFx+ZqtXrJYlRfVHNE6wPhmjEKyYAQuCofh/CRz8LQ1LiJYDSVObp/xjVKp3JQwKOfk2q9BsN7sSMp0eXjhCUmZFBU0MrhDBkKKS+c2blJvJX3Lu3wW/sLAyEfc07bR44EzHazamAaLFHwvOihl0VW3TqHuJkzxwBkadCK0CauWCTuev9FqIJxQFKiPPZhqQfzK9wI78mnjR1Mc/fW5k2bnK+Cuz2Usdb3Rb68dJDGLn5m9hdQBvZFiQSi14NI4WiHqmjt2s2avKO+iv6FvhezWJwR1YYLtmUVAMnhwpkCWD6CcYvT+l/Xm1lowASyL8fy6cNmIwARrpLa5CVztw6nbu03rkWHI0oOLUeBTttQDq9AiReD4xt8OzDL7W2a4546kYxNh2C09PBZWi0h+1C/X7QHfxV/5inT07j1nRcuNj0Cz2UbzAOpCGMteIW3pFGrJB6YHHznTIMLAZ4ngblqbabYoozuk9HKtxLQwu2FYKHgPkOz5D3B5qpkPvCmE7BMAec3pWvPP2co3dx/MV+iIAgC2FUelV9WRLQmNJHa4q4GOpe5syIWTU0L+YuUry3fm6u8OwqS7s3pW4+LOKF+utMVAOR6hmzdPLDq2vOXFOE2qHYtmUFGzMopoCtYZqxGvrAl7E0BA= 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)(36860700013)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 08:18:46.6074 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb54c254-8dd4-49aa-e15b-08dd2bcf3ec4 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: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6131 From: Manali Shukla The IPI HLT test simulates a scenario where a pending event is present while the HLT instruction is executed. Evaluates the idle HLT intercept feature of the AMD architecture, if available. If the feature is not present, this selftest can be extended in the future to include cross-vCPU IPI testing. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/x86/processor.h | 1 + tools/testing/selftests/kvm/ipi_hlt_test.c | 83 +++++++++++++++++++ 3 files changed, 85 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 1f9798ed71f1..23a34a12be48 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -197,6 +197,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) 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..09ed8011450f --- /dev/null +++ b/tools/testing/selftests/kvm/ipi_hlt_test.c @@ -0,0 +1,83 @@ +// 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) +{ + uint32_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_vintr_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_vintr_handler); + virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); + + 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; +}