From nobody Sat Nov 30 07:27:24 2024 Received: from mta-65-226.siemens.flowmailer.net (mta-65-226.siemens.flowmailer.net [185.136.65.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72396195FEC for ; Tue, 10 Sep 2024 15:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.136.65.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725983154; cv=none; b=dS5W4CN2KD7o/kx/RKCt8S9AVEO7+vHMfMt4qxw+UL/h7P0pKXYCxdJ8dbO5KXngOVhdvuMYmuBnn3f+QWBgyy0rhJ5yp3HxqBHBDKhj56tPabXYQd4/jMIU8n61TmNx/8lyeJkzXknbEMOaEAgFiShY8QKnGnOvGClf8EFVoV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725983154; c=relaxed/simple; bh=gEr1cCpObgM8xPbCaVvgWMgIX9dT3M9/NLL3bHUSkQ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=meLtpWhDKJ7EP7DO946cY+aVNcHPUal/LlUUt66sJyp0J3ipXnqPjjgHBtzFBqcvmOI6jIUQZNJ0fxNiPSWVM5dfsb8qzFPh4duXWQuRWdZ8zCFfFcIv6I10vfSpDqR62SRnC6UNPhBRi7wJk347A+w89sQggICWueDIIBjtDxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com; dkim=pass (2048-bit key) header.d=siemens.com header.i=felix.moessbauer@siemens.com header.b=fQIiUeoN; arc=none smtp.client-ip=185.136.65.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=siemens.com header.i=felix.moessbauer@siemens.com header.b="fQIiUeoN" Received: by mta-65-226.siemens.flowmailer.net with ESMTPSA id 20240910154548bdc64baceeee3af79a for ; Tue, 10 Sep 2024 17:45:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=felix.moessbauer@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=V02Mv7Qi+O8u5o24OCWYd+wHeSgI3uHzoIbW8MTflmc=; b=fQIiUeoNAW+Q6pb2ZUhgOnWMDuLe/QcfMkc7XUkr2GxbQ55+yc93eNRLxZ9Q24aXzU2MK6 oICVy6iT+qAKJxtxFBYIpS0saomc5V53ErKuN2C6xXr5RqqRbYwuRH21z20fAJNTiCXOUdMp NOv5j+ZOaxPBynHlxKPlkl9EXoqI1SFHWrI38xuU+oeaMo5QqBLJSisZKRl7tJR4/0cb2hUx wMxaYKgGu0ZkENGw+ec5IVZRKTdLNhNe35RQN4IJse8XSaI1/CT/JJw2eSkz3w8VUchyaa+5 xRMl8fJh4rq4cPvS9m8udbJ0QEWYXVuq6mUJ5ekVbYnEkMUi83zr0peQ==; From: Felix Moessbauer To: axboe@kernel.dk Cc: asml.silence@gmail.com, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, cgroups@vger.kernel.org, dqminh@cloudflare.com, longman@redhat.com, adriaan.schmidt@siemens.com, florian.bezdeka@siemens.com, Felix Moessbauer Subject: [PATCH v2 1/2] io_uring/io-wq: do not allow pinning outside of cpuset Date: Tue, 10 Sep 2024 17:45:34 +0200 Message-Id: <20240910154535.140587-2-felix.moessbauer@siemens.com> In-Reply-To: <20240910154535.140587-1-felix.moessbauer@siemens.com> References: <20240910154535.140587-1-felix.moessbauer@siemens.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-1321639:519-21489:flowmailer Content-Type: text/plain; charset="utf-8" The io worker threads are userland threads that just never exit to the userland. By that, they are also assigned to a cgroup (the group of the creating task). When changing the affinity of the io_wq thread via syscall, we must only allow cpumasks within the limits defined by the cpuset controller of the cgroup (if enabled). Fixes: da64d6db3bd3 ("io_uring: One wqe per wq") Signed-off-by: Felix Moessbauer --- io_uring/io-wq.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index f1e7c670add8..c7055a8895d7 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1322,17 +1323,29 @@ static int io_wq_cpu_offline(unsigned int cpu, stru= ct hlist_node *node) =20 int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask) { + cpumask_var_t allowed_mask; + int ret =3D 0; + if (!tctx || !tctx->io_wq) return -EINVAL; =20 + if (!alloc_cpumask_var(&allowed_mask, GFP_KERNEL)) + return -ENOMEM; + rcu_read_lock(); - if (mask) - cpumask_copy(tctx->io_wq->cpu_mask, mask); - else - cpumask_copy(tctx->io_wq->cpu_mask, cpu_possible_mask); + cpuset_cpus_allowed(tctx->io_wq->task, allowed_mask); + if (mask) { + if (cpumask_subset(mask, allowed_mask)) + cpumask_copy(tctx->io_wq->cpu_mask, mask); + else + ret =3D -EINVAL; + } else { + cpumask_copy(tctx->io_wq->cpu_mask, allowed_mask); + } rcu_read_unlock(); =20 - return 0; + free_cpumask_var(allowed_mask); + return ret; } =20 /* --=20 2.39.2 From nobody Sat Nov 30 07:27:24 2024 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1532191F9B for ; Tue, 10 Sep 2024 15:45:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.136.64.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725983155; cv=none; b=J96jK6lCpy6dWiATHLo43UdXjZjU7JL4XdIU2Vl1S1J47Bj4WQwGs5lzoGxlE5GocqMqSdwMsQxbzEwHJnGMzZ8HxWjvrNGmI2+bLTDTf1UFtCoYSXdixLZNp6zX3DcVeQl3qIJSkVrjSYsEm+xH8wKN5pO8EDWiRUPMxMs0P6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725983155; c=relaxed/simple; bh=XfiVCwa2jWEk1M2MkT7rHET2smIjIcH+WkT+Wy9VZlY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sGr0DJ/QYZjV9WO1C0RtR3BjuopF17bX8AEuN04iaWcXor+fGoSuUGXIsGZR29ehTC0dijUUy1twD5+YGlB262peuyJuB7kxxum4nMxMAIR4hGEncXTkzAdW0uUwd4t0rMuvMxbI35jCWSIoHuauabJSZaQHyuOZO5ZIEviPaNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com; dkim=pass (2048-bit key) header.d=siemens.com header.i=felix.moessbauer@siemens.com header.b=Ik78f7wt; arc=none smtp.client-ip=185.136.64.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=siemens.com header.i=felix.moessbauer@siemens.com header.b="Ik78f7wt" Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 2024091015454942d4547f196d13fe5d for ; Tue, 10 Sep 2024 17:45:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=felix.moessbauer@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=Pv5z/hfaIXxpRwvFKBnqkGUSEgP+MIm2v5ejiY+wuV0=; b=Ik78f7wtiBD0rOCSY3FlwmeymJPjjk6l2dJN2ffdzCk3EfXxPugoMsw9Wzt4y4+JCowQ+E 1JB58XpIGdhdQ7/hvwlwJ8pPayTY5ev6JqjHQoD/1/3zixJXe6O7dybaSAi8z/iyWUN5fuaw OokSQXEtJ6n7DMLwF4slJPl4y52UR/aYnp+WEo/xcfzMhQmluYGpIgvdB1bupCCu5Dxv3/sl HBO4wgDl8TpwOcSsD1gAevl2MJDDpSRdzHF31lShi0YdFoDfEb6umsrvbfgGeG3TykjDuZkx 0uoswQbfVjjuFA5venFb5/IstkdXC5D20KsiOGSgALp+JJgUiRZVqNTA==; From: Felix Moessbauer To: axboe@kernel.dk Cc: asml.silence@gmail.com, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, cgroups@vger.kernel.org, dqminh@cloudflare.com, longman@redhat.com, adriaan.schmidt@siemens.com, florian.bezdeka@siemens.com, Felix Moessbauer Subject: [PATCH v2 2/2] io_uring/io-wq: limit io poller cpuset to ambient one Date: Tue, 10 Sep 2024 17:45:35 +0200 Message-Id: <20240910154535.140587-3-felix.moessbauer@siemens.com> In-Reply-To: <20240910154535.140587-1-felix.moessbauer@siemens.com> References: <20240910154535.140587-1-felix.moessbauer@siemens.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-1321639:519-21489:flowmailer Content-Type: text/plain; charset="utf-8" The io worker threads are userland threads that just never exit to the userland. By that, they are also assigned to a cgroup (the group of the creating task). When creating a new io worker, this worker should inherit the cpuset of the cgroup. Fixes: da64d6db3bd3 ("io_uring: One wqe per wq") Signed-off-by: Felix Moessbauer --- io_uring/io-wq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index c7055a8895d7..a38f36b68060 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -1168,7 +1168,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct i= o_wq_data *data) =20 if (!alloc_cpumask_var(&wq->cpu_mask, GFP_KERNEL)) goto err; - cpumask_copy(wq->cpu_mask, cpu_possible_mask); + cpuset_cpus_allowed(data->task, wq->cpu_mask); wq->acct[IO_WQ_ACCT_BOUND].max_workers =3D bounded; wq->acct[IO_WQ_ACCT_UNBOUND].max_workers =3D task_rlimit(current, RLIMIT_NPROC); --=20 2.39.2