diff mbox series

kvm: emit GUEST_PANICKED event in case of abnormal KVM exit

Message ID 20231101152311.181817-1-andrey.drobyshev@virtuozzo.com
State New
Headers show
Series kvm: emit GUEST_PANICKED event in case of abnormal KVM exit | expand

Commit Message

Andrey Drobyshev Nov. 1, 2023, 3:23 p.m. UTC
Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
exit.  That's a natural thing to do since in this case guest is no
longer operational anyway.

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Acked-by: Denis V. Lunev <den@virtuozzo.com>
---
 accel/kvm/kvm-all.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

Denis V. Lunev Nov. 1, 2023, 4:13 p.m. UTC | #1
On 11/1/23 16:23, Andrey Drobyshev wrote:
> Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
> KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
> extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
> exit.  That's a natural thing to do since in this case guest is no
> longer operational anyway.
>
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> Acked-by: Denis V. Lunev <den@virtuozzo.com>
> ---
>   accel/kvm/kvm-all.c | 19 +++++++++++++++----
>   1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index e39a810a4e..d74b3f0b0e 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2816,6 +2816,14 @@ static void kvm_eat_signals(CPUState *cpu)
>       } while (sigismember(&chkset, SIG_IPI));
>   }
>   
> +static void kvm_emit_guest_crash(CPUState *cpu)
> +{
> +    kvm_cpu_synchronize_state(cpu);
> +    qemu_mutex_lock_iothread();
> +    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
> +    qemu_mutex_unlock_iothread();
> +}
> +
>   int kvm_cpu_exec(CPUState *cpu)
>   {
>       struct kvm_run *run = cpu->kvm_run;
> @@ -2969,21 +2977,24 @@ int kvm_cpu_exec(CPUState *cpu)
>                   ret = EXCP_INTERRUPT;
>                   break;
>               case KVM_SYSTEM_EVENT_CRASH:
> -                kvm_cpu_synchronize_state(cpu);
> -                qemu_mutex_lock_iothread();
> -                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
> -                qemu_mutex_unlock_iothread();
> +                kvm_emit_guest_crash(cpu);
>                   ret = 0;
>                   break;
>               default:
>                   DPRINTF("kvm_arch_handle_exit\n");
>                   ret = kvm_arch_handle_exit(cpu, run);
> +                if (ret < 0) {
> +                    kvm_emit_guest_crash(cpu);
> +                }
>                   break;
>               }
>               break;
>           default:
>               DPRINTF("kvm_arch_handle_exit\n");
>               ret = kvm_arch_handle_exit(cpu, run);
> +            if (ret < 0) {
> +                kvm_emit_guest_crash(cpu);
> +            }
>               break;
>           }
>       } while (ret == 0);
This allows to gracefully handle this problem in production
and reset the guest using on_crash action in libvirt.
Andrey Drobyshev Nov. 22, 2023, 12:17 p.m. UTC | #2
On 11/1/23 18:13, Denis V. Lunev wrote:
> On 11/1/23 16:23, Andrey Drobyshev wrote:
>> Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
>> KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
>> extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
>> exit.  That's a natural thing to do since in this case guest is no
>> longer operational anyway.
>>
>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>> Acked-by: Denis V. Lunev <den@virtuozzo.com>
>> ---
>>   accel/kvm/kvm-all.c | 19 +++++++++++++++----
>>   1 file changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>> index e39a810a4e..d74b3f0b0e 100644
>> --- a/accel/kvm/kvm-all.c
>> +++ b/accel/kvm/kvm-all.c
>> @@ -2816,6 +2816,14 @@ static void kvm_eat_signals(CPUState *cpu)
>>       } while (sigismember(&chkset, SIG_IPI));
>>   }
>>   +static void kvm_emit_guest_crash(CPUState *cpu)
>> +{
>> +    kvm_cpu_synchronize_state(cpu);
>> +    qemu_mutex_lock_iothread();
>> +    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>> +    qemu_mutex_unlock_iothread();
>> +}
>> +
>>   int kvm_cpu_exec(CPUState *cpu)
>>   {
>>       struct kvm_run *run = cpu->kvm_run;
>> @@ -2969,21 +2977,24 @@ int kvm_cpu_exec(CPUState *cpu)
>>                   ret = EXCP_INTERRUPT;
>>                   break;
>>               case KVM_SYSTEM_EVENT_CRASH:
>> -                kvm_cpu_synchronize_state(cpu);
>> -                qemu_mutex_lock_iothread();
>> -                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>> -                qemu_mutex_unlock_iothread();
>> +                kvm_emit_guest_crash(cpu);
>>                   ret = 0;
>>                   break;
>>               default:
>>                   DPRINTF("kvm_arch_handle_exit\n");
>>                   ret = kvm_arch_handle_exit(cpu, run);
>> +                if (ret < 0) {
>> +                    kvm_emit_guest_crash(cpu);
>> +                }
>>                   break;
>>               }
>>               break;
>>           default:
>>               DPRINTF("kvm_arch_handle_exit\n");
>>               ret = kvm_arch_handle_exit(cpu, run);
>> +            if (ret < 0) {
>> +                kvm_emit_guest_crash(cpu);
>> +            }
>>               break;
>>           }
>>       } while (ret == 0);
> This allows to gracefully handle this problem in production
> and reset the guest using on_crash action in libvirt.

Ping
Andrey Drobyshev Jan. 11, 2024, 1:15 p.m. UTC | #3
On 11/1/23 18:13, Denis V. Lunev wrote:
> On 11/1/23 16:23, Andrey Drobyshev wrote:
>> Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
>> KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
>> extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
>> exit.  That's a natural thing to do since in this case guest is no
>> longer operational anyway.
>>
>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>> Acked-by: Denis V. Lunev <den@virtuozzo.com>
>> ---
>>   accel/kvm/kvm-all.c | 19 +++++++++++++++----
>>   1 file changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>> index e39a810a4e..d74b3f0b0e 100644
>> --- a/accel/kvm/kvm-all.c
>> +++ b/accel/kvm/kvm-all.c
>> @@ -2816,6 +2816,14 @@ static void kvm_eat_signals(CPUState *cpu)
>>       } while (sigismember(&chkset, SIG_IPI));
>>   }
>>   +static void kvm_emit_guest_crash(CPUState *cpu)
>> +{
>> +    kvm_cpu_synchronize_state(cpu);
>> +    qemu_mutex_lock_iothread();
>> +    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>> +    qemu_mutex_unlock_iothread();
>> +}
>> +
>>   int kvm_cpu_exec(CPUState *cpu)
>>   {
>>       struct kvm_run *run = cpu->kvm_run;
>> @@ -2969,21 +2977,24 @@ int kvm_cpu_exec(CPUState *cpu)
>>                   ret = EXCP_INTERRUPT;
>>                   break;
>>               case KVM_SYSTEM_EVENT_CRASH:
>> -                kvm_cpu_synchronize_state(cpu);
>> -                qemu_mutex_lock_iothread();
>> -                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>> -                qemu_mutex_unlock_iothread();
>> +                kvm_emit_guest_crash(cpu);
>>                   ret = 0;
>>                   break;
>>               default:
>>                   DPRINTF("kvm_arch_handle_exit\n");
>>                   ret = kvm_arch_handle_exit(cpu, run);
>> +                if (ret < 0) {
>> +                    kvm_emit_guest_crash(cpu);
>> +                }
>>                   break;
>>               }
>>               break;
>>           default:
>>               DPRINTF("kvm_arch_handle_exit\n");
>>               ret = kvm_arch_handle_exit(cpu, run);
>> +            if (ret < 0) {
>> +                kvm_emit_guest_crash(cpu);
>> +            }
>>               break;
>>           }
>>       } while (ret == 0);
> This allows to gracefully handle this problem in production
> and reset the guest using on_crash action in libvirt.

Ping
Andrey Drobyshev Jan. 25, 2024, 4:36 p.m. UTC | #4
On 1/11/24 15:15, Andrey Drobyshev wrote:
> On 11/1/23 18:13, Denis V. Lunev wrote:
>> On 11/1/23 16:23, Andrey Drobyshev wrote:
>>> Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
>>> KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
>>> extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
>>> exit.  That's a natural thing to do since in this case guest is no
>>> longer operational anyway.
>>>
>>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>>> Acked-by: Denis V. Lunev <den@virtuozzo.com>
>>> ---
>>>   accel/kvm/kvm-all.c | 19 +++++++++++++++----
>>>   1 file changed, 15 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>>> index e39a810a4e..d74b3f0b0e 100644
>>> --- a/accel/kvm/kvm-all.c
>>> +++ b/accel/kvm/kvm-all.c
>>> @@ -2816,6 +2816,14 @@ static void kvm_eat_signals(CPUState *cpu)
>>>       } while (sigismember(&chkset, SIG_IPI));
>>>   }
>>>   +static void kvm_emit_guest_crash(CPUState *cpu)
>>> +{
>>> +    kvm_cpu_synchronize_state(cpu);
>>> +    qemu_mutex_lock_iothread();
>>> +    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>>> +    qemu_mutex_unlock_iothread();
>>> +}
>>> +
>>>   int kvm_cpu_exec(CPUState *cpu)
>>>   {
>>>       struct kvm_run *run = cpu->kvm_run;
>>> @@ -2969,21 +2977,24 @@ int kvm_cpu_exec(CPUState *cpu)
>>>                   ret = EXCP_INTERRUPT;
>>>                   break;
>>>               case KVM_SYSTEM_EVENT_CRASH:
>>> -                kvm_cpu_synchronize_state(cpu);
>>> -                qemu_mutex_lock_iothread();
>>> -                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>>> -                qemu_mutex_unlock_iothread();
>>> +                kvm_emit_guest_crash(cpu);
>>>                   ret = 0;
>>>                   break;
>>>               default:
>>>                   DPRINTF("kvm_arch_handle_exit\n");
>>>                   ret = kvm_arch_handle_exit(cpu, run);
>>> +                if (ret < 0) {
>>> +                    kvm_emit_guest_crash(cpu);
>>> +                }
>>>                   break;
>>>               }
>>>               break;
>>>           default:
>>>               DPRINTF("kvm_arch_handle_exit\n");
>>>               ret = kvm_arch_handle_exit(cpu, run);
>>> +            if (ret < 0) {
>>> +                kvm_emit_guest_crash(cpu);
>>> +            }
>>>               break;
>>>           }
>>>       } while (ret == 0);
>> This allows to gracefully handle this problem in production
>> and reset the guest using on_crash action in libvirt.
> 
> Ping

Ping
Andrey Drobyshev Feb. 8, 2024, 6:32 p.m. UTC | #5
On 1/25/24 18:36, Andrey Drobyshev wrote:
> On 1/11/24 15:15, Andrey Drobyshev wrote:
>> On 11/1/23 18:13, Denis V. Lunev wrote:
>>> On 11/1/23 16:23, Andrey Drobyshev wrote:
>>>> Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
>>>> KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
>>>> extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
>>>> exit.  That's a natural thing to do since in this case guest is no
>>>> longer operational anyway.
>>>>
>>>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>>>> Acked-by: Denis V. Lunev <den@virtuozzo.com>
>>>> ---
>>>>   accel/kvm/kvm-all.c | 19 +++++++++++++++----
>>>>   1 file changed, 15 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>>>> index e39a810a4e..d74b3f0b0e 100644
>>>> --- a/accel/kvm/kvm-all.c
>>>> +++ b/accel/kvm/kvm-all.c
>>>> @@ -2816,6 +2816,14 @@ static void kvm_eat_signals(CPUState *cpu)
>>>>       } while (sigismember(&chkset, SIG_IPI));
>>>>   }
>>>>   +static void kvm_emit_guest_crash(CPUState *cpu)
>>>> +{
>>>> +    kvm_cpu_synchronize_state(cpu);
>>>> +    qemu_mutex_lock_iothread();
>>>> +    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>>>> +    qemu_mutex_unlock_iothread();
>>>> +}
>>>> +
>>>>   int kvm_cpu_exec(CPUState *cpu)
>>>>   {
>>>>       struct kvm_run *run = cpu->kvm_run;
>>>> @@ -2969,21 +2977,24 @@ int kvm_cpu_exec(CPUState *cpu)
>>>>                   ret = EXCP_INTERRUPT;
>>>>                   break;
>>>>               case KVM_SYSTEM_EVENT_CRASH:
>>>> -                kvm_cpu_synchronize_state(cpu);
>>>> -                qemu_mutex_lock_iothread();
>>>> -                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
>>>> -                qemu_mutex_unlock_iothread();
>>>> +                kvm_emit_guest_crash(cpu);
>>>>                   ret = 0;
>>>>                   break;
>>>>               default:
>>>>                   DPRINTF("kvm_arch_handle_exit\n");
>>>>                   ret = kvm_arch_handle_exit(cpu, run);
>>>> +                if (ret < 0) {
>>>> +                    kvm_emit_guest_crash(cpu);
>>>> +                }
>>>>                   break;
>>>>               }
>>>>               break;
>>>>           default:
>>>>               DPRINTF("kvm_arch_handle_exit\n");
>>>>               ret = kvm_arch_handle_exit(cpu, run);
>>>> +            if (ret < 0) {
>>>> +                kvm_emit_guest_crash(cpu);
>>>> +            }
>>>>               break;
>>>>           }
>>>>       } while (ret == 0);
>>> This allows to gracefully handle this problem in production
>>> and reset the guest using on_crash action in libvirt.
>>
>> Ping
> 
> Ping

Yet another ping
Alex Bennée Feb. 9, 2024, 5:46 p.m. UTC | #6
Andrey Drobyshev <andrey.drobyshev@virtuozzo.com> writes:

(Add kvm@vger to CC for wider review)

> Currently we emit GUEST_PANICKED event in case kvm_vcpu_ioctl() returns
> KVM_EXIT_SYSTEM_EVENT with the event type KVM_SYSTEM_EVENT_CRASH.  Let's
> extend this scenario and emit GUEST_PANICKED in case of an abnormal KVM
> exit.  That's a natural thing to do since in this case guest is no
> longer operational anyway.
>
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> Acked-by: Denis V. Lunev <den@virtuozzo.com>
> ---
>  accel/kvm/kvm-all.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index e39a810a4e..d74b3f0b0e 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2816,6 +2816,14 @@ static void kvm_eat_signals(CPUState *cpu)
>      } while (sigismember(&chkset, SIG_IPI));
>  }
>  
> +static void kvm_emit_guest_crash(CPUState *cpu)
> +{
> +    kvm_cpu_synchronize_state(cpu);
> +    qemu_mutex_lock_iothread();
> +    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
> +    qemu_mutex_unlock_iothread();
> +}
> +
>  int kvm_cpu_exec(CPUState *cpu)
>  {
>      struct kvm_run *run = cpu->kvm_run;
> @@ -2969,21 +2977,24 @@ int kvm_cpu_exec(CPUState *cpu)
>                  ret = EXCP_INTERRUPT;
>                  break;
>              case KVM_SYSTEM_EVENT_CRASH:
> -                kvm_cpu_synchronize_state(cpu);
> -                qemu_mutex_lock_iothread();
> -                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
> -                qemu_mutex_unlock_iothread();
> +                kvm_emit_guest_crash(cpu);
>                  ret = 0;
>                  break;
>              default:
>                  DPRINTF("kvm_arch_handle_exit\n");
>                  ret = kvm_arch_handle_exit(cpu, run);
> +                if (ret < 0) {
> +                    kvm_emit_guest_crash(cpu);
> +                }
>                  break;
>              }
>              break;
>          default:
>              DPRINTF("kvm_arch_handle_exit\n");
>              ret = kvm_arch_handle_exit(cpu, run);
> +            if (ret < 0) {
> +                kvm_emit_guest_crash(cpu);
> +            }
>              break;
>          }
>      } while (ret == 0);
diff mbox series

Patch

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index e39a810a4e..d74b3f0b0e 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2816,6 +2816,14 @@  static void kvm_eat_signals(CPUState *cpu)
     } while (sigismember(&chkset, SIG_IPI));
 }
 
+static void kvm_emit_guest_crash(CPUState *cpu)
+{
+    kvm_cpu_synchronize_state(cpu);
+    qemu_mutex_lock_iothread();
+    qemu_system_guest_panicked(cpu_get_crash_info(cpu));
+    qemu_mutex_unlock_iothread();
+}
+
 int kvm_cpu_exec(CPUState *cpu)
 {
     struct kvm_run *run = cpu->kvm_run;
@@ -2969,21 +2977,24 @@  int kvm_cpu_exec(CPUState *cpu)
                 ret = EXCP_INTERRUPT;
                 break;
             case KVM_SYSTEM_EVENT_CRASH:
-                kvm_cpu_synchronize_state(cpu);
-                qemu_mutex_lock_iothread();
-                qemu_system_guest_panicked(cpu_get_crash_info(cpu));
-                qemu_mutex_unlock_iothread();
+                kvm_emit_guest_crash(cpu);
                 ret = 0;
                 break;
             default:
                 DPRINTF("kvm_arch_handle_exit\n");
                 ret = kvm_arch_handle_exit(cpu, run);
+                if (ret < 0) {
+                    kvm_emit_guest_crash(cpu);
+                }
                 break;
             }
             break;
         default:
             DPRINTF("kvm_arch_handle_exit\n");
             ret = kvm_arch_handle_exit(cpu, run);
+            if (ret < 0) {
+                kvm_emit_guest_crash(cpu);
+            }
             break;
         }
     } while (ret == 0);