Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3941047ybl; Tue, 21 Jan 2020 09:49:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyi9uQCS8Kiq3h6qVP9Idl1jcoxP0TZ+FYMjw+Yl6u25dnUMnICdUjhOsWBp8ioIJNYOVyM X-Received: by 2002:a9d:62c2:: with SMTP id z2mr4606249otk.309.1579628985220; Tue, 21 Jan 2020 09:49:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579628985; cv=none; d=google.com; s=arc-20160816; b=0bHjKBfn24RqYXtCkv7h+w60N8H3mGwrYE6siIYUCjjiXe2tmAEzJl2s/A9gUcqvwv mO0EHFu/G6jtP0Bc/6IVtBxg+otr5fduzrZ4EDPRXvGZCubVNurtJPiaIDuUbAufMlrj SAI8BVZM4TEPYTMsPaZdumK8+srpaPGW0LiQU15paRI533KFjOOG20Q5NDciqmD+O1pE 2oRBZkZa612f0J0kBFMoV4Xdjc9XjeaZ9YORlM9lNmSuiTeAQj4KYLDC5MM79Le01bfe AUSBSKndKIm375TXtS9y1a1iwq07qypIPVsM47eI+ErLhxm+QKTzxBOhtgJ68xAxwNJ/ fHZQ== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hAQjHaeBanYxuMjYcJ1twnlPqyqOKvbGl8Vhc1t9rTQ=; b=k/7YWwrXYveC1opv9n3fNEqyu+IvuLDuh3gDapcKTMDMK22h6uieEOxPC4ikjSzn1P PWGe0jkUS9kFjvalJZXupdG0YDijvktNdv+PnIMdFlGjftzsJafy4qh2TPDc/TlsFc0h OYPraqATXQ/R/uXOKcYx0bIVUPFEbsWCJYxh7onAmipDaQEpO3drqZITrPUdaYBNMPin NSFXHeX6BFq5FkRef9tzY2N9rSabkt8vXbIdTrvam3vlX0ifxGO+BIgzt2aMq+hATC13 loKsNDXYgsUj3tVPPel72cBovCGDDJLvfjY+AJWa0TWuuHDWVYLLwTM1tNgs8jKlHSDp Dk9w== ARC-Authentication-Results: i=1; mx.google.com; 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 r2si18401005oif.83.2020.01.21.09.49.32; Tue, 21 Jan 2020 09:49: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; 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 S1729212AbgAURr5 (ORCPT + 99 others); Tue, 21 Jan 2020 12:47:57 -0500 Received: from foss.arm.com ([217.140.110.172]:46800 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728186AbgAURr5 (ORCPT ); Tue, 21 Jan 2020 12:47:57 -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 BA1BA30E; Tue, 21 Jan 2020 09:47:56 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5145A3F6C4; Tue, 21 Jan 2020 09:47:54 -0800 (PST) Date: Tue, 21 Jan 2020 17:47:52 +0000 From: Qais Yousef To: Russell King - ARM Linux admin Cc: Thomas Gleixner , Greg Kroah-Hartman , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Jiri Kosina , Nicholas Piggin , Daniel Lezcano , Ingo Molnar , Eiichi Tsukata , Zhenzhong Duan , Nadav Amit , "Rafael J. Wysocki" , Tony Luck , Fenghua Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 01/14] smp: Create a new function to shutdown nonboot cpus Message-ID: <20200121174751.5opyyjwxfnwdgcev@e107158-lin.cambridge.arm.com> References: <20191125112754.25223-1-qais.yousef@arm.com> <20191125112754.25223-2-qais.yousef@arm.com> <20200121170350.GC18808@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200121170350.GC18808@shell.armlinux.org.uk> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/21/20 17:03, Russell King - ARM Linux admin wrote: > On Mon, Nov 25, 2019 at 11:27:41AM +0000, Qais Yousef wrote: > > +void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) > > +{ > > + unsigned int cpu; > > + > > + if (!cpu_online(primary_cpu)) { > > + pr_info("Attempting to shutdodwn nonboot cpus while boot cpu is offline!\n"); > > + cpu_online(primary_cpu); Eh, that should be cpu_up(primary_cpu)! Which I have to say I'm not if is the right thing to do. migrate_to_reboot_cpu() picks the first online cpu if reboot_cpu (assumed 0) is offline migrate_to_reboot_cpu(): 225 /* Make certain the cpu I'm about to reboot on is online */ 226 if (!cpu_online(cpu)) 227 cpu = cpumask_first(cpu_online_mask); > > + } > > + > > + for_each_present_cpu(cpu) { > > + if (cpu == primary_cpu) > > + continue; > > + if (cpu_online(cpu)) > > + cpu_down(cpu); > > + } > > How does this avoid racing with userspace attempting to restart CPUs > that have already been taken down by this function? This is meant to be called from machine_shutdown() only. But you've got a point. The previous logic that used disable_nonboot_cpus(), which in turn called freeze_secondary_cpus() didn't hold hotplug lock. So I assumed the higher level logic of machine_shutdown() ensures that hotplug lock is held to synchronize with potential other hotplug operations. But I can see now that it doesn't. With this series that migrates users to use device_{online,offline}, holding the lock_device_hotplug() should protect against such races. Worth noting that this an existing problem in the code and not something I introduced, of course it makes sense to fix it properly as part of this series. I'm not sure how the other archs deal with this TBH. Thanks for having a look! Cheers -- Qais Yousef