Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Puranjay Mohan <puranjay@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Xu Kuohai <xukuohai@huaweicloud.com>,
	Lucas Wei <lucaswei@google.com>, Mark Brown <broonie@kernel.org>,
	Andre Przywara <andre.przywara@arm.com>,
	Tejun Heo <tj@kernel.org>, Oliver Upton <oupton@kernel.org>,
	Will Deacon <will@kernel.org>,
	Sascha Bischoff <Sascha.Bischoff@arm.com>
Subject: [PATCH 2/2] arm64: insn: make `aarch64_insn_gen_d{m,s}b()` alternative-safe
Date: Fri, 16 Oct 2026 17:51:40 +0100	[thread overview]
Message-ID: <20261016165140.254791-3-ada.coupriediaz@arm.com> (raw)
In-Reply-To: <20261016165140.254791-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 an inline build-time check
now that the compiler can verify all call sites.

As BPF is the only caller, with static arguments, only accept
non-deprecated types for each barrier, as per Arm ARM DDI 0487
version M.c[0], and update `A64_DMB_ISH` accordingly.

As all functions are now inlined and do not call any instrumentable
function, they are now safe to call in alternative callbacks.

[0]: https://support.arm.com/documentation/ddi0487/mc/
         (See C6.2.150, C6.2.152)

Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
 arch/arm64/include/asm/insn.h | 46 +++++++++++++++++++++++++++++++++--
 arch/arm64/lib/insn.c         | 44 ---------------------------------
 arch/arm64/net/bpf_jit.h      |  2 +-
 3 files changed, 45 insertions(+), 47 deletions(-)

diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index 2d19f48aab81..c91a8431c961 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -703,8 +703,50 @@ 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 aarch64_insn_gen_dmb(enum aarch64_insn_mb_type type)
+{
+	u32 insn;
+
+	switch (type) {
+	case AARCH64_INSN_MB_LD:
+	case AARCH64_INSN_MB_ST:
+	case AARCH64_INSN_MB_SY:
+		break;
+	default:
+		BUILD_BUG_ON_MSG(1, "invalid dmb type");
+	}
+
+	insn = aarch64_insn_get_dmb_value();
+	insn &= ~AARCH64_INSN_MB_TYPE_MASK;
+	insn |= type;
+
+	return insn;
+}
+
+static __always_inline u32 aarch64_insn_gen_dsb(enum aarch64_insn_mb_type type)
+{
+	u32 insn;
+
+	switch (type) {
+	case AARCH64_INSN_MB_OSH:
+	case AARCH64_INSN_MB_NSH:
+	case AARCH64_INSN_MB_ISH:
+	case AARCH64_INSN_MB_LD:
+	case AARCH64_INSN_MB_ST:
+	case AARCH64_INSN_MB_SY:
+		break;
+	default:
+		BUILD_BUG_ON_MSG(1, "invalid dsb type");
+	}
+
+	insn = aarch64_insn_get_dsb_base_value();
+	insn &= ~AARCH64_INSN_MB_TYPE_MASK;
+	insn |= type;
+
+	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 fa61a631d687..5c37f3a4c402 100644
--- a/arch/arm64/lib/insn.c
+++ b/arch/arm64/lib/insn.c
@@ -1561,50 +1561,6 @@ u32 aarch64_insn_gen_extr(enum aarch64_insn_variant variant,
 	return aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RM, insn, Rm);
 }
 
-static bool __is_valid_barrier_type(enum aarch64_insn_mb_type type)
-{
-	switch (type) {
-	case AARCH64_INSN_MB_OSH:
-	case AARCH64_INSN_MB_NSH:
-	case AARCH64_INSN_MB_ISH:
-	case AARCH64_INSN_MB_LD:
-	case AARCH64_INSN_MB_ST:
-	case AARCH64_INSN_MB_SY:
-		return true;
-	default:
-		pr_err("%s: unknown barrier type %d\n", __func__, type);
-		return false;
-	}
-}
-
-u32 aarch64_insn_gen_dmb(enum aarch64_insn_mb_type type)
-{
-	u32 insn;
-
-	if (!__is_valid_barrier_type(type))
-		return AARCH64_BREAK_FAULT;
-
-	insn = aarch64_insn_get_dmb_value();
-	insn &= ~AARCH64_INSN_MB_TYPE_MASK;
-	insn |= type;
-
-	return insn;
-}
-
-u32 aarch64_insn_gen_dsb(enum aarch64_insn_mb_type type)
-{
-	u32 insn;
-
-	if (!__is_valid_barrier_type(type))
-		return AARCH64_BREAK_FAULT;
-
-	insn = aarch64_insn_get_dsb_base_value();
-	insn &= ~AARCH64_INSN_MB_TYPE_MASK;
-	insn |= type;
-
-	return insn;
-}
-
 u32 aarch64_insn_gen_mrs(enum aarch64_insn_register result,
 			 enum aarch64_insn_system_register sysreg)
 {
diff --git a/arch/arm64/net/bpf_jit.h b/arch/arm64/net/bpf_jit.h
index b2fe6e6dcf44..08d514b40a5b 100644
--- a/arch/arm64/net/bpf_jit.h
+++ b/arch/arm64/net/bpf_jit.h
@@ -324,7 +324,7 @@
 #define A64_NOP    A64_HINT(AARCH64_INSN_HINT_NOP)
 
 /* DMB */
-#define A64_DMB_ISH aarch64_insn_gen_dmb(AARCH64_INSN_MB_ISH)
+#define A64_DMB_ISH aarch64_insn_gen_dmb(AARCH64_INSN_MB_SY)
 
 /* ADR */
 #define A64_ADR(Rd, offset) \
-- 
2.43.0



  parent reply	other threads:[~2026-10-16 16:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 16:51 [PATCH 0/2] arm64: insn: clean-up memory barrier generation Ada Couprie Diaz
2026-10-16 16:51 ` [PATCH 1/2] arm64: insn: clean-up memory barrier types Ada Couprie Diaz
2026-10-19 10:07   ` Vladimir Murzin
2026-10-19 15:26     ` Ada Couprie Diaz
2026-10-16 16:51 ` Ada Couprie Diaz [this message]
2026-10-19 10:49   ` [PATCH 2/2] arm64: insn: make `aarch64_insn_gen_d{m,s}b()` alternative-safe Vladimir Murzin
2026-10-19 15:24     ` 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=20261016165140.254791-3-ada.coupriediaz@arm.com \
    --to=ada.coupriediaz@arm.com \
    --cc=Sascha.Bischoff@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=baohua@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lpieralisi@kernel.org \
    --cc=lucaswei@google.com \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=puranjay@kernel.org \
    --cc=tj@kernel.org \
    --cc=vladimir.murzin@arm.com \
    --cc=will@kernel.org \
    --cc=xukuohai@huaweicloud.com \
    /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