Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1240863pxb; Fri, 21 Jan 2022 13:08:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqVbcxizJeeYKME//KwVAyCs5ygtKnheqtGuSuh198FkaIzobN6VMBlHiKaL98pclTWtmZ X-Received: by 2002:a62:7506:0:b0:4c7:cf2b:81b5 with SMTP id q6-20020a627506000000b004c7cf2b81b5mr1518301pfc.54.1642799298584; Fri, 21 Jan 2022 13:08:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799298; cv=none; d=google.com; s=arc-20160816; b=Ul2EN6l3TODG0dMdDNQkFzg3e8esHY6UvaDhJuwZSmJVJm8f/ddTRDoxTXGb1SQwnL adFC3wzZWyvKTOI6RGdo0+1WNcQFsQ8QtbsAqwtoN1Y59WHDlQ/ycNcr1Qk3mZRn/yYQ cT+5Cq7dOeuU0hC3l0nyrUvz0BNa4aQ8BR3Pz0P8JvWhiBDG15rFPOExg1fLuPCtKwWR tDMXSpWEBL5HdjTKw6OLDsSDNAVlNBCspR3JmsKOT2jw6T9qZ1w+iwkgxgAJCt+gFDoG V99rSaV4uKBCFt1gJlaJiD0sg5wHdfmoyrWN9671PaFzzF6lUm7u2jCg8hcoIYJBabR5 DySQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=onGzv98WRht4D8tpR18V9phOBcrYpCynWYelf2+w9xs=; b=BowBBhPKeK9CYGoeYjnfEMAIXrY4hVEkyxU/r/sjjh+9ROEAY2fkwvlDrI2Xz7eWxb r6pkHV6W3IgYBByp+PbmHwQ6ho6HNVHLV5OxzcW2ByIw2DvPE2j4aZruzW0p4teLNw1L 4MnZpTyo6sQFU8lJGo7KBY5V6b4OuROo+JzFx0PwbhgYvVfoYexIVjur3RsjU9EgQm1p iN2K7ol07IQnHzR7ECvrBDR9TqgPPlsdb2zBDTvN1gXiBzd3E0kOKCtkjbn7taI5gs1N xFjAPQ9FyeszMZFSnam3k2Gkp43baNqpYP2db2MU5Ng8+7fzcbC9hhTlPMOA13vGi96b i7tQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v64si1603317pgd.505.2022.01.21.13.08.06; Fri, 21 Jan 2022 13:08:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1358931AbiATHOZ (ORCPT + 99 others); Thu, 20 Jan 2022 02:14:25 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:16726 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358745AbiATHOZ (ORCPT ); Thu, 20 Jan 2022 02:14:25 -0500 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JfYZ36lYxzZfDS; Thu, 20 Jan 2022 15:10:35 +0800 (CST) Received: from dggpeml500018.china.huawei.com (7.185.36.186) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 20 Jan 2022 15:14:22 +0800 Received: from [10.67.111.186] (10.67.111.186) by dggpeml500018.china.huawei.com (7.185.36.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 20 Jan 2022 15:14:22 +0800 Message-ID: Date: Thu, 20 Jan 2022 15:14:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: Re: [Question] set_cpus_allowed_ptr() call failed at cpuset_attach() To: =?UTF-8?Q?Michal_Koutn=c3=bd?= CC: Tejun Heo , , , , References: <09ce5796-798e-83d0-f1a6-ba38a787bfc5@huawei.com> <4415cd09-6de3-bb2d-386d-8beb4927fb46@huawei.com> <20220119130221.GA31037@blackbody.suse.cz> From: Zhang Qiao In-Reply-To: <20220119130221.GA31037@blackbody.suse.cz> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.186] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500018.china.huawei.com (7.185.36.186) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hello 在 2022/1/19 21:02, Michal Koutný 写道: > On Fri, Jan 14, 2022 at 09:15:06AM +0800, Zhang Qiao wrote: >> I found the following warning log on qemu. I migrated a task from one cpuset cgroup to >> another, while I also performed the cpu hotplug operation, and got following calltrace. > > Do you have more information on what hotplug event and what error > (from set_cpus_allowed_ptr() you observe? (And what's src/dst cpuset wrt > root/non-root)? I ran the LTP testcases and a test scripts that do hotplug on a random cpu at the same time. The race condition quickly, and I can't reproduce it so far. By reading code about set_cpus_allowed_ptr(), i think __set_cpus_allowed_ptr_locked() will be failed when new_mask and cpu_active_mask do not intersect, as follows: __set_cpus_allowed_ptr_locked(): .... const struct cpumask *cpu_valid_mask = cpu_active_mask; dest_cpu = cpumask_any_and_distribute(cpu_valid_mask, new_mask); if (dest_cpu >= nr_cpu_ids) { ret = -EINVAL; goto out; } .... } > >> Can we use cpus_read_lock()/cpus_read_unlock() to guarantee that set_cpus_allowed_ptr() >> doesn't fail, as follows: > > I'm wondering what can be wrong with the current actors: > > cpuset_can_attach > down_read(cpuset_rwsem) > // check all migratees > up_read(cpuset_rwsem) > [ _cpu_down / cpuhp_setup_state ] > schedule_work > ... > cpuset_hotplug_update_tasks > down_write(cpuset_rwsem) > up_write(cpuset_rwsem) > ... flush_work > [ _cpu_down / cpu_up_down_serialize_trainwrecks ] > cpuset_attach > down_write(cpuset_rwsem) > set_cpus_allowed_ptr(allowed_cpus_weird) > up_write(cpuset_rwsem) > i think the troublesome scenario as follows: cpuset_can_attach down_read(cpuset_rwsem) // check all migratees up_read(cpuset_rwsem) [ _cpu_down / cpuhp_setup_state ] cpuset_attach down_write(cpuset_rwsem) guarantee_online_cpus() // (load cpus_attach) sched_cpu_deactivate set_cpu_active(cpu, false) // 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) schedule_work ... cpuset_hotplug_update_tasks down_write(cpuset_rwsem) up_write(cpuset_rwsem) ... flush_work [ _cpu_down / cpu_up_down_serialize_trainwrecks ] Regards, Qiao > The statement in cpuset_attach() about cpuset_can_attach() test is not > so strong since task_can_attach() is mostly a pass for non-deadline > tasks. Still, the use of cpuset_rwsem above should synchronize (I may be > mistaken) the changes of cpuset's cpu masks, so I'd be interested about > the details above to understand why the current approach doesn't work. > > The additional cpus_read_{,un}lock (when reordered wrt cpuset_rwsem) > may work but your patch should explain why (in what situation). > > My .02€, > Michal > . >