Commit 670ebdf0 authored by Parav Pandit's avatar Parav Pandit Committed by Greg Kroah-Hartman

RDMA/core: Do not expose unsupported counters

[ Upstream commit 0f6ef65d ]

If the provider driver (such as rdma_rxe) doesn't support pma counters,
avoid exposing its directory similar to optional hw_counters directory.
If core fails to read the PMA counter, return an error so that user can
retry later if needed.

Fixes: 35c4cbb1 ("IB/core: Create get_perf_mad function in sysfs.c")
Reported-by: default avatarHolger Hoffstätte <holger@applied-asynchrony.com>
Tested-by: default avatarHolger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4877db2e
...@@ -489,7 +489,7 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr, ...@@ -489,7 +489,7 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data, ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data,
40 + offset / 8, sizeof(data)); 40 + offset / 8, sizeof(data));
if (ret < 0) if (ret < 0)
return sprintf(buf, "N/A (no PMA)\n"); return ret;
switch (width) { switch (width) {
case 4: case 4:
...@@ -1012,10 +1012,12 @@ static int add_port(struct ib_device *device, int port_num, ...@@ -1012,10 +1012,12 @@ static int add_port(struct ib_device *device, int port_num,
goto err_put; goto err_put;
} }
p->pma_table = get_counter_table(device, port_num); if (device->process_mad) {
ret = sysfs_create_group(&p->kobj, p->pma_table); p->pma_table = get_counter_table(device, port_num);
if (ret) ret = sysfs_create_group(&p->kobj, p->pma_table);
goto err_put_gid_attrs; if (ret)
goto err_put_gid_attrs;
}
p->gid_group.name = "gids"; p->gid_group.name = "gids";
p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len); p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
...@@ -1128,7 +1130,8 @@ static int add_port(struct ib_device *device, int port_num, ...@@ -1128,7 +1130,8 @@ static int add_port(struct ib_device *device, int port_num,
p->gid_group.attrs = NULL; p->gid_group.attrs = NULL;
err_remove_pma: err_remove_pma:
sysfs_remove_group(&p->kobj, p->pma_table); if (p->pma_table)
sysfs_remove_group(&p->kobj, p->pma_table);
err_put_gid_attrs: err_put_gid_attrs:
kobject_put(&p->gid_attr_group->kobj); kobject_put(&p->gid_attr_group->kobj);
...@@ -1240,7 +1243,9 @@ static void free_port_list_attributes(struct ib_device *device) ...@@ -1240,7 +1243,9 @@ static void free_port_list_attributes(struct ib_device *device)
kfree(port->hw_stats); kfree(port->hw_stats);
free_hsag(&port->kobj, port->hw_stats_ag); free_hsag(&port->kobj, port->hw_stats_ag);
} }
sysfs_remove_group(p, port->pma_table);
if (port->pma_table)
sysfs_remove_group(p, port->pma_table);
sysfs_remove_group(p, &port->pkey_group); sysfs_remove_group(p, &port->pkey_group);
sysfs_remove_group(p, &port->gid_group); sysfs_remove_group(p, &port->gid_group);
sysfs_remove_group(&port->gid_attr_group->kobj, sysfs_remove_group(&port->gid_attr_group->kobj,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment