From patchwork Fri Feb 8 01:51:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802347 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 8514313BF for ; Fri, 8 Feb 2019 01:51:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 757C32E5FF for ; Fri, 8 Feb 2019 01:51:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 678A92E5EE; Fri, 8 Feb 2019 01:51:54 +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 C7D652E5FF for ; Fri, 8 Feb 2019 01:51:52 +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=/i2z/PDZF731Y2NdkMLiu25+uudMl8+ViAv+zb1M+OE=; b=hsRZ4Omn9GxUNglL9cRxTWYqq8 vNmjvktkE2bek4V4/84QrwdWGdhSuKbCCulDAxPZL2clawaAHCtwpDFWGdBgV2BvmPPSTAKuE8YoR mNEzrxw3MH8rtf79XJE3kOKlqCrB7bQy3dS0rnjpv5p0je+5qdcZfzftR1qWJUN0cUY2XKGIg3Giy xChPWHEageINZ5wmP3qvNw6Y12LS5y99xHOsvQjqTzfdIXbew9SNJEQywAKiIHqNb2Ae2ODxQ2Huc CXQkVCpoTaBjWeSoVEKRAHc58GcmfKKL/qJtEYzaOZmFn1N30Oz0//vObvMb3ZbM5ddskt198qPGU ZkSo5kGQ==; 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 1grvKZ-0002bd-JJ; Fri, 08 Feb 2019 01:51:51 +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 1grvKV-0002Xt-F4 for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:49 +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=1549590707; x=1581126707; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vXTNOfhaX1sMa2pzdV0jZjxGYA61VvpiJl8l5v0afQI=; b=FxVojIHbO0+gZfWaXlVrj+LpcX0g+7RiASSzp1noX+wEPEaS4vbXz07I dJMU5LVLBYUY7bRce/Hbg5cUSbRV2HJzHZqqQLz2rt7elnYGb3PQakgVo vnm5xRST3rlLFeZua/9vGDAloovm2RqBIZ8mEyQNLj6nAkwnRF0E65zRi qup/+b+dMyZECKRQr4KuU80c6Onh6VMzI+3KpalYcCld6t0XQS+ZhbcwC qJyB+2XSrbDfzoeIpZd07G5Ex0Vp5ook9DS/VFnnFHrq9t+0CSXaduUQ8 xNcT2TZQp80DDM2eUj6ffhRVSAHnSRA2kt0xAGRDJoWKb9GC2QAxBZ4lp w==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533279" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:35 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:18 -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; 07 Feb 2019 17:51:35 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 1/8] RISC-V: Do not wait indefinitely in __cpu_up Date: Thu, 7 Feb 2019 17:51:14 -0800 Message-Id: <1549590681-24125-2-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175147_550379_14724B73 X-CRM114-Status: GOOD ( 13.13 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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 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 18cda0e8..669eb332 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 Fri Feb 8 01:51:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802349 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 B67B913BF for ; Fri, 8 Feb 2019 01:51:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6D022E570 for ; Fri, 8 Feb 2019 01:51:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4EE82E60F; Fri, 8 Feb 2019 01:51:55 +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 063F52E570 for ; Fri, 8 Feb 2019 01:51:54 +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=t0G3Fc4uin6mewQnnnh5SS5/bNN3IwBfMxxTH56ndCo=; b=K3JJox75CTQrFcqn1++Dj/rrIM 7ZCGKS+VpPTiMNX57HEX7GtNRj+4r2El8yL3n1rHpVAdcumks9yy5YraT7gRokD+M7VSDEQ3jQ1+X dpjYBRJdqRb3SYyBBAG8PdqquKty9hhprzbcnk8IRdp9pp6Q73RhAenPKUBsPsVCLWsTubmpTEGpu 2A3ItFEvrZrBEFbXnyRju2oM1DKxIap3NnWjuv0WBGOnWULXUTTJPd+qrV4lAZ1cpiK/E5JN0oiJa qQVOxrYluwUpGJvFZK/sUbpemKdPpuFofUld5AArj8diBxAI5XlzYBG9hyOjy0T5CR/SbyvOhAtMg C1VzXqJw==; 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 1grvKa-0002cj-K4; Fri, 08 Feb 2019 01:51:52 +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 1grvKV-0002Yr-Jl for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:49 +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=1549590707; x=1581126707; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=6spYNXZM01ujB3OXUqVnYTsA1aTBPCeAf1NDjBeE6Sw=; b=TWjdYb1mQ2S+OgvPZcslZlTXwLMdIPW4rbGrZvK3D+l6cMDL52jd/WQn fMwMH8UI5gFbkd3uenocfXJMrp/I3lrdQqEimDSgfxlpJhtTnGbI4V1qF BUR0NaaHyiXd0xS3dYmEC+CAqXXxljJebhJdgxknN+gr+AMcLJ6mzPQBX drtq1tHbzA3De0DzpMY5awsmRc8EZfZkgOL032kHbMEh2uoXcYtwIOQoC VbOhvdS78uHvnK1ZpSos2jSthj+xWkdmrxC4QjhV54KPfnHur+sDeyuTL uzoNhalfJfJJjaqPx8r6o3RwMUoKUrDh7DoR4gj9tpeYjADkwe1rjdO7H g==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533280" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:35 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:18 -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; 07 Feb 2019 17:51:35 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 2/8] RISC-V: Move cpuid to hartid mapping to SMP. Date: Thu, 7 Feb 2019 17:51:15 -0800 Message-Id: <1549590681-24125-3-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175148_038273_C41FB93A X-CRM114-Status: GOOD ( 13.41 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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 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 | 14 +++++++++++--- arch/riscv/kernel/setup.c | 9 --------- arch/riscv/kernel/smp.c | 9 +++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 41aa73b4..21fd2d75 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,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 77564310..45e9a2f0 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 Fri Feb 8 01:51:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802351 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 7246E13B5 for ; Fri, 8 Feb 2019 01:51:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 639EA2E5E9 for ; Fri, 8 Feb 2019 01:51:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61EEB2E624; Fri, 8 Feb 2019 01:51:57 +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 110F42E60F for ; Fri, 8 Feb 2019 01:51:57 +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=n+OyUo+NViPX7gVEu/jiSIQ8bLbDgn3KxH3I3WdgE18=; b=p3pUVyyrXCML+JL/4LMeA9QyLD ltXEJieYyz/js94zdxuQbPDAtpnOtJIiI6cvb+o60qqK/yeo0WYd5oHCtRHodqcP/SX+fVIVh7rVi cp6vk5uAsRSuAr3oCYOgWS5FnmHGU66bzeNY38iltjleXWQciPitvvTlwDA27ESiD1fsrFllwsz0l 5fm928ffJZKyh2YTy9rUTELFrjTSsxijrXAEEA3jcXCt+YUrARqG7k4/gf8J2rsCrZHmMr7JLowJp h9crxwUuSSFng1Nov5TrsPKKt1xmHtmbKEBHJrngPGemaIcO5y0XHbB5mtTSaXCWGF5MW8g9iygHB 0j+Gu9Sw==; 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 1grvKc-0002f8-Ny; Fri, 08 Feb 2019 01:51:54 +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 1grvKX-0002Xt-D9 for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:51 +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=1549590709; x=1581126709; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=7egq28/CSCkrSFqdZR+3wqM8pX3AZ5gSH/KN6l36VFg=; b=jDVr9vIdUrjnmSeHxA/wgL7ayiII70mdOAu8tZTMg6Gf7v0siBOKA7KP 79LGSqQd7tG+kj60feJJgIMvB/IAYqMDi7LJOCnta4zVMtO6ax/I8xvfp ROgLzn355sxPUIwd/QLu1xe+NL/0YksClTY11zOk9Mh3R9w/nemXRuF7q oWxtIwNibLRTaQa12oLn6yK3ET7R9uWqk8LXfbpJQ/brbm3OuT0Ykcn/z vansyWifCAo+J8+Ji6ITsBwG/vyr3yJBKzFjDx+geGRFN60KzJjSTE13+ EyPDgakV7eSwwiIbK6DU0dIyEykQ2p+DYga8LXemNitcKY/q2TQCfTvtS g==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533282" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:36 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:19 -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; 07 Feb 2019 17:51:36 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 3/8] RISC-V: Remove NR_CPUs check during hartid search from DT Date: Thu, 7 Feb 2019 17:51:16 -0800 Message-Id: <1549590681-24125-4-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175149_830378_2CCED967 X-CRM114-Status: UNSURE ( 8.82 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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. 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 f8fa2c63..19edaeae 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); From patchwork Fri Feb 8 01:51:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802353 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 C9CAF13B5 for ; Fri, 8 Feb 2019 01:51:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB2612E5D5 for ; Fri, 8 Feb 2019 01:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8DF52E61C; Fri, 8 Feb 2019 01:51:58 +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 69A5D2E5D5 for ; Fri, 8 Feb 2019 01:51:58 +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=lwGMr++5URo0U9Zi0quo9LuxGmbWfHe6+KR6xf3I3Ps=; b=mBuICvsNHS8LqtRsfd5k9YJp/c gNM+kn7t/abnyEz0l2y7y8XRk6tdC2+abLIAEy2ijwflhlEbnU69b+Gj50gkgDsOt47rxab8/3PXb ErGa/gGCRFM6/bLmHSbrfgmDCWPOFS9TJwHoM49X39EZXf+H7Ltk+WHcoJzpsIyF4uKm2bT/FDuDW /alAbZ8kHX34GgXqLDnWsTA8PeONBp7TkyE3IMWar6sNTuRd2qEKjQw2s9XtArzxWm3LwBeJTY4Xd 51KYhigZ1k4GqKPYjuGRRQu8+p825MXRwHkQouI7j8od0azAf1dhJR70GABsu93t/DLzJno6X+jWr 7jBpWGlw==; 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 1grvKe-0002hJ-KX; Fri, 08 Feb 2019 01:51:56 +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 1grvKX-0002Yr-IL for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:51 +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=1549590709; x=1581126709; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ViV6PhKpKnhRP9ucbxYfmK43deu7UXliWl3/nyU8MVA=; b=hzPG/ehFObhMu9QXc7gIxHOyuAPzvC4Yts/8u10/38GmPHa4D0vQXJbs r3hzxqxNH6Q+bc0brhtoNh5vk4HIhORgVBJAVvUpFHeB38xqiWTNYSWNO NrTWLK/yl7pSeo5VAQDtVRYX48qdlunrS8Rjr1UP79KwGTp9/vj7fG/+I YDsR4uItlzPZZCDS/+NKtKVAI7jbm4GwdogZJvR6QWHhzDwqXw5Rwl+t/ ivI8ePeA0uzfH77FnOai8ITIUQTcxW5mPJnAPtsazJm01hMR4lBZpRfpu ZX7X35M2Uv4yByoua+m908YUFAwybv+9aN+DNsWlI7AhsIefVSdIRyDcb w==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533283" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:36 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:19 -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; 07 Feb 2019 17:51:36 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 4/8] RISC-V: Allow hartid-to-cpuid function to fail. Date: Thu, 7 Feb 2019 17:51:17 -0800 Message-Id: <1549590681-24125-5-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175149_867451_D3DBA340 X-CRM114-Status: GOOD ( 11.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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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 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 Fri Feb 8 01:51:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802359 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 1FF0013B5 for ; Fri, 8 Feb 2019 01:52:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10CB92E5D5 for ; Fri, 8 Feb 2019 01:52:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 051FE2E5EE; Fri, 8 Feb 2019 01:52:05 +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 7BFC62E5E9 for ; Fri, 8 Feb 2019 01:52:04 +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=AOG8QA4B4+NI0AuMKPbfk5e0ntZdmlYMjI4ElZCqp9E=; b=aZ8aGKuWADSfy89k4kIXUTzX1S R9HRY5sdWMdB0ieZzdsIBkFvTebIeKvYyZTTCG/GpUYpuZsAGnQ/ftov36tF4LBux6y4dfU8cdixy n/AqtIXpPbwupXZGk+5mar1s/RK01eMLZVxz5nS9dZEWk74tRLo8U4E+OCUHqZt4ABDaOotTNoKPu D/dhYksHW1A3p7TpGdx+rg+iyBaREqrdqjxNeCDGBElYO+NNsP8daR/Wd02MtRFPUD/aXJu5ecXrp 0xxdFPNA7tcBtyVOouMvCmbLt+UJ99jdcYwthqVHLsgXqT6O1fqgusOBgltLqQ//Zg9AXWKhvLBgZ TKypEyYQ==; 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 1grvKj-0002nU-TJ; Fri, 08 Feb 2019 01:52:01 +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 1grvKX-0002Zy-LT for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:53 +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=1549590709; x=1581126709; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=a5eO8iqcCF0fX5LzHmEyvUks9ILPsjzZwae5L7sLHgs=; b=eQaA2m/nwkQz1NjSzz1GRna2u66fHY7tXs/yhW2jNMjUyvSLgCwk8PGE PiE7AK2EUKzA6MYh9kXPtRdL7lYG42oL9gnkkcdHIlshdgjmn/v1FwfpD 0rWgGy2egLrZQuJUPj6M3588sZl3pNVW5Rvvf1QZ0C3a8MScFFSW/8ybF rg5aKql0DWKpMRWt4Dvi+f3IYWFF1GPNiLefgG3C3i8ZW5zomnCvs95es zEvXxVAXRoffxUE0XigoJtLdmKBmlpMRNildFrl11qXt+6IGIkWIGd2XF j0ayI4gPH1x495xWEjOU9VtQkdknQLQX7zk+ckYQ3anrQ0aNirSKHOB0X Q==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533284" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:36 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:19 -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; 07 Feb 2019 17:51:36 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Thu, 7 Feb 2019 17:51:18 -0800 Message-Id: <1549590681-24125-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175149_940164_CA77258A X-CRM114-Status: UNSURE ( 9.91 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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 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 669eb332..f120d325 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 Fri Feb 8 01:51:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802357 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 1C1D013BF for ; Fri, 8 Feb 2019 01:52:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D3682E578 for ; Fri, 8 Feb 2019 01:52:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 018FC2E5D5; Fri, 8 Feb 2019 01:52:02 +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 7CEB82E5CA for ; Fri, 8 Feb 2019 01:52:02 +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=TztQLFTwKAY+svuEaYm4kcFrOAbZCb2kxt7ZUzMPDM4=; b=MqGnd8y14iQO84Bze1eCZOobIO vmRfWO9YApEoBvqteu8RO834soH/X2aJOLVEevQKEjjgvfg+R4VXSczP9IRfhHa+zyQfZPexl0Y7j uOAkf62M472nBNbfMktQ5Ns7k2dn3QlDeoY9bW4TDB5xYTh8XA1SNcHPKBO9tw/7FP2EVjgekuE7t cziqKgdh2Ua7S7fV9zqjYGDbmW6mS0iSfJ9KS5+w+C0j73e9qSLVDpTaBSB9SDR8mCIEW7+t9yG8o t5cpGOOhxifB/c3Ctob8DksjgM0yQjev4ob1hWWKQyqWddqa9zUA5W1eVyONMgbOTeAZfEM+2nJyy FtCHaSZg==; 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 1grvKi-0002lP-Ct; Fri, 08 Feb 2019 01:52:00 +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 1grvKZ-0002Xt-Cm for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:54 +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=1549590711; x=1581126711; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=g/mEff0E+PMOEOwbxWDlOfFNXhWP3FWWB/Ym2Qop9J0=; b=JESNv4gWN7PCskYZwI5HrkEPCZDz8hGz7k80LJwdQcvSdjgCvJFxTvzB ZlGvbXN/3zBkAXuhGoMBn9bv59PFx0a/ptU9hiikdjyNDqfZUYlZ0/TBo hD9UetEOI0gIkvfViX+G70157qKVJjaqFnLLRqq+M0dpiUwI4ZBFxuoc3 MuI0pOqFgP8xpKy0dmvhiPHmx9k+y8P7iYnPtsAfe/iM9ePWTbbwpru4m siaItdT3ntnTHV8iQOCNTaKIENizckt2cVuY71kTVSMOaU8ypnPxFX7uD lKc1gwqlGiLMI/WtXs0m45OBPODdqDPuib6AK9/JdfF8AiiOE+mGlcIk7 g==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533285" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:37 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:20 -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; 07 Feb 2019 17:51:37 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 6/8] clocksource/drivers/riscv: Add required checks during clock source init Date: Thu, 7 Feb 2019 17:51:19 -0800 Message-Id: <1549590681-24125-7-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175151_627607_3782F088 X-CRM114-Status: GOOD ( 12.30 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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, 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..3c7ea75b 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_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; + } 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 Fri Feb 8 01:51:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802355 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 2FD5F13BF for ; Fri, 8 Feb 2019 01:52:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F24B2E5CA for ; Fri, 8 Feb 2019 01:52:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13A112E60C; Fri, 8 Feb 2019 01:52:01 +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 A6BA62E5CA for ; Fri, 8 Feb 2019 01:52:00 +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=f6UQjBouwxU9jU0zZbzH7OOBbz7t9M0eixYqVBQtTrY=; b=m3IHA7dScHoSd1mi/eVEsrWsnl /f8ldKdzKYQlYkCq70e66Ol0snPZoZGmb8/2bQYL8XQI0DXN30XiN74z+o8MOdO3rz+wsTD2i+9Lx tZ1RPuHWRso6hj7SbFATif4UK8eqItzf/J3pyaq3HaJYrAm4M00uXc/LKV4OkcC+t2VYxNKD+u/85 JX6G8MZqnv1+gC5xHAuE9c1mrdh6hW7I83VneB+AM5fnHcC+kVzL5rHVIxOj63mAJZye1B1bxsE0W RTisvNyxwn00p/otMFmVxG2WzpQ8hCZVuphKWYnD0DIOTNgGrSrxLrHgkkwiA721zm5JDUgIYzuvb vA4o0QVw==; 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 1grvKg-0002jJ-Bi; Fri, 08 Feb 2019 01:51:58 +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 1grvKZ-0002Yr-E3 for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:54 +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=1549590711; x=1581126711; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=yFxyFB1JVE6e5EMBaqk5nHsWdldjjgWU0zDphOBw+f8=; b=H4Xbceq6EyGIb+JfN5v3yLpnjtDwdt9gMxzgfCF8H/aQs5wj0UO1nn2W r/C4s41JwMTs5yNdMkRZ7/CLpWCBkSEQdL1Gb0PYvCY5OYXc2YQ5Tp0AN GaQczfVXmQggte2J0V9nGRI8GTZtG0hWAQPZOn9axLnNqeReUcl/ZJDhC WgpZmv4pEvmh4wfina3VWeYESstfWK7SCSU5EIXMNZqNkUgogRJs73Tgu CI0RGS90NqeAfkyvJFFey+WPULqtnXjHRvGA1SBVHaCfbofgpGR5XPZzc eVUCnb8rU7lm2hJKZejRNVNg58J8S8hpCKx5RMsSykSDfhi/uXF5oUwrc Q==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533286" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:37 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:20 -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; 07 Feb 2019 17:51:37 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 7/8] irqchip/irq-sifive-plic:: Check and continue in case of an invalid cpuid. Date: Thu, 7 Feb 2019 17:51:20 -0800 Message-Id: <1549590681-24125-8-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175151_669387_D5812421 X-CRM114-Status: GOOD ( 10.65 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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 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 Fri Feb 8 01:51:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10802361 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 72E3013BF for ; Fri, 8 Feb 2019 01:52:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60F682E562 for ; Fri, 8 Feb 2019 01:52:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EADB2E61B; Fri, 8 Feb 2019 01:52:06 +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 F2CFB2E562 for ; Fri, 8 Feb 2019 01:52:05 +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=Wwcz078Yq5eWf5E8dRn3/C+g0rYBpTKeuYaccvG74Pc=; b=X/oSDYnV889sGVzkL0gBrUBGcm rwPtnAYuOyy43l6TiCraUPKqaZviQQXpRrS4tH8+J1dsCmrod881wDZDWWjJ1BhvDs51Q9cbBZlEP p24qB+YIQx0cwM/JUDXWLgW9Y38GMdZ0PGSLy+eZNb1q3Edh6TeurjCfCSnRPXsDJ8ay0wpyi4Elv 1cvYvo7hPCVSKopfBQ1u1FdCBgQ/UjwYxnlqMUj0JE6o4X4Dz9gSxGpollPIC43I7VG/ywDX1qrWI u9+e0qJm/+vgrx7cCDPGIQEukrH/QiT2zMl5UTfjCBAeOAPx02M331JAtwHTZ+9JnSSl55acMQK+P ecEhH38Q==; 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 1grvKk-0002p2-VW; Fri, 08 Feb 2019 01:52:02 +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 1grvKb-0002Zy-SZ for linux-riscv@lists.infradead.org; Fri, 08 Feb 2019 01:51:58 +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=1549590713; x=1581126713; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ZvCXzp8StVNSMAn/qR+TnMWcDQTO4o6GC0MhJ3P3W7o=; b=g7jOktQxfI9UCrESbgoQaqgowdgBvHDByG/2QXiQOsJCsOK2+E6Gs7GD Yqv6+XzeWpgSYHptTDbiuFlAGXLEkh83Qxw6TIJyov6TXTkxnygMvwT56 nfFFOkPf65AGWMduPGhXmf3nNHIs21S1V4ugHdg5u9YpxeJLh1g5KD5S9 E2xsPiyVMSOXwxJiBk4UHChDAJmASsrblK9Pg8vDZmp4nf2cdhW30oCii IrcpgaWAwDbHmjugdpgchroruVVRJnM0oBH7qGFRFx6r+rKbTfFyE6zMu Uk5Iyvmf9UVSdmE9Ceh4yeD+b0sa50gTuUYGOZqnYSm+OPe3b6gWxMWk9 A==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="102533287" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:37 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Feb 2019 17:30:20 -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; 07 Feb 2019 17:51:38 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [v3 PATCH 8/8] RISC-V: Assign hwcap only according to boot cpu. Date: Thu, 7 Feb 2019 17:51:21 -0800 Message-Id: <1549590681-24125-9-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_175154_286196_48EDF50D X-CRM114-Status: GOOD ( 15.22 ) 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: =?utf-8?q?Patrick_St=C3=A4hlin?= , Albert Ou , Damien Le Moal , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Zong Li , Atish Patra , Palmer Dabbelt , Paul Walmsley , Andreas Schwab , 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, we set hwcap based on first valid cpu from DT. This may not be correct always as that CPU might not be current booting cpu. Set hwcap based on the boot cpu instead of first valid CPU from DT. Add a sanity check to identify if any hwcap do not match. Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 52 +++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index a6e369ed..ed8f0c28 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 @@ -32,6 +33,8 @@ void riscv_fill_hwcap(void) const char *isa; size_t i; static unsigned long isa2hwcap[256] = {0}; + int hartid; + unsigned long temp_hwcap = 0, boot_hwcap = 0; isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I; isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M; @@ -43,27 +46,44 @@ 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. + * We don't support running Linux on hertergenous ISA systems. + * But first "okay" processor might not be the boot cpu. + * Check the ISA of boot cpu. */ - while ((node = of_find_node_by_type(node, "cpu"))) - if (riscv_of_processor_hartid(node) >= 0) - break; - if (!node) { - pr_warning("Unable to find \"cpu\" devicetree entry"); - return; - } + while ((node = of_find_node_by_type(node, "cpu"))) { + if (!node) { + pr_warn("Unable to find \"cpu\" devicetree entry"); + return; + } + + hartid = riscv_of_processor_hartid(node); + if (hartid < 0) + continue; - if (of_property_read_string(node, "riscv,isa", &isa)) { - pr_warning("Unable to find \"riscv,isa\" devicetree entry"); + if (of_property_read_string(node, "riscv,isa", &isa)) { + pr_warn("Unable to find \"riscv,isa\" devicetree entry"); + of_node_put(node); + return; + } of_node_put(node); - return; - } - of_node_put(node); - for (i = 0; i < strlen(isa); ++i) - elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])]; + for (i = 0; i < strlen(isa); ++i) + temp_hwcap |= isa2hwcap[(unsigned char)(isa[i])]; + /* + * All "okay" hart should have same isa. We don't know how to + * handle if they don't. Throw a warning for now. + */ + if (elf_hwcap && temp_hwcap != elf_hwcap) + pr_warn("isa mismatch: 0x%lx != 0x%lx\n", + elf_hwcap, temp_hwcap); + + if (hartid == boot_cpu_hartid) + boot_hwcap = temp_hwcap; + elf_hwcap = temp_hwcap; + temp_hwcap = 0; + } + elf_hwcap = boot_hwcap; /* We don't support systems with F but without D, so mask those out * here. */ if ((elf_hwcap & COMPAT_HWCAP_ISA_F) && !(elf_hwcap & COMPAT_HWCAP_ISA_D)) {