diff mbox

[RFC,v4,02/18] bpf: Move u64_to_ptr() to BPF headers and inline it

Message ID 20161026065654.19166-3-mic@digikod.net (mailing list archive)
State New, archived
Headers show

Commit Message

Mickaël Salaün Oct. 26, 2016, 6:56 a.m. UTC
This helper will be useful for arraymap (next commit).

Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Daniel Borkmann <daniel@iogearbox.net>
---
 include/linux/bpf.h  | 6 ++++++
 kernel/bpf/syscall.c | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)

Comments

Arnd Bergmann Oct. 26, 2016, 7:19 a.m. UTC | #1
On Wednesday, October 26, 2016 8:56:38 AM CEST Mickaël Salaün wrote:
>  include/linux/bpf.h  | 6 ++++++
>  kernel/bpf/syscall.c | 6 ------
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index c201017b5730..cf87db6daf27 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -283,6 +283,12 @@ static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
>  
>  /* verify correctness of eBPF program */
>  int bpf_check(struct bpf_prog **fp, union bpf_attr *attr);
> +
> +/* helper to convert user pointers passed inside __aligned_u64 fields */
> +static inline void __user *u64_to_ptr(__u64 val)
> +{
> +       return (void __user *) (unsigned long) val;
> +}
>  #else
> 


We already have at least six copies of this helper:

fs/btrfs/qgroup.c:#define u64_to_ptr(x) ((struct btrfs_qgroup *)(uintptr_t)x)
kernel/bpf/syscall.c:static void __user *u64_to_ptr(__u64 val)
drivers/staging/android/ion/ion_test.c:#define u64_to_uptr(x) ((void __user *)(unsigned long)(x))
drivers/firewire/core-cdev.c:static void __user *u64_to_uptr(u64 value)
drivers/staging/android/ion/ion_test.c:#define u64_to_uptr(x) ((void __user *)(unsigned long)(x))
include/linux/kernel.h:#define u64_to_user_ptr(x) (            \

Just use the one in linux/kernel.h

	Arnd
David Sterba Oct. 26, 2016, 1:52 p.m. UTC | #2
On Wed, Oct 26, 2016 at 09:19:08AM +0200, Arnd Bergmann wrote:
> On Wednesday, October 26, 2016 8:56:38 AM CEST Mickaël Salaün wrote:
> >  include/linux/bpf.h  | 6 ++++++
> >  kernel/bpf/syscall.c | 6 ------
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index c201017b5730..cf87db6daf27 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -283,6 +283,12 @@ static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
> >  
> >  /* verify correctness of eBPF program */
> >  int bpf_check(struct bpf_prog **fp, union bpf_attr *attr);
> > +
> > +/* helper to convert user pointers passed inside __aligned_u64 fields */
> > +static inline void __user *u64_to_ptr(__u64 val)
> > +{
> > +       return (void __user *) (unsigned long) val;
> > +}
> >  #else
> > 
> 
> 
> We already have at least six copies of this helper:
> 
> fs/btrfs/qgroup.c:#define u64_to_ptr(x) ((struct btrfs_qgroup *)(uintptr_t)x)

This one does not take __user pointers, unlike the rest. Anyway, the name is
misleading, I'll send a cleanup. Thanks.

> kernel/bpf/syscall.c:static void __user *u64_to_ptr(__u64 val)
> drivers/staging/android/ion/ion_test.c:#define u64_to_uptr(x) ((void __user *)(unsigned long)(x))
> drivers/firewire/core-cdev.c:static void __user *u64_to_uptr(u64 value)
> drivers/staging/android/ion/ion_test.c:#define u64_to_uptr(x) ((void __user *)(unsigned long)(x))
> include/linux/kernel.h:#define u64_to_user_ptr(x) (            \
> 
> Just use the one in linux/kernel.h
> 
> 	Arnd
diff mbox

Patch

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index c201017b5730..cf87db6daf27 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -283,6 +283,12 @@  static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
 
 /* verify correctness of eBPF program */
 int bpf_check(struct bpf_prog **fp, union bpf_attr *attr);
+
+/* helper to convert user pointers passed inside __aligned_u64 fields */
+static inline void __user *u64_to_ptr(__u64 val)
+{
+	return (void __user *) (unsigned long) val;
+}
 #else
 static inline void bpf_register_prog_type(struct bpf_prog_type_list *tl)
 {
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 1814c010ace6..13149c9cb3a4 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -252,12 +252,6 @@  struct bpf_map *bpf_map_get_with_uref(u32 ufd)
 	return map;
 }
 
-/* helper to convert user pointers passed inside __aligned_u64 fields */
-static void __user *u64_to_ptr(__u64 val)
-{
-	return (void __user *) (unsigned long) val;
-}
-
 int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value)
 {
 	return -ENOTSUPP;