mbox series

[iproute2/master,00/11] bpf: pass ifindex for bpf offload

Message ID 20171124021208.13419-1-jakub.kicinski@netronome.com
Headers show
Series bpf: pass ifindex for bpf offload | expand

Message

Jakub Kicinski Nov. 24, 2017, 2:11 a.m. UTC
Hi!

This series allows us to pass ifindex automatically when we
set up TC cls_bpf or XDP offload.  There is a fair bit of
refactoring to separate the parse and load stages of lib/bpf.c.
In case of TC the skip_sw flag may come after the program
arguments (e.g. "bpf obj prog.o da skip_sw"), so we can't
just load the program as we parse the arguments.  Note that
this impacts only loading of the program, all other supported
methods of finding a program (pinned, bytecode, bytefile-file)
are handled as previously, the load call will do nothing for
them.

To simplify the implementation f_bpf and m_bpf will no longer
allow specifying programs multiple times.  Device ifindex is 
also resolved before running filter-specific code.


Jakub Kicinski (11):
  bpf: pass program type in struct bpf_cfg_in
  bpf: keep parsed program mode in struct bpf_cfg_in
  bpf: allocate opcode table in struct bpf_cfg_in
  bpf: split parse from program loading
  bpf: rename bpf_parse_common() to bpf_parse_and_load_common()
  bpf: expose bpf_parse_common() and bpf_load_common()
  bpf: allow loading programs for a specific ifindex
  {f,m}_bpf: don't allow specifying multiple bpf programs
  tc_filter: resolve device name before parsing filter
  f_bpf: communicate ifindex for eBPF offload
  iplink: communicate ifindex for xdp offload

 include/bpf_util.h    |  25 +++++++-
 ip/iplink.c           |   4 +-
 ip/iplink_xdp.c       |  13 ++++-
 ip/iproute_lwtunnel.c |   3 +-
 ip/xdp.h              |   4 +-
 lib/bpf.c             | 155 ++++++++++++++++++++++++++++++--------------------
 tc/f_bpf.c            |  18 +++++-
 tc/m_bpf.c            |   6 +-
 tc/tc_filter.c        |  50 ++++++++--------
 9 files changed, 178 insertions(+), 100 deletions(-)

Comments

Stephen Hemminger Nov. 26, 2017, 7:59 p.m. UTC | #1
On Thu, 23 Nov 2017 18:11:57 -0800
Jakub Kicinski <jakub.kicinski@netronome.com> wrote:

> Hi!
> 
> This series allows us to pass ifindex automatically when we
> set up TC cls_bpf or XDP offload.  There is a fair bit of
> refactoring to separate the parse and load stages of lib/bpf.c.
> In case of TC the skip_sw flag may come after the program
> arguments (e.g. "bpf obj prog.o da skip_sw"), so we can't
> just load the program as we parse the arguments.  Note that
> this impacts only loading of the program, all other supported
> methods of finding a program (pinned, bytecode, bytefile-file)
> are handled as previously, the load call will do nothing for
> them.
> 
> To simplify the implementation f_bpf and m_bpf will no longer
> allow specifying programs multiple times.  Device ifindex is 
> also resolved before running filter-specific code.
> 
> 
> Jakub Kicinski (11):
>   bpf: pass program type in struct bpf_cfg_in
>   bpf: keep parsed program mode in struct bpf_cfg_in
>   bpf: allocate opcode table in struct bpf_cfg_in
>   bpf: split parse from program loading
>   bpf: rename bpf_parse_common() to bpf_parse_and_load_common()
>   bpf: expose bpf_parse_common() and bpf_load_common()
>   bpf: allow loading programs for a specific ifindex
>   {f,m}_bpf: don't allow specifying multiple bpf programs
>   tc_filter: resolve device name before parsing filter
>   f_bpf: communicate ifindex for eBPF offload
>   iplink: communicate ifindex for xdp offload
> 
>  include/bpf_util.h    |  25 +++++++-
>  ip/iplink.c           |   4 +-
>  ip/iplink_xdp.c       |  13 ++++-
>  ip/iproute_lwtunnel.c |   3 +-
>  ip/xdp.h              |   4 +-
>  lib/bpf.c             | 155 ++++++++++++++++++++++++++++++--------------------
>  tc/f_bpf.c            |  18 +++++-
>  tc/m_bpf.c            |   6 +-
>  tc/tc_filter.c        |  50 ++++++++--------
>  9 files changed, 178 insertions(+), 100 deletions(-)
> 


Looks good, applied. Thanks Jakub
Daniel Borkmann Nov. 29, 2017, 1:05 a.m. UTC | #2
Hi Stephen,

after merge of master into net-next branch the build is now broken
for BPF loader as follows:

# make

lib
make[1]: Entering directory '/home/darkstar/iproute2/lib'
    CC       libgenl.o
    CC       ll_map.o
    CC       libnetlink.o
libnetlink.c:120:2: warning: #warning "libmnl required for error support" [-Wcpp]
 #warning "libmnl required for error support"
  ^~~~~~~
    AR       libnetlink.a
    CC       utils.o
    CC       rt_names.o
    CC       ll_types.o
    CC       ll_proto.o
    CC       ll_addr.o
    CC       inet_proto.o
    CC       namespace.o
    CC       json_writer.o
    CC       json_print.o
    CC       names.o
    CC       color.o
    CC       bpf.o
bpf.c: In function ‘bpf_prog_load_dev’:
bpf.c:1080:6: error: ‘union bpf_attr’ has no member named ‘prog_ifindex’; did you mean ‘prog_id’?
  attr.prog_ifindex = ifindex;
      ^
../config.mk:39: recipe for target 'bpf.o' failed
make[1]: *** [bpf.o] Error 1
make[1]: Leaving directory '/home/darkstar/iproute2/lib'
Makefile:59: recipe for target 'all' failed
make: *** [all] Error 2

Can you rebase kernel headers to fix it, in net-next branch they
are not up to date which is why the build error occurs in combination
with below merged series?

Thanks,
Daniel


On 11/24/2017 03:11 AM, Jakub Kicinski wrote:
> Hi!
> 
> This series allows us to pass ifindex automatically when we
> set up TC cls_bpf or XDP offload.  There is a fair bit of
> refactoring to separate the parse and load stages of lib/bpf.c.
> In case of TC the skip_sw flag may come after the program
> arguments (e.g. "bpf obj prog.o da skip_sw"), so we can't
> just load the program as we parse the arguments.  Note that
> this impacts only loading of the program, all other supported
> methods of finding a program (pinned, bytecode, bytefile-file)
> are handled as previously, the load call will do nothing for
> them.
> 
> To simplify the implementation f_bpf and m_bpf will no longer
> allow specifying programs multiple times.  Device ifindex is 
> also resolved before running filter-specific code.
> 
> 
> Jakub Kicinski (11):
>   bpf: pass program type in struct bpf_cfg_in
>   bpf: keep parsed program mode in struct bpf_cfg_in
>   bpf: allocate opcode table in struct bpf_cfg_in
>   bpf: split parse from program loading
>   bpf: rename bpf_parse_common() to bpf_parse_and_load_common()
>   bpf: expose bpf_parse_common() and bpf_load_common()
>   bpf: allow loading programs for a specific ifindex
>   {f,m}_bpf: don't allow specifying multiple bpf programs
>   tc_filter: resolve device name before parsing filter
>   f_bpf: communicate ifindex for eBPF offload
>   iplink: communicate ifindex for xdp offload
> 
>  include/bpf_util.h    |  25 +++++++-
>  ip/iplink.c           |   4 +-
>  ip/iplink_xdp.c       |  13 ++++-
>  ip/iproute_lwtunnel.c |   3 +-
>  ip/xdp.h              |   4 +-
>  lib/bpf.c             | 155 ++++++++++++++++++++++++++++++--------------------
>  tc/f_bpf.c            |  18 +++++-
>  tc/m_bpf.c            |   6 +-
>  tc/tc_filter.c        |  50 ++++++++--------
>  9 files changed, 178 insertions(+), 100 deletions(-)
>
Stephen Hemminger Nov. 29, 2017, 2:15 a.m. UTC | #3
On Wed, 29 Nov 2017 02:05:09 +0100
Daniel Borkmann <daniel@iogearbox.net> wrote:

> Hi Stephen,
> 
> after merge of master into net-next branch the build is now broken
> for BPF loader as follows:
> 
> # make
> 
> lib
> make[1]: Entering directory '/home/darkstar/iproute2/lib'
>     CC       libgenl.o
>     CC       ll_map.o
>     CC       libnetlink.o
> libnetlink.c:120:2: warning: #warning "libmnl required for error support" [-Wcpp]
>  #warning "libmnl required for error support"
>   ^~~~~~~
>     AR       libnetlink.a
>     CC       utils.o
>     CC       rt_names.o
>     CC       ll_types.o
>     CC       ll_proto.o
>     CC       ll_addr.o
>     CC       inet_proto.o
>     CC       namespace.o
>     CC       json_writer.o
>     CC       json_print.o
>     CC       names.o
>     CC       color.o
>     CC       bpf.o
> bpf.c: In function ‘bpf_prog_load_dev’:
> bpf.c:1080:6: error: ‘union bpf_attr’ has no member named ‘prog_ifindex’; did you mean ‘prog_id’?
>   attr.prog_ifindex = ifindex;
>       ^
> ../config.mk:39: recipe for target 'bpf.o' failed
> make[1]: *** [bpf.o] Error 1
> make[1]: Leaving directory '/home/darkstar/iproute2/lib'
> Makefile:59: recipe for target 'all' failed
> make: *** [all] Error 2
> 
> Can you rebase kernel headers to fix it, in net-next branch they
> are not up to date which is why the build error occurs in combination
> with below merged series?
> 
> Thanks,
> Daniel
> 
> 
> On 11/24/2017 03:11 AM, Jakub Kicinski wrote:
> > Hi!
> > 
> > This series allows us to pass ifindex automatically when we
> > set up TC cls_bpf or XDP offload.  There is a fair bit of
> > refactoring to separate the parse and load stages of lib/bpf.c.
> > In case of TC the skip_sw flag may come after the program
> > arguments (e.g. "bpf obj prog.o da skip_sw"), so we can't
> > just load the program as we parse the arguments.  Note that
> > this impacts only loading of the program, all other supported
> > methods of finding a program (pinned, bytecode, bytefile-file)
> > are handled as previously, the load call will do nothing for
> > them.
> > 
> > To simplify the implementation f_bpf and m_bpf will no longer
> > allow specifying programs multiple times.  Device ifindex is 
> > also resolved before running filter-specific code.
> > 
> > 
> > Jakub Kicinski (11):
> >   bpf: pass program type in struct bpf_cfg_in
> >   bpf: keep parsed program mode in struct bpf_cfg_in
> >   bpf: allocate opcode table in struct bpf_cfg_in
> >   bpf: split parse from program loading
> >   bpf: rename bpf_parse_common() to bpf_parse_and_load_common()
> >   bpf: expose bpf_parse_common() and bpf_load_common()
> >   bpf: allow loading programs for a specific ifindex
> >   {f,m}_bpf: don't allow specifying multiple bpf programs
> >   tc_filter: resolve device name before parsing filter
> >   f_bpf: communicate ifindex for eBPF offload
> >   iplink: communicate ifindex for xdp offload
> > 
> >  include/bpf_util.h    |  25 +++++++-
> >  ip/iplink.c           |   4 +-
> >  ip/iplink_xdp.c       |  13 ++++-
> >  ip/iproute_lwtunnel.c |   3 +-
> >  ip/xdp.h              |   4 +-
> >  lib/bpf.c             | 155 ++++++++++++++++++++++++++++++--------------------
> >  tc/f_bpf.c            |  18 +++++-
> >  tc/m_bpf.c            |   6 +-
> >  tc/tc_filter.c        |  50 ++++++++--------
> >  9 files changed, 178 insertions(+), 100 deletions(-)
> >   
> 

Are you using your own uapi headers?
On current master branch...

$ git grep prog_ifindex
include/uapi/linux/bpf.h:               __u32           prog_ifindex;   /* ifindex of netdev to prep for */
lib/bpf.c:      attr.prog_ifindex = ifindex;
Stephen Hemminger Nov. 29, 2017, 2:17 a.m. UTC | #4
On Wed, 29 Nov 2017 02:05:09 +0100
Daniel Borkmann <daniel@iogearbox.net> wrote:

> Hi Stephen,
> 
> after merge of master into net-next branch the build is now broken
> for BPF loader as follows:
> 
> # make
> 
> lib
> make[1]: Entering directory '/home/darkstar/iproute2/lib'
>     CC       libgenl.o
>     CC       ll_map.o
>     CC       libnetlink.o
> libnetlink.c:120:2: warning: #warning "libmnl required for error support" [-Wcpp]
>  #warning "libmnl required for error support"
>   ^~~~~~~
>     AR       libnetlink.a
>     CC       utils.o
>     CC       rt_names.o
>     CC       ll_types.o
>     CC       ll_proto.o
>     CC       ll_addr.o
>     CC       inet_proto.o
>     CC       namespace.o
>     CC       json_writer.o
>     CC       json_print.o
>     CC       names.o
>     CC       color.o
>     CC       bpf.o
> bpf.c: In function ‘bpf_prog_load_dev’:
> bpf.c:1080:6: error: ‘union bpf_attr’ has no member named ‘prog_ifindex’; did you mean ‘prog_id’?
>   attr.prog_ifindex = ifindex;
>       ^
> ../config.mk:39: recipe for target 'bpf.o' failed
> make[1]: *** [bpf.o] Error 1
> make[1]: Leaving directory '/home/darkstar/iproute2/lib'
> Makefile:59: recipe for target 'all' failed
> make: *** [all] Error 2
> 
> Can you rebase kernel headers to fix it, in net-next branch they
> are not up to date which is why the build error occurs in combination
> with below merged series?
> 
> Thanks,
> Daniel
> 
> 
> On 11/24/2017 03:11 AM, Jakub Kicinski wrote:
> > Hi!
> > 
> > This series allows us to pass ifindex automatically when we
> > set up TC cls_bpf or XDP offload.  There is a fair bit of
> > refactoring to separate the parse and load stages of lib/bpf.c.
> > In case of TC the skip_sw flag may come after the program
> > arguments (e.g. "bpf obj prog.o da skip_sw"), so we can't
> > just load the program as we parse the arguments.  Note that
> > this impacts only loading of the program, all other supported
> > methods of finding a program (pinned, bytecode, bytefile-file)
> > are handled as previously, the load call will do nothing for
> > them.
> > 
> > To simplify the implementation f_bpf and m_bpf will no longer
> > allow specifying programs multiple times.  Device ifindex is 
> > also resolved before running filter-specific code.
> > 
> > 
> > Jakub Kicinski (11):
> >   bpf: pass program type in struct bpf_cfg_in
> >   bpf: keep parsed program mode in struct bpf_cfg_in
> >   bpf: allocate opcode table in struct bpf_cfg_in
> >   bpf: split parse from program loading
> >   bpf: rename bpf_parse_common() to bpf_parse_and_load_common()
> >   bpf: expose bpf_parse_common() and bpf_load_common()
> >   bpf: allow loading programs for a specific ifindex
> >   {f,m}_bpf: don't allow specifying multiple bpf programs
> >   tc_filter: resolve device name before parsing filter
> >   f_bpf: communicate ifindex for eBPF offload
> >   iplink: communicate ifindex for xdp offload
> > 
> >  include/bpf_util.h    |  25 +++++++-
> >  ip/iplink.c           |   4 +-
> >  ip/iplink_xdp.c       |  13 ++++-
> >  ip/iproute_lwtunnel.c |   3 +-
> >  ip/xdp.h              |   4 +-
> >  lib/bpf.c             | 155 ++++++++++++++++++++++++++++++--------------------
> >  tc/f_bpf.c            |  18 +++++-
> >  tc/m_bpf.c            |   6 +-
> >  tc/tc_filter.c        |  50 ++++++++--------
> >  9 files changed, 178 insertions(+), 100 deletions(-)
> >   
> 

Sorry, net-next branch had out of date headers. Now fixed.
Daniel Borkmann Nov. 29, 2017, 9:09 a.m. UTC | #5
On 11/29/2017 03:17 AM, Stephen Hemminger wrote:
[...]
> Sorry, net-next branch had out of date headers. Now fixed.

Yeah, master worked fine. Thanks for the fix!