diff mbox series

[4/5] exit: add internal include file with helpers

Message ID 20230711204352.214086-5-axboe@kernel.dk (mailing list archive)
State New
Headers show
Series Add io_uring support for waitid | expand

Commit Message

Jens Axboe July 11, 2023, 8:43 p.m. UTC
Move struct wait_opts and waitid_info into kernel/exit.h, and include
function declarations for the recently added helpers. Make them
non-static as well.

This is in preparation for adding a waitid operation through io_uring.
With the abtracted helpers, this is now possible.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 kernel/exit.c | 32 +++++++-------------------------
 kernel/exit.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 25 deletions(-)
 create mode 100644 kernel/exit.h

Comments

Christian Brauner July 14, 2023, 3:38 p.m. UTC | #1
On Tue, Jul 11, 2023 at 02:43:51PM -0600, Jens Axboe wrote:
> Move struct wait_opts and waitid_info into kernel/exit.h, and include
> function declarations for the recently added helpers. Make them
> non-static as well.
> 
> This is in preparation for adding a waitid operation through io_uring.
> With the abtracted helpers, this is now possible.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>  kernel/exit.c | 32 +++++++-------------------------
>  kernel/exit.h | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 37 insertions(+), 25 deletions(-)
>  create mode 100644 kernel/exit.h
> 
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 8934c91a9fe1..1c9d1cbadcd0 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -74,6 +74,8 @@
>  #include <asm/unistd.h>
>  #include <asm/mmu_context.h>
>  
> +#include "exit.h"
> +
>  /*
>   * The default value should be high enough to not crash a system that randomly
>   * crashes its kernel from time to time, but low enough to at least not permit
> @@ -1037,26 +1039,6 @@ SYSCALL_DEFINE1(exit_group, int, error_code)
>  	return 0;
>  }
>  
> -struct waitid_info {
> -	pid_t pid;
> -	uid_t uid;
> -	int status;
> -	int cause;
> -};
> -
> -struct wait_opts {
> -	enum pid_type		wo_type;
> -	int			wo_flags;
> -	struct pid		*wo_pid;
> -
> -	struct waitid_info	*wo_info;
> -	int			wo_stat;
> -	struct rusage		*wo_rusage;
> -
> -	wait_queue_entry_t		child_wait;
> -	int			notask_error;
> -};
> -
>  static int eligible_pid(struct wait_opts *wo, struct task_struct *p)
>  {
>  	return	wo->wo_type == PIDTYPE_MAX ||
> @@ -1520,7 +1502,7 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk)
>  	return 0;
>  }
>  
> -static bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p)
> +bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p)
>  {
>  	if (!eligible_pid(wo, p))
>  		return false;
> @@ -1590,7 +1572,7 @@ static int do_wait_pid(struct wait_opts *wo)
>  	return 0;
>  }
>  
> -static long __do_wait(struct wait_opts *wo)
> +long __do_wait(struct wait_opts *wo)
>  {
>  	long retval;
>  
> @@ -1662,9 +1644,9 @@ static long do_wait(struct wait_opts *wo)
>  	return retval;
>  }
>  
> -static int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
> -				 struct waitid_info *infop, int options,
> -				 struct rusage *ru, unsigned int *f_flags)
> +int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
> +			  struct waitid_info *infop, int options,
> +			  struct rusage *ru, unsigned int *f_flags)
>  {
>  	struct pid *pid = NULL;
>  	enum pid_type type;
> diff --git a/kernel/exit.h b/kernel/exit.h
> new file mode 100644
> index 000000000000..f10207ba1341
> --- /dev/null
> +++ b/kernel/exit.h
> @@ -0,0 +1,30 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +#ifndef LINUX_WAITID_H
> +#define LINUX_WAITID_H
> +
> +struct waitid_info {
> +	pid_t pid;
> +	uid_t uid;
> +	int status;
> +	int cause;
> +};
> +
> +struct wait_opts {
> +	enum pid_type		wo_type;
> +	int			wo_flags;
> +	struct pid		*wo_pid;
> +
> +	struct waitid_info	*wo_info;
> +	int			wo_stat;
> +	struct rusage		*wo_rusage;
> +
> +	wait_queue_entry_t		child_wait;
> +	int			notask_error;
> +};
> +
> +bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p);
> +long __do_wait(struct wait_opts *wo);
> +int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
> +			  struct waitid_info *infop, int options,
> +			  struct rusage *ru, unsigned int *f_flags);

I know this isn't your mess obviously but could you try and see whether
you can expose a nicer, dedicated struct and helper suited to io_uring's
needs instead of exposing the messy kernel/exit.c format?
Jens Axboe July 14, 2023, 8:16 p.m. UTC | #2
On 7/14/23 9:38?AM, Christian Brauner wrote:
>> diff --git a/kernel/exit.h b/kernel/exit.h
>> new file mode 100644
>> index 000000000000..f10207ba1341
>> --- /dev/null
>> +++ b/kernel/exit.h
>> @@ -0,0 +1,30 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +#ifndef LINUX_WAITID_H
>> +#define LINUX_WAITID_H
>> +
>> +struct waitid_info {
>> +	pid_t pid;
>> +	uid_t uid;
>> +	int status;
>> +	int cause;
>> +};
>> +
>> +struct wait_opts {
>> +	enum pid_type		wo_type;
>> +	int			wo_flags;
>> +	struct pid		*wo_pid;
>> +
>> +	struct waitid_info	*wo_info;
>> +	int			wo_stat;
>> +	struct rusage		*wo_rusage;
>> +
>> +	wait_queue_entry_t		child_wait;
>> +	int			notask_error;
>> +};
>> +
>> +bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p);
>> +long __do_wait(struct wait_opts *wo);
>> +int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
>> +			  struct waitid_info *infop, int options,
>> +			  struct rusage *ru, unsigned int *f_flags);
> 
> I know this isn't your mess obviously but could you try and see whether
> you can expose a nicer, dedicated struct and helper suited to io_uring's
> needs instead of exposing the messy kernel/exit.c format?

From a quick look, I think the wait_opts is pretty much what we need,
not much to cut from that. For waitid_info, we can make do with just a
forward declaration, we don't need the whole thing.
Jens Axboe July 14, 2023, 8:21 p.m. UTC | #3
On 7/14/23 2:16?PM, Jens Axboe wrote:
> On 7/14/23 9:38?AM, Christian Brauner wrote:
>>> diff --git a/kernel/exit.h b/kernel/exit.h
>>> new file mode 100644
>>> index 000000000000..f10207ba1341
>>> --- /dev/null
>>> +++ b/kernel/exit.h
>>> @@ -0,0 +1,30 @@
>>> +// SPDX-License-Identifier: GPL-2.0-only
>>> +#ifndef LINUX_WAITID_H
>>> +#define LINUX_WAITID_H
>>> +
>>> +struct waitid_info {
>>> +	pid_t pid;
>>> +	uid_t uid;
>>> +	int status;
>>> +	int cause;
>>> +};
>>> +
>>> +struct wait_opts {
>>> +	enum pid_type		wo_type;
>>> +	int			wo_flags;
>>> +	struct pid		*wo_pid;
>>> +
>>> +	struct waitid_info	*wo_info;
>>> +	int			wo_stat;
>>> +	struct rusage		*wo_rusage;
>>> +
>>> +	wait_queue_entry_t		child_wait;
>>> +	int			notask_error;
>>> +};
>>> +
>>> +bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p);
>>> +long __do_wait(struct wait_opts *wo);
>>> +int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
>>> +			  struct waitid_info *infop, int options,
>>> +			  struct rusage *ru, unsigned int *f_flags);
>>
>> I know this isn't your mess obviously but could you try and see whether
>> you can expose a nicer, dedicated struct and helper suited to io_uring's
>> needs instead of exposing the messy kernel/exit.c format?
> 
> From a quick look, I think the wait_opts is pretty much what we need,
> not much to cut from that. For waitid_info, we can make do with just a
> forward declaration, we don't need the whole thing.

I'm wrong obviously, we do need waitid_info as well as that is the
output side... Seems to me that none of them have anything redundant wrt
io_uring. They could be combined into one thing, but is it worth it?
diff mbox series

Patch

diff --git a/kernel/exit.c b/kernel/exit.c
index 8934c91a9fe1..1c9d1cbadcd0 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -74,6 +74,8 @@ 
 #include <asm/unistd.h>
 #include <asm/mmu_context.h>
 
+#include "exit.h"
+
 /*
  * The default value should be high enough to not crash a system that randomly
  * crashes its kernel from time to time, but low enough to at least not permit
@@ -1037,26 +1039,6 @@  SYSCALL_DEFINE1(exit_group, int, error_code)
 	return 0;
 }
 
-struct waitid_info {
-	pid_t pid;
-	uid_t uid;
-	int status;
-	int cause;
-};
-
-struct wait_opts {
-	enum pid_type		wo_type;
-	int			wo_flags;
-	struct pid		*wo_pid;
-
-	struct waitid_info	*wo_info;
-	int			wo_stat;
-	struct rusage		*wo_rusage;
-
-	wait_queue_entry_t		child_wait;
-	int			notask_error;
-};
-
 static int eligible_pid(struct wait_opts *wo, struct task_struct *p)
 {
 	return	wo->wo_type == PIDTYPE_MAX ||
@@ -1520,7 +1502,7 @@  static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk)
 	return 0;
 }
 
-static bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p)
+bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p)
 {
 	if (!eligible_pid(wo, p))
 		return false;
@@ -1590,7 +1572,7 @@  static int do_wait_pid(struct wait_opts *wo)
 	return 0;
 }
 
-static long __do_wait(struct wait_opts *wo)
+long __do_wait(struct wait_opts *wo)
 {
 	long retval;
 
@@ -1662,9 +1644,9 @@  static long do_wait(struct wait_opts *wo)
 	return retval;
 }
 
-static int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
-				 struct waitid_info *infop, int options,
-				 struct rusage *ru, unsigned int *f_flags)
+int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
+			  struct waitid_info *infop, int options,
+			  struct rusage *ru, unsigned int *f_flags)
 {
 	struct pid *pid = NULL;
 	enum pid_type type;
diff --git a/kernel/exit.h b/kernel/exit.h
new file mode 100644
index 000000000000..f10207ba1341
--- /dev/null
+++ b/kernel/exit.h
@@ -0,0 +1,30 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+#ifndef LINUX_WAITID_H
+#define LINUX_WAITID_H
+
+struct waitid_info {
+	pid_t pid;
+	uid_t uid;
+	int status;
+	int cause;
+};
+
+struct wait_opts {
+	enum pid_type		wo_type;
+	int			wo_flags;
+	struct pid		*wo_pid;
+
+	struct waitid_info	*wo_info;
+	int			wo_stat;
+	struct rusage		*wo_rusage;
+
+	wait_queue_entry_t		child_wait;
+	int			notask_error;
+};
+
+bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p);
+long __do_wait(struct wait_opts *wo);
+int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
+			  struct waitid_info *infop, int options,
+			  struct rusage *ru, unsigned int *f_flags);
+#endif