MIPS: CPS: Fix r1 .set mt assembler warning
Subsystems (2)
Hi James,
Quoted 5 lines · James Hogan
From
17278a91e04f858155d54bee5528ba4fbcec6f87Mon Sep 17 00:00:00 2001
From: James Hogan <[email protected]>
Date: Tue, 14 Nov 2017 12:01:20 +0000
Subject: [PATCH] MIPS: CPS: Fix r1 .set mt assembler warning
Quoted 7 lines
MIPS CPS has a build warning on kernels configured for MIPS32R1 or MIPS64R1, due to the use of .set mt without a prior .set mips{32,64}r2:
arch/mips/kernel/cps-vec.SAssembler messages:arch/mips/kernel/cps-vec.S:238: Warning: the `mt' extension requires MIPS32 revision 2 or greaterAdd .set
MIPS_ISA_LEVEL_RAWbefore .set mt to silence the warning.
This change breaks booting for me on a MediaTek MT7621 platform:
...
Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)^M
pid_max: default: 32768 minimum: 301^M
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)^M Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)^M Hierarchical SRCU implementation.^M
smp: Bringing up secondary CPUs ...^M
Reserved instruction in kernel code[#1]:^M
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.15.0-ac0 #3^M $ 0 : 00000000 00000001 00000000 00000000^M $ 4 : 8501dd80 00000001 00000004 00000000^M $ 8 : 00000004 00000002 00000001 ffffffff^M $12 : 00000000 00000400 00000003 8501de00^M $16 : 807d5ca0 8501dd80 00000000 00000001^M $20 : 80842814 00000000 00000001 000000e0^M $24 : fffffffc 00000001 ^M $28 : 85026000 85027de0 00000020 80013538^M Hi : 00000006^M Lo : 8e778000^M epc : 80656620 mips_cps_boot_vpes+0x4c/0x160^M ra : 80013538 cps_boot_secondary+0x280/0x440^M Status: 11000403 KERNEL EXL IE ^M Cause : 50800028 (ExcCode 0a)^M PrId : 0001992f (MIPS 1004Kc)^M
If I revert the patch then I can boot up again, all works as expected.
I am not exactly using a pure mainline 4.15 source base though. (I have a bunch of additional changes to make this platform actually work).
But this patch certainly does trap as above when present. I am using a gcc-5.4.0/binutils-2.25.1 toolchain.
Any thoughts?
Regards
Greg
Quoted 35 lines
Fixes 245a7868d2f2 ("MIPS: smp-cps: rework core/VPE initialisation")Signed-off-by James Hogan <[email protected]>Cc Paul Burton <[email protected]>Cc James Hogan <[email protected]>Cc James Hogan <[email protected]>Cc Paul Burton <[email protected]>Patchwork: https://patchwork.linux-mips.org/patch/17699/
Signed-off-by Ralf Baechle <[email protected]>--- arch/mips/kernel/cps-vec.S | 2 ++ 1 file changed, 2 insertions(+)arch/mips/kernel/cps-vec.S +2
-0@@ -235,6 +235,7 @@ LEAF(mips_cps_core_init) has_mt t0, 3f .set push + .set MIPS_ISA_LEVEL_RAW .set mt /* Only allow 1 TC per VPE to execute... */@@ -388,6 +389,7 @@ LEAF(mips_cps_boot_vpes) #elif defined(CONFIG_MIPS_MT) .set push + .set MIPS_ISA_LEVEL_RAW .set mt /* If the core doesn't support MT then return */Signature · 1 line
1.9.1
Hi Greg,
Quoted 45 lines · Greg Ungerer
Hi James,
Quoted 5 lines · James Hogan
From
17278a91e04f858155d54bee5528ba4fbcec6f87Mon Sep 17 00:00:00 2001
From: James Hogan <[email protected]>
Date: Tue, 14 Nov 2017 12:01:20 +0000
Subject: [PATCH] MIPS: CPS: Fix r1 .set mt assembler warningQuoted 7 lines
MIPS CPS has a build warning on kernels configured for MIPS32R1 or MIPS64R1, due to the use of .set mt without a prior .set mips{32,64}r2:
arch/mips/kernel/cps-vec.SAssembler messages:arch/mips/kernel/cps-vec.S:238: Warning: the `mt' extension requires MIPS32 revision 2 or greaterAdd .set
MIPS_ISA_LEVEL_RAWbefore .set mt to silence the warning.This change breaks booting for me on a MediaTek MT7621 platform:
...
Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)^M
pid_max: default: 32768 minimum: 301^M
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)^M Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)^M Hierarchical SRCU implementation.^M
smp: Bringing up secondary CPUs ...^M
Reserved instruction in kernel code[#1]:^MCPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.15.0-ac0 #3^M $ 0 : 00000000 00000001 00000000 00000000^M $ 4 : 8501dd80 00000001 00000004 00000000^M $ 8 : 00000004 00000002 00000001 ffffffff^M $12 : 00000000 00000400 00000003 8501de00^M $16 : 807d5ca0 8501dd80 00000000 00000001^M $20 : 80842814 00000000 00000001 000000e0^M $24 : fffffffc 00000001 ^M $28 : 85026000 85027de0 00000020 80013538^M Hi : 00000006^M Lo : 8e778000^M epc : 80656620 mips_cps_boot_vpes+0x4c/0x160^M ra : 80013538 cps_boot_secondary+0x280/0x440^M Status: 11000403 KERNEL EXL IE ^M Cause : 50800028 (ExcCode 0a)^M PrId : 0001992f (MIPS 1004Kc)^MIf I revert the patch then I can boot up again, all works as expected.
Quoted 7 lines
I am not exactly using a pure mainline 4.15 source base though. (I have a bunch of additional changes to make this platform actually work).
But this patch certainly does trap as above when present. I am using a gcc-5.4.0/binutils-2.25.1 toolchain.
Any thoughts?
Hmm, sorry about that.
If there is some more of the log which shows code around the EPC (usually a few lines below where you stopped), that would be helpful to see exactly whats happening. Perhaps it has used a 64-bit instruction.
When I build 32r2el_defconfig, that EPC (relative to mips_cps_boot_vpes) is a move instruction, which is implemented with OR (which should be safe on MIPS32 and MIPS64), both with binutils 2.28ish and 2.24ish (MTI / IMG toolchains, so they may have additional patches).
I'll try limiting the .set mt to code that needs it.
Thanks
James
Quoted 41 lines
Regards
GregQuoted 35 lines
Fixes 245a7868d2f2 ("MIPS: smp-cps: rework core/VPE initialisation")Signed-off-by James Hogan <[email protected]>Cc Paul Burton <[email protected]>Cc James Hogan <[email protected]>Cc James Hogan <[email protected]>Cc Paul Burton <[email protected]>Patchwork: https://patchwork.linux-mips.org/patch/17699/
Signed-off-by Ralf Baechle <[email protected]>--- arch/mips/kernel/cps-vec.S | 2 ++ 1 file changed, 2 insertions(+)arch/mips/kernel/cps-vec.S +2
-0@@ -235,6 +235,7 @@ LEAF(mips_cps_core_init) has_mt t0, 3f .set push + .set MIPS_ISA_LEVEL_RAW .set mt /* Only allow 1 TC per VPE to execute... */@@ -388,6 +389,7 @@ LEAF(mips_cps_boot_vpes) #elif defined(CONFIG_MIPS_MT) .set push + .set MIPS_ISA_LEVEL_RAW .set mt /* If the core doesn't support MT then return */Signature · 1 line
1.9.1
PATCH 1/1 MIPS: CPS: Fix MIPS_ISA_LEVEL_RAW fallout
Commit 17278a91e04f ("MIPS: CPS: Fix r1 .set mt assembler warning") added .set MIPS_ISA_LEVEL_RAW to silence warnings about .set mt on r1, however this can result in a MOVE being encoded as a 64-bit DADDU instruction on certain version of binutils (e.g. 2.22), and reserved instruction exceptions at runtime on 32-bit hardware.
Reduce the sizes of the push/pop sections to include only instructions that are part of the MT ASE or which won't convert to 64-bit instructions after .set mips64r2/mips64r6.
---
Greg: Please can you test this patch.
--- arch/mips/kernel/cps-vec.S | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
arch/mips/kernel/cps-vec.S +12 -5
@@ -388,15 +388,16 @@ LEAF(mips_cps_boot_vpes) #elif defined(CONFIG_MIPS_MT) - .set push - .set MIPS_ISA_LEVEL_RAW - .set mt - /* If the core doesn't support MT then return */ has_mt t0, 5f /* Enter VPE configuration state */ + .set push + .set MIPS_ISA_LEVEL_RAW + .set mt dvpe + .set pop + PTR_LA t1, 1f jr.hb t1 nop
@@ -422,6 +423,10 @@ LEAF(mips_cps_boot_vpes) mtc0 t0, CP0_VPECONTROL ehb + .set push + .set MIPS_ISA_LEVEL_RAW + .set mt + /* Skip the VPE if its TC is not halted */ mftc0 t0, CP0_TCHALT beqz t0, 2f
@@ -495,6 +500,8 @@ LEAF(mips_cps_boot_vpes) ehb evpe + .set pop + /* Check whether this VPE is meant to be running */ li t0, 1 sll t0, t0, a1
@@ -509,7 +516,7 @@ LEAF(mips_cps_boot_vpes) 1: jr.hb t0 nop -2: .set pop +2: #endif /* CONFIG_MIPS_MT_SMP */
Signature · 1 line
2.13.6
Re: [PATCH] MIPS: CPS: Fix MIPS_ISA_LEVEL_RAW fallout
Hi James,
Quoted 17 lines · James Hogan
Commit
17278a91e04f("MIPS: CPS: Fix r1 .set mt assembler warning") added .setMIPS_ISA_LEVEL_RAWto silence warnings about .set mt on r1, however this can result in a MOVE being encoded as a 64-bit DADDU instruction on certain version of binutils (e.g. 2.22), and reserved instruction exceptions at runtime on 32-bit hardware.Reduce the sizes of the push/pop sections to include only instructions that are part of the MT ASE or which won't convert to 64-bit instructions after .set mips64r2/mips64r6.
Reported-by Greg Ungerer <[email protected]>Fixes 17278a91e04f ("MIPS: CPS: Fix r1 .set mt assembler warning")Signed-off-by James Hogan <[email protected]>Cc Ralf Baechle <[email protected]>Cc Paul Burton <[email protected]>Cc <[email protected]> # 4.15
Quoted 2 lines
---
Greg: Please can you test this patch.
Tested and works. Thanks for the quick response and turn around.
Regards
Greg
Quoted 59 lines
--- arch/mips/kernel/cps-vec.S | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)arch/mips/kernel/cps-vec.S +12
-5@@ -388,15 +388,16 @@ LEAF(mips_cps_boot_vpes) #elif defined(CONFIG_MIPS_MT) - .set push - .set MIPS_ISA_LEVEL_RAW - .set mt - /* If the core doesn't support MT then return */ has_mt t0, 5f /* Enter VPE configuration state */ + .set push + .set MIPS_ISA_LEVEL_RAW + .set mt dvpe + .set pop + PTR_LA t1, 1f jr.hb t1 nop@@ -422,6 +423,10 @@ LEAF(mips_cps_boot_vpes) mtc0 t0, CP0_VPECONTROL ehb + .set push + .set MIPS_ISA_LEVEL_RAW + .set mt + /* Skip the VPE if its TC is not halted */ mftc0 t0, CP0_TCHALT beqz t0, 2f@@ -495,6 +500,8 @@ LEAF(mips_cps_boot_vpes) ehb evpe + .set pop + /* Check whether this VPE is meant to be running */ li t0, 1 sll t0, t0, a1@@ -509,7 +516,7 @@ LEAF(mips_cps_boot_vpes) 1: jr.hb t0 nop -2: .set pop +2: #endif /* CONFIG_MIPS_MT_SMP */
Hi James,
Quoted 50 lines · James Hogan
Quoted 49 lines · Greg Ungerer
Quoted 5 lines · James Hogan
From
17278a91e04f858155d54bee5528ba4fbcec6f87Mon Sep 17 00:00:00 2001
From: James Hogan <[email protected]>
Date: Tue, 14 Nov 2017 12:01:20 +0000
Subject: [PATCH] MIPS: CPS: Fix r1 .set mt assembler warningQuoted 7 lines
MIPS CPS has a build warning on kernels configured for MIPS32R1 or MIPS64R1, due to the use of .set mt without a prior .set mips{32,64}r2:
arch/mips/kernel/cps-vec.SAssembler messages:arch/mips/kernel/cps-vec.S:238: Warning: the `mt' extension requires MIPS32 revision 2 or greaterAdd .set
MIPS_ISA_LEVEL_RAWbefore .set mt to silence the warning.This change breaks booting for me on a MediaTek MT7621 platform:
...
Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)^M
pid_max: default: 32768 minimum: 301^M
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)^M Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)^M Hierarchical SRCU implementation.^M
smp: Bringing up secondary CPUs ...^M
Reserved instruction in kernel code[#1]:^MCPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.15.0-ac0 #3^M $ 0 : 00000000 00000001 00000000 00000000^M $ 4 : 8501dd80 00000001 00000004 00000000^M $ 8 : 00000004 00000002 00000001 ffffffff^M $12 : 00000000 00000400 00000003 8501de00^M $16 : 807d5ca0 8501dd80 00000000 00000001^M $20 : 80842814 00000000 00000001 000000e0^M $24 : fffffffc 00000001 ^M $28 : 85026000 85027de0 00000020 80013538^M Hi : 00000006^M Lo : 8e778000^M epc : 80656620 mips_cps_boot_vpes+0x4c/0x160^M ra : 80013538 cps_boot_secondary+0x280/0x440^M Status: 11000403 KERNEL EXL IE ^M Cause : 50800028 (ExcCode 0a)^M PrId : 0001992f (MIPS 1004Kc)^MIf I revert the patch then I can boot up again, all works as expected.
I am not exactly using a pure mainline 4.15 source base though. (I have a bunch of additional changes to make this platform actually work).
But this patch certainly does trap as above when present. I am using a gcc-5.4.0/binutils-2.25.1 toolchain.
Quoted 7 lines
Quoted 1 line
Any thoughts?
Hmm, sorry about that.
If there is some more of the log which shows code around the EPC (usually a few lines below where you stopped), that would be helpful to see exactly whats happening. Perhaps it has used a 64-bit instruction.
Sorry, yes, I snipped that a little too much. Below is the full boot log:
Linux version 4.15.0-ac0 (gerg@goober) (gcc version 5.4.0 (GCC)) #2 SMP Mon Feb 5 08:58:57 AEST 2018
SoC Type: MediaTek MT7621 ver:1 eco:3
bootconsole [early0] enabled
CPU0 revision is: 0001992f (MIPS 1004Kc)
MIPS: machine is Accelerated Concepts 6310-EX
Determined physical RAM map:
memory: 08000000 @ 00000000 (usable)
Initial ramdisk at: 0x84000000 (16777216 bytes)
VPE topology {2,2} total 4
Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
Zone ranges:
Normal [mem 0x0000000000000000-0x0000000007ffffff]
Movable zone start for each node
Early memory node ranges
node 0: [mem 0x0000000000000000-0x0000000007ffffff]
Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
random: get_random_bytes called from start_kernel+0x90/0x4b4 with crng_init=0
percpu: Embedded 15 pages/cpu @(ptrval) s30336 r8192 d22912 u61440
Built 1 zonelists, mobility grouping on. Total pages: 32512
Kernel command line: console=ttyS0,57600 rd_start=0x84000000 rd_size=0x01000000
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Writing ErrCtl register=0004ae58
Readback ErrCtl register=0004ae58
Memory: 104556K/131072K available (6492K kernel code, 227K rwdata, 1452K rodata, 264K init, 262K bss, 26516K reserved, 0K cma-reserved)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
Hierarchical RCU implementation.NR_IRQS: 256
clocksource: GIC: mask: 0xfffffffff max_cycles: 0xfffffffff, max_idle_ns: 34750190079 nssched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 21474836475000000ns
Calibrating delay loop... 586.13 BogoMIPS (lpj=2930688)pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
Hierarchical SRCU implementation.
smp: Bringing up secondary CPUs ...
Reserved instruction in kernel code[#1]:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.15.0-ac0 #2
$ 0 : 00000000 00000001 00000000 00000000
$ 4 : 8501dd80 00000001 00000004 00000000
$ 8 : 00000004 00000002 00000001 ffffffff
$12 : 00000000 00000400 00000003 8501de00
$16 : 807d5ca0 8501dd80 00000000 00000001
$20 : 80842814 00000000 00000001 000000e0
$24 : fffffffc 00000001
$28 : 85026000 85027de0 00000020 80013538
Hi : 00000006
Lo : 8e778000
epc : 80656620 mips_cps_boot_vpes+0x4c/0x160
ra : 80013538 cps_boot_secondary+0x280/0x440
Status: 11000403 KERNEL EXL IE
Cause : 50800028 (ExcCode 0a)
PrId : 0001992f (MIPS 1004Kc)
Modules linked in:
Process swapper/0 (pid: 1, threadinfo=(ptrval), task=(ptrval), tls=00000000)
Stack : 00000000 807d6170 00000004 00000000 00000001 00000001 00000000 807e0000
00000000 807d6170 00000004 00000000 00000000 80012424 807de840 807de81c
8074dfe4 00000001 00000001 80028bf4 811191e4 00000001 00000000 807e0000
00000000 811191e4 00000001 80029ac8 807d6068 807e0000 80750ebc 85027e8c
00000000 8006d584 807d6064 807d0000 807d6068 807e0000 807d0000 00000001
...
Call Trace:
[<(ptrval)>] mips_cps_boot_vpes+0x4c/0x160
[<(ptrval)>] cps_boot_secondary+0x280/0x440
[<(ptrval)>] __cpu_up+0x20/0x88
[<(ptrval)>] bringup_cpu+0x24/0x110
[<(ptrval)>] cpu_up+0x128/0x270
[<(ptrval)>] smp_init+0xdc/0x134
[<(ptrval)>] kernel_init_freeable+0xac/0x240
[<(ptrval)>] kernel_init+0x14/0x110
[<(ptrval)>] ret_from_kernel_thread+0x14/0x1c
Code: 35290002 40890001 000000c0 <01c0c02d> 240d0000 31c80001 1100002b 00000000 40080801 ---[ end trace 0daa832a1a349425 ]--- Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
A "mips-linux-objdump -d" around that PC gives:
80656610: 40090001 mfc0 t1,c0_mvpcontrol 80656614: 35290002 ori t1,t1,0x2 80656618: 40890001 mtc0 t1,c0_mvpcontrol 8065661c: 000000c0 ehb 80656620: 01c0c02d 0x1c0c02d 80656624: 240d0000 li t5,0 80656628: 31c80001 andi t0,t6,0x1 8065662c: 1100002b beqz t0,806566dc <mips_cps_boot_vpes+0x108> 80656630: 00000000 nop
So it can't decode that "01c0c02d"...
Quoted 4 lines
When I build 32r2el_defconfig, that EPC (relative to
mips_cps_boot_vpes) is a move instruction, which is implemented with OR (which should be safe on MIPS32 and MIPS64), both with binutils 2.28ish and 2.24ish (MTI / IMG toolchains, so they may have additional patches).
I am using a strait binutils-2.25.1 and gcc-5.4.0 with no additional patches applied. (configured with "mips-linux" as the target archiecture).
Regards
Greg
Quoted 46 lines
I'll try limiting the .set mt to code that needs it.
Thanks
JamesQuoted 41 lines
Regards
GregQuoted 35 lines
Fixes 245a7868d2f2 ("MIPS: smp-cps: rework core/VPE initialisation")Signed-off-by James Hogan <[email protected]>Cc Paul Burton <[email protected]>Cc James Hogan <[email protected]>Cc James Hogan <[email protected]>Cc Paul Burton <[email protected]>Patchwork: https://patchwork.linux-mips.org/patch/17699/
Signed-off-by Ralf Baechle <[email protected]>--- arch/mips/kernel/cps-vec.S | 2 ++ 1 file changed, 2 insertions(+)arch/mips/kernel/cps-vec.S +2
-0@@ -235,6 +235,7 @@ LEAF(mips_cps_core_init) has_mt t0, 3f .set push + .set MIPS_ISA_LEVEL_RAW .set mt /* Only allow 1 TC per VPE to execute... */@@ -388,6 +389,7 @@ LEAF(mips_cps_boot_vpes) #elif defined(CONFIG_MIPS_MT) .set push + .set MIPS_ISA_LEVEL_RAW .set mt /* If the core doesn't support MT then return */Signature · 1 line
1.9.1
Quoted 12 lines · Greg Ungerer
A "mips-linux-objdump -d" around that PC gives:
80656610: 40090001 mfc0 t1,c0_mvpcontrol 80656614: 35290002 ori t1,t1,0x2 80656618: 40890001 mtc0 t1,c0_mvpcontrol 8065661c: 000000c0 ehb 80656620: 01c0c02d 0x1c0c02d 80656624: 240d0000 li t5,0 80656628: 31c80001 andi t0,t6,0x1 8065662c: 1100002b beqz t0,806566dc <mips_cps_boot_vpes+0x108> 80656630: 00000000 nop
Quoted 1 line
So it can't decode that "
01c0c02d"...
Well, `objdump -mmips:isa64r2 -d' reveals this:
80000000: 01c0c02d move t8,t6
and then `objdump -mmips:isa64r2 -M no-aliases -d' further shows this:
80000000: 01c0c02d daddu t8,t6,zero
which is a 64-bit instruction, so clearly the temporary `.set' override spans too much (we have updated GAS recently to emit machine code for OR rather than ADDU/DADDU as the expansion for the MOVE assembly idiom to minimise impact from such issues though; ADDU/DADDU would schedule better with old superscalar MIPS processors, but that is not an issue with the modern ones, I'm told).
HTH,
Maciej