mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leonardo Bras <leo.bras@arm.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	David Matlack <dmatlack@google.com>,
	Yosry Ahmed <yosry@kernel.org>, Marc Zyngier <maz@kernel.org>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	Oliver Upton <oupton@kernel.org>,
	Leonardo Bras <leo.bras@arm.com>,
	Ackerley Tng <ackerleytng@google.com>,
	Josh Hilke <jrhilke@google.com>,
	Wu Fei <wu.fei9@sanechips.com.cn>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/5] KVM: selftests: memstress: Add option to enable dirty-ring on VM creation
Date: Fri,  9 Oct 2026 14:00:47 +0100	[thread overview]
Message-ID: <20261009130054.3312154-4-leo.bras@arm.com> (raw)
In-Reply-To: <20261009130054.3312154-2-leo.bras@arm.com>

Dirty-ring should be enabled after the VM is created, but before the
creation of any cpu. To to so, add an option on memstress_create_vm() that
takes dirty-ring size, and enables it at the correct moment.

This required a new function memstress_vm_create_with_vcpus() to be
created based on the previously used __vm_create_with_vcpus();

Signed-off-by: Leonardo Bras <leo.bras@arm.com>
---
 .../testing/selftests/kvm/include/memstress.h |  1 +
 tools/testing/selftests/kvm/lib/memstress.c   | 27 +++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/memstress.h b/tools/testing/selftests/kvm/include/memstress.h
index cea2062e1dcb..465edf0da8f3 100644
--- a/tools/testing/selftests/kvm/include/memstress.h
+++ b/tools/testing/selftests/kvm/include/memstress.h
@@ -53,20 +53,21 @@ struct memstress_args {
 	struct memstress_vcpu_args vcpu_args[KVM_MAX_VCPUS];
 };
 
 struct memstress_params {
 	enum vm_guest_mode mode;
 	int nr_vcpus;
 	u64 vcpu_memory_bytes;
 	int slots;
 	enum vm_mem_backing_src_type backing_src;
 	bool partition_vcpu_memory_access;
+	u32 dirty_ring_size;
 };
 
 extern struct memstress_args memstress_args;
 
 struct kvm_vm *memstress_create_vm(struct memstress_params *params);
 void memstress_destroy_vm(struct kvm_vm *vm);
 
 void memstress_set_write_percent(struct kvm_vm *vm, u32 write_percent);
 void memstress_set_random_access(struct kvm_vm *vm, bool random_access);
 
diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c
index 880657df65e9..b1f13499e85f 100644
--- a/tools/testing/selftests/kvm/lib/memstress.c
+++ b/tools/testing/selftests/kvm/lib/memstress.c
@@ -114,20 +114,41 @@ void memstress_setup_vcpus(struct kvm_vm *vm, int nr_vcpus,
 		}
 
 		vcpu_args_set(vcpus[i], 1, i);
 
 		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
 			 i, vcpu_args->gpa, vcpu_args->gpa +
 			 (vcpu_args->pages * args->guest_page_size));
 	}
 }
 
+static struct kvm_vm *memstress_vm_create_with_vcpus(struct memstress_params *params,
+						     u64 extra_mem_pages)
+{
+	struct kvm_vm *vm;
+	int i;
+
+	TEST_ASSERT(params->nr_vcpus > 0, "Invalid number of vCPUs (%d)",
+		    params->nr_vcpus);
+
+	vm = __vm_create(VM_SHAPE(params->mode), params->nr_vcpus, extra_mem_pages);
+
+	if (params->dirty_ring_size)
+		vm_enable_dirty_ring(vm, params->dirty_ring_size);
+
+	for (i = 0; i < params->nr_vcpus; ++i)
+		vcpus[i] = vm_vcpu_add(vm, i, memstress_guest_code);
+
+	kvm_arch_vm_finalize_vcpus(vm);
+	return vm;
+}
+
 struct kvm_vm *memstress_create_vm(struct memstress_params *params)
 {
 	struct memstress_args *args = &memstress_args;
 	struct kvm_vm *vm;
 	u64 guest_num_pages, slot0_pages = 0;
 	u64 backing_src_pagesz = get_backing_src_pagesz(params->backing_src);
 	u64 region_end_gfn;
 	int i;
 
 	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(params->mode));
@@ -158,25 +179,21 @@ struct kvm_vm *memstress_create_vm(struct memstress_params *params)
 	 * in-memory data structures.
 	 */
 	if (args->nested)
 		slot0_pages += memstress_nested_pages(params->nr_vcpus);
 
 	/*
 	 * Pass guest_num_pages to populate the page tables for test memory.
 	 * The memory is also added to memslot 0, but that's a benign side
 	 * effect as KVM allows aliasing HVAs in meslots.
 	 */
-	vm = __vm_create_with_vcpus(VM_SHAPE(params->mode),
-				    params->nr_vcpus,
-				    slot0_pages + guest_num_pages,
-				    memstress_guest_code, vcpus);
-
+	vm = memstress_vm_create_with_vcpus(params, slot0_pages + guest_num_pages);
 	args->vm = vm;
 
 	/* Put the test region at the top guest physical memory. */
 	region_end_gfn = vm->max_gfn + 1;
 
 #ifdef __x86_64__
 	/*
 	 * When running vCPUs in L2, restrict the test region to 48 bits to
 	 * avoid needing 5-level page tables to identity map L2.
 	 */
-- 
2.55.0


  parent reply	other threads:[~2026-10-09 13:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 13:00 [PATCH v2 0/5] KVM: selftests: Add support for dirty-ring on dirty_log_perf_test Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 1/5] KVM: selftests: memstress: Add struct memstress_params, make memstress_create_vm() use it Leonardo Bras
2026-10-09 13:00 ` Leonardo Bras [this message]
2026-10-09 13:00 ` [PATCH v2 3/5] KVM: selftests: Introduce kvm_get_dirty_ring_cap() Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 4/5] KVM: selftests: Check dirty-ring size before enabling Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 5/5] KVM: selftests: dirty_log_perf_test: Add dirty-ring support Leonardo Bras

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=20261009130054.3312154-4-leo.bras@arm.com \
    --to=leo.bras@arm.com \
    --cc=ackerleytng@google.com \
    --cc=dmatlack@google.com \
    --cc=fuad.tabba@linux.dev \
    --cc=imbrenda@linux.ibm.com \
    --cc=jrhilke@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=seiden@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=wu.fei9@sanechips.com.cn \
    --cc=yosry@kernel.org \
    /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

all inboxes | Powered by JetHome®