All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org
Cc: "Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	qemu-ppc@nongnu.org, qemu-arm@nongnu.org,
	"Markus Armbruster" <armbru@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Thomas Huth" <thuth@redhat.com>,
	"Daniel P . Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v2 14/18] hw/nvram/fw_cfg: Add HMP 'info fw_cfg' command
Date: Fri,  8 Mar 2019 02:32:18 +0100	[thread overview]
Message-ID: <20190308013222.12524-15-philmd@redhat.com> (raw)
In-Reply-To: <20190308013222.12524-1-philmd@redhat.com>

When debugging a paravirtualized guest firmware, it results very
useful to dump the fw_cfg table.
Add a HMP command which displays the most useful fields.
We display each fw_cfg item data in hexadecimal (only the first 8
bytes):

$ (echo info fw_cfg; echo q) | qemu-system-x86_64 -S -monitor stdio
(qemu) info fw_cfg
Selector  Well-Known Key  Pathname ArchSpec Perm   Size Order Hex Data
 0x0000   signature                          RO       4       51454d55
 0x0001   id                                 RO       4       03000000
 0x0002   uuid                               RO      16       0000000000000000..
 0x0003   ram_size                           RO       8       0000000800000000
 0x0004   nographic                          RO       2       0000
 0x0005   nb_cpus                            RO       2       0100
 0x000d   numa                               RO      16       0000000000000000..
 0x000e   boot_menu                          RO       2       0000
 0x000f   max_cpus                           RO       2       0100
 0x0019   file_dir                           RO    2052       0000000b00000000..
 0x0021   file: etc/acpi/rsdp                RO      20  160  5253442050545220..
 0x0022   file: etc/acpi/tables              RO  131072  130  4641435340000000..
 0x0023   file: etc/boot-fail-wait           RO       4   15  ffffffff
 0x0024   file: etc/e820                     RO      20   40  0000000000000000..
 0x0025   file: etc/smbios/smbios-anchor     RO      31   30  5f534d5f001f0208..
 0x0026   file: etc/smbios/smbios-tables     RO     321   20  011b000101020300..
 0x0027   file: etc/system-states            RO       6   90  800000818280
 0x0028   file: etc/table-loader             RO    4096  140  010000006574632f..
 0x002a   file: genroms/kvmvapic.bin         RO    9216   55  55aa12060e0731c0..
 0x0002   irq0_override                   *  RO       4       01000000
 0x0003   e820_tables                     *  RO     324       0000000000000000..
 0x0004   hpet                            *  RO     121       0101a286800000d0..
(qemu) q

$ (echo info fw_cfg; echo q) | qemu-system-mips -S -monitor stdio
(qemu) info fw_cfg
This machine does not use fw_cfg
(qemu) q

$ (echo info fw_cfg; echo q) | qemu-system-ppc -S -monitor stdio
(qemu) info fw_cfg
Selector  Well-Known Key  Pathname ArchSpec Perm   Size Order Hex Data
 0x0000   signature                          RO       4       51454d55
 0x0001   id                                 RO       4       01000000
 0x0002   uuid                               RO      16       0000000000000000..
 0x0003   ram_size                           RO       8       0000000800000000
 0x0004   nographic                          RO       2       0000
 0x0005   nb_cpus                            RO       2       0100
 0x0006   machine_id                         RO       2       0200
 0x0007   kernel_addr                        RO       4       00000000
 0x0008   kernel_size                        RO       4       00000000
 0x0009   kernel_cmdline                     RO       4       00000000
 0x000a   initrd_addr                        RO       4       00000000
 0x000b   initdr_size                        RO       4       00000000
 0x000c   boot_device                        RO       2       6300
 0x000e   boot_menu                          RO       2       0000
 0x000f   max_cpus                           RO       2       0100
 0x0019   file_dir                           RO    2052       0000000200000000..
 0x0021   file: etc/boot-fail-wait           RO       4   15  ffffffff
 0x0000   width                           *  RO       2       2003
 0x0001   height                          *  RO       2       5802
 0x0002   depth                           *  RO       2       2000
 0x0003   tbfreq                          *  RO       4       c04bfd00
 0x0004   clockfreq                       *  RO       4       80d6da0f
 0x0005   is_kvm                          *  RO       4       00000000
 0x0009   busfreq                         *  RO       4       8014ef03
(qemu) q

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2: Check fw_cfg != NULL (Michael)
    Rename keys, display data in hexa (Laszlo)
---
 hmp-commands-info.hx      | 17 ++++++++++
 hw/nvram/fw_cfg.c         | 71 ++++++++++++++++++++++++++++++++++++++-
 include/hw/nvram/fw_cfg.h |  2 ++
 3 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index cbee8b944d..2c9538c8da 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -916,6 +916,23 @@ STEXI
 @item info sev
 @findex info sev
 Show SEV information.
+ETEXI
+
+    {
+        .name       = "fw_cfg",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Display the table firmware configuration entries "
+                      "registered by a paravirtualized machine. Helpful "
+                      "when debugging guest firmwares.",
+        .cmd        = hmp_info_fw_cfg,
+    },
+
+STEXI
+@item info fw_cfg
+@findex info fw_cfg
+Display the table firmware configuration entries registered by a paravirtualized
+machine. This information is useful when debugging guest firmwares.
 ETEXI
 
 STEXI
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 2a8d69ba07..4c82dcc125 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -35,6 +35,7 @@
 #include "qemu/config-file.h"
 #include "qemu/cutils.h"
 #include "qapi/error.h"
+#include "monitor/monitor.h"
 #include "qapi/qapi-commands-misc.h"
 
 #define FW_CFG_FILE_SLOTS_DFLT 0x20
@@ -1273,7 +1274,18 @@ static FirmwareConfigurationItem *create_qmp_fw_cfg_item(FWCfgState *s,
     return item;
 }
 
-FirmwareConfigurationItemList *qmp_query_fw_cfg_items(Error **errp)
+/**
+ * query_fw_cfg_items:
+ *
+ * @use_hexdump: Whether to populate the @data field with the hexadecimal
+ *               representation of the item data.
+ * @errp: Pointer to a NULL initialized error object.
+ *
+ * Returns: A list of @FirmwareConfigurationItem, reverse sorted by the
+ *          item selector key.
+ */
+static FirmwareConfigurationItemList *query_fw_cfg_items(bool use_hexdump,
+                                                         Error **errp)
 {
     FirmwareConfigurationItemList *item_list = NULL;
     uint32_t max_entries;
@@ -1294,6 +1306,9 @@ FirmwareConfigurationItemList *qmp_query_fw_cfg_items(Error **errp)
             if (!e->len) {
                 continue;
             }
+            if (use_hexdump) {
+                qmp_hex_length = MIN(e->len, 8);
+            }
 
             info = g_malloc0(sizeof(*info));
             info->value = create_qmp_fw_cfg_item(s, e, arch, key,
@@ -1305,3 +1320,57 @@ FirmwareConfigurationItemList *qmp_query_fw_cfg_items(Error **errp)
 
     return item_list;
 }
+
+FirmwareConfigurationItemList *qmp_query_fw_cfg_items(Error **errp)
+{
+    return query_fw_cfg_items(false, errp);
+}
+
+void hmp_info_fw_cfg(Monitor *mon, const QDict *qdict)
+{
+    FirmwareConfigurationItemList *item_list, *method;
+    Error *err = NULL;
+
+    item_list = query_fw_cfg_items(true, &err);
+    if (!item_list) {
+        monitor_printf(mon, "This machine does not use fw_cfg\n");
+        return;
+    }
+    if (err) {
+        monitor_printf(mon, "Could not query fw_cfg entries: %s\n",
+                       error_get_pretty(err));
+        error_free(err);
+        return;
+    }
+
+    monitor_printf(mon, "Selector  Well-Known Key  Pathname"
+                        " ArchSpec Perm   Size Order Hex Data\n");
+    for (method = item_list; method; method = method->next) {
+        if (method->value->has_path) {
+            monitor_printf(mon,
+                           " 0x%04x   file: %-28s %2s %7" PRId64
+                           "  %3" PRId64 "  %-16s%s\n",
+                           method->value->key,
+                           method->value->path,
+                           method->value->writeable ? "RW" : "RO",
+                           method->value->size,
+                           method->value->order,
+                           method->value->data,
+                           method->value->size > 8 ? ".." : "");
+        } else {
+            monitor_printf(mon,
+                           " 0x%04x   %-30s  %c  %2s %7" PRId64
+                           "       %-16s%s\n",
+                           method->value->key,
+                           method->value->has_keyname
+                                ? method->value->keyname : "",
+                           method->value->architecture_specific ? '*' : ' ',
+                           method->value->writeable ? "RW" : "RO",
+                           method->value->size,
+                           method->value->data,
+                           method->value->size > 8 ? ".." : "");
+       }
+    }
+
+    qapi_free_FirmwareConfigurationItemList(item_list);
+}
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 83a0540b6c..5ac9adfe1f 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -243,4 +243,6 @@ bool fw_cfg_dma_enabled(void *opaque);
  */
 const char *fw_cfg_arch_key_name(uint16_t key);
 
+void hmp_info_fw_cfg(Monitor *mon, const QDict *qdict);
+
 #endif
-- 
2.20.1

  parent reply	other threads:[~2019-03-08  1:35 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08  1:32 [Qemu-devel] [PATCH v2 00/18] fw_cfg: reduce memleaks, add QMP/HMP info + edk2_add_host_crypto_policy Philippe Mathieu-Daudé
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 01/18] hw/arm/virt: Remove null-check in virt_build_smbios() Philippe Mathieu-Daudé
2019-03-09 14:09   ` Markus Armbruster
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 02/18] hw/i386: Remove unused include Philippe Mathieu-Daudé
2019-03-08  9:22   ` Laszlo Ersek
2019-03-08 11:32   ` [Qemu-devel] [Qemu-ppc] " Thomas Huth
2019-03-09 14:54     ` [Qemu-devel] [Qemu-trivial] " Laurent Vivier
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 03/18] cutils: Add qemu_strdup_hexlify() and qemu_strdup_unhexlify() Philippe Mathieu-Daudé
2019-03-08  9:48   ` Laszlo Ersek
2019-03-09 14:32     ` Markus Armbruster
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 04/18] hw/nvram/fw_cfg: Add trace events Philippe Mathieu-Daudé
2019-03-08  9:57   ` Laszlo Ersek
2019-03-08 10:59     ` Philippe Mathieu-Daudé
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 05/18] hw/nvram/fw_cfg: Use the ldst API Philippe Mathieu-Daudé
2019-03-08 10:02   ` Laszlo Ersek
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 06/18] hw/nvram/fw_cfg: Remove the unnecessary boot_splash_filedata_size Philippe Mathieu-Daudé
2019-03-08  6:49   ` Thomas Huth
2019-03-09 14:53     ` [Qemu-devel] [Qemu-trivial] " Laurent Vivier
2019-03-08 10:05   ` [Qemu-devel] " Laszlo Ersek
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 07/18] hw/nvram/fw_cfg: Add fw_cfg_common_unrealize() Philippe Mathieu-Daudé
2019-03-08  6:55   ` Thomas Huth
2019-03-08 10:29     ` Laszlo Ersek
2019-03-09 14:44       ` Markus Armbruster
2019-03-09 14:47   ` Markus Armbruster
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 08/18] hw/nvram/fw_cfg: Move fw_cfg_file_slots_allocate() to common_realize() Philippe Mathieu-Daudé
2019-03-08 10:19   ` Laszlo Ersek
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 09/18] hw/nvram/fw_cfg: Free file_slots in common_unrealize() Philippe Mathieu-Daudé
2019-03-08 10:31   ` Laszlo Ersek
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 10/18] hw/nvram/fw_cfg: Add reboot_timeout to FWCfgState Philippe Mathieu-Daudé
2019-03-08 11:04   ` Laszlo Ersek
2019-03-08 11:22     ` Philippe Mathieu-Daudé
2019-03-08 11:29       ` Philippe Mathieu-Daudé
2019-03-08 13:48   ` Michael S. Tsirkin
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 11/18] hw/nvram/fw_cfg: Add boot_splash.time_le16 " Philippe Mathieu-Daudé
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 12/18] hw/nvram/fw_cfg: Keep reference of file_data in FWCfgState Philippe Mathieu-Daudé
2019-03-08  7:02   ` Thomas Huth
2019-03-08 11:16   ` Laszlo Ersek
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 13/18] hw/nvram/fw_cfg: Add QMP 'info fw_cfg' command Philippe Mathieu-Daudé
2019-03-08  2:04   ` Eric Blake
2019-03-08 11:08     ` Philippe Mathieu-Daudé
2019-03-08 17:31       ` Eric Blake
2019-03-08 18:07         ` Philippe Mathieu-Daudé
2019-03-08 20:00           ` Laszlo Ersek
2019-03-08 20:18             ` Philippe Mathieu-Daudé
2019-03-09 15:04     ` Markus Armbruster
2019-03-08  1:32 ` Philippe Mathieu-Daudé [this message]
2019-03-08 15:49   ` [Qemu-devel] [PATCH v2 14/18] hw/nvram/fw_cfg: Add HMP " Dr. David Alan Gilbert
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 15/18] hw/nvram/fw_cfg: Add fw_cfg_add_file_from_host() Philippe Mathieu-Daudé
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 16/18] hw/firmware: Add Edk2Crypto and edk2_add_host_crypto_policy() Philippe Mathieu-Daudé
2019-03-08  2:16   ` Eric Blake
2019-03-09 18:08     ` Philippe Mathieu-Daudé
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 17/18] hw/i386: Use edk2_add_host_crypto_policy() Philippe Mathieu-Daudé
2019-03-08  1:32 ` [Qemu-devel] [PATCH v2 18/18] hw/arm/virt: " Philippe Mathieu-Daudé
2019-03-08 11:25 ` [Qemu-devel] [PATCH v2 00/18] fw_cfg: reduce memleaks, add QMP/HMP info + edk2_add_host_crypto_policy Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308013222.12524-15-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=armbru@redhat.com \
    --cc=atar4qemu@gmail.com \
    --cc=berrange@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.