mirror of
https://github.com/torvalds/linux.git
synced 2026-03-13 23:46:14 +01:00
for-6.7/io_uring-2023-10-30
-----BEGIN PGP SIGNATURE----- iQJEBAABCAAuFiEEwPw5LcreJtl1+l5K99NY+ylx4KYFAmU/vcMQHGF4Ym9lQGtl cm5lbC5kawAKCRD301j7KXHgpmnaD/4spcYjSSdeHVh3J60QuWjMYOM//E/BNb6e 3I2L6Is2RLuDGhVhHKfRfkJQy1UPKYKu5TZewUnwC3bz12kWGc8CZBF4WgM0159T 0uBm2ZtsstSCONA16tQdmE7gt5MJ6KFO0rsubm/AxNWxTnpyrbrX512TkkJTBrfC ZluAKxGviZOcrl9ROoVMc/FeMmaKVcT79mDuLp0y+Pmb2KO3y9bWTs/wpmEPNVro P7n/j9B4dBQC3Saij/wCdcsodkHUaCfCnRK3g34JKeACb+Kclg7QSzinb3TZjeEw o98l1XMiejkPJDIxYmWPTmdzqu6AUnT3Geq6eL463/PUOjgkzet6idYfk6XQgRyz AhFzA6KruMJ+IhOs974KtmDJj+7LbGkMUpW0kEqKWpXFEO2t+yG6Ue4cdC2FtsqV m/ojTTeejVqJ1RLng9IqVMT/X6sqpTtBOikNIJeWyDZQGpOOBxkG9qyoYxNQTOAr 280UwcFMgsRDQMpi9uIsc7uE7QvN/RYL9nqm49bxJTRm/sRsABPb71yWcbrHSAjh y2tprYqG0V4qK7ogCiqDt8qdq/nZS6d1mN/th33yGAHtWEStTyFKNuYmPOrzLtWb tvnmYGA7YxcpSMEPHQbYG5TlmoWoTlzUlwJ1OWGzqdlPw7USCwjFfTZVJuKm6wkR u0uTkYhn4A== =okQ8 -----END PGP SIGNATURE----- Merge tag 'for-6.7/io_uring-2023-10-30' of git://git.kernel.dk/linux Pull io_uring updates from Jens Axboe: "This contains the core io_uring updates, of which there are not many, and adds support for using WAITID through io_uring and hence not needing to block on these kinds of events. Outside of that, tweaks to the legacy provided buffer handling and some cleanups related to cancelations for uring_cmd support" * tag 'for-6.7/io_uring-2023-10-30' of git://git.kernel.dk/linux: io_uring/poll: use IOU_F_TWQ_LAZY_WAKE for wakeups io_uring/kbuf: Use slab for struct io_buffer objects io_uring/kbuf: Allow the full buffer id space for provided buffers io_uring/kbuf: Fix check of BID wrapping in provided buffers io_uring/rsrc: cleanup io_pin_pages() io_uring: cancelable uring_cmd io_uring: retain top 8bits of uring_cmd flags for kernel internal use io_uring: add IORING_OP_WAITID support exit: add internal include file with helpers exit: add kernel_waitid_prepare() helper exit: move core of do_wait() into helper exit: abstract out should_wake helper for child_wait_callback() io_uring/rw: add support for IORING_OP_READ_MULTISHOT io_uring/rw: mark readv/writev as vectored in the opcode definition io_uring/rw: split io_read() into a helper
This commit is contained in:
commit
ffa059b262
19 changed files with 783 additions and 121 deletions
131
kernel/exit.c
131
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,6 +1502,17 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk)
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p)
|
||||
{
|
||||
if (!eligible_pid(wo, p))
|
||||
return false;
|
||||
|
||||
if ((wo->wo_flags & __WNOTHREAD) && wo->child_wait.private != p->parent)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int child_wait_callback(wait_queue_entry_t *wait, unsigned mode,
|
||||
int sync, void *key)
|
||||
{
|
||||
|
|
@ -1527,13 +1520,10 @@ static int child_wait_callback(wait_queue_entry_t *wait, unsigned mode,
|
|||
child_wait);
|
||||
struct task_struct *p = key;
|
||||
|
||||
if (!eligible_pid(wo, p))
|
||||
return 0;
|
||||
if (pid_child_should_wake(wo, p))
|
||||
return default_wake_function(wait, mode, sync, key);
|
||||
|
||||
if ((wo->wo_flags & __WNOTHREAD) && wait->private != p->parent)
|
||||
return 0;
|
||||
|
||||
return default_wake_function(wait, mode, sync, key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __wake_up_parent(struct task_struct *p, struct task_struct *parent)
|
||||
|
|
@ -1582,16 +1572,10 @@ 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)
|
||||
{
|
||||
int retval;
|
||||
long retval;
|
||||
|
||||
trace_sched_process_wait(wo->wo_pid);
|
||||
|
||||
init_waitqueue_func_entry(&wo->child_wait, child_wait_callback);
|
||||
wo->child_wait.private = current;
|
||||
add_wait_queue(¤t->signal->wait_chldexit, &wo->child_wait);
|
||||
repeat:
|
||||
/*
|
||||
* If there is nothing that can match our criteria, just get out.
|
||||
* We will clear ->notask_error to zero if we see any child that
|
||||
|
|
@ -1603,24 +1587,23 @@ repeat:
|
|||
(!wo->wo_pid || !pid_has_task(wo->wo_pid, wo->wo_type)))
|
||||
goto notask;
|
||||
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
read_lock(&tasklist_lock);
|
||||
|
||||
if (wo->wo_type == PIDTYPE_PID) {
|
||||
retval = do_wait_pid(wo);
|
||||
if (retval)
|
||||
goto end;
|
||||
return retval;
|
||||
} else {
|
||||
struct task_struct *tsk = current;
|
||||
|
||||
do {
|
||||
retval = do_wait_thread(wo, tsk);
|
||||
if (retval)
|
||||
goto end;
|
||||
return retval;
|
||||
|
||||
retval = ptrace_do_wait(wo, tsk);
|
||||
if (retval)
|
||||
goto end;
|
||||
return retval;
|
||||
|
||||
if (wo->wo_flags & __WNOTHREAD)
|
||||
break;
|
||||
|
|
@ -1630,27 +1613,44 @@ repeat:
|
|||
|
||||
notask:
|
||||
retval = wo->notask_error;
|
||||
if (!retval && !(wo->wo_flags & WNOHANG)) {
|
||||
retval = -ERESTARTSYS;
|
||||
if (!signal_pending(current)) {
|
||||
schedule();
|
||||
goto repeat;
|
||||
}
|
||||
}
|
||||
end:
|
||||
if (!retval && !(wo->wo_flags & WNOHANG))
|
||||
return -ERESTARTSYS;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static long do_wait(struct wait_opts *wo)
|
||||
{
|
||||
int retval;
|
||||
|
||||
trace_sched_process_wait(wo->wo_pid);
|
||||
|
||||
init_waitqueue_func_entry(&wo->child_wait, child_wait_callback);
|
||||
wo->child_wait.private = current;
|
||||
add_wait_queue(¤t->signal->wait_chldexit, &wo->child_wait);
|
||||
|
||||
do {
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
retval = __do_wait(wo);
|
||||
if (retval != -ERESTARTSYS)
|
||||
break;
|
||||
if (signal_pending(current))
|
||||
break;
|
||||
schedule();
|
||||
} while (1);
|
||||
|
||||
__set_current_state(TASK_RUNNING);
|
||||
remove_wait_queue(¤t->signal->wait_chldexit, &wo->child_wait);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
|
||||
int options, struct rusage *ru)
|
||||
int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
|
||||
struct waitid_info *infop, int options,
|
||||
struct rusage *ru)
|
||||
{
|
||||
struct wait_opts wo;
|
||||
unsigned int f_flags = 0;
|
||||
struct pid *pid = NULL;
|
||||
enum pid_type type;
|
||||
long ret;
|
||||
unsigned int f_flags = 0;
|
||||
|
||||
if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED|
|
||||
__WNOTHREAD|__WCLONE|__WALL))
|
||||
|
|
@ -1693,19 +1693,32 @@ static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
wo.wo_type = type;
|
||||
wo.wo_pid = pid;
|
||||
wo.wo_flags = options;
|
||||
wo.wo_info = infop;
|
||||
wo.wo_rusage = ru;
|
||||
wo->wo_type = type;
|
||||
wo->wo_pid = pid;
|
||||
wo->wo_flags = options;
|
||||
wo->wo_info = infop;
|
||||
wo->wo_rusage = ru;
|
||||
if (f_flags & O_NONBLOCK)
|
||||
wo.wo_flags |= WNOHANG;
|
||||
wo->wo_flags |= WNOHANG;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
|
||||
int options, struct rusage *ru)
|
||||
{
|
||||
struct wait_opts wo;
|
||||
long ret;
|
||||
|
||||
ret = kernel_waitid_prepare(&wo, which, upid, infop, options, ru);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = do_wait(&wo);
|
||||
if (!ret && !(options & WNOHANG) && (f_flags & O_NONBLOCK))
|
||||
if (!ret && !(options & WNOHANG) && (wo.wo_flags & WNOHANG))
|
||||
ret = -EAGAIN;
|
||||
|
||||
put_pid(pid);
|
||||
put_pid(wo.wo_pid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
30
kernel/exit.h
Normal file
30
kernel/exit.h
Normal file
|
|
@ -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);
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue