[tip:tools/kvm] kvm tools: carefully send and handle debug ipc

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

 



Commit-ID:  c532831900ec181c50d31ed216c2134c197a24d5
Gitweb:     http://git.kernel.org/tip/c532831900ec181c50d31ed216c2134c197a24d5
Author:     Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
AuthorDate: Tue, 20 Dec 2011 17:08:55 +0800
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Wed, 21 Dec 2011 22:28:09 +0200

kvm tools: carefully send and handle debug ipc

Remove struct debug_cmd and use kvm_ipc__send_msg().

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/builtin-debug.c             |   10 +++++-----
 tools/kvm/builtin-run.c               |   13 ++++++++++---
 tools/kvm/include/kvm/builtin-debug.h |    6 ------
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c
index add9b5c..20e27ff 100644
--- a/tools/kvm/builtin-debug.c
+++ b/tools/kvm/builtin-debug.c
@@ -50,18 +50,18 @@ void kvm_debug_help(void)
 static int do_debug(const char *name, int sock)
 {
 	char buff[BUFFER_SIZE];
-	struct debug_cmd cmd = {KVM_IPC_DEBUG, 2 * sizeof(u32)};
+	struct debug_cmd_params cmd = {.dbg_type = 0};
 	int r;
 
 	if (dump)
-		cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_DUMP;
+		cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_DUMP;
 
 	if (nmi != -1) {
-		cmd.params.dbg_type |= KVM_DEBUG_CMD_TYPE_NMI;
-		cmd.params.cpu = nmi;
+		cmd.dbg_type |= KVM_DEBUG_CMD_TYPE_NMI;
+		cmd.cpu = nmi;
 	}
 
-	r = xwrite(sock, &cmd, sizeof(cmd));
+	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 2b45d29..3e28770 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -521,9 +521,16 @@ static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
 static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
 {
 	int i;
-	struct debug_cmd_params *params = (void *)msg;
-	u32 dbg_type = params->dbg_type;
-	u32 vcpu = params->cpu;
+	struct debug_cmd_params *params;
+	u32 dbg_type;
+	u32 vcpu;
+
+	if (WARN_ON(type != KVM_IPC_DEBUG || len != sizeof(*params)))
+		return;
+
+	params = (void *)msg;
+	dbg_type = params->dbg_type;
+	vcpu = params->cpu;
 
 	if (dbg_type & KVM_DEBUG_CMD_TYPE_NMI) {
 		if ((int)vcpu >= kvm->nrcpus)
diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h
index 97df0d97bd..6105a8c 100644
--- a/tools/kvm/include/kvm/builtin-debug.h
+++ b/tools/kvm/include/kvm/builtin-debug.h
@@ -12,12 +12,6 @@ struct debug_cmd_params {
 	u32 cpu;
 };
 
-struct debug_cmd {
-	u32 type;
-	u32 len;
-	struct debug_cmd_params params;
-};
-
 int kvm_cmd_debug(int argc, const char **argv, const char *prefix);
 void kvm_debug_help(void) NORETURN;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux