]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: carefully send and handle debug ipc
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 20 Dec 2011 09:08:55 +0000 (17:08 +0800)
committerPekka Enberg <penberg@kernel.org>
Wed, 21 Dec 2011 20:28:09 +0000 (22:28 +0200)
Remove struct debug_cmd and use kvm_ipc__send_msg().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-debug.c
tools/kvm/builtin-run.c
tools/kvm/include/kvm/builtin-debug.h

index add9b5c4460f6912fa9d5be973b5d3222edde6f9..20e27ff980f145638d5b06d94fc34ac7db06869a 100644 (file)
@@ -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;
 
index 2b45d29a6197746b69c5da097b07573906e74792..3e287706bb90a542d59509c049e670915ee3f8c8 100644 (file)
@@ -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)
index 97df0d97bdc95fe4de5be81f02d1c4527fe747aa..6105a8c487c06a34039820ed8563cc081cf3c83c 100644 (file)
@@ -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;