From patchwork Fri Jul 12 09:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ravi Bangoria X-Patchwork-Id: 13731536 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2052.outbound.protection.outlook.com [40.107.220.52]) (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 B79E814B95A; Fri, 12 Jul 2024 09:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720777293; cv=fail; b=BlMs5fPidjr7A63TzFHVHINlWxa+UeeoK1GqWpL9y05dN/B/zQPJDsa2bf3Hnf/w3BRoYWWVgRQ/JRs/x/B0L6agTm1NphbyttzlfMJOLzlPZxuL4R1yhtzllm/iC8KzoErjBpRDBWBhDNVrt7ORux57NnCotLO6CGzi6sNX98M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720777293; c=relaxed/simple; bh=5rtVdFPU5cEI4KrUx229jRVQzguTWV25lhXzYyQIT6k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HdYU3gUMKJC4mvTDv4djm1otda5/qwuwxYuA4kOitAPv0DqTQ9K6A1yEwN8/V/VSxtxZcoTTGoBy8l6xdk4vC5zZjNqxI9G+B+NbuwKzEaPcVvqfo4cKDo/0DgGdKRlNJ4k0aXC6TOUcu1XjuKtmmUHSZymnVWCDmjR1MZa0Fnw= 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=usiOEBqX; arc=fail smtp.client-ip=40.107.220.52 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="usiOEBqX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kgqm5fJeCEN0jFZW5k8TqpOzrUxkjFqbneBZGKtSJbGDFBbHwpZMjhrfWLkqyGEl9iG9C+pQ373TJnFNO2ebcZlXZCcU318EWHd5eQAxvouqulT9pD5WAdH4FCOP1P0Q3DqlRwveykenuhjolP3TY2va/q3qE7l/SckBzEW8svMBhr8zCg8mKEOoyTa5tYILu4xI8t/bM0eYrmVrbZW/L7/F5GrptNpFQ7A8aVofHEkY8eJ91tuuuF2VOIRZ/iEGkp4qoFMBvTeY0fy4VINNggrF67TAJTW1TOHAH4GL+Kd1hEXhMz/kaa8QbzLWozvtWSPMsJ0Dd+ObSEo3733/dA== 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=0FJc+LLEm3A2DN67vA8hUOqchnflGEqrPUfUrqOJaBA=; b=yVozrWuYF89DeTFupgDW8dPmUHUClfBR3r9b8QCIRuQJb4t4bN2vguj7IaicJHyEmK7mZBSssNjgp+VUBeFuw2+mJKMV1rQfJgdk6b3Kh2KwbxwwssCr7tWrFIdwEp22R8qf/VRfmwV9SjhaQ6lpsLi/TzkDSU6TbLXRHCZbdmYREXphhPVbDLKcM5Dqd3KBJTSAdhzSNE70V4uEZNQmIplxpbLeaoNR6iklHBjBRA8Y7I9YIZYJjgaLoYej8wnqre2EmK1+E7C18sM1ECpADn3oOn1AoF9hHVprpzMrosKISeMardpQW8rHFfx1SjZWR+a2Pft1nfhotaQK/et9xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linutronix.de 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=0FJc+LLEm3A2DN67vA8hUOqchnflGEqrPUfUrqOJaBA=; b=usiOEBqXNs80G4hSmO/ZTZaCuJxd3ddg9czaYrUUKy8XSRJbEwbxShkxsQw3XBTqLjopzoJC1lgf1hIhiTrNuba9BIIwYGbq/2p9YsWTNmkNss9vOaDrfOddSMrbWfRzIXw9sBcW1isaUiIuUGieS/WHVmxaLEn2WC6tjQe2rU8= Received: from DM6PR14CA0047.namprd14.prod.outlook.com (2603:10b6:5:18f::24) by DM6PR12MB4353.namprd12.prod.outlook.com (2603:10b6:5:2a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.23; Fri, 12 Jul 2024 09:41:26 +0000 Received: from DS3PEPF0000C37B.namprd04.prod.outlook.com (2603:10b6:5:18f:cafe::4) by DM6PR14CA0047.outlook.office365.com (2603:10b6:5:18f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.23 via Frontend Transport; Fri, 12 Jul 2024 09:41: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 DS3PEPF0000C37B.mail.protection.outlook.com (10.167.23.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7762.17 via Frontend Transport; Fri, 12 Jul 2024 09:41:26 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 12 Jul 2024 04:41:18 -0500 From: Ravi Bangoria To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 4/4] KVM: SVM: Add Bus Lock Detect support Date: Fri, 12 Jul 2024 09:39:43 +0000 Message-ID: <20240712093943.1288-5-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712093943.1288-1-ravi.bangoria@amd.com> References: <20240712093943.1288-1-ravi.bangoria@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: DS3PEPF0000C37B:EE_|DM6PR12MB4353:EE_ X-MS-Office365-Filtering-Correlation-Id: 730c80cb-7f36-4dae-a784-08dca256ccdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: Bu4SAJgcpybN0oF42Y/lL+igxBUy9DHyuALgxFHRMa6P3g6ycgd7MC+h/cAzd0FJdhP1qnDfNynFQh3fVsUBQNwifhq9tVBkI3ghG2W3V2XBOEy+Ukvi/F0Lu66GtvwdcCsjb9QFeZ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z2GpRl02AMqhNmu6G2aaH3X4H7b9KN0rzxsiGQwDPvXe1SOyaLKmvS2sVBtNW/tClIK51zNiEMCiVhk7b5Ls6X2LkE4w+ZqiBeCXY+/buVKPEuzitLlrbMQ34skq2/fcMFhkAz88806y18RlOpXRvGrU05kBg2T6zXnphiT0aRDmhDcXHYbKvavr/mMAU9S4k7DLIiMaascsXUU83wAtPkVFiphZIpgR2J4e2ehXTXXbh2+v7e84sLRtaGkeHQZTEFW1hSqmUC 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)(82310400026)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2024 09:41:26.6170 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 730c80cb-7f36-4dae-a784-08dca256ccdd 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: DS3PEPF0000C37B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4353 Upcoming AMD uarch will support Bus Lock Detect. Add support for it in KVM. Bus Lock Detect is enabled through MSR_IA32_DEBUGCTLMSR and MSR_IA32_DEBUGCTLMSR is virtualized only if LBR Virtualization is enabled. Add this dependency in the KVM. Signed-off-by: Ravi Bangoria --- arch/x86/kvm/svm/nested.c | 3 ++- arch/x86/kvm/svm/svm.c | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 55b9a6d96bcf..6e93c2d9e7df 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -586,7 +586,8 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12 /* These bits will be set properly on the first execution when new_vmc12 is true */ if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_DR))) { vmcb02->save.dr7 = svm->nested.save.dr7 | DR7_FIXED_1; - svm->vcpu.arch.dr6 = svm->nested.save.dr6 | DR6_ACTIVE_LOW; + /* DR6_RTM is not supported on AMD as of now. */ + svm->vcpu.arch.dr6 = svm->nested.save.dr6 | DR6_FIXED_1 | DR6_RTM; vmcb_mark_dirty(vmcb02, VMCB_DR); } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 4a1d0a8478a5..e00e1e2a0b78 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1044,7 +1044,8 @@ void svm_update_lbrv(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); bool current_enable_lbrv = svm->vmcb->control.virt_ext & LBR_CTL_ENABLE_MASK; - bool enable_lbrv = (svm_get_lbr_vmcb(svm)->save.dbgctl & DEBUGCTLMSR_LBR) || + u64 dbgctl_buslock_lbr = DEBUGCTLMSR_BUS_LOCK_DETECT | DEBUGCTLMSR_LBR; + bool enable_lbrv = (svm_get_lbr_vmcb(svm)->save.dbgctl & dbgctl_buslock_lbr) || (is_guest_mode(vcpu) && guest_can_use(vcpu, X86_FEATURE_LBRV) && (svm->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK)); @@ -3145,6 +3146,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) if (data & DEBUGCTL_RESERVED_BITS) return 1; + if ((data & DEBUGCTLMSR_BUS_LOCK_DETECT) && + !guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT)) + return 1; + svm_get_lbr_vmcb(svm)->save.dbgctl = data; svm_update_lbrv(vcpu); break; @@ -5212,8 +5217,14 @@ static __init void svm_set_cpu_caps(void) /* CPUID 0x8000001F (SME/SEV features) */ sev_set_cpu_caps(); - /* Don't advertise Bus Lock Detect to guest if SVM support is absent */ - kvm_cpu_cap_clear(X86_FEATURE_BUS_LOCK_DETECT); + /* + * LBR Virtualization must be enabled to support BusLockTrap inside the + * guest, since BusLockTrap is enabled through MSR_IA32_DEBUGCTLMSR and + * MSR_IA32_DEBUGCTLMSR is virtualized only if LBR Virtualization is + * enabled. + */ + if (!lbrv) + kvm_cpu_cap_clear(X86_FEATURE_BUS_LOCK_DETECT); } static __init int svm_hardware_setup(void)