From nobody Fri Apr 3 09:28:15 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA67233AD90 for ; Wed, 18 Feb 2026 23:10:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771456207; cv=none; b=MwKaOffPmjlhcF1SYbkDwlOPQHoHxHBxiyaEnmcK2DbYFpYrees130+YLpjJGnR+rFaDLIlikXF/h919w4KY32tIHVQtpDR/Ir4gLj62P/i4RLOnkL0JPg0DSJM/VZlW1lHNVe0j4rk1+EaZsXwM0A9F74oCFUDf7LlKQ8cydgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771456207; c=relaxed/simple; bh=tM8BjxTRUaM9RBki5MGlHN9TGhISx29jk5LkEA8/YTc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=X1uUPy/QeYQjLaY+5h5VhmHIFzGRJaswOWUfvTMFQl8lcdpiHRAcmrEam7SNRH5GceeqHfzvpVKbq/bmUR3qb/CRKDULLcCJWadUfYT7Z4ZKWrzmNx8/TB1KDm6YPfQOZe/dIZJdr/EUQAEmG6491ya2McAAtrkfrGeu4gjL2Jo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hR22eUF+; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hR22eUF+" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a944e6336eso17580305ad.0 for ; Wed, 18 Feb 2026 15:10:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771456205; x=1772061005; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=BUA1fpDExNjo2szFuuW5OFhmaYWnSXBuESu8pBSWCgY=; b=hR22eUF+8g7QtEJBq7VOsz2TXrp+uV5NPHAoKQt4yQj0syvVNug4hhD79rFkdzUmHb UHP5mvr/jRus8TS2kls8fzii7+PvcPJvr07rowqlVx1Q5PAK0h12tcv6KY/MrrB7fDVw 48el9qr5wjJ/UrGKkChvbH7SJuCcNaOVZpL22kammEcR0Qjc+zlcJQsQEweGhSwc2D80 59IiRwFWImQvOUOZqTA3ZL6hSF7nICOmUw8mZPcVEsAfXrxIpr8cE9bNkgP8ci6p+EN0 xCm3v90ITH6OVFTeW/sPg9293+2v1gF6+MN/i0xdEDGupHfV0hm/jdh5Xxcq8NdfoGXr APOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771456205; x=1772061005; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BUA1fpDExNjo2szFuuW5OFhmaYWnSXBuESu8pBSWCgY=; b=md6QhFAqEYaxk3EwDRL03HQLAZ/jATpWIcICIMwogmkUuU68KL6w3/VxnpceRBL18n aUMYJBahUGuu4dwv73aCDVYQ8CSsPhGgDnpfP9yka9IfD+aN6k6eavYRaq7S/jDSrmxM zCGGiyKIB2QjJxGb1/zrM/b66Wi+wGUtvaG9EDDb46qtgpvWSujKRXYpygyB5Zj3aeQy MiVNS8xasg75TYepK4evUBfTGbDWLQV9HTCFqKxrIWM3VQZUvRFjTTQt02F7Ch4XolTX VDolMXduSbWUpGRnD6zRRcm0T1chFRccgsSSjbYSlXE9dQK5BShQ1HtbVE99p4s0UtFc 1WVg== X-Forwarded-Encrypted: i=1; AJvYcCX0gV9VDPpB9XXhNjxqq//jt6+WbY027Owxd2JP2s8YH5NDTv7tZfsDwc1C1FOIaWKEzIgTYsCTwfaNhUM=@vger.kernel.org X-Gm-Message-State: AOJu0Yyl655W/MtOWf8VeX17pg3lzI14N8T54K2dUohpqSZuBo9hxMwZ s6diksr3F10QHJSNawYQM+Mf4UPkuVZpBPI7kI0ok80sUYDJ8w1jNsKxolIws78nQOnsKdJRrwT sT/0W1g== X-Received: from plbbb9.prod.google.com ([2002:a17:902:bc89:b0:2a8:fb03:a261]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f68d:b0:2aa:e6fa:2f6c with SMTP id d9443c01a7336-2ad50ebcee5mr32304845ad.24.1771456205026; Wed, 18 Feb 2026 15:10:05 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 18 Feb 2026 15:09:52 -0800 In-Reply-To: <20260218230958.2877682-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260218230958.2877682-1-seanjc@google.com> X-Mailer: git-send-email 2.53.0.345.g96ddfc5eaa-goog Message-ID: <20260218230958.2877682-3-seanjc@google.com> Subject: [PATCH v2 2/8] KVM: SVM: Separate recalc_intercepts() into nested vs. non-nested parts From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract the non-nested aspects of recalc_intercepts() into a separate helper, svm_mark_intercepts_dirty(), to make it clear that the call isn't *just* recalculating (vmcb02's) intercepts, and to not bury non-nested code in nested.c. As suggested by Yosry, opportunistically prepend "nested_vmbc02_" to recalc_intercepts() so that it's obvious the function specifically deals with recomputing intercepts for L2. No functional change intended. Cc: Yosry Ahmed Signed-off-by: Sean Christopherson Reviewed-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 9 ++------- arch/x86/kvm/svm/sev.c | 2 +- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/svm/svm.h | 26 ++++++++++++++++++++------ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 66701106a51b..48b60dd6e7a3 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -122,17 +122,12 @@ static bool nested_vmcb_needs_vls_intercept(struct vc= pu_svm *svm) return false; } =20 -void recalc_intercepts(struct vcpu_svm *svm) +void nested_vmcb02_recalc_intercepts(struct vcpu_svm *svm) { struct vmcb_control_area *c, *h; struct vmcb_ctrl_area_cached *g; unsigned int i; =20 - vmcb_mark_dirty(svm->vmcb01.ptr, VMCB_INTERCEPTS); - - if (!is_guest_mode(&svm->vcpu)) - return; - vmcb_mark_dirty(svm->vmcb, VMCB_INTERCEPTS); =20 c =3D &svm->vmcb->control; @@ -918,7 +913,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_s= vm *svm, * Merge guest and host intercepts - must be called with vcpu in * guest-mode to take effect. */ - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static void nested_svm_copy_common_state(struct vmcb *from_vmcb, struct vm= cb *to_vmcb) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index ea515cf41168..03b6dc75a6e8 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -4639,7 +4639,7 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm, bo= ol init_event) if (!sev_vcpu_has_debug_swap(svm)) { vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ); vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE); - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } else { /* * Disable #DB intercept iff DebugSwap is enabled. KVM doesn't diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8f8bc863e214..9e76bf1671da 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -635,7 +635,7 @@ static void set_dr_intercepts(struct vcpu_svm *svm) vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ); vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE); =20 - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static void clr_dr_intercepts(struct vcpu_svm *svm) @@ -644,7 +644,7 @@ static void clr_dr_intercepts(struct vcpu_svm *svm) =20 vmcb->control.intercepts[INTERCEPT_DR] =3D 0; =20 - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static bool msr_write_intercepted(struct kvm_vcpu *vcpu, u32 msr) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index ebd7b36b1ceb..92a1691dc7be 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -357,8 +357,6 @@ struct svm_cpu_data { =20 DECLARE_PER_CPU(struct svm_cpu_data, svm_data); =20 -void recalc_intercepts(struct vcpu_svm *svm); - static __always_inline struct kvm_svm *to_kvm_svm(struct kvm *kvm) { return container_of(kvm, struct kvm_svm, kvm); @@ -486,6 +484,22 @@ static inline bool vmcb12_is_intercept(struct vmcb_ctr= l_area_cached *control, u3 return __vmcb_is_intercept((unsigned long *)&control->intercepts, bit); } =20 +void nested_vmcb02_recalc_intercepts(struct vcpu_svm *svm); + +static inline void svm_mark_intercepts_dirty(struct vcpu_svm *svm) +{ + vmcb_mark_dirty(svm->vmcb01.ptr, VMCB_INTERCEPTS); + + /* + * If L2 is active, recalculate the intercepts for vmcb02 to account + * for the changes made to vmcb01. All intercept configuration is done + * for vmcb01 and then propagated to vmcb02 to combine KVM's intercepts + * with L1's intercepts (from the vmcb12 snapshot). + */ + if (is_guest_mode(&svm->vcpu)) + nested_vmcb02_recalc_intercepts(svm); +} + static inline void set_exception_intercept(struct vcpu_svm *svm, u32 bit) { struct vmcb *vmcb =3D svm->vmcb01.ptr; @@ -493,7 +507,7 @@ static inline void set_exception_intercept(struct vcpu_= svm *svm, u32 bit) WARN_ON_ONCE(bit >=3D 32); vmcb_set_intercept(&vmcb->control, INTERCEPT_EXCEPTION_OFFSET + bit); =20 - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static inline void clr_exception_intercept(struct vcpu_svm *svm, u32 bit) @@ -503,7 +517,7 @@ static inline void clr_exception_intercept(struct vcpu_= svm *svm, u32 bit) WARN_ON_ONCE(bit >=3D 32); vmcb_clr_intercept(&vmcb->control, INTERCEPT_EXCEPTION_OFFSET + bit); =20 - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static inline void svm_set_intercept(struct vcpu_svm *svm, int bit) @@ -512,7 +526,7 @@ static inline void svm_set_intercept(struct vcpu_svm *s= vm, int bit) =20 vmcb_set_intercept(&vmcb->control, bit); =20 - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static inline void svm_clr_intercept(struct vcpu_svm *svm, int bit) @@ -521,7 +535,7 @@ static inline void svm_clr_intercept(struct vcpu_svm *s= vm, int bit) =20 vmcb_clr_intercept(&vmcb->control, bit); =20 - recalc_intercepts(svm); + svm_mark_intercepts_dirty(svm); } =20 static inline bool svm_is_intercept(struct vcpu_svm *svm, int bit) --=20 2.53.0.345.g96ddfc5eaa-goog