From patchwork Thu Jun 13 17:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13697190 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7856DC27C4F for ; Thu, 13 Jun 2024 17:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=q+rxknPgtGpoPgAibMURl4JqQLEtHSHQgT82qipZKKs=; b=JLLDaJjvGQG1VD 6b5EO1IZ9MCvm5Cq5HJAjiXjjA/SBZ+JwYAhwQMuBv+7TDpyqAuFRIQZRjOafeE8Z29c7AmhcMEXB Dc3Rc3RDWDXhOFgDsBMdn+1VCzvUCpBZtBQAFR1PukF93QEWmIqj1JHTOPZM4XuPdkK0WPCxR8DkV VeMBEb55HoXY6388xIHLdmk/Ps6K4CEVicYROYeXW4GoMLCaihQEdHRh+V2mNaO7Ozhptks8kdkiO DBnWf8mTrCZu9LNpbxfU5wIyUYPaLzvKYkaOlpyZ4U/WBfGRte8v6SYkS520VRta9kMm8D2hE5o/w Eyi0dsl7cbVmjjbGTccw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHo2J-0000000HTvQ-1tnA; Thu, 13 Jun 2024 17:14:55 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHo2G-0000000HTuI-0iAy for linux-riscv@lists.infradead.org; Thu, 13 Jun 2024 17:14:53 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f717ee193fso9876445ad.0 for ; Thu, 13 Jun 2024 10:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1718298891; x=1718903691; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nWKKc9/VVGODzNuhTkLxFLmhIceztWrJoblOszvDngE=; b=mdvFzZLTuTZQgN5tOKnuffHYo0Gjzc7WkOpCW7IQBAFGxEUSYpX4TyY/2ddKbmBUqz qQH3fBrbkd1Gpw4Ed3Uv/hpLhymxdRgaYUAxlgXEwxAxEXPkziy5IHEDxcQB7LwEKVB5 7/c1klaXC4V9G88XN6+XU7/QbzMIUv9bFB3GvzOrqld0t7xJ3Do4oK332HqVlD/rx5UE pzBktwIR8UBun0jQFj5oyATjuFg1/LgwCuwETbjSNZAiugU9IsZL5sjb/+f9tsMA+eMr oTO0Oy2cqbPXvrYcm0t6q7iAu4+7P7TYQ7/QM0XF+QNX7Up5cbZiZaD4ssh9tRagOv1D Tghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718298891; x=1718903691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nWKKc9/VVGODzNuhTkLxFLmhIceztWrJoblOszvDngE=; b=AfW6+VNNUfWPMU3QsurAJX+Avh5bOkOmcF9MMFLcCucNj245AUTo1pdCVlbGqueGSD VGkiPl0rLTmwPLB1+dubNYczL5Av9w7iQGtCMk/vWZzBsylv9RN1cb5B/ExJdMCprOpe 6lVdAMcDY0PChjab1nu2x6FAj/qRji0H58T46QNdDzJ41kdBv2nu9KVyI3V5OWh97ugU SSwy/p/FBZ6WBIsN8XZcQXXfyG8SJpGC3RFOzt1LlSDHZhPPu2SElb2Yd/OfrMSQji1V 5xmZlHBOJK6Y6LnxTrw6UFFj9Nhiw1DBm7vOdnM8AtQaSMqRw+pnoVAG2d3iaQ9SQV4q E43A== X-Gm-Message-State: AOJu0Yx9dEBHv1GassLTlZ1VJfqMZ1W5flriDuXad8lKJMC6+qHueJZ9 wlCwwR7S6+B1gRJwgsgYEz3CeIl9JKACYjpLw3wcpepOIlF54kYJSZmNOIq3wQ/ty2nNmgvntwm VabfPK/yVUDxBWAygjmloWCFH0diR7nX6Wq9kPcEVTwmznsr9k1aQ0AjnOOhyyPc5ucRzQBTQIE 5nyQuVf3yhK59otpR2gwmVKqfV1f+sjxjoKIOUDMgXC6loKS82LF2Xinkz X-Google-Smtp-Source: AGHT+IHklgQWIpYY76YIpc507mgBwe7YRfUtJ7t8FaDKK4F93+FO1RhmCjEna4DXn6WioYV2N57SxA== X-Received: by 2002:a17:903:244a:b0:1f7:1a31:fae8 with SMTP id d9443c01a7336-1f8625cf24dmr3968735ad.26.1718298890952; Thu, 13 Jun 2024 10:14:50 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e55eb0sm16445035ad.18.2024.06.13.10.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 10:14:50 -0700 (PDT) From: Samuel Holland To: linux-riscv@lists.infradead.org, Palmer Dabbelt Cc: Andrew Jones , Conor Dooley , linux-kernel@vger.kernel.org, Deepak Gupta , Samuel Holland Subject: [PATCH v2 1/3] riscv: Enable cbo.zero only when all harts support Zicboz Date: Thu, 13 Jun 2024 10:14:39 -0700 Message-ID: <20240613171447.3176616-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613171447.3176616-1-samuel.holland@sifive.com> References: <20240613171447.3176616-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240613_101452_231773_5CBD9E48 X-CRM114-Status: GOOD ( 21.45 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, we enable cbo.zero for usermode on each hart that supports the Zicboz extension. This means that the [ms]envcfg CSR value may differ between harts. Other features, such as pointer masking and CFI, require setting [ms]envcfg bits on a per-thread basis. The combination of these two adds quite some complexity and overhead to context switching, as we would need to maintain two separate masks for the per-hart and per-thread bits. Andrew Jones, who originally added Zicboz support, writes[1][2]: I've approached Zicboz the same way I would approach all extensions, which is to be per-hart. I'm not currently aware of a platform that is / will be composed of harts where some have Zicboz and others don't, but there's nothing stopping a platform like that from being built. So, how about we add code that confirms Zicboz is on all harts. If any hart does not have it, then we complain loudly and disable it on all the other harts. If it was just a hardware description bug, then it'll get fixed. If there's actually a platform which doesn't have Zicboz on all harts, then, when the issue is reported, we can decide to not support it, support it with defconfig, or support it under a Kconfig guard which must be enabled by the user. Let's follow his suggested solution and require the extension to be available on all harts, so the envcfg CSR value does not need to change when a thread migrates between harts. Since we are doing this for all extensions with fields in envcfg, the CSR itself only needs to be saved/ restored when it is present on all harts. This should not be a regression as no known hardware has asymmetric Zicboz support, but if anyone reports seeing the warning, we will re-evaluate our solution. Link: https://lore.kernel.org/linux-riscv/20240322-168f191eeb8479b2ea169a5e@orel/ [1] Link: https://lore.kernel.org/linux-riscv/20240323-28943722feb57a41fb0ff488@orel/ [2] Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- (no changes since v1) arch/riscv/kernel/cpufeature.c | 7 ++++++- arch/riscv/kernel/suspend.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 1d6e4fda00f8..4347c9f91dc3 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -27,6 +27,8 @@ #define NUM_ALPHA_EXTS ('z' - 'a' + 1) +static bool any_cpu_has_zicboz; + unsigned long elf_hwcap __read_mostly; /* Host ISA bitmap */ @@ -92,6 +94,7 @@ static bool riscv_isa_extension_check(int id) pr_err("Zicboz disabled as cboz-block-size present, but is not a power-of-2\n"); return false; } + any_cpu_has_zicboz = true; return true; case RISCV_ISA_EXT_INVALID: return false; @@ -768,8 +771,10 @@ unsigned long riscv_get_elf_hwcap(void) void riscv_user_isa_enable(void) { - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZICBOZ)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOZ)) csr_set(CSR_ENVCFG, ENVCFG_CBZE); + else if (any_cpu_has_zicboz) + pr_warn_once("Zicboz disabled as it is unavailable on some harts\n"); } #ifdef CONFIG_RISCV_ALTERNATIVE diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index c8cec0cc5833..9a8a0dc035b2 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -14,7 +14,7 @@ void suspend_save_csrs(struct suspend_context *context) { - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG)) context->envcfg = csr_read(CSR_ENVCFG); context->tvec = csr_read(CSR_TVEC); context->ie = csr_read(CSR_IE); @@ -37,7 +37,7 @@ void suspend_save_csrs(struct suspend_context *context) void suspend_restore_csrs(struct suspend_context *context) { csr_write(CSR_SCRATCH, 0); - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG)) csr_write(CSR_ENVCFG, context->envcfg); csr_write(CSR_TVEC, context->tvec); csr_write(CSR_IE, context->ie); From patchwork Thu Jun 13 17:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13697191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 524D3C27C6E for ; Thu, 13 Jun 2024 17:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZwnVMX6JdVnZpzpZNGE/rdjRj5XHusa8J3P4pUXS1Zs=; b=KQUbzvwyCI4jyE NNUbbIKSdoQuaM04sGjmiykCog52qklIzJgSH6+jsWYsKnZQ1C32zIDA2ZkqiEtgp8klc58wWW543 rZVW/mmHi/Cqsm3PvQl/2OJCAias4dnRvWkiRhYwYz5yubt9D/ogJ/obks/CSfQIuvZwlkiKmDEDg NYFJR4z58a1cX6Ss78BCkI2GVWXkiuwzRrvp/0ZcG5XDBtsUc6Ilkim4Uf0mVVbHNOaDEgvvFxzwS glg6EE2GhAlLsTY6v8DSVZ+QFDYjHFo4aTDIcH0tM4LGl4J0QSTS5bPtsX1YwSlGJCXoJzDA7mpmx /JmQFPR05aLyOJiHN9qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHo2L-0000000HTw2-1R6S; Thu, 13 Jun 2024 17:14:57 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHo2H-0000000HTug-1D2f for linux-riscv@lists.infradead.org; Thu, 13 Jun 2024 17:14:54 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1f6559668e1so11481355ad.3 for ; Thu, 13 Jun 2024 10:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1718298892; x=1718903692; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aV8R4Wka+kWZfjkzpKS7OzxP5uBoNS2Fqf1rx+C8LXA=; b=e6muc5+mLzTVgRiYP367E1Szywj2aGaNDRmJZhQ3X9rCo/jzpXB91I4ozNDWa4NQsO pnBHOVWTW8lQZINLVRkw5V7ymdxK+Nhu/NLR79mK7doU0zrztat4qvQ+Pov+yRJrdwoF XB8CmmjO+lp7JXAXbO2lFnQjRdX/BCE9sJFPF2JCMwMwg4e+x+OG1sF+9EZAzGWRgISE R0b98x/l/82fskHK3YY8dF1DzEwFzgdocVXOASuGz3/sd5chBcl91yGQdL9lUQZOkYGe OIlZWE2rMmUXXYHNwFyju2pbaZX/AsmZmXQrcSJydsDAHvHq8ylX/H7I2lVRxYmQ5kR2 1WrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718298892; x=1718903692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aV8R4Wka+kWZfjkzpKS7OzxP5uBoNS2Fqf1rx+C8LXA=; b=NQGtu+ffTiJCBdh3PBdZ/+/TMmZbjFr2ReSjzDOKZXE3MST+i02SdGlLlsnJwZ4/Y2 HLxS8AmiMBihHdsMw3YNlrkyDJSwbe/XU/68gQUNcGdRcSLyYqHwkk8Or3hPv5FsxYN2 JtCkLmjmMtJvoU8otj6AphkzHexJTDKElOrx/insDub0fYQ3KLfLuw2eh3erfWnGErxg uupUkYFISD9D0Xt4skX35hu7dDTVISc3GjfvudUVZzu7d+8kLtkF/RLfefs5fS2bQRyX diMNAV45wUa+v7w3vycPgmuwcuamZHmN3PfmCxuDAcnQPqzkEeB9TPsn/Cmox4ub8gFA S9ZQ== X-Gm-Message-State: AOJu0YxMHyy64kQdJnHephI19F8IRSZ3ud7Tu+CmfhWnjyqgfYOkZUQW jGCgQzBH4lL4zBn5wLKqUfSV3iMGGdM+r8c/VE6HEs5fRrLZgvufW+AADDZG2tKW5g4V1iAWbj9 7SsIqtDLqaO9Qq7Kd1Lavxik2RbCC4taNL8kOAiTnL0NwXyr8PrtT6FbubnShXPug0no/6DqYeD CiQUgx89Dd5frlPuxgv0/N9/a3ZGm9AGgJihfnBRnangvPSNN3U5cjoUS+ X-Google-Smtp-Source: AGHT+IE+AuA94KlSOrMmKKMHWCbLkDJ+fe3SrEJ/Bo4TkgvXZJ6nzIlGMF8rhlIZJZU0Xh5kVXXaSg== X-Received: by 2002:a17:903:41cf:b0:1f7:17c2:118b with SMTP id d9443c01a7336-1f8627c76a1mr3144095ad.27.1718298892234; Thu, 13 Jun 2024 10:14:52 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e55eb0sm16445035ad.18.2024.06.13.10.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 10:14:51 -0700 (PDT) From: Samuel Holland To: linux-riscv@lists.infradead.org, Palmer Dabbelt Cc: Andrew Jones , Conor Dooley , linux-kernel@vger.kernel.org, Deepak Gupta , Samuel Holland Subject: [PATCH v2 2/3] riscv: Add support for per-thread envcfg CSR values Date: Thu, 13 Jun 2024 10:14:40 -0700 Message-ID: <20240613171447.3176616-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613171447.3176616-1-samuel.holland@sifive.com> References: <20240613171447.3176616-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240613_101453_348713_3EC1CB1A X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Some bits in the [ms]envcfg CSR, such as the CFI state and pointer masking mode, need to be controlled on a per-thread basis. Support this by keeping a copy of the CSR value in struct thread_struct and writing it during context switches. It is safe to discard the old CSR value during the context switch because the CSR is modified only by software, so the CSR will remain in sync with the copy in thread_struct. Use ALTERNATIVE directly instead of riscv_has_extension_unlikely() to minimize branchiness in the context switching code. Since thread_struct is copied during fork(), setting the value for the init task sets the default value for all other threads. Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland --- (no changes since v1) arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/switch_to.h | 8 ++++++++ arch/riscv/kernel/cpufeature.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 68c3432dc6ea..0838922bd1c8 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -118,6 +118,7 @@ struct thread_struct { unsigned long s[12]; /* s[0]: frame pointer */ struct __riscv_d_ext_state fstate; unsigned long bad_cause; + unsigned long envcfg; u32 riscv_v_flags; u32 vstate_ctrl; struct __riscv_v_ext_state vstate; diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index 7594df37cc9f..9685cd85e57c 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -70,6 +70,13 @@ static __always_inline bool has_fpu(void) { return false; } #define __switch_to_fpu(__prev, __next) do { } while (0) #endif +static inline void __switch_to_envcfg(struct task_struct *next) +{ + asm volatile (ALTERNATIVE("nop", "csrw " __stringify(CSR_ENVCFG) ", %0", + 0, RISCV_ISA_EXT_XLINUXENVCFG, 1) + :: "r" (next->thread.envcfg) : "memory"); +} + extern struct task_struct *__switch_to(struct task_struct *, struct task_struct *); @@ -103,6 +110,7 @@ do { \ __switch_to_vector(__prev, __next); \ if (switch_to_should_flush_icache(__next)) \ local_flush_icache_all(); \ + __switch_to_envcfg(__next); \ ((last) = __switch_to(__prev, __next)); \ } while (0) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 4347c9f91dc3..b5b8773c57e8 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -772,7 +772,7 @@ unsigned long riscv_get_elf_hwcap(void) void riscv_user_isa_enable(void) { if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOZ)) - csr_set(CSR_ENVCFG, ENVCFG_CBZE); + current->thread.envcfg |= ENVCFG_CBZE; else if (any_cpu_has_zicboz) pr_warn_once("Zicboz disabled as it is unavailable on some harts\n"); } From patchwork Thu Jun 13 17:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13697192 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9330C27C78 for ; Thu, 13 Jun 2024 17:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=82F19uxTGuNTUDRjpEapHakwMiG3bXaKkSF6COYFJk8=; b=i5+v/d/utTciwG YZjvUiUy5VyE5QL2OCuXANRFIysqaQ7Vm/La9Gl5BIPxkOtgzCwi52sJSAM45h+wKQyXUCTc7IS5+ bRj5cqW0cfuk7ZWsBDQhrPu06Nxed64ONFxu46rrM0QGoLLAzxCxNrGS0UgwCz5o9Hzb0ZU5TNYU6 uvXayAjd4LnrfzeIakaXa/y7cIfZvBigziiRDajFhNuhXJN2U+nJEs9T76ETFiFUiOOjyQ1xXEL/3 VJafa3rQ+vaCjycgnK06C9SPeiLvc2fG6y5gJI+rpyimzD4zjNgHTVHKWr8OngofaV4AiRWtehH7+ 4cA9ZTpMhV09zT2h+qRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHo2N-0000000HTwU-0AwK; Thu, 13 Jun 2024 17:14:59 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHo2I-0000000HTv1-2wkW for linux-riscv@lists.infradead.org; Thu, 13 Jun 2024 17:14:56 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1f6b0a40721so9366395ad.2 for ; Thu, 13 Jun 2024 10:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1718298894; x=1718903694; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PiB/UuEMeERuvvonGAvIVsUp7Uk/id7nJUnnnQyTCfs=; b=kXw8a25MBMlcNxLwCnzGHh/UiX0MX6KxPTqC0T0m6iB8Zx/8lwT2AzpI0OG5jzgKCg ValypveFVJ2BiHBLXWz6YBy/8A2j6JnrTCGjcnuf/+nTSU6bagCi8bSxHjTJaX5LF+Ji +GETHA5kytCEm9wRB+a+lT+YfbcI9xa39WxZOsgX9k0P9h7sjHxyx51ExJ94YmNP39zr kLD5s4G42SV+Jn/SWOVZkCCRt3xtRIc7bbqNw2ZF10ozrIjnC6GDRxlvH+JZRNVNaBPw OMmkFvd3WUevDStKCuO1Hn0zV8HWo8jKOdJs8YCUXtnTXeqCOP1zqheatEY+Uf9cMFlO n3qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718298894; x=1718903694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PiB/UuEMeERuvvonGAvIVsUp7Uk/id7nJUnnnQyTCfs=; b=c7Ue6mM7oNn7Y0e96TH3d+REKoyLo8qAFnQcZ0mzVWTBmelH627ebyuoFxGpMxw6MI 6Qn3Kz2x/RJlT6LzxNvFQlE+N0Xg+7yNSjO9Q2oWtW+4NKm3uSKIbAOctk/QoPF4c4Aa KdXfw47ysp2rXZL7keTJF++IZ4BTMmr1ve8rTMo10j4FXV2cAOPiS7wix7UyTG7SnuaV PjHFf8r/zNj277gSDXgDYdmXEual3DTjOucRUnqeJi4+Pkpt4sZvX2Pwp2zJX2fcZV4g 84yLnmN/RaaSzypSCRyaJiavXsAjmvkEVnaKJA1OXhnYTMBrAFbFDs9ya6vtedtqIeU4 HmTA== X-Gm-Message-State: AOJu0YzMlV8dl7+/k6n9t8AsaN1/y6dU8BeFt46EJ9hNOSO6KK++hgFb /p+V+mwhkpjaDIu22pj/8e3hOg9FaFFRSlt2syoEVmJPY6SJJMyBpAEH45Yl3PCpzE4D5w20fIE QVrijzAyyIM96izVlWDaQPblZvaOIKyPc3ZNF6M+eFWeM8V2UTrrJ06qtf+BZMF23ihulcsiBnp eyrz0HQ0tUC24y7POGZKNT8APDLICvPbEf6rr8n8c/tlIg4h7LnAzl+Jzn X-Google-Smtp-Source: AGHT+IEC3ooBkVTmCDBXrUOrLtGQVRJuUPu9D01slJFB79gG+rGaRpjLKGcsWlDV8sqY64x6kc174A== X-Received: by 2002:a17:902:cec4:b0:1f7:3d44:1f1c with SMTP id d9443c01a7336-1f8625d4e5emr4130615ad.5.1718298893625; Thu, 13 Jun 2024 10:14:53 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e55eb0sm16445035ad.18.2024.06.13.10.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 10:14:53 -0700 (PDT) From: Samuel Holland To: linux-riscv@lists.infradead.org, Palmer Dabbelt Cc: Andrew Jones , Conor Dooley , linux-kernel@vger.kernel.org, Deepak Gupta , Samuel Holland Subject: [PATCH v2 3/3] riscv: Call riscv_user_isa_enable() only on the boot hart Date: Thu, 13 Jun 2024 10:14:41 -0700 Message-ID: <20240613171447.3176616-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613171447.3176616-1-samuel.holland@sifive.com> References: <20240613171447.3176616-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240613_101454_820860_E86C61A8 X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Now that the [ms]envcfg CSR value is maintained per thread, not per hart, riscv_user_isa_enable() only needs to be called once during boot, to set the value for the init task. This also allows it to be marked as __init. riscv_isa_extension_check() sets any_cpu_has_zicboz, so it also needs to be marked __init; it could have had this annotation already. Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- Changes in v2: - Rebase on riscv/linux.git for-next arch/riscv/include/asm/cpufeature.h | 2 +- arch/riscv/kernel/cpufeature.c | 8 ++++---- arch/riscv/kernel/smpboot.c | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 347805446151..4bf7b7ebf6b3 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -31,7 +31,7 @@ DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); /* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS]; -void riscv_user_isa_enable(void); +void __init riscv_user_isa_enable(void); #if defined(CONFIG_RISCV_MISALIGNED) bool check_unaligned_access_emulated_all_cpus(void); diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index b5b8773c57e8..d3e3a865b874 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -27,7 +27,7 @@ #define NUM_ALPHA_EXTS ('z' - 'a' + 1) -static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicboz __initdata; unsigned long elf_hwcap __read_mostly; @@ -74,7 +74,7 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned i } EXPORT_SYMBOL_GPL(__riscv_isa_extension_available); -static bool riscv_isa_extension_check(int id) +static bool __init riscv_isa_extension_check(int id) { switch (id) { case RISCV_ISA_EXT_ZICBOM: @@ -769,12 +769,12 @@ unsigned long riscv_get_elf_hwcap(void) return hwcap; } -void riscv_user_isa_enable(void) +void __init riscv_user_isa_enable(void) { if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOZ)) current->thread.envcfg |= ENVCFG_CBZE; else if (any_cpu_has_zicboz) - pr_warn_once("Zicboz disabled as it is unavailable on some harts\n"); + pr_warn("Zicboz disabled as it is unavailable on some harts\n"); } #ifdef CONFIG_RISCV_ALTERNATIVE diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 19baf0d574d3..0646f79e0a02 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -235,8 +235,6 @@ asmlinkage __visible void smp_callin(void) numa_add_cpu(curr_cpuid); set_cpu_online(curr_cpuid, true); - riscv_user_isa_enable(); - /* * Remote cache and TLB flushes are ignored while the CPU is offline, * so flush them both right now just in case.