From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D649321457; Mon, 20 Oct 2025 16:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760978357; cv=none; b=uAHXjef45eCdtqZaddYawNkO1F0hokDy2XiHBp/Lb9RN3l6V0Kk778Jg4D3MwpClL2e/njfevi2Wio1UZBnoklnBcAr1oo6bKZKE58tOr8YldyuV11S4AS1IfiChXEQ/le+ZK2XdxKnqjSW4hY8AEAnXu/DPhpUflHRA2oZvEIA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760978357; c=relaxed/simple; bh=eeCxTQhmLEWvE9BlEKDnreJyLFhJt0Baibzlj367w+c=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=m9w3PMxMxLKrf1BuOL5ZGC4yejmbV2Iym99tDlaxPk6gijnFRYt6JdYP/7A1iWcujnrGkMKQa0SjpWHcqTNXyEANgM/bGyXmuyeLqA4xvkiI7w64JJvGxdCwSU42leZlPeWK54zUAVGVu6CiPZpfOLLMzDBYe3Mxr70yhp08c/Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CQsMR9Ok; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CQsMR9Ok" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 280ECC4CEF9; Mon, 20 Oct 2025 16:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760978356; bh=eeCxTQhmLEWvE9BlEKDnreJyLFhJt0Baibzlj367w+c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CQsMR9OkVjqYfwZfIiYj58LavMSP9Z1SzFU3bx51MNN7IRRorGu/mCR3C/f2SswJn /+Lwdv/mjLt7HcjyOEAX5oGu2dGldpjxlxBvgYHcjZt9ntQ9eKhcaQz5C8m3/H6Bph IUz7T3xdbO+hOm+MHq9d9179WyxV7/mNCVwSD43MqST4V/t98UxvCGTvcUF6mw72UJ dutwt6+PeKQw7gT++pYzgAFI1s939Zai7aRohv7LRtJjJ66SqW41LjeE46L/rz0CYv O3SyAXrRAhCPHRXkF1NLvXcPEe4C4JJfWVxirlGy1c5WGvNu/azJZe1KT4H4FGCecK 5fkvRq77mNV8A== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vAsuf-0000000FZt9-3Yhi; Mon, 20 Oct 2025 16:39:13 +0000 Date: Mon, 20 Oct 2025 17:39:13 +0100 Message-ID: <86ldl5wmry.wl-maz@kernel.org> From: Marc Zyngier To: Ada Couprie Diaz Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Oliver Upton , Ard Biesheuvel , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kasan-dev@googlegroups.com, Mark Rutland Subject: Re: [RFC PATCH 03/16] arm64/insn: always inline aarch64_insn_decode_register() In-Reply-To: <20250923174903.76283-4-ada.coupriediaz@arm.com> References: <20250923174903.76283-1-ada.coupriediaz@arm.com> <20250923174903.76283-4-ada.coupriediaz@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: ada.coupriediaz@arm.com, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, ardb@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kasan-dev@googlegroups.com, mark.rutland@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 23 Sep 2025 18:48:50 +0100, Ada Couprie Diaz wrote: > > As it is always called with an explicit register type, we can > check for its validity at compile time and remove the runtime error print. > > This makes `aarch64_insn_decode_register()` self-contained and safe > for inlining and usage from patching callbacks. > > Signed-off-by: Ada Couprie Diaz > --- > arch/arm64/include/asm/insn.h | 32 ++++++++++++++++++++++++++++++-- > arch/arm64/lib/insn.c | 29 ----------------------------- > 2 files changed, 30 insertions(+), 31 deletions(-) > > diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h > index 18c7811774d3..f6bce1a62dda 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 > #include > #include > > @@ -558,8 +559,35 @@ enum aarch64_insn_encoding_class aarch64_get_insn_class(u32 insn); > u64 aarch64_insn_decode_immediate(enum aarch64_insn_imm_type type, u32 insn); > u32 aarch64_insn_encode_immediate(enum aarch64_insn_imm_type type, > u32 insn, u64 imm); > -u32 aarch64_insn_decode_register(enum aarch64_insn_register_type type, > - u32 insn); > +static __always_inline u32 aarch64_insn_decode_register( > + enum aarch64_insn_register_type type, u32 insn) > +{ > + compiletime_assert(type >= AARCH64_INSN_REGTYPE_RT && > + type <= AARCH64_INSN_REGTYPE_RS, "unknown register type encoding"); > + int shift; > + > + switch (type) { > + case AARCH64_INSN_REGTYPE_RT: > + case AARCH64_INSN_REGTYPE_RD: > + shift = 0; > + break; > + case AARCH64_INSN_REGTYPE_RN: > + shift = 5; > + break; > + case AARCH64_INSN_REGTYPE_RT2: > + case AARCH64_INSN_REGTYPE_RA: > + shift = 10; > + break; > + case AARCH64_INSN_REGTYPE_RM: > + case AARCH64_INSN_REGTYPE_RS: > + shift = 16; > + break; > + default: > + return 0; Could you replace the above compiletime_assert() with something in the default: case instead (BUILD_BUG_ON() or otherwise)? I'm a bit concerned that if we add an enum entry in the middle of the current lot, this code becomes broken without us noticing. It would also rid us of this "return 0" case, which is pretty brittle. Thanks, M. -- Without deviation from the norm, progress is not possible.