From nobody Mon May 6 02:25:32 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 1523973174206504.91711033261265; Tue, 17 Apr 2018 06:52:54 -0700 (PDT) Received: from localhost ([::1]:40076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8R2T-0007ah-Ap for importer@patchew.org; Tue, 17 Apr 2018 09:52:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8R0t-0006jk-Gu for qemu-devel@nongnu.org; Tue, 17 Apr 2018 09:51:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8R0p-0002Vt-Ah for qemu-devel@nongnu.org; Tue, 17 Apr 2018 09:51:15 -0400 Received: from mail-eopbgr40125.outbound.protection.outlook.com ([40.107.4.125]:6080 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 1f8R0o-0002U8-F3 for qemu-devel@nongnu.org; Tue, 17 Apr 2018 09:51:11 -0400 Received: from vp-pc.sw.ru (195.214.232.6) by AM4PR08MB2850.eurprd08.prod.outlook.com (2603:10a6:205:d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.12; Tue, 17 Apr 2018 13:51:07 +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=elapbRU9vO6mz0xZMyOcv7Zt+8dVjquiHsHsY1oEnQs=; b=cDItDw49VPFENnM8zkcpAxtSm+hx/6UyOUM/jMDVEo8z9ABS2euAn4ki2++dj5fGhGR1rDBIbP8RsujsY9fnJgHf+iolMpsevL6epMYBhAXsn6oytf15wK7Lp8dwiCHmoHJ53XgSP+J6iOFS5k45OtzPXvli9WBR8wT+Mi/zpe4= From: Viktor Prutyanov To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2018 16:50:44 +0300 Message-Id: <1523973044-25754-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: HE1PR0202CA0047.eurprd02.prod.outlook.com (2603:10a6:3:e4::33) To AM4PR08MB2850.eurprd08.prod.outlook.com (2603:10a6:205:d::32) 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:AM4PR08MB2850; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB2850; 3:NhMdQt+xq4Q6iZdIV3DzokmLaVXyNMiuFT427R953L0i8V1bJPBfUGheNRT1VbDAdscAUbbw98Poe3gttzhaZNJ0YtdzUfGsW43FyFFi1/tUo1LmRGapJUpaxCnqRFSg5SWE6O4Xjm9omFRl+YXhUMf+aYuj7jgZTGr53lZR52f5mbJIVBzOG6Z0Kym8dVQwuNkkZ7VPkE/pMG8+6EsEiQU17vTkX/ypj9yT18Pwc8O6UhnrtNS1wwKqhAPi563f; 25:tsJlNHi8+xZxo5Kg5QuFmNf+1RpPE0hIXiD80hcxx8vuScAMSkknI1dlDAYjv1Jrk1udJiBvwfb+eMur7uOSdvA+Qeozyaa3JWWM/+qECmI3zdthZh3M2uryqWYk5PuEXn1zBN0gIAMvI976t+lsVqB7o1Qd/53VJBa+6Ne4d1dCmevYfgRSvSj+Ni7jld79kcF6+2Z6rfprtNMuXi5JH4KLr4ijCys64rBVmilBV7KI+VHJFZn6nhTT8pmmzVcKorBJH3LYXQCpf5Kt+0r8YjnNhuxu7uP+01H8v+XQ0JisEHiX8Yaxs036s6s5aSOzuDzmjFAiHm5IkeSf7ZI3VQ==; 31:LCpAp4/Z4Ose5ObsG8hlC3boqXzNzVlmtuGSIK8A4vUeAz6sWCkUv8dTXCBN2nY1hnRecVY+pbMIrloO9CIXRrwYVYTpA9WbgerZM8bn+3h/wPXwvA8BljgB1Z8W71WcqsBg7LPZOm84BRHAJoVtlWU6qkU1NHCbxFiplErzxX5hvQS4AOdhhkvkdbpt5vjHMhEy4sTiM1jOTEYV+TEa9RNm2dcchtzBG8JqvbN/Vqw= X-MS-TrafficTypeDiagnostic: AM4PR08MB2850: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=viktor.prutyanov@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB2850; 20:TQFYYVYTlvQFv7/51AOOVmRRwYi1yTkqJWSGil5OZTsIXIviov7Ju3WPvfO/9kQhZXT33JcdBJqCpaaEM8Y17lEUtlMSS/EZ+PdPNHiIgcG7WUftplVH3ZhtJloXcHQRdY1dNPEh/w5Z7JL476R6fPgxf1saTfXYvNH0XGeff42gOnOBpl1uMorjjhMB/w/ml66Sz3IMNaIgfINEjLS19EoKvckKbEqNIWvraWe2a4JcoCYPnGnr0TdhD6aJOHALw1NT0UDSVKbZW+/HtyUnXysRzioO8AIBfyYp+zQ2KOxJzoHdLe32RleJhBb0LRvTsb79QOOoWEXU5SE7C23J36g85EOg7bYjKtv1UyWwVNAW+SXIVQwPIiIo5CPKWgamNN8wmuBesSgTB4aP6lx71PCfnH8msjnzgWUhegCLFfs0PB8eAYzWiTN+2p42HtlcEYAkcW82Fb/bSFJhhavZN2DgiFdyB4JBDJJtjEk9rpw8rDc78QMgxTmXOVsjgXHM; 4:FHKvK0DqoIl8QO5X98g/mGUSgOX+XahmC1jjyw24vFX14P0eqv99/9USN0GYMMX8vsHctgW6Y27ZDdue3kH8ust+PEm0q1wcE5PnHjN8MYJsgdzZC1NZ59GPksiN67LnBLDBTF9ShekrdFB003j0C+1qXItPp8vRogtyju1x9dBijsKYsdYLUbzDdng6OBPdQeEHHH82Ba8w2j2NZsbh62PR+lZihiWBHzx2OYiHuHKirdJhPB+0vKhpJT1f/kONUAkLaxEy6E4Sgr8/TtyMjaAmbXZCOlb083Rs1zgPtXPU8UfZRWgzNT1NT7QYY31gLob73bCpx1sGDc6SWZ7id9JhR04/9ZUklKipEQshZtk= 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)(3002001)(93006095)(93001095)(10201501046)(3231232)(944501359)(52105095)(6041310)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM4PR08MB2850; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB2850; X-Forefront-PRVS: 0645BEB7AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(366004)(39380400002)(396003)(346002)(39850400004)(189003)(199004)(39060400002)(8676002)(81156014)(81166006)(50226002)(476003)(956004)(2616005)(16586007)(55236004)(4326008)(47776003)(50466002)(68736007)(6512007)(6306002)(53936002)(6116002)(86362001)(52116002)(36756003)(575784001)(44832011)(3846002)(8936002)(107886003)(2906002)(16526019)(186003)(51416003)(26005)(66066001)(486006)(59450400001)(316002)(386003)(6506007)(966005)(2351001)(69596002)(53416004)(106356001)(105586002)(6666003)(6916009)(2361001)(478600001)(48376002)(97736004)(5660300001)(7736002)(305945005)(6486002)(25786009)(16060500001)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR08MB2850; H:vp-pc.sw.ru; 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; AM4PR08MB2850; 23:wlROoYuZRBpWCfzjhQpG+iZ81PywDK7JqjQD3gzkK?= =?us-ascii?Q?m/EupSLAMg1PAPqQdB52gZRE+HeCDXekQ3EzGv21JiVdk+K7QzQ5nsZoADHE?= =?us-ascii?Q?K0yhz6bu9yO9DF9HdwgCZQCynOofBvCKXGJQhbVlIFkTsUzfDji/uQjeU87b?= =?us-ascii?Q?5K83l+qpVQcJ7CXgRuu50ti4vfY/RYx9kYfy3IhTMyLp2UM8JMSjP3NrwQjn?= =?us-ascii?Q?VUBp1qQgRzt7a9pfceKT7KZoomBgXYXwNN2hSS7WQp6Hyd5JX17h+q+BioBh?= =?us-ascii?Q?4OERkT4xdL0fO4jdrkMypmIux9G7jIMY5iEREvVnSxebNzPR/1ZJ33/rFnti?= =?us-ascii?Q?MT+MysFktI/WVbiObtOzTwD4/VKm+HHcbYUouyk4SsT1/c/uc34jBRrKP5NC?= =?us-ascii?Q?C+FNrnSUukNUl9UhlekBkbKOG17JqY6bAZS40P15rtrDqR7Za4ovx5Nb+A5G?= =?us-ascii?Q?0I5rqWy+5AbUrtpjsn1smDhsBCFUZ6VaH7F+/XfuDN7PI0lMcc0obNN8pL5D?= =?us-ascii?Q?5+r1AT1fgvav4WivnoEFZQzKAFCPRWQUn4m6dEhYWhdCJn3SS1oAWW6NcMrs?= =?us-ascii?Q?a6GCyd0c5po5LoKBQRgcXJ9ELA54cZ3/J2donO5/azW68Ga0Xkf3SrwP5PYc?= =?us-ascii?Q?s+2Nx0RGTkshUtQX8ctaB/q0NZnozp4hveHi+2M5ZhSmBWNtDigL/5325aCV?= =?us-ascii?Q?6n7qXqN9okYQXEVhSjuTRyC62FWd1/yA0GPuk2CVM0Xe6cuv7fre1vtL2aor?= =?us-ascii?Q?1PVGRrOvX75++7oreiENfNc5GkEX0kEV9tP7tf81qfEqXpmqhPvTIJ14CK54?= =?us-ascii?Q?Bim/Zesm2fpdvAwLpXqkYFpz2FJuF96E8eJK6vpTJDn25wxQkzg6o1VTvj2A?= =?us-ascii?Q?ZM5YcFk2J0EKULcxs75eY6dglMoNS2aehKXcFIhKFzgpB6zllml7t6l65ppt?= =?us-ascii?Q?BEPsx91zJbe50YIVn8Cg4lC83QVXMt9jcdR/GeofIQeKCvE9SAHhUe3FCrrJ?= =?us-ascii?Q?goagBMbpYK1zmIeV+zPim5qGJABNk8dIbai2O5A8dtr9MWAmmgZtU2MTMKZr?= =?us-ascii?Q?pDnEvFjMx5nRRFKp5crpiyidL/j+2mSjby4IVEOlYYIvUuGsAioOI2xGphkT?= =?us-ascii?Q?1H86pEyEw/ow9MSClp+yLhJmI+Wc3x2eoC4HAWrBpaAK8aI0I7LdJV8PZuGe?= =?us-ascii?Q?rhgz/0S1xsM7YqnLZy29D0yl/AsKeOWJLZQ9xeUJ4uqrQgQTuT3GvhPud8x1?= =?us-ascii?Q?DI8HrXYlpYp8n3E/qhie1f/9tu3ewpAQcoBTybYKa3iTrGRsDQ2Ss5jLtAs4?= =?us-ascii?Q?y/kKgciq0eBfAVElVqftOUhECBvCWVXLqUp0L49jOkEnga5xgGERrSRekWNb?= =?us-ascii?Q?YTLWSTZNiDMGC8r8TnGRjcE0qDmhQOSWB1coG8Un/kF/Ccr+ErTo1PrB39Ot?= =?us-ascii?Q?y2tUyvKxSbdWUP5gE3VrcxuAtCMOF0=3D?= X-Microsoft-Antispam-Message-Info: 4Q/Su7iPxhyaI7gCj4BKDYZuCOjlDQEK/eZ+q3pOmI3+XbHdZcL1xXxK3vOdJ4e5CucN180hza4aw2nvuJoaIkeSMmhJomc7gpwvB0er5CQxjzIZRuj/oBeQIENCdUSZVVyzd1PwCNLobMewkVkz17FKNGcJfs/FE1dNm+E1+gjz0uR8O0TwonGV6A9fyRgb X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB2850; 6:zAdf2Tl5O92iilOTzsjfRrb+dRURmYHdJvGLBSEDBsuTwuzwg78UT2rCQTmuh9Q52RdxD4LROrkLn7BuOR85lSCIWcuXqlTvEX3az/sMkXn5Sa0Np6z9mGQwpMatMQeDU+5d2PpJ1NR/SQjberK/QnGSb2a26kPdbasnPPCnf8frB0Choz+fV+s4GHIZ60a6VNODq7XRQQ168DTbZKp9pQrZxjKJrWATW95HTNlVzNPcMCikGNu3of6ZNWdW9MFEHTRoOiZlO1hgYb3HKckPE+hd3FQ/b9iVQlZ58kxOrS4exYTNFMqwQR2WOY3KRG/BrJ8S/hrWJze/jrIYoTjBYP6gDZNHME2D3/c1ov3VUTW4G8MQH9ihtfO0+kBLI8ALtDq/wSXty9Mv2A8r+vVoCwpUXI36mGX/nCxFdZj+Ad5uON1Oxn4hgAsxiwZa8VBxBuXUXoc/B7nENXvlEGknrw==; 5:nK1chsqkR6y7FE/Ltieso/iBY4+j8iQU3CezfhGfXM3UGotNlvID527LQv2Mz6tMVc+/VhIJdig7e+EK/ZA0Y0IpnHBrNkm+Gko73VnMjfGds2RybENTDjcE2vxe2HQJWqzP6Zw5E7uXkSL7eu0JlN0KxAQb7NnxMGMnP8/EbsY=; 24:EHCsDH5lBvikpGI1m0ScgMM9y4W/HfmJRyBS1MDPk4bj2Vq0YskcpKuMOSd1szQVcaztMGuPcmFOIVkMRpKXne4ze/h82pirt9mtxPDr5i8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB2850; 7:dIzGogyrCWyatV8ARraBAf9epxgoFTW4KHETmuXSd7DCSWvm7kAJ1znMMC5ffNYJLDy9O0wTTXvmKwdR683dnqICwdtkQNtej3xVI46RyhUIo4vNnqgY1OarWDvjWd5tbEoiJ5oErXz12h4IeUIG/vuSQhL9oER2myRKtOJOhWDhL8Xa1Ci3zphLoiMOWav+ENQtFFypiGqBqGITjUIHuYJK3oLfIJWc/iA4k40WyK/aOLav8nneVWjQ4haiXcny; 20:/OqW3gu8IZRAw9fjUqWbedN6D2f885LjGMysbQqDecH6W3oF5oR6A9hzn6uoFPhGwAw1jeU/Bk7TKKlTlwS9BmYmTCBzD3bgAI4sNjEa1S5OEUe1imB+6RICTT3TUdPPQ0SOOZZ00qGarDUNTQ8NM2t6zymAioZJ3Gzv/ZFx4Ek= X-MS-Office365-Filtering-Correlation-Id: 82f633fd-4009-43ba-a7f0-08d5a46a4517 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2018 13:51:07.0616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82f633fd-4009-43ba-a7f0-08d5a46a4517 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2850 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.125 Subject: [Qemu-devel] [PATCH v1] 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, Viktor Prutyanov , marcandre.lureau@gmail.com, rkagan@virtuozzo.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 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 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..3fb3d3e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1645,10 +1645,12 @@ # # @kdump-snappy: kdump-compressed format with snappy-compressed # +# @win-dmp: Windows full crashdump format (can be used instead of ELF conv= erting) +# # Since: 2.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