[RFC v3 15/18] netdevsim: use netmem descriptor and APIs for page pool

Byungchul Park
2025-05-29T03:11:11Z

To simplify struct page, the effort to separate its own descriptor from
struct page is required and the work for page pool is on going.

Use netmem descriptor and APIs for page pool in netdevsim code.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
drivers/net/netdevsim/netdev.c | 19 ++++++++++---------
drivers/net/netdevsim/netdevsim.h | 2 +-
2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index af545d42961c..d134a6195bfa 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -821,7 +821,7 @@ nsim_pp_hold_read(struct file *file, char __user *data,
struct netdevsim *ns = file->private_data;
char buf[3] = "n\n";

- if (ns->page)
+ if (ns->netmem)
buf[0] = 'y';

return simple_read_from_buffer(data, count, ppos, buf, 2);
@@ -841,18 +841,19 @@ nsim_pp_hold_write(struct file *file, const char __user *data,

rtnl_lock();
ret = count;
- if (val == !!ns->page)
+ if (val == !!ns->netmem)
goto exit;

if (!netif_running(ns->netdev) && val) {
ret = -ENETDOWN;
} else if (val) {
- ns->page = page_pool_dev_alloc_pages(ns->rq[0]->page_pool);
- if (!ns->page)
+ ns->netmem = page_pool_alloc_netmems(ns->rq[0]->page_pool,
+ GFP_ATOMIC | __GFP_NOWARN);
+ if (!ns->netmem)
ret = -ENOMEM;
} else {
- page_pool_put_full_page(ns->page->pp, ns->page, false);
- ns->page = NULL;
+ page_pool_put_full_netmem(netmem_get_pp(ns->netmem), ns->netmem, false);
+ ns->netmem = 0;
}

exit:
@@ -1077,9 +1078,9 @@ void nsim_destroy(struct netdevsim *ns)
nsim_exit_netdevsim(ns);

/* Put this intentionally late to exercise the orphaning path */
- if (ns->page) {
- page_pool_put_full_page(ns->page->pp, ns->page, false);
- ns->page = NULL;
+ if (ns->netmem) {
+ page_pool_put_full_netmem(netmem_get_pp(ns->netmem), ns->netmem, false);
+ ns->netmem = 0;
}

free_netdev(dev);
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index d04401f0bdf7..1dc51468a50c 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -138,7 +138,7 @@ struct netdevsim {
struct debugfs_u32_array dfs_ports[2];
} udp_ports;

- struct page *page;
+ netmem_ref netmem;
struct dentry *pp_dfs;
struct dentry *qr_dfs;

--
2.17.1