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 E68EC1946DF; Fri, 11 Oct 2024 15:24:10 +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=1728660251; cv=none; b=LY1Oygv4qSJwh7w4deh77MAIgmFTHtLcwg6KVxWtBVw+HT2HfKx9dVePkKEsapslwvco2hWhH/rwDRCPtuOPskE2WDvPAujUv8xBpA1Agsl388+KLWelW6TjMjSNI3tdYcPsHK+YnGvevP2BJBiYYL9Tukbw5vSlAeEoWbgliDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728660251; c=relaxed/simple; bh=A3N9Mkq30GPl1hwp0+TVudApr5l241CnTDu+mkjDc68=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LXoUR+2lEo7g5wSd5l5SfaHtLTuNpz0ZUfbt/7+HDoyitY4OrPcX+828pY7Oz/KqNxKHrVOOi4O6a0JvMdpMppcnoTqRWdX10cb6Y36XFQwSoeoE1XNyhOO4x3IRqFtFdg5nnaxpglY9o8NgKxd6LOyBUEsHPBfuxwldw1QLfcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fJy54j3r; 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="fJy54j3r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39333C4CEC3; Fri, 11 Oct 2024 15:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728660250; bh=A3N9Mkq30GPl1hwp0+TVudApr5l241CnTDu+mkjDc68=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fJy54j3rdRFfLY2A7N5cYYGCebcq3yQ7Nn3YpXPetQdckOI3xObxbldIKT/3sa4pY P0pMjlETYXgk5U9otowTN0tcgGSiHOnEA+T7brocFPuL7mxw8+lWpBc3d1IZg7QrTi yxcm1ahYN+C3XxkjCb7gQhnOAJW0mQ24ywsBTW+bD59i1djn7RcWzLwmMWi7FhGtRa f/Wlzo2/2dx4/+fXDKYXgOsTbpGfv868g7eBHtYCnd3ZTbC8zDts+Bjo0zvfstARrm Wu1+LOPZIdHy3rx7zi4/v+iynpsH50cr29F6HhEPLYf51ySyV+L1zOfHn1gFLPgizY WdZnrav+mlECA== Date: Fri, 11 Oct 2024 08:23:12 -0700 From: Josh Poimboeuf To: Alice Ryhl Cc: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Peter Zijlstra , Jason Baron , Ard Biesheuvel , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , linux-trace-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Arnd Bergmann , linux-arch@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Sean Christopherson , Uros Bizjak , Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Mark Rutland , Ryan Roberts , Fuad Tabba , linux-arm-kernel@lists.infradead.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Andrew Jones , Alexandre Ghiti , Conor Dooley , Samuel Holland , linux-riscv@lists.infradead.org, Huacai Chen , WANG Xuerui , Bibo Mao , Tiezhu Yang , Andrew Morton , Tianrui Zhao , loongarch@lists.linux.dev Subject: Re: [PATCH v10 5/5] rust: add arch_static_branch Message-ID: <20241011152312.r5sy7k7hsunmmbfo@treble> References: <20241011-tracepoint-v10-0-7fbde4d6b525@google.com> <20241011-tracepoint-v10-5-7fbde4d6b525@google.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20241011-tracepoint-v10-5-7fbde4d6b525@google.com> On Fri, Oct 11, 2024 at 10:13:38AM +0000, Alice Ryhl wrote: > +#[cfg(CONFIG_JUMP_LABEL)] > +#[cfg(not(CONFIG_HAVE_JUMP_LABEL_HACK))] > +macro_rules! arch_static_branch { > + ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: { > + $crate::asm!( > + include!(concat!(env!("OBJTREE"), "/rust/kernel/arch_static_branch_asm.rs")); > + l_yes = label { > + break 'my_label true; > + }, > + symb = sym $key, > + off = const ::core::mem::offset_of!($keytyp, $field), > + branch = const $crate::jump_label::bool_to_int($branch), > + ); > + > + break 'my_label false; > + }}; > +} > + > +#[macro_export] > +#[doc(hidden)] > +#[cfg(CONFIG_JUMP_LABEL)] > +#[cfg(CONFIG_HAVE_JUMP_LABEL_HACK)] > +macro_rules! arch_static_branch { > + ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: { > + $crate::asm!( > + include!(concat!(env!("OBJTREE"), "/rust/kernel/arch_static_branch_asm.rs")); > + l_yes = label { > + break 'my_label true; > + }, > + symb = sym $key, > + off = const ::core::mem::offset_of!($keytyp, $field), > + branch = const 2 | $crate::jump_label::bool_to_int($branch), > + ); > + > + break 'my_label false; > + }}; Ouch... could we get rid of all this duplication by containing the hack bit to ARCH_STATIC_BRANCH_ASM() like so? diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h index ffd0d1a1a4af..3f1c1d6c0da1 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -24,7 +24,7 @@ #ifdef CONFIG_HAVE_JUMP_LABEL_HACK #define ARCH_STATIC_BRANCH_ASM(key, label) \ "1: jmp " label " # objtool NOPs this \n\t" \ - JUMP_TABLE_ENTRY(key, label) + JUMP_TABLE_ENTRY(key " + 2", label) #else /* !CONFIG_HAVE_JUMP_LABEL_HACK */ #define ARCH_STATIC_BRANCH_ASM(key, label) \ "1: .byte " __stringify(BYTES_NOP5) "\n\t" \ @@ -33,10 +33,8 @@ static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) { - int hack_bit = IS_ENABLED(CONFIG_HAVE_JUMP_LABEL_HACK) ? 2 : 0; - asm goto(ARCH_STATIC_BRANCH_ASM("%c0 + %c1", "%l[l_yes]") - : : "i" (key), "i" (hack_bit | branch) : : l_yes); + : : "i" (key), "i" (branch) : : l_yes); return false; l_yes: