IB/hfi1: Fix incorrect available receive user context count
authorMichael J. Ruhl <michael.j.ruhl@intel.com>
Mon, 2 Oct 2017 18:04:19 +0000 (11:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Nov 2017 08:40:55 +0000 (08:40 +0000)
commit d7d626179fb283aba73699071af0df6d00e32138 upstream.

The addition of the VNIC contexts to num_rcv_contexts changes the
meaning of the sysfs value nctxts from available user contexts, to
user contexts + reserved VNIC contexts.

User applications that use nctxts are now broken.

Update the calculation so that VNIC contexts are used only if there are
hardware contexts available, and do not silently affect nctxts.

Update code to use the calculated VNIC context number.

Update the sysfs value nctxts to be available user contexts only.

Fixes: 2280740f01ae ("IB/hfi1: Virtual Network Interface Controller (VNIC) HW support")
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Niranjana Vishwanathapura <Niranjana.Vishwanathapura@intel.com>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/hw/hfi1/chip.c
drivers/infiniband/hw/hfi1/hfi.h
drivers/infiniband/hw/hfi1/sysfs.c
drivers/infiniband/hw/hfi1/vnic_main.c

index 0be42787759fa78c73d0e0d9776209c2362a3ddc..312444386f54135b6da041a3812d49955ce6e51c 100644 (file)
@@ -13074,7 +13074,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
        first_sdma = last_general;
        last_sdma = first_sdma + dd->num_sdma;
        first_rx = last_sdma;
-       last_rx = first_rx + dd->n_krcv_queues + HFI1_NUM_VNIC_CTXT;
+       last_rx = first_rx + dd->n_krcv_queues + dd->num_vnic_contexts;
 
        /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
        dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
@@ -13294,8 +13294,9 @@ static int set_up_interrupts(struct hfi1_devdata *dd)
         *              slow source, SDMACleanupDone)
         *      N interrupts - one per used SDMA engine
         *      M interrupt - one per kernel receive context
+        *      V interrupt - one for each VNIC context
         */
-       total = 1 + dd->num_sdma + dd->n_krcv_queues + HFI1_NUM_VNIC_CTXT;
+       total = 1 + dd->num_sdma + dd->n_krcv_queues + dd->num_vnic_contexts;
 
        /* ask for MSI-X interrupts */
        request = request_msix(dd, total);
@@ -13356,10 +13357,12 @@ fail:
  *                             in array of contexts
  *     freectxts  - number of free user contexts
  *     num_send_contexts - number of PIO send contexts being used
+ *     num_vnic_contexts - number of contexts reserved for VNIC
  */
 static int set_up_context_variables(struct hfi1_devdata *dd)
 {
        unsigned long num_kernel_contexts;
+       u16 num_vnic_contexts = HFI1_NUM_VNIC_CTXT;
        int total_contexts;
        int ret;
        unsigned ngroups;
@@ -13393,6 +13396,14 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
                           num_kernel_contexts);
                num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
        }
+
+       /* Accommodate VNIC contexts if possible */
+       if ((num_kernel_contexts + num_vnic_contexts) > dd->chip_rcv_contexts) {
+               dd_dev_err(dd, "No receive contexts available for VNIC\n");
+               num_vnic_contexts = 0;
+       }
+       total_contexts = num_kernel_contexts + num_vnic_contexts;
+
        /*
         * User contexts:
         *      - default to 1 user context per real (non-HT) CPU core if
@@ -13402,19 +13413,16 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
                num_user_contexts =
                        cpumask_weight(&node_affinity.real_cpu_mask);
 
-       total_contexts = num_kernel_contexts + num_user_contexts;
-
        /*
         * Adjust the counts given a global max.
         */
-       if (total_contexts > dd->chip_rcv_contexts) {
+       if (total_contexts + num_user_contexts > dd->chip_rcv_contexts) {
                dd_dev_err(dd,
                           "Reducing # user receive contexts to: %d, from %d\n",
-                          (int)(dd->chip_rcv_contexts - num_kernel_contexts),
+                          (int)(dd->chip_rcv_contexts - total_contexts),
                           (int)num_user_contexts);
-               num_user_contexts = dd->chip_rcv_contexts - num_kernel_contexts;
                /* recalculate */
-               total_contexts = num_kernel_contexts + num_user_contexts;
+               num_user_contexts = dd->chip_rcv_contexts - total_contexts;
        }
 
        /* each user context requires an entry in the RMT */
@@ -13427,25 +13435,24 @@ static int set_up_context_variables(struct hfi1_devdata *dd)
                           user_rmt_reduced);
                /* recalculate */
                num_user_contexts = user_rmt_reduced;
-               total_contexts = num_kernel_contexts + num_user_contexts;
        }
 
-       /* Accommodate VNIC contexts */
-       if ((total_contexts + HFI1_NUM_VNIC_CTXT) <= dd->chip_rcv_contexts)
-               total_contexts += HFI1_NUM_VNIC_CTXT;
+       total_contexts += num_user_contexts;
 
        /* the first N are kernel contexts, the rest are user/vnic contexts */
        dd->num_rcv_contexts = total_contexts;
        dd->n_krcv_queues = num_kernel_contexts;
        dd->first_dyn_alloc_ctxt = num_kernel_contexts;
+       dd->num_vnic_contexts = num_vnic_contexts;
        dd->num_user_contexts = num_user_contexts;
        dd->freectxts = num_user_contexts;
        dd_dev_info(dd,
-                   "rcv contexts: chip %d, used %d (kernel %d, user %d)\n",
+                   "rcv contexts: chip %d, used %d (kernel %d, vnic %u, user %u)\n",
                    (int)dd->chip_rcv_contexts,
                    (int)dd->num_rcv_contexts,
                    (int)dd->n_krcv_queues,
-                   (int)dd->num_rcv_contexts - dd->n_krcv_queues);
+                   dd->num_vnic_contexts,
+                   dd->num_user_contexts);
 
        /*
         * Receive array allocation:
index 3ac9c307a285f1f2ed6a2ab1b8fec680fcd412f0..6ff44dc606ebacf0924d455733a45074872fea81 100644 (file)
@@ -1047,6 +1047,8 @@ struct hfi1_devdata {
        u64 z_send_schedule;
 
        u64 __percpu *send_schedule;
+       /* number of reserved contexts for VNIC usage */
+       u16 num_vnic_contexts;
        /* number of receive contexts in use by the driver */
        u32 num_rcv_contexts;
        /* number of pio send contexts in use by the driver */
index 6d2702ef34ac4ce971dcc612df6a7b1b88303e64..25e867393463e5cc634d9a304e85dba8f5ddb89d 100644 (file)
@@ -543,7 +543,7 @@ static ssize_t show_nctxts(struct device *device,
         * give a more accurate picture of total contexts available.
         */
        return scnprintf(buf, PAGE_SIZE, "%u\n",
-                        min(dd->num_rcv_contexts - dd->first_dyn_alloc_ctxt,
+                        min(dd->num_user_contexts,
                             (u32)dd->sc_sizes[SC_USER].count));
 }
 
index f419cbb0592889de1386eb1de364f4436024b41d..1a17708be46a922d5505a1dd38c188d5189fb006 100644 (file)
@@ -840,6 +840,9 @@ struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
        struct rdma_netdev *rn;
        int i, size, rc;
 
+       if (!dd->num_vnic_contexts)
+               return ERR_PTR(-ENOMEM);
+
        if (!port_num || (port_num > dd->num_pports))
                return ERR_PTR(-EINVAL);
 
@@ -848,7 +851,7 @@ struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
 
        size = sizeof(struct opa_vnic_rdma_netdev) + sizeof(*vinfo);
        netdev = alloc_netdev_mqs(size, name, name_assign_type, setup,
-                                 dd->chip_sdma_engines, HFI1_NUM_VNIC_CTXT);
+                                 dd->chip_sdma_engines, dd->num_vnic_contexts);
        if (!netdev)
                return ERR_PTR(-ENOMEM);
 
@@ -856,7 +859,7 @@ struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
        vinfo = opa_vnic_dev_priv(netdev);
        vinfo->dd = dd;
        vinfo->num_tx_q = dd->chip_sdma_engines;
-       vinfo->num_rx_q = HFI1_NUM_VNIC_CTXT;
+       vinfo->num_rx_q = dd->num_vnic_contexts;
        vinfo->netdev = netdev;
        rn->free_rdma_netdev = hfi1_vnic_free_rn;
        rn->set_id = hfi1_vnic_set_vesw_id;