* [Qemu-devel] [PATCH 0/2 v2] kvm: notify host when guest paniced
@ 2012-03-07 1:50 Wen Congyang
2012-03-07 1:53 ` [Qemu-devel] [PATCH 1/2 " Wen Congyang
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Wen Congyang @ 2012-03-07 1:50 UTC (permalink / raw)
To: kvm list, qemu-devel, linux-kernel@vger.kernel.org, Avi Kivity,
Daniel P. Berrange, KAMEZAWA Hiroyuki, Jan Kiszka, Gleb Natapov
We can know the guest is paniced 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 crashed. If management
app does not do auto dump, the guest's user can do dump by hand if
he sees the guest is paniced.
I touch the hypervisor instead of using virtio-serial, because
1. it is simple
2. the virtio-serial is an optional device, and the guest may
not have such device.
Changes from v1 to v2:
1. split up host and guest-side changes
2. introduce new request flag to avoid changing return values.
Wen Congyang (2):
kvm: notify host when guest paniced
kvm: set exit_reason to KVM_EXIT_GUEST_PANICED when guest paniced
arch/x86/kernel/kvm.c | 12 ++++++++++++
arch/x86/kvm/x86.c | 11 +++++++++++
include/linux/kvm.h | 1 +
include/linux/kvm_host.h | 1 +
include/linux/kvm_para.h | 1 +
5 files changed, 26 insertions(+), 0 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 1/2 v2] kvm: notify host when guest paniced
2012-03-07 1:50 [Qemu-devel] [PATCH 0/2 v2] kvm: notify host when guest paniced Wen Congyang
@ 2012-03-07 1:53 ` Wen Congyang
2012-03-07 1:56 ` [Qemu-devel] [PATCH 2/2 v2] kvm: set exit_reason to KVM_EXIT_GUEST_PANICED " Wen Congyang
2012-03-07 1:58 ` [Qemu-devel] [PATCH v2] deal with guest paniced event Wen Congyang
2 siblings, 0 replies; 8+ messages in thread
From: Wen Congyang @ 2012-03-07 1:53 UTC (permalink / raw)
To: kvm list, qemu-devel, linux-kernel@vger.kernel.org, Avi Kivity,
Daniel P. Berrange, KAMEZAWA Hiroyuki, Jan Kiszka, Gleb Natapov
The implementation is the same as xen:
register panic notifier, and call hypercall when the guest
is paniced.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
arch/x86/kernel/kvm.c | 12 ++++++++++++
include/linux/kvm_para.h | 1 +
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index f0c6fd6..7f9afc5 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -331,6 +331,17 @@ static struct notifier_block kvm_pv_reboot_nb = {
.notifier_call = kvm_pv_reboot_notify,
};
+static int
+kvm_pv_panic_notify(struct notifier_block *nb, unsigned long code, void *unused)
+{
+ kvm_hypercall0(KVM_HC_GUEST_PANICED);
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block kvm_pv_panic_nb = {
+ .notifier_call = kvm_pv_panic_notify,
+};
+
static u64 kvm_steal_clock(int cpu)
{
u64 steal;
@@ -417,6 +428,7 @@ void __init kvm_guest_init(void)
paravirt_ops_setup();
register_reboot_notifier(&kvm_pv_reboot_nb);
+ atomic_notifier_chain_register(&panic_notifier_list, &kvm_pv_panic_nb);
for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
spin_lock_init(&async_pf_sleepers[i].lock);
if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
diff --git a/include/linux/kvm_para.h b/include/linux/kvm_para.h
index ff476dd..d030a22 100644
--- a/include/linux/kvm_para.h
+++ b/include/linux/kvm_para.h
@@ -19,6 +19,7 @@
#define KVM_HC_MMU_OP 2
#define KVM_HC_FEATURES 3
#define KVM_HC_PPC_MAP_MAGIC_PAGE 4
+#define KVM_HC_GUEST_PANICED 5
/*
* hypercalls use architecture specific
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 2/2 v2] kvm: set exit_reason to KVM_EXIT_GUEST_PANICED when guest paniced
2012-03-07 1:50 [Qemu-devel] [PATCH 0/2 v2] kvm: notify host when guest paniced Wen Congyang
2012-03-07 1:53 ` [Qemu-devel] [PATCH 1/2 " Wen Congyang
@ 2012-03-07 1:56 ` Wen Congyang
2012-03-07 1:58 ` [Qemu-devel] [PATCH v2] deal with guest paniced event Wen Congyang
2 siblings, 0 replies; 8+ messages in thread
From: Wen Congyang @ 2012-03-07 1:56 UTC (permalink / raw)
To: kvm list, qemu-devel, linux-kernel@vger.kernel.org, Avi Kivity,
Daniel P. Berrange, KAMEZAWA Hiroyuki, Jan Kiszka, Gleb Natapov
This patch introduces new request bit KVM_REQ_GUEST_PANICED.
If this bit is set, set vcpu's exit_reason to KVM_EXIT_GUEST_PANICED.
And then the user space can know the guest paniced.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
arch/x86/kvm/x86.c | 11 +++++++++++
include/linux/kvm.h | 1 +
include/linux/kvm_host.h | 1 +
3 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c9d99e5..978e398 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5013,6 +5013,10 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
case KVM_HC_VAPIC_POLL_IRQ:
ret = 0;
break;
+ case KVM_HC_GUEST_PANICED:
+ ret = 0;
+ kvm_make_request(KVM_REQ_GUEST_PANICED, vcpu);
+ break;
default:
ret = -KVM_ENOSYS;
break;
@@ -5228,6 +5232,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
r = 0;
goto out;
}
+
+ if (kvm_check_request(KVM_REQ_GUEST_PANICED, vcpu)) {
+ vcpu->run->exit_reason = KVM_EXIT_GUEST_PANICED;
+ r = 0;
+ goto out;
+ }
+
if (kvm_check_request(KVM_REQ_DEACTIVATE_FPU, vcpu)) {
vcpu->fpu_active = 0;
kvm_x86_ops->fpu_deactivate(vcpu);
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index acbe429..a46052e 100644
--- a/include/linux/kvm.h
+++ b/include/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/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 355e445..026bbe5 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -54,6 +54,7 @@
#define KVM_REQ_IMMEDIATE_EXIT 15
#define KVM_REQ_PMU 16
#define KVM_REQ_PMI 17
+#define KVM_REQ_GUEST_PANICED 18
#define KVM_USERSPACE_IRQ_SOURCE_ID 0
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v2] deal with guest paniced event
2012-03-07 1:50 [Qemu-devel] [PATCH 0/2 v2] kvm: notify host when guest paniced Wen Congyang
2012-03-07 1:53 ` [Qemu-devel] [PATCH 1/2 " Wen Congyang
2012-03-07 1:56 ` [Qemu-devel] [PATCH 2/2 v2] kvm: set exit_reason to KVM_EXIT_GUEST_PANICED " Wen Congyang
@ 2012-03-07 1:58 ` Wen Congyang
2012-03-07 2:40 ` Eric Blake
2012-03-07 9:53 ` Jan Kiszka
2 siblings, 2 replies; 8+ messages in thread
From: Wen Congyang @ 2012-03-07 1:58 UTC (permalink / raw)
To: kvm list, qemu-devel, linux-kernel@vger.kernel.org, Avi Kivity,
Daniel P. Berrange, KAMEZAWA Hiroyuki, Jan Kiszka, Gleb Natapov
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 ++++
| 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;
case KVM_EXIT_INTERNAL_ERROR:
ret = kvm_handle_internal_error(env, run);
break;
--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 },
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v2] deal with guest paniced event
2012-03-07 1:58 ` [Qemu-devel] [PATCH v2] deal with guest paniced event Wen Congyang
@ 2012-03-07 2:40 ` Eric Blake
2012-03-07 2:45 ` Wen Congyang
2012-03-07 9:53 ` Jan Kiszka
1 sibling, 1 reply; 8+ messages in thread
From: Eric Blake @ 2012-03-07 2:40 UTC (permalink / raw)
To: Wen Congyang
Cc: Gleb Natapov, kvm list, Jan Kiszka, qemu-devel,
linux-kernel@vger.kernel.org, Avi Kivity, KAMEZAWA Hiroyuki
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
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.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v2] deal with guest paniced event
2012-03-07 2:40 ` Eric Blake
@ 2012-03-07 2:45 ` Wen Congyang
0 siblings, 0 replies; 8+ messages in thread
From: Wen Congyang @ 2012-03-07 2:45 UTC (permalink / raw)
To: Eric Blake
Cc: Gleb Natapov, kvm list, Jan Kiszka, qemu-devel,
linux-kernel@vger.kernel.org, Avi Kivity, KAMEZAWA Hiroyuki
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
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v2] deal with guest paniced event
2012-03-07 1:58 ` [Qemu-devel] [PATCH v2] deal with guest paniced event Wen Congyang
2012-03-07 2:40 ` Eric Blake
@ 2012-03-07 9:53 ` Jan Kiszka
2012-03-07 10:05 ` Wen Congyang
1 sibling, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2012-03-07 9:53 UTC (permalink / raw)
To: Wen Congyang
Cc: Gleb Natapov, kvm list, qemu-devel, linux-kernel@vger.kernel.org,
Avi Kivity, KAMEZAWA Hiroyuki
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
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v2] deal with guest paniced event
2012-03-07 9:53 ` Jan Kiszka
@ 2012-03-07 10:05 ` Wen Congyang
0 siblings, 0 replies; 8+ messages in thread
From: Wen Congyang @ 2012-03-07 10:05 UTC (permalink / raw)
To: Jan Kiszka
Cc: Gleb Natapov, kvm list, qemu-devel, linux-kernel@vger.kernel.org,
Avi Kivity, KAMEZAWA Hiroyuki
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
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-03-07 10:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-07 1:50 [Qemu-devel] [PATCH 0/2 v2] kvm: notify host when guest paniced Wen Congyang
2012-03-07 1:53 ` [Qemu-devel] [PATCH 1/2 " Wen Congyang
2012-03-07 1:56 ` [Qemu-devel] [PATCH 2/2 v2] kvm: set exit_reason to KVM_EXIT_GUEST_PANICED " Wen Congyang
2012-03-07 1:58 ` [Qemu-devel] [PATCH v2] deal with guest paniced event Wen Congyang
2012-03-07 2:40 ` Eric Blake
2012-03-07 2:45 ` Wen Congyang
2012-03-07 9:53 ` Jan Kiszka
2012-03-07 10:05 ` Wen Congyang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).