20
20
#include <unistd.h>
21
21
22
22
#include <linux/compiler.h>
23
+ #include <linux/sizes.h>
23
24
24
25
#include <test_util.h>
25
26
#include <kvm_util.h>
26
27
#include <processor.h>
27
28
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
30
33
#define MEM_AUX_GPA MEM_GPA
31
34
#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 )
34
37
35
38
/*
36
39
* 32 MiB is max size that gets well over 100 iterations on 509 slots.
37
40
* Considering that each slot needs to have at least one page up to
38
41
* 8194 slots in use can then be tested (although with slightly
39
42
* limited resolution).
40
43
*/
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 )
43
46
44
47
/*
45
48
* 128 MiB is min size that fills 32k slots with at least one page in each
46
49
* while at the same time gets 100+ iterations in such test
47
50
*
48
51
* 2 MiB chunk size like a typical huge page
49
52
*/
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
52
55
53
56
/*
54
57
* For the move active test the middle of the test area is placed on
64
67
*
65
68
* architecture slots memory-per-slot memory-on-last-slot
66
69
* --------------------------------------------------------------
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
71
74
*/
72
- #define MEM_TEST_MOVE_SIZE 0x10000
75
+ #define MEM_TEST_MOVE_SIZE (3 * SZ_64K)
73
76
#define MEM_TEST_MOVE_GPA_DEST (MEM_GPA + MEM_SIZE)
74
77
static_assert (MEM_TEST_MOVE_SIZE <= MEM_TEST_SIZE ,
75
78
"invalid move test region size" );
@@ -533,7 +536,6 @@ static bool test_memslot_move_prepare(struct vm_data *data,
533
536
uint64_t * maxslots , bool isactive )
534
537
{
535
538
uint32_t guest_page_size = data -> vm -> page_size ;
536
- uint64_t move_pages = MEM_TEST_MOVE_SIZE / guest_page_size ;
537
539
uint64_t movesrcgpa , movetestgpa ;
538
540
539
541
movesrcgpa = vm_slot2gpa (data , data -> nslots - 1 );
@@ -542,7 +544,7 @@ static bool test_memslot_move_prepare(struct vm_data *data,
542
544
uint64_t lastpages ;
543
545
544
546
vm_gpa2hva (data , movesrcgpa , & lastpages );
545
- if (lastpages < move_pages / 2 ) {
547
+ if (lastpages * guest_page_size < MEM_TEST_MOVE_SIZE / 2 ) {
546
548
* maxslots = 0 ;
547
549
return false;
548
550
}
@@ -808,13 +810,13 @@ static const struct test_data tests[] = {
808
810
},
809
811
{
810
812
.name = "unmap" ,
811
- .mem_size = MEM_TEST_UNMAP_SIZE + 4096 ,
813
+ .mem_size = MEM_TEST_UNMAP_SIZE + MEM_EXTRA_SIZE ,
812
814
.guest_code = guest_code_test_memslot_unmap ,
813
815
.loop = test_memslot_unmap_loop ,
814
816
},
815
817
{
816
818
.name = "unmap chunked" ,
817
- .mem_size = MEM_TEST_UNMAP_SIZE + 4096 ,
819
+ .mem_size = MEM_TEST_UNMAP_SIZE + MEM_EXTRA_SIZE ,
818
820
.guest_code = guest_code_test_memslot_unmap ,
819
821
.loop = test_memslot_unmap_loop_chunked ,
820
822
},
@@ -874,8 +876,15 @@ static void help(char *name, struct test_args *targs)
874
876
875
877
static bool check_memory_sizes (void )
876
878
{
879
+ uint32_t host_page_size = getpagesize ();
877
880
uint32_t guest_page_size = vm_guest_mode_params [VM_MODE_DEFAULT ].page_size ;
878
881
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
+
879
888
if (MEM_SIZE % guest_page_size ||
880
889
MEM_TEST_SIZE % guest_page_size ) {
881
890
pr_info ("invalid MEM_SIZE or MEM_TEST_SIZE\n" );
0 commit comments