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 193671D14E4; Wed, 2 Oct 2024 14:29:01 +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=1727879341; cv=none; b=stMo4vuk9Y6OdymKLr0Edm7912h6bT1ZXh528kZYzhLZ0Xm9NzSmrPpJWElGAHTPVKLxkueIaHp9sFu2fRmq9+ammBUirVpf2LFyoeu5btLlKlnrlMvvNvuQJf2n4IAfSUIrXGmaAsC5/ec5nLjNs1emm59FC3dizPHfYwNyLwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727879341; c=relaxed/simple; bh=COJ6NTSN5Bll5eHR6U5XU5erXFDUeqK8BXyTTMXrhss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j2edEr3kGyvyjl+7Ze5CH5Vbd9UGnhlubfezO9D3roDCQStT24H8+xVTZ5TN/nEsu644ryZFd20eOZUCB5YCF8TsyrYqLtlhdqPPNfTw0NZWK+NAYtwm72fvRDjenWv6DOlUyF9f4QMLqucwy5z0CwGe7Hi9bWC1FtKocKU9N7c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GVlJKdxD; 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="GVlJKdxD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9697DC4CEC2; Wed, 2 Oct 2024 14:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1727879341; bh=COJ6NTSN5Bll5eHR6U5XU5erXFDUeqK8BXyTTMXrhss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GVlJKdxD0GUCx4DG9P7TnWqvGXTo+mg9LfRjxKWfFhLWM5aaubSlhq4/6BIxAAlMD /xtNK9pzJjee8ADuTUUPPiIsZazpO46RDRcr1nDpPYAu0rA3KeSq6XMLWLa3dojjhX D8hWq4qhgZNE9otsmGj8LS0UEzUMc4zvqs2TMNAE= 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.6 085/538] io_uring/io-wq: do not allow pinning outside of cpuset Date: Wed, 2 Oct 2024 14:55:24 +0200 Message-ID: <20241002125755.577082180@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241002125751.964700919@linuxfoundation.org> References: <20241002125751.964700919@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 98c9cfb983062..2df8d98738498 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1324,17 +1325,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