Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5912138pxb; Tue, 16 Feb 2021 10:33:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJziC3GtWONErc0nYZX25J9KFvYMUaM0rWkK+tW2N5/NyEklQsKHpdfWWnUmGbGNrukG+8T6 X-Received: by 2002:a05:6402:1a58:: with SMTP id bf24mr22023197edb.191.1613500424556; Tue, 16 Feb 2021 10:33:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613500424; cv=none; d=google.com; s=arc-20160816; b=WfDWqsQuje9r4DLCh0qYyM6GSWXqR1Ygl869MX6jeOkkCeGler+PJ8NwBsirRfOJkp aSxRlmqET9E2tD4uEsCI42DjfxaVN5cpFVKmR8r6iRxK5xebC8krFBdWsZBgXZC8X8Op FvF9mSCj4qDjEuKNyeJeuimF0YZZCA4ZiY9SyfUaqD0xl2jV0bPLB2kMxeLoE3z7cPIN LnbF1d5Ranfn9SHXmCywSqjK69/5lyBqnpedVYPwHsp68JiVzj2kpIYk0IQEBY3ZoWVw BMvAfrvP2mQgUPcqfMB3OwScr8AOc2k6oMhVdt4ZDZp2z44ZVMdmPT04RRocXOo2LAgw xZrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=H1uiC+qEi46PRG3ZsKqHGd/FAON37uMAKOMGl9iT/Ps=; b=EUMupA144OkvYlJBDghkmpGqfgyIyPlSSXSF5blhkBoEMdr7dbXdhX08NqcXyk78GR KbqJphyRU7jIFqczp1dYX4AGLHr2xM8ZkMR4pAzNt/HF5odimUVzIz5QNh8Poj8Lvfi4 MHnbpfUGUOx3YbVfHhTp+xVidVJrR0nVBwH9SAjUjHQEZJQiyOr7Gua23zXaqsuW/7UA JiiWRdua9ayEvLkrNxL9f+DmBtVnAScjAIetcqXuScuN/OjTaeaTPIaLhA7qpDQAyr/H R4CFS0zzWsgTcEolCZJoxAl/xSis3dm+/9P0w/VPZ+ER5l9/nniKl70dmASU/3miyn8q OdIw== 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=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id js1si14208932ejc.662.2021.02.16.10.33.20; Tue, 16 Feb 2021 10:33:44 -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=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbhBPSaX (ORCPT + 99 others); Tue, 16 Feb 2021 13:30:23 -0500 Received: from foss.arm.com ([217.140.110.172]:40928 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbhBPSaV (ORCPT ); Tue, 16 Feb 2021 13:30:21 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 03282101E; Tue, 16 Feb 2021 10:29:35 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (unknown [10.1.195.80]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 206963F73B; Tue, 16 Feb 2021 10:29:28 -0800 (PST) Date: Tue, 16 Feb 2021 18:29:25 +0000 From: Qais Yousef To: Alexey Klimov Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, peterz@infradead.org, yury.norov@gmail.com, daniel.m.jordan@oracle.com, tglx@linutronix.de, jobaker@redhat.com, audralmitchel@gmail.com, arnd@arndb.de, gregkh@linuxfoundation.org, rafael@kernel.org, tj@kernel.org, hannes@cmpxchg.org, klimov.linux@gmail.com Subject: Re: [PATCH v2] cpu/hotplug: wait for cpuset_hotplug_work to finish on cpu onlining Message-ID: <20210216182925.v2fe3foe6dgmiaj6@e107158-lin.cambridge.arm.com> References: <20210212003032.2037750-1-aklimov@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210212003032.2037750-1-aklimov@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/12/21 00:30, Alexey Klimov wrote: > When a CPU offlined and onlined via device_offline() and device_online() > the userspace gets uevent notification. If, after receiving "online" uevent, > userspace executes sched_setaffinity() on some task trying to move it > to a recently onlined CPU, then it often fails with -EINVAL. Userspace needs > to wait around 5..30 ms before sched_setaffinity() will succeed for recently > onlined CPU after receiving uevent. > > If in_mask argument for sched_setaffinity() has only recently onlined CPU, > it often fails with such flow: > > sched_setaffinity() > cpuset_cpus_allowed() > guarantee_online_cpus() <-- cs->effective_cpus mask does not > contain recently onlined cpu > cpumask_and() <-- final new_mask is empty > __set_cpus_allowed_ptr() > cpumask_any_and_distribute() <-- returns dest_cpu equal to nr_cpu_ids > returns -EINVAL > > Cpusets used in guarantee_online_cpus() are updated using workqueue from > cpuset_update_active_cpus() which in its turn is called from cpu hotplug callback > sched_cpu_activate() hence it may not be observable by sched_setaffinity() if > it is called immediately after uevent. nit: newline > Out of line uevent can be avoided if we will ensure that cpuset_hotplug_work > has run to completion using cpuset_wait_for_hotplug() after onlining the > cpu in cpu_device_up() and in cpuhp_smt_enable(). > > Co-analyzed-by: Joshua Baker > Signed-off-by: Alexey Klimov > --- This looks good to me. Reviewed-by: Qais Yousef Thanks -- Qais Yousef