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:16 +00:00
|
|
|
/*
|
|
|
|
* Shared Memory Communications over RDMA (SMC-R) and RoCE
|
|
|
|
*
|
|
|
|
* CLC (connection layer control) handshake over initial TCP socket to
|
|
|
|
* prepare for RDMA traffic
|
|
|
|
*
|
2018-03-16 14:06:40 +00:00
|
|
|
* Copyright IBM Corp. 2016, 2018
|
2017-01-09 15:55:16 +00:00
|
|
|
*
|
|
|
|
* Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/in.h>
|
2018-03-01 12:51:27 +00:00
|
|
|
#include <linux/inetdevice.h>
|
2017-01-12 13:57:15 +00:00
|
|
|
#include <linux/if_ether.h>
|
2017-02-02 07:35:14 +00:00
|
|
|
#include <linux/sched/signal.h>
|
2020-09-26 10:44:31 +00:00
|
|
|
#include <linux/utsname.h>
|
|
|
|
#include <linux/ctype.h>
|
2017-02-02 07:35:14 +00:00
|
|
|
|
2018-03-16 14:06:40 +00:00
|
|
|
#include <net/addrconf.h>
|
2017-01-09 15:55:16 +00:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/tcp.h>
|
|
|
|
|
|
|
|
#include "smc.h"
|
2017-01-09 15:55:17 +00:00
|
|
|
#include "smc_core.h"
|
2017-01-09 15:55:16 +00:00
|
|
|
#include "smc_clc.h"
|
|
|
|
#include "smc_ib.h"
|
2018-06-28 17:05:09 +00:00
|
|
|
#include "smc_ism.h"
|
2021-09-14 08:35:05 +00:00
|
|
|
#include "smc_netlink.h"
|
2018-06-28 17:05:09 +00:00
|
|
|
|
|
|
|
#define SMCR_CLC_ACCEPT_CONFIRM_LEN 68
|
|
|
|
#define SMCD_CLC_ACCEPT_CONFIRM_LEN 48
|
2020-09-26 10:44:30 +00:00
|
|
|
#define SMCD_CLC_ACCEPT_CONFIRM_LEN_V2 78
|
2021-10-16 09:37:45 +00:00
|
|
|
#define SMCR_CLC_ACCEPT_CONFIRM_LEN_V2 108
|
2020-07-08 15:05:15 +00:00
|
|
|
#define SMC_CLC_RECV_BUF_LEN 100
|
2017-01-09 15:55:16 +00:00
|
|
|
|
2018-03-01 12:51:26 +00:00
|
|
|
/* eye catcher "SMCR" EBCDIC for CLC messages */
|
|
|
|
static const char SMC_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xd9'};
|
2018-06-28 17:05:09 +00:00
|
|
|
/* eye catcher "SMCD" EBCDIC for CLC messages */
|
|
|
|
static const char SMCD_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xc4'};
|
2018-03-01 12:51:26 +00:00
|
|
|
|
2020-09-26 10:44:31 +00:00
|
|
|
static u8 smc_hostname[SMC_MAX_HOSTNAME_LEN];
|
|
|
|
|
2021-09-14 08:35:05 +00:00
|
|
|
struct smc_clc_eid_table {
|
|
|
|
rwlock_t lock;
|
|
|
|
struct list_head list;
|
|
|
|
u8 ueid_cnt;
|
|
|
|
u8 seid_enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct smc_clc_eid_table smc_clc_eid_table;
|
|
|
|
|
|
|
|
struct smc_clc_eid_entry {
|
|
|
|
struct list_head list;
|
|
|
|
u8 eid[SMC_MAX_EID_LEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The size of a user EID is 32 characters.
|
|
|
|
* Valid characters should be (single-byte character set) A-Z, 0-9, '.' and '-'.
|
|
|
|
* Blanks should only be used to pad to the expected size.
|
|
|
|
* First character must be alphanumeric.
|
|
|
|
*/
|
|
|
|
static bool smc_clc_ueid_valid(char *ueid)
|
|
|
|
{
|
|
|
|
char *end = ueid + SMC_MAX_EID_LEN;
|
|
|
|
|
|
|
|
while (--end >= ueid && isspace(*end))
|
|
|
|
;
|
|
|
|
if (end < ueid)
|
|
|
|
return false;
|
|
|
|
if (!isalnum(*ueid) || islower(*ueid))
|
|
|
|
return false;
|
|
|
|
while (ueid <= end) {
|
|
|
|
if ((!isalnum(*ueid) || islower(*ueid)) && *ueid != '.' &&
|
|
|
|
*ueid != '-')
|
|
|
|
return false;
|
|
|
|
ueid++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smc_clc_ueid_add(char *ueid)
|
|
|
|
{
|
|
|
|
struct smc_clc_eid_entry *new_ueid, *tmp_ueid;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!smc_clc_ueid_valid(ueid))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* add a new ueid entry to the ueid table if there isn't one */
|
|
|
|
new_ueid = kzalloc(sizeof(*new_ueid), GFP_KERNEL);
|
|
|
|
if (!new_ueid)
|
|
|
|
return -ENOMEM;
|
|
|
|
memcpy(new_ueid->eid, ueid, SMC_MAX_EID_LEN);
|
|
|
|
|
|
|
|
write_lock(&smc_clc_eid_table.lock);
|
|
|
|
if (smc_clc_eid_table.ueid_cnt >= SMC_MAX_UEID) {
|
|
|
|
rc = -ERANGE;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
list_for_each_entry(tmp_ueid, &smc_clc_eid_table.list, list) {
|
|
|
|
if (!memcmp(tmp_ueid->eid, ueid, SMC_MAX_EID_LEN)) {
|
|
|
|
rc = -EEXIST;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list_add_tail(&new_ueid->list, &smc_clc_eid_table.list);
|
|
|
|
smc_clc_eid_table.ueid_cnt++;
|
|
|
|
write_unlock(&smc_clc_eid_table.lock);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
write_unlock(&smc_clc_eid_table.lock);
|
|
|
|
kfree(new_ueid);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-10-16 09:37:44 +00:00
|
|
|
int smc_clc_ueid_count(void)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
read_lock(&smc_clc_eid_table.lock);
|
|
|
|
count = smc_clc_eid_table.ueid_cnt;
|
|
|
|
read_unlock(&smc_clc_eid_table.lock);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:35:05 +00:00
|
|
|
int smc_nl_add_ueid(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct nlattr *nla_ueid = info->attrs[SMC_NLA_EID_TABLE_ENTRY];
|
|
|
|
char *ueid;
|
|
|
|
|
|
|
|
if (!nla_ueid || nla_len(nla_ueid) != SMC_MAX_EID_LEN + 1)
|
|
|
|
return -EINVAL;
|
|
|
|
ueid = (char *)nla_data(nla_ueid);
|
|
|
|
|
|
|
|
return smc_clc_ueid_add(ueid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove one or all ueid entries from the table */
|
|
|
|
static int smc_clc_ueid_remove(char *ueid)
|
|
|
|
{
|
|
|
|
struct smc_clc_eid_entry *lst_ueid, *tmp_ueid;
|
|
|
|
int rc = -ENOENT;
|
|
|
|
|
|
|
|
/* remove table entry */
|
|
|
|
write_lock(&smc_clc_eid_table.lock);
|
|
|
|
list_for_each_entry_safe(lst_ueid, tmp_ueid, &smc_clc_eid_table.list,
|
|
|
|
list) {
|
|
|
|
if (!ueid || !memcmp(lst_ueid->eid, ueid, SMC_MAX_EID_LEN)) {
|
|
|
|
list_del(&lst_ueid->list);
|
|
|
|
smc_clc_eid_table.ueid_cnt--;
|
|
|
|
kfree(lst_ueid);
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-09-14 08:35:07 +00:00
|
|
|
if (!rc && !smc_clc_eid_table.ueid_cnt) {
|
|
|
|
smc_clc_eid_table.seid_enabled = 1;
|
|
|
|
rc = -EAGAIN; /* indicate success and enabling of seid */
|
|
|
|
}
|
2021-09-14 08:35:05 +00:00
|
|
|
write_unlock(&smc_clc_eid_table.lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_nl_remove_ueid(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct nlattr *nla_ueid = info->attrs[SMC_NLA_EID_TABLE_ENTRY];
|
|
|
|
char *ueid;
|
|
|
|
|
|
|
|
if (!nla_ueid || nla_len(nla_ueid) != SMC_MAX_EID_LEN + 1)
|
|
|
|
return -EINVAL;
|
|
|
|
ueid = (char *)nla_data(nla_ueid);
|
|
|
|
|
|
|
|
return smc_clc_ueid_remove(ueid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_nl_flush_ueid(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
smc_clc_ueid_remove(NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smc_nl_ueid_dumpinfo(struct sk_buff *skb, u32 portid, u32 seq,
|
|
|
|
u32 flags, char *ueid)
|
|
|
|
{
|
|
|
|
char ueid_str[SMC_MAX_EID_LEN + 1];
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(skb, portid, seq, &smc_gen_nl_family,
|
|
|
|
flags, SMC_NETLINK_DUMP_UEID);
|
|
|
|
if (!hdr)
|
|
|
|
return -ENOMEM;
|
2022-04-08 15:10:33 +00:00
|
|
|
memcpy(ueid_str, ueid, SMC_MAX_EID_LEN);
|
|
|
|
ueid_str[SMC_MAX_EID_LEN] = 0;
|
2021-09-14 08:35:05 +00:00
|
|
|
if (nla_put_string(skb, SMC_NLA_EID_TABLE_ENTRY, ueid_str)) {
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _smc_nl_ueid_dump(struct sk_buff *skb, u32 portid, u32 seq,
|
|
|
|
int start_idx)
|
|
|
|
{
|
|
|
|
struct smc_clc_eid_entry *lst_ueid;
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
read_lock(&smc_clc_eid_table.lock);
|
|
|
|
list_for_each_entry(lst_ueid, &smc_clc_eid_table.list, list) {
|
|
|
|
if (idx++ < start_idx)
|
|
|
|
continue;
|
|
|
|
if (smc_nl_ueid_dumpinfo(skb, portid, seq, NLM_F_MULTI,
|
|
|
|
lst_ueid->eid)) {
|
|
|
|
--idx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_unlock(&smc_clc_eid_table.lock);
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_nl_dump_ueid(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb);
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = _smc_nl_ueid_dump(skb, NETLINK_CB(cb->skb).portid,
|
|
|
|
cb->nlh->nlmsg_seq, cb_ctx->pos[0]);
|
|
|
|
|
|
|
|
cb_ctx->pos[0] = idx;
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:35:07 +00:00
|
|
|
int smc_nl_dump_seid(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb);
|
|
|
|
char seid_str[SMC_MAX_EID_LEN + 1];
|
|
|
|
u8 seid_enabled;
|
|
|
|
void *hdr;
|
|
|
|
u8 *seid;
|
|
|
|
|
|
|
|
if (cb_ctx->pos[0])
|
|
|
|
return skb->len;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
|
|
|
|
&smc_gen_nl_family, NLM_F_MULTI,
|
|
|
|
SMC_NETLINK_DUMP_SEID);
|
|
|
|
if (!hdr)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (!smc_ism_is_v2_capable())
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
smc_ism_get_system_eid(&seid);
|
2022-04-08 15:10:33 +00:00
|
|
|
memcpy(seid_str, seid, SMC_MAX_EID_LEN);
|
|
|
|
seid_str[SMC_MAX_EID_LEN] = 0;
|
2021-09-14 08:35:07 +00:00
|
|
|
if (nla_put_string(skb, SMC_NLA_SEID_ENTRY, seid_str))
|
|
|
|
goto err;
|
|
|
|
read_lock(&smc_clc_eid_table.lock);
|
|
|
|
seid_enabled = smc_clc_eid_table.seid_enabled;
|
|
|
|
read_unlock(&smc_clc_eid_table.lock);
|
|
|
|
if (nla_put_u8(skb, SMC_NLA_SEID_ENABLED, seid_enabled))
|
|
|
|
goto err;
|
|
|
|
end:
|
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
cb_ctx->pos[0]++;
|
|
|
|
return skb->len;
|
|
|
|
err:
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_nl_enable_seid(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
write_lock(&smc_clc_eid_table.lock);
|
|
|
|
smc_clc_eid_table.seid_enabled = 1;
|
|
|
|
write_unlock(&smc_clc_eid_table.lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_nl_disable_seid(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
write_lock(&smc_clc_eid_table.lock);
|
|
|
|
if (!smc_clc_eid_table.ueid_cnt)
|
|
|
|
rc = -ENOENT;
|
|
|
|
else
|
|
|
|
smc_clc_eid_table.seid_enabled = 0;
|
|
|
|
write_unlock(&smc_clc_eid_table.lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-09-14 08:35:05 +00:00
|
|
|
static bool _smc_clc_match_ueid(u8 *peer_ueid)
|
|
|
|
{
|
|
|
|
struct smc_clc_eid_entry *tmp_ueid;
|
|
|
|
|
|
|
|
list_for_each_entry(tmp_ueid, &smc_clc_eid_table.list, list) {
|
|
|
|
if (!memcmp(tmp_ueid->eid, peer_ueid, SMC_MAX_EID_LEN))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool smc_clc_match_eid(u8 *negotiated_eid,
|
|
|
|
struct smc_clc_v2_extension *smc_v2_ext,
|
|
|
|
u8 *peer_eid, u8 *local_eid)
|
|
|
|
{
|
|
|
|
bool match = false;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
negotiated_eid[0] = 0;
|
|
|
|
read_lock(&smc_clc_eid_table.lock);
|
2021-10-16 09:37:45 +00:00
|
|
|
if (peer_eid && local_eid &&
|
|
|
|
smc_clc_eid_table.seid_enabled &&
|
2021-09-14 08:35:05 +00:00
|
|
|
smc_v2_ext->hdr.flag.seid &&
|
|
|
|
!memcmp(peer_eid, local_eid, SMC_MAX_EID_LEN)) {
|
|
|
|
memcpy(negotiated_eid, peer_eid, SMC_MAX_EID_LEN);
|
|
|
|
match = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < smc_v2_ext->hdr.eid_cnt; i++) {
|
|
|
|
if (_smc_clc_match_ueid(smc_v2_ext->user_eids[i])) {
|
|
|
|
memcpy(negotiated_eid, smc_v2_ext->user_eids[i],
|
|
|
|
SMC_MAX_EID_LEN);
|
|
|
|
match = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
read_unlock(&smc_clc_eid_table.lock);
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2020-09-26 10:44:28 +00:00
|
|
|
/* check arriving CLC proposal */
|
|
|
|
static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)
|
|
|
|
{
|
|
|
|
struct smc_clc_msg_proposal_prefix *pclc_prfx;
|
|
|
|
struct smc_clc_smcd_v2_extension *smcd_v2_ext;
|
|
|
|
struct smc_clc_msg_hdr *hdr = &pclc->hdr;
|
|
|
|
struct smc_clc_v2_extension *v2_ext;
|
|
|
|
|
|
|
|
v2_ext = smc_get_clc_v2_ext(pclc);
|
|
|
|
pclc_prfx = smc_clc_proposal_get_prefix(pclc);
|
|
|
|
if (hdr->version == SMC_V1) {
|
|
|
|
if (hdr->typev1 == SMC_TYPE_N)
|
|
|
|
return false;
|
|
|
|
if (ntohs(hdr->length) !=
|
|
|
|
sizeof(*pclc) + ntohs(pclc->iparea_offset) +
|
|
|
|
sizeof(*pclc_prfx) +
|
|
|
|
pclc_prfx->ipv6_prefixes_cnt *
|
|
|
|
sizeof(struct smc_clc_ipv6_prefix) +
|
|
|
|
sizeof(struct smc_clc_msg_trail))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (ntohs(hdr->length) !=
|
|
|
|
sizeof(*pclc) +
|
|
|
|
sizeof(struct smc_clc_msg_smcd) +
|
|
|
|
(hdr->typev1 != SMC_TYPE_N ?
|
|
|
|
sizeof(*pclc_prfx) +
|
|
|
|
pclc_prfx->ipv6_prefixes_cnt *
|
|
|
|
sizeof(struct smc_clc_ipv6_prefix) : 0) +
|
|
|
|
(hdr->typev2 != SMC_TYPE_N ?
|
|
|
|
sizeof(*v2_ext) +
|
|
|
|
v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN : 0) +
|
|
|
|
(smcd_indicated(hdr->typev2) ?
|
|
|
|
sizeof(*smcd_v2_ext) + v2_ext->hdr.ism_gid_cnt *
|
|
|
|
sizeof(struct smc_clc_smcd_gid_chid) :
|
|
|
|
0) +
|
|
|
|
sizeof(struct smc_clc_msg_trail))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-26 10:44:30 +00:00
|
|
|
/* check arriving CLC accept or confirm */
|
|
|
|
static bool
|
|
|
|
smc_clc_msg_acc_conf_valid(struct smc_clc_msg_accept_confirm_v2 *clc_v2)
|
|
|
|
{
|
|
|
|
struct smc_clc_msg_hdr *hdr = &clc_v2->hdr;
|
|
|
|
|
|
|
|
if (hdr->typev1 != SMC_TYPE_R && hdr->typev1 != SMC_TYPE_D)
|
|
|
|
return false;
|
|
|
|
if (hdr->version == SMC_V1) {
|
|
|
|
if ((hdr->typev1 == SMC_TYPE_R &&
|
|
|
|
ntohs(hdr->length) != SMCR_CLC_ACCEPT_CONFIRM_LEN) ||
|
|
|
|
(hdr->typev1 == SMC_TYPE_D &&
|
|
|
|
ntohs(hdr->length) != SMCD_CLC_ACCEPT_CONFIRM_LEN))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (hdr->typev1 == SMC_TYPE_D &&
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
ntohs(hdr->length) < SMCD_CLC_ACCEPT_CONFIRM_LEN_V2)
|
2020-09-26 10:44:30 +00:00
|
|
|
return false;
|
2021-10-16 09:37:45 +00:00
|
|
|
if (hdr->typev1 == SMC_TYPE_R &&
|
|
|
|
ntohs(hdr->length) < SMCR_CLC_ACCEPT_CONFIRM_LEN_V2)
|
|
|
|
return false;
|
2020-09-26 10:44:30 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-16 09:37:47 +00:00
|
|
|
/* check arriving CLC decline */
|
|
|
|
static bool
|
|
|
|
smc_clc_msg_decl_valid(struct smc_clc_msg_decline *dclc)
|
|
|
|
{
|
|
|
|
struct smc_clc_msg_hdr *hdr = &dclc->hdr;
|
|
|
|
|
|
|
|
if (hdr->typev1 != SMC_TYPE_R && hdr->typev1 != SMC_TYPE_D)
|
|
|
|
return false;
|
|
|
|
if (hdr->version == SMC_V1) {
|
|
|
|
if (ntohs(hdr->length) != sizeof(struct smc_clc_msg_decline))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (ntohs(hdr->length) != sizeof(struct smc_clc_msg_decline_v2))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
static int smc_clc_fill_fce(struct smc_clc_first_contact_ext_v2x *fce,
|
|
|
|
struct smc_init_info *ini)
|
2020-09-26 10:44:31 +00:00
|
|
|
{
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
int ret = sizeof(*fce);
|
|
|
|
|
2020-09-26 10:44:31 +00:00
|
|
|
memset(fce, 0, sizeof(*fce));
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
fce->fce_v2_base.os_type = SMC_CLC_OS_LINUX;
|
|
|
|
fce->fce_v2_base.release = ini->release_nr;
|
|
|
|
memcpy(fce->fce_v2_base.hostname, smc_hostname, sizeof(smc_hostname));
|
|
|
|
if (ini->is_smcd && ini->release_nr < SMC_RELEASE_1)
|
|
|
|
ret = sizeof(struct smc_clc_first_contact_ext);
|
|
|
|
|
|
|
|
return ret;
|
2020-09-26 10:44:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 12:38:49 +00:00
|
|
|
/* check if received message has a correct header length and contains valid
|
|
|
|
* heading and trailing eyecatchers
|
|
|
|
*/
|
2020-07-08 15:05:15 +00:00
|
|
|
static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm, bool check_trl)
|
2017-12-07 12:38:49 +00:00
|
|
|
{
|
2020-09-26 10:44:30 +00:00
|
|
|
struct smc_clc_msg_accept_confirm_v2 *clc_v2;
|
2017-12-07 12:38:49 +00:00
|
|
|
struct smc_clc_msg_proposal *pclc;
|
|
|
|
struct smc_clc_msg_decline *dclc;
|
|
|
|
struct smc_clc_msg_trail *trl;
|
|
|
|
|
2018-06-28 17:05:09 +00:00
|
|
|
if (memcmp(clcm->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)) &&
|
|
|
|
memcmp(clcm->eyecatcher, SMCD_EYECATCHER, sizeof(SMCD_EYECATCHER)))
|
2017-12-07 12:38:49 +00:00
|
|
|
return false;
|
|
|
|
switch (clcm->type) {
|
|
|
|
case SMC_CLC_PROPOSAL:
|
|
|
|
pclc = (struct smc_clc_msg_proposal *)clcm;
|
2020-09-26 10:44:28 +00:00
|
|
|
if (!smc_clc_msg_prop_valid(pclc))
|
2017-12-07 12:38:49 +00:00
|
|
|
return false;
|
|
|
|
trl = (struct smc_clc_msg_trail *)
|
|
|
|
((u8 *)pclc + ntohs(pclc->hdr.length) - sizeof(*trl));
|
|
|
|
break;
|
|
|
|
case SMC_CLC_ACCEPT:
|
|
|
|
case SMC_CLC_CONFIRM:
|
2020-09-26 10:44:30 +00:00
|
|
|
clc_v2 = (struct smc_clc_msg_accept_confirm_v2 *)clcm;
|
|
|
|
if (!smc_clc_msg_acc_conf_valid(clc_v2))
|
2017-12-07 12:38:49 +00:00
|
|
|
return false;
|
2018-06-28 17:05:09 +00:00
|
|
|
trl = (struct smc_clc_msg_trail *)
|
2020-09-26 10:44:30 +00:00
|
|
|
((u8 *)clc_v2 + ntohs(clc_v2->hdr.length) -
|
|
|
|
sizeof(*trl));
|
2017-12-07 12:38:49 +00:00
|
|
|
break;
|
|
|
|
case SMC_CLC_DECLINE:
|
|
|
|
dclc = (struct smc_clc_msg_decline *)clcm;
|
2021-10-16 09:37:47 +00:00
|
|
|
if (!smc_clc_msg_decl_valid(dclc))
|
2017-12-07 12:38:49 +00:00
|
|
|
return false;
|
2021-10-16 09:37:47 +00:00
|
|
|
check_trl = false;
|
2017-12-07 12:38:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-08 15:05:15 +00:00
|
|
|
if (check_trl &&
|
|
|
|
memcmp(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)) &&
|
2018-06-28 17:05:09 +00:00
|
|
|
memcmp(trl->eyecatcher, SMCD_EYECATCHER, sizeof(SMCD_EYECATCHER)))
|
2017-12-07 12:38:49 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:06:39 +00:00
|
|
|
/* find ipv4 addr on device and get the prefix len, fill CLC proposal msg */
|
|
|
|
static int smc_clc_prfx_set4_rcu(struct dst_entry *dst, __be32 ipv4,
|
|
|
|
struct smc_clc_msg_proposal_prefix *prop)
|
|
|
|
{
|
|
|
|
struct in_device *in_dev = __in_dev_get_rcu(dst->dev);
|
2019-05-31 16:27:07 +00:00
|
|
|
const struct in_ifaddr *ifa;
|
2018-03-16 14:06:39 +00:00
|
|
|
|
|
|
|
if (!in_dev)
|
|
|
|
return -ENODEV;
|
2019-05-31 16:27:07 +00:00
|
|
|
|
|
|
|
in_dev_for_each_ifa_rcu(ifa, in_dev) {
|
2018-03-16 14:06:39 +00:00
|
|
|
if (!inet_ifa_match(ipv4, ifa))
|
|
|
|
continue;
|
|
|
|
prop->prefix_len = inet_mask_len(ifa->ifa_mask);
|
|
|
|
prop->outgoing_subnet = ifa->ifa_address & ifa->ifa_mask;
|
|
|
|
/* prop->ipv6_prefixes_cnt = 0; already done by memset before */
|
|
|
|
return 0;
|
2019-05-31 16:27:07 +00:00
|
|
|
}
|
2018-03-16 14:06:39 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:06:40 +00:00
|
|
|
/* fill CLC proposal msg with ipv6 prefixes from device */
|
|
|
|
static int smc_clc_prfx_set6_rcu(struct dst_entry *dst,
|
|
|
|
struct smc_clc_msg_proposal_prefix *prop,
|
|
|
|
struct smc_clc_ipv6_prefix *ipv6_prfx)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
struct inet6_dev *in6_dev = __in6_dev_get(dst->dev);
|
|
|
|
struct inet6_ifaddr *ifa;
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
if (!in6_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
/* use a maximum of 8 IPv6 prefixes from device */
|
|
|
|
list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
|
|
|
|
if (ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)
|
|
|
|
continue;
|
|
|
|
ipv6_addr_prefix(&ipv6_prfx[cnt].prefix,
|
|
|
|
&ifa->addr, ifa->prefix_len);
|
|
|
|
ipv6_prfx[cnt].prefix_len = ifa->prefix_len;
|
|
|
|
cnt++;
|
|
|
|
if (cnt == SMC_CLC_MAX_V6_PREFIX)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prop->ipv6_prefixes_cnt = cnt;
|
|
|
|
if (cnt)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:06:39 +00:00
|
|
|
/* retrieve and set prefixes in CLC proposal msg */
|
|
|
|
static int smc_clc_prfx_set(struct socket *clcsock,
|
2018-03-16 14:06:40 +00:00
|
|
|
struct smc_clc_msg_proposal_prefix *prop,
|
|
|
|
struct smc_clc_ipv6_prefix *ipv6_prfx)
|
2018-03-01 12:51:27 +00:00
|
|
|
{
|
|
|
|
struct dst_entry *dst = sk_dst_get(clcsock->sk);
|
2018-03-16 14:06:39 +00:00
|
|
|
struct sockaddr_storage addrs;
|
2018-03-16 14:06:40 +00:00
|
|
|
struct sockaddr_in6 *addr6;
|
2018-03-16 14:06:39 +00:00
|
|
|
struct sockaddr_in *addr;
|
2018-03-01 12:51:27 +00:00
|
|
|
int rc = -ENOENT;
|
|
|
|
|
|
|
|
if (!dst) {
|
|
|
|
rc = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!dst->dev) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_rel;
|
|
|
|
}
|
|
|
|
/* get address to which the internal TCP socket is bound */
|
2021-09-20 19:18:14 +00:00
|
|
|
if (kernel_getsockname(clcsock, (struct sockaddr *)&addrs) < 0)
|
|
|
|
goto out_rel;
|
2018-03-16 14:06:39 +00:00
|
|
|
/* analyze IP specific data of net_device belonging to TCP socket */
|
2018-03-16 14:06:40 +00:00
|
|
|
addr6 = (struct sockaddr_in6 *)&addrs;
|
2018-03-01 12:51:27 +00:00
|
|
|
rcu_read_lock();
|
2018-03-16 14:06:39 +00:00
|
|
|
if (addrs.ss_family == PF_INET) {
|
|
|
|
/* IPv4 */
|
|
|
|
addr = (struct sockaddr_in *)&addrs;
|
|
|
|
rc = smc_clc_prfx_set4_rcu(dst, addr->sin_addr.s_addr, prop);
|
2018-03-16 14:06:40 +00:00
|
|
|
} else if (ipv6_addr_v4mapped(&addr6->sin6_addr)) {
|
|
|
|
/* mapped IPv4 address - peer is IPv4 only */
|
|
|
|
rc = smc_clc_prfx_set4_rcu(dst, addr6->sin6_addr.s6_addr32[3],
|
|
|
|
prop);
|
|
|
|
} else {
|
|
|
|
/* IPv6 */
|
|
|
|
rc = smc_clc_prfx_set6_rcu(dst, prop, ipv6_prfx);
|
2018-03-16 14:06:39 +00:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
out_rel:
|
|
|
|
dst_release(dst);
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* match ipv4 addrs of dev against addr in CLC proposal */
|
|
|
|
static int smc_clc_prfx_match4_rcu(struct net_device *dev,
|
|
|
|
struct smc_clc_msg_proposal_prefix *prop)
|
|
|
|
{
|
|
|
|
struct in_device *in_dev = __in_dev_get_rcu(dev);
|
2019-05-31 16:27:07 +00:00
|
|
|
const struct in_ifaddr *ifa;
|
2018-03-16 14:06:39 +00:00
|
|
|
|
|
|
|
if (!in_dev)
|
|
|
|
return -ENODEV;
|
2019-05-31 16:27:07 +00:00
|
|
|
in_dev_for_each_ifa_rcu(ifa, in_dev) {
|
2018-03-16 14:06:39 +00:00
|
|
|
if (prop->prefix_len == inet_mask_len(ifa->ifa_mask) &&
|
|
|
|
inet_ifa_match(prop->outgoing_subnet, ifa))
|
|
|
|
return 0;
|
2019-05-31 16:27:07 +00:00
|
|
|
}
|
2018-03-01 12:51:27 +00:00
|
|
|
|
2018-03-16 14:06:39 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:06:40 +00:00
|
|
|
/* match ipv6 addrs of dev against addrs in CLC proposal */
|
|
|
|
static int smc_clc_prfx_match6_rcu(struct net_device *dev,
|
|
|
|
struct smc_clc_msg_proposal_prefix *prop)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
struct inet6_dev *in6_dev = __in6_dev_get(dev);
|
|
|
|
struct smc_clc_ipv6_prefix *ipv6_prfx;
|
|
|
|
struct inet6_ifaddr *ifa;
|
|
|
|
int i, max;
|
|
|
|
|
|
|
|
if (!in6_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
/* ipv6 prefix list starts behind smc_clc_msg_proposal_prefix */
|
|
|
|
ipv6_prfx = (struct smc_clc_ipv6_prefix *)((u8 *)prop + sizeof(*prop));
|
|
|
|
max = min_t(u8, prop->ipv6_prefixes_cnt, SMC_CLC_MAX_V6_PREFIX);
|
|
|
|
list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
|
|
|
|
if (ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)
|
|
|
|
continue;
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
if (ifa->prefix_len == ipv6_prfx[i].prefix_len &&
|
|
|
|
ipv6_prefix_equal(&ifa->addr, &ipv6_prfx[i].prefix,
|
|
|
|
ifa->prefix_len))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:06:39 +00:00
|
|
|
/* check if proposed prefixes match one of our device prefixes */
|
|
|
|
int smc_clc_prfx_match(struct socket *clcsock,
|
|
|
|
struct smc_clc_msg_proposal_prefix *prop)
|
|
|
|
{
|
|
|
|
struct dst_entry *dst = sk_dst_get(clcsock->sk);
|
2018-03-16 14:06:40 +00:00
|
|
|
int rc;
|
2018-03-16 14:06:39 +00:00
|
|
|
|
|
|
|
if (!dst) {
|
|
|
|
rc = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!dst->dev) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_rel;
|
|
|
|
}
|
|
|
|
rcu_read_lock();
|
|
|
|
if (!prop->ipv6_prefixes_cnt)
|
|
|
|
rc = smc_clc_prfx_match4_rcu(dst->dev, prop);
|
2018-03-16 14:06:40 +00:00
|
|
|
else
|
|
|
|
rc = smc_clc_prfx_match6_rcu(dst->dev, prop);
|
2018-03-16 14:06:39 +00:00
|
|
|
rcu_read_unlock();
|
2018-03-01 12:51:27 +00:00
|
|
|
out_rel:
|
|
|
|
dst_release(dst);
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-01-09 15:55:16 +00:00
|
|
|
/* Wait for data on the tcp-socket, analyze received data
|
|
|
|
* Returns:
|
|
|
|
* 0 if success and it was not a decline that we received.
|
|
|
|
* SMC_CLC_DECL_REPLY if decline received for fallback w/o another decl send.
|
|
|
|
* clcsock error, -EINTR, -ECONNRESET, -EPROTO otherwise.
|
|
|
|
*/
|
|
|
|
int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
|
2018-11-22 09:26:39 +00:00
|
|
|
u8 expected_type, unsigned long timeout)
|
2017-01-09 15:55:16 +00:00
|
|
|
{
|
2018-07-18 13:22:51 +00:00
|
|
|
long rcvtimeo = smc->clcsock->sk->sk_rcvtimeo;
|
2017-01-09 15:55:16 +00:00
|
|
|
struct sock *clc_sk = smc->clcsock->sk;
|
|
|
|
struct smc_clc_msg_hdr *clcm = buf;
|
|
|
|
struct msghdr msg = {NULL, 0};
|
|
|
|
int reason_code = 0;
|
2017-09-21 00:21:22 +00:00
|
|
|
struct kvec vec = {buf, buflen};
|
2020-07-08 15:05:15 +00:00
|
|
|
int len, datlen, recvlen;
|
|
|
|
bool check_trl = true;
|
2017-01-09 15:55:16 +00:00
|
|
|
int krflags;
|
|
|
|
|
|
|
|
/* peek the first few bytes to determine length of data to receive
|
|
|
|
* so we don't consume any subsequent CLC message or payload data
|
|
|
|
* in the TCP byte stream
|
|
|
|
*/
|
2017-09-21 00:21:22 +00:00
|
|
|
/*
|
|
|
|
* Caller must make sure that buflen is no less than
|
|
|
|
* sizeof(struct smc_clc_msg_hdr)
|
|
|
|
*/
|
2017-01-09 15:55:16 +00:00
|
|
|
krflags = MSG_PEEK | MSG_WAITALL;
|
2018-11-22 09:26:39 +00:00
|
|
|
clc_sk->sk_rcvtimeo = timeout;
|
2022-09-16 00:25:47 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, ITER_DEST, &vec, 1,
|
2017-09-21 00:21:22 +00:00
|
|
|
sizeof(struct smc_clc_msg_hdr));
|
|
|
|
len = sock_recvmsg(smc->clcsock, &msg, krflags);
|
2017-01-09 15:55:16 +00:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
reason_code = -EINTR;
|
|
|
|
clc_sk->sk_err = EINTR;
|
|
|
|
smc->sk.sk_err = EINTR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (clc_sk->sk_err) {
|
|
|
|
reason_code = -clc_sk->sk_err;
|
2018-11-22 09:26:37 +00:00
|
|
|
if (clc_sk->sk_err == EAGAIN &&
|
|
|
|
expected_type == SMC_CLC_DECLINE)
|
|
|
|
clc_sk->sk_err = 0; /* reset for fallback usage */
|
|
|
|
else
|
|
|
|
smc->sk.sk_err = clc_sk->sk_err;
|
2017-01-09 15:55:16 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!len) { /* peer has performed orderly shutdown */
|
|
|
|
smc->sk.sk_err = ECONNRESET;
|
|
|
|
reason_code = -ECONNRESET;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (len < 0) {
|
2018-11-22 09:26:37 +00:00
|
|
|
if (len != -EAGAIN || expected_type != SMC_CLC_DECLINE)
|
|
|
|
smc->sk.sk_err = -len;
|
2017-01-09 15:55:16 +00:00
|
|
|
reason_code = len;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
datlen = ntohs(clcm->length);
|
|
|
|
if ((len < sizeof(struct smc_clc_msg_hdr)) ||
|
2020-09-10 16:48:21 +00:00
|
|
|
(clcm->version < SMC_V1) ||
|
2017-01-09 15:55:16 +00:00
|
|
|
((clcm->type != SMC_CLC_DECLINE) &&
|
|
|
|
(clcm->type != expected_type))) {
|
|
|
|
smc->sk.sk_err = EPROTO;
|
|
|
|
reason_code = -EPROTO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* receive the complete CLC message */
|
|
|
|
memset(&msg, 0, sizeof(struct msghdr));
|
2020-07-08 15:05:15 +00:00
|
|
|
if (datlen > buflen) {
|
|
|
|
check_trl = false;
|
|
|
|
recvlen = buflen;
|
|
|
|
} else {
|
|
|
|
recvlen = datlen;
|
|
|
|
}
|
2022-09-16 00:25:47 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, ITER_DEST, &vec, 1, recvlen);
|
2017-01-09 15:55:16 +00:00
|
|
|
krflags = MSG_WAITALL;
|
2017-09-21 00:21:22 +00:00
|
|
|
len = sock_recvmsg(smc->clcsock, &msg, krflags);
|
2020-07-08 15:05:15 +00:00
|
|
|
if (len < recvlen || !smc_clc_msg_hdr_valid(clcm, check_trl)) {
|
2017-01-09 15:55:16 +00:00
|
|
|
smc->sk.sk_err = EPROTO;
|
|
|
|
reason_code = -EPROTO;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-07-08 15:05:15 +00:00
|
|
|
datlen -= len;
|
|
|
|
while (datlen) {
|
|
|
|
u8 tmp[SMC_CLC_RECV_BUF_LEN];
|
|
|
|
|
|
|
|
vec.iov_base = &tmp;
|
|
|
|
vec.iov_len = SMC_CLC_RECV_BUF_LEN;
|
|
|
|
/* receive remaining proposal message */
|
|
|
|
recvlen = datlen > SMC_CLC_RECV_BUF_LEN ?
|
|
|
|
SMC_CLC_RECV_BUF_LEN : datlen;
|
2022-09-16 00:25:47 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, ITER_DEST, &vec, 1, recvlen);
|
2020-07-08 15:05:15 +00:00
|
|
|
len = sock_recvmsg(smc->clcsock, &msg, krflags);
|
|
|
|
datlen -= len;
|
|
|
|
}
|
2017-01-09 15:55:17 +00:00
|
|
|
if (clcm->type == SMC_CLC_DECLINE) {
|
2018-07-25 14:35:32 +00:00
|
|
|
struct smc_clc_msg_decline *dclc;
|
|
|
|
|
|
|
|
dclc = (struct smc_clc_msg_decline *)clcm;
|
|
|
|
reason_code = SMC_CLC_DECL_PEERDECL;
|
|
|
|
smc->peer_diagnosis = ntohl(dclc->peer_diagnosis);
|
2020-09-26 10:44:20 +00:00
|
|
|
if (((struct smc_clc_msg_decline *)buf)->hdr.typev2 &
|
|
|
|
SMC_FIRST_CONTACT_MASK) {
|
2018-05-15 15:05:03 +00:00
|
|
|
smc->conn.lgr->sync_err = 1;
|
2020-02-17 15:24:54 +00:00
|
|
|
smc_lgr_terminate_sched(smc->conn.lgr);
|
2017-09-21 07:16:32 +00:00
|
|
|
}
|
2017-01-09 15:55:17 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 15:55:16 +00:00
|
|
|
out:
|
2018-11-22 09:26:39 +00:00
|
|
|
clc_sk->sk_rcvtimeo = rcvtimeo;
|
2017-01-09 15:55:16 +00:00
|
|
|
return reason_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send CLC DECLINE message across internal TCP socket */
|
2020-09-26 10:44:32 +00:00
|
|
|
int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version)
|
2017-01-09 15:55:16 +00:00
|
|
|
{
|
2021-10-16 09:37:47 +00:00
|
|
|
struct smc_clc_msg_decline *dclc_v1;
|
|
|
|
struct smc_clc_msg_decline_v2 dclc;
|
2017-01-09 15:55:16 +00:00
|
|
|
struct msghdr msg;
|
2021-10-16 09:37:47 +00:00
|
|
|
int len, send_len;
|
2017-01-09 15:55:16 +00:00
|
|
|
struct kvec vec;
|
|
|
|
|
2021-10-16 09:37:47 +00:00
|
|
|
dclc_v1 = (struct smc_clc_msg_decline *)&dclc;
|
2017-01-09 15:55:16 +00:00
|
|
|
memset(&dclc, 0, sizeof(dclc));
|
|
|
|
memcpy(dclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER));
|
|
|
|
dclc.hdr.type = SMC_CLC_DECLINE;
|
2020-09-26 10:44:32 +00:00
|
|
|
dclc.hdr.version = version;
|
|
|
|
dclc.os_type = version == SMC_V1 ? 0 : SMC_CLC_OS_LINUX;
|
2020-09-26 10:44:20 +00:00
|
|
|
dclc.hdr.typev2 = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ?
|
|
|
|
SMC_FIRST_CONTACT_MASK : 0;
|
2022-01-13 08:36:41 +00:00
|
|
|
if ((!smc_conn_lgr_valid(&smc->conn) || !smc->conn.lgr->is_smcd) &&
|
2020-02-25 21:41:22 +00:00
|
|
|
smc_ib_is_valid_local_systemid())
|
2020-02-14 07:59:00 +00:00
|
|
|
memcpy(dclc.id_for_peer, local_systemid,
|
|
|
|
sizeof(local_systemid));
|
2017-01-09 15:55:16 +00:00
|
|
|
dclc.peer_diagnosis = htonl(peer_diag_info);
|
2021-10-16 09:37:47 +00:00
|
|
|
if (version == SMC_V1) {
|
|
|
|
memcpy(dclc_v1->trl.eyecatcher, SMC_EYECATCHER,
|
|
|
|
sizeof(SMC_EYECATCHER));
|
|
|
|
send_len = sizeof(*dclc_v1);
|
|
|
|
} else {
|
|
|
|
memcpy(dclc.trl.eyecatcher, SMC_EYECATCHER,
|
|
|
|
sizeof(SMC_EYECATCHER));
|
|
|
|
send_len = sizeof(dclc);
|
|
|
|
}
|
|
|
|
dclc.hdr.length = htons(send_len);
|
2017-01-09 15:55:16 +00:00
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
vec.iov_base = &dclc;
|
2021-10-16 09:37:47 +00:00
|
|
|
vec.iov_len = send_len;
|
|
|
|
len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, send_len);
|
|
|
|
if (len < 0 || len < send_len)
|
2018-11-22 09:26:36 +00:00
|
|
|
len = -EPROTO;
|
|
|
|
return len > 0 ? 0 : len;
|
2017-01-09 15:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send CLC PROPOSAL message across internal TCP socket */
|
2020-09-26 10:44:27 +00:00
|
|
|
int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
|
2017-01-09 15:55:16 +00:00
|
|
|
{
|
2020-09-26 10:44:28 +00:00
|
|
|
struct smc_clc_smcd_v2_extension *smcd_v2_ext;
|
2020-09-10 16:48:22 +00:00
|
|
|
struct smc_clc_msg_proposal_prefix *pclc_prfx;
|
|
|
|
struct smc_clc_msg_proposal *pclc_base;
|
2020-09-26 10:44:28 +00:00
|
|
|
struct smc_clc_smcd_gid_chid *gidchids;
|
2020-09-10 16:48:22 +00:00
|
|
|
struct smc_clc_msg_proposal_area *pclc;
|
|
|
|
struct smc_clc_ipv6_prefix *ipv6_prfx;
|
2020-09-26 10:44:28 +00:00
|
|
|
struct smc_clc_v2_extension *v2_ext;
|
2020-09-10 16:48:22 +00:00
|
|
|
struct smc_clc_msg_smcd *pclc_smcd;
|
|
|
|
struct smc_clc_msg_trail *trl;
|
2023-01-23 18:17:50 +00:00
|
|
|
struct smcd_dev *smcd;
|
2018-03-16 14:06:40 +00:00
|
|
|
int len, i, plen, rc;
|
2017-01-09 15:55:16 +00:00
|
|
|
int reason_code = 0;
|
2020-09-26 10:44:28 +00:00
|
|
|
struct kvec vec[8];
|
2017-01-09 15:55:16 +00:00
|
|
|
struct msghdr msg;
|
|
|
|
|
2020-09-10 16:48:22 +00:00
|
|
|
pclc = kzalloc(sizeof(*pclc), GFP_KERNEL);
|
|
|
|
if (!pclc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pclc_base = &pclc->pclc_base;
|
|
|
|
pclc_smcd = &pclc->pclc_smcd;
|
|
|
|
pclc_prfx = &pclc->pclc_prfx;
|
|
|
|
ipv6_prfx = pclc->pclc_prfx_ipv6;
|
2020-09-26 10:44:28 +00:00
|
|
|
v2_ext = &pclc->pclc_v2_ext;
|
|
|
|
smcd_v2_ext = &pclc->pclc_smcd_v2_ext;
|
|
|
|
gidchids = pclc->pclc_gidchids;
|
2020-09-10 16:48:22 +00:00
|
|
|
trl = &pclc->pclc_trl;
|
|
|
|
|
2020-09-26 10:44:28 +00:00
|
|
|
pclc_base->hdr.version = SMC_V2;
|
|
|
|
pclc_base->hdr.typev1 = ini->smc_type_v1;
|
|
|
|
pclc_base->hdr.typev2 = ini->smc_type_v2;
|
|
|
|
plen = sizeof(*pclc_base) + sizeof(*pclc_smcd) + sizeof(*trl);
|
|
|
|
|
2018-03-16 14:06:39 +00:00
|
|
|
/* retrieve ip prefixes for CLC proposal msg */
|
2020-09-26 10:44:28 +00:00
|
|
|
if (ini->smc_type_v1 != SMC_TYPE_N) {
|
|
|
|
rc = smc_clc_prfx_set(smc->clcsock, pclc_prfx, ipv6_prfx);
|
|
|
|
if (rc) {
|
|
|
|
if (ini->smc_type_v2 == SMC_TYPE_N) {
|
|
|
|
kfree(pclc);
|
|
|
|
return SMC_CLC_DECL_CNFERR;
|
|
|
|
}
|
|
|
|
pclc_base->hdr.typev1 = SMC_TYPE_N;
|
|
|
|
} else {
|
|
|
|
pclc_base->iparea_offset = htons(sizeof(*pclc_smcd));
|
|
|
|
plen += sizeof(*pclc_prfx) +
|
|
|
|
pclc_prfx->ipv6_prefixes_cnt *
|
|
|
|
sizeof(ipv6_prfx[0]);
|
|
|
|
}
|
2020-09-10 16:48:22 +00:00
|
|
|
}
|
2018-03-16 14:06:39 +00:00
|
|
|
|
2020-09-26 10:44:28 +00:00
|
|
|
/* build SMC Proposal CLC message */
|
2020-09-10 16:48:22 +00:00
|
|
|
memcpy(pclc_base->hdr.eyecatcher, SMC_EYECATCHER,
|
|
|
|
sizeof(SMC_EYECATCHER));
|
|
|
|
pclc_base->hdr.type = SMC_CLC_PROPOSAL;
|
2020-09-26 10:44:27 +00:00
|
|
|
if (smcr_indicated(ini->smc_type_v1)) {
|
2018-06-28 17:05:09 +00:00
|
|
|
/* add SMC-R specifics */
|
2020-09-10 16:48:22 +00:00
|
|
|
memcpy(pclc_base->lcl.id_for_peer, local_systemid,
|
2018-06-28 17:05:09 +00:00
|
|
|
sizeof(local_systemid));
|
2020-09-10 16:48:22 +00:00
|
|
|
memcpy(pclc_base->lcl.gid, ini->ib_gid, SMC_GID_SIZE);
|
|
|
|
memcpy(pclc_base->lcl.mac, &ini->ib_dev->mac[ini->ib_port - 1],
|
2019-04-12 10:57:26 +00:00
|
|
|
ETH_ALEN);
|
2018-06-28 17:05:09 +00:00
|
|
|
}
|
2020-09-26 10:44:27 +00:00
|
|
|
if (smcd_indicated(ini->smc_type_v1)) {
|
2018-06-28 17:05:09 +00:00
|
|
|
/* add SMC-D specifics */
|
2020-09-26 10:44:28 +00:00
|
|
|
if (ini->ism_dev[0]) {
|
2023-01-23 18:17:50 +00:00
|
|
|
smcd = ini->ism_dev[0];
|
|
|
|
pclc_smcd->ism.gid =
|
|
|
|
htonll(smcd->ops->get_local_gid(smcd));
|
2020-09-26 10:44:28 +00:00
|
|
|
pclc_smcd->ism.chid =
|
|
|
|
htons(smc_ism_get_chid(ini->ism_dev[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ini->smc_type_v2 == SMC_TYPE_N) {
|
|
|
|
pclc_smcd->v2_ext_offset = 0;
|
|
|
|
} else {
|
2021-09-14 08:35:05 +00:00
|
|
|
struct smc_clc_eid_entry *ueident;
|
2020-09-26 10:44:28 +00:00
|
|
|
u16 v2_ext_offset;
|
|
|
|
|
2021-10-16 09:37:45 +00:00
|
|
|
v2_ext->hdr.flag.release = SMC_RELEASE;
|
2020-09-26 10:44:28 +00:00
|
|
|
v2_ext_offset = sizeof(*pclc_smcd) -
|
|
|
|
offsetofend(struct smc_clc_msg_smcd, v2_ext_offset);
|
|
|
|
if (ini->smc_type_v1 != SMC_TYPE_N)
|
|
|
|
v2_ext_offset += sizeof(*pclc_prfx) +
|
|
|
|
pclc_prfx->ipv6_prefixes_cnt *
|
|
|
|
sizeof(ipv6_prfx[0]);
|
|
|
|
pclc_smcd->v2_ext_offset = htons(v2_ext_offset);
|
2021-10-16 09:37:45 +00:00
|
|
|
plen += sizeof(*v2_ext);
|
2021-09-14 08:35:05 +00:00
|
|
|
|
|
|
|
read_lock(&smc_clc_eid_table.lock);
|
|
|
|
v2_ext->hdr.eid_cnt = smc_clc_eid_table.ueid_cnt;
|
|
|
|
plen += smc_clc_eid_table.ueid_cnt * SMC_MAX_EID_LEN;
|
|
|
|
i = 0;
|
|
|
|
list_for_each_entry(ueident, &smc_clc_eid_table.list, list) {
|
|
|
|
memcpy(v2_ext->user_eids[i++], ueident->eid,
|
|
|
|
sizeof(ueident->eid));
|
|
|
|
}
|
|
|
|
read_unlock(&smc_clc_eid_table.lock);
|
2021-10-16 09:37:45 +00:00
|
|
|
}
|
|
|
|
if (smcd_indicated(ini->smc_type_v2)) {
|
|
|
|
u8 *eid = NULL;
|
|
|
|
|
|
|
|
v2_ext->hdr.flag.seid = smc_clc_eid_table.seid_enabled;
|
2020-09-26 10:44:28 +00:00
|
|
|
v2_ext->hdr.ism_gid_cnt = ini->ism_offered_cnt;
|
|
|
|
v2_ext->hdr.smcd_v2_ext_offset = htons(sizeof(*v2_ext) -
|
|
|
|
offsetofend(struct smc_clnt_opts_area_hdr,
|
|
|
|
smcd_v2_ext_offset) +
|
|
|
|
v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN);
|
2021-09-14 08:35:06 +00:00
|
|
|
smc_ism_get_system_eid(&eid);
|
2021-09-14 08:35:05 +00:00
|
|
|
if (eid && v2_ext->hdr.flag.seid)
|
2020-09-26 10:44:28 +00:00
|
|
|
memcpy(smcd_v2_ext->system_eid, eid, SMC_MAX_EID_LEN);
|
2021-10-16 09:37:45 +00:00
|
|
|
plen += sizeof(*smcd_v2_ext);
|
2020-09-26 10:44:28 +00:00
|
|
|
if (ini->ism_offered_cnt) {
|
|
|
|
for (i = 1; i <= ini->ism_offered_cnt; i++) {
|
2023-01-23 18:17:50 +00:00
|
|
|
smcd = ini->ism_dev[i];
|
2020-09-26 10:44:28 +00:00
|
|
|
gidchids[i - 1].gid =
|
2023-01-23 18:17:50 +00:00
|
|
|
htonll(smcd->ops->get_local_gid(smcd));
|
2020-09-26 10:44:28 +00:00
|
|
|
gidchids[i - 1].chid =
|
|
|
|
htons(smc_ism_get_chid(ini->ism_dev[i]));
|
|
|
|
}
|
|
|
|
plen += ini->ism_offered_cnt *
|
|
|
|
sizeof(struct smc_clc_smcd_gid_chid);
|
|
|
|
}
|
2018-06-28 17:05:09 +00:00
|
|
|
}
|
2021-10-16 09:37:45 +00:00
|
|
|
if (smcr_indicated(ini->smc_type_v2))
|
|
|
|
memcpy(v2_ext->roce, ini->smcrv2.ib_gid_v2, SMC_GID_SIZE);
|
|
|
|
|
2020-09-10 16:48:22 +00:00
|
|
|
pclc_base->hdr.length = htons(plen);
|
|
|
|
memcpy(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER));
|
2020-09-26 10:44:28 +00:00
|
|
|
|
|
|
|
/* send SMC Proposal CLC message */
|
2017-01-09 15:55:16 +00:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
2018-03-16 14:06:40 +00:00
|
|
|
i = 0;
|
2020-09-10 16:48:22 +00:00
|
|
|
vec[i].iov_base = pclc_base;
|
|
|
|
vec[i++].iov_len = sizeof(*pclc_base);
|
2020-09-26 10:44:28 +00:00
|
|
|
vec[i].iov_base = pclc_smcd;
|
|
|
|
vec[i++].iov_len = sizeof(*pclc_smcd);
|
|
|
|
if (ini->smc_type_v1 != SMC_TYPE_N) {
|
|
|
|
vec[i].iov_base = pclc_prfx;
|
|
|
|
vec[i++].iov_len = sizeof(*pclc_prfx);
|
|
|
|
if (pclc_prfx->ipv6_prefixes_cnt > 0) {
|
|
|
|
vec[i].iov_base = ipv6_prfx;
|
|
|
|
vec[i++].iov_len = pclc_prfx->ipv6_prefixes_cnt *
|
|
|
|
sizeof(ipv6_prfx[0]);
|
|
|
|
}
|
2018-06-28 17:05:09 +00:00
|
|
|
}
|
2020-09-26 10:44:28 +00:00
|
|
|
if (ini->smc_type_v2 != SMC_TYPE_N) {
|
|
|
|
vec[i].iov_base = v2_ext;
|
2021-09-14 08:35:05 +00:00
|
|
|
vec[i++].iov_len = sizeof(*v2_ext) +
|
|
|
|
(v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN);
|
2021-10-16 09:37:45 +00:00
|
|
|
if (smcd_indicated(ini->smc_type_v2)) {
|
|
|
|
vec[i].iov_base = smcd_v2_ext;
|
|
|
|
vec[i++].iov_len = sizeof(*smcd_v2_ext);
|
|
|
|
if (ini->ism_offered_cnt) {
|
|
|
|
vec[i].iov_base = gidchids;
|
|
|
|
vec[i++].iov_len = ini->ism_offered_cnt *
|
2020-09-26 10:44:28 +00:00
|
|
|
sizeof(struct smc_clc_smcd_gid_chid);
|
2021-10-16 09:37:45 +00:00
|
|
|
}
|
2020-09-26 10:44:28 +00:00
|
|
|
}
|
2018-03-16 14:06:40 +00:00
|
|
|
}
|
2020-09-10 16:48:22 +00:00
|
|
|
vec[i].iov_base = trl;
|
|
|
|
vec[i++].iov_len = sizeof(*trl);
|
2017-01-09 15:55:16 +00:00
|
|
|
/* due to the few bytes needed for clc-handshake this cannot block */
|
2018-03-16 14:06:40 +00:00
|
|
|
len = kernel_sendmsg(smc->clcsock, &msg, vec, i, plen);
|
2018-09-18 13:46:38 +00:00
|
|
|
if (len < 0) {
|
|
|
|
smc->sk.sk_err = smc->clcsock->sk->sk_err;
|
|
|
|
reason_code = -smc->sk.sk_err;
|
2020-09-10 16:48:22 +00:00
|
|
|
} else if (len < ntohs(pclc_base->hdr.length)) {
|
2018-09-18 13:46:38 +00:00
|
|
|
reason_code = -ENETUNREACH;
|
|
|
|
smc->sk.sk_err = -reason_code;
|
2017-01-09 15:55:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 16:48:22 +00:00
|
|
|
kfree(pclc);
|
2017-01-09 15:55:16 +00:00
|
|
|
return reason_code;
|
|
|
|
}
|
|
|
|
|
2020-09-10 16:48:23 +00:00
|
|
|
/* build and send CLC CONFIRM / ACCEPT message */
|
|
|
|
static int smc_clc_send_confirm_accept(struct smc_sock *smc,
|
2020-09-26 10:44:30 +00:00
|
|
|
struct smc_clc_msg_accept_confirm_v2 *clc_v2,
|
2021-09-14 08:35:05 +00:00
|
|
|
int first_contact, u8 version,
|
2021-10-16 09:37:45 +00:00
|
|
|
u8 *eid, struct smc_init_info *ini)
|
2017-01-09 15:55:16 +00:00
|
|
|
{
|
2017-01-09 15:55:17 +00:00
|
|
|
struct smc_connection *conn = &smc->conn;
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
struct smc_clc_first_contact_ext_v2x fce;
|
2020-09-26 10:44:30 +00:00
|
|
|
struct smc_clc_msg_accept_confirm *clc;
|
2021-10-16 09:37:45 +00:00
|
|
|
struct smc_clc_fce_gid_ext gle;
|
2020-09-26 10:44:22 +00:00
|
|
|
struct smc_clc_msg_trail trl;
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
int i, len, fce_len;
|
2021-10-16 09:37:45 +00:00
|
|
|
struct kvec vec[5];
|
2017-01-09 15:55:16 +00:00
|
|
|
struct msghdr msg;
|
|
|
|
|
|
|
|
/* send SMC Confirm CLC msg */
|
2020-09-26 10:44:30 +00:00
|
|
|
clc = (struct smc_clc_msg_accept_confirm *)clc_v2;
|
|
|
|
clc->hdr.version = version; /* SMC version */
|
2020-09-10 16:48:23 +00:00
|
|
|
if (first_contact)
|
2020-09-26 10:44:20 +00:00
|
|
|
clc->hdr.typev2 |= SMC_FIRST_CONTACT_MASK;
|
2020-09-10 16:48:21 +00:00
|
|
|
if (conn->lgr->is_smcd) {
|
2018-06-28 17:05:09 +00:00
|
|
|
/* SMC-D specific settings */
|
2020-09-10 16:48:23 +00:00
|
|
|
memcpy(clc->hdr.eyecatcher, SMCD_EYECATCHER,
|
2018-06-28 17:05:09 +00:00
|
|
|
sizeof(SMCD_EYECATCHER));
|
2020-09-26 10:44:20 +00:00
|
|
|
clc->hdr.typev1 = SMC_TYPE_D;
|
2023-01-23 18:17:50 +00:00
|
|
|
clc->d0.gid =
|
|
|
|
conn->lgr->smcd->ops->get_local_gid(conn->lgr->smcd);
|
2020-09-10 16:48:23 +00:00
|
|
|
clc->d0.token = conn->rmb_desc->token;
|
2023-08-04 17:06:23 +00:00
|
|
|
clc->d0.dmbe_size = conn->rmbe_size_comp;
|
2020-09-10 16:48:23 +00:00
|
|
|
clc->d0.dmbe_idx = 0;
|
|
|
|
memcpy(&clc->d0.linkid, conn->lgr->id, SMC_LGR_ID_SIZE);
|
2020-09-26 10:44:30 +00:00
|
|
|
if (version == SMC_V1) {
|
|
|
|
clc->hdr.length = htons(SMCD_CLC_ACCEPT_CONFIRM_LEN);
|
|
|
|
} else {
|
2021-10-16 09:37:45 +00:00
|
|
|
clc_v2->d1.chid =
|
|
|
|
htons(smc_ism_get_chid(conn->lgr->smcd));
|
|
|
|
if (eid && eid[0])
|
|
|
|
memcpy(clc_v2->d1.eid, eid, SMC_MAX_EID_LEN);
|
2020-09-26 10:44:31 +00:00
|
|
|
len = SMCD_CLC_ACCEPT_CONFIRM_LEN_V2;
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
if (first_contact) {
|
|
|
|
fce_len = smc_clc_fill_fce(&fce, ini);
|
|
|
|
len += fce_len;
|
|
|
|
}
|
2020-09-26 10:44:31 +00:00
|
|
|
clc_v2->hdr.length = htons(len);
|
2020-09-26 10:44:30 +00:00
|
|
|
}
|
2020-09-26 10:44:22 +00:00
|
|
|
memcpy(trl.eyecatcher, SMCD_EYECATCHER,
|
2018-06-28 17:05:09 +00:00
|
|
|
sizeof(SMCD_EYECATCHER));
|
|
|
|
} else {
|
2020-09-10 16:48:23 +00:00
|
|
|
struct smc_link *link = conn->lnk;
|
|
|
|
|
2018-06-28 17:05:09 +00:00
|
|
|
/* SMC-R specific settings */
|
2020-09-10 16:48:23 +00:00
|
|
|
memcpy(clc->hdr.eyecatcher, SMC_EYECATCHER,
|
2018-06-28 17:05:09 +00:00
|
|
|
sizeof(SMC_EYECATCHER));
|
2020-09-26 10:44:20 +00:00
|
|
|
clc->hdr.typev1 = SMC_TYPE_R;
|
2020-09-10 16:48:23 +00:00
|
|
|
clc->hdr.length = htons(SMCR_CLC_ACCEPT_CONFIRM_LEN);
|
|
|
|
memcpy(clc->r0.lcl.id_for_peer, local_systemid,
|
2018-06-28 17:05:09 +00:00
|
|
|
sizeof(local_systemid));
|
2020-09-10 16:48:23 +00:00
|
|
|
memcpy(&clc->r0.lcl.gid, link->gid, SMC_GID_SIZE);
|
|
|
|
memcpy(&clc->r0.lcl.mac, &link->smcibdev->mac[link->ibport - 1],
|
2018-06-28 17:05:09 +00:00
|
|
|
ETH_ALEN);
|
2020-09-10 16:48:23 +00:00
|
|
|
hton24(clc->r0.qpn, link->roce_qp->qp_num);
|
|
|
|
clc->r0.rmb_rkey =
|
net/smc: Allow virtually contiguous sndbufs or RMBs for SMC-R
On long-running enterprise production servers, high-order contiguous
memory pages are usually very rare and in most cases we can only get
fragmented pages.
When replacing TCP with SMC-R in such production scenarios, attempting
to allocate high-order physically contiguous sndbufs and RMBs may result
in frequent memory compaction, which will cause unexpected hung issue
and further stability risks.
So this patch is aimed to allow SMC-R link group to use virtually
contiguous sndbufs and RMBs to avoid potential issues mentioned above.
Whether to use physically or virtually contiguous buffers can be set
by sysctl smcr_buf_type.
Note that using virtually contiguous buffers will bring an acceptable
performance regression, which can be mainly divided into two parts:
1) regression in data path, which is brought by additional address
translation of sndbuf by RNIC in Tx. But in general, translating
address through MTT is fast.
Taking 256KB sndbuf and RMB as an example, the comparisons in qperf
latency and bandwidth test with physically and virtually contiguous
buffers are as follows:
- client:
smc_run taskset -c <cpu> qperf <server> -oo msg_size:1:64K:*2\
-t 5 -vu tcp_{bw|lat}
- server:
smc_run taskset -c <cpu> qperf
[latency]
msgsize tcp smcr smcr-use-virt-buf
1 11.17 us 7.56 us 7.51 us (-0.67%)
2 10.65 us 7.74 us 7.56 us (-2.31%)
4 11.11 us 7.52 us 7.59 us ( 0.84%)
8 10.83 us 7.55 us 7.51 us (-0.48%)
16 11.21 us 7.46 us 7.51 us ( 0.71%)
32 10.65 us 7.53 us 7.58 us ( 0.61%)
64 10.95 us 7.74 us 7.80 us ( 0.76%)
128 11.14 us 7.83 us 7.87 us ( 0.47%)
256 10.97 us 7.94 us 7.92 us (-0.28%)
512 11.23 us 7.94 us 8.20 us ( 3.25%)
1024 11.60 us 8.12 us 8.20 us ( 0.96%)
2048 14.04 us 8.30 us 8.51 us ( 2.49%)
4096 16.88 us 9.13 us 9.07 us (-0.64%)
8192 22.50 us 10.56 us 11.22 us ( 6.26%)
16384 28.99 us 12.88 us 13.83 us ( 7.37%)
32768 40.13 us 16.76 us 16.95 us ( 1.16%)
65536 68.70 us 24.68 us 24.85 us ( 0.68%)
[bandwidth]
msgsize tcp smcr smcr-use-virt-buf
1 1.65 MB/s 1.59 MB/s 1.53 MB/s (-3.88%)
2 3.32 MB/s 3.17 MB/s 3.08 MB/s (-2.67%)
4 6.66 MB/s 6.33 MB/s 6.09 MB/s (-3.85%)
8 13.67 MB/s 13.45 MB/s 11.97 MB/s (-10.99%)
16 25.36 MB/s 27.15 MB/s 24.16 MB/s (-11.01%)
32 48.22 MB/s 54.24 MB/s 49.41 MB/s (-8.89%)
64 106.79 MB/s 107.32 MB/s 99.05 MB/s (-7.71%)
128 210.21 MB/s 202.46 MB/s 201.02 MB/s (-0.71%)
256 400.81 MB/s 416.81 MB/s 393.52 MB/s (-5.59%)
512 746.49 MB/s 834.12 MB/s 809.99 MB/s (-2.89%)
1024 1292.33 MB/s 1641.96 MB/s 1571.82 MB/s (-4.27%)
2048 2007.64 MB/s 2760.44 MB/s 2717.68 MB/s (-1.55%)
4096 2665.17 MB/s 4157.44 MB/s 4070.76 MB/s (-2.09%)
8192 3159.72 MB/s 4361.57 MB/s 4270.65 MB/s (-2.08%)
16384 4186.70 MB/s 4574.13 MB/s 4501.17 MB/s (-1.60%)
32768 4093.21 MB/s 4487.42 MB/s 4322.43 MB/s (-3.68%)
65536 4057.14 MB/s 4735.61 MB/s 4555.17 MB/s (-3.81%)
2) regression in buffer initialization and destruction path, which is
brought by additional MR operations of sndbufs. But thanks to link
group buffer reuse mechanism, the impact of this kind of regression
decreases as times of buffer reuse increases.
Taking 256KB sndbuf and RMB as an example, latency of some key SMC-R
buffer-related function obtained by bpftrace are as follows:
Function Phys-bufs Virt-bufs
smcr_new_buf_create() 67154 ns 79164 ns
smc_ib_buf_map_sg() 525 ns 928 ns
smc_ib_get_memory_region() 162294 ns 161191 ns
smc_wr_reg_send() 9957 ns 9635 ns
smc_ib_put_memory_region() 203548 ns 198374 ns
smc_ib_buf_unmap_sg() 508 ns 1158 ns
------------
Test environment notes:
1. Above tests run on 2 VMs within the same Host.
2. The NIC is ConnectX-4Lx, using SRIOV and passing through 2 VFs to
the each VM respectively.
3. VMs' vCPUs are binded to different physical CPUs, and the binded
physical CPUs are isolated by `isolcpus=xxx` cmdline.
4. NICs' queue number are set to 1.
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-07-14 09:44:04 +00:00
|
|
|
htonl(conn->rmb_desc->mr[link->link_idx]->rkey);
|
2020-09-10 16:48:23 +00:00
|
|
|
clc->r0.rmbe_idx = 1; /* for now: 1 RMB = 1 RMBE */
|
|
|
|
clc->r0.rmbe_alert_token = htonl(conn->alert_token_local);
|
|
|
|
switch (clc->hdr.type) {
|
|
|
|
case SMC_CLC_ACCEPT:
|
|
|
|
clc->r0.qp_mtu = link->path_mtu;
|
|
|
|
break;
|
|
|
|
case SMC_CLC_CONFIRM:
|
|
|
|
clc->r0.qp_mtu = min(link->path_mtu, link->peer_mtu);
|
|
|
|
break;
|
|
|
|
}
|
2023-08-04 17:06:23 +00:00
|
|
|
clc->r0.rmbe_size = conn->rmbe_size_comp;
|
net/smc: Allow virtually contiguous sndbufs or RMBs for SMC-R
On long-running enterprise production servers, high-order contiguous
memory pages are usually very rare and in most cases we can only get
fragmented pages.
When replacing TCP with SMC-R in such production scenarios, attempting
to allocate high-order physically contiguous sndbufs and RMBs may result
in frequent memory compaction, which will cause unexpected hung issue
and further stability risks.
So this patch is aimed to allow SMC-R link group to use virtually
contiguous sndbufs and RMBs to avoid potential issues mentioned above.
Whether to use physically or virtually contiguous buffers can be set
by sysctl smcr_buf_type.
Note that using virtually contiguous buffers will bring an acceptable
performance regression, which can be mainly divided into two parts:
1) regression in data path, which is brought by additional address
translation of sndbuf by RNIC in Tx. But in general, translating
address through MTT is fast.
Taking 256KB sndbuf and RMB as an example, the comparisons in qperf
latency and bandwidth test with physically and virtually contiguous
buffers are as follows:
- client:
smc_run taskset -c <cpu> qperf <server> -oo msg_size:1:64K:*2\
-t 5 -vu tcp_{bw|lat}
- server:
smc_run taskset -c <cpu> qperf
[latency]
msgsize tcp smcr smcr-use-virt-buf
1 11.17 us 7.56 us 7.51 us (-0.67%)
2 10.65 us 7.74 us 7.56 us (-2.31%)
4 11.11 us 7.52 us 7.59 us ( 0.84%)
8 10.83 us 7.55 us 7.51 us (-0.48%)
16 11.21 us 7.46 us 7.51 us ( 0.71%)
32 10.65 us 7.53 us 7.58 us ( 0.61%)
64 10.95 us 7.74 us 7.80 us ( 0.76%)
128 11.14 us 7.83 us 7.87 us ( 0.47%)
256 10.97 us 7.94 us 7.92 us (-0.28%)
512 11.23 us 7.94 us 8.20 us ( 3.25%)
1024 11.60 us 8.12 us 8.20 us ( 0.96%)
2048 14.04 us 8.30 us 8.51 us ( 2.49%)
4096 16.88 us 9.13 us 9.07 us (-0.64%)
8192 22.50 us 10.56 us 11.22 us ( 6.26%)
16384 28.99 us 12.88 us 13.83 us ( 7.37%)
32768 40.13 us 16.76 us 16.95 us ( 1.16%)
65536 68.70 us 24.68 us 24.85 us ( 0.68%)
[bandwidth]
msgsize tcp smcr smcr-use-virt-buf
1 1.65 MB/s 1.59 MB/s 1.53 MB/s (-3.88%)
2 3.32 MB/s 3.17 MB/s 3.08 MB/s (-2.67%)
4 6.66 MB/s 6.33 MB/s 6.09 MB/s (-3.85%)
8 13.67 MB/s 13.45 MB/s 11.97 MB/s (-10.99%)
16 25.36 MB/s 27.15 MB/s 24.16 MB/s (-11.01%)
32 48.22 MB/s 54.24 MB/s 49.41 MB/s (-8.89%)
64 106.79 MB/s 107.32 MB/s 99.05 MB/s (-7.71%)
128 210.21 MB/s 202.46 MB/s 201.02 MB/s (-0.71%)
256 400.81 MB/s 416.81 MB/s 393.52 MB/s (-5.59%)
512 746.49 MB/s 834.12 MB/s 809.99 MB/s (-2.89%)
1024 1292.33 MB/s 1641.96 MB/s 1571.82 MB/s (-4.27%)
2048 2007.64 MB/s 2760.44 MB/s 2717.68 MB/s (-1.55%)
4096 2665.17 MB/s 4157.44 MB/s 4070.76 MB/s (-2.09%)
8192 3159.72 MB/s 4361.57 MB/s 4270.65 MB/s (-2.08%)
16384 4186.70 MB/s 4574.13 MB/s 4501.17 MB/s (-1.60%)
32768 4093.21 MB/s 4487.42 MB/s 4322.43 MB/s (-3.68%)
65536 4057.14 MB/s 4735.61 MB/s 4555.17 MB/s (-3.81%)
2) regression in buffer initialization and destruction path, which is
brought by additional MR operations of sndbufs. But thanks to link
group buffer reuse mechanism, the impact of this kind of regression
decreases as times of buffer reuse increases.
Taking 256KB sndbuf and RMB as an example, latency of some key SMC-R
buffer-related function obtained by bpftrace are as follows:
Function Phys-bufs Virt-bufs
smcr_new_buf_create() 67154 ns 79164 ns
smc_ib_buf_map_sg() 525 ns 928 ns
smc_ib_get_memory_region() 162294 ns 161191 ns
smc_wr_reg_send() 9957 ns 9635 ns
smc_ib_put_memory_region() 203548 ns 198374 ns
smc_ib_buf_unmap_sg() 508 ns 1158 ns
------------
Test environment notes:
1. Above tests run on 2 VMs within the same Host.
2. The NIC is ConnectX-4Lx, using SRIOV and passing through 2 VFs to
the each VM respectively.
3. VMs' vCPUs are binded to different physical CPUs, and the binded
physical CPUs are isolated by `isolcpus=xxx` cmdline.
4. NICs' queue number are set to 1.
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-07-14 09:44:04 +00:00
|
|
|
clc->r0.rmb_dma_addr = conn->rmb_desc->is_vm ?
|
|
|
|
cpu_to_be64((uintptr_t)conn->rmb_desc->cpu_addr) :
|
|
|
|
cpu_to_be64((u64)sg_dma_address
|
|
|
|
(conn->rmb_desc->sgt[link->link_idx].sgl));
|
2020-09-10 16:48:23 +00:00
|
|
|
hton24(clc->r0.psn, link->psn_initial);
|
2021-10-16 09:37:45 +00:00
|
|
|
if (version == SMC_V1) {
|
|
|
|
clc->hdr.length = htons(SMCR_CLC_ACCEPT_CONFIRM_LEN);
|
|
|
|
} else {
|
|
|
|
if (eid && eid[0])
|
|
|
|
memcpy(clc_v2->r1.eid, eid, SMC_MAX_EID_LEN);
|
|
|
|
len = SMCR_CLC_ACCEPT_CONFIRM_LEN_V2;
|
|
|
|
if (first_contact) {
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
fce_len = smc_clc_fill_fce(&fce, ini);
|
|
|
|
len += fce_len;
|
|
|
|
fce.fce_v2_base.v2_direct = !link->lgr->uses_gateway;
|
2023-08-17 13:20:27 +00:00
|
|
|
if (clc->hdr.type == SMC_CLC_CONFIRM) {
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
memset(&gle, 0, sizeof(gle));
|
2021-10-16 09:37:45 +00:00
|
|
|
gle.gid_cnt = ini->smcrv2.gidlist.len;
|
|
|
|
len += sizeof(gle);
|
|
|
|
len += gle.gid_cnt * sizeof(gle.gid[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clc_v2->hdr.length = htons(len);
|
|
|
|
}
|
2020-09-26 10:44:22 +00:00
|
|
|
memcpy(trl.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER));
|
2018-06-28 17:05:09 +00:00
|
|
|
}
|
2017-01-09 15:55:16 +00:00
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
2020-09-26 10:44:22 +00:00
|
|
|
i = 0;
|
2020-09-26 10:44:30 +00:00
|
|
|
vec[i].iov_base = clc_v2;
|
|
|
|
if (version > SMC_V1)
|
2021-10-16 09:37:45 +00:00
|
|
|
vec[i++].iov_len = (clc->hdr.typev1 == SMC_TYPE_D ?
|
|
|
|
SMCD_CLC_ACCEPT_CONFIRM_LEN_V2 :
|
|
|
|
SMCR_CLC_ACCEPT_CONFIRM_LEN_V2) -
|
|
|
|
sizeof(trl);
|
2020-09-26 10:44:30 +00:00
|
|
|
else
|
|
|
|
vec[i++].iov_len = (clc->hdr.typev1 == SMC_TYPE_D ?
|
|
|
|
SMCD_CLC_ACCEPT_CONFIRM_LEN :
|
|
|
|
SMCR_CLC_ACCEPT_CONFIRM_LEN) -
|
|
|
|
sizeof(trl);
|
2020-09-26 10:44:31 +00:00
|
|
|
if (version > SMC_V1 && first_contact) {
|
|
|
|
vec[i].iov_base = &fce;
|
net/smc: add vendor unique experimental options area in clc handshake
Add vendor unique experimental options area in clc handshake. In clc
accept and confirm msg, vendor unique experimental options use the
16-Bytes reserved field, which defined in struct smc_clc_fce_gid_ext
in previous version. Because of the struct smc_clc_first_contact_ext
is widely used and limit the scope of modification, this patch moves
the 16-Bytes reserved field out of struct smc_clc_fce_gid_ext, and
followed with the struct smc_clc_first_contact_ext in a new struct
names struct smc_clc_first_contact_ext_v2x.
For SMC-R first connection, in previous version, the struct smc_clc_
first_contact_ext and the 16-Bytes reserved field has already been
included in clc accept and confirm msg. Thus, this patch use struct
smc_clc_first_contact_ext_v2x instead of the struct smc_clc_first_
contact_ext and the 16-Bytes reserved field in SMC-R clc accept and
confirm msg is compatible with previous version.
For SMC-D first connection, in previous version, only the struct smc_
clc_first_contact_ext is included in clc accept and confirm msg, and
the 16-Bytes reserved field is not included. Thus, when the negotiated
smc release version is the version before v2.1, we still use struct
smc_clc_first_contact_ext for compatible consideration. If the negotiated
smc release version is v2.1 or later, use struct smc_clc_first_contact_
ext_v2x instead.
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-17 13:20:28 +00:00
|
|
|
vec[i++].iov_len = fce_len;
|
2021-10-16 09:37:45 +00:00
|
|
|
if (!conn->lgr->is_smcd) {
|
|
|
|
if (clc->hdr.type == SMC_CLC_CONFIRM) {
|
|
|
|
vec[i].iov_base = &gle;
|
|
|
|
vec[i++].iov_len = sizeof(gle);
|
|
|
|
vec[i].iov_base = &ini->smcrv2.gidlist.list;
|
|
|
|
vec[i++].iov_len = gle.gid_cnt *
|
|
|
|
sizeof(gle.gid[0]);
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 10:44:31 +00:00
|
|
|
}
|
2020-09-26 10:44:22 +00:00
|
|
|
vec[i].iov_base = &trl;
|
|
|
|
vec[i++].iov_len = sizeof(trl);
|
|
|
|
return kernel_sendmsg(smc->clcsock, &msg, vec, 1,
|
2020-09-10 16:48:23 +00:00
|
|
|
ntohs(clc->hdr.length));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send CLC CONFIRM message across internal TCP socket */
|
2020-09-26 10:44:30 +00:00
|
|
|
int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact,
|
2021-10-16 09:37:45 +00:00
|
|
|
u8 version, u8 *eid, struct smc_init_info *ini)
|
2020-09-10 16:48:23 +00:00
|
|
|
{
|
2020-09-26 10:44:30 +00:00
|
|
|
struct smc_clc_msg_accept_confirm_v2 cclc_v2;
|
2020-09-10 16:48:23 +00:00
|
|
|
int reason_code = 0;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* send SMC Confirm CLC msg */
|
2020-09-26 10:44:30 +00:00
|
|
|
memset(&cclc_v2, 0, sizeof(cclc_v2));
|
|
|
|
cclc_v2.hdr.type = SMC_CLC_CONFIRM;
|
|
|
|
len = smc_clc_send_confirm_accept(smc, &cclc_v2, clnt_first_contact,
|
2021-10-16 09:37:45 +00:00
|
|
|
version, eid, ini);
|
2020-09-26 10:44:30 +00:00
|
|
|
if (len < ntohs(cclc_v2.hdr.length)) {
|
2017-01-09 15:55:16 +00:00
|
|
|
if (len >= 0) {
|
|
|
|
reason_code = -ENETUNREACH;
|
|
|
|
smc->sk.sk_err = -reason_code;
|
|
|
|
} else {
|
|
|
|
smc->sk.sk_err = smc->clcsock->sk->sk_err;
|
|
|
|
reason_code = -smc->sk.sk_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reason_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send CLC ACCEPT message across internal TCP socket */
|
2020-09-26 10:44:30 +00:00
|
|
|
int smc_clc_send_accept(struct smc_sock *new_smc, bool srv_first_contact,
|
2023-08-17 13:20:27 +00:00
|
|
|
u8 version, u8 *negotiated_eid, struct smc_init_info *ini)
|
2017-01-09 15:55:16 +00:00
|
|
|
{
|
2020-09-26 10:44:30 +00:00
|
|
|
struct smc_clc_msg_accept_confirm_v2 aclc_v2;
|
2017-01-09 15:55:16 +00:00
|
|
|
int len;
|
|
|
|
|
2020-09-26 10:44:30 +00:00
|
|
|
memset(&aclc_v2, 0, sizeof(aclc_v2));
|
|
|
|
aclc_v2.hdr.type = SMC_CLC_ACCEPT;
|
|
|
|
len = smc_clc_send_confirm_accept(new_smc, &aclc_v2, srv_first_contact,
|
2023-08-17 13:20:27 +00:00
|
|
|
version, negotiated_eid, ini);
|
2020-09-26 10:44:30 +00:00
|
|
|
if (len < ntohs(aclc_v2.hdr.length))
|
2018-11-22 09:26:36 +00:00
|
|
|
len = len >= 0 ? -EPROTO : -new_smc->clcsock->sk->sk_err;
|
2017-01-09 15:55:16 +00:00
|
|
|
|
2018-11-22 09:26:36 +00:00
|
|
|
return len > 0 ? 0 : len;
|
2017-01-09 15:55:16 +00:00
|
|
|
}
|
2020-09-26 10:44:31 +00:00
|
|
|
|
2020-12-01 19:20:44 +00:00
|
|
|
void smc_clc_get_hostname(u8 **host)
|
|
|
|
{
|
|
|
|
*host = &smc_hostname[0];
|
|
|
|
}
|
|
|
|
|
2020-09-26 10:44:31 +00:00
|
|
|
void __init smc_clc_init(void)
|
|
|
|
{
|
|
|
|
struct new_utsname *u;
|
|
|
|
|
|
|
|
memset(smc_hostname, _S, sizeof(smc_hostname)); /* ASCII blanks */
|
|
|
|
u = utsname();
|
|
|
|
memcpy(smc_hostname, u->nodename,
|
|
|
|
min_t(size_t, strlen(u->nodename), sizeof(smc_hostname)));
|
2021-09-14 08:35:05 +00:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&smc_clc_eid_table.list);
|
|
|
|
rwlock_init(&smc_clc_eid_table.lock);
|
|
|
|
smc_clc_eid_table.ueid_cnt = 0;
|
|
|
|
smc_clc_eid_table.seid_enabled = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smc_clc_exit(void)
|
|
|
|
{
|
|
|
|
smc_clc_ueid_remove(NULL);
|
2020-09-26 10:44:31 +00:00
|
|
|
}
|