Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: kvm: s390: Add debug print functions

Add functions to simply print some basic state information in selftests.

The output can be enabled by setting:

#define TH_LOG_ENABLED 1
#define DEBUG 1

* print_psw: current SIE state description and VM run state
* print_hex_bytes: print memory with some counting markers
* print_hex: PRINT_HEX with 512 bytes
* print_run: use print_psw and print_hex to print contents of VM run
state and SIE state description
* print_regs: print content of general and control registers

All prints use pr_debug for the output and can be configured using
DEBUG.

Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com>
Acked-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20240807154512.316936-6-schlameuss@linux.ibm.com
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Message-ID: <20240807154512.316936-6-schlameuss@linux.ibm.com>

authored by

Christoph Schlameuss and committed by
Janosch Frank
100932fc d4f8592f

+69
+69
tools/testing/selftests/kvm/include/s390x/debug_print.h
··· 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 + 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 + 38 + static inline void print_hex(const char *name, u64 addr) 39 + { 40 + print_hex_bytes(name, addr, 512); 41 + } 42 + 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 + 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 + 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 */