[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 36/53] qapi: introduce x-query-skeys QMP command
From: |
Daniel P . Berrangé |
Subject: |
[PATCH v2 36/53] qapi: introduce x-query-skeys QMP command |
Date: |
Tue, 14 Sep 2021 15:20:25 +0100 |
This is a counterpart to the HMP "info skeys" command. It is being
added with an "x-" prefix because this QMP command is intended as an
adhoc debugging tool and will thus not be modelled in QAPI as fully
structured data, nor will it have long term guaranteed stability.
The existing HMP command is rewritten to call the QMP command.
This command is unable to use the pre-existing HumanReadableText,
because if 'common.json' is included into 'machine-target.json'
the static marshalling method for HumanReadableText will be reported
as unused by the compiler on all architectures except s390x.
Possible options were
1 Support 'if' conditionals on 'include' statements in QAPI
2 Add further commands to 'machine-target.json' that use
HumanReadableText, such that it has at least one usage
on all architecture targets.
3 Duplicate HumanReadableText as TargetHumanReadableText
adding conditions
This patch takes option (3) in the belief that we will eventually
get to a point where option (2) happens, and TargetHumanReadableText
can be removed again.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
hw/s390x/s390-skeys.c | 37 +++++++++++++++++++++++++++++--------
qapi/machine-target.json | 27 +++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 5024faf411..3a404d0574 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -15,6 +15,7 @@
#include "hw/s390x/storage-keys.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qapi-commands-machine-target.h"
#include "qapi/qmp/qdict.h"
#include "qemu/error-report.h"
#include "sysemu/memory_mapping.h"
@@ -73,34 +74,54 @@ static void write_keys(FILE *f, uint8_t *keys, uint64_t
startgfn,
}
}
-void hmp_info_skeys(Monitor *mon, const QDict *qdict)
+TargetHumanReadableText *qmp_x_query_skeys(int64_t addr, Error **errp)
{
+ TargetHumanReadableText *ret;
+ g_autoptr(GString) buf = g_string_new("");
S390SKeysState *ss = s390_get_skeys_device();
S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
- uint64_t addr = qdict_get_int(qdict, "addr");
uint8_t key;
int r;
/* Quick check to see if guest is using storage keys*/
if (!skeyclass->skeys_are_enabled(ss)) {
- monitor_printf(mon, "Error: This guest is not using storage keys\n");
- return;
+ error_setg(errp, "this guest is not using storage keys");
+ return NULL;
}
if (!address_space_access_valid(&address_space_memory,
addr & TARGET_PAGE_MASK, TARGET_PAGE_SIZE,
false, MEMTXATTRS_UNSPECIFIED)) {
- monitor_printf(mon, "Error: The given address is not valid\n");
- return;
+ error_setg(errp, "the given address is not valid");
+ return NULL;
}
r = skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key);
if (r < 0) {
- monitor_printf(mon, "Error: %s\n", strerror(-r));
+ error_setg_errno(errp, r, "unable to query storage keys");
+ return NULL;
+ }
+
+ g_string_append_printf(buf, " key: 0x%X\n", key);
+
+ ret = g_new0(TargetHumanReadableText, 1);
+ ret->human_readable_text = g_steal_pointer(&buf->str);
+ return ret;
+}
+
+void hmp_info_skeys(Monitor *mon, const QDict *qdict)
+{
+ Error *err = NULL;
+ g_autoptr(TargetHumanReadableText) info = NULL;
+ uint64_t addr = qdict_get_int(qdict, "addr");
+
+ info = qmp_x_query_skeys(addr, &err);
+ if (err) {
+ error_report_err(err);
return;
}
- monitor_printf(mon, " key: 0x%X\n", key);
+ monitor_printf(mon, "%s", info->human_readable_text);
}
void hmp_dump_skeys(Monitor *mon, const QDict *qdict)
diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index f5ec4bc172..00476bcdd4 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -341,3 +341,30 @@
'TARGET_I386',
'TARGET_S390X',
'TARGET_MIPS' ] } }
+
+
+##
+# @TargetHumanReadableText:
+#
+# @human-readable-text: Formatted output intended for humans.
+#
+# Since: 6.2.0
+#
+##
+{ 'struct': 'TargetHumanReadableText',
+ 'data': { 'human-readable-text': 'str' },
+ 'if': 'TARGET_S390X' }
+
+##
+# @x-query-skeys:
+#
+# Query the value of a storage key
+#
+# Returns: storage key value
+#
+# Since: 6.2
+##
+{ 'command': 'x-query-skeys',
+ 'data': { 'addr': 'int' },
+ 'returns': 'TargetHumanReadableText',
+ 'if': 'TARGET_S390X' }
--
2.31.1
- Re: [PATCH v2 29/53] qapi: introduce x-query-registers QMP command, (continued)
[PATCH v2 30/53] qapi: introduce x-query-roms QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 31/53] qapi: introduce x-query-profile QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 32/53] qapi: introduce x-query-numa QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 33/53] qapi: introduce x-query-usb QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 35/53] qapi: introduce x-query-ramblock QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 34/53] qapi: introduce x-query-rdma QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 36/53] qapi: introduce x-query-skeys QMP command,
Daniel P . Berrangé <=
[PATCH v2 37/53] qapi: introduce x-query-cmma QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 38/53] qapi: introduce x-query-lapic QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 39/53] qapi: introduce x-query-irq QMP command, Daniel P . Berrangé, 2021/09/14
[PATCH v2 40/53] hw/core: drop "dump_state" callback from CPU targets, Daniel P . Berrangé, 2021/09/14
[PATCH v2 41/53] hw/core: drop support for NULL pointer for FILE * in cpu_dump_state, Daniel P . Berrangé, 2021/09/14
[PATCH v2 42/53] hw/core: introduce a 'format_tlb' callback, Daniel P . Berrangé, 2021/09/14