Skip to contentSkip to conversation

m68k: Define NR_CPUS

PATCH In review Guenter Roeck 4 participants 10 messages Sep 23, 2024 – Sep 24, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 m68k: Define NR_CPUS

SPLIT_PTE_PTLOCKS depends on "NR_CPUS >= 4". Unfortunately, that evaluates to true if there is no NR_CPUS configuration option. This results in CONFIG_SPLIT_PTE_PTLOCKS=y for mac_defconfig. This in turn causes the m68k "q800" and "virt" machines to crash in qemu if debugging options are enabled.

Making CONFIG_SPLIT_PTE_PTLOCKS dependent on the existence of NR_CPUS does not work since a dependency on the existence of a numeric Kconfig entry always evaluates to false. Example:

config HAVE_NO_NR_CPUS
def_bool y
depends on !NR_CPUS

After adding this to a Kconfig file, "make defconfig" includes:

$ grep NR_CPUS .config
CONFIG_NR_CPUS=64
CONFIG_HAVE_NO_NR_CPUS=y

Define NR_CPUS for m68k instead to solve the problem.

Fixes 394290cba966 ("mm: turn USE_SPLIT_PTE_PTLOCKS / USE_SPLIT_PTE_PTLOCKS into Kconfig options")
Cc David Hildenbrand <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

---
v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

v1: https://lore.kernel.org/lkml/[email protected]/T/#t

 arch/m68k/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
arch/m68k/Kconfig +4 -0
index cc26df907bfe..53e4058d2e3c 100644
@@ -76,6 +76,10 @@ config PGTABLE_LEVELS
 	default 2 if SUN3 || COLDFIRE
 	default 3
 
+config NR_CPUS
+	int
+	default "1"
+
 config MMU
 	bool "MMU-based Paged Memory Management Support"
 	default y
Signature · 1 line
2.45.2
#1 lore raw
Quoted 27 lines · Guenter Roeck

SPLIT_PTE_PTLOCKS depends on "NR_CPUS >= 4". Unfortunately, that evaluates to true if there is no NR_CPUS configuration option. This results in CONFIG_SPLIT_PTE_PTLOCKS=y for mac_defconfig. This in turn causes the m68k "q800" and "virt" machines to crash in qemu if debugging options are enabled.

Making CONFIG_SPLIT_PTE_PTLOCKS dependent on the existence of NR_CPUS does not work since a dependency on the existence of a numeric Kconfig entry always evaluates to false. Example:

config HAVE_NO_NR_CPUS
def_bool y
depends on !NR_CPUS

After adding this to a Kconfig file, "make defconfig" includes:

$ grep NR_CPUS .config
CONFIG_NR_CPUS=64
CONFIG_HAVE_NO_NR_CPUS=y

Define NR_CPUS for m68k instead to solve the problem.

Fixes 394290cba966 ("mm: turn USE_SPLIT_PTE_PTLOCKS / USE_SPLIT_PTE_PTLOCKS into Kconfig options")
Cc David Hildenbrand <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Quoted 3 lines

---
v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

Okay, looks like we're cleaning up CONFIG_NR_CPUS for good.

I'm back from conference travel tomorrow; I'll then throw in the following into cross compilers and fixup any other arch that needs attention:

include/linux/threads.h +1 -2
index 1674a471b0b4..e31715e6746b 100644
@@ -13,8 +13,7 @@
  * bit of memory.  Use nr_cpu_ids instead of this except for static bitmaps.
  */
 #ifndef CONFIG_NR_CPUS
-/* FIXME: This should be fixed in the arch's Kconfig */
-#define CONFIG_NR_CPUS 1
+#error "CONFIG_NR_CPUS not defined"
 #endif
 
 /* Places which use this should consider cpumask_var_t. */
Signature · 3 lines
Cheers,

David / dhildenb
#2 lore raw

Hi David,

Quoted 15 lines · David Hildenbrand
Quoted 2 lines · Guenter Roeck

v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

Okay, looks like we're cleaning up CONFIG_NR_CPUS for good.

I'm back from conference travel tomorrow; I'll then throw in the following into cross compilers and fixup any other arch that needs attention:

include/linux/threads.h +0 -0
index 1674a471b0b4..e31715e6746b 100644

include/linux/threads.h line 19

Quoted 9 lines
include/linux/threads.h +1 -2
@@ -13,8 +13,7 @@
   * bit of memory.  Use nr_cpu_ids instead of this except for static bitmaps.
   */
  #ifndef CONFIG_NR_CPUS
-/* FIXME: This should be fixed in the arch's Kconfig */
-#define CONFIG_NR_CPUS 1
+#error "CONFIG_NR_CPUS not defined"
  #endif
 
  /* Places which use this should consider cpumask_var_t. */

This is gonna trigger on almost all architectures if CONFIG_SMP=n.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw
Quoted 26 lines · Geert Uytterhoeven

Hi David,

Quoted 23 lines · David Hildenbrand
Quoted 2 lines · Guenter Roeck

v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

Okay, looks like we're cleaning up CONFIG_NR_CPUS for good.

I'm back from conference travel tomorrow; I'll then throw in the following into cross compilers and fixup any other arch that needs attention:

include/linux/threads.h +1 -2
index 1674a471b0b4..e31715e6746b 100644
@@ -13,8 +13,7 @@
    * bit of memory.  Use nr_cpu_ids instead of this except for static bitmaps.
    */
   #ifndef CONFIG_NR_CPUS
-/* FIXME: This should be fixed in the arch's Kconfig */
-#define CONFIG_NR_CPUS 1
+#error "CONFIG_NR_CPUS not defined"
   #endif
 
Quoted 3 lines

include/linux/threads.h line 19

Quoted 1 line
include/linux/threads.h +0 -0
   /* Places which use this should consider cpumask_var_t. */

This is gonna trigger on almost all architectures if CONFIG_SMP=n.

Right, probably it's not as easy as:

mm/Kconfig +7 -0
index 09aebca1cae3..b9566312fc9c 100644
@@ -581,6 +581,13 @@ endif # MEMORY_HOTPLUG
 config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE
        bool
 
+if !SMP
+
+config NR_CPUS
+       default 1
+
+endif # !SMP
+
 # Heavily threaded applications may benefit from splitting the mm-wide
 # page_table_lock, so that faults on different parts of the user address
 # space can be handled with less contention: split it at this NR_CPUS.
Signature · 3 lines
Cheers,

David / dhildenb
#4 lore raw
Quoted 27 lines · David Hildenbrand
Quoted 26 lines · Geert Uytterhoeven

Hi David,

Quoted 23 lines · David Hildenbrand
Quoted 2 lines · Guenter Roeck

v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

Okay, looks like we're cleaning up CONFIG_NR_CPUS for good.

I'm back from conference travel tomorrow; I'll then throw in the following into cross compilers and fixup any other arch that needs attention:

include/linux/threads.h +1 -2
index 1674a471b0b4..e31715e6746b 100644
@@ -13,8 +13,7 @@
     * bit of memory.  Use nr_cpu_ids instead of this except for static bitmaps.
     */
    #ifndef CONFIG_NR_CPUS
-/* FIXME: This should be fixed in the arch's Kconfig */
-#define CONFIG_NR_CPUS 1
+#error "CONFIG_NR_CPUS not defined"
    #endif
 
Quoted 5 lines
Quoted 3 lines

include/linux/threads.h line 19

Quoted 1 line
include/linux/threads.h +0 -0
    /* Places which use this should consider cpumask_var_t. */

This is gonna trigger on almost all architectures if CONFIG_SMP=n.

Right, probably it's not as easy as:

Yeah, as assumed, Kconfig behaves weird if a symbol is not around. Let me think about this the upcoming weeks. Making split locks depend on SMP should make it work for now.

Signature · 3 lines
Cheers,

David / dhildenb
#5 lore raw
In reply to Geert Uytterhoeven
Quoted 26 lines · Geert Uytterhoeven

Hi David,

Quoted 23 lines · David Hildenbrand
Quoted 2 lines · Guenter Roeck

v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

Okay, looks like we're cleaning up CONFIG_NR_CPUS for good.

I'm back from conference travel tomorrow; I'll then throw in the following into cross compilers and fixup any other arch that needs attention:

include/linux/threads.h +1 -2
index 1674a471b0b4..e31715e6746b 100644
@@ -13,8 +13,7 @@
    * bit of memory.  Use nr_cpu_ids instead of this except for static bitmaps.
    */
   #ifndef CONFIG_NR_CPUS
-/* FIXME: This should be fixed in the arch's Kconfig */
-#define CONFIG_NR_CPUS 1
+#error "CONFIG_NR_CPUS not defined"
   #endif
 
Quoted 4 lines

include/linux/threads.h line 19

Quoted 1 line
include/linux/threads.h +0 -0
   /* Places which use this should consider cpumask_var_t. */

This is gonna trigger on almost all architectures if CONFIG_SMP=n.

Guess that means that my patch won't work either. Any better ideas ?

Guenter

#6 lore raw
Quoted 27 lines · Guenter Roeck
Quoted 26 lines · Geert Uytterhoeven

Hi David,

Quoted 23 lines · David Hildenbrand
Quoted 2 lines · Guenter Roeck

v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

Okay, looks like we're cleaning up CONFIG_NR_CPUS for good.

I'm back from conference travel tomorrow; I'll then throw in the following into cross compilers and fixup any other arch that needs attention:

include/linux/threads.h +1 -2
index 1674a471b0b4..e31715e6746b 100644
@@ -13,8 +13,7 @@
     * bit of memory.  Use nr_cpu_ids instead of this except for static bitmaps.
     */
    #ifndef CONFIG_NR_CPUS
-/* FIXME: This should be fixed in the arch's Kconfig */
-#define CONFIG_NR_CPUS 1
+#error "CONFIG_NR_CPUS not defined"
    #endif
 
Quoted 6 lines
Quoted 4 lines

include/linux/threads.h line 19

Quoted 1 line
include/linux/threads.h +0 -0
    /* Places which use this should consider cpumask_var_t. */

This is gonna trigger on almost all architectures if CONFIG_SMP=n.

Guess that means that my patch won't work either. Any better ideas ?

As discussed,

mm/Kconfig +1 -0
index 09aebca1cae3..4c9f5ea13271 100644
@@ -595,6 +595,7 @@ config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE
 config SPLIT_PTE_PTLOCKS
        def_bool y
        depends on MMU
+       depends on SMP
        depends on NR_CPUS >= 4
        depends on !ARM || CPU_CACHE_VIPT
        depends on !PARISC || PA20

Might work for the time being.

Signature · 3 lines
Cheers,

David / dhildenb
#7 lore raw

mm/Kconfig config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE · line 599

Quoted 10 lines · David Hildenbrand
mm/Kconfig +1 -0
index 09aebca1cae3..4c9f5ea13271 100644
@@ -595,6 +595,7 @@ config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE
 config SPLIT_PTE_PTLOCKS
        def_bool y
        depends on MMU
+       depends on SMP
        depends on NR_CPUS >= 4

I think it might be more intuitive if written as:

	depends on SMP && NR_CPUS >= 4

(with a note in the change description to the effect that NR_CPUS will have been unset and the condition won't work as expected unless SMP).

FWIW,

Maciej

#8 lore raw
In reply to Guenter Roeck

Hi Günter,

Thanks for your patch!

Quoted 19 lines · Guenter Roeck

SPLIT_PTE_PTLOCKS depends on "NR_CPUS >= 4". Unfortunately, that evaluates to true if there is no NR_CPUS configuration option. This results in CONFIG_SPLIT_PTE_PTLOCKS=y for mac_defconfig. This in turn causes the m68k "q800" and "virt" machines to crash in qemu if debugging options are enabled.

Making CONFIG_SPLIT_PTE_PTLOCKS dependent on the existence of NR_CPUS does not work since a dependency on the existence of a numeric Kconfig entry always evaluates to false. Example:

config HAVE_NO_NR_CPUS
def_bool y
depends on !NR_CPUS

After adding this to a Kconfig file, "make defconfig" includes:

$ grep NR_CPUS .config
CONFIG_NR_CPUS=64
CONFIG_HAVE_NO_NR_CPUS=y
Quoted 7 lines

Define NR_CPUS for m68k instead to solve the problem.

Fixes 394290cba966 ("mm: turn USE_SPLIT_PTE_PTLOCKS / USE_SPLIT_PTE_PTLOCKS into Kconfig options")
Cc David Hildenbrand <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

I think it's a bit premature to add David's tag, as v2 is completely different from v1.

Quoted 6 lines

---
v2: Instead of trying to make SPLIT_PTE_PTLOCKS depend on the
existence of NR_CPUS, define NR_CPUS for m68k.

v1: https://lore.kernel.org/lkml/[email protected]/T/#t

I replied on v1 why I think this is not the right solution.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#9 lore raw
Quoted 26 lines · Geert Uytterhoeven

Hi Günter,

Thanks for your patch!

Quoted 21 lines · Guenter Roeck

SPLIT_PTE_PTLOCKS depends on "NR_CPUS >= 4". Unfortunately, that evaluates to true if there is no NR_CPUS configuration option. This results in CONFIG_SPLIT_PTE_PTLOCKS=y for mac_defconfig. This in turn causes the m68k "q800" and "virt" machines to crash in qemu if debugging options are enabled.

Making CONFIG_SPLIT_PTE_PTLOCKS dependent on the existence of NR_CPUS does not work since a dependency on the existence of a numeric Kconfig entry always evaluates to false. Example:

config HAVE_NO_NR_CPUS
def_bool y
depends on !NR_CPUS

After adding this to a Kconfig file, "make defconfig" includes:

$ grep NR_CPUS .config
CONFIG_NR_CPUS=64
CONFIG_HAVE_NO_NR_CPUS=y

Define NR_CPUS for m68k instead to solve the problem.

Quoted 9 lines
Quoted 5 lines
Fixes 394290cba966 ("mm: turn USE_SPLIT_PTE_PTLOCKS / USE_SPLIT_PTE_PTLOCKS into Kconfig options")
Cc David Hildenbrand <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Geert Uytterhoeven <[email protected]>

I think it's a bit premature to add David's tag, as v2 is completely different from v1.

Ups, sorry, that was an unintentional carryover. Anyway, looks like it may need v3 anyway.

Guenter