Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2203000imm; Thu, 19 Jul 2018 15:19:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfzNbUYSreYacVLicKsHwamRH7rqcZeVGL84C+4kvj62Q++OwU7HvhFRQ5yd2Aa2rf1BjDL X-Received: by 2002:a62:a649:: with SMTP id t70-v6mr11289515pfe.149.1532038783792; Thu, 19 Jul 2018 15:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532038783; cv=none; d=google.com; s=arc-20160816; b=0o6O8pzUxaJICXhA0YIgo3uEMhI32RCcB74LEKXgGnMOeihTEjzblaLXBS3w+15shJ 4zueYB/BH6G14OofL8z7PY8D/cEy5tJJvXFP2HppmBzXdmsSkTKanAEFJWGJ1H9J/Lvh psNrn+TcS5eTJ1Nr4GJkdNl+gQCmet5rYQKcmaTo14rmXJlMWqFHgS2ZTK2O7xCmCL43 PLWBv9BfxXUyTVaYzhxXoF79YW8lVLbj38OACYC3fyueUub17gkTPYMLSCQI+JATfniK euIb8MwPmetQRCY1vecFNLkI5Xp28IRFnLh9M31R92igZfO3o48TWpHRDQZhUlVltE0B xinQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=NLSNfWCHMl4OGGg/ZS0l/CIuoG11+/yEbRtwF8kR18I=; b=mrHwNWBzD6OFFvr3frvlI29Blu+065yqZ1Kt2HJUGc1SMzmdNpdwtUlddcBN3Od2Kw wEZ4ZYWPT12oLL4jspyxvW+USBvIJb2Kt356hyXavrIwrv0iFCUHq+ETQ34l7J8P1mpa +6lGGP9nc4tC2k9MMqnM7G9Dp0z57Q9AhSkVXD1DBIBJXWaQ6vdpFvtZwYellSXlpadY /6QHHycFPgOXIKktPVZ9yFmQSRKHHE+mLORouQrx76rD1JK7ORaMWLTaAua3H+xgLmKt 6C8NWFoxlQwBt+cxnuC11UnjLn0NhAyw3yEnHehRtEvCo1dpiYIkOsyfMDhtM/rO6flC 9sVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=JA966Qz9; dkim=pass header.i=@codeaurora.org header.s=default header.b=UKMkvVpE; 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 i124-v6si288704pfc.110.2018.07.19.15.19.28; Thu, 19 Jul 2018 15:19:43 -0700 (PDT) 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=pass header.i=@codeaurora.org header.s=default header.b=JA966Qz9; dkim=pass header.i=@codeaurora.org header.s=default header.b=UKMkvVpE; 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 S1730897AbeGSXEB (ORCPT + 99 others); Thu, 19 Jul 2018 19:04:01 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:48302 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730383AbeGSXEA (ORCPT ); Thu, 19 Jul 2018 19:04:00 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7C03560B1E; Thu, 19 Jul 2018 22:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1532038734; bh=PGYF59ny5Qx8fu1sEfS/nVzeA68tRuCHlJyVezeXR2Q=; h=From:To:Cc:Subject:Date:From; b=JA966Qz96kZ9Tc7HbuDcTNtoRR0AlsCWDt/Y+GbZJy9fhKh+A4oIKykZlHa0N3C6Q NfpcjdohByUOxSorAhm0AuChbUQHaCFXszLPDuOmXHYAe+/MWsW55iRBYd4BgJW6QO sP50IxqDxdF6p4lbFAh+kmSg02LYJ1x+gRfacQhI= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from vgutta-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vnkgutta@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 05E1C60274; Thu, 19 Jul 2018 22:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1532038733; bh=PGYF59ny5Qx8fu1sEfS/nVzeA68tRuCHlJyVezeXR2Q=; h=From:To:Cc:Subject:Date:From; b=UKMkvVpEEWc2LnY6vZeqO4/0tUOKiJPiVbjlhsdXwhdcnPUWGnBvB9/3nl0+g3+oY YbP0NNP15P5SALlOHLrMox+D2J9jMOYlhoY06ZKnFhfOtLStukk2+k5PYqN3SyM9+2 qUl8rP+LEleiqzDQnJMflOIv8LRwtlhbB+q0p5CE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 05E1C60274 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vnkgutta@codeaurora.org From: Venkata Narendra Kumar Gutta To: linux-arm-kernel@lists.infradead.org, tsoni@codeaurora.org, ckadabi@codeaurora.org, rishabhb@codeaurora.org, linux-kernel@vger.kernel.org, robh@kernel.org, hoeun.ryu@gmail.com, adobriyan@gmail.com, zhizhouzhang@asrmicro.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, will.deacon@arm.com, catalin.marinas@arm.com Cc: Abhimanyu Kapur , Venkata Narendra Kumar Gutta Subject: [PATCH] ARM64: smp: Fix cpu_up() racing with sys_reboot Date: Thu, 19 Jul 2018 15:18:46 -0700 Message-Id: <1532038726-3376-1-git-send-email-vnkgutta@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nothing stops a process from hotplugging in a CPU concurrently with a sys_reboot() call. In such a situation we could have ipi_cpu_stop() mark a cpu as 'offline' and _cpu_up() ignore the fact that the CPU is not really offline and call the CPU_UP_PREPARE notifier. When this happens stop_machine code will complain that the cpu thread already exists and BUG_ON(). CPU0 CPU1 sys_reboot() kernel_restart() machine_restart() machine_shutdown() smp_send_stop() ... ipi_cpu_stop() set_cpu_online(1, false) local_irq_disable() while(1) cpu_up() _cpu_up() if (!cpu_online(1)) __cpu_notify(CPU_UP_PREPARE...) cpu_stop_cpu_callback() BUG_ON(stopper->thread) This is easily reproducible by hotplugging in and out in a tight loop while also rebooting. Since the CPU is not really offline and hasn't gone through the proper steps to be marked as such, let's mark the CPU as inactive. This is just as easily testable as online and avoids any possibility of _cpu_up() trying to bring the CPU back online when it never was offline to begin with. Based on the similar patchset by for arm targets 040c163( "ARM: smp: Fix cpu_up() racing with sys_reboot)" Signed-off-by: Abhimanyu Kapur Signed-off-by: Venkata Narendra Kumar Gutta --- arch/arm64/kernel/smp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 2faa986..adee4d3 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -790,7 +790,7 @@ void arch_irq_work_raise(void) */ static void ipi_cpu_stop(unsigned int cpu) { - set_cpu_online(cpu, false); + set_cpu_active(cpu, false); local_daif_mask(); sdei_mask_local_cpu(); @@ -925,10 +925,10 @@ void smp_send_stop(void) /* Wait up to one second for other CPUs to stop */ timeout = USEC_PER_SEC; - while (num_online_cpus() > 1 && timeout--) + while (num_active_cpus() > 1 && timeout--) udelay(1); - if (num_online_cpus() > 1) + if (num_active_cpus() > 1) pr_warning("SMP: failed to stop secondary CPUs %*pbl\n", cpumask_pr_args(cpu_online_mask)); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project