netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 net-next] net: filter: move load_pointer() into filter.h
@ 2014-07-03 14:56 Zi Shen Lim
  2014-07-03 15:03 ` Daniel Borkmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zi Shen Lim @ 2014-07-03 14:56 UTC (permalink / raw)
  To: David S. Miller
  Cc: Zi Shen Lim, Daniel Borkmann, Alexei Starovoitov, netdev,
	linux-kernel

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 <zlim.lnx@gmail.com>
---
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 <linux/atomic.h>
 #include <linux/compat.h>
+#include <linux/skbuff.h>
 #include <linux/workqueue.h>
 #include <uapi/linux/filter.h>
 
@@ -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 <stdarg.h>
 #include <linux/linkage.h>
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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCHv2 net-next] net: filter: move load_pointer() into filter.h
  2014-07-03 14:56 [PATCHv2 net-next] net: filter: move load_pointer() into filter.h Zi Shen Lim
@ 2014-07-03 15:03 ` Daniel Borkmann
  2014-07-03 17:23 ` Alexei Starovoitov
  2014-07-08 21:11 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2014-07-03 15:03 UTC (permalink / raw)
  To: Zi Shen Lim; +Cc: David S. Miller, Alexei Starovoitov, netdev, linux-kernel

On 07/03/2014 04:56 PM, Zi Shen Lim wrote:
> 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 <zlim.lnx@gmail.com>

Reviewed-by: Daniel Borkmann <dborkman@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2 net-next] net: filter: move load_pointer() into filter.h
  2014-07-03 14:56 [PATCHv2 net-next] net: filter: move load_pointer() into filter.h Zi Shen Lim
  2014-07-03 15:03 ` Daniel Borkmann
@ 2014-07-03 17:23 ` Alexei Starovoitov
  2014-07-08 21:11 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2014-07-03 17:23 UTC (permalink / raw)
  To: Zi Shen Lim; +Cc: David S. Miller, Daniel Borkmann, Network Development, LKML

On Thu, Jul 3, 2014 at 7:56 AM, Zi Shen Lim <zlim.lnx@gmail.com> wrote:
> 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 <zlim.lnx@gmail.com>

Acked-by: Alexei Starovoitov <ast@plumgrid.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2 net-next] net: filter: move load_pointer() into filter.h
  2014-07-03 14:56 [PATCHv2 net-next] net: filter: move load_pointer() into filter.h Zi Shen Lim
  2014-07-03 15:03 ` Daniel Borkmann
  2014-07-03 17:23 ` Alexei Starovoitov
@ 2014-07-08 21:11 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-07-08 21:11 UTC (permalink / raw)
  To: zlim.lnx; +Cc: dborkman, ast, netdev, linux-kernel

From: Zi Shen Lim <zlim.lnx@gmail.com>
Date: Thu,  3 Jul 2014 07:56:54 -0700

> 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 <zlim.lnx@gmail.com>
> ---
> v1->v2:
> * Renamed to more specific name of bpf_load_pointer(), as suggested
>   by Daniel.

Applied, thank you.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-08 21:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-03 14:56 [PATCHv2 net-next] net: filter: move load_pointer() into filter.h Zi Shen Lim
2014-07-03 15:03 ` Daniel Borkmann
2014-07-03 17:23 ` Alexei Starovoitov
2014-07-08 21:11 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).