From: Ada Couprie Diaz <ada.coupriediaz@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
Marc Zyngier <maz@kernel.org>, Barry Song <baohua@kernel.org>,
Vladimir Murzin <vladimir.murzin@arm.com>,
Arnd Bergmann <arnd@arndb.de>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Shanker Donthineni <sdonthineni@nvidia.com>,
Vikram Sethi <vsethi@nvidia.com>,
Oliver Upton <oupton@kernel.org>,
James Morse <james.morse@arm.com>,
Andre Przywara <andre.przywara@arm.com>,
Tejun Heo <tj@kernel.org>, Lucas Wei <lucaswei@google.com>,
Will Deacon <will@kernel.org>
Subject: [PATCH 2/6] arm64: insn: make `aarch64_insn_gen_d{m,s}b()` alternative-safe
Date: Mon, 28 Sep 2026 14:30:30 +0100 [thread overview]
Message-ID: <20260928133034.243541-3-ada.coupriediaz@arm.com> (raw)
In-Reply-To: <20260928133034.243541-1-ada.coupriediaz@arm.com>
Move `aarch64_insn_gen_d{m,s}b()` and `__get_barrier_crm_val()`
to `insn.h` and mark them `__always_inline`.
Replace the error print by a build-time check now that the compiler can
verify all call sites.
This is possible thanks to all enum types being covered in the previous
commit, and the only current caller being BPF with static arguments.
As all functions are now inlined and do not call any instrumentable
function, they are now safe to call in alternative callbacks.
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
arch/arm64/include/asm/insn.h | 56 +++++++++++++++++++++++++++++++++--
arch/arm64/lib/insn.c | 52 --------------------------------
2 files changed, 54 insertions(+), 54 deletions(-)
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index 8ec9d86cc575c..40f13d28a5fd7 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -7,6 +7,7 @@
*/
#ifndef __ASM_INSN_H
#define __ASM_INSN_H
+#include <linux/bits.h>
#include <linux/build_bug.h>
#include <linux/types.h>
@@ -699,8 +700,59 @@ u32 aarch64_insn_gen_cas(enum aarch64_insn_register result,
enum aarch64_insn_register value,
enum aarch64_insn_size_type size,
enum aarch64_insn_mem_order_type order);
-u32 aarch64_insn_gen_dmb(enum aarch64_insn_mb_type type);
-u32 aarch64_insn_gen_dsb(enum aarch64_insn_mb_type type);
+
+static __always_inline u32 __get_barrier_crm_val(enum aarch64_insn_mb_type type)
+{
+ switch (type) {
+ case AARCH64_INSN_MB_SY:
+ return 0xf;
+ case AARCH64_INSN_MB_ST:
+ return 0xe;
+ case AARCH64_INSN_MB_LD:
+ return 0xd;
+ case AARCH64_INSN_MB_ISH:
+ return 0xb;
+ case AARCH64_INSN_MB_NSH:
+ return 0x7;
+ case AARCH64_INSN_MB_OSH:
+ return 0x3;
+ default:
+ BUILD_BUG_ON_MSG(1, "unknown barrier type");
+ return AARCH64_BREAK_FAULT;
+ }
+}
+
+static __always_inline u32 aarch64_insn_gen_dmb(enum aarch64_insn_mb_type type)
+{
+ u32 opt;
+ u32 insn;
+
+ opt = __get_barrier_crm_val(type);
+ if (opt == AARCH64_BREAK_FAULT)
+ return AARCH64_BREAK_FAULT;
+
+ insn = aarch64_insn_get_dmb_value();
+ insn &= ~GENMASK(11, 8);
+ insn |= (opt << 8);
+
+ return insn;
+}
+
+static __always_inline u32 aarch64_insn_gen_dsb(enum aarch64_insn_mb_type type)
+{
+ u32 opt, insn;
+
+ opt = __get_barrier_crm_val(type);
+ if (opt == AARCH64_BREAK_FAULT)
+ return AARCH64_BREAK_FAULT;
+
+ insn = aarch64_insn_get_dsb_base_value();
+ insn &= ~GENMASK(11, 8);
+ insn |= (opt << 8);
+
+ return insn;
+}
+
u32 aarch64_insn_gen_mrs(enum aarch64_insn_register result,
enum aarch64_insn_system_register sysreg);
diff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c
index c70820d65805f..5c37f3a4c402b 100644
--- a/arch/arm64/lib/insn.c
+++ b/arch/arm64/lib/insn.c
@@ -1561,58 +1561,6 @@ u32 aarch64_insn_gen_extr(enum aarch64_insn_variant variant,
return aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RM, insn, Rm);
}
-static u32 __get_barrier_crm_val(enum aarch64_insn_mb_type type)
-{
- switch (type) {
- case AARCH64_INSN_MB_SY:
- return 0xf;
- case AARCH64_INSN_MB_ST:
- return 0xe;
- case AARCH64_INSN_MB_LD:
- return 0xd;
- case AARCH64_INSN_MB_ISH:
- return 0xb;
- case AARCH64_INSN_MB_NSH:
- return 0x7;
- case AARCH64_INSN_MB_OSH:
- return 0x3;
- default:
- pr_err("%s: unknown barrier type %d\n", __func__, type);
- return AARCH64_BREAK_FAULT;
- }
-}
-
-u32 aarch64_insn_gen_dmb(enum aarch64_insn_mb_type type)
-{
- u32 opt;
- u32 insn;
-
- opt = __get_barrier_crm_val(type);
- if (opt == AARCH64_BREAK_FAULT)
- return AARCH64_BREAK_FAULT;
-
- insn = aarch64_insn_get_dmb_value();
- insn &= ~GENMASK(11, 8);
- insn |= (opt << 8);
-
- return insn;
-}
-
-u32 aarch64_insn_gen_dsb(enum aarch64_insn_mb_type type)
-{
- u32 opt, insn;
-
- opt = __get_barrier_crm_val(type);
- if (opt == AARCH64_BREAK_FAULT)
- return AARCH64_BREAK_FAULT;
-
- insn = aarch64_insn_get_dsb_base_value();
- insn &= ~GENMASK(11, 8);
- insn |= (opt << 8);
-
- return insn;
-}
-
u32 aarch64_insn_gen_mrs(enum aarch64_insn_register result,
enum aarch64_insn_system_register sysreg)
{
--
2.43.0
next prev parent reply other threads:[~2026-09-28 13:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 13:30 [PATCH 0/6] arm64: alternatives: switch most used alternatives to callbacks Ada Couprie Diaz
2026-09-28 13:30 ` [PATCH 1/6] arm64: insn: remove deprecated memory barrier types Ada Couprie Diaz
2026-10-07 6:21 ` Vladimir Murzin
2026-10-07 17:05 ` Ada Couprie Diaz
2026-10-09 10:19 ` Vladimir Murzin
2026-09-28 13:30 ` Ada Couprie Diaz [this message]
2026-09-28 13:30 ` [PATCH 3/6] arm64: io: replace NVIDIA Olympus erratum alternative with callback Ada Couprie Diaz
2026-09-28 13:30 ` [PATCH 4/6] arm64: io: replace ARM erratum 832075 " Ada Couprie Diaz
2026-09-28 13:30 ` [PATCH 5/6] arm64: insn: operate on MSR/MRS sysreg field via defines Ada Couprie Diaz
2026-10-07 6:53 ` Vladimir Murzin
2026-10-07 16:31 ` Ada Couprie Diaz
2026-10-09 9:14 ` Vladimir Murzin
2026-09-28 13:30 ` [PATCH 6/6] arm64: use alternatie callback to patch TPIDR_EL1 accesses Ada Couprie Diaz
2026-10-06 16:28 ` [PATCH 0/6] arm64: alternatives: switch most used alternatives to callbacks Catalin Marinas
2026-10-06 17:30 ` Ada Couprie Diaz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260928133034.243541-3-ada.coupriediaz@arm.com \
--to=ada.coupriediaz@arm.com \
--cc=andre.przywara@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=arnd@arndb.de \
--cc=baohua@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=lucaswei@google.com \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sdonthineni@nvidia.com \
--cc=tj@kernel.org \
--cc=vladimir.murzin@arm.com \
--cc=vsethi@nvidia.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox