From patchwork Tue May 28 04:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13676089 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2063.outbound.protection.outlook.com [40.107.92.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 832C0442C; Tue, 28 May 2024 04:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869986; cv=fail; b=uHjnaHtjnZMJRjP6v1IZD5IV+8wqkAHkFqCNZSHex4wzzgmxRRFwpzS3wX/9NO8VisXFPbdJeUelEa0sIIinVXk66oCPydn6dk0KHSdMpMTkczI4+JgLIrxJ48zFmf+uGkTZDQjAyS22pDK6BLDl6PRHNbbv6nVBXVnZju44caQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869986; c=relaxed/simple; bh=QigwGiAo6it6zUdtue6alaHEgr0OFO7JUGjv4KgpzR4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r+EoKICoAuR9gYmkJp8fcmFLAgGSiAf0l5qhjYijZrEoGJP9D+ls+JVhtHv0/hHAdl9gTuhfFjjuxRvjTsyqUPkGYLdDST/0MiIOJv0/6eLTZQzRRdBavbyw1g//NhwjXniLiNYmrv/z5Nj3bohhMwuqhjjbpOHOgvdXuMtPu0M= 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=B6vUffjb; arc=fail smtp.client-ip=40.107.92.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="B6vUffjb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H6TMIf4ZJuudhFsQtfYCEla/Iq+mdEwUyG3EsyXko8MEgwAA3mFF92SataBRt/yrjYip4V20d+3mvTMUDwji7r4r1vnAbtBGqxv6EIYfqmrNrhWJnmT4TTd+BvOLpb74O0RsD6wf0wYxa2ZSo+xizmCoXMS8VvsR9jh9Swu5hDe/wZP8dnrGDi/0ifnQLII09xzwhEIq4D6xxb3fto0im+/Yn2x6CClI2xm/rFBQped4vbSzLLnEZ1Y+s6YLX0DKAMvWOG02SSzr3RXdy5ib+SqrhMkr+GsCxACMlXrSXKlRgljgQID1PjOMZ42p4qhtJOf9B3QYk5PSlULfxGwrrQ== 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=zgZCoOnHZATsQYnzsBa1FDCDXWeL2/cS6zDFGCgSotQ=; b=N5j9tHCKA50Ad04Y9Adi2xhrqEUF1wqUR92i0iPV6JGbNOyYQ5/seLbdooedIGdMI8B4S+OCpp95odCht11976K4gmCno8RcQfXYIrCMBED5rc0s2Dxv0EPDk/f+JinX7Za7bi0Kp5I1qnFw6QK30hI2NAlktFPXVGG+vdJFKXU1ZXZTzpcPdt4QOFQQOaG9lqq5OiQ8/OKyD+BtrMLQYgVfrgsGASC0aXUn/S1pzN93CfJev3/9MAiuc/M/rprcc3P6PNmkjq9asuay21Q4CrMOG2E0sAQ2zMY/tZAQZCcUbqtZJh94fMIkGBnF/pPt0dzvXEjDL5gP3wKxBuFJmA== 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=zgZCoOnHZATsQYnzsBa1FDCDXWeL2/cS6zDFGCgSotQ=; b=B6vUffjbslsg47SPHr4kahdU0JHfhGcvfCsRa1VEeALlIX7Q0qZaQVHXOJ13bjUHcH0jOJ1Wve/mBOIKTAn6tnif76PNj9x/xXxZIn7Oag8b8YOT+x11eSmnd9vDRW9XczzykAS2qECQAkyHhxUe01l5TmFPvL+TvjR6BKu4CvU= Received: from BN9PR03CA0853.namprd03.prod.outlook.com (2603:10b6:408:13d::18) by CH3PR12MB7596.namprd12.prod.outlook.com (2603:10b6:610:14b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30; Tue, 28 May 2024 04:19:41 +0000 Received: from BN2PEPF0000449E.namprd02.prod.outlook.com (2603:10b6:408:13d:cafe::2d) by BN9PR03CA0853.outlook.office365.com (2603:10b6:408:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.28 via Frontend Transport; Tue, 28 May 2024 04:19:41 +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 BN2PEPF0000449E.mail.protection.outlook.com (10.167.243.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Tue, 28 May 2024 04:19:41 +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; Mon, 27 May 2024 23:19:38 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v3 1/5] x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept Date: Tue, 28 May 2024 04:19:22 +0000 Message-ID: <20240528041926.3989-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528041926.3989-1-manali.shukla@amd.com> References: <20240528041926.3989-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: 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: BN2PEPF0000449E:EE_|CH3PR12MB7596:EE_ X-MS-Office365-Filtering-Correlation-Id: 230df140-dda7-4a68-f462-08dc7ecd6599 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?q?8flugDLgXNVjhtW87dQxpV9eY1JG7Sj?= =?utf-8?q?jLe+9hJ2YjCV7NUXClhh1V1Ar2DLZ9OW1FIYpXAYow5ax/+/44nrEVhbaluLbxf+D?= =?utf-8?q?toA6uWiJHhnDZim7/T+Ydj6ASWAJc5xb5xBqzbtVyxPO8hLcTM8y84mNDQ4h7qZqI?= =?utf-8?q?woPaWEhqNaF5XLpTqaeNijHqC1Ahr+4g1d0XA7JXEwbWKuCvxA6i0ElGlFBX2WSwB?= =?utf-8?q?AxjxC5N//6Nnqx/rolZAJx+RlDJL85qsfnA/P3iVU56q8FvKb1lUTlofk3kvE1Ewn?= =?utf-8?q?iIMg6cA29vLQgk96OoVktFFiMtGAUcrjgaGMCeiTOjfvHU8HUEmLYWeremVA9njM/?= =?utf-8?q?daTAH74pDgLyTAOyX+D7zr6k5HJEwiGhSu05lpuGHPq1QsaqJ6EOumO5jpQ3JoTVv?= =?utf-8?q?XsUBhN/E/1nkHu+k5by3eLEjuh5YYZ4reHJ/DxeQh9Cs9FYJmeK+o8eeC8ftrsIZx?= =?utf-8?q?HWYtHpMIgWQd8ub0YRwvq96NhNVmiFvRw2D7eXvIJRRGnjZY2wwRw2+8ay9YZ6tj7?= =?utf-8?q?NnX3AGZQg9VaV4ZolU/ChuwR6vBT9XnGnLwxDaXSDCqjqUvUranFwMcnOfOHV4bIg?= =?utf-8?q?1DJ94XxwC8A+BamqXncXNdOX+erK0q0GcK/YB6eQg0SHS1gbQ7DRQG4qMJhgYQf4c?= =?utf-8?q?tg85HRLsLzc+APqbBgTrpBsPjDFn/FPQt3oYePQ4lHtVknt/+1FxT+z5CydXWRL1x?= =?utf-8?q?azyar/H3X/8VY77G4wenzxAiTzuTuzy//ZQvQHFXyS8CAg95xYPtDnXrhZ2dTcDkW?= =?utf-8?q?+Y9/r/2c1AP/UVp3kkmUc0SH3fng88N33dF31OT5Tr4Chl5EkPpj39VqrZLHVfV43?= =?utf-8?q?KhZ05B9piKEdEiTa4O/q3KGF1ZeZSMW82luOnhziomHq7JZesTFfS+fwT2UZOGfuS?= =?utf-8?q?XEhUtAsrBf6h8tAVMWH97DOzXFrFGM8H7CcJWrf+OtBI0YNcQTFwKowtJ1V2fW0sU?= =?utf-8?q?VYQEW/PJwv3I4DqgkNAJesD14VF3BpEm3rbYSm4AREXOtCEbv/Pgs724j1lSTmZd9?= =?utf-8?q?rvxTje3Iqk2Qv7SUxFIsqNTkRAYa7HsmsIOVjTfZ1Jt8+2t7G4V0+39w/m+TJzqV5?= =?utf-8?q?iSi98xupFmGa2AzmNgqpHFpodnAT9ChDUmvKeUGqF20PinV3LJZN4IdX6l49nrpUt?= =?utf-8?q?My6H8I+GC4xtSgpxYIygRDzwP7PERIIgktOjTikP78ibr/f9em3HQ4pvR3cLc3o4K?= =?utf-8?q?88H/8szLvAwrQnMWijKb805mPBuE0rHLb8j/wTo0MGvmLEPjaVZmv+dBpchRcD/wl?= =?utf-8?q?rHggWJySVKlAtb7sIAUWGXYXUcOsoT6wZNegL6MCKH41XEhCTSitgsy89h1gX7Gm6?= =?utf-8?q?uSK+vY8XNW7S?= 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)(376005)(1800799015)(82310400017)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2024 04:19:41.7282 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 230df140-dda7-4a68-f462-08dc7ecd6599 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: BN2PEPF0000449E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7596 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 Acked-by: Borislav Petkov (AMD) --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) base-commit: d91a9cc16417b8247213a0144a1f0fd61dc855dd 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 Tue May 28 04:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13676093 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2066.outbound.protection.outlook.com [40.107.93.66]) (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 EE7022110E; Tue, 28 May 2024 04:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869989; cv=fail; b=MOjJWtluIMpvkkIRU/J1eAXIei3oF3mQDP74BIGYC6eqR0WxL229HB/ul53h2tr0DWxYtFGx1owtTl9ozVdBvhfBK36SsusE4cpcP+LnkbokXRMD/B9P/pSBdc6HnBJZbh1mCS1n7im2Wg2QrqbXQeTF2JhCEGtoX8GdMxNqs2U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869989; c=relaxed/simple; bh=+PpE7OSbqgD4TJj17DhUIBYvXAfbrt+REe4apd+vuws=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JCLw074xxrl4VMKHEFSy2DmipQ6HKepX2lAc5Dz+12RHfQi/llz5XpxyNfuOa6DtpTXwW/IBApNqajHZQ1Sn9eNXLt23X6EACsKrdKMnOXDGx2kq1cU51/gAxbjBeDwa6PhRyUlyxdjK+dnGzqzTkKsoCx5DIHdgs1CmFb7VXa8= 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=WCWD8goe; arc=fail smtp.client-ip=40.107.93.66 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="WCWD8goe" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B0JWeYQ9hGwt0Nv6V1UzWlwlgdL4zZmAbcABOkHIb/dsmUj6I/giadV2u5R2PU0wu5kzv15Ff5P77to5J4OT8lMnlUfo5Ye6mh9qHDmO/Us8Y5i4EDrsnQ/nAVYW7hKGoNdh/poaFRC+m19EwL+g/K8BM76CAH3OfpSjv2ZnccRC579wIsRRM2QwngTY3IJ+tMnUMoeavHj21+h7fvPMtxzrn9jA6/8gLTUicgks3UxSyBmzawP6FlrKAXtJQmu/zWYyVhrE2XgcE/YTmpFG7FLYYIIR6UYRyKmbqcB4tA8C02dKAsugyIPDE++e3jLZRIRZEhnjc63AkVCvhZvHmg== 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=17TNL9Ff3CSKZT4WSNqacUZhz8FMFtpKFHhMjc77pXo=; b=GfyILJbsSxU3Mfx8W8qb1cRFTVIZC6DS8fug2eSV2j6FpSHB6Jd3r2DnBJIZ5ZbPesAB8RTIESgTnsjOauQL5x2xBZXefp1AOBQGrBMminIzSAc8datg2fctco5H8bWY9rEJaOzs4xaVn7JjAFc+Bt1JmXdjvui7cI5BKeZ5pRS26aK9vzaxWpTbIEf4NBuJuAJOIaWRgD9hlcmO8s2JImDPvZjPIEBu0IKn6jEA1+JArF8AK4XKoIbSXbnCoMnKS8jSJ3ZDJMuHu3spb3dyhRjBFREbRw6kK4nq9mwdtwMZpNJY3umQs8chwl7ejJWJJLBEVmJ//Es8fMFApdOHRg== 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=17TNL9Ff3CSKZT4WSNqacUZhz8FMFtpKFHhMjc77pXo=; b=WCWD8goeqJRPV+Mt36qT75Ei+XBYgqItwnm9kIwIEbeugKo4OjqhUYA/UMezKUShFFMz1OcYNBInUim36VkU3BgltCNxl5S1MW4+5TYd7US19GAEJ1DVZ9o9KZoJYkFobI8WxkVvoiphZWzfwl7chblQo/58SvRgmg3/PV02MzM= Received: from BN9P223CA0019.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::24) by CH3PR12MB9021.namprd12.prod.outlook.com (2603:10b6:610:173::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Tue, 28 May 2024 04:19:42 +0000 Received: from BN2PEPF0000449D.namprd02.prod.outlook.com (2603:10b6:408:10b:cafe::9f) by BN9P223CA0019.outlook.office365.com (2603:10b6:408:10b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29 via Frontend Transport; Tue, 28 May 2024 04:19:42 +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 BN2PEPF0000449D.mail.protection.outlook.com (10.167.243.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Tue, 28 May 2024 04:19:42 +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; Mon, 27 May 2024 23:19:40 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v3 2/5] KVM: SVM: Add Idle HLT intercept support Date: Tue, 28 May 2024 04:19:23 +0000 Message-ID: <20240528041926.3989-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528041926.3989-1-manali.shukla@amd.com> References: <20240528041926.3989-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: 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: BN2PEPF0000449D:EE_|CH3PR12MB9021:EE_ X-MS-Office365-Filtering-Correlation-Id: 97216f8b-8a15-4bf4-1114-08dc7ecd65ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: Wk0BCMZzGYUqIQ/PNpP732DuVWaeh824GNRLMVoPYtJF7YCwOCL3O3tUn6ufqqrRUyE1jAmWauJKOhy5WnWGrmALYGBQl55ylSrhfBAOVpltNCLWiz/Lm/1xqGLLKrmu8yYlcBJ+6qjR8UX+vr+uLQ6dRKtK9XUdD1u2Hf3c9JKOwOysQZcLZs5Et30hxypeM1jTVQptTKOc1v0E/INWUqHxONuF2p+y3m9HeOCvpNCjMlaeRq5ELTvzSNnu8M6XJ8Z5doJHMt//+KdGeTkqvZlp7cbUH0PLEAI/O0PUZqHW0Kct3wwju1ANTu2XnLB9O/92bu4uKrpbJ7C7I2g5EexCCHHO4HkIQDphCS7naELFAXQxYVNdPsMO2JWIvnHL+yNd7mPVa/08FA+cHaJYceLoo4Hgf0gLqIuwRWdGYjbh+lxuFUtBcXAncDEBncIXI3Yq37Di+NaqSA0jn3ILXc7iZotk+KXQ5Cv12F5R/GEzcMG2YUpHKk/BWZ0qlYHzviOe9KaMOw4yJ7mrtxwGRDiWuN1jjhEGJbXxOFRl67sfF1RdUtBEHQUSxtszT/3E8Ke5B8WutGMZmA53xQO4g4sSaQmk9HHkSqvI6gmJ1mwzAZwKTUdKydjMyUQm3pbvrb+Griy+dV0P7zKq4/FRk4h1MDJlbLV8vyPW1W0eOxZA36SQjc4TWbC2AP0CzxmnSzxbq12tTMdlkwuPCBflhSz3XU/0+uqM8aWc/bn8RdcrYTeNWD0xxfbrh/aGBNVk3mIpLwcfSO4hLri70FljMzwOtnD0U8PlcyB/U7R3jkqT09FBljADly0NG+bTkm5jD0zKlAM56zJhTK8Kc894Reg0dQ1eSpRUFrFEiBOF1wty4JoTCWdEkBUTNs7/TnwXQ8/RauRb19bKi2a9kXHjg3biClM1jGBaKxfKjKX/VGyMe3q60uuHxTPj7HMU73pjkZLpKIseEsakRU4AirFiNmvemlw/iYl/wnAm0vRhZls1o/g2Bm5yofH/URQx48e/Ufbi5rj9i56sjA+gpor07GbWjditqdsyg/vC19pGnv/xixNEHyRVsfIJEphgdNYu4ODbXxUjButPJjZRAnMvdEj006oi0f2axmKXvAwCzh74tsT4qlWfVLRDf0bW4p5qSRvsCPb/4RvcWp9tf1LAj998AT4Jw2opTR2rAe1q4/F96TCyjSblu0xRxUW6SPGlfiWL2g4I/b12fs0MwiSCup0oK/iwYzCP90B/QD1krJsVKsE5bYYJ3SHauRnlKBwS63t5OyWaI0O5Xl7gQgPiOBs1Mk1PfJHNJfreD9IHpAyNDXrepYR/t+RKJ0Ylz7Wk 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)(82310400017)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2024 04:19:42.2533 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 97216f8b-8a15-4bf4-1114-08dc7ecd65ea 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: BN2PEPF0000449D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9021 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_INTR and V_NMI). The feature allows the hypervisor to determine whether vCPU is idle and reduces wasteful VMEXITs. 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 | 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 Tue May 28 04:19:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13676091 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.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 6B7F81BC40; Tue, 28 May 2024 04:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869987; cv=fail; b=gpQ6T/kdPWvP39sOcA0g6hCzLSRDGYCPgU81sU0iu88U1lP5vZyYk0IBkIWPNNKVgov+7pGLWqy5/6Jav2TRlx2QsyCWFMBaEVXHW4VaEzrc/8+MJ8P4etGZS1IZqWAv0nZ2eXFY3HsKatuqdgQIbt9KQ6GQWxQ/rxlg1r24TPI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869987; 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=U2T8/FX7mZ+I6vdOW9Hq7gtZuEI4AHh1aYe9LkC/DZ3C5wpGOEyCXnVu0+YiXbxkLpD28fUTicnUYgJJFI9sa0aA52AhiFS890jTWCijQwqS8B4SggF3PQYd3Bqi05MIBvmWbFnMj6XJ+x0r6/AlcFJI2KfXZJNBXA9iNDnPp3U= 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=4TDxtQzX; arc=fail smtp.client-ip=40.107.220.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="4TDxtQzX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j0oyM/2qaSV57iNZltFGDhrRbQlagwiVq9aSomTN3rpEDAkXRRChOY2gV/o+1ZB8CEJH4LTf/jCOZSczmjDyVdoss/i4gSseMVF8XJSx/cWJzD2YGVzg3Gq2aiyV6zmTe4lvgC+RRuz7spysLv0D7uqNLSdVU76t4yp6LZPW43T2HxEiHNPJv1mL/0KN9u124c+Xe4agkGyYLApYY/+793xTKmlG0rktoNZY8zY8J9AGjzHpqRdp3/zjq3m8VZ+8nIXOMBgzrm683al1fzJ1au0Uzgieqvx9NBvUIV0C05qHg+WT0fNqgZlMs0jwCraj1dDIBUG1HyNr6xSXQ/q6Lw== 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=euHXIrKHa7tAD4evkGWhOB3KG9DorWeyXgbwZyN9g+t9bJrYuwMzLlWEHrLsjMzmPAkoFzE0OQFp9UrEpSo0ZCCQmhZhT7sv5nPeZ7d7bAYnHSxCNvU+R4ivt859flhxqFdMWJvvkvPmZH6+e+y4hiDvfervHodkZmCddDTpmVK9/pXDXZIrAB1sSZEn2z+Yt65X1ObsBS1F17auS3haK0wPRk37c/7h58NISQgEWYaMYJ5rZgDOI7IonYskfKlcez00jWy/UiX353Fe2hHpm/06zaP17yChwCCwS5+P81TeTcIvNKE5bBx19ltNGRQhocbIJS8Z6z4SrsHye4SiYw== 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=4TDxtQzXYpHfvv4fu1odjYeMEuB2sayyjwivhXXzbguh9QzjlSrVPWKTZ4plzMMi9Tm3RP/1+stjrtdooKN7MTcmkVAV4nL6ffClHsbtpyk+KIJZl5wJF539VXxvAVNgeRQHGdHj5jgW7vEfg38n5acuI0/HWleN9ztJ3RtcDpA= Received: from BN9PR03CA0845.namprd03.prod.outlook.com (2603:10b6:408:13d::10) by IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Tue, 28 May 2024 04:19:42 +0000 Received: from BN2PEPF0000449E.namprd02.prod.outlook.com (2603:10b6:408:13d:cafe::6f) by BN9PR03CA0845.outlook.office365.com (2603:10b6:408:13d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29 via Frontend Transport; Tue, 28 May 2024 04:19:42 +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 BN2PEPF0000449E.mail.protection.outlook.com (10.167.243.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Tue, 28 May 2024 04:19:42 +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; Mon, 27 May 2024 23:19:41 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v3 3/5] KVM: selftests: Add safe_halt() and cli() helpers to common code Date: Tue, 28 May 2024 04:19:24 +0000 Message-ID: <20240528041926.3989-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528041926.3989-1-manali.shukla@amd.com> References: <20240528041926.3989-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: 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: BN2PEPF0000449E:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 39d2f06d-2bb4-4495-b356-08dc7ecd661a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|376005|36860700004; X-Microsoft-Antispam-Message-Info: 1Jpj1rC/0YHPEFqcWaMsrBH089N5yumm1HNlDhxj5krliFp2877OcbpQyrj1XeyL/aFlucg+mnAdJm+X6a2NFYCb+LtDakrkgODBo7sAayWh2Zx11FUAKjntHBVPCiNW6MVVvuVY5EBrjxPBJUiumzEswg/u9WpsZ9MF+qwpbAn3Q9BPfVidIV/uelwJnIXe7voKqPOcTKxDxuGyClskQxseaKCjzXRfjCl9sRn25/VC3TCp+mbrVnfOpzLmcwtEWtWXwCzQMA2u/DXhq6dwIY4QourLD0uKTamwqwUjJNRkkITR2HZon3OdT5MkdgCrEgW49MLzwltgzQUAG2iUQXUPk8lIu9qTM3nF0Lsm1h0TR0AtWInSJrd3wliwim0aAyRLpAbKstUrhIko4Sh2po1zyXYttZHuYfupzGzybzy1F7v/CsDz83tDBZqnf2bpUeW6a7wTMP0ypwhEwJWUpafAH1PzW16qPIEE+HRKqjljJev8HbJWxuj7rli+7razSG6A7NuueZ4n7vmHgF7bAlAV1GRIuEwu00Cv71uql+MpxxeZRiptjylNxmAQALVRD+4WRPbv45PhfNRExYGKIjoW1C876DWqvrQ8jFMo6fHHjiLQEaHg4ls3qQe3RgcgoflcJMQPvrjyuza6HfotNtS3fMZ9nGck5fMSpUnmcgrkTZDeN7sDAGw8WTYcAgViQ5RFFKTIK8nsGSECELTnN/Wnd1/NEjeHY1V51lfyQKhXIFupQE9MkuAfsHGXxj0/5Di/XfeEhOuG30B+JE94GIIIT9YFvDHUTD6/l2lla8qXYvTARLRMxnKhqw7KmjByVm2z/wFI3PmY1U00czdQ54IC/+qMRAWyHZXc+UzASWY4zCR5YHig6vtd/u/GrRJwY6BT30nQ+kXmoWRz9UU2EKdrk8oVmMvshEBQTidQxM+W7UvNvcbygJQ7zW0PbKld6sc0jw8WLMUV7awk4+Z0PStKiWQASb/OCjxUAre6I8tx2PV69p/rh11uUBHYglA96yJF6ftsOZ+enWZm2dgr0PxYH8SK3V+JxSPeM7/BhajS6mAV5oflclHPYK5ORAfpslz12lqU4BPJTqQL366/mrr9j7v1P+FiL2waXrDhJLNng5LQjFYkwb5ZLR/0JKyeEgGDPbu5v5h8kX3j69kbvZppu9koH2CKGJZKwWbwV+5trzZQSfQFQcE4zPa94XnxZncCtWU3a3CSZo2LbZCy8X+JmFRthFuyyuxqa3ZWlgjc2HFlRP3jlB//0Q3OZjLB7zNGmAzqfzZ6pK4xk+rOAPhOl2Cjl3SjVRK777DwYTBQ6VLLoiEmV3aS27AtsMZl6nUeEAg6RWAOltDMdsh0Mug9tzr8pZu79c27HLACDaPLJ4TbOmzwW26ZmQHjZCts 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)(82310400017)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2024 04:19:42.5720 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39d2f06d-2bb4-4495-b356-08dc7ecd661a 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: BN2PEPF0000449E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 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 Tue May 28 04:19:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13676090 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2063.outbound.protection.outlook.com [40.107.244.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 0020F199B9; Tue, 28 May 2024 04:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869987; cv=fail; b=IKt1v2wktjRkv+1Rmxx1Tt+mrD4yovFJZcQVsNbaFN/heYsZN9PfMHDvUc6SPkWIWBifEHTh7v4etl6tIZ+mjFNARXPB0K2OjmEw+Y6g3B4Gzn4MILIS9aHaxmJwwE91K560nk7SJnyqDhhfk02C6BU7S4HMIVFS6g6KaeGQWs4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869987; c=relaxed/simple; bh=vdWv85wKkf5qMxZI2VPjUaqBY/Rnfh+MkH1wqv6bfyE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZBcQQQokzNM82cO+Fs3DfOVq6vJwm/6YXz4ievfd3DxD1uEfMQ8ObhKzVwdWOjmPsupoEMuTNUdmlNuSrhQm5EFNh4x4D73zLAL7dQcj/OW+D7kwI9/X3V6ucvX1EqXQGi1nzUpaommAdXiS8qL4UfeR0OJ0jjnLdDDleZqs5Ig= 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=YU2KtLMl; arc=fail smtp.client-ip=40.107.244.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="YU2KtLMl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AxzWLLiw5e2PAee6z5DgIGJHmGfC1fhlPKNn9fxtW933HINFyUsvO28LdyBRWohRcC7jcY6GURi2JrJcfR9IOgNOIYDXQMW2QwSqAlY9fLwcx3zVtHrknHJZILXXQoIkEzAJgQr+jq688JKopVC8wWgyq41Uua0c/yeARlicaGz6/Gd+s24THsPdeoib7z9dpleTkaokRnodIW4fUtN/QAwd2IRahCSYHkHfM6xnQFgg8DKxVPOz8hmGRD4sfHknDVw9UnA85Iv6ZLj3yYbitbZdeToNONQbd7dql1tKjLfm+EoIe43OtoUMCmIts2Wbs+RBd4tvzZCcfPNTlrJySw== 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=1fRdkaASirapCelzeWYERjJ5QmVerDinpGOSsFFnlww=; b=PjdV/zeEglp2Dev8fowxM8qQxWAEx1QKrDDwOXGXWSgPmZmHwgKRXtUH2ztb+5lMn+WkK7nOjXtIc5bz/61su+EI1mK2msXukH2rhTPK01vvq1l10pDGsvl3JJnJLRUe5qpMoyjMzOYxBshfERTZ7gKPbBhomfqQCzdGggDDGJb/uyB2J66lIi3yEGtgn4NVvAcqYhVlVyBNv2NBCpcBDMAbl1fDoBT8xn6dYp+bP9ppuQqdbl/6Cs3/Fe5QIyGrjUIqQgllnmsVxwYg6S8B2S0jsvlazHOzj4P9I35fqDy4FRA1x9nu9xEsCblx3l8aU9hCFT4yAv3msbqtFIh5Tw== 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=1fRdkaASirapCelzeWYERjJ5QmVerDinpGOSsFFnlww=; b=YU2KtLMlnW3be2IujUxhJ0I2oryd/0I/2m5/+N4fy8/b98TGX9N+Oy+J7JVFbrLYy9kRLuAUfgy3Msm3hEYYEZ7HDBJ9gQ9Jz+QubGFwt5cAASUzszc93ABx2J1N28VuIOYpQ0mNBhV44nDQxk1aYMi30QHNiwct41kPHJaxCHI= Received: from BN9P223CA0008.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::13) by CH3PR12MB8972.namprd12.prod.outlook.com (2603:10b6:610:169::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19; Tue, 28 May 2024 04:19:43 +0000 Received: from BN2PEPF0000449D.namprd02.prod.outlook.com (2603:10b6:408:10b:cafe::8e) by BN9P223CA0008.outlook.office365.com (2603:10b6:408:10b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.28 via Frontend Transport; Tue, 28 May 2024 04:19:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF0000449D.mail.protection.outlook.com (10.167.243.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Tue, 28 May 2024 04:19:43 +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; Mon, 27 May 2024 23:19:42 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v3 4/5] KVM: selftests: Add an interface to read the data of named vcpu stat Date: Tue, 28 May 2024 04:19:25 +0000 Message-ID: <20240528041926.3989-5-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528041926.3989-1-manali.shukla@amd.com> References: <20240528041926.3989-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: 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: BN2PEPF0000449D:EE_|CH3PR12MB8972:EE_ X-MS-Office365-Filtering-Correlation-Id: 365663d0-da46-4e52-7f20-08dc7ecd669a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|82310400017|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: Y3QcCaMpfvMosn7Qaj0pMqVW4I1ixqveJdE4MpxoJIeVPcaLrmNIZCyP1Eul8K8VFEtZptb9k3y1pG7xYR0XVM+90DAAWVZXs8SIG3JGPScFjmuge6Jz4afbiv5zzOnbjlgDlPMhVQLBp9pedgElNTSiThR7uuulp88UVVWJxs+N8qx1Kf9VlZDGjnmzy1nXvMYrKBXpjeSGgy+VSsRnPnG4g7wiRsK8nl0YZDtd/uqCjdHUvoaewbHilH4Wa1DAwTDtNdBsQm7+RcS4mTMWqcsX2omY0mOMiVtTR4VdHEvwioPFle2yOj2Drbq7ImtqT77gJRbiOmk2vDxsilFGxTW2HKsCcP+CR7eVH7Gy8IsxRME9eLRZmMAg+Ik546kwKsWu37JskXN4etcq9eoVw1MuSx5v+BLtVCtEGU/Nyph6/nFNTFTahyOFZX+NbVN/Tugh2o+yojghYWpYxMs/F27kHxP4iRFonvlpIyXQfKSy0LZEWxgCACezZMbdKC/0wkUvfSZq9HRnr2uDgnWnjOJqVkzZeAjfDwJ3XV0Y0vrK97dPfVlPVO4mRKqFdpXGek3wo44pzw8CL1KL21V5Pyt0df+mwBCdLpFJO9hbdvMk8TFHG9QZzTX6gieOyvwQucakp6yTNYpAO3XrUBQmbNIjlmt3lecx0lziG0y8d2j6Z0yAoQEhuyeqe0A/V3xyOAjWzXM6PGfBpwVGf5J4TM7UzrMpiOYbxHSscTUad3x/Y7ukKK+KVgJRuhKkjx3bKCX4IBvGQ1Zp1gnYuzRHMR/0v6HjUSudo92HtLeCdsgZcV3oShhoWrdv9NntFV4XLd5KQR3Q+4A1n3OaUkkys7ngXQ8WtI/wg+WwbOz+1AZofKeExlaLAbc1xqKuoAm2jdYYxQIw87gX1H2BLulzk2yMot1j8O68sHwrFSjFFZ5y04XjBJAfa1aUQjGJpYqkbfzdtAtrqzLO9oQNCs5vSdrAd0BZ/L4HEo6vcI49U0rb/Egc58q2fJ4rMIVw7zbomY1ms0/msW5MWQr2YPT7Z3wQZKzBDsuQoJEOxxWzw6oc/LKIO82sRGCu0JPWnnbvoapcPLLmZHsTvl2TZ+M3nQ0HgoI8GDWF/Yzot/lxQauwN5Ex5toaQfZ6N4SZztkyu3Zgdbw/I2y29s5l/9OrgBuOdUHvVLNgZEAIceFbYfk9YUL285ykgbidbOSKYTpsNMj4x9Ay66JhxSp3FFq5/d/t6VBu0bQuPw+N9zLi0cV/0PQ9xPK8V1XUmr778dqQEf8YMS9trd02cXeElFkHYSqMtoIPB1rE9dxWz2ZfVELT6tcnz+ismHcGS5LxhqdtWvZYa7IfKD8YjdFz3oWlBYUHINysnAdEEo1FP6nK10M= 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)(376005)(82310400017)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2024 04:19:43.4095 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 365663d0-da46-4e52-7f20-08dc7ecd669a 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: BN2PEPF0000449D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8972 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 --- .../kvm/include/kvm_arch_vcpu_states.h | 49 +++++++++++++++++++ .../testing/selftests/kvm/include/kvm_util.h | 34 +++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 32 ++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h diff --git a/tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h b/tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h new file mode 100644 index 000000000000..755ff7de53d9 --- /dev/null +++ b/tools/testing/selftests/kvm/include/kvm_arch_vcpu_states.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Arch-specific stats are added to the kvm_arch_vcpu_states.h. Sequence + * of arch-specific vcpu_stat_type should be same as they are declared in + * arch-specific kvm_vcpu_stat. + */ +#ifdef __x86_64__ +#define KVM_X86_VCPU_STATE(x) KVM_VCPU_STATE(x) + +KVM_X86_VCPU_STATE(PF_TAKEN) +KVM_X86_VCPU_STATE(PF_FIXED) +KVM_X86_VCPU_STATE(PF_EMULATE) +KVM_X86_VCPU_STATE(PF_SPURIOUS) +KVM_X86_VCPU_STATE(PF_FAST) +KVM_X86_VCPU_STATE(PF_MMIO_SPTE_CREATED) +KVM_X86_VCPU_STATE(PF_GUEST) +KVM_X86_VCPU_STATE(TLB_FLUSH) +KVM_X86_VCPU_STATE(INVLPG) +KVM_X86_VCPU_STATE(EXITS) +KVM_X86_VCPU_STATE(IO_EXITS) +KVM_X86_VCPU_STATE(MMIO_EXITS) +KVM_X86_VCPU_STATE(SIGNAL_EXITS) +KVM_X86_VCPU_STATE(IRQ_WINDOW_EXITS) +KVM_X86_VCPU_STATE(NMI_WINDOW_EXITS) +KVM_X86_VCPU_STATE(LD_FLUSH) +KVM_X86_VCPU_STATE(HALT_EXITS) +KVM_X86_VCPU_STATE(REQUEST_IRQ_EXITS) +KVM_X86_VCPU_STATE(IRQ_EXITS) +KVM_X86_VCPU_STATE(HOST_STATE_RELOAD) +KVM_X86_VCPU_STATE(FPU_RELOAD) +KVM_X86_VCPU_STATE(INSN_EMULATION) +KVM_X86_VCPU_STATE(INSN_EMULATION_FAIL) +KVM_X86_VCPU_STATE(HYPERCALLS) +KVM_X86_VCPU_STATE(IRQ_INJECTIONS) +KVM_X86_VCPU_STATE(NMI_INJECTIONS) +KVM_X86_VCPU_STATE(REQ_EVENT) +KVM_X86_VCPU_STATE(NESTED_RUN) +KVM_X86_VCPU_STATE(DIRECTED_YIELD_ATTEMPTED) +KVM_X86_VCPU_STATE(DIRECTED_YIELD_SUCCESSFUL) +KVM_X86_VCPU_STATE(PREEMPTION_REPORTED) +KVM_X86_VCPU_STATE(PREEMPTION_OTHER) +KVM_X86_VCPU_STATE(GUEST_MODE) +KVM_X86_VCPU_STATE(NOTIFY_WINDOW_EXITS) + +#undef KVM_X86_VCPU_STATE +#undef KVM_VCPU_STATE +#endif + diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 63c2aaae51f3..fe66b1736060 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -518,6 +518,40 @@ 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, +#define KVM_VCPU_STATE(x) x, +#include "kvm_arch_vcpu_states.h" +}; + +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 ad00e4761886..d4b6a352c1ae 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2264,6 +2264,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 Tue May 28 04:19:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13676092 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) (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 78BA11D551; Tue, 28 May 2024 04:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869989; cv=fail; b=CDuZcw3HIqM0Y2rqDUHt6iuEOOhzzZG4cnQVqHha9IptNO93AECTIvR7lKjj70gnQSQHSLgXzapY9399woS6eVp41GOuYkiTQlAzAeYsBA7YV+u+JWYKtKnn9aa+66AVWQQapbZhlqLFNBptFUSIQAecp+j8LCJ0JOV+GsYv5dE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716869989; c=relaxed/simple; bh=TjAb69OVRcVxE+ATZRBVvDKSBq0XOqz4+21X4RPthus=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ugMePkheesjIbiIrwxrDqxvCLbaIjVx+LTuZAzTvEzzX+9/4a5XcdwD+pzuCgeXmnvywhXLTSu+ABNvrZ1JU0i5+3FYEYKI4KfLqcIOEiGFGKgWPc2aC2A0fq3gAcpMDui5zd/FFKawI2Glwr6215JAvtuAXisw5HL9j29dyYk8= 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=NcrzoNF6; arc=fail smtp.client-ip=40.107.220.72 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="NcrzoNF6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NVYzevsdFEZyN9BYT6HrPNe4UkqvP5j7b+ueHLq49bWT6OY4aimpmhKnmADKLKa+LD3bSgaBuZUaRNHqo8Z7S/tDN1m1D0tqSQxuheWubn7oDy7COZ+9HKe7tLoFU0BrGLYj3PGWvTgHWJhcHXexq6O6vPUMy087j6elO8/0Z0FzYXAxe/W6OjPoHHKDjP6+PxW7Kw0czfsSCzwZDA5mX4fp1vczfF9q1Qqjg5E9X+ll51f90dnx08/0JbpRltw+Ce8tcnk6pV1OFjyZw6IemtBLvKIffibOVwE5LhaIpst3dxB27j0LfiEftlqSvdIOefmRzNs81VqimXpofFMgKQ== 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=hqoG/1nk14upxLbURXPVTSfXZdYpcmH/F48wOXn07VWihlXZifTjELVkhylS3NKGvs4bQQ8bAgw/CVNBe6dIbxrCkFN00gH/6UAI77Vjx9X5hDdbenBDlq4ua+zC8gqJvFyywcDjOW1M54P5kJ6v9bUFPIVsc1diuuHWxRkfuVauHNDzIF77XtTt61fHP0kihC6uHTItRH/cBvOkFGRnPxLElwqGM7dPuek0jtBujGtBNLG4z7hrHLfIqElKvOJ5rUd68skOlad4n0FJYxP7fC8QUWOaRRhpbQ0pHUYPIlwz3YuW3pk/YI8aQnlHdo6/daq6MmHrLwdSII9z7inGDw== 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=NcrzoNF649BLrc5F8BmDydvlzXVEPz9EsoGcG2TbRB4yEYiDi40r7T9KMXZLMt+5orjBIntIbBBscwlEfmlfaLKMt80YkArAH9ffVspOAkoxeGuAZ2bnLGw3NVvRyaTjuNc/jdPj0itnbg5ckRSlGa9kmRTQFJoZHp4g8nQry6Y= Received: from BN9P223CA0028.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::33) by PH7PR12MB7937.namprd12.prod.outlook.com (2603:10b6:510:270::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30; Tue, 28 May 2024 04:19:45 +0000 Received: from BN2PEPF0000449D.namprd02.prod.outlook.com (2603:10b6:408:10b:cafe::56) by BN9P223CA0028.outlook.office365.com (2603:10b6:408:10b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29 via Frontend Transport; Tue, 28 May 2024 04:19:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF0000449D.mail.protection.outlook.com (10.167.243.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Tue, 28 May 2024 04:19:44 +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; Mon, 27 May 2024 23:19:43 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v3 5/5] KVM: selftests: KVM: SVM: Add Idle HLT intercept test Date: Tue, 28 May 2024 04:19:26 +0000 Message-ID: <20240528041926.3989-6-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528041926.3989-1-manali.shukla@amd.com> References: <20240528041926.3989-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: 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: BN2PEPF0000449D:EE_|PH7PR12MB7937:EE_ X-MS-Office365-Filtering-Correlation-Id: e5129e38-61db-4cfe-ffe3-08dc7ecd675d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: wflSQkQcCkLiGooUIzSFpyP3YyzfhFUD5QwhqYq5OB308OhGMdiuXrckrb8SviPHTXShgNGTioWxqi43n4NbGmAZJ1uX/SVmgUH07Nqb6W8y4ZhppTd/u4iop7scKPwgJqMz+vevzYV+5PZPn7h/r3KNF5uDEd8sZdM+dvTg0unUmgmDoy6S9Ti3wO8DW1No/leSitzxHKCg45sPX5sJT74z0HRHtvzEQb5vuAJBh8aB1A8/T+2Xxvb9P1cVrEy2RynChr0vHmIiSVfmcmEriU6Gyol6wAM7fRXaWO5sqOT3YAh9N/NI4ckKVxC4P0W1Rv4FYG/oARW8x6hg+zCg1Zrx+FXkX2vFMNalKCWxoAXAbw7IRc3Nxot2t1mUIfopXT3ipZV/xEla5om7z1Kg2zk5YVCskOz3nrB6UJq5udleyFKD+LZkCzMQpFPiauSacX1xPUfQ/ILwheYZqoW2CReFrBxbV7gaVoI5WMYt/k5p+/4f6gR/Nfo57MpVuyQ5xGZh9FxEb6LRSfOH8eXTjS3jN9xUi+pQqm8r76InLehqZrnY0DPO/VTE6gKWIyWqbFjIaRKkMIpFKv8MLr/ayxcJaYzPQ0IWZuxcL4C20UVAS/bi2ltiJ8ePNNVDAD7u25Ru0Rmu1gP8xiLSCTXfgnEkIabj/NYysmLdmk87UjWRSoemJrnjzFIAIb4lz+vHe7EJLSWhTzVQPA22MnGkKepCXgtFfcDfQuzbLabxkyB+MhH8oyUS83kjq42y0eYfT3e5uHU03ITdyC3270OFbU98t7L/S9Vtd6iKYZ2yyK4/LFfVivTT2BfhgOnk+ZqU3Cd/sZwgdgPILWDdwHGe47LHs9kXrO4/VpGf0QyJbGxTt6vEbU8RRakz8kIGqgm2myw/3ohm0ZZZDERaoBTlhxOahMw3nkKNnLxdX78SwBUa9znPq5fEfcaE7zskbHnsTdbLgRAHFsqQyxfIAkCGibCUmeqRLppfTTqFWds9cZKCuqbQJ2OZH9DFWSdoVEMZE4fkXXajQ0e4WiredlGsOtB2P7AsIR3K0OBx9DSp0xpBX09ejI4x/o4DEtlzymR4UGACYFTQLdMpZSR12TU+Z4a/0NfZhnzmf8ezq1foxoHExYeAJZ1uLjapLMS5DQKUqaNbyxVt9y3+g0Dwp+Zy9zjqyox0mXbeSo7Y0EPmpDM03rSiEri6DsxOM3D5p69u+8IiNQtoYwFLS0QdNaTMybtWELuhgk1QjHbo8DsncnpYwE6PgH3aIjhFS+tAFTyvP5BHrbdXevB0/FZp1j3Q2zXAZeRvZ8AJSuLQjCzvjlCAHPRVBXfayDkgI8zVDgxMF3LPXyuCJjPmBJ4Jlv88bC4uLB2WHXBJvhDLaLI0aT8= 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)(82310400017)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2024 04:19:44.6908 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5129e38-61db-4cfe-ffe3-08dc7ecd675d 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: BN2PEPF0000449D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7937 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; +}