qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: Blue Swirl <blauwirbel@gmail.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH v3 10/16] memory: Introduce memory_region_init_reservation
Date: Tue,  6 Dec 2011 13:58:10 +0100	[thread overview]
Message-ID: <e13f047ebbd2ca56de1ebc576c20a6370bfd90c2.1323176291.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1323176291.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1323176291.git.jan.kiszka@siemens.com>

Introduce a memory region type that can reserve I/O space. Such regions
are useful for modeling I/O that is only handled outside of QEMU, i.e.
in the context of an accelerator like KVM.

Any access to such a region from QEMU is a bug, but could theoretically
be triggered by guest code (DMA to reserved region). So only warning
about such events once, then ignore them.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 memory.c |   36 ++++++++++++++++++++++++++++++++++++
 memory.h |   16 ++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index dc5e35d..6d55cf6 100644
--- a/memory.c
+++ b/memory.c
@@ -1003,6 +1003,42 @@ void memory_region_init_rom_device(MemoryRegion *mr,
     mr->backend_registered = true;
 }
 
+static uint64_t invalid_read(void *opaque, target_phys_addr_t addr,
+                             unsigned size)
+{
+    MemoryRegion *mr = opaque;
+
+    if (!mr->warning_printed) {
+        fprintf(stderr, "Invalid read from memory region %s\n", mr->name);
+        mr->warning_printed = true;
+    }
+    return -1U;
+}
+
+static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data,
+                          unsigned size)
+{
+    MemoryRegion *mr = opaque;
+
+    if (!mr->warning_printed) {
+        fprintf(stderr, "Invalid write to memory region %s\n", mr->name);
+        mr->warning_printed = true;
+    }
+}
+
+static const MemoryRegionOps reservation_ops = {
+    .read = invalid_read,
+    .write = invalid_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+void memory_region_init_reservation(MemoryRegion *mr,
+                                    const char *name,
+                                    uint64_t size)
+{
+    memory_region_init_io(mr, &reservation_ops, mr, name, size);
+}
+
 void memory_region_destroy(MemoryRegion *mr)
 {
     assert(QTAILQ_EMPTY(&mr->subregions));
diff --git a/memory.h b/memory.h
index d5b47da..b479350 100644
--- a/memory.h
+++ b/memory.h
@@ -115,6 +115,7 @@ struct MemoryRegion {
     bool terminates;
     bool readable;
     bool readonly; /* For RAM regions */
+    bool warning_printed; /* For reservations */
     MemoryRegion *alias;
     target_phys_addr_t alias_offset;
     unsigned priority;
@@ -242,6 +243,21 @@ void memory_region_init_rom_device(MemoryRegion *mr,
                                    uint64_t size);
 
 /**
+ * memory_region_init_reservation: Initialize a memory region that reserves
+ *                                 I/O space.
+ *
+ * A reservation region primariy serves debugging purposes.  It claims I/O
+ * space that is not supposed to be handled by QEMU itself.  Any access via
+ * the memory API will cause an abort().
+ *
+ * @mr: the #MemoryRegion to be initialized
+ * @name: used for debugging; not visible to the user or ABI
+ * @size: size of the region.
+ */
+void memory_region_init_reservation(MemoryRegion *mr,
+                                    const char *name,
+                                    uint64_t size);
+/**
  * memory_region_destroy: Destroy a memory region and relaim all resources.
  *
  * @mr: the region to be destroyed.  May not currently be a subregion
-- 
1.7.3.4

  parent reply	other threads:[~2011-12-06 12:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06 12:58 [Qemu-devel] [PATCH v3 00/16] uq/master: Introduce basic irqchip support Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 01/16] msi: Generalize msix_supported to msi_supported Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 02/16] kvm: Move kvmclock into hw/kvm folder Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 03/16] apic: Stop timer on reset Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 04/16] apic: Introduce backend/frontend infrastructure for KVM reuse Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 05/16] apic: Open-code timer save/restore Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 06/16] i8259: Introduce backend/frontend infrastructure for KVM reuse Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 07/16] ioapic: Convert to memory API Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 08/16] ioapic: Reject non-dword accesses to IOWIN register Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 09/16] ioapic: Introduce backend/frontend infrastructure for KVM reuse Jan Kiszka
2011-12-06 12:58 ` Jan Kiszka [this message]
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 11/16] kvm: Introduce core services for in-kernel irqchip support Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 12/16] kvm: x86: Establish IRQ0 override control Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 13/16] kvm: x86: Add user space part for in-kernel APIC Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 14/16] kvm: x86: Add user space part for in-kernel i8259 Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 15/16] kvm: x86: Add user space part for in-kernel IOAPIC Jan Kiszka
2011-12-06 12:58 ` [Qemu-devel] [PATCH v3 16/16] kvm: Arm in-kernel irqchip support Jan Kiszka
2011-12-06 13:55 ` [Qemu-devel] [PATCH v3 00/16] uq/master: Introduce basic " Avi Kivity
2011-12-06 14:21   ` Jan Kiszka

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=e13f047ebbd2ca56de1ebc576c20a6370bfd90c2.1323176291.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).