SIGSEGV when reading ARM GIC registers through GDB stub
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
QEMU |
Expired
|
Undecided
|
Unassigned |
Bug Description
When trying to access ARM GIC CPU registers through a target GDB connected to QEMU, QEMU crashes with a SIGSEGV.
Reproducible on last master revision (74e1b78 at the time of writing):
$ ./configure --target-
$ make
$ gdb --args ./arm-softmmu/
Connect a gdb on the other side:
$ arm-none-eabi-gdb
(gdb) tar rem :1234
Remote debugging using :1234
0x00000000 in ?? ()
(gdb) x /x 0x2c002000
QEMU crashes as it tries to access current_
Thread 1 "qemu-system-arm" received signal SIGSEGV, Segmentation fault.
0x0000555555a372cf in gic_get_current_cpu (s=0x555556a34f10) at hw/intc/
53 return current_
(gdb) p current_cpu
$1 = (CPUState *) 0x0
Backtrace:
(gdb) bt
#0 0x0000555555a372cf in gic_get_current_cpu (s=0x555556a34f10) at hw/intc/
#1 0x0000555555a3b0e3 in gic_thiscpu_read (opaque=
#2 0x00005555557ae2bb in memory_
#3 0x00005555557ae7ac in access_
at /home/sekoia/
#4 0x00005555557b0de7 in memory_
#5 0x00005555557b0e9d in memory_
#6 0x000055555576775b in address_
#7 0x0000555555767929 in address_
#8 0x00005555557679eb in address_space_read (len=4, buf=0x7fffffffb440 "", attrs=..., addr=738205696, as=0x5555569c70b0) at /home/sekoia/
#9 address_space_rw (as=0x5555569c70b0, addr=738205696, attrs=..., buf=0x7fffffffb440 "", len=4, is_write=false) at /home/sekoia/
#10 0x000055555576988f in cpu_memory_rw_debug (cpu=0x5555568a
#11 0x00005555557a3db3 in target_
#12 0x00005555557a53f5 in gdb_handle_packet (s=0x55555722c530, line_buf=
#13 0x00005555557a6b84 in gdb_read_byte (s=0x55555722c530, ch=52) at /home/sekoia/
#14 0x00005555557a6ca4 in gdb_chr_receive (opaque=0x0, buf=0x7fffffffc590 "$m2c002000,
at /home/sekoia/
#15 0x000055555591c562 in qemu_chr_
len=15) at qemu-char.c:387
#16 0x000055555591c5c0 in qemu_chr_be_write (s=0x555557226e20, buf=0x7fffffffc590 "$m2c002000,
at qemu-char.c:399
#17 0x00005555559207f3 in tcp_chr_read (chan=0x555556e
#18 0x0000555555c4a9b7 in qio_channel_
#19 0x00007fffed977c8a in g_main_
#20 0x0000555555bbf711 in glib_pollfds_poll () at main-loop.c:213
#21 0x0000555555bbf7ec in os_host_
#22 0x0000555555bbf899 in main_loop_wait (nonblocking=0) at main-loop.c:506
#23 0x0000555555929cd2 in main_loop () at vl.c:1908
#24 0x00005555559315b7 in main (argc=8, argv=0x7fffffff
Note that this bug is triggered only when the number of simulated CPUs is greater than 1.
This happens because although the gdbstub tells the memory system which CPU it wants to perform the access as, this gets lost in cpu_memory_ rw_debug( ), which doesn't set current_cpu. I'm not sure if we could get away with just doing that at that point: I wouldn't be surprised if that would break other things.
Ideally we'd have a better mechanism for devices which care about which CPU was doing the access to work than looking at current_cpu.