From nobody Fri May 3 04:17:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491966218265796.7078856291296; Tue, 11 Apr 2017 20:03:38 -0700 (PDT) Received: from localhost ([::1]:41976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy8ZA-0008Jo-92 for importer@patchew.org; Tue, 11 Apr 2017 23:03:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy8YO-00082S-8h for qemu-devel@nongnu.org; Tue, 11 Apr 2017 23:02:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cy8YK-0001cT-A1 for qemu-devel@nongnu.org; Tue, 11 Apr 2017 23:02:44 -0400 Received: from out1.zte.com.cn ([202.103.147.172]:59578) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy8YJ-0001UE-Mg for qemu-devel@nongnu.org; Tue, 11 Apr 2017 23:02:40 -0400 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 12 Apr 2017 02:55:02 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v3C31TLl047661; Wed, 12 Apr 2017 11:01:29 +0800 (GMT-8) (envelope-from huang.yong@zte.com.cn) Received: from localhost.localdomain ([10.74.121.225]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017041211013309-577729 ; Wed, 12 Apr 2017 11:01:33 +0800 X-scanvirus: By SEG_CYREN AntiVirus Engine X-scanresult: CLEAN X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170412105502 From: Huang Yong To: pbonzini@redhat.com Date: Wed, 12 Apr 2017 10:59:59 +0800 Message-Id: <1491965999-17528-1-git-send-email-huang.yong@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-04-12 11:01:33, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-04-12 11:01:10, Serialize complete at 2017-04-12 11:01:10 X-MAIL: mse01.zte.com.cn v3C31TLl047661 X-HQIP: 127.0.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 202.103.147.172 Subject: [Qemu-devel] [PATCH] Main loop: Register a specific IO port to monitor guest linux os crash event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huang Yong , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When guest os crash, there is no way to notify qemu on the host quickly (wi= thin 1s), and it is not convenient for libvirt management. We suggest to register a IO port (wi= th specific addr) when qemu process be launched, on the other hand, a linux module which is compri= sed of kprobe hooks will be inserted in VM. When guest linux os crash, kprobe hooks write IO port me= ntioned above to notify qemu. With this approach, VM management component (e.g.libvirt) can monitor= VM running state in time. Signed-off-by: Huang Yong --- vl.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/vl.c b/vl.c index 0b4ed52..2760c52 100644 --- a/vl.c +++ b/vl.c @@ -129,9 +129,12 @@ int main(int argc, char **argv) #include "sysemu/replay.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "exec/memory.h" +#include "qapi/error.h" =20 #define MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 +#define CRASH_IO_PORT (0xcff0) =20 static const char *data_dir[16]; static int data_dir_idx; @@ -2939,6 +2942,37 @@ static int qemu_read_default_config_file(void) return 0; } =20 +static MemoryRegion crash_io; + +static uint64_t crash_io_read(void *opaque, hwaddr addr, + unsigned int size) +{ + return 0; +} + +static void crash_io_write(void *opaque, hwaddr addr, + uint64_t value, unsigned int size) +{ + qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, + false, NULL, &error_abort); +} + +static const MemoryRegionOps crash_io_ops =3D { + .read =3D crash_io_read, + .write =3D crash_io_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +static void init_crash_port(int port) +{ + int addr =3D port; + MemoryRegion *system_io =3D get_system_io(); + + memory_region_init_io(&crash_io, NULL, &crash_io_ops, + NULL, "crash_event_port", 2); + memory_region_add_subregion(system_io, addr, &crash_io); +} + int main(int argc, char **argv, char **envp) { int i; @@ -4706,6 +4740,7 @@ int main(int argc, char **argv, char **envp) =20 os_setup_post(); =20 + init_crash_port(CRASH_IO_PORT); main_loop(); replay_disable_events(); iothread_stop_all(); --=20 1.8.3.1