From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
dw@davidwei.uk, almasrymina@google.com, jdamato@fastly.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 5/8] netdevsim: add queue alloc/free helpers
Date: Fri, 3 Jan 2025 10:59:50 -0800 [thread overview]
Message-ID: <20250103185954.1236510-6-kuba@kernel.org> (raw)
In-Reply-To: <20250103185954.1236510-1-kuba@kernel.org>
We'll need the code to allocate and free queues in the queue management
API, factor it out.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
drivers/net/netdevsim/netdev.c | 35 +++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 7487697ac417..e1bd3c1563b7 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -595,6 +595,24 @@ static const struct netdev_stat_ops nsim_stat_ops = {
.get_base_stats = nsim_get_base_stats,
};
+static struct nsim_rq *nsim_queue_alloc(void)
+{
+ struct nsim_rq *rq;
+
+ rq = kzalloc(sizeof(*rq), GFP_KERNEL);
+ if (!rq)
+ return NULL;
+
+ skb_queue_head_init(&rq->skb_queue);
+ return rq;
+}
+
+static void nsim_queue_free(struct nsim_rq *rq)
+{
+ skb_queue_purge_reason(&rq->skb_queue, SKB_DROP_REASON_QUEUE_PURGE);
+ kfree(rq);
+}
+
static ssize_t
nsim_pp_hold_read(struct file *file, char __user *data,
size_t count, loff_t *ppos)
@@ -683,11 +701,9 @@ static int nsim_queue_init(struct netdevsim *ns)
return -ENOMEM;
for (i = 0; i < dev->num_rx_queues; i++) {
- ns->rq[i] = kzalloc(sizeof(**ns->rq), GFP_KERNEL);
+ ns->rq[i] = nsim_queue_alloc();
if (!ns->rq[i])
goto err_free_prev;
-
- skb_queue_head_init(&ns->rq[i]->skb_queue);
}
return 0;
@@ -699,16 +715,13 @@ static int nsim_queue_init(struct netdevsim *ns)
return -ENOMEM;
}
-static void nsim_queue_free(struct netdevsim *ns)
+static void nsim_queue_uninit(struct netdevsim *ns)
{
struct net_device *dev = ns->netdev;
int i;
- for (i = 0; i < dev->num_rx_queues; i++) {
- skb_queue_purge_reason(&ns->rq[i]->skb_queue,
- SKB_DROP_REASON_QUEUE_PURGE);
- kfree(ns->rq[i]);
- }
+ for (i = 0; i < dev->num_rx_queues; i++)
+ nsim_queue_free(ns->rq[i]);
kvfree(ns->rq);
ns->rq = NULL;
@@ -754,7 +767,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
nsim_macsec_teardown(ns);
nsim_bpf_uninit(ns);
err_rq_destroy:
- nsim_queue_free(ns);
+ nsim_queue_uninit(ns);
err_utn_destroy:
rtnl_unlock();
nsim_udp_tunnels_info_destroy(ns->netdev);
@@ -836,7 +849,7 @@ void nsim_destroy(struct netdevsim *ns)
nsim_macsec_teardown(ns);
nsim_ipsec_teardown(ns);
nsim_bpf_uninit(ns);
- nsim_queue_free(ns);
+ nsim_queue_uninit(ns);
}
rtnl_unlock();
if (nsim_dev_port_is_pf(ns->nsim_dev_port))
--
2.47.1
next prev parent reply other threads:[~2025-01-03 19:00 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 18:59 [PATCH net-next 0/8] net: make sure we retain NAPI ordering on netdev->napi_list Jakub Kicinski
2025-01-03 18:59 ` [PATCH net-next 1/8] " Jakub Kicinski
2025-01-06 9:35 ` Eric Dumazet
2025-01-03 18:59 ` [PATCH net-next 2/8] netdev: define NETDEV_INTERNAL Jakub Kicinski
2025-01-06 9:36 ` Eric Dumazet
2025-01-07 21:04 ` Mina Almasry
2025-01-03 18:59 ` [PATCH net-next 3/8] netdevsim: support NAPI config Jakub Kicinski
2025-01-06 9:36 ` Eric Dumazet
2025-01-03 18:59 ` [PATCH net-next 4/8] netdevsim: allocate rqs individually Jakub Kicinski
2025-01-06 9:52 ` Eric Dumazet
2025-01-07 10:33 ` Paolo Abeni
2025-01-03 18:59 ` Jakub Kicinski [this message]
2025-01-06 9:57 ` [PATCH net-next 5/8] netdevsim: add queue alloc/free helpers Eric Dumazet
2025-01-07 21:08 ` Mina Almasry
2025-01-07 21:15 ` Jakub Kicinski
2025-01-03 18:59 ` [PATCH net-next 6/8] netdevsim: add queue management API support Jakub Kicinski
2025-01-06 16:45 ` Stanislav Fomichev
2025-01-07 14:03 ` Willem de Bruijn
2025-01-07 14:49 ` Jakub Kicinski
2025-01-07 15:16 ` Willem de Bruijn
2025-01-03 18:59 ` [PATCH net-next 7/8] netdevsim: add debugfs-triggered queue reset Jakub Kicinski
2025-01-06 16:46 ` Stanislav Fomichev
2025-01-07 11:06 ` Paolo Abeni
2025-01-07 14:04 ` Willem de Bruijn
2025-01-03 18:59 ` [PATCH net-next 8/8] selftests: net: test listing NAPI vs queue resets Jakub Kicinski
2025-01-06 16:47 ` Stanislav Fomichev
2025-01-07 14:06 ` [PATCH net-next 0/8] net: make sure we retain NAPI ordering on netdev->napi_list Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250103185954.1236510-6-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=almasrymina@google.com \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=jdamato@fastly.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).