From nobody Sat Nov 30 07:45:19 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 913D717C22F for ; Tue, 10 Sep 2024 14:33:32 +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=1725978816; cv=none; b=jIMHVLrwHvJyebVmAWn9bd04AY2IjE7xQDDQvPAKnQhqI/TheVmcSB0r5QmsXgDy42wK2GqrWWGX1gakogbNFa3irCTUIaefRmwrmHvfa+412GHovBO4fUx6XRUYhjKvTkrRbhVv2426AizbD/oYvgnPuv6xRKVLAM4eaiMgXtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725978816; c=relaxed/simple; bh=JJ+DdDXeUJ6flbA+QfumePVA4yIjXcT651pOhkeHREY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WIJj9XR9jfYTiw4BWz/L7snK3nXquy1mpq0LA9O9gMGZg19mTewT1916Xwh9g3KhxmdvRUv+wDWNFjsmWN2lh0DD8IPKvLNp1Ch9DFj4nLQa0iTADNzJ5MI9Y961/mXV1eUAEkPsaXfSbBzjV9EyqSdFXyF1pMIWkCSUTxxDpwI= 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=Dc/KxDbE; 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="Dc/KxDbE" Received: by mta-65-226.siemens.flowmailer.net with ESMTPSA id 20240910143330a312320ffecac7d5d3 for ; Tue, 10 Sep 2024 16:33:30 +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=o/hbiqvNhfjZcBz7cNxNDB+PJkwANn7n0tH6iRSE4no=; b=Dc/KxDbEOSo2DKI8ACmHiQSlwWT61RF1uGFT9sYhRRNOdwVHf/bbGPezZV9ecoeaXbuIbN NdR2oyU9IHiA9dy6xbqMJBURHnN2LiCF7fFXzs/f6/YJuqYE88ZvpTSQ8jwlw8dZi0lwmhNy zoIxocgBUtKDpbkdutsE8ZgVyVtlqxTFwO/dm0NHhCpxbB6nM8/tTA/Qjzte3TPrneNu3+Bl JgUGoq9TKbNajrdUQg1vIhR4lh3pjeiwYTijej8AGl2Pnl0vHCTCKkTO9HH5REPUBs4ZHR/g DKIvMq6ZkqWLZB8LMrGou34+0PVj14Jxe82qFexknKiH7K3Fe7dydW/Q==; 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 1/2] io_uring/io-wq: do not allow pinning outside of cpuset Date: Tue, 10 Sep 2024 16:33:19 +0200 Message-Id: <20240910143320.123234-2-felix.moessbauer@siemens.com> In-Reply-To: <20240910143320.123234-1-felix.moessbauer@siemens.com> References: <20240910143320.123234-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 work queue polling 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 ambient limits. These are 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:45:19 2024 Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net [185.136.65.225]) (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 57A1F193096 for ; Tue, 10 Sep 2024 14:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.136.65.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725978816; cv=none; b=Bt+tyNXybRLDsHeACFtNYz44aLOAbEMftAD93nRZGUD0OJKViZFGwSZnmsbBBHdXRXFAhlR13D8FaseRzjdwb5rCkS7j0y0Juxg1O+8886oBcgE2Qjl8c0gue1ihOZRLudyyd40TuEjL8mP+uAoS0Nph5gs3d23eTk3AwNTNNss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725978816; c=relaxed/simple; bh=HdjpHHoNjYhBNqAxemQTKbJ7B8cX2tOtQLZrtAyVLgk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KCp0FKQ2tvNjPKgL0vbEl6Sx5gAvB67vsICOCB4PSBFfqLD+VdjZqrWEQ9fh7ZJpBhJQ7b/KUDuDvfPmj0IXJlHd0GM9gADgFRWJcZ1Hvw95wGw/rPuRDRL5fgtwe7eIH6jnf6968/MKnPMLAxkU8ZGN/HGy4xYOgpFuQp550DE= 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=aLjdWnrr; arc=none smtp.client-ip=185.136.65.225 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="aLjdWnrr" Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20240910143331298567b938e27cb3c7 for ; Tue, 10 Sep 2024 16:33:31 +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=n2V+rpn0MsoDnSoEFfdxd31DQiUD8YinS8WdnXxpaHA=; b=aLjdWnrraN9sTjU0K0JxfJEbsKlJHU3RGuyyvDTifxtBVtGcPAgQPicpqN0YzHzHMNJ0iN lvbbSUTFekouVMhaU5rxBl/04r1pz6SkK1jN6O3szNKQeuijZR75rb6vcDuOSQjThb3IJRt9 QdtrpimuBVImvEO2PW7IrNTV5dN8+n3IXfPzo7dCMuV2vGEga0ynWkQ0Wpve2woBBszaaYkd jJ4XOv/EQeJ6EmVMSgM8rw+QiE9DGVFOySl1bngfYbJ6tSuWVEVnZ4eeTwpuXKrmqvp2edmJ RuVIfHb6siZsDUpz1cVYDsl32kcXIm8IcYPv8FshZtB+OMtsW4OBvLxA==; 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 2/2] io_uring/io-wq: limit io poller cpuset to ambient one Date: Tue, 10 Sep 2024 16:33:20 +0200 Message-Id: <20240910143320.123234-3-felix.moessbauer@siemens.com> In-Reply-To: <20240910143320.123234-1-felix.moessbauer@siemens.com> References: <20240910143320.123234-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 work queue polling 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 poller, this poller should inherit the cpu limits of the cgroup, as it belongs to the cgroup of the creating task. 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