Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Murzin <vladimir.murzin@arm.com>
To: Ada Couprie Diaz <ada.coupriediaz@arm.com>,
	linux-arm-kernel@lists.infradead.org
Cc: Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Tejun Heo <tj@kernel.org>,
	Andre Przywara <andre.przywara@arm.com>,
	Marc Zyngier <maz@kernel.org>, Mark Brown <broonie@kernel.org>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Lucas Wei <lucaswei@google.com>,
	Sascha Bischoff <Sascha.Bischoff@arm.com>,
	Barry Song <baohua@kernel.org>, Oliver Upton <oupton@kernel.org>,
	Xu Kuohai <xukuohai@huaweicloud.com>,
	Puranjay Mohan <puranjay@kernel.org>
Subject: Re: [PATCH 2/2] arm64: insn: make `aarch64_insn_gen_d{m,s}b()` alternative-safe
Date: Mon, 19 Oct 2026 11:49:56 +0100	[thread overview]
Message-ID: <5f1c9d90-2269-4e46-9a20-e8152153384c@arm.com> (raw)
In-Reply-To: <20261016165140.254791-3-ada.coupriediaz@arm.com>

Hi Ada,

On 10/16/26 17:51, Ada Couprie Diaz wrote:
> Move `aarch64_insn_gen_d{m,s}b()` and `__get_barrier_crm_val()`

__get_barrier_crm_val()/__is_valid_barrier_type() has gone, so
reference to it confuses.

> 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.

My understanding is that error printing is not alternative-safe,
so we replace it with a build-time check. The latter requires the
barrier type to be visible to the compiler, hence moving the
helper to a header and marking it __always_inline (with the side
effect that the code may be inlined into noinstr functions).

However, is it safe to assume that the barrier type will always
be visible to the compiler? This is true today, but I can imagine
a scenario where the barrier type is passed through a helper
defined in a separate translation units, making it impossible for
the compiler to observe its value at build time. I'm not sure
whether this is something we should worry about right now.

Another thing I'm wondering about is how we plan to make other
helpers alternative-safe. Do we eventually intend to move all of
them into header?

I also noticed that we're not entirely consistent with error
reporting across helpers. In several cases, we simply return
AARCH64_BREAK_FAULT without printing anything to the log. Perhaps
a better approach to making these helpers alternative-safe would
be to remove error printing altogether, mark them noinstr, and
return AARCH64_BREAK_FAULT whenever we cannot construct a valid
opcode?

> 
> 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)
>  

ISH - This option has the same behavior as SY and is deprecated.    

so conversion is valid.

Cheers
Vladimir

>  /* ADR */
>  #define A64_ADR(Rd, offset) \
> -- 2.43.0
> 



  reply	other threads:[~2026-10-19 10:50 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 ` [PATCH 2/2] arm64: insn: make `aarch64_insn_gen_d{m,s}b()` alternative-safe Ada Couprie Diaz
2026-10-19 10:49   ` Vladimir Murzin [this message]
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=5f1c9d90-2269-4e46-9a20-e8152153384c@arm.com \
    --to=vladimir.murzin@arm.com \
    --cc=Sascha.Bischoff@arm.com \
    --cc=ada.coupriediaz@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=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