diff options
| author | Jiri Pirko <jiri@nvidia.com> | 2026-07-16 15:23:07 +0200 |
|---|---|---|
| committer | Leon Romanovsky <leon@kernel.org> | 2026-07-26 03:11:00 -0400 |
| commit | 47b9ef3c0013e1cc6ca7b342c8d28ddb9f35cb12 (patch) | |
| tree | 9a9bb152d8bda8001eb2d476fd8b07664a37d01e | |
| parent | 601f3fd97dec0525f1fca9887ca16574f81588b7 (diff) | |
| download | linux-next-47b9ef3c0013e1cc6ca7b342c8d28ddb9f35cb12.tar.gz linux-next-47b9ef3c0013e1cc6ca7b342c8d28ddb9f35cb12.zip | |
net/smc: Look up the pnetid ib device within the net namespace
Scope smc_pnet_find_ib() to the caller's net namespace so pnetid setup
cannot bind to a same-named RDMA device from another namespace once names
become per-netns.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Link: https://patch.msgid.link/20260716132316.1495242-7-jiri@resnulli.us
Signed-off-by: Leon Romanovsky <leon@kernel.org>
| -rw-r--r-- | net/smc/smc_pnet.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c index 63e286e2dfaa..ff9c9c35cc2f 100644 --- a/net/smc/smc_pnet.c +++ b/net/smc/smc_pnet.c @@ -304,13 +304,18 @@ static bool smc_pnetid_valid(const char *pnet_name, char *pnetid) return true; } -/* Find an infiniband device by a given name. The device might not exist. */ -static struct smc_ib_device *smc_pnet_find_ib(char *ib_name) +/* + * Find an infiniband device by a given name, restricted to the devices + * accessible from @net. The device might not exist. + */ +static struct smc_ib_device *smc_pnet_find_ib(struct net *net, char *ib_name) { struct smc_ib_device *ibdev; mutex_lock(&smc_ib_devices.mutex); list_for_each_entry(ibdev, &smc_ib_devices.list, list) { + if (!rdma_dev_access_netns(ibdev->ibdev, net)) + continue; if (!strncmp(ibdev->ibdev->name, ib_name, sizeof(ibdev->ibdev->name)) || (ibdev->ibdev->dev.parent && @@ -408,8 +413,8 @@ out_put: return rc; } -static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, - u8 ib_port, char *pnet_name) +static int smc_pnet_add_ib(struct smc_pnettable *pnettable, struct net *net, + char *ib_name, u8 ib_port, char *pnet_name) { struct smc_pnetentry *tmp_pe, *new_pe; struct smc_ib_device *ib_dev; @@ -419,7 +424,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, bool new_ibdev; /* try to apply the pnetid to active devices */ - ib_dev = smc_pnet_find_ib(ib_name); + ib_dev = smc_pnet_find_ib(net, ib_name); if (ib_dev) { ibdev_applied = smc_pnet_apply_ib(ib_dev, ib_port, pnet_name); if (ibdev_applied) @@ -518,7 +523,7 @@ static int smc_pnet_enter(struct net *net, struct nlattr *tb[]) if (ibport < 1 || ibport > SMC_MAX_PORTS) goto error; } - rc = smc_pnet_add_ib(pnettable, string, ibport, pnet_name); + rc = smc_pnet_add_ib(pnettable, net, string, ibport, pnet_name); if (!rc) new_ibdev = true; else if (rc != -EEXIST) @@ -1170,6 +1175,9 @@ int smc_pnetid_by_table_ib(struct smc_ib_device *smcibdev, u8 ib_port) struct smc_net *sn; int rc = -ENOENT; + if (!rdma_dev_access_netns(smcibdev->ibdev, &init_net)) + return -ENOENT; + /* get pnettable for init namespace */ sn = net_generic(&init_net, smc_net_id); pnettable = &sn->pnettable; |
