RDMA/rxe: Add the support that rxe can work in net namespace
Subsystems (3)
v6 cover RDMA/rxe: Add the support that rxe can work in net namespace
Currently rxe does not work correctly in network namespaces.
When the rdma_rxe module is loaded, a UDP socket listening on port 4791 is created in init_net. When users run:
ip link add ... type rxe
inside another network namespace, the RXE RDMA link is created but it cannot function properly because the underlying UDP socket belongs to init_net. Other network namespaces cannot use that socket.
To address this issue, this series introduces net namespace support for rxe and moves socket management to be per network namespace.
The series first introduces per-net namespace management for the IPv4 and IPv6 sockets used by rxe. The sockets are created when the network namespace becomes active and are released when the namespace is destroyed.
Based on this infrastructure, rxe RDMA links are then created and destroyed within each network namespace. This ensures that both the UDP sockets and RDMA links are correctly scoped to the namespace in which they are used.
With these changes, rxe RDMA links can be created and used both in init_net and in other network namespaces, and resources are properly cleaned up during namespace teardown.
The series also includes a selftest to verify RXE functionality in network namespaces.
"
# make -C tools/testing/selftests/ TARGETS=rdma run_tests make: Entering directory 'tools/testing/selftests' make[1]: Nothing to be done for 'all'. TAP version 13 1..4 # timeout set to 45 # selftests: rdma: rxe_rping_between_netns.sh # client DISCONNECT EVENT... ok 1 selftests: rdma: rxe_rping_between_netns.sh # timeout set to 45 # selftests: rdma: rxe_ipv6.sh ok 2 selftests: rdma: rxe_ipv6.sh # timeout set to 45 # selftests: rdma: rxe_socket_with_netns.sh ok 3 selftests: rdma: rxe_socket_with_netns.sh # timeout set to 45 # selftests: rdma: rxe_test_NETDEV_UNREGISTER.sh ok 4 selftests: rdma: rxe_test_NETDEV_UNREGISTER.sh make: Leaving directory 'tools/testing/selftests' "
V5 -> V6: Fix some problems based on Leon's advice
V4 -> V5: Fix rcu warnings
V3 -> V4: Squash all the changes about rxe_ns.c/h into one commit. V2 -> V3: Fix build warnings
V1 -> V2: Fix the problems based on David Ahern.
Zhu Yanjun (4):
RDMA/nldev: Add dellink function pointer
RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets RDMA/rxe: Support RDMA link creation and destruction per net namespace RDMA/rxe: Add testcase for net namespace rxe
MAINTAINERS | 1 + drivers/infiniband/core/nldev.c | 6 + drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 38 ++++- drivers/infiniband/sw/rxe/rxe_net.c | 144 +++++++++++++----- drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 124 +++++++++++++++ drivers/infiniband/sw/rxe/rxe_ns.h | 26 ++++ include/rdma/rdma_netlink.h | 2 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rdma/Makefile | 7 + tools/testing/selftests/rdma/config | 3 + tools/testing/selftests/rdma/rxe_ipv6.sh | 63 ++++++++ .../selftests/rdma/rxe_rping_between_netns.sh | 85 +++++++++++ .../selftests/rdma/rxe_socket_with_netns.sh | 76 +++++++++ .../rdma/rxe_test_NETDEV_UNREGISTER.sh | 63 ++++++++ 16 files changed, 604 insertions(+), 47 deletions(-) create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.c create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.h create mode 100644 tools/testing/selftests/rdma/Makefile create mode 100644 tools/testing/selftests/rdma/config create mode 100755 tools/testing/selftests/rdma/rxe_ipv6.sh create mode 100755 tools/testing/selftests/rdma/rxe_rping_between_netns.sh create mode 100755 tools/testing/selftests/rdma/rxe_socket_with_netns.sh create mode 100755 tools/testing/selftests/rdma/rxe_test_NETDEV_UNREGISTER.sh
Signature · 1 line
2.52.0
PATCH v6 1/4 RDMA/nldev: Add dellink function pointer
The newlink function pointer is added. And the sock listening on port 4791 is added in the newlink function. So the dellink function is needed to remove the sock.
--- drivers/infiniband/core/nldev.c | 6 ++++++ include/rdma/rdma_netlink.h | 2 ++ 2 files changed, 8 insertions(+)
drivers/infiniband/core/nldev.c +6 -0
@@ -1824,6 +1824,12 @@ static int nldev_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,return -EINVAL ; } +if ((device->ops.driver_id ==RDMA_DRIVER_RXE ) && device->link_ops) { + err = device->link_ops->dellink (device); +if (err) +return err; + } +ib_unregister_device_and_put (device);return 0 ; }
include/rdma/rdma_netlink.h +2 -0
@@ -5,6 +5,7 @@#include <linux/netlink.h> #include <uapi/rdma/rdma_netlink.h> +#include <rdma/ib_verbs.h> struct ib_device ;
@@ -126,6 +127,7 @@ struct rdma_link_ops {struct list_head list;const char *type;int (*newlink)(const char *ibdev_name,struct net_device *ndev); +int (*dellink)(struct ib_device *dev); };void rdma_link_register (struct rdma_link_ops *ops);
Signature · 1 line
2.52.0
PATCH v6 2/4 RDMA/rxe: Add net namespace support for IPv4/IPv6 sockets
In reply to Zhu YanjunAdd a net namespace implementation file to rxe to manage the lifecycle of IPv4 and IPv6 sockets per network namespace.
This implementation handles the creation and destruction of the sockets both for init_net and for dynamically created network namespaces. The sockets are initialized when a namespace becomes active and are properly released when the namespace is removed.
This change provides the infrastructure needed for rxe to operate correctly in environments using multiple network namespaces.
--- drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe_ns.c | 124 +++++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_ns.h | 26 ++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.c create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.h
drivers/infiniband/sw/rxe/Makefile +2 -1
@@ -22,6 +22,7 @@ rdma_rxe-y := \ rxe_mcast.o \ rxe_task.o \ rxe_net.o \ - rxe_hw_counters.o + rxe_hw_counters.o \ + rxe_ns.o rdma_rxe-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += rxe_odp.o
drivers/infiniband/sw/rxe/rxe_ns.c new file +124 -0
124 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_ns.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ + +#ifndef RXE_NS_H +#define RXE_NS_H + +struct sock *rxe_ns_pernet_sk4 (struct net *net); +void rxe_ns_pernet_set_sk4 (struct net *net,struct sock *sk); + +#if IS_ENABLED (CONFIG_IPV6 ) +void rxe_ns_pernet_set_sk6 (struct net *net,struct sock *sk); +struct sock *rxe_ns_pernet_sk6 (struct net *net); +#else /* IPv6 */ +static inline struct sock *rxe_ns_pernet_sk6 (struct net *net) +{ +return NULL ; +} + +static inline void rxe_ns_pernet_set_sk6 (struct net *net,struct sock *sk) +{ +} +#endif /* IPv6 */ + +int rxe_namespace_init (void ); +void rxe_namespace_exit (void ); + +#endif /* RXE_NS_H */
Signature · 1 line
2.52.0
PATCH v6 3/4 RDMA/rxe: Support RDMA link creation and destruction per net namespace
In reply to Zhu YanjunAfter introducing dellink handling and per-net namespace management for IPv4 and IPv6 sockets, extend rxe to create and destroy RDMA links within each network namespace.
With this change, RDMA links can be instantiated both in init_net and in other network namespaces. The lifecycle of the RDMA link is now tied to the corresponding namespace and is properly cleaned up when the namespace or link is removed.
This ensures rxe behaves correctly in multi-namespace environments and keeps socket and RDMA link resources consistent across namespace creation and teardown.
--- drivers/infiniband/sw/rxe/rxe.c | 38 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 144 +++++++++++++++++++++------- drivers/infiniband/sw/rxe/rxe_net.h | 9 +- 3 files changed, 145 insertions(+), 46 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +33 -5
@@ -8,6 +8,8 @@#include <net/addrconf.h> #include "rxe.h" #include "rxe_loc.h" +#include "rxe_net.h" +#include "rxe_ns.h" MODULE_AUTHOR ("Bob Pearson, Frank Zago, John Groves, Kamal Heib" );MODULE_DESCRIPTION ("Soft RDMA transport" );
@@ -200,6 +202,8 @@ void rxe_set_mtu(struct rxe_dev *rxe, unsigned int ndev_mtu) port->mtu_cap =ib_mtu_enum_to_int (mtu); } +static struct rdma_link_ops rxe_link_ops; +/* called by ifc layer to create new rxe device. * The caller should allocate memory for rxe by calling ib_alloc_device. */
@@ -208,6 +212,7 @@ int rxe_add(struct rxe_dev *rxe, unsigned int mtu, const char *ibdev_name, {rxe_init (rxe, ndev);rxe_set_mtu (rxe, mtu); + rxe->ib_dev.link_ops = &rxe_link_ops;return rxe_register_device (rxe, ibdev_name, ndev); }
@@ -231,6 +236,10 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) goto err; } + err =rxe_net_init (ndev); +if (err) +return err; + err =rxe_net_add (ibdev_name, ndev);if (err) {rxe_err ("failed to add %s\n" , ndev->name);
@@ -240,9 +249,17 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)return err; } +static int rxe_dellink (struct ib_device *dev) +{ +rxe_net_del (dev); + +return 0 ; +} +static struct rdma_link_ops rxe_link_ops = { .type ="rxe" , .newlink = rxe_newlink, + .dellink = rxe_dellink, };static int __init rxe_module_init (void )
@@ -253,15 +270,24 @@ static int __init rxe_module_init(void)if (err)return err; - err =rxe_net_init (); -if (err) { -rxe_destroy_wq (); -return err; - } + err =rxe_namespace_init (); +if (err) + goto err_destroy_wq; + + err =rxe_register_notifier (); +if (err) + goto err_namespace_exit;rdma_link_register (&rxe_link_ops); +pr_info ("loaded\n" );return 0 ; + +err_namespace_exit: +rxe_namespace_exit (); +err_destroy_wq: +rxe_destroy_wq (); +return err; } static void __exit rxe_module_exit(void)
@@ -271,6 +297,8 @@ static void __exit rxe_module_exit(void)rxe_net_exit ();rxe_destroy_wq (); +rxe_namespace_exit (); +pr_info ("unloaded\n" ); }
drivers/infiniband/sw/rxe/rxe_net.c +109 -35
268 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_net.h +3 -6
@@ -11,14 +11,11 @@#include <net/if_inet6.h> #include <linux/module.h> -struct rxe_recv_sockets { -struct socket *sk4; -struct socket *sk6; -}; -int rxe_net_add (const char *ibdev_name,struct net_device *ndev); +void rxe_net_del (struct ib_device *dev); -int rxe_net_init (void ); +int rxe_register_notifier (void ); +int rxe_net_init (struct net_device *ndev);void rxe_net_exit (void );#endif /* RXE_NET_H */
Signature · 1 line
2.52.0
PATCH v6 4/4 RDMA/rxe: Add testcase for net namespace rxe
In reply to Zhu YanjunAdd 4 testcases for rxe with net namespace.
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rdma/Makefile | 7 ++ tools/testing/selftests/rdma/config | 3 + tools/testing/selftests/rdma/rxe_ipv6.sh | 63 ++++++++++++++ .../selftests/rdma/rxe_rping_between_netns.sh | 85 +++++++++++++++++++ .../selftests/rdma/rxe_socket_with_netns.sh | 76 +++++++++++++++++ .../rdma/rxe_test_NETDEV_UNREGISTER.sh | 63 ++++++++++++++ 8 files changed, 299 insertions(+) create mode 100644 tools/testing/selftests/rdma/Makefile create mode 100644 tools/testing/selftests/rdma/config create mode 100755 tools/testing/selftests/rdma/rxe_ipv6.sh create mode 100755 tools/testing/selftests/rdma/rxe_rping_between_netns.sh create mode 100755 tools/testing/selftests/rdma/rxe_socket_with_netns.sh create mode 100755 tools/testing/selftests/rdma/rxe_test_NETDEV_UNREGISTER.sh
MAINTAINERS +1 -0
@@ -24492,6 +24492,7 @@ L: [email protected] S: Supported F: drivers/infiniband/sw/rxe/ F: include/uapi/rdma/rdma_user_rxe.h +F: tools/testing/selftests/rdma/exe* SOFTLOGIC 6x10 MPEG CODEC M: Bluecherry Maintainers <[email protected]>
tools/testing/selftests/Makefile +1 -0
@@ -94,6 +94,7 @@ TARGETS += proc TARGETS += pstore TARGETS += ptrace TARGETS += openat2 +TARGETS += rdma TARGETS += resctrl TARGETS += riscv TARGETS += rlimits
tools/testing/selftests/rdma/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_PROGS := rxe_rping_between_netns.sh \ + rxe_ipv6.sh \ + rxe_socket_with_netns.sh \ + rxe_test_NETDEV_UNREGISTER.sh + +include ../lib.mk
tools/testing/selftests/rdma/config new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_TUN +CONFIG_VETH +CONFIG_RDMA_RXE
tools/testing/selftests/rdma/rxe_ipv6.sh new file +63 -0
63 lines not on this page · raw message
tools/testing/selftests/rdma/rxe_rping_between_netns.sh new file +85 -0
85 lines not on this page · raw message
tools/testing/selftests/rdma/rxe_socket_with_netns.sh new file +76 -0
76 lines not on this page · raw message
tools/testing/selftests/rdma/rxe_test_NETDEV_UNREGISTER.sh new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v6 4/4] RDMA/rxe: Add testcase for net namespace rxe
Quoted 26 lines · Zhu Yanjun
Add 4 testcases for rxe with net namespace.
Reviewed-by David Ahern <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rdma/Makefile | 7 ++ tools/testing/selftests/rdma/config | 3 + tools/testing/selftests/rdma/rxe_ipv6.sh | 63 ++++++++++++++ .../selftests/rdma/rxe_rping_between_netns.sh | 85 +++++++++++++++++++ .../selftests/rdma/rxe_socket_with_netns.sh | 76 +++++++++++++++++ .../rdma/rxe_test_NETDEV_UNREGISTER.sh | 63 ++++++++++++++ 8 files changed, 299 insertions(+)create mode 100644
tools/testing/selftests/rdma/Makefile
create mode 100644tools/testing/selftests/rdma/config
create mode 100755tools/testing/selftests/rdma/rxe_ipv6.shcreate mode 100755tools/testing/selftests/rdma/rxe_rping_between_netns.shcreate mode 100755tools/testing/selftests/rdma/rxe_socket_with_netns.shcreate mode 100755tools/testing/selftests/rdma/rxe_test_NETDEV_UNREGISTER.shMAINTAINERS +0
-0
MAINTAINERS L: [email protected] · line 24495
Quoted 4 lines
MAINTAINERS +1
-0@@ -24492,6 +24492,7 @@ L: [email protected] S: Supported F: drivers/infiniband/sw/rxe/ F: include/uapi/rdma/rdma_user_rxe.h +F: tools/testing/selftests/rdma/exe*
Sorry. Should be "tools/testing/selftests/rdma/rxe*"
Zhu Yanjun
Quoted 348 lines
MAINTAINERS +0
-0SOFTLOGIC 6x10 MPEG CODEC M: Bluecherry Maintainers <[email protected]>tools/testing/selftests/Makefile +1
-0@@ -94,6 +94,7 @@ TARGETS += proc TARGETS += pstore TARGETS += ptrace TARGETS += openat2 +TARGETS += rdma TARGETS += resctrl TARGETS += riscv TARGETS += rlimitstools/testing/selftests/rdma/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_PROGS := rxe_rping_between_netns.sh \ + rxe_ipv6.sh \ + rxe_socket_with_netns.sh \ + rxe_test_NETDEV_UNREGISTER.sh + +include ../lib.mktools/testing/selftests/rdma/config new file +3
-0@@ -0,0 +1,3 @@ +CONFIG_TUN +CONFIG_VETH +CONFIG_RDMA_RXEtools/testing/selftests/rdma/rxe_ipv6.sh new file +63
-0@@ -0,0 +1,63 @@ +#!/bin/bash + +# Configuration +NS_NAME="net6" +VETH_HOST="veth0" +VETH_NS="veth1" +RXE_NAME="rxe6" +PORT=4791 +IP6_ADDR="2001:db8::1/64" + +exec > /dev/null + +# Cleanup function to run on exit (even on failure) +cleanup() { + ip netns del "$NS_NAME" 2>/dev/null + modprobe -r rdma_rxe 2>/dev/null + echo "Done." +} +trap cleanup EXIT + +# 1. Prerequisites check +for mod in tun veth rdma_rxe; do + if ! modinfo "$mod" >/dev/null 2>&1; then + echo "Error: Kernel module '$mod' not found." + exit 1 + fi +done + +modprobe rdma_rxe + +# 2. Setup Namespace and Networking +echo "Setting up IPv6 network namespace..." +ip netns add "$NS_NAME" +ip link add "$VETH_HOST" type veth peer name "$VETH_NS" +ip link set "$VETH_NS" netns "$NS_NAME" +ip netns exec "$NS_NAME" ip addr add "$IP6_ADDR" dev "$VETH_NS" +ip netns exec "$NS_NAME" ip link set "$VETH_NS" up +ip link set "$VETH_HOST" up + +# 3. Add RDMA Link +echo "Adding RDMA RXE link..." +if ! ip netns exec "$NS_NAME" rdma link add "$RXE_NAME" type rxe netdev "$VETH_NS"; then + echo "Error: Failed to create RXE link." + exit 1 +fi + +# 4. Verification: Port should be listening +# Using -H to skip headers and -q for quiet exit codes +if ! ip netns exec "$NS_NAME" ss -Hul6n sport = :$PORT | grep -q ":$PORT"; then + echo "Error: UDP port $PORT is NOT listening after link creation." + exit 1 +fi +echo "Verified: Port $PORT is active." + +# 5. Removal and Verification +echo "Deleting RDMA link..." +ip netns exec "$NS_NAME" rdma link del "$RXE_NAME" + +if ip netns exec "$NS_NAME" ss -Hul6n sport = :$PORT | grep -q ":$PORT"; then + echo "Error: UDP port $PORT still active after link deletion." + exit 1 +fi +echo "Verified: Port $PORT closed successfully."tools/testing/selftests/rdma/rxe_rping_between_netns.sh new file +85
-0@@ -0,0 +1,85 @@ +#!/bin/bash + +# Configuration +NS="test1" +VETH_A="veth-a" +VETH_B="veth-b" +IP_A="1.1.1.1" +IP_B="1.1.1.2" +PORT=4791 + +exec > /dev/null + +# --- Cleanup Routine --- +cleanup() { + echo "Cleaning up resources..." + rdma link del rxe1 2>/dev/null + ip netns exec "$NS" rdma link del rxe0 2>/dev/null + ip link delete "$VETH_B" 2>/dev/null + ip netns del "$NS" 2>/dev/null + modprobe -r rdma_rxe 2>/dev/null +} +trap cleanup EXIT + +# --- Prerequisite Checks --- +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + +modprobe rdma_rxe || { echo "Failed to load rdma_rxe"; exit 1; } + +# --- Setup Network Topology --- +echo "Setting up network namespace and veth pair..." +ip netns add "$NS" +ip link add "$VETH_A" type veth peer name "$VETH_B" +ip link set "$VETH_A" netns "$NS" + +# Configure Namespace side (test1) +ip netns exec "$NS" ip addr add "$IP_A/24" dev "$VETH_A" +ip netns exec "$NS" ip link set "$VETH_A" up +ip netns exec "$NS" ip link set lo up + +# Configure Host side +ip addr add "$IP_B/24" dev "$VETH_B" +ip link set "$VETH_B" up + +# --- RXE Link Creation --- +echo "Creating RDMA links..." +ip netns exec "$NS" rdma link add rxe0 type rxe netdev "$VETH_A" +rdma link add rxe1 type rxe netdev "$VETH_B" + +# Verify UDP 4791 is listening +check_port() { + local target=$1 # "host" or "ns" + if [ "$target" == "ns" ]; then + ip netns exec "$NS" ss -Huln sport == :$PORT | grep -q ":$PORT" + else + ss -Huln sport == :$PORT | grep -q ":$PORT" + fi +} + +check_port "ns" || { echo "Error: RXE port not listening in namespace"; exit 1; } +check_port "host" || { echo "Error: RXE port not listening on host"; exit 1; } + +# --- Connectivity Test --- +echo "Testing connectivity with rping..." +ping -c 2 -W 1 "$IP_A" > /dev/null || { echo "Ping failed"; exit 1; } + +# Start rping server in background +ip netns exec "$NS" rping -s -a "$IP_A" -v > /dev/null 2>&1 & +RPING_PID=$! +sleep 1 # Allow server to bind + +# Run rping client +rping -c -a "$IP_A" -d -v -C 3 +RESULT=$? + +kill $RPING_PID 2>/dev/null + +if [ $RESULT -eq 0 ]; then + echo "SUCCESS: RDMA traffic verified." +else + echo "FAILURE: rping failed." + exit 1 +fitools/testing/selftests/rdma/rxe_socket_with_netns.sh new file +76
-0@@ -0,0 +1,76 @@ +#!/bin/bash + +# Configuration +PORT=4791 +MODS=("tun" "rdma_rxe") + +exec > /dev/null + +# --- Helper: Cleanup Routine --- +cleanup() { + echo "Cleaning up resources..." + rdma link del rxe1 2>/dev/null + rdma link del rxe0 2>/dev/null + ip link del tun0 2>/dev/null + ip link del tun1 2>/dev/null + for m in "${MODS[@]}"; do modprobe -r "$m" 2>/dev/null; done +} + +# Ensure cleanup runs on script exit or interrupt +trap cleanup EXIT + +# --- Phase 1: Environment Check --- +if [[ $EUID -ne 0 ]]; then + echo "Error: This script must be run as root." + exit 1 +fi + +for m in "${MODS[@]}"; do + modprobe "$m" || { echo "Error: Failed to load $m"; exit 1; } +done + +# --- Phase 2: Create Interfaces & RXE Links --- +echo "Creating tun0 (1.1.1.1) and rxe0..." +ip tuntap add mode tun tun0 +ip addr add 1.1.1.1/24 dev tun0 +ip link set tun0 up +rdma link add rxe0 type rxe netdev tun0 + +# Verify port 4791 is listening +if ! ss -Huln sport = :$PORT | grep -q ":$PORT"; then + echo "Error: UDP port $PORT not found after rxe0 creation" + exit 1 +fi + +echo "Creating tun1 (2.2.2.2) and rxe1..." +ip tuntap add mode tun tun1 +ip addr add 2.2.2.2/24 dev tun1 +ip link set tun1 up +rdma link add rxe1 type rxe netdev tun1 + +# Verify port 4791 is still listening +if ! ss -Huln sport = :$PORT | grep -q ":$PORT"; then + echo "Error: UDP port $PORT missing after rxe1 creation" + exit 1 +fi + +# --- Phase 3: Targeted Deletion --- +echo "Deleting rxe1..." +rdma link del rxe1 + +# Port should still be active because rxe0 is still alive +if ! ss -Huln sport = :$PORT | grep -q ":$PORT"; then + echo "Error: UDP port $PORT closed prematurely" + exit 1 +fi + +echo "Deleting rxe0..." +rdma link del rxe0 + +# Port should now be gone +if ss -Huln sport = :$PORT | grep -q ":$PORT"; then + echo "Error: UDP port $PORT still exists after all links deleted" + exit 1 +fi + +echo "Test passed successfully."tools/testing/selftests/rdma/rxe_test_NETDEV_UNREGISTER.sh new file +63
-0@@ -0,0 +1,63 @@ +#!/bin/bash + +# Configuration +DEV_NAME="tun0" +RXE_NAME="rxe0" +RDMA_PORT=4791 + +exec > /dev/null + +# --- Cleanup Routine --- +# Ensures environment is clean even if the script hits an error +cleanup() { + echo "Performing cleanup..." + rdma link del $RXE_NAME 2>/dev/null + ip link del $DEV_NAME 2>/dev/null + modprobe -r rdma_rxe 2>/dev/null +} +trap cleanup EXIT + +# 1. Dependency Check +if ! modinfo rdma_rxe >/dev/null 2>&1; then + echo "Error: rdma_rxe module not found." + exit 1 +fi + +modprobe rdma_rxe + +# 2. Setup TUN Device +echo "Creating $DEV_NAME..." +ip tuntap add mode tun "$DEV_NAME" +ip addr add 1.1.1.1/24 dev "$DEV_NAME" +ip link set "$DEV_NAME" up + +# 3. Attach RXE Link +echo "Attaching RXE link $RXE_NAME to $DEV_NAME..." +rdma link add "$RXE_NAME" type rxe netdev "$DEV_NAME" + +# 4. Verification: Port Check +# Use -H (no header) and -q (quiet) for cleaner scripting logic +if ! ss -Huln sport == :$RDMA_PORT | grep -q ":$RDMA_PORT"; then + echo "Error: UDP port $RDMA_PORT is not listening." + exit 1 +fi +echo "Verified: RXE is listening on UDP $RDMA_PORT." + +# 5. Trigger NETDEV_UNREGISTER +# We delete the underlying device without deleting the RDMA link first. +echo "Triggering NETDEV_UNREGISTER by deleting $DEV_NAME..." +ip link del "$DEV_NAME" + +# 6. Final Verification +# The RXE link and the UDP port should be automatically cleaned up by the kernel. +if rdma link show "$RXE_NAME" 2>/dev/null; then + echo "Error: $RXE_NAME still exists after netdev removal." + exit 1 +fi + +if ss -Huln sport == :$RDMA_PORT | grep -q ":$RDMA_PORT"; then + echo "Error: UDP port $RDMA_PORT still listening after netdev removal." + exit 1 +fi + +echo "Success: NETDEV_UNREGISTER handled correctly."
Signature · 2 lines
Best Regards, Yanjun.Zhu