Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp833189pja; Wed, 1 Apr 2020 09:31:50 -0700 (PDT) X-Google-Smtp-Source: APiQypJsyyeSqJtUZ/hL/7XgT2J76fXRSK51fkg+q8tuzqqmjIlsNs/XVFLQUBGRmqL/oPIbAuXB X-Received: by 2002:aca:5403:: with SMTP id i3mr3544477oib.174.1585758709647; Wed, 01 Apr 2020 09:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585758709; cv=none; d=google.com; s=arc-20160816; b=dfz0/IRvcW58JIKeNmafpcoZPp321jwIiblke59HJ/CztQciafbjf8HtXym2kmyaA2 WALP505/8XIa2e07zlfKXnFKoNUKiYU+w4EhwNholh0zvGFlmLCLMEMGalpYeawCGLOq 1NM5Orz7oBFTEGjmJ3Qoizj/RUAIxFaKitk6l5JC4rzUdHeu4Q0nps8wc/8vVPNDNcUd 6ar3CkW7K5pvuOlYwj+s+cNDq2jLYFuCl+A9lR8EMEXpe4BmRFgLygXaeeWgZH9bPwte ogj9BgFXseKwj/8Cna9c2ugqFKdNBWE47hf9RSqv/f67PkO72yOwKXZRNpCPZJPjJIig 0BFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=imV6I3/uAzfSQhsU1L2IJwtrPGFCYyMTCl83WrG2VmA=; b=YOUuE6qfKQpuOlKlsZWRWlbSyfeF8YXEAgvzEtl7IjkKdSq3IfYi64xmRM2KUWJy1w fWiua7ai3jpr/4gIJS5n358BIQCtPavtkrxdhCQHmrE8ycz7nPvaQn7pgdFzV3eBgIni r6VQjrc7Bv8wGt0M8wGpcD+1mkVYo71M9sk+2jM1UHoWUS/wo9vfsr982ReNOuHV8lRh Nhp3SYcLQ1FG0O+Vun5cttKMtsL/wCbTgBPfVmOx1Goo4rBliz8XkwC4esTgvGlD23Z3 XDs/FicQIu+M1qVjHqfAc5KJHUE15xSHlorXKGCH3IXb64Loi0Nxr7jc1Rinklf1KuzG w1vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=11Cw9ZHD; 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 x136si1088990oif.122.2020.04.01.09.31.36; Wed, 01 Apr 2020 09:31:49 -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=@kernel.org header.s=default header.b=11Cw9ZHD; 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 S2387807AbgDAQao (ORCPT + 99 others); Wed, 1 Apr 2020 12:30:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387649AbgDAQam (ORCPT ); Wed, 1 Apr 2020 12:30:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B2002137B; Wed, 1 Apr 2020 16:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585758641; bh=B1JqZLJuWW+QWK97LdjyPhekqbup566AvV18ey+cPh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=11Cw9ZHDWKDFszLQwG93MyGc++AWx/gZe9zk+vfwcl6V119N3BkbMvi257/vfsFus bTM2unWRNoknhq4rKN/405hNtKRKys2jpHRq5tGC94qg0+RcRXrkgziWsTW0szccTk pEnQsybb4u+0BfU6u1GGGgqLe2psL2g7VlciejN0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Martin , Mark Rutland , Cristian Marussi , Will Deacon Subject: [PATCH 4.4 32/91] arm64: smp: fix smp_send_stop() behaviour Date: Wed, 1 Apr 2020 18:17:28 +0200 Message-Id: <20200401161524.675710937@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161512.917494101@linuxfoundation.org> References: <20200401161512.917494101@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cristian Marussi commit d0bab0c39e32d39a8c5cddca72e5b4a3059fe050 upstream. On a system with only one CPU online, when another one CPU panics while starting-up, smp_send_stop() will fail to send any STOP message to the other already online core, resulting in a system still responsive and alive at the end of the panic procedure. [ 186.700083] CPU3: shutdown [ 187.075462] CPU2: shutdown [ 187.162869] CPU1: shutdown [ 188.689998] ------------[ cut here ]------------ [ 188.691645] kernel BUG at arch/arm64/kernel/cpufeature.c:886! [ 188.692079] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 188.692444] Modules linked in: [ 188.693031] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 5.6.0-rc4-00001-g338d25c35a98 #104 [ 188.693175] Hardware name: Foundation-v8A (DT) [ 188.693492] pstate: 200001c5 (nzCv dAIF -PAN -UAO) [ 188.694183] pc : has_cpuid_feature+0xf0/0x348 [ 188.694311] lr : verify_local_elf_hwcaps+0x84/0xe8 [ 188.694410] sp : ffff800011b1bf60 [ 188.694536] x29: ffff800011b1bf60 x28: 0000000000000000 [ 188.694707] x27: 0000000000000000 x26: 0000000000000000 [ 188.694801] x25: 0000000000000000 x24: ffff80001189a25c [ 188.694905] x23: 0000000000000000 x22: 0000000000000000 [ 188.694996] x21: ffff8000114aa018 x20: ffff800011156a38 [ 188.695089] x19: ffff800010c944a0 x18: 0000000000000004 [ 188.695187] x17: 0000000000000000 x16: 0000000000000000 [ 188.695280] x15: 0000249dbde5431e x14: 0262cbe497efa1fa [ 188.695371] x13: 0000000000000002 x12: 0000000000002592 [ 188.695472] x11: 0000000000000080 x10: 00400032b5503510 [ 188.695572] x9 : 0000000000000000 x8 : ffff800010c80204 [ 188.695659] x7 : 00000000410fd0f0 x6 : 0000000000000001 [ 188.695750] x5 : 00000000410fd0f0 x4 : 0000000000000000 [ 188.695836] x3 : 0000000000000000 x2 : ffff8000100939d8 [ 188.695919] x1 : 0000000000180420 x0 : 0000000000180480 [ 188.696253] Call trace: [ 188.696410] has_cpuid_feature+0xf0/0x348 [ 188.696504] verify_local_elf_hwcaps+0x84/0xe8 [ 188.696591] check_local_cpu_capabilities+0x44/0x128 [ 188.696666] secondary_start_kernel+0xf4/0x188 [ 188.697150] Code: 52805001 72a00301 6b01001f 54000ec0 (d4210000) [ 188.698639] ---[ end trace 3f12ca47652f7b72 ]--- [ 188.699160] Kernel panic - not syncing: Attempted to kill the idle task! [ 188.699546] Kernel Offset: disabled [ 188.699828] CPU features: 0x00004,20c02008 [ 188.700012] Memory Limit: none [ 188.700538] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]--- [root@arch ~]# echo Helo Helo [root@arch ~]# cat /proc/cpuinfo | grep proce processor : 0 Make smp_send_stop() account also for the online status of the calling CPU while evaluating how many CPUs are effectively online: this way, the right number of STOPs is sent, so enforcing a proper freeze of the system at the end of panic even under the above conditions. Fixes: 08e875c16a16c ("arm64: SMP support") Reported-by: Dave Martin Acked-by: Mark Rutland Signed-off-by: Cristian Marussi Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/smp.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -769,11 +769,22 @@ void tick_broadcast(const struct cpumask } #endif +/* + * The number of CPUs online, not counting this CPU (which may not be + * fully online and so not counted in num_online_cpus()). + */ +static inline unsigned int num_other_online_cpus(void) +{ + unsigned int this_cpu_online = cpu_online(smp_processor_id()); + + return num_online_cpus() - this_cpu_online; +} + void smp_send_stop(void) { unsigned long timeout; - if (num_online_cpus() > 1) { + if (num_other_online_cpus()) { cpumask_t mask; cpumask_copy(&mask, cpu_online_mask); @@ -784,10 +795,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_other_online_cpus() && timeout--) udelay(1); - if (num_online_cpus() > 1) + if (num_other_online_cpus()) pr_warning("SMP: failed to stop secondary CPUs\n"); }