Skip to content

Commit

Permalink
net: prepare for non devmem TCP memory providers
Browse files Browse the repository at this point in the history
There is a good bunch of places in generic paths assuming that the only
page pool memory provider is devmem TCP. As we want to reuse the net_iov
and provider infrastructure, we need to patch it up and explicitly check
the provider type when we branch into devmem TCP code.

Reviewed-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: David Wei <dw@davidwei.uk>
Link: https://patch.msgid.link/20250204215622.695511-9-dw@davidwei.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Pavel Begunkov authored and Jakub Kicinski committed Feb 7, 2025
1 parent f8350a4 commit 69e3953
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions net/core/devmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);

static const struct memory_provider_ops dmabuf_devmem_ops;

bool net_is_devmem_iov(struct net_iov *niov)
{
return niov->pp->mp_ops == &dmabuf_devmem_ops;
}

static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool,
struct gen_pool_chunk *chunk,
void *not_used)
Expand Down
7 changes: 7 additions & 0 deletions net/core/devmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ struct net_iov *
net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding);
void net_devmem_free_dmabuf(struct net_iov *ppiov);

bool net_is_devmem_iov(struct net_iov *niov);

#else
struct net_devmem_dmabuf_binding;

Expand Down Expand Up @@ -163,6 +165,11 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
{
return 0;
}

static inline bool net_is_devmem_iov(struct net_iov *niov)
{
return false;
}
#endif

#endif /* _NET_DEVMEM_H */
5 changes: 5 additions & 0 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,11 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb,
}

niov = skb_frag_net_iov(frag);
if (!net_is_devmem_iov(niov)) {
err = -ENODEV;
goto out;
}

end = start + skb_frag_size(frag);
copy = end - offset;

Expand Down

0 comments on commit 69e3953

Please sign in to comment.