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 4/5] KVM: selftests: Check dirty-ring size before enabling
Date: Fri, 9 Oct 2026 14:00:49 +0100 [thread overview]
Message-ID: <20261009130054.3312154-6-leo.bras@arm.com> (raw)
In-Reply-To: <20261009130054.3312154-2-leo.bras@arm.com>
As of today, trying to enable dirty-ring with a size bigger than the
maximum will return an "argument list too long" error.
Change vm_enable_dirty_ring() to get the maximum size, then compare it to
the desired size before enabling. If the value is invalid, print a more
precise error message.
Signed-off-by: Leonardo Bras <leo.bras@arm.com>
---
tools/testing/selftests/kvm/lib/kvm_util.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 9ddc047d5c27..fbd0aaa679d6 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -168,24 +168,36 @@ unsigned int kvm_check_cap(long cap)
ret = __kvm_ioctl(kvm_fd, KVM_CHECK_EXTENSION, (void *)cap);
TEST_ASSERT(ret >= 0, KVM_IOCTL_ERROR(KVM_CHECK_EXTENSION, ret));
kvm_free_fd(kvm_fd);
return (unsigned int)ret;
}
void vm_enable_dirty_ring(struct kvm_vm *vm, u32 ring_size)
{
- if (vm_check_cap(vm, KVM_CAP_DIRTY_LOG_RING_ACQ_REL))
- vm_enable_cap(vm, KVM_CAP_DIRTY_LOG_RING_ACQ_REL, ring_size);
- else
- vm_enable_cap(vm, KVM_CAP_DIRTY_LOG_RING, ring_size);
+ long cap = kvm_get_dirty_ring_cap();
+ int max_size;
+
+ TEST_ASSERT(cap, "Dirty-ring not supported, check CONFIG_HAVE_KVM_DIRTY_RING");
+
+ TEST_ASSERT(is_power_of_2(ring_size),
+ "Dirty-ring size '0x%x' must be a power-of-2", ring_size);
+ TEST_ASSERT(ring_size >= getpagesize(),
+ "Dirty-ring size '0x%x' must be at least one (host) page", ring_size);
+
+ max_size = vm_check_cap(vm, cap);
+ TEST_ASSERT(ring_size <= max_size,
+ "Dirty-ring size '0x%x' is larger than KVM's limit of '0x%x'",
+ ring_size, max_size);
+
+ vm_enable_cap(vm, cap, ring_size);
vm->dirty_ring_size = ring_size;
}
static void vm_open(struct kvm_vm *vm)
{
vm->kvm_fd = _open_kvm_dev_path_or_exit(O_RDWR);
TEST_REQUIRE(kvm_has_cap(KVM_CAP_IMMEDIATE_EXIT));
vm->fd = __kvm_ioctl(vm->kvm_fd, KVM_CREATE_VM, (void *)vm->type);
--
2.55.0
next prev 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 ` [PATCH v2 2/5] KVM: selftests: memstress: Add option to enable dirty-ring on VM creation Leonardo Bras
2026-10-09 13:00 ` [PATCH v2 3/5] KVM: selftests: Introduce kvm_get_dirty_ring_cap() Leonardo Bras
2026-10-09 13:00 ` Leonardo Bras [this message]
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-6-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®