Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2316235imc; Tue, 12 Mar 2019 11:13:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKMnk4lgfmRgowqJRkQNqxKd2adK0YIFqBEeI40f2BfqBauVeVPPw6HupQ4LU0E6swrotK X-Received: by 2002:a62:cf02:: with SMTP id b2mr39529777pfg.71.1552414407985; Tue, 12 Mar 2019 11:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552414407; cv=none; d=google.com; s=arc-20160816; b=D584ELDJF87hZTei+F9J9gUaqUMD6cCyT/bo/+GktfNEPgVdib3qay8PpWxGOfMImV gVY9VcFbjYy6xxka2S6NGGGGclIk/Jk0wfBHaaE3AfEh9MqeI6N3bV1cwujVcyaZs4Ar WHcAhNNabY69yafkeXZA3jrTYER1UZDFXvO9ESTDsdCxfiODi8r5f5I9HomuqVdl1MWj 7SQqV9ede4WdroiNYSLxW2BO8/pcWAQ6WOgePn2A0gKcz2TplhLfeJrsvEr12srUQXuE svqObQf379iOIrT/bJoA/Z1G4jwDJQBPpVym8e25LwrO7zt+UOzBA2ztATsGhZUjJVg8 u9AA== 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=xPV+GWg1ymIgTeCAFGpj4duOYfI2oYbnfEr2YoPzm5k=; b=HS8kfnft3iw491CVVMZ2Ol4OMr7TVzHo7mKUomNS3ZSc77D1Rph4ab4hWWNJExPl3i y8ig2oB2vl2diShQfA5Gn6+Tm1Fsr3/uvVJgG3EXXyXa6RouRhRyeKlSYSI5TZMX6x81 hK8X5wqjNCEM1RJyzE6b0f00R0yjhuPzbD+fveVQT/TD0NtYjP9vobXjhXGaQiWi+mEF e0Wu5buHriAUMMgeRIxo04ReHHUcZeUk2bsLGUT23xbBycbwYpj2o+XXLp3PZ/PEXxWP gEdV3etAOgr21SSbsF9wYQk11j/DjdcQyaQ1cwdezNda7zYZMMvV5a18LQzhS3GrsLI7 OYpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PKxzLIvT; 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 k7si8462257plt.198.2019.03.12.11.13.11; Tue, 12 Mar 2019 11:13:27 -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=PKxzLIvT; 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 S1729374AbfCLSKb (ORCPT + 99 others); Tue, 12 Mar 2019 14:10:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:45962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbfCLRLx (ORCPT ); Tue, 12 Mar 2019 13:11:53 -0400 Received: from localhost (unknown [104.133.8.98]) (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 B65B8214AE; Tue, 12 Mar 2019 17:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410711; bh=sWPq+YBYelIVtVm9NhMJgi8U7/XEdMu3gPww/xgAOo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PKxzLIvTC+IIzl/D9tGOI79IsQhDoLmQHn7mOBhkgONPqA3CrSGEhHTuXID301uJa bccW3FCKUcsQOzcatZmQEbDB9D05/DAcd7HLMY4zkCtJXiX3ck1ju8Zs2k4I5azBvk GylGB7MILsPpcO4G5Z3HCGSQBgL+KrISgTHGyBTA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Max Filippov , Sasha Levin Subject: [PATCH 4.20 025/171] xtensa: SMP: fix secondary CPU initialization Date: Tue, 12 Mar 2019 10:06:45 -0700 Message-Id: <20190312170350.108634865@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170347.868927101@linuxfoundation.org> References: <20190312170347.868927101@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 32a7726c4f4aadfabdb82440d84f88a5a2c8fe13 ] - add missing memory barriers to the secondary CPU synchronization spin loops; add comment to the matching memory barrier in the boot_secondary and __cpu_die functions; - use READ_ONCE/WRITE_ONCE to access cpu_start_id/cpu_start_ccount instead of reading/writing them directly; - re-initialize cpu_running every time before starting secondary CPU to flush possible previous CPU startup results. Signed-off-by: Max Filippov Signed-off-by: Sasha Levin --- arch/xtensa/kernel/head.S | 5 ++++- arch/xtensa/kernel/smp.c | 34 +++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/arch/xtensa/kernel/head.S b/arch/xtensa/kernel/head.S index 9053a5622d2c..5bd38ea2da38 100644 --- a/arch/xtensa/kernel/head.S +++ b/arch/xtensa/kernel/head.S @@ -280,12 +280,13 @@ should_never_return: movi a2, cpu_start_ccount 1: + memw l32i a3, a2, 0 beqi a3, 0, 1b movi a3, 0 s32i a3, a2, 0 - memw 1: + memw l32i a3, a2, 0 beqi a3, 0, 1b wsr a3, ccount @@ -321,11 +322,13 @@ ENTRY(cpu_restart) rsr a0, prid neg a2, a0 movi a3, cpu_start_id + memw s32i a2, a3, 0 #if XCHAL_DCACHE_IS_WRITEBACK dhwbi a3, 0 #endif 1: + memw l32i a2, a3, 0 dhi a3, 0 bne a2, a0, 1b diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c index 932d64689bac..c9fc2c4f71b3 100644 --- a/arch/xtensa/kernel/smp.c +++ b/arch/xtensa/kernel/smp.c @@ -195,9 +195,11 @@ static int boot_secondary(unsigned int cpu, struct task_struct *ts) int i; #ifdef CONFIG_HOTPLUG_CPU - cpu_start_id = cpu; - system_flush_invalidate_dcache_range( - (unsigned long)&cpu_start_id, sizeof(cpu_start_id)); + WRITE_ONCE(cpu_start_id, cpu); + /* Pairs with the third memw in the cpu_restart */ + mb(); + system_flush_invalidate_dcache_range((unsigned long)&cpu_start_id, + sizeof(cpu_start_id)); #endif smp_call_function_single(0, mx_cpu_start, (void *)cpu, 1); @@ -206,18 +208,21 @@ static int boot_secondary(unsigned int cpu, struct task_struct *ts) ccount = get_ccount(); while (!ccount); - cpu_start_ccount = ccount; + WRITE_ONCE(cpu_start_ccount, ccount); - while (time_before(jiffies, timeout)) { + do { + /* + * Pairs with the first two memws in the + * .Lboot_secondary. + */ mb(); - if (!cpu_start_ccount) - break; - } + ccount = READ_ONCE(cpu_start_ccount); + } while (ccount && time_before(jiffies, timeout)); - if (cpu_start_ccount) { + if (ccount) { smp_call_function_single(0, mx_cpu_stop, - (void *)cpu, 1); - cpu_start_ccount = 0; + (void *)cpu, 1); + WRITE_ONCE(cpu_start_ccount, 0); return -EIO; } } @@ -237,6 +242,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) pr_debug("%s: Calling wakeup_secondary(cpu:%d, idle:%p, sp: %08lx)\n", __func__, cpu, idle, start_info.stack); + init_completion(&cpu_running); ret = boot_secondary(cpu, idle); if (ret == 0) { wait_for_completion_timeout(&cpu_running, @@ -298,8 +304,10 @@ void __cpu_die(unsigned int cpu) unsigned long timeout = jiffies + msecs_to_jiffies(1000); while (time_before(jiffies, timeout)) { system_invalidate_dcache_range((unsigned long)&cpu_start_id, - sizeof(cpu_start_id)); - if (cpu_start_id == -cpu) { + sizeof(cpu_start_id)); + /* Pairs with the second memw in the cpu_restart */ + mb(); + if (READ_ONCE(cpu_start_id) == -cpu) { platform_cpu_kill(cpu); return; } -- 2.19.1