qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Richard Henderson <richard.henderson@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>, Thomas Huth <thuth@redhat.com>,
	Halil Pasic <pasic@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>,
	David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH 2/3] hw/misc: Add mmio-debug-exit device
Date: Mon, 11 Jul 2022 20:56:39 +0200	[thread overview]
Message-ID: <20220711185640.3558813-3-iii@linux.ibm.com> (raw)
In-Reply-To: <20220711185640.3558813-1-iii@linux.ibm.com>

System tests on x86 use isa-debug-exit device in order to signal
success or failure to the test runner. Unfortunately it's not easily
usable on other architectures, since a guest needs to access
address_space_io, which may not be as straightforward as on x86.
Also, it requires adding ISA bus, which an architecture might not
otherwise need.

Introduce mmio-debug-exit device, which has the same semantics, but is
triggered by writes to memory.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 hw/misc/Kconfig          |  3 ++
 hw/misc/debugexit_mmio.c | 80 ++++++++++++++++++++++++++++++++++++++++
 hw/misc/meson.build      |  1 +
 hw/s390x/Kconfig         |  1 +
 4 files changed, 85 insertions(+)
 create mode 100644 hw/misc/debugexit_mmio.c

diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index cbabe9f78c..0f12735ef7 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -15,6 +15,9 @@ config ISA_DEBUG
     bool
     depends on ISA_BUS
 
+config MMIO_DEBUGEXIT
+    bool
+
 config SGA
     bool
     depends on ISA_BUS
diff --git a/hw/misc/debugexit_mmio.c b/hw/misc/debugexit_mmio.c
new file mode 100644
index 0000000000..5e823cc01c
--- /dev/null
+++ b/hw/misc/debugexit_mmio.c
@@ -0,0 +1,80 @@
+/*
+ * Exit with status X when the guest writes X (little-endian) to a specified
+ * address. For testing purposes only.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "exec/address-spaces.h"
+#include "exec/memory.h"
+#include "hw/qdev-core.h"
+#include "hw/qdev-properties.h"
+
+#define TYPE_MMIO_DEBUG_EXIT_DEVICE "mmio-debug-exit"
+OBJECT_DECLARE_SIMPLE_TYPE(MMIODebugExitState, MMIO_DEBUG_EXIT_DEVICE)
+
+struct MMIODebugExitState {
+    DeviceState parent_obj;
+
+    uint32_t base;
+    uint32_t size;
+    MemoryRegion region;
+};
+
+static uint64_t mmio_debug_exit_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0;
+}
+
+static void mmio_debug_exit_write(void *opaque, hwaddr addr, uint64_t val,
+                                  unsigned width)
+{
+    exit(val);
+}
+
+static const MemoryRegionOps mmio_debug_exit_ops = {
+    .read = mmio_debug_exit_read,
+    .write = mmio_debug_exit_write,
+    .valid.min_access_size = 1,
+    .valid.max_access_size = 8,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static void mmio_debug_exit_realizefn(DeviceState *d, Error **errp)
+{
+    MMIODebugExitState *s = MMIO_DEBUG_EXIT_DEVICE(d);
+
+    memory_region_init_io(&s->region, OBJECT(s), &mmio_debug_exit_ops, s,
+                          TYPE_MMIO_DEBUG_EXIT_DEVICE, s->size);
+    memory_region_add_subregion(get_system_memory(), s->base, &s->region);
+}
+
+static Property mmio_debug_exit_properties[] = {
+    DEFINE_PROP_UINT32("base", MMIODebugExitState, base, 0),
+    DEFINE_PROP_UINT32("size", MMIODebugExitState, size, 1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void mmio_debug_exit_class_initfn(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = mmio_debug_exit_realizefn;
+    device_class_set_props(dc, mmio_debug_exit_properties);
+    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+}
+
+static const TypeInfo mmio_debug_exit_info = {
+    .name          = TYPE_MMIO_DEBUG_EXIT_DEVICE,
+    .parent        = TYPE_DEVICE,
+    .instance_size = sizeof(MMIODebugExitState),
+    .class_init    = mmio_debug_exit_class_initfn,
+};
+
+static void mmio_debug_exit_register_types(void)
+{
+    type_register_static(&mmio_debug_exit_info);
+}
+
+type_init(mmio_debug_exit_register_types)
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
index 95268eddc0..1d2a1067dc 100644
--- a/hw/misc/meson.build
+++ b/hw/misc/meson.build
@@ -2,6 +2,7 @@ softmmu_ss.add(when: 'CONFIG_APPLESMC', if_true: files('applesmc.c'))
 softmmu_ss.add(when: 'CONFIG_EDU', if_true: files('edu.c'))
 softmmu_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('vmcoreinfo.c'))
 softmmu_ss.add(when: 'CONFIG_ISA_DEBUG', if_true: files('debugexit.c'))
+softmmu_ss.add(when: 'CONFIG_MMIO_DEBUGEXIT', if_true: files('debugexit_mmio.c'))
 softmmu_ss.add(when: 'CONFIG_ISA_TESTDEV', if_true: files('pc-testdev.c'))
 softmmu_ss.add(when: 'CONFIG_PCA9552', if_true: files('pca9552.c'))
 softmmu_ss.add(when: 'CONFIG_PCI_TESTDEV', if_true: files('pci-testdev.c'))
diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig
index 5e7d8a2bae..9223715dcc 100644
--- a/hw/s390x/Kconfig
+++ b/hw/s390x/Kconfig
@@ -5,6 +5,7 @@ config S390_CCW_VIRTIO
     imply VFIO_AP
     imply VFIO_CCW
     imply WDT_DIAG288
+    imply MMIO_DEBUGEXIT
     select PCI
     select S390_FLIC
     select SCLPCONSOLE
-- 
2.35.3



  parent reply	other threads:[~2022-07-11 19:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11 18:56 [PATCH 0/3] accel/tcg: Fix unaligned stores to s390x low-address-protected lowcore Ilya Leoshkevich
2022-07-11 18:56 ` [PATCH 1/3] " Ilya Leoshkevich
2022-07-12  5:12   ` Richard Henderson
2022-07-12  7:14   ` David Hildenbrand
2022-07-11 18:56 ` Ilya Leoshkevich [this message]
2022-07-12  5:12   ` [PATCH 2/3] hw/misc: Add mmio-debug-exit device Richard Henderson
2022-07-12  9:52     ` Ilya Leoshkevich
2022-07-12 10:08       ` David Hildenbrand
2022-07-12 10:08       ` David Hildenbrand
2022-07-12 10:30         ` Ilya Leoshkevich
2022-07-11 18:56 ` [PATCH 3/3] tests/tcg/s390x: Test unaligned accesses to lowcore Ilya Leoshkevich

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=20220711185640.3558813-3-iii@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).