From nobody Sun Apr 28 15:59:28 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 1523907736614554.3469416893354; Mon, 16 Apr 2018 12:42:16 -0700 (PDT) Received: from localhost ([::1]:39211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8A10-0006DG-Kx for importer@patchew.org; Mon, 16 Apr 2018 15:42:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f89zP-0005G4-Py for qemu-devel@nongnu.org; Mon, 16 Apr 2018 15:40:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f89zM-0006dN-I0 for qemu-devel@nongnu.org; Mon, 16 Apr 2018 15:40:35 -0400 Received: from mail-eopbgr40125.outbound.protection.outlook.com ([40.107.4.125]:37664 helo=EUR03-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 1f89zL-0006bR-Iz for qemu-devel@nongnu.org; Mon, 16 Apr 2018 15:40:32 -0400 Received: from localhost.localdomain (93.175.11.132) by VI1PR08MB2864.eurprd08.prod.outlook.com (2603:10a6:802:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.14; Mon, 16 Apr 2018 19:40:26 +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=+XLl/DmJcQLY9+M3EGjl7Zt15ctvNAzuekLhwU7eMi8=; b=Pjd6v0p918Qwf+R2Q3GrH6JV4eGYhyAn5IYwoWz2UBTO88Vpiz5t98/cJCJydNZE9btiwcBRPMMAU4nBBD63+XqY0b7EhOfw4y47ZtRcrQp5QsMd3CW2Odv/w4BgU/0MHBRMipNoxWEU8U/50Girr9VorHQu1S6xGaJllzotjPw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=viktor.prutyanov@virtuozzo.com; From: Viktor Prutyanov To: qemu-devel@nongnu.org Date: Mon, 16 Apr 2018 22:40:11 +0300 Message-Id: <20180416194011.11969-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: PR0P264CA0030.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1::18) To VI1PR08MB2864.eurprd08.prod.outlook.com (2603:10a6:802:1f::12) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:VI1PR08MB2864; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB2864; 3:kI/20+y8PuoZVuyXLXTLD+ApgNtouaZ1f3MyBWBhiXzp4IugSRrdUKHpRvOJkQDojvJSpqBJLZem3NAXP4bYiY15ElDqKcW9tjMHEYoZ5aJcvnxzGitsx/2qBxl9f3wb7n8P7u9lD7X5EHA5Y+tD2qYCEzdoPAEEdCXrWsVRze8R1JkF8LQ7NV2TEqc4YV2Ij9ytiJfhnTmRhyadE/hag6zBYg6WSJjP8EIxPdTokdBKPd9UIWD0iIijMpJy29ft; 25:d4GNOWNYLc6Y6mtTu4rzw9msJJFycc1rIOoCwrQ081FCnu9kimhzEvugJNhO2Fm4wYNNZ8kzQlFNiplqh2s0dwjN/hVwQPr003sb8Zbvj7qg7uokoSPvll2GY6P2JcSwONvc/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dIf9ej0OwkOHXgzXtcOgpoY74QFvOkmw5V/8x2qD0QYp8VoSx/HhnCAwvVpATSxqw+juTN9qLvO1HkpBnQ3V359hzo2NHxr0auAG9bpXT57YgcJAK0bdcNOBrlQal3JDWqyPbbhpo+Qy1WqwGpod9g5yQIkKYrOc1uBLEOaqD0hVsIMv90pxvpk2dnEj51iyQZNjs+NEnsztW6Qhp77QSbJQlpwz5JKrnq6CFBAlcYyNt2nnvDGs5XWzZojyDauiXeWh+jvPtXyuE3JlsLmtJZs0LeKdvP4mG4DpU6Z/V4wuw== 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)(3231232)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011); SRVR:VI1PR08MB2864; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB2864; X-Forefront-PRVS: 0644578634 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39380400002)(376002)(366004)(396003)(39850400004)(346002)(189003)(199004)(44832011)(51416003)(68736007)(52116002)(8676002)(2906002)(106356001)(48376002)(81166006)(81156014)(26005)(478600001)(2351001)(16526019)(186003)(6916009)(59450400001)(2361001)(6666003)(5660300001)(966005)(47776003)(105586002)(66066001)(97736004)(36756003)(1076002)(305945005)(6116002)(53936002)(50226002)(4326008)(6512007)(25786009)(8936002)(50466002)(3846002)(6306002)(7736002)(107886003)(486006)(6486002)(2616005)(16586007)(386003)(575784001)(1857600001)(956004)(316002)(86362001)(6506007)(476003)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB2864; 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; VI1PR08MB2864; 23:QPw4ZhHkC5HQJUtSjyvuCNfL1+nLXP4MpRkr+nLkq?= =?us-ascii?Q?wpoa5MUBP/QIhhGXdP6VhJP/dDJC8SxfUuSQ0Q2yymbnMmhl3n7NbnBbAEh/?= =?us-ascii?Q?HnGKlnf6QKFwEy3hpg1U2O7mNaQfrO8YSzKC0BawLsLZIIJ5DwjzegFLji69?= =?us-ascii?Q?xBvmvHgjBdZ3GLH990gzeuviJOyDn49SQRkGV121P8lM6a0i64bOztUbivd4?= =?us-ascii?Q?/t9U6mC93IB5HgLUz0WK+X2DwggHDqCuGhKC2JDg84rB3GiWwgZMXCXDX+xb?= =?us-ascii?Q?OOVycllZKERvdwqmjU9MG6IDK1MeagPaWeAQcoEZ1xayh8IS8vhFI+sd9HeT?= =?us-ascii?Q?KJl+0/et3X0pKdLBoXoszvWjxj6yKVmGZ6mml67yt9Nz4g6Hc/dAzaDqZSxO?= =?us-ascii?Q?BR0J9mePPR3DEBmhwdQ0hPFijqfi6I8PsqjEep3nBUHt8DxI9nOVudAGX5WF?= =?us-ascii?Q?MTIK0UgOd7X5z+u5AqtUxtC7O0tmL3J/4Z6oI6TRCmW1W1ip6uDWVANFVzWZ?= =?us-ascii?Q?919yQOF7FheGOULx4ZCTxy3ADbrq+XawD+I9Ib19Epq0whi83F47o1QMVUWE?= =?us-ascii?Q?+6Id6C69zwKg6oBNPrw3+HefaK6BRoLdtKKhOIvOG2UmNh4ndkQhcldkkzVI?= =?us-ascii?Q?0w98uRb776baDp7sLPWZ2knlFd6gSqmwRo9jt5ZPsiekBn/xS4sK6DeM+N+J?= =?us-ascii?Q?N+pC8sJmFHx74dDppOOJE9LVea2Y0JByJaOdf/nrSUKXXXDX65MAiRWZcqmK?= =?us-ascii?Q?4dhsZshpF7FiQ3C+OTkNwvaSFqTrtj6oPPmmufmpexBF70OmZj0/hSfDBlwL?= =?us-ascii?Q?K84hpGDVUyv+Xrr+i9Mc5MQa2PQozImSrBaIzVAsus/iCOHUhTvkUg1LATdu?= =?us-ascii?Q?24FhMMMvDiZIf2SKPAmsFRn7KprkUpeZrPpyLr2QjRJegoLsX2B0ZoB47r8Y?= =?us-ascii?Q?jyHOL0kx1OkUr0ANCJi7Z5lXqIglHgLUnYrtz3fnHISQxdVyRx7dVCJc4ICS?= =?us-ascii?Q?O0iK573eB8ZDDPC0okiyC6lFEoLnC1Dg64fXJNMopdaGjxdf/NFpzacU7pzt?= =?us-ascii?Q?tAbXjneMF0KXh4myns51o1k+WrSKVLfA3AckQ88GKH/DGRKn9QgykjyB/nt6?= =?us-ascii?Q?I01kiJkUp3zeq8g0pJw48xREARL6l0BMhb7oiV6aoXV/Y47AZCCKjyqR++s7?= =?us-ascii?Q?HmnNJchmHhm0UvlKUX7QDLN62MDM9yAdVusCp25n7ZdAi7R/kfVWRsjGC+z0?= =?us-ascii?Q?UX3UU2ZztQs+FnEWTD+w+vbRXyxA3CASnggmecoUQxUAHFlzBYtwxiT/dCu5?= =?us-ascii?Q?2fw166d34rUNtTvhqdP/X25PPk/YunEmit+KkejT1c5kF+TQtRVviat3dTrE?= =?us-ascii?Q?fI4AApvDZtvEu3z7YKhHiJac4w=3D?= X-Microsoft-Antispam-Message-Info: hN7JVXnc1DfQZ3omKWs0gvh54L8UJGEWR41FDL+1Ywjmwp1/mgrRkwzJBgooX5EioDkIpM+zCRuFbQW/VJqSxa3gJ3B3w+E3UBj/uPnT6iiTUvpohYUb8VaqFegKE0L0qvxa4th9mlXo8SBxbyG1dhVc4ZbXoFwh/NUnG3x4hVXzcaaDl/YF+x1b9dSWKFvG X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB2864; 6:j3OENR8Z/Dr+4R8S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:/pm2dFg1kC8pomBveSTQxJrXvBxsB+f/1kTjH6ab1y6VeNAmYyakEcukfhXy547AM23/Xmmkjo8tO1vmiNX56v4uHEJEuG9RR6o1B5MFuJxySkQaVYVci5U+CAhYLaupENYyNAcO1NUFd1zcHJodNQSQr0BV1eCTlTAliS1KhGY= X-MS-Office365-Filtering-Correlation-Id: f07be858-b8de-4f90-c30b-08d5a3d1e793 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2018 19:40:26.4943 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f07be858-b8de-4f90-c30b-08d5a3d1e793 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB2864 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.125 Subject: [Qemu-devel] [PATCH] 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 crashdump file understandable for WinDbg. 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. Option '-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 --- 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 6549481096..f47ae7187e 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 6bdb0dbe23..961f26a7ee 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 @@ -1861,7 +1865,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); @@ -1965,6 +1973,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); @@ -2039,5 +2054,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..196aebea65 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,\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, + 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 679467d85a..7c93e5851d 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..25db4b17c5 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 +# # 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