From nobody Sun May 12 14:13:21 2024 Delivered-To: importer@patchew.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525180923488449.91563616381404; Tue, 1 May 2018 06:22:03 -0700 (PDT) Received: from localhost ([::1]:42508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDVEI-0005CP-5H for importer@patchew.org; Tue, 01 May 2018 09:22:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDVDK-0004sc-D7 for qemu-devel@nongnu.org; Tue, 01 May 2018 09:21:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDVDH-0001B3-49 for qemu-devel@nongnu.org; Tue, 01 May 2018 09:21:02 -0400 Received: from mail-ve1eur01on0110.outbound.protection.outlook.com ([104.47.1.110]:25520 helo=EUR01-VE1-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 1fDVDG-00019w-9m for qemu-devel@nongnu.org; Tue, 01 May 2018 09:20:59 -0400 Received: from localhost.localdomain (93.175.11.132) by DB6PR08MB2855.eurprd08.prod.outlook.com (2603:10a6:6:20::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.715.18; Tue, 1 May 2018 13:20:54 +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=novDytB24N1EvOyHjALny839QC0+00qgyi8VrfGX0Os=; b=d/aY8qAoV2+RQdLmJQI6JB0H5p7guWcxnoePU5onZgDz/CSDitwfWxfwj6JKjaNxxz8y6SczClcH0NFP9BvEGAGL6F4OVuSHS9b/Tjj7Vr1SkBOr/xhmqUzyByY1067SYBHfLXOY+ghGKFAevHTGBqE7MKJL7kkoUB3DMRo/aBw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=viktor.prutyanov@virtuozzo.com; From: Viktor Prutyanov To: qemu-devel@nongnu.org Date: Tue, 1 May 2018 16:20:31 +0300 Message-ID: <20180501132031.13270-1-viktor.prutyanov@virtuozzo.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [93.175.11.132] X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To DB6PR08MB2855.eurprd08.prod.outlook.com (2603:10a6:6:20::26) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB6PR08MB2855; X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2855; 3:+5CcggWiEwJZVSJmwC1eJ3VfLjry8yWRAfyWCpzzNuCR8Gz2lKc/grm8x2zqLXQBj6vATWtfhANVG2n+i5A3tXE/leyyHj8WbeyhSspsJQ2isUGsJFRTeF5NTV3dx9apI8FaR7SzJCqWBULvGqfdIx3og1J1CFdUEXjZIceeNu+bJs8JvW/7IR8gk7GLPXb5iA7u13Fptj6KX9JxA5X2eYGYV6B5HfCEan2GRtCMHbmU8HUPTgrfTKG/2Magb9cD; 25:slcv6VHGuZ81yeP9gAfDlXLzdjve8q37GDPOO3mWzHpkD1ezcSgSUfjihsDBb6vIFVzWNIpFjGddeWkO7zOJcZpG7J972bgDX2JEnevM9vJAiF8ZhCGUgJgcJ8jIoOi5GQRnLLjjAPDgbe7a48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acP9V9wL/CnDvwwEyO7xevPbsmzwDEDxD3z7dzMlekU48jK+On6iJUfmy/qHd4dfrY971rnT3G3Ljo4t2pxDn5xKg2oAtodfLt8LHSAIcMMZpuRDNZ5+FFy4IRTCdBLCGLlaAaSUpVq7mQOAXTJ4LPO2MPFqhNbcs1qxClDptYjqE0O2XXnaRvAMYJNqNvCb7xULzu+h6pR2rb6wgXgzAYowYInOHvPfQ7FsBBGmiIiSm/wEUGhY9XqHfhA7AbvEGsFPR0d2Z9XowzSnxRVfpUvHw== 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)(8121501046)(5005006)(3231254)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(6041310)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:DB6PR08MB2855; BCL:0; PCL:0; RULEID:; SRVR:DB6PR08MB2855; X-Forefront-PRVS: 06592CCE58 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(979002)(6069001)(346002)(366004)(39830400003)(39380400002)(396003)(376002)(189003)(199004)(386003)(316002)(6506007)(2906002)(6116002)(1076002)(59450400001)(97736004)(52116002)(6486002)(47776003)(8676002)(478600001)(106356001)(6916009)(2351001)(4326008)(26005)(5660300001)(2870700001)(476003)(81166006)(66066001)(50226002)(107886003)(53936002)(86362001)(68736007)(50466002)(6512007)(25786009)(2616005)(36756003)(16526019)(6666003)(956004)(486006)(8936002)(2361001)(105586002)(81156014)(305945005)(6306002)(966005)(575784001)(23676004)(7736002)(186003)(3846002)(44832011)(19627235001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR08MB2855; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; 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; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR08MB2855; 23:gdCSIa0k3v5Y0r8CtIsjkWNf6jU+Cush8c+6YaHOH?= =?us-ascii?Q?RowygdEb0Btc9MrrhGWQ+34SZ+w2zC4I1T4s0yAn1LQBIN/dS4GTd3cpJuBg?= =?us-ascii?Q?WE+x6bkukAcaajDdne0FUojA9BloZIck8MVhABJuTO+u0wkocBD9VMPYR+RY?= =?us-ascii?Q?TMk/9pYJVrX+5C0qYBvkVkfHb1YzE3Zx7qnCEN48RgwwQhumuplHhADdWPjU?= =?us-ascii?Q?BzfXa8qgRwTnogRQM21w0zbMHb64oa5uJbvhYm+P0uvZx5NSQ7iAjOgmZcdz?= =?us-ascii?Q?AUoif470jMXVqGhsz2foEUQwk3uh30yX4sQZboj5msV1izoOA+N/dLH/fpTf?= =?us-ascii?Q?Qv1Ufwi7h2S+1GY/p6TZpASf2hAyN2s5nZ2lIpxq+ypMuQBDDp9hff5cmtLu?= =?us-ascii?Q?Scijc40sz+4seL8p2mLokqt3Ad3/57AEWMDHs6m9MK3H2MRV/D5KQcF++Y2J?= =?us-ascii?Q?v+wnhRYwR+FFkP+9rTNLlSTmfDI2fivGR7YiGWutS0DkHbVVD3mrRSn2x2Yc?= =?us-ascii?Q?yQ62jA2T9Y/nVOOjhJo56xbRHL2QtTBm9nAPcKQb5+VcXaXXgfdtsOSFN174?= =?us-ascii?Q?XYX/9nKooJ+RkCqUp5uwswXeMeYPpCwwWp+8z3Ra9JdiN7srPzmCA4V3Smyx?= =?us-ascii?Q?sMrMk9kkg6SRflaun4ye6RwQi5Jv20dbCeMgjGIr22T96HtKSnGWYGU2OV/j?= =?us-ascii?Q?ldQq9aanrWDbY/Tk/b9vo38caM/1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+S1wbEOs9AB0yVuqBtu2q+fDBFOwNvRrDUfjBq X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2855; 6:rn01v9Nky4nYLmJwluRCWJ3cOjhlt7M0leZD1PEzvPQ72JKZQF5N+uvTnn6wi0drmIwX6VByJuPjhCsadzFVp0m6P7Dg7BcKAOY93ZTFR4z/OLwCDKzyEceP7LfulP6x5SqmVYAiuHshCtvURTkrzt6siIzSSJBDpPvfm2leqbXo6OYH18kIJR7NyRcgeu2cudsySwkzXWYgJwA2ugd3MtlmVgi5opRjpTzi7MICaB7g4y3s8pSZewnzeTyT45fXeXOA3B3kaIpE9znCcWiQh4LYIdzP6DQy3RVjw6yffVEj14scRBDOlOc8NC6bVceDLcjBoYdWCD3i9tYymXIPW/gQYrUkIyyAMh2pHsiJLbffhyu0/+D+zjTYonxzA1dsCamDgRSuqDv/luJadTDjUy0ppUeh4Cl+pXztmbWkW/3pEgVAtGDE2juYEPV7q1Q+nM9lYwmMnds8V5yxFVDTpw==; 5:o4PxQNrW2qWr5gO/Y4DIos5h0DA/Cz1hjS1k98A3FyHnBpWD25q7Mi9PWyDVf/iWI1ff1VII03hCd5ZjEQcIpOUDXJzIn6ssnzEqeQr61ERBem/X1Ee7djdEUYzRzpngE9N6KF8to+yoXMB4GSTqJjHklNKApTvZHIs6+HmpQ9g=; 24:r9AOBdlxteZVvYPFsQYumh5vpSd0d2vcv00RsBvuTiJnJJB21RcqEQMZAsx5GdkpNDtZJt2mFPh35M4xtYNs6FnkD/SDK8YOFQB8+27OfR0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2855; 7:U6cUPKK/dwyUJ03pkjdgzkpexwKzzCJnXtHrH0CdcbJJ6LwFDlFFM7nH9yh+RVljd42CdjSOvIPAnSbHzh5BZDPI21PFHyKmjvO8g7FL982fgNw85jhD04/eCtaCSYzjEYjh9djTU06sV4NxVi+XqSQmg55bRU6Y+I19C5VBDAd0M8iUhIoQ8FXtEJG1TR8/9ybS+fn04U/+zdYc3k/Z+AZdJhW4oVXarhOma1doqvCUkNhc2nR7dkMc1LUCa0Z0; 20:tE7E/aadPyojwLjkubKXDHq/C7cSIGMB0hbVOYtSBcD+xFaWbqIhqCjseYorJxd0vaZXSCVW/f26g7Y8Wypr4RQaGs1G1G7it22KWmzN9cevZS9oVNyaZ8EjZZCNiyeE7n1cOa9h/mxt+nfw8OKSJ70btvWUGbaCab+kGHPijkg= X-MS-Office365-Filtering-Correlation-Id: 1294e44e-6ad2-4512-587f-08d5af665e9c X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2018 13:20:54.5997 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1294e44e-6ad2-4512-587f-08d5af665e9c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2855 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.110 Subject: [Qemu-devel] [PATCH v4] 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: marcandre.lureau@redhat.com, Viktor Prutyanov , rkagan@virtuozzo.com, armbru@redhat.com, dgilbert@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-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 Acked-by: Markus Armbruster --- v1: documentation updated v2: qapi/misc.json updated with version info v3: qapi/misc.json codestyle fixed v4: make error processing more quality Makefile.target | 1 + dump.c | 24 ++++++- hmp-commands.hx | 13 ++-- hmp.c | 9 ++- qapi/misc.json | 5 +- win_dump.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ win_dump.h | 87 +++++++++++++++++++++++ 7 files changed, 339 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..83f2df6b41 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1645,10 +1645,13 @@ # # @kdump-snappy: kdump-compressed format with snappy-compressed # +# @win-dmp: Windows full crashdump format, +# can be used instead of ELF converting (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..58255c12ee --- /dev/null +++ b/win_dump.c @@ -0,0 +1,209 @@ +/* + * 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"); + 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); + local_err =3D NULL; + } + 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; + } +} + +static void check_kdbg(WinDumpHeader64 *h, Error **errp) +{ + const char OwnerTag[] =3D "KDBG"; + char read_OwnerTag[4]; + + if (cpu_memory_rw_debug(first_cpu, + h->KdDebuggerDataBlock + KDBG_OWNER_TAG_OFFSET64, + (uint8_t *)&read_OwnerTag, sizeof(read_OwnerTag), 0)) { + error_setg(errp, "win-dump: failed to read OwnerTag"); + return; + } + + if (memcmp(read_OwnerTag, OwnerTag, sizeof(read_OwnerTag))) { + error_setg(errp, "win-dump: invalid KDBG OwnerTag," + " expected '%.4s', got '%.4s'," + " KdDebuggerDataBlock seems to be encrypted", + OwnerTag, read_OwnerTag); + 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; + } + + check_kdbg(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..281241881e --- /dev/null +++ b/win_dump.h @@ -0,0 +1,87 @@ +/* + * 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_OWNER_TAG_OFFSET64 0x10 +#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