From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
David Hildenbrand <david@redhat.com>,
Sven Schnelle <svens@linux.ibm.com>,
kvm@vger.kernel.org, linux-s390@vger.kernel.org,
linux-kernel@vger.kernel.org,
Jens Freimann <jfreimann@redhat.com>
Subject: Re: [PATCH v3 6/6] KVM: s390: selftests: Add selftest for single-stepping
Date: Tue, 25 Jul 2023 15:53:25 +0200 [thread overview]
Message-ID: <20230725155325.513ee076@p-imbrenda> (raw)
In-Reply-To: <20230724094716.91510-7-iii@linux.ibm.com>
On Mon, 24 Jul 2023 11:44:12 +0200
Ilya Leoshkevich <iii@linux.ibm.com> wrote:
> Test different variations of single-stepping into interrupts:
>
> - SVC and PGM interrupts;
> - Interrupts generated by ISKE;
> - Interrupts generated by instructions emulated by KVM;
> - Interrupts generated by instructions emulated by userspace.
thank you for writing this selftest!
>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
> tools/testing/selftests/kvm/Makefile | 1 +
> .../testing/selftests/kvm/s390x/debug_test.c | 160 ++++++++++++++++++
> 2 files changed, 161 insertions(+)
> create mode 100644 tools/testing/selftests/kvm/s390x/debug_test.c
>
> diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
> index c692cc86e7da..f3306eaa7031 100644
> --- a/tools/testing/selftests/kvm/Makefile
> +++ b/tools/testing/selftests/kvm/Makefile
> @@ -166,6 +166,7 @@ TEST_GEN_PROGS_s390x += s390x/resets
> TEST_GEN_PROGS_s390x += s390x/sync_regs_test
> TEST_GEN_PROGS_s390x += s390x/tprot
> TEST_GEN_PROGS_s390x += s390x/cmma_test
> +TEST_GEN_PROGS_s390x += s390x/debug_test
> TEST_GEN_PROGS_s390x += demand_paging_test
> TEST_GEN_PROGS_s390x += dirty_log_test
> TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
> diff --git a/tools/testing/selftests/kvm/s390x/debug_test.c b/tools/testing/selftests/kvm/s390x/debug_test.c
> new file mode 100644
> index 000000000000..a8fa9fe93b3c
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/s390x/debug_test.c
> @@ -0,0 +1,160 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/* Test KVM debugging features. */
> +#include "kvm_util.h"
> +#include "test_util.h"
> +
> +#include <linux/kvm.h>
> +
> +#define __LC_SVC_NEW_PSW 0x1c0
> +#define __LC_PGM_NEW_PSW 0x1d0
> +#define ICPT_INSTRUCTION 0x04
> +#define IPA0_DIAG 0x8300
> +#define PGM_SPECIFICATION 0x06
> +
> +/* Common code for testing single-stepping interruptions. */
> +extern char int_handler[];
> +asm("int_handler:\n"
> + "j .\n");
> +
> +static struct kvm_vm *test_step_int_1(struct kvm_vcpu **vcpu, void *guest_code,
> + size_t new_psw_off, uint64_t *new_psw)
> +{
> + struct kvm_guest_debug debug = {};
> + struct kvm_regs regs;
> + struct kvm_vm *vm;
> + char *lowcore;
> +
> + vm = vm_create_with_one_vcpu(vcpu, guest_code);
> + lowcore = addr_gpa2hva(vm, 0);
> + new_psw[0] = (*vcpu)->run->psw_mask;
> + new_psw[1] = (uint64_t)int_handler;
> + memcpy(lowcore + new_psw_off, new_psw, 16);
> + vcpu_regs_get(*vcpu, ®s);
> + regs.gprs[2] = -1;
> + vcpu_regs_set(*vcpu, ®s);
> + debug.control = KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
> + vcpu_guest_debug_set(*vcpu, &debug);
> + vcpu_run(*vcpu);
> +
> + return vm;
> +}
> +
> +static void test_step_int(void *guest_code, size_t new_psw_off)
> +{
> + struct kvm_vcpu *vcpu;
> + uint64_t new_psw[2];
> + struct kvm_vm *vm;
> +
> + vm = test_step_int_1(&vcpu, guest_code, new_psw_off, new_psw);
> + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_DEBUG);
> + ASSERT_EQ(vcpu->run->psw_mask, new_psw[0]);
> + ASSERT_EQ(vcpu->run->psw_addr, new_psw[1]);
> + kvm_vm_free(vm);
> +}
> +
> +/* Test single-stepping "boring" program interruptions. */
> +extern char test_step_pgm_guest_code[];
> +asm("test_step_pgm_guest_code:\n"
> + ".insn rr,0x1d00,%r1,%r0 /* dr %r1,%r0 */\n"
> + "j .\n");
> +
> +static void test_step_pgm(void)
> +{
> + test_step_int(test_step_pgm_guest_code, __LC_PGM_NEW_PSW);
> +}
> +
> +/*
> + * Test single-stepping program interruptions caused by DIAG.
> + * Userspace emulation must not interfere with single-stepping.
> + */
> +extern char test_step_pgm_diag_guest_code[];
> +asm("test_step_pgm_diag_guest_code:\n"
> + "diag %r0,%r0,0\n"
> + "j .\n");
> +
> +static void test_step_pgm_diag(void)
> +{
> + struct kvm_s390_irq irq = {
> + .type = KVM_S390_PROGRAM_INT,
> + .u.pgm.code = PGM_SPECIFICATION,
> + };
> + struct kvm_vcpu *vcpu;
> + uint64_t new_psw[2];
> + struct kvm_vm *vm;
> +
> + vm = test_step_int_1(&vcpu, test_step_pgm_diag_guest_code,
> + __LC_PGM_NEW_PSW, new_psw);
> + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
> + ASSERT_EQ(vcpu->run->s390_sieic.icptcode, ICPT_INSTRUCTION);
> + ASSERT_EQ(vcpu->run->s390_sieic.ipa & 0xff00, IPA0_DIAG);
> + vcpu_ioctl(vcpu, KVM_S390_IRQ, &irq);
> + vcpu_run(vcpu);
> + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_DEBUG);
> + ASSERT_EQ(vcpu->run->psw_mask, new_psw[0]);
> + ASSERT_EQ(vcpu->run->psw_addr, new_psw[1]);
> + kvm_vm_free(vm);
> +}
> +
> +/*
> + * Test single-stepping program interruptions caused by ISKE.
> + * CPUSTAT_KSS handling must not interfere with single-stepping.
> + */
> +extern char test_step_pgm_iske_guest_code[];
> +asm("test_step_pgm_iske_guest_code:\n"
> + "iske %r2,%r2\n"
> + "j .\n");
> +
> +static void test_step_pgm_iske(void)
> +{
> + test_step_int(test_step_pgm_iske_guest_code, __LC_PGM_NEW_PSW);
> +}
> +
> +/*
> + * Test single-stepping program interruptions caused by LCTL.
> + * KVM emulation must not interfere with single-stepping.
> + */
> +extern char test_step_pgm_lctl_guest_code[];
> +asm("test_step_pgm_lctl_guest_code:\n"
> + "lctl %c0,%c0,1\n"
> + "j .\n");
> +
> +static void test_step_pgm_lctl(void)
> +{
> + test_step_int(test_step_pgm_lctl_guest_code, __LC_PGM_NEW_PSW);
> +}
> +
> +/* Test single-stepping supervisor-call interruptions. */
> +extern char test_step_svc_guest_code[];
> +asm("test_step_svc_guest_code:\n"
> + "svc 0\n"
> + "j .\n");
> +
> +static void test_step_svc(void)
> +{
> + test_step_int(test_step_svc_guest_code, __LC_SVC_NEW_PSW);
> +}
> +
> +/* Run all tests above. */
> +static struct testdef {
> + const char *name;
> + void (*test)(void);
> +} testlist[] = {
> + { "single-step pgm", test_step_pgm },
> + { "single-step pgm caused by diag", test_step_pgm_diag },
> + { "single-step pgm caused by iske", test_step_pgm_iske },
> + { "single-step pgm caused by lctl", test_step_pgm_lctl },
> + { "single-step svc", test_step_svc },
> +};
> +
> +int main(int argc, char *argv[])
> +{
> + int idx;
> +
> + ksft_print_header();
> + ksft_set_plan(ARRAY_SIZE(testlist));
> + for (idx = 0; idx < ARRAY_SIZE(testlist); idx++) {
> + testlist[idx].test();
> + ksft_test_result_pass("%s\n", testlist[idx].name);
> + }
> + ksft_finished();
> +}
prev parent reply other threads:[~2023-07-25 13:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 9:44 [PATCH v3 0/6] KVM: s390: interrupt: Fix stepping into interrupt handlers Ilya Leoshkevich
2023-07-24 9:44 ` [PATCH v3 1/6] KVM: s390: interrupt: Fix single-stepping " Ilya Leoshkevich
2023-07-25 11:56 ` Claudio Imbrenda
2023-07-24 9:44 ` [PATCH v3 2/6] KVM: s390: interrupt: Fix single-stepping into program " Ilya Leoshkevich
2023-07-25 8:58 ` Claudio Imbrenda
2023-07-24 9:44 ` [PATCH v3 3/6] KVM: s390: interrupt: Fix single-stepping kernel-emulated instructions Ilya Leoshkevich
2023-07-25 12:04 ` Claudio Imbrenda
2023-07-24 9:44 ` [PATCH v3 4/6] KVM: s390: interrupt: Fix single-stepping userspace-emulated instructions Ilya Leoshkevich
2023-07-24 11:31 ` David Hildenbrand
2023-07-25 12:25 ` Claudio Imbrenda
2023-07-24 9:44 ` [PATCH v3 5/6] KVM: s390: interrupt: Fix single-stepping keyless mode exits Ilya Leoshkevich
2023-07-24 9:44 ` [PATCH v3 6/6] KVM: s390: selftests: Add selftest for single-stepping Ilya Leoshkevich
2023-07-25 13:53 ` Claudio Imbrenda [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230725155325.513ee076@p-imbrenda \
--to=imbrenda@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=jfreimann@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=svens@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox