From nobody Wed May 1 22:37:34 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 1524479601604580.533922073434; Mon, 23 Apr 2018 03:33:21 -0700 (PDT) Received: from localhost ([::1]:34473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAYkc-0007VL-Iq for importer@patchew.org; Mon, 23 Apr 2018 06:31:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAYiE-00060G-7L for qemu-devel@nongnu.org; Mon, 23 Apr 2018 06:28:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAYi9-0004Hw-6f for qemu-devel@nongnu.org; Mon, 23 Apr 2018 06:28:46 -0400 Received: from mail-db5eur01on0114.outbound.protection.outlook.com ([104.47.2.114]:36256 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 1fAYi8-0004GY-NQ for qemu-devel@nongnu.org; Mon, 23 Apr 2018 06:28:41 -0400 Received: from vp-pc.sw.ru (195.214.232.6) by DB6PR08MB2853.eurprd08.prod.outlook.com (10.170.222.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Mon, 23 Apr 2018 10:28:36 +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=2rKhO9MA4qXZf7EH9+P39PyPs8jTgcUQBUF31TT4Ips=; b=I8Vzh99vkXPXiwUL1oABnNtJwTVTdsBZJBdgFzW8J86rIeAuLOtYB7Gr1zm2cZD3b65tQ2WNEJajtmNMLLhmt8LYLFk2DvLlHdXfTaZ9+8sbdL/h+AYv4vF3fkgyRkGdpqvXvvRGi7fHWfA6TT1lqX+WZBzgYK/486TFRi/Awek= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=viktor.prutyanov@virtuozzo.com; From: Viktor Prutyanov To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 13:28:16 +0300 Message-Id: <1524479296-4792-1-git-send-email-viktor.prutyanov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0373.eurprd05.prod.outlook.com (20.176.161.32) To DB6PR08MB2853.eurprd08.prod.outlook.com (10.170.222.160) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB6PR08MB2853; X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2853; 3:N9xoe7O8bI1DtPIIdKwmWoZuFaAnkP+KvRLfSOddPZ/oTvIyFCVXUVukxrTa0qf/iQXkgSqCIUoK8eKUuUjRu026EZS5wjjeVOzcuKGEnwtg295leAvQ5ruN4ZlJCUaX5kWbB+5Dwb1h+FWDONDyASJv+bfFKspZTRtiG34O3ZM5K21CdwqlRlpxLjF/VU9JY57fonpBGur9S7oP5+fBdTc4ot7QnKv+5Zq26gG+DyeLqGZA1AIC7oLoqRs2dJEa; 25:gvCYbMDwPdb6V9Kcw3y2a9qKrzDkOZdx8iYv510z3ThLlFTQadkqvB7L2IMyJE3K+J8zPL31XFIrl/L4YbmqnXP5jXpVSSZJ+1nQA3EzrxGeVF/cONJeYoWfiV0bL1q5ALK+cKgwegHJKquY3lnjwhFWl1EZFQh+B9P4WUnczXhMuhQhrhyw1ZIxiaQt3tEcF+1U68PBGXCrgJA4wLXDAHlwxVBoJ/pDFApyTs6uzOXegK/XdU3l5ZUOAVjVIeQvDnFv9fPTqXy17a+23Eds4126tQd0QG5xWSqkZ/NtKquFOWfwKBb2MuodGJ9Ios1AD3xrXTROAx8yQKhP7z09zw==; 31:PsT0tovEaxUs2c8QVIYTv4C3LTtedQiij+Ogh7YC+4WLe+NyNorBTVPp6Jl+oRIB3c2StEE0cJcjeIWZgFF3tumHkqnSKtQLJ1Ayw7prrXZ31ovhJbsJKOoQpqIl6pOrpxNor6/I3KbOhI47ohPr241pI+qxMXqKJBo8JvS17JkWfJArly2eLH5MpoY1V7AxPtTvXwhe0sjPYrYsrJde9ORSqhOQE0GSeCA7j28qrs0= X-MS-TrafficTypeDiagnostic: DB6PR08MB2853: X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2853; 20:VkaAjxaq6jYKBUGgJMbQGQoGaxNkA0FtYB9p6Wdg69X2u+NJ/TnNUN4jo5/id9xJrO5UYWAmcOa+l6Ro/EZ4Z9t+hRj+f00yQdR5oJJABkexYtC9+eD7jDFUttIcl1DoJqJmWe9iBQjPlkKa6l4fdXGc1zFsQRupDNw4spWq6ZFh52nWDaLoqMG81q4M2HG49+eaXEqKOD18W+o6KCgwVCBp0kk8TQNUMfZLm7HHgXpLHUJSAU4PmYPmQ8TxVL9cRECs0Lu8x8pNe1d5bYHD9a0nxd14wK0NJ20KKuJqmmaCY3Ymc3U8s9XCjveyQFuFFOU+Ocb2m2IrGEkXY0mWc/2ARkVLs9iAva5tAwVrAeEj/4Nin6KQkTZFymaCZv+Yi2RqDvlaYNIl0F9IQo31pJNxcvNEsnmkIzKIpp9GOG0gk07TwvaiGR7+gw7lPxvGsy1H6ubzsRj5m1N7G1uYophtoy7dp8dTxgldyVo8j3zAPktBPk5eHFUaDGDUCXUY; 4:N6Z7t0rmJaV9gb+n3TRBxlPZsrf2RAVO6AwIrvt7LVuAj8CnYj5Ae+3jN8EHA0csSBwMvhFs/9RToGYBhnxUZppPo64bg9+ioCUsQkMqSBAhbcANUW1atIsRn1lYuucwy2of3EvVX/KGiH0t478bAgxcjC1u89em2SEC6rpJeAyQmhCmMyXAJ3A2EexO2fgdDPa6f6URfnx1dYSzh2OJRAW7t1OUGhZfpO974kUPOqd7JTn43Gm5wwd9VzP2/t5X7lDGPWn259+5JQxNVLwo8MJvpk6Xy+L5BcJXirnc+/OqgOWBnc3c6QEu7dTC0VmAGU0fL29mv7EIflaUoJumNA== 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)(10201501046)(3002001)(3231232)(944501410)(52105095)(93006095)(93001095)(6041310)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:DB6PR08MB2853; BCL:0; PCL:0; RULEID:; SRVR:DB6PR08MB2853; X-Forefront-PRVS: 06515DA04B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39840400004)(366004)(39380400002)(346002)(396003)(376002)(2616005)(44832011)(2351001)(956004)(5660300001)(6916009)(6666003)(26005)(50466002)(478600001)(6486002)(53416004)(16526019)(186003)(86362001)(25786009)(575784001)(81166006)(8676002)(476003)(966005)(66066001)(50226002)(47776003)(59450400001)(386003)(55236004)(52116002)(51416003)(6506007)(316002)(16586007)(4326008)(8936002)(53936002)(6306002)(2906002)(107886003)(6512007)(3846002)(6116002)(7736002)(48376002)(305945005)(2361001)(36756003)(16060500001)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR08MB2853; H:vp-pc.sw.ru; FPR:; SPF:None; LANG:en; MLV:nov; PTR:InfoNoRecords; 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; DB6PR08MB2853; 23:Qs0biqM7GeXed92zjCvtsa6JeNIloLnx5SyUE1MEh?= =?us-ascii?Q?Jjo+xBio+clB369DihzycssWCUW5CaOTgo2wXg9LhcCIBDpS0Iv2LYyV0GUK?= =?us-ascii?Q?PDZAZ3dIYTpZp+sQOPAvDV8MvLkvFPFPi97yNQXPYuZ2rPQMdwrGWSFoXfPw?= =?us-ascii?Q?seMpixR+ukpvc9m038qvcFbXyFz0WIJKaknsWj/q9dwXDWAk8XjZP9lnr/sI?= =?us-ascii?Q?2sYBLRATgXSoWG606Xbp986zdTSfmMa930dhhqOc2i/J+96WaueIB9H0w7TY?= =?us-ascii?Q?/EDh7gunniCINNM/3Q0LpP12TxQSPjPgdKm1eUHTGdgnmEhswnKh5gxpF5o3?= =?us-ascii?Q?Tc0sFhX2qH3H/pqDysQknzUqJvBcthPDkhtZYpXoa+LgXp3LuyG4qU8f9oWH?= =?us-ascii?Q?auqEF0gm+USmh9TM8Yri4IeiNsvyP9XbSqkegA8dI/eLjLS2JwnCgXap3wJn?= =?us-ascii?Q?zg+5uhmE50ZCIuG1vRgOMUVJ02ADKyV6/Sk6IsDBVMIUv6Y/Al/Jx+TQkTft?= =?us-ascii?Q?nnzvjZWEiBqvwVdAHr+XV6ZMAFnr2KheOMhIMiYlErHlK6Y9nwc1aJ1CL62l?= =?us-ascii?Q?o04CdXxPz8O0XReHUKnkHq8jcPUq2TaoR9OcOhtv1F/PXZehmuOoKQddbxPg?= =?us-ascii?Q?8bwJB0skSg3FhDGV/QJ8MUlwULhvHEMGCAVd3Xv8zXmud7rCzNc1HJA4WGat?= =?us-ascii?Q?mjU8pkY53qqURYVD9mu1xcR9dUneN+TeyQHNNlDLho04z3nBRIjR5dDC3Ex7?= =?us-ascii?Q?N3433F5sCe+kH20CfN2+Ufnby8i6s7kpDC1KkfM+CV35tnDxmR/l8yGQ9/g0?= =?us-ascii?Q?+UxxdbpZu6apEjDfXPiIlOBqThqkoE3v5TmaoXmwz6OK2F7XyUdRZgev35M0?= =?us-ascii?Q?/zFSVT0TP7nST/TrlsQJXWQsHXxSZr08S1Tm7Dsgjn32w7rO4RUb09DOkqaa?= =?us-ascii?Q?uStASXueLLmA8i0UIyiXHv2tqu13/70mSVLK4/CtiPjTnepiXN4A02ssxw9M?= =?us-ascii?Q?JWbdniiU270R20nz9XIsD6DRtlRieRCQNQJD7QkLWt+yVLGPDBcXUhXWczZF?= =?us-ascii?Q?yQCVjntSnbxMwHl1ifyHNiqlWeKQ0PtxRKVmL56SqfQw2OJFpGMnk+hwHTfL?= =?us-ascii?Q?hvFw2qKgTPd1ECzMxoWtO1HzfppnX2eDTI6gWBrwTNowXHn8hmMeA+4GBx8Z?= =?us-ascii?Q?+nW79TagdDEd/91zTX/M7v8rHM6pED8GqSN/hzNWHDbhtKpKYNP0NQdLw=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Antispam-Message-Info: PaAZAN/mTTVe/8EVLUQ56M7hEHJRZ3Nwoo3tfo9/1BFY3Ji6HG4XSbabDyvZwcdULEj9KgObSDwQc3ETEr2/PwobQun9NvgTE4exRyjfdYJF+B4OULF7cJ+A84AGLRzy+YwmcGAkF3atb6h1A6gAR53EnvfsxTY14bWbzqBZEaPvvdMqYHM8zGMOsGskzBQF X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2853; 6:5AXxBmLV+KPl2guvs+EELzAzG63rlWVN51h811p1n8G6fi4zkKPfTlIVIq5sXn0w6hhUtBiRYz3OFZUKhYFmaDpvFPTTxq736AJL3552sU6n0Uifo3COucBbxgM8XwkzrGrNDrA3FmTmMbS1M+7iIgnIMIhTRh/8KeNHQG9fFzTKdoEtCV+3r2QqhYxkulQCmjzLR75yWpyogylP0UQX/d49rqpDHjsqTxujF2Osklcl+On6SD60jM5sBDSrE7KRwfA3BZT1RrYYeHlpljWLF1Id8aguMVns2QcOrN4HseUZs84v3byZuXxFcb8iho/3HNF2z2/t37A4UDLTFiALfjt6YSV4Xvljj/yyI18756qL/376s6HlKij5FeSF557xDxXTn2yDfES/Lyo712hzWdw+rel0S7GYK+GpaufiSFzMvgJnbp3ezELjZzbR3cfpREyib1n/QRkmfakcARBPiw==; 5:mP3983ufZtp3vrs/nwKtZaYF8SSP2IVsJIZUTqyy1qJ5Ojg48+u2QcpuBkK/PqHpa7hahmxmma7cX8QG1yP1/6RTwnHm9QuZW2kAkj1UcwBG3q1Y15qOFwzr+zW+ycK+ZqXcv0lKl+De31ZW3RR8F6vBi3N2AuqM5n/5OlCy2zY=; 24:BSmJphrN0IySHUHJ2GHMvc1+x2zRNNvo/ovhP52RJE7yLqoItB6w3C081dp0zaoYoTXB6Hp4PbodwyeZTpzkTBDfN3Mk63TtEpmnpWBmd1o= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR08MB2853; 7:T/JSYLYhUClq4UM5/3OBII8K9ItfqpHODom205hmjHnpLY6F/K6RTpuYuWbJTbKdQnM83OKJU2xCaxrNzbi9LxkddhqiKeorvCBWGUxJ9WB1FAko+LWfPt3BrmxPHBXduERzjqWw9dyjf2g2BdWrsDSHEUHhaLj1UcAVuShx/R/zo1EnzM8JEAMP8JykdYKY1eqrIDrCyua2yS3JP+8jr6vOA1b9CCQLY5OWj/2L8QrlUDbHZakNgypS3T9GdFi6; 20:GrV2mU6qAKczVxmciwXzl5HPKybI9XDO9LcGPxN4VEEPcPxRul9Lj/Oc8lz0s12hOpiuA4lQ4k42kfIkpp/mlqcKjEHVAdSAH4qGl3uGaeh6N4x0e29M0uzP1NCy7W2HFwlPbPZvNnkyys6lz2UrS9ktwCVpbe6Xag7HFQCO6Cw= X-MS-Office365-Filtering-Correlation-Id: c2bd2a26-fc0d-41ec-229b-08d5a904f99a X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2018 10:28:36.9290 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2bd2a26-fc0d-41ec-229b-08d5a904f99a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2853 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.114 Subject: [Qemu-devel] [PATCH v3] 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-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 --- v1: documentation updated v2: qapi/misc.json updated with version info v3: qapi/misc.json codestyle fixed Makefile.target | 1 + dump.c | 24 +++++++- hmp-commands.hx | 13 ++-- hmp.c | 9 ++- qapi/misc.json | 5 +- win_dump.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ win_dump.h | 86 ++++++++++++++++++++++++++ 7 files changed, 311 insertions(+), 9 deletions(-) create mode 100644 win_dump.c create mode 100644 win_dump.h diff --git a/Makefile.target b/Makefile.target index d0ec77a..6ae2609 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 b54cd42..04467b3 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 35d862a..6f35e4f 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 a25c7bd..bb6a6ea 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 5636f4a..83f2df6 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 0000000..7502808 --- /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 0000000..7a76fd4 --- /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.7.4