Fix the problem that rxe can not work in net namespace
Subsystems (2)
v5 cover Fix the problem that rxe can not work in net namespace
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in init_net when the rdma_rxe module is loaded into kernel. That is, the sock listening on udp port 4791 is created in init_net. Other net namespace is difficult to use this sock.
The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from module_init function to rdma link creating functions. That is, after the module rdma_rxe is loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.
In the second commit, the functions udp4_lib_lookup and udp6_lib_lookup will check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the module rdma_rxe is loaded, this notifier will be registered.
After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions udp4_lib_lookup and udp6_lib_lookup totally. Because the function udp6_lib_lookup is in the fast path, a member variable l_sk6 is added to store the sock. If l_sk6 is NULL, udp6_lib_lookup is called to lookup the sock, then the sock is stored in l_sk6, in the future,it can be used directly.
All the above work has been done in init_net. And it can also work in the net namespace. So the init_net is replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.
In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new l_sk6. As such, in the 8th commit, the l_sk6 is replaced with the sk6 in pernet namespace.
Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.
# ip netns exec net0 ip link
3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP
link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff
altname enp5s0 # ip netns exec net1 ip link
4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel
link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2
net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno3
3) Run rping test.
net0
# ip netns exec net0 rping -s -a 192.168.2.1 -C 1&
[1] 1737
# ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1
verbose
count 1
...
ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr
...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*
# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
net1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*
# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replace l_sk6 with sk6 of pernet_name_space
V1->V2: Add the explicit initialization of sk6.
Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links in init_net RDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replace l_sk6 with sk6 in net namespace
drivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-) create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.c create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.h
Signature · 1 line
2.27.0
PATCH v5 1/8 RDMA/rxe: Creating listening sock in newlink function
From: Zhu Yanjun <[email protected]>
Originally when the module rdma_rxe is loaded, the sock listening on udp port 4791 is created. Currently moving the creating listening port to newlink function.
So when running "rdma link add" command, the sock listening on udp port 4791 is created.
--- drivers/infiniband/sw/rxe/rxe.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +4 -6
@@ -194,6 +194,10 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) goto err; } + err =rxe_net_init (); +if (err) +return err; + err =rxe_net_add (ibdev_name, ndev);if (err) {rxe_err ("failed to add %s\n" , ndev->name);
@@ -210,12 +214,6 @@ static struct rdma_link_ops rxe_link_ops = {static int __init rxe_module_init (void ) { -int err; - - err =rxe_net_init (); -if (err) -return err; -rdma_link_register (&rxe_link_ops);pr_info ("loaded\n" );return 0 ;
Signature · 1 line
2.27.0
Re: [PATCH v6.4-rc1 v5 1/8] RDMA/rxe: Creating listening sock in newlink function
Quoted 20 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
Originally when the module
rdma_rxeis loaded, the sock listening on udp port 4791 is created. Currently moving the creating listening port to newlink function.So when running "rdma link add" command, the sock listening on udp port 4791 is created.
Tested-by Rain River <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/infiniband/sw/rxe/rxe.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/infiniband/sw/rxe/rxe.c +0
-0
drivers/infiniband/sw/rxe/rxe.c static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) · line 200
Quoted 7 lines
drivers/infiniband/sw/rxe/rxe.c +4
-0@@ -194,6 +194,10 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) goto err; } + err =rxe_net_init (); +if (err) +return err; +
If you put this here you cannot create more than one rxe device. E.g. if you type
sudo rdma link add rxe0 type rxe netdev enp6s0
sudo rdma link add rxe1 type rxe netdev lo
the second call will fail. This worked before this patch. Maybe you will fix later but by itself this patch breaks the driver.
Bob
Quoted 16 lines
drivers/infiniband/sw/rxe/rxe.c +0
-6err =rxe_net_add (ibdev_name, ndev);if (err) {rxe_err ("failed to add %s\n" , ndev->name);@@ -210,12 +214,6 @@ static struct rdma_link_ops rxe_link_ops = {static int __init rxe_module_init (void ) { -int err; - - err =rxe_net_init (); -if (err) -return err; -rdma_link_register (&rxe_link_ops);pr_info ("loaded\n" );return 0 ;
Re: [PATCH v6.4-rc1 v5 1/8] RDMA/rxe: Creating listening sock in newlink function
Quoted 31 lines · Bob Pearson
Quoted 20 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
Originally when the module
rdma_rxeis loaded, the sock listening on udp port 4791 is created. Currently moving the creating listening port to newlink function.So when running "rdma link add" command, the sock listening on udp port 4791 is created.
Tested-by Rain River <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/infiniband/sw/rxe/rxe.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/infiniband/sw/rxe/rxe.c +0
-0drivers/infiniband/sw/rxe/rxe.c static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) · line 200
Quoted 7 lines
drivers/infiniband/sw/rxe/rxe.c +4
-0@@ -194,6 +194,10 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) goto err; } + err =rxe_net_init (); +if (err) +return err; +If you put this here you cannot create more than one rxe device. E.g. if you type
Quoted 5 lines
sudo rdma link add rxe0 type rxe netdev enp6s0
sudo rdma link add rxe1 type rxe netdev lothe second call will fail. This worked before this patch. Maybe you will fix later but by itself this patch breaks the driver.
Hi, Bob
Thanks a lot for your code review.
I made tests. The followings are results. If we add the secode rxe1, the second rxe can be created.
# rdma link add rxe0 type rxe netdev eno12399np0 # rdma link add rxe1 type rxe netdev ens7f1np1 # rdma link
link rxe0/1 state ACTIVE physical_state LINK_UP netdev eno12399np0 link rxe1/1 state ACTIVE physical_state LINK_UP netdev ens7f1np1
And the followings are the port 4791 after rxe devices are created.
# ss -lun State Recv-Q Send-Q Local Address:Port Peer Address:Port Process ... UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* ... UNCONN 0 0 [::]:4791 [::]:* ..
# rdma link del rxe0 # rdma link del rxe1
After the rxe devices are removed, the port 4791 is removed.
# ss -lun | grep 4791 State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
Zhu Yanjun
Quoted 18 lines
Bob
Quoted 16 lines
drivers/infiniband/sw/rxe/rxe.c +0
-6err =rxe_net_add (ibdev_name, ndev);if (err) {rxe_err ("failed to add %s\n" , ndev->name);@@ -210,12 +214,6 @@ static struct rdma_link_ops rxe_link_ops = {static int __init rxe_module_init (void ) { -int err; - - err =rxe_net_init (); -if (err) -return err; -rdma_link_register (&rxe_link_ops);pr_info ("loaded\n" );return 0 ;
PATCH v5 2/8 RDMA/rxe: Support more rdma links in init_net
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
In init_net, when several rdma links are created with the command "rdma link add", newlink will check whether the udp port 4791 is listening or not.
If not, creating a sock listening on udp port 4791. If yes, increasing the reference count of the sock.
--- drivers/infiniband/sw/rxe/rxe.c | 12 ++++++- drivers/infiniband/sw/rxe/rxe_net.c | 55 +++++++++++++++++++++-------- drivers/infiniband/sw/rxe/rxe_net.h | 1 + 3 files changed, 52 insertions(+), 16 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +11 -1
@@ -8,6 +8,7 @@#include <net/addrconf.h> #include "rxe.h" #include "rxe_loc.h" +#include "rxe_net.h" MODULE_AUTHOR ("Bob Pearson, Frank Zago, John Groves, Kamal Heib" );MODULE_DESCRIPTION ("Soft RDMA transport" );
@@ -207,14 +208,23 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)return err; } -static struct rdma_link_ops rxe_link_ops = { +struct rdma_link_ops rxe_link_ops = { .type ="rxe" , .newlink = rxe_newlink, };static int __init rxe_module_init (void ) { +int err; +rdma_link_register (&rxe_link_ops); + + err =rxe_register_notifier (); +if (err) { +pr_err ("Failed to register netdev notifier\n" ); +return -1 ; + } +pr_info ("loaded\n" );return 0 ; }
drivers/infiniband/sw/rxe/rxe_net.c +40 -15
96 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_net.h +1 -0
@@ -18,6 +18,7 @@ struct rxe_recv_sockets {int rxe_net_add (const char *ibdev_name,struct net_device *ndev); +int rxe_register_notifier (void );int rxe_net_init (void );void rxe_net_exit (void );
Signature · 1 line
2.27.0
Re: [PATCH v6.4-rc1 v5 2/8] RDMA/rxe: Support more rdma links in init_net
Quoted 64 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
In
init_net, when several rdma links are created with the command "rdma link add", newlink will check whether the udp port 4791 is listening or not.
If not, creating a sock listening on udp port 4791. If yes, increasing the reference count of the sock.Tested-by Rain River <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/infiniband/sw/rxe/rxe.c | 12 ++++++- drivers/infiniband/sw/rxe/rxe_net.c | 55 +++++++++++++++++++++-------- drivers/infiniband/sw/rxe/rxe_net.h | 1 + 3 files changed, 52 insertions(+), 16 deletions(-)drivers/infiniband/sw/rxe/rxe.c +11
-1@@ -8,6 +8,7 @@#include <net/addrconf.h> #include "rxe.h" #include "rxe_loc.h" +#include "rxe_net.h" MODULE_AUTHOR ("Bob Pearson, Frank Zago, John Groves, Kamal Heib" );MODULE_DESCRIPTION ("Soft RDMA transport" );@@ -207,14 +208,23 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)return err; } -static struct rdma_link_ops rxe_link_ops = { +struct rdma_link_ops rxe_link_ops = { .type ="rxe" , .newlink = rxe_newlink, };static int __init rxe_module_init (void ) { +int err; +rdma_link_register (&rxe_link_ops); + + err =rxe_register_notifier (); +if (err) { +pr_err ("Failed to register netdev notifier\n" ); +return -1 ; + } +pr_info ("loaded\n" );return 0 ; }drivers/infiniband/sw/rxe/rxe_net.c +0
-3@@ -626,13 +626,23 @@ static struct notifier_block rxe_net_notifier = {static int rxe_net_ipv4_init (void ) { - recv_sockets.sk4 =rxe_setup_udp_tunnel (&init_net, -htons (ROCE_V2_UDP_DPORT ), false); -if (IS_ERR (recv_sockets.sk4)) {
drivers/infiniband/sw/rxe/rxe_net.c static struct notifier_block rxe_net_notifier = { · line 637
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_net.c +9
-1- recv_sockets.sk4 =NULL ; +struct sock *sk; +struct socket *sock; + +rcu_read_lock (); + sk =udp4_lib_lookup (&init_net,0 ,0 ,htonl (INADDR_ANY ), +htons (ROCE_V2_UDP_DPORT ),0 ); +rcu_read_unlock (); +if (sk) +return 0 ;
After this patch 2/8 attempting to execute
sudo rdma link add rxe[n] type rxe netdev exxxx
more than once now succeeds and both devices show up.
I would suggest that you merge patch 1/8 and 2/8 so patches don't break the driver.
Bob
Quoted 94 lines
drivers/infiniband/sw/rxe/rxe_net.c +31
-11+ + sock =rxe_setup_udp_tunnel (&init_net,htons (ROCE_V2_UDP_DPORT ), false); +if (IS_ERR (sock)) {pr_err ("Failed to create IPv4 UDP tunnel\n" ); + recv_sockets.sk4 =NULL ;return -1 ; } + recv_sockets.sk4 = sock;return 0 ; }@@ -640,24 +650,46 @@ static int rxe_net_ipv4_init(void)static int rxe_net_ipv6_init (void ) {#if IS_ENABLED (CONFIG_IPV6 ) +struct sock *sk; +struct socket *sock; + +rcu_read_lock (); + sk =udp6_lib_lookup (&init_net,NULL ,0 , &in6addr_any, +htons (ROCE_V2_UDP_DPORT ),0 ); +rcu_read_unlock (); +if (sk) +return 0 ; - recv_sockets.sk6 =rxe_setup_udp_tunnel (&init_net, -htons (ROCE_V2_UDP_DPORT ), true); -if (PTR_ERR (recv_sockets.sk6) == -EAFNOSUPPORT ) { + sock =rxe_setup_udp_tunnel (&init_net,htons (ROCE_V2_UDP_DPORT ), true); +if (PTR_ERR (sock) == -EAFNOSUPPORT ) { recv_sockets.sk6 =NULL ;pr_warn ("IPv6 is not supported, can not create a UDPv6 socket\n" );return 0 ; } -if (IS_ERR (recv_sockets.sk6)) { +if (IS_ERR (sock)) { recv_sockets.sk6 =NULL ;pr_err ("Failed to create IPv6 UDP tunnel\n" );return -1 ; } + recv_sockets.sk6 = sock;#endif return 0 ; } +int rxe_register_notifier (void ) +{ +int err; + + err =register_netdevice_notifier (&rxe_net_notifier); +if (err) { +pr_err ("Failed to register netdev notifier\n" ); +return -1 ; + } + +return 0 ; +} +void rxe_net_exit (void ) {rxe_release_udp_tunnel (recv_sockets.sk6);@@ -669,19 +701,12 @@ int rxe_net_init(void) {int err; - recv_sockets.sk6 =NULL ; - err =rxe_net_ipv4_init ();if (err)return err; err =rxe_net_ipv6_init ();if (err) goto err_out; - err =register_netdevice_notifier (&rxe_net_notifier); -if (err) { -pr_err ("Failed to register netdev notifier\n" ); - goto err_out; - }return 0 ; err_out:rxe_net_exit ();drivers/infiniband/sw/rxe/rxe_net.h +1
-0@@ -18,6 +18,7 @@ struct rxe_recv_sockets {int rxe_net_add (const char *ibdev_name,struct net_device *ndev); +int rxe_register_notifier (void );int rxe_net_init (void );void rxe_net_exit (void );
Re: [PATCH v6.4-rc1 v5 2/8] RDMA/rxe: Support more rdma links in init_net
Quoted 72 lines · Bob Pearson
Quoted 71 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
In
init_net, when several rdma links are created with the command "rdma link add", newlink will check whether the udp port 4791 is listening or not.
If not, creating a sock listening on udp port 4791. If yes, increasing the reference count of the sock.Tested-by Rain River <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/infiniband/sw/rxe/rxe.c | 12 ++++++- drivers/infiniband/sw/rxe/rxe_net.c | 55 +++++++++++++++++++++-------- drivers/infiniband/sw/rxe/rxe_net.h | 1 + 3 files changed, 52 insertions(+), 16 deletions(-)drivers/infiniband/sw/rxe/rxe.c +11
-1@@ -8,6 +8,7 @@#include <net/addrconf.h> #include "rxe.h" #include "rxe_loc.h" +#include "rxe_net.h" MODULE_AUTHOR ("Bob Pearson, Frank Zago, John Groves, Kamal Heib" );MODULE_DESCRIPTION ("Soft RDMA transport" );@@ -207,14 +208,23 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)return err; } -static struct rdma_link_ops rxe_link_ops = { +struct rdma_link_ops rxe_link_ops = { .type ="rxe" , .newlink = rxe_newlink, };static int __init rxe_module_init (void ) { +int err; +rdma_link_register (&rxe_link_ops); + + err =rxe_register_notifier (); +if (err) { +pr_err ("Failed to register netdev notifier\n" ); +return -1 ; + } +pr_info ("loaded\n" );return 0 ; }drivers/infiniband/sw/rxe/rxe_net.c +6
-4@@ -626,13 +626,23 @@ static struct notifier_block rxe_net_notifier = {static int rxe_net_ipv4_init (void ) { - recv_sockets.sk4 =rxe_setup_udp_tunnel (&init_net, -htons (ROCE_V2_UDP_DPORT ), false); -if (IS_ERR (recv_sockets.sk4)) { - recv_sockets.sk4 =NULL ; +struct sock *sk; +struct socket *sock; + +rcu_read_lock (); + sk =udp4_lib_lookup (&init_net,0 ,0 ,htonl (INADDR_ANY ), +htons (ROCE_V2_UDP_DPORT ),0 );
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_net.c static struct notifier_block rxe_net_notifier = { · line 637
Quoted 3 lines
drivers/infiniband/sw/rxe/rxe_net.c +3
-0+rcu_read_unlock (); +if (sk) +return 0 ;After this patch 2/8 attempting to execute
sudo rdma link add rxe[n] type rxe netdev exxxx
more than once now succeeds and both devices show up.
I would suggest that you merge patch 1/8 and 2/8 so patches don't break the driver.
I split the steps to implement net namespace into several commits. So we can find out
what we have done to implement net namespace. The viewer can easily catch the steps.
Your suggestions seem to make sense. Let me consider sorting out the commits.
Zhu Yanjun
Quoted 96 lines
Bob
Quoted 94 lines
drivers/infiniband/sw/rxe/rxe_net.c +31
-11+ + sock =rxe_setup_udp_tunnel (&init_net,htons (ROCE_V2_UDP_DPORT ), false); +if (IS_ERR (sock)) {pr_err ("Failed to create IPv4 UDP tunnel\n" ); + recv_sockets.sk4 =NULL ;return -1 ; } + recv_sockets.sk4 = sock;return 0 ; }@@ -640,24 +650,46 @@ static int rxe_net_ipv4_init(void)static int rxe_net_ipv6_init (void ) {#if IS_ENABLED (CONFIG_IPV6 ) +struct sock *sk; +struct socket *sock; + +rcu_read_lock (); + sk =udp6_lib_lookup (&init_net,NULL ,0 , &in6addr_any, +htons (ROCE_V2_UDP_DPORT ),0 ); +rcu_read_unlock (); +if (sk) +return 0 ; - recv_sockets.sk6 =rxe_setup_udp_tunnel (&init_net, -htons (ROCE_V2_UDP_DPORT ), true); -if (PTR_ERR (recv_sockets.sk6) == -EAFNOSUPPORT ) { + sock =rxe_setup_udp_tunnel (&init_net,htons (ROCE_V2_UDP_DPORT ), true); +if (PTR_ERR (sock) == -EAFNOSUPPORT ) { recv_sockets.sk6 =NULL ;pr_warn ("IPv6 is not supported, can not create a UDPv6 socket\n" );return 0 ; } -if (IS_ERR (recv_sockets.sk6)) { +if (IS_ERR (sock)) { recv_sockets.sk6 =NULL ;pr_err ("Failed to create IPv6 UDP tunnel\n" );return -1 ; } + recv_sockets.sk6 = sock;#endif return 0 ; } +int rxe_register_notifier (void ) +{ +int err; + + err =register_netdevice_notifier (&rxe_net_notifier); +if (err) { +pr_err ("Failed to register netdev notifier\n" ); +return -1 ; + } + +return 0 ; +} +void rxe_net_exit (void ) {rxe_release_udp_tunnel (recv_sockets.sk6);@@ -669,19 +701,12 @@ int rxe_net_init(void) {int err; - recv_sockets.sk6 =NULL ; - err =rxe_net_ipv4_init ();if (err)return err; err =rxe_net_ipv6_init ();if (err) goto err_out; - err =register_netdevice_notifier (&rxe_net_notifier); -if (err) { -pr_err ("Failed to register netdev notifier\n" ); - goto err_out; - }return 0 ; err_out:rxe_net_exit ();drivers/infiniband/sw/rxe/rxe_net.h +1
-0@@ -18,6 +18,7 @@ struct rxe_recv_sockets {int rxe_net_add (const char *ibdev_name,struct net_device *ndev); +int rxe_register_notifier (void );int rxe_net_init (void );void rxe_net_exit (void );
PATCH v5 3/8 RDMA/nldev: Add dellink function pointer
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
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
@@ -1758,6 +1758,12 @@ static int nldev_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,return -EINVAL ; } +if (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> enum {RDMA_NLDEV_ATTR_EMPTY_STRING =1 ,
@@ -114,6 +115,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.27.0
PATCH v5 4/8 RDMA/rxe: Implement dellink in rxe
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
When running "rdma link del" command, dellink function will be called. If the sock refcnt is greater than the refcnt needed for udp tunnel, the sock refcnt will be decreased by 1.
If equal, the last rdma link is removed. The udp tunnel will be destroyed.
--- drivers/infiniband/sw/rxe/rxe.c | 12 +++++++++++- drivers/infiniband/sw/rxe/rxe_net.c | 17 +++++++++++++++-- drivers/infiniband/sw/rxe/rxe_net.h | 1 + 3 files changed, 27 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +11 -1
@@ -168,10 +168,12 @@ void rxe_set_mtu(struct rxe_dev *rxe, unsigned int ndev_mtu)/* called by ifc layer to create new rxe device. * The caller should allocate memory for rxe by calling ib_alloc_device. */ +static struct rdma_link_ops rxe_link_ops;int rxe_add (struct rxe_dev *rxe,unsigned int mtu,const char *ibdev_name) {rxe_init (rxe);rxe_set_mtu (rxe, mtu); + rxe->ib_dev.link_ops = &rxe_link_ops;return rxe_register_device (rxe, ibdev_name); }
@@ -208,9 +210,17 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev)return err; } -struct rdma_link_ops rxe_link_ops = { +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 )
drivers/infiniband/sw/rxe/rxe_net.c +15 -2
@@ -533,6 +533,21 @@ int rxe_net_add(const char *ibdev_name, struct net_device *ndev)return 0 ; } +#define SK_REF_FOR_TUNNEL 2 +void rxe_net_del (struct ib_device *dev) +{ +if (refcount_read (&recv_sockets.sk6->sk->sk_refcnt) >SK_REF_FOR_TUNNEL ) +__sock_put (recv_sockets.sk6->sk); +else +rxe_release_udp_tunnel (recv_sockets.sk6); + +if (refcount_read (&recv_sockets.sk4->sk->sk_refcnt) >SK_REF_FOR_TUNNEL ) +__sock_put (recv_sockets.sk4->sk); +else +rxe_release_udp_tunnel (recv_sockets.sk4); +} +#undef SK_REF_FOR_TUNNEL +static void rxe_port_event (struct rxe_dev *rxe,enum ib_event_type event) {
@@ -692,8 +707,6 @@ int rxe_register_notifier(void)void rxe_net_exit (void ) { -rxe_release_udp_tunnel (recv_sockets.sk6); -rxe_release_udp_tunnel (recv_sockets.sk4);unregister_netdevice_notifier (&rxe_net_notifier); }
drivers/infiniband/sw/rxe/rxe_net.h +1 -0
@@ -17,6 +17,7 @@ struct rxe_recv_sockets { };int rxe_net_add (const char *ibdev_name,struct net_device *ndev); +void rxe_net_del (struct ib_device *dev);int rxe_register_notifier (void );int rxe_net_init (void );
Signature · 1 line
2.27.0
PATCH v5 5/8 RDMA/rxe: Replace global variable with sock lookup functions
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
Originally a global variable is to keep the sock of udp listening on port 4791. In fact, sock lookup functions can be used to get the sock.
--- drivers/infiniband/sw/rxe/rxe.c | 1 + drivers/infiniband/sw/rxe/rxe_net.c | 58 ++++++++++++++++++++------- drivers/infiniband/sw/rxe/rxe_net.h | 5 --- drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 4 files changed, 45 insertions(+), 20 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +1 -0
@@ -74,6 +74,7 @@ static void rxe_init_device_param(struct rxe_dev *rxe) rxe->ndev->dev_addr); rxe->max_ucontext =RXE_MAX_UCONTEXT ; + rxe->l_sk6 =NULL ; }/* initialize port attributes */
drivers/infiniband/sw/rxe/rxe_net.c +43 -15
107 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_net.h +0 -5
@@ -11,11 +11,6 @@#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);
drivers/infiniband/sw/rxe/rxe_verbs.h +1 -0
@@ -382,6 +382,7 @@ struct rxe_dev {struct rxe_port port;struct crypto_shash *tfm; +struct socket *l_sk6; };static inline void rxe_counter_inc (struct rxe_dev *rxe,enum rxe_counters index)
Signature · 1 line
2.27.0
PATCH v5 6/8 RDMA/rxe: add the support of net namespace
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
Originally init_net is used to indicate the current net namespace. Currently more net namespaces are supported.
--- drivers/infiniband/sw/rxe/rxe.c | 2 +- drivers/infiniband/sw/rxe/rxe_net.c | 33 +++++++++++++++++------------ drivers/infiniband/sw/rxe/rxe_net.h | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +1 -1
@@ -198,7 +198,7 @@ static int rxe_newlink(const char *ibdev_name, struct net_device *ndev) goto err; } - err =rxe_net_init (); + err =rxe_net_init (ndev);if (err)return err;
drivers/infiniband/sw/rxe/rxe_net.c +20 -13
@@ -32,7 +32,7 @@ static struct dst_entry *rxe_find_route4(struct rxe_qp *qp,memcpy (&fl.daddr, daddr,sizeof (*daddr)); fl.flowi4_proto =IPPROTO_UDP ; - rt =ip_route_output_key (&init_net, &fl); + rt =ip_route_output_key (dev_net (ndev), &fl);if (IS_ERR (rt)) {rxe_dbg_qp (qp,"no route to %pI4\n" , &daddr->s_addr);return NULL ;
@@ -56,7 +56,8 @@ static struct dst_entry *rxe_find_route6(struct rxe_qp *qp,struct sock *sk;rcu_read_lock (); - sk =udp6_lib_lookup (&init_net,NULL ,0 , &in6addr_any,htons (ROCE_V2_UDP_DPORT ),0 ); + sk =udp6_lib_lookup (dev_net (ndev),NULL ,0 , &in6addr_any, +htons (ROCE_V2_UDP_DPORT ),0 );rcu_read_unlock ();if (!sk) {pr_info ("file: %s +%d, error\n" , __FILE__, __LINE__);
@@ -552,9 +553,13 @@ int rxe_net_add(const char *ibdev_name, struct net_device *ndev)void rxe_net_del (struct ib_device *dev) {struct sock *sk; +struct rxe_dev *rdev; + + rdev = container_of(dev, struct rxe_dev, ib_dev);rcu_read_lock (); - sk =udp4_lib_lookup (&init_net,0 ,0 ,htonl (INADDR_ANY ),htons (ROCE_V2_UDP_DPORT ),0 ); + sk =udp4_lib_lookup (dev_net (rdev->ndev),0 ,0 ,htonl (INADDR_ANY ), +htons (ROCE_V2_UDP_DPORT ),0 );rcu_read_unlock ();if (!sk)return ;
@@ -567,7 +572,8 @@ void rxe_net_del(struct ib_device *dev)rxe_release_udp_tunnel (sk->sk_socket);rcu_read_lock (); - sk =udp6_lib_lookup (&init_net,NULL ,0 , &in6addr_any,htons (ROCE_V2_UDP_DPORT ),0 ); + sk =udp6_lib_lookup (dev_net (rdev->ndev),NULL ,0 , &in6addr_any, +htons (ROCE_V2_UDP_DPORT ),0 );rcu_read_unlock ();if (!sk)return ;
@@ -639,6 +645,7 @@ static int rxe_notify(struct notifier_block *not_blk,switch (event) {case NETDEV_UNREGISTER :ib_unregister_device_queued (&rxe->ib_dev); +rxe_net_del (&rxe->ib_dev);break ;case NETDEV_UP :rxe_port_up (rxe);
@@ -672,19 +679,19 @@ static struct notifier_block rxe_net_notifier = { .notifier_call = rxe_notify, }; -static int rxe_net_ipv4_init (void ) +static int rxe_net_ipv4_init (struct net_device *ndev) {struct sock *sk;struct socket *sock;rcu_read_lock (); - sk =udp4_lib_lookup (&init_net,0 ,0 ,htonl (INADDR_ANY ), + sk =udp4_lib_lookup (dev_net (ndev),0 ,0 ,htonl (INADDR_ANY ),htons (ROCE_V2_UDP_DPORT ),0 );rcu_read_unlock ();if (sk)return 0 ; - sock =rxe_setup_udp_tunnel (&init_net,htons (ROCE_V2_UDP_DPORT ), false); + sock =rxe_setup_udp_tunnel (dev_net (ndev),htons (ROCE_V2_UDP_DPORT ), false);if (IS_ERR (sock)) {pr_err ("Failed to create IPv4 UDP tunnel\n" );return -1 ;
@@ -693,20 +700,20 @@ static int rxe_net_ipv4_init(void)return 0 ; } -static int rxe_net_ipv6_init (void ) +static int rxe_net_ipv6_init (struct net_device *ndev) {#if IS_ENABLED (CONFIG_IPV6 )struct sock *sk;struct socket *sock;rcu_read_lock (); - sk =udp6_lib_lookup (&init_net,NULL ,0 , &in6addr_any, + sk =udp6_lib_lookup (dev_net (ndev),NULL ,0 , &in6addr_any,htons (ROCE_V2_UDP_DPORT ),0 );rcu_read_unlock ();if (sk)return 0 ; - sock =rxe_setup_udp_tunnel (&init_net,htons (ROCE_V2_UDP_DPORT ), true); + sock =rxe_setup_udp_tunnel (dev_net (ndev),htons (ROCE_V2_UDP_DPORT ), true);if (PTR_ERR (sock) == -EAFNOSUPPORT ) {pr_warn ("IPv6 is not supported, can not create a UDPv6 socket\n" );return 0 ;
@@ -738,14 +745,14 @@ void rxe_net_exit(void)unregister_netdevice_notifier (&rxe_net_notifier); } -int rxe_net_init (void ) +int rxe_net_init (struct net_device *ndev) {int err; - err =rxe_net_ipv4_init (); + err =rxe_net_ipv4_init (ndev);if (err)return err; - err =rxe_net_ipv6_init (); + err =rxe_net_ipv6_init (ndev);if (err) goto err_out;return 0 ;
drivers/infiniband/sw/rxe/rxe_net.h +1 -1
@@ -15,7 +15,7 @@ int rxe_net_add(const char *ibdev_name, struct net_device *ndev);void rxe_net_del (struct ib_device *dev);int rxe_register_notifier (void ); -int rxe_net_init (void ); +int rxe_net_init (struct net_device *ndev);void rxe_net_exit (void );#endif /* RXE_NET_H */
Signature · 1 line
2.27.0
PATCH v5 7/8 RDMA/rxe: Add the support of net namespace notifier
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
The functions register_pernet_subsys/unregister_pernet_subsys register a notifier of net namespace. When a new net namespace is created, the init function of rxe will be called to initialize sk4 and sk6 socks. When a net namespace is destroyed, the exit function will be called to handle sk4 and sk6 socks.
The functions rxe_ns_pernet_sk4 and rxe_ns_pernet_sk6 are used to get sk4 and sk6 socks.
The functions rxe_ns_pernet_set_sk4 and rxe_ns_pernet_set_sk6 are used to set sk4 and sk6 socks.
--- drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 9 ++ drivers/infiniband/sw/rxe/rxe_net.c | 50 +++++------ drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ 5 files changed, 187 insertions(+), 26 deletions(-) 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,4 +22,5 @@ rdma_rxe-y := \ rxe_mcast.o \ rxe_task.o \ rxe_net.o \ - rxe_hw_counters.o + rxe_hw_counters.o \ + rxe_ns.o
drivers/infiniband/sw/rxe/rxe.c +9 -0
@@ -9,6 +9,7 @@#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" );
@@ -236,6 +237,12 @@ static int __init rxe_module_init(void)return -1 ; } + err =rxe_namespace_init (); +if (err) { +pr_err ("Failed to register net namespace notifier\n" ); +return -1 ; + } +pr_info ("loaded\n" );return 0 ; }
@@ -246,6 +253,8 @@ static void __exit rxe_module_exit(void)ib_unregister_driver (RDMA_DRIVER_RXE );rxe_net_exit (); +rxe_namespace_exit (); +pr_info ("unloaded\n" ); }
drivers/infiniband/sw/rxe/rxe_net.c +25 -25
100 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_ns.c new file +134 -0
134 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_ns.h new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* +* Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. +* Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. +*/ + +#ifndef RXE_NS_H +#define RXE_NS_H + +struct sock *rxe_ns_pernet_sk4 (struct net *net); +struct sock *rxe_ns_pernet_sk6 (struct net *net); +void rxe_ns_pernet_set_sk4 (struct net *net,struct sock *sk); +void rxe_ns_pernet_set_sk6 (struct net *net,struct sock *sk); +int __init rxe_namespace_init (void ); +void __exit rxe_namespace_exit(void); + +#endif /* RXE_NS_H */
Signature · 1 line
2.27.0
PATCH v5 8/8 RDMA/rxe: Replace l_sk6 with sk6 in net namespace
In reply to Zhu YanjunFrom: Zhu Yanjun <[email protected]>
The net namespace variable sk6 can be used. As such, l_sk6 can be replaced with it.
--- drivers/infiniband/sw/rxe/rxe.c | 1 - drivers/infiniband/sw/rxe/rxe_net.c | 20 +------------------- drivers/infiniband/sw/rxe/rxe_verbs.h | 1 - 3 files changed, 1 insertion(+), 21 deletions(-)
drivers/infiniband/sw/rxe/rxe.c +0 -1
@@ -75,7 +75,6 @@ static void rxe_init_device_param(struct rxe_dev *rxe) rxe->ndev->dev_addr); rxe->max_ucontext =RXE_MAX_UCONTEXT ; - rxe->l_sk6 =NULL ; }/* initialize port attributes */
drivers/infiniband/sw/rxe/rxe_net.c +1 -19
@@ -50,24 +50,6 @@ static struct dst_entry *rxe_find_route6(struct rxe_qp *qp, {struct dst_entry *ndst;struct flowi6 fl6 = { {0 } }; -struct rxe_dev *rdev; - - rdev =rxe_get_dev_from_net (ndev); -if (!rdev->l_sk6) { -struct sock *sk; - -rcu_read_lock (); - sk =udp6_lib_lookup (dev_net (ndev),NULL ,0 , &in6addr_any, -htons (ROCE_V2_UDP_DPORT ),0 ); -rcu_read_unlock (); -if (!sk) { -pr_info ("file: %s +%d, error\n" , __FILE__, __LINE__); -return (struct dst_entry *)sk; - } -__sock_put (sk); - rdev->l_sk6 = sk->sk_socket; - } -memset (&fl6,0 ,sizeof (fl6)); fl6.flowi6_oif = ndev->ifindex;
@@ -76,7 +58,7 @@ static struct dst_entry *rxe_find_route6(struct rxe_qp *qp, fl6.flowi6_proto =IPPROTO_UDP ; ndst = ipv6_stub->ipv6_dst_lookup_flow (dev_net (ndev), - rdev->l_sk6->sk, &fl6, +rxe_ns_pernet_sk6 (dev_net (ndev)), &fl6,NULL );if (IS_ERR (ndst)) {rxe_dbg_qp (qp,"no route to %pI6\n" , daddr);
drivers/infiniband/sw/rxe/rxe_verbs.h +0 -1
@@ -382,7 +382,6 @@ struct rxe_dev {struct rxe_port port;struct crypto_shash *tfm; -struct socket *l_sk6; };static inline void rxe_counter_inc (struct rxe_dev *rxe,enum rxe_counters index)
Signature · 1 line
2.27.0
Quoted 138 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0 # ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespace
Quoted 12 lines
drivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-) create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.c create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.hip netns add test
Zhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Bob
Quoted 207 lines · Bob Pearson
Quoted 138 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0 # ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespaceQuoted 12 lines
drivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-) create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.c create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.hip netns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]
Quoted 5 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Bob
Forgot to mention. It also is definitely not good that a process in the default namespace can destroy a rxe device in the test namespace by trying to use it.
Bob
Quoted 207 lines · Bob Pearson
Quoted 206 lines · Bob Pearson
Quoted 147 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0 # ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-)Quoted 3 lines
create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]
Quoted 7 lines
Quoted 5 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Bob
Forgot to mention. It also is definitely not good that a process in the default namespace can destroy a rxe device in the test namespace by trying to use it.
Thanks a lot.
I am not sure if it is correct or not to destroy a rxe device outside this this net namespace.
Because to irdma/mlx5 rdma devices, we can also destroy them with the command "modprobe -v irdma/mlx5..." outside of the net namespace.
I am not sure if this is correct or not.
Zhu Yanjun
Quoted 2 lines
Bob
Quoted 219 lines · Zhu Yanjun
Quoted 207 lines · Bob Pearson
Quoted 206 lines · Bob Pearson
Quoted 146 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0# ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++-
drivers/infiniband/sw/rxe/rxe_net.c| 113 +++++++++++++++++------drivers/infiniband/sw/rxe/rxe_net.h| 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 +Quoted 4 lines
8 files changed, 279 insertions(+), 40 deletions(-)create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]Quoted 7 lines
Quoted 5 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Bob
Forgot to mention. It also is definitely not good that a process in the default namespace can destroy a rxe device in the test namespace by trying to use it.
Thanks a lot.
Quoted 10 lines
I am not sure if it is correct or not to destroy a rxe device outside this this net namespace.
Because to irdma/mlx5 rdma devices, we can also destroy them with the command "modprobe -v irdma/mlx5..." outside of the net namespace.
I am not sure if this is correct or not.
Zhu Yanjun
Quoted 2 lines
Bob
I didn' intentionally destroy lo2. I just tried to access the rxe device but it failed. The rxe device was destroyed as a side effect of failing to open it.
Bob
Quoted 222 lines · Bob Pearson
Quoted 221 lines · Zhu Yanjun
Quoted 207 lines · Bob Pearson
Quoted 206 lines · Bob Pearson
Quoted 147 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0# ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-)Quoted 3 lines
create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]Quoted 7 lines
Quoted 5 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Bob
Forgot to mention. It also is definitely not good that a process in the default namespace can destroy a rxe device in the test namespace by trying to use it.
Thanks a lot.
I am not sure if it is correct or not to destroy a rxe device outside this this net namespace.
Because to irdma/mlx5 rdma devices, we can also destroy them with the command "modprobe -v irdma/mlx5..." outside of the net namespace.
Quoted 7 lines
Quoted 5 lines
I am not sure if this is correct or not.
Zhu Yanjun
Quoted 1 line
Bob
I didn' intentionally destroy lo2. I just tried to access the rxe device but it failed. The rxe device was destroyed as a side effect of failing to open it.
The GID of rxe can not be generated with lo. This is a problem. Now Chuck Lever <[email protected]> will fix it.
Not sure if the problem that you confronted is related with this. Please use physical NIC to make tests again.
Thanks a lot.
Zhu Yanjun
Quoted 2 lines
Bob
-----Original Message-----
From: Zhu Yanjun <[email protected]>
Sent: Friday, June 23, 2023 6:51 PM
To: Bob Pearson <[email protected]>; Zhu Yanjun <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6.4-rc1 v5 0/8] Fix the problem that rxe can not work in net namespace
Quoted 250 lines · Bob Pearson
Quoted 249 lines · Zhu Yanjun
Quoted 239 lines · Bob Pearson
Quoted 238 lines · Bob Pearson
Quoted 162 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference
count needed by udp tunnel, the sock reference count is decreased
by one. If equal, it indicates that this rdma link is the last
one. As such, the udp tunnel is shut down and the sock is closed.
The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes
dellink function pointer. And the 4th commit implements the dellink function in rxe.To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work
in the net namespace. So theinit_netis replaced by the
individual net namespace. This is what the 6th commit does.
Because rxe device is dependent on the net device and the sock
listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the
register_pernet_subsys/unregister_pernet_subsys
functions are added. When a new net namespace is created, the init
function will initialize the sk4 and sk6 socks. Then the 2 socks
will be released when the net namespace is destroyed. The
functions
rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in
the net namespace. The functions
rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0# ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, andV2->use"ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys
net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-)Quoted 4 lines
create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns
add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]My take, it sort of works. But there are some serious issues. You shouldn't be able to use the
rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)Quoted 3 lines
Quoted 1 line
Bob
Forgot to mention. It also is definitely not good that a process in
the default namespace can destroy a rxe device in the test namespace by trying to use it.Thanks a lot.
I am not sure if it is correct or not to destroy a rxe device outside this this net namespace.
Because to irdma/mlx5 rdma devices, we can also destroy them with the command "modprobe -v irdma/mlx5..." outside of the net namespace.
Quoted 7 lines
Quoted 5 lines
I am not sure if this is correct or not.
Zhu Yanjun
Quoted 1 line
Bob
I didn' intentionally destroy lo2. I just tried to access the rxe device but it failed. The rxe device was destroyed as a side effect of failing to open it.
The GID of rxe can not be generated with lo. This is a problem. Now Chuck Lever <[email protected]> will fix it.
Not sure if the problem that you confronted is related with this. Please use physical NIC to make tests again.
Thanks a lot.
Zhu Yanjun
Quoted 2 lines
Bob
That was why I added the IPV6 address by hand. That created the gid table entry. This is also a problem for all ethernet devices for distros that mangle the MAC address when creating the IPV6 address as a security measure. These include Ubuntu which I use. So I have to always add an IPV6 address based on the MAC address for any ethernet device.
Bob
Quoted 2 lines
The GID of rxe can not be generated with lo. This is a problem.
I agree, and would like to see a fix. It's obviously going to be a very useful use case for CI environments for upper layer storage protocols such as NFS and SMB, for instance.
Quoted 1 line
Now Chuck Lever <[email protected]> will fix it.
My understanding is that, because RoCE allows more than one port per egress device, the mechanism for enabling rxe-on-lo is going to be different than it is for iWARP -- or it might not be possible at all. That's why my siw patches do not implement a fix for rxe.
Jason needs to outline a mechanism for it so we can see what needs to be done. At which point, any interested party should be able to fix it.
--
Chuck Lever
Quoted 6 lines · Chuck Lever III
Quoted 1 line
The GID of rxe can not be generated with lo. This is a problem.
I agree, and would like to see a fix. It's obviously going to be a very useful use case for CI environments for upper layer storage protocols such as NFS and SMB, for instance.
Quoted 8 lines
Quoted 1 line
Now Chuck Lever <[email protected]> will fix it.
My understanding is that, because RoCE allows more than one port per egress device, the mechanism for enabling rxe-on-lo is going to be different than it is for iWARP -- or it might not be possible at all. That's why my siw patches do not implement a fix for rxe.
Jason needs to outline a mechanism for it so we can see what needs to be done. At which point, any interested party should be able to fix it.
Look forward to the fix.
Zhu Yanjun
Quoted 6 lines
--
Chuck Lever
Quoted 271 lines · Robert B
-----Original Message-----
From: Zhu Yanjun <[email protected]>
Sent: Friday, June 23, 2023 6:51 PM
To: Bob Pearson <[email protected]>; Zhu Yanjun <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6.4-rc1 v5 0/8] Fix the problem that rxe can not work in net namespaceQuoted 250 lines · Bob Pearson
Quoted 249 lines · Zhu Yanjun
Quoted 239 lines · Bob Pearson
Quoted 238 lines · Bob Pearson
Quoted 162 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference
count needed by udp tunnel, the sock reference count is decreased
by one. If equal, it indicates that this rdma link is the last
one. As such, the udp tunnel is shut down and the sock is closed.
The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes
dellink function pointer. And the 4th commit implements the dellink function in rxe.To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work
in the net namespace. So theinit_netis replaced by the
individual net namespace. This is what the 6th commit does.
Because rxe device is dependent on the net device and the sock
listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the
register_pernet_subsys/unregister_pernet_subsys
functions are added. When a new net namespace is created, the init
function will initialize the sk4 and sk6 socks. Then the 2 socks
will be released when the net namespace is destroyed. The
functions
rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in
the net namespace. The functions
rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0# ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process UNCONN 0 0 0.0.0.0:4791 0.0.0.0:* UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1# ip netns exec net0 ss -lu State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, andV2->use"ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys
net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-)Quoted 4 lines
create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns
add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]My take, it sort of works. But there are some serious issues. You shouldn't be able to use the
rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)Quoted 3 lines
Quoted 1 line
Bob
Forgot to mention. It also is definitely not good that a process in
the default namespace can destroy a rxe device in the test namespace by trying to use it.Thanks a lot.
I am not sure if it is correct or not to destroy a rxe device outside this this net namespace.
Because to irdma/mlx5 rdma devices, we can also destroy them with the command "modprobe -v irdma/mlx5..." outside of the net namespace.
Quoted 7 lines
Quoted 5 lines
I am not sure if this is correct or not.
Zhu Yanjun
Quoted 1 line
Bob
I didn' intentionally destroy lo2. I just tried to access the rxe device but it failed. The rxe device was destroyed as a side effect of failing to open it.
The GID of rxe can not be generated with lo. This is a problem. Now Chuck Lever <[email protected]> will fix it.
Not sure if the problem that you confronted is related with this. Please use physical NIC to make tests again.
Thanks a lot.
Quoted 7 lines
Zhu Yanjun
Quoted 1 line
Bob
That was why I added the IPV6 address by hand. That created the gid table entry. This is also a problem for all ethernet devices for distros that mangle the MAC address when creating the IPV6 address as a security measure. These include Ubuntu which I use. So I have to always add an IPV6 address based on the MAC address for any ethernet device.
Chuck Lever <[email protected]> will fix this problem. Before the fix for this problem is merged, it is not good to make tests with rxe-on-lo.
It is difficult for us to tell the failure from lo or net name space.
So please use physical NIC instead of lo now.
Zhu Yanjun
Quoted 2 lines
Bob
Quoted 206 lines · Bob Pearson
Quoted 147 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0 # ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-)Quoted 3 lines
create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]
Quoted 3 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Thanks, Bob. I will delve into your tests and reply you tomorrow.
Zhu Yanjun
Quoted 2 lines
Bob
Quoted 206 lines · Bob Pearson
Quoted 147 lines · Zhu Yanjun
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0 # ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespacedrivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-)Quoted 3 lines
create mode 100644
drivers/infiniband/sw/rxe/rxe_ns.ccreate mode 100644drivers/infiniband/sw/rxe/rxe_ns.hipnetns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]
Quoted 3 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Thanks a lot for your testing. Bob.
There are 2 modes in rdma net namespace. One is shared mode, the other is exclusive mode.
Share mode is the defaut mode. So what you have found is normal.
The followings are the explanations of both shared and exclusive modes.
rdma system set netns shared|exclusive, specifies the RDMA subsystem mode. Either exclusive or shared. When user wants
to assign dedicated RDMA device to a particular network namespace, exclusive mode should be set before creating any network namespace. If there are active network namespaces and if one or more RDMA devices exist, changing mode from shared to exclusive returns error code EBUSY.
When RDMA subsystem is in shared mode, RDMA device is accessible in all network namespace. When RDMA device isolation among multiple network namespaces is not needed, shared mode can be used.
It is preferred to not change the subsystem mode when there is active RDMA traffic
running, even though it is supported.
Zhu Yanjun
Quoted 2 lines
Bob
Quoted 206 lines
Quoted 138 lines
From: Zhu Yanjun <[email protected]>
When run "ip link add" command to add a rxe rdma link in a net namespace, normally this rxe rdma link can not work in a net name space.
The root cause is that a sock listening on udp port 4791 is created in
init_netwhen therdma_rxemodule is loaded into kernel. That is, the sock listening on udp port 4791 is created ininit_net. Other net namespace is difficult to use this sock.The following commits will solve this problem.
In the first commit, move the creating sock listening on udp port 4791 from
module_initfunction to rdma link creating functions. That is, after the modulerdma_rxeis loaded, the sock will not be created. When run "rdma link add ..." command, the sock will be created. So when creating a rdma link in the net namespace, the sock will be created in this net namespace.In the second commit, the functions
udp4_lib_lookupandudp6_lib_lookupwill check the sock exists in the net namespace or not. If yes, rdma link will increase the reference count of this sock, then continue other jobs instead of creating a new sock to listen on udp port 4791. Since the network notifier is global, when the modulerdma_rxeis loaded, this notifier will be registered.After the rdma link is created, the command "rdma link del" is to delete rdma link at the same time the sock is checked. If the reference count of this sock is greater than the sock reference count needed by udp tunnel, the sock reference count is decreased by one. If equal, it indicates that this rdma link is the last one. As such, the udp tunnel is shut down and the sock is closed. The above work should be implemented in linkdel function. But currently no dellink function in rxe. So the 3rd commit addes dellink function pointer. And the 4th commit implements the dellink function in rxe.
To now, it is not necessary to keep a global variable to store the sock listening udp port 4791. This global variable can be replaced by the functions
udp4_lib_lookupandudp6_lib_lookuptotally. Because the functionudp6_lib_lookupis in the fast path, a member variablel_sk6is added to store the sock. Ifl_sk6is NULL,udp6_lib_lookupis called to lookup the sock, then the sock is stored inl_sk6, in the future,it can be used directly.All the above work has been done in
init_net. And it can also work in the net namespace. So theinit_netis replaced by the individual net namespace. This is what the 6th commit does. Because rxe device is dependent on the net device and the sock listening on udp port 4791, every rxe device is in exclusive mode in the individual net namespace. Other rdma netns operations will be considerred in the future.In the 7th commit, the register_pernet_subsys/unregister_pernet_subsys functions are added. When a new net namespace is created, the init function will initialize the sk4 and sk6 socks. Then the 2 socks will be released when the net namespace is destroyed. The functions rxe_ns_pernet_sk4/rxe_ns_pernet_set_sk4 will get and set sk4 in the net namespace. The functions rxe_ns_pernet_sk6/rxe_ns_pernet_set_sk6 will handle sk6. Then sk4 and sk6 are used in the previous commits.
As the sk4 and sk6 in pernet namespace can be accessed, it is not necessary to add a new
l_sk6. As such, in the 8th commit, thel_sk6is replaced with the sk6 in pernet namespace.Test steps:
1) Suppose that 2 NICs are in 2 different net namespaces.# ip netns exec net0 ip link 3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP link/ether 00:1e:67:a0:22:3f brd ff:ff:ff:ff:ff:ff altname enp5s0# ip netns exec net1 ip link 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel link/ether f8:e4:3b:3b:e4:10 brd ff:ff:ff:ff:ff:ff2) Add rdma link in the different net namespace
net0:
# ip netns exec net0 rdma link add rxe0 type rxe netdev eno2net1:
# ip netns exec net1 rdma link add rxe1 type rxe netdev eno33) Run rping test.
net0 # ip netns exec net0 rping -s -a 192.168.2.1 -C 1& [1] 1737 # ip netns exec net1 rping -c -a 192.168.2.1 -d -v -C 1 verbose count 1 ... ping data: rdma-ping-0: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr ...4) Remove the rdma links from the net namespaces.
net0:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net0 rdma link del rxe0
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Processnet1:
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:4791 0.0.0.0:*
UNCONN 0 0 [::]:4791 [::]:*# ip netns exec net1 rdma link del rxe1
# ip netns exec net0 ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
V4->V5: Rebase the commits to V6.4-rc1
V3->V4: Rebase the commits to rdma-next;
V2->V3: 1) Add "rdma link del" example in the cover letter, and use "ss -lu" to
verify rdma link is removed.
2) Add register_pernet_subsys/unregister_pernet_subsys net namespace
3) Replacel_sk6with sk6 ofpernet_name_space
V1->V2: Add the explicit initialization of sk6.Zhu Yanjun (8):
RDMA/rxe: Creating listening sock in newlink function RDMA/rxe: Support more rdma links ininit_netRDMA/nldev: Add dellink function pointer
RDMA/rxe: Implement dellink in rxe
RDMA/rxe: Replace global variable with sock lookup functions RDMA/rxe: add the support of net namespace RDMA/rxe: Add the support of net namespace notifier RDMA/rxe: Replacel_sk6with sk6 in net namespaceQuoted 12 lines
drivers/infiniband/core/nldev.c | 6 ++ drivers/infiniband/sw/rxe/Makefile | 3 +- drivers/infiniband/sw/rxe/rxe.c | 35 +++++++- drivers/infiniband/sw/rxe/rxe_net.c | 113 +++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_net.h | 9 +- drivers/infiniband/sw/rxe/rxe_ns.c | 134 ++++++++++++++++++++++++++++ip netns add test drivers/infiniband/sw/rxe/rxe_ns.h | 17 ++++ include/rdma/rdma_netlink.h | 2 + 8 files changed, 279 insertions(+), 40 deletions(-) create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.c create mode 100644 drivers/infiniband/sw/rxe/rxe_ns.hip netns add testZhu,
I did some simple experiments on netns functionality.
With your patch set applied and rxe0 created on enp6s0 and rxe1 created on lo in the default namespace
# sudo ip netns add test # ip netns test # sudo ip netns exec test ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip link set dev lo up # sudo ip netns exec test ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # sudo ip netns exec test ip addr add dev lo fe80::0200:00ff:fe00:0000/64 [rxe doesn't work unless this IPV6 address is set] # sudo ip netns exec test ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 fe80::200:ff:fe00:0/64 scope link valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever # sudo ip netns exec test ls /sys/class/infiniband rxe0 rxe1 [These show up even though the ndevs do *not* belong to the test namespace! Probably OK.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [The new rxe device shows up in the default namespace. At least we're consistent.] # ib_send_bw -d rxe0 ... 192.168.0.27 [Works. Didn't break the existing rxe devices. Expected] # ib_send_bw -d rxe1 ... 127.0.0.1 [Works. Expected] # ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Not work. Expected.] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 IB device rxe2 not found Unable to find the Infiniband/RoCE device [Also not work. Turns out rxe2 device is gone after failure. Not expected.] # sudo ip netns exec test rdma link add rxe2 type rxe netdev lo # ls /sys/class/infiniband rxe0 rxe1 rxe2 [Good. It's back] # sudo ip netns exec test ib_send_bw -d rxe2 ... 127.0.0.1 [Works in test namespace! Expected.] # sudo ip netns exec test ib_send_bw -d rxe1 ... 127.0.0.1 [Also works. Definitely not expected.]
Quoted 3 lines
My take, it sort of works. But there are some serious issues. You shouldn't be able to use the rxe2 device in the default namespace. It would be nice if you couldn't see the rxe devices in each other's namespaces (Like ip link or ip addr hide other namespace's devices.)
Hi mates:
If rdma's system is shared, should every net namespace see all rdma devices?
Thanks for your work. I'm working on cloud native web related and I really need this patch :).
Nowadays AI + Cloud Native is becoming more and more popular and there are more and more AI clusters running on Kubernetes. Most AI clusters use RDMA technology to communicate across nodes between training tasks, which speeds up training and reduces network latency. However, RDMA hardware devices are very expensive and costly for those who want to experience or test the entire AI training process (involving scheduling, using RDMA networks, and using nccl-like communication libraries, etc.). So we plan to develop a Kubernetes CNI plugin that can run RDMA locally, which will mount the rdma device on the host inside the container so that the AI tasks can also use the RDMA network.
I understand that Soft Roce is able to virtualize rdma devices without RDMA hardware, and I have verified this locally, being able to test it with tools like ib_send_bw. However, I further moved the NIC on the host or the NIC on the host using macvlan technology to the network namespace inside the container, and then manually added the rdma device inside the container using the rdma link add command, and then finally found out that I couldn't see the virtualized rdma device inside the container by using the ibv_devices command, and I switched the system mode of the rdma respectively(shared or exclusive), and neither of them worked. I've also seen other developers report similar issues, refer [nccl-tests container can't use Soft-RoCE interfaces](https://github.com/NVIDIA/deepops/issues/772).
I guess the Linux kernel upstream doesn't support soft roce containerization yet. I read the linux kernel upstream code and related patches carefully and confirmed my guess. So I contacted Yanjun, I really hope this patch can be merged into upstream, thanks again for your work, looking forward to working further.
Best Regards
Cyclinder
Quoted 1 line
Bob