From nobody Thu Feb 12 09:31:22 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 A6CF0145FFD for ; Thu, 13 Jun 2024 17:14:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718298893; cv=none; b=TPSETF41PHpBfFBSu4/nMYNK/Q+Eg5UE8zUZLdYsNdVd65Uc5cCPXWcq8dYKsqFdWCXxML0NzgVU+XrnN9b68ITi4nHmEbyON8/xZdcmKLti54raZK0hG3vOpwsvgdS0FYoF7CvfOROvBzfmfB3Rtl6M8GR8IKAPLQdfMxhmAtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718298893; c=relaxed/simple; bh=u3vd/ly9zjF+WctuwxHgm2L54X7Zhgk7u+s6+h7VaEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D3PTDGr2Kr5Cz+39yx9op6ZvHF4bRVPgurgaG78HU1TMHkZG89PCfL/7yG/EPPqD9gitiYhsVnBFBxaT7UMNoB+1EhXwxy+u7FpxgZIhzPUZWznlxppccS3fVqQSlu/4c/x1i6GKkgTrZF2cxTcvltZ1qaUKzF5L9ucTq7MRTwk= 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=ZxXTW7t4; arc=none smtp.client-ip=209.85.214.171 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="ZxXTW7t4" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f480624d0dso10913835ad.1 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=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=nWKKc9/VVGODzNuhTkLxFLmhIceztWrJoblOszvDngE=; b=ZxXTW7t4PGcZGI/W4t2dnXvBncBIEJFOzRLuJUOEv4fQpRE4loEJvgwo1D9UyL5I5/ lym8RlluTRsGLSoCwp/8UPlxUSL0AbozGpOSsoTjrfUE5hR1xRJ6Gg8SjM0DsoXbzFXZ Si5RGaAUGeBysv+yO/z1pe9EaFVPQ+5J5Xsi0hu8pOA2nzbXHxJoXgFQeUNdfVJlimbW PSrOwxLpYoGn6/9HI1Cx/qQCM5eP0c7VqeCc4EEkw45JpkZRgTkxjURVnesg+Z9oMRAT fVB0IqaqsdAkMJ3ze3chTJuD60V703L6RUvJ4E1Nid/RGedgKqNc1DPU8Sf++u5j/9rX HMhQ== 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=BuTGD7UFisrDAm2m3hzBPRy/WYXuN6fYl3w/fq0gDiN7n3zntjoXdsgs75TekM6OY5 2xQ6F3ObJsxS4xP1D7uqGXzuHxCn+66eQ3zImfXen9BMD9lTY0p+Qp9K9AfOpU/RgRS4 UoIM47LxRrgVj4tjaE9g4tt1xYI6DhTM7mrpxaW9IRvQRTAlqxzo/FqtRJwPjM5Uk8Lg mDc/O0PW8+v9nFpBg6dagUhG0pILg3rVLwsWmsOjcAtL9MF9Ek503hg/EjNYc0sLXBaf ZfBSi9hQREPAqKyzA8NMEaMCJweIgZgqjCRSdJMSXt7yoLgUhUEfF04v88Fq/CCJjujy UZWg== X-Forwarded-Encrypted: i=1; AJvYcCVcBeOcvmiAuEv1ycZsoAaZASPxCzouIbxbvKYyfWqWM9zXfsH5OOnBQldBZu37DA4MW1EfbgDbORk50ILe48l4WPshMBIhFK9sckFP X-Gm-Message-State: AOJu0YxhpZYUu7QP7BmuAdyKlA6bNTaYeGr5zN85WYfvoEbfsQCWsjUw F+DIPIOw61AlzJeazX7k2Nqi0Je9ZXRx898maWRBmnN4b3yzBzAKePWJhg4I7Gs= 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> 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] Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Andrew Jones 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 @@ =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; @@ -768,8 +771,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 09:31:22 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 E71D514A088 for ; Thu, 13 Jun 2024 17:14:52 +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=1718298894; cv=none; b=EK1JxLY42KobgvenTI9K6rB73d4IcrN3kDvREjt0PbSE6onpb2gF+E9SC67A/FYcjdJIzl40QSgaJS2JuffsqDaF4dUWR9HnqlMhUlrAl5olMqh+6jk4/7cMUIaINrOPfqm/SWFTUlJsRewsMFPZ/9q+sg75GZhQJRNL77k9Ynw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718298894; c=relaxed/simple; bh=ikUn9j7um+1PRt+XL0P1n+5KyCeKJKPW6ebX3/KMFFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4bX/EGUlrkRL1y5GmALMBW778xtlXraZfdExtTOiT5OaN/1fojxVW65I9mwt6jdBMwmpMvU7QTOWDJPH5NZVs/X8MM0PWy2oM03fVPJlKyj3k+wE5QPS77qCGbkHsC37eDqmlPFtiXeyDpIG14w2liEyj87keZLXUPatFQGa8k= 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=jM5Eyj1x; 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="jM5Eyj1x" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f6f38b1ab0so10582565ad.1 for ; Thu, 13 Jun 2024 10:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1718298892; x=1718903692; 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=aV8R4Wka+kWZfjkzpKS7OzxP5uBoNS2Fqf1rx+C8LXA=; b=jM5Eyj1x9kysN/eL2WCOQ1qiVAtBMZcC45qC3lP7BTYkY0Ohuga6CPr/0qFyWK5Pk8 wZJxW+iNnDzb3aWP4Vr8sCYDmGM3ZeWCjEYchQq/UDczrJEzcEkAxbLeMul8VsQhgy+I Y8oWxbTWmzwWhaI5dm0prJ6aUjZo+ByycMi5tmYWjpoXb3vWhkgJnwbvma37nFxsdiWO ixk8NUqoirf4NSi3tfnDtnWKvME0+obebDEDPfqmKEFeuFyWNb3BEmRh0a/a/yZdIAS4 ur1LegVabmg/1DTt8x9/6Z/MdaqxlTcZU9aW/K0Xb233X47STIit+LHnA4y7CNfX/J+h 8ueg== 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=WucOFfKc8QUDoq1aRrSce8XaEiPHTIIt4XX2+NACng5Xi/hg0BgzI5icyEnBpaBAgi 5DRvph8TRKrjpsw1a8MEbgXrsE0g8UCIYYkEHeUg+D0oURIev2TN36vpW3TfHfr3vt7C aghXsYEuUJEu05gL+tyKP+IE1qjl/ut+3ZA0AjvNuwuIaD1eqBuF/oKC1SJN/p/5iLAl TxRp30b3xeQmIavdngBNgg7fhNdUBN7gCREOjWcbZpevtrl9I+DAxfZqrKhQtL8S5uMO Z9X09zKD84tIXlelf2jSWnobAm8+j28WIZqyvrKpetM8KgafRxhY9UO6H/QfaZs2Zini t4Ig== X-Forwarded-Encrypted: i=1; AJvYcCV+cQ8eiYjfO8TK5vsl3egU51yR5tFC1lQsTImKkI0Oe4SvqTEVKB1vLmrqaMy1eJoiQkGyHLEy/ZuPkET/G39gsVXPYVxCV2QJSR7d X-Gm-Message-State: AOJu0YyBXAlg+DRim8lU0/hIT1FRzLV4Y8Qagv9FT4EHrT6CS3q5KKwm t6UEOGEGd5kZVig/2wuV81M4Znf8QwMi5Q2GqIqk+zLeZgajY5mulaszRTqyRUylUEQbY+2Psay O 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> 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. Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Andrew Jones --- (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/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 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 |=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 09:31:22 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 715CC14A4C0 for ; Thu, 13 Jun 2024 17:14:54 +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=1718298895; cv=none; b=gfpb9g0P5/Tur4hzlMBeBg5pZ0M9g8CRAyOhmfCHSVDYXyLjTDySd9rq54jpSloihf+91kRKbSTxKdXOY7a3H0GoLe76CVADdPOJBMG8u47+ulICF5AzVmpicv9OlObazP02Hj/pYod+SVobaW9EYeXVRsWpte45TAYZhdeFSu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718298895; c=relaxed/simple; bh=raO8BlRYfCkKG8Wn/ddo0lHN1cbPvlB7ACCuaxzdsVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CmpcBXAK/t2ZOnKIrzYG6xjWk95xK8CbKjbmeGDD64VnjyYQBlklXdXCl/QXllnUUmdd2e83iSgFkfgTkdLchStvZwLdZLjsTg9NHGcQ0V4csP7Q3KmjXmCVe58MkP+K0lJpvjS0XyXlCDbSFWKLWce2iOzzHhv1uHSoa7cNg9Q= 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=UHI8EtTE; 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="UHI8EtTE" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f4c7b022f8so12298805ad.1 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=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=PiB/UuEMeERuvvonGAvIVsUp7Uk/id7nJUnnnQyTCfs=; b=UHI8EtTE8QsXdYRJBhZngLXFmqn0wx6AynccIqU0oE6ro4c3oXsShnju2/Mt2mj+YX 0+rU7dSehhPW1vJxr9hdaecydIRzVH1IEA8M2wd4hHWoc94bmrkEwlWIAB6kUWOuKLCU JDrwI2jcuHLIhRfy1ruuvD9fM0O1dGAiH/fvZXwKoFTfhHl0e9zMwsWMeUpu+JivaKeu /h/o+KgtvXcZTeYU3cBgUO/DTZWqdHIwjquEkZ6/j1GQ3T5KtO5DWHuEoggq9ofv38/T CQ/rVqN8ujniSXqYaGKFHaY3z/yf72JHM6kK4ebw8miSs/8rn9sE4GBbsfV/nGg/jDDw Adag== 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=iUyxGs+bpcnGPU1Zm2NnBdvLlKHg7DzU6dzt/GbFlBlCpu/soNKqlFFjTWh54XTIYW 96V/ApeTnY964Aw4+R7oHqs7L/bSke/Pr7YcJCKAvEbL4fzA41Up7BVaI8bZG07C7hIF qnisMUgwVpdhycJgIjxqkTgnK5X8RZfkNtlCIAczQ9rlNnd8uzbj5M2F3XvFcHoQfyUQ S78UW0j2izI+2x06n5f4evn2JpLZ+0yRGMRKBwkiDNPT0lUjPj8i02I5G7359rkYXKnS XF3ShDK5R3Lv+MGe1nY8Ih47CzTzBLKvyAtySjkoRie5rT/YSSyJ0D4LZq/gpEAi+Ss+ ec1g== X-Forwarded-Encrypted: i=1; AJvYcCWcYdK4esjxdJcx2l/B/aOU/p6xaZpwCZNks5A7b6lldVAufN23X0xNN+JKL/yG/ZVxlmoXOVMMNHMwA7BWUlJ6hEEuPmT1Rqdmci+8 X-Gm-Message-State: AOJu0Yy0hTuxiv7HWf9rfju3k293i2JIuTfDS0AiAIdnScoRMGknyMkC zjo9OQnh78zGWSjUL4elVwL7vQHSCLMMZpbQoCxxIiIFV9mQGT14q/LFtiDOVhA= 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> 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. Reviewed-by: Deepak Gupta Signed-off-by: Samuel Holland Reviewed-by: Andrew Jones --- 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/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 b5b8773c57e8..d3e3a865b874 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: @@ -769,12 +769,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 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); =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