Skip to content

Commit 6e18ed9

Browse files
spikehkuba-moo
authored andcommitted
net: add helpers for setting a memory provider on an rx queue
Add helpers that properly prep or remove a memory provider for an rx queue then restart the queue. Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: David Wei <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 56102c0 commit 6e18ed9

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

include/net/page_pool/memory_provider.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr);
2222
void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov);
2323
void net_mp_niov_clear_page_pool(struct net_iov *niov);
2424

25+
int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx,
26+
struct pp_memory_provider_params *p);
27+
void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
28+
struct pp_memory_provider_params *old_p);
29+
2530
/**
2631
* net_mp_netmem_place_in_cache() - give a netmem to a page pool
2732
* @pool: the page pool to place the netmem into

net/core/netdev_rx_queue.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/netdevice.h>
44
#include <net/netdev_queues.h>
55
#include <net/netdev_rx_queue.h>
6+
#include <net/page_pool/memory_provider.h>
67

78
#include "page_pool_priv.h"
89

@@ -80,3 +81,71 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
8081
return err;
8182
}
8283
EXPORT_SYMBOL_NS_GPL(netdev_rx_queue_restart, "NETDEV_INTERNAL");
84+
85+
static int __net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx,
86+
struct pp_memory_provider_params *p)
87+
{
88+
struct netdev_rx_queue *rxq;
89+
int ret;
90+
91+
if (ifq_idx >= dev->real_num_rx_queues)
92+
return -EINVAL;
93+
ifq_idx = array_index_nospec(ifq_idx, dev->real_num_rx_queues);
94+
95+
rxq = __netif_get_rx_queue(dev, ifq_idx);
96+
if (rxq->mp_params.mp_ops)
97+
return -EEXIST;
98+
99+
rxq->mp_params = *p;
100+
ret = netdev_rx_queue_restart(dev, ifq_idx);
101+
if (ret) {
102+
rxq->mp_params.mp_ops = NULL;
103+
rxq->mp_params.mp_priv = NULL;
104+
}
105+
return ret;
106+
}
107+
108+
int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx,
109+
struct pp_memory_provider_params *p)
110+
{
111+
int ret;
112+
113+
rtnl_lock();
114+
ret = __net_mp_open_rxq(dev, ifq_idx, p);
115+
rtnl_unlock();
116+
return ret;
117+
}
118+
119+
static void __net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
120+
struct pp_memory_provider_params *old_p)
121+
{
122+
struct netdev_rx_queue *rxq;
123+
124+
if (WARN_ON_ONCE(ifq_idx >= dev->real_num_rx_queues))
125+
return;
126+
127+
rxq = __netif_get_rx_queue(dev, ifq_idx);
128+
129+
/* Callers holding a netdev ref may get here after we already
130+
* went thru shutdown via dev_memory_provider_uninstall().
131+
*/
132+
if (dev->reg_state > NETREG_REGISTERED &&
133+
!rxq->mp_params.mp_ops)
134+
return;
135+
136+
if (WARN_ON_ONCE(rxq->mp_params.mp_ops != old_p->mp_ops ||
137+
rxq->mp_params.mp_priv != old_p->mp_priv))
138+
return;
139+
140+
rxq->mp_params.mp_ops = NULL;
141+
rxq->mp_params.mp_priv = NULL;
142+
WARN_ON(netdev_rx_queue_restart(dev, ifq_idx));
143+
}
144+
145+
void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx,
146+
struct pp_memory_provider_params *old_p)
147+
{
148+
rtnl_lock();
149+
__net_mp_close_rxq(dev, ifq_idx, old_p);
150+
rtnl_unlock();
151+
}

0 commit comments

Comments
 (0)