From: Paul Mackerras <hidden> Date: 2025-05-10 01:36:06
Running Linux on Microwatt with a kernel compiled on an x86-64 system
running Fedora 42 (using the packaged cross-compiler, i.e. the
gcc-powerpcle64-linux-gnu package), I'm seeing a crash like this:
[ 0.141591] smp: Bringing up secondary CPUs ...
[ 0.167628] BUG: Unable to handle kernel data access on write at 0xc00a0000be8d6004
[ 0.175409] Faulting instruction address: 0xc00000000000fcb4
cpu 0x0: Vector: 300 (Data Access) at [c0000000012f78d0]
pc: c00000000000fcb4: __do_IRQ+0x64/0x84
lr: c00000000000fccc: __do_IRQ+0x7c/0x84
sp: c0000000012f7b70
msr: 9000000000001033
dar: c00a0000be8d6004
dsisr: 42000000
current = 0xc0000000012de000
paca = 0xc00000000135d000 irqmask: 0x03 irq_happened: 0x01
pid = 0, comm = swapper/0
Linux version 6.15.0-rc1-00001-g72b73737d483-dirty (paulus@thinks) (powerpc64le-linux-gnu-gcc (GCC) 15.0.1 20250329 (Red Hat Cross 15.0.1-0), GNU ld version 2.44-1.fc42) #5 SMP Thu May 8 22:20:34 AEST 2025
enter ? for help
[c0000000012f7b70] c00000000000fd50 do_IRQ+0x7c/0x90 (unreliable)
[c0000000012f7ba0] c000000000007db4 hardware_interrupt_common_virt+0x1c4/0x1d0
--- Exception: 500 (Hardware Interrupt) at c00000000001c2ec arch_local_irq_restore+0x60/0xc4
[c0000000012f7ea0] c000000000083c68 do_idle+0xd4/0xf4
[c0000000012f7ee0] c000000000083e08 cpu_startup_entry+0x34/0x38
[c0000000012f7f10] c00000000000cc7c kernel_init+0x0/0x144
[c0000000012f7f40] c000000001000ecc do_one_initcall+0x0/0x160
[c0000000012f7fe0] c00000000000ba6c start_here_common+0x1c/0x20
0:mon>
What's happening is that gcc 15 seems to be using r2 as an ordinary
register, and r2 has a live value in it at the point where __do_IRQ()
calls call_do_irq(). Since r2 is not in the clobber list for the
inline asm in call_do_irq(), it doesn't get saved and restored around
the call to __do_irq(), and when we come back to __do_IRQ(), it has
been modified. Then when __do_IRQ() subsequently does a store using
r2, it blows up like the above.
Adding r2 to the clobber list in call_do_irq() fixes it. Does this
seem like the right fix? Does it need to be conditional on the gcc
version? Or is there a better way to fix the problem?
Thanks,
Paul.
Running Linux on Microwatt with a kernel compiled on an x86-64 system
running Fedora 42 (using the packaged cross-compiler, i.e. the
gcc-powerpcle64-linux-gnu package), I'm seeing a crash like this:
[ 0.141591] smp: Bringing up secondary CPUs ...
[ 0.167628] BUG: Unable to handle kernel data access on write at 0xc00a0000be8d6004
[ 0.175409] Faulting instruction address: 0xc00000000000fcb4
cpu 0x0: Vector: 300 (Data Access) at [c0000000012f78d0]
pc: c00000000000fcb4: __do_IRQ+0x64/0x84
lr: c00000000000fccc: __do_IRQ+0x7c/0x84
sp: c0000000012f7b70
msr: 9000000000001033
dar: c00a0000be8d6004
dsisr: 42000000
current = 0xc0000000012de000
paca = 0xc00000000135d000 irqmask: 0x03 irq_happened: 0x01
pid = 0, comm = swapper/0
Linux version 6.15.0-rc1-00001-g72b73737d483-dirty (paulus@thinks) (powerpc64le-linux-gnu-gcc (GCC) 15.0.1 20250329 (Red Hat Cross 15.0.1-0), GNU ld version 2.44-1.fc42) #5 SMP Thu May 8 22:20:34 AEST 2025
enter ? for help
[c0000000012f7b70] c00000000000fd50 do_IRQ+0x7c/0x90 (unreliable)
[c0000000012f7ba0] c000000000007db4 hardware_interrupt_common_virt+0x1c4/0x1d0
--- Exception: 500 (Hardware Interrupt) at c00000000001c2ec arch_local_irq_restore+0x60/0xc4
What's happening is that gcc 15 seems to be using r2 as an ordinary
register, and r2 has a live value in it at the point where __do_IRQ()
calls call_do_irq(). Since r2 is not in the clobber list for the
inline asm in call_do_irq(), it doesn't get saved and restored around
the call to __do_irq(), and when we come back to __do_IRQ(), it has
been modified. Then when __do_IRQ() subsequently does a store using
r2, it blows up like the above.
Adding r2 to the clobber list in call_do_irq() fixes it. Does this
seem like the right fix? Does it need to be conditional on the gcc
version? Or is there a better way to fix the problem?
I guess if we plan to go with adding r2 to clobber, it has to be gcc
specific, since my FC41 (gcc 14.1) complains of PIC registers usage
in the clobber list.
inlined from ‘__do_IRQ’ at arch/powerpc/kernel/irq.c:297:3:
arch/powerpc/kernel/irq.c:262:9: error: PIC register clobbered by ‘r2’ in ‘asm’
262 | asm volatile (
| ^~~
Can you try with this patch, I am testing this in my setup.
Maddy
From: Michael Ellerman <mpe@ellerman.id.au> Date: 2025-05-12 03:31:44
Paul Mackerras [off-list ref] writes:
quoted hunk
Running Linux on Microwatt with a kernel compiled on an x86-64 system
running Fedora 42 (using the packaged cross-compiler, i.e. the
gcc-powerpcle64-linux-gnu package), I'm seeing a crash like this:
[ 0.141591] smp: Bringing up secondary CPUs ...
[ 0.167628] BUG: Unable to handle kernel data access on write at 0xc00a0000be8d6004
[ 0.175409] Faulting instruction address: 0xc00000000000fcb4
cpu 0x0: Vector: 300 (Data Access) at [c0000000012f78d0]
pc: c00000000000fcb4: __do_IRQ+0x64/0x84
lr: c00000000000fccc: __do_IRQ+0x7c/0x84
sp: c0000000012f7b70
msr: 9000000000001033
dar: c00a0000be8d6004
dsisr: 42000000
current = 0xc0000000012de000
paca = 0xc00000000135d000 irqmask: 0x03 irq_happened: 0x01
pid = 0, comm = swapper/0
Linux version 6.15.0-rc1-00001-g72b73737d483-dirty (paulus@thinks) (powerpc64le-linux-gnu-gcc (GCC) 15.0.1 20250329 (Red Hat Cross 15.0.1-0), GNU ld version 2.44-1.fc42) #5 SMP Thu May 8 22:20:34 AEST 2025
enter ? for help
[c0000000012f7b70] c00000000000fd50 do_IRQ+0x7c/0x90 (unreliable)
[c0000000012f7ba0] c000000000007db4 hardware_interrupt_common_virt+0x1c4/0x1d0
--- Exception: 500 (Hardware Interrupt) at c00000000001c2ec arch_local_irq_restore+0x60/0xc4
[c0000000012f7ea0] c000000000083c68 do_idle+0xd4/0xf4
[c0000000012f7ee0] c000000000083e08 cpu_startup_entry+0x34/0x38
[c0000000012f7f10] c00000000000cc7c kernel_init+0x0/0x144
[c0000000012f7f40] c000000001000ecc do_one_initcall+0x0/0x160
[c0000000012f7fe0] c00000000000ba6c start_here_common+0x1c/0x20
0:mon>
What's happening is that gcc 15 seems to be using r2 as an ordinary
register, and r2 has a live value in it at the point where __do_IRQ()
calls call_do_irq(). Since r2 is not in the clobber list for the
inline asm in call_do_irq(), it doesn't get saved and restored around
the call to __do_irq(), and when we come back to __do_IRQ(), it has
been modified. Then when __do_IRQ() subsequently does a store using
r2, it blows up like the above.
Are you building with pcrel? Otherwise r2 shouldn't be getting used as
an ordinary register.
Can you show the disassembly of where it's getting used?
There was a change to r2 handling in GCC 15, but AFAICS it was meant to
only affect pcrel code.
Still it's likely our bug because we are being weird and calling a
function inside an inline asm block.
cheers
Running Linux on Microwatt with a kernel compiled on an x86-64 system
running Fedora 42 (using the packaged cross-compiler, i.e. the
gcc-powerpcle64-linux-gnu package), I'm seeing a crash like this:
[ 0.141591] smp: Bringing up secondary CPUs ...
[ 0.167628] BUG: Unable to handle kernel data access on write at 0xc00a0000be8d6004
[ 0.175409] Faulting instruction address: 0xc00000000000fcb4
cpu 0x0: Vector: 300 (Data Access) at [c0000000012f78d0]
pc: c00000000000fcb4: __do_IRQ+0x64/0x84
lr: c00000000000fccc: __do_IRQ+0x7c/0x84
sp: c0000000012f7b70
msr: 9000000000001033
dar: c00a0000be8d6004
dsisr: 42000000
current = 0xc0000000012de000
paca = 0xc00000000135d000 irqmask: 0x03 irq_happened: 0x01
pid = 0, comm = swapper/0
Linux version 6.15.0-rc1-00001-g72b73737d483-dirty (paulus@thinks) (powerpc64le-linux-gnu-gcc (GCC) 15.0.1 20250329 (Red Hat Cross 15.0.1-0), GNU ld version 2.44-1.fc42) #5 SMP Thu May 8 22:20:34 AEST 2025
enter ? for help
[c0000000012f7b70] c00000000000fd50 do_IRQ+0x7c/0x90 (unreliable)
[c0000000012f7ba0] c000000000007db4 hardware_interrupt_common_virt+0x1c4/0x1d0
--- Exception: 500 (Hardware Interrupt) at c00000000001c2ec arch_local_irq_restore+0x60/0xc4
[c0000000012f7ea0] c000000000083c68 do_idle+0xd4/0xf4
[c0000000012f7ee0] c000000000083e08 cpu_startup_entry+0x34/0x38
[c0000000012f7f10] c00000000000cc7c kernel_init+0x0/0x144
[c0000000012f7f40] c000000001000ecc do_one_initcall+0x0/0x160
[c0000000012f7fe0] c00000000000ba6c start_here_common+0x1c/0x20
0:mon>
What's happening is that gcc 15 seems to be using r2 as an ordinary
register, and r2 has a live value in it at the point where __do_IRQ()
calls call_do_irq(). Since r2 is not in the clobber list for the
inline asm in call_do_irq(), it doesn't get saved and restored around
the call to __do_irq(), and when we come back to __do_IRQ(), it has
been modified. Then when __do_IRQ() subsequently does a store using
r2, it blows up like the above.
Adding r2 to the clobber list in call_do_irq() fixes it. Does this
seem like the right fix? Does it need to be conditional on the gcc
version? Or is there a better way to fix the problem?
Thanks,
Paul.
I have to create a new build environment for gcc-15 after I lost
access to the machine I used for the earlier builds. I should
be able to do that within a few weeks, but unfortunately it's
a little more work than just rerunning my scripts (which I still
have).
Arnd
There was a change to r2 handling in GCC 15, but AFAICS it was meant to
only affect pcrel code.
Still it's likely our bug because we are being weird and calling a
function inside an inline asm block.
Hi!
On Mon, May 12, 2025 at 01:31:34PM +1000, Michael Ellerman wrote:
Paul Mackerras [off-list ref] writes:
Are you building with pcrel? Otherwise r2 shouldn't be getting used as
an ordinary register.
With any ELFv2 in fact, which is implied by the target triple. PCrel
has nothing to do with it (well, indirectly, functions that use PCrel
less often need a TOC register after all).
GPR2 usually *is* a normal volatile register in ELFv2. (You detect
ELFv2 by checking if _CALL_ELF is 2). If you want to treat it
differently (just like on other ABIs) you'll need to arrange for that,
maybe using some inline asm or such? Ideally this will work everywhere
of course, and you do no longer depend on it accidentally working
elsewhere :-)
Segher
That works as long as I have CONFIG_PPC_KERNEL_PCREL enabled, but with
it disabled, it fails to compile. With PCREL disabled, the kernel
runs just fine without the r2 clobber. I guess it needs to be:
#if __GNUC__ >= 15 && IS_ENABLED(CONFIG_PPC_KERNEL_PCREL)
or something like that.
Thanks,
Paul.
I have to create a new build environment for gcc-15 after I lost
access to the machine I used for the earlier builds. I should
be able to do that within a few weeks, but unfortunately it's
a little more work than just rerunning my scripts (which I still
have).
I've uploaded gcc-15.1 binaries now. I've only tested the arm64,
as usual, so please let me know if the powerpc and x86 hosted
ones cause any problems.
Arnd
That works as long as I have CONFIG_PPC_KERNEL_PCREL enabled, but with
it disabled, it fails to compile. With PCREL disabled, the kernel
runs just fine without the r2 clobber. I guess it needs to be:
#if __GNUC__ >= 15 && IS_ENABLED(CONFIG_PPC_KERNEL_PCREL)
or something like that.
I have now done some tests with both gcc 14 and gcc 15 and they behave
the same, so at the end I think all we need is:
#ifdef CONFIG_PPC_KERNEL_PCREL
without any mention to GCC version.
I have to create a new build environment for gcc-15 after I lost
access to the machine I used for the earlier builds. I should
be able to do that within a few weeks, but unfortunately it's
a little more work than just rerunning my scripts (which I still
have).
I've uploaded gcc-15.1 binaries now. I've only tested the arm64,
as usual, so please let me know if the powerpc and x86 hosted
ones cause any problems.