Received: by 10.223.164.202 with SMTP id h10csp210653wrb; Mon, 13 Nov 2017 05:20:01 -0800 (PST) X-Google-Smtp-Source: AGs4zMZggdmXd/ZyFmVtY7SDzIwUwZXLZyOPctdjyPyKMZ7+cnEPz8cISxTdOpAcr0qmF1bP8lwZ X-Received: by 10.159.252.1 with SMTP id n1mr8865939pls.415.1510579201781; Mon, 13 Nov 2017 05:20:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510579201; cv=none; d=google.com; s=arc-20160816; b=L2JfLnkiGvflpfIo59cS249xKLPFpHQz9kmSvGvryJeRI/5CUmRoXzwyHJSk3tayXc tAG69FsWB00WiWaGYYlNnoUW83AVcV6ymv3P0Z1SaHWn9EYrPXveNYDvPFhMXqUvpggn uCmpmvZtSQsb0IJEcHA5/FN5ndt05ykExssbP6rpZl5xKJRQL9BEguHLnip9bFYZvwu4 3bFkqyZ9QB7JzipZsI0Bu3tdIZXSZhwCMJ8EMbOGEo8+m/+xldrKJlRw0TmE9bEGFTFH apP/hz7kliRqXdjurKNHfYjHjjer3IfK+ld9DrFLKJ/PXS8Y+SNuGLzf3PktrIphTh5g Y12w== 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=NzfDG4k+RIP5lBQQmMTow6LYAF77SKk+ELd9rT8YJxM=; b=LGjqOAmqzS739u8HJ8Vw0ldVJxON6kVj73iNV4wQi/XGdoWvor08yhNu8huUBmLKoa dMbn9NgAcCv+uPfJE9llsoPvoycHn/HH9Y4HnENDrQXet4HDOsfiUTdx1ZrCMa08aPWM gkq942Fm4a4kcmQfw54573TJVFczJGHw7xn3rs9xsRSvU/z66ZkzGAkaUP5/repVs/ES h4Q0KuLJX4DiSXddHoMXKSBDJqiPAGinpBFiU/Y+6XIWD1BzIJdQjEEYv5y9rFpDdQaG 4dCVBN6ibkUhQd6YsmziQAmzkGGGZosi79SuNrZDfj1Mf6RO5wMXdMQ84+vJIwMYe0zW suKw== 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 r7si13531118pgf.713.2017.11.13.05.19.48; Mon, 13 Nov 2017 05:20:01 -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 S1754791AbdKMNCK (ORCPT + 95 others); Mon, 13 Nov 2017 08:02:10 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50624 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754768AbdKMNCH (ORCPT ); Mon, 13 Nov 2017 08:02:07 -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 65EE8AAE; Mon, 13 Nov 2017 13:02:04 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matija Glavinic Pecotic , Alexander Sverdlin , linux-mips@linux-mips.org, Ralf Baechle Subject: [PATCH 4.9 68/87] MIPS: Fix race on setting and getting cpu_online_mask Date: Mon, 13 Nov 2017 13:56:25 +0100 Message-Id: <20171113125621.475541426@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: Matija Glavinic Pecotic commit 6f542ebeaee0ee552a902ce3892220fc22c7ec8e upstream. While testing cpu hoptlug (cpu down and up in loops) on kernel 4.4, it was observed that occasionally check for cpu online will fail in kernel/cpu.c, _cpu_up: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/kernel/cpu.c?h=v4.4.79#n485 518 /* Arch-specific enabling code. */ 519 ret = __cpu_up(cpu, idle); 520 521 if (ret != 0) 522 goto out_notify; 523 BUG_ON(!cpu_online(cpu)); Reason is race between start_secondary and _cpu_up. cpu_callin_map is set before cpu_online_mask. In __cpu_up, cpu_callin_map is waited for, but cpu online mask is not, resulting in race in which secondary processor started and set cpu_callin_map, but not yet set the online mask,resulting in above BUG being hit. Upstream differs in the area. cpu_online check is in bringup_wait_for_ap, which is after cpu reached AP_ONLINE_IDLE,where secondary passed its start function. Nonetheless, fix makes start_secondary safe and not depending on other locks throughout the code. It protects as well against cpu_online checks put in between sometimes in the future. Fix this by moving completion after all flags are set. Signed-off-by: Matija Glavinic Pecotic Cc: Alexander Sverdlin Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/16925/ Signed-off-by: Ralf Baechle Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/smp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -371,9 +371,6 @@ asmlinkage void start_secondary(void) cpumask_set_cpu(cpu, &cpu_coherent_mask); notify_cpu_starting(cpu); - complete(&cpu_running); - synchronise_count_slave(cpu); - set_cpu_online(cpu, true); set_cpu_sibling_map(cpu); @@ -381,6 +378,9 @@ asmlinkage void start_secondary(void) calculate_cpu_foreign_map(); + complete(&cpu_running); + synchronise_count_slave(cpu); + /* * irq will be enabled in ->smp_finish(), enabling it too early * is dangerous. From 1583956678166630519@xxx Mon Nov 13 13:13:22 +0000 2017 X-GM-THRID: 1583956678166630519 X-Gmail-Labels: Inbox,Category Updates,HistoricalUnread