From nobody Thu Feb 12 23:04:44 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45EA915F41F for ; Wed, 5 Jun 2024 20:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717621024; cv=none; b=bFfT72hz8axh2eIn+vTzlL8oxnWmBE4z90SwZFehU7Hc5YjtVXYBOsSUgIcwZ/512vKDs7kE+Fm3zMm/2xNr1nLUiBnYRAoDHqiZDfrQoGqXCs0YuGBK7CneAwCAmjHT/KHD9wrW9q8Pgob6nsyXGLW7SpqQBh2zY5VVhSta2Aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717621024; c=relaxed/simple; bh=UwGdShtt55ngYaoblk5KGQivCkS0QFEToBpGh5fXpGc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l3wqiLK5zn9WC7spenJn8lxX7K3zuqWF3ABR25bvui+pg+++xvukKpHQFlaprNKS0sWHmxflIwfIb+sYt2YvutmIVhbKIUJI/M/xJ6Dwmj3lwd6P1bM/mNA4o9B8QKH32kDPY3Nw1kgYYBf9D1h+GED2p1QWJURIRyieMAuJlH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=Tbbq1xIT; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Tbbq1xIT" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f6ad2e2f5bso2745075ad.2 for ; Wed, 05 Jun 2024 13:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1717621022; x=1718225822; darn=vger.kernel.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=M2bVegCzCkDHXMVMeg8qYCHprvPezD5elt/KHLJxQVU=; b=Tbbq1xITkX1A7ONtD6L1XvJeVLzvf/2Y/5wRvdCzazIkhvFGc2plFjGYOo5wVErEJU VnRuU/dIXk7xOG9H0pZftxvsnObCe6YXzW1tek+qD59PsaKxzvgvI/RonX0s+TkeHLVM nya8lkqZBl2p9FcM3ibrsakb1GL8UJY9vstETAE2gvrngD18UaFYSOoFC/aFf0vL3dd4 g3GSoY6QoXTBg7Kh0cl72ZMJAx7mVM1Rc33Zba4vIgxB0Xc75c119VBdy3uedz0rMq23 nFTIDbhgOUVFyf+5/Vu5ekRRZS4RCOcOC5UBNhTZQUvxqDnMbjeNtLDwdCsHnsvSOHt6 s0Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717621022; x=1718225822; 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=M2bVegCzCkDHXMVMeg8qYCHprvPezD5elt/KHLJxQVU=; b=OVx5Lz1pMaJNBWBAl+I4atJLaqsRfW8pbrZO6OGteE7yr8mjE9dWYxMDurgUKZMZ2V /akgSEUeF8T0HoyDr6Xg8YHCDcAqJgxzDtLMh8ajJQjIW37qdOG/ZxiSPEyXdPjzEssQ Id6m+45SrTp/uQvv3WrYWoAUYRI9gnGZkCdFmPbpRDyHVrnDvynu2X4dLhC4TJowBy/7 dDmYCefemqqDM9EXbOrsL9UZYSwbNBlU7Z7k3PnHbbliasfbwAyASROdMDpf4EGsWl2c wWZ5OdlY0ZG/zV9rfwThnZBgebRqoKVG3pwOiColxX0bBOXPEHxLKAg9/mqsFL1NhhV1 rdng== X-Forwarded-Encrypted: i=1; AJvYcCWFI3vHzvMicEc3KLYNVBDKxqfeyf8MjrNOCQMwKvdKswOi+fwa9WAtpenZpYJHeWYUn7L6MhC2sS9z0l9w/YSEuRq+MJKh9rchHxY3 X-Gm-Message-State: AOJu0Yw6I3vPvkWX+ftQoGb7BFwEyd0ZQV39S6ozTQ8RVBIVhSkqIjtK AgC0srNIy5aH8So6R1sALr/mQK24OoQFo7ZjsUcZfStaeCbloN0Q9E3HvKkrdOY= X-Google-Smtp-Source: AGHT+IEMiuzcom7/QujTrzZBUVPvtMGj/7csXw9/xKWBGQkukRtCW8OVo9AbXr0Dsd33zcb6XPLvdA== X-Received: by 2002:a17:902:f684:b0:1f6:6ad1:fdf9 with SMTP id d9443c01a7336-1f6a5a84d6cmr39536575ad.57.1717621021640; Wed, 05 Jun 2024 13:57:01 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323dd86esm107332135ad.121.2024.06.05.13.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:57:01 -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 1/3] riscv: Enable cbo.zero only when all harts support Zicboz Date: Wed, 5 Jun 2024 13:56:45 -0700 Message-ID: <20240605205658.184399-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240605205658.184399-1-samuel.holland@sifive.com> References: <20240605205658.184399-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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] Signed-off-by: Samuel Holland Reviewed-By: Deepak Gupta --- 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 5ef48cb20ee1..2879e26dbcd8 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -27,6 +27,8 @@ =20 #define NUM_ALPHA_EXTS ('z' - 'a' + 1) =20 +static bool any_cpu_has_zicboz; + unsigned long elf_hwcap __read_mostly; =20 /* 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 =3D true; return true; case RISCV_ISA_EXT_INVALID: return false; @@ -724,8 +727,10 @@ unsigned long riscv_get_elf_hwcap(void) =20 void riscv_user_isa_enable(void) { - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZI= CBOZ)) + 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"); } =20 #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 @@ =20 void suspend_save_csrs(struct suspend_context *context) { - if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XL= INUXENVCFG)) + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG)) context->envcfg =3D csr_read(CSR_ENVCFG); context->tvec =3D csr_read(CSR_TVEC); context->ie =3D 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_XL= INUXENVCFG)) + 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); --=20 2.44.1 From nobody Thu Feb 12 23:04:44 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7E7815F304 for ; Wed, 5 Jun 2024 20:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717621025; cv=none; b=BVQwG9vprJuDUFVC3kFt7NoK5Npul0ihef/te+1OxX8xYx5b0WfzBqKph8OE7Ppb7a9Xk4UPxA+gCoiiapq0Fxqru+HyYsP9olnkNqMuPHnLHRY356UWcMShuY3FxXRv6gt5TA8alC84Ea+MLpE9LkiIJDuvu9fz2yDkvpJ8OZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717621025; c=relaxed/simple; bh=mG512uQGDJDRQSetHea6N15e1/E0RyLER/3LVj9tvKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eiqRDO2A91tsUc1mEE8JXG9uov9uIp9cgzJoHW+0U9hLsXcAclM+/9T8juRZdgFOL04s1FA7+fKKqzBkQBOf5Ap/QEaVwkqxwMSA9b07+fIlQVepYKGa0rl482ODai1W2pIPeRd7Yj9nKnaArnvpS7D+VSenHKaWLqX+UQnWZCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=RQrgwp5e; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="RQrgwp5e" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f4a5344ec7so1506065ad.1 for ; Wed, 05 Jun 2024 13:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1717621023; x=1718225823; darn=vger.kernel.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=3r1mxtMIe36MczsOX0LoCkPpmMGMczt9refp0xJPcqI=; b=RQrgwp5ewpAQLstIZ0JznsxEMCcChoEV2o1G5I3PuyyflVWfJF7BQSWOJ6m643WXmH V9D9xDct0DNXvP7NNGsylGUt3bJjFo9jKHf/iY3CUPKcpOr0oRtHyYYA6CdOq208XygF 5fzDkaB9jotoSVcrS2smx7Y9iqYrafkM8xDI6OJLuIwKI0jM8F69wCeasRZYaKqQuVwl 30FQDufNwosimaaMoBA1TgqD4Qxy3ZkrCSCpCbr3QnLBSY6arR6VfJEsq6TH8xUUCUBb WPwtFhpoGWa+K2UjE+9SghfTT5oOO4k/0kqy1RbNEPbLiemqNQ80DdpTDFaOzdice3cS pdPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717621023; x=1718225823; 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=3r1mxtMIe36MczsOX0LoCkPpmMGMczt9refp0xJPcqI=; b=CzQkX7GGjePrrCdXCftNTOhQDad5CR6is+toz4NvXH9exBAcdsy0m3XPdrr5/S31Xc W3H2mavUYMrfNWXPKuPvn6WHfEDI4hCInFDW8pzFD4wu9rw7ywYGNjIqrMcdYAC9afwW mp9mq1NGIuPH31lMq0OApB+Ek7FuGahxICRrwjMLUANx0SqNtyjwhKeyZCc7aXUz8CnM HvtMl682/81xd2zk3D122hCkGFfE4YgqjViOR/wdGHbWaAdpF5sYliUlRX4JrvohNa9o CzRsECerc/m1To4QQHV8snlv+Dlp/fbwK8fEd9lPe/Y8Ikp0dyISF8zqDAMjeSsgU5Ky KAaQ== X-Forwarded-Encrypted: i=1; AJvYcCWoJxkI6vhBStZP3EovuOKKTUuapxXh1tN/d41rqSNcB4NWN91hnzmLoLxucvQawLxhHDkt0eycTGxA80V2MQi1wSnyvre9BWGuRU/+ X-Gm-Message-State: AOJu0Yyzx1XGichpYR3OEzAsJtkDUsOlQUJGri8doAiOVuXmO7oDNJHC ChFlZXVh/ANoq97WYpaCwDW62zaHSkobkVrl/FcwZpboEJ5f1CXtToyHrCOaQa8= X-Google-Smtp-Source: AGHT+IGYEMlz2TI2K028q2R9LiSsS1U83s3xkaZ3dDH4PwwxuERT+O3HCrcKeci9losqt5I2efFSAQ== X-Received: by 2002:a17:902:dac9:b0:1f4:808e:9f6e with SMTP id d9443c01a7336-1f6b8ee5023mr9974405ad.21.1717621022907; Wed, 05 Jun 2024 13:57:02 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323dd86esm107332135ad.121.2024.06.05.13.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:57:02 -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 2/3] riscv: Add support for per-thread envcfg CSR values Date: Wed, 5 Jun 2024 13:56:46 -0700 Message-ID: <20240605205658.184399-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240605205658.184399-1-samuel.holland@sifive.com> References: <20240605205658.184399-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Samuel Holland Reviewed-By: Deepak Gupta --- 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/pr= ocessor.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/sw= itch_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 =20 +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 *); =20 @@ -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) =3D __switch_to(__prev, __next)); \ } while (0) =20 diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 2879e26dbcd8..1153b96346ae 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -728,7 +728,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 |=3D ENVCFG_CBZE; else if (any_cpu_has_zicboz) pr_warn_once("Zicboz disabled as it is unavailable on some harts\n"); } --=20 2.44.1 From nobody Thu Feb 12 23:04:44 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E75E15FA75 for ; Wed, 5 Jun 2024 20:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717621026; cv=none; b=n5UUw23FoXxfz53c3AcN+rF4IEBjnU3sewgZTYC5dn+iNj+HUu+8fbz2rOXZKTaf/EbZH1FLbEIIxWpDv6qFbGMUlUWRKKsFlNnSHZREtro1QBh1FdF37vIu9n+IUHraEshB4JufzF7n8m8bCb8HsDUQwAx+D8t05OSWSSWpetM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717621026; c=relaxed/simple; bh=qDj+MgB0zc+Q81L2PsjZdeWfozqjI0P+THgHibhhnXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k+QhaWSN1RdzwTwzK8s3xo3VBgZJQYprS48DcTHPQCJnquSAQqAgpYzZL9oBYvH3raQdQqDtHmasEF36CKUgOdJM/A3qzYlWHf0uQtDjsswDHCs83hxag/AoXn9MvkrNUCFzWg1PTO+hczzR3NX4dZJ0K7JbNkSZAv8JBd6JCW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=ZeAjMAag; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="ZeAjMAag" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f44b42e9a6so2917305ad.0 for ; Wed, 05 Jun 2024 13:57:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1717621024; x=1718225824; darn=vger.kernel.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=Uty7FoscHz4fIjCNzqhW6L2ro7Xc7g0lgY7rTZohcbw=; b=ZeAjMAagdhUnjkEXu2C9MfIQS5yy0/WHWFEQIppso4Cy7xcdYOCyUVxGWdtZzlQ6Nw cBaao6nSPB0q+IiQmI3szsNAWD99mdogB0eQRoQZGpGWHFe6C7rNgM0uNsiADXopH2wO RmBQWqJnh/YrFwtFxTo2tqQjYRN/su7hQE98L+5luJj4muf8VmoswPQT45+znjdH5+oY vPpvkjHg7fOBgc5B28uTGzGYov7W3wDQvgHVWbocbZJdVwPDxfvVKwjW219BMN4C36pS EPK8DMJ8XZgGfHdySGKUZh4E6tJXHOV2sQhqbAyRuxJckffussCh5CdpYT9j+qMCuu1h 9pMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717621024; x=1718225824; 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=Uty7FoscHz4fIjCNzqhW6L2ro7Xc7g0lgY7rTZohcbw=; b=lUn5WaezcYV7ZcgV1W26MUWFfe5OvQiZ+p6bOHAnKGYS5XZX+2Xk6ICToLcOoBrENb DMF6it8Oj75qywzAsgi4fcTLJ1bI8HqJrApjS7tJ9s9JouPSJRa1ccnMHnBoSVHnMB7F bwGfV5swWcFN4p1mlJoGUWC1ajm1+Ap9suIMfT2adMkVH10WPIRsCf8bmgTvS6P0HBHz movNO2lfbCII1ELdXXT+OIWPW5utmNCb00ug4WJQT7UJIgvcwC6k9aMdtBIf4DxEM+l3 86/2j887M0drEkZXgU3MPuRZ2yyvbs2CqcEJKeE2aruF7pg6dd2ScRUNTpj+AIi8mPBE wZFw== X-Forwarded-Encrypted: i=1; AJvYcCXnq+Wz4lNBZAIw8M+QRnHbAZrN23SX1r9BOP032lfxd8a5891IBW7ni5EpyD3c2fABSS7egCpOuC2TS04WTGnwB6+eHVvTMCASMDyf X-Gm-Message-State: AOJu0Yz4xXZ+v+eLONP1JQrkfPXkcCiO3xshL78zLGiCMDGSp4bomRC3 0pDgzSN827Szwvmnac1V5gEDKrmIyqloUz1ecl+Z5dtIauO3rfKjskwVhDJ1ZqU= X-Google-Smtp-Source: AGHT+IFKrVvHD0aCZ85QY1knnJIWvkOUtWAJ3vKHRJSp/gSnF42JTtt2tr6r7NWF/3DXkYV7sTZKtA== X-Received: by 2002:a17:903:1c2:b0:1f4:b2ce:8dbe with SMTP id d9443c01a7336-1f6a590400dmr43547455ad.9.1717621024293; Wed, 05 Jun 2024 13:57:04 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323dd86esm107332135ad.121.2024.06.05.13.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:57:03 -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 3/3] riscv: Call riscv_user_isa_enable() only on the boot hart Date: Wed, 5 Jun 2024 13:56:47 -0700 Message-ID: <20240605205658.184399-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240605205658.184399-1-samuel.holland@sifive.com> References: <20240605205658.184399-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Samuel Holland Reviewed-By: Deepak Gupta --- 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/c= pufeature.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]; =20 -void riscv_user_isa_enable(void); +void __init riscv_user_isa_enable(void); =20 #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 1153b96346ae..bfe8550c0aae 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -27,7 +27,7 @@ =20 #define NUM_ALPHA_EXTS ('z' - 'a' + 1) =20 -static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicboz __initdata; =20 unsigned long elf_hwcap __read_mostly; =20 @@ -74,7 +74,7 @@ bool __riscv_isa_extension_available(const unsigned long = *isa_bitmap, unsigned i } EXPORT_SYMBOL_GPL(__riscv_isa_extension_available); =20 -static bool riscv_isa_extension_check(int id) +static bool __init riscv_isa_extension_check(int id) { switch (id) { case RISCV_ISA_EXT_ZICBOM: @@ -725,12 +725,12 @@ unsigned long riscv_get_elf_hwcap(void) return hwcap; } =20 -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 |=3D 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"); } =20 #ifdef CONFIG_RISCV_ALTERNATIVE diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 1319b29ce3b5..3e8ece31c30d 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -231,8 +231,6 @@ asmlinkage __visible void smp_callin(void) elf_hwcap &=3D ~COMPAT_HWCAP_ISA_V; } =20 - 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. --=20 2.44.1