[PATCH v17 36/47] dept: assign unique dept_key to each distinct wait_for_completion() caller

Byungchul Park posted 47 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH v17 36/47] dept: assign unique dept_key to each distinct wait_for_completion() caller
Posted by Byungchul Park 2 months, 2 weeks ago
wait_for_completion() can be used at various points in the code and it's
very hard to distinguish wait_for_completion()s between different usages.
Using a single dept_key for all the wait_for_completion()s could trigger
false positive reports.

Assign unique dept_key to each distinct wait_for_completion() caller to
avoid false positive reports.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
 include/linux/completion.h | 100 +++++++++++++++++++++++++++++++------
 kernel/sched/completion.c  |  60 +++++++++++-----------
 2 files changed, 115 insertions(+), 45 deletions(-)

diff --git a/include/linux/completion.h b/include/linux/completion.h
index 3200b741de28..4d8fb1d95c0a 100644
--- a/include/linux/completion.h
+++ b/include/linux/completion.h
@@ -27,12 +27,10 @@
 struct completion {
 	unsigned int done;
 	struct swait_queue_head wait;
-	struct dept_map dmap;
 };
 
 #define init_completion(x)				\
 do {							\
-	sdt_map_init(&(x)->dmap);			\
 	__init_completion(x);				\
 } while (0)
 
@@ -43,17 +41,14 @@ do {							\
 
 static inline void complete_acquire(struct completion *x, long timeout)
 {
-	sdt_might_sleep_start_timeout(&x->dmap, timeout);
 }
 
 static inline void complete_release(struct completion *x)
 {
-	sdt_might_sleep_end();
 }
 
 #define COMPLETION_INITIALIZER(work) \
-	{ 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), \
-	  .dmap = DEPT_MAP_INITIALIZER(work, NULL), }
+	{ 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), }
 
 #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
 	(*({ init_completion_map(&(work), &(map)); &(work); }))
@@ -119,18 +114,18 @@ static inline void reinit_completion(struct completion *x)
 	x->done = 0;
 }
 
-extern void wait_for_completion(struct completion *);
-extern void wait_for_completion_io(struct completion *);
-extern int wait_for_completion_interruptible(struct completion *x);
-extern int wait_for_completion_killable(struct completion *x);
-extern int wait_for_completion_state(struct completion *x, unsigned int state);
-extern unsigned long wait_for_completion_timeout(struct completion *x,
+extern void __wait_for_completion(struct completion *);
+extern void __wait_for_completion_io(struct completion *);
+extern int __wait_for_completion_interruptible(struct completion *x);
+extern int __wait_for_completion_killable(struct completion *x);
+extern int __wait_for_completion_state(struct completion *x, unsigned int state);
+extern unsigned long __wait_for_completion_timeout(struct completion *x,
 						   unsigned long timeout);
-extern unsigned long wait_for_completion_io_timeout(struct completion *x,
+extern unsigned long __wait_for_completion_io_timeout(struct completion *x,
 						    unsigned long timeout);
-extern long wait_for_completion_interruptible_timeout(
+extern long __wait_for_completion_interruptible_timeout(
 	struct completion *x, unsigned long timeout);
-extern long wait_for_completion_killable_timeout(
+extern long __wait_for_completion_killable_timeout(
 	struct completion *x, unsigned long timeout);
 extern bool try_wait_for_completion(struct completion *x);
 extern bool completion_done(struct completion *x);
@@ -139,4 +134,79 @@ extern void complete(struct completion *);
 extern void complete_on_current_cpu(struct completion *x);
 extern void complete_all(struct completion *);
 
+#define wait_for_completion(x)						\
+({									\
+	sdt_might_sleep_start_timeout(NULL, -1L);			\
+	__wait_for_completion(x);					\
+	sdt_might_sleep_end();						\
+})
+#define wait_for_completion_io(x)					\
+({									\
+	sdt_might_sleep_start_timeout(NULL, -1L);			\
+	__wait_for_completion_io(x);					\
+	sdt_might_sleep_end();						\
+})
+#define wait_for_completion_interruptible(x)				\
+({									\
+	int __ret;							\
+									\
+	sdt_might_sleep_start_timeout(NULL, -1L);			\
+	__ret = __wait_for_completion_interruptible(x);			\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
+#define wait_for_completion_killable(x)					\
+({									\
+	int __ret;							\
+									\
+	sdt_might_sleep_start_timeout(NULL, -1L);			\
+	__ret = __wait_for_completion_killable(x);			\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
+#define wait_for_completion_state(x, s)					\
+({									\
+	int __ret;							\
+									\
+	sdt_might_sleep_start_timeout(NULL, -1L);			\
+	__ret = __wait_for_completion_state(x, s);			\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
+#define wait_for_completion_timeout(x, t)				\
+({									\
+	unsigned long __ret;						\
+									\
+	sdt_might_sleep_start_timeout(NULL, t);				\
+	__ret = __wait_for_completion_timeout(x, t);			\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
+#define wait_for_completion_io_timeout(x, t)				\
+({									\
+	unsigned long __ret;						\
+									\
+	sdt_might_sleep_start_timeout(NULL, t);				\
+	__ret = __wait_for_completion_io_timeout(x, t);			\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
+#define wait_for_completion_interruptible_timeout(x, t)			\
+({									\
+	long __ret;							\
+									\
+	sdt_might_sleep_start_timeout(NULL, t);				\
+	__ret = __wait_for_completion_interruptible_timeout(x, t);	\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
+#define wait_for_completion_killable_timeout(x, t)			\
+({									\
+	long __ret;							\
+									\
+	sdt_might_sleep_start_timeout(NULL, t);				\
+	__ret = __wait_for_completion_killable_timeout(x, t);		\
+	sdt_might_sleep_end();						\
+	__ret;								\
+})
 #endif
diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
index 5e45a60ff7b3..7262000db114 100644
--- a/kernel/sched/completion.c
+++ b/kernel/sched/completion.c
@@ -4,7 +4,7 @@
  * Generic wait-for-completion handler;
  *
  * It differs from semaphores in that their default case is the opposite,
- * wait_for_completion default blocks whereas semaphore default non-block. The
+ * __wait_for_completion default blocks whereas semaphore default non-block. The
  * interface also makes it easy to 'complete' multiple waiting threads,
  * something which isn't entirely natural for semaphores.
  *
@@ -42,7 +42,7 @@ void complete_on_current_cpu(struct completion *x)
  * This will wake up a single thread waiting on this completion. Threads will be
  * awakened in the same order in which they were queued.
  *
- * See also complete_all(), wait_for_completion() and related routines.
+ * See also complete_all(), __wait_for_completion() and related routines.
  *
  * If this function wakes up a task, it executes a full memory barrier before
  * accessing the task state.
@@ -139,23 +139,23 @@ wait_for_common_io(struct completion *x, long timeout, int state)
 }
 
 /**
- * wait_for_completion: - waits for completion of a task
+ * __wait_for_completion: - waits for completion of a task
  * @x:  holds the state of this particular completion
  *
  * This waits to be signaled for completion of a specific task. It is NOT
  * interruptible and there is no timeout.
  *
- * See also similar routines (i.e. wait_for_completion_timeout()) with timeout
+ * See also similar routines (i.e. __wait_for_completion_timeout()) with timeout
  * and interrupt capability. Also see complete().
  */
-void __sched wait_for_completion(struct completion *x)
+void __sched __wait_for_completion(struct completion *x)
 {
 	wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE);
 }
-EXPORT_SYMBOL(wait_for_completion);
+EXPORT_SYMBOL(__wait_for_completion);
 
 /**
- * wait_for_completion_timeout: - waits for completion of a task (w/timeout)
+ * __wait_for_completion_timeout: - waits for completion of a task (w/timeout)
  * @x:  holds the state of this particular completion
  * @timeout:  timeout value in jiffies
  *
@@ -167,28 +167,28 @@ EXPORT_SYMBOL(wait_for_completion);
  * till timeout) if completed.
  */
 unsigned long __sched
-wait_for_completion_timeout(struct completion *x, unsigned long timeout)
+__wait_for_completion_timeout(struct completion *x, unsigned long timeout)
 {
 	return wait_for_common(x, timeout, TASK_UNINTERRUPTIBLE);
 }
-EXPORT_SYMBOL(wait_for_completion_timeout);
+EXPORT_SYMBOL(__wait_for_completion_timeout);
 
 /**
- * wait_for_completion_io: - waits for completion of a task
+ * __wait_for_completion_io: - waits for completion of a task
  * @x:  holds the state of this particular completion
  *
  * This waits to be signaled for completion of a specific task. It is NOT
  * interruptible and there is no timeout. The caller is accounted as waiting
  * for IO (which traditionally means blkio only).
  */
-void __sched wait_for_completion_io(struct completion *x)
+void __sched __wait_for_completion_io(struct completion *x)
 {
 	wait_for_common_io(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE);
 }
-EXPORT_SYMBOL(wait_for_completion_io);
+EXPORT_SYMBOL(__wait_for_completion_io);
 
 /**
- * wait_for_completion_io_timeout: - waits for completion of a task (w/timeout)
+ * __wait_for_completion_io_timeout: - waits for completion of a task (w/timeout)
  * @x:  holds the state of this particular completion
  * @timeout:  timeout value in jiffies
  *
@@ -201,14 +201,14 @@ EXPORT_SYMBOL(wait_for_completion_io);
  * till timeout) if completed.
  */
 unsigned long __sched
-wait_for_completion_io_timeout(struct completion *x, unsigned long timeout)
+__wait_for_completion_io_timeout(struct completion *x, unsigned long timeout)
 {
 	return wait_for_common_io(x, timeout, TASK_UNINTERRUPTIBLE);
 }
-EXPORT_SYMBOL(wait_for_completion_io_timeout);
+EXPORT_SYMBOL(__wait_for_completion_io_timeout);
 
 /**
- * wait_for_completion_interruptible: - waits for completion of a task (w/intr)
+ * __wait_for_completion_interruptible: - waits for completion of a task (w/intr)
  * @x:  holds the state of this particular completion
  *
  * This waits for completion of a specific task to be signaled. It is
@@ -216,7 +216,7 @@ EXPORT_SYMBOL(wait_for_completion_io_timeout);
  *
  * Return: -ERESTARTSYS if interrupted, 0 if completed.
  */
-int __sched wait_for_completion_interruptible(struct completion *x)
+int __sched __wait_for_completion_interruptible(struct completion *x)
 {
 	long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE);
 
@@ -224,10 +224,10 @@ int __sched wait_for_completion_interruptible(struct completion *x)
 		return t;
 	return 0;
 }
-EXPORT_SYMBOL(wait_for_completion_interruptible);
+EXPORT_SYMBOL(__wait_for_completion_interruptible);
 
 /**
- * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr))
+ * __wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr))
  * @x:  holds the state of this particular completion
  * @timeout:  timeout value in jiffies
  *
@@ -238,15 +238,15 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
  * or number of jiffies left till timeout) if completed.
  */
 long __sched
-wait_for_completion_interruptible_timeout(struct completion *x,
+__wait_for_completion_interruptible_timeout(struct completion *x,
 					  unsigned long timeout)
 {
 	return wait_for_common(x, timeout, TASK_INTERRUPTIBLE);
 }
-EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
+EXPORT_SYMBOL(__wait_for_completion_interruptible_timeout);
 
 /**
- * wait_for_completion_killable: - waits for completion of a task (killable)
+ * __wait_for_completion_killable: - waits for completion of a task (killable)
  * @x:  holds the state of this particular completion
  *
  * This waits to be signaled for completion of a specific task. It can be
@@ -254,7 +254,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
  *
  * Return: -ERESTARTSYS if interrupted, 0 if completed.
  */
-int __sched wait_for_completion_killable(struct completion *x)
+int __sched __wait_for_completion_killable(struct completion *x)
 {
 	long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
 
@@ -262,9 +262,9 @@ int __sched wait_for_completion_killable(struct completion *x)
 		return t;
 	return 0;
 }
-EXPORT_SYMBOL(wait_for_completion_killable);
+EXPORT_SYMBOL(__wait_for_completion_killable);
 
-int __sched wait_for_completion_state(struct completion *x, unsigned int state)
+int __sched __wait_for_completion_state(struct completion *x, unsigned int state)
 {
 	long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, state);
 
@@ -272,10 +272,10 @@ int __sched wait_for_completion_state(struct completion *x, unsigned int state)
 		return t;
 	return 0;
 }
-EXPORT_SYMBOL(wait_for_completion_state);
+EXPORT_SYMBOL(__wait_for_completion_state);
 
 /**
- * wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable))
+ * __wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable))
  * @x:  holds the state of this particular completion
  * @timeout:  timeout value in jiffies
  *
@@ -287,12 +287,12 @@ EXPORT_SYMBOL(wait_for_completion_state);
  * or number of jiffies left till timeout) if completed.
  */
 long __sched
-wait_for_completion_killable_timeout(struct completion *x,
+__wait_for_completion_killable_timeout(struct completion *x,
 				     unsigned long timeout)
 {
 	return wait_for_common(x, timeout, TASK_KILLABLE);
 }
-EXPORT_SYMBOL(wait_for_completion_killable_timeout);
+EXPORT_SYMBOL(__wait_for_completion_killable_timeout);
 
 /**
  *	try_wait_for_completion - try to decrement a completion without blocking
@@ -334,7 +334,7 @@ EXPORT_SYMBOL(try_wait_for_completion);
  *	completion_done - Test to see if a completion has any waiters
  *	@x:	completion structure
  *
- *	Return: 0 if there are waiters (wait_for_completion() in progress)
+ *	Return: 0 if there are waiters (__wait_for_completion() in progress)
  *		 1 if there are no waiters.
  *
  *	Note, this will always return true if complete_all() was called on @X.
-- 
2.17.1
[PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Guangbo Cui 2 months, 2 weeks ago
> -extern void wait_for_completion(struct completion *);
> -extern void wait_for_completion_io(struct completion *);
> -extern int wait_for_completion_interruptible(struct completion *x);
> -extern int wait_for_completion_killable(struct completion *x);
> -extern int wait_for_completion_state(struct completion *x, unsigned int state);
> -extern unsigned long wait_for_completion_timeout(struct completion *x,
> +extern void __wait_for_completion(struct completion *);
> +extern void __wait_for_completion_io(struct completion *);
> +extern int __wait_for_completion_interruptible(struct completion *x);
> +extern int __wait_for_completion_killable(struct completion *x);
> +extern int __wait_for_completion_state(struct completion *x, unsigned int state);
> +extern unsigned long __wait_for_completion_timeout(struct completion *x,
>  						   unsigned long timeout);
> -extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> +extern unsigned long __wait_for_completion_io_timeout(struct completion *x,
>  						    unsigned long timeout);
> -extern long wait_for_completion_interruptible_timeout(
> +extern long __wait_for_completion_interruptible_timeout(
>  	struct completion *x, unsigned long timeout);
> -extern long wait_for_completion_killable_timeout(
> +extern long __wait_for_completion_killable_timeout(
>  	struct completion *x, unsigned long timeout);
>  extern bool try_wait_for_completion(struct completion *x);
>  extern bool completion_done(struct completion *x);
> @@ -139,4 +134,79 @@ extern void complete(struct completion *);
>  extern void complete_on_current_cpu(struct completion *x);
>  extern void complete_all(struct completion *);
>  
> +#define wait_for_completion(x)						\
> +({									\
> +	sdt_might_sleep_start_timeout(NULL, -1L);			\
> +	__wait_for_completion(x);					\
> +	sdt_might_sleep_end();						\
> +})

The DEPT patch series changed `wait_for_completion` into a macro.
Because bindgen cannot handle function-like macros, this caused
Rust build errors. Add a helper function to fix it.

```
error[E0425]: cannot find function `wait_for_completion` in crate `bindings`
     --> rust/kernel/sync/completion.rs:110:28
      |
  110 |         unsafe { bindings::wait_for_completion(self.as_raw()) };
      |                            ^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `__wait_for_completion`
      |
     ::: /root/linux/rust/bindings/bindings_generated.rs:33440:5
      |
33440 |     pub fn __wait_for_completion(arg1: *mut completion);
      |     ---------------------------------------------------- similarly named function `__wait_for_completion` defined here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
```

Signed-off-by: Guangbo Cui <2407018371@qq.com>
---
 rust/helpers/completion.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/rust/helpers/completion.c b/rust/helpers/completion.c
index b2443262a2ae..5bae5e749def 100644
--- a/rust/helpers/completion.c
+++ b/rust/helpers/completion.c
@@ -6,3 +6,8 @@ void rust_helper_init_completion(struct completion *x)
 {
 	init_completion(x);
 }
+
+void rust_helper_wait_for_completion(struct completion *x)
+{
+	wait_for_completion(x);
+}
-- 
2.43.0
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Boqun Feng 2 months, 2 weeks ago
On Thu, Oct 02, 2025 at 10:06:17AM +0000, Guangbo Cui wrote:
> > -extern void wait_for_completion(struct completion *);
> > -extern void wait_for_completion_io(struct completion *);
> > -extern int wait_for_completion_interruptible(struct completion *x);
> > -extern int wait_for_completion_killable(struct completion *x);
> > -extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > -extern unsigned long wait_for_completion_timeout(struct completion *x,
> > +extern void __wait_for_completion(struct completion *);
> > +extern void __wait_for_completion_io(struct completion *);
> > +extern int __wait_for_completion_interruptible(struct completion *x);
> > +extern int __wait_for_completion_killable(struct completion *x);
> > +extern int __wait_for_completion_state(struct completion *x, unsigned int state);
> > +extern unsigned long __wait_for_completion_timeout(struct completion *x,
> >  						   unsigned long timeout);
> > -extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > +extern unsigned long __wait_for_completion_io_timeout(struct completion *x,
> >  						    unsigned long timeout);
> > -extern long wait_for_completion_interruptible_timeout(
> > +extern long __wait_for_completion_interruptible_timeout(
> >  	struct completion *x, unsigned long timeout);
> > -extern long wait_for_completion_killable_timeout(
> > +extern long __wait_for_completion_killable_timeout(
> >  	struct completion *x, unsigned long timeout);
> >  extern bool try_wait_for_completion(struct completion *x);
> >  extern bool completion_done(struct completion *x);
> > @@ -139,4 +134,79 @@ extern void complete(struct completion *);
> >  extern void complete_on_current_cpu(struct completion *x);
> >  extern void complete_all(struct completion *);
> >  
> > +#define wait_for_completion(x)						\
> > +({									\
> > +	sdt_might_sleep_start_timeout(NULL, -1L);			\
> > +	__wait_for_completion(x);					\
> > +	sdt_might_sleep_end();						\
> > +})
> 
> The DEPT patch series changed `wait_for_completion` into a macro.
> Because bindgen cannot handle function-like macros, this caused
> Rust build errors. Add a helper function to fix it.
> 
> ```
> error[E0425]: cannot find function `wait_for_completion` in crate `bindings`
>      --> rust/kernel/sync/completion.rs:110:28
>       |
>   110 |         unsafe { bindings::wait_for_completion(self.as_raw()) };
>       |                            ^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `__wait_for_completion`
>       |
>      ::: /root/linux/rust/bindings/bindings_generated.rs:33440:5
>       |
> 33440 |     pub fn __wait_for_completion(arg1: *mut completion);
>       |     ---------------------------------------------------- similarly named function `__wait_for_completion` defined here
> 
> error: aborting due to 1 previous error
> 
> For more information about this error, try `rustc --explain E0425`.
> ```
> 

I think Danilo already made it clear, please fold this the existing
patch. Moreover, since this patchset doesn't adjust init_completion()
from the Rust side, the result is Rust code will also use the same dept
key for completion, which has to be fixed if dept wants to be in-tree.

Regards,
Boqun

> Signed-off-by: Guangbo Cui <2407018371@qq.com>
> ---
>  rust/helpers/completion.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/rust/helpers/completion.c b/rust/helpers/completion.c
> index b2443262a2ae..5bae5e749def 100644
> --- a/rust/helpers/completion.c
> +++ b/rust/helpers/completion.c
> @@ -6,3 +6,8 @@ void rust_helper_init_completion(struct completion *x)
>  {
>  	init_completion(x);
>  }
> +
> +void rust_helper_wait_for_completion(struct completion *x)
> +{
> +	wait_for_completion(x);
> +}
> -- 
> 2.43.0
>
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Byungchul Park 4 weeks ago
On Thu, Oct 02, 2025 at 10:27:51AM -0700, Boqun Feng wrote:
> On Thu, Oct 02, 2025 at 10:06:17AM +0000, Guangbo Cui wrote:
> > > -extern void wait_for_completion(struct completion *);
> > > -extern void wait_for_completion_io(struct completion *);
> > > -extern int wait_for_completion_interruptible(struct completion *x);
> > > -extern int wait_for_completion_killable(struct completion *x);
> > > -extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > > -extern unsigned long wait_for_completion_timeout(struct completion *x,
> > > +extern void __wait_for_completion(struct completion *);
> > > +extern void __wait_for_completion_io(struct completion *);
> > > +extern int __wait_for_completion_interruptible(struct completion *x);
> > > +extern int __wait_for_completion_killable(struct completion *x);
> > > +extern int __wait_for_completion_state(struct completion *x, unsigned int state);
> > > +extern unsigned long __wait_for_completion_timeout(struct completion *x,
> > >                                                unsigned long timeout);
> > > -extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > > +extern unsigned long __wait_for_completion_io_timeout(struct completion *x,
> > >                                                 unsigned long timeout);
> > > -extern long wait_for_completion_interruptible_timeout(
> > > +extern long __wait_for_completion_interruptible_timeout(
> > >     struct completion *x, unsigned long timeout);
> > > -extern long wait_for_completion_killable_timeout(
> > > +extern long __wait_for_completion_killable_timeout(
> > >     struct completion *x, unsigned long timeout);
> > >  extern bool try_wait_for_completion(struct completion *x);
> > >  extern bool completion_done(struct completion *x);
> > > @@ -139,4 +134,79 @@ extern void complete(struct completion *);
> > >  extern void complete_on_current_cpu(struct completion *x);
> > >  extern void complete_all(struct completion *);
> > >
> > > +#define wait_for_completion(x)                                             \
> > > +({                                                                 \
> > > +   sdt_might_sleep_start_timeout(NULL, -1L);                       \
> > > +   __wait_for_completion(x);                                       \
> > > +   sdt_might_sleep_end();                                          \
> > > +})
> >
> > The DEPT patch series changed `wait_for_completion` into a macro.
> > Because bindgen cannot handle function-like macros, this caused
> > Rust build errors. Add a helper function to fix it.
> >
> > ```
> > error[E0425]: cannot find function `wait_for_completion` in crate `bindings`
> >      --> rust/kernel/sync/completion.rs:110:28
> >       |
> >   110 |         unsafe { bindings::wait_for_completion(self.as_raw()) };
> >       |                            ^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `__wait_for_completion`
> >       |
> >      ::: /root/linux/rust/bindings/bindings_generated.rs:33440:5
> >       |
> > 33440 |     pub fn __wait_for_completion(arg1: *mut completion);
> >       |     ---------------------------------------------------- similarly named function `__wait_for_completion` defined here
> >
> > error: aborting due to 1 previous error
> >
> > For more information about this error, try `rustc --explain E0425`.
> > ```
> >
> 
> I think Danilo already made it clear, please fold this the existing
> patch. Moreover, since this patchset doesn't adjust init_completion()
> from the Rust side, the result is Rust code will also use the same dept
> key for completion, which has to be fixed if dept wants to be in-tree.

Right.  The same key in Rust may generate false positives.  However, for
now, I will keep the current code until finding ways to assign
appropriate keys in Rust.  Thanks anyway.

	Byungchul

> Regards,
> Boqun
> 
> > Signed-off-by: Guangbo Cui <2407018371@qq.com>
> > ---
> >  rust/helpers/completion.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/rust/helpers/completion.c b/rust/helpers/completion.c
> > index b2443262a2ae..5bae5e749def 100644
> > --- a/rust/helpers/completion.c
> > +++ b/rust/helpers/completion.c
> > @@ -6,3 +6,8 @@ void rust_helper_init_completion(struct completion *x)
> >  {
> >       init_completion(x);
> >  }
> > +
> > +void rust_helper_wait_for_completion(struct completion *x)
> > +{
> > +     wait_for_completion(x);
> > +}
> > --
> > 2.43.0
> >
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Byungchul Park 1 month ago
On Thu, Oct 02, 2025 at 10:27:51AM -0700, Boqun Feng wrote:
> On Thu, Oct 02, 2025 at 10:06:17AM +0000, Guangbo Cui wrote:
> > > -extern void wait_for_completion(struct completion *);
> > > -extern void wait_for_completion_io(struct completion *);
> > > -extern int wait_for_completion_interruptible(struct completion *x);
> > > -extern int wait_for_completion_killable(struct completion *x);
> > > -extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > > -extern unsigned long wait_for_completion_timeout(struct completion *x,
> > > +extern void __wait_for_completion(struct completion *);
> > > +extern void __wait_for_completion_io(struct completion *);
> > > +extern int __wait_for_completion_interruptible(struct completion *x);
> > > +extern int __wait_for_completion_killable(struct completion *x);
> > > +extern int __wait_for_completion_state(struct completion *x, unsigned int state);
> > > +extern unsigned long __wait_for_completion_timeout(struct completion *x,
> > >                                                unsigned long timeout);
> > > -extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > > +extern unsigned long __wait_for_completion_io_timeout(struct completion *x,
> > >                                                 unsigned long timeout);
> > > -extern long wait_for_completion_interruptible_timeout(
> > > +extern long __wait_for_completion_interruptible_timeout(
> > >     struct completion *x, unsigned long timeout);
> > > -extern long wait_for_completion_killable_timeout(
> > > +extern long __wait_for_completion_killable_timeout(
> > >     struct completion *x, unsigned long timeout);
> > >  extern bool try_wait_for_completion(struct completion *x);
> > >  extern bool completion_done(struct completion *x);
> > > @@ -139,4 +134,79 @@ extern void complete(struct completion *);
> > >  extern void complete_on_current_cpu(struct completion *x);
> > >  extern void complete_all(struct completion *);
> > >
> > > +#define wait_for_completion(x)                                             \
> > > +({                                                                 \
> > > +   sdt_might_sleep_start_timeout(NULL, -1L);                       \
> > > +   __wait_for_completion(x);                                       \
> > > +   sdt_might_sleep_end();                                          \
> > > +})
> >
> > The DEPT patch series changed `wait_for_completion` into a macro.
> > Because bindgen cannot handle function-like macros, this caused
> > Rust build errors. Add a helper function to fix it.
> >
> > ```
> > error[E0425]: cannot find function `wait_for_completion` in crate `bindings`
> >      --> rust/kernel/sync/completion.rs:110:28
> >       |
> >   110 |         unsafe { bindings::wait_for_completion(self.as_raw()) };
> >       |                            ^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `__wait_for_completion`
> >       |
> >      ::: /root/linux/rust/bindings/bindings_generated.rs:33440:5
> >       |
> > 33440 |     pub fn __wait_for_completion(arg1: *mut completion);
> >       |     ---------------------------------------------------- similarly named function `__wait_for_completion` defined here
> >
> > error: aborting due to 1 previous error
> >
> > For more information about this error, try `rustc --explain E0425`.
> > ```
> >
> 
> I think Danilo already made it clear, please fold this the existing
> patch. Moreover, since this patchset doesn't adjust init_completion()
> from the Rust side, the result is Rust code will also use the same dept
> key for completion, which has to be fixed if dept wants to be in-tree.

Thank you for informing that.  I will take a look on it.

	Byungchul
> 
> Regards,
> Boqun
> 
> > Signed-off-by: Guangbo Cui <2407018371@qq.com>
> > ---
> >  rust/helpers/completion.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/rust/helpers/completion.c b/rust/helpers/completion.c
> > index b2443262a2ae..5bae5e749def 100644
> > --- a/rust/helpers/completion.c
> > +++ b/rust/helpers/completion.c
> > @@ -6,3 +6,8 @@ void rust_helper_init_completion(struct completion *x)
> >  {
> >       init_completion(x);
> >  }
> > +
> > +void rust_helper_wait_for_completion(struct completion *x)
> > +{
> > +     wait_for_completion(x);
> > +}
> > --
> > 2.43.0
> >
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Byungchul Park 1 month ago
On Thu, Nov 13, 2025 at 10:20:36AM +0900, Byungchul Park wrote:
> On Thu, Oct 02, 2025 at 10:27:51AM -0700, Boqun Feng wrote:
> > On Thu, Oct 02, 2025 at 10:06:17AM +0000, Guangbo Cui wrote:
> > > > -extern void wait_for_completion(struct completion *);
> > > > -extern void wait_for_completion_io(struct completion *);
> > > > -extern int wait_for_completion_interruptible(struct completion *x);
> > > > -extern int wait_for_completion_killable(struct completion *x);
> > > > -extern int wait_for_completion_state(struct completion *x, unsigned int state);
> > > > -extern unsigned long wait_for_completion_timeout(struct completion *x,
> > > > +extern void __wait_for_completion(struct completion *);
> > > > +extern void __wait_for_completion_io(struct completion *);
> > > > +extern int __wait_for_completion_interruptible(struct completion *x);
> > > > +extern int __wait_for_completion_killable(struct completion *x);
> > > > +extern int __wait_for_completion_state(struct completion *x, unsigned int state);
> > > > +extern unsigned long __wait_for_completion_timeout(struct completion *x,
> > > >                                                unsigned long timeout);
> > > > -extern unsigned long wait_for_completion_io_timeout(struct completion *x,
> > > > +extern unsigned long __wait_for_completion_io_timeout(struct completion *x,
> > > >                                                 unsigned long timeout);
> > > > -extern long wait_for_completion_interruptible_timeout(
> > > > +extern long __wait_for_completion_interruptible_timeout(
> > > >     struct completion *x, unsigned long timeout);
> > > > -extern long wait_for_completion_killable_timeout(
> > > > +extern long __wait_for_completion_killable_timeout(
> > > >     struct completion *x, unsigned long timeout);
> > > >  extern bool try_wait_for_completion(struct completion *x);
> > > >  extern bool completion_done(struct completion *x);
> > > > @@ -139,4 +134,79 @@ extern void complete(struct completion *);
> > > >  extern void complete_on_current_cpu(struct completion *x);
> > > >  extern void complete_all(struct completion *);
> > > >
> > > > +#define wait_for_completion(x)                                             \
> > > > +({                                                                 \
> > > > +   sdt_might_sleep_start_timeout(NULL, -1L);                       \
> > > > +   __wait_for_completion(x);                                       \
> > > > +   sdt_might_sleep_end();                                          \
> > > > +})
> > >
> > > The DEPT patch series changed `wait_for_completion` into a macro.
> > > Because bindgen cannot handle function-like macros, this caused
> > > Rust build errors. Add a helper function to fix it.
> > >
> > > ```
> > > error[E0425]: cannot find function `wait_for_completion` in crate `bindings`
> > >      --> rust/kernel/sync/completion.rs:110:28
> > >       |
> > >   110 |         unsafe { bindings::wait_for_completion(self.as_raw()) };
> > >       |                            ^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `__wait_for_completion`
> > >       |
> > >      ::: /root/linux/rust/bindings/bindings_generated.rs:33440:5
> > >       |
> > > 33440 |     pub fn __wait_for_completion(arg1: *mut completion);
> > >       |     ---------------------------------------------------- similarly named function `__wait_for_completion` defined here
> > >
> > > error: aborting due to 1 previous error
> > >
> > > For more information about this error, try `rustc --explain E0425`.
> > > ```
> > >
> > 
> > I think Danilo already made it clear, please fold this the existing
> > patch. Moreover, since this patchset doesn't adjust init_completion()
> > from the Rust side, the result is Rust code will also use the same dept
> > key for completion, which has to be fixed if dept wants to be in-tree.
> 
> Thank you for informing that.  I will take a look on it.

It looks not easy unless Rust side uses explicit maps for that purpose.
I think there are the same issues in 'lockdep + typical lock' too.  How
does lockdep deal with the issue?  Use explicit keys for that?

	Byungchul

> 
> 	Byungchul
> > 
> > Regards,
> > Boqun
> > 
> > > Signed-off-by: Guangbo Cui <2407018371@qq.com>
> > > ---
> > >  rust/helpers/completion.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/rust/helpers/completion.c b/rust/helpers/completion.c
> > > index b2443262a2ae..5bae5e749def 100644
> > > --- a/rust/helpers/completion.c
> > > +++ b/rust/helpers/completion.c
> > > @@ -6,3 +6,8 @@ void rust_helper_init_completion(struct completion *x)
> > >  {
> > >       init_completion(x);
> > >  }
> > > +
> > > +void rust_helper_wait_for_completion(struct completion *x)
> > > +{
> > > +     wait_for_completion(x);
> > > +}
> > > --
> > > 2.43.0
> > >
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Miguel Ojeda 2 months, 2 weeks ago
On Thu, Oct 2, 2025 at 12:12 PM Guangbo Cui <2407018371@qq.com> wrote:
>
> The DEPT patch series changed `wait_for_completion` into a macro.

Thanks!

In general, it is useful to provide a Link: to Lore to the right patch
(i.e. context is good), and please clarify in which tree you found the
issue if any -- I don't see it in linux-next, so I imagine it is not
applied, but "changed" sounds like it was? If it was actually applied,
please also provide a Fixes: tag.

Cheers,
Miguel
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Guangbo Cui 2 months, 2 weeks ago
On Thu, Oct 02, 2025 at 12:39:44PM +0200, Miguel Ojeda wrote:
> issue if any -- I don't see it in linux-next, so I imagine it is not
> applied, but "changed" sounds like it was? If it was actually applied,
> please also provide a Fixes: tag.

Yeah, it's not applied yet, this should be squashed into [1].

Sorry, I forgot to check the commit message.

Thanks,
Guangbo

[1] https://lore.kernel.org/all/20251002081247.51255-37-byungchul@sk.com/
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Danilo Krummrich 2 months, 2 weeks ago
On Thu Oct 2, 2025 at 12:06 PM CEST, Guangbo Cui wrote:
> The DEPT patch series changed `wait_for_completion` into a macro.
> Because bindgen cannot handle function-like macros, this caused
> Rust build errors. Add a helper function to fix it.

Good catch!

Given that the latest version of this series was just posted, please squash this
fix into patch "dept: assign unique dept_key to each distinct
wait_for_completion() caller" [1].

Thanks,
Danilo

[1] https://lore.kernel.org/all/20251002081247.51255-37-byungchul@sk.com/
Re: [PATCH] rust: bindings: add `rust_helper_wait_for_completion` helper function
Posted by Byungchul Park 1 month ago
On Thu, Oct 02, 2025 at 12:27:53PM +0200, Danilo Krummrich wrote:
> On Thu Oct 2, 2025 at 12:06 PM CEST, Guangbo Cui wrote:
> > The DEPT patch series changed `wait_for_completion` into a macro.
> > Because bindgen cannot handle function-like macros, this caused
> > Rust build errors. Add a helper function to fix it.
> 
> Good catch!
> 
> Given that the latest version of this series was just posted, please squash this
> fix into patch "dept: assign unique dept_key to each distinct
> wait_for_completion() caller" [1].

Thank you all.  I will squash this into the patch.  Thanks again!

	Byungchul
> 
> Thanks,
> Danilo
> 
> [1] https://lore.kernel.org/all/20251002081247.51255-37-byungchul@sk.com/