Skip to contentSkip to conversation

pv event to notify host when the guest is panicked

PATCH Superseded Hu Tao 2 participants 15 messages Dec 12, 2012 – Jan 14, 2013

Subsystems (8)
x86 KVM PowerPC s390 +4 more subsystems

v12 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Hu Tao

author
#0 lore raw

v12 cover pv event to notify host when the guest is panicked

This series implements a new interface, kvm pv event, to notify host when some events happen in guest. Right now there is one supported event: guest panic.

changes from v11:

- add a new patch 'save/load cpu runstate'
- fix a bug of null-dereference when no -machine option is supplied
- reserve RUN_STATE_GUEST_PANICKED during migration
- add doc of enable_pv_event option
- disable reboot-on-panic if pv_event is on

v11: http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04361.html

Hu Tao (7):
save/load cpu runstate
update kernel headers
add a new runstate: RUN_STATE_GUEST_PANICKED add a new qevent: QEVENT_GUEST_PANICKED introduce a new qom device to deal with panicked event allower the user to disable pv event support pv event: add document to describe the usage

Wen Congyang (1):
start vm after resetting it

 block.h                          |   2 +
 docs/pv-event.txt                |  17 ++++
 hw/kvm/Makefile.objs             |   2 +-
 hw/kvm/pv_event.c                | 197 +++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c                     |  11 +++
 kvm-stub.c                       |   4 +
 kvm.h                            |   2 +
 linux-headers/asm-x86/kvm_para.h |   1 +
 linux-headers/linux/kvm_para.h   |   6 ++
 migration.c                      |   7 +-
 monitor.c                        |   6 +-
 monitor.h                        |   1 +
 qapi-schema.json                 |   6 +-
 qemu-config.c                    |   4 +
 qemu-options.hx                  |   3 +-
 qmp.c                            |   5 +-
 savevm.c                         |   1 +
 sysemu.h                         |   2 +
 vl.c                             |  52 ++++++++++-
 19 files changed, 312 insertions(+), 17 deletions(-)
 create mode 100644 docs/pv-event.txt
 create mode 100644 hw/kvm/pv_event.c
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#1 lore raw

PATCH v12 1/8 save/load cpu runstate

---
 migration.c |  6 +-----
 monitor.c   |  5 ++---
 savevm.c    |  1 +
 sysemu.h    |  2 ++
 vl.c        | 34 ++++++++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+), 8 deletions(-)
migration.c +1 -5
index 73ce170..31fa300 100644
@@ -102,11 +102,7 @@ static void process_incoming_migration_co(void *opaque)
     /* Make sure all file formats flush their mutable metadata */
     bdrv_invalidate_cache_all();
 
-    if (autostart) {
-        vm_start();
-    } else {
-        runstate_set(RUN_STATE_PAUSED);
-    }
+    load_run_state();
 }
 
 static void enter_migration_coroutine(void *opaque)
monitor.c +2 -3
index c0e32d6..1226501 100644
@@ -2067,13 +2067,12 @@ void qmp_closefd(const char *fdname, Error **errp)
 
 static void do_loadvm(Monitor *mon, const QDict *qdict)
 {
-    int saved_vm_running  = runstate_is_running();
     const char *name = qdict_get_str(qdict, "name");
 
     vm_stop(RUN_STATE_RESTORE_VM);
 
-    if (load_vmstate(name) == 0 && saved_vm_running) {
-        vm_start();
+    if (load_vmstate(name) == 0) {
+        load_run_state();
     }
 }
 
savevm.c +1 -0
index 5d04d59..98963a4 100644
@@ -2149,6 +2149,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     }
 
     saved_vm_running = runstate_is_running();
+    save_run_state();
     vm_stop(RUN_STATE_SAVE_VM);
 
     memset(sn, 0, sizeof(*sn));
sysemu.h +2 -0
index f5ac664..618f55e 100644
@@ -19,6 +19,8 @@ extern uint8_t qemu_uuid[];
 int qemu_uuid_parse(const char *str, uint8_t *uuid);
 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
+void save_run_state(void);
+void load_run_state(void);
 bool runstate_check(RunState state);
 void runstate_set(RunState new_state);
 int runstate_is_running(void);
vl.c +34 -0
index c8e9c78..6f274cc 100644
@@ -331,6 +331,7 @@ static int default_driver_check(QemuOpts *opts, void *opaque)
 /* QEMU state */
 
 static RunState current_run_state = RUN_STATE_PRELAUNCH;
+static RunState saved_run_state = RUN_STATE_PRELAUNCH;
 
 typedef struct {
     RunState from;
@@ -354,6 +355,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
 
     { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_POSTMIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
 
     { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
@@ -364,6 +366,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
 
     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
+    { RUN_STATE_RESTORE_VM, RUN_STATE_PAUSED },
 
     { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
     { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
@@ -393,11 +396,39 @@ static const RunStateTransition runstate_transitions_def[] = {
 
 static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
 
+void save_run_state(void)
+{
+    saved_run_state = current_run_state;
+}
+
+void load_run_state(void)
+{
+    if (saved_run_state == RUN_STATE_RUNNING) {
+        vm_start();
+    } else if (!runstate_check(saved_run_state)) {
+        runstate_set(saved_run_state);
+    } else {
+        ; /* leave unchanged */
+    }
+}
+
 bool runstate_check(RunState state)
 {
     return current_run_state == state;
 }
 
+static void runstate_save(QEMUFile *f, void *opaque)
+{
+    qemu_put_byte(f, saved_run_state);
+}
+
+static int runstate_load(QEMUFile *f, void *opaque, int version_id)
+{
+    saved_run_state = qemu_get_byte(f);
+
+    return 0;
+}
+
 static void runstate_init(void)
 {
     const RunStateTransition *p;
@@ -407,6 +438,9 @@ static void runstate_init(void)
     for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
         runstate_valid_transitions[p->from][p->to] = true;
     }
+
+    register_savevm(NULL, "runstate", 0, 1,
+                    runstate_save, runstate_load, NULL);
 }
 
 /* This function will abort() on invalid state transitions */
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#2 lore raw

PATCH v12 2/8 start vm after resetting it

In reply to Hu Tao

From: Wen Congyang <[email protected]>

The guest should run after resetting it, but it does not run if its old state is RUN_STATE_INTERNAL_ERROR or RUN_STATE_PAUSED.

We don't set runstate to RUN_STATE_PAUSED when resetting the guest, so the runstate will be changed from RUN_STATE_INTERNAL_ERROR or RUN_STATE_PAUSED to RUN_STATE_RUNNING(not RUN_STATE_PAUSED).

---
 block.h | 2 ++
 qmp.c   | 2 +-
 vl.c    | 7 ++++---
 3 files changed, 7 insertions(+), 4 deletions(-)
block.h +2 -0
index 722c620..2eea979 100644
@@ -365,6 +365,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);
 void bdrv_set_in_use(BlockDriverState *bs, int in_use);
 int bdrv_in_use(BlockDriverState *bs);
 
+void iostatus_bdrv_it(void *opaque, BlockDriverState *bs);
+
 enum BlockAcctType {
     BDRV_ACCT_READ,
     BDRV_ACCT_WRITE,
qmp.c +1 -1
index 13e83a5..bcd7229 100644
@@ -129,7 +129,7 @@ SpiceInfo *qmp_query_spice(Error **errp)
 };
 #endif
 
-static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs)
+void iostatus_bdrv_it(void *opaque, BlockDriverState *bs)
 {
     bdrv_iostatus_reset(bs);
 }
vl.c +4 -3
index 6f274cc..69fca16 100644
@@ -345,7 +345,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
 
-    { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
+    { RUN_STATE_INTERNAL_ERROR, RUN_STATE_RUNNING },
     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
 
     { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
@@ -380,7 +380,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
 
-    { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
+    { RUN_STATE_SHUTDOWN, RUN_STATE_RUNNING },
     { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
 
     { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
@@ -1770,7 +1770,8 @@ static bool main_loop_should_exit(void)
         resume_all_vcpus();
         if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
             runstate_check(RUN_STATE_SHUTDOWN)) {
-            runstate_set(RUN_STATE_PAUSED);
+            bdrv_iterate(iostatus_bdrv_it, NULL);
+            vm_start();
         }
     }
     if (qemu_wakeup_requested()) {
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#3 lore raw

PATCH v12 3/8 update kernel headers

In reply to Hu Tao

update kernel headers to add pv event macros.

---
 linux-headers/asm-x86/kvm_para.h | 1 +
 linux-headers/linux/kvm_para.h   | 6 ++++++
 2 files changed, 7 insertions(+)
linux-headers/asm-x86/kvm_para.h +1 -0
index a1c3d72..781959a 100644
@@ -96,5 +96,6 @@ struct kvm_vcpu_pv_apf_data {
 #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK
 #define KVM_PV_EOI_DISABLED 0x0
 
+#define KVM_PV_EVENT_PORT	(0x505UL)
 
 #endif /* _ASM_X86_KVM_PARA_H */
linux-headers/linux/kvm_para.h +6 -0
index cea2c5c..c41ddce 100644
@@ -20,6 +20,12 @@
 #define KVM_HC_FEATURES			3
 #define KVM_HC_PPC_MAP_MAGIC_PAGE	4
 
+/* The bit of supported pv event */
+#define KVM_PV_FEATURE_PANICKED	0
+
+/* The pv event value */
+#define KVM_PV_EVENT_PANICKED	1
+
 /*
  * hypercalls use architecture specific
  */
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#4 lore raw

PATCH v12 4/8 add a new runstate: RUN_STATE_GUEST_PANICKED

In reply to Hu Tao

The guest will be in this state when it is panicked.

---
 migration.c      |  1 +
 qapi-schema.json |  6 +++++-
 qmp.c            |  3 ++-
 vl.c             | 11 ++++++++++-
 4 files changed, 18 insertions(+), 3 deletions(-)
migration.c +1 -0
index 31fa300..9122dca 100644
@@ -345,6 +345,7 @@ void migrate_fd_put_ready(MigrationState *s)
         int64_t start_time, end_time;
 
         DPRINTF("done iterating\n");
+        save_run_state();
         start_time = qemu_get_clock_ms(rt_clock);
         qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
         vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
qapi-schema.json +5 -1
index 542e3ac..5fd4ae8 100644
@@ -174,11 +174,15 @@
 # @suspended: guest is suspended (ACPI S3)
 #
 # @watchdog: the watchdog action is configured to pause and has been triggered
+#
+# @guest-panicked: the panicked action is configured to pause and has been
+# triggered.
 ##
 { 'enum': 'RunState',
   'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
             'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
-            'running', 'save-vm', 'shutdown', 'suspended', 'watchdog' ] }
+            'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
+            'guest-panicked' ] }
 
 ##
 # @SnapshotInfo
qmp.c +2 -1
index bcd7229..2c590e4 100644
@@ -149,7 +149,8 @@ void qmp_cont(Error **errp)
     Error *local_err = NULL;
 
     if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
-               runstate_check(RUN_STATE_SHUTDOWN)) {
+            runstate_check(RUN_STATE_SHUTDOWN) ||
+            runstate_check(RUN_STATE_GUEST_PANICKED)) {
         error_set(errp, QERR_RESET_REQUIRED);
         return;
     } else if (runstate_check(RUN_STATE_SUSPENDED)) {
vl.c +10 -1
index 69fca16..30d6e58 100644
@@ -344,6 +344,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
+    { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED },
 
     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_RUNNING },
     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
@@ -357,6 +358,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
     { RUN_STATE_POSTMIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_POSTMIGRATE, RUN_STATE_GUEST_PANICKED },
 
     { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
     { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
@@ -367,6 +369,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
     { RUN_STATE_RESTORE_VM, RUN_STATE_PAUSED },
+    { RUN_STATE_RESTORE_VM, RUN_STATE_GUEST_PANICKED },
 
     { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
     { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
@@ -377,6 +380,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
     { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
     { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
+    { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
 
     { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
 
@@ -391,6 +395,10 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
     { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
 
+    { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
+    { RUN_STATE_GUEST_PANICKED, RUN_STATE_PAUSED },
+    { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
+
     { RUN_STATE_MAX, RUN_STATE_MAX },
 };
 
@@ -1769,7 +1777,8 @@ static bool main_loop_should_exit(void)
         qemu_system_reset(VMRESET_REPORT);
         resume_all_vcpus();
         if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
-            runstate_check(RUN_STATE_SHUTDOWN)) {
+            runstate_check(RUN_STATE_SHUTDOWN) ||
+            runstate_check(RUN_STATE_GUEST_PANICKED)) {
             bdrv_iterate(iostatus_bdrv_it, NULL);
             vm_start();
         }
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#5 lore raw

PATCH v12 5/8 add a new qevent: QEVENT_GUEST_PANICKED

In reply to Hu Tao

This event will be emited when the guest is panicked.

---
 monitor.c | 1 +
 monitor.h | 1 +
 2 files changed, 2 insertions(+)
monitor.c +1 -0
index 1226501..231785b 100644
@@ -458,6 +458,7 @@ static const char *monitor_event_names[] = {
     [QEVENT_WAKEUP] = "WAKEUP",
     [QEVENT_BALLOON_CHANGE] = "BALLOON_CHANGE",
     [QEVENT_SPICE_MIGRATE_COMPLETED] = "SPICE_MIGRATE_COMPLETED",
+    [QEVENT_GUEST_PANICKED] = "GUEST_PANICKED",
 };
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
monitor.h +1 -0
index b4ef955..16c1c83 100644
@@ -46,6 +46,7 @@ typedef enum MonitorEvent {
     QEVENT_WAKEUP,
     QEVENT_BALLOON_CHANGE,
     QEVENT_SPICE_MIGRATE_COMPLETED,
+    QEVENT_GUEST_PANICKED,
 
     /* Add to 'monitor_event_names' array in monitor.c when
      * defining new events here */
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#6 lore raw

PATCH v12 6/8 introduce a new qom device to deal with panicked event

In reply to Hu Tao

If the target is x86/x86_64, the guest's kernel will write 0x01 to the port KVM_PV_EVENT_PORT when it is panciked. This patch introduces a new qom device kvm_pv_ioport to listen this I/O port, and deal with panicked event according to panicked_action's value. The possible actions are:
1. emit QEVENT_GUEST_PANICKED only
2. emit QEVENT_GUEST_PANICKED and pause the guest
3. emit QEVENT_GUEST_PANICKED and poweroff the guest
4. emit QEVENT_GUEST_PANICKED and reset the guest

I/O ports does not work for some targets(for example: s390). And you can implement another qom device, and include it's code into pv_event.c for such target.

Note: if we emit QEVENT_GUEST_PANICKED only, and the management application does not receive this event(the management may not run when the event is emitted), the management won't know the guest is panicked.

---
 hw/kvm/Makefile.objs |   2 +-
 hw/kvm/pv_event.c    | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c         |   5 ++
 kvm-stub.c           |   4 ++
 kvm.h                |   2 +
 5 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 hw/kvm/pv_event.c
hw/kvm/Makefile.objs +1 -1
index f620d7f..cf93199 100644
@@ -1 +1 @@
-obj-$(CONFIG_KVM) += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o
+obj-$(CONFIG_KVM) += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o pv_event.o
hw/kvm/pv_event.c new file +197 -0

197 lines not on this page · raw message

hw/pc_piix.c +5 -0
index cfa839c..8380702 100644
@@ -47,6 +47,7 @@
 #ifdef CONFIG_XEN
 #  include <xen/hvm/hvm_info_table.h>
 #endif
+#include <linux/kvm_para.h>
 
 #define MAX_IDE_BUS 2
 
@@ -286,6 +287,10 @@ static void pc_init1(MemoryRegion *system_memory,
     if (pci_enabled) {
         pc_pci_device_init(pci_bus);
     }
+
+    if (kvm_enabled()) {
+        kvm_pv_event_init(isa_bus);
+    }
 }
 
 static void pc_init_pci(QEMUMachineInitArgs *args)
kvm-stub.c +4 -0
index a3455e2..c9cfe4a 100644
@@ -140,3 +140,7 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
 {
     return -ENOSYS;
 }
+
+void kvm_pv_event_init(void *opaque)
+{
+}
kvm.h +2 -0
index 1e7f244..a4a0795 100644
@@ -275,4 +275,6 @@ void kvm_irqchip_release_virq(KVMState *s, int virq);
 
 int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
 int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
+
+void kvm_pv_event_init(void *opaque);
 #endif
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#7 lore raw

PATCH v12 7/8 allower the user to disable pv event support

In reply to Hu Tao
---
 hw/pc_piix.c    | 8 +++++++-
 qemu-config.c   | 4 ++++
 qemu-options.hx | 3 ++-
 3 files changed, 13 insertions(+), 2 deletions(-)
hw/pc_piix.c +7 -1
index 8380702..bf31b96 100644
@@ -150,6 +150,8 @@ static void pc_init1(MemoryRegion *system_memory,
     MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
     void *fw_cfg = NULL;
+    QemuOptsList *list = qemu_find_opts("machine");
+    bool enable_pv_event = false;
 
     pc_cpus_init(cpu_model);
 
@@ -288,7 +290,11 @@ static void pc_init1(MemoryRegion *system_memory,
         pc_pci_device_init(pci_bus);
     }
 
-    if (kvm_enabled()) {
+    if (list && !QTAILQ_EMPTY(&list->head)) {
+        enable_pv_event = qemu_opt_get_bool(QTAILQ_FIRST(&list->head),
+                                            "enable_pv_event", false);
+    }
+    if (kvm_enabled() && enable_pv_event) {
         kvm_pv_event_init(isa_bus);
     }
 }
qemu-config.c +4 -0
index 10d1ba4..6682276 100644
@@ -627,6 +627,10 @@ static QemuOptsList qemu_machine_opts = {
             .name = "usb",
             .type = QEMU_OPT_BOOL,
             .help = "Set on/off to enable/disable usb",
+        }, {
+            .name = "enable_pv_event",
+            .type = QEMU_OPT_BOOL,
+            .help = "handle pv event"
         },
         { /* End of list */ }
     },
qemu-options.hx +2 -1
index dd86bfe..44c7760 100644
@@ -35,7 +35,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                kernel_irqchip=on|off controls accelerated irqchip support\n"
     "                kvm_shadow_mem=size of KVM shadow MMU\n"
     "                dump-guest-core=on|off include guest memory in a core dump (default=on)\n"
-    "                mem-merge=on|off controls memory merge support (default: on)\n",
+    "                mem-merge=on|off controls memory merge support (default: on)\n"
+    "                enable_pv_event=on|off controls pv event support (default: off)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#8 lore raw

PATCH v12 8/8 pv event: add document to describe the usage

In reply to Hu Tao
---
 docs/pv-event.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 docs/pv-event.txt
docs/pv-event.txt new file +17 -0
new file mode 100644
index 0000000..ac9e7fa
@@ -0,0 +1,17 @@
+KVM PV EVENT
+============
+
+kvm pv event allows guest OS to notify host OS of some events, for
+example, guest panic. Currently, there is one event supported, that
+is, guest panic. More events can be added later.
+
+By default, kvm pv event is disabled. In order to enable it, you have
+to specify enable_pv_event=on for -machine command line option, along
+with -global kvm_pv_event.panicked_action to specify the action taken
+when panic event has occurred. Aviable panic actions are: "none",
+"pause", "poweroff" and "reset". Following is example:
+
+  qemu-system-x86_64 -enable-kvm -machine pc-0.12,enable_pv_event=on \
+    -global kvm_pv_event.panicked_action=pause <other options>
+
+kvm pv event needs kvm support.
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#9 lore raw

PATCH 1/1 kvm: notify host when the guest is panicked

In reply to Hu Tao

We can know the guest is panicked when the guest runs on xen. But we do not have such feature on kvm.

Another purpose of this feature is: management app(for example:
libvirt) can do auto dump when the guest is panicked. If management app does not do auto dump, the guest's user can do dump by hand if he sees the guest is panicked.

We have three solutions to implement this feature:
1. use vmcall
2. use I/O port
3. use virtio-serial.

We have decided to avoid touching hypervisor. The reason why I choose choose the I/O port is:
1. it is easier to implememt
2. it does not depend any virtual device
3. it can work when starting the kernel

---
 arch/ia64/kvm/irq.h                 | 19 +++++++++++++
 arch/powerpc/include/asm/kvm_para.h | 18 +++++++++++++
 arch/s390/include/asm/kvm_para.h    | 19 +++++++++++++
 arch/x86/include/asm/kvm_para.h     | 23 ++++++++++++++++
 arch/x86/kernel/kvm.c               | 53 +++++++++++++++++++++++++++++++++++++
 include/linux/kvm_para.h            | 18 +++++++++++++
 include/uapi/linux/kvm_para.h       |  6 +++++
 kernel/panic.c                      |  4 +++
 8 files changed, 160 insertions(+)
arch/ia64/kvm/irq.h +19 -0
index c0785a7..b3870f8 100644
@@ -30,4 +30,23 @@ static inline int irqchip_in_kernel(struct kvm *kvm)
 	return 1;
 }
 
+static inline int kvm_arch_pv_event_init(void)
+{
+	return 0;
+}
+
+static inline unsigned int kvm_arch_pv_features(void)
+{
+	return 0;
+}
+
+static inline void kvm_arch_pv_eject_event(unsigned int event)
+{
+}
+
+static inline bool kvm_arch_pv_event_enabled(void)
+{
+	return false;
+}
+
 #endif
arch/powerpc/include/asm/kvm_para.h +18 -0
index 9365860..4b0e8dd 100644
@@ -145,4 +145,22 @@ static inline bool kvm_check_and_clear_guest_paused(void)
 	return false;
 }
 
+static inline int kvm_arch_pv_event_init(void)
+{
+	return 0;
+}
+
+static inline unsigned int kvm_arch_pv_features(void)
+{
+	return 0;
+}
+
+static inline void kvm_arch_pv_eject_event(unsigned int event)
+{
+}
+
+static inline bool kvm_arch_pv_event_enabled(void)
+{
+	return false;
+}
 #endif /* __POWERPC_KVM_PARA_H__ */
arch/s390/include/asm/kvm_para.h +19 -0
index e0f8423..81d87ec 100644
@@ -154,4 +154,23 @@ static inline bool kvm_check_and_clear_guest_paused(void)
 	return false;
 }
 
+static inline int kvm_arch_pv_event_init(void)
+{
+	return 0;
+}
+
+static inline unsigned int kvm_arch_pv_features(void)
+{
+	return 0;
+}
+
+static inline void kvm_arch_pv_eject_event(unsigned int event)
+{
+}
+
+static inline bool kvm_arch_pv_event_enabled(void)
+{
+	return false;
+}
+
 #endif /* __S390_KVM_PARA_H */
arch/x86/include/asm/kvm_para.h +23 -0
index eb3e9d8..5c38429 100644
@@ -96,8 +96,11 @@ struct kvm_vcpu_pv_apf_data {
 #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK
 #define KVM_PV_EOI_DISABLED 0x0
 
+#define KVM_PV_EVENT_PORT	(0x505UL)
+
 #ifdef __KERNEL__
 #include <asm/processor.h>
+#include <linux/ioport.h>
 
 extern void kvmclock_init(void);
 extern int kvm_register_clock(char *txt);
@@ -228,6 +231,26 @@ static inline void kvm_disable_steal_time(void)
 }
 #endif
 
+static inline int kvm_arch_pv_event_init(void)
+{
+	if (!request_region(KVM_PV_EVENT_PORT, 4, "KVM_PV_EVENT"))
+		return -1;
+
+	return 0;
+}
+
+static inline unsigned int kvm_arch_pv_features(void)
+{
+	return inl(KVM_PV_EVENT_PORT);
+}
+
+static inline void kvm_arch_pv_eject_event(unsigned int event)
+{
+	outl(event, KVM_PV_EVENT_PORT);
+}
+
+bool kvm_arch_pv_event_enabled(void);
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_KVM_PARA_H */
arch/x86/kernel/kvm.c +53 -0

71 lines not on this page · raw message

include/linux/kvm_para.h +18 -0
index 00a97bb..6fb6198 100644
@@ -10,4 +10,22 @@ static inline int kvm_para_has_feature(unsigned int feature)
 		return 1;
 	return 0;
 }
+
+static inline int kvm_pv_has_feature(unsigned int feature)
+{
+	if (kvm_arch_pv_features() & (1UL << feature))
+		return 1;
+	return 0;
+}
+
+static inline void kvm_pv_eject_event(unsigned int event)
+{
+	kvm_arch_pv_eject_event(event);
+}
+
+static inline bool kvm_pv_event_enabled(void)
+{
+	return kvm_arch_pv_event_enabled();
+}
+
 #endif /* __LINUX_KVM_PARA_H */
include/uapi/linux/kvm_para.h +6 -0
index cea2c5c..c41ddce 100644
@@ -20,6 +20,12 @@
 #define KVM_HC_FEATURES			3
 #define KVM_HC_PPC_MAP_MAGIC_PAGE	4
 
+/* The bit of supported pv event */
+#define KVM_PV_FEATURE_PANICKED	0
+
+/* The pv event value */
+#define KVM_PV_EVENT_PANICKED	1
+
 /*
  * hypercalls use architecture specific
  */
kernel/panic.c +4 -0
index e1b2822..a764d2e 100644
@@ -23,6 +23,7 @@
 #include <linux/init.h>
 #include <linux/nmi.h>
 #include <linux/dmi.h>
+#include <linux/kvm_para.h>
 
 #define PANIC_TIMER_STEP 100
 #define PANIC_BLINK_SPD 18
@@ -132,6 +133,9 @@ void panic(const char *fmt, ...)
 	if (!panic_blink)
 		panic_blink = no_blink;
 
+	if (kvm_pv_event_enabled())
+		panic_timeout = 0;
+
 	if (panic_timeout > 0) {
 		/*
 		 * Delay timeout seconds before rebooting the machine.
Signature · 1 line
1.8.0.1.240.ge8a1f5a
author
#10 lore raw
In reply to Hu Tao

Hi,

Any comments?

Quoted 51 lines · Hu Tao

This series implements a new interface, kvm pv event, to notify host when some events happen in guest. Right now there is one supported event: guest panic.

changes from v11:

- add a new patch 'save/load cpu runstate'
- fix a bug of null-dereference when no -machine option is supplied
- reserve RUN_STATE_GUEST_PANICKED during migration
- add doc of enable_pv_event option
- disable reboot-on-panic if pv_event is on

v11: http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04361.html

Hu Tao (7):
save/load cpu runstate
update kernel headers
add a new runstate: RUN_STATE_GUEST_PANICKED add a new qevent: QEVENT_GUEST_PANICKED introduce a new qom device to deal with panicked event allower the user to disable pv event support pv event: add document to describe the usage

Wen Congyang (1):
start vm after resetting it

 block.h                          |   2 +
 docs/pv-event.txt                |  17 ++++
 hw/kvm/Makefile.objs             |   2 +-
 hw/kvm/pv_event.c                | 197 +++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c                     |  11 +++
 kvm-stub.c                       |   4 +
 kvm.h                            |   2 +
 linux-headers/asm-x86/kvm_para.h |   1 +
 linux-headers/linux/kvm_para.h   |   6 ++
 migration.c                      |   7 +-
 monitor.c                        |   6 +-
 monitor.h                        |   1 +
 qapi-schema.json                 |   6 +-
 qemu-config.c                    |   4 +
 qemu-options.hx                  |   3 +-
 qmp.c                            |   5 +-
 savevm.c                         |   1 +
 sysemu.h                         |   2 +
 vl.c                             |  52 ++++++++++-
 19 files changed, 312 insertions(+), 17 deletions(-)
 create mode 100644 docs/pv-event.txt
 create mode 100644 hw/kvm/pv_event.c
Signature · 1 line
1.8.0.1.240.ge8a1f5a
#11 lore raw
Quoted 3 lines · Hu Tao

Hi,

Any comments?

As far as i can see, items 2 and 3 of

https://lkml.org/lkml/2012/11/12/588

Have not been addressed.

https://lkml.org/lkml/2012/11/20/653 contains discussions on those items.

2) Format of the interface for other architectures (you can choose a different KVM supported architecture and write an example). It was your choice to choose an I/O port, which is x86 specific.

3) Clear/documented management interface for the feature.

Note 3 is for management, not the guest<->host interface.

Quoted 56 lines · Hu Tao
Quoted 40 lines

This series implements a new interface, kvm pv event, to notify host when some events happen in guest. Right now there is one supported event: guest panic.

changes from v11:

- add a new patch 'save/load cpu runstate'
- fix a bug of null-dereference when no -machine option is supplied
- reserve RUN_STATE_GUEST_PANICKED during migration
- add doc of enable_pv_event option
- disable reboot-on-panic if pv_event is on

v11: http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04361.html

Hu Tao (7):
save/load cpu runstate
update kernel headers
add a new runstate: RUN_STATE_GUEST_PANICKED add a new qevent: QEVENT_GUEST_PANICKED introduce a new qom device to deal with panicked event allower the user to disable pv event support pv event: add document to describe the usage

Wen Congyang (1):
start vm after resetting it

 block.h                          |   2 +
 docs/pv-event.txt                |  17 ++++
 hw/kvm/Makefile.objs             |   2 +-
 hw/kvm/pv_event.c                | 197 +++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c                     |  11 +++
 kvm-stub.c                       |   4 +
 kvm.h                            |   2 +
 linux-headers/asm-x86/kvm_para.h |   1 +
 linux-headers/linux/kvm_para.h   |   6 ++
 migration.c                      |   7 +-
 monitor.c                        |   6 +-
 monitor.h                        |   1 +
 qapi-schema.json                 |   6 +-
 qemu-config.c                    |   4 +
Quoted 11 lines
 qemu-options.hx                  |   3 +-
 qmp.c                            |   5 +-
 savevm.c                         |   1 +
 sysemu.h                         |   2 +
 vl.c                             |  52 ++++++++++-
 19 files changed, 312 insertions(+), 17 deletions(-)
 create mode 100644 docs/pv-event.txt
 create mode 100644 hw/kvm/pv_event.c
Signature · 1 line
1.8.0.1.240.ge8a1f5a

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

author
#12 lore raw

Hi Marcelo,

Sorry for the late reply.

Quoted 9 lines · Marcelo Tosatti
Quoted 3 lines · Hu Tao

Hi,

Any comments?

As far as i can see, items 2 and 3 of

https://lkml.org/lkml/2012/11/12/588

Quoted 8 lines

Have not been addressed.

https://lkml.org/lkml/2012/11/20/653 contains discussions on those items.

2) Format of the interface for other architectures (you can choose a different KVM supported architecture and write an example). It was your choice to choose an I/O port, which is x86 specific.

Unfortunately I don't have hardware other than x86 in hand to test it.

Quoted 2 lines

3) Clear/documented management interface for the feature.

Patch #8 adds a document to describe the usage of pv event. But as you are asking again, I must be misunderstanding the meaning of management interface. Can you clarify it?

Quoted 59 lines

Note 3 is for management, not the guest<->host interface.

Quoted 56 lines · Hu Tao
Quoted 40 lines

This series implements a new interface, kvm pv event, to notify host when some events happen in guest. Right now there is one supported event: guest panic.

changes from v11:

- add a new patch 'save/load cpu runstate'
- fix a bug of null-dereference when no -machine option is supplied
- reserve RUN_STATE_GUEST_PANICKED during migration
- add doc of enable_pv_event option
- disable reboot-on-panic if pv_event is on

v11: http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04361.html

Hu Tao (7):
save/load cpu runstate
update kernel headers
add a new runstate: RUN_STATE_GUEST_PANICKED add a new qevent: QEVENT_GUEST_PANICKED introduce a new qom device to deal with panicked event allower the user to disable pv event support pv event: add document to describe the usage

Wen Congyang (1):
start vm after resetting it

 block.h                          |   2 +
 docs/pv-event.txt                |  17 ++++
 hw/kvm/Makefile.objs             |   2 +-
 hw/kvm/pv_event.c                | 197 +++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c                     |  11 +++
 kvm-stub.c                       |   4 +
 kvm.h                            |   2 +
 linux-headers/asm-x86/kvm_para.h |   1 +
 linux-headers/linux/kvm_para.h   |   6 ++
 migration.c                      |   7 +-
 monitor.c                        |   6 +-
 monitor.h                        |   1 +
 qapi-schema.json                 |   6 +-
 qemu-config.c                    |   4 +
Quoted 11 lines
 qemu-options.hx                  |   3 +-
 qmp.c                            |   5 +-
 savevm.c                         |   1 +
 sysemu.h                         |   2 +
 vl.c                             |  52 ++++++++++-
 19 files changed, 312 insertions(+), 17 deletions(-)
 create mode 100644 docs/pv-event.txt
 create mode 100644 hw/kvm/pv_event.c
Signature · 1 line
1.8.0.1.240.ge8a1f5a

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

#13 lore raw
In reply to Hu Tao
Quoted 3 lines · Hu Tao

Hi,

Any comments?

Did you verify possibilities listed at
https://lkml.org/lkml/2012/11/20/653 ?

If so, a summary in the patchset would be helpful.

Quoted 56 lines · Hu Tao
Quoted 40 lines

This series implements a new interface, kvm pv event, to notify host when some events happen in guest. Right now there is one supported event: guest panic.

changes from v11:

- add a new patch 'save/load cpu runstate'
- fix a bug of null-dereference when no -machine option is supplied
- reserve RUN_STATE_GUEST_PANICKED during migration
- add doc of enable_pv_event option
- disable reboot-on-panic if pv_event is on

v11: http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04361.html

Hu Tao (7):
save/load cpu runstate
update kernel headers
add a new runstate: RUN_STATE_GUEST_PANICKED add a new qevent: QEVENT_GUEST_PANICKED introduce a new qom device to deal with panicked event allower the user to disable pv event support pv event: add document to describe the usage

Wen Congyang (1):
start vm after resetting it

 block.h                          |   2 +
 docs/pv-event.txt                |  17 ++++
 hw/kvm/Makefile.objs             |   2 +-
 hw/kvm/pv_event.c                | 197 +++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c                     |  11 +++
 kvm-stub.c                       |   4 +
 kvm.h                            |   2 +
 linux-headers/asm-x86/kvm_para.h |   1 +
 linux-headers/linux/kvm_para.h   |   6 ++
 migration.c                      |   7 +-
 monitor.c                        |   6 +-
 monitor.h                        |   1 +
 qapi-schema.json                 |   6 +-
 qemu-config.c                    |   4 +
Quoted 11 lines
 qemu-options.hx                  |   3 +-
 qmp.c                            |   5 +-
 savevm.c                         |   1 +
 sysemu.h                         |   2 +
 vl.c                             |  52 ++++++++++-
 19 files changed, 312 insertions(+), 17 deletions(-)
 create mode 100644 docs/pv-event.txt
 create mode 100644 hw/kvm/pv_event.c
Signature · 1 line
1.8.0.1.240.ge8a1f5a

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

author
#14 lore raw
Quoted 7 lines · Marcelo Tosatti
Quoted 3 lines · Hu Tao

Hi,

Any comments?

Did you verify possibilities listed at
https://lkml.org/lkml/2012/11/20/653 ?

Except the EIO one you mentioned. I don't know how to reproduce it.

Quoted 2 lines

If so, a summary in the patchset would be helpful.

Thanks for reminding, I'll add it in the next version.

Basically, the run state is saved and loaded again so we can know the state when restoring a vm. This is done by patch #1, and is independent of guest panic. Can you have a review of patch #1 before next version?

Quoted 57 lines
Quoted 57 lines · Hu Tao
Quoted 40 lines

This series implements a new interface, kvm pv event, to notify host when some events happen in guest. Right now there is one supported event: guest panic.

changes from v11:

- add a new patch 'save/load cpu runstate'
- fix a bug of null-dereference when no -machine option is supplied
- reserve RUN_STATE_GUEST_PANICKED during migration
- add doc of enable_pv_event option
- disable reboot-on-panic if pv_event is on

v11: http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04361.html

Hu Tao (7):
save/load cpu runstate
update kernel headers
add a new runstate: RUN_STATE_GUEST_PANICKED add a new qevent: QEVENT_GUEST_PANICKED introduce a new qom device to deal with panicked event allower the user to disable pv event support pv event: add document to describe the usage

Wen Congyang (1):
start vm after resetting it

 block.h                          |   2 +
 docs/pv-event.txt                |  17 ++++
 hw/kvm/Makefile.objs             |   2 +-
 hw/kvm/pv_event.c                | 197 +++++++++++++++++++++++++++++++++++++++
 hw/pc_piix.c                     |  11 +++
 kvm-stub.c                       |   4 +
 kvm.h                            |   2 +
 linux-headers/asm-x86/kvm_para.h |   1 +
 linux-headers/linux/kvm_para.h   |   6 ++
 migration.c                      |   7 +-
 monitor.c                        |   6 +-
 monitor.h                        |   1 +
 qapi-schema.json                 |   6 +-
 qemu-config.c                    |   4 +
Quoted 11 lines
 qemu-options.hx                  |   3 +-
 qmp.c                            |   5 +-
 savevm.c                         |   1 +
 sysemu.h                         |   2 +
 vl.c                             |  52 ++++++++++-
 19 files changed, 312 insertions(+), 17 deletions(-)
 create mode 100644 docs/pv-event.txt
 create mode 100644 hw/kvm/pv_event.c
Signature · 1 line
1.8.0.1.240.ge8a1f5a

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