Skip to content

Commit 28b2dce

Browse files
yosrym93sean-jc
authored andcommitted
KVM: selftests: Stop hardcoding PAGE_SIZE in x86 selftests
Use PAGE_SIZE instead of 4096. Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev> Link: https://patch.msgid.link/20251021074736.1324328-9-yosry.ahmed@linux.dev Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3c40777 commit 28b2dce

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

tools/testing/selftests/kvm/x86/hyperv_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall)
9494

9595
if (!(hcall->control & HV_HYPERCALL_FAST_BIT)) {
9696
input = pgs_gpa;
97-
output = pgs_gpa + 4096;
97+
output = pgs_gpa + PAGE_SIZE;
9898
} else {
9999
input = output = 0;
100100
}

tools/testing/selftests/kvm/x86/hyperv_ipi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void sender_guest_code(void *hcall_page, vm_vaddr_t pgs_gpa)
102102
/* 'Slow' HvCallSendSyntheticClusterIpi to RECEIVER_VCPU_ID_1 */
103103
ipi->vector = IPI_VECTOR;
104104
ipi->cpu_mask = 1 << RECEIVER_VCPU_ID_1;
105-
hyperv_hypercall(HVCALL_SEND_IPI, pgs_gpa, pgs_gpa + 4096);
105+
hyperv_hypercall(HVCALL_SEND_IPI, pgs_gpa, pgs_gpa + PAGE_SIZE);
106106
nop_loop();
107107
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_1] == ++ipis_expected[0]);
108108
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_2] == ipis_expected[1]);
@@ -116,13 +116,13 @@ static void sender_guest_code(void *hcall_page, vm_vaddr_t pgs_gpa)
116116
GUEST_SYNC(stage++);
117117

118118
/* 'Slow' HvCallSendSyntheticClusterIpiEx to RECEIVER_VCPU_ID_1 */
119-
memset(hcall_page, 0, 4096);
119+
memset(hcall_page, 0, PAGE_SIZE);
120120
ipi_ex->vector = IPI_VECTOR;
121121
ipi_ex->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
122122
ipi_ex->vp_set.valid_bank_mask = 1 << 0;
123123
ipi_ex->vp_set.bank_contents[0] = BIT(RECEIVER_VCPU_ID_1);
124124
hyperv_hypercall(HVCALL_SEND_IPI_EX | (1 << HV_HYPERCALL_VARHEAD_OFFSET),
125-
pgs_gpa, pgs_gpa + 4096);
125+
pgs_gpa, pgs_gpa + PAGE_SIZE);
126126
nop_loop();
127127
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_1] == ++ipis_expected[0]);
128128
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_2] == ipis_expected[1]);
@@ -138,13 +138,13 @@ static void sender_guest_code(void *hcall_page, vm_vaddr_t pgs_gpa)
138138
GUEST_SYNC(stage++);
139139

140140
/* 'Slow' HvCallSendSyntheticClusterIpiEx to RECEIVER_VCPU_ID_2 */
141-
memset(hcall_page, 0, 4096);
141+
memset(hcall_page, 0, PAGE_SIZE);
142142
ipi_ex->vector = IPI_VECTOR;
143143
ipi_ex->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
144144
ipi_ex->vp_set.valid_bank_mask = 1 << 1;
145145
ipi_ex->vp_set.bank_contents[0] = BIT(RECEIVER_VCPU_ID_2 - 64);
146146
hyperv_hypercall(HVCALL_SEND_IPI_EX | (1 << HV_HYPERCALL_VARHEAD_OFFSET),
147-
pgs_gpa, pgs_gpa + 4096);
147+
pgs_gpa, pgs_gpa + PAGE_SIZE);
148148
nop_loop();
149149
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_1] == ipis_expected[0]);
150150
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_2] == ++ipis_expected[1]);
@@ -160,14 +160,14 @@ static void sender_guest_code(void *hcall_page, vm_vaddr_t pgs_gpa)
160160
GUEST_SYNC(stage++);
161161

162162
/* 'Slow' HvCallSendSyntheticClusterIpiEx to both RECEIVER_VCPU_ID_{1,2} */
163-
memset(hcall_page, 0, 4096);
163+
memset(hcall_page, 0, PAGE_SIZE);
164164
ipi_ex->vector = IPI_VECTOR;
165165
ipi_ex->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
166166
ipi_ex->vp_set.valid_bank_mask = 1 << 1 | 1;
167167
ipi_ex->vp_set.bank_contents[0] = BIT(RECEIVER_VCPU_ID_1);
168168
ipi_ex->vp_set.bank_contents[1] = BIT(RECEIVER_VCPU_ID_2 - 64);
169169
hyperv_hypercall(HVCALL_SEND_IPI_EX | (2 << HV_HYPERCALL_VARHEAD_OFFSET),
170-
pgs_gpa, pgs_gpa + 4096);
170+
pgs_gpa, pgs_gpa + PAGE_SIZE);
171171
nop_loop();
172172
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_1] == ++ipis_expected[0]);
173173
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_2] == ++ipis_expected[1]);
@@ -183,10 +183,10 @@ static void sender_guest_code(void *hcall_page, vm_vaddr_t pgs_gpa)
183183
GUEST_SYNC(stage++);
184184

185185
/* 'Slow' HvCallSendSyntheticClusterIpiEx to HV_GENERIC_SET_ALL */
186-
memset(hcall_page, 0, 4096);
186+
memset(hcall_page, 0, PAGE_SIZE);
187187
ipi_ex->vector = IPI_VECTOR;
188188
ipi_ex->vp_set.format = HV_GENERIC_SET_ALL;
189-
hyperv_hypercall(HVCALL_SEND_IPI_EX, pgs_gpa, pgs_gpa + 4096);
189+
hyperv_hypercall(HVCALL_SEND_IPI_EX, pgs_gpa, pgs_gpa + PAGE_SIZE);
190190
nop_loop();
191191
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_1] == ++ipis_expected[0]);
192192
GUEST_ASSERT(ipis_rcvd[RECEIVER_VCPU_ID_2] == ++ipis_expected[1]);

tools/testing/selftests/kvm/x86/sev_smoke_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void test_sync_vmsa(uint32_t type, uint64_t policy)
104104
vm_sev_launch(vm, policy, NULL);
105105

106106
/* This page is shared, so make it decrypted. */
107-
memset(hva, 0, 4096);
107+
memset(hva, 0, PAGE_SIZE);
108108

109109
vcpu_run(vcpu);
110110

tools/testing/selftests/kvm/x86/state_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void __attribute__((__flatten__)) guest_code(void *arg)
141141

142142
if (this_cpu_has(X86_FEATURE_XSAVE)) {
143143
uint64_t supported_xcr0 = this_cpu_supported_xcr0();
144-
uint8_t buffer[4096];
144+
uint8_t buffer[PAGE_SIZE];
145145

146146
memset(buffer, 0xcc, sizeof(buffer));
147147

tools/testing/selftests/kvm/x86/userspace_io_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
8585
regs.rcx = 1;
8686
if (regs.rcx == 3)
8787
regs.rcx = 8192;
88-
memset((void *)run + run->io.data_offset, 0xaa, 4096);
88+
memset((void *)run + run->io.data_offset, 0xaa, PAGE_SIZE);
8989
vcpu_regs_set(vcpu, &regs);
9090
}
9191

tools/testing/selftests/kvm/x86/vmx_dirty_log_test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ static void test_vmx_dirty_log(bool enable_ept)
122122
if (enable_ept) {
123123
prepare_eptp(vmx, vm, 0);
124124
nested_map_memslot(vmx, vm, 0);
125-
nested_map(vmx, vm, NESTED_TEST_MEM1, GUEST_TEST_MEM, 4096);
126-
nested_map(vmx, vm, NESTED_TEST_MEM2, GUEST_TEST_MEM, 4096);
125+
nested_map(vmx, vm, NESTED_TEST_MEM1, GUEST_TEST_MEM, PAGE_SIZE);
126+
nested_map(vmx, vm, NESTED_TEST_MEM2, GUEST_TEST_MEM, PAGE_SIZE);
127127
}
128128

129129
bmap = bitmap_zalloc(TEST_MEM_PAGES);
130130
host_test_mem = addr_gpa2hva(vm, GUEST_TEST_MEM);
131131

132132
while (!done) {
133-
memset(host_test_mem, 0xaa, TEST_MEM_PAGES * 4096);
133+
memset(host_test_mem, 0xaa, TEST_MEM_PAGES * PAGE_SIZE);
134134
vcpu_run(vcpu);
135135
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
136136

@@ -153,9 +153,9 @@ static void test_vmx_dirty_log(bool enable_ept)
153153
}
154154

155155
TEST_ASSERT(!test_bit(1, bmap), "Page 1 incorrectly reported dirty");
156-
TEST_ASSERT(host_test_mem[4096 / 8] == 0xaaaaaaaaaaaaaaaaULL, "Page 1 written by guest");
156+
TEST_ASSERT(host_test_mem[PAGE_SIZE / 8] == 0xaaaaaaaaaaaaaaaaULL, "Page 1 written by guest");
157157
TEST_ASSERT(!test_bit(2, bmap), "Page 2 incorrectly reported dirty");
158-
TEST_ASSERT(host_test_mem[8192 / 8] == 0xaaaaaaaaaaaaaaaaULL, "Page 2 written by guest");
158+
TEST_ASSERT(host_test_mem[PAGE_SIZE*2 / 8] == 0xaaaaaaaaaaaaaaaaULL, "Page 2 written by guest");
159159
break;
160160
case UCALL_DONE:
161161
done = true;

0 commit comments

Comments
 (0)