diff mbox series

[net-next,3/6] net: mvneta: update mb bit before passing the xdp buffer to eBPF layer

Message ID 08f8656e906ff69bd30915a6a37a01d5f0422194.1597842004.git.lorenzo@kernel.org
State Changes Requested
Delegated to: David Miller
Headers show
Series mvneta: introduce XDP multi-buffer support | expand

Commit Message

Lorenzo Bianconi Aug. 19, 2020, 1:13 p.m. UTC
Update multi-buffer bit (mb) in xdp_buff to notify XDP/eBPF layer and
XDP remote drivers if this is a "non-linear" XDP buffer

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/marvell/mvneta.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jesper Dangaard Brouer Aug. 20, 2020, 8:02 a.m. UTC | #1
On Wed, 19 Aug 2020 15:13:48 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Update multi-buffer bit (mb) in xdp_buff to notify XDP/eBPF layer and
> XDP remote drivers if this is a "non-linear" XDP buffer
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/marvell/mvneta.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> index 832bbb8b05c8..36a3defa63fa 100644
> --- a/drivers/net/ethernet/marvell/mvneta.c
> +++ b/drivers/net/ethernet/marvell/mvneta.c
> @@ -2170,11 +2170,14 @@ mvneta_run_xdp(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
>  	       struct bpf_prog *prog, struct xdp_buff *xdp,
>  	       u32 frame_sz, struct mvneta_stats *stats)
>  {
> +	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
>  	unsigned int len, data_len, sync;
>  	u32 ret, act;
>  
>  	len = xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction;
>  	data_len = xdp->data_end - xdp->data;
> +
> +	xdp->mb = !!sinfo->nr_frags;
>  	act = bpf_prog_run_xdp(prog, xdp);

Reading the memory sinfo->nr_frags could be a performance issue for our
baseline case of no-multi-buffer.  As you are reading a cache-line that
you don't need to (and driver have not touch yet).
Lorenzo Bianconi Aug. 20, 2020, 8:11 a.m. UTC | #2
> On Wed, 19 Aug 2020 15:13:48 +0200
> Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> 
> > Update multi-buffer bit (mb) in xdp_buff to notify XDP/eBPF layer and
> > XDP remote drivers if this is a "non-linear" XDP buffer
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  drivers/net/ethernet/marvell/mvneta.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> > index 832bbb8b05c8..36a3defa63fa 100644
> > --- a/drivers/net/ethernet/marvell/mvneta.c
> > +++ b/drivers/net/ethernet/marvell/mvneta.c
> > @@ -2170,11 +2170,14 @@ mvneta_run_xdp(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
> >  	       struct bpf_prog *prog, struct xdp_buff *xdp,
> >  	       u32 frame_sz, struct mvneta_stats *stats)
> >  {
> > +	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
> >  	unsigned int len, data_len, sync;
> >  	u32 ret, act;
> >  
> >  	len = xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction;
> >  	data_len = xdp->data_end - xdp->data;
> > +
> > +	xdp->mb = !!sinfo->nr_frags;
> >  	act = bpf_prog_run_xdp(prog, xdp);
> 
> Reading the memory sinfo->nr_frags could be a performance issue for our
> baseline case of no-multi-buffer.  As you are reading a cache-line that
> you don't need to (and driver have not touch yet).

ack, I will rework it in v2 to remove this access.

Regards,
Lorenzo

> 
> -- 
> Best regards,
>   Jesper Dangaard Brouer
>   MSc.CS, Principal Kernel Engineer at Red Hat
>   LinkedIn: http://www.linkedin.com/in/brouer
>
Maciej Fijalkowski Aug. 20, 2020, 7:38 p.m. UTC | #3
On Wed, Aug 19, 2020 at 03:13:48PM +0200, Lorenzo Bianconi wrote:
> Update multi-buffer bit (mb) in xdp_buff to notify XDP/eBPF layer and
> XDP remote drivers if this is a "non-linear" XDP buffer
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/marvell/mvneta.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> index 832bbb8b05c8..36a3defa63fa 100644
> --- a/drivers/net/ethernet/marvell/mvneta.c
> +++ b/drivers/net/ethernet/marvell/mvneta.c
> @@ -2170,11 +2170,14 @@ mvneta_run_xdp(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
>  	       struct bpf_prog *prog, struct xdp_buff *xdp,
>  	       u32 frame_sz, struct mvneta_stats *stats)
>  {
> +	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
>  	unsigned int len, data_len, sync;
>  	u32 ret, act;
>  
>  	len = xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction;
>  	data_len = xdp->data_end - xdp->data;
> +
> +	xdp->mb = !!sinfo->nr_frags;

But this set is not utilizing it from BPF side in any way. Personally I
would like to see this as a part of work where BPF program would actually
be taught how to rely on xdp->mb. Especially after John's comment in other
patch.

>  	act = bpf_prog_run_xdp(prog, xdp);
>  
>  	/* Due xdp_adjust_tail: DMA sync for_device cover max len CPU touch */
> -- 
> 2.26.2
>
Lorenzo Bianconi Aug. 21, 2020, 7:43 a.m. UTC | #4
On Aug 20, Maciej Fijalkowski wrote:
> On Wed, Aug 19, 2020 at 03:13:48PM +0200, Lorenzo Bianconi wrote:
> > Update multi-buffer bit (mb) in xdp_buff to notify XDP/eBPF layer and
> > XDP remote drivers if this is a "non-linear" XDP buffer
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >  drivers/net/ethernet/marvell/mvneta.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
> > index 832bbb8b05c8..36a3defa63fa 100644
> > --- a/drivers/net/ethernet/marvell/mvneta.c
> > +++ b/drivers/net/ethernet/marvell/mvneta.c
> > @@ -2170,11 +2170,14 @@ mvneta_run_xdp(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
> >  	       struct bpf_prog *prog, struct xdp_buff *xdp,
> >  	       u32 frame_sz, struct mvneta_stats *stats)
> >  {
> > +	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
> >  	unsigned int len, data_len, sync;
> >  	u32 ret, act;
> >  
> >  	len = xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction;
> >  	data_len = xdp->data_end - xdp->data;
> > +
> > +	xdp->mb = !!sinfo->nr_frags;
> 
> But this set is not utilizing it from BPF side in any way. Personally I
> would like to see this as a part of work where BPF program would actually
> be taught how to rely on xdp->mb. Especially after John's comment in other
> patch.
> 

Sameeh is working on them. I did not include the patches since IMO they are
not strictly related to this series. I will include Sameeh's patches in v2.

Regards,
Lorenzo

> >  	act = bpf_prog_run_xdp(prog, xdp);
> >  
> >  	/* Due xdp_adjust_tail: DMA sync for_device cover max len CPU touch */
> > -- 
> > 2.26.2
> > 
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index 832bbb8b05c8..36a3defa63fa 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -2170,11 +2170,14 @@  mvneta_run_xdp(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
 	       struct bpf_prog *prog, struct xdp_buff *xdp,
 	       u32 frame_sz, struct mvneta_stats *stats)
 {
+	struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
 	unsigned int len, data_len, sync;
 	u32 ret, act;
 
 	len = xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction;
 	data_len = xdp->data_end - xdp->data;
+
+	xdp->mb = !!sinfo->nr_frags;
 	act = bpf_prog_run_xdp(prog, xdp);
 
 	/* Due xdp_adjust_tail: DMA sync for_device cover max len CPU touch */