Skip to contentSkip to conversation

ARM: Make CPU_DCACHE_DISABLE depend on !SMP

RFC In review Florian Fainelli 5 participants 12 messages Jan 8, 2015 – Jan 9, 2015 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

RFC 1/1 ARM: Make CPU_DCACHE_DISABLE depend on !SMP

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

(gdb) x/10i $pc

=> 0xc053cfa8 <_raw_spin_lock+4>:       ldrex   r3, [r0]
   0xc053cfac <_raw_spin_lock+8>:       add     r2, r3, #65536  ; 0x10000

which is taken by the very first printk call:

    at /home/fainelli/work/linux/arch/arm/include/asm/spinlock.h:65
    fmt=0xc0637650 "\001\066Booting Linux on physical CPU 0x%x\n", args=<incomplete type>)
    at kernel/printk/printk.c:1525
    fmt=0xc05370f4 <printk+52> "\024\320\215\342\004\340\235\344\020\320\215\342\036\377/\341\017") at kernel/printk/printk.c:1688

ldrex requires exclusive monitor(s) (local or global) which are no longer working when the Data cache is disabled in CP15 and will just hang the CPU there.

---
 arch/arm/mm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mm/Kconfig +1 -1
index 03823e784f63..09245fd1e900 100644
@@ -738,7 +738,7 @@ config CPU_ICACHE_DISABLE
 
 config CPU_DCACHE_DISABLE
 	bool "Disable D-Cache (C-bit)"
-	depends on CPU_CP15
+	depends on CPU_CP15 && !SMP
 	help
 	  Say Y here to disable the processor data cache. Unless
 	  you have a reason not to or are unsure, say N.
Signature · 1 line
2.1.0
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · On Wednesday 07 January 2015 18:11:28 Florian Fainelli wrote:

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

(gdb) x/10i $pc

=> 0xc053cfa8 <_raw_spin_lock+4>:       ldrex   r3, [r0]
   0xc053cfac <_raw_spin_lock+8>:       add     r2, r3, #65536  ; 0x10000

which is taken by the very first printk call:

    at /home/fainelli/work/linux/arch/arm/include/asm/spinlock.h:65
    fmt=0xc0637650 "\001\066Booting Linux on physical CPU 0x%x\n", args=<incomplete type>)
    at kernel/printk/printk.c:1525
    fmt=0xc05370f4 <printk+52> "\024\320\215\342\004\340\235\344\020\320\215\342\036\377/\341\017") at kernel/printk/printk.c:1688
Quoted 5 lines

ldrex requires exclusive monitor(s) (local or global) which are no longer working when the Data cache is disabled in CP15 and will just hang the CPU there.

We stumbled on this a while back when Kaixu was trying to fix allmodconfig builds to run on real hardware, but never submitted it in the end when Russell didn't like some of the other parts required for that to work.

This one clearly makes sense independently.

Quoted 14 lines
arch/arm/mm/Kconfig +1 -1
index 03823e784f63..09245fd1e900 100644
@@ -738,7 +738,7 @@ config CPU_ICACHE_DISABLE
 
 config CPU_DCACHE_DISABLE
 	bool "Disable D-Cache (C-bit)"
-	depends on CPU_CP15
+	depends on CPU_CP15 && !SMP
 	help
 	  Say Y here to disable the processor data cache. Unless
 	  you have a reason not to or are unsure, say N.
#2 lore raw
Quoted 22 lines · Arnd Bergmann
Quoted 15 lines · On Wednesday 07 January 2015 18:11:28 Florian Fainelli wrote:

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

(gdb) x/10i $pc

=> 0xc053cfa8 <_raw_spin_lock+4>:       ldrex   r3, [r0]
   0xc053cfac <_raw_spin_lock+8>:       add     r2, r3, #65536  ; 0x10000

which is taken by the very first printk call:

    at /home/fainelli/work/linux/arch/arm/include/asm/spinlock.h:65
    fmt=0xc0637650 "\001\066Booting Linux on physical CPU 0x%x\n", args=<incomplete type>)
    at kernel/printk/printk.c:1525
    fmt=0xc05370f4 <printk+52> "\024\320\215\342\004\340\235\344\020\320\215\342\036\377/\341\017") at kernel/printk/printk.c:1688
Quoted 5 lines

ldrex requires exclusive monitor(s) (local or global) which are no longer working when the Data cache is disabled in CP15 and will just hang the CPU there.

Quoted 7 lines

We stumbled on this a while back when Kaixu was trying to fix allmodconfig builds to run on real hardware, but never submitted it in the end when Russell didn't like some of the other parts required for that to work.

This one clearly makes sense independently.

What about platforms where exclusives to strongly ordered memory do work?

I seem to remember patches from Tony for the pstore/ram_core driver to allow it to map stuff strongly ordered, and use exclusives on it.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
#3 lore raw

Le 08/01/2015 03:52, Russell King - ARM Linux a ?crit :

Quoted 25 lines · Arnd Bergmann
Quoted 24 lines · On Wednesday 07 January 2015 18:11:28 Florian Fainelli wrote:
Quoted 15 lines

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

(gdb) x/10i $pc

=> 0xc053cfa8 <_raw_spin_lock+4>:       ldrex   r3, [r0]
   0xc053cfac <_raw_spin_lock+8>:       add     r2, r3, #65536  ; 0x10000

which is taken by the very first printk call:

    at /home/fainelli/work/linux/arch/arm/include/asm/spinlock.h:65
    fmt=0xc0637650 "\001\066Booting Linux on physical CPU 0x%x\n", args=<incomplete type>)
    at kernel/printk/printk.c:1525
    fmt=0xc05370f4 <printk+52> "\024\320\215\342\004\340\235\344\020\320\215\342\036\377/\341\017") at kernel/printk/printk.c:1688
Quoted 5 lines

ldrex requires exclusive monitor(s) (local or global) which are no longer working when the Data cache is disabled in CP15 and will just hang the CPU there.

Quoted 7 lines
Quoted 5 lines

We stumbled on this a while back when Kaixu was trying to fix allmodconfig builds to run on real hardware, but never submitted it in the end when Russell didn't like some of the other parts required for that to work.

This one clearly makes sense independently.

What about platforms where exclusives to strongly ordered memory do work?

Do we have a comprehensive list of these platforms?

Quoted 3 lines

I seem to remember patches from Tony for the pstore/ram_core driver to allow it to map stuff strongly ordered, and use exclusives on it.

Would you have links to these patches handy?
--
Florian

#4 lore raw
Quoted 30 lines · Florian Fainelli

Le 08/01/2015 03:52, Russell King - ARM Linux a ?crit :

Quoted 29 lines · Arnd Bergmann
Quoted 28 lines · On Wednesday 07 January 2015 18:11:28 Florian Fainelli wrote:
Quoted 15 lines

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

(gdb) x/10i $pc

=> 0xc053cfa8 <_raw_spin_lock+4>:       ldrex   r3, [r0]
   0xc053cfac <_raw_spin_lock+8>:       add     r2, r3, #65536  ; 0x10000

which is taken by the very first printk call:

    at /home/fainelli/work/linux/arch/arm/include/asm/spinlock.h:65
    fmt=0xc0637650 "\001\066Booting Linux on physical CPU 0x%x\n", args=<incomplete type>)
    at kernel/printk/printk.c:1525
    fmt=0xc05370f4 <printk+52> "\024\320\215\342\004\340\235\344\020\320\215\342\036\377/\341\017") at kernel/printk/printk.c:1688
Quoted 5 lines

ldrex requires exclusive monitor(s) (local or global) which are no longer working when the Data cache is disabled in CP15 and will just hang the CPU there.

We stumbled on this a while back when Kaixu was trying to fix allmodconfig builds to run on real hardware, but never submitted it in the end when Russell didn't like some of the other parts required for that to work.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This one clearly makes sense independently.

What about platforms where exclusives to strongly ordered memory do work?

Do we have a comprehensive list of these platforms?

I haven't had a chance to go through all of the TRMs, but section A3.4.5 of the ARMv7-A ARM says:

"It is IMPLEMENTATION DEFINED whether LDREX and STREX operations can be performed to a memory region
with the Device or Strongly-ordered memory attribute. Unless the implementation documentation explicitly
states that LDREX and STREX operations to a memory region with the Device or Strongly-ordered attribute are
permitted, the effect of such operations is UNPREDICTABLE ."

Quoted 1 line

From 6.4.5 "Synchronization primitives" in the Cortex-A15 TRM:

"Use of synchronization primitives on addresses in regions marked as Strongly-ordered or
Device is UNPREDICTABLE in the ARMv7-A Architecture. Code that makes such accesses
is not portable."

It looks like this is not generally permissible for ARMv7, maybe someone else can check the other versions. Perhaps it would make sense to disallow disabling the D-cache for !SMP in general and special-case those architectures which do support exclusives to strongly ordered memory.

Best regards,
Gregory

#5 lore raw
Quoted 33 lines · On Thursday 08 January 2015 13:54:29 Gregory Fong wrote:
Quoted 7 lines · Florian Fainelli

Le 08/01/2015 03:52, Russell King - ARM Linux a ?crit :

Quoted 6 lines · Arnd Bergmann
Quoted 5 lines

We stumbled on this a while back when Kaixu was trying to fix allmodconfig builds to run on real hardware, but never submitted it in the end when Russell didn't like some of the other parts required for that to work.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This one clearly makes sense independently.

What about platforms where exclusives to strongly ordered memory do work?

Do we have a comprehensive list of these platforms?

I haven't had a chance to go through all of the TRMs, but section A3.4.5 of the ARMv7-A ARM says:

"It is IMPLEMENTATION DEFINED whether LDREX and STREX operations can be performed to a memory region
with the Device or Strongly-ordered memory attribute. Unless the implementation documentation explicitly
states that LDREX and STREX operations to a memory region with the Device or Strongly-ordered attribute are
permitted, the effect of such operations is UNPREDICTABLE ."

From 6.4.5 "Synchronization primitives" in the Cortex-A15 TRM:

"Use of synchronization primitives on addresses in regions marked as Strongly-ordered or
Device is UNPREDICTABLE in the ARMv7-A Architecture. Code that makes such accesses
is not portable."

Quoted 5 lines

It looks like this is not generally permissible for ARMv7, maybe someone else can check the other versions. Perhaps it would make sense to disallow disabling the D-cache for !SMP in general and special-case those architectures which do support exclusives to strongly ordered memory.

Too many negations, I assume you meant on SMP rather than !SMP.

My guess is that any implementation that has working LDREX/STREX on uncached memory does not support SMP, because these instructions tend to be implemented through the cache coherency logic on SMP systems but could be implemented more easily without a dcache on uniprocessor cores.

Arnd

#10 lore raw
In reply to Gregory Fong
Quoted 56 lines · Gregory Fong
Quoted 30 lines · Florian Fainelli

Le 08/01/2015 03:52, Russell King - ARM Linux a ?crit :

Quoted 29 lines · Arnd Bergmann
Quoted 28 lines · On Wednesday 07 January 2015 18:11:28 Florian Fainelli wrote:
Quoted 15 lines

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

(gdb) x/10i $pc

=> 0xc053cfa8 <_raw_spin_lock+4>:       ldrex   r3, [r0]
   0xc053cfac <_raw_spin_lock+8>:       add     r2, r3, #65536  ; 0x10000

which is taken by the very first printk call:

    at /home/fainelli/work/linux/arch/arm/include/asm/spinlock.h:65
    fmt=0xc0637650 "\001\066Booting Linux on physical CPU 0x%x\n", args=<incomplete type>)
    at kernel/printk/printk.c:1525
    fmt=0xc05370f4 <printk+52> "\024\320\215\342\004\340\235\344\020\320\215\342\036\377/\341\017") at kernel/printk/printk.c:1688
Quoted 5 lines

ldrex requires exclusive monitor(s) (local or global) which are no longer working when the Data cache is disabled in CP15 and will just hang the CPU there.

We stumbled on this a while back when Kaixu was trying to fix allmodconfig builds to run on real hardware, but never submitted it in the end when Russell didn't like some of the other parts required for that to work.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This one clearly makes sense independently.

What about platforms where exclusives to strongly ordered memory do work?

Do we have a comprehensive list of these platforms?

I haven't had a chance to go through all of the TRMs, but section A3.4.5 of the ARMv7-A ARM says:

"It is IMPLEMENTATION DEFINED whether LDREX and STREX operations can be performed to a memory region
with the Device or Strongly-ordered memory attribute. Unless the implementation documentation explicitly
states that LDREX and STREX operations to a memory region with the Device or Strongly-ordered attribute are
permitted, the effect of such operations is UNPREDICTABLE ."

From 6.4.5 "Synchronization primitives" in the Cortex-A15 TRM:

"Use of synchronization primitives on addresses in regions marked as Strongly-ordered or
Device is UNPREDICTABLE in the ARMv7-A Architecture. Code that makes such accesses
is not portable."

Quoted 5 lines

It looks like this is not generally permissible for ARMv7, maybe someone else can check the other versions. Perhaps it would make sense to disallow disabling the D-cache for !SMP in general and special-case those architectures which do support exclusives to strongly ordered memory.

Er, I meant "disallow disabling the D-cache for SMP", sorry. Too many negatives.

#6 lore raw
In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

My guess is that any implementation that has working LDREX/STREX on uncached memory does not support SMP, because these instructions tend to be implemented through the cache coherency logic on SMP systems but could be implemented more easily without a dcache on uniprocessor cores.

Yes, I negated Tony's patches... Tony was fixing pstore to use writecombine memory.

So this change is fine.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
#7 lore raw
Quoted 11 lines · Russell King - ARM Linux
Quoted 5 lines · Arnd Bergmann

My guess is that any implementation that has working LDREX/STREX on uncached memory does not support SMP, because these instructions tend to be implemented through the cache coherency logic on SMP systems but could be implemented more easily without a dcache on uniprocessor cores.

Yes, I negated Tony's patches... Tony was fixing pstore to use writecombine memory.

So this change is fine.

Do you want me to submit the patch as-is to your patch tracking, or would you want to include Gregory's quotes for completeness? --
Florian

#8 lore raw
Quoted 8 lines · Florian Fainelli
Quoted 7 lines · Russell King - ARM Linux
Quoted 5 lines · Arnd Bergmann

My guess is that any implementation that has working LDREX/STREX on uncached memory does not support SMP, because these instructions tend to be implemented through the cache coherency logic on SMP systems but could be implemented more easily without a dcache on uniprocessor cores.

Quoted 7 lines
Quoted 4 lines

Yes, I negated Tony's patches... Tony was fixing pstore to use writecombine memory.

So this change is fine.

Do you want me to submit the patch as-is to your patch tracking, or would you want to include Gregory's quotes for completeness?

I think as-is.

Thanks.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
#11 lore raw
In reply to Florian Fainelli
Quoted 3 lines · Florian Fainelli

Enabling CPU_DCACHE_DISABLE on a SMP capable system will prevent the kernel from booting because of the following ldrex instruction in arch_spin_lock:

BTW, it's not just SMP spin_lock which uses ldrex/strex. The atomic ops, set_bit() and friends, and cmpxchg() and related functions all use ldrex/strex on ARMv6+ processors, even if you disable SMP.

#9 lore raw
In reply to Russell King - ARM Linux
Quoted 12 lines · Russell King - ARM Linux
Quoted 11 lines · Florian Fainelli
Quoted 10 lines · Russell King - ARM Linux
Quoted 5 lines · Arnd Bergmann

My guess is that any implementation that has working LDREX/STREX on uncached memory does not support SMP, because these instructions tend to be implemented through the cache coherency logic on SMP systems but could be implemented more easily without a dcache on uniprocessor cores.

Yes, I negated Tony's patches... Tony was fixing pstore to use writecombine memory.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

So this change is fine.

Do you want me to submit the patch as-is to your patch tracking, or would you want to include Gregory's quotes for completeness?

I think as-is.

Thanks, submitted as 8276/1.

Signature · 1 line
Florian