Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1105757imj; Thu, 7 Feb 2019 17:53:16 -0800 (PST) X-Google-Smtp-Source: AHgI3IY1lt2niJrXoX8jAIL3deNyXx/tQOX4ksp66joWKL3OBBnhL5n3ORk1B9frNL8FZSzzn3xJ X-Received: by 2002:aa7:83c6:: with SMTP id j6mr19321477pfn.91.1549590796021; Thu, 07 Feb 2019 17:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549590796; cv=none; d=google.com; s=arc-20160816; b=EBAsxkPBBqi3ICw+hwuBJW07bXAkE73+xtEjml3QhKRydyqyTuiM03w4CN7dPOfbMH kBQVv8y6BGHU8w1YyvO87H6z++qSvhcE1PTp4tNr1tENXguK67b9erGezuFLbEfydX0f Vv5PQtkzSBBFSy0hu9Fo+3egYljPJMzbRygGgG/BN6ejipYWJ8vJR46ip1Qj8TcuM/L/ 31+zJyrjtmFGzwDoe3XyJY07aY4ii5jrJqBVLoWu8CaUg0LbQEX0WTjWe52omHcH3I+J 72WN94QmInZXRboFhewMTmrwAAKL5wjJuECcnd3Cf5EJWc3cXAO+jGacDHx/0mnsp8Ot EH/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=nYOQJls6f+tK9Bv2QgN81S/c8aAHBT2bDsYg+pyttO4=; b=CHSFT95U4NKv+a4+9IjSiN4NOkT2At0uPCIksNoPjtiZs2ZxSy16/xhQEvsNnelRTS J6iYr2YlBg8PXHU9vctGh+AEg4HpRTRtGsBlGxl/t0vBv40Dg1UH0C47shl+o94r30wX YkNy3paUUmUxzEgE2DNccaxoslaHkweEBHhVD6Wnm+KJ0eJ9TscokH8j4ufXMI5mnsmM Fg8bf1q0j6juFH+oROy739LmIXsO3JmUwUgCfWWLZ1yj3KJenyE9sv1k4TRGyupjf7u6 GkvCqRdOfEI6AP+xymz3thj4pUaigctZhJSJ++7wkF1PR7ZOYKzFIUcc45PZanhAEIch RCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=bmQLFtaW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc7si734955plb.120.2019.02.07.17.53.00; Thu, 07 Feb 2019 17:53:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=bmQLFtaW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727273AbfBHBvy (ORCPT + 99 others); Thu, 7 Feb 2019 20:51:54 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:13347 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727226AbfBHBvi (ORCPT ); Thu, 7 Feb 2019 20:51:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1549590699; x=1581126699; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ZvCXzp8StVNSMAn/qR+TnMWcDQTO4o6GC0MhJ3P3W7o=; b=bmQLFtaWXvaLxuymJzD6g+WnApCuWpZl4Hlmc/FoOAqRFOWIh+EvnPj/ sa2Vm6CoAKL3+k4i7dMDucsTyQyMneaVyEcoIU/W1KlWOfM4ZBIiGDc88 N8g8WSw8WSz1+szvcQDOMQLhO3vqlsSFQ14YN5qG7Ep+PiNpeLx7a9vg5 zoWUod4/43RPQYKzX4t1UtUjrEY4mdWJfYqlU+6sMzdvsosx7MPtXPD7b vNaAdy4ceYRnvSlmOv4hzL+JHD04oX4JHffNWwQCeQeCbhwUTAuCVI1W0 X3yX3jmjUwkWEvr6Q2hkDI/TW+5yJTZgkC1Vxp1KeieGcgMz/cDX5ONaD Q==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="100752826" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:38 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 07 Feb 2019 17:32:21 -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 Cc: Atish Patra , Alan Kao , Albert Ou , Andreas Schwab , Anup Patel , Daniel Lezcano , Dmitriy Cherkasov , Jason Cooper , linux-kernel@vger.kernel.org, Marc Zyngier , Palmer Dabbelt , =?UTF-8?q?Patrick=20St=C3=A4hlin?= , Paul Walmsley , Thomas Gleixner , Zong Li , Damien Le Moal 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)) { -- 2.7.4