Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4673571ybl; Wed, 22 Jan 2020 02:34:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyh0bbOwtxX0VwtA8fJMecHeXRWQi7qFa3dAv13h+G4NXoQNDsC1OhZ+k0GkeQAYrz2FLJj X-Received: by 2002:aca:f354:: with SMTP id r81mr6104275oih.90.1579689247094; Wed, 22 Jan 2020 02:34:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579689247; cv=none; d=google.com; s=arc-20160816; b=IoqRGt+9gzpC0tGQI6bqx/GO3q0caEeKaPbxnRwQzteRolZ8Pl/GKzNkOk60RyYDVV kg2hsqb3OLIMG+cUKO8VlXzLIJZkvLvetKEfe/3JNQzgQGJHVRtV/N4Rl4Gla+GTcgZX 2GCpYXuasZ1inY4SPfhEC97Bxlq3zx4PXrIkhKQMuRPbaMyjd3WsPlY0IWzudEflQC3c VzUvm6Qa0DYSNGXO9xUgTUqs1Gz88Jzsscr5t4KyK/qDWZ09YU27SMMdxm3olAZcU2hP loVcKZacTWr5ODaJ+C5aS/2Z0Ljue0Ma4M960g2vsoE4taRM8jjDH/ML5GYwwLeKv5BR jmcQ== 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=yQTTQ+wIAWEtUX0y7Mq3tTQL1Jh1iwY3gJn6DSSLKP4=; b=hQJI+9yAB+CtQyQl42n8rmzpZet3C21M72ljBKpFqjBQ8b85TR77T7hdvg0OMzH3v7 kXxI17daENV/ILvn7mcsXalh39CE1g9S93dwHEYlzfiHnFKuybSj6bJvM0nJKh4ugADN 98epvhZS477hide7QqmQmD72ba9AEYnPnXd/PoDR01Kf1RFooh5yHcdysQDQ4URYHUVR +5WcpgjlFcD72Y+Pmso+cSQM2kQ8pBxvuIRLjYtb5pd5wVaG7bgfkEaEWhTtAD7Q5QDv aC49dXLzvlRvq1Z5pntXmwunKrqHkwyqOd47n13eMVTdF3kDiL15m9Ja5LvQcgZ8U2v+ H2/Q== 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 z11si20704848oic.176.2020.01.22.02.33.54; Wed, 22 Jan 2020 02:34:07 -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 S1729360AbgAVKc5 (ORCPT + 99 others); Wed, 22 Jan 2020 05:32:57 -0500 Received: from foss.arm.com ([217.140.110.172]:54612 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729148AbgAVKc5 (ORCPT ); Wed, 22 Jan 2020 05:32: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 3942A1FB; Wed, 22 Jan 2020 02:32: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 C72CD3F68E; Wed, 22 Jan 2020 02:32:53 -0800 (PST) Date: Wed, 22 Jan 2020 10:32:51 +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: <20200122103250.jdssttb7veevfttz@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> <20200121174751.5opyyjwxfnwdgcev@e107158-lin.cambridge.arm.com> <20200121180930.GJ25745@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200121180930.GJ25745@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 18:09, Russell King - ARM Linux admin wrote: > On Tue, Jan 21, 2020 at 05:47:52PM +0000, Qais Yousef wrote: > > 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. > > freeze_secondary_cpus() takes the CPU maps lock while it takes CPUs > down, and then disables cpu hotplug by incrementing > cpu_hotplug_disabled. Incrementing that prevents cpu_up() and > cpu_down() being used, thereby preventing userspace from changing the > online state of any CPU in the system. I see. Sorry I missed the CPU maps lock. Yes this makes sense and should work here too. Thanks for the help. Thomas, I'll wait for your comment on this and potentially other patches before sending v3. Thanks -- Qais Yousef