Commit 226e727b authored by Sasha Levin's avatar Sasha Levin Committed by Will Deacon
Browse files

kvm tools: support injecting arbitrary sysrqs



Add support to 'lkvm debug' to inject arbitrary sysrqs using a new
'-s <sysrq>' argument.

Signed-off-by: default avatarSasha Levin <levinsasha928@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent e2341580
......@@ -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;
......
......@@ -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)
......
......@@ -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)
......
......@@ -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 */
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment