Skip to content

Commit b47ae6f

Browse files
Mark Zhangjgunthorpe
authored andcommitted
RDMA/nldev: Allow counter auto mode configration through RDMA netlink
Provide an option to enable/disable per-port counter auto mode through RDMA netlink. Limit it to users with ADMIN capability only. Signed-off-by: Mark Zhang <markz@mellanox.com> Reviewed-by: Majd Dibbiny <majd@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 45842fc commit b47ae6f

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎drivers/infiniband/core/nldev.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
126126
[RDMA_NLDEV_ATTR_RES_USECNT] = { .type = NLA_U64 },
127127
[RDMA_NLDEV_ATTR_SM_LID] = { .type = NLA_U32 },
128128
[RDMA_NLDEV_ATTR_SUBNET_PREFIX] = { .type = NLA_U64 },
129+
[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK] = { .type = NLA_U32 },
130+
[RDMA_NLDEV_ATTR_STAT_MODE] = { .type = NLA_U32 },
131+
[RDMA_NLDEV_ATTR_STAT_RES] = { .type = NLA_U32 },
129132
[RDMA_NLDEV_ATTR_SYS_IMAGE_GUID] = { .type = NLA_U64 },
130133
[RDMA_NLDEV_ATTR_UVERBS_DRIVER_ID] = { .type = NLA_U32 },
131134
[RDMA_NLDEV_NET_NS_FD] = { .type = NLA_U32 },
@@ -1482,6 +1485,78 @@ static int nldev_set_sys_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
14821485
return err;
14831486
}
14841487

1488+
static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1489+
struct netlink_ext_ack *extack)
1490+
{
1491+
struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
1492+
u32 index, port, mode, mask = 0;
1493+
struct ib_device *device;
1494+
struct sk_buff *msg;
1495+
int ret;
1496+
1497+
ret = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
1498+
nldev_policy, extack);
1499+
/* Currently only counter for QP is supported */
1500+
if (ret || !tb[RDMA_NLDEV_ATTR_STAT_RES] ||
1501+
!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
1502+
!tb[RDMA_NLDEV_ATTR_PORT_INDEX] || !tb[RDMA_NLDEV_ATTR_STAT_MODE])
1503+
return -EINVAL;
1504+
1505+
if (nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_RES]) != RDMA_NLDEV_ATTR_RES_QP)
1506+
return -EINVAL;
1507+
1508+
index = nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
1509+
device = ib_device_get_by_index(sock_net(skb->sk), index);
1510+
if (!device)
1511+
return -EINVAL;
1512+
1513+
port = nla_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
1514+
if (!rdma_is_port_valid(device, port)) {
1515+
ret = -EINVAL;
1516+
goto err;
1517+
}
1518+
1519+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1520+
if (!msg) {
1521+
ret = -ENOMEM;
1522+
goto err;
1523+
}
1524+
nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
1525+
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
1526+
RDMA_NLDEV_CMD_STAT_SET),
1527+
0, 0);
1528+
1529+
mode = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_MODE]);
1530+
if (mode != RDMA_COUNTER_MODE_AUTO) {
1531+
ret = -EMSGSIZE;
1532+
goto err_msg;
1533+
}
1534+
1535+
if (tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK])
1536+
mask = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK]);
1537+
1538+
ret = rdma_counter_set_auto_mode(device, port,
1539+
mask ? true : false, mask);
1540+
if (ret)
1541+
goto err_msg;
1542+
1543+
if (nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_MODE, mode) ||
1544+
nla_put_u32(msg, RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK, mask)) {
1545+
ret = -EMSGSIZE;
1546+
goto err_msg;
1547+
}
1548+
1549+
nlmsg_end(msg, nlh);
1550+
ib_device_put(device);
1551+
return rdma_nl_unicast(msg, NETLINK_CB(skb).portid);
1552+
1553+
err_msg:
1554+
nlmsg_free(msg);
1555+
err:
1556+
ib_device_put(device);
1557+
return ret;
1558+
}
1559+
14851560
static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
14861561
[RDMA_NLDEV_CMD_GET] = {
14871562
.doit = nldev_get_doit,
@@ -1535,6 +1610,9 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
15351610
},
15361611
[RDMA_NLDEV_CMD_SYS_SET] = {
15371612
.doit = nldev_set_sys_set_doit,
1613+
},
1614+
[RDMA_NLDEV_CMD_STAT_SET] = {
1615+
.doit = nldev_stat_set_doit,
15381616
.flags = RDMA_NL_ADMIN_PERM,
15391617
},
15401618
};

‎include/uapi/rdma/rdma_netlink.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ enum rdma_nldev_command {
281281

282282
RDMA_NLDEV_CMD_GET_CHARDEV,
283283

284+
RDMA_NLDEV_CMD_STAT_SET,
285+
284286
RDMA_NLDEV_NUM_OPS
285287
};
286288

@@ -488,6 +490,12 @@ enum rdma_nldev_attr {
488490
* File descriptor handle of the net namespace object
489491
*/
490492
RDMA_NLDEV_NET_NS_FD, /* u32 */
493+
/*
494+
* Counter-specific attributes.
495+
*/
496+
RDMA_NLDEV_ATTR_STAT_MODE, /* u32 */
497+
RDMA_NLDEV_ATTR_STAT_RES, /* u32 */
498+
RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK, /* u32 */
491499

492500
/*
493501
* Information about a chardev.

0 commit comments

Comments
 (0)