From patchwork Wed May 1 14:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13650821 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2086.outbound.protection.outlook.com [40.107.236.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 A534812EBDB; Wed, 1 May 2024 14:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575323; cv=fail; b=pdtKOJTTqW6WZPLXxomQQCnmBRXWKptjGNDGFVGGSy53aySwSfLT8OY1GRYJCJdoZoOVamwrMb9O9wVu05GanYO0YdBxlVnpQj8WnylmHxIDZmT9EN10Dagxmm1rczGjLgSGE1FsK064Ssdwfi9qelVj/EUjVrUAiuVSWH5WcGs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575323; c=relaxed/simple; bh=yhiOSw02sfQ+2JEXPUMkAiQwnhoeWSZYG3qgCOMVQqU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Chq3a7Hf2dRu0EqWxLy9j8JK3eXlITneoosT1NCC9CnccYcWHA2mzmVmE38Q3jsnbEme/89ItOiytca/Heg+WjZI+z+NWmpNL1ough7UmY2t41wvTYJ3i13Q3OSegdL8A0i9JNc9Ao7YwQSqqhAaIoDGgaNtkiQv1TJMkFwF6io= 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=vFrmTerO; arc=fail smtp.client-ip=40.107.236.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="vFrmTerO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y+56munmoc5yOfAPDZZKzeU0uKsMyW72UfrVsv68wTHYxyYRsw22/rp2NjD0KtdPZ/h8XUCLQ1On5AtF084kWesRG3IES652ZqBhJpYeDGH6lT5bGt8HWPY5r+TWDtC8DoCNYNQIp8FYORAEYickdlM3MM52RCRDlxtjh5gGGTJPFUQmqtJtRxmdsB7hdaGB4s9a09hwANWWsBYe0VOagfcZTLLcJb7NpYyx8xpWYbd8l8wy+dj/4e4k7UEEPGlnLpWTxg/ymafMCEuPcHKdMILv8D8si6L2C8V9t7z5vq+Lghgsk/7uUksRVBX+wP/E6pPiubV2lVOp9hJIZNKuKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oLiqfplFvQsiftF6GTviacnEqj4GbmvWGeDw4ye3uhc=; b=HD0VCxvciCPgX8DSvqIPKOu3gvvjGXZW8OtsKtqY4QrMWo41oNzhwAFXagyL6ZemaveI13xBhARBKTX4CSRULZ+Dacf1SVF2oIfwaCJwWxqYaOOTLuYxO0shrTPK2WALKN7it8f+FXcREOqkGd71qbGTEfRnyzt7eTMRXYMFLXVoVvI5rPfAo2gTr+G2AYbEhTGyWstf/izBGpKzDerUJUH5YGHg8quC9cQMYG4xIP57s97a07TcGcEFmWdLHr3MNYl12jOZtwGYIi/Ifs4ee6zuCCuwy8y2ojny5cjF/X5PKPInsgnJSaPsXpITpheKd2TfGIvF0hvBRs+nTqhuDA== 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=oLiqfplFvQsiftF6GTviacnEqj4GbmvWGeDw4ye3uhc=; b=vFrmTerO8WE9hfZi0vGOrJtx+n5wsnxT1OkWpL94qyCtQc4WkC450OTtKJE1YKuhK4Ee5NQkEhIbgsy+XzFsFsB9CKxGNHeknabnSE1Hc0Is/kv1tgZWcu630r/+cOMP+giJ0P+JNnAjwUZWRsESrZGntD4lbHvQyc7W6Ricz8M= Received: from CH2PR10CA0013.namprd10.prod.outlook.com (2603:10b6:610:4c::23) by SJ0PR12MB7005.namprd12.prod.outlook.com (2603:10b6:a03:486::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36; Wed, 1 May 2024 14:55:15 +0000 Received: from CH3PEPF00000016.namprd21.prod.outlook.com (2603:10b6:610:4c:cafe::96) by CH2PR10CA0013.outlook.office365.com (2603:10b6:610:4c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28 via Frontend Transport; Wed, 1 May 2024 14:55:15 +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 CH3PEPF00000016.mail.protection.outlook.com (10.167.244.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Wed, 1 May 2024 14:55:15 +0000 Received: from chalupa-4a00host.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.35; Wed, 1 May 2024 09:55:14 -0500 From: Manali Shukla To: , CC: , , , , , , , Subject: [PATCH v2 1/5] x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept Date: Wed, 1 May 2024 14:54:29 +0000 Message-ID: <20240501145433.4070-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501145433.4070-1-manali.shukla@amd.com> References: <20240501145433.4070-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000016:EE_|SJ0PR12MB7005:EE_ X-MS-Office365-Filtering-Correlation-Id: ac22a883-aedb-479e-f196-08dc69eeb5ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400014|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?alvGdP8dvOjLiIA8hcMpWBmFK/lbQf8?= =?utf-8?q?LG+s0asrHuhev4y3xrw5xhus6Oy9BphyCQDvmLTq34zddOKRmJQT009zRJR5hlO4g?= =?utf-8?q?8f72P6sYhgcM9zt3b9xjtNr2pNa/LfZO+yCKLoie0ChS2paYFDD2v4ptwCPLIY9RR?= =?utf-8?q?4weiaAKaKRJ0zmEJwxCYJ9pBbxYjPi+/t8XCD6i0AvBs64xT9yljGQ5Ee+XnDLRiX?= =?utf-8?q?97fd3QuHhDkrI8QgO80sV46NHL6joRoUAysN/BY5MU0Z4epo0nusW1YR9iI5jSwQk?= =?utf-8?q?eX08yBoG+W6QD8KRfVOKAtgI1WTIqWPM0eZulUUJZjKTxqA2DHYYDJfdoTJmrkzwT?= =?utf-8?q?akEmrM9UpxG7Ai1opsXfRVKAD7fDdRWdBIyajzEN5ximnSvnEb5YlLAsC9A8FJU7v?= =?utf-8?q?Jp/BGLLAQxchaI1A8el7ynasGOoRSZLQc6vZLAStgrZGxcieoxqQGvr2v9Xxsi5ne?= =?utf-8?q?d7RCSK9T5jZEYORFdhb4YLdo7GjMC1hPpouu//5D9cHcMCGC8RKnykjcRC0H0MGod?= =?utf-8?q?lr3saqg9XeoX132LqP3Sm5qGw3zQeDqlUWt7U3TVqivutKrsA9HhX8wYTMHW/iPBK?= =?utf-8?q?17usFH45b2seYLa+jWu++dIOwbNRMcQrOQqCRfFVebPURYJ64Vbcghk3zQVlc3MUR?= =?utf-8?q?lYA9kzQuZo1uJ9K16OADDQTuAisnQ0usl5QixW1QLYDemKggXPUK+/qoBFf9NGkn6?= =?utf-8?q?CcEBzvFxOY89Uk5gU4gZ/Ev8TJGmNS4663h+bP78sF/EHVDzpHtZus9Ab4qVhLHT2?= =?utf-8?q?BRHRqSBVCeRfXGHUJl8uhYkXDWVWjTc1ZfXsheURnmimE6cFTIcEubGcwKxok/Uyd?= =?utf-8?q?xBPRd+3oeaAm7v14sC6stvaQmnHnitIXqosV/H/TM+vGUt+4xowduGYgRXfsLIInE?= =?utf-8?q?4ozUElnUD+r+iUfNI0UtxqZhY4IsD1THh4oDJRMPVxhgMmlNV2E+g7qxHbNC+8IoV?= =?utf-8?q?tAArcrVrdgKZgNFBgvby3D1ZhHX/yE8dWovrscyRVAz+OyEoPOC+9wYtVVkI3USgV?= =?utf-8?q?zWksqB5HI92i1/frHRiJBPynP31mtgFIwlzpNgXFx6gguqYaZW6aLLeHF8hWwhWVG?= =?utf-8?q?s/mSISADdDBDJcxlDnkphjNAmSaW5UJsSdKh3BpMmcbwkN/h5FsU+6l4VXlFEIFXA?= =?utf-8?q?tmIcSVGbiRbDR7nDf3DMPCcx0SqLAxgzTB8Xl5V5r05rdv3lRXN7OTwNXBleGD+nj?= =?utf-8?q?iDfg3OcbFPK6Edzg/VafVdNm6yEDu1Te5Shvy6RuHoD+O6rC2jfKA3YxNgz7itQZL?= =?utf-8?q?4W0jC+B3V6azHO8QQpNokLIzXY2SUZ9LP+8cioecVq/J670XosTlfyyv+6btI8ai0?= =?utf-8?q?Do5d4oiatX0F?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400014)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 14:55:15.4611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac22a883-aedb-479e-f196-08dc69eeb5ee 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: CH3PEPF00000016.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7005 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. Presence of Idle HLT intercept feature for guests is indicated via CPUID function 0x8000000A_EDX[30]. Signed-off-by: Manali Shukla --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) base-commit: 2489e6c9ebb57d6d0e98936479b5f586201379c7 diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index a38f8f9ba657..a8c5dec042dc 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -381,6 +381,7 @@ #define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* Virtual SPEC_CTRL */ #define X86_FEATURE_VNMI (15*32+25) /* 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) /* AVX512 Vector Bit Manipulation instructions*/ From patchwork Wed May 1 14:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13650819 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2068.outbound.protection.outlook.com [40.107.93.68]) (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 8F8F912E6A; Wed, 1 May 2024 14:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575321; cv=fail; b=XX2SAjSO+9jTLLlElXrFFOxP33KAVd4OS79qqj6Ce+pGAtHLv0pss5SHP4YrKBjP1IJoxuJIbHP/duq9AKFl6FANWONL7f3QPGYQTHyHWi+5lQyzZq0vObtGyYHHvTHJ8AsvxsgEnnSKpECblmJwxIP+xA2yw0GJwwRzwniwws4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575321; c=relaxed/simple; bh=48q1j6Zleo3Tvd1hgW3XVRzW4u5hL79/W3FOzcFXhpE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YtTth7BXapv9YiamnNcYV2hSYf7ocGddEL0r/VD7v7PRUKkrv/Dnnu5Lsyl+iY4D6fY4NE9DMnk03tJlXO8VDfkC3v92MzFloBXMSUeK9XLCvez78xWYFYrviHdDNDUw6ZnTuCcAB7TDndaXVTMDBeV2GwGArXH7K/7vyniVXF4= 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=2I+PX8VC; arc=fail smtp.client-ip=40.107.93.68 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="2I+PX8VC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=frlGvCFayWR+cO8HBuJ4+KsQgophEAsK6D8NtePMym+87ugpd+48XAriNpB9T88Wy67GMPw+WBkNHKtWFN0HQoVEk65teYIpuO6Fz0Bo11r0zvNfO6LGkhkSEuIWkeiFixrGwGsnjqtFVRtvu/TVxsWMEjIj1kI2wzZ9FGUIFeXHi6l+GEjguKWgJXAkUF25dzs7yxrBn90/QFSjz3xqUb0v2y+JbUar7Y+c1vMZTw8YhQVFJSTxd/Vp0NN8Hq3DqaFzyIgSboddqln7FhJLIh2ZLPlEtJwM+yr8nHQ53PV9jYF29LE/Y0y07SNz+cQ/KKpDL+Pano6zFltEhcyRkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O7O1D9rPzshxPT36TCV4lnUf/IACP+FaJhuqydq6OOE=; b=bTfMKuEmIERjiSJM0hezddoonvZflmCRSUQEOBnRLGzusjwbgmCpBe48AHZtMGrQuv1UaLBSuF37itKuy4eVscHie+vJCWU14vA9Ufq3ZCGxpgfSfsHhSt9FKIJafx+FiUHpDmYW4FNRcbXcr/bNMfkzjn0Euh4ilJ39UmNB5sdpCa0/TkWDcqdnY/fHpr8o6bsQpGaNiKqk0n/MXW92GZnkDtRf/K7Lf7h0XfR9lxWtQxZur5oUoRUJdAqCTkTMayjyiNbqta36ToJL4MR7Cn8HWqQ0BRXQhTZiinUBFDlrQUkqxfxPCNPdqE55mdBW4Ekf+5KYWJ7IfHUYeZrdew== 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=O7O1D9rPzshxPT36TCV4lnUf/IACP+FaJhuqydq6OOE=; b=2I+PX8VCfCEvB4HHnq8SRgqYLJmNlt4Zim5AOF/Nrb5l2t0by3BoqBgB/ZefNv27tx/4JuZIwC8dkYqEqDLIsAZ4tbRme2PQ8BQAJTo2V9k3t/5RLl2FJCPVYLMuS7npLT3zoz0Hm/BUNEfHB8M3xokQiTY36hB27gRb8p4xrDw= Received: from CH2PR10CA0026.namprd10.prod.outlook.com (2603:10b6:610:4c::36) by DS0PR12MB8199.namprd12.prod.outlook.com (2603:10b6:8:de::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Wed, 1 May 2024 14:55:16 +0000 Received: from CH3PEPF00000016.namprd21.prod.outlook.com (2603:10b6:610:4c:cafe::84) by CH2PR10CA0026.outlook.office365.com (2603:10b6:610:4c::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35 via Frontend Transport; Wed, 1 May 2024 14:55:16 +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 CH3PEPF00000016.mail.protection.outlook.com (10.167.244.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Wed, 1 May 2024 14:55:16 +0000 Received: from chalupa-4a00host.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.35; Wed, 1 May 2024 09:55:15 -0500 From: Manali Shukla To: , CC: , , , , , , , Subject: [PATCH v2 2/5] KVM: SVM: Add Idle HLT intercept support Date: Wed, 1 May 2024 14:54:30 +0000 Message-ID: <20240501145433.4070-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501145433.4070-1-manali.shukla@amd.com> References: <20240501145433.4070-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000016:EE_|DS0PR12MB8199:EE_ X-MS-Office365-Filtering-Correlation-Id: cc4a87ea-12a9-4006-b0bd-08dc69eeb66f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400014|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: aEFKlzsIu9U/8VcPACN2yQeEZw+hZ0PxeqzSLrieU6QuJvaHpscM47Dw2CAwvFbWFIKlSlnhPbvQWT9v94XnJKTS41bRwUagrFKnvAsErKxcixlsDtJItEsKQEezuMUOPdDwKJjkXpej9TngrVTOHAc0BhXgVkyQzfB27j4NiKpLgmllskjtX2gASXdBuZRzefFrtLLD48bxcAgM7+rZoYUR6mLCpm7ymVPFODZfTpZ7TB44Ye/L8j8EFQa80QE0K0o5GWrMWZvF4GkBW6qF4HJQrBzw4fRC97mktdD/uHT2i1OI7BIXD7gGiEivPzP8913jDtRmC1aOcHg4XoQoNO8bEfmtsPpNylAF1LNvHXt/+pVNuB3xG9qNQIrgvVfzZ7GBwK4+FonPefBgOEInu6NbifTu5KPpObyvm0UmaCEMKsyaTlbxczgVVzjtD6uYBhDwwF4RBEdcZax9Ho561B0Nrmm+HSUg+s0JFzhbwEogGuUXhK5iNTtv2ROEbO2Nziaz62Cib2u/mq0P5ZykrwL/8dEsSbkScigi6Kn4CnteP7qMQl+NXhIqHEL6tBjRbwmDftgVSBKoDAQZAFW5wA5qD2+tuE4qhde0bLRzbQ4lyWiIwAAqTEv+eyiEy+5xFBy9ExRsFyBcNpw/1/k6JZgXoIydPgvxVUKENz2z1ClXpJzJMESWDenPDduCEHkmO4RAxt4Z7tPIVseT12VPWoyKVR3VWAp4i3P0HT0uFT0PsQbcUO7P2QmnplKWgepZB/1ZtpOvtDx8QGzdH28ByDZs8Qg+nXukUrUc2qtjHVSki/ezvRdUELXpMn1/fxwnk9qdSmag5TxulvlVKhI0XhPV4sxzjcmySLKlHvPCnkxZGWHjq0CdFamBbDa17ZyA04T8r9OYRp8hdQlhKvRhStIAi4Dzgt/1V6Z94z0JNqK2yjQMHw0gZhLukGSowPdDNZiMQdo6ynqMSfpGwamb6dUcQZIZekKr+egh5KPh5Lvf58alTUBydlPejlzp2iwYEtMqREp/9vLMlr2fe8HPrxyadJwxlcRTn6IBbPORClyZHrvI9r2cEuLu0fiaI3qlRheXpRRjMeTR2kHOS/N0+3sDjtYUgus97RbFXroHR0cX7R8Tdgw7eKUcJjLcSi+2KL8FXXd9aJdkcTSCPlI4Z2FfHkSFN1hbIZPqW2srdZqjXfijNAKYaoIbth575In0Gq0OqWOFFqbEK0NlyGfOfwQrnVjz/83nWVa7yphJ0vgMgz+04l7z0lmTQRogP7DUpo8DGkeLP55mEBcKJRRxGYYPhbugaP5T1i2CdHMHkG3XCBBsB7SucfqdPqi3lPmL X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400014)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 14:55:16.3048 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc4a87ea-12a9-4006-b0bd-08dc69eeb66f 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: CH3PEPF00000016.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8199 From: Manali Shukla Execution of the HLT instruction by a vCPU can be intercepted by the hypervisor by setting the HLT-Intercept Bit in VMCB, thus resulting in a VMEXIT. It can be possible that soon after the VMEXIT, hypervisor observes that there are pending V_INTR and V_NMI events for the vCPU and causes it to perform a VMRUN to service those events. In that case VMEXIT is wasteful. The Idle HLT intercept feature allows for the HLT instruction execution by a vCPU to be intercepted by hypervisor only if there are no pending V_INTR and V_NMI events for the vCPU. The Idle HLT intercept will not be triggerred, when vCPU is expected to have pending events (V_INR and V_NMI). The feature allows the hypervisor to determine whether vCPU is idle and reduces wasteful VMEXITs. Details about Idle HLT intercept 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 | 11 ++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 728c98175b9c..3a91928a4060 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 80e1df482337..9910f86a2cef 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 @@ -223,6 +224,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 0f3b59da0d4a..223c670bf986 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1289,8 +1289,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 = __sme_set(iopm_base); control->msrpm_base_pa = __sme_set(__pa(svm->msrpm)); @@ -3291,6 +3295,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, @@ -3453,7 +3458,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); From patchwork Wed May 1 14:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13650822 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2077.outbound.protection.outlook.com [40.107.92.77]) (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 4B03E12F58F; Wed, 1 May 2024 14:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575325; cv=fail; b=XPQPb++3XTHj8Hx8nj+GgbflXHh8eDAYG/EzgPyEJazPPtcXyb/JIrsIKPRj7YmeweuqT5uziKA+vjj7Q9YKUPw6sm2EfxE1zzKyoD2NjPuJk5zCDXbqohFtvwM6lPV0o2QkiPIQBdcHo7rw1gPpyjDw+rIZabw/AemRpdlEt48= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575325; c=relaxed/simple; bh=W3SoGjtP3/E+c/JuG/ackI/Xac4zWkk7EDVFsDH7UoA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jEX0M/EJbUR08hNtoKi6N9HYjIOQJPneKsD7xzihT7qDhKYL376dMfcAW+aJ2VCZUy+gzMy+aLUI/4UPv92AwgOOI9l83XuXatvI6wVNjZ6BmpYdazlozoMo1qHPzH3xai37ksLIgSSFdOihzjWFRDfIOT/C5bzoGQALBel5wIw= 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=BgrMXuJf; arc=fail smtp.client-ip=40.107.92.77 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="BgrMXuJf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HaA1OvnW0w8BfIvc/VgJyFo4xd3Fa4PiOOQinK38ZFKhll1ubguUsq8Sjp2YMzMNASHn6PnkiM5Kk2OsV28Kc8yutJV9s0ZzM7lMoMmc/EOrTnUeQBccHrdrBHO+aY+q4ZeufYZsgcnyggBg+glOAg8mjwmtYE3Ufb9Jf0hPC2yfdhZ/W5rcphlkqDNabLXiddHDQk1kIz7ZD9O0Po3CDAtLs0GrjYAuvaPlks5iU/dkmvL+k2Kup+0r590fXExmILDz2MR63LTmNXXzT2C3Btwp6Gh6cRMobWnH3ohpppOT6X9j+PZuVG4rZWNp5HH04Ow3vzs9HOelsSeTEzwNcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aqDkOBpQO/PeplcaBdvoCMmeLxIyffTnBOx2f9spVP8=; b=b2xCbi5fIsdWGFS8qCg4tUacVDoyWSHH0Xap3/F7TgQm8PC3rlKmOai+cLDs3AOimaidwZBmAb0yC1f4X5shImYtqc0yH5SfyqNiRCG/gAO1ifLpQn3eDZHieL0E67oiivWkXzv/KWjuc86AzpFyBl4HWGkuTQ+IeXjviweHtHiPrlQoSmOjY+99joLLqfSV/xb0FABQO/Ppm+0wX/L8dut9xhmMPDB1zvPFlnVt8nJApv9XWBjcE/wxqVSFtRozkG9TTv1ATeAxJ2c4E4Two335RtyegwrF5voPHf/smZGkFGpLuVSmMx3RCoxixNBw/DzvtsVG/qrfwoGCKyKFAg== 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=aqDkOBpQO/PeplcaBdvoCMmeLxIyffTnBOx2f9spVP8=; b=BgrMXuJfoTTvafBuMxtRgBtOVXqRk5AwcKtGDJAeFnvQvFgaGZt0qte1YW7D+QePN630NbYNNO0G2wfrtIGMQyKYRqYrAa8lKBtTxJwUUN7q0fW0MG8KoqY9Mdgq9/xQ1wLRRe7EKHqxoHZD10wIpYXE0xGbMGiIxc/xZXAiHaE= Received: from CH0PR08CA0018.namprd08.prod.outlook.com (2603:10b6:610:33::23) by CH3PR12MB8910.namprd12.prod.outlook.com (2603:10b6:610:179::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.32; Wed, 1 May 2024 14:55:17 +0000 Received: from CH3PEPF00000012.namprd21.prod.outlook.com (2603:10b6:610:33:cafe::12) by CH0PR08CA0018.outlook.office365.com (2603:10b6:610:33::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.37 via Frontend Transport; Wed, 1 May 2024 14:55: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 CH3PEPF00000012.mail.protection.outlook.com (10.167.244.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Wed, 1 May 2024 14:55:17 +0000 Received: from chalupa-4a00host.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.35; Wed, 1 May 2024 09:55:16 -0500 From: Manali Shukla To: , CC: , , , , , , , Subject: [PATCH v2 3/5] KVM: selftests: Add safe_halt() and cli() helpers to common code Date: Wed, 1 May 2024 14:54:31 +0000 Message-ID: <20240501145433.4070-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501145433.4070-1-manali.shukla@amd.com> References: <20240501145433.4070-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000012:EE_|CH3PR12MB8910:EE_ X-MS-Office365-Filtering-Correlation-Id: fe7ffe09-37c6-4baa-e6d2-08dc69eeb70e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400014|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: t32FEH+rMWn3TtGEXF+33zArCy6EodW8FXXVf0NF4heSYS3/6LibTFJKy6lVrLSs+YPndJhPdhhKIpkSuWrT6zwkY0vScC9DQiPin8rjwVNnonUZJ6t/hP5o08xxfopwkAKthgAuW4NB05z+EgaeVrD8pZaC3jDXLBZH6PT+zJnU5O3JRyERDnKRrR5dtP1YljotsJrPwGHSVBu0Susj/klEH8OqKLsF3nJIaZNm+EcVVg+wShjrO7vW6ciPNioQtCRRUFUrBszfxhA/lACyabc7q1+MQprg26bYZOviKtsd/11PhpqB5S77VBTyWHE8Gritp+HZlhrQA0gy0Qhtw/Z3IkOyjO21ydVf5hCi1osKtDwRRQ6s4EJKrC8npSIQmxcFyFuOgd4x87TS0k8QXlufqNXgL+qit5yr8brd74Hvt5O6dF1ubLzQYv0WhoTxOyX8vK0NLN6Ji5LduX+kdN9xis9hCOmJikSUkZZmmUpomUyYPad3WM3TWtjl1IUVgUsgasKNRWL5ZRyhoV1Pt8e6l9jx/Y6qphm7lZbXjzBiUAETzILRBykcjGesLayhT0mol1sgAHCMOCcNpfJ5TZ7KB8uZwA2Bkv3Av7uNm7geEr/3LTBJ9Fr0SQ+eMClNkz5OMW5kbOLaXaHPobafi6gfBRXiKYgWmtyKzxWuEZC4weuSQygGPTnzQ4nqwfky9OZQZxAqu4c1Ymp8UvOr/y3cphm5fJM1T2gjzgdE6aXiv7kwpsb5rmNHgo5DVyHNkvtwRhzSKvZBRf4/bC39rWg3eMTpm+CTnRxOKrbodX0dHNKdPx7VtLLX6L1OxUKodkTJ0Afqb79QqXw0d5flLokIkw/KdtbBGhVhHXviicloK2rvUjc2J+/+KLJro031+srkE4I16cbt4E/OdhQ8vK7uyzj877gZiNcdB6eNGCv8r8TioGoLk/fsToAdTm9kAeH4iYcgbtFOryDYMXFaE1e0QXutKNMSjgMZYaE2N7x0RBEZoNxUDa6TbJ44jlQA20KE+/PtHDC2HSZQQJPsbGi85J+I8QaqqFj1IyeHK/A2X5E0QGmHkB+o7x8bX3/5QPCOuE/9r1AP1iGbHhKkbn/DbmM9TJzhI/dJI8PR4zyOsTaoeXSOFcfpQXhF4w6D1H5TZz3wB10QCr7yYBWVFY5cfEiaoPelbovp0z66RyBCTvXNGm/SLibNGxePffhIzPfvHLmBaS0S5CjD9t8/sJRI2ZyOPv6N7NAjHe9gxQB6eq2RUY3lv4cL8yQ0JFue2d4oVocaN7YrFDF/fFZvrQU6UW2DHQY3ssskrDyuaUGPXLwNJXeXBDkqdZEEO9ST7y1YzuaZmVg6yyn5XqvrwZfEuZ1Ewvwcldx1Pr11vfHtyfqxIwvXIL+C39blIAco X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400014)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 14:55:17.3482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe7ffe09-37c6-4baa-e6d2-08dc69eeb70e 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: CH3PEPF00000012.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8910 Add safe_halt() and cli() helpers to processor.h to make them broadly available in KVM selftests. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- .../selftests/kvm/include/x86_64/processor.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 8eb57de0b587..f74f31df96d2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1305,6 +1305,23 @@ static inline void kvm_hypercall_map_gpa_range(uint64_t gpa, uint64_t size, GUEST_ASSERT(!ret); } +/* + * Execute HLT in an STI interrupt shadow to ensure that a pending IRQ that's + * intended to be a wake event arrives *after* HLT is executed. Modern CPUs, + * except for a few oddballs that KVM is unlikely to run on, block IRQs for one + * instruction after STI, *if* RFLAGS.IF=0 before STI. Note, Intel CPUs may + * block other events beyond regular IRQs, e.g. may block NMIs and SMIs too. + */ +static inline void safe_halt(void) +{ + asm volatile("sti; hlt"); +} + +static inline void cli(void) +{ + asm volatile ("cli"); +} + void __vm_xsave_require_permission(uint64_t xfeature, const char *name); #define vm_xsave_require_permission(xfeature) \ From patchwork Wed May 1 14:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13650823 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2061.outbound.protection.outlook.com [40.107.223.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 EB43112EBDB; Wed, 1 May 2024 14:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575326; cv=fail; b=jkWIlgAzJqcP/QcIZ5xoLVr6NbVNTDNWv8DPvOsQQgVn1A0ravxmKDP//98k8PHn2LpfrrkWC/wqc5unuCHfXH62bmDX5LxxwR/M4OtwXeF2TrmDhKJ3LF+rn44HQLV2kMA77rwL9LPVKWVCmu/MOg16nV7FM9tYfdSlbz5uG5s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575326; c=relaxed/simple; bh=OIRk0hD5CPFkm9poMTyIyD+t489GGjZfQk3Lh0eCPcA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CeT1HJZom2258on/9nRueDBOYK1EkzsKifmgVET61mOglIXgWL1IeuBiEMfRhYjd2E40a2m8LKEI6vbvlcTKrGXv42RwmWlfm83YJZqYiKGsKRjAMouv4N/Sqhg3KEzj0Y4Kouhpc+hxWGQVLGgBPr4rhuIGEpyUwZAT5m8eKBg= 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=EH98ngP6; arc=fail smtp.client-ip=40.107.223.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="EH98ngP6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYU3Vsx1g+5SjKFYOJ16ioG5nYIZT+1ROh/RwphdKgT7Xwq9Jplq37HxeYqQ6G3aNFWbIa+IDVZ54o73h+fZwiBGVup37uinTY8d8MwFR0+bdcVWe4JLX9GVTpnNsScnkhdNdfHndqOdqOlmASnTayeY7tS4/kMGZ6rmFZ7YB8lyIBgyFCv/PxLKOpEADwb1DaPUejYXPV+KvqYsAOkE4oM/U+yu5Nlz0ENBY3lmC1EhRhSOKcbvvsVFZiOOE1/NEnc0CCzyUrS3AAPWWu6mmofFbjb5zWmRp6rr08u0gYaKj1C5Y5pgWbd8mqetese7OwpMBjzC0RlyJo3aCj0wZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uixHsE91hXyDexiFCZ883Ml19yfeOsfqf764919pxd8=; b=O6o+spZwZ95A3U5U91SmVMB3ZgQGq9TIi8iDiLOZOPGOhydVyeNjWSzJMc3EfIuurgVoXErtFHJ77EHEv9NgM4QedwDMwD+dvHP34gttWS9oiAH/VS2mr270yzO4R4cky68+czTJ7B51dmJxwx+By2/9AQlBbdvXFOVd48EkwBV9YchFqqoMUaBvhKLDTWeW5Z94qHjTSiFrG3u+YkjfvJHL76yOXmJKKWNaeRQ2IBYxs+gluLAJMajj4cK5PefixREq7aOJvCOtJVmwe6scKsjQp9hZaWaXyGsnUB7wBxTB/zVBcGCvhZYRkoIcUR4NGjFAqmcGaCX7SaTf2D9KEw== 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=uixHsE91hXyDexiFCZ883Ml19yfeOsfqf764919pxd8=; b=EH98ngP6qGKAjiSgO/OyG8FDjAgvYUVeyi4JxGWaIkY0Vyz3tsfAOn1ZSghszjvB+A6ETBEo5rfAKqRRAq91Ln6vh+KmNqeScT779sU7sc0pIw2Y7zZke9KnFiaxgb/2/w1ztXDdp5MLi4b43Qz/+RMdVFJpVsfGT/Mvm9BQUX8= Received: from CH0PR04CA0002.namprd04.prod.outlook.com (2603:10b6:610:76::7) by CYXPR12MB9317.namprd12.prod.outlook.com (2603:10b6:930:e2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Wed, 1 May 2024 14:55:21 +0000 Received: from CH3PEPF00000017.namprd21.prod.outlook.com (2603:10b6:610:76:cafe::31) by CH0PR04CA0002.outlook.office365.com (2603:10b6:610:76::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.27 via Frontend Transport; Wed, 1 May 2024 14:55:18 +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 CH3PEPF00000017.mail.protection.outlook.com (10.167.244.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Wed, 1 May 2024 14:55:18 +0000 Received: from chalupa-4a00host.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.35; Wed, 1 May 2024 09:55:17 -0500 From: Manali Shukla To: , CC: , , , , , , , Subject: [PATCH v2 4/5] KVM: selftests: Add an interface to read the data of named vcpu stat Date: Wed, 1 May 2024 14:54:32 +0000 Message-ID: <20240501145433.4070-5-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501145433.4070-1-manali.shukla@amd.com> References: <20240501145433.4070-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000017:EE_|CYXPR12MB9317:EE_ X-MS-Office365-Filtering-Correlation-Id: 135e8365-1a98-4b2b-cfc6-08dc69eeb7a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|82310400014|36860700004; X-Microsoft-Antispam-Message-Info: 677r4TRiDcCp404V48Nrc5UsOeZxi00emaC7f4kTwe5PDmJ527K8i9SK/YmHcRzBJzjv7PURytwZDid2Aa1hXaAOIdv7AmgYdwyqTTd+9Qpq5ENlsSqxPFKixJdDH1OGA+lBY+cPkuSraD06jLXM5AqLjtDpd6130pru5qQMbSOpVx3X5wrLIE6RF8BShLK04mrIlddvs0AytFyHdfl40U9npwEvQ0UI9uES09zpmhdNNSTF1TVXU6wk3JX4mbbLDYjRlTTwL576RTRrmjX5Cn+FDrPTRcAl/fDtM3QIfFsumvPcNmEdGyM1k4WPCwWrG1PwSND5Nb7StPRpGV8P+EazjalVdMLKeKdtIaVXbzKEtgCMLmSay1WoS9mDENc1lAVp3c9DiRhtCP/9w5x/Ne1hbuIJ6O1QacngBPOmR2T/NkqCVsHZPvRFljN4DxNh65i1xW5w2/pNCc318FCjVGgTxaCBUlK+q/kTvXs0rgbb1NzZv5qVDjzghtq5wT7HOt8Kja9SswCC+D4kiILJZjai6s4CtkPQiU+f8HQRZKw5dUEKfRDLu3HtIjGlE7HuixpSauaOJtSA18kFhc5V4wEUsohr+86IpteLco/dXnVsG/JYQxFviAB8KYLig5SUvpbsJynZ9dJ1EeQRN9mBOsSdWpe6iIGI5j2hDT+G+P8czgBMk4s5O1xUyyVDNfIb0SIA38KiQVBaxjEgrkYNHGliMJ/hfDBVt37FYaIyCKDI7YZ5/dXs+m4jNbQue51pXOklyjBALLxYRXRfKntxH/DkKXcTu69OQ3Ok6irNqaOfZ+Xoy4+b9Je6bTw0uICasQNE7Pa3PfVqnNG4NmCl28wXYel/EH5+F+2Fo0LpXbRdng8gp+2QHTWg6Jl0SkIvbAODRHxUezC9y1gAE6kSOdEqCWHnoBPOs+dl0MkcX9q8RTFYz4/19Tsi4tcaa/Iwo5fh1PatY+r7ESbApCBB4r10iMqVtF9et/01ukXb62kHEKq6R785H9R0KpurPjHLlEbLZXjG8uTQU2SzWcLAInW7DCvBRBh9lKukhfMqx0kj+wJjoWmAUf5bZGpDQoeH5D5xAMeLUDvCRRDa7lF2skMHS1m1USALqnkedlLc6uMvEHyfrGnDNsFyLDH2IfVub/OQtHFiNOgWK+BbYJhP9vtumonYhRonhIn9Zyetq9GER/lARmSEa7jodoZ/gZ7A6uEJjVyo3lCEZbBVc7dTqMPZfug9SLurU0fkQKkYd9ACit+mereaQSMvkH4xA+3Un8NHwJxUxe4tKF+Peq9if5Hfaf1booHtTZaD+ZUTNW0l9VLb6yZ1Ab1mbUWCtEKRjB41ie3gYlK+WWf52XsNsAjizZNL3bwmeTr2XtlPidU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 14:55:18.3045 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 135e8365-1a98-4b2b-cfc6-08dc69eeb7a0 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: CH3PEPF00000017.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9317 From: Manali Shukla The interface is used to read the data values of a specified vcpu stat from the currenly available binary stats interface. Signed-off-by: Manali Shukla --- .../testing/selftests/kvm/include/kvm_util.h | 66 +++++++++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 32 +++++++++ 2 files changed, 98 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 63c2aaae51f3..7dad3275a4d3 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -518,6 +518,72 @@ static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name) return data; } +/* + * Ensure that the sequence of the enum vcpu_stat_types matches the order of + * kvm_vcpu_stats_desc[]. Otherwise, vcpu_get_stat() may return incorrect data + * because __vcpu_get_stat() uses the enum type as an index to get the + * descriptor for a given stat and then uses read_stat_data() to get the stats + * from the descriptor. + */ +enum vcpu_stat_types { + HALT_SUCCESSFUL_POLL, + HALT_ATTEMPTED_POLL, + HALT_POLL_INVALID, + HALT_WAKEUP, + HALT_POLL_SUCCESS_NS, + HALT_POLL_FAIL_NS, + HALT_WAIT_NS, + HALT_POLL_SUCCESS_HIST, + HALT_POLL_FAIL_HIST, + HALT_WAIT_HIST, + BLOCKING, + PF_TAKEN, + PF_FIXED, + PF_EMULATE, + PF_SPURIOUS, + PF_FAST, + PF_MMIO_SPTE_CREATED, + PF_GUEST, + TLB_FLUSH, + INVLPG, + EXITS, + IO_EXITS, + MMIO_EXITS, + SIGNAL_EXITS, + IRQ_WINDOW_EXITS, + NMI_WINDOW_EXITS, + LD_FLUSH, + HALT_EXITS, + REQUEST_IRQ_EXITS, + IRQ_EXITS, + HOST_STATE_RELOAD, + FPU_RELOAD, + INSN_EMULATION, + INSN_EMULATION_FAIL, + HYPERCALLS, + IRQ_INJECTIONS, + NMI_INJECTIONS, + REQ_EVENT, + NESTED_RUN, + DIRECTED_YIELD_ATTEMPTED, + DIRECTED_YIELD_SUCCESSFUL, + PREEMPTION_REPORTED, + PREEMPTION_OTHER, + GUEST_MODE, + NOTIFY_WINDOW_EXITS, +}; + +void __vcpu_get_stat(struct kvm_vcpu *vcpu, enum vcpu_stat_types type, uint64_t *data, + size_t max_elements); + +static inline uint64_t vcpu_get_stat(struct kvm_vcpu *vcpu, enum vcpu_stat_types type) +{ + uint64_t data; + + __vcpu_get_stat(vcpu, type, &data, 1); + return data; +} + void vm_create_irqchip(struct kvm_vm *vm); static inline int __vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 6b2158655baa..3de292ca9280 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2256,6 +2256,38 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, desc->name, size, ret); } +/* + * Read the data of the named vcpu stat + * + * Input Args: + * vcpu - the vcpu for which the stat should be read + * stat_name - the name of the stat to read + * max_elements - the maximum number of 8-byte values to read into data + * + * Output Args: + * data - the buffer into which stat data should be read + * + * Read the data values of a specified stat from the binary stats interface. + */ +void __vcpu_get_stat(struct kvm_vcpu *vcpu, enum vcpu_stat_types type, uint64_t *data, + size_t max_elements) +{ + int vcpu_stats_fd; + struct kvm_stats_header header; + struct kvm_stats_desc *desc, *t_desc; + size_t size_desc; + + vcpu_stats_fd = vcpu_get_stats_fd(vcpu); + read_stats_header(vcpu_stats_fd, &header); + + desc = read_stats_descriptors(vcpu_stats_fd, &header); + size_desc = get_stats_descriptor_size(&header); + + t_desc = (void *)desc + (type * size_desc); + read_stat_data(vcpu_stats_fd, &header, t_desc, + data, max_elements); +} + /* * Read the data of the named stat * From patchwork Wed May 1 14:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13650824 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2063.outbound.protection.outlook.com [40.107.243.63]) (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 7106C12EBCC; Wed, 1 May 2024 14:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575327; cv=fail; b=bq1df1WdtZvhdhrd7Q/Uk6o2XIt3RsSORA+vuxT0AR+SBbUBxH7jElIu+5Axxn+UjDpiW09fjqxnz+mt0pSbQC86Orm/6G/9K1qRcsTPGlxhEzuV/o4AJDNMHmTb8wbnAsq/TFXpWImfmVc1CS6XeR9EXvyySujUtWyVQm9faPg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575327; c=relaxed/simple; bh=TjAb69OVRcVxE+ATZRBVvDKSBq0XOqz4+21X4RPthus=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m1UcIyVYEDTorjqTFkmQ7+oabeDmsJwWU37TDgMjOJBOjxfwr1Lzy2T3hDd3SYH+TE+Zt4OmMfMSyMsuC8CoxQVCYqcGhtdWmGH5oSBNnHt3kPA7Uiu/xr+eMITckW5WOIAor6dLvUOkvRSeuwpzZsTBPD/pxYEsdxUWDcfe/d4= 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=xCkwmAZP; arc=fail smtp.client-ip=40.107.243.63 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="xCkwmAZP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DHYvJrCKTVhxlw1XKMLaP//kuAkA5TleyBq+dFg3hB2kAyTIBEEM2o2OwAj5XRk6v827BnkNzeE+mzS1yGQprvSuIgu6LXWkqnBhOpgu9NJD/ANRhpksQrc+Kfcf6UNrMYZFR9aCTgZud3lzm6Z0tu1OJatwQyqTPilUHqX+CuoEGNOWT6xEnqEUJEOpwA00vhQD2vMcsnNy4E1oY9GR+OEl/lXj6AF4CP5n5djZvp+3m2BmTB6ugWQcvSQkNWXdpxWrIf2bmRD2OKFwmrkiaTD5JJ6nYoUI6TnlvjzuaqdVp58U+/JDEK2p2G/nGquCjdnCGRUCne4nW+VZS8dWTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JKpmEanb1+kqijWMrcl26r9SQLcjXziANdt0nCooqrI=; b=D5F/UjLCUiM17qmJDlwgoY35qgwzMHTPJ4JdO/IVakwIV2+UJNIktkjl9sZaWSRdIoqS1WSi/nbJZgbLZTxoPwfUfA6zS+cnni6bz62tq6ccMXtEfOdglULfx9J1iQm+i2GmA6TROk1d0dNQQK/9yE67xu0aImtikKtEjgTOruiOvUnFquTQDKcSatXq8fbuemQpFIfVrB6u6sjX1IIc3nFVSCG66/tR5GmPK9if84plJydGVthAL9s4jdN0jNkcV8S9SNkqvQxqsmzxuvbucrMbFVFPXr4vrCsu9nMI56LPTjyAG7Y3wXseg9vzOSGj9AoQDtQt27l5V9hGk333mw== 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=JKpmEanb1+kqijWMrcl26r9SQLcjXziANdt0nCooqrI=; b=xCkwmAZPx4K5PWka1fBwp/JYJhkUmPW+PoW/3B513FDjNSj2cg55ZUlOWMGyKoJHwU7eBcA///ujDivunMZdpiORbT2SMD8AoWIFYonldLbPQmE9aw8IC3/AUoX1M9tW+HmNgNfX5/JGgMffO18KNkNFIqp0yPBopnS/TcKGhU0= Received: from CH0PR04CA0030.namprd04.prod.outlook.com (2603:10b6:610:76::35) by LV3PR12MB9258.namprd12.prod.outlook.com (2603:10b6:408:1bb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.25; Wed, 1 May 2024 14:55:22 +0000 Received: from CH3PEPF00000017.namprd21.prod.outlook.com (2603:10b6:610:76:cafe::a3) by CH0PR04CA0030.outlook.office365.com (2603:10b6:610:76::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28 via Frontend Transport; Wed, 1 May 2024 14:55: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 CH3PEPF00000017.mail.protection.outlook.com (10.167.244.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.0 via Frontend Transport; Wed, 1 May 2024 14:55:22 +0000 Received: from chalupa-4a00host.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.35; Wed, 1 May 2024 09:55:18 -0500 From: Manali Shukla To: , CC: , , , , , , , Subject: [PATCH v2 5/5] KVM: selftests: KVM: SVM: Add Idle HLT intercept test Date: Wed, 1 May 2024 14:54:33 +0000 Message-ID: <20240501145433.4070-6-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501145433.4070-1-manali.shukla@amd.com> References: <20240501145433.4070-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000017:EE_|LV3PR12MB9258:EE_ X-MS-Office365-Filtering-Correlation-Id: fb6f3479-1b80-4f97-50e5-08dc69eeb9eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|82310400014|1800799015; X-Microsoft-Antispam-Message-Info: yPWkM2SAHPbM1sWj+5bSEtQRzeNTqCsdVmr5yYvRXcqQJtu0QcjEI21JHXzkOrKiVjMUHRUCSavspunSEVMWMyXDqk2oks4eQ6KhqosKqCAZg0fEwEkGRGEtlcPLpUyBG/2HYDkC826AKsnuVCNG3+IKMdJAjay6qne6FgsabDGkmP2klzJHS+rPXEQ6O2aDF/XlmTdtIS7u5Qyc2Fm9dmAnOp6o4XyYEtTTec7O8G71HTWxnGOt1OQpH6RwBYvUgnRSdq0uHvMBUocUDtiia9x3Lxj6W4IEBnAc3tvstZmAB+f71Px5FDB1z9hSrGXdYmnwAcSYeSQTmGZ7730KgcNMpJ7cU2X9wdFzQ4o4gJDWf2cUp9Cc9liXrHM/QXjwzRWyPxnutyKxr3LMYmqKoxF/FMDknkzHX9Rbv7pNe3eIiLzghWw6TXtyhn3oCgmhE9Iit+j+/JPVdkuy4sQiiViXQjcFcQK4+P/nIhHzhuMn1wdkh0ABQ+7SwIRCwKSr87Hrg/knRiQUDh3smu8cbk82odggiYDlpRWymFUzDBCBAr070hAT0E2Me+ZYzil4MaprhfLUuJ5vtGK5DrwWLzwI0khtNw960cgNhLkHb01+vUaOtiIK2rYHmXfiF6Vzfiabb51MfpjeOOSgttZ6Yxnec+f1hfGPzvjyvGKc2P8wh4NRo6U7v+SNPlXB7Bl9tV27pb5payou602lJBDsbRSWNvvDTfYF3BLwq3PO9JNRVelYlio1v65QWuLOcqwJ9oBmTZB39OeH6MhkPgO+QFbAtUT8n3X7SDCsxgmlnW0QPf6N9Mu+Z/ygAjxXGehOaFt6LRM8HoqWWReKX9Ozf4phxmVqtXIAnXKt02X7oprlvqVM8/TDmMQRUKj56KxSywyPCsEyC5DTmBBUItpW9t72G4+y31zOC965PH4jUClzawmTAegqg0ng9HHRj3J06YRwSrOhuUKisV8AQ7bvwy23JqIN6JqseDPCWkmmiSz47Lu0bIJwoR7FqEE1XMfYk1G0yAsM4lLvII+qnWAXmIRlzn9yi2sw4xqgQ54wL8A6hnulo2ABDzWy8hMRixMHL1wnfwQqJbgCU3WkgyE9dCdfrcvT+yAAnUb+24Wt+zRzoTUOi0iOIzO9M3XtdNOvsnnGufgVZoaEfrXQQvVeD8UCXbLpH4ItlMUDKt0qerI4daPZ/Vu7ULmQ1p3CL9GhAue5SZWFWMrzNGjn2we1iayM57RD4/RQnOW3GHCAw1KcQSoewY7lgHUIVBC5slOdnitf7TW7bc2X2tIGhr/itN5y+JdOxPOFrhnEvFC6jfmBitfazAJpGdAAhUbMIiFfvPtM8pRvpyZUPb1qoimzkNEVrV0vz60vIoI/d1UhbX0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(36860700004)(376005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 14:55:22.1482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb6f3479-1b80-4f97-50e5-08dc69eeb9eb 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: CH3PEPF00000017.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9258 From: Manali Shukla Execution of the HLT instruction results in VMEXIT. Hypervisor observes pending V_INTR and V_NMI events just after VMEXIT generated by HLT for the vCPU and causes VM entry to service the pending events. The Idle HLT intercept feature avoids the wasteful VMEXIT during halt if there are pending V_INTR and V_NMI events for the vCPU. The selftest for Idle HLT intercept instruments above-mentioned scenario. Signed-off-by: Manali Shukla --- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/include/x86_64/processor.h | 1 + .../selftests/kvm/x86_64/svm_idle_hlt_test.c | 89 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/svm_idle_hlt_test.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 6de9994971c9..bd97586d7c04 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -93,6 +93,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/smaller_maxphyaddr_emulation_test TEST_GEN_PROGS_x86_64 += x86_64/smm_test TEST_GEN_PROGS_x86_64 += x86_64/state_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test +TEST_GEN_PROGS_x86_64 += x86_64/svm_idle_hlt_test TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test TEST_GEN_PROGS_x86_64 += x86_64/svm_nested_shutdown_test diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index f74f31df96d2..0036937b1be4 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -192,6 +192,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/x86_64/svm_idle_hlt_test.c b/tools/testing/selftests/kvm/x86_64/svm_idle_hlt_test.c new file mode 100644 index 000000000000..594caac7194b --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/svm_idle_hlt_test.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + * + */ +#include +#include +#include +#include "svm_util.h" +#include "apic.h" + +#define VINTR_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. The HLT VM Exit doesn't + * occur in above-mentioned scenario if Idle HLT intercept feature is enabled. + */ + +static void guest_code(void) +{ + uint32_t icr_val; + int i; + + xapic_enable(); + + icr_val = (APIC_DEST_SELF | APIC_INT_ASSERT | VINTR_VECTOR); + + for (i = 0; i < NUM_ITERATIONS; i++) { + cli(); + xapic_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); + xapic_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, vintr_exits; + + /* Check the extension for binary stats */ + TEST_REQUIRE(this_cpu_has(X86_FEATURE_IDLE_HLT)); + TEST_REQUIRE(kvm_has_cap(KVM_CAP_BINARY_STATS_FD)); + + vm = vm_create_with_one_vcpu(&vcpu, guest_code); + + vm_install_exception_handler(vm, VINTR_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); + vintr_exits = vcpu_get_stat(vcpu, IRQ_WINDOW_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); + } + + TEST_ASSERT_EQ(halt_exits, 0); + pr_debug("Guest executed VINTR followed by halts: %d times.\n" + "The guest exited due to halt: %ld times and number\n" + "of vintr exits: %ld.\n", + NUM_ITERATIONS, halt_exits, vintr_exits); + + kvm_vm_free(vm); + return 0; +}