From patchwork Wed Aug 14 08:10: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: 13763032 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 AB4AFC531DC for ; Wed, 14 Aug 2024 08:11:38 +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=q6ToOoQ6j01rdoPRVVkX0NfS+LXPZmWjTkboqBG53iQ=; b=c4VkDOPA5DJnf2 PtDN1qwOqqB979mZxxz30MTDHFEOj8kQC9tQBALunKYHN27rBLurl73RqLnO58D3UGEla8Gts3ME9 3Lx3IoeXvsThtMmOoqhrVCg99y2tZEp35tUgUyX3Gb51JoZsmBGGNPPTeu1G32NgPhFtGop8s/wlU 3qYtqNZCH4SpQyS+iESm9MEJsQhaVSzHxnGpo7NDvw8gfweMZxPRVcSII8+Rp7T+wQJDM/6NZmYdD Cxxt1Uv+suvM6xfhMs2W/QeqcRSXB+GXyAj6W0uF+0kPUGxb7Oi3mqZvdJmZBueasB0RTlTkfVFVb TtDs7GZrNLean4H6WWBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1se96V-00000006BoH-3e9u; Wed, 14 Aug 2024 08:11:35 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se96S-00000006Bml-3pJX for linux-riscv@lists.infradead.org; Wed, 14 Aug 2024 08:11:34 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-710ec581999so3253172b3a.2 for ; Wed, 14 Aug 2024 01:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723623091; x=1724227891; 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=7aeJwSkJyEYhCArckd2TWKFlpkUc8ta4z33pmclBmZc=; b=Ikdr1Lvb0FVIbPAyi3St+hDn6QQuBPzYEaaAMwklRlgCy89QrHxFPrjPSktYCBpWV8 NnLuWl1A+UNS3JgFE3kb8oWjURyBjPGJKRzJ7S3HGCnEsgwqwEKPZZUo948kFWe6oj4C 2eHWY/bEXa/Te2KIxlVDMdIiAjFj8GjpFXqwWYCvcwxUv9PCcM2obcLckBVOrARKAHW1 qgnX3B17BBTaWRYKRaNgxoWQ1eUo5tDcjpx7fZHNGy5r9onYGU08clgpiDMzWuY6HcvF 2kogf+jrZ3cjjpSZGS/9q9i85o5BZWyLBs1tFhUdCKp7HXJC5H+R/7VaqGeL1Y6kwmcf oTIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723623091; x=1724227891; 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=7aeJwSkJyEYhCArckd2TWKFlpkUc8ta4z33pmclBmZc=; b=IjpVWq6IE4mU9oHj8TLQUdPm3V3PsmBGi8HrWX2CbPkueswh7hXJBEZSfm+rPGpXxB JAn06p7cuzgb6ZnO+L6BVGKN3v8g7y085TC7bNHFL0Tvvv3ywweJV96piIKEFucIAHjK Mhc0Ed0hoZv5cz5IiA1mBWcGY8lX7Ce22NwETgyV4uPYgGZ2Hsv6LUAsPZUE+TvZdgDt /hlykTBvat4q9Bn0ZXrmPQIJ6N0cExa9fnbupXxwIKVFRJmuRWBYHdtu38WnGK12YQew pvPgii6i1rLxauCOyp+g8OOAoOgqAv+PHxWmhiFQvg1tEujEvr9RWQH21os834s96iJy zv+A== X-Gm-Message-State: AOJu0YxgB17Gg+UZy2GFKYTEEArD6BU/0iLmMp6/SxPKpFyD10TkL3Ps Qa1gg0Dv0oIXWXTvVRzcixTpsqRNJ8b+iSYcd1Q6C3igtptUOGe//6u3YGYSBdLXkoC9tjBdauk dTfrfG17vYFjaI2Rxfgp42vsJnKBqMNn4iAC00oCVOK/owd0TrK661vJJ8gdCxkqTSxg/+pXpJ4 mD554zwHzNe23KWF/9OLn1NbzjPuD9aB5Sq8hXdBBax7xceESy6C9w22ob X-Google-Smtp-Source: AGHT+IHzz6k/y9eJBQjHqqaXxD/Ow2KDkmoZxQIFeBXhlwFgBTesdH1eA+S+4NnIpxaGBpdLmz+UBA== X-Received: by 2002:a05:6a20:c908:b0:1c4:7929:a593 with SMTP id adf61e73a8af0-1c8eae8dccemr2856680637.23.1723623091285; Wed, 14 Aug 2024 01:11:31 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd1a94d2sm24559955ad.127.2024.08.14.01.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:11:30 -0700 (PDT) From: Samuel Holland To: linux-riscv@lists.infradead.org, Palmer Dabbelt Subject: [PATCH v4 1/3] riscv: Enable cbo.zero only when all harts support Zicboz Date: Wed, 14 Aug 2024 01:10:54 -0700 Message-ID: <20240814081126.956287-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240814081126.956287-1-samuel.holland@sifive.com> References: <20240814081126.956287-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-20240814_011132_980279_61AEC508 X-CRM114-Status: GOOD ( 22.76 ) 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 , Charlie Jenkins , linux-kernel@vger.kernel.org, Conor Dooley , Samuel Holland , Conor Dooley , 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: Conor Dooley Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Charlie Jenkins Tested-by: Charlie Jenkins --- (no changes since v3) 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 b427188b28fc..0139d4ea8426 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -28,6 +28,8 @@ #define NUM_ALPHA_EXTS ('z' - 'a' + 1) +static bool any_cpu_has_zicboz; + unsigned long elf_hwcap __read_mostly; /* Host ISA bitmap */ @@ -98,6 +100,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; } @@ -918,8 +921,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 Wed Aug 14 08:10: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: 13763033 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 C1BB9C52D7F for ; Wed, 14 Aug 2024 08:11:40 +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=kfXUvmBj9fILdR06ojLWYJIDd2SI3qiUfQhQAyCpfVU=; b=0AtOFGS5EXJS9A VlOOX69hqLBjZf3mG3J2dU+SmluRrj8d9ccDj//uEl3UodEs1mQ//E9KHhMFSQpGso19GTWpEMFuU +m/fewxip9cNxpkk9w5EgbduJSc8wN0aZRtk3azSo5jFKY+F9cX7gM+4iDaVvbJaduRtJw4/SCGhU o2aGB/a1ExMTA558yKXmXHDFtPJuxTOcLHw+uDnpk/++OaoS1Qgs1CoxMEqHz/Aa4zSIbCFPdf7f2 YAuig4fq0d5GmmLSO9J2W3IAnW/N1vo+7VbbGwY/TwFys+w/6sN+gS+3eH/lqbm1W1T5I/roc5iCi 1QsmTX2X5yFP/soZ/p9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1se96Y-00000006BpH-0q7t; Wed, 14 Aug 2024 08:11:38 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se96U-00000006BnT-2TOi for linux-riscv@lists.infradead.org; Wed, 14 Aug 2024 08:11:36 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ff1cd07f56so53160935ad.2 for ; Wed, 14 Aug 2024 01:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723623093; x=1724227893; 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=ZPBDT7aylVUsHOeEB1LM43PupNXpIhM1dDweQwhBYlQ=; b=NwUbprPcIKqJibh7uiq0b1Al+m49eY6VPUhP2vwvlfWgm8tTZpTXopSFbVxig6NjYP RgRT1fDQlwDbiMykOt+4DINq1vPWftLVTYqIt5CaUSXEIR9mP5V1GfT7pJFm4wbzPRgn nFebMdtW0qOH2IIaSRBEDSzTtHdmK2FEM+CmJIE7D4U33rBrbnHHc8FGY72/TfPLUSXs 5Tc7ah8vD7J5QovN7Gz/r16jzrb/3Q5+UKDBAs2dTlrbzjFrUHuF6v4WbwJALmUHjVm8 AdX0FxQyxXfeifmfkbRs7/pW/JBswrnGpr62Ij5gDS20tcBWy0IZn9TVKzR3EQKiEzmE xytw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723623093; x=1724227893; 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=ZPBDT7aylVUsHOeEB1LM43PupNXpIhM1dDweQwhBYlQ=; b=mga0w4y1t+fKEKpV0nChnlYwWfczv/X+JgMLOjKmYRElfEptl58kBX53OgKUd/jPb6 qCm//oMzzgsLPqO4fsqqkXI3ZcH0uqLoNySpUrH8nX8DZ5kHRVd+fQITAU2dVM1vfsv2 cjvxp9htlYLeeGpNAeOH1aI4jhKB/GxhTQpoPTn3XA535O9mC/XIjZdfAsXPkO1Uvxw/ jOp7bwMF9uFUEKvoDQX0WRyhT6GIOyQ+lJLWMFnh28LOOOOGo0x4R7KIQWDOUpl1iYrw 0zpDICDCMtJ7pxQk0RebDeGt1kpADZ73ATfGMnS2Wrk0uc9Yy+2h6xEZxiGODbiSTUiT 5wVg== X-Gm-Message-State: AOJu0YzIf8FCqkWCrHhBqvTw9QUt3vX9JyzQ96hTwFso0oRfaUh885b9 CV3KgDESxfO3x3hCgHDRHQYpKk35EPBzuf+3E2cncEH/dzGa+vTuVIt8VkM3MppBBh6S0meXyEp tRFZPSPFCEp24eHvUONLfJe4qxvPB8Z44AHAn6gw8zauAuEbpB39i1+1xD3qFYVXDebm0rEApbP EYSk03UDmxKsiFahx6L+zdEM2NXj1TRUqRjfBSgREa/jBW12tCxi0jxdni X-Google-Smtp-Source: AGHT+IEqqh03VoThtjgWPQLBrpFrEOpKeAi4wVz6y0BwfWNUlOLSmFDsplnBip1l0vDTl8VOYklDcQ== X-Received: by 2002:a17:902:ec8c:b0:201:daee:6fae with SMTP id d9443c01a7336-201daee71b6mr9353495ad.48.1723623093101; Wed, 14 Aug 2024 01:11:33 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd1a94d2sm24559955ad.127.2024.08.14.01.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:11:32 -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 v4 2/3] riscv: Add support for per-thread envcfg CSR values Date: Wed, 14 Aug 2024 01:10:55 -0700 Message-ID: <20240814081126.956287-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240814081126.956287-1-samuel.holland@sifive.com> References: <20240814081126.956287-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-20240814_011134_688621_5EC14B43 X-CRM114-Status: GOOD ( 16.10 ) 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 0139d4ea8426..df3e7e8d6d78 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -922,7 +922,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 Wed Aug 14 08:10: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: 13763034 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 92EF2C3DA4A for ; Wed, 14 Aug 2024 08:11:42 +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=k//hY7F3Kl9u7Y/OiIUSNHDzv7oKQsnO2DXv5Fv/F3k=; b=T60k8lAreZVYGe BWN9e3aDv5NOb+wSwuHa1FaubdtsGiqlLo02RneRxpd39nYFbtCx5mGhd8FGUMQQl7hoOFAyqbzy/ 5dhYx8Xc+AUEhuhsb8sA4G13I2ecgqdKnwKOSFDuw+jb8QGw5iMGhQz/tB0jc6Eor8rf1SA41QMMX hO5t6Aa+zLXZKQOuzo0WeRy9cjtI4cwvFa4g4VgskiuThsNkNwZr7xDti0ztTL58TtuKqSQB3s1x3 YgzYGeYLZMESGfA84FcCvhivqLlFKvxLJL8IRMqpgyqeKXAvIFLuPYdtlr9QqMruT4sENh/y95Y5G yqahRgxnhlNMQ9DtaQ8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1se96a-00000006BqU-0U7y; Wed, 14 Aug 2024 08:11:40 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se96W-00000006BoE-1SvR for linux-riscv@lists.infradead.org; Wed, 14 Aug 2024 08:11:38 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7104f93a20eso5313781b3a.1 for ; Wed, 14 Aug 2024 01:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723623095; x=1724227895; 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=HRg7k8b1pNHrGkCawN5XlEnE++zRqhFin8UtxZvnPiA=; b=XQgU0iZFDjbZtOH4a0Hcg+B7dnMIqVHG8DF4o+PgWS2DhzIY1M2S6CWYXvnSJ5irJc T9DwFXHaNtKlYA7V8wdlzrQASIAF7z504zeZr7jG8lKBd0SGymTmD0tG50y/lTH1S9l+ Pej9D8Nez6JHCPIKFXBYO+xNNts8HkZAGqQMkCmQXd4DaIfpu7jztNqId519BmQUwluw Q5tUzFmwzIvkCwMU8EYBIsUWJ6ZYekDJBFy2RcxGsy+X2Q/wZbzoc5V2SI8rQc8McWgH Vtw/tcENWE8fVVtDrZuwRZT2G3DCnhjQeGBav1ZRVTMkCtNy0i1ZWw+X60DX6WTeEjrj 9PUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723623095; x=1724227895; 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=HRg7k8b1pNHrGkCawN5XlEnE++zRqhFin8UtxZvnPiA=; b=gg5T8kbLxp6/lJCH/jlH8Ahk8pieHSC6Z2rrIyrVflXaGQZNsOVz0KS+lqjQ0gog5i JDkjGPjEgoxM76MTr1ow3GoomNfe0Is1WPwbO6737omS1+vn0/NyWZPufUy8jYYaMJf6 zt9UOZkML3haEuXsQp00yJCRaVMiK2pVX/8YOcgU7vE+7IELmK7bLlBsESBF6aEGJdKn FeyQ4w4acXF5BY1yB5D0iRTul8n/61xV3KIaQZqFQ1bJ8zJ3Y9LpuUBzIvfzE9dWtS7p +UZnZcB7JN3p6Tnkmx6H+3MNQQwFBBKGXQdYsaIDcqKrJNYmZ4jDuIEbZCmeyANWg9xZ mXqw== X-Gm-Message-State: AOJu0YyNBm+t7baw72NFkmWTY2XSjF+k5a7+g2y6TOnkJ6Xliny4XJQW M5PH7yuBvDiqbZQDQkcNOb+xEArI3p1g8v4JeiEQTGhsS/R9JB9T9SgQHwBVbIeOh+47n5MRauw kwF2QLprPI0/JsDaXL3cBk1UIajfB7izTYehSxr8etlIwDZnFzi8bDVwUIm04c+AzAFF2nJnKmW 5htVyWEDWiEcmB6MGs4jDgq8ViMw+FBQv5oqvlDa7StprrY7m2WkVOljV5 X-Google-Smtp-Source: AGHT+IH0hIuDifGPsQ/ifvUQj74P9NaxskpxaUYin4TYlEuYI0bGgoYZnDTa7sdcogfJRcGcPQNb/Q== X-Received: by 2002:a05:6a20:8b1a:b0:1c8:eb6e:5817 with SMTP id adf61e73a8af0-1c8eb6e5864mr1613115637.5.1723623095015; Wed, 14 Aug 2024 01:11:35 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd1a94d2sm24559955ad.127.2024.08.14.01.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:11:34 -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 , Conor Dooley , Albert Ou , Andy Chiu , Charlie Jenkins , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Evan Green , Paul Walmsley , Thomas Gleixner , Xiao Wang , Zhao Ke Subject: [PATCH v4 3/3] riscv: Call riscv_user_isa_enable() only on the boot hart Date: Wed, 14 Aug 2024 01:10:56 -0700 Message-ID: <20240814081126.956287-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240814081126.956287-1-samuel.holland@sifive.com> References: <20240814081126.956287-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-20240814_011136_539698_4E9A19FF X-CRM114-Status: GOOD ( 14.68 ) 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: Conor Dooley Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Charlie Jenkins --- Changes in v4: - Rebase on riscv/for-next (v6.11-rc) - Add Conor's Reviewed-by tags from v2 (missed in v3) 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 45f9c1171a48..ce9a995730c1 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); #define _RISCV_ISA_EXT_DATA(_name, _id, _subset_exts, _subset_exts_size, _validate) { \ .name = #_name, \ diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index df3e7e8d6d78..b3b9735cb19a 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -919,12 +919,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 0f8f1c95ac38..e36d20205bd7 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -233,8 +233,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.