Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3117929pxm; Mon, 28 Feb 2022 12:23:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNc9zEmc/wybmlIHaytXDg4EhSdz0XjU6XxhuGwEczBoDjNvSzhFZLcHWj5nLq/LsN0qrq X-Received: by 2002:a17:90b:19c7:b0:1bc:6002:7c5a with SMTP id nm7-20020a17090b19c700b001bc60027c5amr18657917pjb.179.1646079832921; Mon, 28 Feb 2022 12:23:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079832; cv=none; d=google.com; s=arc-20160816; b=lWyguO0c/YDutYPS1g2PJ70rj2D2bD970REDarlQisNzWuMjJKRk7tv+THIsoV8F4r eFQJn0e2+FOuVRpQAhA025JqSMIWQ+csYd45+Nqun7zbEmC20jCgeX2dZVHJ5ShYFBsM DMj4M0bUTF2HPXt0UaKKyeIQr6rFiGUwMDa6WgtEv/R+7GzoWVwFOaU4GvMJJOefiCZA d9clfsXDFjGb6ktpRubiibg60F1SefhjK/N/nMakoyEv9UDe3mHKOvU+DR8AK1/2J8Sg u+b5vX2SyvD/9LZctefpINxykaBrk46egoGKaz/ezcie1F7b4ckFEGpMr2TJSrCMefgo 2E3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J5qK97Si6iAL/v3SCDFsJaqk3NfjdomzqrxTobShV8M=; b=YFYoSURhZWXszhpsqN3sEgnJ27/yONkP7ul5Ofcr1gLkh7/SbUxLrfMmXJrFSOBsN8 Z6MNK9a/RE3kl5U/QgMx4Ed9gkxv+CXklQXydH5qGqYnCkqg0DcmRRGUUrvTgJQh5CKG gTBMEOMi1pVzRpuK+hCe+jULZ9uMNi802vdoXOTosMUSYmtNPHQ1di4gloa3wUgF/FlL LyHNVYnyefukOTBwypd0zUbNag4cvuAetqWQ+1RNfrlkK2KjxqDFrvXjNSJr9BZJ0kWi wHSN1w+jraCwcAzWZwtxM5QQMDubBKpVKgJcesFLWg1FuoPKu0Ogu2NktDsDuuPkwOgw mlZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n6Y6cTnq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m3-20020a170902db0300b0014fd360c0d0si12177517plx.517.2022.02.28.12.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:23:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n6Y6cTnq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9FC181D528A; Mon, 28 Feb 2022 11:42:46 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234220AbiB1Rgj (ORCPT + 99 others); Mon, 28 Feb 2022 12:36:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238525AbiB1Rde (ORCPT ); Mon, 28 Feb 2022 12:33:34 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DED2C90FF8; Mon, 28 Feb 2022 09:30:10 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F21C3B815B8; Mon, 28 Feb 2022 17:30:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E4B3C340E7; Mon, 28 Feb 2022 17:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646069407; bh=KkzO5SfNgv6pefqurUmAIt4FKijkSthd8pPmqIR/5/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n6Y6cTnqE4qkNvQkRmzk6AztpWZ7BML3toqaRHz7Ys3eUKw5BlPcaUfqZVPd0qHo5 VvUn7f6yH2CsP/R4ZRX3g8kDIssSS5WPlNhW4+6gn9DsSUu5hKgLww7Fr2yW54erU1 SKE60jHFWWWUsktmUdCVdC+Eqz9V4gXwbsKwxtds= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhao Gongyi , Zhang Qiao , Waiman Long , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo Subject: [PATCH 5.4 01/53] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug Date: Mon, 28 Feb 2022 18:23:59 +0100 Message-Id: <20220228172248.327750002@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172248.232273337@linuxfoundation.org> References: <20220228172248.232273337@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Qiao commit 05c7b7a92cc87ff8d7fde189d0fade250697573c upstream. As previously discussed(https://lkml.org/lkml/2022/1/20/51), cpuset_attach() is affected with similar cpu hotplug race, as follow scenario: cpuset_attach() cpu hotplug --------------------------- ---------------------- down_write(cpuset_rwsem) guarantee_online_cpus() // (load cpus_attach) sched_cpu_deactivate set_cpu_active() // will change cpu_active_mask set_cpus_allowed_ptr(cpus_attach) __set_cpus_allowed_ptr_locked() // (if the intersection of cpus_attach and cpu_active_mask is empty, will return -EINVAL) up_write(cpuset_rwsem) To avoid races such as described above, protect cpuset_attach() call with cpu_hotplug_lock. Fixes: be367d099270 ("cgroups: let ss->can_attach and ss->attach do whole threadgroups at a time") Cc: stable@vger.kernel.org # v2.6.32+ Reported-by: Zhao Gongyi Signed-off-by: Zhang Qiao Acked-by: Waiman Long Reviewed-by: Michal Koutný Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- kernel/cgroup/cpuset.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2204,6 +2204,7 @@ static void cpuset_attach(struct cgroup_ cgroup_taskset_first(tset, &css); cs = css_cs(css); + cpus_read_lock(); percpu_down_write(&cpuset_rwsem); /* prepare for attach */ @@ -2259,6 +2260,7 @@ static void cpuset_attach(struct cgroup_ wake_up(&cpuset_attach_wq); percpu_up_write(&cpuset_rwsem); + cpus_read_unlock(); } /* The various types of files and directories in a cpuset file system */