Patchwork [v2] deal with guest paniced event

login
register
mail settings
Submitter Wen Congyang
Date March 7, 2012, 1:58 a.m.
Message ID <4F56C0E1.1090703@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/145140/
State New
Headers show

Comments

Wen Congyang - March 7, 2012, 1:58 a.m.
When the host knows the guest is paniced, it will set
exit_reason to KVM_EXIT_GUEST_PANICED. So if qemu receive
this exit_reason, we can send a event to tell management
application that the guest is paniced and set the guest
status to RUN_STATE_PANICED.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
 kvm-all.c                 |    4 ++++
 linux-headers/linux/kvm.h |    1 +
 monitor.c                 |    3 +++
 monitor.h                 |    1 +
 qapi-schema.json          |    2 +-
 qmp.c                     |    3 ++-
 vl.c                      |    1 +
 7 files changed, 13 insertions(+), 2 deletions(-)
Eric Blake - March 7, 2012, 2:40 a.m.
On 03/06/2012 06:58 PM, Wen Congyang wrote:
> When the host knows the guest is paniced, it will set
> exit_reason to KVM_EXIT_GUEST_PANICED. So if qemu receive
> this exit_reason, we can send a event to tell management
> application that the guest is paniced and set the guest
> status to RUN_STATE_PANICED.

s/PANICED/PANICKED/ throughout your series, for the correct spelling of
the past tense of panic.
Wen Congyang - March 7, 2012, 2:45 a.m.
At 03/07/2012 10:40 AM, Eric Blake Wrote:
> On 03/06/2012 06:58 PM, Wen Congyang wrote:
>> When the host knows the guest is paniced, it will set
>> exit_reason to KVM_EXIT_GUEST_PANICED. So if qemu receive
>> this exit_reason, we can send a event to tell management
>> application that the guest is paniced and set the guest
>> status to RUN_STATE_PANICED.
> 
> s/PANICED/PANICKED/ throughout your series, for the correct spelling of
> the past tense of panic.

Sorry for my bad english. I will update it.

Thanks
Wen Congyang

>
Jan Kiszka - March 7, 2012, 9:53 a.m.
On 2012-03-07 02:58, Wen Congyang wrote:
> When the host knows the guest is paniced, it will set
> exit_reason to KVM_EXIT_GUEST_PANICED. So if qemu receive
> this exit_reason, we can send a event to tell management
> application that the guest is paniced and set the guest
> status to RUN_STATE_PANICED.
> 
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> ---
>  kvm-all.c                 |    4 ++++
>  linux-headers/linux/kvm.h |    1 +
>  monitor.c                 |    3 +++
>  monitor.h                 |    1 +
>  qapi-schema.json          |    2 +-
>  qmp.c                     |    3 ++-
>  vl.c                      |    1 +
>  7 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index c4babda..d356948 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1190,6 +1190,10 @@ int kvm_cpu_exec(CPUState *env)
>                      (uint64_t)run->hw.hardware_exit_reason);
>              ret = -1;
>              break;
> +        case KVM_EXIT_GUEST_PANICED:
> +            monitor_protocol_event(QEVENT_GUEST_PANICED, NULL);
> +            vm_stop(RUN_STATE_PANICED);
> +            break;

This cannot work. You missed to set ret to -1 to break out of loop.

>          case KVM_EXIT_INTERNAL_ERROR:
>              ret = kvm_handle_internal_error(env, run);
>              break;
> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
> index f6b5343..ddc9716 100644
> --- a/linux-headers/linux/kvm.h
> +++ b/linux-headers/linux/kvm.h
> @@ -163,6 +163,7 @@ struct kvm_pit_config {
>  #define KVM_EXIT_OSI              18
>  #define KVM_EXIT_PAPR_HCALL	  19
>  #define KVM_EXIT_S390_UCONTROL	  20
> +#define KVM_EXIT_GUEST_PANICED	  21

Linux header must be sync'ed in a separate patch, referencing the
upstream (typically kvm.git) commit hash that was used as base. Make
sure to use the update-linux-headers.sh script for this.

So the ordering is: Get the kernel changes accepted, then push the
(final) user space patches. That said, a patch like this can still be
posted in advance for informational purposes, but not for application.

Jan
Wen Congyang - March 7, 2012, 10:05 a.m.
At 03/07/2012 05:53 PM, Jan Kiszka Wrote:
> On 2012-03-07 02:58, Wen Congyang wrote:
>> When the host knows the guest is paniced, it will set
>> exit_reason to KVM_EXIT_GUEST_PANICED. So if qemu receive
>> this exit_reason, we can send a event to tell management
>> application that the guest is paniced and set the guest
>> status to RUN_STATE_PANICED.
>>
>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>> ---
>>  kvm-all.c                 |    4 ++++
>>  linux-headers/linux/kvm.h |    1 +
>>  monitor.c                 |    3 +++
>>  monitor.h                 |    1 +
>>  qapi-schema.json          |    2 +-
>>  qmp.c                     |    3 ++-
>>  vl.c                      |    1 +
>>  7 files changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/kvm-all.c b/kvm-all.c
>> index c4babda..d356948 100644
>> --- a/kvm-all.c
>> +++ b/kvm-all.c
>> @@ -1190,6 +1190,10 @@ int kvm_cpu_exec(CPUState *env)
>>                      (uint64_t)run->hw.hardware_exit_reason);
>>              ret = -1;
>>              break;
>> +        case KVM_EXIT_GUEST_PANICED:
>> +            monitor_protocol_event(QEVENT_GUEST_PANICED, NULL);
>> +            vm_stop(RUN_STATE_PANICED);
>> +            break;
> 
> This cannot work. You missed to set ret to -1 to break out of loop.

I fotgot to do it. But it works fine while I test this patch. I
think ret has set to 0 before I guest is panicked.

> 
>>          case KVM_EXIT_INTERNAL_ERROR:
>>              ret = kvm_handle_internal_error(env, run);
>>              break;
>> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
>> index f6b5343..ddc9716 100644
>> --- a/linux-headers/linux/kvm.h
>> +++ b/linux-headers/linux/kvm.h
>> @@ -163,6 +163,7 @@ struct kvm_pit_config {
>>  #define KVM_EXIT_OSI              18
>>  #define KVM_EXIT_PAPR_HCALL	  19
>>  #define KVM_EXIT_S390_UCONTROL	  20
>> +#define KVM_EXIT_GUEST_PANICED	  21
> 
> Linux header must be sync'ed in a separate patch, referencing the
> upstream (typically kvm.git) commit hash that was used as base. Make
> sure to use the update-linux-headers.sh script for this.
> 
> So the ordering is: Get the kernel changes accepted, then push the
> (final) user space patches. That said, a patch like this can still be
> posted in advance for informational purposes, but not for application.

OK.

Thanks
Wen Congyang

> 
> Jan
>

Patch

diff --git a/kvm-all.c b/kvm-all.c
index c4babda..d356948 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1190,6 +1190,10 @@  int kvm_cpu_exec(CPUState *env)
                     (uint64_t)run->hw.hardware_exit_reason);
             ret = -1;
             break;
+        case KVM_EXIT_GUEST_PANICED:
+            monitor_protocol_event(QEVENT_GUEST_PANICED, NULL);
+            vm_stop(RUN_STATE_PANICED);
+            break;
         case KVM_EXIT_INTERNAL_ERROR:
             ret = kvm_handle_internal_error(env, run);
             break;
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index f6b5343..ddc9716 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -163,6 +163,7 @@  struct kvm_pit_config {
 #define KVM_EXIT_OSI              18
 #define KVM_EXIT_PAPR_HCALL	  19
 #define KVM_EXIT_S390_UCONTROL	  20
+#define KVM_EXIT_GUEST_PANICED	  21
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 #define KVM_INTERNAL_ERROR_EMULATION 1
diff --git a/monitor.c b/monitor.c
index 953e748..9802792 100644
--- a/monitor.c
+++ b/monitor.c
@@ -494,6 +494,9 @@  void monitor_protocol_event(MonitorEvent event, QObject *data)
         case QEVENT_WAKEUP:
             event_name = "WAKEUP";
             break;
+        case QEVENT_GUEST_PANICED:
+            event_name = "GUEST_PANICED";
+            break;
         default:
             abort();
             break;
diff --git a/monitor.h b/monitor.h
index 0d49800..a62da93 100644
--- a/monitor.h
+++ b/monitor.h
@@ -41,6 +41,7 @@  typedef enum MonitorEvent {
     QEVENT_DEVICE_TRAY_MOVED,
     QEVENT_SUSPEND,
     QEVENT_WAKEUP,
+    QEVENT_GUEST_PANICED,
     QEVENT_MAX,
 } MonitorEvent;
 
diff --git a/qapi-schema.json b/qapi-schema.json
index d0b6792..dd4b7a0 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -121,7 +121,7 @@ 
 { 'enum': 'RunState',
   'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
             'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
-            'running', 'save-vm', 'shutdown', 'watchdog' ] }
+            'running', 'save-vm', 'shutdown', 'watchdog', 'paniced' ] }
 
 ##
 # @StatusInfo:
diff --git a/qmp.c b/qmp.c
index a182b51..eeb6d3b 100644
--- a/qmp.c
+++ b/qmp.c
@@ -148,7 +148,8 @@  void qmp_cont(Error **errp)
         error_set(errp, QERR_MIGRATION_EXPECTED);
         return;
     } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
-               runstate_check(RUN_STATE_SHUTDOWN)) {
+               runstate_check(RUN_STATE_SHUTDOWN) ||
+               runstate_check(RUN_STATE_PANICED)) {
         error_set(errp, QERR_RESET_REQUIRED);
         return;
     }
diff --git a/vl.c b/vl.c
index 1d4c350..d9c13cf 100644
--- a/vl.c
+++ b/vl.c
@@ -359,6 +359,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_PANICED },
 
     { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },