From patchwork Tue Oct 22 05:48:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13845133 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2055.outbound.protection.outlook.com [40.107.243.55]) (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 062A81E529; Tue, 22 Oct 2024 05:48:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729576111; cv=fail; b=fWP6/NwbCWEJW5D9GQv9mjad0Zfcr5RlI0ejzVAEZzKYnH9xhMvxzO8GiUv+tHg7uBPD8ggqY6rwKsCGH0mwiTjglTimIg03UAHFFW8TMFNIYUFUElZn9kHsO9Re6dOpxHVIr2gGT8aGCNVRnY/z2M46nAB5Wbh0o6Jny/lvds0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729576111; c=relaxed/simple; bh=sc6HM7Xlox17can0MY/QOMfBcJW/6In6No0oos46pmE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cgVi+zEptCHCcX38/4i2+KkHLmZhD/BYfnLmC1R3KWigAFb06+KR8WAvvs/GvCJEl8m86g26CVK1TSpVKEc0OcOfhhdWYYyDZ9hOEMMBN/G94VGs040E00W9XJyeH1LiIEucWuFzMqB4DCw151ziMZwKE3dvzBPbbTL7FUY/VsQ= 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=ADXhBBmV; arc=fail smtp.client-ip=40.107.243.55 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="ADXhBBmV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A4+qbAFjxA63QtUISuBYT+CJBysaEYYPKpAfZbAmkfge8nNa7acQXfbj47eMiO9RWZKLNj4FK8R7LhfeZROf0oAynfJdam0v5IC/4ngqjkfTWdgqZiDMdNMNmX6VV/MkjpWpTkBzaHNhPvjmMn4gSG0h6XuHZaU3x1ew6oRkiUllTY/MqrBM9IauYXgngQdswIvZaFbhlcCD7RaazAWkJ9iyit8/YlySFJSqnuOp2hUbAaOM3OsKbaRL7Yk7ehRhxSF8c6NNYBUOfdV9BqoxpMBvXq8YfFhafepUk0HaoR4lfB9m5gVetvmetuRh2TSd8Rz6OPqrc2dnylYIR1hwAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DSRCWKClXPhRoI/mrxQGcL/Rja0auo871KakVsXbAbs=; b=A5lO5bLk8zRnxdBNVhiThD8xt/gnjDiwDW0PyjzSlhc8tWVeLZbqTV0fqJ2VaZmJ9wVv8nY/Dc4AmcNNeF94AB4bLSPaL+cDnLoPe3anuKxPKDC63ZM37cqV9nFVh6CQ8vXsrW/aqblR1AorlfT2RI+pVfIFH1Z5IMqQJ9uWP0TrwieGzTyWO3y5O9g5m6tYlu65wyum8WenwIx8GXg38KKX1vMJkKoRwp06aiLVmN1mIE7aSVra+5+B97cYhfMUYG21whnk6TvzN9ECDXrdHA56qjl+CSuJd+fCsadvXTsj5aJaQs8lfShqELbA0O2QNceq0yaMn4PIURYOc9phUw== 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=DSRCWKClXPhRoI/mrxQGcL/Rja0auo871KakVsXbAbs=; b=ADXhBBmVOrRfXpm5B8NIgWYBdawWoGS3jMN6sPvoAkm2d7mdva1epOBqZWIW4qJc2P+XcP8RZix6b1eH8vfnMWSzWhJp+8gMXVvKAT4ICzdrU6660gmsOmBQ020iX5mPaeCzPssrCcttXE58W1B+oaB3jZGvV1eZ6F91AF5AePY= Received: from BYAPR04CA0029.namprd04.prod.outlook.com (2603:10b6:a03:40::42) by PH7PR12MB8780.namprd12.prod.outlook.com (2603:10b6:510:26b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 05:48:26 +0000 Received: from CO1PEPF000075ED.namprd03.prod.outlook.com (2603:10b6:a03:40:cafe::58) by BYAPR04CA0029.outlook.office365.com (2603:10b6:a03:40::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29 via Frontend Transport; Tue, 22 Oct 2024 05:48:26 +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 CO1PEPF000075ED.mail.protection.outlook.com (10.167.249.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8093.14 via Frontend Transport; Tue, 22 Oct 2024 05:48:25 +0000 Received: from chalupa-d178host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 22 Oct 2024 00:48:24 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [PATCH v4 0/4] Add support for the Idle HLT intercept feature Date: Tue, 22 Oct 2024 05:48:06 +0000 Message-ID: <20241022054810.23369-1-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075ED:EE_|PH7PR12MB8780:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ca4d8ee-87b7-478f-144c-08dcf25d25d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?5s4ySreEnhasaHl+07dLwpdSotfD7AR?= =?utf-8?q?r6xxEpzrAN1sHQ4nrzTTaiOo+IoN8p5iufir0zINyMtZJtpQ7YiNPs6z/w22yqB6n?= =?utf-8?q?2dw2YL/gdE6SqrPGkpqpb+u31wrNnnZARHnWiyYZiy4gKRZ9GeJpQSa5x80W/oRo/?= =?utf-8?q?woE5fki+OOZ1K8s5gkdzfxRzSgqE/nNZnM0sTCzyFmuraGbPtMevD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kdeIxrowTr6ns13jmAe5KE+D?= =?utf-8?q?zwyorcV6uLd4oLtNYT7avPJrHpHr+XAYejbKBE6FoonkqwsnB85ubFEIjPlVQSUAh?= =?utf-8?q?T29/5Xk/lwdZi+JmghCOqPK++dptkn6+Cqe6oSA0J4jyCQFBy1BF6IZOe2sgxxAMJ?= =?utf-8?q?H3KQd2XWaH6LY77xRQdZ4uS28jnsM+lbiAcNQBgzgMpqq0jrjEj5B0RcuPZYLJPCu?= =?utf-8?q?LgxxT83Rjq3SfiNxYJrC80rsfSoEZ+NsbkG/PijeEUnewv5QnXZGJKIgL8pNZ9kyK?= =?utf-8?q?ALHa05c2OVQ6rT1MZMwFWpjZRTOu2dkBjYoauJioJniCI5aqsLzCm7Q=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 05:48:25.8716 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ca4d8ee-87b7-478f-144c-08dcf25d25d6 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: CO1PEPF000075ED.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8780 The upcoming new 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 V_INTR and V_NMI events for the vCPU. When the vCPU is expected to service the pending V_INTR and V_NMI events, the Idle HLT intercept won’t trigger. The feature allows the hypervisor to determine if the vCPU is actually idle and reduces wasteful VMEXITs. The idle HLT intercept feature is used for enlightened guests who wish to securely handle the events. When an enlightened guest does a HLT while an interrupt is pending, hypervisor will not have a way to figure out whether the guest needs to be re-entered or not. The Idle HLT intercept feature allows the HLT execution only if there are no pending V_INTR and V_NMI events. Presence of the Idle HLT Intercept feature is indicated via CPUID function Fn8000_000A_EDX[30]. Document for the Idle HLT intercept feature is available at [1]. This series is based on kvm-next/next (64dbb3a771a1) + [2]. Experiments done: ---------------- kvm_amd.avic is set to '0' for this experiment. The below numbers represent the average of 10 runs. Normal guest (L1) The below netperf command was run on the guest with smp = 1 (pinned). netperf -H -t TCP_RR -l 60 ---------------------------------------------------------------- |with Idle HLT(transactions/Sec)|w/o Idle HLT(transactions/Sec)| ---------------------------------------------------------------- | 25645.7136 | 25773.2796 | ---------------------------------------------------------------- Number of transactions/sec with and without idle HLT intercept feature are almost same. Nested guest (L2) The below netperf command was run on L2 guest with smp = 1 (pinned). netperf -H -t TCP_RR -l 60 ---------------------------------------------------------------- |with Idle HLT(transactions/Sec)|w/o Idle HLT(transactions/Sec)| ---------------------------------------------------------------- | 5655.4468 | 5755.2189 | ---------------------------------------------------------------- Number of transactions/sec with and without idle HLT intercept feature are almost same. Testing Done: - Tested the functionality for the Idle HLT intercept feature using selftest svm_idle_hlt_test. - Tested SEV and SEV-ES guest for the Idle HLT intercept functionality. - Tested the Idle HLT intercept functionality on nested guest. v3 -> v4 - Drop the patches to add vcpu_get_stat() into a new series [2]. - Added nested Idle HLT intercept support. v2 -> v3 - Incorporated Andrew's suggestion to structure vcpu_stat_types in a way that each architecture can share the generic types and also provide its own. v1 -> v2 - Done changes in svm_idle_hlt_test based on the review comments from Sean. - Added an enum based approach to get binary stats in vcpu_get_stat() which doesn't use string to get stat data based on the comments from Sean. - Added self_halt() and cli() helpers based on the comments from Sean. [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 [2]: https://lore.kernel.org/kvm/20241021062226.108657-1-manali.shukla@amd.com/T/#t Manali Shukla (4): x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept KVM: SVM: Add Idle HLT intercept support KVM: nSVM: implement the nested idle halt intercept KVM: selftests: KVM: SVM: Add Idle HLT intercept test arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 1 + arch/x86/include/uapi/asm/svm.h | 2 + arch/x86/kvm/governed_features.h | 1 + arch/x86/kvm/svm/nested.c | 7 ++ arch/x86/kvm/svm/svm.c | 15 +++- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/include/x86_64/processor.h | 1 + .../selftests/kvm/x86_64/svm_idle_hlt_test.c | 89 +++++++++++++++++++ 9 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86_64/svm_idle_hlt_test.c base-commit: c8d430db8eec7d4fd13a6bea27b7086a54eda6da prerequisite-patch-id: ca912571db5c004f77b70843b8dd35517ff1267f prerequisite-patch-id: 164ea3b4346f9e04bc69819278d20f5e1b5df5ed prerequisite-patch-id: 90d870f426ebc2cec43c0dd89b701ee998385455 prerequisite-patch-id: 45812b799c517a4521782a1fdbcda881237e1eda