Message ID | 20240730072413.143556-7-schlameuss@linux.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | selftests: kvm: s390: Add s390x ucontrol selftests | expand |
On 7/30/24 9:24 AM, Christoph Schlameuss wrote: > Add test case running code interacting with registers within a > ucontrol VM. > > * Add uc_gprs test case > > The test uses the same VM setup using the fixture and debug macros > introduced in earlier patches in this series. > > Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com> > --- > .../selftests/kvm/s390x/ucontrol_test.c | 126 ++++++++++++++++++ > 1 file changed, 126 insertions(+) > > diff --git a/tools/testing/selftests/kvm/s390x/ucontrol_test.c b/tools/testing/selftests/kvm/s390x/ucontrol_test.c > index 029233374465..817b1e08559c 100644 > --- a/tools/testing/selftests/kvm/s390x/ucontrol_test.c > +++ b/tools/testing/selftests/kvm/s390x/ucontrol_test.c > @@ -41,6 +41,23 @@ void require_ucontrol_admin(void) > TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_UCONTROL)); > } [...] > +/* verify SIEIC exit > + * * reset stop requests > + * * fail on codes not expected in the test cases > + */ > +static bool uc_handle_sieic(FIXTURE_DATA(uc_kvm) * self) > +{ > + struct kvm_s390_sie_block *sie_block = self->sie_block; > + struct kvm_run *run = self->run; > + > + /* check SIE interception code */ > + pr_info("sieic: 0x%2x 0x%4x 0x%4x\n", I don't think there should be a space before the 4: sieic: 0x 4 0x8300 0x440000 We can automatically add in the missing 0 0x%02x > + run->s390_sieic.icptcode, > + run->s390_sieic.ipa, > + run->s390_sieic.ipb); > + switch (run->s390_sieic.icptcode) { > + case ICPT_STOP: > + /* stopped via sie V P --> ignore */ > + /* reset stop request */ > + sie_block->cpuflags = sie_block->cpuflags & ~CPUSTAT_STOP_INT; > + pr_info("sie V P - cleared %.4x\n", sie_block->cpuflags); > + break; With the added code that removes the P bit this shouldn't be called anymore, no? > + case ICPT_INST: > + /* end execution in caller on intercepted instruction */ > + return false; > + default: > + TEST_FAIL("UNEXPECTED SIEIC CODE %d", run->s390_sieic.icptcode); > + } > + return true; > +}
On Wed, 31 Jul 2024 16:37:19 +0200 Janosch Frank <frankja@linux.ibm.com> wrote: > On 7/30/24 9:24 AM, Christoph Schlameuss wrote: > > Add test case running code interacting with registers within a > > ucontrol VM. > > > > * Add uc_gprs test case > > > > The test uses the same VM setup using the fixture and debug macros > > introduced in earlier patches in this series. > > > > Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com> > > --- > > .../selftests/kvm/s390x/ucontrol_test.c | 126 ++++++++++++++++++ > > 1 file changed, 126 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/s390x/ucontrol_test.c b/tools/testing/selftests/kvm/s390x/ucontrol_test.c > > index 029233374465..817b1e08559c 100644 > > --- a/tools/testing/selftests/kvm/s390x/ucontrol_test.c > > +++ b/tools/testing/selftests/kvm/s390x/ucontrol_test.c > > @@ -41,6 +41,23 @@ void require_ucontrol_admin(void) > > TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_UCONTROL)); > > } > [...] > > +/* verify SIEIC exit > > + * * reset stop requests > > + * * fail on codes not expected in the test cases > > + */ > > +static bool uc_handle_sieic(FIXTURE_DATA(uc_kvm) * self) > > +{ > > + struct kvm_s390_sie_block *sie_block = self->sie_block; > > + struct kvm_run *run = self->run; > > + > > + /* check SIE interception code */ > > + pr_info("sieic: 0x%2x 0x%4x 0x%4x\n", > > I don't think there should be a space before the 4: > sieic: 0x 4 0x8300 0x440000 > > We can automatically add in the missing 0 > 0x%02x > At some point I considered that easier to read without the leading zeroes, but even that is not even true for me any more. I will change that to "sieic: 0x%.2x 0x%.4x 0x%.4x\n". > > + run->s390_sieic.icptcode, > > + run->s390_sieic.ipa, > > + run->s390_sieic.ipb); > > + switch (run->s390_sieic.icptcode) { > > + case ICPT_STOP: > > + /* stopped via sie V P --> ignore */ > > + /* reset stop request */ > > + sie_block->cpuflags = sie_block->cpuflags & ~CPUSTAT_STOP_INT; > > + pr_info("sie V P - cleared %.4x\n", sie_block->cpuflags); > > + break; > > With the added code that removes the P bit this shouldn't be called > anymore, no? > Yes, you are right this is no longer needed. And I will remove it. > > + case ICPT_INST: > > + /* end execution in caller on intercepted instruction */ > > + return false; > > + default: > > + TEST_FAIL("UNEXPECTED SIEIC CODE %d", run->s390_sieic.icptcode); > > + } > > + return true; > > +} >
diff --git a/tools/testing/selftests/kvm/s390x/ucontrol_test.c b/tools/testing/selftests/kvm/s390x/ucontrol_test.c index 029233374465..817b1e08559c 100644 --- a/tools/testing/selftests/kvm/s390x/ucontrol_test.c +++ b/tools/testing/selftests/kvm/s390x/ucontrol_test.c @@ -41,6 +41,23 @@ void require_ucontrol_admin(void) TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_UCONTROL)); } +/* Test program setting some registers and looping */ +extern char test_gprs_asm[]; +asm("test_gprs_asm:\n" + "xgr %r0, %r0\n" + "lgfi %r1,1\n" + "lgfi %r2,2\n" + "lgfi %r3,3\n" + "lgfi %r4,4\n" + "lgfi %r5,5\n" + "lgfi %r6,6\n" + "lgfi %r7,7\n" + "0:\n" + " diag 0,0,0x44\n" + " ahi %r0,1\n" + " j 0b\n" +); + FIXTURE(uc_kvm) { struct kvm_s390_sie_block *sie_block; @@ -205,4 +222,113 @@ TEST(uc_cap_hpage) close(kvm_fd); } +/* verify SIEIC exit + * * reset stop requests + * * fail on codes not expected in the test cases + */ +static bool uc_handle_sieic(FIXTURE_DATA(uc_kvm) * self) +{ + struct kvm_s390_sie_block *sie_block = self->sie_block; + struct kvm_run *run = self->run; + + /* check SIE interception code */ + pr_info("sieic: 0x%2x 0x%4x 0x%4x\n", + run->s390_sieic.icptcode, + run->s390_sieic.ipa, + run->s390_sieic.ipb); + switch (run->s390_sieic.icptcode) { + case ICPT_STOP: + /* stopped via sie V P --> ignore */ + /* reset stop request */ + sie_block->cpuflags = sie_block->cpuflags & ~CPUSTAT_STOP_INT; + pr_info("sie V P - cleared %.4x\n", sie_block->cpuflags); + break; + case ICPT_INST: + /* end execution in caller on intercepted instruction */ + return false; + default: + TEST_FAIL("UNEXPECTED SIEIC CODE %d", run->s390_sieic.icptcode); + } + return true; +} + +/* verify VM state on exit */ +static bool uc_handle_exit(FIXTURE_DATA(uc_kvm) * self) +{ + struct kvm_run *run = self->run; + + switch (run->exit_reason) { + case KVM_EXIT_S390_SIEIC: + return uc_handle_sieic(self); + default: + pr_info("exit_reason %2d not handled\n", run->exit_reason); + } + return true; +} + +/* run the VM until interrupted */ +static int uc_run_once(FIXTURE_DATA(uc_kvm) * self) +{ + int rc; + + rc = ioctl(self->vcpu_fd, KVM_RUN, NULL); + print_run(self->run, self->sie_block); + print_regs(self->run); + pr_debug("run %d / %d %s\n", rc, errno, strerror(errno)); + return rc; +} + +static void uc_assert_diag44(FIXTURE_DATA(uc_kvm) * self) +{ + struct kvm_s390_sie_block *sie_block = self->sie_block; + + /* assert vm was interrupted by diag 0x0044 */ + TEST_ASSERT_EQ(KVM_EXIT_S390_SIEIC, self->run->exit_reason); + TEST_ASSERT_EQ(ICPT_INST, sie_block->icptcode); + TEST_ASSERT_EQ(0x8300, sie_block->ipa); + TEST_ASSERT_EQ(0x440000, sie_block->ipb); +} + +TEST_F(uc_kvm, uc_gprs) +{ + struct kvm_sync_regs *sync_regs = &self->run->s.regs; + struct kvm_run *run = self->run; + struct kvm_regs regs = {}; + + /* Set registers to values that are different from the ones that we expect below */ + for (int i = 0; i < 8; i++) + sync_regs->gprs[i] = 8; + run->kvm_dirty_regs |= KVM_SYNC_GPRS; + + /* copy test_gprs_asm to code_hva / code_gpa */ + TH_LOG("copy code %p to vm mapped memory %p / %p", + &test_gprs_asm, (void *)self->code_hva, (void *)self->code_gpa); + memcpy((void *)self->code_hva, &test_gprs_asm, PAGE_SIZE); + + run->psw_mask = 0x0000000180000000ULL; /* DAT disabled + 64 bit mode */ + run->psw_addr = self->code_gpa; + + /* run and expect interception of diag 44 */ + ASSERT_EQ(0, uc_run_once(self)); + ASSERT_EQ(false, uc_handle_exit(self)); + uc_assert_diag44(self); + + /* Retrieve and check guest register values */ + ASSERT_EQ(0, ioctl(self->vcpu_fd, KVM_GET_REGS, ®s)); + for (int i = 0; i < 8; i++) { + ASSERT_EQ(i, regs.gprs[i]); + ASSERT_EQ(i, sync_regs->gprs[i]); + } + + /* run and expect interception of diag 44 again */ + ASSERT_EQ(0, uc_run_once(self)); + ASSERT_EQ(false, uc_handle_exit(self)); + uc_assert_diag44(self); + + /* check continued increment of register 0 value */ + ASSERT_EQ(0, ioctl(self->vcpu_fd, KVM_GET_REGS, ®s)); + ASSERT_EQ(1, regs.gprs[0]); + ASSERT_EQ(1, sync_regs->gprs[0]); +} + TEST_HARNESS_MAIN
Add test case running code interacting with registers within a ucontrol VM. * Add uc_gprs test case The test uses the same VM setup using the fixture and debug macros introduced in earlier patches in this series. Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com> --- .../selftests/kvm/s390x/ucontrol_test.c | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+)