netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 6/7] bpf: Add "live packet" mode for XDP in bpf_prog_run()
Date: Thu, 06 Jan 2022 15:28:41 +0100	[thread overview]
Message-ID: <871r1laqg6.fsf@toke.dk> (raw)
In-Reply-To: <20220106042618.kperh3ovyuckxecl@ast-mbp.dhcp.thefacebook.com>

Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:

> On Mon, Jan 03, 2022 at 04:08:11PM +0100, Toke Høiland-Jørgensen wrote:
>> +static void xdp_test_run_init_page(struct page *page, void *arg)
>> +{
>> +	struct xdp_page_head *head = phys_to_virt(page_to_phys(page));
>> +	struct xdp_buff *new_ctx, *orig_ctx;
>> +	u32 headroom = XDP_PACKET_HEADROOM;
>> +	struct xdp_test_data *xdp = arg;
>> +	size_t frm_len, meta_len;
>> +	struct xdp_frame *frm;
>> +	void *data;
>> +
>> +	orig_ctx = xdp->orig_ctx;
>> +	frm_len = orig_ctx->data_end - orig_ctx->data_meta;
>> +	meta_len = orig_ctx->data - orig_ctx->data_meta;
>> +	headroom -= meta_len;
>> +
>> +	new_ctx = &head->ctx;
>> +	frm = &head->frm;
>> +	data = &head->data;
>> +	memcpy(data + headroom, orig_ctx->data_meta, frm_len);
>> +
>> +	xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq);
>> +	xdp_prepare_buff(new_ctx, data, headroom, frm_len, true);
>> +	new_ctx->data_meta = new_ctx->data + meta_len;
>
> data vs data_meta is the other way around, no?
>
> Probably needs a selftest to make sure.

Yup, you're right; nice catch! Will fix and add a test for it.

>> +static int xdp_recv_frames(struct xdp_frame **frames, int nframes,
>> +			   struct net_device *dev)
>> +{
>> +	gfp_t gfp = __GFP_ZERO | GFP_ATOMIC;
>> +	void *skbs[TEST_XDP_BATCH];
>> +	int i, n;
>> +	LIST_HEAD(list);
>> +
>> +	n = kmem_cache_alloc_bulk(skbuff_head_cache, gfp, nframes, skbs);
>> +	if (unlikely(n == 0)) {
>> +		for (i = 0; i < nframes; i++)
>> +			xdp_return_frame(frames[i]);
>> +		return -ENOMEM;
>> +	}
>> +
>> +	for (i = 0; i < nframes; i++) {
>> +		struct xdp_frame *xdpf = frames[i];
>> +		struct sk_buff *skb = skbs[i];
>> +
>> +		skb = __xdp_build_skb_from_frame(xdpf, skb, dev);
>> +		if (!skb) {
>> +			xdp_return_frame(xdpf);
>> +			continue;
>> +		}
>> +
>> +		list_add_tail(&skb->list, &list);
>> +	}
>> +	netif_receive_skb_list(&list);
>
> Does it need local_bh_disable() like cpumap does?

Yes, I think it probably does, actually. Or at least having it can
potentially improve performance since we're then sure that the whole
batch will be processed at once. Will add!

> I've applied patches 1 - 5.

Thanks! Will respin this and the selftest :)


  reply	other threads:[~2022-01-06 14:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 15:08 [PATCH bpf-next v5 0/7] Add support for transmitting packets using XDP in bpf_prog_run() Toke Høiland-Jørgensen
2022-01-03 15:08 ` [PATCH bpf-next v5 1/7] xdp: Allow registering memory model without rxq reference Toke Høiland-Jørgensen
2022-01-03 15:08 ` [PATCH bpf-next v5 2/7] page_pool: Add callback to init pages when they are allocated Toke Høiland-Jørgensen
2022-01-05 11:01   ` Jesper Dangaard Brouer
2022-01-03 15:08 ` [PATCH bpf-next v5 3/7] page_pool: Store the XDP mem id Toke Høiland-Jørgensen
2022-01-05 11:02   ` Jesper Dangaard Brouer
2022-01-03 15:08 ` [PATCH bpf-next v5 4/7] xdp: Move conversion to xdp_frame out of map functions Toke Høiland-Jørgensen
2022-01-03 15:08 ` [PATCH bpf-next v5 5/7] xdp: add xdp_do_redirect_frame() for pre-computed xdp_frames Toke Høiland-Jørgensen
2022-01-03 15:08 ` [PATCH bpf-next v5 6/7] bpf: Add "live packet" mode for XDP in bpf_prog_run() Toke Høiland-Jørgensen
2022-01-06  4:26   ` Alexei Starovoitov
2022-01-06 14:28     ` Toke Høiland-Jørgensen [this message]
2022-01-03 15:08 ` [PATCH bpf-next v5 7/7] selftests/bpf: Add selftest for XDP_REDIRECT " Toke Høiland-Jørgensen
2022-01-06  4:20   ` Alexei Starovoitov
2022-01-06 14:34     ` Toke Høiland-Jørgensen
2022-01-06 17:18       ` Alexei Starovoitov
2022-01-06 18:21         ` Toke Høiland-Jørgensen
2022-01-06 19:56           ` Alexei Starovoitov
2022-01-06 20:20             ` Toke Høiland-Jørgensen

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=871r1laqg6.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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
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).