From patchwork Thu Jul 3 14:56:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Shen Lim X-Patchwork-Id: 33029 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6F575203AC for ; Thu, 3 Jul 2014 14:57:22 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id v10sf1764963pde.11 for ; Thu, 03 Jul 2014 07:57:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=Ba1oL2NITd7G6OEjMAfaoaRYLmlE+O//6lYCNYZwY+o=; b=Nju+vq351gYyzy12g7cdzGZ/gphlHZoQ6DJqJ6Nw0GQmjzeEGugEnLv39v71OvWEVz EvsGcWGr+ZWel65r4NXqDB24fizITOmvAUWykFXX4VWbqAE9jijTz0kAV0DppM64HzcK Pe3LvrrWC7uDu3p+is8rJhAXCREnidu0NYSp5F1gO12QG9MYYB+o7DYxV8ipC9KK30u/ y9siOGYUfdRV7ugvc+wkG7aoowzuapqjdkvRpQrJ/3W4qO/c/hSLitHKZquXkK/2Vn2/ A/OUeVcJefJLf6a69etE6lAb+vKog0XymvVwvy2+sDICfjWQgoT/vVqXSp0W98ekiOZt Jo9Q== X-Gm-Message-State: ALoCoQm+kgZfjMqQQwBU5G70pllEAqdLg0hQ8fxsPZPixp8jQMPi0oGyOb7Ig3IFW7jjVnAYjUPH X-Received: by 10.66.160.34 with SMTP id xh2mr2474815pab.6.1404399441509; Thu, 03 Jul 2014 07:57:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.1 with SMTP id p1ls526175qga.97.gmail; Thu, 03 Jul 2014 07:57:21 -0700 (PDT) X-Received: by 10.220.164.198 with SMTP id f6mr939227vcy.51.1404399441394; Thu, 03 Jul 2014 07:57:21 -0700 (PDT) Received: from mail-ve0-x22b.google.com (mail-ve0-x22b.google.com [2607:f8b0:400c:c01::22b]) by mx.google.com with ESMTPS id ca9si3085197vdc.71.2014.07.03.07.57.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Jul 2014 07:57:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22b as permitted sender) client-ip=2607:f8b0:400c:c01::22b; Received: by mail-ve0-f171.google.com with SMTP id jz11so352021veb.16 for ; Thu, 03 Jul 2014 07:57:21 -0700 (PDT) X-Received: by 10.220.92.135 with SMTP id r7mr4294489vcm.11.1404399441298; Thu, 03 Jul 2014 07:57:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp382857vcb; Thu, 3 Jul 2014 07:57:20 -0700 (PDT) X-Received: by 10.66.175.166 with SMTP id cb6mr5206419pac.128.1404399440457; Thu, 03 Jul 2014 07:57:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qs6si33186707pbc.21.2014.07.03.07.57.19; Thu, 03 Jul 2014 07:57:19 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758837AbaGCO5J (ORCPT + 27 others); Thu, 3 Jul 2014 10:57:09 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:50857 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758616AbaGCO5G (ORCPT ); Thu, 3 Jul 2014 10:57:06 -0400 Received: by mail-pd0-f176.google.com with SMTP id ft15so344579pdb.21 for ; Thu, 03 Jul 2014 07:57:06 -0700 (PDT) X-Received: by 10.70.102.44 with SMTP id fl12mr4577723pdb.125.1404399426168; Thu, 03 Jul 2014 07:57:06 -0700 (PDT) Received: from gup76.hsd1.ca.comcast.net ([98.234.176.204]) by mx.google.com with ESMTPSA id pn4sm41354020pbb.7.2014.07.03.07.57.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Jul 2014 07:57:05 -0700 (PDT) From: Zi Shen Lim To: "David S. Miller" Cc: Zi Shen Lim , Daniel Borkmann , Alexei Starovoitov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv2 net-next] net: filter: move load_pointer() into filter.h Date: Thu, 3 Jul 2014 07:56:54 -0700 Message-Id: <1404399414-32099-1-git-send-email-zlim.lnx@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: zlim.lnx@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22b as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , load_pointer() is already a static inline function. Let's move it into filter.h so BPF JIT implementations can reuse this function. Since we're exporting this function, let's also rename it to bpf_load_pointer() for clarity. Signed-off-by: Zi Shen Lim Reviewed-by: Daniel Borkmann Acked-by: Alexei Starovoitov --- v1->v2: * Renamed to more specific name of bpf_load_pointer(), as suggested by Daniel. This patch is based on discussion with Alexei in the context of reusing load_pointer for upcoming arm64 BPF JIT compiler. [1] Compile tested on x86_64 and arm64. [1] https://lkml.org/lkml/2014/7/3/14 include/linux/filter.h | 13 +++++++++++++ net/core/filter.c | 15 +++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index a7e3c48..b885dcb 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -406,6 +407,18 @@ static inline u16 bpf_anc_helper(const struct sock_filter *ftest) } } +void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, + int k, unsigned int size); + +static inline void *bpf_load_pointer(const struct sk_buff *skb, int k, + unsigned int size, void *buffer) +{ + if (k >= 0) + return skb_header_pointer(skb, k, size, buffer); + + return bpf_internal_load_pointer_neg_helper(skb, k, size); +} + #ifdef CONFIG_BPF_JIT #include #include diff --git a/net/core/filter.c b/net/core/filter.c index 1dbf646..87af1e3 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -84,15 +84,6 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns return NULL; } -static inline void *load_pointer(const struct sk_buff *skb, int k, - unsigned int size, void *buffer) -{ - if (k >= 0) - return skb_header_pointer(skb, k, size, buffer); - - return bpf_internal_load_pointer_neg_helper(skb, k, size); -} - /** * sk_filter - run a packet through a socket filter * @sk: sock associated with &sk_buff @@ -537,7 +528,7 @@ load_word: * BPF_R0 - 8/16/32-bit skb data converted to cpu endianness */ - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp); + ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp); if (likely(ptr != NULL)) { BPF_R0 = get_unaligned_be32(ptr); CONT; @@ -547,7 +538,7 @@ load_word: LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */ off = IMM; load_half: - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp); + ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp); if (likely(ptr != NULL)) { BPF_R0 = get_unaligned_be16(ptr); CONT; @@ -557,7 +548,7 @@ load_half: LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */ off = IMM; load_byte: - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp); + ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp); if (likely(ptr != NULL)) { BPF_R0 = *(u8 *)ptr; CONT;