Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1269214pxb; Thu, 28 Jan 2021 12:00:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwvzzPW5/oHGEDWBUUwP/R/IFmnC4Vv/lG44wReLZBS1hhnv0ErtLSMymb/XKXC2Tl7M0QZ X-Received: by 2002:a17:906:154d:: with SMTP id c13mr1083806ejd.471.1611864034994; Thu, 28 Jan 2021 12:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611864034; cv=none; d=google.com; s=arc-20160816; b=UW54m/LiimVMKDGloBLJA3ATjALEN5Oluwtko8toIwodE6eWjX+meyHwGIbP8TTzi3 wQTaGE9dC+viqk7a5IcBI5/QCSiSibhcq1k7ixeU60C3XmT5dupEX3W8Z5iUTAdJqTJJ n8MNA1wCVigpysGFr4K7V67qZADPPrZvQYvb3VlPI117qyVMsDnUu6lnxcG8QUNVKc9p JcByjSsX4cENQWhFyvAbd9LkrZBu6q8/emqlxsGnv3gBZV2AnD7AYkukEkbldRABWINV hLJP+QsFMAvgO9mwN2X5FLAwq3BlfdVLPqWhuiiYM0RNsIXY5p+51gx54pR3RbltBHb7 XxRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from; bh=LmIB3gVcb7/gsVZq9NXBvRb9cx5HASd/dBb/20aGKqg=; b=0zFUXLTaJNlRBD4/DdjdYVlFPqLtuf1v1/Oil0KoXsnX+4hbpair2LWfWZ9WLmCanC wQJejtGIp0hD8UZbeymctL4Ugwd2tm2oAul6ga9T8iRCfcZjerUwpXjuGG3hE5z6ivkJ Y6jOnyjJ4O5dO8ccRa03s1GZWGnmFNDhIoT/Y/juiwkNDh9o5xUNBWYp1pRFubdP6Sq5 0qFHi0YqKrfZsWQo7J+4/OmhPIhaYauYNn/uRijR+YZ/FVj1sRVZqWYJYh1pG+DKAYyH 0oMgZVf/EOCMrLUcvjekTWokmNRcomM6vp4ZyqR2Q/DOF+0LZn5eGvSnyL36pkC58r26 jP2Q== 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 f29si3848149edj.297.2021.01.28.12.00.09; Thu, 28 Jan 2021 12:00:34 -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 S232804AbhA1TCI (ORCPT + 99 others); Thu, 28 Jan 2021 14:02:08 -0500 Received: from foss.arm.com ([217.140.110.172]:37758 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232640AbhA1S6C (ORCPT ); Thu, 28 Jan 2021 13:58:02 -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 714D113A1; Thu, 28 Jan 2021 10:56:09 -0800 (PST) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 350863F719; Thu, 28 Jan 2021 10:56:07 -0800 (PST) From: Valentin Schneider To: Tao Zhou Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, bigeasy@linutronix.de, qais.yousef@arm.com, swood@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vincent.donnefort@arm.com, tj@kernel.org, ouwen210@hotmail.com Subject: Re: [RFC PATCH] sched/core: Fix premature p->migration_pending completion In-Reply-To: References: <20210127193035.13789-1-valentin.schneider@arm.com> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/26.3 (x86_64-pc-linux-gnu) Date: Thu, 28 Jan 2021 18:56:01 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/01/21 01:02, Tao Zhou wrote: > Hi, > > On Wed, Jan 27, 2021 at 07:30:35PM +0000, Valentin Schneider wrote: > >> Fiddling some more with a TLA+ model of set_cpus_allowed_ptr() & friends >> unearthed one more outstanding issue. This doesn't even involve >> migrate_disable(), but rather affinity changes and execution of the stopper >> racing with each other. >> >> My own interpretation of the (lengthy) TLA+ splat (note the potential for >> errors at each level) is: >> >> Initial conditions: >> victim.cpus_mask = {CPU0, CPU1} >> >> CPU0 CPU1 CPU >> >> switch_to(victim) >> set_cpus_allowed(victim, {CPU1}) >> kick CPU0 migration_cpu_stop({.dest_cpu = CPU1}) >> switch_to(stopper/0) >> // e.g. CFS load balance >> move_queued_task(CPU0, victim, CPU1); > ^^^^^^^^^^^^^^^^ > > Why is move_queued_task() not attach_task()/detach_task() for CFS load.. > Heh I expected that one; it is indeed detach_task()/attach_task() for CFS LB. I didn't want to make this any longer than it needed to, and I figured that move_queued_task() being a composition of detach_task(), attach_task() and rq_locks, this would get the point across. This does raise an "interesting" point that ATM I think this issue cannot actually involve move_queued_task(), since all current move_queued_task() callsites are issued either from a stopper or from set_cpus_allowed_ptr(). CFS' detach_task() + attach_task() could do it, though. >> diff --git a/kernel/sched/core.c b/kernel/sched/core.c >> index 06b449942adf..b57326b0a742 100644 >> --- a/kernel/sched/core.c >> +++ b/kernel/sched/core.c >> @@ -1923,20 +1923,28 @@ static int migration_cpu_stop(void *data) >> complete = true; >> } >> >> - /* migrate_enable() -- we must not race against SCA */ >> - if (dest_cpu < 0) { >> - /* >> - * When this was migrate_enable() but we no longer >> - * have a @pending, a concurrent SCA 'fixed' things >> - * and we should be valid again. Nothing to do. >> - */ >> - if (!pending) { >> - WARN_ON_ONCE(!cpumask_test_cpu(task_cpu(p), &p->cpus_mask)); >> - goto out; >> - } >> + /* >> + * When this was migrate_enable() but we no longer >> + * have a @pending, a concurrent SCA 'fixed' things >> + * and we should be valid again. >> + * >> + * This can also be a stopper invocation that was 'fixed' by an >> + * earlier one. >> + * >> + * Nothing to do. >> + */ >> + if ((dest_cpu < 0 || dest_cpu == cpu_of(rq)) && !pending) { > > When the condition 'dest_cpu == cpu_of(rq)' is true, pending is not NULL. > The condition may be like this: > > if ((dest_cpu < 0 && !pending) || dest_cpu == cpu_of(rq)) > > We want to choose one cpu in the new(currently modified) cpu_mask and > complete all. > Consider the execution of migration_cpu_stop() in above trace with migrate_task_to(). We do have: - dest_cpu == cpu_of(rq) - p->migration_pending but we do *not* want to bail out at this condition, because we need to fix up dest_cpu.