From b9ff7703a707da888a43c2c164cd1b13ef562ad6 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 22 Jul 2012 18:29:51 +0200 Subject: [PATCH] kvm tools: support injecting arbitrary sysrqs Add support to 'lkvm debug' to inject arbitrary sysrqs using a new '-s ' argument. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/builtin-debug.c | 7 +++++++ tools/kvm/builtin-run.c | 5 ++++- tools/kvm/hw/serial.c | 7 +++---- tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/include/kvm/builtin-debug.h | 2 ++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c index 20e27ff980f1..4ae51d200374 100644 --- a/tools/kvm/builtin-debug.c +++ b/tools/kvm/builtin-debug.c @@ -16,6 +16,7 @@ static bool all; static int nmi = -1; static bool dump; static const char *instance_name; +static const char *sysrq; static const char * const debug_usage[] = { "lkvm debug [--all] [-n name] [-d] [-m vcpu]", @@ -26,6 +27,7 @@ static const struct option debug_options[] = { OPT_GROUP("General options:"), OPT_BOOLEAN('d', "dump", &dump, "Generate a debug dump from guest"), OPT_INTEGER('m', "nmi", &nmi, "Generate NMI on VCPU"), + OPT_STRING('s', "sysrq", &sysrq, "sysrq", "Inject a sysrq"), OPT_GROUP("Instance options:"), OPT_BOOLEAN('a', "all", &all, "Debug all instances"), OPT_STRING('n', "name", &instance_name, "name", "Instance name"), @@ -61,6 +63,11 @@ static int do_debug(const char *name, int sock) cmd.cpu = nmi; } + if (sysrq) { + cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_SYSRQ; + cmd.sysrq = sysrq[0]; + } + r = kvm_ipc__send_msg(sock, KVM_IPC_DEBUG, sizeof(cmd), (u8 *)&cmd); if (r < 0) return r; diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index a120fe27ab3b..21d5f341f5d0 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -557,6 +557,9 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg) dbg_type = params->dbg_type; vcpu = params->cpu; + if (dbg_type & KVM_DEBUG_CMD_TYPE_SYSRQ) + serial8250__inject_sysrq(kvm, params->sysrq); + if (dbg_type & KVM_DEBUG_CMD_TYPE_NMI) { if ((int)vcpu >= kvm->nrcpus) return; @@ -589,7 +592,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg) close(fd); - serial8250__inject_sysrq(kvm); + serial8250__inject_sysrq(kvm, 'p'); } static void handle_sigalrm(int sig) diff --git a/tools/kvm/hw/serial.c b/tools/kvm/hw/serial.c index 852aea423c8a..956307c5d539 100644 --- a/tools/kvm/hw/serial.c +++ b/tools/kvm/hw/serial.c @@ -153,14 +153,13 @@ static void serial8250_update_irq(struct kvm *kvm, struct serial8250_device *dev } #define SYSRQ_PENDING_NONE 0 -#define SYSRQ_PENDING_BREAK 1 static int sysrq_pending; static void serial8250__sysrq(struct kvm *kvm, struct serial8250_device *dev) { dev->lsr |= UART_LSR_DR | UART_LSR_BI; - dev->rxbuf[dev->rxcnt++] = 'p'; + dev->rxbuf[dev->rxcnt++] = sysrq_pending; sysrq_pending = SYSRQ_PENDING_NONE; } @@ -219,9 +218,9 @@ void serial8250__update_consoles(struct kvm *kvm) } } -void serial8250__inject_sysrq(struct kvm *kvm) +void serial8250__inject_sysrq(struct kvm *kvm, char sysrq) { - sysrq_pending = SYSRQ_PENDING_BREAK; + sysrq_pending = sysrq; } static struct serial8250_device *find_device(u16 port) diff --git a/tools/kvm/include/kvm/8250-serial.h b/tools/kvm/include/kvm/8250-serial.h index df8ef5308385..e9545517351c 100644 --- a/tools/kvm/include/kvm/8250-serial.h +++ b/tools/kvm/include/kvm/8250-serial.h @@ -6,6 +6,6 @@ struct kvm; int serial8250__init(struct kvm *kvm); int serial8250__exit(struct kvm *kvm); void serial8250__update_consoles(struct kvm *kvm); -void serial8250__inject_sysrq(struct kvm *kvm); +void serial8250__inject_sysrq(struct kvm *kvm, char sysrq); #endif /* KVM__8250_SERIAL_H */ diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h index 6105a8c487c0..efa0268402b3 100644 --- a/tools/kvm/include/kvm/builtin-debug.h +++ b/tools/kvm/include/kvm/builtin-debug.h @@ -6,10 +6,12 @@ #define KVM_DEBUG_CMD_TYPE_DUMP (1 << 0) #define KVM_DEBUG_CMD_TYPE_NMI (1 << 1) +#define KVM_DEBUG_CMD_TYPE_SYSRQ (1 << 2) struct debug_cmd_params { u32 dbg_type; u32 cpu; + char sysrq; }; int kvm_cmd_debug(int argc, const char **argv, const char *prefix); -- 2.39.5