OSDN Git Service

RDMA/rxe: Add ib_device_get_by_name() and use it in rxe
authorJason Gunthorpe <jgg@mellanox.com>
Wed, 13 Feb 2019 04:12:55 +0000 (21:12 -0700)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 20 Feb 2019 03:52:18 +0000 (20:52 -0700)
rxe has an open coded version of this that is not as safe as the core
version. This lets us eliminate the internal device list entirely from
rxe.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/device.c
drivers/infiniband/sw/rxe/rxe.c
drivers/infiniband/sw/rxe/rxe.h
drivers/infiniband/sw/rxe/rxe_net.c
drivers/infiniband/sw/rxe/rxe_sysfs.c
drivers/infiniband/sw/rxe/rxe_verbs.h

index e470fa6..2a7d547 100644 (file)
@@ -240,6 +240,34 @@ static struct ib_device *__ib_device_get_by_name(const char *name)
        return NULL;
 }
 
+/**
+ * ib_device_get_by_name - Find an IB device by name
+ * @name: The name to look for
+ * @driver_id: The driver ID that must match (RDMA_DRIVER_UNKNOWN matches all)
+ *
+ * Find and hold an ib_device by its name. The caller must call
+ * ib_device_put() on the returned pointer.
+ */
+struct ib_device *ib_device_get_by_name(const char *name,
+                                       enum rdma_driver_id driver_id)
+{
+       struct ib_device *device;
+
+       down_read(&devices_rwsem);
+       device = __ib_device_get_by_name(name);
+       if (device && driver_id != RDMA_DRIVER_UNKNOWN &&
+           device->driver_id != driver_id)
+               device = NULL;
+
+       if (device) {
+               if (!ib_device_try_get(device))
+                       device = NULL;
+       }
+       up_read(&devices_rwsem);
+       return device;
+}
+EXPORT_SYMBOL(ib_device_get_by_name);
+
 int ib_device_rename(struct ib_device *ibdev, const char *name)
 {
        int ret;
index cd93c54..08a45ce 100644 (file)
@@ -69,8 +69,6 @@ void rxe_dealloc(struct ib_device *ib_dev)
 
        if (rxe->tfm)
                crypto_free_shash(rxe->tfm);
-
-       list_del(&rxe->list);
 }
 
 /* initialize rxe device parameters */
@@ -275,7 +273,6 @@ static int rxe_init(struct rxe_dev *rxe)
        spin_lock_init(&rxe->mmap_offset_lock);
        spin_lock_init(&rxe->pending_lock);
        INIT_LIST_HEAD(&rxe->pending_mmaps);
-       INIT_LIST_HEAD(&rxe->list);
 
        mutex_init(&rxe->usdev_lock);
 
index ce4bf05..63b3b89 100644 (file)
@@ -99,8 +99,6 @@ int rxe_add(struct rxe_dev *rxe, unsigned int mtu);
 
 void rxe_rcv(struct sk_buff *skb);
 
-struct rxe_dev *get_rxe_by_name(const char *name);
-
 /* The caller must do a matching ib_device_put(&dev->ib_dev) */
 static inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev)
 {
index d56a967..d6dfbcf 100644 (file)
 #include "rxe_net.h"
 #include "rxe_loc.h"
 
-static LIST_HEAD(rxe_dev_list);
-static DEFINE_SPINLOCK(dev_list_lock); /* spinlock for device list */
-
-struct rxe_dev *get_rxe_by_name(const char *name)
-{
-       struct rxe_dev *rxe;
-       struct rxe_dev *found = NULL;
-
-       spin_lock_bh(&dev_list_lock);
-       list_for_each_entry(rxe, &rxe_dev_list, list) {
-               if (!strcmp(name, dev_name(&rxe->ib_dev.dev))) {
-                       found = rxe;
-                       break;
-               }
-       }
-       spin_unlock_bh(&dev_list_lock);
-       return found;
-}
-
 static struct rxe_recv_sockets recv_sockets;
 
 struct device *rxe_dma_device(struct rxe_dev *rxe)
@@ -553,9 +534,6 @@ struct rxe_dev *rxe_net_add(struct net_device *ndev)
                return NULL;
        }
 
-       spin_lock_bh(&dev_list_lock);
-       list_add_tail(&rxe->list, &rxe_dev_list);
-       spin_unlock_bh(&dev_list_lock);
        return rxe;
 }
 
index c863063..d51b55b 100644 (file)
@@ -101,7 +101,7 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
 {
        int len;
        char intf[32];
-       struct rxe_dev *rxe;
+       struct ib_device *ib_dev;
 
        len = sanitize_arg(val, intf, sizeof(intf));
        if (!len) {
@@ -115,14 +115,13 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
                return 0;
        }
 
-       rxe = get_rxe_by_name(intf);
-
-       if (!rxe) {
+       ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE);
+       if (!ib_dev) {
                pr_err("not configured on %s\n", intf);
                return -EINVAL;
        }
 
-       ib_unregister_device(&rxe->ib_dev);
+       ib_unregister_device_and_put(ib_dev);
 
        return 0;
 }
index ad5574d..a228225 100644 (file)
@@ -411,7 +411,6 @@ struct rxe_dev {
        atomic64_t              stats_counters[RXE_NUM_OF_COUNTERS];
 
        struct rxe_port         port;
-       struct list_head        list;
        struct crypto_shash     *tfm;
 };