* [PATCH bpf-next] xdp: introduce convert_to_xdp_buff utility routine
@ 2020-05-26 13:48 Lorenzo Bianconi
2020-05-26 14:20 ` Jesper Dangaard Brouer
0 siblings, 1 reply; 3+ messages in thread
From: Lorenzo Bianconi @ 2020-05-26 13:48 UTC (permalink / raw)
To: bpf, netdev
Cc: ast, davem, brouer, daniel, lorenzo.bianconi, dsahern, toshiaki.makita1
Introduce convert_to_xdp_buff utility routine to initialize xdp_buff
fields from xdp_frames ones. Rely on convert_to_xdp_buff in veth xdp
code
Suggested-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
drivers/net/veth.c | 12 ++----------
include/net/xdp.h | 10 ++++++++++
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index b586d2fa5551..dfbe553f967e 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -559,27 +559,19 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
struct veth_xdp_tx_bq *bq,
struct veth_stats *stats)
{
- void *hard_start = frame->data - frame->headroom;
int len = frame->len, delta = 0;
struct xdp_frame orig_frame;
struct bpf_prog *xdp_prog;
unsigned int headroom;
struct sk_buff *skb;
- /* bpf_xdp_adjust_head() assures BPF cannot access xdp_frame area */
- hard_start -= sizeof(struct xdp_frame);
-
rcu_read_lock();
xdp_prog = rcu_dereference(rq->xdp_prog);
if (likely(xdp_prog)) {
struct xdp_buff xdp;
u32 act;
- xdp.data_hard_start = hard_start;
- xdp.data = frame->data;
- xdp.data_end = frame->data + frame->len;
- xdp.data_meta = frame->data - frame->metasize;
- xdp.frame_sz = frame->frame_sz;
+ convert_to_xdp_buff(frame, &xdp);
xdp.rxq = &rq->xdp_rxq;
act = bpf_prog_run_xdp(xdp_prog, &xdp);
@@ -626,7 +618,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
rcu_read_unlock();
headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
- skb = veth_build_skb(hard_start, headroom, len, frame->frame_sz);
+ skb = veth_build_skb(frame, headroom, len, frame->frame_sz);
if (!skb) {
xdp_return_frame(frame);
stats->rx_drops++;
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 90f11760bd12..5dbdd65866a9 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -106,6 +106,16 @@ void xdp_warn(const char *msg, const char *func, const int line);
struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
+static inline
+void convert_to_xdp_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
+{
+ xdp->data_hard_start = (void *)frame;
+ xdp->data = frame->data;
+ xdp->data_end = frame->data + frame->len;
+ xdp->data_meta = frame->data - frame->metasize;
+ xdp->frame_sz = frame->frame_sz;
+}
+
/* Convert xdp_buff to xdp_frame */
static inline
struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] xdp: introduce convert_to_xdp_buff utility routine
2020-05-26 13:48 [PATCH bpf-next] xdp: introduce convert_to_xdp_buff utility routine Lorenzo Bianconi
@ 2020-05-26 14:20 ` Jesper Dangaard Brouer
2020-05-26 14:33 ` Lorenzo Bianconi
0 siblings, 1 reply; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2020-05-26 14:20 UTC (permalink / raw)
To: Lorenzo Bianconi
Cc: bpf, netdev, ast, davem, daniel, lorenzo.bianconi, dsahern,
toshiaki.makita1, brouer
On Tue, 26 May 2020 15:48:13 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> Introduce convert_to_xdp_buff utility routine to initialize xdp_buff
> fields from xdp_frames ones. Rely on convert_to_xdp_buff in veth xdp
> code
>
> Suggested-by: Jesper Dangaard Brouer <brouer@redhat.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/net/veth.c | 12 ++----------
> include/net/xdp.h | 10 ++++++++++
> 2 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index b586d2fa5551..dfbe553f967e 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -559,27 +559,19 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
> struct veth_xdp_tx_bq *bq,
> struct veth_stats *stats)
> {
> - void *hard_start = frame->data - frame->headroom;
> int len = frame->len, delta = 0;
> struct xdp_frame orig_frame;
> struct bpf_prog *xdp_prog;
> unsigned int headroom;
> struct sk_buff *skb;
>
> - /* bpf_xdp_adjust_head() assures BPF cannot access xdp_frame area */
> - hard_start -= sizeof(struct xdp_frame);
> -
> rcu_read_lock();
> xdp_prog = rcu_dereference(rq->xdp_prog);
> if (likely(xdp_prog)) {
> struct xdp_buff xdp;
> u32 act;
>
> - xdp.data_hard_start = hard_start;
> - xdp.data = frame->data;
> - xdp.data_end = frame->data + frame->len;
> - xdp.data_meta = frame->data - frame->metasize;
> - xdp.frame_sz = frame->frame_sz;
> + convert_to_xdp_buff(frame, &xdp);
> xdp.rxq = &rq->xdp_rxq;
>
> act = bpf_prog_run_xdp(xdp_prog, &xdp);
> @@ -626,7 +618,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
> rcu_read_unlock();
>
> headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
> - skb = veth_build_skb(hard_start, headroom, len, frame->frame_sz);
> + skb = veth_build_skb(frame, headroom, len, frame->frame_sz);
> if (!skb) {
> xdp_return_frame(frame);
> stats->rx_drops++;
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 90f11760bd12..5dbdd65866a9 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -106,6 +106,16 @@ void xdp_warn(const char *msg, const char *func, const int line);
>
> struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
>
> +static inline
> +void convert_to_xdp_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
> +{
> + xdp->data_hard_start = (void *)frame;
This assumption is problematic. You are suppose to deduct this from
frame->data pointer.
Currently the xdp_frame is designed and access such that is is possible
to use another memory area for xdp_frame. That would break after this
change.
This should instead be:
xdp->data_hard_start = frame->data - (frame->headroom + sizeof(struct xdp_frame));
> + xdp->data = frame->data;
> + xdp->data_end = frame->data + frame->len;
> + xdp->data_meta = frame->data - frame->metasize;
> + xdp->frame_sz = frame->frame_sz;
> +}
> +
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] xdp: introduce convert_to_xdp_buff utility routine
2020-05-26 14:20 ` Jesper Dangaard Brouer
@ 2020-05-26 14:33 ` Lorenzo Bianconi
0 siblings, 0 replies; 3+ messages in thread
From: Lorenzo Bianconi @ 2020-05-26 14:33 UTC (permalink / raw)
To: Jesper Dangaard Brouer
Cc: bpf, netdev, ast, davem, daniel, lorenzo.bianconi, dsahern,
toshiaki.makita1
[-- Attachment #1: Type: text/plain, Size: 1387 bytes --]
> On Tue, 26 May 2020 15:48:13 +0200
> Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
[...]
> > diff --git a/include/net/xdp.h b/include/net/xdp.h
> > index 90f11760bd12..5dbdd65866a9 100644
> > --- a/include/net/xdp.h
> > +++ b/include/net/xdp.h
> > @@ -106,6 +106,16 @@ void xdp_warn(const char *msg, const char *func, const int line);
> >
> > struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
> >
> > +static inline
> > +void convert_to_xdp_buff(struct xdp_frame *frame, struct xdp_buff *xdp)
> > +{
> > + xdp->data_hard_start = (void *)frame;
>
> This assumption is problematic. You are suppose to deduct this from
> frame->data pointer.
>
> Currently the xdp_frame is designed and access such that is is possible
> to use another memory area for xdp_frame. That would break after this
> change.
>
> This should instead be:
>
> xdp->data_hard_start = frame->data - (frame->headroom + sizeof(struct xdp_frame));
ack, fine. I will fix it v2.
Regards,
Lorenzo
>
> > + xdp->data = frame->data;
> > + xdp->data_end = frame->data + frame->len;
> > + xdp->data_meta = frame->data - frame->metasize;
> > + xdp->frame_sz = frame->frame_sz;
> > +}
> > +
>
> --
> Best regards,
> Jesper Dangaard Brouer
> MSc.CS, Principal Kernel Engineer at Red Hat
> LinkedIn: http://www.linkedin.com/in/brouer
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-26 14:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 13:48 [PATCH bpf-next] xdp: introduce convert_to_xdp_buff utility routine Lorenzo Bianconi
2020-05-26 14:20 ` Jesper Dangaard Brouer
2020-05-26 14:33 ` Lorenzo Bianconi
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).