License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-01-09 15:55:15 +00:00
|
|
|
/*
|
|
|
|
|
* Shared Memory Communications over RDMA (SMC-R) and RoCE
|
|
|
|
|
*
|
|
|
|
|
* Generic netlink support functions to configure an SMC-R PNET table
|
|
|
|
|
*
|
|
|
|
|
* Copyright IBM Corp. 2016
|
|
|
|
|
*
|
|
|
|
|
* Author(s): Thomas Richter <tmricht@linux.vnet.ibm.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
|
#include <linux/ctype.h>
|
2020-07-08 15:05:13 +00:00
|
|
|
#include <linux/mutex.h>
|
2017-01-09 15:55:15 +00:00
|
|
|
#include <net/netlink.h>
|
|
|
|
|
#include <net/genetlink.h>
|
|
|
|
|
|
|
|
|
|
#include <uapi/linux/if.h>
|
|
|
|
|
#include <uapi/linux/smc.h>
|
|
|
|
|
|
|
|
|
|
#include <rdma/ib_verbs.h>
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
#include <net/netns/generic.h>
|
|
|
|
|
#include "smc_netns.h"
|
|
|
|
|
|
2017-01-09 15:55:15 +00:00
|
|
|
#include "smc_pnet.h"
|
|
|
|
|
#include "smc_ib.h"
|
2018-06-28 17:05:08 +00:00
|
|
|
#include "smc_ism.h"
|
2019-04-12 10:57:26 +00:00
|
|
|
#include "smc_core.h"
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2020-09-26 10:44:26 +00:00
|
|
|
static struct net_device *__pnet_find_base_ndev(struct net_device *ndev);
|
2019-02-21 12:01:00 +00:00
|
|
|
static struct net_device *pnet_find_base_ndev(struct net_device *ndev);
|
|
|
|
|
|
2020-05-25 15:31:58 +00:00
|
|
|
static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX + 1] = {
|
2017-01-09 15:55:15 +00:00
|
|
|
[SMC_PNETID_NAME] = {
|
|
|
|
|
.type = NLA_NUL_STRING,
|
2019-01-30 17:51:01 +00:00
|
|
|
.len = SMC_MAX_PNETID_LEN
|
2017-01-09 15:55:15 +00:00
|
|
|
},
|
|
|
|
|
[SMC_PNETID_ETHNAME] = {
|
|
|
|
|
.type = NLA_NUL_STRING,
|
|
|
|
|
.len = IFNAMSIZ - 1
|
|
|
|
|
},
|
|
|
|
|
[SMC_PNETID_IBNAME] = {
|
|
|
|
|
.type = NLA_NUL_STRING,
|
|
|
|
|
.len = IB_DEVICE_NAME_MAX - 1
|
|
|
|
|
},
|
|
|
|
|
[SMC_PNETID_IBPORT] = { .type = NLA_U8 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct genl_family smc_pnet_nl_family;
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
enum smc_pnet_nametype {
|
|
|
|
|
SMC_PNET_ETH = 1,
|
|
|
|
|
SMC_PNET_IB = 2,
|
2017-01-09 15:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
/* pnet entry stored in pnet table */
|
|
|
|
|
struct smc_pnetentry {
|
|
|
|
|
struct list_head list;
|
|
|
|
|
char pnet_name[SMC_MAX_PNETID_LEN + 1];
|
2020-04-29 15:10:37 +00:00
|
|
|
enum smc_pnet_nametype type;
|
|
|
|
|
union {
|
|
|
|
|
struct {
|
|
|
|
|
char eth_name[IFNAMSIZ + 1];
|
|
|
|
|
struct net_device *ndev;
|
2021-12-07 01:30:36 +00:00
|
|
|
netdevice_tracker dev_tracker;
|
2020-04-29 15:10:37 +00:00
|
|
|
};
|
|
|
|
|
struct {
|
|
|
|
|
char ib_name[IB_DEVICE_NAME_MAX + 1];
|
|
|
|
|
u8 ib_port;
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-02-21 12:01:00 +00:00
|
|
|
};
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2020-09-26 10:44:19 +00:00
|
|
|
/* Check if the pnetid is set */
|
2020-09-26 10:44:27 +00:00
|
|
|
bool smc_pnet_is_pnetid_set(u8 *pnetid)
|
2020-09-26 10:44:19 +00:00
|
|
|
{
|
|
|
|
|
if (pnetid[0] == 0 || pnetid[0] == _S)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
/* Check if two given pnetids match */
|
|
|
|
|
static bool smc_pnet_match(u8 *pnetid1, u8 *pnetid2)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
2019-02-21 12:01:00 +00:00
|
|
|
int i;
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
for (i = 0; i < SMC_MAX_PNETID_LEN; i++) {
|
2020-09-26 10:44:19 +00:00
|
|
|
if ((pnetid1[i] == 0 || pnetid1[i] == _S) &&
|
|
|
|
|
(pnetid2[i] == 0 || pnetid2[i] == _S))
|
2017-01-09 15:55:15 +00:00
|
|
|
break;
|
2019-02-21 12:01:00 +00:00
|
|
|
if (pnetid1[i] != pnetid2[i])
|
|
|
|
|
return false;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
2019-02-21 12:01:00 +00:00
|
|
|
return true;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove a pnetid from the pnet table.
|
|
|
|
|
*/
|
2019-02-21 12:01:02 +00:00
|
|
|
static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
|
|
|
|
struct smc_pnetentry *pnetelem, *tmp_pe;
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_pnettable *pnettable;
|
2019-02-21 12:01:00 +00:00
|
|
|
struct smc_ib_device *ibdev;
|
2023-01-23 18:17:52 +00:00
|
|
|
struct smcd_dev *smcd;
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_net *sn;
|
2017-01-09 15:55:15 +00:00
|
|
|
int rc = -ENOENT;
|
2019-02-21 12:01:00 +00:00
|
|
|
int ibport;
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* get pnettable for namespace */
|
|
|
|
|
sn = net_generic(net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* remove table entry */
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2019-02-21 12:01:02 +00:00
|
|
|
list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist,
|
2017-01-09 15:55:15 +00:00
|
|
|
list) {
|
2019-02-21 12:01:00 +00:00
|
|
|
if (!pnet_name ||
|
|
|
|
|
smc_pnet_match(pnetelem->pnet_name, pnet_name)) {
|
2017-01-09 15:55:15 +00:00
|
|
|
list_del(&pnetelem->list);
|
2020-05-05 13:01:20 +00:00
|
|
|
if (pnetelem->type == SMC_PNET_ETH && pnetelem->ndev) {
|
2022-06-08 04:39:55 +00:00
|
|
|
netdev_put(pnetelem->ndev,
|
|
|
|
|
&pnetelem->dev_tracker);
|
2020-05-05 13:01:20 +00:00
|
|
|
pr_warn_ratelimited("smc: net device %s "
|
|
|
|
|
"erased user defined "
|
|
|
|
|
"pnetid %.16s\n",
|
|
|
|
|
pnetelem->eth_name,
|
|
|
|
|
pnetelem->pnet_name);
|
|
|
|
|
}
|
2017-01-09 15:55:15 +00:00
|
|
|
kfree(pnetelem);
|
|
|
|
|
rc = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2019-02-21 12:01:02 +00:00
|
|
|
|
|
|
|
|
/* if this is not the initial namespace, stop here */
|
|
|
|
|
if (net != &init_net)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
/* remove ib devices */
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2019-02-21 12:01:00 +00:00
|
|
|
list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
|
|
|
|
|
for (ibport = 0; ibport < SMC_MAX_PORTS; ibport++) {
|
|
|
|
|
if (ibdev->pnetid_by_user[ibport] &&
|
|
|
|
|
(!pnet_name ||
|
|
|
|
|
smc_pnet_match(pnet_name,
|
|
|
|
|
ibdev->pnetid[ibport]))) {
|
2020-05-05 13:01:20 +00:00
|
|
|
pr_warn_ratelimited("smc: ib device %s ibport "
|
|
|
|
|
"%d erased user defined "
|
|
|
|
|
"pnetid %.16s\n",
|
|
|
|
|
ibdev->ibdev->name,
|
|
|
|
|
ibport + 1,
|
|
|
|
|
ibdev->pnetid[ibport]);
|
2019-02-21 12:01:00 +00:00
|
|
|
memset(ibdev->pnetid[ibport], 0,
|
|
|
|
|
SMC_MAX_PNETID_LEN);
|
|
|
|
|
ibdev->pnetid_by_user[ibport] = false;
|
|
|
|
|
rc = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2019-02-21 12:01:01 +00:00
|
|
|
/* remove smcd devices */
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_lock(&smcd_dev_list.mutex);
|
2023-01-23 18:17:52 +00:00
|
|
|
list_for_each_entry(smcd, &smcd_dev_list.list, list) {
|
|
|
|
|
if (smcd->pnetid_by_user &&
|
2019-02-21 12:01:01 +00:00
|
|
|
(!pnet_name ||
|
2023-01-23 18:17:52 +00:00
|
|
|
smc_pnet_match(pnet_name, smcd->pnetid))) {
|
2020-05-05 13:01:20 +00:00
|
|
|
pr_warn_ratelimited("smc: smcd device %s "
|
|
|
|
|
"erased user defined pnetid "
|
2023-01-23 18:17:52 +00:00
|
|
|
"%.16s\n",
|
2025-09-18 11:04:54 +00:00
|
|
|
dev_name(&smcd->dibs->dev),
|
2023-01-23 18:17:52 +00:00
|
|
|
smcd->pnetid);
|
|
|
|
|
memset(smcd->pnetid, 0, SMC_MAX_PNETID_LEN);
|
|
|
|
|
smcd->pnetid_by_user = false;
|
2019-02-21 12:01:01 +00:00
|
|
|
rc = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_unlock(&smcd_dev_list.mutex);
|
2017-01-09 15:55:15 +00:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* Add the reference to a given network device to the pnet table.
|
2017-01-09 15:55:15 +00:00
|
|
|
*/
|
2020-04-29 15:10:37 +00:00
|
|
|
static int smc_pnet_add_by_ndev(struct net_device *ndev)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
|
|
|
|
struct smc_pnetentry *pnetelem, *tmp_pe;
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_pnettable *pnettable;
|
|
|
|
|
struct net *net = dev_net(ndev);
|
|
|
|
|
struct smc_net *sn;
|
2017-01-09 15:55:15 +00:00
|
|
|
int rc = -ENOENT;
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* get pnettable for namespace */
|
|
|
|
|
sn = net_generic(net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
|
|
|
|
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2019-02-21 12:01:02 +00:00
|
|
|
list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist, list) {
|
2020-04-29 15:10:37 +00:00
|
|
|
if (pnetelem->type == SMC_PNET_ETH && !pnetelem->ndev &&
|
|
|
|
|
!strncmp(pnetelem->eth_name, ndev->name, IFNAMSIZ)) {
|
2022-06-08 04:39:55 +00:00
|
|
|
netdev_hold(ndev, &pnetelem->dev_tracker, GFP_ATOMIC);
|
2020-04-29 15:10:37 +00:00
|
|
|
pnetelem->ndev = ndev;
|
2017-01-09 15:55:15 +00:00
|
|
|
rc = 0;
|
2020-05-05 13:01:20 +00:00
|
|
|
pr_warn_ratelimited("smc: adding net device %s with "
|
|
|
|
|
"user defined pnetid %.16s\n",
|
|
|
|
|
pnetelem->eth_name,
|
|
|
|
|
pnetelem->pnet_name);
|
2017-01-09 15:55:15 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2017-01-09 15:55:15 +00:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* Remove the reference to a given network device from the pnet table.
|
2017-01-09 15:55:15 +00:00
|
|
|
*/
|
2020-04-29 15:10:37 +00:00
|
|
|
static int smc_pnet_remove_by_ndev(struct net_device *ndev)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
2020-04-29 15:10:37 +00:00
|
|
|
struct smc_pnetentry *pnetelem, *tmp_pe;
|
|
|
|
|
struct smc_pnettable *pnettable;
|
|
|
|
|
struct net *net = dev_net(ndev);
|
|
|
|
|
struct smc_net *sn;
|
|
|
|
|
int rc = -ENOENT;
|
2019-02-21 12:01:00 +00:00
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* get pnettable for namespace */
|
|
|
|
|
sn = net_generic(net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
2019-02-21 12:01:01 +00:00
|
|
|
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist, list) {
|
|
|
|
|
if (pnetelem->type == SMC_PNET_ETH && pnetelem->ndev == ndev) {
|
2022-06-08 04:39:55 +00:00
|
|
|
netdev_put(pnetelem->ndev, &pnetelem->dev_tracker);
|
2020-04-29 15:10:37 +00:00
|
|
|
pnetelem->ndev = NULL;
|
|
|
|
|
rc = 0;
|
2020-05-05 13:01:20 +00:00
|
|
|
pr_warn_ratelimited("smc: removing net device %s with "
|
|
|
|
|
"user defined pnetid %.16s\n",
|
|
|
|
|
pnetelem->eth_name,
|
|
|
|
|
pnetelem->pnet_name);
|
2020-04-29 15:10:37 +00:00
|
|
|
break;
|
2019-02-21 12:01:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
return rc;
|
|
|
|
|
}
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* Apply pnetid to ib device when no pnetid is set.
|
|
|
|
|
*/
|
|
|
|
|
static bool smc_pnet_apply_ib(struct smc_ib_device *ib_dev, u8 ib_port,
|
|
|
|
|
char *pnet_name)
|
|
|
|
|
{
|
|
|
|
|
bool applied = false;
|
2019-02-21 12:01:00 +00:00
|
|
|
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2020-09-26 10:44:19 +00:00
|
|
|
if (!smc_pnet_is_pnetid_set(ib_dev->pnetid[ib_port - 1])) {
|
2020-04-29 15:10:37 +00:00
|
|
|
memcpy(ib_dev->pnetid[ib_port - 1], pnet_name,
|
|
|
|
|
SMC_MAX_PNETID_LEN);
|
|
|
|
|
ib_dev->pnetid_by_user[ib_port - 1] = true;
|
|
|
|
|
applied = true;
|
|
|
|
|
}
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2020-04-29 15:10:37 +00:00
|
|
|
return applied;
|
|
|
|
|
}
|
2019-02-21 12:01:00 +00:00
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* Apply pnetid to smcd device when no pnetid is set.
|
|
|
|
|
*/
|
|
|
|
|
static bool smc_pnet_apply_smcd(struct smcd_dev *smcd_dev, char *pnet_name)
|
|
|
|
|
{
|
|
|
|
|
bool applied = false;
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_lock(&smcd_dev_list.mutex);
|
2020-09-26 10:44:19 +00:00
|
|
|
if (!smc_pnet_is_pnetid_set(smcd_dev->pnetid)) {
|
2020-04-29 15:10:37 +00:00
|
|
|
memcpy(smcd_dev->pnetid, pnet_name, SMC_MAX_PNETID_LEN);
|
|
|
|
|
smcd_dev->pnetid_by_user = true;
|
|
|
|
|
applied = true;
|
2019-02-21 12:01:00 +00:00
|
|
|
}
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_unlock(&smcd_dev_list.mutex);
|
2020-04-29 15:10:37 +00:00
|
|
|
return applied;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The limit for pnetid is 16 characters.
|
|
|
|
|
* Valid characters should be (single-byte character set) a-z, A-Z, 0-9.
|
|
|
|
|
* Lower case letters are converted to upper case.
|
|
|
|
|
* Interior blanks should not be used.
|
|
|
|
|
*/
|
|
|
|
|
static bool smc_pnetid_valid(const char *pnet_name, char *pnetid)
|
|
|
|
|
{
|
|
|
|
|
char *bf = skip_spaces(pnet_name);
|
|
|
|
|
size_t len = strlen(bf);
|
|
|
|
|
char *end = bf + len;
|
|
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
|
return false;
|
|
|
|
|
while (--end >= bf && isspace(*end))
|
|
|
|
|
;
|
2018-06-28 17:05:05 +00:00
|
|
|
if (end - bf >= SMC_MAX_PNETID_LEN)
|
2017-01-09 15:55:15 +00:00
|
|
|
return false;
|
|
|
|
|
while (bf <= end) {
|
|
|
|
|
if (!isalnum(*bf))
|
|
|
|
|
return false;
|
|
|
|
|
*pnetid++ = islower(*bf) ? toupper(*bf) : *bf;
|
|
|
|
|
bf++;
|
|
|
|
|
}
|
|
|
|
|
*pnetid = '\0';
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find an infiniband device by a given name. The device might not exist. */
|
2017-04-10 12:57:57 +00:00
|
|
|
static struct smc_ib_device *smc_pnet_find_ib(char *ib_name)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
|
|
|
|
struct smc_ib_device *ibdev;
|
|
|
|
|
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2017-01-09 15:55:15 +00:00
|
|
|
list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
|
|
|
|
|
if (!strncmp(ibdev->ibdev->name, ib_name,
|
2019-02-21 12:01:03 +00:00
|
|
|
sizeof(ibdev->ibdev->name)) ||
|
2022-04-08 15:10:34 +00:00
|
|
|
(ibdev->ibdev->dev.parent &&
|
|
|
|
|
!strncmp(dev_name(ibdev->ibdev->dev.parent), ib_name,
|
|
|
|
|
IB_DEVICE_NAME_MAX - 1))) {
|
2017-01-09 15:55:15 +00:00
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ibdev = NULL;
|
|
|
|
|
out:
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2017-01-09 15:55:15 +00:00
|
|
|
return ibdev;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:01 +00:00
|
|
|
/* Find an smcd device by a given name. The device might not exist. */
|
|
|
|
|
static struct smcd_dev *smc_pnet_find_smcd(char *smcd_name)
|
|
|
|
|
{
|
|
|
|
|
struct smcd_dev *smcd_dev;
|
|
|
|
|
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_lock(&smcd_dev_list.mutex);
|
2019-02-21 12:01:01 +00:00
|
|
|
list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) {
|
2025-09-18 11:04:55 +00:00
|
|
|
if (!strncmp(dev_name(&smcd_dev->dibs->dev), smcd_name,
|
|
|
|
|
IB_DEVICE_NAME_MAX - 1) ||
|
|
|
|
|
(smcd_dev->dibs->dev.parent &&
|
|
|
|
|
!strncmp(dev_name(smcd_dev->dibs->dev.parent), smcd_name,
|
|
|
|
|
IB_DEVICE_NAME_MAX - 1)))
|
2019-02-21 12:01:01 +00:00
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
smcd_dev = NULL;
|
|
|
|
|
out:
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_unlock(&smcd_dev_list.mutex);
|
2019-02-21 12:01:01 +00:00
|
|
|
return smcd_dev;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
|
|
|
|
|
char *eth_name, char *pnet_name)
|
|
|
|
|
{
|
|
|
|
|
struct smc_pnetentry *tmp_pe, *new_pe;
|
|
|
|
|
struct net_device *ndev, *base_ndev;
|
|
|
|
|
u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
|
|
|
|
|
bool new_netdev;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
/* check if (base) netdev already has a pnetid. If there is one, we do
|
|
|
|
|
* not want to add a pnet table entry
|
|
|
|
|
*/
|
|
|
|
|
rc = -EEXIST;
|
|
|
|
|
ndev = dev_get_by_name(net, eth_name); /* dev_hold() */
|
|
|
|
|
if (ndev) {
|
|
|
|
|
base_ndev = pnet_find_base_ndev(ndev);
|
|
|
|
|
if (!smc_pnetid_by_dev_port(base_ndev->dev.parent,
|
|
|
|
|
base_ndev->dev_port, ndev_pnetid))
|
|
|
|
|
goto out_put;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a new netdev entry to the pnet table if there isn't one */
|
|
|
|
|
rc = -ENOMEM;
|
|
|
|
|
new_pe = kzalloc(sizeof(*new_pe), GFP_KERNEL);
|
|
|
|
|
if (!new_pe)
|
|
|
|
|
goto out_put;
|
|
|
|
|
new_pe->type = SMC_PNET_ETH;
|
|
|
|
|
memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
|
2025-06-20 10:25:59 +00:00
|
|
|
strscpy(new_pe->eth_name, eth_name);
|
2020-04-29 15:10:37 +00:00
|
|
|
rc = -EEXIST;
|
|
|
|
|
new_netdev = true;
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
|
|
|
|
|
if (tmp_pe->type == SMC_PNET_ETH &&
|
|
|
|
|
!strncmp(tmp_pe->eth_name, eth_name, IFNAMSIZ)) {
|
|
|
|
|
new_netdev = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (new_netdev) {
|
2022-02-06 05:05:16 +00:00
|
|
|
if (ndev) {
|
|
|
|
|
new_pe->ndev = ndev;
|
|
|
|
|
netdev_tracker_alloc(ndev, &new_pe->dev_tracker,
|
2022-02-06 14:33:48 +00:00
|
|
|
GFP_ATOMIC);
|
2022-02-06 05:05:16 +00:00
|
|
|
}
|
2020-04-29 15:10:37 +00:00
|
|
|
list_add_tail(&new_pe->list, &pnettable->pnetlist);
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
} else {
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
kfree(new_pe);
|
|
|
|
|
goto out_put;
|
|
|
|
|
}
|
2020-05-05 13:01:20 +00:00
|
|
|
if (ndev)
|
|
|
|
|
pr_warn_ratelimited("smc: net device %s "
|
|
|
|
|
"applied user defined pnetid %.16s\n",
|
|
|
|
|
new_pe->eth_name, new_pe->pnet_name);
|
2020-04-29 15:10:37 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
out_put:
|
2021-08-05 11:55:27 +00:00
|
|
|
dev_put(ndev);
|
2020-04-29 15:10:37 +00:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
|
|
|
|
|
u8 ib_port, char *pnet_name)
|
|
|
|
|
{
|
|
|
|
|
struct smc_pnetentry *tmp_pe, *new_pe;
|
|
|
|
|
struct smc_ib_device *ib_dev;
|
|
|
|
|
bool smcddev_applied = true;
|
|
|
|
|
bool ibdev_applied = true;
|
2023-01-23 18:17:52 +00:00
|
|
|
struct smcd_dev *smcd;
|
2020-04-29 15:10:37 +00:00
|
|
|
bool new_ibdev;
|
|
|
|
|
|
|
|
|
|
/* try to apply the pnetid to active devices */
|
|
|
|
|
ib_dev = smc_pnet_find_ib(ib_name);
|
2020-05-05 13:01:20 +00:00
|
|
|
if (ib_dev) {
|
2020-04-29 15:10:37 +00:00
|
|
|
ibdev_applied = smc_pnet_apply_ib(ib_dev, ib_port, pnet_name);
|
2020-05-05 13:01:20 +00:00
|
|
|
if (ibdev_applied)
|
|
|
|
|
pr_warn_ratelimited("smc: ib device %s ibport %d "
|
|
|
|
|
"applied user defined pnetid "
|
|
|
|
|
"%.16s\n", ib_dev->ibdev->name,
|
|
|
|
|
ib_port,
|
|
|
|
|
ib_dev->pnetid[ib_port - 1]);
|
|
|
|
|
}
|
2023-01-23 18:17:52 +00:00
|
|
|
smcd = smc_pnet_find_smcd(ib_name);
|
|
|
|
|
if (smcd) {
|
|
|
|
|
smcddev_applied = smc_pnet_apply_smcd(smcd, pnet_name);
|
|
|
|
|
if (smcddev_applied) {
|
2025-09-18 11:04:54 +00:00
|
|
|
pr_warn_ratelimited("smc: smcd device %s applied user defined pnetid %.16s\n",
|
|
|
|
|
dev_name(&smcd->dibs->dev),
|
2023-01-23 18:17:52 +00:00
|
|
|
smcd->pnetid);
|
|
|
|
|
}
|
2020-05-05 13:01:20 +00:00
|
|
|
}
|
2020-04-29 15:10:37 +00:00
|
|
|
/* Apply fails when a device has a hardware-defined pnetid set, do not
|
|
|
|
|
* add a pnet table entry in that case.
|
|
|
|
|
*/
|
|
|
|
|
if (!ibdev_applied || !smcddev_applied)
|
|
|
|
|
return -EEXIST;
|
|
|
|
|
|
|
|
|
|
/* add a new ib entry to the pnet table if there isn't one */
|
|
|
|
|
new_pe = kzalloc(sizeof(*new_pe), GFP_KERNEL);
|
|
|
|
|
if (!new_pe)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
new_pe->type = SMC_PNET_IB;
|
|
|
|
|
memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
|
2025-09-01 03:04:59 +00:00
|
|
|
strscpy(new_pe->ib_name, ib_name);
|
2020-04-29 15:10:37 +00:00
|
|
|
new_pe->ib_port = ib_port;
|
|
|
|
|
|
|
|
|
|
new_ibdev = true;
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
|
|
|
|
|
if (tmp_pe->type == SMC_PNET_IB &&
|
|
|
|
|
!strncmp(tmp_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX)) {
|
|
|
|
|
new_ibdev = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (new_ibdev) {
|
|
|
|
|
list_add_tail(&new_pe->list, &pnettable->pnetlist);
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
} else {
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
kfree(new_pe);
|
|
|
|
|
}
|
|
|
|
|
return (new_ibdev) ? 0 : -EEXIST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Append a pnetid to the end of the pnet table if not already on this list.
|
2017-01-09 15:55:15 +00:00
|
|
|
*/
|
2020-04-29 15:10:37 +00:00
|
|
|
static int smc_pnet_enter(struct net *net, struct nlattr *tb[])
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
2020-04-29 15:10:37 +00:00
|
|
|
char pnet_name[SMC_MAX_PNETID_LEN + 1];
|
|
|
|
|
struct smc_pnettable *pnettable;
|
|
|
|
|
bool new_netdev = false;
|
|
|
|
|
bool new_ibdev = false;
|
|
|
|
|
struct smc_net *sn;
|
|
|
|
|
u8 ibport = 1;
|
|
|
|
|
char *string;
|
2018-05-14 00:01:30 +00:00
|
|
|
int rc;
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* get pnettable for namespace */
|
|
|
|
|
sn = net_generic(net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
2018-05-14 00:01:30 +00:00
|
|
|
|
|
|
|
|
rc = -EINVAL;
|
|
|
|
|
if (!tb[SMC_PNETID_NAME])
|
|
|
|
|
goto error;
|
|
|
|
|
string = (char *)nla_data(tb[SMC_PNETID_NAME]);
|
2020-04-29 15:10:37 +00:00
|
|
|
if (!smc_pnetid_valid(string, pnet_name))
|
2018-05-14 00:01:30 +00:00
|
|
|
goto error;
|
|
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
if (tb[SMC_PNETID_ETHNAME]) {
|
|
|
|
|
string = (char *)nla_data(tb[SMC_PNETID_ETHNAME]);
|
2020-04-29 15:10:37 +00:00
|
|
|
rc = smc_pnet_add_eth(pnettable, net, string, pnet_name);
|
|
|
|
|
if (!rc)
|
|
|
|
|
new_netdev = true;
|
|
|
|
|
else if (rc != -EEXIST)
|
2019-02-21 12:01:00 +00:00
|
|
|
goto error;
|
|
|
|
|
}
|
2018-05-14 00:01:30 +00:00
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* if this is not the initial namespace, stop here */
|
|
|
|
|
if (net != &init_net)
|
2020-04-29 15:10:37 +00:00
|
|
|
return new_netdev ? 0 : -EEXIST;
|
2019-02-21 12:01:02 +00:00
|
|
|
|
2018-05-14 00:01:30 +00:00
|
|
|
rc = -EINVAL;
|
2019-02-21 12:01:00 +00:00
|
|
|
if (tb[SMC_PNETID_IBNAME]) {
|
2020-04-29 15:10:37 +00:00
|
|
|
string = (char *)nla_data(tb[SMC_PNETID_IBNAME]);
|
|
|
|
|
string = strim(string);
|
|
|
|
|
if (tb[SMC_PNETID_IBPORT]) {
|
|
|
|
|
ibport = nla_get_u8(tb[SMC_PNETID_IBPORT]);
|
|
|
|
|
if (ibport < 1 || ibport > SMC_MAX_PORTS)
|
2019-02-21 12:01:00 +00:00
|
|
|
goto error;
|
|
|
|
|
}
|
2020-04-29 15:10:37 +00:00
|
|
|
rc = smc_pnet_add_ib(pnettable, string, ibport, pnet_name);
|
|
|
|
|
if (!rc)
|
|
|
|
|
new_ibdev = true;
|
|
|
|
|
else if (rc != -EEXIST)
|
|
|
|
|
goto error;
|
2019-02-21 12:01:00 +00:00
|
|
|
}
|
2020-04-29 15:10:37 +00:00
|
|
|
return (new_netdev || new_ibdev) ? 0 : -EEXIST;
|
2017-01-09 15:55:15 +00:00
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert an smc_pnetentry to a netlink attribute sequence */
|
2019-02-21 12:01:00 +00:00
|
|
|
static int smc_pnet_set_nla(struct sk_buff *msg,
|
2020-04-29 15:10:37 +00:00
|
|
|
struct smc_pnetentry *pnetelem)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
2019-02-21 12:01:00 +00:00
|
|
|
if (nla_put_string(msg, SMC_PNETID_NAME, pnetelem->pnet_name))
|
2017-01-09 15:55:15 +00:00
|
|
|
return -1;
|
2020-04-29 15:10:37 +00:00
|
|
|
if (pnetelem->type == SMC_PNET_ETH) {
|
2019-02-21 12:01:00 +00:00
|
|
|
if (nla_put_string(msg, SMC_PNETID_ETHNAME,
|
2020-04-29 15:10:37 +00:00
|
|
|
pnetelem->eth_name))
|
2019-02-21 12:01:00 +00:00
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
if (nla_put_string(msg, SMC_PNETID_ETHNAME, "n/a"))
|
|
|
|
|
return -1;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
2020-04-29 15:10:37 +00:00
|
|
|
if (pnetelem->type == SMC_PNET_IB) {
|
|
|
|
|
if (nla_put_string(msg, SMC_PNETID_IBNAME, pnetelem->ib_name) ||
|
2019-02-21 12:01:00 +00:00
|
|
|
nla_put_u8(msg, SMC_PNETID_IBPORT, pnetelem->ib_port))
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
if (nla_put_string(msg, SMC_PNETID_IBNAME, "n/a") ||
|
|
|
|
|
nla_put_u8(msg, SMC_PNETID_IBPORT, 0xff))
|
|
|
|
|
return -1;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
return 0;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_add(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
|
{
|
|
|
|
|
struct net *net = genl_info_net(info);
|
2019-02-21 12:01:02 +00:00
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
return smc_pnet_enter(net, info->attrs);
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_del(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
|
{
|
2019-02-21 12:01:02 +00:00
|
|
|
struct net *net = genl_info_net(info);
|
|
|
|
|
|
2018-05-14 00:01:30 +00:00
|
|
|
if (!info->attrs[SMC_PNETID_NAME])
|
|
|
|
|
return -EINVAL;
|
2019-02-21 12:01:02 +00:00
|
|
|
return smc_pnet_remove_by_pnetid(net,
|
2017-01-09 15:55:15 +00:00
|
|
|
(char *)nla_data(info->attrs[SMC_PNETID_NAME]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_dump_start(struct netlink_callback *cb)
|
|
|
|
|
{
|
|
|
|
|
cb->args[0] = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_dumpinfo(struct sk_buff *skb,
|
|
|
|
|
u32 portid, u32 seq, u32 flags,
|
2020-04-29 15:10:37 +00:00
|
|
|
struct smc_pnetentry *pnetelem)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
|
|
hdr = genlmsg_put(skb, portid, seq, &smc_pnet_nl_family,
|
|
|
|
|
flags, SMC_PNETID_GET);
|
|
|
|
|
if (!hdr)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
if (smc_pnet_set_nla(skb, pnetelem) < 0) {
|
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
}
|
|
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
static int _smc_pnet_dump(struct net *net, struct sk_buff *skb, u32 portid,
|
|
|
|
|
u32 seq, u8 *pnetid, int start_idx)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_pnettable *pnettable;
|
2017-01-09 15:55:15 +00:00
|
|
|
struct smc_pnetentry *pnetelem;
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_net *sn;
|
2017-01-09 15:55:15 +00:00
|
|
|
int idx = 0;
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* get pnettable for namespace */
|
|
|
|
|
sn = net_generic(net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* dump pnettable entries */
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2019-02-21 12:01:02 +00:00
|
|
|
list_for_each_entry(pnetelem, &pnettable->pnetlist, list) {
|
2019-02-21 12:01:00 +00:00
|
|
|
if (pnetid && !smc_pnet_match(pnetelem->pnet_name, pnetid))
|
|
|
|
|
continue;
|
|
|
|
|
if (idx++ < start_idx)
|
2017-01-09 15:55:15 +00:00
|
|
|
continue;
|
2020-04-29 15:10:37 +00:00
|
|
|
/* if this is not the initial namespace, dump only netdev */
|
|
|
|
|
if (net != &init_net && pnetelem->type != SMC_PNET_ETH)
|
|
|
|
|
continue;
|
2019-02-21 12:01:00 +00:00
|
|
|
if (smc_pnet_dumpinfo(skb, portid, seq, NLM_F_MULTI,
|
2020-04-29 15:10:37 +00:00
|
|
|
pnetelem)) {
|
2017-01-09 15:55:15 +00:00
|
|
|
--idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2019-02-21 12:01:00 +00:00
|
|
|
return idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
|
{
|
2019-02-21 12:01:02 +00:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2019-02-21 12:01:00 +00:00
|
|
|
int idx;
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
idx = _smc_pnet_dump(net, skb, NETLINK_CB(cb->skb).portid,
|
2019-02-21 12:01:00 +00:00
|
|
|
cb->nlh->nlmsg_seq, NULL, cb->args[0]);
|
|
|
|
|
|
|
|
|
|
cb->args[0] = idx;
|
2017-01-09 15:55:15 +00:00
|
|
|
return skb->len;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:00 +00:00
|
|
|
/* Retrieve one PNETID entry */
|
|
|
|
|
static int smc_pnet_get(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
|
{
|
2019-02-21 12:01:02 +00:00
|
|
|
struct net *net = genl_info_net(info);
|
2019-02-21 12:01:00 +00:00
|
|
|
struct sk_buff *msg;
|
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
|
|
if (!info->attrs[SMC_PNETID_NAME])
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
|
|
|
|
if (!msg)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
_smc_pnet_dump(net, msg, info->snd_portid, info->snd_seq,
|
2019-02-21 12:01:00 +00:00
|
|
|
nla_data(info->attrs[SMC_PNETID_NAME]), 0);
|
|
|
|
|
|
|
|
|
|
/* finish multi part message and send it */
|
|
|
|
|
hdr = nlmsg_put(msg, info->snd_portid, info->snd_seq, NLMSG_DONE, 0,
|
|
|
|
|
NLM_F_MULTI);
|
|
|
|
|
if (!hdr) {
|
|
|
|
|
nlmsg_free(msg);
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
}
|
|
|
|
|
return genlmsg_reply(msg, info);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-09 15:55:15 +00:00
|
|
|
/* Remove and delete all pnetids from pnet table.
|
|
|
|
|
*/
|
|
|
|
|
static int smc_pnet_flush(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
|
{
|
2019-02-21 12:01:02 +00:00
|
|
|
struct net *net = genl_info_net(info);
|
|
|
|
|
|
2019-04-11 09:17:33 +00:00
|
|
|
smc_pnet_remove_by_pnetid(net, NULL);
|
|
|
|
|
return 0;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* SMC_PNETID generic netlink operation definition */
|
|
|
|
|
static const struct genl_ops smc_pnet_ops[] = {
|
|
|
|
|
{
|
|
|
|
|
.cmd = SMC_PNETID_GET,
|
2019-04-26 12:07:31 +00:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2020-01-21 00:04:46 +00:00
|
|
|
/* can be retrieved by unprivileged users */
|
2017-01-09 15:55:15 +00:00
|
|
|
.doit = smc_pnet_get,
|
|
|
|
|
.dumpit = smc_pnet_dump,
|
|
|
|
|
.start = smc_pnet_dump_start
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.cmd = SMC_PNETID_ADD,
|
2019-04-26 12:07:31 +00:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2017-01-09 15:55:15 +00:00
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
|
.doit = smc_pnet_add
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.cmd = SMC_PNETID_DEL,
|
2019-04-26 12:07:31 +00:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2017-01-09 15:55:15 +00:00
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
|
.doit = smc_pnet_del
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.cmd = SMC_PNETID_FLUSH,
|
2019-04-26 12:07:31 +00:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2017-01-09 15:55:15 +00:00
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
|
.doit = smc_pnet_flush
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* SMC_PNETID family definition */
|
2018-09-20 07:27:30 +00:00
|
|
|
static struct genl_family smc_pnet_nl_family __ro_after_init = {
|
2017-01-09 15:55:15 +00:00
|
|
|
.hdrsize = 0,
|
|
|
|
|
.name = SMCR_GENL_FAMILY_NAME,
|
|
|
|
|
.version = SMCR_GENL_FAMILY_VERSION,
|
|
|
|
|
.maxattr = SMC_PNETID_MAX,
|
genetlink: make policy common to family
Since maxattr is common, the policy can't really differ sanely,
so make it common as well.
The only user that did in fact manage to make a non-common policy
is taskstats, which has to be really careful about it (since it's
still using a common maxattr!). This is no longer supported, but
we can fake it using pre_doit.
This reduces the size of e.g. nl80211.o (which has lots of commands):
text data bss dec hex filename
398745 14323 2240 415308 6564c net/wireless/nl80211.o (before)
397913 14331 2240 414484 65314 net/wireless/nl80211.o (after)
--------------------------------
-832 +8 0 -824
Which is obviously just 8 bytes for each command, and an added 8
bytes for the new policy pointer. I'm not sure why the ops list is
counted as .text though.
Most of the code transformations were done using the following spatch:
@ops@
identifier OPS;
expression POLICY;
@@
struct genl_ops OPS[] = {
...,
{
- .policy = POLICY,
},
...
};
@@
identifier ops.OPS;
expression ops.POLICY;
identifier fam;
expression M;
@@
struct genl_family fam = {
.ops = OPS,
.maxattr = M,
+ .policy = POLICY,
...
};
This also gets rid of devlink_nl_cmd_region_read_dumpit() accessing
the cb->data as ops, which we want to change in a later genl patch.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-03-21 21:51:02 +00:00
|
|
|
.policy = smc_pnet_policy,
|
2017-01-09 15:55:15 +00:00
|
|
|
.netnsok = true,
|
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
|
.ops = smc_pnet_ops,
|
2022-08-25 00:18:30 +00:00
|
|
|
.n_ops = ARRAY_SIZE(smc_pnet_ops),
|
|
|
|
|
.resv_start_op = SMC_PNETID_FLUSH + 1,
|
2017-01-09 15:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
2020-09-26 10:44:26 +00:00
|
|
|
bool smc_pnet_is_ndev_pnetid(struct net *net, u8 *pnetid)
|
|
|
|
|
{
|
|
|
|
|
struct smc_net *sn = net_generic(net, smc_net_id);
|
|
|
|
|
struct smc_pnetids_ndev_entry *pe;
|
|
|
|
|
bool rc = false;
|
|
|
|
|
|
|
|
|
|
read_lock(&sn->pnetids_ndev.lock);
|
|
|
|
|
list_for_each_entry(pe, &sn->pnetids_ndev.list, list) {
|
|
|
|
|
if (smc_pnet_match(pnetid, pe->pnetid)) {
|
|
|
|
|
rc = true;
|
|
|
|
|
goto unlock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
|
read_unlock(&sn->pnetids_ndev.lock);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int smc_pnet_add_pnetid(struct net *net, u8 *pnetid)
|
|
|
|
|
{
|
|
|
|
|
struct smc_net *sn = net_generic(net, smc_net_id);
|
|
|
|
|
struct smc_pnetids_ndev_entry *pe, *pi;
|
|
|
|
|
|
|
|
|
|
pe = kzalloc(sizeof(*pe), GFP_KERNEL);
|
|
|
|
|
if (!pe)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
write_lock(&sn->pnetids_ndev.lock);
|
|
|
|
|
list_for_each_entry(pi, &sn->pnetids_ndev.list, list) {
|
2024-10-14 11:53:21 +00:00
|
|
|
if (smc_pnet_match(pnetid, pi->pnetid)) {
|
2020-09-26 10:44:26 +00:00
|
|
|
refcount_inc(&pi->refcnt);
|
|
|
|
|
kfree(pe);
|
|
|
|
|
goto unlock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
refcount_set(&pe->refcnt, 1);
|
|
|
|
|
memcpy(pe->pnetid, pnetid, SMC_MAX_PNETID_LEN);
|
|
|
|
|
list_add_tail(&pe->list, &sn->pnetids_ndev.list);
|
|
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
|
write_unlock(&sn->pnetids_ndev.lock);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void smc_pnet_remove_pnetid(struct net *net, u8 *pnetid)
|
|
|
|
|
{
|
|
|
|
|
struct smc_net *sn = net_generic(net, smc_net_id);
|
|
|
|
|
struct smc_pnetids_ndev_entry *pe, *pe2;
|
|
|
|
|
|
|
|
|
|
write_lock(&sn->pnetids_ndev.lock);
|
|
|
|
|
list_for_each_entry_safe(pe, pe2, &sn->pnetids_ndev.list, list) {
|
|
|
|
|
if (smc_pnet_match(pnetid, pe->pnetid)) {
|
|
|
|
|
if (refcount_dec_and_test(&pe->refcnt)) {
|
|
|
|
|
list_del(&pe->list);
|
|
|
|
|
kfree(pe);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
write_unlock(&sn->pnetids_ndev.lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void smc_pnet_add_base_pnetid(struct net *net, struct net_device *dev,
|
|
|
|
|
u8 *ndev_pnetid)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *base_dev;
|
|
|
|
|
|
|
|
|
|
base_dev = __pnet_find_base_ndev(dev);
|
|
|
|
|
if (base_dev->flags & IFF_UP &&
|
|
|
|
|
!smc_pnetid_by_dev_port(base_dev->dev.parent, base_dev->dev_port,
|
|
|
|
|
ndev_pnetid)) {
|
|
|
|
|
/* add to PNETIDs list */
|
|
|
|
|
smc_pnet_add_pnetid(net, ndev_pnetid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create initial list of netdevice pnetids */
|
|
|
|
|
static void smc_pnet_create_pnetids_list(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
|
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
net/smc: reduce rtnl pressure in smc_pnet_create_pnetids_list()
Many syzbot reports show extreme rtnl pressure, and many of them hint
that smc acquires rtnl in netns creation for no good reason [1]
This patch returns early from smc_pnet_net_init()
if there is no netdevice yet.
I am not even sure why smc_pnet_create_pnetids_list() even exists,
because smc_pnet_netdev_event() is also calling
smc_pnet_add_base_pnetid() when handling NETDEV_UP event.
[1] extract of typical syzbot reports
2 locks held by syz-executor.3/12252:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.4/12253:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.1/12257:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.2/12261:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.0/12265:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.3/12268:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.4/12271:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.1/12274:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
2 locks held by syz-executor.2/12280:
#0: ffffffff8f369610 (pernet_ops_rwsem){++++}-{3:3}, at: copy_net_ns+0x4c7/0x7b0 net/core/net_namespace.c:491
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_create_pnetids_list net/smc/smc_pnet.c:809 [inline]
#1: ffffffff8f375b88 (rtnl_mutex){+.+.}-{3:3}, at: smc_pnet_net_init+0x10a/0x1e0 net/smc/smc_pnet.c:878
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Wenjia Zhang <wenjia@linux.ibm.com>
Cc: Jan Karcher <jaka@linux.ibm.com>
Cc: "D. Wythe" <alibuda@linux.alibaba.com>
Cc: Tony Lu <tonylu@linux.alibaba.com>
Cc: Wen Gu <guwen@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Link: https://lore.kernel.org/r/20240302100744.3868021-1-edumazet@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2024-03-02 10:07:44 +00:00
|
|
|
/* Newly created netns do not have devices.
|
|
|
|
|
* Do not even acquire rtnl.
|
|
|
|
|
*/
|
|
|
|
|
if (list_empty(&net->dev_base_head))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Note: This might not be needed, because smc_pnet_netdev_event()
|
|
|
|
|
* is also calling smc_pnet_add_base_pnetid() when handling
|
|
|
|
|
* NETDEV_UP event.
|
|
|
|
|
*/
|
2020-09-26 10:44:26 +00:00
|
|
|
rtnl_lock();
|
|
|
|
|
for_each_netdev(net, dev)
|
|
|
|
|
smc_pnet_add_base_pnetid(net, dev, ndev_pnetid);
|
|
|
|
|
rtnl_unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* clean up list of netdevice pnetids */
|
|
|
|
|
static void smc_pnet_destroy_pnetids_list(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
struct smc_net *sn = net_generic(net, smc_net_id);
|
|
|
|
|
struct smc_pnetids_ndev_entry *pe, *temp_pe;
|
|
|
|
|
|
|
|
|
|
write_lock(&sn->pnetids_ndev.lock);
|
|
|
|
|
list_for_each_entry_safe(pe, temp_pe, &sn->pnetids_ndev.list, list) {
|
|
|
|
|
list_del(&pe->list);
|
|
|
|
|
kfree(pe);
|
|
|
|
|
}
|
|
|
|
|
write_unlock(&sn->pnetids_ndev.lock);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-09 15:55:15 +00:00
|
|
|
static int smc_pnet_netdev_event(struct notifier_block *this,
|
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
|
2020-09-26 10:44:26 +00:00
|
|
|
struct net *net = dev_net(event_dev);
|
|
|
|
|
u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
|
2017-01-09 15:55:15 +00:00
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
case NETDEV_REBOOT:
|
|
|
|
|
case NETDEV_UNREGISTER:
|
|
|
|
|
smc_pnet_remove_by_ndev(event_dev);
|
2020-12-01 19:20:40 +00:00
|
|
|
smc_ib_ndev_change(event_dev, event);
|
2018-06-28 17:05:04 +00:00
|
|
|
return NOTIFY_OK;
|
2020-04-29 15:10:37 +00:00
|
|
|
case NETDEV_REGISTER:
|
|
|
|
|
smc_pnet_add_by_ndev(event_dev);
|
2020-12-01 19:20:40 +00:00
|
|
|
smc_ib_ndev_change(event_dev, event);
|
2020-04-29 15:10:37 +00:00
|
|
|
return NOTIFY_OK;
|
2020-09-26 10:44:26 +00:00
|
|
|
case NETDEV_UP:
|
|
|
|
|
smc_pnet_add_base_pnetid(net, event_dev, ndev_pnetid);
|
|
|
|
|
return NOTIFY_OK;
|
|
|
|
|
case NETDEV_DOWN:
|
|
|
|
|
event_dev = __pnet_find_base_ndev(event_dev);
|
|
|
|
|
if (!smc_pnetid_by_dev_port(event_dev->dev.parent,
|
|
|
|
|
event_dev->dev_port, ndev_pnetid)) {
|
|
|
|
|
/* remove from PNETIDs list */
|
|
|
|
|
smc_pnet_remove_pnetid(net, ndev_pnetid);
|
|
|
|
|
}
|
|
|
|
|
return NOTIFY_OK;
|
2017-01-09 15:55:15 +00:00
|
|
|
default:
|
2018-06-28 17:05:04 +00:00
|
|
|
return NOTIFY_DONE;
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct notifier_block smc_netdev_notifier = {
|
|
|
|
|
.notifier_call = smc_pnet_netdev_event
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* init network namespace */
|
|
|
|
|
int smc_pnet_net_init(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
struct smc_net *sn = net_generic(net, smc_net_id);
|
|
|
|
|
struct smc_pnettable *pnettable = &sn->pnettable;
|
2020-09-26 10:44:26 +00:00
|
|
|
struct smc_pnetids_ndev *pnetids_ndev = &sn->pnetids_ndev;
|
2019-02-21 12:01:02 +00:00
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&pnettable->pnetlist);
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_init(&pnettable->lock);
|
2020-09-26 10:44:26 +00:00
|
|
|
INIT_LIST_HEAD(&pnetids_ndev->list);
|
|
|
|
|
rwlock_init(&pnetids_ndev->lock);
|
|
|
|
|
|
|
|
|
|
smc_pnet_create_pnetids_list(net);
|
2019-02-21 12:01:02 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-09 15:55:15 +00:00
|
|
|
int __init smc_pnet_init(void)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
rc = genl_register_family(&smc_pnet_nl_family);
|
|
|
|
|
if (rc)
|
|
|
|
|
return rc;
|
|
|
|
|
rc = register_netdevice_notifier(&smc_netdev_notifier);
|
|
|
|
|
if (rc)
|
|
|
|
|
genl_unregister_family(&smc_pnet_nl_family);
|
2020-09-26 10:44:26 +00:00
|
|
|
|
2017-01-09 15:55:15 +00:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* exit network namespace */
|
|
|
|
|
void smc_pnet_net_exit(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
/* flush pnet table */
|
|
|
|
|
smc_pnet_remove_by_pnetid(net, NULL);
|
2020-09-26 10:44:26 +00:00
|
|
|
smc_pnet_destroy_pnetids_list(net);
|
2019-02-21 12:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-09 15:55:15 +00:00
|
|
|
void smc_pnet_exit(void)
|
|
|
|
|
{
|
|
|
|
|
unregister_netdevice_notifier(&smc_netdev_notifier);
|
|
|
|
|
genl_unregister_family(&smc_pnet_nl_family);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-26 10:44:26 +00:00
|
|
|
static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)
|
2017-01-09 15:55:15 +00:00
|
|
|
{
|
2018-06-28 17:05:05 +00:00
|
|
|
int i, nest_lvl;
|
2017-01-09 15:55:15 +00:00
|
|
|
|
2020-09-26 10:44:26 +00:00
|
|
|
ASSERT_RTNL();
|
2019-10-21 18:47:58 +00:00
|
|
|
nest_lvl = ndev->lower_level;
|
2018-06-28 17:05:05 +00:00
|
|
|
for (i = 0; i < nest_lvl; i++) {
|
|
|
|
|
struct list_head *lower = &ndev->adj_list.lower;
|
|
|
|
|
|
|
|
|
|
if (list_empty(lower))
|
|
|
|
|
break;
|
|
|
|
|
lower = lower->next;
|
|
|
|
|
ndev = netdev_lower_get_next(ndev, &lower);
|
|
|
|
|
}
|
2020-09-26 10:44:26 +00:00
|
|
|
return ndev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Determine one base device for stacked net devices.
|
|
|
|
|
* If the lower device level contains more than one devices
|
|
|
|
|
* (for instance with bonding slaves), just the first device
|
|
|
|
|
* is used to reach a base device.
|
|
|
|
|
*/
|
|
|
|
|
static struct net_device *pnet_find_base_ndev(struct net_device *ndev)
|
|
|
|
|
{
|
|
|
|
|
rtnl_lock();
|
|
|
|
|
ndev = __pnet_find_base_ndev(ndev);
|
2018-06-28 17:05:05 +00:00
|
|
|
rtnl_unlock();
|
|
|
|
|
return ndev;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
static int smc_pnet_find_ndev_pnetid_by_table(struct net_device *ndev,
|
2019-02-21 12:01:00 +00:00
|
|
|
u8 *pnetid)
|
|
|
|
|
{
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_pnettable *pnettable;
|
|
|
|
|
struct net *net = dev_net(ndev);
|
2019-02-21 12:01:00 +00:00
|
|
|
struct smc_pnetentry *pnetelem;
|
2019-02-21 12:01:02 +00:00
|
|
|
struct smc_net *sn;
|
2019-02-21 12:01:00 +00:00
|
|
|
int rc = -ENOENT;
|
|
|
|
|
|
2019-02-21 12:01:02 +00:00
|
|
|
/* get pnettable for namespace */
|
|
|
|
|
sn = net_generic(net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
|
|
|
|
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2019-02-21 12:01:02 +00:00
|
|
|
list_for_each_entry(pnetelem, &pnettable->pnetlist, list) {
|
2020-04-29 15:10:37 +00:00
|
|
|
if (pnetelem->type == SMC_PNET_ETH && ndev == pnetelem->ndev) {
|
2019-02-21 12:01:00 +00:00
|
|
|
/* get pnetid of netdev device */
|
|
|
|
|
memcpy(pnetid, pnetelem->pnet_name, SMC_MAX_PNETID_LEN);
|
|
|
|
|
rc = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2019-02-21 12:01:00 +00:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-16 09:37:48 +00:00
|
|
|
static int smc_pnet_determine_gid(struct smc_ib_device *ibdev, int i,
|
|
|
|
|
struct smc_init_info *ini)
|
|
|
|
|
{
|
|
|
|
|
if (!ini->check_smcrv2 &&
|
|
|
|
|
!smc_ib_determine_gid(ibdev, i, ini->vlan_id, ini->ib_gid, NULL,
|
|
|
|
|
NULL)) {
|
|
|
|
|
ini->ib_dev = ibdev;
|
|
|
|
|
ini->ib_port = i;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (ini->check_smcrv2 &&
|
|
|
|
|
!smc_ib_determine_gid(ibdev, i, ini->vlan_id, ini->smcrv2.ib_gid_v2,
|
|
|
|
|
NULL, &ini->smcrv2)) {
|
|
|
|
|
ini->smcrv2.ib_dev_v2 = ibdev;
|
|
|
|
|
ini->smcrv2.ib_port_v2 = i;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:10:37 +00:00
|
|
|
/* find a roce device for the given pnetid */
|
|
|
|
|
static void _smc_pnet_find_roce_by_pnetid(u8 *pnet_id,
|
2020-05-01 10:48:11 +00:00
|
|
|
struct smc_init_info *ini,
|
2021-12-28 13:06:09 +00:00
|
|
|
struct smc_ib_device *known_dev,
|
|
|
|
|
struct net *net)
|
2020-04-29 15:10:37 +00:00
|
|
|
{
|
|
|
|
|
struct smc_ib_device *ibdev;
|
|
|
|
|
int i;
|
|
|
|
|
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2020-04-29 15:10:37 +00:00
|
|
|
list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
|
2021-12-28 13:06:09 +00:00
|
|
|
if (ibdev == known_dev ||
|
|
|
|
|
!rdma_dev_access_netns(ibdev->ibdev, net))
|
2020-05-01 10:48:11 +00:00
|
|
|
continue;
|
2020-04-29 15:10:37 +00:00
|
|
|
for (i = 1; i <= SMC_MAX_PORTS; i++) {
|
|
|
|
|
if (!rdma_is_port_valid(ibdev->ibdev, i))
|
|
|
|
|
continue;
|
|
|
|
|
if (smc_pnet_match(ibdev->pnetid[i - 1], pnet_id) &&
|
|
|
|
|
smc_ib_port_active(ibdev, i) &&
|
2021-10-16 09:37:48 +00:00
|
|
|
!test_bit(i - 1, ibdev->ports_going_away)) {
|
|
|
|
|
if (!smc_pnet_determine_gid(ibdev, i, ini))
|
|
|
|
|
goto out;
|
2020-04-29 15:10:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
out:
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2020-04-29 15:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-28 13:06:09 +00:00
|
|
|
/* find alternate roce device with same pnet_id, vlan_id and net namespace */
|
2020-05-01 10:48:11 +00:00
|
|
|
void smc_pnet_find_alt_roce(struct smc_link_group *lgr,
|
|
|
|
|
struct smc_init_info *ini,
|
|
|
|
|
struct smc_ib_device *known_dev)
|
|
|
|
|
{
|
2021-12-28 13:06:09 +00:00
|
|
|
struct net *net = lgr->net;
|
|
|
|
|
|
|
|
|
|
_smc_pnet_find_roce_by_pnetid(lgr->pnet_id, ini, known_dev, net);
|
2020-05-01 10:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-28 14:10:08 +00:00
|
|
|
/* if handshake network device belongs to a roce device, return its
|
|
|
|
|
* IB device and port
|
|
|
|
|
*/
|
|
|
|
|
static void smc_pnet_find_rdma_dev(struct net_device *netdev,
|
2019-04-12 10:57:26 +00:00
|
|
|
struct smc_init_info *ini)
|
2019-02-28 14:10:08 +00:00
|
|
|
{
|
2021-12-28 13:06:09 +00:00
|
|
|
struct net *net = dev_net(netdev);
|
2019-02-28 14:10:08 +00:00
|
|
|
struct smc_ib_device *ibdev;
|
|
|
|
|
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2019-02-28 14:10:08 +00:00
|
|
|
list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
|
|
|
|
|
struct net_device *ndev;
|
|
|
|
|
int i;
|
|
|
|
|
|
2021-12-28 13:06:09 +00:00
|
|
|
/* check rdma net namespace */
|
|
|
|
|
if (!rdma_dev_access_netns(ibdev->ibdev, net))
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-02-28 14:10:08 +00:00
|
|
|
for (i = 1; i <= SMC_MAX_PORTS; i++) {
|
|
|
|
|
if (!rdma_is_port_valid(ibdev->ibdev, i))
|
|
|
|
|
continue;
|
2024-11-06 08:26:12 +00:00
|
|
|
ndev = ib_device_get_netdev(ibdev->ibdev, i);
|
2019-02-28 14:10:08 +00:00
|
|
|
if (!ndev)
|
|
|
|
|
continue;
|
|
|
|
|
dev_put(ndev);
|
|
|
|
|
if (netdev == ndev &&
|
|
|
|
|
smc_ib_port_active(ibdev, i) &&
|
2021-10-16 09:37:48 +00:00
|
|
|
!test_bit(i - 1, ibdev->ports_going_away)) {
|
|
|
|
|
if (!smc_pnet_determine_gid(ibdev, i, ini))
|
|
|
|
|
break;
|
2019-02-28 14:10:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-08 15:05:13 +00:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2019-02-28 14:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 17:05:05 +00:00
|
|
|
/* Determine the corresponding IB device port based on the hardware PNETID.
|
2018-07-25 14:35:31 +00:00
|
|
|
* Searching stops at the first matching active IB device port with vlan_id
|
|
|
|
|
* configured.
|
2019-02-28 14:10:08 +00:00
|
|
|
* If nothing found, check pnetid table.
|
|
|
|
|
* If nothing found, try to use handshake device
|
2018-06-28 17:05:05 +00:00
|
|
|
*/
|
|
|
|
|
static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev,
|
2019-04-12 10:57:26 +00:00
|
|
|
struct smc_init_info *ini)
|
2018-06-28 17:05:05 +00:00
|
|
|
{
|
|
|
|
|
u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
|
net/smc: use the correct ndev to find pnetid by pnetid table
When using smc_pnet in SMC, it will only search the pnetid in the
base_ndev of the netdev hierarchy(both HW PNETID and User-defined
sw pnetid). This may not work for some scenarios when using SMC in
container on cloud environment.
In container, there have choices of different container network,
such as directly using host network, virtual network IPVLAN, veth,
etc. Different choices of container network have different netdev
hierarchy. Examples of netdev hierarchy show below. (eth0 and eth1
in host below is the netdev directly related to the physical device).
_______________________________
| _________________ |
| |POD | |
| | | |
| | eth0_________ | |
| |____| |__| |
| | | |
| | | |
| eth1|base_ndev| eth0_______ |
| | | | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if directly using host network
________________________________
| _________________ |
| |POD __________ | |
| | |upper_ndev| | |
| |eth0|__________| | |
| |_______|_________| |
| |lower netdev |
| __|______ |
| eth1| | eth0_______ |
| |base_ndev| | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if using IPVLAN
_______________________________
| _____________________ |
| |POD _________ | |
| | |base_ndev|| |
| |eth0(veth)|_________|| |
| |____________|________| |
| |pairs |
| _______|_ |
| | | eth0_______ |
| veth|base_ndev| | RDMA ||
| |_________| |_______||
| _________ |
| eth1|base_ndev| |
| host |_________| |
---------------------------------
netdev hierarchy if using veth
Due to some reasons, the eth1 in host is not RDMA attached netdevice,
pnetid is needed to map the eth1(in host) with RDMA device so that POD
can do SMC-R. Because the eth1(in host) is managed by CNI plugin(such
as Terway, network management plugin in container environment), and in
cloud environment the eth(in host) can dynamically be inserted by CNI
when POD create and dynamically be removed by CNI when POD destroy and
no POD related to the eth(in host) anymore. It is hard to config the
pnetid to the eth1(in host). But it is easy to config the pnetid to the
netdevice which can be seen in POD. When do SMC-R, both the container
directly using host network and the container using veth network can
successfully match the RDMA device, because the configured pnetid netdev
is a base_ndev. But the container using IPVLAN can not successfully
match the RDMA device and 0x03030000 fallback happens, because the
configured pnetid netdev is not a base_ndev. Additionally, if config
pnetid to the eth1(in host) also can not work for matching RDMA device
when using veth network and doing SMC-R in POD.
To resolve the problems list above, this patch extends to search user
-defined sw pnetid in the clc handshake ndev when no pnetid can be found
in the base_ndev, and the base_ndev take precedence over ndev for backward
compatibility. This patch also can unify the pnetid setup of different
network choices list above in container(Config user-defined sw pnetid in
the netdevice can be seen in POD).
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2025-03-04 12:43:04 +00:00
|
|
|
struct net_device *base_ndev;
|
2021-12-28 13:06:09 +00:00
|
|
|
struct net *net;
|
2018-06-28 17:05:05 +00:00
|
|
|
|
net/smc: use the correct ndev to find pnetid by pnetid table
When using smc_pnet in SMC, it will only search the pnetid in the
base_ndev of the netdev hierarchy(both HW PNETID and User-defined
sw pnetid). This may not work for some scenarios when using SMC in
container on cloud environment.
In container, there have choices of different container network,
such as directly using host network, virtual network IPVLAN, veth,
etc. Different choices of container network have different netdev
hierarchy. Examples of netdev hierarchy show below. (eth0 and eth1
in host below is the netdev directly related to the physical device).
_______________________________
| _________________ |
| |POD | |
| | | |
| | eth0_________ | |
| |____| |__| |
| | | |
| | | |
| eth1|base_ndev| eth0_______ |
| | | | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if directly using host network
________________________________
| _________________ |
| |POD __________ | |
| | |upper_ndev| | |
| |eth0|__________| | |
| |_______|_________| |
| |lower netdev |
| __|______ |
| eth1| | eth0_______ |
| |base_ndev| | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if using IPVLAN
_______________________________
| _____________________ |
| |POD _________ | |
| | |base_ndev|| |
| |eth0(veth)|_________|| |
| |____________|________| |
| |pairs |
| _______|_ |
| | | eth0_______ |
| veth|base_ndev| | RDMA ||
| |_________| |_______||
| _________ |
| eth1|base_ndev| |
| host |_________| |
---------------------------------
netdev hierarchy if using veth
Due to some reasons, the eth1 in host is not RDMA attached netdevice,
pnetid is needed to map the eth1(in host) with RDMA device so that POD
can do SMC-R. Because the eth1(in host) is managed by CNI plugin(such
as Terway, network management plugin in container environment), and in
cloud environment the eth(in host) can dynamically be inserted by CNI
when POD create and dynamically be removed by CNI when POD destroy and
no POD related to the eth(in host) anymore. It is hard to config the
pnetid to the eth1(in host). But it is easy to config the pnetid to the
netdevice which can be seen in POD. When do SMC-R, both the container
directly using host network and the container using veth network can
successfully match the RDMA device, because the configured pnetid netdev
is a base_ndev. But the container using IPVLAN can not successfully
match the RDMA device and 0x03030000 fallback happens, because the
configured pnetid netdev is not a base_ndev. Additionally, if config
pnetid to the eth1(in host) also can not work for matching RDMA device
when using veth network and doing SMC-R in POD.
To resolve the problems list above, this patch extends to search user
-defined sw pnetid in the clc handshake ndev when no pnetid can be found
in the base_ndev, and the base_ndev take precedence over ndev for backward
compatibility. This patch also can unify the pnetid setup of different
network choices list above in container(Config user-defined sw pnetid in
the netdevice can be seen in POD).
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2025-03-04 12:43:04 +00:00
|
|
|
base_ndev = pnet_find_base_ndev(ndev);
|
2021-12-28 13:06:09 +00:00
|
|
|
net = dev_net(ndev);
|
net/smc: use the correct ndev to find pnetid by pnetid table
When using smc_pnet in SMC, it will only search the pnetid in the
base_ndev of the netdev hierarchy(both HW PNETID and User-defined
sw pnetid). This may not work for some scenarios when using SMC in
container on cloud environment.
In container, there have choices of different container network,
such as directly using host network, virtual network IPVLAN, veth,
etc. Different choices of container network have different netdev
hierarchy. Examples of netdev hierarchy show below. (eth0 and eth1
in host below is the netdev directly related to the physical device).
_______________________________
| _________________ |
| |POD | |
| | | |
| | eth0_________ | |
| |____| |__| |
| | | |
| | | |
| eth1|base_ndev| eth0_______ |
| | | | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if directly using host network
________________________________
| _________________ |
| |POD __________ | |
| | |upper_ndev| | |
| |eth0|__________| | |
| |_______|_________| |
| |lower netdev |
| __|______ |
| eth1| | eth0_______ |
| |base_ndev| | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if using IPVLAN
_______________________________
| _____________________ |
| |POD _________ | |
| | |base_ndev|| |
| |eth0(veth)|_________|| |
| |____________|________| |
| |pairs |
| _______|_ |
| | | eth0_______ |
| veth|base_ndev| | RDMA ||
| |_________| |_______||
| _________ |
| eth1|base_ndev| |
| host |_________| |
---------------------------------
netdev hierarchy if using veth
Due to some reasons, the eth1 in host is not RDMA attached netdevice,
pnetid is needed to map the eth1(in host) with RDMA device so that POD
can do SMC-R. Because the eth1(in host) is managed by CNI plugin(such
as Terway, network management plugin in container environment), and in
cloud environment the eth(in host) can dynamically be inserted by CNI
when POD create and dynamically be removed by CNI when POD destroy and
no POD related to the eth(in host) anymore. It is hard to config the
pnetid to the eth1(in host). But it is easy to config the pnetid to the
netdevice which can be seen in POD. When do SMC-R, both the container
directly using host network and the container using veth network can
successfully match the RDMA device, because the configured pnetid netdev
is a base_ndev. But the container using IPVLAN can not successfully
match the RDMA device and 0x03030000 fallback happens, because the
configured pnetid netdev is not a base_ndev. Additionally, if config
pnetid to the eth1(in host) also can not work for matching RDMA device
when using veth network and doing SMC-R in POD.
To resolve the problems list above, this patch extends to search user
-defined sw pnetid in the clc handshake ndev when no pnetid can be found
in the base_ndev, and the base_ndev take precedence over ndev for backward
compatibility. This patch also can unify the pnetid setup of different
network choices list above in container(Config user-defined sw pnetid in
the netdevice can be seen in POD).
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2025-03-04 12:43:04 +00:00
|
|
|
if (smc_pnetid_by_dev_port(base_ndev->dev.parent, base_ndev->dev_port,
|
2019-02-21 12:01:00 +00:00
|
|
|
ndev_pnetid) &&
|
net/smc: use the correct ndev to find pnetid by pnetid table
When using smc_pnet in SMC, it will only search the pnetid in the
base_ndev of the netdev hierarchy(both HW PNETID and User-defined
sw pnetid). This may not work for some scenarios when using SMC in
container on cloud environment.
In container, there have choices of different container network,
such as directly using host network, virtual network IPVLAN, veth,
etc. Different choices of container network have different netdev
hierarchy. Examples of netdev hierarchy show below. (eth0 and eth1
in host below is the netdev directly related to the physical device).
_______________________________
| _________________ |
| |POD | |
| | | |
| | eth0_________ | |
| |____| |__| |
| | | |
| | | |
| eth1|base_ndev| eth0_______ |
| | | | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if directly using host network
________________________________
| _________________ |
| |POD __________ | |
| | |upper_ndev| | |
| |eth0|__________| | |
| |_______|_________| |
| |lower netdev |
| __|______ |
| eth1| | eth0_______ |
| |base_ndev| | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if using IPVLAN
_______________________________
| _____________________ |
| |POD _________ | |
| | |base_ndev|| |
| |eth0(veth)|_________|| |
| |____________|________| |
| |pairs |
| _______|_ |
| | | eth0_______ |
| veth|base_ndev| | RDMA ||
| |_________| |_______||
| _________ |
| eth1|base_ndev| |
| host |_________| |
---------------------------------
netdev hierarchy if using veth
Due to some reasons, the eth1 in host is not RDMA attached netdevice,
pnetid is needed to map the eth1(in host) with RDMA device so that POD
can do SMC-R. Because the eth1(in host) is managed by CNI plugin(such
as Terway, network management plugin in container environment), and in
cloud environment the eth(in host) can dynamically be inserted by CNI
when POD create and dynamically be removed by CNI when POD destroy and
no POD related to the eth(in host) anymore. It is hard to config the
pnetid to the eth1(in host). But it is easy to config the pnetid to the
netdevice which can be seen in POD. When do SMC-R, both the container
directly using host network and the container using veth network can
successfully match the RDMA device, because the configured pnetid netdev
is a base_ndev. But the container using IPVLAN can not successfully
match the RDMA device and 0x03030000 fallback happens, because the
configured pnetid netdev is not a base_ndev. Additionally, if config
pnetid to the eth1(in host) also can not work for matching RDMA device
when using veth network and doing SMC-R in POD.
To resolve the problems list above, this patch extends to search user
-defined sw pnetid in the clc handshake ndev when no pnetid can be found
in the base_ndev, and the base_ndev take precedence over ndev for backward
compatibility. This patch also can unify the pnetid setup of different
network choices list above in container(Config user-defined sw pnetid in
the netdevice can be seen in POD).
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2025-03-04 12:43:04 +00:00
|
|
|
smc_pnet_find_ndev_pnetid_by_table(base_ndev, ndev_pnetid) &&
|
2019-02-28 14:10:08 +00:00
|
|
|
smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) {
|
net/smc: use the correct ndev to find pnetid by pnetid table
When using smc_pnet in SMC, it will only search the pnetid in the
base_ndev of the netdev hierarchy(both HW PNETID and User-defined
sw pnetid). This may not work for some scenarios when using SMC in
container on cloud environment.
In container, there have choices of different container network,
such as directly using host network, virtual network IPVLAN, veth,
etc. Different choices of container network have different netdev
hierarchy. Examples of netdev hierarchy show below. (eth0 and eth1
in host below is the netdev directly related to the physical device).
_______________________________
| _________________ |
| |POD | |
| | | |
| | eth0_________ | |
| |____| |__| |
| | | |
| | | |
| eth1|base_ndev| eth0_______ |
| | | | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if directly using host network
________________________________
| _________________ |
| |POD __________ | |
| | |upper_ndev| | |
| |eth0|__________| | |
| |_______|_________| |
| |lower netdev |
| __|______ |
| eth1| | eth0_______ |
| |base_ndev| | RDMA ||
| host |_________| |_______||
---------------------------------
netdev hierarchy if using IPVLAN
_______________________________
| _____________________ |
| |POD _________ | |
| | |base_ndev|| |
| |eth0(veth)|_________|| |
| |____________|________| |
| |pairs |
| _______|_ |
| | | eth0_______ |
| veth|base_ndev| | RDMA ||
| |_________| |_______||
| _________ |
| eth1|base_ndev| |
| host |_________| |
---------------------------------
netdev hierarchy if using veth
Due to some reasons, the eth1 in host is not RDMA attached netdevice,
pnetid is needed to map the eth1(in host) with RDMA device so that POD
can do SMC-R. Because the eth1(in host) is managed by CNI plugin(such
as Terway, network management plugin in container environment), and in
cloud environment the eth(in host) can dynamically be inserted by CNI
when POD create and dynamically be removed by CNI when POD destroy and
no POD related to the eth(in host) anymore. It is hard to config the
pnetid to the eth1(in host). But it is easy to config the pnetid to the
netdevice which can be seen in POD. When do SMC-R, both the container
directly using host network and the container using veth network can
successfully match the RDMA device, because the configured pnetid netdev
is a base_ndev. But the container using IPVLAN can not successfully
match the RDMA device and 0x03030000 fallback happens, because the
configured pnetid netdev is not a base_ndev. Additionally, if config
pnetid to the eth1(in host) also can not work for matching RDMA device
when using veth network and doing SMC-R in POD.
To resolve the problems list above, this patch extends to search user
-defined sw pnetid in the clc handshake ndev when no pnetid can be found
in the base_ndev, and the base_ndev take precedence over ndev for backward
compatibility. This patch also can unify the pnetid setup of different
network choices list above in container(Config user-defined sw pnetid in
the netdevice can be seen in POD).
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2025-03-04 12:43:04 +00:00
|
|
|
smc_pnet_find_rdma_dev(base_ndev, ini);
|
2018-06-28 17:05:05 +00:00
|
|
|
return; /* pnetid could not be determined */
|
2019-02-28 14:10:08 +00:00
|
|
|
}
|
2021-12-28 13:06:09 +00:00
|
|
|
_smc_pnet_find_roce_by_pnetid(ndev_pnetid, ini, NULL, net);
|
2018-06-28 17:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 17:05:08 +00:00
|
|
|
static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
|
2019-04-12 10:57:26 +00:00
|
|
|
struct smc_init_info *ini)
|
2018-06-28 17:05:08 +00:00
|
|
|
{
|
|
|
|
|
u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
|
|
|
|
|
struct smcd_dev *ismdev;
|
|
|
|
|
|
|
|
|
|
ndev = pnet_find_base_ndev(ndev);
|
|
|
|
|
if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port,
|
2019-02-21 12:01:01 +00:00
|
|
|
ndev_pnetid) &&
|
|
|
|
|
smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid))
|
2018-06-28 17:05:08 +00:00
|
|
|
return; /* pnetid could not be determined */
|
|
|
|
|
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_lock(&smcd_dev_list.mutex);
|
2018-06-28 17:05:08 +00:00
|
|
|
list_for_each_entry(ismdev, &smcd_dev_list.list, list) {
|
2019-10-09 08:07:46 +00:00
|
|
|
if (smc_pnet_match(ismdev->pnetid, ndev_pnetid) &&
|
2020-09-10 16:48:24 +00:00
|
|
|
!ismdev->going_away &&
|
2023-12-19 14:26:13 +00:00
|
|
|
(!ini->ism_peer_gid[0].gid ||
|
|
|
|
|
!smc_ism_cantalk(&ini->ism_peer_gid[0], ini->vlan_id,
|
2020-09-10 16:48:24 +00:00
|
|
|
ismdev))) {
|
2020-09-26 10:44:23 +00:00
|
|
|
ini->ism_dev[0] = ismdev;
|
2018-06-28 17:05:08 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-08 15:05:14 +00:00
|
|
|
mutex_unlock(&smcd_dev_list.mutex);
|
2018-06-28 17:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 17:05:05 +00:00
|
|
|
/* PNET table analysis for a given sock:
|
|
|
|
|
* determine ib_device and port belonging to used internal TCP socket
|
|
|
|
|
* ethernet interface.
|
|
|
|
|
*/
|
2019-04-12 10:57:26 +00:00
|
|
|
void smc_pnet_find_roce_resource(struct sock *sk, struct smc_init_info *ini)
|
2018-06-28 17:05:05 +00:00
|
|
|
{
|
smc: Fix use-after-free in __pnet_find_base_ndev().
syzbot reported use-after-free of net_device in __pnet_find_base_ndev(),
which was called during connect(). [0]
smc_pnet_find_ism_resource() fetches sk_dst_get(sk)->dev and passes
down to pnet_find_base_ndev(), where RTNL is held. Then, UAF happened
at __pnet_find_base_ndev() when the dev is first used.
This means dev had already been freed before acquiring RTNL in
pnet_find_base_ndev().
While dev is going away, dst->dev could be swapped with blackhole_netdev,
and the dev's refcnt by dst will be released.
We must hold dev's refcnt before calling smc_pnet_find_ism_resource().
Also, smc_pnet_find_roce_resource() has the same problem.
Let's use __sk_dst_get() and dst_dev_rcu() in the two functions.
[0]:
BUG: KASAN: use-after-free in __pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
Read of size 1 at addr ffff888036bac33a by task syz.0.3632/18609
CPU: 1 UID: 0 PID: 18609 Comm: syz.0.3632 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
pnet_find_base_ndev net/smc/smc_pnet.c:946 [inline]
smc_pnet_find_ism_by_pnetid net/smc/smc_pnet.c:1103 [inline]
smc_pnet_find_ism_resource+0xef/0x390 net/smc/smc_pnet.c:1154
smc_find_ism_device net/smc/af_smc.c:1030 [inline]
smc_find_proposal_devices net/smc/af_smc.c:1115 [inline]
__smc_connect+0x372/0x1890 net/smc/af_smc.c:1545
smc_connect+0x877/0xd90 net/smc/af_smc.c:1715
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x313/0x440 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47cbf8eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f47ccdb1038 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f47cc1d5fa0 RCX: 00007f47cbf8eba9
RDX: 0000000000000010 RSI: 0000200000000280 RDI: 000000000000000b
RBP: 00007f47cc011e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f47cc1d6038 R14: 00007f47cc1d5fa0 R15: 00007ffc512f8aa8
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888036bacd00 pfn:0x36bac
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001243d08 ffff8880b863fdc0 0000000000000000
raw: ffff888036bacd00 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x446dc0(GFP_KERNEL_ACCOUNT|__GFP_ZERO|__GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_COMP), pid 16741, tgid 16741 (syz-executor), ts 343313197788, free_ts 380670750466
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
___kmalloc_large_node+0x5f/0x1b0 mm/slub.c:4317
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:4348
__do_kmalloc_node mm/slub.c:4364 [inline]
__kvmalloc_node_noprof+0x6d/0x5f0 mm/slub.c:5067
alloc_netdev_mqs+0xa3/0x11b0 net/core/dev.c:11812
tun_set_iff+0x532/0xef0 drivers/net/tun.c:2775
__tun_chr_ioctl+0x788/0x1df0 drivers/net/tun.c:3085
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 18610 tgid 18608 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
free_large_kmalloc+0x13a/0x1f0 mm/slub.c:4820
device_release+0x99/0x1c0 drivers/base/core.c:-1
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x22b/0x480 lib/kobject.c:737
netdev_run_todo+0xd2e/0xea0 net/core/dev.c:11513
rtnl_unlock net/core/rtnetlink.c:157 [inline]
rtnl_net_unlock include/linux/rtnetlink.h:135 [inline]
rtnl_dellink+0x537/0x710 net/core/rtnetlink.c:3563
rtnetlink_rcv_msg+0x7cc/0xb70 net/core/rtnetlink.c:6946
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888036bac200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac280: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888036bac300: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff888036bac380: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac400: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Fixes: 0afff91c6f5e ("net/smc: add pnetid support")
Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM")
Reported-by: syzbot+ea28e9d85be2f327b6c6@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/68c237c7.050a0220.3c6139.0036.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250916214758.650211-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-16 21:47:19 +00:00
|
|
|
struct net_device *dev;
|
|
|
|
|
struct dst_entry *dst;
|
2018-06-28 17:05:05 +00:00
|
|
|
|
smc: Fix use-after-free in __pnet_find_base_ndev().
syzbot reported use-after-free of net_device in __pnet_find_base_ndev(),
which was called during connect(). [0]
smc_pnet_find_ism_resource() fetches sk_dst_get(sk)->dev and passes
down to pnet_find_base_ndev(), where RTNL is held. Then, UAF happened
at __pnet_find_base_ndev() when the dev is first used.
This means dev had already been freed before acquiring RTNL in
pnet_find_base_ndev().
While dev is going away, dst->dev could be swapped with blackhole_netdev,
and the dev's refcnt by dst will be released.
We must hold dev's refcnt before calling smc_pnet_find_ism_resource().
Also, smc_pnet_find_roce_resource() has the same problem.
Let's use __sk_dst_get() and dst_dev_rcu() in the two functions.
[0]:
BUG: KASAN: use-after-free in __pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
Read of size 1 at addr ffff888036bac33a by task syz.0.3632/18609
CPU: 1 UID: 0 PID: 18609 Comm: syz.0.3632 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
pnet_find_base_ndev net/smc/smc_pnet.c:946 [inline]
smc_pnet_find_ism_by_pnetid net/smc/smc_pnet.c:1103 [inline]
smc_pnet_find_ism_resource+0xef/0x390 net/smc/smc_pnet.c:1154
smc_find_ism_device net/smc/af_smc.c:1030 [inline]
smc_find_proposal_devices net/smc/af_smc.c:1115 [inline]
__smc_connect+0x372/0x1890 net/smc/af_smc.c:1545
smc_connect+0x877/0xd90 net/smc/af_smc.c:1715
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x313/0x440 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47cbf8eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f47ccdb1038 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f47cc1d5fa0 RCX: 00007f47cbf8eba9
RDX: 0000000000000010 RSI: 0000200000000280 RDI: 000000000000000b
RBP: 00007f47cc011e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f47cc1d6038 R14: 00007f47cc1d5fa0 R15: 00007ffc512f8aa8
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888036bacd00 pfn:0x36bac
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001243d08 ffff8880b863fdc0 0000000000000000
raw: ffff888036bacd00 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x446dc0(GFP_KERNEL_ACCOUNT|__GFP_ZERO|__GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_COMP), pid 16741, tgid 16741 (syz-executor), ts 343313197788, free_ts 380670750466
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
___kmalloc_large_node+0x5f/0x1b0 mm/slub.c:4317
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:4348
__do_kmalloc_node mm/slub.c:4364 [inline]
__kvmalloc_node_noprof+0x6d/0x5f0 mm/slub.c:5067
alloc_netdev_mqs+0xa3/0x11b0 net/core/dev.c:11812
tun_set_iff+0x532/0xef0 drivers/net/tun.c:2775
__tun_chr_ioctl+0x788/0x1df0 drivers/net/tun.c:3085
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 18610 tgid 18608 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
free_large_kmalloc+0x13a/0x1f0 mm/slub.c:4820
device_release+0x99/0x1c0 drivers/base/core.c:-1
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x22b/0x480 lib/kobject.c:737
netdev_run_todo+0xd2e/0xea0 net/core/dev.c:11513
rtnl_unlock net/core/rtnetlink.c:157 [inline]
rtnl_net_unlock include/linux/rtnetlink.h:135 [inline]
rtnl_dellink+0x537/0x710 net/core/rtnetlink.c:3563
rtnetlink_rcv_msg+0x7cc/0xb70 net/core/rtnetlink.c:6946
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888036bac200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac280: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888036bac300: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff888036bac380: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac400: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Fixes: 0afff91c6f5e ("net/smc: add pnetid support")
Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM")
Reported-by: syzbot+ea28e9d85be2f327b6c6@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/68c237c7.050a0220.3c6139.0036.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250916214758.650211-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-16 21:47:19 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
|
dst = __sk_dst_get(sk);
|
|
|
|
|
dev = dst ? dst_dev_rcu(dst) : NULL;
|
|
|
|
|
dev_hold(dev);
|
|
|
|
|
rcu_read_unlock();
|
2018-06-28 17:05:05 +00:00
|
|
|
|
smc: Fix use-after-free in __pnet_find_base_ndev().
syzbot reported use-after-free of net_device in __pnet_find_base_ndev(),
which was called during connect(). [0]
smc_pnet_find_ism_resource() fetches sk_dst_get(sk)->dev and passes
down to pnet_find_base_ndev(), where RTNL is held. Then, UAF happened
at __pnet_find_base_ndev() when the dev is first used.
This means dev had already been freed before acquiring RTNL in
pnet_find_base_ndev().
While dev is going away, dst->dev could be swapped with blackhole_netdev,
and the dev's refcnt by dst will be released.
We must hold dev's refcnt before calling smc_pnet_find_ism_resource().
Also, smc_pnet_find_roce_resource() has the same problem.
Let's use __sk_dst_get() and dst_dev_rcu() in the two functions.
[0]:
BUG: KASAN: use-after-free in __pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
Read of size 1 at addr ffff888036bac33a by task syz.0.3632/18609
CPU: 1 UID: 0 PID: 18609 Comm: syz.0.3632 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
pnet_find_base_ndev net/smc/smc_pnet.c:946 [inline]
smc_pnet_find_ism_by_pnetid net/smc/smc_pnet.c:1103 [inline]
smc_pnet_find_ism_resource+0xef/0x390 net/smc/smc_pnet.c:1154
smc_find_ism_device net/smc/af_smc.c:1030 [inline]
smc_find_proposal_devices net/smc/af_smc.c:1115 [inline]
__smc_connect+0x372/0x1890 net/smc/af_smc.c:1545
smc_connect+0x877/0xd90 net/smc/af_smc.c:1715
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x313/0x440 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47cbf8eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f47ccdb1038 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f47cc1d5fa0 RCX: 00007f47cbf8eba9
RDX: 0000000000000010 RSI: 0000200000000280 RDI: 000000000000000b
RBP: 00007f47cc011e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f47cc1d6038 R14: 00007f47cc1d5fa0 R15: 00007ffc512f8aa8
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888036bacd00 pfn:0x36bac
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001243d08 ffff8880b863fdc0 0000000000000000
raw: ffff888036bacd00 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x446dc0(GFP_KERNEL_ACCOUNT|__GFP_ZERO|__GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_COMP), pid 16741, tgid 16741 (syz-executor), ts 343313197788, free_ts 380670750466
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
___kmalloc_large_node+0x5f/0x1b0 mm/slub.c:4317
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:4348
__do_kmalloc_node mm/slub.c:4364 [inline]
__kvmalloc_node_noprof+0x6d/0x5f0 mm/slub.c:5067
alloc_netdev_mqs+0xa3/0x11b0 net/core/dev.c:11812
tun_set_iff+0x532/0xef0 drivers/net/tun.c:2775
__tun_chr_ioctl+0x788/0x1df0 drivers/net/tun.c:3085
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 18610 tgid 18608 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
free_large_kmalloc+0x13a/0x1f0 mm/slub.c:4820
device_release+0x99/0x1c0 drivers/base/core.c:-1
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x22b/0x480 lib/kobject.c:737
netdev_run_todo+0xd2e/0xea0 net/core/dev.c:11513
rtnl_unlock net/core/rtnetlink.c:157 [inline]
rtnl_net_unlock include/linux/rtnetlink.h:135 [inline]
rtnl_dellink+0x537/0x710 net/core/rtnetlink.c:3563
rtnetlink_rcv_msg+0x7cc/0xb70 net/core/rtnetlink.c:6946
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888036bac200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac280: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888036bac300: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff888036bac380: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac400: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Fixes: 0afff91c6f5e ("net/smc: add pnetid support")
Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM")
Reported-by: syzbot+ea28e9d85be2f327b6c6@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/68c237c7.050a0220.3c6139.0036.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250916214758.650211-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-16 21:47:19 +00:00
|
|
|
if (dev) {
|
|
|
|
|
smc_pnet_find_roce_by_pnetid(dev, ini);
|
|
|
|
|
dev_put(dev);
|
|
|
|
|
}
|
2017-01-09 15:55:15 +00:00
|
|
|
}
|
2018-06-28 17:05:08 +00:00
|
|
|
|
2019-04-12 10:57:26 +00:00
|
|
|
void smc_pnet_find_ism_resource(struct sock *sk, struct smc_init_info *ini)
|
2018-06-28 17:05:08 +00:00
|
|
|
{
|
smc: Fix use-after-free in __pnet_find_base_ndev().
syzbot reported use-after-free of net_device in __pnet_find_base_ndev(),
which was called during connect(). [0]
smc_pnet_find_ism_resource() fetches sk_dst_get(sk)->dev and passes
down to pnet_find_base_ndev(), where RTNL is held. Then, UAF happened
at __pnet_find_base_ndev() when the dev is first used.
This means dev had already been freed before acquiring RTNL in
pnet_find_base_ndev().
While dev is going away, dst->dev could be swapped with blackhole_netdev,
and the dev's refcnt by dst will be released.
We must hold dev's refcnt before calling smc_pnet_find_ism_resource().
Also, smc_pnet_find_roce_resource() has the same problem.
Let's use __sk_dst_get() and dst_dev_rcu() in the two functions.
[0]:
BUG: KASAN: use-after-free in __pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
Read of size 1 at addr ffff888036bac33a by task syz.0.3632/18609
CPU: 1 UID: 0 PID: 18609 Comm: syz.0.3632 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
pnet_find_base_ndev net/smc/smc_pnet.c:946 [inline]
smc_pnet_find_ism_by_pnetid net/smc/smc_pnet.c:1103 [inline]
smc_pnet_find_ism_resource+0xef/0x390 net/smc/smc_pnet.c:1154
smc_find_ism_device net/smc/af_smc.c:1030 [inline]
smc_find_proposal_devices net/smc/af_smc.c:1115 [inline]
__smc_connect+0x372/0x1890 net/smc/af_smc.c:1545
smc_connect+0x877/0xd90 net/smc/af_smc.c:1715
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x313/0x440 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47cbf8eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f47ccdb1038 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f47cc1d5fa0 RCX: 00007f47cbf8eba9
RDX: 0000000000000010 RSI: 0000200000000280 RDI: 000000000000000b
RBP: 00007f47cc011e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f47cc1d6038 R14: 00007f47cc1d5fa0 R15: 00007ffc512f8aa8
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888036bacd00 pfn:0x36bac
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001243d08 ffff8880b863fdc0 0000000000000000
raw: ffff888036bacd00 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x446dc0(GFP_KERNEL_ACCOUNT|__GFP_ZERO|__GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_COMP), pid 16741, tgid 16741 (syz-executor), ts 343313197788, free_ts 380670750466
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
___kmalloc_large_node+0x5f/0x1b0 mm/slub.c:4317
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:4348
__do_kmalloc_node mm/slub.c:4364 [inline]
__kvmalloc_node_noprof+0x6d/0x5f0 mm/slub.c:5067
alloc_netdev_mqs+0xa3/0x11b0 net/core/dev.c:11812
tun_set_iff+0x532/0xef0 drivers/net/tun.c:2775
__tun_chr_ioctl+0x788/0x1df0 drivers/net/tun.c:3085
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 18610 tgid 18608 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
free_large_kmalloc+0x13a/0x1f0 mm/slub.c:4820
device_release+0x99/0x1c0 drivers/base/core.c:-1
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x22b/0x480 lib/kobject.c:737
netdev_run_todo+0xd2e/0xea0 net/core/dev.c:11513
rtnl_unlock net/core/rtnetlink.c:157 [inline]
rtnl_net_unlock include/linux/rtnetlink.h:135 [inline]
rtnl_dellink+0x537/0x710 net/core/rtnetlink.c:3563
rtnetlink_rcv_msg+0x7cc/0xb70 net/core/rtnetlink.c:6946
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888036bac200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac280: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888036bac300: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff888036bac380: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac400: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Fixes: 0afff91c6f5e ("net/smc: add pnetid support")
Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM")
Reported-by: syzbot+ea28e9d85be2f327b6c6@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/68c237c7.050a0220.3c6139.0036.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250916214758.650211-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-16 21:47:19 +00:00
|
|
|
struct net_device *dev;
|
|
|
|
|
struct dst_entry *dst;
|
2018-06-28 17:05:08 +00:00
|
|
|
|
2020-09-26 10:44:23 +00:00
|
|
|
ini->ism_dev[0] = NULL;
|
2018-06-28 17:05:08 +00:00
|
|
|
|
smc: Fix use-after-free in __pnet_find_base_ndev().
syzbot reported use-after-free of net_device in __pnet_find_base_ndev(),
which was called during connect(). [0]
smc_pnet_find_ism_resource() fetches sk_dst_get(sk)->dev and passes
down to pnet_find_base_ndev(), where RTNL is held. Then, UAF happened
at __pnet_find_base_ndev() when the dev is first used.
This means dev had already been freed before acquiring RTNL in
pnet_find_base_ndev().
While dev is going away, dst->dev could be swapped with blackhole_netdev,
and the dev's refcnt by dst will be released.
We must hold dev's refcnt before calling smc_pnet_find_ism_resource().
Also, smc_pnet_find_roce_resource() has the same problem.
Let's use __sk_dst_get() and dst_dev_rcu() in the two functions.
[0]:
BUG: KASAN: use-after-free in __pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
Read of size 1 at addr ffff888036bac33a by task syz.0.3632/18609
CPU: 1 UID: 0 PID: 18609 Comm: syz.0.3632 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
pnet_find_base_ndev net/smc/smc_pnet.c:946 [inline]
smc_pnet_find_ism_by_pnetid net/smc/smc_pnet.c:1103 [inline]
smc_pnet_find_ism_resource+0xef/0x390 net/smc/smc_pnet.c:1154
smc_find_ism_device net/smc/af_smc.c:1030 [inline]
smc_find_proposal_devices net/smc/af_smc.c:1115 [inline]
__smc_connect+0x372/0x1890 net/smc/af_smc.c:1545
smc_connect+0x877/0xd90 net/smc/af_smc.c:1715
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x313/0x440 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47cbf8eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f47ccdb1038 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f47cc1d5fa0 RCX: 00007f47cbf8eba9
RDX: 0000000000000010 RSI: 0000200000000280 RDI: 000000000000000b
RBP: 00007f47cc011e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f47cc1d6038 R14: 00007f47cc1d5fa0 R15: 00007ffc512f8aa8
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888036bacd00 pfn:0x36bac
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001243d08 ffff8880b863fdc0 0000000000000000
raw: ffff888036bacd00 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x446dc0(GFP_KERNEL_ACCOUNT|__GFP_ZERO|__GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_COMP), pid 16741, tgid 16741 (syz-executor), ts 343313197788, free_ts 380670750466
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
___kmalloc_large_node+0x5f/0x1b0 mm/slub.c:4317
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:4348
__do_kmalloc_node mm/slub.c:4364 [inline]
__kvmalloc_node_noprof+0x6d/0x5f0 mm/slub.c:5067
alloc_netdev_mqs+0xa3/0x11b0 net/core/dev.c:11812
tun_set_iff+0x532/0xef0 drivers/net/tun.c:2775
__tun_chr_ioctl+0x788/0x1df0 drivers/net/tun.c:3085
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 18610 tgid 18608 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
free_large_kmalloc+0x13a/0x1f0 mm/slub.c:4820
device_release+0x99/0x1c0 drivers/base/core.c:-1
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x22b/0x480 lib/kobject.c:737
netdev_run_todo+0xd2e/0xea0 net/core/dev.c:11513
rtnl_unlock net/core/rtnetlink.c:157 [inline]
rtnl_net_unlock include/linux/rtnetlink.h:135 [inline]
rtnl_dellink+0x537/0x710 net/core/rtnetlink.c:3563
rtnetlink_rcv_msg+0x7cc/0xb70 net/core/rtnetlink.c:6946
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888036bac200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac280: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888036bac300: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff888036bac380: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac400: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Fixes: 0afff91c6f5e ("net/smc: add pnetid support")
Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM")
Reported-by: syzbot+ea28e9d85be2f327b6c6@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/68c237c7.050a0220.3c6139.0036.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250916214758.650211-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-16 21:47:19 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
|
dst = __sk_dst_get(sk);
|
|
|
|
|
dev = dst ? dst_dev_rcu(dst) : NULL;
|
|
|
|
|
dev_hold(dev);
|
|
|
|
|
rcu_read_unlock();
|
2018-06-28 17:05:08 +00:00
|
|
|
|
smc: Fix use-after-free in __pnet_find_base_ndev().
syzbot reported use-after-free of net_device in __pnet_find_base_ndev(),
which was called during connect(). [0]
smc_pnet_find_ism_resource() fetches sk_dst_get(sk)->dev and passes
down to pnet_find_base_ndev(), where RTNL is held. Then, UAF happened
at __pnet_find_base_ndev() when the dev is first used.
This means dev had already been freed before acquiring RTNL in
pnet_find_base_ndev().
While dev is going away, dst->dev could be swapped with blackhole_netdev,
and the dev's refcnt by dst will be released.
We must hold dev's refcnt before calling smc_pnet_find_ism_resource().
Also, smc_pnet_find_roce_resource() has the same problem.
Let's use __sk_dst_get() and dst_dev_rcu() in the two functions.
[0]:
BUG: KASAN: use-after-free in __pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
Read of size 1 at addr ffff888036bac33a by task syz.0.3632/18609
CPU: 1 UID: 0 PID: 18609 Comm: syz.0.3632 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__pnet_find_base_ndev+0x1b1/0x1c0 net/smc/smc_pnet.c:926
pnet_find_base_ndev net/smc/smc_pnet.c:946 [inline]
smc_pnet_find_ism_by_pnetid net/smc/smc_pnet.c:1103 [inline]
smc_pnet_find_ism_resource+0xef/0x390 net/smc/smc_pnet.c:1154
smc_find_ism_device net/smc/af_smc.c:1030 [inline]
smc_find_proposal_devices net/smc/af_smc.c:1115 [inline]
__smc_connect+0x372/0x1890 net/smc/af_smc.c:1545
smc_connect+0x877/0xd90 net/smc/af_smc.c:1715
__sys_connect_file net/socket.c:2086 [inline]
__sys_connect+0x313/0x440 net/socket.c:2105
__do_sys_connect net/socket.c:2111 [inline]
__se_sys_connect net/socket.c:2108 [inline]
__x64_sys_connect+0x7a/0x90 net/socket.c:2108
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47cbf8eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f47ccdb1038 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: ffffffffffffffda RBX: 00007f47cc1d5fa0 RCX: 00007f47cbf8eba9
RDX: 0000000000000010 RSI: 0000200000000280 RDI: 000000000000000b
RBP: 00007f47cc011e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f47cc1d6038 R14: 00007f47cc1d5fa0 R15: 00007ffc512f8aa8
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888036bacd00 pfn:0x36bac
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001243d08 ffff8880b863fdc0 0000000000000000
raw: ffff888036bacd00 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x446dc0(GFP_KERNEL_ACCOUNT|__GFP_ZERO|__GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_COMP), pid 16741, tgid 16741 (syz-executor), ts 343313197788, free_ts 380670750466
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
___kmalloc_large_node+0x5f/0x1b0 mm/slub.c:4317
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:4348
__do_kmalloc_node mm/slub.c:4364 [inline]
__kvmalloc_node_noprof+0x6d/0x5f0 mm/slub.c:5067
alloc_netdev_mqs+0xa3/0x11b0 net/core/dev.c:11812
tun_set_iff+0x532/0xef0 drivers/net/tun.c:2775
__tun_chr_ioctl+0x788/0x1df0 drivers/net/tun.c:3085
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:598 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:584
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 18610 tgid 18608 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
free_large_kmalloc+0x13a/0x1f0 mm/slub.c:4820
device_release+0x99/0x1c0 drivers/base/core.c:-1
kobject_cleanup lib/kobject.c:689 [inline]
kobject_release lib/kobject.c:720 [inline]
kref_put include/linux/kref.h:65 [inline]
kobject_put+0x22b/0x480 lib/kobject.c:737
netdev_run_todo+0xd2e/0xea0 net/core/dev.c:11513
rtnl_unlock net/core/rtnetlink.c:157 [inline]
rtnl_net_unlock include/linux/rtnetlink.h:135 [inline]
rtnl_dellink+0x537/0x710 net/core/rtnetlink.c:3563
rtnetlink_rcv_msg+0x7cc/0xb70 net/core/rtnetlink.c:6946
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888036bac200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac280: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888036bac300: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff888036bac380: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff888036bac400: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Fixes: 0afff91c6f5e ("net/smc: add pnetid support")
Fixes: 1619f770589a ("net/smc: add pnetid support for SMC-D and ISM")
Reported-by: syzbot+ea28e9d85be2f327b6c6@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/68c237c7.050a0220.3c6139.0036.GAE@google.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250916214758.650211-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-16 21:47:19 +00:00
|
|
|
if (dev) {
|
|
|
|
|
smc_pnet_find_ism_by_pnetid(dev, ini);
|
|
|
|
|
dev_put(dev);
|
|
|
|
|
}
|
2018-06-28 17:05:08 +00:00
|
|
|
}
|
2020-04-29 15:10:37 +00:00
|
|
|
|
|
|
|
|
/* Lookup and apply a pnet table entry to the given ib device.
|
|
|
|
|
*/
|
|
|
|
|
int smc_pnetid_by_table_ib(struct smc_ib_device *smcibdev, u8 ib_port)
|
|
|
|
|
{
|
|
|
|
|
char *ib_name = smcibdev->ibdev->name;
|
|
|
|
|
struct smc_pnettable *pnettable;
|
|
|
|
|
struct smc_pnetentry *tmp_pe;
|
|
|
|
|
struct smc_net *sn;
|
|
|
|
|
int rc = -ENOENT;
|
|
|
|
|
|
|
|
|
|
/* get pnettable for init namespace */
|
|
|
|
|
sn = net_generic(&init_net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
|
|
|
|
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
|
|
|
|
|
if (tmp_pe->type == SMC_PNET_IB &&
|
|
|
|
|
!strncmp(tmp_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX) &&
|
|
|
|
|
tmp_pe->ib_port == ib_port) {
|
|
|
|
|
smc_pnet_apply_ib(smcibdev, ib_port, tmp_pe->pnet_name);
|
|
|
|
|
rc = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Lookup and apply a pnet table entry to the given smcd device.
|
|
|
|
|
*/
|
|
|
|
|
int smc_pnetid_by_table_smcd(struct smcd_dev *smcddev)
|
|
|
|
|
{
|
|
|
|
|
struct smc_pnettable *pnettable;
|
|
|
|
|
struct smc_pnetentry *tmp_pe;
|
|
|
|
|
struct smc_net *sn;
|
|
|
|
|
int rc = -ENOENT;
|
|
|
|
|
|
|
|
|
|
/* get pnettable for init namespace */
|
|
|
|
|
sn = net_generic(&init_net, smc_net_id);
|
|
|
|
|
pnettable = &sn->pnettable;
|
|
|
|
|
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_lock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
list_for_each_entry(tmp_pe, &pnettable->pnetlist, list) {
|
|
|
|
|
if (tmp_pe->type == SMC_PNET_IB &&
|
2025-09-18 11:04:55 +00:00
|
|
|
(!strncmp(tmp_pe->ib_name,
|
|
|
|
|
dev_name(&smcddev->dibs->dev),
|
|
|
|
|
sizeof(tmp_pe->ib_name)) ||
|
|
|
|
|
(smcddev->dibs->dev.parent &&
|
|
|
|
|
!strncmp(tmp_pe->ib_name,
|
|
|
|
|
dev_name(smcddev->dibs->dev.parent),
|
|
|
|
|
sizeof(tmp_pe->ib_name))))) {
|
2020-04-29 15:10:37 +00:00
|
|
|
smc_pnet_apply_smcd(smcddev, tmp_pe->pnet_name);
|
|
|
|
|
rc = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-23 10:02:52 +00:00
|
|
|
mutex_unlock(&pnettable->lock);
|
2020-04-29 15:10:37 +00:00
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|