From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0691CCD19F for ; Mon, 20 Oct 2025 16:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ljgwGTyHDyNrzUm2wfSApTtDIUOkOST1fBvM18Ofiu4=; b=D1dJN7cY0PixgZ5B89tFGEMC8F myfo/lVHF6GxK5LmppmRaxnD0koAb8muv9WwG2D0GPymShYRfaO7G/vvj3NjBNCfqO63ZLP88Gwuz Kkaim3Pof2Gs49J/ne9iQm8zxDvmZYyXRQ2yofSnktKm5acupZjKc+jy45jFx04G7SYZt4WyA1uTi HYzyaZ6S2ntE89VmPySAgKZF5C7zEG7DVWAcXY2nKi41L7lkQqOyQRYCPNE9j4EJByN1QUcNjMAqE 7eQ1Ifs9crXZUbwxkOnbuJgFVHlNCvyjvS34kklDfqpea5TyYP2+XFL4Doe661g5iPz2ydoOZh945 IyPTLedg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vAsuz-0000000ELYA-41BM; Mon, 20 Oct 2025 16:39:33 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vAsux-0000000ELXb-0SWD for linux-arm-kernel@lists.infradead.org; Mon, 20 Oct 2025 16:39:32 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 560754182C; Mon, 20 Oct 2025 16:39:16 +0000 (UTC) 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) 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251020_093931_188034_ECCA4587 X-CRM114-Status: GOOD ( 22.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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.