From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 657F91D0434; Wed, 2 Oct 2024 13:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727875521; cv=none; b=Dy1NX03zoidmuBCJ6SARvAAPZleWblNP/XXgnb6itdemNZutvU7pt/a7olf6cUPmtNx17R4TmLreAQq6Pe7zo15t0Le9yhjvudxiETgMjCn865FuK25WZU/L4MixV6ecCNpdBe1UKHXG+W/VO0EoeqBms9fw9LX2bG1gRS8Zfsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727875521; c=relaxed/simple; bh=3hszm5FnksqC6og8//xjhTgJ1qzomznNxwnG7/Vud3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gqRpvSW/IItW2H1LR9fD+T5e5D2oAb85Hy4esKvz5D/Z67ptI/0QfXpVwdFuO60nMQa4IueaeqTSnmmoVyr9OPMJuPPvNiy8iDIMMXKd9zPrhWgQf60dUiNKdFGKvJXJdTUpsgTYXI5DrWYSPeakwzsZtEVLvtXkE4UyzJG3GvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pFylxZ9y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pFylxZ9y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C1F0C4CEC5; Wed, 2 Oct 2024 13:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1727875521; bh=3hszm5FnksqC6og8//xjhTgJ1qzomznNxwnG7/Vud3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pFylxZ9y4E55ypFDcDuFl/v2q1bExl4wiy1c0ZmQfUQ4wSf6BROA1qfFTt1m/WKcT L1Pc+2tyCJcHS8SqgGD83rMJkgSYuG1TjbBvblKgtCHhpbPdxY2zNkx15fJOZA7qSE Rle0Q6ArcKd7liEnpG06vfL92BwLRTs5+yKtQmj8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Felix Moessbauer , Jens Axboe , Sasha Levin Subject: [PATCH 6.11 130/695] io_uring/io-wq: do not allow pinning outside of cpuset Date: Wed, 2 Oct 2024 14:52:08 +0200 Message-ID: <20241002125827.667261592@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241002125822.467776898@linuxfoundation.org> References: <20241002125822.467776898@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.11-stable review patch. If anyone has any objections, please let me know. ------------------ From: Felix Moessbauer [ Upstream commit 0997aa5497c714edbb349ca366d28bd550ba3408 ] 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 Link: https://lore.kernel.org/r/20240910171157.166423-2-felix.moessbauer@siemens.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- 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 f1e7c670add85..c7055a8895d7e 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, struct hlist_node *node) int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask) { + cpumask_var_t allowed_mask; + int ret = 0; + if (!tctx || !tctx->io_wq) return -EINVAL; + 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 = -EINVAL; + } else { + cpumask_copy(tctx->io_wq->cpu_mask, allowed_mask); + } rcu_read_unlock(); - return 0; + free_cpumask_var(allowed_mask); + return ret; } /* -- 2.43.0