[PATCH] kvm tools: support injecting arbitrary sysrqs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 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 20e27ff..4ae51d2 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 a120fe2..750d30c 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 852aea4..956307c 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 df8ef53..e954551 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 6105a8c..efa0268 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);
-- 
1.7.8.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux