Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9790464imu; Wed, 5 Dec 2018 10:15:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/VocMQpX8EuoPK0RzwCLDHvd6QkgLva2Odi5ZwAOrOHluwECfAyPeUriIZC8eVFcyy5Me0P X-Received: by 2002:a17:902:720c:: with SMTP id ba12mr25299176plb.79.1544033756217; Wed, 05 Dec 2018 10:15:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544033756; cv=none; d=google.com; s=arc-20160816; b=q5h1aI0RCfYgoQY5QOdIaBhZJ/Mu/zR63BQjYY7mXEKIXp8zmwxQSdGerhs1DkrvBU NnM8N383lwWpWjZzAGD01BqWKp/c62zt5MT3qRZ01epjEknT1RG6nOXN1laAujwCqD3r EYDkuxOSAzGbWATNAzJYVHj95O0hLsQ1Rq4rkhCH61O6NmT4kgR1P2AhMelqrAf+5HHO vOOIvUveOhrUYzomGKB8j0aR1ANc5IlNyN9BVKts8NVxjeHT/W/ogH8GVh0nIBvN6l6Y 8lZl6aKlJ2fb0OQx8LkuJktdeh93/7Lxz9//5I6expemBssGNu+js+M3lwQRZOdUlTwf 3CcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mipC3vdjG4Lt+lUke1C3tVh8WrTM3V+GJapPE+Zwm6I=; b=VHk+G5Es7FPx1FOp7D/BxaWr0PUP4rbXjJApCPYUgdiKOcu8NmJS30s0mT8xOjTgLZ YOKUy4X5poLjH/umEDm4CjCZzW+fS2ym2DF6DEsxB3Bo7TWTjxh+aTYjhegzTi/zfxcA 1aYSemM1PDHEdiDSDK/HLLFTbWciDfmIxLWauboPu/E+P52XmT7yemp+ippAHIEzIyBV u1MiVpZeCxa63W5GgksegOo/wYWbI8E2ieBsTGuAEa+LaMJUkLu3pGv/gX8rZ/eCCX1L xO1NLZib3LFjNDudxdxFjAD/pGqvc7WrEFh/e8vMS13sDfyD4t1UN/4Kwaxx5QFoGISC cD3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p23si8912577plo.7.2018.12.05.10.15.17; Wed, 05 Dec 2018 10:15:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728174AbeLESOb (ORCPT + 99 others); Wed, 5 Dec 2018 13:14:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38702 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbeLESO1 (ORCPT ); Wed, 5 Dec 2018 13:14:27 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BFC6C056807; Wed, 5 Dec 2018 18:14:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.32.181.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 736A21001F54; Wed, 5 Dec 2018 18:14:26 +0000 (UTC) From: Paolo Abeni To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paul Turner , linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 1/4] indirect call wrappers: helpers to speed-up indirect calls of builtin Date: Wed, 5 Dec 2018 19:13:39 +0100 Message-Id: <07aaed31eb0b515c173138e1358c412157e58ec2.1544032300.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 05 Dec 2018 18:14:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This header define a bunch of helpers that allow avoiding the retpoline overhead when calling builtin functions via function pointers. It boils down to explicitly comparing the function pointers to known builtin functions and eventually invoke directly the latter. The macros defined here implement the boilerplate for the above schema and will be used by the next patches. rfc -> v1: - use branch prediction hint, as suggested by Eric v1 -> v2: - list explicitly the builtin function names in INDIRECT_CALL_*() Suggested-by: Eric Dumazet Signed-off-by: Paolo Abeni --- include/linux/indirect_call_wrapper.h | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/linux/indirect_call_wrapper.h diff --git a/include/linux/indirect_call_wrapper.h b/include/linux/indirect_call_wrapper.h new file mode 100644 index 000000000000..7c8b7f4948af --- /dev/null +++ b/include/linux/indirect_call_wrapper.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_INDIRECT_CALL_WRAPPER_H +#define _LINUX_INDIRECT_CALL_WRAPPER_H + +#ifdef CONFIG_RETPOLINE + +/* + * INDIRECT_CALL_$NR - wrapper for indirect calls with $NR known builtin + * @f: function pointer + * @f$NR: builtin functions names, up to $NR of them + * @__VA_ARGS__: arguments for @f + * + * Avoid retpoline overhead for known builtin, checking @f vs each of them and + * eventually invoking directly the builtin function. The functions are check + * in the given order. Fallback to the indirect call. + */ +#define INDIRECT_CALL_1(f, f1, ...) \ + ({ \ + likely(f == f1) ? f1(__VA_ARGS__) : f(__VA_ARGS__); \ + }) +#define INDIRECT_CALL_2(f, f2, f1, ...) \ + ({ \ + likely(f == f2) ? f2(__VA_ARGS__) : \ + INDIRECT_CALL_1(f, f1, __VA_ARGS__); \ + }) + +#define INDIRECT_CALLABLE_DECLARE(f) f +#define INDIRECT_CALLABLE_SCOPE + +#else +#define INDIRECT_CALL_1(f, name, ...) f(__VA_ARGS__) +#define INDIRECT_CALL_2(f, name, ...) f(__VA_ARGS__) +#define INDIRECT_CALLABLE_DECLARE(f) +#define INDIRECT_CALLABLE_SCOPE static +#endif + +/* + * We can use INDIRECT_CALL_$NR for ipv6 related functions only if ipv6 is + * builtin, this macro simplify dealing with indirect calls with only ipv4/ipv6 + * alternatives + */ +#if IS_BUILTIN(CONFIG_IPV6) +#define INDIRECT_CALL_INET(f, f2, f1, ...) \ + INDIRECT_CALL_2(f, f2, f1, __VA_ARGS__) +#elif IS_ENABLED(CONFIG_INET) +#define INDIRECT_CALL_INET(f, f2, f1, ...) INDIRECT_CALL_1(f, f1, __VA_ARGS__) +#else +#define INDIRECT_CALL_INET(f, f2, f1, ...) f(__VA_ARGS__) +#endif + +#endif -- 2.19.2