Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/812446/?format=api
{ "id": 812446, "url": "http://patchwork.ozlabs.org/api/patches/812446/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911165929.2791-4-marcandre.lureau@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170911165929.2791-4-marcandre.lureau@redhat.com>", "list_archive_url": null, "date": "2017-09-11T16:59:25", "name": "[v6,3/7] dump: add guest ELF note", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "dd2a3f1b353672f13754e703cd48e301e6bb21eb", "submitter": { "id": 66774, "url": "http://patchwork.ozlabs.org/api/people/66774/?format=api", "name": "Marc-André Lureau", "email": "marcandre.lureau@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911165929.2791-4-marcandre.lureau@redhat.com/mbox/", "series": [ { "id": 2525, "url": "http://patchwork.ozlabs.org/api/series/2525/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2525", "date": "2017-09-11T16:59:22", "name": "KASLR kernel dump support", "version": 6, "mbox": "http://patchwork.ozlabs.org/series/2525/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/812446/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/812446/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)", "ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com", "ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=marcandre.lureau@redhat.com" ], "Received": [ "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrZ4D6glfz9s81\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 03:02:52 +1000 (AEST)", "from localhost ([::1]:59164 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drS6k-00084x-WC\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 13:02:51 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:57640)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <marcandre.lureau@redhat.com>) id 1drS3q-0005wf-6n\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 12:59:51 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <marcandre.lureau@redhat.com>) id 1drS3p-00077T-5Q\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 12:59:50 -0400", "from mx1.redhat.com ([209.132.183.28]:60366)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <marcandre.lureau@redhat.com>)\n\tid 1drS3o-000778-SI\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 12:59:49 -0400", "from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id BABF4C00DBB0\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 16:59:47 +0000 (UTC)", "from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 24BA46B25A;\n\tMon, 11 Sep 2017 16:59:46 +0000 (UTC)" ], "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com BABF4C00DBB0", "From": "=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>", "To": "qemu-devel@nongnu.org", "Date": "Mon, 11 Sep 2017 18:59:25 +0200", "Message-Id": "<20170911165929.2791-4-marcandre.lureau@redhat.com>", "In-Reply-To": "<20170911165929.2791-1-marcandre.lureau@redhat.com>", "References": "<20170911165929.2791-1-marcandre.lureau@redhat.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.15", "X-Greylist": "Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.31]);\n\tMon, 11 Sep 2017 16:59:47 +0000 (UTC)", "Content-Transfer-Encoding": "quoted-printable", "X-detected-operating-system": "by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]", "X-Received-From": "209.132.183.28", "Subject": "[Qemu-devel] [PATCH v6 3/7] dump: add guest ELF note", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.21", "Precedence": "list", "List-Id": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Cc": "ehabkost@redhat.com, mst@redhat.com, anderson@redhat.com, =?utf-8?q?Ma?=\n\t=?utf-8?q?rc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n\timammedo@redhat.com, lersek@redhat.com", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>" }, "content": "Read the guest ELF PT_NOTE from guest memory when fw_cfg\netc/vmcoreinfo entry provides the location, and write it as an\nadditional note in the dump.\n\nSigned-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>\n---\n include/sysemu/dump.h | 2 +\n dump.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 109 insertions(+)", "diff": "diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h\nindex 2672a15f8b..df43bd0e07 100644\n--- a/include/sysemu/dump.h\n+++ b/include/sysemu/dump.h\n@@ -192,6 +192,8 @@ typedef struct DumpState {\n * this could be used to calculate\n * how much work we have\n * finished. */\n+ uint8_t *guest_note; /* ELF note content */\n+ size_t guest_note_size;\n } DumpState;\n \n uint16_t cpu_to_dump16(DumpState *s, uint16_t val);\ndiff --git a/dump.c b/dump.c\nindex a79773d0f7..3cec6a8c93 100644\n--- a/dump.c\n+++ b/dump.c\n@@ -26,6 +26,8 @@\n #include \"qapi/qmp/qerror.h\"\n #include \"qmp-commands.h\"\n #include \"qapi-event.h\"\n+#include \"qemu/error-report.h\"\n+#include \"hw/misc/vmcoreinfo.h\"\n \n #include <zlib.h>\n #ifdef CONFIG_LZO\n@@ -38,6 +40,13 @@\n #define ELF_MACHINE_UNAME \"Unknown\"\n #endif\n \n+#define MAX_GUEST_NOTE_SIZE (1 << 20) /* 1MB should be enough */\n+\n+#define ELF_NOTE_SIZE(hdr_size, name_size, desc_size) \\\n+ ((DIV_ROUND_UP((hdr_size), 4) + \\\n+ DIV_ROUND_UP((name_size), 4) + \\\n+ DIV_ROUND_UP((desc_size), 4)) * 4)\n+\n uint16_t cpu_to_dump16(DumpState *s, uint16_t val)\n {\n if (s->dump_info.d_endian == ELFDATA2LSB) {\n@@ -76,6 +85,8 @@ static int dump_cleanup(DumpState *s)\n guest_phys_blocks_free(&s->guest_phys_blocks);\n memory_mapping_list_free(&s->list);\n close(s->fd);\n+ g_free(s->guest_note);\n+ s->guest_note = NULL;\n if (s->resume) {\n if (s->detached) {\n qemu_mutex_lock_iothread();\n@@ -235,6 +246,19 @@ static inline int cpu_index(CPUState *cpu)\n return cpu->cpu_index + 1;\n }\n \n+static void write_guest_note(WriteCoreDumpFunction f, DumpState *s,\n+ Error **errp)\n+{\n+ int ret;\n+\n+ if (s->guest_note) {\n+ ret = f(s->guest_note, s->guest_note_size, s);\n+ if (ret < 0) {\n+ error_setg(errp, \"dump: failed to write guest note\");\n+ }\n+ }\n+}\n+\n static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,\n Error **errp)\n {\n@@ -258,6 +282,8 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,\n return;\n }\n }\n+\n+ write_guest_note(f, s, errp);\n }\n \n static void write_elf32_note(DumpState *s, Error **errp)\n@@ -303,6 +329,8 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,\n return;\n }\n }\n+\n+ write_guest_note(f, s, errp);\n }\n \n static void write_elf_section(DumpState *s, int type, Error **errp)\n@@ -714,6 +742,44 @@ static int buf_write_note(const void *buf, size_t size, void *opaque)\n return 0;\n }\n \n+/*\n+ * This function retrieves various sizes from an elf header.\n+ *\n+ * @note has to be a valid ELF note. The return sizes are unmodified\n+ * (not padded or rounded up to be multiple of 4).\n+ */\n+static void get_note_sizes(DumpState *s, const void *note,\n+ uint64_t *note_head_size,\n+ uint64_t *name_size,\n+ uint64_t *desc_size)\n+{\n+ uint64_t note_head_sz;\n+ uint64_t name_sz;\n+ uint64_t desc_sz;\n+\n+ if (s->dump_info.d_class == ELFCLASS64) {\n+ const Elf64_Nhdr *hdr = note;\n+ note_head_sz = sizeof(Elf64_Nhdr);\n+ name_sz = tswap64(hdr->n_namesz);\n+ desc_sz = tswap64(hdr->n_descsz);\n+ } else {\n+ const Elf32_Nhdr *hdr = note;\n+ note_head_sz = sizeof(Elf32_Nhdr);\n+ name_sz = tswap32(hdr->n_namesz);\n+ desc_sz = tswap32(hdr->n_descsz);\n+ }\n+\n+ if (note_head_size) {\n+ *note_head_size = note_head_sz;\n+ }\n+ if (name_size) {\n+ *name_size = name_sz;\n+ }\n+ if (desc_size) {\n+ *desc_size = desc_sz;\n+ }\n+}\n+\n /* write common header, sub header and elf note to vmcore */\n static void create_header32(DumpState *s, Error **errp)\n {\n@@ -1492,6 +1558,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,\n DumpGuestMemoryFormat format, bool paging, bool has_filter,\n int64_t begin, int64_t length, Error **errp)\n {\n+ VMCoreInfoState *vmci = vmcoreinfo_find();\n CPUState *cpu;\n int nr_cpus;\n Error *err = NULL;\n@@ -1563,6 +1630,46 @@ static void dump_init(DumpState *s, int fd, bool has_format,\n goto cleanup;\n }\n \n+ /*\n+ * The goal of this block is to copy the guest note out of\n+ * the guest. Failure to do so is not fatal for dumping.\n+ */\n+ if (vmci) {\n+ uint64_t addr, note_head_size, name_size, desc_size;\n+ uint32_t size;\n+ uint16_t format;\n+\n+ note_head_size = s->dump_info.d_class == ELFCLASS32 ?\n+ sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr);\n+\n+ format = le16_to_cpu(vmci->vmcoreinfo.guest_format);\n+ size = le32_to_cpu(vmci->vmcoreinfo.size);\n+ addr = le64_to_cpu(vmci->vmcoreinfo.paddr);\n+ if (!vmci->has_vmcoreinfo) {\n+ warn_report(\"guest note is not present\");\n+ } else if (size < note_head_size || size > MAX_GUEST_NOTE_SIZE) {\n+ warn_report(\"guest note size is invalid: %\" PRIu32, size);\n+ } else if (format != VMCOREINFO_FORMAT_ELF) {\n+ warn_report(\"guest note format is unsupported: %\" PRIu16, format);\n+ } else {\n+ s->guest_note = g_malloc(size + 1); /* +1 for adding \\0 */\n+ cpu_physical_memory_read(addr, s->guest_note, size);\n+\n+ get_note_sizes(s, s->guest_note, NULL, &name_size, &desc_size);\n+ s->guest_note_size = ELF_NOTE_SIZE(note_head_size, name_size,\n+ desc_size);\n+ if (name_size > MAX_GUEST_NOTE_SIZE ||\n+ desc_size > MAX_GUEST_NOTE_SIZE ||\n+ s->guest_note_size > size) {\n+ warn_report(\"Invalid guest note header\");\n+ g_free(s->guest_note);\n+ s->guest_note = NULL;\n+ } else {\n+ s->note_size += s->guest_note_size;\n+ }\n+ }\n+ }\n+\n /* get memory mapping */\n if (paging) {\n qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &err);\n", "prefixes": [ "v6", "3/7" ] }