Linux-HyperV List
 help / color / mirror / Atom feed
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 15/15] KVM: selftests: Test the register write filter with a nested guest
Date: Fri, 27 Nov 2026 15:47:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-237780@kernel.org> (raw)
In-Reply-To: <20261127152730.99319-16-dwmw2@infradead.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: selftests: intercepted CR4 write in l2_vmx_code() masks
  clean-vmcs12 bug
--

commit 6862822e0c88af446e20e6806bc0fab3b0651065
Author: David Woodhouse <dwmw@amazon.co.uk>

KVM: selftests: Test the register write filter with a nested guest

This commit adds an x86 KVM selftest to verify XCR0, CR0, and CR4 register
write filter behavior across L1 and L2 on SVM and VMX.

> diff --git a/tools/testing/selftests/kvm/x86/nested_reg_write_filter_test.c b/tools/testing/selftests/kvm/x86/nested_reg_write_filter_test.c
> new file mode 100644
> index 0000000000000..4977b3d5f64bd
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/nested_reg_write_filter_test.c

[ ... ]

> +static void l2_vmx_code(void)
> +{
> +	xsetbv(0, LEGACY);
> +	vmcall();
> +
> +	/* Out to L1 once more, which resumes L2 with vmcs12 as it is. */
> +	vmcall();
> +
> +	/* So L2 still owns this bit, and sets it without an exit. */
> +	set_cr4(get_cr4() | FILTERED_CR4_BIT);
> +
> +	/* These two exit to KVM, which must not filter them. */
> +	set_cr4(get_cr4() | INTERCEPTED_CR4_BIT);
> +	set_cr0(get_cr0() ^ INTERCEPTED_CR0_BIT);
> +	vmcall();
> +}

[Severity: Medium]
Does writing INTERCEPTED_CR4_BIT after FILTERED_CR4_BIT cause the
STAGE_L2_CR4 check in test_vmx() to pass even if KVM fails to update
vcpu->arch.cr4_guest_owned_bits on the second VMRESUME in resume_twice()?

The first VMRESUME in resume_twice() has a dirty vmcs12, so
prepare_vmcs02_rare() clears FILTERED_CR4_BIT in vmcs02's hardware
CR4_GUEST_HOST_MASK.  The nested VM-exit to L1 then clears FILTERED_CR4_BIT
from vcpu->arch.cr4_guest_owned_bits via vmx_refresh_reg_write_filter(),
while vmcs02's hardware CR4_GUEST_HOST_MASK keeps FILTERED_CR4_BIT clear.

Even if the second (clean-vmcs12) VMRESUME skips updating
vcpu->arch.cr4_guest_owned_bits, setting FILTERED_CR4_BIT in L2 updates
hardware GUEST_CR4 without an exit.  The subsequent get_cr4() |
INTERCEPTED_CR4_BIT then reads FILTERED_CR4_BIT = 1 from hardware GUEST_CR4
and triggers a CR4 VM-exit to KVM, where handle_set_cr4() writes the full
register value (including FILTERED_CR4_BIT) into vmcs02's CR4_READ_SHADOW.
When L2 later exits on vmcall(), vmcs12_guest_cr4() pulls FILTERED_CR4_BIT
from CR4_READ_SHADOW into vmcs12->guest_cr4 regardless of
vcpu->arch.cr4_guest_owned_bits.

Setting INTERCEPTED_CR4_BIT before FILTERED_CR4_BIT avoids populating
CR4_READ_SHADOW with FILTERED_CR4_BIT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127152730.99319-1-dwmw2@infradead.org?part=15

      reply	other threads:[~2026-11-27 15:47 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
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 [this message]

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-237780@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