From nobody Fri May 3 16:32:14 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 1524491467383813.9140180732279; Mon, 23 Apr 2018 06:51:07 -0700 (PDT) Received: from localhost ([::1]:48685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAbs2-00030R-7n for importer@patchew.org; Mon, 23 Apr 2018 09:51:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAbqy-0002WF-AC for qemu-devel@nongnu.org; Mon, 23 Apr 2018 09:50:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAbqt-00021O-B0 for qemu-devel@nongnu.org; Mon, 23 Apr 2018 09:50:00 -0400 Received: from mail-he1eur01on0100.outbound.protection.outlook.com ([104.47.0.100]:50400 helo=EUR01-HE1-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 1fAbqs-000203-HE for qemu-devel@nongnu.org; Mon, 23 Apr 2018 09:49:55 -0400 Received: from vp-pc.sw.ru (195.214.232.6) by VI1PR08MB2862.eurprd08.prod.outlook.com (2603:10a6:802:1f::10) 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 13:49:50 +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=OD9WcEOaJWnXBtZqhroqGQ3+DneudE9wk3C+lQY5jaY=; b=CzeJyFAD1hhZv73rsF+a14luZ4MB9YCYkxWaPoFHISLfJVwibcrFDTkkpUuxg3HBBXGz05/+MHYE0bbrK1vbsaN8Q16tU8OyeyxuAsDy+6lTMdjD2dxhu7J4K6MbrqKh5KzugnR/lvLm/ld4LyRJyWoJxaBu8+AstHRmNJ0oCRM= From: Viktor Prutyanov To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 16:49:35 +0300 Message-ID: <1524491375-7814-1-git-send-email-viktor.prutyanov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P191CA0020.EURP191.PROD.OUTLOOK.COM (2603:10a6:3:cf::30) To VI1PR08MB2862.eurprd08.prod.outlook.com (2603:10a6:802:1f::10) 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:VI1PR08MB2862; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB2862; 3:UvTRH9P7/r/4rpiQNj4VCvRBGOCZ1rcdj1i77U3lXM6ba5jdBh9ZkvjnZaY1n64r4ZgAFtfxlyIxT/6/x5wXAy00leX/eJC9j6LjYjBIuhWDZS2R7capYKJqWSkZqCP5w7FGUNA2EePX/A0Dx6jt26t16SgfErjWu4S4PtRBAtkG81T4elhQApOdNrLhzIMxYxoF+U+ANtTNgn/scLC2D6PN2kPnNf9QTykEb3+uQ59wgk1vtYtJtW5Os983E4Vb; 25:NLKK4wKqngcyLhpZDDaXtwSewYqVx3fgnKy88w17v95PKXXeAy2MP9HgNCKY+TV29xvWry11O+MeXO2oofyAs7k4Lu8W939vY/k5qxp+9gweNikD/pf0NBQpqBECu0tTmiuQ/me32YWpmEUe9WJHu/mTNEuuZJOZLk+7LkEBVucsLr9Nb+av56DM8nLPL+7xSnM7iQhbQJfva7I8sgcqvOGNRX6LGdef4XjcW7CYL9azX4tdEwsGhbPgmiRqRlYKG6AjAc9on5+FRqTHwSv9JZ3q7BuoUk7B3YoB6Gc1HD7OUTUyvN8sMfi/wgtZRKPJayqUzWMp6jYl+MCRUp0GAA==; 31:j+GsSyp3LkeFku3ZaauD+RloDOp33mqNifkO4744+uL1kXwwa2B+9n3YJY3xabarDNTlX3PArQh70NelYofa59qDzF42/aXvt01gx1/vY7cxaZNybgyttZPsnEhRNqem1/u0ECH4atnqHkI2HhE1ovBpkNEcbY9H81dpGU2odK5l61Y2+WI2ndcIiTjODDUND0DVj8XyuM+HDwY5G4t7Mw7zOja/y81V9x38S0cZ7mA= X-MS-TrafficTypeDiagnostic: VI1PR08MB2862: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=viktor.prutyanov@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB2862; 20:gVLgXMY8kvL6bzHBHAhEhemL2mNO3ob4Yb5wJO+lXzcFuCMxZjIq/v7zRgm1gJiSmYEiuOp/bVXkwDE3+U3eifzR6d1rI2uRfIHTwiI3bO0mTWwkAQde2oupk/7Fdc0QKKV7p4HrT9eWfIzozh3Pq7NYuApeyiVtqftdAE2TIsYN4Hhr0fMomjZtRCofdDcULDD8kbPcgcuxv5uz/rqc3fUwW2b4xPYFxF+PNv7luzGtL61PVjr/JmCuo9i62wsny/A26GNcEO8X4K6+zF0ILn4oF9RG0l8xVp0xq9Eb34ixD/qpMtjHXpFoQngmJ6t5ykcFxAGmozgmltRH0uacL4VSnk2BPdGCt4eFJzIGEKL/EJ8xWkaWg7qimBNX5eG1Zzu45ioWIonq/hhnvN3/1ZaCKlaM+chOhqMR7o+lP9/KqMrGUbRDQjAZDaTUhub25ITMlUxy7CmWIKMIdOTsuXGcDp4ouU2AzFf7rnTftFxxTm8vYgX/nDUI1Czj9D48; 4:H49nitjxYfX489rMwuAMzedAyn+FyWAyelR5F8exg0DNHmmMMMSAAD9nxb4x+RCTBcIVly0mwOWm2qBteKymrlLoWWACgn12ID0KJ7qmgqSYJO33FBwAHwaJKsKAGTIzr4qNmO2agIDZuVebFKGPWHmn7pfSz6xs3UZS0mqrqXkGa2atTyBS19NmTuWa2o6+yhDvW+CniWzSgdtrpm0d057pZUOBzC4Ndt/a8E268sDkHwKwL5dWK2NZIPMuI0/OiU+QJwCa+K+3Dr3qFt5QzodDUa/NfsonkUDEDzW3U6JeeNkRKnAvspkSlenjLHn6EOr9GLk/vn5Lw9aXPtb67rXQvmBizWprKQJvp8gOkXs= 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)(93006095)(93001095)(3002001)(3231232)(944501410)(52105095)(10201501046)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR08MB2862; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB2862; X-Forefront-PRVS: 06515DA04B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(39850400004)(396003)(346002)(366004)(39380400002)(6116002)(3846002)(305945005)(7736002)(575784001)(6486002)(86362001)(2351001)(8676002)(44832011)(2361001)(5660300001)(55236004)(16526019)(186003)(956004)(476003)(50466002)(2616005)(23676004)(6666003)(966005)(6916009)(26005)(386003)(6506007)(316002)(66066001)(478600001)(52116002)(6306002)(6512007)(59450400001)(47776003)(36756003)(107886003)(81166006)(53936002)(50226002)(8936002)(53416004)(2906002)(2870700001)(4326008)(25786009)(16060500001)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB2862; 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; VI1PR08MB2862; 23:szBDnI+0j/8yyfRTXY/Y/Wpw6u3zHTzCn2HD6IAUV?= =?us-ascii?Q?yn+5oS8v5IiB0icsprlWNu4IDdqxTcRj23bga9t6hBM9hokLKErqSbJwC4rk?= =?us-ascii?Q?w0ZtVErQojNQR6LzOp0RJiQ4kzVftgys8GRDJ9CNamTK9/0NQ/869MnEERFn?= =?us-ascii?Q?dkUMUsSwisO/u1To4jiY/ixJCy98btXNED14WRCVBj7HzrvgjifUd03nDqI3?= =?us-ascii?Q?opcr6xn8E+kpZkLtktbDQbgnlRn1TxyYHoaz5Uzy9qYUvwczrvpqRzsMUP4U?= =?us-ascii?Q?aa6E9uCwy/CClM8afOga2X80F0o2sGMU7UU1UBAWa2l9EF7SSdfEzvJIFWyH?= =?us-ascii?Q?x352HSlEENEARDiZn7SH7txeX2UFbv6NcHsxB5I6TIC36L7pSIzd7LqLoGtV?= =?us-ascii?Q?EQ/Z7TdpNWsMSP4nS5yvoFKysWhHgvgqg+5mncHLtHI7LVjzz9vM167yAHbD?= =?us-ascii?Q?x0T5Q84xU0PqT+9YDIFBCsQfKdanLeS7dHmmoZcHjUiFoNb30Ep+6DqiTOK4?= =?us-ascii?Q?wW6YU1WbS531YvhffJEUl+MT600+9gYK7eoa/QzzydtNGAenQp705jKG03vs?= =?us-ascii?Q?GsF4PoaWjsgFRekibDc7pz6h/K4uDuzLxuV1ueyxrIR0K4U5r4x3ma0Ph6p6?= =?us-ascii?Q?NuqX29LYq3WZaEUi5Z33CEe4iqIAEt2W+yRJLpOBsXIrdH2a1zBnEv2HoY68?= =?us-ascii?Q?kVjqFRLqZZViUgWr6ZVBm+rB5UUd/mgUiXISttqTMA7EGjWhNrtAxDyM7kKI?= =?us-ascii?Q?ouiAemzTaD2XMFPfyDGVTEfFWefpVoCsM8qrZLLosdvIc2JQwxjqKqWX7nPm?= =?us-ascii?Q?5gsBbhOlgrLNQPVvQHnjddNtawmjWfWtfXLVa83fC4bArl0QMhcWiMES8bjX?= =?us-ascii?Q?P4R9liqtd4tT6x96iGLPIPGcsLuLgU18V1/9m7CQVRRk4q2gZj2VVOIlAAjS?= =?us-ascii?Q?WuRQVbMXOXqGfr3OzEnfdu6IMerEf0dAWPgoY0o9YrbW77SKBp3XMJNwFnM7?= =?us-ascii?Q?gyxgoPT+8h4/bH/0tTxWJvpUFNa8U1XXmkvIVPycXZyy74C19/E5QO+bhMZA?= =?us-ascii?Q?W+/cA5XgaOodkoonfQ4yUH2XmJC2TajLieL/ohCppWSsNDScqu8dIYcmarLg?= =?us-ascii?Q?3smpmsRe1icjGyA67R2J2ErXN9LiJ+I5Mq9BGOEErfNyZn42SpbZLZQSBoPx?= =?us-ascii?Q?OEZGgWGFl5zpsyLYgb/zSmC2OPIwLh6e4vQ?= X-Microsoft-Antispam-Message-Info: 3MMT6Pja10cFSem0XeGgJPyQrhRLCimoG+KrcEOtEti1SjpZZE6LWJ4T6n/weCvUA5pGNXjjqNWtvDwR0miEBrcGJyLc8I2Ng5ug5D7vqZAngYoQm9GRsgQ4qX/qd2LP7l/gc9tpQJzoz8DcM0WQm20K6OF7350XQpbdYq9Z5N/CKgYKX9rauD3L3d6wakt6 X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB2862; 6:DpH4/s5b/Jj2e943AOcgIQItlBKmTo1VMRjDH7mVxIH3KvQs/b+GzYazJZZGNjPn1OWA71Ywp+LSCsNkuNK7i0k/UtvqqdUhovSjobS+mZ9i6HhCZaG1fMtGqVElSpZS/1xwgB07RDvXM7MPvXyiYmf4eaGOGQSmOsnMy860SxG1+q20Qy8c24pIxWKxxU3s8n8zXj8rbWRxBz4Bf+NTmkvF2fhhyvqCO0pH0IFF71hvsFhKC/YTwAUZXcS1q2vFqaoC7m4iN1O3uq1kVI/zYEcBrwDdOPHxS/QaNz3sO9xGbSuz8ionyuwOrlZ2ljdGxix0HMMXh6fQzSw8U8xdd6z2pGOV/59Y7Qu9d4D/HKEyel8SSl4ZiISZZhHd2Yo/V8SbTma2zLryUpEdo7gIACSvd0s1lacvNnvxYQx6TTWGwr3j33C/1VLSLeCCJvb4vrnT4ZknvRavYLphDKzl4Q==; 5:Mm9gJPqF+LSV40OhHKG8QdXXVsn1v59MLaoruiIE+jA+OmUcKyopwMKNloda5N+Zp/FhiBsbVnmz+JU6lrC98r331v7057iJ/oTyAM7avZzMO5i/JOZufJm76NePMrPTSWh8IiUR3CoESeEyMfPfpNnh6DXD03w1mTX0Uh2Ak6Q=; 24:T8lmBve3PKMuDWctJaCrTV4543ibcvf5WvZowJi05QB49DhVqBb6YUsVixAgfHS5j/E3RTfwDqEb6C/paqwZbMfHyfp3c8YR4qj28MgWndY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB2862; 7:DhCRhYI53zfpF8b4A8x7ZT5ZREe5fyEC4MVfiVuNYLj7B29h5X0caipwDVKkdxGV8wyIwX+T6fOEfgGySjUHCJGPhGgytmr9Bnu6SlA3uaha6LawTwLUGn+a06R0i0bS3vjdwJArhiNbHLytzPzFBTeOd8qO5imrnryLejFPo/umFm1OqAJuAEytVCtnBL7mfnxAum5Bk+72gYUofRSQB8K+fPZ8AtLgUO9+FF4Vj9ArIqibYM55kA373nUH+1eb; 20:e9FM9lCYa/sHsDLYFgm07eWnTmlnXKjXq1MrTs7QYGTzAwX8nhRHFqFoFtWzSBVOt46cwfRnImuJc7jhQBnvLETiTBpMMMMT78ukuvYqBXmmkBoRhRqlcvMXu6uT2Q5kLuwyObBjmpAA2lbNyMHyiMvM5yprVDRdJa/u1PAn/Rk= X-MS-Office365-Filtering-Correlation-Id: 127feab1-a361-41ba-cc44-08d5a9211640 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2018 13:49:50.9528 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 127feab1-a361-41ba-cc44-08d5a9211640 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB2862 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.100 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-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 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