diff mbox series

[v3,1/1] io_uring/sqpoll: do not put cpumask on stack

Message ID 20240916111150.1266191-1-felix.moessbauer@siemens.com (mailing list archive)
State New
Headers show
Series [v3,1/1] io_uring/sqpoll: do not put cpumask on stack | expand

Commit Message

Felix Moessbauer Sept. 16, 2024, 11:11 a.m. UTC
Putting the cpumask on the stack is deprecated for a long time (since
2d3854a37e8), as these can be big. Given that, change the on-stack
allocation of allowed_mask to be dynamically allocated.

Fixes: f011c9cf04c0 ("io_uring/sqpoll: do not allow pinning outside of cpuset")
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
Changes since v2:

- reworded commit message
- make error checking consisten with pattern used in kernel
  @Jens: Thanks for guiding me and helping me to get this right.
  Much appreciated.

Changes since v1:

- don't leak mask in case CPU is not online or too big

Best regards,
Felix

 io_uring/sqpoll.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Jens Axboe Sept. 16, 2024, 1:49 p.m. UTC | #1
On Mon, 16 Sep 2024 13:11:50 +0200, Felix Moessbauer wrote:
> Putting the cpumask on the stack is deprecated for a long time (since
> 2d3854a37e8), as these can be big. Given that, change the on-stack
> allocation of allowed_mask to be dynamically allocated.
> 
> 

Applied, thanks!

[1/1] io_uring/sqpoll: do not put cpumask on stack
      commit: 7f44beadcc11adb98220556d2ddbe9c97aa6d42d

Best regards,
diff mbox series

Patch

diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 7adfcf6818ff..7c79685baeb1 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 (cpu >= nr_cpu_ids || !cpu_online(cpu))
 				goto err_sqpoll;
-			cpuset_cpus_allowed(current, &allowed_mask);
-			if (!cpumask_test_cpu(cpu, &allowed_mask))
+			ret = -ENOMEM;
+			if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL))
 				goto err_sqpoll;
+			ret = -EINVAL;
+			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;