From nobody Tue Feb 10 10:04:00 2026 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502129954189581.2294985389859; Mon, 7 Aug 2017 11:19:14 -0700 (PDT) Received: from localhost ([::1]:38814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1demcS-0008DZ-AF for importer@patchew.org; Mon, 07 Aug 2017 14:19:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1demaE-0006uR-AH for qemu-devel@nongnu.org; Mon, 07 Aug 2017 14:16:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dema9-00007A-5p for qemu-devel@nongnu.org; Mon, 07 Aug 2017 14:16:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dema8-00005u-UP for qemu-devel@nongnu.org; Mon, 07 Aug 2017 14:16:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4F827EA88 for ; Mon, 7 Aug 2017 18:16:47 +0000 (UTC) Received: from localhost (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D737C5D9C9; Mon, 7 Aug 2017 18:16:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D4F827EA88 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 20:16:15 +0200 Message-Id: <20170807181618.22562-6-marcandre.lureau@redhat.com> In-Reply-To: <20170807181618.22562-1-marcandre.lureau@redhat.com> References: <20170807181618.22562-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 07 Aug 2017 18:16:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 5/8] dump: update phys_base header field based on VMCOREINFO content 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: ehabkost@redhat.com, mst@redhat.com, anderson@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , imammedo@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If the guest note is VMCOREINFO, try to get phys_base from it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- dump.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++= ++-- docs/specs/fw_cfg.txt | 8 ++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/dump.c b/dump.c index 7fe1044280..cef2dd5bf9 100644 --- a/dump.c +++ b/dump.c @@ -780,6 +780,23 @@ static void get_note_sizes(DumpState *s, const void *n= ote, } } =20 +static bool note_name_equal(DumpState *s, + const uint8_t *note, const char *name) +{ + int len =3D strlen(name) + 1; + uint64_t head_size, name_size; + + get_note_sizes(s, note, &head_size, &name_size, NULL); + head_size =3D ROUND_UP(head_size, 4); + + if (name_size !=3D len || + memcmp(note + head_size, "VMCOREINFO", len)) { + return false; + } + + return true; +} + /* write common header, sub header and elf note to vmcore */ static void create_header32(DumpState *s, Error **errp) { @@ -1554,6 +1571,39 @@ static int64_t dump_calculate_size(DumpState *s) return total; } =20 +static void vmcoreinfo_update_phys_base(DumpState *s) +{ + uint64_t size, note_head_size, name_size, phys_base; + char **lines; + uint8_t *vmci; + size_t i; + + if (!note_name_equal(s, s->guest_note, "VMCOREINFO")) { + return; + } + + get_note_sizes(s, s->guest_note, ¬e_head_size, &name_size, &size); + note_head_size =3D ROUND_UP(note_head_size, 4); + + vmci =3D s->guest_note + note_head_size + ROUND_UP(name_size, 4); + *(vmci + size) =3D '\0'; + + lines =3D g_strsplit((char *)vmci, "\n", -1); + for (i =3D 0; lines[i]; i++) { + if (g_str_has_prefix(lines[i], "NUMBER(phys_base)=3D")) { + if (qemu_strtou64(lines[i] + 18, NULL, 16, + &phys_base) < 0) { + warn_report("Failed to read NUMBER(phys_base)=3D"); + } else { + s->dump_info.phys_base =3D phys_base; + } + break; + } + } + + g_strfreev(lines); +} + static void dump_init(DumpState *s, int fd, bool has_format, DumpGuestMemoryFormat format, bool paging, bool has_= filter, int64_t begin, int64_t length, Error **errp) @@ -1631,8 +1681,9 @@ static void dump_init(DumpState *s, int fd, bool has_= format, } =20 /* - * The goal of this block is to copy the guest note out of - * the guest. Failure to do so is not fatal for dumping. + * The goal of this block is to (a) update the previously guessed + * phys_base, (b) copy the guest note note out of the guest. + * Failure to do so is not fatal for dumping. */ if (fw_cfg) { uint64_t addr, note_head_size, name_size, desc_size; @@ -1661,6 +1712,7 @@ static void dump_init(DumpState *s, int fd, bool has_= format, g_free(s->guest_note); s->guest_note =3D NULL; } else { + vmcoreinfo_update_phys_base(s); s->note_size +=3D s->guest_note_size; } } diff --git a/docs/specs/fw_cfg.txt b/docs/specs/fw_cfg.txt index 37d0f9f40a..64c6aaed1f 100644 --- a/docs/specs/fw_cfg.txt +++ b/docs/specs/fw_cfg.txt @@ -152,6 +152,14 @@ struct FWCfgVMCoreInfo { The note format/class must be of the target bitness and the size must be less than 1Mb. =20 +If the ELF note name is "VMCOREINFO", it is expected to be the Linux +vmcoreinfo note (see Documentation/ABI/testing/sysfs-kernel-vmcoreinfo +in Linux source). In this case, qemu dump code will read the content +as a key=3Dvalue text file, looking for "NUMBER(phys_base)" key +value. The value is expected to be more accurate than architecture +guess of the value. This is useful for KASLR-enabled guest with +ancient tools not handling the VMCOREINFO note. + =3D=3D=3D All Other Data Items =3D=3D=3D =20 Please consult the QEMU source for the most up-to-date and authoritative l= ist --=20 2.14.0.1.geff633fa0