Re: [PATCH net] xsk: respect the offsets when copying frags

From: Jakub Kicinski
Date: Fri Apr 25 2025 - 20:23:52 EST


On Fri, 25 Apr 2025 22:46:35 +0700 Bui Quang Minh wrote:
> On 4/23/25 17:10, Bui Quang Minh wrote:
> > Add the missing offsets when copying frags in xdp_copy_frags_from_zc().
> >
> > Fixes: 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")
> > Signed-off-by: Bui Quang Minh <minhquangbui99@xxxxxxxxx>
> > ---
> > net/core/xdp.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/core/xdp.c b/net/core/xdp.c
> > index f86eedad586a..a723dc301f94 100644
> > --- a/net/core/xdp.c
> > +++ b/net/core/xdp.c
> > @@ -697,7 +697,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
> > nr_frags = xinfo->nr_frags;
> >
> > for (u32 i = 0; i < nr_frags; i++) {
> > - u32 len = skb_frag_size(&xinfo->frags[i]);
> > + const skb_frag_t *frag = &xinfo->frags[i];
> > + u32 len = skb_frag_size(frag);
> > u32 offset, truesize = len;
> > netmem_ref netmem;
> >
> > @@ -707,8 +708,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
> > return false;
> > }
> >
> > - memcpy(__netmem_address(netmem),
> > - __netmem_address(xinfo->frags[i].netmem),
> > + memcpy(__netmem_address(netmem) + offset,
> > + __netmem_address(frag->netmem) + skb_frag_off(frag),
> > LARGEST_ALIGN(len));
> > __skb_fill_netmem_desc_noacc(sinfo, i, netmem, offset, len);
> >
>
> I know it's very unlikely but do we need to
> kmap_local_page(skb_frag_page(frag) before using
> __netmem_address(frag->netmem) to make sure the frag's page is mapped?
> Or it is impossible that the frag's page to be highmem and unmapped?

AFAIU these frags come from a AF_XDP umem so they should be mapped
already.