Skip to content

Commit

Permalink
netdevsim: allow normal queue reset while down
Browse files Browse the repository at this point in the history
Resetting queues while the device is down should be legal.
Allow it, test it. Ideally we'd test this with a real device
supporting devmem but I don't have access to such devices.

Reviewed-by: Mina Almasry <almasrymina@google.com>
Link: https://patch.msgid.link/20250206225638.1387810-5-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Feb 8, 2025
1 parent c1e00bc commit 285b3f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 4 additions & 6 deletions drivers/net/netdevsim/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,11 @@ nsim_queue_mem_alloc(struct net_device *dev, void *per_queue_mem, int idx)
if (ns->rq_reset_mode > 3)
return -EINVAL;

if (ns->rq_reset_mode == 1)
if (ns->rq_reset_mode == 1) {
if (!netif_running(ns->netdev))
return -ENETDOWN;
return nsim_create_page_pool(&qmem->pp, &ns->rq[idx]->napi);
}

qmem->rq = nsim_queue_alloc();
if (!qmem->rq)
Expand Down Expand Up @@ -754,11 +757,6 @@ nsim_qreset_write(struct file *file, const char __user *data,
return -EINVAL;

rtnl_lock();
if (!netif_running(ns->netdev)) {
ret = -ENETDOWN;
goto exit_unlock;
}

if (queue >= ns->netdev->real_num_rx_queues) {
ret = -EINVAL;
goto exit_unlock;
Expand Down
18 changes: 17 additions & 1 deletion tools/testing/selftests/net/nl_netdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ def napi_list_check(nf) -> None:
comment=f"queue count after reset queue {q} mode {i}")


def nsim_rxq_reset_down(nf) -> None:
"""
Test that the queue API supports resetting a queue
while the interface is down. We should convert this
test to testing real HW once more devices support
queue API.
"""
with NetdevSimDev(queue_count=4) as nsimdev:
nsim = nsimdev.nsims[0]

ip(f"link set dev {nsim.ifname} down")
for i in [0, 2, 3]:
nsim.dfs_write("queue_reset", f"1 {i}")


def page_pool_check(nf) -> None:
with NetdevSimDev() as nsimdev:
nsim = nsimdev.nsims[0]
Expand Down Expand Up @@ -106,7 +121,8 @@ def get_pp():

def main() -> None:
nf = NetdevFamily()
ksft_run([empty_check, lo_check, page_pool_check, napi_list_check],
ksft_run([empty_check, lo_check, page_pool_check, napi_list_check,
nsim_rxq_reset_down],
args=(nf, ))
ksft_exit()

Expand Down

0 comments on commit 285b3f7

Please sign in to comment.