Skip to content

Commit da5c850

Browse files
Steve Wisedledford
authored andcommitted
RDMA/nldev: add driver-specific resource tracking
Each driver can register a "fill entry" function with the restrack core. This function will be called when filling out a resource, allowing the driver to add driver-specific details. The details consist of a nltable of nested attributes, that are in the form of <key, [print-type], value> tuples. Both key and value attributes are mandatory. The key nlattr must be a string, and the value nlattr can be one of the driver attributes that are generic, but typed, allowing the attributes to be validated. Currently the driver nlattr types include string, s32, u32, s64, and u64. The print-type nlattr allows a driver to specify an alternative display format for user tools displaying the attribute. For example, a u32 attribute will default to "%u", but a print-type attribute can be included for it to be displayed in hex. This allows the user tool to print the number in the format desired by the driver driver. More attrs can be defined as they become needed by drivers. Signed-off-by: Steve Wise <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 25a0ad8 commit da5c850

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
9898
[RDMA_NLDEV_ATTR_NDEV_INDEX] = { .type = NLA_U32 },
9999
[RDMA_NLDEV_ATTR_NDEV_NAME] = { .type = NLA_NUL_STRING,
100100
.len = IFNAMSIZ },
101+
[RDMA_NLDEV_ATTR_DRIVER] = { .type = NLA_NESTED },
102+
[RDMA_NLDEV_ATTR_DRIVER_ENTRY] = { .type = NLA_NESTED },
103+
[RDMA_NLDEV_ATTR_DRIVER_STRING] = { .type = NLA_NUL_STRING,
104+
.len = RDMA_NLDEV_ATTR_ENTRY_STRLEN },
105+
[RDMA_NLDEV_ATTR_DRIVER_PRINT_TYPE] = { .type = NLA_U8 },
106+
[RDMA_NLDEV_ATTR_DRIVER_S32] = { .type = NLA_S32 },
107+
[RDMA_NLDEV_ATTR_DRIVER_U32] = { .type = NLA_U32 },
108+
[RDMA_NLDEV_ATTR_DRIVER_S64] = { .type = NLA_S64 },
109+
[RDMA_NLDEV_ATTR_DRIVER_U64] = { .type = NLA_U64 },
101110
};
102111

103112
static int fill_nldev_handle(struct sk_buff *msg, struct ib_device *device)
@@ -285,6 +294,7 @@ static int fill_res_qp_entry(struct sk_buff *msg, struct netlink_callback *cb,
285294
struct rdma_restrack_entry *res, uint32_t port)
286295
{
287296
struct ib_qp *qp = container_of(res, struct ib_qp, res);
297+
struct rdma_restrack_root *resroot = &qp->device->res;
288298
struct ib_qp_init_attr qp_init_attr;
289299
struct nlattr *entry_attr;
290300
struct ib_qp_attr qp_attr;
@@ -334,6 +344,9 @@ static int fill_res_qp_entry(struct sk_buff *msg, struct netlink_callback *cb,
334344
if (fill_res_name_pid(msg, res))
335345
goto err;
336346

347+
if (resroot->fill_res_entry(msg, res))
348+
goto err;
349+
337350
nla_nest_end(msg, entry_attr);
338351
return 0;
339352

@@ -349,6 +362,7 @@ static int fill_res_cm_id_entry(struct sk_buff *msg,
349362
{
350363
struct rdma_id_private *id_priv =
351364
container_of(res, struct rdma_id_private, res);
365+
struct rdma_restrack_root *resroot = &id_priv->id.device->res;
352366
struct rdma_cm_id *cm_id = &id_priv->id;
353367
struct nlattr *entry_attr;
354368

@@ -390,6 +404,9 @@ static int fill_res_cm_id_entry(struct sk_buff *msg,
390404
if (fill_res_name_pid(msg, res))
391405
goto err;
392406

407+
if (resroot->fill_res_entry(msg, res))
408+
goto err;
409+
393410
nla_nest_end(msg, entry_attr);
394411
return 0;
395412

@@ -403,6 +420,7 @@ static int fill_res_cq_entry(struct sk_buff *msg, struct netlink_callback *cb,
403420
struct rdma_restrack_entry *res, uint32_t port)
404421
{
405422
struct ib_cq *cq = container_of(res, struct ib_cq, res);
423+
struct rdma_restrack_root *resroot = &cq->device->res;
406424
struct nlattr *entry_attr;
407425

408426
entry_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_CQ_ENTRY);
@@ -423,6 +441,9 @@ static int fill_res_cq_entry(struct sk_buff *msg, struct netlink_callback *cb,
423441
if (fill_res_name_pid(msg, res))
424442
goto err;
425443

444+
if (resroot->fill_res_entry(msg, res))
445+
goto err;
446+
426447
nla_nest_end(msg, entry_attr);
427448
return 0;
428449

@@ -436,6 +457,7 @@ static int fill_res_mr_entry(struct sk_buff *msg, struct netlink_callback *cb,
436457
struct rdma_restrack_entry *res, uint32_t port)
437458
{
438459
struct ib_mr *mr = container_of(res, struct ib_mr, res);
460+
struct rdma_restrack_root *resroot = &mr->pd->device->res;
439461
struct nlattr *entry_attr;
440462

441463
entry_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_MR_ENTRY);
@@ -459,6 +481,9 @@ static int fill_res_mr_entry(struct sk_buff *msg, struct netlink_callback *cb,
459481
if (fill_res_name_pid(msg, res))
460482
goto err;
461483

484+
if (resroot->fill_res_entry(msg, res))
485+
goto err;
486+
462487
nla_nest_end(msg, entry_attr);
463488
return 0;
464489

@@ -472,6 +497,7 @@ static int fill_res_pd_entry(struct sk_buff *msg, struct netlink_callback *cb,
472497
struct rdma_restrack_entry *res, uint32_t port)
473498
{
474499
struct ib_pd *pd = container_of(res, struct ib_pd, res);
500+
struct rdma_restrack_root *resroot = &pd->device->res;
475501
struct nlattr *entry_attr;
476502

477503
entry_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_PD_ENTRY);
@@ -498,6 +524,9 @@ static int fill_res_pd_entry(struct sk_buff *msg, struct netlink_callback *cb,
498524
if (fill_res_name_pid(msg, res))
499525
goto err;
500526

527+
if (resroot->fill_res_entry(msg, res))
528+
goto err;
529+
501530
nla_nest_end(msg, entry_attr);
502531
return 0;
503532

drivers/infiniband/core/restrack.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212

1313
#include "cma_priv.h"
1414

15+
static int fill_res_noop(struct sk_buff *msg,
16+
struct rdma_restrack_entry *entry)
17+
{
18+
return 0;
19+
}
20+
1521
void rdma_restrack_init(struct rdma_restrack_root *res)
1622
{
1723
init_rwsem(&res->rwsem);
24+
res->fill_res_entry = fill_res_noop;
1825
}
1926

2027
static const char *type2str(enum rdma_restrack_type type)

include/rdma/restrack.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ enum rdma_restrack_type {
4444
};
4545

4646
#define RDMA_RESTRACK_HASH_BITS 8
47+
struct rdma_restrack_entry;
48+
4749
/**
4850
* struct rdma_restrack_root - main resource tracking management
4951
* entity, per-device
@@ -57,6 +59,13 @@ struct rdma_restrack_root {
5759
* @hash: global database for all resources per-device
5860
*/
5961
DECLARE_HASHTABLE(hash, RDMA_RESTRACK_HASH_BITS);
62+
/**
63+
* @fill_res_entry: driver-specific fill function
64+
*
65+
* Allows rdma drivers to add their own restrack attributes.
66+
*/
67+
int (*fill_res_entry)(struct sk_buff *msg,
68+
struct rdma_restrack_entry *entry);
6069
};
6170

6271
/**

include/uapi/rdma/rdma_netlink.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ enum rdma_nldev_command {
249249
RDMA_NLDEV_NUM_OPS
250250
};
251251

252+
enum {
253+
RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16,
254+
};
255+
256+
enum rdma_nldev_print_type {
257+
RDMA_NLDEV_PRINT_TYPE_UNSPEC,
258+
RDMA_NLDEV_PRINT_TYPE_HEX,
259+
};
260+
252261
enum rdma_nldev_attr {
253262
/* don't change the order or add anything between, this is ABI! */
254263
RDMA_NLDEV_ATTR_UNSPEC,
@@ -390,6 +399,20 @@ enum rdma_nldev_attr {
390399
RDMA_NLDEV_ATTR_RES_PD_ENTRY, /* nested table */
391400
RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY, /* u32 */
392401
RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY, /* u32 */
402+
/*
403+
* driver-specific attributes.
404+
*/
405+
RDMA_NLDEV_ATTR_DRIVER, /* nested table */
406+
RDMA_NLDEV_ATTR_DRIVER_ENTRY, /* nested table */
407+
RDMA_NLDEV_ATTR_DRIVER_STRING, /* string */
408+
/*
409+
* u8 values from enum rdma_nldev_print_type
410+
*/
411+
RDMA_NLDEV_ATTR_DRIVER_PRINT_TYPE, /* u8 */
412+
RDMA_NLDEV_ATTR_DRIVER_S32, /* s32 */
413+
RDMA_NLDEV_ATTR_DRIVER_U32, /* u32 */
414+
RDMA_NLDEV_ATTR_DRIVER_S64, /* s64 */
415+
RDMA_NLDEV_ATTR_DRIVER_U64, /* u64 */
393416

394417
/*
395418
* Provides logical name and index of netdevice which is

0 commit comments

Comments
 (0)