From nobody Thu Apr 2 19:06:36 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 E3543342C8C for ; Wed, 11 Feb 2026 16:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770827353; cv=none; b=mpIrNG0h2fV2hlbvTXYkLujnfl4FOxwVjnFhoNcaxCxsEpp0YEPHCslpYIMacCk/GyiZroqwFiFiDB3GOTxB2/FpCdCIwD2eFASW8rN76Xx0v9i/kDaj5DZpy1whcwueaTPLnGMrzCRJ2vhpbq9l3HvoYWIxhAm/WFcVkojiojk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770827353; c=relaxed/simple; bh=6YOnt69hh33xI0AM5ZsndXVvbB6SsOgg8IHG8x0zhkQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WQxi9D9kdqBg+VFlWVXMTB58Mtq8yCJzjSNfKPpnpT4agmqVa30fjLctc9Od0CZtCNX0XCvqFfJxhAlEgUqaffImouv6ljgonZH5Kz3QvsisZK9SYFIjPAUf7YrtsHOEGAy7/vP+yg7ef2hQNV5rCRcIgjXsLto/p9ubEpYh3CE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VNqNxvUp; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VNqNxvUp" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770827350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O2sl1XMMR/LmDqFSCtGv6iunZkhUJ85VwJIVaeYY+xw=; b=VNqNxvUpnNBdyNIcW0kZJjPrRRQDf8b0BA8D4qeT+vfpucdebZ3NoJinnWiQ6zZVxdNQcn 5VTi9uHzuN9eEYp8N0tq9qEZGCVITgCBQg/NBEedK251/cHCuDJ+k3NRnEdg3XuHLN4bvi 5BE1Pz6rROxQthyseiTVTeYxy4iLMEI= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v2 3/5] KVM: nSVM: Move sync'ing to vmcb12 cache after completing interrupts Date: Wed, 11 Feb 2026 16:28:40 +0000 Message-ID: <20260211162842.454151-4-yosry.ahmed@linux.dev> In-Reply-To: <20260211162842.454151-1-yosry.ahmed@linux.dev> References: <20260211162842.454151-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" nested_sync_control_from_vmcb02() sync's some fields from vmcb02 to the cached vmcb12 after a VMRUN of L2, mainly to keep the cache up-to-date for save/restore. However, NextRIP is sync'd separately after completing interrupts, as svm_complete_soft_interrupt() may update it (e.g. for soft IRQ re-injection). Move the call to nested_sync_control_from_vmcb02() after completing interrupts, moving the NextRIP sync (and the FIXME) inside it. This keeps the sync code together, and puts the FIXME in a more adequate location, as it applies to most/all fields sync'd by nested_sync_control_from_vmcb02(). Moving the call is safe, as nothing in-between accesses any of the VMCB fields sync'd by nested_sync_control_from_vmcb02(), except NextRIP. Opportunistically make some whitespace fixes. No functional change intended. Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 10 ++++++++-- arch/x86/kvm/svm/svm.c | 26 ++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 9909ff237e5c..6a7c7c5b742a 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -519,9 +519,15 @@ void nested_copy_vmcb_save_to_cache(struct vcpu_svm *s= vm, void nested_sync_control_from_vmcb02(struct vcpu_svm *svm) { u32 mask; - svm->nested.ctl.event_inj =3D svm->vmcb->control.event_inj; - svm->nested.ctl.event_inj_err =3D svm->vmcb->control.event_inj_err; + + /* + * FIXME: Rework svm_get_nested_state() to not pull data from the + * cache (except for maybe int_ctl). + */ + svm->nested.ctl.event_inj =3D svm->vmcb->control.event_inj; + svm->nested.ctl.event_inj_err =3D svm->vmcb->control.event_inj_err; svm->nested.ctl.int_state =3D svm->vmcb->control.int_state; + svm->nested.ctl.next_rip =3D svm->vmcb->control.next_rip; =20 /* Only a few fields of int_ctl are written by the processor. */ mask =3D V_IRQ_MASK | V_TPR_MASK; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1073a32a96fa..458abead9d5b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4399,17 +4399,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm= _vcpu *vcpu, u64 run_flags) sync_cr8_to_lapic(vcpu); =20 svm->next_rip =3D 0; - if (is_guest_mode(vcpu)) { - nested_sync_control_from_vmcb02(svm); - - /* Track VMRUNs that have made past consistency checking */ - if (svm->nested.nested_run_pending && - !svm_is_vmrun_failure(svm->vmcb->control.exit_code)) - ++vcpu->stat.nested_run; - - svm->nested.nested_run_pending =3D 0; - } - svm->vmcb->control.tlb_ctl =3D TLB_CONTROL_DO_NOTHING; =20 /* @@ -4438,12 +4427,17 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kv= m_vcpu *vcpu, u64 run_flags) /* * Update the cache after completing interrupts to get an accurate * NextRIP, e.g. when re-injecting a soft interrupt. - * - * FIXME: Rework svm_get_nested_state() to not pull data from the - * cache (except for maybe int_ctl). */ - if (is_guest_mode(vcpu)) - svm->nested.ctl.next_rip =3D svm->vmcb->control.next_rip; + if (is_guest_mode(vcpu)) { + nested_sync_control_from_vmcb02(svm); + + /* Track VMRUNs that have made past consistency checking */ + if (svm->nested.nested_run_pending && + !svm_is_vmrun_failure(svm->vmcb->control.exit_code)) + ++vcpu->stat.nested_run; + + svm->nested.nested_run_pending =3D 0; + } =20 return svm_exit_handlers_fastpath(vcpu); } --=20 2.53.0.239.g8d8fc8a987-goog