hw/timer/a9gtimer: Handle QTest mode in a9_gtimer_get_current_cpu
PATCH 1/1 hw/timer/a9gtimer: Handle QTest mode in a9_gtimer_get_current_cpu
This commit updates the a9_gtimer_get_current_cpu() function to handle cases where QTest is enabled. When QTest is used, it returns 0 instead of dereferencing the current_cpu, which can be NULL. This prevents the program from crashing during QTest runs.
Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine npcm750-evb -qtest stdio writel 0xf03fe20c 0x26d7468c
EOF
--- hw/timer/a9gtimer.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/timer/a9gtimer.c +5 -0
@@ -32,6 +32,7 @@#include "qemu/log.h" #include "qemu/module.h" #include "hw/core/cpu.h" +#include "sysemu/qtest.h" #ifndef A9_GTIMER_ERR_DEBUG #define A9_GTIMER_ERR_DEBUG 0
@@ -48,6 +49,10 @@static inline int a9_gtimer_get_current_cpu (A9GTimerState *s) { +if (qtest_enabled ()) { +return 0 ; + } +if (current_cpu->cpu_index >= s->num_cpu) {hw_error ("a9gtimer: num-cpu %d but this cpu is %d!\n" , s->num_cpu, current_cpu->cpu_index);
Signature · 1 line
2.34.1
Quoted 29 lines · Zheyu Ma
This commit updates the
a9_gtimer_get_current_cpu()function to handle cases where QTest is enabled. When QTest is used, it returns 0 instead of dereferencing thecurrent_cpu, which can be NULL. This prevents the program from crashing during QTest runs.Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine npcm750-evb -qtest stdio writel0xf03fe20c0x26d7468c
EOFSigned-off-by Zheyu Ma <[email protected]>--- hw/timer/a9gtimer.c | 5 +++++ 1 file changed, 5 insertions(+)hw/timer/a9gtimer.c +1
-0@@ -32,6 +32,7 @@#include "qemu/log.h" #include "qemu/module.h" #include "hw/core/cpu.h" +#include "sysemu/qtest.h" #ifndef A9_GTIMER_ERR_DEBUG #define A9_GTIMER_ERR_DEBUG 0
hw/timer/a9gtimer.c line 53
Quoted 5 lines
hw/timer/a9gtimer.c +2
-0@@ -48,6 +49,10 @@static inline int a9_gtimer_get_current_cpu (A9GTimerState *s) { +if (qtest_enabled ()) { +return 0 ;
Indeed this is how we fixed hw/intc/arm_gic in commit 09bbdb89bc, so:
hw/timer/a9gtimer.c line 56
Quoted 3 lines
hw/timer/a9gtimer.c +2
-0+ } +if (current_cpu->cpu_index >= s->num_cpu) {
That said, such accesses of @current_cpu from hw/ are dubious.
Quoted 2 lines
hw/timer/a9gtimer.c +0
-0hw_error ("a9gtimer: num-cpu %d but this cpu is %d!\n" , s->num_cpu, current_cpu->cpu_index);
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 29 lines · Zheyu Ma
This commit updates the
a9_gtimer_get_current_cpu()function to handle cases where QTest is enabled. When QTest is used, it returns 0 instead of dereferencing thecurrent_cpu, which can be NULL. This prevents the program from crashing during QTest runs.Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine npcm750-evb -qtest stdio writel0xf03fe20c0x26d7468c
EOFSigned-off-by Zheyu Ma <[email protected]>--- hw/timer/a9gtimer.c | 5 +++++ 1 file changed, 5 insertions(+)hw/timer/a9gtimer.c +1
-0@@ -32,6 +32,7 @@#include "qemu/log.h" #include "qemu/module.h" #include "hw/core/cpu.h" +#include "sysemu/qtest.h" #ifndef A9_GTIMER_ERR_DEBUG #define A9_GTIMER_ERR_DEBUG 0hw/timer/a9gtimer.c line 53
Quoted 5 lines
hw/timer/a9gtimer.c +2
-0@@ -48,6 +49,10 @@static inline int a9_gtimer_get_current_cpu (A9GTimerState *s) { +if (qtest_enabled ()) { +return 0 ;Indeed this is how we fixed hw/intc/arm_gic in commit
09bbdb89bc, so:
Quoted 7 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>hw/timer/a9gtimer.c line 56
Quoted 3 lines
hw/timer/a9gtimer.c +2
-0+ } +if (current_cpu->cpu_index >= s->num_cpu) {That said, such accesses of @current_cpu from hw/ are dubious.
True, but I'm not sure we ever settled on the right way to avoid them, did we?
Anyway, I've applied this patch to target-arm.next.
-- PMM
Quoted 20 lines · Peter Maydell
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Zheyu Ma
This commit updates the
a9_gtimer_get_current_cpu()function to handle cases where QTest is enabled. When QTest is used, it returns 0 instead of dereferencing thecurrent_cpu, which can be NULL. This prevents the program from crashing during QTest runs.Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine npcm750-evb -qtest stdio writel0xf03fe20c0x26d7468c
EOFSigned-off-by Zheyu Ma <[email protected]>--- hw/timer/a9gtimer.c | 5 +++++ 1 file changed, 5 insertions(+)
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
if (current_cpu->cpu_index >= s->num_cpu) {That said, such accesses of @current_cpu from hw/ are dubious.
True, but I'm not sure we ever settled on the right way to avoid them, did we?
No we didn't, it is still in my TODO list; we might discuss it when I post my RFC.
Regards,
Phil.
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · Peter Maydell
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Zheyu Ma
This commit updates the
a9_gtimer_get_current_cpu()function to handle cases where QTest is enabled. When QTest is used, it returns 0 instead of dereferencing thecurrent_cpu, which can be NULL. This prevents the program from crashing during QTest runs.Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine npcm750-evb -qtest stdio writel0xf03fe20c0x26d7468c
EOFSigned-off-by Zheyu Ma <[email protected]>--- hw/timer/a9gtimer.c | 5 +++++ 1 file changed, 5 insertions(+)if (current_cpu->cpu_index >= s->num_cpu) {
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
That said, such accesses of @current_cpu from hw/ are dubious.
True, but I'm not sure we ever settled on the right way to avoid them, did we?
No we didn't, it is still in my TODO list; we might discuss it when I post my RFC.
Yeah, this way of getting the core id is a problem when having multiple ARM CPU subsystems (and for heterogenous cores).
IIRC, when I looked at what the GIC v2 HW does, the GIC exposes an AMBA port for each CPU. In my mental model that would translate to exposing multiple Memory Reginos (sysbus_init_mmio) and mapping the appropriate device MR to each CPU AddressSpace.
We could also do it with memory attributes but I don't think the master Ids are standardised enough to extract a core-index from with out having SoC specific code,, at least not accross Xilinx devices.
I never looked at newer GIC versions nor the mmio mapped timers though...
Cheers,
Edgar
Quoted 34 lines · Edgar E. Iglesias
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · Peter Maydell
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Zheyu Ma
This commit updates the
a9_gtimer_get_current_cpu()function to handle cases where QTest is enabled. When QTest is used, it returns 0 instead of dereferencing thecurrent_cpu, which can be NULL. This prevents the program from crashing during QTest runs.Reproducer:
cat << EOF | qemu-system-aarch64 -display \
none -machine accel=qtest, -m 512M -machine npcm750-evb -qtest stdio writel0xf03fe20c0x26d7468c
EOFSigned-off-by Zheyu Ma <[email protected]>--- hw/timer/a9gtimer.c | 5 +++++ 1 file changed, 5 insertions(+)if (current_cpu->cpu_index >= s->num_cpu) {Quoted 8 lines
Quoted 4 lines
Quoted 1 line
That said, such accesses of @current_cpu from hw/ are dubious.
True, but I'm not sure we ever settled on the right way to avoid them, did we?
No we didn't, it is still in my TODO list; we might discuss it when I post my RFC.
Quoted 7 lines
Yeah, this way of getting the core id is a problem when having multiple ARM CPU subsystems (and for heterogenous cores).
IIRC, when I looked at what the GIC v2 HW does, the GIC exposes an AMBA port for each CPU. In my mental model that would translate to exposing multiple Memory Reginos (
sysbus_init_mmio) and mapping the appropriate device MR to each CPU AddressSpace.
Yeah. The trouble is that doing this requires massively rearranging how all the GICv2 board models connect up address spaces...
Quoted 3 lines
We could also do it with memory attributes but I don't think the master Ids are standardised enough to extract a core-index from with out having SoC specific code,, at least not accross Xilinx devices.
...and yes, using the requester ID to specify the CPU in the MemTxAttrs is the other proposal.
thanks
-- PMM