From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC3EC402BA0 for ; Thu, 9 Jul 2026 09:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783590958; cv=none; b=qU4tIuGFNOCx4rNldFWi/kWst2dEeXZ5HP2iEAkRAnajyKXgRv2bthNP7ShHWhFWDU7JzA5gUgOOtOmBzm3ILyVdgPCE+msC5CS+s80ivh6BpOZMBhe+7gANW+gox1PQKLDDkAfc4GP8La2Yf2jlViH/wzOYmm1sPTKp27Yv/oA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783590958; c=relaxed/simple; bh=pdMmpZJCv+StAJxQjGBnq4nulDEDCbuKp7xLyLbTHHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ILDr/67JN+VoPRqCt2G9ZS/lMHKsoAoGM0yLiP+yC3ybo5TVssdRrf2H9EL14oXtdePE9vSr8cTo84ybVGk9Po2H6MsDlZr/jb6oH8tspIJmEvgTN/apTuzXc7BT/dsYjk29V6iPRaRonexL63Q5TAeN2s55fHiNVgjjmCxw2/0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20251104.gappssmtp.com header.i=@resnulli-us.20251104.gappssmtp.com header.b=N54syBis; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20251104.gappssmtp.com header.i=@resnulli-us.20251104.gappssmtp.com header.b="N54syBis" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-47c6e9a694bso886168f8f.1 for ; Thu, 09 Jul 2026 02:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20251104.gappssmtp.com; s=20251104; t=1783590955; x=1784195755; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NfMuLF2nfHbgRgmO34SL3Jj6SviYlx2uzsjm64OYl7Y=; b=N54syBiswM9Yk8e2fpr9lVVBcEETybUF1tI5udYUpv4oHGx0pm3G3j9HCZ0uWX4EAM zY719SAoQ3LW8R/m2rwbA4CFuMt2dcW0dmkpd9T7mJTKi+a7bjKgQrdi/Isj/Rxofy3R DrcnkJAw8aLRzMMqVe4q+I07EuqfeHV4RThu/3+rQoUCzpLdwTDG0Y0c4v6dWTQqdhr3 qJ1JlzrGKOoBwqssop5hmxZplWSMNUv3d+kgOIHp4DJC6pax29POn/xpxZcIDhYZzGQ6 ONEAmkPd3b5JHV9gnmkB1e/Z8Iu7QIUY2jEeV3TUODc8BVSFY6vFrH2XVJlKDn3AbZyZ KtNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783590955; x=1784195755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NfMuLF2nfHbgRgmO34SL3Jj6SviYlx2uzsjm64OYl7Y=; b=laz2qCvfWqvoq3qeth9mtNeJN+IH6Hw3jMcQc7MgB0F6K0fUt11g006/9IY+wt0+E5 nV9nKgxIhIaq9WIMyYU4/0+BxcDpo+DMO2nTtlO78D/SgFy50cY5VwKpU+cxTIqLBp6N zrlgSXb/gUlp1IL7FDsTJp6Jss1/4XmnTDUYDjHg6ew6At12gIaSomQGCWeblfO2UJ1/ E5qkXVi2VphTI1/AoxpuWh1xMJxQmHTytyLe1QvZ5pMz19IoMh88aWE2hE6zYs4r6KgN eaq/kiulx6XOXcC13MXD651QIGo+O1mpP5mIDh7Y+XYReYkM1GWB64EE2wJGg4jkglap Ey/Q== X-Forwarded-Encrypted: i=1; AHgh+RoiYlQVmyiJWJK/7MpdmvGNHNmj/xg8Dbk/L+dK+vFDMS7LyIhgbxIOSR1zKyBbbGYmpJpZJWE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6CdpyQFxT7IagsjsoxOPI6YMl8E5Q/53OUvM4jKw+oINuVetZ ghg2TCId3l9DsR2YAviVkfVss9egyy7o/pv8BSPC4utMx0wv1HxNiG3zN8hI/wWPqfQ= X-Gm-Gg: AfdE7cl3pd26lmydTf8Wo/aD0pqZbJN03+3TkFncYtddfRKZLtVMjbqbZL/iS40xUZn dhfWPUWPcH22ELoALKbq/7yi1Xfz521afk+crneye7z4/JuIArgIejtj7yhjxGQX2fwmd5ov2C8 71O3KWr7UfmHDxuvDQWWY4kkqXxKw6LDU9ltbRTqbqtaoTyOyKHaUAkQrpWWe8UlVhcwwv/2uaL E7y9NC8OErZfprp1hcrVpAuvsEfXPoBKNOy9PgZnxBJKslizIGLzJWPqKCnKbP3rPeTCTargqRO wz0LCjm/sEo+MPLB50WrA9QRLuRI8vQvcl9iCcL7jrtiht135vGu20he7nVVNiPe/22mKkw56XL BX6KpK6qZ4eBIelL8OuVsQOp6/VI7mWBA5Izd+meKvE7ErBEYM5onivEtIijPBNRp1zHT/60sl/ nZdHZ0plRJr4LWPzGTsRNKOA== X-Received: by 2002:a05:600c:83c6:b0:493:b8cd:2555 with SMTP id 5b1f17b1804b1-493e690497emr64042885e9.3.1783590955326; Thu, 09 Jul 2026 02:55:55 -0700 (PDT) Received: from localhost ([140.209.217.211]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47a9de1e6ccsm50293284f8f.5.2026.07.09.02.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 02:55:54 -0700 (PDT) From: Jiri Pirko To: linux-rdma@vger.kernel.org Cc: cgroups@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kselftest@vger.kernel.org, jgg@ziepe.ca, leon@kernel.org, parav@nvidia.com, mbloch@nvidia.com, cmeiohas@nvidia.com, roman.gushchin@linux.dev, bvanassche@acm.org, zyjzyj2000@gmail.com, shuah@kernel.org, tj@kernel.org, mkoutny@suse.com, hannes@cmpxchg.org, alibuda@linux.alibaba.com, dust.li@linux.alibaba.com, sidraya@linux.ibm.com, wenjia@linux.ibm.com Subject: [PATCH rdma-next 06/13] net/smc: Look up the pnetid ib device within the net namespace Date: Thu, 9 Jul 2026 11:55:25 +0200 Message-ID: <20260709095532.855647-7-jiri@resnulli.us> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260709095532.855647-1-jiri@resnulli.us> References: <20260709095532.855647-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jiri Pirko 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 --- net/smc/smc_pnet.c | 20 ++++++++++++++------ 1 file 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 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net, 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; -- 2.54.0