From patchwork Sat Jul 1 06:50:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 115004 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10880533vqr; Sat, 1 Jul 2023 00:17:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGoAIxn7ZMuwNfRhhx+UB0afgiSlddTsJR6tgFrMn6rrh6rSoDTtcYj831c5MWif7fyiqpd X-Received: by 2002:a17:903:2606:b0:1b8:15bf:d2ed with SMTP id jd6-20020a170903260600b001b815bfd2edmr4154175plb.65.1688195859244; Sat, 01 Jul 2023 00:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688195859; cv=none; d=google.com; s=arc-20160816; b=N3uXT37aVx/vZDupdVPXxsAmWaGFi8LeCud+cvaaj8szDoLBpsyLre+1+fsKEuxgHf b/2DKfqhwQ6+L4pVN7P/MbcBOYQoetzyZ/WRJHSZoe4YCvasEwjjiTs9o0Y5uVWU253Z QZlv0zsXBA7oU2aitB4fusxqV8KR9c5N8kJynhE+CiqiIsmb+us236HF9q7zr4o77Y53 0E16ezIWfKXF9GiGxHPTeYP76g5tYskhIisyPtXcSeafwRHi/myVGrKuQSheJHShINA6 hLJaCycXK7DfTrNCYlfoVXQsp/iW5Y+rhM6aWJSggjB9BJxD0D7sT74TIEz35oebbcXa MlKQ== 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 :message-id:date:subject:cc:to:from; bh=AYnFhvIMZyh/5xzJjTtA6c4mbUbz4Pn+uQs+8vDT4qg=; fh=xm61FqaKFbVtJj3DZjMBwIjT3viqbFfn4Ws5hFHxOsg=; b=xtanLqhIt0bY9QR8PPuKLTjGxDzyG3fjvP9cRGp21cd9SnbDkg+ypfXnmJJeOt6EuC AzTX1nRMdtYKgVjH7eAsOIKSbwJzMhi2pzhMolkpzp6SKX4YSTSvybH+RHL6Kk+FhzZ5 QDouHx76rjxL2CwZEnPp/0xtLgvmHDQZdR5L93qSL04RlPANFzPr1HGKryd39oNpVKN+ f0AJcRX11jvIQQ2XMetJrwT8Wl8VjOMc+7F9yXB5ZRvhTlM7e9Axr7+opxXXHceeHNUH wFPGYP6a3Bxoqjm7BX+WS+GFm7cmBzBRat6HbA2ylQEWXoik5AeVPeIF86s88OaUQnBg RNSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a170902ea0300b001b876d46162si2398460plg.38.2023.07.01.00.17.24; Sat, 01 Jul 2023 00:17:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231685AbjGAG4U (ORCPT + 99 others); Sat, 1 Jul 2023 02:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbjGAGza (ORCPT ); Sat, 1 Jul 2023 02:55:30 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11539423B; Fri, 30 Jun 2023 23:50:27 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QtN966WN7zqSKb; Sat, 1 Jul 2023 14:50:02 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 1 Jul 2023 14:50:23 +0800 From: Miaohe Lin To: , , , CC: , , Subject: [PATCH] cgroup/cpuset: update parent subparts cpumask while holding css refcnt Date: Sat, 1 Jul 2023 14:50:49 +0800 Message-ID: <20230701065049.1758266-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770201661217664888?= X-GMAIL-MSGID: =?utf-8?q?1770201661217664888?= update_parent_subparts_cpumask() is called outside RCU read-side critical section without holding extra css refcnt of cp. In theroy, cp could be freed at any time. Holding extra css refcnt to ensure cp is valid while updating parent subparts cpumask. Fixes: d7c8142d5a55 ("cgroup/cpuset: Make partition invalid if cpumask change violates exclusivity rule") Signed-off-by: Miaohe Lin Reviewed-by: Waiman Long --- kernel/cgroup/cpuset.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 58e6f18f01c1..632a9986d5de 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1806,9 +1806,12 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, cpuset_for_each_child(cp, css, parent) if (is_partition_valid(cp) && cpumask_intersects(trialcs->cpus_allowed, cp->cpus_allowed)) { + if (!css_tryget_online(&cp->css)) + continue; rcu_read_unlock(); update_parent_subparts_cpumask(cp, partcmd_invalidate, NULL, &tmp); rcu_read_lock(); + css_put(&cp->css); } rcu_read_unlock(); retval = 0;