]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net/rds: Add mutex exclusion for vector_load
authorHåkon Bugge <Haakon.Bugge@oracle.com>
Fri, 7 Jul 2017 10:33:30 +0000 (12:33 +0200)
committerChuck Anderson <chuck.anderson@oracle.com>
Tue, 11 Jul 2017 07:00:36 +0000 (00:00 -0700)
Several TOS connections may invoke ibdev_get_unused_vector()
concurrently. Hence, mutual exclusion is required to protect
rds_ibdev->vector_load.

Changes from v1:
   - Reworded commit message and commentary based on Avinash's feedback
   - Added r-b from Wei Lin and Avinash

Orabug: 26406492

Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com>
Reviewed-by: Wei Lin Guay <wei.lin.guay@oracle.com>
Reviewed-by: Avinash Repaka <avinash.repaka@oracle.com>
net/rds/ib.c
net/rds/ib.h
net/rds/ib_cm.c

index 93425b800dfba6d468223cebf9d0817bb67b9a6b..35dac3bfee74bd8c07ae8eb2cdd5b59691e75d59 100644 (file)
@@ -2052,6 +2052,7 @@ void rds_ib_add_one(struct ib_device *device)
                printk(KERN_ERR "RDS/IB: failed to allocate vector memoru\n");
                goto put_dev;
        }
+       mutex_init(&rds_ibdev->vector_load_lock);
 
        rds_ibdev->mr = ib_get_dma_mr(rds_ibdev->pd, IB_ACCESS_LOCAL_WRITE);
        if (IS_ERR(rds_ibdev->mr)) {
index fd705edac6a7e1baa8274187d75a9d96c6333666..f595f358d8d77fcb83f6862817122719474148af 100644 (file)
@@ -431,6 +431,10 @@ struct rds_ib_device {
        struct rds_ib_port      *ports;
        struct ib_event_handler event_handler;
        int                     *vector_load;
+       /* Several TOS connections may invoke ibdev_get_unused_vector()
+        * concurrently, hence we need protection for vector_load
+        */
+       struct mutex            vector_load_lock;
 
        /* flag indicating ib_device is under freeing up or is freed up to make
         * the race between rds_ib_remove_one() and rds_release() safe.
index a217d978c894f5c1c9e938133c41437b464a991c..98c14c6e2aa836c41e2c42748281c9f5b8668335 100644 (file)
@@ -599,10 +599,14 @@ static void rds_ib_qp_event_handler(struct ib_event *event, void *data)
 
 static inline int ibdev_get_unused_vector(struct rds_ib_device *rds_ibdev)
 {
-       int min = rds_ibdev->vector_load[rds_ibdev->dev->num_comp_vectors - 1];
-       int index = rds_ibdev->dev->num_comp_vectors - 1;
+       int index;
+       int min;
        int i;
 
+       mutex_lock(&rds_ibdev->vector_load_lock);
+       min = rds_ibdev->vector_load[rds_ibdev->dev->num_comp_vectors - 1];
+       index = rds_ibdev->dev->num_comp_vectors - 1;
+
        for (i = rds_ibdev->dev->num_comp_vectors - 1; i >= 0; i--) {
                if (rds_ibdev->vector_load[i] < min) {
                        index = i;
@@ -611,12 +615,16 @@ static inline int ibdev_get_unused_vector(struct rds_ib_device *rds_ibdev)
        }
 
        rds_ibdev->vector_load[index]++;
+       mutex_unlock(&rds_ibdev->vector_load_lock);
+
        return index;
 }
 
 static inline void ibdev_put_vector(struct rds_ib_device *rds_ibdev, int index)
 {
+       mutex_lock(&rds_ibdev->vector_load_lock);
        rds_ibdev->vector_load[index]--;
+       mutex_unlock(&rds_ibdev->vector_load_lock);
 }
 
 /*