Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3536939ybl; Tue, 21 Jan 2020 02:36:45 -0800 (PST) X-Google-Smtp-Source: APXvYqw669PrIV3zsnVommU0tpM7S9kie2I9tCdj/U8ET3wHW3acJ3Ryup5lM1nIX2RlGvmq0YnL X-Received: by 2002:a9d:5885:: with SMTP id x5mr2945717otg.132.1579603005619; Tue, 21 Jan 2020 02:36:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579603005; cv=none; d=google.com; s=arc-20160816; b=vnJN62XeaJ5P/7kW/3IxRmBtUvaFGDgARzOyxMPXyXzMCd+EzA3WFu2bUMPHJvbHG2 1rztPkWnOjpCt8Cnz44jCF2thl0j0lmrmKFkvMkjZUKWhXqutECQGeS+BEdyTmcvEL3p CJQh3VPke5xj5hr+AM3LE1JG/tTXlgPYhT8qGVMP/NUAuYq38C3NG+epPXLN2F9GCm0T 8eInArmneeI8EEk5L6PSKhaggi2HGGcZqrOxs1oLKCv/HRVMg4k4CUOuohrNKSdgd41d TBMh+/kIk6a1JRBzSeWzaQh2MmUnmmT/T6SUBmWMiZTOoxKSR6rI3ORBwKW+n57qr8E3 Zisw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=et4RlvUeOkCtUnhuSYbRl6HA7YBgNI1b2eb9AQ7Bu7g=; b=sHIq7ev+J9F1ke3xuT0cpt+p7Tlnqkmrq2cusecg+7FD74hvImChB3ySFu8JrzC90f ZMlGkvmXgnAxtut9AKPvHNCShGvpEqBTSN8LaJuWqtVqNZCaMTqR2s8lYSOwIdpZIKTN 6CLu3pAi9R9TlvS6+N8v0+HonySriJn3o9FJJLhw8nhFd4cNkUr5t9GjBW1tZnq0MZDu W8LZ4CKuiD3MApgQ1pYBC8LOp7acuDFHPb+qnh0198oPb3dsJHyiPEfptvdgraJj53g6 bsCM39H1Lqipz/uDBqoJIKUG7ApUYDINm4a0S1IyxFYEAAho6mfw0yTIM0RTqwpgknXx rbYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZJIQ5Cnz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q126si19806120oia.8.2020.01.21.02.36.33; Tue, 21 Jan 2020 02:36:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZJIQ5Cnz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729417AbgAUKfa (ORCPT + 99 others); Tue, 21 Jan 2020 05:35:30 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48594 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727220AbgAUKfa (ORCPT ); Tue, 21 Jan 2020 05:35:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=et4RlvUeOkCtUnhuSYbRl6HA7YBgNI1b2eb9AQ7Bu7g=; b=ZJIQ5CnzMhpg81at8gIF7EAM+e NpAk6n6JqQyaj/XvmM2/4Hoah19eqvQq6/GVYSSug9wO3tALXiGX89jU3yguB2hWaSwsbCIku7OFn fMk70GIJZXu7xwdklj5f4qG/oZaqmdXs0l4lFJS+3bjOS18gDCYnEhbRS9DVPwaK8oeI1xSTlpSF5 YsCWPdRgO6OJYFDR+TxQaWFQUFIn42/a5sUSlUczfdxrGIl34/fifHMfvBpMOr2I1s2rLIStAFXO4 FFYX8CytLgPX97DkSPyAqEYi+J0tkcWND8BPq1QFb16bIW70Mf2Vg1Suh6kheYybjwWmBL+6POJY/ bfW18+lQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1itqsI-00019I-5k; Tue, 21 Jan 2020 10:35:10 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D7A07300B8D; Tue, 21 Jan 2020 11:33:27 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id EA6A020146B6C; Tue, 21 Jan 2020 11:35:06 +0100 (CET) Date: Tue, 21 Jan 2020 11:35:06 +0100 From: Peter Zijlstra To: Qian Cai Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, paulmck@kernel.org, tglx@linutronix.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched/core: fix illegal RCU from offline CPUs Message-ID: <20200121103506.GH14914@hirez.programming.kicks-ass.net> References: <20200120101652.GM14879@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 20, 2020 at 03:35:09PM -0500, Qian Cai wrote: > > On Jan 20, 2020, at 5:17 AM, Peter Zijlstra wrote: > > > > Bah.. that's horrible. Surely we can find a better place to do this in > > the whole hotplug machinery. > > > > Perhaps you can have takedown_cpu() do the mmdrop()? > > The problem is that no all arch_cpu_idle_dead() will call > idle_task_exit(). For example, alpha and parisc are not, so it needs How is that not broken? If the idle thread runs on an active_mm, we need to drop that reference. This needs fixing regardless. > to deal with some kind of ifdef dance in takedown_cpu() to > conditionally call mmdrop() which sounds even more horrible? > > If you really prefer it anyway, maybe something like touching every arch’s __cpu_die() to also call mmdrop() depends on arches? > > BTW, how to obtain the other CPU’s current task mm? Is that cpu_rq(cpu)->curr->active_mm? Something like this; except you'll need to go audit archs to make sure they all call idle_task_exit() and/or put in comments on why they don't have to (perhaps their bringup switches them to &init_mm unconditionally and the switch_mm() is not required). --- diff --git a/kernel/cpu.c b/kernel/cpu.c index 9c706af713fb..2b4d8a69e8d9 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -564,6 +564,23 @@ static int bringup_cpu(unsigned int cpu) return bringup_wait_for_ap(cpu); } +static int finish_cpu(unsigned int cpu) +{ + struct task_struct *idle = idle_thread_get(cpu); + struct mm_struct *mm = idle->active_mm; + + /* + * idle_task_exit() will have switched to &init_mm, now + * clean up any remaining active_mm state. + */ + + if (mm == &init_mm) + return; + + idle->active_mm = &init_mm; + mmdrop(mm); +} + /* * Hotplug state machine related functions */ @@ -1434,7 +1451,7 @@ static struct cpuhp_step cpuhp_hp_states[] = { [CPUHP_BRINGUP_CPU] = { .name = "cpu:bringup", .startup.single = bringup_cpu, - .teardown.single = NULL, + .teardown.single = finish_cpu, .cant_stop = true, }, /* Final state before CPU kills itself */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index fc1dfc007604..8f049fb77a3d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6188,13 +6188,14 @@ void idle_task_exit(void) struct mm_struct *mm = current->active_mm; BUG_ON(cpu_online(smp_processor_id())); + BUG_ON(current != this_rq()->idle); if (mm != &init_mm) { switch_mm(mm, &init_mm, current); - current->active_mm = &init_mm; finish_arch_post_lock_switch(); } - mmdrop(mm); + + /* finish_cpu(), as ran on the BP, will clean up the active_mm state */ } /*