Skip to content

Commit 88a64e6

Browse files
Gavin ShanMarc Zyngier
authored andcommitted
KVM: selftests: memslot_perf_test: Consolidate memory
The addresses and sizes passed to vm_userspace_mem_region_add() and madvise() should be aligned to host page size, which can be 64KB on aarch64. So it's wrong by passing additional fixed 4KB memory area to various tests. Fix it by passing additional fixed 64KB memory area to various tests. We also add checks to ensure that none of host/guest page size exceeds 64KB. MEM_TEST_MOVE_SIZE is fixed up to 192KB either. With this, the following command works fine on 64KB-page-size-host and 4KB-page-size-guest. # ./memslot_perf_test -v -s 512 Signed-off-by: Gavin Shan <[email protected]> Reviewed-by: Maciej S. Szmigiero <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8675c6f commit 88a64e6

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

tools/testing/selftests/kvm/memslot_perf_test.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,38 @@
2020
#include <unistd.h>
2121

2222
#include <linux/compiler.h>
23+
#include <linux/sizes.h>
2324

2425
#include <test_util.h>
2526
#include <kvm_util.h>
2627
#include <processor.h>
2728

28-
#define MEM_SIZE ((512U << 20) + 4096)
29-
#define MEM_GPA 0x10000000UL
29+
#define MEM_EXTRA_SIZE SZ_64K
30+
31+
#define MEM_SIZE (SZ_512M + MEM_EXTRA_SIZE)
32+
#define MEM_GPA SZ_256M
3033
#define MEM_AUX_GPA MEM_GPA
3134
#define MEM_SYNC_GPA MEM_AUX_GPA
32-
#define MEM_TEST_GPA (MEM_AUX_GPA + 4096)
33-
#define MEM_TEST_SIZE (MEM_SIZE - 4096)
35+
#define MEM_TEST_GPA (MEM_AUX_GPA + MEM_EXTRA_SIZE)
36+
#define MEM_TEST_SIZE (MEM_SIZE - MEM_EXTRA_SIZE)
3437

3538
/*
3639
* 32 MiB is max size that gets well over 100 iterations on 509 slots.
3740
* Considering that each slot needs to have at least one page up to
3841
* 8194 slots in use can then be tested (although with slightly
3942
* limited resolution).
4043
*/
41-
#define MEM_SIZE_MAP ((32U << 20) + 4096)
42-
#define MEM_TEST_MAP_SIZE (MEM_SIZE_MAP - 4096)
44+
#define MEM_SIZE_MAP (SZ_32M + MEM_EXTRA_SIZE)
45+
#define MEM_TEST_MAP_SIZE (MEM_SIZE_MAP - MEM_EXTRA_SIZE)
4346

4447
/*
4548
* 128 MiB is min size that fills 32k slots with at least one page in each
4649
* while at the same time gets 100+ iterations in such test
4750
*
4851
* 2 MiB chunk size like a typical huge page
4952
*/
50-
#define MEM_TEST_UNMAP_SIZE (128U << 20)
51-
#define MEM_TEST_UNMAP_CHUNK_SIZE (2U << 20)
53+
#define MEM_TEST_UNMAP_SIZE SZ_128M
54+
#define MEM_TEST_UNMAP_CHUNK_SIZE SZ_2M
5255

5356
/*
5457
* For the move active test the middle of the test area is placed on
@@ -64,12 +67,12 @@
6467
*
6568
* architecture slots memory-per-slot memory-on-last-slot
6669
* --------------------------------------------------------------
67-
* x86-4KB 32763 16KB 100KB
68-
* arm64-4KB 32766 16KB 52KB
69-
* arm64-16KB 32766 16KB 48KB
70-
* arm64-64KB 8192 64KB 64KB
70+
* x86-4KB 32763 16KB 160KB
71+
* arm64-4KB 32766 16KB 112KB
72+
* arm64-16KB 32766 16KB 112KB
73+
* arm64-64KB 8192 64KB 128KB
7174
*/
72-
#define MEM_TEST_MOVE_SIZE 0x10000
75+
#define MEM_TEST_MOVE_SIZE (3 * SZ_64K)
7376
#define MEM_TEST_MOVE_GPA_DEST (MEM_GPA + MEM_SIZE)
7477
static_assert(MEM_TEST_MOVE_SIZE <= MEM_TEST_SIZE,
7578
"invalid move test region size");
@@ -533,7 +536,6 @@ static bool test_memslot_move_prepare(struct vm_data *data,
533536
uint64_t *maxslots, bool isactive)
534537
{
535538
uint32_t guest_page_size = data->vm->page_size;
536-
uint64_t move_pages = MEM_TEST_MOVE_SIZE / guest_page_size;
537539
uint64_t movesrcgpa, movetestgpa;
538540

539541
movesrcgpa = vm_slot2gpa(data, data->nslots - 1);
@@ -542,7 +544,7 @@ static bool test_memslot_move_prepare(struct vm_data *data,
542544
uint64_t lastpages;
543545

544546
vm_gpa2hva(data, movesrcgpa, &lastpages);
545-
if (lastpages < move_pages / 2) {
547+
if (lastpages * guest_page_size < MEM_TEST_MOVE_SIZE / 2) {
546548
*maxslots = 0;
547549
return false;
548550
}
@@ -808,13 +810,13 @@ static const struct test_data tests[] = {
808810
},
809811
{
810812
.name = "unmap",
811-
.mem_size = MEM_TEST_UNMAP_SIZE + 4096,
813+
.mem_size = MEM_TEST_UNMAP_SIZE + MEM_EXTRA_SIZE,
812814
.guest_code = guest_code_test_memslot_unmap,
813815
.loop = test_memslot_unmap_loop,
814816
},
815817
{
816818
.name = "unmap chunked",
817-
.mem_size = MEM_TEST_UNMAP_SIZE + 4096,
819+
.mem_size = MEM_TEST_UNMAP_SIZE + MEM_EXTRA_SIZE,
818820
.guest_code = guest_code_test_memslot_unmap,
819821
.loop = test_memslot_unmap_loop_chunked,
820822
},
@@ -874,8 +876,15 @@ static void help(char *name, struct test_args *targs)
874876

875877
static bool check_memory_sizes(void)
876878
{
879+
uint32_t host_page_size = getpagesize();
877880
uint32_t guest_page_size = vm_guest_mode_params[VM_MODE_DEFAULT].page_size;
878881

882+
if (host_page_size > SZ_64K || guest_page_size > SZ_64K) {
883+
pr_info("Unsupported page size on host (0x%x) or guest (0x%x)\n",
884+
host_page_size, guest_page_size);
885+
return false;
886+
}
887+
879888
if (MEM_SIZE % guest_page_size ||
880889
MEM_TEST_SIZE % guest_page_size) {
881890
pr_info("invalid MEM_SIZE or MEM_TEST_SIZE\n");

0 commit comments

Comments
 (0)