Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Siddharth Mishra" <smish149@asu.edu>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: selftests: Test dirty ring pushes from vCPU preemption
Date: Mon, 23 Nov 2026 15:46:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-229603@kernel.org> (raw)
In-Reply-To: <20261123153238.1036972-3-smish149@asu.edu>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] KVM: selftests: duplicate CPU pinning, pthread, and atoi helpers
- [Low] KVM: selftests: 60-second default runtime in
  dirty_ring_steal_time_test
--

commit ed3801d4ab73947519efff505ae4499cdb0daaef
Author: Siddharth Mishra <smish149@asu.edu>

KVM: selftests: Test dirty ring pushes from vCPU preemption

This commit adds an x86 KVM selftest that exercises dirty ring pushes when
a vCPU thread flushing its PML buffer is preempted and updates its
steal-time structure in a dirty-logged memslot.

> diff --git a/tools/testing/selftests/kvm/x86/dirty_ring_steal_time_test.c b/tools/testing/selftests/kvm/x86/dirty_ring_steal_time_test.c
> new file mode 100644
> index 0000000000000..6e65055e8c2dc
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/dirty_ring_steal_time_test.c
> @@ -0,0 +1,146 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +#define _GNU_SOURCE
> +#include <pthread.h>
> +#include <sched.h>
> +#include <stdlib.h>
> +#include <time.h>
> +#include <unistd.h>
> +#include <asm/barrier.h>
> +
> +#include "kvm_util.h"
> +#include "processor.h"
> +#include "ucall_common.h"
> +
> +#define TEST_SLOT		1
> +#define TEST_GPA		0x10000000ul
> +#define TEST_PAGES		16384
> +#define RING_ENTRIES		65536u
> +#define DEFAULT_SECONDS		60

[Severity: Low]
Is a 60-second default runtime too long for a test in TEST_GEN_PROGS_x86?

Because the test is added to TEST_GEN_PROGS_x86 in Makefile.kvm, default
kselftest runs will spin two threads on one CPU for a full minute, using
half of the 120-second timeout in tools/testing/selftests/kvm/settings.
Other race tests in TEST_GEN_PROGS_x86 (such as x86/xapic_ipi_test.c,
x86/recalc_apic_map_test.c, and x86/xen_shinfo_test.c) default to 2-5
seconds and rely on a command-line flag for longer stress runs.

[ ... ]

> +static void pin_self(int cpu)
> +{
> +	cpu_set_t set;
> +
> +	CPU_ZERO(&set);
> +	CPU_SET(cpu, &set);
> +	TEST_ASSERT(!pthread_setaffinity_np(pthread_self(), sizeof(set), &set),
> +		    "Failed to pin to CPU %d", cpu);
> +}

[ ... ]

> +	while ((opt = getopt(argc, argv, "c:t:S")) != -1) {
> +		switch (opt) {
> +		case 'c':
> +			test_cpu = atoi(optarg);
> +			break;
> +		case 't':
> +			seconds = atoi(optarg);
> +			break;

[ ... ]

> +	pin_self(test_cpu);
> +
> +	vm = __vm_create(VM_SHAPE_DEFAULT, 1, 0);

[ ... ]

> +	ring = vcpu_map_dirty_ring(vcpu);
> +	TEST_ASSERT(!pthread_create(&thread, NULL, hog, NULL),
> +		    "Failed to create hog thread");

[ ... ]

> +	WRITE_ONCE(stop_hog, true);
> +	pthread_join(thread, NULL);
> +	kvm_vm_free(vm);
> +	return 0;
> +}

[Severity: Low]
This isn't a bug, but several helpers here duplicate existing KVM selftest
utilities already pulled in via kvm_util.h:

- pin_self() duplicates pin_self_to_cpu() in kvm_util.h.
- atoi(optarg) for -c and -t skips input validation that
  atoi_non_negative() and atoi_positive() in test_util.h provide (for
  example, rejecting a negative CPU index before passing it to CPU_SET()).
- __vm_create(VM_SHAPE_DEFAULT, 1, 0) can use vm_create(1), and the raw
  pthread_create() and pthread_join() calls can use kvm_pthread_create()
  and kvm_pthread_join() from kvm_syscalls.h.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123153238.1036972-1-smish149@asu.edu?part=2

      reply	other threads:[~2026-11-23 15:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:32 [PATCH 0/2] KVM: Fix lost dirty ring entries when a vCPU is preempted Siddharth Mishra
2026-11-23 15:32 ` [PATCH 1/2] KVM: Disable preemption while pushing to the dirty ring Siddharth Mishra
2026-11-23 15:32 ` [PATCH 2/2] KVM: selftests: Test dirty ring pushes from vCPU preemption Siddharth Mishra
2026-11-23 15:46   ` 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-229603@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=smish149@asu.edu \
    /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