hw/misc/bcm2835_thermal: Fix access size handling in bcm2835_thermal_ops
Subsystems (2)
PATCH v2 1/1 hw/misc/bcm2835_thermal: Fix access size handling in bcm2835_thermal_ops
The current implementation of bcm2835_thermal_ops sets impl.max_access_size and valid.min_access_size to 4, but leaves impl.min_access_size and valid.max_access_size unset, defaulting to 1. This causes issues when the memory system is presented with an access of size 2 at an offset of 3, leading to an attempt to synthesize it as a pair of byte accesses at offsets 3 and 4, which trips an assert.
Additionally, the lack of valid.max_access_size setting causes another
issue: the memory system tries to synthesize a read using a 4-byte access at offset 3 even though the device doesn't allow unaligned accesses.
This patch addresses these issues by explicitly setting both impl.min_access_size and valid.max_access_size to 4, ensuring proper handling of access sizes.
Error log:
ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached Bail out! ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached Aborted
Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine raspi3b -m 1G -qtest stdio readw 0x3f212003
EOF
---
Changes in v2:
- Added .valid.min_access_size and .valid.max_access_size settings to ensure proper handling of valid access sizes.
--- hw/misc/bcm2835_thermal.c | 2 ++ 1 file changed, 2 insertions(+)
hw/misc/bcm2835_thermal.c +2 -0
@@ -80,8 +80,10 @@ static void bcm2835_thermal_write(void *opaque, hwaddr addr,static const MemoryRegionOps bcm2835_thermal_ops = { .read = bcm2835_thermal_read, .write = bcm2835_thermal_write, + .impl.min_access_size =4 , .impl.max_access_size =4 , .valid.min_access_size =4 , + .valid.max_access_size =4 , .endianness =DEVICE_NATIVE_ENDIAN , };
Signature · 1 line
2.34.1
Quoted 21 lines · Zheyu Ma
The current implementation of
bcm2835_thermal_opssets impl.max_access_size and valid.min_access_size to 4, but leaves impl.min_access_size and valid.max_access_size unset, defaulting to 1. This causes issues when the memory system is presented with an access of size 2 at an offset of 3, leading to an attempt to synthesize it as a pair of byte accesses at offsets 3 and 4, which trips an assert.Additionally, the lack of valid.max_access_size setting causes another
issue: the memory system tries to synthesize a read using a 4-byte access at offset 3 even though the device doesn't allow unaligned accesses.This patch addresses these issues by explicitly setting both impl.min_access_size and valid.max_access_size to 4, ensuring proper handling of access sizes.
Error log:
ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached Bail out! ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached Aborted
Quoted 6 lines
Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine raspi3b -m 1G -qtest stdio readw0x3f212003
EOF
Quoted 14 lines
Signed-off-by Zheyu Ma <[email protected]>---
Changes in v2:
- Added .valid.min_access_size and .valid.max_access_size settings to ensure proper handling of valid access sizes.--- hw/misc/bcm2835_thermal.c | 2 ++ 1 file changed, 2 insertions(+)hw/misc/bcm2835_thermal.c +0
-0
hw/misc/bcm2835_thermal.c static void bcm2835_thermal_write(void *opaque, hwaddr addr, · line 83
Quoted 4 lines
hw/misc/bcm2835_thermal.c +1
-0@@ -80,8 +80,10 @@ static void bcm2835_thermal_write(void *opaque, hwaddr addr,static const MemoryRegionOps bcm2835_thermal_ops = { .read = bcm2835_thermal_read, .write = bcm2835_thermal_write, + .impl.min_access_size =4 ,
Personally I consider accepting access of
.valid.min_access_size > .impl.min_access_size
as a bug in the memory core layer, whether being
unaligned or not.
Quoted 6 lines
hw/misc/bcm2835_thermal.c +1
-0.impl.max_access_size = 4, .valid.min_access_size = 4, + .valid.max_access_size = 4, .endianness = DEVICE_NATIVE_ENDIAN, };
Quoted 6 lines · Philippe Mathieu-Daudé
Personally I consider accepting access of
.valid.min_access_size > .impl.min_access_size
as a bug in the memory core layer, whether being
unaligned or not.
Mmm. You could make an argument for
.valid: min_access_size = 4, unaligned = true .impl.min_access_size = 1, unaligned = false
meaning "accesses must be 32 bits, and if the guest makes an unaligned 32 bit access then you can synthesize it with 4 byte reads/writes", I guess. But whether we (a) get that right (b) use it anywhere
(c) use it anywhere intentionally is not something I'd be very confident in asserting :-)
I definitely think that our "synthesize accesses where valid and impl mismatch" code could use a going-over, so we either get it right or assert if the MemoryRegionOps ask for something we don't handle. Maybe someday...
thanks
-- PMM
Peter Maydell
AppliedQuoted 22 lines · Zheyu Ma
The current implementation of
bcm2835_thermal_opssets impl.max_access_size and valid.min_access_size to 4, but leaves impl.min_access_size and valid.max_access_size unset, defaulting to 1. This causes issues when the memory system is presented with an access of size 2 at an offset of 3, leading to an attempt to synthesize it as a pair of byte accesses at offsets 3 and 4, which trips an assert.Additionally, the lack of valid.max_access_size setting causes another
issue: the memory system tries to synthesize a read using a 4-byte access at offset 3 even though the device doesn't allow unaligned accesses.This patch addresses these issues by explicitly setting both impl.min_access_size and valid.max_access_size to 4, ensuring proper handling of access sizes.
Error log:
ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached Bail out! ERROR:hw/misc/bcm2835_thermal.c:55:bcm2835_thermal_read: code should not be reached Aborted
Quoted 8 lines
Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine raspi3b -m 1G -qtest stdio readw0x3f212003
EOFSigned-off-by Zheyu Ma <[email protected]>---
Applied to target-arm.next, thanks.
-- PMM