Netdev Archive on lore.kernel.org
 help / color / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, davem@davemloft.net,
	ast@kernel.org, brouer@redhat.com, toke@redhat.com,
	lorenzo.bianconi@redhat.com, dsahern@kernel.org,
	andrii.nakryiko@gmail.com
Subject: Re: [PATCH v5 bpf-next 5/9] bpf: cpumap: add the possibility to attach an eBPF program to cpumap
Date: Fri, 3 Jul 2020 17:46:28 +0200
Message-ID: <20200703154628.GA1321275@localhost.localdomain> (raw)
In-Reply-To: <cb2f7b80-7c0f-4f96-6285-87cc615c7484@iogearbox.net>


[-- Attachment #1: Type: text/plain, Size: 2334 bytes --]

> On 6/30/20 2:49 PM, Lorenzo Bianconi wrote:
> [...]

[...]

> > +	prog = READ_ONCE(rcpu->prog);
> 
> What purpose does the READ_ONCE() have here, also given you don't use it in above check?
> Since upon map update you realloc, repopulate and then xchg() the rcpu entry itself, there
> is never the case where you xchg() or WRITE_ONCE() the rcpu->prog, so what does READ_ONCE()
> serve in this context? Imho, it should probably just be deleted and plain rcpu->prog used
> to avoid confusion.

Hi Daniel,

ack, I will fix it in v6

> 
> > +	for (i = 0; i < n; i++) {
> > +		struct xdp_frame *xdpf = frames[i];
> > +		u32 act;
> > +		int err;
> > +
> > +		rxq.dev = xdpf->dev_rx;
> > +		rxq.mem = xdpf->mem;
> > +		/* TODO: report queue_index to xdp_rxq_info */
> > +
> > +		xdp_convert_frame_to_buff(xdpf, &xdp);
> > +
> > +		act = bpf_prog_run_xdp(prog, &xdp);
> > +		switch (act) {
> > +		case XDP_PASS:
> > +			err = xdp_update_frame_from_buff(&xdp, xdpf);
> > +			if (err < 0) {
> > +				xdp_return_frame(xdpf);
> > +				stats->drop++;
> > +			} else {
> > +				frames[nframes++] = xdpf;
> > +				stats->pass++;
> > +			}
> > +			break;
> > +		default:
> > +			bpf_warn_invalid_xdp_action(act);
> > +			/* fallthrough */
> > +		case XDP_DROP:
> > +			xdp_return_frame(xdpf);
> > +			stats->drop++;
> > +			break;
> > +		}
> > +	}
> > +
> > +	xdp_clear_return_frame_no_direct();
> > +
> > +	rcu_read_unlock();
> > +
> > +	return nframes;
> > +}
> [...]
> > +bool cpu_map_prog_allowed(struct bpf_map *map)
> > +{
> > +	return map->map_type == BPF_MAP_TYPE_CPUMAP &&
> > +	       map->value_size != offsetofend(struct bpf_cpumap_val, qsize);
> > +}
> > +
> > +static int __cpu_map_load_bpf_program(struct bpf_cpu_map_entry *rcpu, int fd)
> > +{
> > +	struct bpf_prog *prog;
> > +
> > +	prog = bpf_prog_get_type_dev(fd, BPF_PROG_TYPE_XDP, false);
> 
> Nit: why the _dev variant; just use bpf_prog_get_type()?

ack, I will fix in v6

Regards,
Lorenzo

> 
> > +	if (IS_ERR(prog))
> > +		return PTR_ERR(prog);
> > +
> > +	if (prog->expected_attach_type != BPF_XDP_CPUMAP) {
> > +		bpf_prog_put(prog);
> > +		return -EINVAL;
> > +	}
> > +
> > +	rcpu->value.bpf_prog.id = prog->aux->id;
> > +	rcpu->prog = prog;
> > +
> > +	return 0;
> > +}
> > +

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply index

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 12:49 [PATCH v5 bpf-next 0/9] introduce support for XDP programs in CPUMAP Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 1/9] cpumap: use non-locked version __ptr_ring_consume_batched Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 2/9] net: refactor xdp_convert_buff_to_frame Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 3/9] samples/bpf: xdp_redirect_cpu_user: do not update bpf maps in option loop Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 4/9] cpumap: formalize map value as a named struct Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 5/9] bpf: cpumap: add the possibility to attach an eBPF program to cpumap Lorenzo Bianconi
2020-07-01 23:02   ` Daniel Borkmann
2020-07-03 15:46     ` Lorenzo Bianconi [this message]
2020-07-01 23:39   ` Daniel Borkmann
2020-07-03 20:48     ` Lorenzo Bianconi
2020-07-03 22:24       ` Daniel Borkmann
2020-06-30 12:49 ` [PATCH v5 bpf-next 6/9] bpf: cpumap: implement XDP_REDIRECT for eBPF programs attached to map entries Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 7/9] libbpf: add SEC name for xdp programs attached to CPUMAP Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 8/9] samples/bpf: xdp_redirect_cpu: load a eBPF program on cpumap Lorenzo Bianconi
2020-06-30 12:49 ` [PATCH v5 bpf-next 9/9] selftest: add tests for XDP programs in CPUMAP entries Lorenzo Bianconi

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=20200703154628.GA1321275@localhost.localdomain \
    --to=lorenzo@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=toke@redhat.com \
    /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

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git