From: sashiko-bot@kernel.org
To: "David Woodhouse" <dwmw2@infradead.org>, kvm@vger.kernel.org
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH v3 12/15] KVM: SVM: Support CR0 and CR4 write filters
Date: Fri, 27 Nov 2026 15:49:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-237785@kernel.org> (raw)
In-Reply-To: <20261127152730.99319-13-dwmw2@infradead.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: SVM: unnecessary INTERCEPT_CR0_WRITE for non-TS/MP
filters and L2 guests
--
commit 94f59c3becb8e9910d861b5136b68fa9775be16d
Author: David Woodhouse <dwmw@amazon.co.uk>
KVM: SVM: Support CR0 and CR4 write filters
This commit adds support for CR0 and CR4 register write filters on SVM by
keeping INTERCEPT_CR0_WRITE enabled while a CR0 filter is armed and
checking for filtered writes in cr_interception().
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 4ffb41234dc25..c91467a59e201 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -1135,6 +1135,22 @@ static void svm_recalc_intercepts(struct kvm_vcpu *vcpu)
> svm_recalc_msr_intercepts(vcpu);
> }
>
> +static void svm_update_reg_write_filter(struct kvm_vcpu *vcpu)
> +{
> + struct vcpu_svm *svm = to_svm(vcpu);
> +
> + /*
> + * CR4 writes are always intercepted. CR0 writes are not when the
> + * guest and host views agree (hcr0 == cr0): force the intercept in
> + * vmcb01 while a CR0 filter is armed. Disarming leaves the
> + * intercept in place - a forced intercept only costs exits, which
> + * cr_interception() handles as usual - and the next svm_set_cr0(),
> + * which respects the filter, restores its own state.
> + */
> + if (vcpu->arch.reg_write_filter_armed & BIT(KVM_X86_REG_FILTER_CR0))
> + svm_set_intercept(svm, INTERCEPT_CR0_WRITE);
> +}
> +
> static void init_vmcb(struct kvm_vcpu *vcpu, bool init_event)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
> @@ -1867,7 +1883,13 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
> if (hcr0 == cr0) {
> /* Selective CR0 write remains on. */
> svm_clr_intercept(svm, INTERCEPT_CR0_READ);
> - svm_clr_intercept(svm, INTERCEPT_CR0_WRITE);
> + /*
> + * The selective intercept misses writes that change only
> + * TS or MP, and CLTS: a CR0 write filter needs them all.
> + */
> + if (!(vcpu->arch.reg_write_filter_armed &
> + BIT(KVM_X86_REG_FILTER_CR0)))
> + svm_clr_intercept(svm, INTERCEPT_CR0_WRITE);
> } else {
> svm_set_intercept(svm, INTERCEPT_CR0_READ);
> svm_set_intercept(svm, INTERCEPT_CR0_WRITE);
[Severity: Medium]
Should INTERCEPT_CR0_WRITE only be forced when
vcpu->arch.reg_write_filter[KVM_X86_REG_FILTER_CR0] intersects
SVM_CR0_SELECTIVE_MASK (and when not running in L2 guest mode)?
INTERCEPT_SELECTIVE_CR0 is always enabled and already traps writes to any
CR0 bit outside CR0.TS and CR0.MP. Forcing INTERCEPT_CR0_WRITE for any
armed CR0 filter causes every guest CLTS and TS/MP-only CR0 write to
VM-exit (with CLTS falling back to the instruction emulator in
cr_interception() because CR_VALID is clear), even when userspace only
filters bits like CR0.WP.
Because nested_vmcb02_recalc_intercepts() copies vmcb01's intercepts into
vmcb02 and svm_set_cr0() also runs during nested entry, this also forces
INTERCEPT_CR0_WRITE on unfiltered L2 guests.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127152730.99319-1-dwmw2@infradead.org?part=12
next prev parent reply other threads:[~2026-11-27 15:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:27 [PATCH v3 00/15] KVM: x86: Exit handling for Hyper-V hcalls, register intercept David Woodhouse
2026-11-27 15:27 ` [PATCH v3 01/15] KVM: selftests: Make the x86 SSE register helpers volatile David Woodhouse
2026-11-27 15:27 ` [PATCH v3 02/15] KVM: Define what completing an exit does with its instruction David Woodhouse
2026-11-27 15:55 ` sashiko-bot
2026-11-27 15:27 ` [PATCH v3 03/15] KVM: x86: Let userspace leave an MSR access alone David Woodhouse
2026-11-27 15:27 ` [PATCH v3 04/15] KVM: selftests: Test MSR accesses which userspace leaves alone David Woodhouse
2026-11-27 15:27 ` [PATCH v3 05/15] KVM: x86: hyper-v: Add KVM_CAP_HYPERV_FORWARD_HCALL David Woodhouse
2026-11-27 15:27 ` [PATCH v3 06/15] KVM: x86: hyper-v: Let userspace leave a hypercall uncompleted David Woodhouse
2026-11-27 15:27 ` [PATCH v3 07/15] KVM: x86: hyper-v: Advertise XMM fast hypercall output David Woodhouse
2026-11-27 15:27 ` [PATCH v3 08/15] KVM: selftests: Add Hyper-V hypercall forwarding test David Woodhouse
2026-11-27 15:27 ` [PATCH v3 09/15] KVM: x86: Add a per-vCPU register write filter David Woodhouse
2026-11-27 15:27 ` [PATCH v3 10/15] KVM: x86: Filter emulated CR0 and CR4 writes David Woodhouse
2026-11-27 15:48 ` sashiko-bot
2026-11-27 15:27 ` [PATCH v3 11/15] KVM: VMX: Support CR0 and CR4 write filters David Woodhouse
2026-11-27 15:27 ` [PATCH v3 12/15] KVM: SVM: " David Woodhouse
2026-11-27 15:49 ` sashiko-bot [this message]
2026-11-27 15:27 ` [PATCH v3 13/15] KVM: x86: Add descriptor-table registers to the write filter David Woodhouse
2026-11-27 15:52 ` sashiko-bot
2026-11-27 15:27 ` [PATCH v3 14/15] KVM: selftests: Add x86 register write filter test David Woodhouse
2026-11-27 15:27 ` [PATCH v3 15/15] KVM: selftests: Test the register write filter with a nested guest David Woodhouse
2026-11-27 15:47 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-237785@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox