public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring/sqpoll: do not put cpumask on stack
@ 2024-09-16 10:20 Felix Moessbauer
  2024-09-16 10:23 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Felix Moessbauer @ 2024-09-16 10:20 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, linux-kernel, Felix Moessbauer

Putting the cpumask on the stack is deprecated for a long time (since
2d3854a37e8), as the masks can be big. Given that, we port-over the
stack allocated mask to the cpumask allocation api.

Fixes: f011c9cf04c0 ("io_uring/sqpoll: do not allow pinning outside of cpuset")
Signed-off-by: Felix Moessbauer <[email protected]>
---
 io_uring/sqpoll.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 7adfcf6818ff..004740d6577e 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -461,15 +461,22 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
 			return 0;
 
 		if (p->flags & IORING_SETUP_SQ_AFF) {
-			struct cpumask allowed_mask;
+			cpumask_var_t allowed_mask;
 			int cpu = p->sq_thread_cpu;
 
 			ret = -EINVAL;
+			if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL)) {
+				ret = -ENOMEM;
+				goto err_sqpoll;
+			}
 			if (cpu >= nr_cpu_ids || !cpu_online(cpu))
 				goto err_sqpoll;
-			cpuset_cpus_allowed(current, &allowed_mask);
-			if (!cpumask_test_cpu(cpu, &allowed_mask))
+			cpuset_cpus_allowed(current, allowed_mask);
+			if (!cpumask_test_cpu(cpu, allowed_mask)) {
+				free_cpumask_var(allowed_mask);
 				goto err_sqpoll;
+			}
+			free_cpumask_var(allowed_mask);
 			sqd->sq_cpu = cpu;
 		} else {
 			sqd->sq_cpu = -1;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] io_uring/sqpoll: do not put cpumask on stack
  2024-09-16 10:20 [PATCH 1/1] io_uring/sqpoll: do not put cpumask on stack Felix Moessbauer
@ 2024-09-16 10:23 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2024-09-16 10:23 UTC (permalink / raw)
  To: Felix Moessbauer; +Cc: io-uring, linux-kernel

On 9/16/24 4:20 AM, Felix Moessbauer wrote:
> Putting the cpumask on the stack is deprecated for a long time (since
> 2d3854a37e8), as the masks can be big. Given that, we port-over the
> stack allocated mask to the cpumask allocation api.
> 
> Fixes: f011c9cf04c0 ("io_uring/sqpoll: do not allow pinning outside of cpuset")
> Signed-off-by: Felix Moessbauer <[email protected]>
> ---
>  io_uring/sqpoll.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
> index 7adfcf6818ff..004740d6577e 100644
> --- a/io_uring/sqpoll.c
> +++ b/io_uring/sqpoll.c
> @@ -461,15 +461,22 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
>  			return 0;
>  
>  		if (p->flags & IORING_SETUP_SQ_AFF) {
> -			struct cpumask allowed_mask;
> +			cpumask_var_t allowed_mask;
>  			int cpu = p->sq_thread_cpu;
>  
>  			ret = -EINVAL;
> +			if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL)) {
> +				ret = -ENOMEM;
> +				goto err_sqpoll;
> +			}
>  			if (cpu >= nr_cpu_ids || !cpu_online(cpu))
>  				goto err_sqpoll;

This leaks allowed_mask... Probably allocate this _after_ we've already
sanity checked the 'cpu' value itself.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-09-16 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-16 10:20 [PATCH 1/1] io_uring/sqpoll: do not put cpumask on stack Felix Moessbauer
2024-09-16 10:23 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox