Received: by 10.223.164.202 with SMTP id h10csp210889wrb; Mon, 13 Nov 2017 05:20:15 -0800 (PST) X-Google-Smtp-Source: AGs4zMZleHl+hd2Eb3601apPu19SJrlzkOUb3eOnSJVdwKcNfzYaDn58QcYvxdWqmljxJdGWe4QP X-Received: by 10.99.120.131 with SMTP id t125mr8586491pgc.81.1510579215190; Mon, 13 Nov 2017 05:20:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510579215; cv=none; d=google.com; s=arc-20160816; b=zApXuQYpu93l32EMmg4WMbBOyO1r0RUlakxnCPdUU/4ryZw2cpzBA1r/O5W1TjbCpY TtualF1BOZUoI8xTzmncsUm9S+klkZ0qAFzWnmRD9FF0+L7uk3XkUt/m9J9Bf25IULL7 FGto96MzXuZfJpGWkU1wlyI5aB+F62temCXX5iN7XGShiNDmZMCufFm/lw0Ed7sh9mBt aVQ9Glv8/Rk3PNzi/ODgy09JusSCfnOag3Dm8Liakh+ES0EN9OxzPUATpi307XHYltVu z8sClpnmoaHFrwZ9FcC4GSzwZZGjIejJWcw0yis3v/Cch/MH5hMLajfGjKq68NsHaZsP ompw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=WCBA2Cae2S7Vajq2W1yLvMfvgZzvYhDXE6pHrv169Gk=; b=tijqj/yZqR1Invij6hYM/th36nj1Jy187h4yRLsuHzZyuu0nWpW0IwV4QJPhw10re7 iIYIyy3G5rpFtvQvIBu5lmC6TF/rMkwSwzpHEcI0SNJwCMW6kXGcCLezvf3J22fnpVbL eizuzAUVVVov+GNQfr/t/lfcF3gdyGeW/enEOkxCRVl+55LN9BcxwaV5yyauop0a9OpZ oOj98DadQN5p1LOYMt6zYiPcbWJbT+haIG+9zwCRTsMkA9rlcisjbKSvQ4vIimTKx2qj 3C0LTP3R511Wsu4zw7dOb7Ox0j+AlH3p6dnsRYTNH5JmE4I1ngPx8+CbDy9C3y3Uk+NB mX6Q== 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 r6si14444566pls.575.2017.11.13.05.20.02; Mon, 13 Nov 2017 05:20:15 -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 S1753652AbdKMNT3 (ORCPT + 95 others); Mon, 13 Nov 2017 08:19:29 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50670 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754346AbdKMNCJ (ORCPT ); Mon, 13 Nov 2017 08:02:09 -0500 Received: from localhost (LFbn-1-12253-150.w90-92.abo.wanadoo.fr [90.92.67.150]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 23CA0AB5; Mon, 13 Nov 2017 13:02:06 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matt Redfearn , Matija Glavinic Pecotic , James Hogan Subject: [PATCH 4.9 69/87] MIPS: SMP: Fix deadlock & online race Date: Mon, 13 Nov 2017 13:56:26 +0100 Message-Id: <20171113125621.560497439@linuxfoundation.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171113125615.304035578@linuxfoundation.org> References: <20171113125615.304035578@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matt Redfearn commit 9e8c399a88f0b87e41a894911475ed2a8f8dff9e upstream. Commit 6f542ebeaee0 ("MIPS: Fix race on setting and getting cpu_online_mask") effectively reverted commit 8f46cca1e6c06 ("MIPS: SMP: Fix possibility of deadlock when bringing CPUs online") and thus has reinstated the possibility of deadlock. The commit was based on testing of kernel v4.4, where the CPU hotplug core code issued a BUG() if the starting CPU is not marked online when the boot CPU returns from __cpu_up. The commit fixes this race (in v4.4), but re-introduces the deadlock situation. As noted in the commit message, upstream differs in this area. Commit 8df3e07e7f21f ("cpu/hotplug: Let upcoming cpu bring itself fully up") adds a completion event in the CPU hotplug core code, making this race impossible. However, people were unhappy with relying on the core code to do the right thing. To address the issues both commits were trying to fix, add a second completion event in the MIPS smp hotplug path. It removes the possibility of a race, since the MIPS smp hotplug code now synchronises both the boot and secondary CPUs before they return to the hotplug core code. It also addresses the deadlock by ensuring that the secondary CPU is not marked online before it's counters are synchronised. This fix should also be backported to fix the race condition introduced by the backport of commit 8f46cca1e6c06 ("MIPS: SMP: Fix possibility of deadlock when bringing CPUs online"), through really that race only existed before commit 8df3e07e7f21f ("cpu/hotplug: Let upcoming cpu bring itself fully up"). Signed-off-by: Matt Redfearn Fixes: 6f542ebeaee0 ("MIPS: Fix race on setting and getting cpu_online_mask") CC: Matija Glavinic Pecotic Patchwork: https://patchwork.linux-mips.org/patch/17376/ Signed-off-by: James Hogan [jhogan@kernel.org: Backported 4.1..4.9] Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/smp.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -68,6 +68,7 @@ EXPORT_SYMBOL(cpu_sibling_map); cpumask_t cpu_core_map[NR_CPUS] __read_mostly; EXPORT_SYMBOL(cpu_core_map); +static DECLARE_COMPLETION(cpu_starting); static DECLARE_COMPLETION(cpu_running); /* @@ -371,6 +372,12 @@ asmlinkage void start_secondary(void) cpumask_set_cpu(cpu, &cpu_coherent_mask); notify_cpu_starting(cpu); + /* Notify boot CPU that we're starting & ready to sync counters */ + complete(&cpu_starting); + + synchronise_count_slave(cpu); + + /* The CPU is running and counters synchronised, now mark it online */ set_cpu_online(cpu, true); set_cpu_sibling_map(cpu); @@ -378,8 +385,11 @@ asmlinkage void start_secondary(void) calculate_cpu_foreign_map(); + /* + * Notify boot CPU that we're up & online and it can safely return + * from __cpu_up + */ complete(&cpu_running); - synchronise_count_slave(cpu); /* * irq will be enabled in ->smp_finish(), enabling it too early @@ -438,17 +448,17 @@ int __cpu_up(unsigned int cpu, struct ta { mp_ops->boot_secondary(cpu, tidle); - /* - * We must check for timeout here, as the CPU will not be marked - * online until the counters are synchronised. - */ - if (!wait_for_completion_timeout(&cpu_running, + /* Wait for CPU to start and be ready to sync counters */ + if (!wait_for_completion_timeout(&cpu_starting, msecs_to_jiffies(1000))) { pr_crit("CPU%u: failed to start\n", cpu); return -EIO; } synchronise_count_master(cpu); + + /* Wait for CPU to finish startup & mark itself online before return */ + wait_for_completion(&cpu_running); return 0; } From 1583999078332129939@xxx Tue Nov 14 00:27:18 +0000 2017 X-GM-THRID: 1583733269071130633 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread