From patchwork Mon Mar 24 13:02:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 14027233 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2063.outbound.protection.outlook.com [40.107.95.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 AD096200CB; Mon, 24 Mar 2025 13:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821395; cv=fail; b=WMw0VeBisa2BtXIrBIOfv2qycwDCuQBGZIBH2Flj4kQM7A3lOzocmYo6v/vMrd0l5BFHU7Ciu7VvUFMGvT0jecLAE0FasmWI07HG4q1ct2WtVEqUx7kqzCRTbWYNmi5B7nydm5DKSGvSNf6QkW/Ec/JO7B5SY/26xM7hVB4h8rM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821395; c=relaxed/simple; bh=CNJPbtzph0aKEFLduNoLhAhPJAJAKoXYBbBwKDgqu3M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o+GNK8nbdMA2JzDkon/+mkEJ0r8vqC49Ai3JgoeOAOvg/cDYaQf7HP9S3FUyabqmyJSyrikWJKh711RU0XY0SZX2s+Uu4wKyvNcERSOjmVodqjW6DRmOPVvwdaAhK4jQeO+Mk71eI+zZ+bJrSmavUzXlY9+PH1ajoY5BC0HnKLw= 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=5NOHTgwH; arc=fail smtp.client-ip=40.107.95.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="5NOHTgwH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sbPth/INHpR8swiSu/YrI73WlG+nWK74rq2WkAwEhY9IQfp+OBO3neOrXTQQ45faHE2+/FiRG4eOnSY5KYKvrjNPEDysE6YAKaaMk53DHgRiMcBQzE/IJjh1VwRhu71LrNzhjEN90/EOq9Wxu6ovg4TbZpA4MB2wlcYCZEpoLieesNvzZ7bIP+de4oxEARgE5QQkgHt+dYPOMlL2jHp7VVsMk+q7QwUp1NKjbmiDKpfYZyXAuj/5XLVnoLw8va7RswLI4Ao1g4bOujyENTxWtr/9BPc/mc7ZChxhcnesTWrAKQ2VYrCpGMjq7jw+ZCoVvYW3He2m7aO6jxKOD4hiGg== 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=WEYo4QKmQK4kOdiFQoLuAIl624Dljd56uc2HwPB0e+s=; b=RoglkIhwsQvpHrRJ6ko6BhKOqwi38z/LLUxQ6t8/bfywi8yXI+fSfLXLF0wKJaHMtvsLt2X9ntuKFw8xjpVwN9+nHpHfgz49ihBeoCiIACYqT/sFJk2oYyGy5DeVjbOLNoGbfdoD8rhHccxwG8Mu2sJRfvz+Tpa/fxmafT2JSlQIFgMBhKL5oWkPGAXIqqnSf1q2q6AaCB3FdhCvN2VwfoE6nzFb/sAtCTgzNAd1nPzqqW4ozWCpNNoY7a0+cuUeXJY/4qC1pztVJyUhQPYiwuvg5WGV+D/Ux/ZdB7waOzCWS/eqC5xUT27dt2UquunQo7tpvRTja4i6vdIvEiyyeQ== 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=WEYo4QKmQK4kOdiFQoLuAIl624Dljd56uc2HwPB0e+s=; b=5NOHTgwHC+QrPXVyxeMkFNGKXPyKt8eCFXLlpE/dc+YFuHSGqpJ1UOOniLg4dM4y0pHCju9VasvTJoqCRcDdpd7dbKA/vp6noUU0aq8TKPXJ+ys5+YguYzll0WlELxzedIdAem4vuQKcsZz0UB6mUUqx7u6MGy+ZDHjKGwKrMLg= Received: from BYAPR05CA0037.namprd05.prod.outlook.com (2603:10b6:a03:74::14) by PH7PR12MB7916.namprd12.prod.outlook.com (2603:10b6:510:26a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.42; Mon, 24 Mar 2025 13:03:11 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:a03:74:cafe::4a) by BYAPR05CA0037.outlook.office365.com (2603:10b6:a03:74::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.42 via Frontend Transport; Mon, 24 Mar 2025 13:03:11 +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 SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8534.20 via Frontend Transport; Mon, 24 Mar 2025 13:03:10 +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; Mon, 24 Mar 2025 08:03:09 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v4 1/5] KVM: x86: Preparatory patch to move linear_rip out of kvm_pio_request Date: Mon, 24 Mar 2025 13:02:44 +0000 Message-ID: <20250324130248.126036-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250324130248.126036-1-manali.shukla@amd.com> References: <20250324130248.126036-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: SN1PEPF0002529F:EE_|PH7PR12MB7916:EE_ X-MS-Office365-Filtering-Correlation-Id: 38e75fab-fbab-4012-dc25-08dd6ad43aa4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: OubhptYA2JoEb1pmR4nNwsBbv4SqniNmFY7I+M+4orhF6Uxz89qaViAhgiFVd1VDBVkMTrcgWxUHMZN+PbSGHcH0aoM/pH5OAEPfiF50e3YfVt5qvO1GHPRBmnKAQe3R7QKdp2DOAN6h1oWlN/1vBxPIT5VswZ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2hu5aF0dG+uZ1yxn91jj/Df2Pn7JM454/aI2VnR2HEpsbs2WvftUACeIkthPwo8LgZWVapZmoacc44Y1kcNcG8Kjt2BRfYahA2cuUN3suJcZL4yALfFBsEhDdVtENlBdT2wojrFP1kz2meCDbv6pKJc2Zyf/rhQ/9stS6vGCQz2t//jgsK87378G5k7UIuEwF7E6MdAoFXv/OvFQB1uCXYE7xiKQOrrmK6XQ90ozxDERx7hHBNv55m1VUV08eJGm2QrhkIKp+cOLSkKlCjWE0= 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)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2025 13:03:10.5347 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38e75fab-fbab-4012-dc25-08dd6ad43aa4 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: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7916 Add a refactoring prep patch to move linear_rip out of kvm_pio_request and place it next to complete_userspace_io. There's nothing port I/O specific about linear_rip field, it just so happens to that port I/O is the only case where KVM's ABI is to let userspace stuff state (to emulate RESET) without first completing the I/O instruction. No functional changes intended. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/x86.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) base-commit: c9ea48bb6ee6b28bbc956c1e8af98044618fed5e diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index d881e7d276b1..f8a564dd5422 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -410,7 +410,6 @@ struct kvm_rmap_head { }; struct kvm_pio_request { - unsigned long linear_rip; unsigned long count; int in; int port; @@ -909,6 +908,7 @@ struct kvm_vcpu_arch { bool emulate_regs_need_sync_to_vcpu; bool emulate_regs_need_sync_from_vcpu; int (*complete_userspace_io)(struct kvm_vcpu *vcpu); + unsigned long cui_linear_rip; gpa_t time; s8 pvclock_tsc_shift; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 69c20a68a3f0..8282ae350eec 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9324,7 +9324,7 @@ static int complete_fast_pio_out(struct kvm_vcpu *vcpu) { vcpu->arch.pio.count = 0; - if (unlikely(!kvm_is_linear_rip(vcpu, vcpu->arch.pio.linear_rip))) + if (unlikely(!kvm_is_linear_rip(vcpu, vcpu->arch.cui_linear_rip))) return 1; return kvm_skip_emulated_instruction(vcpu); @@ -9349,7 +9349,7 @@ static int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, complete_fast_pio_out_port_0x7e; kvm_skip_emulated_instruction(vcpu); } else { - vcpu->arch.pio.linear_rip = kvm_get_linear_rip(vcpu); + vcpu->arch.cui_linear_rip = kvm_get_linear_rip(vcpu); vcpu->arch.complete_userspace_io = complete_fast_pio_out; } return 0; @@ -9362,7 +9362,7 @@ static int complete_fast_pio_in(struct kvm_vcpu *vcpu) /* We should only ever be called with arch.pio.count equal to 1 */ BUG_ON(vcpu->arch.pio.count != 1); - if (unlikely(!kvm_is_linear_rip(vcpu, vcpu->arch.pio.linear_rip))) { + if (unlikely(!kvm_is_linear_rip(vcpu, vcpu->arch.cui_linear_rip))) { vcpu->arch.pio.count = 0; return 1; } @@ -9391,7 +9391,7 @@ static int kvm_fast_pio_in(struct kvm_vcpu *vcpu, int size, return ret; } - vcpu->arch.pio.linear_rip = kvm_get_linear_rip(vcpu); + vcpu->arch.cui_linear_rip = kvm_get_linear_rip(vcpu); vcpu->arch.complete_userspace_io = complete_fast_pio_in; return 0; From patchwork Mon Mar 24 13:02:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 14027234 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2048.outbound.protection.outlook.com [40.107.101.48]) (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 A69A118FC80; Mon, 24 Mar 2025 13:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821396; cv=fail; b=eZl/wvAI0+vEgX98m0cQQOEzNg4q+VrcTRA0fn5FzWg6UYFpOjMmml2bPNIsy7xuMbkV5cEjo9jyOGrLZnUGlN/tgfvNrTQ+kiRuqxRQ2+9EDlb+mvXDRJzAgo13WSKZEl+SdRuk0niDpY1reV6xlxsunh8zI/RzBFDC719kkZQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821396; c=relaxed/simple; bh=+phLJBiIwUgkBYxA3zkuYmW4If+tkPTLvSOP7khcv3s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P8bBSR0pc7CskHk8m2MswLp5f60Yo6lioTaBSja+dLD9Mag/FLDU+6DJpKr8WXGPOBn2Tccn7EbdYfKsoOugyGh0QhSiOmYshzxQZYUBs6UCLseOhNBm3TkM1vGRxd9fAymzWD0CNWOiCw5oszr/oHJtgXAWYL9PyPz9WV0BLLY= 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=RYekrwdm; arc=fail smtp.client-ip=40.107.101.48 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="RYekrwdm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mmz7COFke8KyCbPvR4GApZoW4E+wLdT5cTOMqEHUjAqliGbXaC4Gb6iAS8eULzcJgVWjDvP+uMAjDEVLsWKALjZYGY3zRumGFMZI19roaph4WMh2nfMrW+AYSwkUfGXshp6NzPtcYhwJEqggwbLlslW9ETD3yqWeRgzqvDbwac3VTRmzwaSASLKUjeW4eJYSrhL2y6qey+jDvOjxhQBrq6axowDSMenF5oS0Xwt4DfCAck10NpklhuIlz1zGy47Mq1aoK1FPgLbges8iDcLRlVcUJkeNGEJVV3e4F1+yub/NtGUh/IlzWEjXiXWLLEXPl4cy/Uk8YRHwUMCFUTTe+w== 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=OLnvJc5Cf5oWadc/ZkcBLJlrGhY/U1X3HSxtAbqzze0=; b=J3Zt+a3Yb4S66dS7T3AzZdxVE1NWpN8/GM3O9G3Ct/MT04CfbUAFcqUHWPrKSCZ7FAUPST0/vPXvb4yLj2ge3/GIyJuxqZjh71ePg6Fk+gaq0D2oBiYUigE8YMZ+AhHQEK2o2Fw+oTuwSBHITbsF780iiBnYenBlCkl0ZCiqfUQd1XR6qY0TsVsxvDW/CaRrRwr6ja/OO86ifGYnys7fkxgipxCLk3749msJYTA99Nap1KQ9yqoyLcjg9zCL7AXEQ8BrR0AZmgUqBmN7AkmGw48I/vLHhkFfA6FLlcFn10ci13ibfhu+5kKKmWjCUT4eQEatmBBT/gGS9AA9bvICVQ== 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=OLnvJc5Cf5oWadc/ZkcBLJlrGhY/U1X3HSxtAbqzze0=; b=RYekrwdmArKHtC51Mi8vIJrNXh1qnTaKiSrxU0oIrpEMGvnqNvDlWdxj8WnuXREhv4ocT8Tpr0Wk8SaOWgRM1wX53vhi9GGL6g12kPiTzKsBhXqyc9+eTL2u89fgn/cuuRfJviWKgerIfl0PLe5wYLoK9qHWdLMhX3wOhfAD2uw= Received: from BYAPR05CA0052.namprd05.prod.outlook.com (2603:10b6:a03:74::29) by SA3PR12MB9197.namprd12.prod.outlook.com (2603:10b6:806:39e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.42; Mon, 24 Mar 2025 13:03:12 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:a03:74:cafe::81) by BYAPR05CA0052.outlook.office365.com (2603:10b6:a03:74::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.42 via Frontend Transport; Mon, 24 Mar 2025 13:03:12 +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 SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8534.20 via Frontend Transport; Mon, 24 Mar 2025 13:03:12 +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; Mon, 24 Mar 2025 08:03:10 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v4 2/5] x86/cpufeatures: Add CPUID feature bit for the Bus Lock Threshold Date: Mon, 24 Mar 2025 13:02:45 +0000 Message-ID: <20250324130248.126036-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250324130248.126036-1-manali.shukla@amd.com> References: <20250324130248.126036-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: SN1PEPF0002529F:EE_|SA3PR12MB9197:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a151ddd-974d-47c2-e27e-08dd6ad43bce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|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AuryPIRmbDHDaIzqPDapJ5aSf/KapuKpDZTZC8SBjeywEi4BDWi2bhs2hqxeWk4WD97Jo0dvYDPZ2QmKPqbqL7SqpNeZbgak8/Bz6vUkWFKMu1WZdXzOzHftPklp1L7wgavyawJiKCBYOBX58t5UFwobjwSIn6AjNSyWP7NM4Rn2vO11YelndqrzAn7zbuA0Ue7F5hUhwSpg7AYXerjERSXG/QUHPG9gxLPl0zKOK45MVwXPXjIfUKXX+Cse2PYyZb3fKcfsl3ABu6HUOmtjkOrPM6NpUuKNvgKsn1JO0ttzNlH2wGHyIv7a3kOr1JJ/Px2F9uIDWePKY6oy+Bsl0cUrC0T9n9A2821nCUD/rrptQxyudHGHb3Z6MSqQKOENLz59OiCb8rE8Cj1O6jvsAl7jN8NhrvY/fFtSMAijGQomw3TC/nExwL6/G7HVTnrA/oE3T2w849xfoSbgRsmZXY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2025 13:03:12.4878 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a151ddd-974d-47c2-e27e-08dd6ad43bce 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: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9197 Misbehaving guests can cause bus locks to degrade the performance of the system. The Bus Lock Threshold feature can be used to address this issue by providing capability to the hypervisor to limit guest's ability to generate bus lock, thereby preventing system slowdown due to performance penalities. When the Bus Lock Threshold feature is enabled, the processor checks the bus lock threshold count before executing the buslock and decides whether to trigger bus lock exit or not. The value of the bus lock threshold count '0' generates bus lock exits, and if the value is greater than '0', the bus lock is executed successfully and the bus lock threshold count is decremented. Presence of the Bus Lock threshold feature is indicated via CPUID function 0x8000000A_EDX[29]. Signed-off-by: Manali Shukla --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 8f8aaf94dc00..a3ab8d1f5c17 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -386,6 +386,7 @@ #define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* "v_spec_ctrl" Virtual SPEC_CTRL */ #define X86_FEATURE_VNMI (15*32+25) /* "vnmi" Virtual NMI */ #define X86_FEATURE_SVME_ADDR_CHK (15*32+28) /* SVME addr check */ +#define X86_FEATURE_BUS_LOCK_THRESHOLD (15*32+29) /* "buslock" Bus lock threshold */ #define X86_FEATURE_IDLE_HLT (15*32+30) /* IDLE HLT intercept */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */ From patchwork Mon Mar 24 13:02:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 14027236 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2048.outbound.protection.outlook.com [40.107.244.48]) (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 1471725EF81; Mon, 24 Mar 2025 13:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821397; cv=fail; b=KUXG69KU7LZFcGYD6MYRrzxWaf+A/aQaQ9mxpvfaYW1CM+DacYb5tejUCivD/z8lNItf5LGB+aM87nPYEL2DuP3AcxeXcxNnqppHitmrDNJ5lcdLsjSrh6g2R1DM/lnpuXoGiRUxImrJ+Pryftf6jUuEsacEZ/bA4MvlNVr6fjo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821397; c=relaxed/simple; bh=Nvlf40lsRomEsTbpFDq0h/npw04AyqKKaheQE5t5YWg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W/Ds8dx7D8zz71vbH56egTtigxEd5Ig4QMmngoXISe3AfRNKmrH6edozN4DeREVJIkTbvz8D22sDkTarbDl8eFrIUx+CERTS6GgiNJTFGfw0sNj+NIo3CoGT4qSIPSxo61LSg3QYYv8OnkNBPrr1VTChdl1gZIAzNksVcUR5goI= 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=PEQQFlVV; arc=fail smtp.client-ip=40.107.244.48 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="PEQQFlVV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uFTLttkAK5H7vO3mPkviEW8bYpS7zBL9TA0PpXlw8fve3EkvCHNcGQWnChy6IuBmlS95PEJ+6ITko3hlbeQM0dJdhSYnwjThecHeL2e2+oRy761J4evK1UmATdZtPKJFashqO091MH2rcy8FMo8ZXQKnLKSJsL5nc2ipbUHxWKKOepzUlunxJ8N8kM6eJuNL+GtqB3HE3wYP882SADj1usmLeo5GB4df/a/bHbG8k6hxUMVneMjyH9NZP/bJeLkQRMWqO9+kinxcfcm5yueHnHv6cT20Ds3g/zZ+dT4mN405wRfjmmbxZlgwy+zqwx1RjB7v6M3sKh5vlrLe8UwFIA== 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=Svp+hat4gRn2oJdJoKVMuLjd03Ln8HUu+0DKhOzuEJY=; b=rLW8oTAaAj5ot/1nDpK6s2d6agB+4i4ZcRnAZw7xQr+ax/Gr4atpruuJ1EHHTJ5e1gjgTYxnBAxhHBkOzj8/VgzIfzbwGgO0dPhXFjUs9o9+yJtT3OqkuRCgFwFURjAa2HdaE3O7ZUbA5KaiWKzUO4+Hr1DI7NGNuJLBcBMGyFKryl9k0DeUsUCu9BKDI9nYNa1vrQcTcTM2iUEEER+SKSxwv2UnshHGtMEaimlFXNLq7WTySShp2Sx1BL+JxTO9CGs8QIuQvsKnf40orEy+fx6dx4VDF1cvXPqvjGDuo/Pnh/H0EGOpyO51rWwxRE/BSR7aoCkjXkl1JKUIAY1oBw== 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=Svp+hat4gRn2oJdJoKVMuLjd03Ln8HUu+0DKhOzuEJY=; b=PEQQFlVV8D0DA44UGJXk4TExQ+TL0r/8X1efY5bQF0W55PJFbWcb7+7M2j/orFv13IB3Dgx+hgYkceGhSAAgm7kfNoqkjTaJtsu9vYi0OGSN0RcUq7kHx7w1GoqMJkmnZZ7Q7/5jn1IyfYnhoihBRKkcDRohxMMKhSkvA8cOpso= Received: from BYAPR05CA0056.namprd05.prod.outlook.com (2603:10b6:a03:74::33) by BN7PPF915F74166.namprd12.prod.outlook.com (2603:10b6:40f:fc02::6d9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.42; Mon, 24 Mar 2025 13:03:13 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:a03:74:cafe::cb) by BYAPR05CA0056.outlook.office365.com (2603:10b6:a03:74::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.42 via Frontend Transport; Mon, 24 Mar 2025 13:03:13 +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 SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8534.20 via Frontend Transport; Mon, 24 Mar 2025 13:03:13 +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; Mon, 24 Mar 2025 08:03:11 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v4 3/5] KVM: SVM: Enable Bus lock threshold exit Date: Mon, 24 Mar 2025 13:02:46 +0000 Message-ID: <20250324130248.126036-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250324130248.126036-1-manali.shukla@amd.com> References: <20250324130248.126036-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: SN1PEPF0002529F:EE_|BN7PPF915F74166:EE_ X-MS-Office365-Filtering-Correlation-Id: 37110d99-7280-4dd6-8e94-08dd6ad43c3c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: Eceg3nB9X5vtACLFBJHPKxjtPn1WYsUrT5+lDEmvPMr5a/9EU4yGat8UTUCp6H7ZHYcrbWcCDU6ZeRuiCOESjWMfF9Gu3yhVg+dEQJKIco4bG3kODBjM7UlpKkXe9kJTaDRQBJsDMWXEM4afU9SEiMmNlcFVsvgBh+cFiWm5CsDmuVMJ/Ddr9/TsyYvC6NnJ8niYD8C/+S1+DiMlGKwzJf8XfYTyKgX+ucW8KDLkaRyE856DK3g3tbkojHSiOh/bTflsHbb2d/wv5/fu2P/mLfqNdqpZUa/J+2MEGVvdwdRXhwOi8yCjv+BxFGtp3h0LiikKo/SqW+dKyKVaBA4rTjKJ5V5vr2OsUWnYHOyWnCWQqByUqmHJh15VrWoHFhdp3all70pQbDZ6f+MfJ+qoQoEn2oVKe1ZSee6N2ft5OvTa7/ErAtbXdayrXVLclUOlIPaXYu6/ZIGpFiHaGNjHD+KC1eeEsBvxF0ceZ9n4BFMO2vs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SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2025 13:03:13.1909 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37110d99-7280-4dd6-8e94-08dd6ad43c3c 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: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PPF915F74166 From: Nikunj A Dadhania Virtual machines can exploit bus locks to degrade the performance of the system. Bus locks can be caused by Non-WB(Write back) and misaligned locked RMW (Read-modify-Write) instructions and require systemwide synchronization among all processors which can result into significant performance penalties. To address this issue, the Bus Lock Threshold feature is introduced to provide ability to hypervisor to restrict guests' capability of initiating mulitple buslocks, thereby preventing system slowdowns. Support for the buslock threshold is indicated via CPUID function 0x8000000A_EDX[29]. On the processors that support the Bus Lock Threshold feature, the VMCB provides a Bus Lock Threshold enable bit and an unsigned 16-bit Bus Lock threshold count. VMCB intercept bit VMCB Offset Bits Function 14h 5 Intercept bus lock operations Bus lock threshold count VMCB Offset Bits Function 120h 15:0 Bus lock counter When a VMRUN instruction is executed, the bus lock threshold count is loaded into an internal count register. Before the processor executes a bus lock in the guest, it checks the value of this register: - If the value is greater than '0', the processor successfully executes the bus lock and decrements the count. - If the value is '0', the bus lock is not executed, and a #VMEXIT to the VMM is taken. The bus lock threshold #VMEXIT is reported to the VMM with the VMEXIT code A5h, SVM_EXIT_BUS_LOCK. Signed-off-by: Nikunj A Dadhania Co-developed-by: Manali Shukla Signed-off-by: Manali Shukla --- arch/x86/include/asm/svm.h | 5 ++++- arch/x86/include/uapi/asm/svm.h | 2 ++ arch/x86/kvm/svm/svm.c | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 9b7fa99ae951..9dc54da1835a 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_BUSLOCK, INTERCEPT_IDLE_HLT = 166, }; @@ -159,7 +160,9 @@ struct __attribute__ ((__packed__)) vmcb_control_area { u64 avic_physical_id; /* Offset 0xf8 */ u8 reserved_7[8]; u64 vmsa_pa; /* Used for an SEV-ES guest */ - u8 reserved_8[720]; + u8 reserved_8[16]; + u16 bus_lock_counter; /* Offset 0x120 */ + u8 reserved_9[702]; /* * Offset 0x3e0, 32 bytes reserved * for use by hypervisor/software. diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h index ec1321248dac..9c640a521a67 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_BUS_LOCK 0x0a5 #define SVM_EXIT_IDLE_HLT 0x0a6 #define SVM_EXIT_NPF 0x400 #define SVM_EXIT_AVIC_INCOMPLETE_IPI 0x401 @@ -225,6 +226,7 @@ { SVM_EXIT_CR4_WRITE_TRAP, "write_cr4_trap" }, \ { SVM_EXIT_CR8_WRITE_TRAP, "write_cr8_trap" }, \ { SVM_EXIT_INVPCID, "invpcid" }, \ + { SVM_EXIT_BUS_LOCK, "buslock" }, \ { SVM_EXIT_IDLE_HLT, "idle-halt" }, \ { SVM_EXIT_NPF, "npf" }, \ { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, \ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8abeab91d329..244e099e7262 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1375,6 +1375,9 @@ static void init_vmcb(struct kvm_vcpu *vcpu) svm->vmcb->control.int_ctl |= V_GIF_ENABLE_MASK; } + if (vcpu->kvm->arch.bus_lock_detection_enabled) + svm_set_intercept(svm, INTERCEPT_BUSLOCK); + if (sev_guest(vcpu->kvm)) sev_init_vmcb(svm); @@ -5299,6 +5302,11 @@ static __init void svm_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK); } + if (cpu_feature_enabled(X86_FEATURE_BUS_LOCK_THRESHOLD)) { + pr_info("Bus Lock Threshold supported\n"); + kvm_caps.has_bus_lock_exit = true; + } + /* CPUID 0x80000008 */ if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) || boot_cpu_has(X86_FEATURE_AMD_SSBD)) From patchwork Mon Mar 24 13:02:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 14027237 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2077.outbound.protection.outlook.com [40.107.237.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 3BF6F200CB; Mon, 24 Mar 2025 13:03:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821399; cv=fail; b=dIpRnfJ6pkMhpHN84TBi+Wm7grEOZjF3iEgkl547/S0QL6P3/2eqbFgdmxTZ5YDuRw52r2yRJEyKVwJbvwFqryR5kpkmNiogEzU6E6h9k9SY3EMUWGrvbnB76atYL7EzKUeJUAg7f9h0s8+xX+zZnQna0j20gXkR3I5cnB5wHB4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821399; c=relaxed/simple; bh=jhQ4zr7Kfa09cG0Xb8NLSl4V9m28FxwT3T8YrPL6DT4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EWlOZVEYFRYfl15Z9h6jmsbJlIHLDWC2OwDO9upqqjju2p508l+0HkWCBKqd465yf1Lv0HK3oTTXIpvfGKAyRFKylDdai0cR5DKjqi6Y2FEEigbUr6NS8+jYs2/a0c1EbcDSmrreljQ1JjKu+qutFGnMUMlwCJF7iICpC0zyNrQ= 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=wxDsza8s; arc=fail smtp.client-ip=40.107.237.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="wxDsza8s" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FTE5b/8kok59jHxIjzXVtW6XQHWyVmc0mdYXCIx2bslgW5LZrQF2bGtDjj6nSCPu81McH8XeXZ6+TzSuqKVrMy2ikiSQgF25PGybZk+Jwy/9NXeHu7mKittXVIh9kF4CfvQ6LDFYa7mnMuasUuTWgPz6x/gSs6OZDg+upJzX/arrkM83WEg4GFEv1+38m0iMB+zKnp8vodO7NxcMMfmCoUfTDt3pmAkwamo7DUnYcahPnMlW3jkQauLXv0odHJ8S7y8PDkLbZ31CHbUR7gLZSWuIspeuQF/pDZLdn/ApaQew9CPdImYIQVgiCIQBcvSa7Pc3u0H9HHq05mdr8rxo8w== 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=3yZ9hrH+xnegprnalvkzSPS7ctBOJM3J5fbifm42+fw=; b=Ljf3mWFAFg0BbRn5VzmFgjSMAaL6Kt9N/k6S4lbGV7TGvJ8td0KCbwGLzyCObtcUG6WCVkWh3NvYjpX1eF2huwdiJA+ZcdQLhUnTEQpkdsGaQ1w0G82v3n6W8CVruWpD5HA/5yDqlwzwFsvTBzqizq2QOW2Yx7FL8ayCpcgXSCJmrHmmKQLYQPyuqaOe070CuGgpUb2KbExD7IbApccus2ZB1mNNL/L58vlQx+2svj1aJPmOUGuh8jaKWMKD4oa0VUwuqozLxjTTk1mUN39/lfZI4it/9789kwdEgQWCm9qP8EQAd6ppz2uTU+5hvtK6Wr+OvYfcH6sRBl/2BOJVwQ== 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=3yZ9hrH+xnegprnalvkzSPS7ctBOJM3J5fbifm42+fw=; b=wxDsza8sFBT+H5o00C/MlzPJSyeQH9ulYmvwyVN2xrQmZkex0qt/rLzSsd86qE1rn8z7vQNOnRP/fbBgEuWxQg59mpeOGzahtKJRxh0ZQZX2yTos6ZbzMrx2yJX8Ee+kRILu73iCXqhA0eRvGbprOZaQLqhooCMdynsBq8Mlnfc= Received: from BYAPR05CA0047.namprd05.prod.outlook.com (2603:10b6:a03:74::24) by IA1PR12MB7760.namprd12.prod.outlook.com (2603:10b6:208:418::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.42; Mon, 24 Mar 2025 13:03:14 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:a03:74:cafe::35) by BYAPR05CA0047.outlook.office365.com (2603:10b6:a03:74::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.42 via Frontend Transport; Mon, 24 Mar 2025 13:03:14 +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 SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8534.20 via Frontend Transport; Mon, 24 Mar 2025 13:03:14 +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; Mon, 24 Mar 2025 08:03:11 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v4 4/5] KVM: SVM: Add support for KVM_CAP_X86_BUS_LOCK_EXIT on SVM CPUs Date: Mon, 24 Mar 2025 13:02:47 +0000 Message-ID: <20250324130248.126036-5-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250324130248.126036-1-manali.shukla@amd.com> References: <20250324130248.126036-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: SN1PEPF0002529F:EE_|IA1PR12MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 63e0113a-ba0a-4475-4dc8-08dd6ad43cbd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: t9zpzz/fhn3YCyZQSSosa9+d+slC0FQuz3PHwVsXRN0SwUmItGSnODGVohCfxo/k9f3NZwUul7OIwlwM/bk+K4w1Er/vNoZIBPbHivDZgkavBXQ5+YoXJnuVHL3/9+JILHeKZHCfrcGcs0SEN8PvzxArdUL0ooQ0a9PN/0RJBRjOvpCxtvOkqbeburawn5AwzSneOcmZZgEi94nLxDW3pSZeNcVt4Qu3GTnuuEx8CaKhota2Zg0ko34XVdEDerBGSoUM3CGHl1/eJlqxSvMcS87EpjgbDDWSEwiALbCr89jhkPAnSp7x6nAHm3SB+EqTukfX8L6zc2pid63ZD7TyeHufYANiJTPBQF+IoqWPbdjhTln+jpNxkL7MCqr11y7yvJBk/lBQvf28MM1kmmLiXienXOjBuN5btTQRVNoJmsfQ/TIotXCgw8hDR+jQQhkDppYpoHPbye1SiCzJIW7vhk/UlZ6hKm9ntZy6SXi2H6yNzgIUSIwOwiymX/40w8E/rU4mrbzjJX4Pwz5f9ox+N1+8JuYg1/TdpnNr7Z5zPWUyay1hKlfrD5NZ+ppxuc1f8a1Wzg69n8vMUfZPM516g+qU7SGmx7/qxk2xdJ4GwL7pfS0g47Ei70sw1KDg190OKZruGcqCvxqUfpHUysQWn/+GqOrmNbDPTM9ixvMuL/A2NTcudhsPmwesBmC7BLlmNvlEqyheHk/cOS20/lYa+BgCL1zYZejnjutcooKuPEFZ2ezvNKXQNmB8ioNYSs24ZkasaxrvOQla2yroAGVWCLvNh5wiXr3tikXaXUM+c2/mhMqQbPtPsV5t2l0Z3CzBOl0hqalpPjp+nOFt6/El33oK3Ah7XwHsxCvWOIvZOaQdBfLTUKPenpQa7FyBo22p3KB265XZyRTWII5R0eH0VCe4r4aJuxwRrmSYQJ+rv6wzlgAMxSJf3bzofHPFKqtCa0brxCxFSxzOwOyVxfxc29hlC1cUANviYoSgqC3xYYoM5aOdd9SauuJ0Wlus2/XooPtVpjJUuAYYl40NXRNW3MlpcttNcffW+mEjkL7oW09OxYqX3ZRcyxFen59DB/f+LIwae0nc1fas5hx4RQHcjJ/YJYHzUTIoA6TGQQ6jVCm+d4xFMqsg8cenqU7I+zleV2oDbG707U9VYkxJyExvOUM5ogivsUuoRxKzJHHQvjTyTyQ1aGXN/tNzItjSF5fG/DDgEYgjimq06XX4ozFYQmZ5dC6J6rs6lyBWFJeWMugHguyPmTZiUmSjft7O+eH0nkmCd3YZA3QP7KaP4cTDXmzWxOJjZIQFjQGtsHKM0886yrBO6nhUnz6lsdcjS6i1uk1UNDxpiUMXh7cGdxOXKSojZwYODpzII32vnhl74Uc63QLmwsLYJ02ud0Pb3Azva++1LADbN00ySRmsnZIgmD9Ihfww9Di9fpnb0vMzb0ggFVB9dYlXpPpS1lBQLxN96PKO4ppP1tOSog4IqnCIOQDiC/p077UB9Rcax3hb2Wk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2025 13:03:14.0034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63e0113a-ba0a-4475-4dc8-08dd6ad43cbd 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: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7760 Add support for KVM_CAP_X86_BUS_LOCK_EXIT on SVM CPUs with Bus Lock Threshold, which is close enough to VMX's Bus Lock Detection VM-Exit to allow reusing KVM_CAP_X86_BUS_LOCK_EXIT. The biggest difference between the two features is that Threshold is fault-like, whereas Detection is trap-like. To allow the guest to make forward progress, Threshold provides a per-VMCB counter which is decremented every time a bus lock occurs, and a VM-Exit is triggered if and only if the counter is '0'. To provide Detection-like semantics, initialize the counter to '0', i.e. exit on every bus lock, and when re-executing the guilty instruction, set the counter to '1' to effectively step past the instruction. Note, in the unlikely scenario that re-executing the instruction doesn't trigger a bus lock, e.g. because the guest has changed memory types or patched the guilty instruction, the bus lock counter will be left at '1', i.e. the guest will be able to do a bus lock on a different instruction. In a perfect world, KVM would ensure the counter is '0' if the guest has made forward progress, e.g. if RIP has changed. But trying to close that hole would incur non-trivial complexity, for marginal benefit; the intent of KVM_CAP_X86_BUS_LOCK_EXIT is to allow userspace rate-limit bus locks, not to allow for precise detection of problematic guest code. And, it's simply not feasible to fully close the hole, e.g. if an interrupt arrives before the original instruction can re-execute, the guest could step past a different bus lock. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- Documentation/virt/kvm/api.rst | 19 +++++++++++++++ arch/x86/kvm/svm/nested.c | 42 ++++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 30 ++++++++++++++++++++++++ arch/x86/kvm/svm/svm.h | 2 ++ 4 files changed, 93 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 5fe84f2427b5..f7c925aa0c4f 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -7909,6 +7909,25 @@ apply some other policy-based mitigation. When exiting to userspace, KVM sets KVM_RUN_X86_BUS_LOCK in vcpu-run->flags, and conditionally sets the exit_reason to KVM_EXIT_X86_BUS_LOCK. +Note! KVM_CAP_X86_BUS_LOCK_EXIT on AMD CPUs with the Bus Lock Threshold is close +enough to INTEL's Bus Lock Detection VM-Exit to allow using +KVM_CAP_X86_BUS_LOCK_EXIT for AMD CPUs. + +The biggest difference between the two features is that Threshold (AMD CPUs) is +fault-like i.e. the bus lock exit to user space occurs with RIP pointing at the +offending instruction, whereas Detection (Intel CPUs) is trap-like i.e. the bus +lock exit to user space occurs with RIP pointing at the instruction right after +the guilty one. + +The bus lock threshold on AMD CPUs provides a per-VMCB counter which is +decremented every time a bus lock occurs, and a VM-Exit is triggered if and only +if the bus lock counter is '0'. + +To provide Detection-like semantics for AMD CPUs, the bus lock counter has been +initialized to '0', i.e. exit on every bus lock, and when re-executing the +guilty instruction, the bus lock counter has been set to '1' to effectively step +past the instruction. + Note! Detected bus locks may be coincident with other exits to userspace, i.e. KVM_RUN_X86_BUS_LOCK should be checked regardless of the primary exit reason if userspace wants to take action on all detected bus locks. diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 834b67672d50..a42ef7dd9143 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -678,6 +678,36 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, vmcb02->control.iopm_base_pa = vmcb01->control.iopm_base_pa; vmcb02->control.msrpm_base_pa = vmcb01->control.msrpm_base_pa; + /* + * Stash vmcb02's counter if the guest hasn't moved past the guilty + * instrution; otherwise, reset the counter to '0'. + * + * In order to detect if L2 has made forward progress or not, track the + * RIP at which a bus lock has occurred on a per-vmcb12 basis. If RIP + * is changed, guest has clearly made forward progress, bus_lock_counter + * still remained '1', so reset bus_lock_counter to '0'. Eg. In the + * scenario, where a buslock happened in L1 before VMRUN, the bus lock + * firmly happened on an instruction in the past. Even if vmcb01's + * counter is still '1', (because the guilty instruction got patched), + * the vCPU has clearly made forward progress and so KVM should reset + * vmcb02's counter to '0'. + * + * If the RIP hasn't changed, stash the bus lock counter at nested VMRUN + * to prevent the same guilty instruction from triggering a VM-Exit. Eg. + * if userspace rate-limits the vCPU, then it's entirely possible that + * L1's tick interrupt is pending by the time userspace re-runs the + * vCPU. If KVM unconditionally clears the counter on VMRUN, then when + * L1 re-enters L2, the same instruction will trigger a VM-Exit and the + * entire cycle start over. + */ + if (vmcb02->save.rip && (svm->nested.ctl.bus_lock_rip == vmcb02->save.rip)) { + vmcb02->control.bus_lock_counter = 1; + svm->bus_lock_rip = svm->nested.ctl.bus_lock_rip; + } else { + vmcb02->control.bus_lock_counter = 0; + } + svm->nested.ctl.bus_lock_rip = INVALID_GPA; + /* Done at vmrun: asid. */ /* Also overwritten later if necessary. */ @@ -1039,6 +1069,18 @@ int nested_svm_vmexit(struct vcpu_svm *svm) } + /* + * If bus_lock_counter is nonzero and the guest has not moved past the + * guilty instruction, save bus_lock_rip in svm_nested_state. This will + * help determine at nested VMRUN whether to stash vmcb02's counter or + * reset it to '0'. + */ + if (vmcb02->control.bus_lock_counter && + svm->bus_lock_rip == vmcb02->save.rip) + svm->nested.ctl.bus_lock_rip = svm->bus_lock_rip; + else + svm->nested.ctl.bus_lock_rip = INVALID_GPA; + nested_svm_copy_common_state(svm->nested.vmcb02.ptr, svm->vmcb01.ptr); svm_switch_vmcb(svm, &svm->vmcb01); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 244e099e7262..ea12e93ae983 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3310,6 +3310,35 @@ static int invpcid_interception(struct kvm_vcpu *vcpu) return kvm_handle_invpcid(vcpu, type, gva); } +static inline int complete_userspace_buslock(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + /* + * If userspace has NOT changed RIP, then KVM's ABI is to let the guest + * execute the bus-locking instruction. Set the bus lock counter to '1' + * to effectively step past the bus lock. + */ + if (kvm_is_linear_rip(vcpu, vcpu->arch.cui_linear_rip)) + svm->vmcb->control.bus_lock_counter = 1; + + return 1; +} + +static int bus_lock_exit(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + vcpu->run->exit_reason = KVM_EXIT_X86_BUS_LOCK; + vcpu->run->flags |= KVM_RUN_X86_BUS_LOCK; + + vcpu->arch.cui_linear_rip = kvm_get_linear_rip(vcpu); + svm->bus_lock_rip = vcpu->arch.cui_linear_rip; + vcpu->arch.complete_userspace_io = complete_userspace_buslock; + + return 0; +} + static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { [SVM_EXIT_READ_CR0] = cr_interception, [SVM_EXIT_READ_CR3] = cr_interception, @@ -3379,6 +3408,7 @@ static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { [SVM_EXIT_INVPCID] = invpcid_interception, [SVM_EXIT_IDLE_HLT] = kvm_emulate_halt, [SVM_EXIT_NPF] = npf_interception, + [SVM_EXIT_BUS_LOCK] = bus_lock_exit, [SVM_EXIT_RSM] = rsm_interception, [SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception, [SVM_EXIT_AVIC_UNACCELERATED_ACCESS] = avic_unaccelerated_access_interception, diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index d4490eaed55d..7a4c5848c952 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -169,6 +169,7 @@ struct vmcb_ctrl_area_cached { u64 nested_cr3; u64 virt_ext; u32 clean; + u64 bus_lock_rip; union { #if IS_ENABLED(CONFIG_HYPERV) || IS_ENABLED(CONFIG_KVM_HYPERV) struct hv_vmcb_enlightenments hv_enlightenments; @@ -327,6 +328,7 @@ struct vcpu_svm { /* Guest GIF value, used when vGIF is not enabled */ bool guest_gif; + u64 bus_lock_rip; }; struct svm_cpu_data { From patchwork Mon Mar 24 13:02:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 14027238 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2057.outbound.protection.outlook.com [40.107.236.57]) (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 D1718200CB; Mon, 24 Mar 2025 13:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821402; cv=fail; b=IV82hSmRm54zV/a0apjVkK4DLq2zsCzehegyFMMhQCEl1j2sCMYnOwRHoD/uh1zRY9rRuu02t7wzPbGqLhQIQnDXKmYhpyH4t/bFjS5g+FJm3QQZ0DoCd4RGs79fS9MdI3CGBcMaRt/SgJei6V+C7JsBX32zlJjLS3+Hm5J/B8U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742821402; c=relaxed/simple; bh=PIC92M46MlQOjw5mMZ4/P5vECj7rVr+bL/ug8bUAZzY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KSfeGIQ4U8RPlUTRVaszVgqlILBEeiHZLYeN/FOJSfeLGoeNZS5fHuTq2TasAaFEjK2yGJK3Xim7p5HWSKCzgkAQp674u7DWla6Yy2/8eLcw+0UxhyeOM4lGPjvb6oKNHbve/SuBju4+gAC/Xouh8AJkw+N+RXgthUUjMWS6YDk= 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=GXpWa04C; arc=fail smtp.client-ip=40.107.236.57 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="GXpWa04C" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HbO8Q4a1dff8R2ZPMuHnUlpIkuWvFz8hY6yydmf+bg+auvOa6lQBYZVcIBEsjtXa9GfOfpFStX+1dw4MF4e+1MsQyiMjO2g1afH9WN1CJIxMF6Y3C144zTrJkdiYwUmEwq6CMQSBT2d7tJEPgXvOS+fmbwsKZkSCPZGGrSOIylf1dxub73Y9KjxvOBWt6RsYtZbYk6vBewgbuslLIET/m0zw5K2/0GF/ql2MPDVI5xbDsN9XiU3DDp3gSkIbUOGeemHhIORSYN9TVlEfhIQgumqMqnoZnoAFNoxJM3FDG0O21Rwmq++Dq8wTLsPS907KguI8vvpFVD828bcu8JmPmw== 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=k2zDMJ6JCIneIgXzaLY/KFLNFSs6O3p0d01D/JiY8gY=; b=ISNt64Um2+4bcyfx9y8IuUlYqbw5DSIpJ15fGSIlpHkWEbprgGuhRPbDbp4phiuZaFBnyZFsqnVwowxaWyr0DlMjCS3syz+6LXFc+G+BHuId2JUR37H7zYGaN7JcScjU9TgrUjjyhckej1KYh1yE5r+bbThW0URaLNYkwIKypFNWLPhCq5dAE0FHbJ7GopqwR3wV4O0ruTxqIs2ORj0O+985lBNR3GZRn8B9uUeKKuZSw8NkMNqeENgRzub+XE1pORl+79aeZuk/GqcEN6r6Bv3o1rZDzpp38drZKnNKhgKwbwIwM4gLYpGSHXtiHo/aXndDdoVFyEueuF1KD/qVDQ== 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=k2zDMJ6JCIneIgXzaLY/KFLNFSs6O3p0d01D/JiY8gY=; b=GXpWa04C7QBij5n2DC+f4UTxwIwNuusG/tJW5SggO/sgsaiVWuA6WvxX3AyCFNiFY3Rrrf2ql7Yixu1Rky9SbOCS5bdWHj2dKkasmgx/D/d7E6iSGmPJ69EJI6irLD9k93y8q8mtkq2YDH5yXArNUprsp0OVRS+VZJt8FHHOo7Y= Received: from BYAPR05CA0066.namprd05.prod.outlook.com (2603:10b6:a03:74::43) by PH0PR12MB7958.namprd12.prod.outlook.com (2603:10b6:510:285::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.42; Mon, 24 Mar 2025 13:03:15 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:a03:74:cafe::d6) by BYAPR05CA0066.outlook.office365.com (2603:10b6:a03:74::43) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.42 via Frontend Transport; Mon, 24 Mar 2025 13:03: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 SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8534.20 via Frontend Transport; Mon, 24 Mar 2025 13:03:15 +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; Mon, 24 Mar 2025 08:03:12 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v4 5/5] KVM: selftests: Add bus lock exit test Date: Mon, 24 Mar 2025 13:02:48 +0000 Message-ID: <20250324130248.126036-6-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250324130248.126036-1-manali.shukla@amd.com> References: <20250324130248.126036-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: SN1PEPF0002529F:EE_|PH0PR12MB7958:EE_ X-MS-Office365-Filtering-Correlation-Id: c4eafd24-a3f5-4dbb-81ed-08dd6ad43d53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSp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yDFAdAClWnTURxEGoE56fDq/YV3e+uESl4yBMrJIunGEFlK7LgDLsooJgEufRR6LmsB2x8SCW8RMyZ8j9vGQgRq32UQOFqo9slSoaA8ZGigvFez+yfZrri0VHQ+xoiQdM7/fuQqXkdJA1VpFd5qjoM3ucNigBJPigvHXwZIxV7gas0Z0OG0Q+0vpT5wrBdOL3Nz1jOY8wlmwH7DT8gGLd5pjs7T0ZLe8x/wJJbqTUTWuQDsyUVzz3QK3zklbBRo3FBCB6P9qmd8Ikx9atVhA6zhAeShPrFGPD+nWC7Fv1DfT1v7qIgcKkjKkozYjVdTCLeSOSDosnqOvbT1b18STSv3MxzTN9bmxpm6i+PxLTN3imEfZD9ZXacvqDOQ7i97FAPDVJO92uN9psj+Tz1YSqKf3lUA7SjwWQXrOxmQIGIOZVqN2mBp33UlvjXHsHtM09HAuiuJ7TopAphCGSJz9gw3lOtPLqzZtDJNY0tY76kQRBYlCrOsTzkNRAY49dysBM+2fKDguBcIY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2025 13:03:15.0347 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4eafd24-a3f5-4dbb-81ed-08dd6ad43d53 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: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7958 From: Nikunj A Dadhania Add a test case to verify the Bus Lock exit feature The main thing that the selftest verifies is that when a Buslock is generated in the guest context, the KVM_EXIT_X86_BUS_LOCK is triggered for SVM or VMX when the KVM capability KVM_CAP_X86_BUS_LOCK_EXIT is enabled. This test case also verifies the Bus Lock exit in nested scenario. Signed-off-by: Nikunj A Dadhania Co-developed-by: Manali Shukla Signed-off-by: Manali Shukla --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/x86/kvm_buslock_test.c | 135 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86/kvm_buslock_test.c diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm index f773f8f99249..17c77f947ae8 100644 --- a/tools/testing/selftests/kvm/Makefile.kvm +++ b/tools/testing/selftests/kvm/Makefile.kvm @@ -68,6 +68,7 @@ TEST_GEN_PROGS_x86 += x86/hyperv_svm_test TEST_GEN_PROGS_x86 += x86/hyperv_tlb_flush TEST_GEN_PROGS_x86 += x86/kvm_clock_test TEST_GEN_PROGS_x86 += x86/kvm_pv_test +TEST_GEN_PROGS_x86 += x86/kvm_buslock_test TEST_GEN_PROGS_x86 += x86/monitor_mwait_test TEST_GEN_PROGS_x86 += x86/nested_emulation_test TEST_GEN_PROGS_x86 += x86/nested_exceptions_test diff --git a/tools/testing/selftests/kvm/x86/kvm_buslock_test.c b/tools/testing/selftests/kvm/x86/kvm_buslock_test.c new file mode 100644 index 000000000000..9c081525ac2a --- /dev/null +++ b/tools/testing/selftests/kvm/x86/kvm_buslock_test.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + */ + +#include "test_util.h" +#include "kvm_util.h" +#include "processor.h" +#include "svm_util.h" +#include "vmx.h" + +#define NR_ITERATIONS 100 +#define L2_GUEST_STACK_SIZE 64 + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" + +struct buslock_test { + unsigned char pad[PAGE_SIZE - 2]; + atomic_long_t val; +} __packed; + +struct buslock_test test __aligned(PAGE_SIZE); + +static __always_inline void buslock_atomic_add(int i, atomic_long_t *v) +{ + asm volatile(LOCK_PREFIX "addl %1,%0" + : "+m" (v->counter) + : "ir" (i) : "memory"); +} + +static void buslock_add(void) +{ + /* + * Increment a page unaligned variable atomically. + * This should generate a bus lock exit. + */ + for (int i = 0; i < NR_ITERATIONS; i++) + buslock_atomic_add(2, &test.val); +} + +#pragma GCC diagnostic pop + +static void l2_guest_code(void) +{ + buslock_add(); + GUEST_DONE(); +} + +static void l1_svm_code(struct svm_test_data *svm) +{ + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + struct vmcb *vmcb = svm->vmcb; + + generic_svm_setup(svm, l2_guest_code, + &l2_guest_stack[L2_GUEST_STACK_SIZE]); + run_guest(vmcb, svm->vmcb_gpa); + GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL); + GUEST_DONE(); +} + +static void l1_vmx_code(struct vmx_pages *vmx) +{ + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + + GUEST_ASSERT_EQ(prepare_for_vmx_operation(vmx), true); + GUEST_ASSERT_EQ(load_vmcs(vmx), true); + + prepare_vmcs(vmx, NULL, &l2_guest_stack[L2_GUEST_STACK_SIZE]); + + GUEST_ASSERT(!vmwrite(GUEST_RIP, (u64)l2_guest_code)); + GUEST_ASSERT(!vmlaunch()); + + GUEST_ASSERT_EQ(vmreadz(VM_EXIT_REASON), EXIT_REASON_VMCALL); + GUEST_DONE(); +} + +static void guest_code(void *test_data) +{ + buslock_add(); + + if (this_cpu_has(X86_FEATURE_SVM)) + l1_svm_code(test_data); + else + l1_vmx_code(test_data); +} + +int main(int argc, char *argv[]) +{ + struct kvm_vcpu *vcpu; + struct kvm_run *run; + struct kvm_vm *vm; + vm_vaddr_t nested_test_data_gva; + + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM) || kvm_cpu_has(X86_FEATURE_VMX)); + TEST_REQUIRE(kvm_has_cap(KVM_CAP_X86_BUS_LOCK_EXIT)); + + vm = vm_create(1); + vm_enable_cap(vm, KVM_CAP_X86_BUS_LOCK_EXIT, KVM_BUS_LOCK_DETECTION_EXIT); + vcpu = vm_vcpu_add(vm, 0, guest_code); + + if (kvm_cpu_has(X86_FEATURE_SVM)) + vcpu_alloc_svm(vm, &nested_test_data_gva); + else + vcpu_alloc_vmx(vm, &nested_test_data_gva); + + vcpu_args_set(vcpu, 1, nested_test_data_gva); + + run = vcpu->run; + + for (;;) { + struct ucall uc; + + vcpu_run(vcpu); + + if (run->exit_reason == KVM_EXIT_IO) { + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + /* NOT REACHED */ + case UCALL_SYNC: + continue; + case UCALL_DONE: + goto done; + default: + TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd); + } + } + + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_X86_BUS_LOCK); + } +done: + kvm_vm_free(vm); + return 0; +}