Re: IORING_SETUP_ATTACH_WQ (was Re: [PATCH 1/3] io_uring: fix invalid ctx->sq_thread_idle)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jens,

> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 6c62a3c95c1a..9a732b3b39fa 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -269,6 +269,7 @@ struct io_sq_data {
>  	unsigned		sq_thread_idle;
>  	int			sq_cpu;
>  	pid_t			task_pid;
> +	pid_t			task_tgid;
>  
>  	unsigned long		state;
>  	struct completion	startup;
> @@ -7081,6 +7082,10 @@ static struct io_sq_data *io_attach_sq_data(struct io_uring_params *p)
>  		fdput(f);
>  		return ERR_PTR(-EINVAL);
>  	}
> +	if (sqd->task_tgid != current->tgid) {
> +		fdput(f);
> +		return ERR_PTR(-EPERM);
> +	}
>  
>  	refcount_inc(&sqd->refs);
>  	fdput(f);
> @@ -7091,8 +7096,14 @@ static struct io_sq_data *io_get_sq_data(struct io_uring_params *p)
>  {
>  	struct io_sq_data *sqd;
>  
> -	if (p->flags & IORING_SETUP_ATTACH_WQ)
> -		return io_attach_sq_data(p);
> +	if (p->flags & IORING_SETUP_ATTACH_WQ) {
> +		sqd = io_attach_sq_data(p);
> +		if (!IS_ERR(sqd))
> +			return sqd;
> +		/* fall through for EPERM case, setup new sqd/task */
> +		if (PTR_ERR(sqd) != -EPERM)
> +			return sqd;
> +	}
>  
>  	sqd = kzalloc(sizeof(*sqd), GFP_KERNEL);
>  	if (!sqd)
> @@ -7793,6 +7804,7 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
>  		}
>  
>  		sqd->task_pid = current->pid;
> +		sqd->task_tgid = current->tgid;
>  		tsk = create_io_thread(io_sq_thread, sqd, NUMA_NO_NODE);
>  		if (IS_ERR(tsk)) {
>  			ret = PTR_ERR(tsk);
> 

Ok, that looks nice and simple, thanks!

metze



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux