Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp25553108rwd; Sun, 2 Jul 2023 20:13:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7iPj9jl305gFKjET3yWLFj2xETq8/nNBIx7rXeUGsOzZtnVxbq+Kv3usoVcuk7zSSQz4OF X-Received: by 2002:aca:2307:0:b0:3a1:a1b0:c41f with SMTP id e7-20020aca2307000000b003a1a1b0c41fmr7733229oie.23.1688354033058; Sun, 02 Jul 2023 20:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688354033; cv=none; d=google.com; s=arc-20160816; b=ZXYVllZ9l56Xy1rSZ1jJzHMII4pxwj1WNBOu4PTVAxFSnWmssnQfvHfAYoJzuD8wZc 2OgBBlhk18MdTKdcWB9M6n+z6H8jbt5P6/cZylI02m+A7CyJ0sXyH9dKE+5UMvdhnk3P 4NsYKPK6dH9BkLyEuO4VCylc/rsjn9cf4TAQe8Ndxni/kF+sD0tm0z0wGsq6z1672uUC hrJAcl4xyF6aJbL4bb83GVMGqgxJnIPdUuAWGIj+3Cx+vUrMtyq60wNwuo+kWVX29lT2 +7aEJ77lnFR41Is1s8QBuT1cRNCH5oqhTqkNlHwJaWt2MBbwZphqrLVnGRztNkLKF840 tP2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=CyfwmKLW32CKCpa1uHlAPDocNWwcnQGq3hx4kOAF2kw=; fh=3AgzGiQsRPnMrcKawKzgmCW2ph1U9ucpyVMzUUxOXco=; b=RkBiPYv/savPRTwFwxsBLqDMTxQODFanx66sReCM1KNp3xMfnUN3jnv7LaejqwCebh Rt/OLZPZgsAng6tEK0RW4u3WCkmY58dB1GlEBXUpdJuNkcdiFmA+pYX/TJsuTpPZ/Bmq HP1LtooHCkqzmwl9Ki22RR7vxIIDaRWwVqIcgdpQ5G97JnVkecs+cTHT4SfKZeW5Yjwe l916MI+EJgIiu9yzq//pdNXPbxFkaCnVDfhazeR4Fezt/FZCwm+gwROzpCy+0fxkNlBD qmMimMNwXYURhIMeG5RnX92CRXBx75tVrmIRzkIVnoKbZd1MHvuV8wknkU/mFA/BrWJU ZBzQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a170902c18b00b001b80641e90dsi13886235pld.438.2023.07.02.20.13.32; Sun, 02 Jul 2023 20:13:53 -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 S229733AbjGCC6Y (ORCPT + 99 others); Sun, 2 Jul 2023 22:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjGCC6X (ORCPT ); Sun, 2 Jul 2023 22:58:23 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BCC81BC; Sun, 2 Jul 2023 19:58:22 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QvVs70rv2zMpvF; Mon, 3 Jul 2023 10:55:07 +0800 (CST) Received: from [10.174.151.185] (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; Mon, 3 Jul 2023 10:58:19 +0800 Subject: Re: [PATCH] cgroup/cpuset: update parent subparts cpumask while holding css refcnt To: Waiman Long CC: , , , , References: <20230701065049.1758266-1-linmiaohe@huawei.com> <9244d968-b25a-066f-2ff3-1281bf03983e@redhat.com> From: Miaohe Lin Message-ID: <53486caa-8ca7-78f5-71ac-d5692b482c94@huawei.com> Date: Mon, 3 Jul 2023 10:58:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 2023/7/2 7:46, Waiman Long wrote: > On 7/1/23 19:38, Waiman Long wrote: >> On 7/1/23 02:50, Miaohe Lin wrote: >>> 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 >>> --- >>>   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; >> >> Thanks for finding that. It looks good to me. >> >> Reviewed-by: Waiman Long > > Though, I will say that an offline cpuset cannot be a valid partition root. So it is not really a problem. For correctness sake and consistency with other similar code, I am in favor of getting it merged. Yes, cpuset_mutex will prevent cpuset from being offline while update cpumask. And as you mentioned, this patch makes code more consistency at least. Thanks for your review and comment.