All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Ada Couprie Diaz <ada.coupriediaz@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Oliver Upton <oliver.upton@linux.dev>,
	Ard Biesheuvel <ardb@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev,
	kasan-dev@googlegroups.com, Mark Rutland <mark.rutland@arm.com>
Subject: Re: [RFC PATCH 06/16] arm64/insn: always inline aarch64_insn_gen_movewide()
Date: Mon, 20 Oct 2025 17:48:43 +0100	[thread overview]
Message-ID: <86jz0pwmc4.wl-maz@kernel.org> (raw)
In-Reply-To: <20250923174903.76283-7-ada.coupriediaz@arm.com>

On Tue, 23 Sep 2025 18:48:53 +0100,
Ada Couprie Diaz <ada.coupriediaz@arm.com> wrote:
> 
> As it is always called with an explicit movewide type, we can
> check for its validity at compile time and remove the runtime error print.
> 
> The other error prints cannot be verified at compile time, but should not
> occur in practice and will still lead to a fault BRK, so remove them.
> 
> This makes `aarch64_insn_gen_movewide()` safe for inlining
> and usage from patching callbacks, as both
> `aarch64_insn_encode_register()` and `aarch64_insn_encode_immediate()`
> have been made safe in previous commits.
> 
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
> ---
>  arch/arm64/include/asm/insn.h | 58 ++++++++++++++++++++++++++++++++---
>  arch/arm64/lib/insn.c         | 56 ---------------------------------
>  2 files changed, 54 insertions(+), 60 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
> index 5f5f6a125b4e..5a25e311717f 100644
> --- a/arch/arm64/include/asm/insn.h
> +++ b/arch/arm64/include/asm/insn.h
> @@ -624,6 +624,8 @@ static __always_inline bool aarch64_get_imm_shift_mask(
>  #define ADR_IMM_LOSHIFT		29
>  #define ADR_IMM_HISHIFT		5
>  
> +#define AARCH64_INSN_SF_BIT	BIT(31)
> +
>  enum aarch64_insn_encoding_class aarch64_get_insn_class(u32 insn);
>  u64 aarch64_insn_decode_immediate(enum aarch64_insn_imm_type type, u32 insn);
>  
> @@ -796,10 +798,58 @@ u32 aarch64_insn_gen_bitfield(enum aarch64_insn_register dst,
>  			      int immr, int imms,
>  			      enum aarch64_insn_variant variant,
>  			      enum aarch64_insn_bitfield_type type);
> -u32 aarch64_insn_gen_movewide(enum aarch64_insn_register dst,
> -			      int imm, int shift,
> -			      enum aarch64_insn_variant variant,
> -			      enum aarch64_insn_movewide_type type);
> +
> +static __always_inline u32 aarch64_insn_gen_movewide(
> +				 enum aarch64_insn_register dst,
> +				 int imm, int shift,
> +				 enum aarch64_insn_variant variant,
> +				 enum aarch64_insn_movewide_type type)

nit: I personally find this definition style pretty unreadable, and
would rather see the "static __always_inline" stuff put on a line of
its own:

static __always_inline
u32 aarch64_insn_gen_movewide(enum aarch64_insn_register dst,
			      int imm, int shift,
			      enum aarch64_insn_variant variant,
			      enum aarch64_insn_movewide_type type)

But again, that's a personal preference, nothing else.

> +{
> +	compiletime_assert(type >=  AARCH64_INSN_MOVEWIDE_ZERO &&
> +		type <= AARCH64_INSN_MOVEWIDE_INVERSE, "unknown movewide encoding");
> +	u32 insn;
> +
> +	switch (type) {
> +	case AARCH64_INSN_MOVEWIDE_ZERO:
> +		insn = aarch64_insn_get_movz_value();
> +		break;
> +	case AARCH64_INSN_MOVEWIDE_KEEP:
> +		insn = aarch64_insn_get_movk_value();
> +		break;
> +	case AARCH64_INSN_MOVEWIDE_INVERSE:
> +		insn = aarch64_insn_get_movn_value();
> +		break;
> +	default:
> +		return AARCH64_BREAK_FAULT;

Similar request to one of the previous patches: since you can check
the validity at compile time, place it in the default: case, and drop
the return statement.

> +	}
> +
> +	if (imm & ~(SZ_64K - 1)) {
> +		return AARCH64_BREAK_FAULT;
> +	}
> +
> +	switch (variant) {
> +	case AARCH64_INSN_VARIANT_32BIT:
> +		if (shift != 0 && shift != 16) {
> +			return AARCH64_BREAK_FAULT;
> +		}
> +		break;
> +	case AARCH64_INSN_VARIANT_64BIT:
> +		insn |= AARCH64_INSN_SF_BIT;
> +		if (shift != 0 && shift != 16 && shift != 32 && shift != 48) {
> +			return AARCH64_BREAK_FAULT;
> +		}
> +		break;
> +	default:
> +		return AARCH64_BREAK_FAULT;

You could also check the variant.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2025-10-20 16:48 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 17:48 [RFC PATCH 00/16] arm64: make alternative patching callbacks safe Ada Couprie Diaz
2025-09-23 17:48 ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 01/16] kasan: mark kasan_(hw_)tags_enabled() __always_inline Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 02/16] arm64: kasan: make kasan_hw_tags_enable() callback safe Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 03/16] arm64/insn: always inline aarch64_insn_decode_register() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-10-20 16:39   ` Marc Zyngier
2025-09-23 17:48 ` [RFC PATCH 04/16] arm64/insn: always inline aarch64_insn_encode_register() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 05/16] arm64/insn: always inline aarch64_insn_encode_immediate() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 06/16] arm64/insn: always inline aarch64_insn_gen_movewide() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-10-20 16:48   ` Marc Zyngier [this message]
2025-09-23 17:48 ` [RFC PATCH 07/16] arm64/proton-pack: make alternative callbacks safe Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 08/16] arm64/insn: always inline aarch64_insn_gen_logical_immediate() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 09/16] arm64/insn: always inline aarch64_insn_gen_add_sub_imm() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 10/16] arm64/insn: always inline aarch64_insn_gen_branch_reg() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 11/16] arm64/insn: always inline aarch64_insn_gen_extr() Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-09-23 17:48 ` [RFC PATCH 12/16] kvm/arm64: make alternative callbacks safe Ada Couprie Diaz
2025-09-23 17:48   ` Ada Couprie Diaz
2025-10-20 17:05   ` Marc Zyngier
2025-09-23 17:49 ` [RFC PATCH 13/16] arm64/insn: introduce missing is_store/is_load helpers Ada Couprie Diaz
2025-09-23 17:49   ` Ada Couprie Diaz
2025-09-23 17:49 ` [RFC PATCH 14/16] arm64/insn: always inline aarch64_insn_encode_ldst_size() Ada Couprie Diaz
2025-09-23 17:49   ` Ada Couprie Diaz
2025-10-20 17:12   ` Marc Zyngier
2025-09-23 17:49 ` [RFC PATCH 15/16] arm64/insn: always inline aarch64_insn_gen_load_acq_store_rel() Ada Couprie Diaz
2025-09-23 17:49   ` Ada Couprie Diaz
2025-09-23 17:49 ` [RFC PATCH 16/16] arm64/io: rework Cortex-A57 erratum 832075 to use callback Ada Couprie Diaz
2025-09-23 17:49   ` 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=86jz0pwmc4.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=ada.coupriediaz@arm.com \
    --cc=andreyknvl@gmail.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=joey.gouly@arm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=oliver.upton@linux.dev \
    --cc=ryabinin.a.a@gmail.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.