RDMA/counter: Add PID category support in auto mode
authorMark Zhang <markz@mellanox.com>
Thu, 2 Jul 2020 08:29:31 +0000 (11:29 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 10 Jul 2020 19:50:53 +0000 (16:50 -0300)
With the "PID" category QPs have same PID will be bound to same counter;
If this category is not set then QPs have different PIDs will be bound
to same counter.

This is implemented for 2 reasons:
1. The counter is a limited resource, while there may be dozens of
   applications, each of which creates several types of QPs, which means
   it may doesn't have enough counter.
2. The system administrator needs all QPs created by all applications
   with same type bound to one counter.

The counter name and PID is only make sense when "PID" category are
configured.

This category can also be used in combine with others, e.g. QP type.

Link: https://lore.kernel.org/r/20200702082933.424537-2-leon@kernel.org
Signed-off-by: Mark Zhang <markz@mellanox.com>
Reviewed-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/counters.c
drivers/infiniband/core/nldev.c
include/uapi/rdma/rdma_netlink.h

index 2257d7f7810fd99396257039e897c5ddc3b59d31..40204c6caa5baecf50e74de84ed6c05259a492af 100644 (file)
@@ -8,7 +8,7 @@
 #include "core_priv.h"
 #include "restrack.h"
 
-#define ALL_AUTO_MODE_MASKS (RDMA_COUNTER_MASK_QP_TYPE)
+#define ALL_AUTO_MODE_MASKS (RDMA_COUNTER_MASK_QP_TYPE | RDMA_COUNTER_MASK_PID)
 
 static int __counter_set_mode(struct rdma_counter_mode *curr,
                              enum rdma_nl_counter_mode new_mode,
@@ -149,23 +149,13 @@ static bool auto_mode_match(struct ib_qp *qp, struct rdma_counter *counter,
        struct auto_mode_param *param = &counter->mode.param;
        bool match = true;
 
-       /*
-        * Ensure that counter belongs to the right PID.  This operation can
-        * race with user space which kills the process and leaves QP and
-        * counters orphans.
-        *
-        * It is not a big deal because exitted task will leave both QP and
-        * counter in the same bucket of zombie process. Just ensure that
-        * process is still alive before procedding.
-        *
-        */
-       if (task_pid_nr(counter->res.task) != task_pid_nr(qp->res.task) ||
-           !task_pid_nr(qp->res.task))
-               return false;
-
        if (auto_mask & RDMA_COUNTER_MASK_QP_TYPE)
                match &= (param->qp_type == qp->qp_type);
 
+       if (auto_mask & RDMA_COUNTER_MASK_PID)
+               match &= (task_pid_nr(counter->res.task) ==
+                         task_pid_nr(qp->res.task));
+
        return match;
 }
 
index 1051b5622b625f210558954514956787cd07e924..76af7ea2875d01ab137417b51d4a33d1edb7c09a 100644 (file)
@@ -711,11 +711,16 @@ static int fill_stat_counter_mode(struct sk_buff *msg,
        if (nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_MODE, m->mode))
                return -EMSGSIZE;
 
-       if (m->mode == RDMA_COUNTER_MODE_AUTO)
+       if (m->mode == RDMA_COUNTER_MODE_AUTO) {
                if ((m->mask & RDMA_COUNTER_MASK_QP_TYPE) &&
                    nla_put_u8(msg, RDMA_NLDEV_ATTR_RES_TYPE, m->param.qp_type))
                        return -EMSGSIZE;
 
+               if ((m->mask & RDMA_COUNTER_MASK_PID) &&
+                   fill_res_name_pid(msg, &counter->res))
+                       return -EMSGSIZE;
+       }
+
        return 0;
 }
 
@@ -855,7 +860,6 @@ static int fill_res_counter_entry(struct sk_buff *msg, bool has_cap_net_admin,
 
        if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, counter->port) ||
            nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_COUNTER_ID, counter->id) ||
-           fill_res_name_pid(msg, &counter->res) ||
            fill_stat_counter_mode(msg, counter) ||
            fill_stat_counter_qps(msg, counter) ||
            fill_stat_counter_hwcounters(msg, counter))
index 3826143d420dd10b46092d0d8951c87a5a23a4d1..d2f5b839624320ffa1ce1cded227729cd4a57c49 100644 (file)
@@ -569,5 +569,6 @@ enum rdma_nl_counter_mode {
  */
 enum rdma_nl_counter_mask {
        RDMA_COUNTER_MASK_QP_TYPE = 1,
+       RDMA_COUNTER_MASK_PID = 1 << 1,
 };
 #endif /* _UAPI_RDMA_NETLINK_H */