Lines Matching +full:self +full:- +full:test
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Test code for the s390x kvm ucontrol interface
39 TEST_REQUIRE((data->effective & CAP_TO_MASK(CAP_SYS_ADMIN)) > 0); in require_ucontrol_admin()
44 /* Test program setting some registers and looping */
86 self->kvm_fd = open_kvm_dev_path_or_exit(); in FIXTURE_SETUP()
87 self->vm_fd = ioctl(self->kvm_fd, KVM_CREATE_VM, KVM_VM_S390_UCONTROL); in FIXTURE_SETUP()
88 ASSERT_GE(self->vm_fd, 0); in FIXTURE_SETUP()
90 kvm_device_attr_get(self->vm_fd, KVM_S390_VM_CPU_MODEL, in FIXTURE_SETUP()
94 self->vcpu_fd = ioctl(self->vm_fd, KVM_CREATE_VCPU, 0); in FIXTURE_SETUP()
95 ASSERT_GE(self->vcpu_fd, 0); in FIXTURE_SETUP()
97 self->kvm_run_size = ioctl(self->kvm_fd, KVM_GET_VCPU_MMAP_SIZE, NULL); in FIXTURE_SETUP()
98 ASSERT_GE(self->kvm_run_size, sizeof(struct kvm_run)) in FIXTURE_SETUP()
99 TH_LOG(KVM_IOCTL_ERROR(KVM_GET_VCPU_MMAP_SIZE, self->kvm_run_size)); in FIXTURE_SETUP()
100 self->run = (struct kvm_run *)mmap(NULL, self->kvm_run_size, in FIXTURE_SETUP()
101 PROT_READ | PROT_WRITE, MAP_SHARED, self->vcpu_fd, 0); in FIXTURE_SETUP()
102 ASSERT_NE(self->run, MAP_FAILED); in FIXTURE_SETUP()
109 self->sie_block = (struct kvm_s390_sie_block *)mmap(NULL, PAGE_SIZE, in FIXTURE_SETUP()
111 self->vcpu_fd, KVM_S390_SIE_PAGE_OFFSET << PAGE_SHIFT); in FIXTURE_SETUP()
112 ASSERT_NE(self->sie_block, MAP_FAILED); in FIXTURE_SETUP()
114 TH_LOG("VM created %p %p", self->run, self->sie_block); in FIXTURE_SETUP()
116 self->base_gpa = 0; in FIXTURE_SETUP()
117 self->code_gpa = self->base_gpa + (3 * SZ_1M); in FIXTURE_SETUP()
119 self->vm_mem = aligned_alloc(SZ_1M, VM_MEM_SIZE); in FIXTURE_SETUP()
120 ASSERT_NE(NULL, self->vm_mem) TH_LOG("malloc failed %u", errno); in FIXTURE_SETUP()
121 self->base_hva = (uintptr_t)self->vm_mem; in FIXTURE_SETUP()
122 self->code_hva = self->base_hva - self->base_gpa + self->code_gpa; in FIXTURE_SETUP()
124 .user_addr = self->base_hva, in FIXTURE_SETUP()
125 .vcpu_addr = self->base_gpa, in FIXTURE_SETUP()
130 rc = ioctl(self->vcpu_fd, KVM_S390_UCAS_MAP, &map); in FIXTURE_SETUP()
134 TH_LOG("page in %p", (void *)self->base_gpa); in FIXTURE_SETUP()
135 rc = ioctl(self->vcpu_fd, KVM_S390_VCPU_FAULT, self->base_gpa); in FIXTURE_SETUP()
137 (void *)self->base_hva, rc, strerror(errno)); in FIXTURE_SETUP()
139 self->sie_block->cpuflags &= ~CPUSTAT_STOPPED; in FIXTURE_SETUP()
144 munmap(self->sie_block, PAGE_SIZE); in FIXTURE_TEARDOWN()
145 munmap(self->run, self->kvm_run_size); in FIXTURE_TEARDOWN()
146 close(self->vcpu_fd); in FIXTURE_TEARDOWN()
147 close(self->vm_fd); in FIXTURE_TEARDOWN()
148 close(self->kvm_fd); in FIXTURE_TEARDOWN()
149 free(self->vm_mem); in FIXTURE_TEARDOWN()
155 EXPECT_EQ(0, self->sie_block->ecb & ECB_SPECI); in TEST_F()
168 rc = ioctl(self->vm_fd, KVM_GET_DEVICE_ATTR, &attr); in TEST_F()
173 rc = ioctl(self->vm_fd, KVM_SET_DEVICE_ATTR, &attr); in TEST_F()
174 EXPECT_EQ(-1, rc); in TEST_F()
183 rc = ioctl(self->vm_fd, KVM_GET_DIRTY_LOG, &dlog); in TEST_F()
184 EXPECT_EQ(-1, rc); in TEST_F()
191 TEST(uc_cap_hpage) in TEST() function
208 /* Test that KVM_CAP_S390_HPAGE_1M can't be enabled for a ucontrol vm */ in TEST()
210 EXPECT_EQ(-1, rc); in TEST()
217 EXPECT_EQ(-1, rc); in TEST()
226 * * fail on codes not expected in the test cases
228 static bool uc_handle_sieic(FIXTURE_DATA(uc_kvm) * self) in uc_handle_sieic() argument
230 struct kvm_s390_sie_block *sie_block = self->sie_block; in uc_handle_sieic()
231 struct kvm_run *run = self->run; in uc_handle_sieic()
235 run->s390_sieic.icptcode, in uc_handle_sieic()
236 run->s390_sieic.ipa, in uc_handle_sieic()
237 run->s390_sieic.ipb); in uc_handle_sieic()
238 switch (run->s390_sieic.icptcode) { in uc_handle_sieic()
245 TEST_FAIL("sie exception on %.4x%.8x", sie_block->ipa, sie_block->ipb); in uc_handle_sieic()
247 TEST_FAIL("UNEXPECTED SIEIC CODE %d", run->s390_sieic.icptcode); in uc_handle_sieic()
253 static bool uc_handle_exit(FIXTURE_DATA(uc_kvm) * self) in uc_handle_exit() argument
255 struct kvm_run *run = self->run; in uc_handle_exit()
257 switch (run->exit_reason) { in uc_handle_exit()
259 return uc_handle_sieic(self); in uc_handle_exit()
261 pr_info("exit_reason %2d not handled\n", run->exit_reason); in uc_handle_exit()
267 static int uc_run_once(FIXTURE_DATA(uc_kvm) * self) in uc_run_once() argument
271 rc = ioctl(self->vcpu_fd, KVM_RUN, NULL); in uc_run_once()
272 print_run(self->run, self->sie_block); in uc_run_once()
273 print_regs(self->run); in uc_run_once()
278 static void uc_assert_diag44(FIXTURE_DATA(uc_kvm) * self) in uc_assert_diag44() argument
280 struct kvm_s390_sie_block *sie_block = self->sie_block; in uc_assert_diag44()
283 TEST_ASSERT_EQ(KVM_EXIT_S390_SIEIC, self->run->exit_reason); in uc_assert_diag44()
284 TEST_ASSERT_EQ(ICPT_INST, sie_block->icptcode); in uc_assert_diag44()
285 TEST_ASSERT_EQ(0x8300, sie_block->ipa); in uc_assert_diag44()
286 TEST_ASSERT_EQ(0x440000, sie_block->ipb); in uc_assert_diag44()
291 struct kvm_sync_regs *sync_regs = &self->run->s.regs; in TEST_F()
292 struct kvm_run *run = self->run; in TEST_F()
297 sync_regs->gprs[i] = 8; in TEST_F()
298 run->kvm_dirty_regs |= KVM_SYNC_GPRS; in TEST_F()
302 &test_gprs_asm, (void *)self->code_hva, (void *)self->code_gpa); in TEST_F()
303 memcpy((void *)self->code_hva, &test_gprs_asm, PAGE_SIZE); in TEST_F()
306 run->psw_mask = 0x0000000180000000ULL; in TEST_F()
307 run->psw_addr = self->code_gpa; in TEST_F()
310 ASSERT_EQ(0, uc_run_once(self)); in TEST_F()
311 ASSERT_EQ(false, uc_handle_exit(self)); in TEST_F()
312 uc_assert_diag44(self); in TEST_F()
315 ASSERT_EQ(0, ioctl(self->vcpu_fd, KVM_GET_REGS, ®s)); in TEST_F()
318 ASSERT_EQ(i, sync_regs->gprs[i]); in TEST_F()
322 ASSERT_EQ(0, uc_run_once(self)); in TEST_F()
323 ASSERT_EQ(false, uc_handle_exit(self)); in TEST_F()
324 uc_assert_diag44(self); in TEST_F()
327 ASSERT_EQ(0, ioctl(self->vcpu_fd, KVM_GET_REGS, ®s)); in TEST_F()
329 ASSERT_EQ(1, sync_regs->gprs[0]); in TEST_F()