Subject: Re: linux-next: build failure after merge of the tip tree

From: Peter Zijlstra <[email-masked]>
Date: Thu, 7 Nov 2024 11:34:14 +0100

On Thu, Nov 07, 2024 at 06:24:11PM +1100, Stephen Rothwell wrote:
> Hi all,
> 
> After merging the tip tree, today's linux-next build (x86_64 allmodconfig)
> failed like this:
> 
> In file included from rust/helpers/helpers.c:26:
> rust/helpers/spinlock.c: In function 'rust_helper___spin_lock_init':
> rust/helpers/spinlock.c:10:30: error: implicit declaration of function 'spinlock_check'; did you mean 'spin_lock_bh'? [-Wimplicit-function-declaration]
>    10 |         __raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
>       |                              ^~~~~~~~~~~~~~
>       |                              spin_lock_bh
> rust/helpers/spinlock.c:10:30: error: passing argument 1 of '__raw_spin_lock_init' makes pointer from integer without a cast [-Wint-conversion]
>    10 |         __raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
>       |                              ^~~~~~~~~~~~~~~~~~~~
>       |                              |
>       |                              int
> In file included from include/linux/wait.h:9,
>                  from include/linux/wait_bit.h:8,
>                  from include/linux/fs.h:6,
>                  from include/linux/highmem.h:5,
>                  from include/linux/bvec.h:10,
>                  from include/linux/blk_types.h:10,
>                  from include/linux/blkdev.h:9,
>                  from include/linux/blk-mq.h:5,
>                  from rust/helpers/blk.c:3,
>                  from rust/helpers/helpers.c:10:
> include/linux/spinlock.h:101:52: note: expected 'raw_spinlock_t *' {aka 'struct raw_spinlock *'} but argument is of type 'int'
>   101 |   extern void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
>       |                                    ~~~~~~~~~~~~~~~~^~~~
> 

So I can't get RUST=y, even though make rustavailable is happy.

make LLVM=-19 allmodconfig does not get me RUST=y

I started out with tip/master, tried adding rust-next, then kbuild-next
gave up and tried next/master. Nada.

Anyway, I think the above needs something like this:

---
diff --git a/rust/helpers/spinlock.c b/rust/helpers/spinlock.c
index b7b0945e8b3c..5804a6062eb1 100644
--- a/rust/helpers/spinlock.c
+++ b/rust/helpers/spinlock.c
@@ -5,11 +5,16 @@
 void rust_helper___spin_lock_init(spinlock_t *lock, const char *name,
 				  struct lock_class_key *key)
 {
+#ifndef CONFIG_PREEMPT_RT
 #ifdef CONFIG_DEBUG_SPINLOCK
 	__raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
 #else
 	spin_lock_init(lock);
 #endif
+#else
+	rt_mutex_base_init(&lock->lock);
+	__rt_spin_lock_init(lock, name, key, false);
+#endif
 }
 
 void rust_helper_spin_lock(spinlock_t *lock)

> Probably caused by commit
> 
>   35772d627b55 ("sched: Enable PREEMPT_DYNAMIC for PREEMPT_RT")
> 
> at least reverting commit
> 
>   dafc2d42c0a6 ("Merge branch into tip/master: 'sched/core'")
> 
> makes the build work again for me - so I have done that for today.
> 
> Without the revert CONFIG_PREEMPT_RT=y, after the revert it is not set
> and spinlock_check is only defined for !defined(CONFIG_PREEMPT_RT).

Right, that moved PREEMPT_RT out of the preemption choice. Now I'm not
sure we want it =y for all{yes,mod}config. Is the below the right
incantation to avoid this?

---
diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
index 7c1b29a3a491..54ea59ff8fbe 100644
--- a/kernel/Kconfig.preempt
+++ b/kernel/Kconfig.preempt
@@ -88,7 +88,7 @@ endchoice
 
 config PREEMPT_RT
 	bool "Fully Preemptible Kernel (Real-Time)"
-	depends on EXPERT && ARCH_SUPPORTS_RT
+	depends on EXPERT && ARCH_SUPPORTS_RT && !COMPILE_TEST
 	select PREEMPTION
 	help
 	  This option turns the kernel into a real-time kernel by replacing