Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1918815imu; Fri, 14 Dec 2018 02:54:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/U3n/cy3X33f1xyKQYdMWnT7rRrnvyN/uZSgO/WArSysveeqM2rUNhsNX39F00S7L9uxT2Y X-Received: by 2002:a62:8c11:: with SMTP id m17mr2364212pfd.224.1544784853772; Fri, 14 Dec 2018 02:54:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544784853; cv=none; d=google.com; s=arc-20160816; b=y8LkQrgiDIkJ4rtJOHqsobg9vRrJvNAOeI8ZzhMHqSFNhTN04NmdEVs+JqISSmd0M7 DDPWqREfZlhniRIdCN21yLzUEC2s6Kik4qDZVILn4OkHRZg3kpPagIGSX8NW/AICf3C5 prohjTXFGauAlSMddxP9cptD1tcxJhKjMb3dT4jy61kJ6Q7fDs+8lvRTsvWDeUwYK995 vk8EKTqc1kPMXiJvKDJodVkO64OjejRdlEw2UegBUGyjVDqddh5RnzMm3+pKrxI/Zl7i i5j8wvUIioqZ9iDbXKO/MtIo8EU0Dl7OsmLFKBLQhsVtqgNlmGxetJexpS0QNDh3wUUI 3/yg== 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=5YpLCCwcRPfnofZqslKHzUx5gdhdB6E4LJ+H9hOBIXI=; b=eyUyCzsP7BzT8QrrwSRgnTZ4XasH0D/4+KqY0ne0PNs2ADdPvTewsRETY6yv9h9gsO 8P9nRaJVH3T8W1l7hT6eoTWz3OvPNga47MH4/7NTsiZgTGPIhsAJTZYdHHPDenkVsA2+ gTO+zZxafolrLw3Wrs+tnsagkdBAeN3oC2rgspoMw41pDWK7fVcdqV6Ku8VLCugkeRk+ SFYZQgMT5x83e0qtphc52d/RQCqnuwCfyvROLpiOIjHLlQJP3bific71X5ytUz2EHnDD h+exxVF0VIhsxeNe0d2LqKsjmTSmiYagTYzQDW+jOZ2TMeq5b8sVftRCa9DnqV28McfU S4fg== 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 o68si4325203pfo.140.2018.12.14.02.53.58; Fri, 14 Dec 2018 02:54:13 -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 S1729564AbeLNKwY (ORCPT + 99 others); Fri, 14 Dec 2018 05:52:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49692 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbeLNKwW (ORCPT ); Fri, 14 Dec 2018 05:52:22 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E80AE307EA84; Fri, 14 Dec 2018 10:52:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.32.181.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C08B26FA9; Fri, 14 Dec 2018 10:52:20 +0000 (UTC) From: Paolo Abeni To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Paul Turner , linux-kernel@vger.kernel.org, Edward Cree , David Woodhouse Subject: [PATCH net-next v3 1/4] indirect call wrappers: helpers to speed-up indirect calls of builtin Date: Fri, 14 Dec 2018 11:51:57 +0100 Message-Id: <645eb0fcfe12b7765d2a27025b1806247649f783.1544784419.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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 14 Dec 2018 10:52:22 +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_*(), as suggested by Ed Cree 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