Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp152101ybj; Fri, 8 May 2020 08:32:39 -0700 (PDT) X-Google-Smtp-Source: APiQypI9JVpQNNhj6QV3D5xUQYCIyDUXJWZz21RylMHS5eSXwYTU9Dp8io2ZssV0+sPIp90pax51 X-Received: by 2002:a17:906:2b8a:: with SMTP id m10mr2352739ejg.183.1588951959283; Fri, 08 May 2020 08:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588951959; cv=none; d=google.com; s=arc-20160816; b=uB6PTuz3oaM4ZQpJOfIjEspA/xjaF/JQDayZFFqMdjbOW3v620Ey/3xE944nkyL97J qA5pIKzKV/zHGmAmrJVtbbgtl0vIQjYlDjIt9J6p4ELNSvhGvZicMv7Rsr9/GBwebn4c aHhwc+eqIItrAgLfMqpf/Mr3+VPKsLyMV5aYSeWCJzDI8o305m7CvQehvVqOXnN4+dGk 1JDKSXw0rSsg0Ep0mZDvu51zTqeOx/fjB2aL3ljQHMaeHT2I79OTZvWZHDLmS5zVd7kc uLp+uyinC8uBtwQGpVvqd+z82MAUFBepF4WJ+JZ6A93xnRCPZ8VvBnz3kfbwal6tUD+Y YtcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ijaFvPasWKUsbhA2kdV/wZu4/wcIgDcX0/4aV7FEpOw=; b=bSvRLbThJd43E9zy/BF0CyrNEzAVdbSi2XJE5QKxqC8QzQmThnMLGrzg1ai4vHed6r 4RH2N7qNfhqI4fB0Vz4yOA5U71xTTPVOxIlugTaNwCsvDGvE45EMZdzex097GvcjcV3y AMZp1og0oojMmpETp+qJXLbUMrZ5u3DhaxIp35dbefSainEPVUGWkFBgbpSvH8gp3izj biyrXLmlHIRpM+wvfqQLNMGluwA6zEPT8dymmPCTLi61/Avvw/XNt+XUqMnAvKsjr2VZ RxFW/XqLLEskfRi/ZJ/Ljfz+4dLyBibodE9rpsmJEG1UgzwZ91q44RdiSBxspl3gHFua MdXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=F0LIwmWP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si1110693edr.270.2020.05.08.08.32.08; Fri, 08 May 2020 08:32:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=F0LIwmWP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbgEHP2Q (ORCPT + 99 others); Fri, 8 May 2020 11:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726948AbgEHP2O (ORCPT ); Fri, 8 May 2020 11:28:14 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F110FC061A0C for ; Fri, 8 May 2020 08:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ijaFvPasWKUsbhA2kdV/wZu4/wcIgDcX0/4aV7FEpOw=; b=F0LIwmWPAQRoQkL1B1fUf81p9A hgaeHxDtDWrclHPEJfJT81bgNKVDvPOjGOvIPCcj7ICL9wlu+VKeSDDn4X0u3j5+edgEiGj0zsQgL vlxphxIm3dOzu/8Uy7tGi2W+IyDdon1ML2ArhLVDi0PrHfDhs3/TP8ApM6ybHKAhxy5Non+6qY0Lj Kkd9rV3vnF85kaXFx7oZYaUJ54J0M4hZzM7Ngj/ZetnPCo5kyq4tYbhQuZcQ2uSpWH+aLPJJhbQ2k 7rnL76QqiLnnt0V4kyHOYNIuop+hRJpXzhJqE9jxcadMShtMzdJ2MG14xE1inBt8b74HsDSAYK858 6kxJ4U+w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX4uU-000786-HI; Fri, 08 May 2020 15:27:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 112CE3010C8; Fri, 8 May 2020 17:27:31 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E48F1286E8FF5; Fri, 8 May 2020 17:27:30 +0200 (CEST) Date: Fri, 8 May 2020 17:27:30 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: x86@kernel.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, bristot@redhat.com, jbaron@akamai.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, namit@vmware.com, hpa@zytor.com, luto@kernel.org, ard.biesheuvel@linaro.org, pbonzini@redhat.com, mathieu.desnoyers@efficios.com Subject: Re: [PATCH v4 14/18] static_call: Add static_cond_call() Message-ID: <20200508152730.GB3344@hirez.programming.kicks-ass.net> References: <20200501202849.647891881@infradead.org> <20200501202944.593400184@infradead.org> <20200506172455.ho5em2mtzn7qqfjl@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200506172455.ho5em2mtzn7qqfjl@treble> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 06, 2020 at 12:24:55PM -0500, Josh Poimboeuf wrote: > On that note, what do you think about tweaking the naming from > > DEFINE_STATIC_COND_CALL(name, typename); > static_cond_call(name)(args...); > > to > > DEFINE_STATIC_CALL_NO_FUNC(name, typename); > static_call_if_func(name)(args...); > > ? > > Seems clearer to me. They're still STATIC_CALLs, so it seems logical to > keep those two words together. And NO_FUNC clarifies the initialized > value. > > Similarly RETTRAMP could be ARCH_DEFINE_STATIC_CALL_NO_FUNC. So I dislike static_call_if_func(), that's so much typing. Also, I prefer ARCH_*_RETTRAMP as it clearly describes what the thing is. How is something like this? --- --- a/include/linux/static_call.h +++ b/include/linux/static_call.h @@ -16,7 +16,7 @@ * * DECLARE_STATIC_CALL(name, func); * DEFINE_STATIC_CALL(name, func); - * DEFINE_STATIC_COND_CALL(name, typename); + * DEFINE_STATIC_CALL_NULL(name, typename); * static_call(name)(args...); * static_cond_call(name)(args...); * static_call_update(name, func); @@ -54,6 +54,43 @@ * rather than calling through the trampoline. This requires objtool or a * compiler plugin to detect all the static_call() sites and annotate them * in the .static_call_sites section. + * + * + * Notes on NULL function pointers: + * + * Static_call()s support NULL functions, with many of the caveats that + * regular function pointers have. + * + * Clearly calling a NULL function pointer is 'BAD', so too for + * static_call()s (although when HAVE_STATIC_CALL it might not be immediately + * fatal). A NULL static_call can be the result of: + * + * DECLARE_STATIC_CALL_NULL(my_static_call, void (*)(int)); + * + * which is equivalent to declaring a NULL function pointer with just a + * typename: + * + * void (*my_func_ptr)(int arg1) = NULL; + * + * or using static_call_update() with a NULL function. In both cases the + * HAVE_STATIC_CALL implementation will patch the trampoline with a RET + * instruction, instead of an immediate tail-call JMP. HAVE_STATIC_CALL_INLINE + * architectures can patch the trampoline call to a NOP. + * + * In all cases, any argument evaluation is unconditional. Unlike a regular + * conditional function pointer call: + * + * if (my_func_ptr) + * my_func_ptr(arg1) + * + * where the argument evaludation also depends on the pointer value. + * + * When calling a static_call that can be NULL, use: + * + * static_cond_call(name)(arg1); + * + * which will include the required value tests to avoid NULL-pointer + * dereferences. */ #include @@ -122,7 +159,7 @@ extern int static_call_text_reserved(voi }; \ ARCH_DEFINE_STATIC_CALL_TRAMP(name, _func) -#define DEFINE_STATIC_COND_CALL(name, _func) \ +#define DEFINE_STATIC_CALL_NULL(name, _func) \ DECLARE_STATIC_CALL(name, _func); \ struct static_call_key STATIC_CALL_KEY(name) = { \ .func = NULL, \ @@ -154,7 +191,7 @@ struct static_call_key { }; \ ARCH_DEFINE_STATIC_CALL_TRAMP(name, _func) -#define DEFINE_STATIC_COND_CALL(name, _func) \ +#define DEFINE_STATIC_CALL_NULL(name, _func) \ DECLARE_STATIC_CALL(name, _func); \ struct static_call_key STATIC_CALL_KEY(name) = { \ .func = NULL, \ @@ -198,7 +235,7 @@ struct static_call_key { .func = _func, \ } -#define DEFINE_STATIC_COND_CALL(name, _func) \ +#define DEFINE_STATIC_CALL_NULL(name, _func) \ DECLARE_STATIC_CALL(name, _func); \ struct static_call_key STATIC_CALL_KEY(name) = { \ .func = NULL, \