From: Tharit Tangkijwanichakul <tharitt97@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: Shuah Khan <shuah@kernel.org>, Marc Zyngier <maz@kernel.org>,
Oliver Upton <oupton@kernel.org>,
Fuad Tabba <fuad.tabba@linux.dev>,
Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Anup Patel <anup@brainfault.org>,
Atish Patra <atish.patra@linux.dev>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org,
linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org,
me@brighamcampbell.com, jkoolstra@xs4all.nl,
Tharit Tangkijwanichakul <tharitt97@gmail.com>
Subject: [PATCH 2/5] KVM: selftests: Use the shared memslot base in memslot_perf_test
Date: Sat, 17 Oct 2026 18:02:10 +0700 [thread overview]
Message-ID: <20261017110213.46199-3-tharitt97@gmail.com> (raw)
In-Reply-To: <20261017110213.46199-1-tharitt97@gmail.com>
Use TEST_MEM_SLOT_BASE for test memslot IDs and account for the
reserved slots when calculating the available slot count. This
prepares memslot_perf_test for reserving slot 1 for library use.
Signed-off-by: Tharit Tangkijwanichakul <tharitt97@gmail.com>
---
.../testing/selftests/kvm/memslot_perf_test.c | 62 +++++++++++--------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c
index e1299611be32..cbb900ab58af 100644
--- a/tools/testing/selftests/kvm/memslot_perf_test.c
+++ b/tools/testing/selftests/kvm/memslot_perf_test.c
@@ -60,7 +60,7 @@
* other memslot(s).
*
* We have different number of memory slots, excluding the reserved
- * memory slot 0, on various architectures and configurations. The
+ * memory slots 0 and 1, on various architectures and configurations. The
* memory size in this test is calculated by picking the maximal
* last memory slot's memory size, with alignment to the largest
* supported page size (64KB). In this way, the selected memory
@@ -68,9 +68,9 @@
*
* architecture slots memory-per-slot memory-on-last-slot
* --------------------------------------------------------------
- * x86-4KB 32763 16KB 160KB
- * arm64-4KB 32766 16KB 112KB
- * arm64-16KB 32766 16KB 112KB
+ * x86-4KB 32762 16KB 176KB
+ * arm64-4KB 32765 16KB 128KB
+ * arm64-16KB 32765 16KB 128KB
* arm64-64KB 8192 64KB 128KB
*/
#define MEM_TEST_MOVE_SIZE (3 * SZ_64K)
@@ -276,7 +276,7 @@ static u64 get_max_slots(struct vm_data *data, u32 host_page_size)
rempages = mempages % pages_per_slot;
if (check_slot_pages(host_page_size, guest_page_size,
pages_per_slot, rempages))
- return slots + 1; /* slot 0 is reserved */
+ return slots + TEST_MEM_SLOT_BASE;
}
return 0;
@@ -313,38 +313,42 @@ static bool prepare_vm(struct vm_data *data, int nslots, u64 *maxslots,
data->hva_slots = malloc(sizeof(*data->hva_slots) * data->nslots);
TEST_ASSERT(data->hva_slots, "malloc() fail");
- pr_info_v("Adding slots 1..%i, each slot with %"PRIu64" pages + %"PRIu64" extra pages last\n",
- data->nslots, data->pages_per_slot, rempages);
+ pr_info_v("Adding slots %u..%u, each slot with %" PRIu64
+ " pages + %" PRIu64 " extra pages last\n",
+ (u32)TEST_MEM_SLOT_BASE,
+ TEST_MEM_SLOT_BASE + data->nslots - 1,
+ data->pages_per_slot, rempages);
clock_gettime(CLOCK_MONOTONIC, &tstart);
- for (slot = 1, guest_addr = MEM_GPA; slot <= data->nslots; slot++) {
+ for (slot = 0, guest_addr = MEM_GPA; slot < data->nslots; slot++) {
u64 npages;
npages = data->pages_per_slot;
- if (slot == data->nslots)
+ if (slot == data->nslots - 1)
npages += rempages;
vm_userspace_mem_region_add(data->vm, VM_MEM_SRC_ANONYMOUS,
- guest_addr, slot, npages,
- 0);
+ guest_addr, TEST_MEM_SLOT_BASE + slot,
+ npages, 0);
guest_addr += npages * guest_page_size;
}
*slot_runtime = timespec_elapsed(tstart);
- for (slot = 1, guest_addr = MEM_GPA; slot <= data->nslots; slot++) {
+ for (slot = 0, guest_addr = MEM_GPA; slot < data->nslots; slot++) {
u64 npages;
gpa_t gpa;
npages = data->pages_per_slot;
- if (slot == data->nslots)
+ if (slot == data->nslots - 1)
npages += rempages;
- gpa = vm_phy_pages_alloc(data->vm, npages, guest_addr, slot);
+ gpa = vm_phy_pages_alloc(data->vm, npages, guest_addr,
+ TEST_MEM_SLOT_BASE + slot);
TEST_ASSERT(gpa == guest_addr,
"vm_phy_pages_alloc() failed");
- data->hva_slots[slot - 1] = addr_gpa2hva(data->vm, guest_addr);
- memset(data->hva_slots[slot - 1], 0, npages * guest_page_size);
+ data->hva_slots[slot] = addr_gpa2hva(data->vm, guest_addr);
+ memset(data->hva_slots[slot], 0, npages * guest_page_size);
guest_addr += npages * guest_page_size;
}
@@ -631,9 +635,10 @@ static void test_memslot_move_loop(struct vm_data *data, struct sync_area *sync)
u64 movesrcgpa;
movesrcgpa = vm_slot2gpa(data, data->nslots - 1);
- vm_mem_region_move(data->vm, data->nslots - 1 + 1,
+ vm_mem_region_move(data->vm, TEST_MEM_SLOT_BASE + data->nslots - 1,
MEM_TEST_MOVE_GPA_DEST);
- vm_mem_region_move(data->vm, data->nslots - 1 + 1, movesrcgpa);
+ vm_mem_region_move(data->vm, TEST_MEM_SLOT_BASE + data->nslots - 1,
+ movesrcgpa);
}
static void test_memslot_do_unmap(struct vm_data *data,
@@ -988,8 +993,10 @@ static bool parse_args(int argc, char *argv[],
#endif
case 's':
targs->nslots = atoi_paranoid(optarg);
- if (targs->nslots <= 1 && targs->nslots != -1) {
- pr_info("Slot count cap must be larger than 1 or -1 for no cap\n");
+ if (targs->nslots <= TEST_MEM_SLOT_BASE &&
+ targs->nslots != -1) {
+ pr_info("Slot count cap must be larger than %d or -1 for no cap\n",
+ TEST_MEM_SLOT_BASE);
return false;
}
break;
@@ -1027,20 +1034,21 @@ static bool parse_args(int argc, char *argv[],
}
max_mem_slots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS);
- if (max_mem_slots <= 1) {
- pr_info("KVM_CAP_NR_MEMSLOTS should be greater than 1\n");
+ if (max_mem_slots <= TEST_MEM_SLOT_BASE) {
+ pr_info("KVM_CAP_NR_MEMSLOTS should be greater than %d\n",
+ TEST_MEM_SLOT_BASE);
return false;
}
- /* Memory slot 0 is reserved */
+ /* Memory slots below TEST_MEM_SLOT_BASE are reserved. */
if (targs->nslots == -1)
- targs->nslots = max_mem_slots - 1;
+ targs->nslots = max_mem_slots - TEST_MEM_SLOT_BASE;
else
- targs->nslots = min_t(int, targs->nslots, max_mem_slots) - 1;
+ targs->nslots = min_t(int, targs->nslots, max_mem_slots)
+ - TEST_MEM_SLOT_BASE;
pr_info_v("Allowed Number of memory slots: %"PRIu32"\n",
- targs->nslots + 1);
-
+ (u32)(targs->nslots + TEST_MEM_SLOT_BASE));
return true;
}
--
2.53.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-10-17 11:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 11:02 [PATCH 0/5] KVM: selftests: Reserve memslot 1 for ucall MMIO Tharit Tangkijwanichakul
2026-10-17 11:02 ` [PATCH 1/5] KVM: selftests: Introduce a shared base for test memslots Tharit Tangkijwanichakul
2026-10-17 11:02 ` Tharit Tangkijwanichakul [this message]
2026-10-17 11:02 ` [PATCH 3/5] KVM: selftests: Use the shared memslot base in memstress Tharit Tangkijwanichakul
2026-10-17 11:02 ` [PATCH 4/5] KVM: selftests: Reserve memslot 1 for the ucall MMIO address Tharit Tangkijwanichakul
2026-10-17 11:02 ` [PATCH 5/5] KVM: selftests: Test protection of the ucall MMIO region Tharit Tangkijwanichakul
2026-10-17 15:25 ` Tharit Tangkijwanichakul
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=20261017110213.46199-3-tharitt97@gmail.com \
--to=tharitt97@gmail.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=fuad.tabba@linux.dev \
--cc=jkoolstra@xs4all.nl \
--cc=joey.gouly@arm.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maz@kernel.org \
--cc=me@brighamcampbell.com \
--cc=oupton@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=pjw@kernel.org \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/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