From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.19 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796020610; b=V60ddFG77Vb3cbSx/alR1UJ0+djjrn1wZxVnIEznivr6ptOf8zVGFz2lYiuJE3rZSu29 sI+sfGKfK7OGScIabqWXsVVquXz8wpCgRxFoQM5z53SzWR/qPv85isSr1RT+amVs2dQ0f v6j6no/VtkzBWOZzCpEQTDt/XviIcv6VvibhXXB/vYJFrIKfpPAriWIfkRxy7v3Q4Hujc YxRlPuGaYOiVXAYUoEc7KUesimn7TYLzF7+3Kahrm8CHhJluNhGt9jwAg5vFehQbP6Suk BlDh0YBE+fqRuwF08i/cTyJxd+WkmleudsCucrCOlE8okhgIZUHDthEudB0KmvxQjHQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020610; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To:CC: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=jqLgMlxVIbtZuk/UGQ5T3gB7J0875gZ2PL2hNnkiOAs=; b=kAkzsbv4M3w7HS/ev7bQpyIYnrlTMOpPv0cX1c6B28AONwVjmHDiAkEq1W12rupsQxlq QGm+OvAmubMjxUFhKOTeCUdfDO+0gGVuwl9MFlvPmjIFcQ0EhCg23hXL+evqLvcOaFoeY lfS16RTyDpncg1eLyWor9AnDrs4sZTYigvutPDCHNIEFjUVcDBDR37MtbOxOlta1S7E8E qAIuQxlZwGUGdVksnNpKC75D5u532t9t+gGp6k0GUXmNnDzI0sqklQiW/Nd1suX71/eDb sm3M0VVv3e6YcKfXMuAQOlq2HnIL13HuyIopHVx83Jal0xgLa2PUuP+prVxOLs9p6Wg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b="AoAm/hCR"; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.19 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011019.outbound.protection.outlook.com [52.101.52.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D56A606A686 for ; Mon, 30 Nov 2026 06:36:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D56A606A686 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=AoAm/hCR ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=r/NsDm2zeB523wBdOkn6biI9TlisNPVAJp7Gp6a6eM4vQZ3pVIZ5K1icmOLVdyimp4oibcLvHL/YZhPDxvo6VtW5exuWsrXIc62GX9aaZgVXcRZ9FqKIKHDMYAKGIeMxj1ieyzMxKk6qm7SbqA7JfX98t9dtJ0kxfI1Di4X6KlaKoTWTnnL+6nb9A8zYe/xOE0f0jzZ5/h5OWuhBoJ3chxzmP4GNA90sOFQyF78r69/83hhvMkQVp3QK8I9uJcjtdKTF6H1mA7fCFqnaNLk3ckNX+hykhFDcAzAd43ATfyhbSgxnj+9m+RbgskaHg2IwztQXdtHM00TGR5sB0obUWw== 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=jqLgMlxVIbtZuk/UGQ5T3gB7J0875gZ2PL2hNnkiOAs=; b=advhA+85kCTZQPf0DLPYJG3quDpseeyftwBRhPPmIirVIW+TVb3mGeCn3ROyea3QYcI10npDlBKlKtHnzCH/w0jyM2kX8sCpZic4cbxPf/0+u7vDgPz86x9gn/cialL8WRWEBBVAx4WlQsLv2upl/++/2pnA4J3dVOZnsgallp5vzIzrHgq4VrO3i8F2oBeDvpp7+qVnIVPA+YhmbcHoLlLm+NfEzNoNqIDbig1NIkKtCHntBCtGMx0zDU5Qju5L+q5kCn667+uXODXZ4JnbWn7nZxdVkgiGTrD5i4lNb652+mWL0i59b4Lz2cGKmRi2WtzYGOxCM5EDnCvIo9W4hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.linux.dev 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=jqLgMlxVIbtZuk/UGQ5T3gB7J0875gZ2PL2hNnkiOAs=; b=AoAm/hCRkdGz5b5w+8rlPWMZAvaHQYmaLS4bBcYg42AGM+B2BpXb+xZH3IpDaZvCU46R5PNLZdhfJdv4MgaUK7m7+JPKp83k0Yf69ZndmS3PHhOQEGUY8aqPW7RK50gqs28rZbIVOL09P744Km6kvD5TWhHsvbd7SNnPKPeF73U= Received: from PH2PEPF00003857.namprd17.prod.outlook.com (2603:10b6:518:1::79) by MN2PR12MB4391.namprd12.prod.outlook.com (2603:10b6:208:269::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 06:36:45 +0000 Received: from PH5PEPF0000002E.namprd04.prod.outlook.com (2a01:111:f403:c95d::b) by PH2PEPF00003857.outlook.office365.com (2603:1036:903:48::3) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.13 via Frontend Transport; Mon, 30 Nov 2026 06:36:45 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by PH5PEPF0000002E.mail.protection.outlook.com (10.167.243.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Mon, 30 Nov 2026 06:36:45 +0000 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 00:36:45 -0600 Received: from [10.136.44.188] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Mon, 30 Nov 2026 00:36:44 -0600 Message-ID: <5a8d8763-346e-4e38-b707-c91f67e0bcb2@amd.com> Date: Mon, 30 Nov 2026 12:06:43 +0530 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 04/12] KVM: SVM: Enable hardware-assisted LBRv2 virtualization To: CC: , Shivansh Dhiman References: <20261019210532.378628-1-shivansh.dhiman@amd.com> <20261019210532.378628-5-shivansh.dhiman@amd.com> Content-Language: en-US From: Shivansh Dhiman In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH5PEPF0000002E:EE_|MN2PR12MB4391:EE_ X-MS-Office365-Filtering-Correlation-Id: c0db5dd5-ede7-4270-5085-08df4eac4dc5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|36860700016|1800799024|376014|4143699003|18002099003|22082099003|10067099003|11063799006|56012099006|261102123227099003|261028144727099003|261022105027099003|261026121527099003|261026140227099003|261021121427099003|261009223027099003; X-Microsoft-Antispam-Message-Info: mhEfNcSwff8RMkwcwcBJ+FxydkCiUO0ASGUWNQoPY68MYKZeQbkEAlHs3+lx85oaFVm7gaQRPCZNUqxdy58vOt5Ju4R6I4WdH3jHFvpMDquoDGEc4uc6Uyw4bQChF/hexpKLVjzlQYBxgpR1nq74+iPXWmUgfazP0KAZcZIOBCf/4lHAQysDoDn+JEH5haljaods9uld3T0MlPwJ0gkIppUUS3iato6LqSkXega8fJ8mvowi2cTC9prU7IQ8uzwPr3IQmv+4HTmrHwoN/igzR7B/JZK9oUq2Vfkic/iOg5mjPvghem4OAlLSwFT+n7US9YMKjOsvCC9qktFkZYgQ7WWcNe1aWiq9Vrl7O/1wgJVUvZBqbN1rK4q3qDWREkMn+PhP+Oaz2GT599x8rvlqr+F2Fvr72eDkBKPDua/qJCUy49vkTeM/ybC6HKL0Bbt0eR4oa07qafKoCPeqfRvgtuZ0TPYQ3O4el4UJi8EJuy8pzU+HyDsipbeS1ys/5Wj3SSXRhXR/tFbeczkgecB/YzF1t62tfWnkmOGsWxhr0UKrQkYyO7ES7C+sjRk1L8M/dyV7tMrF7Vf0JqrbC02R6a+Pvdnjf5n0+Tn6Y1g52wY3g9s450wjwaFO5spQEyH7r4l+Fqgna93Uhhtlp41J/nus9MozkcTAL6Ri940HJegtowBdNfvVScleAp0wWtoLk4dBlGHMHxY4uyjbrIjXXw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(82310400026)(36860700016)(1800799024)(376014)(4143699003)(18002099003)(22082099003)(10067099003)(11063799006)(56012099006)(261102123227099003)(261028144727099003)(261022105027099003)(261026121527099003)(261026140227099003)(261021121427099003)(261009223027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lzv/V52PFB1z6ha5xvuELbQ3DZ3TTXMUE93Mgj/kxFsuqf7ryi2M9tQi48TcxaM2pISiqdPNFC3uYIHZzq2J+ygRD2CH4abyIMeAXTeBm/fU4aNt55J/XTIEWmNcGSQZUtTz5PDcxAEaW4kwTIFuq9EnC0nP/OCZJ7TF1XQUF+qgKA5BWFXVF0BSdx+Eb968q/Kd5KUur2O36i/zdhYf6STJxlDLNSDuoAB4PPqACuIFM2JwYhsrBbkvN/s//TEzVdM8S6w9uN+z/T+bLdyyTe0C7KMZb12j0KNSRb+jawObL+qAbXJYp8jl9ozWpJ/yNp9yo9ZTa7+2P5Zlqvry2IErZzfLOrPSE40lV7469lfxuosv9TorQON6IgoenE07iHOBam7elD3fELJ0l2dR9NTE3hJ/pbFTDQdqbVp0mfGFnN8tGIYOt+kOzGWAygZX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 06:36:45.5268 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0db5dd5-ede7-4270-5085-08df4eac4dc5 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: PH5PEPF0000002E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4391 On 20-10-26 03:03, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: > - [High] KVM: SVM: Missing VMCB_LBR dirty mark when toggling V_LBR in svm_update_lbrv() > -- > > commit 46b5fce40fe2fd2edafbeb3ed6f81f7158c27cba > Author: Shivansh Dhiman > > KVM: SVM: Enable hardware-assisted LBRv2 virtualization > > This commit enables V_LBR when LBRv2 is active in the guest and passes > the LBRv2 MSRs through to the guest by disabling their intercepts while > branch recording is enabled. > >> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c >> index 428c95d7ef21b..69f9ea746bb6f 100644 >> --- a/arch/x86/kvm/svm/svm.c >> +++ b/arch/x86/kvm/svm/svm.c > > [ ... ] > >> @@ -897,6 +935,9 @@ static bool svm_need_lbr_virtualization(struct kvm_vcpu *vcpu) >> if (svm->vmcb->save.dbgctl & (DEBUGCTLMSR_LBR | DEBUGCTLMSR_BUS_LOCK_DETECT)) >> return true; >> >> + if (svm_lbrv2_active(vcpu)) >> + return true; >> + >> return is_guest_mode(vcpu) && >> (svm->nested.ctl.misc_ctl2 & SVM_MISC2_ENABLE_V_LBR); >> } >> @@ -919,6 +960,7 @@ void svm_update_lbrv(struct kvm_vcpu *vcpu) >> * do, so always recalculate the intercepts here. >> */ >> svm_recalc_lbr_msr_intercepts(vcpu); >> + svm_recalc_lbrv2_msr_intercepts(vcpu); >> } > [...] > Per the AMD APM, VMCB clean bit 10 (VMCB_LBR) covers the LBR virtualization > enable bit (SVM_MISC2_ENABLE_V_LBR) in addition to DBGCTL and the legacy LBR > MSRs. Unlike the MSR_IA32_DEBUGCTLMSR path in svm_set_msr(), neither the > MSR_AMD_DBG_EXTN_CFG handler nor __svm_enable_lbrv() / __svm_disable_lbrv() > marks VMCB_LBR dirty. The VMCB clean bit 10 (LBR) doesn't cover V_LBR bit, as per APM. > > After a previous VMRUN has marked VMCB_LBR clean via vmcb_mark_all_clean() > in svm_vcpu_run(), can toggling DBG_EXTN_CFG_LBRV2EN leave VMCB_LBR clean in > svm->vmcb->control.clean, causing the CPU to use a stale cached value for > SVM_MISC2_ENABLE_V_LBR and DBGCTL on VMRUN while KVM stops manually > switching DEBUGCTL and disables the LBR MSR intercepts? Good point, the stale DBGCTL maybe possible. VMRUN loads DBGCTL from the VMCB only while V_LBR is set. A DBG_EXTN_CFG write can set V_LBR without a DEBUGCTL write, so VMCB_LBR can stay clean and VMRUN can use a stale cached DBGCTL. > > Should __svm_enable_lbrv() and __svm_disable_lbrv() call > vmcb_mark_dirty(svm->vmcb, VMCB_LBR)? I think it is better to mark VMCB_LBR dirty in the MSR_AMD_DBG_EXTN_CFG case of svm_set_msr(), the same as commit dc55b3c3f612 ("KVM: SVM: Mark VMCB_LBR dirty when MSR_IA32_DEBUGCTLMSR is updated").