From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH iproute2 master] bpf: provide fallback defs for __NR_bpf when not avail Date: Wed, 14 Jun 2017 16:34:08 -0700 Message-ID: <20170614163408.4a04c191@xeon-e3> References: <20170614155648.4cfd7a73@xeon-e3> <5941C03A.6010107@iogearbox.net> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: alexei.starovoitov@gmail.com, netdev@vger.kernel.org To: Daniel Borkmann Return-path: Received: from mail-pg0-f46.google.com ([74.125.83.46]:33043 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752121AbdFNXeQ (ORCPT ); Wed, 14 Jun 2017 19:34:16 -0400 Received: by mail-pg0-f46.google.com with SMTP id f185so6713399pgc.0 for ; Wed, 14 Jun 2017 16:34:15 -0700 (PDT) In-Reply-To: <5941C03A.6010107@iogearbox.net> Sender: netdev-owner@vger.kernel.org List-ID: On Thu, 15 Jun 2017 01:01:14 +0200 Daniel Borkmann wrote: > On 06/15/2017 12:56 AM, Stephen Hemminger wrote: > > On Thu, 15 Jun 2017 00:47:15 +0200 > > Daniel Borkmann wrote: > > > >> panji reported that he wasn't able to build iproute2's bpf library > >> due to lack of __NR_bpf in his system headers. Providing a fallback > >> definition when __NR_bpf is not available in the system lets the > >> loader compile just fine, so lets add them for majority of archs. > >> > >> Reported-by: panji > >> Signed-off-by: Daniel Borkmann > >> --- > >> lib/bpf.c | 20 ++++++++++++++++++++ > >> 1 file changed, 20 insertions(+) > >> > >> diff --git a/lib/bpf.c b/lib/bpf.c > >> index ae4d97d..e1e29cc 100644 > >> --- a/lib/bpf.c > >> +++ b/lib/bpf.c > >> @@ -128,6 +128,26 @@ static inline __u64 bpf_ptr_to_u64(const void *ptr) > >> return (__u64)(unsigned long)ptr; > >> } > >> > >> +#ifndef __NR_bpf > >> +# if defined(__i386__) > >> +# define __NR_bpf 357 > >> +# elif defined(__x86_64__) > >> +# define __NR_bpf 321 > >> +# elif defined(__aarch64__) > >> +# define __NR_bpf 280 > >> +# elif defined(__sparc__) > >> +# define __NR_bpf 349 > >> +# elif defined(__arm__) > >> +# define __NR_bpf 386 > >> +# elif defined(__powerpc__) > >> +# define __NR_bpf 361 > >> +# elif defined(__s390__) > >> +# define __NR_bpf 351 > >> +# else > >> +# error __NR_bpf not defined. Update kernel headers. > >> +# endif > >> +#endif > >> + > >> static int bpf(int cmd, union bpf_attr *attr, unsigned int size) > >> { > >> #ifdef __NR_bpf > > > > Sorry this looks like a mess. enumerating architectures in two different > > projects is likely to break in future. > > It says ifndef __NR_bpf, so only used then. And the numbers are uabi, > what will break here exactly? libbpf in kernel tree is having a similar > approach by the way. You are defining values in two places (kernel and userspace) which has caused lots of mismatch in the past. Why isn't this in a kernel uapi header somewhere?