From patchwork Thu Jul 18 00:47:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13735891 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 BC6F7C3DA64 for ; Thu, 18 Jul 2024 00:48:32 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=JVixOxZJ41aM6yq1GPMKB5diDLAFe2ZdNIUPM4pYBvo=; b=Ozc3n9q83U3KUd kqG4C5x4Fd9vAvlivaVPgCC1LIdbNPeDRF47p1e1hy9pel37SW8rBiuShW/XpLdMP4Ymx1Awykw1l 2dLoFr0998LGr638bCxYPFfqbSZ9twyjKCdBiRvzEkZ/qDUgW0L96FHtj3NaZSuLHfousc7FtNfGE 9TLGCE8FtquWncVnlfs89T5hDxL1P/2tZv6XqHleUXZR5QsObXmh6uPPOWuE+fFx8J3P1Jp37VQc0 PQTmRIt9w5FsDRvhq37+ubYTTRChpFm8QlzjrWF0tlNP4ctzhYdM2Xf9pMH8kIvSlFcIERXhZf8NX zcvnRYZZFMPiJIhGmOUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUFJi-0000000FIFg-3XBm; Thu, 18 Jul 2024 00:48:18 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUFJe-0000000FIEO-3bf6 for linux-riscv@lists.infradead.org; Thu, 18 Jul 2024 00:48:16 +0000 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3839d74a2abso814165ab.1 for ; Wed, 17 Jul 2024 17:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1721263694; x=1721868494; 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=OQiU3jLs/PVYv24pQZF1OM35EdgJeLHTVO+iajBsq3c=; b=XSBCZOP/J1GpXtzOeG1uNMnURKl7ARY47Lr4P+6vYhsHmAhrxEo635OO2DWtcQpPVW ZFWtoxTk1m/CNrllY7kL+UJdBhchlOrUSySfal3Z4vkJO7RSjowSclK+LXi8O9/QFOs4 kx2ZU9Blbi2u621wT3/HWb/yMD6KVUfOSgNTV3C/o1zSNV7ezE9fCgF6yzLRQ3eowwsO mqjpvTvAk0ymB4idH+Jk+3poTofcK7+SXDkTVLIekDc5sZB5HZP2AikeF4SIzIgXXS7n c5MeCL/WlUCrPEQj30fVhuA1wYm4GUs36XeID7yyGXAuuRuXdV6emVS8kGhxSeFIF4bG yQTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721263694; x=1721868494; 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=OQiU3jLs/PVYv24pQZF1OM35EdgJeLHTVO+iajBsq3c=; b=EccKWvlmpdjEnTe5V5+PJ0HL5kQMP534aTocAPoWVYEwse2bqOONkdFcVUOMYXOCs1 E2+kSYoBkixES5YnuhzwANGpxvj9G6mY+vEWXUSZANyG+h24+YnthOFfCGQe3Z+C0hek Czmt5Ivl+dYJMV+R5LO6SO4bx77M/gGoqaERS18HHwNyx00uf1lWS1gMvltpZzXVJqTU Gmntt6zkZm3AeYhY/wORbIuKE1p4Dga/zW41F4AhJMWGeZT9BL1v8Al70GeUCZhg/qTn +/duvmnbNl/17IJTKdPHAXADPlVYAm0ICl1aye+UqowqKD3Wb6v2bEufwuEuLwE3STgr C/YQ== X-Gm-Message-State: AOJu0Yx/n1SK3TtottJfje5jfelmg//w1o7ZUN9SvWkvR4KCpyeadSJd SHel3fWbLStd9IEFdlfuI9+E0bVMwGBcLqOoADg7KjS2GuNLJHnbn9KG95h5zfryBbFTXjwSOv9 vfAP+iKTAGjJIPbX/L8acxV8totfPukxrhFkXL/jOZD8wXyoz+W0CL84bq0XBAtC+O71vrIILhN Z9fTP5QS+gmo0cZRo8UWkxuplpcXf6rcilIdgZzgt2toGVjA8KBSQBlCri X-Google-Smtp-Source: AGHT+IHQC2fSybGj1wvVXYG/rNOyfBlLM1/ZwN9ZqAtrY4RDk0eAm6Wfwf7zO3wfGYZ7JiO0lxUPvQ== X-Received: by 2002:a05:6e02:15c4:b0:376:410b:ae69 with SMTP id e9e14a558f8ab-39555cd31f3mr46347585ab.15.1721263693464; Wed, 17 Jul 2024 17:48:13 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-78e386d53e4sm5694300a12.70.2024.07.17.17.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 17:48:12 -0700 (PDT) From: Samuel Holland To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v3 1/3] riscv: Enable cbo.zero only when all harts support Zicboz Date: Wed, 17 Jul 2024 17:47:54 -0700 Message-ID: <20240718004808.2246354-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240718004808.2246354-1-samuel.holland@sifive.com> References: <20240718004808.2246354-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-20240717_174814_923527_739540A3 X-CRM114-Status: GOOD ( 22.71 ) 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: , Cc: Albert Ou , "Rafael J. Wysocki" , Charlie Jenkins , linux-kernel@vger.kernel.org, Conor Dooley , Samuel Holland , Evan Green , Andy Chiu , Paul Walmsley , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Andrew Jones , Deepak Gupta 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: Andrew Jones Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Charlie Jenkins Tested-by: Charlie Jenkins --- Changes in v3: - Rebase on riscv/for-next 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 0366dc3baf33..4efaf12b470e 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 */ @@ -97,6 +99,7 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data, pr_err("Zicboz disabled as cboz-block-size present, but is not a power-of-2\n"); return -EINVAL; } + any_cpu_has_zicboz = true; return 0; } @@ -874,8 +877,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 Jul 18 00:47:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13735888 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 9AD72C3DA5D for ; Thu, 18 Jul 2024 00:48:31 +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=U4DQwfrrSVPHhehvZ4r1tkJidKzRLZW64z0JBILMtXs=; b=OjA1lyDAzPStJm CItPG+N9K+drdBZDChVWPUmr+fmoUvh4AgQssLSElpyM83BWcJSwDZAOjp2VP9c9jou0hiCrDzW2b igKBBZNKB0OcWMo6UdPwOcMvqUZSeK3t3hqnngFai++H+2OGFCLUIzx0/dzx8kjtT62wNLfDJ0Ur6 5PFGeZ9DovQcODh+rUBxqX9xdwOHFg7IobltCCU1V76obzTGMJz4jwA3hsnRT8IIXDQgYb0P3CMRm cVWtHfvhBTijNSTiAgvIqKRdERwmL2CWfSAEBvpwLX3IFgkuVtw0RTG7uscpx2yf1f4fBbnjLqERb 9H8wwWB6q8+UlH7JjxmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUFJk-0000000FIGI-2V1Q; Thu, 18 Jul 2024 00:48:20 +0000 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUFJg-0000000FIEn-3ECH for linux-riscv@lists.infradead.org; Thu, 18 Jul 2024 00:48:18 +0000 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5b9776123a3so90397eaf.0 for ; Wed, 17 Jul 2024 17:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1721263695; x=1721868495; 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=0yshoBMmTilnB7Tn31CojFxfms9fcaLBu92AZXjz1tU=; b=fEIbSon7afZUmLlaUmKIUR9L0E7vw8QjLhC1cZiDlghSP+jN7xxRVTz8jgv/YeJqRD VrnI1BxjSViB5xCYWUHq4R36jW3Eqa6LLBldpcIBNSUymiRerj54eVSa9ScCFShOJuFG 2hjrU7cPsSP6RHUuckm4U2OFMeFebL4cgZJSi5o3IdjmpYsrj0gEXX1SBsCKUZJutRc1 UqbSSzxqq/YQmnXVwjdy3cBBekaFnPoVgJTZ4vUy9D9HvQqZLAxqLKbx79/3YnRoHX1c w6b7g1HOBzZvcZpq55l9Ge8CFDuRpKQYbNkjyiv7Iucpe5JIijZq0dEbGNzxptxzQxla wjHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721263695; x=1721868495; 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=0yshoBMmTilnB7Tn31CojFxfms9fcaLBu92AZXjz1tU=; b=vkSj+F5gTx91480dcoUWGWogXRaPH1af8Yd31jRVNzaIcbdu1m9zXrNC7auV04bYEb BrSjtANGIZ3B7VC7fANovNG/6FPDq8NpW/0nrErVq5wq2g2UbeyIQNUJL8XQov+SHG6v Vaz9Ns/Y8U6FE3x7pnqplidwM9mHC3Et7WVwCu8YCfHJe1vIVhCisPpJy4XSyokLDSxa 1Gmp3hizXNPlOghy2L5CIDQvxKBPPn0pdKPZuOrO/L4gEN+YfjqKWH56RMUVTwFw170s 3Fp7BHP33GoTjq1DgtFy48vyTNiGBLpQ3j7TfPLEfczDj1ETyrto06SGy3wKaClXRhBd Km7g== X-Gm-Message-State: AOJu0YzSKjqCCrxmF8CAjPE0OI08Pf3RqF8WpzTS4QzK8Lvz4gvFXaVk 3QVvFMS/rJvESQJrUIDbfZACqiceYlz/7I4UtQuMJungMp5ltqn5+ztMGUuX4amCSQO+rnRepkh nQKJvR87pTOGOMfdsHqsgGqccXfmz+OCfJnbz2b+9vWxFUJA/5Im4BO9SupfdpZsTskC3HQ7Bhm gLeq+hR+PwFgEOIb+2BIYPr2Ul76u8oRdRTExlkwHpeNK0+E/QIklC3uCC X-Google-Smtp-Source: AGHT+IFRqJmu713tBVUOkgi8JXhj0gBme+e9qJOsn5K+mQGju57nj8Rza2na6vwCvpeIB6ToTiVXyQ== X-Received: by 2002:a05:6820:3095:b0:5c6:9320:4f1e with SMTP id 006d021491bc7-5d41d0c0709mr4511184eaf.6.1721263695492; Wed, 17 Jul 2024 17:48:15 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-78e386d53e4sm5694300a12.70.2024.07.17.17.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 17:48:14 -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 , Albert Ou , Andy Chiu , Charlie Jenkins , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Evan Green , Greentime Hu , Guo Ren , Leonardo Bras , Paul Walmsley , Xiao Wang Subject: [PATCH v3 2/3] riscv: Add support for per-thread envcfg CSR values Date: Wed, 17 Jul 2024 17:47:55 -0700 Message-ID: <20240718004808.2246354-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240718004808.2246354-1-samuel.holland@sifive.com> References: <20240718004808.2246354-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-20240717_174816_834153_B13D3E01 X-CRM114-Status: GOOD ( 16.14 ) 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: Andrew Jones Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Charlie Jenkins --- (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 8702b8721a27..586e4ab701c4 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -124,6 +124,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 4efaf12b470e..43fdae953379 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -878,7 +878,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 Jul 18 00:47:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13735889 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 98A65C3DA60 for ; Thu, 18 Jul 2024 00:48:31 +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=DaHTef2NRNk3Dv3wb/wNREem1n0pT8PtfLNvvJx/SUc=; b=EoDr6ehs8Ic5uv 6qRT/hEDKlrJICPflEbttqB31ipJsUNAcPfRqoW8UJ/q+m8TMX6JxvRB4XykmWkzWfPOL0cNSKj+K YkVCpCfQn3XxezYUisUcKDRk/cqplQUWfPL1breLuZX/BVbHeyuO2WMX5HcRO5RaVGEPGVRdUDEN5 SH+Xo1EjzyyZUYTwCSbxRIrjZze/w+d6QadlwjgKLnCNwvUV+WnBVI+LZ7TVu7H6bfwF7Gc9tpnuj yszdPGGjjBi155EpEnidjXwksirjul/qjjtp1W+SRZ679fR1oiBGYNknLkpNCqQvoOSnXE/OMsDVd 3dXhs+O4kIOGTGpmlAXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUFJn-0000000FIGs-2DPO; Thu, 18 Jul 2024 00:48:23 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUFJi-0000000FIFV-3QEK for linux-riscv@lists.infradead.org; Thu, 18 Jul 2024 00:48:20 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-70b07bdbfbcso1127501b3a.0 for ; Wed, 17 Jul 2024 17:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1721263698; x=1721868498; 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=CFld1vW28kOoabvpVtGlz2RoBm7PVswCH1l6QYeAzTM=; b=mNI04PIHwvX64YNByPSyDUik0dy/FYDB4XhOOHWgmhzr0iUZmYbuDkKs5PdcJ84zKB iJkwsD7UDooCd0deKwz6J2AD4l4Z+8gWcjXsqysBfd1QfX92gIh4nXZlWs4vWI9WyVmy cmzPeKW7NDUVMvkEBQ+0eQSXinAqjtQE9X8dxDWBFkeAoYk0lnPfewta+SayuVlr96oI Tl6ijF5zyidjo5aDt8XV1Nz6ssaIWvfw1bprSi0mK1qxnSh5wwsXzl7aXHza951vFCzR MCUUaTlLLv+FHCq4OUwizn5XCI2EIMoKP64ZLJx0aGhXp7FBtLfffqTFG8K6HEQHZ8X/ qs6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721263698; x=1721868498; 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=CFld1vW28kOoabvpVtGlz2RoBm7PVswCH1l6QYeAzTM=; b=YARKRRx0H28zKzPXzzmsF+T/SoVLrZTdusAWnIHzuXDx9J2ywrgi8p6c8biliDzfRp /QbDEt8JKAXDrL/xqHnkBluEWViEA4fwtFLItR9bMKfqFjKACAKCdMF7YiEVB7p+3Iwa nhWLpzEj18CKvB9w4GY3e8RZnLmokTn3uCbItFaiA6klJ57XQVBuKx2z5vO0PxFDg0av paoIjkOkiKuwesb6yRvvi0QkpwfsoPIeeyk8Ku4RQ+90rNTJZDbF5rpic8KEdA73niQ2 ctTVC98NjIEH7q9sSz0j6iTFld2BgcF8DUYQVbwSnyzsfATRd+/v1tdMx/bCYo1I7X+i 02Pg== X-Gm-Message-State: AOJu0YxJmIHQZ42z76ZHDstjsgVfUmindsPB2KylHzdpvcqIbzSPWTDQ ohygHfY0TSHX4Lj3AoqIdh+yeIP9mbTw5IGiu4cwGltdWHk0Y7yUE//C/0jYW4MUyXS+rAB3vu1 ZUeXVoP8ihuEoVvfMfzYOK6nlq1PIOHEdjUCHIAiVV4VDXSSwZNBOIr4OAGieANhfXlN220cPO0 p7VMVRemzkYLMqldeBWSCS65viNZLVQZB80U8g6ysKkBXszKVBjcl7QNIp X-Google-Smtp-Source: AGHT+IF8mHZFxowkJGrx83wri8IP0GWRoDPRyQHAkdVWFwQ+fv5skyg8lghAXu3kMcXnk8PDhmI/Og== X-Received: by 2002:a05:6a20:12c9:b0:1c0:e225:b11e with SMTP id adf61e73a8af0-1c407846c80mr2231878637.13.1721263697497; Wed, 17 Jul 2024 17:48:17 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-78e386d53e4sm5694300a12.70.2024.07.17.17.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 17:48:16 -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 , Albert Ou , Andy Chiu , Charlie Jenkins , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , Evan Green , Paul Walmsley , Thomas Gleixner , Xiao Wang Subject: [PATCH v3 3/3] riscv: Call riscv_user_isa_enable() only on the boot hart Date: Wed, 17 Jul 2024 17:47:56 -0700 Message-ID: <20240718004808.2246354-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240718004808.2246354-1-samuel.holland@sifive.com> References: <20240718004808.2246354-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-20240717_174818_883323_215EBAAC X-CRM114-Status: GOOD ( 14.24 ) 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. Reviewed-by: Andrew Jones Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland --- Changes in v3: - Drop use of __initdata due to conflicts with cpufeature.c refactoring Changes in v2: - Rebase on riscv/for-next arch/riscv/include/asm/cpufeature.h | 2 +- arch/riscv/kernel/cpufeature.c | 4 ++-- arch/riscv/kernel/smpboot.c | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 000796c2d0b1..7670792760b6 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 43fdae953379..517035356107 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -875,12 +875,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.