Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: kvm: s390: Define page sizes in shared header

Multiple test cases need page size and shift definitions.
By moving the definitions to a single architecture specific header we
limit the repetition.

Make use of PAGE_SIZE, PAGE_SHIFT and PAGE_MASK defines in existing
code.

Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20240807154512.316936-2-schlameuss@linux.ibm.com
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Message-ID: <20240807154512.316936-2-schlameuss@linux.ibm.com>

authored by

Christoph Schlameuss and committed by
Janosch Frank
252b6fd2 09c38ad0

+17 -14
+5
tools/testing/selftests/kvm/include/s390x/processor.h
··· 21 21 #define PAGE_PROTECT 0x200 /* HW read-only bit */ 22 22 #define PAGE_NOEXEC 0x100 /* HW no-execute bit */ 23 23 24 + /* Page size definitions */ 25 + #define PAGE_SHIFT 12 26 + #define PAGE_SIZE BIT_ULL(PAGE_SHIFT) 27 + #define PAGE_MASK (~(PAGE_SIZE - 1)) 28 + 24 29 /* Is there a portable way to do this? */ 25 30 static inline void cpu_relax(void) 26 31 {
+5 -5
tools/testing/selftests/kvm/lib/s390x/processor.c
··· 14 14 { 15 15 vm_paddr_t paddr; 16 16 17 - TEST_ASSERT(vm->page_size == 4096, "Unsupported page size: 0x%x", 17 + TEST_ASSERT(vm->page_size == PAGE_SIZE, "Unsupported page size: 0x%x", 18 18 vm->page_size); 19 19 20 20 if (vm->pgd_created) ··· 79 79 } 80 80 81 81 /* Fill in page table entry */ 82 - idx = (gva >> 12) & 0x0ffu; /* page index */ 82 + idx = (gva >> PAGE_SHIFT) & 0x0ffu; /* page index */ 83 83 if (!(entry[idx] & PAGE_INVALID)) 84 84 fprintf(stderr, 85 85 "WARNING: PTE for gpa=0x%"PRIx64" already set!\n", gpa); ··· 91 91 int ri, idx; 92 92 uint64_t *entry; 93 93 94 - TEST_ASSERT(vm->page_size == 4096, "Unsupported page size: 0x%x", 94 + TEST_ASSERT(vm->page_size == PAGE_SIZE, "Unsupported page size: 0x%x", 95 95 vm->page_size); 96 96 97 97 entry = addr_gpa2hva(vm, vm->pgd); ··· 103 103 entry = addr_gpa2hva(vm, entry[idx] & REGION_ENTRY_ORIGIN); 104 104 } 105 105 106 - idx = (gva >> 12) & 0x0ffu; /* page index */ 106 + idx = (gva >> PAGE_SHIFT) & 0x0ffu; /* page index */ 107 107 108 108 TEST_ASSERT(!(entry[idx] & PAGE_INVALID), 109 109 "No page mapping for vm virtual address 0x%lx", gva); ··· 168 168 struct kvm_sregs sregs; 169 169 struct kvm_vcpu *vcpu; 170 170 171 - TEST_ASSERT(vm->page_size == 4096, "Unsupported page size: 0x%x", 171 + TEST_ASSERT(vm->page_size == PAGE_SIZE, "Unsupported page size: 0x%x", 172 172 vm->page_size); 173 173 174 174 stack_vaddr = __vm_vaddr_alloc(vm, stack_size,
+4 -3
tools/testing/selftests/kvm/s390x/cmma_test.c
··· 17 17 #include "kvm_util.h" 18 18 #include "kselftest.h" 19 19 #include "ucall_common.h" 20 + #include "processor.h" 20 21 21 22 #define MAIN_PAGE_COUNT 512 22 23 23 24 #define TEST_DATA_PAGE_COUNT 512 24 25 #define TEST_DATA_MEMSLOT 1 25 - #define TEST_DATA_START_GFN 4096 26 + #define TEST_DATA_START_GFN PAGE_SIZE 26 27 27 28 #define TEST_DATA_TWO_PAGE_COUNT 256 28 29 #define TEST_DATA_TWO_MEMSLOT 2 29 - #define TEST_DATA_TWO_START_GFN 8192 30 + #define TEST_DATA_TWO_START_GFN (2 * PAGE_SIZE) 30 31 31 32 static char cmma_value_buf[MAIN_PAGE_COUNT + TEST_DATA_PAGE_COUNT]; 32 33 ··· 67 66 " lghi 5,%[page_count]\n" 68 67 /* r5 += r1 */ 69 68 "2: agfr 5,1\n" 70 - /* r2 = r1 << 12 */ 69 + /* r2 = r1 << PAGE_SHIFT */ 71 70 "1: sllg 2,1,12(0)\n" 72 71 /* essa(r4, r2, SET_STABLE) */ 73 72 " .insn rrf,0xb9ab0000,4,2,1,0\n"
+1 -3
tools/testing/selftests/kvm/s390x/memop.c
··· 16 16 #include "kvm_util.h" 17 17 #include "kselftest.h" 18 18 #include "ucall_common.h" 19 + #include "processor.h" 19 20 20 21 enum mop_target { 21 22 LOGICAL, ··· 227 226 228 227 #define CHECK_N_DO(f, ...) ({ f(__VA_ARGS__, CHECK_ONLY); f(__VA_ARGS__); }) 229 228 230 - #define PAGE_SHIFT 12 231 - #define PAGE_SIZE (1ULL << PAGE_SHIFT) 232 - #define PAGE_MASK (~(PAGE_SIZE - 1)) 233 229 #define CR0_FETCH_PROTECTION_OVERRIDE (1UL << (63 - 38)) 234 230 #define CR0_STORAGE_PROTECTION_OVERRIDE (1UL << (63 - 39)) 235 231
+2 -3
tools/testing/selftests/kvm/s390x/tprot.c
··· 9 9 #include "kvm_util.h" 10 10 #include "kselftest.h" 11 11 #include "ucall_common.h" 12 + #include "processor.h" 12 13 13 - #define PAGE_SHIFT 12 14 - #define PAGE_SIZE (1 << PAGE_SHIFT) 15 14 #define CR0_FETCH_PROTECTION_OVERRIDE (1UL << (63 - 38)) 16 15 #define CR0_STORAGE_PROTECTION_OVERRIDE (1UL << (63 - 39)) 17 16 ··· 150 151 * instead. 151 152 * In order to skip these tests we detect this inside the guest 152 153 */ 153 - skip = tests[*i].addr < (void *)4096 && 154 + skip = tests[*i].addr < (void *)PAGE_SIZE && 154 155 tests[*i].expected != TRANSL_UNAVAIL && 155 156 !mapped_0; 156 157 if (!skip) {