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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F477C61DA4 for ; Tue, 14 Mar 2023 01:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbjCNB6z (ORCPT ); Mon, 13 Mar 2023 21:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjCNB6p (ORCPT ); Mon, 13 Mar 2023 21:58:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7CE51633C for ; Mon, 13 Mar 2023 18:58:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9234C615AC for ; Tue, 14 Mar 2023 01:58:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89529C4339C; Tue, 14 Mar 2023 01:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678759119; bh=G8RSycebZt3dD6O9pae5i1zOll+TP4NQkVvirx16U5E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jJ6o60P6vfHynwVAWVlEdshVJuLRDXM4LsT42GrnKOP7BRLiEhk9eVDo1najCZVtt AskJmJQ6fL5AQDDlKg5B90ToUmqTTsQnTXxilOFMwlc6Uu4mADASUiDzTdGSLiE7fX JItVplN7N/csXBVs4YkgahhIl2hLxQXbKJcnMktx//aV5IVN6X9Wcozz189Bu5t/gs fhGLZTXOFXcfGnL/aycIT7CbzrtxPeOjVimVcuvxxb+SQnp3EuAcDyZRxOEq7z5gMh I9j3plRrm8iHZWFwlbJtEj3YiJl2iLeksTYBnsihqWI1/6Vya2KCezcnrlBuBHSt+Z jD7kN20O4kQJA== Date: Mon, 13 Mar 2023 18:58:36 -0700 From: Josh Poimboeuf To: Sami Tolvanen Cc: Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Jason Baron , Steven Rostedt , Ard Biesheuvel , Christophe Leroy , Paolo Bonzini , Sean Christopherson , Nick Desaulniers Subject: Re: [RFC][PATCH 1/5] static_call: Make NULL static calls consistent Message-ID: <20230314015836.p3l43w7ez7qzxylr@treble> References: <016c1e9cbdf726a885a406ff6baed85087ad1213.1678474914.git.jpoimboe@kernel.org> <20230310205926.GB1605437@hirez.programming.kicks-ass.net> <20230311012004.vyc4kdlqjsv4zliw@treble> <20230312151731.GB1757905@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 13, 2023 at 10:48:58AM -0700, Sami Tolvanen wrote: > On Sun, Mar 12, 2023 at 8:17 AM Peter Zijlstra wrote: > > > > On Fri, Mar 10, 2023 at 05:20:04PM -0800, Josh Poimboeuf wrote: > > > 2) Create yet another "tier" of static call implementations, for > > > arches which can have the unfortunate combo of CFI_CLANG + > > > !HAVE_STATIC_CALL. CONFIG_ALMOST_DONT_HAVE_STATIC_CALL? > > > > > > The arch can define ARCH_DEFINE_STATIC_CALL_NOP() which uses inline > > > asm to create a CFI-compliant NOP/BUG/whatever version of the > > > function (insert lots of hand-waving). Is the kcfi hash available > > > to inline asm at build time? > > > > Yes, clang creates magic symbol for everything it sees a declaration > > for. This symbols can be referenced from asm, linking will make it all > > work. > > > > And yes, C sucks, you can't actually create a function definition from a > > type :/ Otherwise this could be trivially fixable. > > Wouldn't creating a separate inline assembly nop function that > references the CFI hash of another function with the correct type > potentially solve this issue like Josh suggested? Right, I was thinking something like this, where the nop function gets generated by DEFINE_STATIC_CALL(). Completely untested of course... #define STATIC_CALL_NOP_PREFIX __SCN__ #define STATIC_CALL_NOP(name) __PASTE(STATIC_CALL_NOP_PREFIX, name) #define STATIC_CALL_NOP_STR(name) __stringify(STATIC_CALL_NOP(name)) #define ARCH_DEFINE_STATIC_CALL_NOP(name, func) \ asm(".align 4 \n" \ ".word __kcfi_typeid_" STATIC_CALL_NOP_STR(name) " \n" \ ".globl " STATIC_CALL_NOP_STR(name) " \n" \ STATIC_CALL_NOP_STR(name) ": \n" \ "bti c \n" \ "mov x0, xzr \n" \ "ret \n" \ ".type " STATIC_CALL_NOP_STR(name) ", @function \n" \ ".size " STATIC_CALL_NOP_STR(name) ", . - " STATIC_CALL_NOP_STR(name) " \n") #define DECLARE_STATIC_CALL(name, func) \ extern struct static_call_key STATIC_CALL_KEY(name); \ extern typeof(func) STATIC_CALL_TRAMP(name) \ extern typeof(func) STATIC_CALL_NOP(name) #define DEFINE_STATIC_CALL(name, _func, _func_init) \ DECLARE_STATIC_CALL(name, _func); \ ARCH_DEFINE_STATIC_CALL_NOP(name); \ struct static_call_key STATIC_CALL_KEY(name) = { \ .func = _func_init, \ } -- Josh