From: sashiko-bot@kernel.org
To: "Dan Carpenter" <dan@pereq.eu>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
"Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v3 9/9] KVM: arm64: selftests: Test that a vcpu reset clears the vcpu's state
Date: Mon, 30 Nov 2026 09:06:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-240741@kernel.org> (raw)
In-Reply-To: <20261130-double_exception_v3-v3-9-864856664b26@pereq.eu>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] KVM: arm64: selftests: test_reset() fails to test
NESTED_SERROR_PENDING reset
- [Low] KVM: arm64: selftests: inaccurate register names in vcpu_reset
comment and log
--
commit e0dc05479432662821477413d58658908cb2348e
Author: Dan Carpenter <dan@pereq.eu>
KVM: arm64: selftests: Test that a vcpu reset clears the vcpu's state
This commit adds an arm64 KVM selftest verifying that KVM_ARM_VCPU_INIT
resets modified registers, pending SErrors, and pending MMIO reads back to
the state of a freshly initialized vCPU.
> diff --git a/tools/testing/selftests/kvm/arm64/vcpu_reset.c b/tools/testing/selftests/kvm/arm64/vcpu_reset.c
> new file mode 100644
> index 0000000000000..cdc051e4b897e
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/arm64/vcpu_reset.c
> @@ -0,0 +1,210 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * vcpu_reset - Test that resetting a vcpu that has run with KVM_ARM_VCPU_INIT
> + * puts it back in the state of a new vcpu.
> + *
> + * Before the reset, the vcpu has an MMIO read waiting for userspace and a
> + * pending SError, and userspace has written to every register it can. After
> + * the reset, every register must match a new vcpu's, except the ones in
> + * preserved_regs[], which must keep the value userspace wrote, and the
> + * counters, which keep counting. No SError may be pending, and the next
> + * KVM_RUN must not complete the MMIO read.
> + */
[Severity: Low]
This isn't a bug, but this comment refers to preserved_regs[] while the
code uses is_preserved(). Also, the commit message refers to CLIDR_EL1
and CCSIDR as counters that keep counting, whereas those are cache ID
registers in is_preserved() and the counters are KVM_REG_ARM_TIMER_CNT and
KVM_REG_ARM_PTIMER_CNT in is_counter().
[ ... ]
> +static void test_reset(bool el2)
> +{
> + struct kvm_vcpu_events events = {};
> + struct regs new, before, after;
> + struct kvm_vcpu *vcpu, *ref;
> + struct kvm_vm *vm, *ref_vm;
> + u64 i, id;
> +
> + /*
> + * A new vcpu: initialised again to undo what the library set up, and
> + * through its first KVM_RUN without running any code.
> + */
> + ref_vm = create_vcpu(el2, &ref);
> + vcpu_ioctl(ref, KVM_ARM_VCPU_INIT, &ref->init);
> + vcpu_run_complete_io(ref);
> + get_regs(ref, &new);
> +
> + vm = create_vcpu(el2, &vcpu);
> + virt_map(vm, MMIO_ADDR, MMIO_ADDR, 1);
> +
> + vcpu_run(vcpu);
> + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_MMIO);
> + TEST_ASSERT(!vcpu->run->mmio.is_write, "Expected an MMIO read");
> + memset(vcpu->run->mmio.data, 0x5a, sizeof(vcpu->run->mmio.data));
> +
> + events.exception.serror_pending = true;
> + vcpu_events_set(vcpu, &events);
[Severity: Medium]
Does calling vcpu_events_set() after vcpu_run() leave
NESTED_SERROR_PENDING untested when el2 is true?
aarch64_vcpu_setup() sets HCR_EL2_TGE and HCR_EL2_E2H in SYS_HCR_EL2 and
leaves PSTATE.A set, so kvm_serror_undeliverable_at_el2() returns false
and kvm_inject_serror_esr() pends the SError in HCR_EL2_VSE rather than
NESTED_SERROR_PENDING:
arch/arm64/kvm/inject_fault.c:kvm_inject_serror_esr() {
...
if (vcpu_is_el2(vcpu) && kvm_serror_undeliverable_at_el2(vcpu)) {
vcpu_set_vsesr(vcpu, esr);
vcpu_set_flag(vcpu, NESTED_SERROR_PENDING);
return 1;
}
...
}
Because no KVM_RUN exit occurs between vcpu_events_set() and
KVM_ARM_VCPU_INIT, kvm_nested_sync_hwstate() never runs to move
HCR_EL2_VSE into NESTED_SERROR_PENDING, and test_reset(true) would pass
even if kvm_reset_vcpu() failed to clear NESTED_SERROR_PENDING. Calling
vcpu_events_set() before vcpu_run() would let the KVM_EXIT_MMIO exit sync
HCR_EL2_VSE into NESTED_SERROR_PENDING while PSTATE.A keeps the SError
masked during the guest MMIO read.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-double_exception_v3-v3-0-864856664b26@pereq.eu?part=9
prev parent reply other threads:[~2026-11-30 9:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 8:48 [PATCH v3 0/9] KVM: arm64: Fix kvm_reset_vcpu() and SError handling for nested virt Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 1/9] KVM: arm64: nv: Use a vcpu request to reprogram the PMU Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 2/9] KVM: arm64: Drop an incomplete MMIO access when resetting a vcpu Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 3/9] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 " Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 4/9] KVM: arm64: Discard a pending SError " Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 5/9] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu() Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 6/9] KVM: arm64: nv: Replace a pending SError when injecting a new one Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 7/9] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 8/9] KVM: arm64: nv: Re-inject a stored SError after the exit is handled Dan Carpenter
2026-11-30 8:48 ` [PATCH v3 9/9] KVM: arm64: selftests: Test that a vcpu reset clears the vcpu's state Dan Carpenter
2026-11-30 9:06 ` 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-240741@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dan@pereq.eu \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@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