* [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs
@ 2017-12-13 17:52 Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 1/2] exec: Don't reuse unassigned_mem_ops for io_mem_rom Peter Maydell
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Peter Maydell @ 2017-12-13 17:52 UTC (permalink / raw)
To: qemu-devel
Cc: patches, Paolo Bonzini, Aurelien Jarno, Yongbok Kim, Paul Burton
Currently we set up the io_mem_rom special memory region using the
unassigned_mem_ops structure; this is then used when a guest tries to
write to ROM. This is incorrect, because the behaviour of unassigned
memory may be different from that of ROM for writes. In particular,
on some architectures writing to unassigned memory generates a guest
exception, whereas writing to ROM is generally ignored.
This patchset creates a separate readonly_mem_ops for handling the
writes to readonly memory, which just ignores them.
Patch 2 removes a workaround in the MIPS boston board which
is no longer needed once the core memory system is fixed.
Disclaimer: I haven't tested the mips change beyond 'make check'
(I tested the exec patch with a temporary hack to the Arm
virt board), but I believe it to be correct...
thanks
-- PMM
Peter Maydell (2):
exec: Don't reuse unassigned_mem_ops for io_mem_rom
hw/mips/boston: Remove workaround for writes to ROM aborting
exec.c | 34 +++++++++++++++++++++++++++++++++-
hw/mips/boston.c | 14 ++------------
2 files changed, 35 insertions(+), 13 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 1/2] exec: Don't reuse unassigned_mem_ops for io_mem_rom
2017-12-13 17:52 [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Peter Maydell
@ 2017-12-13 17:52 ` Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 2/2] hw/mips/boston: Remove workaround for writes to ROM aborting Peter Maydell
2017-12-14 11:27 ` [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2017-12-13 17:52 UTC (permalink / raw)
To: qemu-devel
Cc: patches, Paolo Bonzini, Aurelien Jarno, Yongbok Kim, Paul Burton
We set up the io_mem_rom special memory region using the
unassigned_mem_ops structure; this is then used when a guest tries to
write to ROM. This is incorrect, because the behaviour of unassigned
memory may be different from that of ROM for writes. In particular,
on some architectures writing to unassigned memory generates a guest
exception, whereas writing to ROM is generally ignored. Use a
special readonly_mem_ops for this purpose instead, so writes to
ROM are ignored for all guest CPUs.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
exec.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/exec.c b/exec.c
index 03238a3..74b8727 100644
--- a/exec.c
+++ b/exec.c
@@ -2720,6 +2720,37 @@ static uint16_t dummy_section(PhysPageMap *map, FlatView *fv, MemoryRegion *mr)
return phys_section_add(map, §ion);
}
+static void readonly_mem_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+ /* Ignore any write to ROM. */
+}
+
+static bool readonly_mem_accepts(void *opaque, hwaddr addr,
+ unsigned size, bool is_write)
+{
+ return is_write;
+}
+
+/* This will only be used for writes, because reads are special cased
+ * to directly access the underlying host ram.
+ */
+static const MemoryRegionOps readonly_mem_ops = {
+ .write = readonly_mem_write,
+ .valid.accepts = readonly_mem_accepts,
+ .endianness = DEVICE_NATIVE_ENDIAN,
+ .valid = {
+ .min_access_size = 1,
+ .max_access_size = 8,
+ .unaligned = false,
+ },
+ .impl = {
+ .min_access_size = 1,
+ .max_access_size = 8,
+ .unaligned = false,
+ },
+};
+
MemoryRegion *iotlb_to_region(CPUState *cpu, hwaddr index, MemTxAttrs attrs)
{
int asidx = cpu_asidx_from_attrs(cpu, attrs);
@@ -2732,7 +2763,8 @@ MemoryRegion *iotlb_to_region(CPUState *cpu, hwaddr index, MemTxAttrs attrs)
static void io_mem_init(void)
{
- memory_region_init_io(&io_mem_rom, NULL, &unassigned_mem_ops, NULL, NULL, UINT64_MAX);
+ memory_region_init_io(&io_mem_rom, NULL, &readonly_mem_ops,
+ NULL, NULL, UINT64_MAX);
memory_region_init_io(&io_mem_unassigned, NULL, &unassigned_mem_ops, NULL,
NULL, UINT64_MAX);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/2] hw/mips/boston: Remove workaround for writes to ROM aborting
2017-12-13 17:52 [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 1/2] exec: Don't reuse unassigned_mem_ops for io_mem_rom Peter Maydell
@ 2017-12-13 17:52 ` Peter Maydell
2017-12-14 11:27 ` [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2017-12-13 17:52 UTC (permalink / raw)
To: qemu-devel
Cc: patches, Paolo Bonzini, Aurelien Jarno, Yongbok Kim, Paul Burton
Now that the memory system correctly handles writes to ROM for
guest CPUs that may generate exceptions for decode errors, we
can remove the workaround from the boston board.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Disclaimer: not tested beyond 'make check'...
---
hw/mips/boston.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 1cb4b6a..fb23161 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -248,16 +248,6 @@ static const MemoryRegionOps boston_platreg_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-static void boston_flash_write(void *opaque, hwaddr addr,
- uint64_t val, unsigned size)
-{
-}
-
-static const MemoryRegionOps boston_flash_ops = {
- .write = boston_flash_write,
- .endianness = DEVICE_NATIVE_ENDIAN,
-};
-
static const TypeInfo boston_device = {
.name = TYPE_MIPS_BOSTON,
.parent = TYPE_SYS_BUS_DEVICE,
@@ -481,8 +471,8 @@ static void boston_mach_init(MachineState *machine)
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(s->cps), 0, 0, 1);
flash = g_new(MemoryRegion, 1);
- memory_region_init_rom_device_nomigrate(flash, NULL, &boston_flash_ops, s,
- "boston.flash", 128 * M_BYTE, &err);
+ memory_region_init_rom_nomigrate(flash, NULL,
+ "boston.flash", 128 * M_BYTE, &err);
memory_region_add_subregion_overlap(sys_mem, 0x18000000, flash, 0);
ddr = g_new(MemoryRegion, 1);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs
2017-12-13 17:52 [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 1/2] exec: Don't reuse unassigned_mem_ops for io_mem_rom Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 2/2] hw/mips/boston: Remove workaround for writes to ROM aborting Peter Maydell
@ 2017-12-14 11:27 ` Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2017-12-14 11:27 UTC (permalink / raw)
To: Peter Maydell, qemu-devel
Cc: patches, Aurelien Jarno, Yongbok Kim, Paul Burton
On 13/12/2017 18:52, Peter Maydell wrote:
> Currently we set up the io_mem_rom special memory region using the
> unassigned_mem_ops structure; this is then used when a guest tries to
> write to ROM. This is incorrect, because the behaviour of unassigned
> memory may be different from that of ROM for writes. In particular,
> on some architectures writing to unassigned memory generates a guest
> exception, whereas writing to ROM is generally ignored.
>
> This patchset creates a separate readonly_mem_ops for handling the
> writes to readonly memory, which just ignores them.
>
> Patch 2 removes a workaround in the MIPS boston board which
> is no longer needed once the core memory system is fixed.
>
> Disclaimer: I haven't tested the mips change beyond 'make check'
> (I tested the exec patch with a temporary hack to the Arm
> virt board), but I believe it to be correct...
>
> thanks
> -- PMM
>
>
> Peter Maydell (2):
> exec: Don't reuse unassigned_mem_ops for io_mem_rom
> hw/mips/boston: Remove workaround for writes to ROM aborting
>
> exec.c | 34 +++++++++++++++++++++++++++++++++-
> hw/mips/boston.c | 14 ++------------
> 2 files changed, 35 insertions(+), 13 deletions(-)
>
Queued for 2.12, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-12-14 11:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13 17:52 [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 1/2] exec: Don't reuse unassigned_mem_ops for io_mem_rom Peter Maydell
2017-12-13 17:52 ` [Qemu-devel] [PATCH 2/2] hw/mips/boston: Remove workaround for writes to ROM aborting Peter Maydell
2017-12-14 11:27 ` [Qemu-devel] [PATCH 0/2] Don't abort on writes to ROMs Paolo Bonzini
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).