Add netdev_rx_queue_restart(), which resets an rx queue using the
queue API recently merged[1].
The queue API was merged to enable the core net stack to reset individual
rx queues to actuate changes in the rx queue's configuration. In later
patches in this series, we will use netdev_rx_queue_restart() to reset
rx queues after binding or unbinding dmabuf configuration, which will
cause reallocation of the page_pool to repopulate its memory using the
new configuration.
[1] https://lore.kernel.org/netdev/20240430231420.699177-1-shailend@google.com/…
Signed-off-by: David Wei <dw(a)davidwei.uk>
Signed-off-by: Mina Almasry <almasrymina(a)google.com>
Reviewed-by: Pavel Begunkov <asml.silence(a)gmail.com>
Reviewed-by: Jakub Kicinski <kuba(a)kernel.org>
---
v18:
- Add more color to commit message (Xuan Zhuo).
v17:
- Use ASSERT_RTNL() (Jakub).
v13:
- Add reviewed-by from Pavel (thanks!)
- Fixed comment (Pavel)
v11:
- Fix not checking dev->queue_mgmt_ops (Pavel).
- Fix ndo_queue_mem_free call that passed the wrong pointer (David).
v9: https://lore.kernel.org/all/20240502045410.3524155-4-dw@davidwei.uk/
(submitted by David).
- fixed SPDX license identifier (Simon).
- Rebased on top of merged queue API definition, and changed
implementation to match that.
- Replace rtnl_lock() with rtnl_is_locked() to make it useable from my
netlink code where rtnl is already locked.
---
include/net/netdev_rx_queue.h | 3 ++
net/core/Makefile | 1 +
net/core/netdev_rx_queue.c | 74 +++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+)
create mode 100644 net/core/netdev_rx_queue.c
diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
index aa1716fb0e53..e78ca52d67fb 100644
--- a/include/net/netdev_rx_queue.h
+++ b/include/net/netdev_rx_queue.h
@@ -54,4 +54,7 @@ get_netdev_rx_queue_index(struct netdev_rx_queue *queue)
return index;
}
#endif
+
+int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq);
+
#endif
diff --git a/net/core/Makefile b/net/core/Makefile
index 62be9aef2528..f82232b358a2 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
obj-y += net-sysfs.o
obj-y += hotdata.o
+obj-y += netdev_rx_queue.o
obj-$(CONFIG_PAGE_POOL) += page_pool.o page_pool_user.o
obj-$(CONFIG_PROC_FS) += net-procfs.o
obj-$(CONFIG_NET_PKTGEN) += pktgen.o
diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c
new file mode 100644
index 000000000000..da11720a5983
--- /dev/null
+++ b/net/core/netdev_rx_queue.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/netdevice.h>
+#include <net/netdev_queues.h>
+#include <net/netdev_rx_queue.h>
+
+int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
+{
+ void *new_mem, *old_mem;
+ int err;
+
+ if (!dev->queue_mgmt_ops || !dev->queue_mgmt_ops->ndo_queue_stop ||
+ !dev->queue_mgmt_ops->ndo_queue_mem_free ||
+ !dev->queue_mgmt_ops->ndo_queue_mem_alloc ||
+ !dev->queue_mgmt_ops->ndo_queue_start)
+ return -EOPNOTSUPP;
+
+ ASSERT_RTNL();
+
+ new_mem = kvzalloc(dev->queue_mgmt_ops->ndo_queue_mem_size, GFP_KERNEL);
+ if (!new_mem)
+ return -ENOMEM;
+
+ old_mem = kvzalloc(dev->queue_mgmt_ops->ndo_queue_mem_size, GFP_KERNEL);
+ if (!old_mem) {
+ err = -ENOMEM;
+ goto err_free_new_mem;
+ }
+
+ err = dev->queue_mgmt_ops->ndo_queue_mem_alloc(dev, new_mem, rxq_idx);
+ if (err)
+ goto err_free_old_mem;
+
+ err = dev->queue_mgmt_ops->ndo_queue_stop(dev, old_mem, rxq_idx);
+ if (err)
+ goto err_free_new_queue_mem;
+
+ err = dev->queue_mgmt_ops->ndo_queue_start(dev, new_mem, rxq_idx);
+ if (err)
+ goto err_start_queue;
+
+ dev->queue_mgmt_ops->ndo_queue_mem_free(dev, old_mem);
+
+ kvfree(old_mem);
+ kvfree(new_mem);
+
+ return 0;
+
+err_start_queue:
+ /* Restarting the queue with old_mem should be successful as we haven't
+ * changed any of the queue configuration, and there is not much we can
+ * do to recover from a failure here.
+ *
+ * WARN if we fail to recover the old rx queue, and at least free
+ * old_mem so we don't also leak that.
+ */
+ if (dev->queue_mgmt_ops->ndo_queue_start(dev, old_mem, rxq_idx)) {
+ WARN(1,
+ "Failed to restart old queue in error path. RX queue %d may be unhealthy.",
+ rxq_idx);
+ dev->queue_mgmt_ops->ndo_queue_mem_free(dev, old_mem);
+ }
+
+err_free_new_queue_mem:
+ dev->queue_mgmt_ops->ndo_queue_mem_free(dev, new_mem);
+
+err_free_old_mem:
+ kvfree(old_mem);
+
+err_free_new_mem:
+ kvfree(new_mem);
+
+ return err;
+}
--
2.46.0.76.ge559c4bf1a-goog
GCC 13.2.0 reported warning about (void *) being used as a param where (char *)
is expected:
In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’, \
but argument 6 has type ‘const void *’ [-Wformat=]
106 | fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
| ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
101 | __TH_LOG(fmt, ##__VA_ARGS__); \
| ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
235 | TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
| ^~~~~~
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’, \
but argument 6 has type ‘const void *’ [-Wformat=]
106 | fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
| ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
101 | __TH_LOG(fmt, ##__VA_ARGS__); \
| ^~~~~~~~
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
259 | TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
| ^~~~~~
As Simon suggested, all calls to __recvpair() have char * as expected_buf param, so
it is safe to change param type from (const void *) to (const char *), which silences
the warning.
Fixes: d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
Reported-by: Mirsad Todorovac <mtodorovac69(a)gmail.com>
Cc: "David S. Miller" <davem(a)davemloft.net>
Cc: Eric Dumazet <edumazet(a)google.com>
Cc: Jakub Kicinski <kuba(a)kernel.org>
Cc: Paolo Abeni <pabeni(a)redhat.com>
Cc: Shuah Khan <shuah(a)kernel.org>
Cc: Kuniyuki Iwashima <kuniyu(a)amazon.com>
Cc: netdev(a)vger.kernel.org
Cc: linux-kselftest(a)vger.kernel.org
Suggested-by: Simon Horman <horms(a)kernel.org>
Signed-off-by: Mirsad Todorovac <mtodorovac69(a)gmail.com>
---
v1 -> v2:
fixed a typo.
change funct param type rather than making two casts, as Simon suggested.
changed Subject: line to reflect the modification.
minor formatting changes.
v1:
initial version to fix the compiler warning.
tools/testing/selftests/net/af_unix/msg_oob.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/af_unix/msg_oob.c b/tools/testing/selftests/net/af_unix/msg_oob.c
index 16d0c172eaeb..535eb2c3d7d1 100644
--- a/tools/testing/selftests/net/af_unix/msg_oob.c
+++ b/tools/testing/selftests/net/af_unix/msg_oob.c
@@ -209,7 +209,7 @@ static void __sendpair(struct __test_metadata *_metadata,
static void __recvpair(struct __test_metadata *_metadata,
FIXTURE_DATA(msg_oob) *self,
- const void *expected_buf, int expected_len,
+ const char *expected_buf, int expected_len,
int buf_len, int flags)
{
int i, ret[2], recv_errno[2], expected_errno = 0;
--
2.43.0
The BPF tracing infrastructure has undergone significant evolution,
leading to the introduction of more robust and efficient APIs.
However, some of the existing tests in the samples/bpf directory have
not kept pace with these developments. These outdated tests not only
create confusion among users but also increase maintenance overhead.
For starter, this patchset focuses on cleaning up outdated 'tracing'
related tests within the BPF testing framework. The goal is to
modernize and streamline selftests by removing obsolete tests and
migrating necessaries to more appropriate locations.
Daniel T. Lee (3):
selftests/bpf: migrate tracepoint overhead test to prog_tests
selftests/bpf: add rename tracepoint bench test
samples/bpf: remove obsolete tracing related tests
samples/bpf/Makefile | 12 -
samples/bpf/test_overhead_kprobe.bpf.c | 41 ----
samples/bpf/test_overhead_raw_tp.bpf.c | 17 --
samples/bpf/test_overhead_tp.bpf.c | 23 --
samples/bpf/test_overhead_user.c | 225 ------------------
samples/bpf/test_override_return.sh | 16 --
samples/bpf/test_probe_write_user.bpf.c | 52 ----
samples/bpf/test_probe_write_user_user.c | 108 ---------
samples/bpf/tracex7.bpf.c | 15 --
samples/bpf/tracex7_user.c | 56 -----
tools/testing/selftests/bpf/bench.c | 2 +
.../selftests/bpf/benchs/bench_rename.c | 16 ++
.../selftests/bpf/benchs/run_bench_rename.sh | 2 +-
.../selftests/bpf/prog_tests/test_overhead.c | 14 +-
.../selftests/bpf/progs/test_overhead.c | 11 +-
15 files changed, 39 insertions(+), 571 deletions(-)
delete mode 100644 samples/bpf/test_overhead_kprobe.bpf.c
delete mode 100644 samples/bpf/test_overhead_raw_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_user.c
delete mode 100755 samples/bpf/test_override_return.sh
delete mode 100644 samples/bpf/test_probe_write_user.bpf.c
delete mode 100644 samples/bpf/test_probe_write_user_user.c
delete mode 100644 samples/bpf/tracex7.bpf.c
delete mode 100644 samples/bpf/tracex7_user.c
--
2.43.0
This patchset introduces SEV-SNP test to the kernel selftest framework.
It also adds negative testing of SEV, ES and SNP VM types.
Patch 1 - Extend the sev smoke tests to use the SNP specific ioctl
calls and sets up memory to boot a SNP guest VM
Patch 2 - Cleanup patch that decouples the ioctl calls from the sev
selftest library with its test assert and status counterparts. No
functional change introduced
Patch 3 - Introduce ioctl test for SEV, ES
Patch 4 - Introduce positive and negative ioctl test for SEV-SNP
Patch 5 - Adds the X86_FEATURE_SEV_SNP vm type test for KVM_SEV_INIT2
Any feedback/review on the approach and design is highly appreciated!
Pratik R. Sampat (5):
selftests: KVM: Add a basic SNP smoke test
selftests: KVM: Decouple SEV ioctls from asserts
selftests: KVM: SEV IOCTL test
selftests: KVM: SNP IOCTL test
selftests: KVM: SEV-SNP test for KVM_SEV_INIT2
.../selftests/kvm/include/x86_64/processor.h | 1 +
.../selftests/kvm/include/x86_64/sev.h | 39 ++-
tools/testing/selftests/kvm/lib/kvm_util.c | 7 +-
.../selftests/kvm/lib/x86_64/processor.c | 6 +-
tools/testing/selftests/kvm/lib/x86_64/sev.c | 181 +++++++++++---
.../selftests/kvm/x86_64/sev_init2_tests.c | 13 +
.../selftests/kvm/x86_64/sev_smoke_test.c | 223 +++++++++++++++++-
7 files changed, 418 insertions(+), 52 deletions(-)
--
2.34.1