From: sashiko-bot@kernel.org
To: "David Woodhouse" <dwmw2@infradead.org>, kvm@vger.kernel.org
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 20/20] KVM: selftests: Add Xen evtchn vs mmu_notifier race test for HVA caches
Date: Thu, 05 Nov 2026 02:28:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-198461@kernel.org> (raw)
In-Reply-To: <20261105020104.2507083-21-dwmw2@infradead.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] KVM: selftests: commit message claims 20000 sends but TEST_ITERATIONS is 5000
- [Low] KVM: selftests: xen_evtchn_hva_notify_race_test duplicates memslot race test
- [Low] KVM: selftests: unchecked madvise() and raw mmap() in HVA race test
--
commit cf7aec0532723ffed105931f7f5b74967ac26723
Author: David Woodhouse <dwmw@amazon.co.uk>
KVM: selftests: Add Xen evtchn vs mmu_notifier race test for HVA caches
This commit adds a KVM selftest racing a guest EVTCHNOP_send loop against a
host thread invoking MADV_DONTNEED on the userspace page backing the
HVA-based shared_info and vcpu_info caches.
> KVM: selftests: Add Xen evtchn vs mmu_notifier race test for HVA caches
>
> Race a guest EVTCHNOP_send loop against a host thread hammering
> MADV_DONTNEED on the userspace page backing HVA-based shared_info and
> vcpu_info caches. Every madvise zaps the PTE and invalidates both
> gfn_to_pfn_caches; every delivery must refresh through the window
> (hva_to_pfn_retry() retries until the invalidation has finished, then
> faults the page back in) and must succeed. The caches are HVA-based,
> so no memslot semantics excuse a drop: unlike
> xen_evtchn_memslot_race_test, which only pins the no-deadlock claim,
> this test asserts every one of the 20000 sends delivers, and any
> hypercall bounce to userspace fails the test.
>
> This exercises the pfncache invalidation protocol itself — the
> invalidate_start walk, the reader draining for a cache mid-teardown,
> and the handshake between a refresh publishing a new mapping and a
> concurrent invalidation vetoing it — which is where a lifetime bug
> in the cache would live; on a debug kernel one is expected to
> surface as a splat rather than a dropped event.
>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
[Severity: Low]
The commit message states that this test asserts every one of the 20000 sends
delivers, but in tools/testing/selftests/kvm/x86/xen_evtchn_hva_notify_race_test.c
TEST_ITERATIONS is defined as 5000 and guest_code() runs TEST_ITERATIONS
hypercalls:
#define TEST_ITERATIONS 5000
...
for (i = 0; i < TEST_ITERATIONS; i++) {
rc = __xen_hypercall(__HYPERVISOR_event_channel_op,
EVTCHNOP_send, &s);
Should the commit message say 5000 sends to match TEST_ITERATIONS and the
runtime estimate comment in main()?
> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> index c17408f8d61f5..19dc0744f25f8 100644
> --- a/tools/testing/selftests/kvm/Makefile.kvm
> +++ b/tools/testing/selftests/kvm/Makefile.kvm
> @@ -150,6 +150,7 @@ TEST_GEN_PROGS_x86 += x86/debug_regs
> TEST_GEN_PROGS_x86 += x86/tsc_msrs_test
> TEST_GEN_PROGS_x86 += x86/vmx_pmu_caps_test
> TEST_GEN_PROGS_x86 += x86/xen_evtchn_memslot_race_test
> +TEST_GEN_PROGS_x86 += x86/xen_evtchn_hva_notify_race_test
[Severity: Low]
This isn't a bug, but tools/testing/selftests/kvm/x86/xen_evtchn_hva_notify_race_test.c
duplicates most of tools/testing/selftests/kvm/x86/xen_evtchn_memslot_race_test.c,
including the hypercall definitions, struct evtchn_send, VM and vCPU creation,
KVM_XEN_HVM_CONFIG setup, KVM_XEN_ATTR_TYPE_LONG_MODE setup,
KVM_XEN_ATTR_TYPE_EVTCHN IPI loopback routing, worker thread lifecycle,
alarm() watchdog setup, and the vcpu_run() / get_ucall() loop in main().
Since only the backing memory setup (HVA vs GPA/memslot), the churn thread
body (madvise MADV_DONTNEED vs memslot update), and whether KVM_EXIT_XEN
hypercall bounces are tolerated differ between the two tests, could this HVA
mmu_notifier variant be folded into xen_evtchn_memslot_race_test.c as a test
mode or parameter rather than adding a separate standalone binary?
> diff --git a/tools/testing/selftests/kvm/x86/xen_evtchn_hva_notify_race_test.c b/tools/testing/selftests/kvm/x86/xen_evtchn_hva_notify_race_test.c
> new file mode 100644
> index 0000000000000..c105435f63577
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/xen_evtchn_hva_notify_race_test.c
[ ... ]
> +static void *backing_churn(void *arg)
> +{
> + void *backing = arg;
> +
> + while (!atomic_load(&churn_stop))
> + madvise(backing, PAGE_SIZE, MADV_DONTNEED);
> +
> + return NULL;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + struct kvm_vcpu *vcpu;
> + struct kvm_vm *vm;
> + pthread_t thread;
> + struct ucall uc;
> + void *backing;
> + int done = 0;
> +
> + int xen_caps = kvm_check_cap(KVM_CAP_XEN_HVM);
> +
> + TEST_REQUIRE(xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA);
> + TEST_REQUIRE(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND);
> +
> + vm = vm_create_with_one_vcpu(&vcpu, guest_code);
> +
> + /*
> + * The shared_info page and the vcpu_info within it live in plain
> + * anonymous VMM memory, not in any memslot: nothing but the
> + * mmu_notifier churn below can perturb the caches.
> + */
> + backing = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
> + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> + TEST_ASSERT(backing != MAP_FAILED, "mmap of backing page failed");
[ ... ]
> + atomic_store(&churn_stop, true);
> + kvm_pthread_join(thread, NULL);
> + alarm(0);
> +
> + kvm_vm_free(vm);
> + return 0;
> +}
[Severity: Low]
In backing_churn(), madvise(backing, PAGE_SIZE, MADV_DONTNEED) does not check
for errors; if madvise() fails, the churn loop would spin without zapping PTEs
or triggering mmu_notifier invalidations, allowing the test to pass without
exercising the race.
In addition, main() open-codes mmap() + TEST_ASSERT() and exits after
kvm_vm_free(vm) without unmapping backing.
Should backing_churn() and main() use the kvm_madvise(), kvm_mmap(), and
kvm_munmap() helpers from kvm_syscalls.h instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105020104.2507083-1-dwmw2@infradead.org?part=20
next prev parent reply other threads:[~2026-11-05 2:28 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 2:00 [PATCH v2 00/20] KVM: Use atomic SRCU for gfn-to-pfn cache, reinstate guest mode for x86 nesting David Woodhouse
2026-11-05 2:00 ` [PATCH v2 01/20] KVM: x86/xen: Fill the hypercall page with a single guest write David Woodhouse
2026-11-05 2:00 ` [PATCH v2 02/20] KVM: x86/xen: Add KVM_XEN_VCPU_ATTR_TYPE_WRITE_HYPERCALL_PAGE David Woodhouse
2026-11-05 2:00 ` [PATCH v2 03/20] KVM: x86/xen: Extract delivery of event to vCPU into a separate helper David Woodhouse
2026-11-05 2:00 ` [PATCH v2 04/20] KVM: x86/xen: Explicitly tag "shared info" page as never being dirty tracked David Woodhouse
2026-11-05 2:00 ` [PATCH v2 05/20] KVM: x86/xen: Don't dirty track "vCPU info" page David Woodhouse
2026-11-05 2:00 ` [PATCH v2 06/20] KVM: x86: Request the guest TLB flush from record_steal_time() David Woodhouse
2026-11-10 20:19 ` Sean Christopherson
2026-11-10 21:14 ` David Woodhouse
2026-11-05 2:00 ` [PATCH v2 07/20] KVM: selftests: Actually deactivate the HVA-based shared_info cache in xen_shinfo_test David Woodhouse
2026-11-05 2:00 ` [PATCH v2 08/20] KVM: pfncache: Use atomic SRCU for readers instead of a rwlock David Woodhouse
2026-11-05 2:00 ` [PATCH v2 09/20] KVM: x86: Use gfn_to_pfn_cache for steal time / preempted status David Woodhouse
2026-11-05 2:00 ` [PATCH v2 10/20] KVM: pfncache: Add guest-mode pinning (GUEST_USES_PFN successor) David Woodhouse
2026-11-05 2:29 ` sashiko-bot
2026-11-05 2:00 ` [PATCH v2 11/20] KVM: nVMX: Implement cache for L1 MSR bitmap David Woodhouse
2026-11-05 2:00 ` [PATCH v2 12/20] KVM: nVMX: Use pinned pfncache for L1 APIC virtualization pages David Woodhouse
2026-11-05 2:33 ` sashiko-bot
2026-11-05 2:00 ` [PATCH v2 13/20] KVM: x86: Post KVM_REQ_GET_NESTED_STATE_PAGES on memslot updates David Woodhouse
2026-11-05 2:00 ` [PATCH v2 14/20] KVM: selftests: Add nested VMX APIC cache invalidation test David Woodhouse
2026-11-05 2:25 ` sashiko-bot
2026-11-05 2:00 ` [PATCH v2 15/20] KVM: nSVM: Use a gfn_to_pfn_cache for the vmcb12 page David Woodhouse
2026-11-05 2:00 ` [PATCH v2 16/20] KVM: nSVM: Cache L1's MSR permissions map pages David Woodhouse
2026-11-05 2:00 ` [PATCH v2 17/20] KVM: nSVM: Cache L1's IO " David Woodhouse
2026-11-05 2:01 ` [PATCH v2 18/20] KVM: selftests: Add nested transition benchmark David Woodhouse
2026-11-05 2:01 ` [PATCH v2 19/20] KVM: selftests: Add Xen evtchn vs memslot-update race test David Woodhouse
2026-11-05 2:01 ` [PATCH v2 20/20] KVM: selftests: Add Xen evtchn vs mmu_notifier race test for HVA caches David Woodhouse
2026-11-05 2:28 ` sashiko-bot [this message]
2026-11-10 19:52 ` [PATCH v2 00/20] KVM: Use atomic SRCU for gfn-to-pfn cache, reinstate guest mode for x86 nesting David Woodhouse
2026-11-10 20:14 ` Sean Christopherson
2026-11-11 18:38 ` David Woodhouse
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-198461@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.