1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Definition for kernel virtual machines on s390x
4 *
5 * Copyright IBM Corp. 2024
6 *
7 * Authors:
8 * Christoph Schlameuss <schlameuss@linux.ibm.com>
9 */
10
11 #ifndef SELFTEST_KVM_DEBUG_PRINT_H
12 #define SELFTEST_KVM_DEBUG_PRINT_H
13
14 #include "asm/ptrace.h"
15 #include "kvm_util.h"
16 #include "sie.h"
17
print_hex_bytes(const char * name,u64 addr,size_t len)18 static inline void print_hex_bytes(const char *name, u64 addr, size_t len)
19 {
20 u64 pos;
21
22 pr_debug("%s (%p)\n", name, (void *)addr);
23 pr_debug(" 0/0x00---------|");
24 if (len > 8)
25 pr_debug(" 8/0x08---------|");
26 if (len > 16)
27 pr_debug(" 16/0x10--------|");
28 if (len > 24)
29 pr_debug(" 24/0x18--------|");
30 for (pos = 0; pos < len; pos += 8) {
31 if ((pos % 32) == 0)
32 pr_debug("\n %3lu 0x%.3lx ", pos, pos);
33 pr_debug(" %16lx", *((u64 *)(addr + pos)));
34 }
35 pr_debug("\n");
36 }
37
print_hex(const char * name,u64 addr)38 static inline void print_hex(const char *name, u64 addr)
39 {
40 print_hex_bytes(name, addr, 512);
41 }
42
print_psw(struct kvm_run * run,struct kvm_s390_sie_block * sie_block)43 static inline void print_psw(struct kvm_run *run, struct kvm_s390_sie_block *sie_block)
44 {
45 pr_debug("flags:0x%x psw:0x%.16llx:0x%.16llx exit:%u %s\n",
46 run->flags,
47 run->psw_mask, run->psw_addr,
48 run->exit_reason, exit_reason_str(run->exit_reason));
49 pr_debug("sie_block psw:0x%.16llx:0x%.16llx\n",
50 sie_block->psw_mask, sie_block->psw_addr);
51 }
52
print_run(struct kvm_run * run,struct kvm_s390_sie_block * sie_block)53 static inline void print_run(struct kvm_run *run, struct kvm_s390_sie_block *sie_block)
54 {
55 print_hex_bytes("run", (u64)run, 0x150);
56 print_hex("sie_block", (u64)sie_block);
57 print_psw(run, sie_block);
58 }
59
print_regs(struct kvm_run * run)60 static inline void print_regs(struct kvm_run *run)
61 {
62 struct kvm_sync_regs *sync_regs = &run->s.regs;
63
64 print_hex_bytes("GPRS", (u64)sync_regs->gprs, 8 * NUM_GPRS);
65 print_hex_bytes("ACRS", (u64)sync_regs->acrs, 4 * NUM_ACRS);
66 print_hex_bytes("CRS", (u64)sync_regs->crs, 8 * NUM_CRS);
67 }
68
69 #endif /* SELFTEST_KVM_DEBUG_PRINT_H */
70