netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: <netdev@vger.kernel.org>, Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: Re: [PATCH v2 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG
Date: Tue, 13 Jun 2017 20:43:00 -0700	[thread overview]
Message-ID: <20170613204300.38580ec2@cakuba.netronome.com> (raw)
In-Reply-To: <20170614031953.5jcbtlcwetcjqodj@kridsdale-mbp.DHCP.thefacebook.com>

On Tue, 13 Jun 2017 20:19:53 -0700, Martin KaFai Lau wrote:
> On Tue, Jun 13, 2017 at 07:19:50PM -0700, Jakub Kicinski wrote:
> > On Tue, 13 Jun 2017 17:37:50 -0700, Martin KaFai Lau wrote:  
> > > On Tue, Jun 13, 2017 at 04:52:32PM -0700, Jakub Kicinski wrote:  
> > > > On Tue, 13 Jun 2017 14:08:40 -0700, Martin KaFai Lau wrote:  
> > > > > -	case XDP_QUERY_PROG:
> > > > > -		xdp->prog_attached = !!nn->dp.xdp_prog;
> > > > > +	case XDP_QUERY_PROG: {
> > > > > +		const struct bpf_prog *xdp_prog;
> > > > > +
> > > > > +		xdp_prog = nn->dp.xdp_prog;
> > > > > +		if (xdp_prog) {
> > > > > +			xdp->prog_id = xdp_prog->aux->id;
> > > > > +			xdp->prog_attached = true;
> > > > > +		} else {
> > > > > +			xdp->prog_id = 0;
> > > > > +			xdp->prog_attached = false;
> > > > > +		}
> > > > >  		return 0;
> > > > > +	}  
> > > >
> > > > I'm sorry to nit pick but it could be done on a single line:
> > > >
> > > > 	case XDP_QUERY_PROG:
> > > > 		xdp->prog_attached = !!nn->dp.xdp_prog;
> > > > +		xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;
> > > >  		return 0;
> > > >  	default:
> > > >  		return -EINVAL;  
> > > OK...
> > >  
> > > >
> > > >
> > > > What would be even cooler is a helper like this:
> > > >
> > > > static inline u32 bpf_prog_id(struct bpf_prog *prog)
> > > > {
> > > > 	if (!prog)
> > > > 		return 0;
> > > > 	return prog->aux->id;
> > > > }
> > > >
> > > > in linux/bpf.h.  
> > > Good idea.  
> >
> > You may actually have to add that into a source file, because bpf.h
> > does not know the definition of struct bpf_prog :(  
> Yeah. filter.h seems not working well either.
> It looks good to me at the first thought.  After a second thought,
> in the future, I am not so sure having a getter for every fields
> in bpf_prog.

Yes, if it's not a static inline it's far less appealing...
 
> I can put bpf_prog_id() in nfp_net_common.c only.
> or do 'xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;'
> as you suggested earlier also.
> I am fine either way.  Your call ;)

OK, let's do the ternary operator version then :)  Sorry for leading you
into this dead end.

  reply	other threads:[~2017-06-14  3:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-13 21:08 [PATCH v2 net-next 0/9] bpf: xdp: Report bpf_prog ID in IFLA_XDP Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 1/9] net: Add IFLA_XDP_PROG_ID Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 2/9] bpf: mlx4: Report bpf_prog ID during XDP_QUERY_PROG Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 3/9] bpf: mlx5e: " Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 4/9] bpf: virtio_net: " Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 5/9] bpf: bnxt: " Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 6/9] bpf: thunderx: " Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 7/9] bpf: ixgbe: " Martin KaFai Lau
2017-06-13 21:08 ` [PATCH v2 net-next 8/9] bpf: nfp: " Martin KaFai Lau
2017-06-13 23:52   ` Jakub Kicinski
2017-06-14  0:37     ` Martin KaFai Lau
2017-06-14  2:19       ` Jakub Kicinski
2017-06-14  3:19         ` Martin KaFai Lau
2017-06-14  3:43           ` Jakub Kicinski [this message]
2017-06-13 21:08 ` [PATCH v2 net-next 9/9] bpf: qede: " Martin KaFai Lau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170613204300.38580ec2@cakuba.netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).