From patchwork Tue Jan 8 09:38:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751715 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 CA1ED6C5 for ; Tue, 8 Jan 2019 09:38:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6D9E2625B for ; Tue, 8 Jan 2019 09:38:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA78428864; Tue, 8 Jan 2019 09:38:53 +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 5935D2625B for ; Tue, 8 Jan 2019 09:38:53 +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=4VKF1bL37WEIFj7bWl9ibslJCtU+dtmLfpmtcQs39Bc=; b=AXxg2F8NKC7RRMWshwR1Cb2s7V 8e2LF6kCC2M63rduvM4xCLmadGxM/hyWEMvgiNAzbcwmh8K9o5M/5CusOhFsEQKyDCqOA54Oso/lJ QuPy9wyvbSHl78sd+f6sg3D1jXjJ+B6R30clyddcTsPJrRCffFE1zzy7ovknIBWVPxlrtDQzIuWYS bpLvxvtCzR/02hVT4pMLWo+5/Ra84PX+GwEEcegyeEumY0NPzm4f84fX3P+J/8IYo/Ru2bmIxxyoE Os30M4v69VCMiKZamoybXYJUSy43GEZX3vR6VO28Aq/nwLPCnjz58rauIi9ZQ6UebHktUWSR6cIGo TMqK5wZA==; 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 1ggnqV-0003od-Vr; Tue, 08 Jan 2019 09:38: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 1ggnqR-0003lv-NI for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38: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=1546940328; x=1578476328; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=yvtspfG7CoIHnopRwUo0DnfYLecRH2XoGu3rQKnIYZw=; b=fwSkIkN7kMQq3es1isctmxbbServOjPInPtNGvIUywc63R6gOZhelzJD wTPVftGEbeDG5ZC4e6Dopx09p77aZvaBJ/lQt4d0wTDX76TpgL3aimIuV a8sTBl0Z7l7/LXZGERXLgfH22aWvwQbGHx8dl4JVfnno2oBO2+5jbYBvH jZpeMwXlFF6WQ8ZK7Y82IHOusafQbwWXoUSonX1XyJqkmWohRxhfypu9X L3VFm5i+84zA6DggcZZYzoJYYVvZxMlWUFyOdKibfkdcZJzaBvt1kpq4j PGhYlNt/t/6wB9KdFmgeNYIN5ovx70Zvh0O8frzTOr6O1P8UcusxS4+G7 A==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000248" 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 Jan 2019 17:38:46 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:50 -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; 08 Jan 2019 01:38:45 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 1/8] RISC-V: Do not wait indefinitely in __cpu_up Date: Tue, 8 Jan 2019 01:38:31 -0800 Message-Id: <1546940318-9752-2-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013847_819728_96E2F278 X-CRM114-Status: GOOD ( 13.47 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In SMP path, __cpu_up waits for other CPU to come online indefinitely. This is wrong as other CPU might be disabled in machine mode and possible CPU is set to the cpus present in DT. Introduce a completion variable and waits only for a second. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/kernel/smpboot.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index fc185eca..32e14572 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) { @@ -81,6 +82,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; @@ -96,10 +98,15 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle) task_stack_page(tidle) + THREAD_SIZE); WRITE_ONCE(__cpu_up_task_pointer[hartid], tidle); - while (!cpu_online(cpu)) - cpu_relax(); + wait_for_completion_timeout(&cpu_running, + msecs_to_jiffies(1000)); - return 0; + if (!cpu_online(cpu)) { + pr_crit("CPU%u: failed to come online\n", cpu); + ret = -EIO; + } + + return ret; } void __init smp_cpus_done(unsigned int max_cpus) @@ -125,6 +132,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 Tue Jan 8 09:38:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751717 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 BE0AE6C5 for ; Tue, 8 Jan 2019 09:38:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC3E528864 for ; Tue, 8 Jan 2019 09:38:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FEA12893B; Tue, 8 Jan 2019 09:38:56 +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 2C7142625B for ; Tue, 8 Jan 2019 09:38:56 +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=NwBhB+JOH6drCpD6hIX6AdVBAeuqln3hJRlSS1XRB0E=; b=gqYKGErMG6WuXlZek5NYScC75V 2h0/22I5dEngAaR7Z0yxgt0+uy8siHngRlxHHCezfrxBRB5hcZxw9KmafALH1cfxIsrOGEgViZpbr clQLwNEKjGqe1rxNd0wszdGTlS/rBn7XkhGBHeryVN7E2nRA8QTfsnV6EjQo9frBPwYwQ/0xeaM+q th3EpoaLhEdvrqndBll+UjyNmRQCdkuZ69xJlUwQBj153PXJjYApkRJk8Zb0TjQ0apBoEMEaF7AK9 MkVCjv0evxDt4oVbfMAJf0D6UHCFvYOFyyaHJNjpvZNX2u6pGDlU94/l9QjzfP0AtsO5dOZ59ixM/ Mw5FFMIA==; 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 1ggnqX-0003qq-PY; Tue, 08 Jan 2019 09:38:53 +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 1ggnqS-0003mL-HA for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38:50 +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=1546940329; x=1578476329; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=+kHLJqXpKvqZKIDRCZJEthrfqa0q8DvX1wCsViqCYIU=; b=Osp9HU1oNDjue2O4oeR5pdFUirEbi04FBBuRp9F7RUJ0o7u5hh97t6+Y GUNz1X+BRBOhq6wPOb3ogYM1Z7q4iIWSk8AmgJnXEBi0WZ0z5UUewTFyx A3ftgewbO3PElrUycobnt8Qfz9YGrTE4uvLzHx3YW4o65/tUtWBp6o5wr b5H5Ky79hxDVaiQ9qNwFzMKtYqQtbjkrhsLC8JOE6Pr8g2CRYyGsD5jo8 W4yCJfzk9WZW23l/IaQT8IXCu7g3dxO4fMBK9bgIAPfqYeZdmbMU9MW34 Va8BJL+w4RVrSdtSTIeKEJ279t4qz4bKrCldn23/NXdJMYqHue8ipEqSC g==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000249" 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 Jan 2019 17:38:47 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:51 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2019 01:38:46 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 2/8] RISC-V: Move cpuid to hartid mapping to SMP. Date: Tue, 8 Jan 2019 01:38:32 -0800 Message-Id: <1546940318-9752-3-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013848_606634_9552712B X-CRM114-Status: GOOD ( 13.57 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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 --- arch/riscv/include/asm/smp.h | 15 ++++++++++++--- arch/riscv/kernel/setup.c | 9 --------- arch/riscv/kernel/smp.c | 9 +++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 41aa73b4..8f30300f 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -22,12 +22,13 @@ /* * Mapping between linux logical cpu index and hartid. */ -extern unsigned long __cpuid_to_hartid_map[NR_CPUS]; -#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu] +extern unsigned long boot_cpu_hartid; struct seq_file; #ifdef CONFIG_SMP +extern unsigned long __cpuid_to_hartid_map[NR_CPUS]; +#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu] /* print IPI stats */ void show_ipi_stats(struct seq_file *p, int prec); @@ -58,7 +59,15 @@ static inline void show_ipi_stats(struct seq_file *p, int prec) static inline int riscv_hartid_to_cpuid(int hartid) { - return 0; + if (hartid == boot_cpu_hartid) + return 0; + else + return -1; +} +static inline unsigned long cpuid_to_hartid_map(int cpu) +{ + + return boot_cpu_hartid; } static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in, diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index fc8006a0..f377add4 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 57b1383e..e407bd4f 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -34,6 +34,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 Tue Jan 8 09:38:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751719 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 D8A0917E1 for ; Tue, 8 Jan 2019 09:38:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C68762625B for ; Tue, 8 Jan 2019 09:38:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA5432897F; Tue, 8 Jan 2019 09:38:56 +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 651DD2885E for ; Tue, 8 Jan 2019 09:38:56 +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=AK6m0/F8snbWxj284KZIIMnrG81Fiki9OwkblnXfO6E=; b=Zsi6IbcMa+iTGBQ59F4aWoy5Vq T9WfJxWaNaSjxs0MC1zgCWuwcz5g0wOwydw6j19S0pHLUx1Z1c671U/XBjxM3WQGN5CBc8ZKoeUFU FSXlIrDXiYGOM5+Ehe9IWre+aarSe+7Ztga80vzwXxnTyD+mUkY8EXs/IVQVHL6n0Vc8BI2AjkqPn YKsMxANqj5QB6DXzYyCT2SbY1YP7AjMOMC7o6WzoXAvhLTNZoG9UiNFoB/YnAx8cWIuGKE2q1xkHV c5FtJ2yRcsQqEFHLhgGImYjZF5jXCMjemwkaqiEl46tkwkT7Mda2kPPX+xl6Qf7O4DPfCRveFjrNK d3HvxY8g==; 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 1ggnqZ-0003sT-Ci; Tue, 08 Jan 2019 09:38:55 +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 1ggnqT-0003lt-7y for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38:50 +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=1546940330; x=1578476330; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=m/8wk+BMZ6U5qeF6LVioutsW76YRgCcFXfZnC5OB1os=; b=cOJOA4pjCe6j91zsVunQzimpYC/JrXLYrMw9pLDF2Dm97nn1z93SM50m h7Nb01eqaQZ81uzYvYsncCRsnUjdrUQGsMTyP1/+LpyYCqkCIvEHPeh02 xnx0XESHlqXd0n6U8Hl3aCsr7RgBWIw33h9bXf9HPhWZS4iWQQpu3P7Fy 3Q9x7Ah5pOqGAjNiPEGK7EkABBYXvGFm3Xwb/BJDd3U8x0b/b7Q0OOaUQ jjJ+SI38kj3cbnLuGeDkvit+zkUIx6fINwL31p59QgVWw0PYjHPKQZuLH 3nPGcD5+pHeLtIwdDDgpDllLw98MrBgIjWua6We6uUL/8WelR5XnBUDu/ g==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000252" 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 Jan 2019 17:38:47 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:51 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2019 01:38:46 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 3/8] RISC-V: Remove NR_CPUs check during hartid search from DT Date: Tue, 8 Jan 2019 01:38:33 -0800 Message-Id: <1546940318-9752-4-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013849_386091_E745DDA1 X-CRM114-Status: UNSURE ( 8.66 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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: Anup Patel Reviewed-by: Christoph Hellwig --- 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 Tue Jan 8 09:38:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751721 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 6D1476C5 for ; Tue, 8 Jan 2019 09:38:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 575EE2625B for ; Tue, 8 Jan 2019 09:38:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A8F328864; Tue, 8 Jan 2019 09:38:59 +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 059122625B for ; Tue, 8 Jan 2019 09:38:59 +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=iaVQLkgs2QWgkqE3Qtu8mqs865dfS2z9DuCvBdss/gs=; b=Xx6uFDT1BQRRhSFfI+uMNYOJQh qiffvX/cmjr9+cIb/FFIHuhOItZPB8sZ9LiYa0oGY3SkYByccc7eAZv+YtnKJVVcs3ZdmpIvcGcwB TPO837UxYy/gEprfEbaWm8hKYc6VEd53hlXRgM0DuThhG5I/Gd7n3EssTJdSDn3wBGnh+ubPJ6OX/ gs0ViGARVyHHoHm9s0NUXISW3LZSF399PfQ1Oi82U1rVco4GvrVyyD7ihpHdW8bfLwKqknaq0jYzo 7gfJUJWGx77HKexFqkz9BluAPyzAoZ4ig+QU0hojctdE7NXves0QVYasqi42ihGkdp8Xm9NIffAHs gwD2O5Iw==; 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 1ggnqb-0003un-29; Tue, 08 Jan 2019 09:38:57 +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 1ggnqT-0003lv-Ak for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38:50 +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=1546940330; x=1578476330; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=c3GlsSU9hpztl0F7FBnfC5nPlii3rUi/viUc2pT+k2g=; b=JDRKqt76G/lqPd5zX/UzTvH8wE7a4teB0xD1e3y8d+Q1mAqdAruQugHe /W8RIafPy9EjX91bcEIGUKslq2ECRPgZjsteidMhSg4d1ovdv0D1J+YG/ SVkOv6zZhTjLlSc/+7CHBynGYHmsKwx9wCKoHYMsnTGtiyFmjRTgF1QsF AqBcm3VyGyy9OvZ2bgVxjuaP5yl/2qEHlPg3kPQUP16g2zdEkN01PuxdY we6PAMoQo4jadbb4n+BCsSnAjn3j9xH+hUOBALMNiadZvKDD3vU4DYbL/ MktkemhHfY99GLGt6iZ7NwZ98uJXP7M50zqwcsbNTXjh5+iLzT4AUHAQL Q==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000254" 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 Jan 2019 17:38:48 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:51 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2019 01:38:46 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 4/8] RISC-V: Allow hartid-to-cpuid function to fail. Date: Tue, 8 Jan 2019 01:38:34 -0800 Message-Id: <1546940318-9752-5-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013849_482014_025F8A13 X-CRM114-Status: GOOD ( 11.11 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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 e407bd4f..ce9a2e73 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -58,7 +58,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 Tue Jan 8 09:38:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751723 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 1EF656C5 for ; Tue, 8 Jan 2019 09:39:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BFAD2625B for ; Tue, 8 Jan 2019 09:39:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0013928864; Tue, 8 Jan 2019 09:39:00 +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 AB47D2625B for ; Tue, 8 Jan 2019 09:39: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=FBzY/BYBQVTn7M5/IdfSn9JXASTRRO6az+HPqKYyVuU=; b=prhTpQXzwtVBSZntirD+Jkd0i4 pnJxVTcvYpvTr71Re4ye67NMJBLcB8OeOH96e4qQJKBLvJCavlIgtotDJXKmHMlOXmGpuKL9bDINR H20UvRdLRaGfhvYgPoSSaM4p4Nh+VdtdVC6e2bVa+5kvy3mrdZilu/xlrQP2eUQEdD0ynyN2Sh2GO i2pHcCiR8lS9e3JtoykZ1W3amyLbGeqVMBwYZUD3n0iXCNysjk1GXQb24uAkurjW2R46ML/UruQEz DcnqhUu0O7+cXUuwl9WnpDaMADqQ1BEAl05zpXn8O/ykAONPLlqLk6151UhtNJsSrVjtB1tgeIB/4 7zesT9MQ==; 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 1ggnqc-0003wh-SY; Tue, 08 Jan 2019 09:38: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 1ggnqU-0003mL-RX for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38:52 +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=1546940331; x=1578476331; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bojnfVslHWWf25l3Qcim0lvK5HIdSXIJ0sC4JHd9reg=; b=i3u2DC2f90e7gwkOsGyQC1jBPjSjn99wDqU7ui575fJKkpoyDA4QzB3O TWAeNIWZ6aE3CfyPIsBxtGqHEDr7iHEFab5vCuRfwchrqx2U/0gCB1Ldg G8Jcdi8RVPqzw69ZwDnUYwxZk2QisduPll1++eFPIaUYRft2KhG7jVuse 0jLu2mObSMmmheKHetkEHF0VCYCIgNS/qkpR+eSNew3+T2s6WJmej3rWA 301ulR5WiJj+n0/QJ6EyNxXtK6vI8wFIiRMxvAHhEMypghLc/Wd8cXDMw 1QknnVcPCZEv2xF2i2v8sz9dcfH5zmtb5GpMBBloBxOcP6bdOt6Ao74w1 Q==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000255" 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 Jan 2019 17:38:48 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:52 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2019 01:38:47 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Tue, 8 Jan 2019 01:38:35 -0800 Message-Id: <1546940318-9752-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013851_008307_A258BE0F X-CRM114-Status: UNSURE ( 9.47 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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 32e14572..7954470b 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -69,6 +69,11 @@ void __init setup_smp(void) of_node_put(dn); 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 Tue Jan 8 09:38:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751725 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 2129614DE for ; Tue, 8 Jan 2019 09:39:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E3322625B for ; Tue, 8 Jan 2019 09:39:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 008E128864; Tue, 8 Jan 2019 09:39: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 9DEDC2625B for ; Tue, 8 Jan 2019 09:39:01 +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=MelWyik/GvTedYzr0C70EUDI4YFAIhb+oANEHLcLFj0=; b=JvWRLOgW7kYqU6yoWjwo2SrzB0 lQIUfjqX8WdVBtu1sQiovvDRk6quG3VdnnZI9AUUjf2tPW//PmTyLiJ+IEvCY2VEE8HXtd/iJKVLQ V2tXOMQwZHaV0EeTvD4P6/QSMftk0RYbTv7ITwgY4liSX3ASYbhXrh0YZPI2RyOTZBOD0J2MDvjl9 BzNaFc8j2LdU8vq8wdQBHtDNamjpAgjY5MNBnbq9zusGNMe2tX7vK2duyaX0UtC4NZJHvLEZQgeLa YO4ugLROyNSCa96TfNmkWnDNhReGbkrxOwB21c7zHyh9sUoZe6t+uXsSmy9+Fm7D7IEVMdIM0NtQQ W4qKs9kw==; 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 1ggnqe-0003yL-Bh; Tue, 08 Jan 2019 09:39: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 1ggnqU-0003lt-SD for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38: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=1546940332; x=1578476332; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=EOWNqUgwtvE7+G+LcAd3R3IxmYj+WfEqytDyPfTDJSM=; b=dT/I3FdO0+UedEahT3/fGcReO1KaV2gNjHmp0Jcq9K/BPKLL6DeNk4V5 tG613nsaDKHGgvHAsib2GlOhplVIvLWA4bPu9vSSyYSTTGiHv+0KcLFU4 vLGUMKmNf54edcQhxwgHnTQuj5anajSWAZxt/7WFNqRGKZhwf8QQjGhky ZQcpG4+s3z1NK3f4Bd/pYPFlOtnV2jo7KYJffWGBYKgav+PI4qrGy+u9I b8woeV2Z5g5eCA49mxQXCKawovQjg7R4wmmivEHbuQ62BmImtUzJ9Lcno Q68Tqod+yBwX5aWceIUF31fNt5dAGnFlktk62bbTY3OO334//CO6BIqPv A==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000258" 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 Jan 2019 17:38:48 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18:52 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jan 2019 01:38:47 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 6/8] RISC-V: Add required checks during clock source init Date: Tue, 8 Jan 2019 01:38:36 -0800 Message-Id: <1546940318-9752-7-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013851_011272_6C0A160F X-CRM114-Status: GOOD ( 12.23 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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 Reviewed-by: Anup Patel --- 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..d9b914e9 100644 --- a/drivers/clocksource/timer-riscv.c +++ b/drivers/clocksource/timer-riscv.c @@ -95,14 +95,31 @@ 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 Tue Jan 8 09:38:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751727 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 EC41414DE for ; Tue, 8 Jan 2019 09:39:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA49C2625B for ; Tue, 8 Jan 2019 09:39:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE9B328864; Tue, 8 Jan 2019 09:39:04 +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 8C0CB2625B for ; Tue, 8 Jan 2019 09:39: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=Hn8tPbLs5wq7OnIXj8LC4XthZctS8qwMEG9+VR2o1cY=; b=ZG1KVoQImgKwb0pbkcOiupUv5P fgQh0yjFYk39fXD+1MKJXN4yFDJia7q/UeolycGxEWWl+xiCgn9048QEbscpgve39CB7f95Jov2sq XpwYhgsQ/GPkJ3f6kIhw1XbHYn8Bs/wctWysQUlJm9HZtUhj65vu05Tjgd4lpgpeFj/KFykuMeW8p 0rN6WZPu41F0w+4BrkpsuSXVRMqOx/Eq7gt5SMfDk6mLOHQQi3zgIH+Lp0ApWiYlkaZ6gbkz3AIW0 7404cxVQzEYcC2n8kBi+xTwiC+JrH6+2of5GyQCULZo9/BCq7pjPA6zE+f71iwsQJjoY+uKEEl/TR pAJ8mCdg==; 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 1ggnqh-000425-9f; Tue, 08 Jan 2019 09:39:03 +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 1ggnqV-0003lv-0S for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38:56 +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=1546940332; x=1578476332; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=bw1/Vq2gne9LAKNuyEBhQX+XTh+Fz0MdGc7HYnZ0izk=; b=DSRG03E9Ba1K7rcKXlL2HzxhKoZLZgRTGeyMZPBV/GFxMIQGbPfx9CtF dR0+ky3g17XHhGxoUCIDZOZQyZxdxFSF8CsySMFarKh8NWHC+reZjAKzx kI6sUKxeyWBXCofAcVec4cbR8qxHaa6WtVuA4dnDjiWfBYbobov4wY/en EJGCOBsyRllzsFJYMQVRx1k2hG1GbGCY8a+pzunBbDWbLpmtEkQsnKkU0 cDrXO1aqfpjUGeVgMBBB1E5r02uEfrGPO54W1dNbKPppdTY97/F6RH92r q6E+6N+3sIcusm2CCb+Lr13N8MiNic7xZ/feSncSdJQ1iCTWRgKI3UnMl A==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000261" 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 Jan 2019 17:38:49 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18: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; 08 Jan 2019 01:38:47 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 7/8] RISC-V: Check and continue in case of an invalid cpuid. Date: Tue, 8 Jan 2019 01:38:37 -0800 Message-Id: <1546940318-9752-8-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013851_184931_C4B7D8FE X-CRM114-Status: GOOD ( 10.57 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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 Tue Jan 8 09:38:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 10751729 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 0222E6C5 for ; Tue, 8 Jan 2019 09:39:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3E152885E for ; Tue, 8 Jan 2019 09:39:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7E132893B; Tue, 8 Jan 2019 09:39: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 7DA0F2885E for ; Tue, 8 Jan 2019 09:39:06 +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=XZC93RHIJuajpVVW0d07Lj6xT0XOVJkZMu8gFekjfYU=; b=h0VdzLekaHRSDfv/3e/+7l27PL QytIaH4mQt0RKtZoVMbvIOt3yobuxeGYz8OMSkL9z6fhgRBKu4r3TZdX12RcZMuJLABv04xBYPN49 xwe/QjpSxFl9wycK6ur6yPeY03j37oKGldNUzFtBOYOv/h4O1z3GK7w0RJh0J+nNGLqES7MqmdHFH LiMypCI230eeNqcrSjz2JUofOtQI4yo6doMid1IkDy8qXFGOW/8FAIGeujBWjbGAb7aOLAuGTwKbZ av5el4zUyrfislV6Ui63Khouo5+ZsRv0rKlx20j4C8D5+xnE2GAoTpa/rC7bDAgNBGydc4EmrSbJ9 cEq+AQoA==; 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 1ggnqi-00043N-3j; Tue, 08 Jan 2019 09:39:04 +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 1ggnqW-0003mL-Jd for linux-riscv@lists.infradead.org; Tue, 08 Jan 2019 09:38:56 +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=1546940333; x=1578476333; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=hIYjBsfhX3gB/IHDl4/QkkHLXfbPQQMg3EaMmAjjBhc=; b=Vmn8I9dlPdmSZXVVNqPgu9ckgNwyIfcgYqnrc3unxf6uN6+dCXILcSMO BmfrTqYFq4Zt3yK207TEC4fNsdbBuWnXhkkYAoLhy35UN8MmhkumZ1pDW NUFPH3GDrC8mNZPeuf6ASlm5kQrTIERPdIsY5M6rLiJNJ6HCBmDm1KAlP Mp2ZdGFKMmOtHJ4YmMMx+IDLvdYQMIIRXqPXG5gsCC7Fc/JcdVrHhBrTG /Hx81g/SVPED6Rm4oVOM6yH3N5GF+0T6IKFBZaDzT/eNKBLGQ51TozyWo Krl7cRANc51HKwHFN3ixfwcd3Ys28r/dA3PFFJp+iA21t5GX7OkD+6LL4 g==; X-IronPort-AV: E=Sophos;i="5.56,453,1539619200"; d="scan'208";a="100000264" 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 Jan 2019 17:38:49 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 08 Jan 2019 01:18: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; 08 Jan 2019 01:38:48 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Subject: [PATCH v2 8/8] RISC-V: Assign hwcap only according to current cpu. Date: Tue, 8 Jan 2019 01:38:38 -0800 Message-Id: <1546940318-9752-9-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> References: <1546940318-9752-1-git-send-email-atish.patra@wdc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190108_013852_997798_92D46AE9 X-CRM114-Status: GOOD ( 10.06 ) 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 , Jason Cooper , Alan Kao , Dmitriy Cherkasov , Anup Patel , Daniel Lezcano , linux-kernel@vger.kernel.org, Michael Clark , Atish Patra , Palmer Dabbelt , Andreas Schwab , Marc Zyngier , Thomas Gleixner , Zong Li 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 current cpu instead of first valid CPU from DT. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/kernel/cpufeature.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index a6e369ed..ed6122ff 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -43,12 +43,15 @@ 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) + while ((node = of_find_node_by_type(node, "cpu"))) { + if (riscv_of_processor_hartid(node) == boot_cpu_hartid) break; + } + if (!node) { pr_warning("Unable to find \"cpu\" devicetree entry"); return;