From patchwork Wed Feb 13 20:18:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810833 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 79C7B746 for ; Wed, 13 Feb 2019 20:18:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6520D28DEB for ; Wed, 13 Feb 2019 20:18:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58AE52920D; Wed, 13 Feb 2019 20:18: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 E0A4B28DEB for ; Wed, 13 Feb 2019 20:18:27 +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=s5n0kmZryF/yYyhNCfrb6EktvSjET86Qc4/MapKPBYE=; b=pKTbdW4HSZSAnXraAbYJUYkXQf JOFMc0sAOW4R6gWAgc1Nb738eP7gLJ6Zb9EwL5+n027aNNCvf5CMwNlgsEuXZxA5kTG2UIglmGlS+ AzVtzgiM+rFm6U9/vpymTpUN7sL6CscmDy0KAj9JZsK4J5Z2ZmvAq/NdcKYANZ3CaCj1hmta4LZGo sQnjNmiBJ+ZRrFwSU5Xf4NB9b5T7MFF7PPdivk20nwlvAcPJnBzSSmuAigWtibE8jkl5+MekxQt0/ X1qc7AnJWD5uF2FyNzfe/7+IcrRuZttBqyjM58bon2lNI5y+iQ5BvjvQkFhSPcEP7foquP8BWeoRX kNWkQLlQ==; 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 1gu0zB-0003Du-DN; Wed, 13 Feb 2019 20:18:25 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0z7-0003CA-U4 for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18:23 +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=1550089102; x=1581625102; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=YZUqK4Qfap9iJXTgeai1JroJ8SUKDUcCMd3sVPqcbE8=; b=hWbCZM9DATtPDB1v+XGcqU+t1O8dwrAqolK2o1ofbFzUsfBW1fQHxyhY TR/Hm2Aoq7AyUrV31wQFhy7YZ4aA1zQJv6tqd1idBtSz1jxmu4HbntHth j9mWA3GiPqUGo+y3J2S/8SYyXHbnaFOmRlT4NKhOlFJseW/m5EOuKXE7F fxf7RppTs/h9CC/rQs5B86skevNqVt7NVzJB5bWU4Mxn6Jd0pdwvxvHaF aARf0rqwyV+RopuvFBsEQ/cnYKpSZGfTntvIxHy0pzSa2OtX7yf9SI7qj PG3EpiiRyqdBGLipqgKi2tsKun2pg7lSVF1uNwYjE9fpTqWarlkqgE1Li g==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463809" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:20 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:53 -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; 13 Feb 2019 12:18:20 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 1/8] RISC-V: Do not wait indefinitely in __cpu_up Date: Wed, 13 Feb 2019 12:18:05 -0800 Message-Id: <1550089092-28783-2-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121822_080399_FBC1145F X-CRM114-Status: GOOD ( 12.89 ) 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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 Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/smpboot.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 6e281325..d369b669 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,16 @@ 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(); + lockdep_assert_held(&cpu_running); + 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 +129,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 Feb 13 20:18:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810837 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 D7AA6746 for ; Wed, 13 Feb 2019 20:18:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C351C28DEB for ; Wed, 13 Feb 2019 20:18:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B744028FC9; Wed, 13 Feb 2019 20:18:31 +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 1215328DEB for ; Wed, 13 Feb 2019 20:18:31 +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=A57V2roDiIPnB41LpU97C67UdyiZZ2y9fphC5t1se/Q=; b=iL5X/XuRxzMKOOFPMcf1b9crPG hM/2qs6bdX3CAOzn5JxlMIsWKqXcw05cecLumMdFACInBVjlgdvi7lG9hOGMXE0F77e/qdt0u1CAn Hcul4ThoBrMArEX4VHV3vMTun8qsQB4keWdNPO5M+xeEh2Sxh3VZzszCq3tba+ClduX99WyNKQCj8 uzmPdv26pyZcpezVQUnIIba90W+zEbAmjIh5Kn+fXLKKyEOKv8NoPHUURA+X2D99mG/uxE87IC4a0 0K9iDU8rxeaJsEI+URBSVg8fYTACy5ul5IG3lI6A7OA1i8LbrYCfh12jr5+qdcBxVnq+no7zaQS9T 0jTLy23w==; 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 1gu0zE-0003IR-CX; Wed, 13 Feb 2019 20:18:28 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0z8-0003Ca-W1 for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18: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=1550089103; x=1581625103; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=h2fKv5100GvHj+ysLhrtvyrBQOE+5MV8IiW0LUcjPlE=; b=aFEbMyXxBzDjy6FL7GIzAL8ah3O2yL7oOnHYQg3GNJxq6QqvyMJz4n7m b04QflmuKyFQKXmoETV+WPGLrChxW1mFIFtsmB436YTGO4/y9CtWZrhZc 4GYvK5rplZUrGytHKjwSDzGX9PNSq/sjLfvytNtPwocuhPTk5/fKFQxzR a1f7Xh/8MHwOGYq6h0Vh8XKILbmT/ShGpIodvaYClGB8cGYaMlBQgDg1K 3OM+LK9OlDqBR7LDjCsLNpBFPPxrB4OlDHpR17k/y2uCj+n2Q2gQkykXc OqA04Tiar2dWk+tepJJsnTWDm6rYi7ETaL6fPN029B9kIvsTxPnqYnzcJ Q==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463814" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:20 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:54 -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; 13 Feb 2019 12:18:21 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 2/8] RISC-V: Move cpuid to hartid mapping to SMP. Date: Wed, 13 Feb 2019 12:18:06 -0800 Message-Id: <1550089092-28783-3-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121823_139895_76381075 X-CRM114-Status: GOOD ( 13.28 ) 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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 use case. 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 Reviewed-by: Christoph Hellwig --- arch/riscv/include/asm/smp.h | 18 +++++++++++++----- arch/riscv/kernel/setup.c | 9 --------- arch/riscv/kernel/smp.c | 9 +++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 41aa73b4..636a934f 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -19,16 +19,17 @@ #include #define INVALID_HARTID ULONG_MAX + +struct seq_file; +extern unsigned long boot_cpu_hartid; + +#ifdef CONFIG_SMP /* * 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] -struct seq_file; - -#ifdef CONFIG_SMP - /* print IPI stats */ void show_ipi_stats(struct seq_file *p, int prec); @@ -58,7 +59,14 @@ static inline void show_ipi_stats(struct seq_file *p, int prec) static inline int riscv_hartid_to_cpuid(int hartid) { - return 0; + if (hartid == boot_cpu_hartid) + return 0; + + 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 fb09e013..61c81616 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -61,15 +61,6 @@ EXPORT_SYMBOL(empty_zero_page); atomic_t hart_lottery; unsigned long boot_cpu_hartid; -unsigned long __cpuid_to_hartid_map[NR_CPUS] = { - [0 ... NR_CPUS-1] = INVALID_HARTID -}; - -void __init smp_setup_processor_id(void) -{ - cpuid_to_hartid_map(0) = boot_cpu_hartid; -} - #ifdef CONFIG_BLK_DEV_INITRD static void __init setup_initrd(void) { diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index 246635ea..b69883c6 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -36,6 +36,15 @@ enum ipi_message_type { IPI_MAX }; +unsigned long __cpuid_to_hartid_map[NR_CPUS] = { + [0 ... NR_CPUS-1] = INVALID_HARTID +}; + +void __init smp_setup_processor_id(void) +{ + cpuid_to_hartid_map(0) = boot_cpu_hartid; +} + /* A collection of single bit ipi messages. */ static struct { unsigned long stats[IPI_MAX] ____cacheline_aligned; From patchwork Wed Feb 13 20:18:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810839 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 7A9D8746 for ; Wed, 13 Feb 2019 20:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 631E128DEB for ; Wed, 13 Feb 2019 20:18:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56FE72920D; Wed, 13 Feb 2019 20:18:32 +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 E3FCB28DEB for ; Wed, 13 Feb 2019 20:18:31 +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=yp824XKfX+CAHGGUn+XWKhrKyv674BKevqdM2T9jp/M=; b=lZpvts46Q5+7vPcOsyWSMODQ3o /Gpkoyhb+MumGlh5cjF2m/RWu1bmlBKoqzrw2J3By+2pdi1u8ik+3a4hpIfQOrUHi8xG+Y1i5StXR 9S+1BWrwaNKN9hSCF85NguqAohXPD9Y5gEt2IEYH0jHtVGydlhrHrWx+LG8qWtLxg8TbY99D1Ftgw THUyHhGedKX1NuLZzaRYZMlbKtAnDIQf9NKGrJfEh3zb1H+rx7+E7ni7LZ+hkAS0E3DA5fyHwCJnV 2AYoTpioVQJVMFaP6Yb9KuZt/FWK7nBvy9ReOa6kh0EuOgZmoi8SxUHzdtbD+eOSmIpkfDNAqNPAY uUPsbrMA==; 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 1gu0zF-0003Ju-E3; Wed, 13 Feb 2019 20:18:29 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0z9-0003C4-R9 for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18: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=1550089104; x=1581625104; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=dA6aSe5XZKK9jbqPUE7aSPe08mUJ7TsRaBX9UTEfvg4=; b=PyUNhGEo8zyQx0+LlTmOagrDzt+NZp6n/22lE6VWiwZzADZufT1zEFtt ELE0wjp1Idpg+y5MOK2yHmX+4YvwoKI5eZgrDUBlGHVuxbSuyzE0hbadW C5bM9uJC5Wsq2iLzGIurgfXbBx0+wg2pl6GkVglxFQxtDuiV4WYkDtcol QPFx/o91i6TlRfIx5I2O3vqTdFfSbotB879nCBQoSzTnpwv9JF+NMLDH5 d8Um9kEZnvy8U+rU492/2MAY89Wl8b+0WwJrCl8AvYB9ryOAK2kgwG/RN an0BhQm60ZyfBkpP7sZFE5OaF6PT12bMmRrcPKjNfeWauDmEELAmAz1zr w==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463817" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:21 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:54 -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; 13 Feb 2019 12:18:21 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 3/8] RISC-V: Remove NR_CPUs check during hartid search from DT Date: Wed, 13 Feb 2019 12:18:07 -0800 Message-Id: <1550089092-28783-4-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121823_996977_CBA0F5C5 X-CRM114-Status: UNSURE ( 8.35 ) X-CRM114-Notice: Please train this message. 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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. Signed-off-by: Atish Patra Reviewed-by: Christoph Hellwig Reviewed-by: Anup Patel --- arch/riscv/kernel/cpu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index d1d9bfd5..cf2fca12 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_device_is_available(node)) { pr_info("CPU with hartid=%d is not available\n", hart); From patchwork Wed Feb 13 20:18:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810841 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 C155117E0 for ; Wed, 13 Feb 2019 20:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF8DB28FC9 for ; Wed, 13 Feb 2019 20:18:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A368229244; Wed, 13 Feb 2019 20:18:33 +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 5053C28FC9 for ; Wed, 13 Feb 2019 20:18:33 +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=Ta9gXPE3TfFK+SXfYXeO+10Ybyu0RNdH1K6svt3iFso=; b=Wk05DFo9ESXkxhdacleGMDKeKm UDWgGv2U6cINF62ngdF536zxNgWFvsZEQ+9hN/Xt8RLaFobRaqP9gu36xvZ969mM2dCYOkfEbI1wh bjkaRXjdm/IoHo3hyHwv7ffot0suCzfgDFcef/U+ccFvmOcQPkscNksqXuMx0HlnJvkB0n/bVdt6u r3kR4z2wKzZm6WalD+Z9uStmeeCMxNc+BP4S1Vh+nczEoO0VAYFPZTsCf5vRtFNz5utlMfAR84QM+ omX6+I6alUs9Nb9/zWXgqka2MO0QkdmN+yvLF3YbAyk0qCFF+l/aBC1eK+rbMzeNZfmlC3EXrOESt ZTv6LbxQ==; 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 1gu0zG-0003LA-CX; Wed, 13 Feb 2019 20:18:30 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0z9-0003CA-R9 for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18: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=1550089104; x=1581625104; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=BXPJoBB0Kgm4J4WvDGeNZxKZbFFkYo9XWYKOd8CvDv0=; b=BBCCa5DAhQK+V6SQTEpHctl+v6p7M/cLSJ/LtS1e9Vy8Sb007FvFehXA 7S9rq4v5tXhu4LdS36vSq1j+udmgTOfzuZn5cghOl0IgGFk3zhciUqD6R Q3AJGndflMjzWM2M6smcWkl+0DMtYDBHO49pOmQMk+tgiMckhekbXCuht 2c/reLG8k4lZtwVyvI6C1vsZL0e8nddpZgfbU00H+1LAS/EWdaEGNRE7a jbN5WclsSHBH43nIeSg9g246J4IFlaacVFnwm1FUBYzHLjG/r6N7yaRQv zg1XEFH7Gw38TC2TcN7/50lAMxpovhz+J6IIZDUm8vPj+l92AOS9u7MLq w==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463820" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:21 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:54 -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; 13 Feb 2019 12:18:21 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 4/8] RISC-V: Allow hartid-to-cpuid function to fail. Date: Wed, 13 Feb 2019 12:18:08 -0800 Message-Id: <1550089092-28783-5-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121823_988532_4ABE1811 X-CRM114-Status: GOOD ( 10.51 ) 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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 It is perfectly okay to call riscv_hartid_to_cpuid for a hartid that is not mapped with an CPU id. It can happen if the calling functions retrieves the hartid from DT. However, that hartid was never brought online by the firmware or kernel for any reasons. No need to BUG() in the above case. A negative error return is sufficient and the calling function should check for the return value always. Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/smp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index b69883c6..ca99f0fb 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -60,7 +60,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; } From patchwork Wed Feb 13 20:18:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810843 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 19205139A for ; Wed, 13 Feb 2019 20:18:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04EF128DEB for ; Wed, 13 Feb 2019 20:18:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7DB529211; Wed, 13 Feb 2019 20:18:36 +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 9A4C528DEB for ; Wed, 13 Feb 2019 20:18:36 +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=1ohqkYrYbHi7JsdRtBpb7ro2zRfGBy4MjqRl3r7PSyQ=; b=qMN+l6UYsGEP1TnZJj0ssH4VBA BqUnRL5XSSntD6WfnBFe8ubyKd6IUB80NW3xekrM8Yq+Ry5e4JuqsaFte+GUEKz91ocFwsHlOV00n YlvfeP+hdkGmX4QeLh2Z4vYEg5hnHkmDRwjGevJU8JYQGiwWyD+50pY4NrHcPO8orlbOQWAHwrCko +dxDxsQSkNj6k9GIzXh3tkQ9NARzEsAMGaYu6zA+/sarEm6ReLrS4zMFCRxh4dHmbcjmFyurvmpYj +EQSpLvLvYEsFAkmXcgJ9d3bfsqnuw7yBDpYYHynF6MtgB0LWh8dsZcbhhfD3cKTXUVHHIszh2I24 /ImLN6DQ==; 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 1gu0zJ-0003Pr-HP; Wed, 13 Feb 2019 20:18:33 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0zB-0003Ca-6K for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18:28 +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=1550089106; x=1581625106; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bTj3ZFVXgC5G434PAQjLdqn3TV1DqlyoGc/NiuvITNw=; b=b9b01Gb5CJGs1BB2KHEeWvAIlss0BZzRcr+nlXidcNzw9lrrBR3IcFya 8CtxtEnaWCA1c98625AKsQ62zziriSRM5+LD2YgYHoARnme3lQWk9YCTh rUXRmTUHQ2aeu+Ba/d3wi/E0Sff8l2LJqNmHb51rLcgR5Vef5R3STNKLG D1Bn6G/JKEv4L3iwFjTtEGLMcLn7jrTnS3KYUuFyOf2fuKA8CmtdQTtxE v/J1rGPhX+cZsfVUTqW3QaFo+9eXwtr0qp8Z0rHtFSkiuScMm4GEWKQaN ESRANIdfyR/P+rtF5KV0X+uQMr6H8H+SM+ECqWXRu4X0qRks8zfFhnnxM Q==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463823" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:22 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:55 -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; 13 Feb 2019 12:18:22 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Wed, 13 Feb 2019 12:18:09 -0800 Message-Id: <1550089092-28783-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121825_521472_8A662DD7 X-CRM114-Status: UNSURE ( 9.25 ) X-CRM114-Notice: Please train this message. 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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 We should never have a cpuid greater that NR_CPUS. Compare with NR_CPUS before creating the mapping between logical and physical CPU ids. This is also mandatory as NR_CPUS check is removed from riscv_of_processor_hartid. Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/smpboot.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index d369b669..eb533b5c 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); From patchwork Wed Feb 13 20:18:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810845 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 D18D8139A for ; Wed, 13 Feb 2019 20:18:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF51428DEB for ; Wed, 13 Feb 2019 20:18:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B35B829211; Wed, 13 Feb 2019 20:18:37 +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 626B728DEB for ; Wed, 13 Feb 2019 20:18: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=xyDOVltDhEVfD/vtxa6yUM45HIeX+CH07SYiRAH/tPE=; b=IJve9w4kMrlT5mfYJYbNXuuj3H asQcIkoKBxpIXeAKkCQ0pp018SkowNpDzdx6q81WWUhJ5LD5IgYgnNvZijsAIiETdROoLdBM56sTo P9LcevC3B3Vt/Rn+IXdGUYCHIJ72wviueV1xv1MLab/Ioc3fIxZlEs3Gz7iKpn2hlFOUmeKVDOQUh sZJSDn9RCv/3ekOG2wX32p9AQthysUn3ewfjtZcDyuFn73MbgvKfQvD3lVhbl3a0S3+13bOX19ddo nIWfIqyuIF9FEk4/4LY/Wu9Z2rpvo2Oigm85gVWzLopevHc0Z5P8meJRdISUKcUkFzSx1o4r18utc tBeIhTog==; 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 1gu0zL-0003Ru-3L; Wed, 13 Feb 2019 20:18:35 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0zB-0003C4-Kx for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18:28 +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=1550089106; x=1581625106; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vnRdayaz5Pz6NDhpDj4PwPWoeZAvCxUKf5wSxkfkfNk=; b=AA89jXaECPV3NB82QHRslylbQpnq58XufiLaLlrzm8nvX9SjzLfswwwz GBj73CHaVaHsIyTxkdmNvTAD4nFOVvAg8PxbtMmL1oGzxZ6jBKAPXkmxw MIACWHJdXrdchAOJuiCG9ptNJIzhkLZgPXrWNX7DGxhTrnLwNwcYUhJQz QPOf9/zL/6OzEivrwH9+noO+qWByymoAlkJhzlKJHxJq6n/nwhTQLZEzP L6jq4OSY3yvLFxPlBW+gLpHuck2/mJaNc4wxVppOKzBmveeRutLrSLWNt 1rodU+Hl9n6EZ/fGZYtoPyuRgaoMPQzjHCu3QSpkWRc/53uN/I7bJZAve A==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463829" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:22 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:55 -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; 13 Feb 2019 12:18:22 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 6/8] clocksource/drivers/riscv: Add required checks during clock source init Date: Wed, 13 Feb 2019 12:18:10 -0800 Message-Id: <1550089092-28783-7-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121826_079618_82486E3B X-CRM114-Status: GOOD ( 11.83 ) 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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, clocksource registration happens for an invalid cpu for non-smp kernels. This lead to kernel panic as cpu hotplug registration will fail for those cpus. Moreover, riscv_hartid_to_cpuid can return errors now. Do not proceed if hartid or cpuid is invalid. Take this opprtunity to print appropriate error strings for different failure cases. Signed-off-by: Atish Patra --- drivers/clocksource/timer-riscv.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c index 43189220..e8163693 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -95,13 +95,30 @@ 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); + return cpuid; + } if (cpuid != smp_processor_id()) return 0; + pr_info("%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; + } sched_clock_register(riscv_sched_clock, BITS_PER_LONG, riscv_timebase); @@ -110,8 +127,8 @@ static int __init riscv_timer_init_dt(struct device_node *n) "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; } From patchwork Wed Feb 13 20:18:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810847 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 421C4746 for ; Wed, 13 Feb 2019 20:18:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3132828DEB for ; Wed, 13 Feb 2019 20:18:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 257D029211; Wed, 13 Feb 2019 20:18: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 D03C22920D for ; Wed, 13 Feb 2019 20:18: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=ylVZlvhij+al/8yHz0kKZJpV6j87gnvZlcGdryqgNdQ=; b=HC4uwCgHwPg04wOCSsitzzidFv Jo8bwngx5z64fT3Ytf66urp/4t4lzn1ROk01LowFTKIofCQTe95Re98plpOZ329RwDOlxYBVJk/Ad B2a1dLtaR2qQAHm9fQ3ElBefWidx2HDZ2fkMwvjeTIJrcSquk9z0qDQAoqK5qQcLFU2RPbfzfeJ7t Xb1jrZ6/3U16r4pk01JsnVUZ8hglQgwiVdpw28etL63WOh3N0cr6k3mf9EwKuKmJRkMiqUzEb7XNi Z/jAyn/zeE+htWsKl3uaFtGOLPIdLDFfVPyYi8gKeZW2AplJZdd2uRHr0XW0LiSPc8sNcE1GHnUkN mhufD14g==; 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 1gu0zK-0003R6-C9; Wed, 13 Feb 2019 20:18:34 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0zB-0003CA-OS for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18:28 +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=1550089106; x=1581625106; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=8ACS64L8kLVdF8msWr97l0gsAFThAeL/KOxtN4a6b6E=; b=QGF8W1HZGRzWc8dWzYQ4zESBFx0bptQ34y4Mitv9tKGggKuLuysku27g AE1QXXg77FHyMSyPP4tNd36XjnTKcQBFe4SdsApTO2tt9hAsSAchr27FC Bt0F8x7sSp13y6Jcf8B33Z+nIGblBSBxrS1viLoMM4aiXtbEZnPgMFw6S o5zO5bFQ/cQq1ZYaSRBWIOwnQO3T2q2e4dxBBfZ2IhsLk4msc9QDhddNF EBERzAqLYIpGV4HneYDowTYhuGM7OfKjpgSeS2soi8havuVCADdaGCCaD m/oD78H37ddXX32S6tlzWDkmm4QCaGiaOtGDo20+0TGY+ML1EQn0DzjBo w==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463833" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:22 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:55 -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; 13 Feb 2019 12:18:22 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 7/8] irqchip/irq-sifive-plic: Check and continue in case of an invalid cpuid. Date: Wed, 13 Feb 2019 12:18:11 -0800 Message-Id: <1550089092-28783-8-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121826_139687_A4B54896 X-CRM114-Status: UNSURE ( 9.99 ) X-CRM114-Notice: Please train this message. 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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 riscv_hartid_to_cpuid can return invalid cpuid for a hart that is present in DT but was never brought up. Print the appropriate warning message and continue. Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Christoph Hellwig --- drivers/irqchip/irq-sifive-plic.c | 5 +++++ 1 file changed, 5 insertions(+) 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; From patchwork Wed Feb 13 20:18:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10810849 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 AE634139A for ; Wed, 13 Feb 2019 20:18:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C44528DEB for ; Wed, 13 Feb 2019 20:18:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9066229211; Wed, 13 Feb 2019 20:18:40 +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 3C57E28DEB for ; Wed, 13 Feb 2019 20:18:40 +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=Nn5Bz0aXryPwwz+VDY1dgiOnhNRlEmuld5j2wwPETQc=; b=hAtcrY9W58rOet1J6h5a9PXTO1 Fj8u7vwrwRdtkkwUof4Gmp/B/9vnNNO9oF+xst5Ms0zjpGEHRPHCjQsY+Q4skudFrxfmDigDQ4XbE fdL1VuyCaCqjHp9PHpbeGdwDbkdbsgKY5n5fR92yOHftyuAxyeypAeJGYPD3027roBlpOG3PVRZfo wDYwD0uDJQRM17SZyH8V+CQv9KeDI0z5Mhafj2JX6nWoSGucUTRzpRes6PAKfTahTtH3lAYIRyNqp 88ehFwWNprRfvf7AhJ+W3YlLUdpq7IX/8zMZzzx7+aHEZGlqJ+5xcajxpq398X0h94+RYbKYkQzCB ru1Z5mZg==; 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 1gu0zM-0003UF-Qw; Wed, 13 Feb 2019 20:18:36 +0000 Received: from esa5.hgst.iphmx.com ([216.71.153.144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gu0zE-0003Ca-CR for linux-riscv@lists.infradead.org; Wed, 13 Feb 2019 20:18:32 +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=1550089109; x=1581625109; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=LuHhF9t57ihPno63oc42DW7mqejQI1UJBdnLjc5u4ww=; b=BGYDabWY22bp2Pu1FD9dC0fnk1j3smZ8TRtISOGazsyP45mW+bKlXMeC ASxQvOafzsEXn+Gi8iZ7p7x9z+XMmwtuAw6mBluv6kGSdd6TMTnFA88Py 05SVVheXjVqRKaMW0g8fLMdk7Z23lYB3iGy2fl7JrcCs7WWsPMn+4sigQ m3ceXfdjw4s/sRXlpeR0a+YLFmKIsrfZO1XW6ix3XXNIENLwQbgwmp8s5 qTclzH7bQ0KRANsC0BomTPXz5VjzKoOMVtZdPUijI171gNCNuywZvK/Xc 7E9UpX3V5A+elDX6vFIAn7PjzRuU3GEtRWZYhiwaWv9LfkFLQTrYUww/R Q==; X-IronPort-AV: E=Sophos;i="5.58,366,1544457600"; d="scan'208";a="102463837" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2019 04:18:23 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Feb 2019 11:56:56 -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; 13 Feb 2019 12:18:23 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v5 PATCH 8/8] RISC-V: Assign hwcap as per comman capabilities. Date: Wed, 13 Feb 2019 12:18:12 -0800 Message-Id: <1550089092-28783-9-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> References: <1550089092-28783-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190213_121828_889327_C7EFE32D X-CRM114-Status: GOOD ( 11.68 ) 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: Albert Ou , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , Johan Hovold , linux-kernel@vger.kernel.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Guenter Roeck 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, we set hwcap based on first valid hart from DT. This may not be correct always as that hart might not be current booting cpu or may have a different capability. Set hwcap as the capabilities supported by all possible harts with "okay" status. Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index e7a4701f..bc29b010 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -20,6 +20,7 @@ #include #include #include +#include unsigned long elf_hwcap __read_mostly; #ifdef CONFIG_FPU @@ -42,28 +43,30 @@ void riscv_fill_hwcap(void) elf_hwcap = 0; - /* - * We don't support running Linux on hertergenous ISA systems. For - * now, we just check the ISA of the first "okay" processor. - */ for_each_of_cpu_node(node) { - if (riscv_of_processor_hartid(node) >= 0) - break; - } - if (!node) { - pr_warn("Unable to find \"cpu\" devicetree entry\n"); - return; - } + unsigned long this_hwcap = 0; - if (of_property_read_string(node, "riscv,isa", &isa)) { - pr_warn("Unable to find \"riscv,isa\" devicetree entry\n"); - of_node_put(node); - return; - } - of_node_put(node); + if (riscv_of_processor_hartid(node) < 0) + continue; - for (i = 0; i < strlen(isa); ++i) - elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])]; + if (of_property_read_string(node, "riscv,isa", &isa)) { + pr_warn("Unable to find \"riscv,isa\" devicetree entry\n"); + continue; + } + + for (i = 0; i < strlen(isa); ++i) + this_hwcap |= isa2hwcap[(unsigned char)(isa[i])]; + + /* + * All "okay" hart should have same isa. Set HWCAP based on + * common capabilities of every "okay" hart, in case they don't + * have. + */ + if (elf_hwcap) + elf_hwcap &= this_hwcap; + else + elf_hwcap = this_hwcap; + } /* We don't support systems with F but without D, so mask those out * here. */