RDMA/core: Make sure the netdev is not already associated
Make sure that the requested net_device is not already associated with an ib_device before trying to create a new ib_device that will be associated with the same net_device, this is needed to avoid creating siw and rxe devices that will be associated with the same net_device.
--- drivers/infiniband/core/nldev.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/core/nldev.c +7 -0
@@ -1696,6 +1696,7 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,const struct rdma_link_ops *ops;char ndev_name[IFNAMSIZ ];struct net_device *ndev; +struct ib_device *ibdev;char type[IFNAMSIZ ];int err;
@@ -1718,6 +1719,12 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,if (!ndev)return -ENODEV ; + ibdev =ib_device_get_by_netdev (ndev,RDMA_DRIVER_UNKNOWN ); +if (ibdev) { +ib_device_put (ibdev); +return -EINVAL ; + } +down_read (&link_ops_rwsem); ops =link_ops_get (type);#ifdef CONFIG_MODULES
Signature · 1 line
2.38.1
Leon Romanovsky
Reviewed-byQuoted 11 lines · Kamal Heib
Make sure that the requested
net_deviceis not already associated with anib_devicebefore trying to create a newib_devicethat will be associated with the samenet_device, this is needed to avoid creating siw and rxe devices that will be associated with the samenet_device.Fixes 3856ec4b93c9 ("RDMA/core: Add RDMA_NLDEV_CMD_NEWLINK/DELLINK support")Signed-off-by Kamal Heib <[email protected]>--- drivers/infiniband/core/nldev.c | 7 +++++++ 1 file changed, 7 insertions(+)
Thanks,
Quoted 24 lines · Kamal Heib
Make sure that the requested
net_deviceis not already associated with anib_devicebefore trying to create a newib_devicethat will be associated with the samenet_device, this is needed to avoid creating siw and rxe devices that will be associated with the samenet_device.Fixes 3856ec4b93c9 ("RDMA/core: Add RDMA_NLDEV_CMD_NEWLINK/DELLINK support")Signed-off-by Kamal Heib <[email protected]>--- drivers/infiniband/core/nldev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/infiniband/core/nldev.c +1
-0@@ -1696,6 +1696,7 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,const struct rdma_link_ops *ops;char ndev_name[IFNAMSIZ ];struct net_device *ndev; +struct ib_device *ibdev;char type[IFNAMSIZ ];int err;
drivers/infiniband/core/nldev.c static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, · line 1726
Quoted 8 lines
drivers/infiniband/core/nldev.c +5
-0@@ -1718,6 +1719,12 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,if (!ndev)return -ENODEV ; + ibdev =ib_device_get_by_netdev (ndev,RDMA_DRIVER_UNKNOWN ); +if (ibdev) { +ib_device_put (ibdev); +return -EINVAL ; + }
This is racy
What is wrong with creating two IB devices on top of the same net device?
Jason
Quoted 28 lines · Jason Gunthorpe
Quoted 27 lines · Kamal Heib
Make sure that the requested
net_deviceis not already associated with anib_devicebefore trying to create a newib_devicethat will be associated with the samenet_device, this is needed to avoid creating siw and rxe devices that will be associated with the samenet_device.Fixes 3856ec4b93c9 ("RDMA/core: Add RDMA_NLDEV_CMD_NEWLINK/DELLINK support")Signed-off-by Kamal Heib <[email protected]>--- drivers/infiniband/core/nldev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/infiniband/core/nldev.c +1
-0@@ -1696,6 +1696,7 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,const struct rdma_link_ops *ops;char ndev_name[IFNAMSIZ ];struct net_device *ndev; +struct ib_device *ibdev;char type[IFNAMSIZ ];int err;@@ -1718,6 +1719,12 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,if (!ndev)return -ENODEV ;
Quoted 7 lines
drivers/infiniband/core/nldev.c static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, · line 1726
Quoted 5 lines
drivers/infiniband/core/nldev.c +5
-0+ ibdev =ib_device_get_by_netdev (ndev,RDMA_DRIVER_UNKNOWN ); +if (ibdev) { +ib_device_put (ibdev); +return -EINVAL ; + }This is racy
It can be seen as best effort.
Quoted 2 lines
What is wrong with creating two IB devices on top of the same net device?
Any place where we need to convert from ndev to ib will return random answer.
Quoted 2 lines
Jason