Skip to content

Commit 252b6fd

Browse files
schlacfrankjaa
authored andcommitted
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 <[email protected]> Reviewed-by: Claudio Imbrenda <[email protected]> Reviewed-by: Janosch Frank <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Janosch Frank <[email protected]> Message-ID: <[email protected]>
1 parent 09c38ad commit 252b6fd

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

tools/testing/selftests/kvm/include/s390x/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#define PAGE_PROTECT 0x200 /* HW read-only bit */
2222
#define PAGE_NOEXEC 0x100 /* HW no-execute bit */
2323

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+
2429
/* Is there a portable way to do this? */
2530
static inline void cpu_relax(void)
2631
{

tools/testing/selftests/kvm/lib/s390x/processor.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void virt_arch_pgd_alloc(struct kvm_vm *vm)
1414
{
1515
vm_paddr_t paddr;
1616

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",
1818
vm->page_size);
1919

2020
if (vm->pgd_created)
@@ -79,7 +79,7 @@ void virt_arch_pg_map(struct kvm_vm *vm, uint64_t gva, uint64_t gpa)
7979
}
8080

8181
/* Fill in page table entry */
82-
idx = (gva >> 12) & 0x0ffu; /* page index */
82+
idx = (gva >> PAGE_SHIFT) & 0x0ffu; /* page index */
8383
if (!(entry[idx] & PAGE_INVALID))
8484
fprintf(stderr,
8585
"WARNING: PTE for gpa=0x%"PRIx64" already set!\n", gpa);
@@ -91,7 +91,7 @@ vm_paddr_t addr_arch_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
9191
int ri, idx;
9292
uint64_t *entry;
9393

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",
9595
vm->page_size);
9696

9797
entry = addr_gpa2hva(vm, vm->pgd);
@@ -103,7 +103,7 @@ vm_paddr_t addr_arch_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
103103
entry = addr_gpa2hva(vm, entry[idx] & REGION_ENTRY_ORIGIN);
104104
}
105105

106-
idx = (gva >> 12) & 0x0ffu; /* page index */
106+
idx = (gva >> PAGE_SHIFT) & 0x0ffu; /* page index */
107107

108108
TEST_ASSERT(!(entry[idx] & PAGE_INVALID),
109109
"No page mapping for vm virtual address 0x%lx", gva);
@@ -168,7 +168,7 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id)
168168
struct kvm_sregs sregs;
169169
struct kvm_vcpu *vcpu;
170170

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",
172172
vm->page_size);
173173

174174
stack_vaddr = __vm_vaddr_alloc(vm, stack_size,

tools/testing/selftests/kvm/s390x/cmma_test.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
#include "kvm_util.h"
1818
#include "kselftest.h"
1919
#include "ucall_common.h"
20+
#include "processor.h"
2021

2122
#define MAIN_PAGE_COUNT 512
2223

2324
#define TEST_DATA_PAGE_COUNT 512
2425
#define TEST_DATA_MEMSLOT 1
25-
#define TEST_DATA_START_GFN 4096
26+
#define TEST_DATA_START_GFN PAGE_SIZE
2627

2728
#define TEST_DATA_TWO_PAGE_COUNT 256
2829
#define TEST_DATA_TWO_MEMSLOT 2
29-
#define TEST_DATA_TWO_START_GFN 8192
30+
#define TEST_DATA_TWO_START_GFN (2 * PAGE_SIZE)
3031

3132
static char cmma_value_buf[MAIN_PAGE_COUNT + TEST_DATA_PAGE_COUNT];
3233

@@ -66,7 +67,7 @@ static void guest_dirty_test_data(void)
6667
" lghi 5,%[page_count]\n"
6768
/* r5 += r1 */
6869
"2: agfr 5,1\n"
69-
/* r2 = r1 << 12 */
70+
/* r2 = r1 << PAGE_SHIFT */
7071
"1: sllg 2,1,12(0)\n"
7172
/* essa(r4, r2, SET_STABLE) */
7273
" .insn rrf,0xb9ab0000,4,2,1,0\n"

tools/testing/selftests/kvm/s390x/memop.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "kvm_util.h"
1717
#include "kselftest.h"
1818
#include "ucall_common.h"
19+
#include "processor.h"
1920

2021
enum mop_target {
2122
LOGICAL,
@@ -226,9 +227,6 @@ static void memop_ioctl(struct test_info info, struct kvm_s390_mem_op *ksmo,
226227

227228
#define CHECK_N_DO(f, ...) ({ f(__VA_ARGS__, CHECK_ONLY); f(__VA_ARGS__); })
228229

229-
#define PAGE_SHIFT 12
230-
#define PAGE_SIZE (1ULL << PAGE_SHIFT)
231-
#define PAGE_MASK (~(PAGE_SIZE - 1))
232230
#define CR0_FETCH_PROTECTION_OVERRIDE (1UL << (63 - 38))
233231
#define CR0_STORAGE_PROTECTION_OVERRIDE (1UL << (63 - 39))
234232

tools/testing/selftests/kvm/s390x/tprot.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
#include "kvm_util.h"
1010
#include "kselftest.h"
1111
#include "ucall_common.h"
12+
#include "processor.h"
1213

13-
#define PAGE_SHIFT 12
14-
#define PAGE_SIZE (1 << PAGE_SHIFT)
1514
#define CR0_FETCH_PROTECTION_OVERRIDE (1UL << (63 - 38))
1615
#define CR0_STORAGE_PROTECTION_OVERRIDE (1UL << (63 - 39))
1716

@@ -151,7 +150,7 @@ static enum stage perform_next_stage(int *i, bool mapped_0)
151150
* instead.
152151
* In order to skip these tests we detect this inside the guest
153152
*/
154-
skip = tests[*i].addr < (void *)4096 &&
153+
skip = tests[*i].addr < (void *)PAGE_SIZE &&
155154
tests[*i].expected != TRANSL_UNAVAIL &&
156155
!mapped_0;
157156
if (!skip) {

0 commit comments

Comments
 (0)