From nobody Sun Apr 28 10:31:21 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.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524073249812330.29654986682453; Wed, 18 Apr 2018 10:40:49 -0700 (PDT) Received: from localhost ([::1]:41343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8r4P-0006cF-LM for importer@patchew.org; Wed, 18 Apr 2018 13:40:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8r3O-00067E-0l for qemu-devel@nongnu.org; Wed, 18 Apr 2018 13:39:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8r3K-0007XI-R7 for qemu-devel@nongnu.org; Wed, 18 Apr 2018 13:39:34 -0400 Received: from mail-db5eur01on0128.outbound.protection.outlook.com ([104.47.2.128]:53929 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f8r3K-0007WV-4j for qemu-devel@nongnu.org; Wed, 18 Apr 2018 13:39:30 -0400 Received: from localhost.localdomain (93.175.11.132) by AM4PR08MB2849.eurprd08.prod.outlook.com (2603:10a6:205:d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.12; Wed, 18 Apr 2018 17:39:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=/Agjjp3Rz3EJRISvewVBv/r7hJvLKE7clyG3A6A2m/k=; b=MieBEmo9P3Vw3/zAUurmbzHfdGCDIpIzNg/I6bGPjEhHtDMBtayRyZ0ONGJJQ1+rzMNJGh3V/HYPUmV4gq9boCdxYtPgY9FAttF8vj2kzwjrWa1zokiTJeMW8DR3q0kUd55hzVPpQGmEpfvPKmvo/IcJ3fE2gx/tCDXwsR84fss= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Viktor Prutyanov To: qemu-devel@nongnu.org Date: Wed, 18 Apr 2018 20:39:01 +0300 Message-Id: <20180418173901.19843-1-viktor.prutyanov@virtuozzo.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-Originating-IP: [93.175.11.132] X-ClientProxiedBy: HE1PR0202CA0018.eurprd02.prod.outlook.com (2603:10a6:3:8c::28) To AM4PR08MB2849.eurprd08.prod.outlook.com (2603:10a6:205:d::31) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM4PR08MB2849; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB2849; 3:PF4F/5Q6RRbG4vyAsM5rGfrBq36NFkojD22zrVoowYANXCa+xMilwhiu1yW1gJRDJAPjZJVvQd/qL2FehWjoIOlxEko57Lslq51785hdzt8QlJ51vXXfCZl/tCe4N446pXTYJNwuetTDmOV1ivL2lKCcBIuc/IdjaBY19hF/fNOp7/NIb4VRNtRmUDjl3KTRepKauEFXEqcFO0blxC93xYnCyx8h73WhqPaG0s3p3lFPwgUxAVoeON7EGj+Taozg; 25:g71B70Zh0gFsOiK8SDbPJeWfkR7QkOFtqP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3Cx1H3hy1xBfczvzQ/fRCYwJ+zXwYdpwsWOWgCnLjB1; 4:u4KcMn6KUdBkgVSDG6OSqaeoTrBBtCjRYKIulRhKBxbFrAdXsq6SKq+XeHaVwI+UXmq9DIEHPVG1pMoBaJ3xZXS/3vZQWhnIGuJHdP7aSVP8Cgw7Pmh3eHCBEFCnQsAfiIUnwFJUhb7U7pmr0CurbOMnmxHgdUf1uZnoMtYCVQ8DvlJDEOiFax9rQ3sw1ZUylsLmoKDNCCPr4VivR87ztpb6uQ5dgKUn3Pxov1U0n92ds08frlqX9Zxe5VuDUSXMSrCg0ejUcHMsboATeFKbAAdM9zid1bCn89NsivlxDf4N/Z3RGSl/Vr3PPidovARfiT1GhuI4wVcV33aoViWilg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(6846125436962)(166708455590820); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231232)(944501327)(52105095)(10201501046)(93006095)(93001095)(3002001)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:AM4PR08MB2849; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB2849; X-Forefront-PRVS: 06469BCC91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(979002)(6069001)(39380400002)(366004)(376002)(396003)(346002)(39850400004)(189003)(199004)(8936002)(81166006)(2906002)(81156014)(48376002)(107886003)(52116002)(6916009)(6306002)(8676002)(478600001)(50466002)(51416003)(5660300001)(6666003)(26005)(3846002)(1076002)(7736002)(53936002)(6116002)(6512007)(4326008)(50226002)(47776003)(186003)(2351001)(66066001)(305945005)(2361001)(16526019)(86362001)(575784001)(6506007)(386003)(25786009)(16586007)(36756003)(956004)(966005)(316002)(44832011)(2616005)(59450400001)(6486002)(476003)(19627235001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR08MB2849; H:localhost.localdomain; FPR:; SPF:None; LANG:en; MLV:ovrnspm; PTR:InfoNoRecords; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR08MB2849; 23:NRTsHCQXBZcTxq4wHYDRVcZ6zS06hPa1h2pI5XJ6K?= =?us-ascii?Q?MdaBHIlHnRDJ7LK44I5BvZgRzn6H+YUWCtBjVcTXGVO4uoYQq9Sxtca0hCfi?= =?us-ascii?Q?4JDbmxOWPTrvexYe06YTlMFIvloicbuVXLVz+bpoJKnrleLCUhoXR0WgxdfQ?= =?us-ascii?Q?BlAzadWhzsxgJblt+btDSs3yJu0j6yE8MpVOaqCNy+65cnZmEa8d1P2jzOuQ?= =?us-ascii?Q?RY15qtj6IZj1wKyccGYCzXhtj0TsyrIJwCg3VEA2QS4pJbFsTe+/F0rpvw3W?= =?us-ascii?Q?dPgQ+NMo00ucb3W4LnqN+M+OyRiC7hVJ+BeBg+FGCMQXfSJeLTFu7xymvz/Q?= =?us-ascii?Q?j+mVxIDtS7UZ5GyNy7Cf3uh5qE4nuf15iCQYBqCABW6GB6w25/lB/YuzJ0Jj?= =?us-ascii?Q?tWsk6PddLLduhT4tz56RdiaFULtziCRmrP40cXcOMoI9lbljsK2g8TvTFgzo?= =?us-ascii?Q?vcAiVAgh852gZUXLABxwe7Uy0eC5L4ZlNrqhq9N3sVdgQArVSzbWooDlaLF+?= =?us-ascii?Q?U7jnpZmwg7zDDyTPokjkcXPVfrfJQBKwV5B4zrz10JkjnzM7HJmuERc0wfrf?= =?us-ascii?Q?cHzfnG8n1GHcY5eO+wCASYwV26X/kVipfejzO5GFGXojyKuwt+ZLbA0Rdg+W?= =?us-ascii?Q?rtDKCBUbJOHTnm4xEb6xkIz8Wz447s8vKFRHbR3V3fwtv/gdhRDTcXw7up8R?= =?us-ascii?Q?pr0FmoP6SKgDqWf5wtHWPgK32Izhz31hfe7sbLppy9UCbjPfufZU4NbeA0Lc?= =?us-ascii?Q?FgUIrd+NitERlDC2LwZ0xhgZqLFUZ9c9vroGJq2O83EZovOx52IDIiQ6zQR0?= =?us-ascii?Q?mJIBxUfuxTp8EjSr8/zQlWgkje2cHCcd7fPK8UEqE4KaXlYJbCLOq/l8Q/TB?= =?us-ascii?Q?fBvNnnlrOMaqg26+xArK0v5FxoO2Pvp6hAxvlZ8Uw4UdkYXIBCAA55xyIawS?= =?us-ascii?Q?v4mhreTlrMHtqM3rukwmIUgsLMMFDi6DpShtnQqLFOpQPIcHBpFuhyFJv4Ib?= =?us-ascii?Q?QTfGFp8yYsr0za3/DbCg4H3o80DI1bUjlfxXM8mFt4dVB4EMD07CSaLTK2mB?= =?us-ascii?Q?QJ4G3y/LJ4rMZ2TkBlxpHngfdmotJX7b+lAICGBMay4RGp74nzAlPbFlITSt?= =?us-ascii?Q?gVs1sUZvut+QbcSE/zFH3ufpSWBdM5vjIOem5ksvESMl8tfSWy6SWH9IaEWz?= =?us-ascii?Q?7ibsfFmFuhugf/nyeVKiXX+Wlzuoi9oOJrmtzMixgIrRerrfG2icJxX6/euC?= =?us-ascii?Q?suSy0UVF3xvVn4Jd59HtNuNYO59EuDCBCzIBnNR+tu4c829qxNHU4F5y/jyq?= =?us-ascii?Q?ia7bZIMXgmNhuLLRFKVg/5yXN6Fm6ihNARPdmq6KH7BFAWZgMaVIHhZno4my?= =?us-ascii?Q?Oozbw=3D=3D?= X-Microsoft-Antispam-Message-Info: ha0/5tCyfQGXDIyOc/jhGpb0WEhaVg9ddlhxqpxZINc/X42JoTjBIlr3EqqmqBv8Pkp4YVkNXDzfOH3ldl/J8SLWMySw0tHQ9EqI1xZrI40q3DkKivzTkXYiaimK0E4k157ueuh+FXnq+phcXywy0UbV7+uflnNZ9gmtHr+ADT9jQbmkwkIaCfcc0RwozM3e X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB2849; 6:FHbpF8iq1FDWfQJRRtJJBgOqXZseO9KROyXVJPemFprXGjgNthau6qEAd1K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EpKOVCzG2rEkK/dPn2HbvFn6MeX+w090WjI0e9UnWWxthSOk7GOXPk8gyZZiZSwXKZojDVJpNGSj/ViIcbIkAuMynfs53r81WqluOXO0KZQmaLgqCcg8PF9KThCfOg8= X-MS-Office365-Filtering-Correlation-Id: 3d136264-db28-4423-6509-08d5a55354ad X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2018 17:39:25.5092 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d136264-db28-4423-6509-08d5a55354ad X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2849 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.128 Subject: [Qemu-devel] [PATCH v2] dump: add Windows dump format to dump-guest-memory 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: armbru@redhat.com, dgilbert@redhat.com, Viktor Prutyanov , rkagan@virtuozzo.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch adds Windows crashdumping feature. Now QEMU can produce ELF-dump containing Windows crashdump header, which can help to convert to a valid WinDbg-understandable crashdump file, or immediately create such file. The crashdump will be obtained by joining physical memory dump and 8K header exposed through vmcoreinfo/fw_cfg device by guest driver at BSOD time. Opti= on '-w' was added to dump-guest-memory command. At the moment, only x64 configuration is supported. Suitable driver can be found at https://github.com/virtio-win/kvm-guest-drivers-windows/tree/master/fwcfg64 Signed-off-by: Viktor Prutyanov Reviewed-by: Marc-Andr=C3=A9 Lureau --- v1: documentation updated v2: qapi/misc.json updated with version info Makefile.target | 1 + dump.c | 24 +++++++- hmp-commands.hx | 13 ++-- hmp.c | 9 ++- qapi/misc.json | 4 +- win_dump.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ win_dump.h | 86 ++++++++++++++++++++++++++ 7 files changed, 310 insertions(+), 9 deletions(-) create mode 100644 win_dump.c create mode 100644 win_dump.h diff --git a/Makefile.target b/Makefile.target index d0ec77a307..6ae2609597 100644 --- a/Makefile.target +++ b/Makefile.target @@ -138,6 +138,7 @@ obj-y +=3D hw/ obj-y +=3D memory.o obj-y +=3D memory_mapping.o obj-y +=3D dump.o +obj-y +=3D win_dump.o obj-y +=3D migration/ram.o LIBS :=3D $(libs_softmmu) $(LIBS) =20 diff --git a/dump.c b/dump.c index b54cd42b21..04467b353e 100644 --- a/dump.c +++ b/dump.c @@ -29,6 +29,10 @@ #include "qemu/error-report.h" #include "hw/misc/vmcoreinfo.h" =20 +#ifdef TARGET_X86_64 +#include "win_dump.h" +#endif + #include #ifdef CONFIG_LZO #include @@ -1866,7 +1870,11 @@ static void dump_process(DumpState *s, Error **errp) Error *local_err =3D NULL; DumpQueryResult *result =3D NULL; =20 - if (s->has_format && s->format !=3D DUMP_GUEST_MEMORY_FORMAT_ELF) { + if (s->has_format && s->format =3D=3D DUMP_GUEST_MEMORY_FORMAT_WIN_DMP= ) { +#ifdef TARGET_X86_64 + create_win_dump(s, &local_err); +#endif + } else if (s->has_format && s->format !=3D DUMP_GUEST_MEMORY_FORMAT_EL= F) { create_kdump_vmcore(s, &local_err); } else { create_vmcore(s, &local_err); @@ -1970,6 +1978,13 @@ void qmp_dump_guest_memory(bool paging, const char *= file, } #endif =20 +#ifndef TARGET_X86_64 + if (has_format && format =3D=3D DUMP_GUEST_MEMORY_FORMAT_WIN_DMP) { + error_setg(errp, "Windows dump is only available for x86-64"); + return; + } +#endif + #if !defined(WIN32) if (strstart(file, "fd:", &p)) { fd =3D monitor_get_fd(cur_mon, p, errp); @@ -2044,5 +2059,12 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memo= ry_capability(Error **errp) item->value =3D DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY; #endif =20 + /* Windows dump is available only if target is x86_64 */ +#ifdef TARGET_X86_64 + item->next =3D g_malloc0(sizeof(DumpGuestMemoryFormatList)); + item =3D item->next; + item->value =3D DUMP_GUEST_MEMORY_FORMAT_WIN_DMP; +#endif + return cap; } diff --git a/hmp-commands.hx b/hmp-commands.hx index 35d862a5d2..6f35e4f5d0 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1088,30 +1088,33 @@ ETEXI =20 { .name =3D "dump-guest-memory", - .args_type =3D "paging:-p,detach:-d,zlib:-z,lzo:-l,snappy:-s,file= name:F,begin:i?,length:i?", - .params =3D "[-p] [-d] [-z|-l|-s] filename [begin length]", + .args_type =3D "paging:-p,detach:-d,windmp:-w,zlib:-z,lzo:-l,snap= py:-s,filename:F,begin:i?,length:i?", + .params =3D "[-p] [-d] [-z|-l|-s|-w] filename [begin length]", .help =3D "dump guest memory into file 'filename'.\n\t\t\t" "-p: do paging to get guest's memory mapping.\n\t\t\= t" "-d: return immediately (do not wait for completion)= .\n\t\t\t" "-z: dump in kdump-compressed format, with zlib comp= ression.\n\t\t\t" "-l: dump in kdump-compressed format, with lzo compr= ession.\n\t\t\t" "-s: dump in kdump-compressed format, with snappy co= mpression.\n\t\t\t" + "-w: dump in Windows crashdump format (can be used i= nstead of ELF-dump converting),\n\t\t\t" + " for Windows x64 guests with vmcoreinfo driver o= nly.\n\t\t\t" "begin: the starting physical address.\n\t\t\t" "length: the memory size, in bytes.", .cmd =3D hmp_dump_guest_memory, }, =20 - STEXI @item dump-guest-memory [-p] @var{filename} @var{begin} @var{length} -@item dump-guest-memory [-z|-l|-s] @var{filename} +@item dump-guest-memory [-z|-l|-s|-w] @var{filename} @findex dump-guest-memory Dump guest memory to @var{protocol}. The file can be processed with crash = or -gdb. Without -z|-l|-s, the dump format is ELF. +gdb. Without -z|-l|-s|-w, the dump format is ELF. -p: do paging to get guest's memory mapping. -z: dump in kdump-compressed format, with zlib compression. -l: dump in kdump-compressed format, with lzo compression. -s: dump in kdump-compressed format, with snappy compression. + -w: dump in Windows crashdump format (can be used instead of ELF-d= ump converting), + for Windows x64 guests with vmcoreinfo driver only filename: dump file name. begin: the starting physical address. It's optional, and should be specified together with length. diff --git a/hmp.c b/hmp.c index a25c7bd9a8..bb6a6eaf00 100644 --- a/hmp.c +++ b/hmp.c @@ -1951,6 +1951,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict) void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; + bool win_dmp =3D qdict_get_try_bool(qdict, "windmp", false); bool paging =3D qdict_get_try_bool(qdict, "paging", false); bool zlib =3D qdict_get_try_bool(qdict, "zlib", false); bool lzo =3D qdict_get_try_bool(qdict, "lzo", false); @@ -1965,12 +1966,16 @@ void hmp_dump_guest_memory(Monitor *mon, const QDic= t *qdict) enum DumpGuestMemoryFormat dump_format =3D DUMP_GUEST_MEMORY_FORMAT_EL= F; char *prot; =20 - if (zlib + lzo + snappy > 1) { - error_setg(&err, "only one of '-z|-l|-s' can be set"); + if (zlib + lzo + snappy + win_dmp > 1) { + error_setg(&err, "only one of '-z|-l|-s|-w' can be set"); hmp_handle_error(mon, &err); return; } =20 + if (win_dmp) { + dump_format =3D DUMP_GUEST_MEMORY_FORMAT_WIN_DMP; + } + if (zlib) { dump_format =3D DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB; } diff --git a/qapi/misc.json b/qapi/misc.json index 5636f4a149..69005052bf 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1645,10 +1645,12 @@ # # @kdump-snappy: kdump-compressed format with snappy-compressed # +# @win-dmp: Windows full crashdump format, can be used instead of ELF conv= erting (since 2.13) +# # Since: 2.0 ## { 'enum': 'DumpGuestMemoryFormat', - 'data': [ 'elf', 'kdump-zlib', 'kdump-lzo', 'kdump-snappy' ] } + 'data': [ 'elf', 'kdump-zlib', 'kdump-lzo', 'kdump-snappy', 'win-dmp' ] } =20 ## # @dump-guest-memory: diff --git a/win_dump.c b/win_dump.c new file mode 100644 index 0000000000..75028083d8 --- /dev/null +++ b/win_dump.c @@ -0,0 +1,182 @@ +/* + * Windows crashdump + * + * Copyright (c) 2018 Virtuozzo International GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "elf.h" +#include "cpu.h" +#include "exec/hwaddr.h" +#include "monitor/monitor.h" +#include "sysemu/kvm.h" +#include "sysemu/dump.h" +#include "sysemu/sysemu.h" +#include "sysemu/memory_mapping.h" +#include "sysemu/cpus.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" +#include "hw/misc/vmcoreinfo.h" +#include "win_dump.h" + +static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp) +{ + void *buf; + uint64_t addr =3D run->BasePage << TARGET_PAGE_BITS; + uint64_t size =3D run->PageCount << TARGET_PAGE_BITS; + uint64_t len =3D size; + + buf =3D cpu_physical_memory_map(addr, &len, false); + if (!buf) { + error_setg(errp, "win-dump: failed to map run"); + return 0; + } + if (len !=3D size) { + error_setg(errp, "win-dump: failed to map entire run"); + len =3D 0; + goto out_unmap; + } + + len =3D qemu_write_full(fd, buf, len); + if (len !=3D size) { + error_setg(errp, QERR_IO_ERROR); + } + +out_unmap: + cpu_physical_memory_unmap(buf, addr, false, len); + + return len; +} + +static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp) +{ + WinDumpPhyMemDesc64 *desc =3D &h->PhysicalMemoryBlock; + WinDumpPhyMemRun64 *run =3D desc->Run; + Error *local_err =3D NULL; + int i; + + for (i =3D 0; i < desc->NumberOfRuns; i++) { + s->written_size +=3D write_run(run + i, s->fd, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } +} + +static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp) +{ + if (cpu_memory_rw_debug(first_cpu, + h->KdDebuggerDataBlock + KDBG_MM_PFN_DATABASE_OFFSET64, + (uint8_t *)&h->PfnDatabase, sizeof(h->PfnDatabase), 0)) { + error_setg(errp, "win-dump: failed to read MmPfnDatabase"); + return; + } +} + +static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp) +{ + uint64_t KiBugcheckData; + + if (cpu_memory_rw_debug(first_cpu, + h->KdDebuggerDataBlock + KDBG_KI_BUGCHECK_DATA_OFFSET64, + (uint8_t *)&KiBugcheckData, sizeof(KiBugcheckData), 0)) { + error_setg(errp, "win-dump: failed to read KiBugcheckData"); + return; + } + + if (cpu_memory_rw_debug(first_cpu, + KiBugcheckData, + h->BugcheckData, sizeof(h->BugcheckData), 0)) { + error_setg(errp, "win-dump: failed to read bugcheck data," + " KdDebuggerDataBlock may be encrypted."); + return; + } +} + +/* + * This routine tries to correct mistakes in crashdump header. + */ +static void patch_header(WinDumpHeader64 *h) +{ + Error *local_err =3D NULL; + + h->RequiredDumpSpace =3D sizeof(WinDumpHeader64) + + (h->PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS); + h->PhysicalMemoryBlock.unused =3D 0; + h->unused1 =3D 0; + + /* + * We assume h->DirectoryBase and current CR3 are the same when we acc= ess + * memory by virtual address. In other words, we suppose current conte= xt + * is system context. It is definetely true in case of BSOD. + */ + + patch_mm_pfn_database(h, &local_err); + if (local_err) { + warn_report_err(local_err); + } + patch_bugcheck_data(h, &local_err); + if (local_err) { + warn_report_err(local_err); + } +} + +static void check_header(WinDumpHeader64 *h, Error **errp) +{ + const char Signature[] =3D "PAGE"; + const char ValidDump[] =3D "DU64"; + + if (memcmp(h->Signature, Signature, sizeof(h->Signature))) { + error_setg(errp, "win-dump: invalid header, expected '%.4s'," + " got '%.4s'", Signature, h->Signature); + return; + } + + if (memcmp(h->ValidDump, ValidDump, sizeof(h->ValidDump))) { + error_setg(errp, "win-dump: invalid header, expected '%.4s'," + " got '%.4s'", ValidDump, h->ValidDump); + return; + } +} + +void create_win_dump(DumpState *s, Error **errp) +{ + WinDumpHeader64 *h =3D (WinDumpHeader64 *)(s->guest_note + + VMCOREINFO_ELF_NOTE_HDR_SIZE); + Error *local_err =3D NULL; + + if (s->guest_note_size !=3D sizeof(WinDumpHeader64) + + VMCOREINFO_ELF_NOTE_HDR_SIZE) { + error_setg(errp, "win-dump: invalid vmcoreinfo note size"); + return; + } + + check_header(h, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + patch_header(h); + + s->total_size =3D h->RequiredDumpSpace; + + s->written_size =3D qemu_write_full(s->fd, h, sizeof(*h)); + if (s->written_size !=3D sizeof(*h)) { + error_setg(errp, QERR_IO_ERROR); + return; + } + + write_runs(s, h, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } +} diff --git a/win_dump.h b/win_dump.h new file mode 100644 index 0000000000..7a76fd4528 --- /dev/null +++ b/win_dump.h @@ -0,0 +1,86 @@ +/* + * Windows crashdump + * + * Copyright (c) 2018 Virtuozzo International GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +typedef struct WinDumpPhyMemRun64 { + uint64_t BasePage; + uint64_t PageCount; +} QEMU_PACKED WinDumpPhyMemRun64; + +typedef struct WinDumpPhyMemDesc64 { + uint32_t NumberOfRuns; + uint32_t unused; + uint64_t NumberOfPages; + WinDumpPhyMemRun64 Run[43]; +} QEMU_PACKED WinDumpPhyMemDesc64; + +typedef struct WinDumpExceptionRecord { + uint32_t ExceptionCode; + uint32_t ExceptionFlags; + uint64_t ExceptionRecord; + uint64_t ExceptionAddress; + uint32_t NumberParameters; + uint32_t unused; + uint64_t ExceptionInformation[15]; +} QEMU_PACKED WinDumpExceptionRecord; + +typedef struct WinDumpHeader64 { + char Signature[4]; + char ValidDump[4]; + uint32_t MajorVersion; + uint32_t MinorVersion; + uint64_t DirectoryTableBase; + uint64_t PfnDatabase; + uint64_t PsLoadedModuleList; + uint64_t PsActiveProcessHead; + uint32_t MachineImageType; + uint32_t NumberProcessors; + union { + struct { + uint32_t BugcheckCode; + uint32_t unused0; + uint64_t BugcheckParameter1; + uint64_t BugcheckParameter2; + uint64_t BugcheckParameter3; + uint64_t BugcheckParameter4; + }; + uint8_t BugcheckData[40]; + }; + uint8_t VersionUser[32]; + uint64_t KdDebuggerDataBlock; + union { + WinDumpPhyMemDesc64 PhysicalMemoryBlock; + uint8_t PhysicalMemoryBlockBuffer[704]; + }; + union { + uint8_t ContextBuffer[3000]; + }; + WinDumpExceptionRecord Exception; + uint32_t DumpType; + uint32_t unused1; + uint64_t RequiredDumpSpace; + uint64_t SystemTime; + char Comment[128]; + uint64_t SystemUpTime; + uint32_t MiniDumpFields; + uint32_t SecondaryDataState; + uint32_t ProductType; + uint32_t SuiteMask; + uint32_t WriterStatus; + uint8_t unused2; + uint8_t KdSecondaryVersion; + uint8_t reserved[4018]; +} QEMU_PACKED WinDumpHeader64; + +void create_win_dump(DumpState *s, Error **errp); + +#define KDBG_KI_BUGCHECK_DATA_OFFSET64 0x88 +#define KDBG_MM_PFN_DATABASE_OFFSET64 0xC0 + +#define VMCOREINFO_ELF_NOTE_HDR_SIZE 24 --=20 2.14.3