From patchwork Wed Dec 26 23:08:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10743327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E85517FB for ; Wed, 26 Dec 2018 23:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CE4A28620 for ; Wed, 26 Dec 2018 23:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FFA7286A4; Wed, 26 Dec 2018 23:09:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D1DCF28620 for ; Wed, 26 Dec 2018 23:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BtEcL+yTIvT80jvmcnCq3jEn3iRigR8dKWdSGL7/ADs=; b=WoD17Xyc996XdSZXDN+fKP82KH jzy85GKwkDKfSVX6+zNztPHztjATwJrI94+7kKYyZehQDARBm1JEcyWjwPgFxQ4uI41+nvDthNVP+ nCP96dYQWxlOKLm0IPP5KjwFsb7+xyWCRz1iqG7JidDkumIo0Bu19YFFeoHLdsinkQfbvT/geg1kN uTL1XEatCG3Xi+u2pvfhbwifXvY2/sX4k5jhFl1WASiEFSXtTzneK8uTytG0Xog8Un2t3TriJsU9H E7EoZ6COvMgNHp+zjd8ccP7oLeY/Y40Fr16oJ+by02Efp5zUZOSyLBTEH/nUM6O4Z3QX+M5vfoU2c o5JLA5yQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcIIn-0002DP-He; Wed, 26 Dec 2018 23:09:25 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcIIk-00027y-SA for linux-riscv@lists.infradead.org; Wed, 26 Dec 2018 23:09:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1545865763; x=1577401763; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=8S/RrFDjuKHkFUQKssSKhJVyNonR+n8bd5mR5vPrqWA=; b=hTmWRca0sTnqfGShZXufy5EEs04OsDmSRyR3wVoX3EvnogZPc8KvfXjB 90bYT9HIAH+6MibqDJEGcIL4ZqLw9UB1L/69ZI2ChVVJBV94YCeKekcxI ERA803zZYVnnwxfRhxfzhDwaeDF2oitHm54HRmvre2Q4R4jv1/H7aDkuN Ax3MkEg5OR2UfsTUZyEf9HQxhUfC8d/+k77eUwZINsg4ZSKUK6gtEZ8K3 +xz1Jthp5Fv3oWy892KBZSIhRY+oaHQ0Rba7yEUBpL3ySuCYLx+WPdWER SiMYiei2LeMz/8y2OUL+bZfqjlr89Lw1f0X+WHzFmc3Une8AtKsLwoTli g==; X-IronPort-AV: E=Sophos;i="5.56,401,1539619200"; d="scan'208";a="99246004" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Dec 2018 07:09:07 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 26 Dec 2018 14:49:51 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Dec 2018 15:09:07 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH 1/3] RISC-V: Do not wait indefinitely in __cpu_up Date: Wed, 26 Dec 2018 15:08:59 -0800 Message-Id: <1545865741-22795-2-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545865741-22795-1-git-send-email-atish.patra@wdc.com> References: <1545865741-22795-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181226_150922_946003_58F4CB4E X-CRM114-Status: GOOD ( 13.59 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Marc Zyngier , Thomas Gleixner MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In SMP path, __cpu_up waits for other CPU to come online indefinitely. This is wrong as other CPU might be disabled in machine mode and possible CPU is set to the cpus present in DT. Introduce a completion variable and waits only for a second. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/kernel/smpboot.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 18cda0e8..bb8cd242 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -39,6 +39,7 @@ void *__cpu_up_stack_pointer[NR_CPUS]; void *__cpu_up_task_pointer[NR_CPUS]; +static DECLARE_COMPLETION(cpu_running); void __init smp_prepare_boot_cpu(void) { @@ -77,6 +78,7 @@ void __init setup_smp(void) int __cpu_up(unsigned int cpu, struct task_struct *tidle) { + int ret = 0; int hartid = cpuid_to_hartid_map(cpu); tidle->thread_info.cpu = cpu; @@ -92,10 +94,15 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle) task_stack_page(tidle) + THREAD_SIZE); WRITE_ONCE(__cpu_up_task_pointer[hartid], tidle); - while (!cpu_online(cpu)) - cpu_relax(); + wait_for_completion_timeout(&cpu_running, + msecs_to_jiffies(1000)); - return 0; + if (!cpu_online(cpu)) { + pr_crit("CPU%u: failed to come online\n", cpu); + ret = -EIO; + } + + return ret; } void __init smp_cpus_done(unsigned int max_cpus) @@ -121,6 +128,7 @@ asmlinkage void __init smp_callin(void) * a local TLB flush right now just in case. */ local_flush_tlb_all(); + complete(&cpu_running); /* * Disable preemption before enabling interrupts, so we don't try to * schedule a CPU that hasn't actually started yet. From patchwork Wed Dec 26 23:09:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10743333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C9806C2 for ; Wed, 26 Dec 2018 23:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39DD62861E for ; Wed, 26 Dec 2018 23:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DF4628647; Wed, 26 Dec 2018 23:09:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA47F28622 for ; Wed, 26 Dec 2018 23:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zAKvRPNM+TpreEgv1u56FLxijFnb++xOkH4pZ6qO9YQ=; b=VWB2Glaq/vFxWOfB+hfI1PwsYZ IIH2223guHEZGiA2ZxkWC1lOz7veS2KbnTbxqq6nD6Y9wZyPA7jee6L8cBhprzBBnFULgmWTjOGvx V9BLGkeaZV8Fb77p03yAwr7MV2/QD63m2sY1wNElzDCLVx0/I7N01Ixk1sK2GxbAtmBglQKQbJptv 5kO1sLI8Tcl9I4Go8x6/KUHXfJZ/oVEh6g4tWMT/eBBW6va3iT2TlN63gnInnXcWyEOHiVbgdnjQU IhgBLOOXjejv5FQRwbXU116vd8JEzJt3Yuz9+BX9VclnSQyfCxAQU47C8yMgxNM+Vz8QdfhhtELtG UD4RJD9Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcIIz-0002Lp-1l; Wed, 26 Dec 2018 23:09:37 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcIIv-0002CD-8b for linux-riscv@lists.infradead.org; Wed, 26 Dec 2018 23:09:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1545865773; x=1577401773; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=meu8IE2Cb35XRAORiR9qLyyfGNjZhzm1rUp8PRNo5pE=; b=HLRROgTWN0/wAyCM2UMk73KiuLIrVI+axPYP05XKrzz9+9FTRdSu9lxy F4RDzFOHxW/D0to5XNwiO9oabMYH1RSKa93pPn31NU+oe/feqPQyMB3x1 822TN35bFKqyzlyfZlQ6bXx6/QMHymn2JFK2IxuMLwDEBr3HTtLNomUxj 8NNOHdmjMm+h+bnkzjIhw0hevA30KCiJYgt0C3Jovlh3qWIl1l4Bw1eP1 x+bLT7j1W9reexm198L1K5X0nNaLIb006Enp+uzsN9AF1sKNX5CvorJg2 lXMjJOXqjK7WavMLw3/8dGE8evayVOBwSSSQrFBi00IPLm9nokPBSoBCQ g==; X-IronPort-AV: E=Sophos;i="5.56,401,1539619200"; d="scan'208";a="99246005" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Dec 2018 07:09:07 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 26 Dec 2018 14:49:51 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Dec 2018 15:09:07 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH 2/3] RISC-V: Move cpuid to hartid mapping to SMP. Date: Wed, 26 Dec 2018 15:09:00 -0800 Message-Id: <1545865741-22795-3-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545865741-22795-1-git-send-email-atish.patra@wdc.com> References: <1545865741-22795-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181226_150933_345406_E1AE79FB X-CRM114-Status: GOOD ( 13.12 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Marc Zyngier , Thomas Gleixner MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, logical CPU id to physical hartid mapping is defined for both smp and non-smp configurations. This is not required as we need this only for smp configuration. The mapping function can define directly boot_cpu_hartid for non-smp usecase. The reverse mapping function i.e. hartid to cpuid can be called for any valid but not booted harts. So it should return default cpu 0 only if it is a boot hartid Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/include/asm/smp.h | 13 +++++++++++-- arch/riscv/kernel/setup.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 41aa73b4..8f30300f 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -22,12 +22,13 @@ /* * Mapping between linux logical cpu index and hartid. */ -extern unsigned long __cpuid_to_hartid_map[NR_CPUS]; -#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu] +extern unsigned long boot_cpu_hartid; struct seq_file; #ifdef CONFIG_SMP +extern unsigned long __cpuid_to_hartid_map[NR_CPUS]; +#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu] /* print IPI stats */ void show_ipi_stats(struct seq_file *p, int prec); @@ -58,7 +59,15 @@ static inline void show_ipi_stats(struct seq_file *p, int prec) static inline int riscv_hartid_to_cpuid(int hartid) { + if (hartid == boot_cpu_hartid) return 0; + else + return -1; +} +static inline unsigned long cpuid_to_hartid_map(int cpu) +{ + + return boot_cpu_hartid; } static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in, diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 2c290e6a..bd4d7b85 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -83,6 +83,7 @@ EXPORT_SYMBOL(empty_zero_page); atomic_t hart_lottery; unsigned long boot_cpu_hartid; +#ifdef CONFIG_SMP unsigned long __cpuid_to_hartid_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HARTID }; @@ -91,6 +92,7 @@ void __init smp_setup_processor_id(void) { cpuid_to_hartid_map(0) = boot_cpu_hartid; } +#endif #ifdef CONFIG_BLK_DEV_INITRD static void __init setup_initrd(void) From patchwork Wed Dec 26 23:09:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10743331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1EA76C2 for ; Wed, 26 Dec 2018 23:09:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0FAD2861E for ; Wed, 26 Dec 2018 23:09:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9444228622; Wed, 26 Dec 2018 23:09:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AE272861E for ; Wed, 26 Dec 2018 23:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ruSGODaEuVOkGboB/lkObm5+Qm066qbELpcZb1vHcLc=; b=HhfqGWtVG6Ap7t1bNWvgacBkRv AmMCVyNpUFkTj8ghfc4n0ZZA3Jao04nWy2wIFaz4eccC2DJP4OQwxqnhzk6CrRvOE7HGO3p91LF7P 7c4rBbrTFxbw0uZz3eMwdplR9BrF3zpGu14NjXNNHEJSsvvvpynTTZ5nHK8qsqkuJtv/sGHdkhE8/ m1NYAOpNnODgYTouPCfYkRaN2FpTIkkRCYrFuzRxjFskjdUKXPatyJpcyLxS6GT7JFbwj2dnA2vCR cfCZaOS/5VywqkUz6reSZS4jnn58XgWR/pd/YErjTvZuWZ2nIyvnwF4bBCOUF986yBjd7osFnAPcW 7VIt/Cqw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcIIp-0002FU-Eo; Wed, 26 Dec 2018 23:09:27 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcIIm-00027y-Ct for linux-riscv@lists.infradead.org; Wed, 26 Dec 2018 23:09:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1545865764; x=1577401764; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Al1RyQfl0mslg7dvwfKrlns3Gv2SeAFssupFxW5Hyac=; b=SOwn9I5SlLHRIhNBezk8Hy/Ayh7utWT0XP/kf2FVZpClDFDPSg0g/QT+ 2NIFFu66xYOTExcXlaPW3kT+/GBuSOeJW4glijQsjaMfj5irOYqNjkybM +Q6blXM7cajWhaOWBKA8kQpGwml6WcI7ptczqePAEDV7Il90imvlW0kSU eTXKNaTRKw21zXDsJMmkASLZ4JEqqJfq9AheQbEMSwLkEXN4YdlsGC/uY 3cskUZy9zyGIzxhjAgnv7aRyEPzh1rffyKd9a/+f5Ca9ZEUpFy0gj19Mw YKINkA1Gzp1puyw3SQ2YZCCJEOjFW1kDKoGRhWtGdrTZ7qwPZjRFJfezu Q==; X-IronPort-AV: E=Sophos;i="5.56,401,1539619200"; d="scan'208";a="99246006" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Dec 2018 07:09:07 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 26 Dec 2018 14:49:52 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Dec 2018 15:09:08 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH 3/3] RISC-V: Fix non-smp kernel boot on SMP systems Date: Wed, 26 Dec 2018 15:09:01 -0800 Message-Id: <1545865741-22795-4-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545865741-22795-1-git-send-email-atish.patra@wdc.com> References: <1545865741-22795-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181226_150924_470235_780FF883 X-CRM114-Status: GOOD ( 14.73 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Marc Zyngier , Thomas Gleixner MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In non-smp configuration, hartid can be higher that NR_CPUS. riscv_of_processor_hartid should not be compared to hartid to NR_CPUS in that case. Moreover, this function checks all the DT properties of a hart node. NR_CPUS comparison seems out of place. Do cpuid comparison with NR_CPUs in smp setup code. Update the drivers to handle appropriate code as well. Signed-off-by: Atish Patra --- arch/riscv/kernel/cpu.c | 4 ---- arch/riscv/kernel/smp.c | 1 - arch/riscv/kernel/smpboot.c | 5 +++++ drivers/clocksource/riscv_timer.c | 21 ++++++++++++++++++--- drivers/irqchip/irq-sifive-plic.c | 5 +++++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index b4a7d442..251ffab6 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -34,10 +34,6 @@ int riscv_of_processor_hartid(struct device_node *node) pr_warn("Found CPU without hart ID\n"); return -(ENODEV); } - if (hart >= NR_CPUS) { - pr_info("Found hart ID %d, which is above NR_CPUs. Disabling this hart\n", hart); - return -(ENODEV); - } if (of_property_read_string(node, "status", &status)) { pr_warn("CPU with hartid=%d has no \"status\" property\n", hart); diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 57b1383e..9ea7ac7d 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -49,7 +49,6 @@ int riscv_hartid_to_cpuid(int hartid) return i; pr_err("Couldn't find cpu id for hartid [%d]\n", hartid); - BUG(); return i; } diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index bb8cd242..05291840 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -66,6 +66,11 @@ void __init setup_smp(void) found_boot_cpu = 1; continue; } + if (cpuid >= NR_CPUS) { + pr_warn("Invalid cpuid [%d] for hartid [%d]\n", + cpuid, hart); + break; + } cpuid_to_hartid_map(cpuid) = hart; set_cpu_possible(cpuid, true); diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c index 084e97dc..acf2af10 100644 --- a/drivers/clocksource/riscv_timer.c +++ b/drivers/clocksource/riscv_timer.c @@ -89,20 +89,35 @@ static int __init riscv_timer_init_dt(struct device_node *n) struct clocksource *cs; hartid = riscv_of_processor_hartid(n); + if (hartid < 0) { + pr_warn("Not valid hartid for node [%pOF] error = [%d]\n", + n, hartid); + return hartid; + } cpuid = riscv_hartid_to_cpuid(hartid); + if (cpuid < 0) + pr_warn("Invalid cpuid for hartid [%d]\n", hartid); + if (cpuid != smp_processor_id()) return 0; + pr_err("%s: Registering clocksource cpuid [%d] hartid [%d]\n", + __func__, cpuid, hartid); cs = per_cpu_ptr(&riscv_clocksource, cpuid); - clocksource_register_hz(cs, riscv_timebase); + error = clocksource_register_hz(cs, riscv_timebase); + if (error) { + pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", + error, cpuid); + return error; + } error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING, "clockevents/riscv/timer:starting", riscv_timer_starting_cpu, riscv_timer_dying_cpu); if (error) - pr_err("RISCV timer register failed [%d] for cpu = [%d]\n", - error, cpuid); + pr_err("cpu hp setup state failed for RISCV timer [%d]\n", + error); return error; } diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 357e9daf..254ecd76 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -237,6 +237,11 @@ static int __init plic_init(struct device_node *node, } cpu = riscv_hartid_to_cpuid(hartid); + if (cpu < 0) { + pr_warn("Invalid cpuid for context %d\n", i); + continue; + } + handler = per_cpu_ptr(&plic_handlers, cpu); handler->present = true; handler->ctxid = i;