tools/testing/selftests/kvm/s390/debug_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/s390/debug_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kvm/s390/debug_test.c
Extension
.c
Size
4261 bytes
Lines
161
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/* Test KVM debugging features. */
#include "kvm_util.h"
#include "test_util.h"
#include "sie.h"

#include <linux/kvm.h>

#define __LC_SVC_NEW_PSW 0x1c0
#define __LC_PGM_NEW_PSW 0x1d0
#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, u64 *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] = (u64)int_handler;
	memcpy(lowcore + new_psw_off, new_psw, 16);
	vcpu_regs_get(*vcpu, &regs);
	regs.gprs[2] = -1;
	vcpu_regs_set(*vcpu, &regs);
	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;
	u64 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);
	TEST_ASSERT_EQ(vcpu->run->psw_mask, new_psw[0]);
	TEST_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;
	u64 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);
	TEST_ASSERT_EQ(vcpu->run->s390_sieic.icptcode, ICPT_INST);
	TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipa & 0xff00, IPA0_DIAG);
	vcpu_ioctl(vcpu, KVM_S390_IRQ, &irq);

Annotation

Implementation Notes