From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1AE49331A53; Tue, 24 Feb 2026 22:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771972464; cv=none; b=I3dCHLIhH9szF4KuIYyGMwRR9q2huZBcTQcj2RGOd4kNrsy++5xsktMMbvsQspKUaR7Vq6SMK34qE6a+f/STWLwqnWEssof5mlAmzPOmOEb1E/P1qcKnDP3f0SmMe9g9kXh4CIrxKNqdBB4YmjTDIajkzZvdCH6tmyv2HWYtprU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771972464; c=relaxed/simple; bh=9ShEO/QZRZBcKkoR1itXOhFupVlsvEfFEAnT4eRqWzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fALD/k0+RLa5KqlVXNGkff86z7+RAmsl3wZbKdTZ7Bj94GpjUP4IwnTY/oePvfTP250kovKQI7VmZbBqSStCWLlGDM2wF3evZJgVeEbP6+8wJ7MZ+4B+PWCurV2iX1dHKcEflnMASLjNPyI5GNmgfxXTTmZh1plM9GmRDV6DcAU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r6t5A8AG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r6t5A8AG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BB7FC116D0; Tue, 24 Feb 2026 22:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771972463; bh=9ShEO/QZRZBcKkoR1itXOhFupVlsvEfFEAnT4eRqWzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r6t5A8AG86SBeI03wXSpI6G/WcTEAQ+4bJg8/2NyhEJ5HujejEuoIgom62DT5kMX6 A4Xq/M5aL3/duo2BGRSP80A9ymADvVRTmYtlSo43yC3RWHOYwxuokXCsjvgrdgXVWe 7cfrSI14U7k5biQmVqD7KGhNFU7bAgCbLT5F7mrlNjpo3JmroDrXbPf19FpPGOvcD1 8wD2i6/viAimr+SUgDUuJq6y4xQzt7DAEhCXMx1bkRsHXIEnjBdo459T4mx89hSCX6 8HKzs/RNzkLo4CtyFZsfofwp40s3gOB1ZNN6Cb6/knF2W/OFdh13aXYR32ng7+VR1D wXVilpIdo2xoA== From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , stable@vger.kernel.org Subject: [PATCH v6 06/31] KVM: nSVM: Refactor checking LBRV enablement in vmcb12 into a helper Date: Tue, 24 Feb 2026 22:33:40 +0000 Message-ID: <20260224223405.3270433-7-yosry@kernel.org> X-Mailer: git-send-email 2.53.0.414.gf7e9f6c205-goog In-Reply-To: <20260224223405.3270433-1-yosry@kernel.org> References: <20260224223405.3270433-1-yosry@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Refactor the vCPU cap and vmcb12 flag checks into a helper. The unlikely() annotation is dropped, it's unlikely (huh) to make a difference and the CPU will probably predict it better on its own. CC: stable@vger.kernel.org Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index fab0d3d5baa27..d11cf4968adbe 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -639,6 +639,12 @@ void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm) svm->nested.vmcb02.ptr->save.g_pat = svm->vmcb01.ptr->save.g_pat; } +static bool nested_vmcb12_has_lbrv(struct kvm_vcpu *vcpu) +{ + return guest_cpu_cap_has(vcpu, X86_FEATURE_LBRV) && + (to_svm(vcpu)->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK); +} + static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12) { bool new_vmcb12 = false; @@ -703,8 +709,7 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12 vmcb_mark_dirty(vmcb02, VMCB_DR); } - if (unlikely(guest_cpu_cap_has(vcpu, X86_FEATURE_LBRV) && - (svm->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK))) { + if (nested_vmcb12_has_lbrv(vcpu)) { /* * Reserved bits of DEBUGCTL are ignored. Be consistent with * svm_set_msr's definition of reserved bits. @@ -1232,8 +1237,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) if (!nested_exit_on_intr(svm)) kvm_make_request(KVM_REQ_EVENT, &svm->vcpu); - if (unlikely(guest_cpu_cap_has(vcpu, X86_FEATURE_LBRV) && - (svm->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK))) { + if (nested_vmcb12_has_lbrv(vcpu)) { svm_copy_lbrs(&vmcb12->save, &vmcb02->save); } else { svm_copy_lbrs(&vmcb01->save, &vmcb02->save); -- 2.53.0.414.gf7e9f6c205-goog