Skip to content

Commit f6350da

Browse files
bonktreedledford
authored andcommitted
IB/ipoib: Log sysfs 'dev_id' accesses from userspace
Some tools may currently be using only the deprecated attribute; let's print an elaborate and clear deprecation notice to kmsg. To do that, we have to replace the whole sysfs file, since we inherit the original one from netdev. Signed-off-by: Arseny Maslennikov <ar@cs.msu.ru> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 9b8b2a3 commit f6350da

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

drivers/infiniband/ulp/ipoib/ipoib_main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,35 @@ int ipoib_add_pkey_attr(struct net_device *dev)
23872387
return device_create_file(&dev->dev, &dev_attr_pkey);
23882388
}
23892389

2390+
/*
2391+
* We erroneously exposed the iface's port number in the dev_id
2392+
* sysfs field long after dev_port was introduced for that purpose[1],
2393+
* and we need to stop everyone from relying on that.
2394+
* Let's overload the shower routine for the dev_id file here
2395+
* to gently bring the issue up.
2396+
*
2397+
* [1] https://www.spinics.net/lists/netdev/msg272123.html
2398+
*/
2399+
static ssize_t dev_id_show(struct device *dev,
2400+
struct device_attribute *attr, char *buf)
2401+
{
2402+
struct net_device *ndev = to_net_dev(dev);
2403+
2404+
if (ndev->dev_id == ndev->dev_port)
2405+
netdev_info_once(ndev,
2406+
"\"%s\" wants to know my dev_id. Should it look at dev_port instead? See Documentation/ABI/testing/sysfs-class-net for more info.\n",
2407+
current->comm);
2408+
2409+
return sprintf(buf, "%#x\n", ndev->dev_id);
2410+
}
2411+
static DEVICE_ATTR_RO(dev_id);
2412+
2413+
int ipoib_intercept_dev_id_attr(struct net_device *dev)
2414+
{
2415+
device_remove_file(&dev->dev, &dev_attr_dev_id);
2416+
return device_create_file(&dev->dev, &dev_attr_dev_id);
2417+
}
2418+
23902419
static struct net_device *ipoib_add_port(const char *format,
23912420
struct ib_device *hca, u8 port)
23922421
{
@@ -2428,6 +2457,8 @@ static struct net_device *ipoib_add_port(const char *format,
24282457
*/
24292458
ndev->priv_destructor = ipoib_intf_free;
24302459

2460+
if (ipoib_intercept_dev_id_attr(ndev))
2461+
goto sysfs_failed;
24312462
if (ipoib_cm_add_mode_attr(ndev))
24322463
goto sysfs_failed;
24332464
if (ipoib_add_pkey_attr(ndev))

0 commit comments

Comments
 (0)