Skip to contentSkip to conversation

Fix unassigned memory and I/O access handling

PATCH Superseded Jan Kiszka 5 participants 12 messages Aug 9, 2013 – Sep 2, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

cover Fix unassigned memory and I/O access handling

This just binds both patches properly together and fixes up the return value size of unassigned_io_read as suggested. Please merge before the 1.6 release.

Jan Kiszka (2):
memory: Provide separate handling of unassigned io ports accesses Revert "memory: Return -1 again on reads from unsigned regions"

 exec.c                |    3 ++-
 include/exec/ioport.h |    2 ++
 ioport.c              |   16 ++++++++++++++++
 memory.c              |    2 +-
 4 files changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.3.4
author
#1 lore raw

PATCH 1/2 memory: Provide separate handling of unassigned io ports accesses

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

---
 exec.c                |    3 ++-
 include/exec/ioport.h |    2 ++
 ioport.c              |   16 ++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletions(-)
exec.c +2 -1
index 3ca9381..9ed598f 100644
@@ -1820,7 +1820,8 @@ static void memory_map_init(void)
     address_space_init(&address_space_memory, system_memory, "memory");
 
     system_io = g_malloc(sizeof(*system_io));
-    memory_region_init(system_io, NULL, "io", 65536);
+    memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
+                          65536);
     address_space_init(&address_space_io, system_io, "I/O");
 
     memory_listener_register(&core_memory_listener, &address_space_memory);
include/exec/ioport.h +2 -0
index bdd4e96..84f7f85 100644
@@ -45,6 +45,8 @@ typedef struct MemoryRegionPortio {
 
 #define PORTIO_END_OF_LIST() { }
 
+extern const MemoryRegionOps unassigned_io_ops;
+
 void cpu_outb(pio_addr_t addr, uint8_t val);
 void cpu_outw(pio_addr_t addr, uint16_t val);
 void cpu_outl(pio_addr_t addr, uint32_t val);
ioport.c +16 -0
index 79b7f1a..707cce8 100644
@@ -44,6 +44,22 @@ typedef struct MemoryRegionPortioList {
     MemoryRegionPortio ports[];
 } MemoryRegionPortioList;
 
+static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return -1ULL;
+}
+
+static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val,
+                                unsigned size)
+{
+}
+
+const MemoryRegionOps unassigned_io_ops = {
+    .read = unassigned_io_read,
+    .write = unassigned_io_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 void cpu_outb(pio_addr_t addr, uint8_t val)
 {
     LOG_IOPORT("outb: %04"FMT_pioaddr" %02"PRIx8"\n", addr, val);
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [Qemu-devel] [PATCH for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

Quoted 5 lines · Jan Kiszka

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

Breaks the build (linux-user):

LINK xtensa-softmmu/qemu-system-xtensa
CC alpha-linux-user/exec.o
In file included from /home/aliguori/git/qemu/include/hw/hw.h:11:0,

                 from /home/aliguori/git/qemu/exec.c:30:

/home/aliguori/git/qemu/include/exec/ioport.h:48:1: error: unknown type name ‘MemoryRegionOps’ make[1]: *** [exec.o] Error 1
make: *** [subdir-alpha-linux-user] Error 2

Regards,

Anthony Liguori

Quoted 62 lines
---
 exec.c                |    3 ++-
 include/exec/ioport.h |    2 ++
 ioport.c              |   16 ++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletions(-)
exec.c +2 -1
index 3ca9381..9ed598f 100644
@@ -1820,7 +1820,8 @@ static void memory_map_init(void)
     address_space_init(&address_space_memory, system_memory, "memory");
 
     system_io = g_malloc(sizeof(*system_io));
-    memory_region_init(system_io, NULL, "io", 65536);
+    memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
+                          65536);
     address_space_init(&address_space_io, system_io, "I/O");
 
     memory_listener_register(&core_memory_listener, &address_space_memory);
include/exec/ioport.h +2 -0
index bdd4e96..84f7f85 100644
@@ -45,6 +45,8 @@ typedef struct MemoryRegionPortio {
 
 #define PORTIO_END_OF_LIST() { }
 
+extern const MemoryRegionOps unassigned_io_ops;
+
 void cpu_outb(pio_addr_t addr, uint8_t val);
 void cpu_outw(pio_addr_t addr, uint16_t val);
 void cpu_outl(pio_addr_t addr, uint32_t val);
ioport.c +16 -0
index 79b7f1a..707cce8 100644
@@ -44,6 +44,22 @@ typedef struct MemoryRegionPortioList {
     MemoryRegionPortio ports[];
 } MemoryRegionPortioList;
 
+static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return -1ULL;
+}
+
+static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val,
+                                unsigned size)
+{
+}
+
+const MemoryRegionOps unassigned_io_ops = {
+    .read = unassigned_io_read,
+    .write = unassigned_io_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 void cpu_outb(pio_addr_t addr, uint8_t val)
 {
     LOG_IOPORT("outb: %04"FMT_pioaddr" %02"PRIx8"\n", addr, val);
Signature · 1 line
1.7.3.4
author
#3 lore raw

PATCH v2 1/2 memory: Provide separate handling of unassigned io ports accesses

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

---

Changes in v2:
- avoid breakage in ioport.h for user build

 exec.c                |    3 ++-
 include/exec/ioport.h |    4 ++++
 ioport.c              |   16 ++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletions(-)
exec.c +2 -1
index 3ca9381..9ed598f 100644
@@ -1820,7 +1820,8 @@ static void memory_map_init(void)
     address_space_init(&address_space_memory, system_memory, "memory");
 
     system_io = g_malloc(sizeof(*system_io));
-    memory_region_init(system_io, NULL, "io", 65536);
+    memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
+                          65536);
     address_space_init(&address_space_io, system_io, "I/O");
 
     memory_listener_register(&core_memory_listener, &address_space_memory);
include/exec/ioport.h +4 -0
index bdd4e96..b3848be 100644
@@ -45,6 +45,10 @@ typedef struct MemoryRegionPortio {
 
 #define PORTIO_END_OF_LIST() { }
 
+#ifndef CONFIG_USER_ONLY
+extern const MemoryRegionOps unassigned_io_ops;
+#endif
+
 void cpu_outb(pio_addr_t addr, uint8_t val);
 void cpu_outw(pio_addr_t addr, uint16_t val);
 void cpu_outl(pio_addr_t addr, uint32_t val);
ioport.c +16 -0
index 79b7f1a..707cce8 100644
@@ -44,6 +44,22 @@ typedef struct MemoryRegionPortioList {
     MemoryRegionPortio ports[];
 } MemoryRegionPortioList;
 
+static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return -1ULL;
+}
+
+static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val,
+                                unsigned size)
+{
+}
+
+const MemoryRegionOps unassigned_io_ops = {
+    .read = unassigned_io_read,
+    .write = unassigned_io_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 void cpu_outb(pio_addr_t addr, uint8_t val)
 {
     LOG_IOPORT("outb: %04"FMT_pioaddr" %02"PRIx8"\n", addr, val);
Signature · 1 line
1.7.3.4
#4 lore raw

Re: [Qemu-devel] [PATCH v2 for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

Quoted 5 lines · Jan Kiszka

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

Please top-post.

Regards,

Anthony Liguori

Quoted 68 lines

---

Changes in v2:
- avoid breakage in ioport.h for user build

 exec.c                |    3 ++-
 include/exec/ioport.h |    4 ++++
 ioport.c              |   16 ++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletions(-)
exec.c +2 -1
index 3ca9381..9ed598f 100644
@@ -1820,7 +1820,8 @@ static void memory_map_init(void)
     address_space_init(&address_space_memory, system_memory, "memory");
 
     system_io = g_malloc(sizeof(*system_io));
-    memory_region_init(system_io, NULL, "io", 65536);
+    memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
+                          65536);
     address_space_init(&address_space_io, system_io, "I/O");
 
     memory_listener_register(&core_memory_listener, &address_space_memory);
include/exec/ioport.h +4 -0
index bdd4e96..b3848be 100644
@@ -45,6 +45,10 @@ typedef struct MemoryRegionPortio {
 
 #define PORTIO_END_OF_LIST() { }
 
+#ifndef CONFIG_USER_ONLY
+extern const MemoryRegionOps unassigned_io_ops;
+#endif
+
 void cpu_outb(pio_addr_t addr, uint8_t val);
 void cpu_outw(pio_addr_t addr, uint16_t val);
 void cpu_outl(pio_addr_t addr, uint32_t val);
ioport.c +16 -0
index 79b7f1a..707cce8 100644
@@ -44,6 +44,22 @@ typedef struct MemoryRegionPortioList {
     MemoryRegionPortio ports[];
 } MemoryRegionPortioList;
 
+static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return -1ULL;
+}
+
+static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val,
+                                unsigned size)
+{
+}
+
+const MemoryRegionOps unassigned_io_ops = {
+    .read = unassigned_io_read,
+    .write = unassigned_io_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
 void cpu_outb(pio_addr_t addr, uint8_t val)
 {
     LOG_IOPORT("outb: %04"FMT_pioaddr" %02"PRIx8"\n", addr, val);
Signature · 1 line
1.7.3.4
#5 lore raw

Re: [Qemu-devel] [PATCH v2 for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

In reply to Jan Kiszka

Am 12.08.2013 17:29, schrieb Jan Kiszka:

Quoted 9 lines

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

---

Changes in v2:
- avoid breakage in ioport.h for user build

Looks OK, but if you want Anthony to apply this for rc3 then please repost as a full, top-level series.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw

Re: [Qemu-devel] [PATCH v2 for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

Quoted 5 lines · Andreas Färber

Am 12.08.2013 17:29, schrieb Jan Kiszka:

Quoted 4 lines

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

Quoted 8 lines
Quoted 5 lines

---

Changes in v2:
- avoid breakage in ioport.h for user build

Looks OK, but if you want Anthony to apply this for rc3 then please repost as a full, top-level series.

It looks like this never happened, so this bug is still present in master :-( [noticed by stsquad since integratorcp is busted too].

thanks
-- PMM

author
#7 lore raw

Re: [Qemu-devel] [PATCH v2 for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

Quoted 9 lines · Peter Maydell
Quoted 8 lines · Andreas Färber

Am 12.08.2013 17:29, schrieb Jan Kiszka:

Quoted 7 lines

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

---

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Changes in v2:
- avoid breakage in ioport.h for user build

Looks OK, but if you want Anthony to apply this for rc3 then please repost as a full, top-level series.

It looks like this never happened, so this bug is still present in master :-( [noticed by stsquad since integratorcp is busted too].

I suppose the repost just fell through the cracks at the end of the release cycle. Let me re-repost the whole thing, CC'ing stable.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#8 lore raw

Re: [Qemu-devel] [PATCH v2 for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

Am 02.09.2013 17:56, schrieb Jan Kiszka:

Quoted 13 lines · Peter Maydell
Quoted 12 lines · Andreas Färber
Quoted 11 lines

Am 12.08.2013 17:29, schrieb Jan Kiszka:

Quoted 9 lines

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

---

Changes in v2:
- avoid breakage in ioport.h for user build

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks OK, but if you want Anthony to apply this for rc3 then please repost as a full, top-level series.

It looks like this never happened, so this bug is still present in master :-( [noticed by stsquad since integratorcp is busted too].

I suppose the repost just fell through the cracks at the end of the release cycle. Let me re-repost the whole thing, CC'ing stable.

I vaguely remember you reposting 2/2 top-level only and asking Anthony to fix his tool instead, which was quite apparently not helpful. ;)

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#9 lore raw

Re: [Qemu-devel] [PATCH v2 for 1.6 1/2] memory: Provide separate handling of unassigned io ports accesses

Quoted 17 lines · Andreas Färber

Am 02.09.2013 17:56, schrieb Jan Kiszka:

Quoted 16 lines · Peter Maydell
Quoted 15 lines · Andreas Färber
Quoted 13 lines

Am 12.08.2013 17:29, schrieb Jan Kiszka:

Quoted 9 lines

Accesses to unassigned io ports shall return -1 on read and be ignored on write. Ensure these properties via dedicated ops, decoupling us from the memory core's handling of unassigned accesses.

---

Changes in v2:
- avoid breakage in ioport.h for user build

Looks OK, but if you want Anthony to apply this for rc3 then please repost as a full, top-level series.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

It looks like this never happened, so this bug is still present in master :-( [noticed by stsquad since integratorcp is busted too].

I suppose the repost just fell through the cracks at the end of the release cycle. Let me re-repost the whole thing, CC'ing stable.

I vaguely remember you reposting 2/2 top-level only and asking Anthony to fix his tool instead, which was quite apparently not helpful. ;)

Well, I wasn't expecting this to happen within the release cycle. But I would still appreciate having to do such thread-breaking updates in the future.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
author
#10 lore raw

PATCH 2/2 Revert "memory: Return -1 again on reads from unsigned regions"

In reply to Jan Kiszka

This reverts commit 9b8c69243585a32d14b9bb9fcd52c37b0b5a1b71.

The commit was wrong: We only return -1 on invalid accesses, not on valid but unbacked ones. This broke various corner cases.

---
 memory.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
memory.c +1 -1
index 886f838..5a10fd0 100644
@@ -872,7 +872,7 @@ static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
     if (current_cpu != NULL) {
         cpu_unassigned_access(current_cpu, addr, false, false, 0, size);
     }
-    return -1ULL;
+    return 0;
 }
 
 static void unassigned_mem_write(void *opaque, hwaddr addr,
Signature · 1 line
1.7.3.4
Tested-by on v1 2/2
#11 lore raw

Re: [Qemu-devel] [PATCH for 1.6 2/2] Revert "memory: Return -1 again on reads from unsigned regions"

Am 09.08.2013 14:01, schrieb Jan Kiszka:

Quoted 6 lines

This reverts commit 9b8c69243585a32d14b9bb9fcd52c37b0b5a1b71.

The commit was wrong: We only return -1 on invalid accesses, not on valid but unbacked ones. This broke various corner cases.

Restores previous PReP behavior.

Thanks,
Andreas