Skip to contentSkip to conversation

qemu,qmp: convert do_inject_nmi() to QObject, QError

PATCH In review Lai Jiangshan 4 participants 5 messages Dec 10, 2010 – Jan 3, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 qemu,qmp: convert do_inject_nmi() to QObject, QError

Convert do_inject_nmi() to QObject, QError, we need to use it(via libvirt).

changed from v1
Add document.
Add error handling when the cpu index is invalid.

---

hmp-commands.hx +2 -1
index 23024ba..f86d9fe 100644
@@ -724,7 +724,8 @@ ETEXI
         .args_type  = "cpu_index:i",
         .params     = "cpu",
         .help       = "inject an NMI on the given CPU",
-        .mhandler.cmd = do_inject_nmi,
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_inject_nmi,
     },
 #endif
 STEXI
monitor.c +5 -2
index ec31eac..f375eb3 100644
@@ -2119,7 +2119,7 @@ static void do_wav_capture(Monitor *mon, const QDict *qdict)
 #endif
 
 #if defined(TARGET_I386)
-static void do_inject_nmi(Monitor *mon, const QDict *qdict)
+static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     CPUState *env;
     int cpu_index = qdict_get_int(qdict, "cpu_index");
@@ -2127,8 +2127,11 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict)
     for (env = first_cpu; env != NULL; env = env->next_cpu)
         if (env->cpu_index == cpu_index) {
             cpu_interrupt(env, CPU_INTERRUPT_NMI);
-            break;
+            return 0;
         }
+
+    qerror_report(QERR_INVALID_CPU_INDEX, cpu_index);
+    return -1;
 }
 #endif
 
qmp-commands.hx +27 -0
index e5f157f..fcb6bf2 100644
@@ -429,6 +429,33 @@ Example:
 
 EQMP
 
+#if defined(TARGET_I386)
+    {
+        .name       = "inject_nmi",
+        .args_type  = "cpu_index:i",
+        .params     = "cpu",
+        .help       = "inject an NMI on the given CPU",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_inject_nmi,
+    },
+#endif
+SQMP
+inject_nmi
+----------
+
+Inject an NMI on the given CPU (x86 only).
+
+Arguments:
+
+- "cpu_index": the index of the CPU to be injected NMI (json-int)
+
+Example:
+
+-> { "execute": "inject_nmi", "arguments": { "cpu_index": 0 } }
+<- { "return": {} }
+
+EQMP
+
     {
         .name       = "migrate",
         .args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
#1 lore raw
Quoted 36 lines · Lai Jiangshan

Convert do_inject_nmi() to QObject, QError, we need to use it(via libvirt).

changed from v1
Add document.
Add error handling when the cpu index is invalid.

---

hmp-commands.hx +2 -1
index 23024ba..f86d9fe 100644
@@ -724,7 +724,8 @@ ETEXI
         .args_type  = "cpu_index:i",
         .params     = "cpu",
         .help       = "inject an NMI on the given CPU",
-        .mhandler.cmd = do_inject_nmi,
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_inject_nmi,
     },
 #endif
 STEXI
monitor.c +1 -1
index ec31eac..f375eb3 100644
@@ -2119,7 +2119,7 @@ static void do_wav_capture(Monitor *mon, const QDict *qdict)
 #endif
 
 #if defined(TARGET_I386)
-static void do_inject_nmi(Monitor *mon, const QDict *qdict)
+static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     CPUState *env;
     int cpu_index = qdict_get_int(qdict, "cpu_index");

monitor.c static void do_inject_nmi(Monitor *mon, const QDict *qdict) · line 2134

Quoted 9 lines
monitor.c +4 -1
@@ -2127,8 +2127,11 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict)
     for (env = first_cpu; env != NULL; env = env->next_cpu)
         if (env->cpu_index == cpu_index) {
             cpu_interrupt(env, CPU_INTERRUPT_NMI);
-            break;
+            return 0;
         }
+
+    qerror_report(QERR_INVALID_CPU_INDEX, cpu_index);
+    return -1;

do_cpu_set() reports invalud index like this:

        qerror_report(QERR_INVALID_PARAMETER_VALUE, "index",
                      "a CPU number");

What about sticking to that?

[...]

#2 lore raw
In reply to Lai Jiangshan
Quoted 7 lines · On Fri, 10 Dec 2010 14:36:08 +0800 Lai Jiangshan <[email protected]> wrote:
qmp-commands.hx +7 -0
+SQMP
+inject_nmi
+----------
+
+Inject an NMI on the given CPU (x86 only).
+
+Arguments:

qmp-commands.hx Example: · line 458

Quoted 10 lines
qmp-commands.hx +10 -0
+
+- "cpu_index": the index of the CPU to be injected NMI (json-int)
+
+Example:
+
+-> { "execute": "inject_nmi", "arguments": { "cpu_index": 0 } }
+<- { "return": {} }
+
+EQMP
+

Avi, Anthony, can you please review this? Do we expect some kind of ack from the guest? Do we expect it respond in some way?

Also note that the current series defines only one error condition: invalid cpu index. Can this fail in other ways?

#3 lore raw
Quoted 15 lines · Luiz Capitulino
Quoted 12 lines · On Fri, 10 Dec 2010 14:36:08 +0800 Lai Jiangshan <[email protected]> wrote:
qmp-commands.hx +12 -0
+SQMP
+inject_nmi
+----------
+
+Inject an NMI on the given CPU (x86 only).
+
+Arguments:
+
+- "cpu_index": the index of the CPU to be injected NMI (json-int)
+
+Example:
+
Quoted 8 lines

qmp-commands.hx Example: · line 458

Quoted 5 lines

+-> { "execute": "inject_nmi", "arguments": { "cpu_index": 0 } } +<- { "return": {} }

qmp-commands.hx +3 -0
+
+EQMP
+

Avi, Anthony, can you please review this? Do we expect some kind of ack from the guest? Do we expect it respond in some way?

Looks good to me. Don't except any response from the guest.

Quoted 3 lines

Also note that the current series defines only one error condition: invalid cpu index. Can this fail in other ways?
--

Not really. An NMI can be pending already (which means the current command has no effect), but i don't see the need to report that.

#4 lore raw
Quoted 25 lines · On Mon, 20 Dec 2010 08:47:46 -0200 Marcelo Tosatti <[email protected]> wrote:
Quoted 15 lines · Luiz Capitulino
Quoted 12 lines · On Fri, 10 Dec 2010 14:36:08 +0800 Lai Jiangshan <[email protected]> wrote:
qmp-commands.hx +12 -0
+SQMP
+inject_nmi
+----------
+
+Inject an NMI on the given CPU (x86 only).
+
+Arguments:
+
+- "cpu_index": the index of the CPU to be injected NMI (json-int)
+
+Example:
+
Quoted 8 lines

qmp-commands.hx Example: · line 458

Quoted 5 lines

+-> { "execute": "inject_nmi", "arguments": { "cpu_index": 0 } } +<- { "return": {} }

qmp-commands.hx +3 -0
+
+EQMP
+

Avi, Anthony, can you please review this? Do we expect some kind of ack from the guest? Do we expect it respond in some way?

Quoted 8 lines

Looks good to me. Don't except any response from the guest.

Quoted 3 lines

Also note that the current series defines only one error condition: invalid cpu index. Can this fail in other ways?
--

Not really. An NMI can be pending already (which means the current command has no effect), but i don't see the need to report that.

Ok, thanks for the feedback Marcelo.

Quoted 1 line