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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-01-09 23:55:14 +08:00
|
|
|
/*
|
|
|
|
* Shared Memory Communications over RDMA (SMC-R) and RoCE
|
|
|
|
*
|
|
|
|
* IB infrastructure:
|
|
|
|
* Establish SMC-R as an Infiniband Client to be notified about added and
|
|
|
|
* removed IB devices of type RDMA.
|
|
|
|
* Determine device and port characteristics for these IB devices.
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2016
|
|
|
|
*
|
|
|
|
* Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2021-12-29 08:49:13 +08:00
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/if_vlan.h>
|
2017-01-09 23:55:14 +08:00
|
|
|
#include <linux/random.h>
|
2017-01-09 23:55:20 +08:00
|
|
|
#include <linux/workqueue.h>
|
2017-07-28 19:56:22 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2019-11-17 00:47:29 +08:00
|
|
|
#include <linux/wait.h>
|
2020-07-08 23:05:13 +08:00
|
|
|
#include <linux/mutex.h>
|
2021-10-16 17:37:48 +08:00
|
|
|
#include <linux/inetdevice.h>
|
2017-01-09 23:55:14 +08:00
|
|
|
#include <rdma/ib_verbs.h>
|
2018-06-05 13:40:19 +08:00
|
|
|
#include <rdma/ib_cache.h>
|
2017-01-09 23:55:14 +08:00
|
|
|
|
2017-01-09 23:55:15 +08:00
|
|
|
#include "smc_pnet.h"
|
2017-01-09 23:55:14 +08:00
|
|
|
#include "smc_ib.h"
|
2017-01-09 23:55:18 +08:00
|
|
|
#include "smc_core.h"
|
2017-01-09 23:55:19 +08:00
|
|
|
#include "smc_wr.h"
|
2017-01-09 23:55:14 +08:00
|
|
|
#include "smc.h"
|
2020-12-02 03:20:49 +08:00
|
|
|
#include "smc_netlink.h"
|
2017-01-09 23:55:14 +08:00
|
|
|
|
net/smc: pay attention to MAX_ORDER for CQ entries
smc allocates a certain number of CQ entries for used RoCE devices. For
mlx5 devices the chosen constant number results in a large allocation
causing this warning:
[13355.124656] WARNING: CPU: 3 PID: 16535 at mm/page_alloc.c:3883 __alloc_pages_nodemask+0x2be/0x10c0
[13355.124657] Modules linked in: smc_diag(O) smc(O) xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp bridge stp llc ip6table_filter ip6_tables iptable_filter mlx5_ib ib_core sunrpc mlx5_core s390_trng rng_core ghash_s390 prng aes_s390 des_s390 des_generic sha512_s390 sha256_s390 sha1_s390 sha_common ptp pps_core eadm_sch dm_multipath dm_mod vhost_net tun vhost tap sch_fq_codel kvm ip_tables x_tables autofs4 [last unloaded: smc]
[13355.124672] CPU: 3 PID: 16535 Comm: kworker/3:0 Tainted: G O 4.14.0uschi #1
[13355.124673] Hardware name: IBM 3906 M04 704 (LPAR)
[13355.124675] Workqueue: events smc_listen_work [smc]
[13355.124677] task: 00000000e2f22100 task.stack: 0000000084720000
[13355.124678] Krnl PSW : 0704c00180000000 000000000029da76 (__alloc_pages_nodemask+0x2be/0x10c0)
[13355.124681] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[13355.124682] Krnl GPRS: 0000000000000000 00550e00014080c0 0000000000000000 0000000000000001
[13355.124684] 000000000029d8b6 00000000f3bfd710 0000000000000000 00000000014080c0
[13355.124685] 0000000000000009 00000000ec277a00 0000000000200000 0000000000000000
[13355.124686] 0000000000000000 00000000000001ff 000000000029d8b6 0000000084723720
[13355.124708] Krnl Code: 000000000029da6a: a7110200 tmll %r1,512
000000000029da6e: a774ff29 brc 7,29d8c0
#000000000029da72: a7f40001 brc 15,29da74
>000000000029da76: a7f4ff25 brc 15,29d8c0
000000000029da7a: a7380000 lhi %r3,0
000000000029da7e: a7f4fef1 brc 15,29d860
000000000029da82: 5820f0c4 l %r2,196(%r15)
000000000029da86: a53e0048 llilh %r3,72
[13355.124720] Call Trace:
[13355.124722] ([<000000000029d8b6>] __alloc_pages_nodemask+0xfe/0x10c0)
[13355.124724] [<000000000013bd1e>] s390_dma_alloc+0x6e/0x148
[13355.124733] [<000003ff802eeba6>] mlx5_dma_zalloc_coherent_node+0x8e/0xe0 [mlx5_core]
[13355.124740] [<000003ff802eee18>] mlx5_buf_alloc_node+0x70/0x108 [mlx5_core]
[13355.124744] [<000003ff804eb410>] mlx5_ib_create_cq+0x558/0x898 [mlx5_ib]
[13355.124749] [<000003ff80407d40>] ib_create_cq+0x48/0x88 [ib_core]
[13355.124751] [<000003ff80109fba>] smc_ib_setup_per_ibdev+0x52/0x118 [smc]
[13355.124753] [<000003ff8010bcb6>] smc_conn_create+0x65e/0x728 [smc]
[13355.124755] [<000003ff801081a2>] smc_listen_work+0x2d2/0x540 [smc]
[13355.124756] [<0000000000162c66>] process_one_work+0x1be/0x440
[13355.124758] [<0000000000162f40>] worker_thread+0x58/0x458
[13355.124759] [<0000000000169e7e>] kthread+0x14e/0x168
[13355.124760] [<00000000009ce8be>] kernel_thread_starter+0x6/0xc
[13355.124762] [<00000000009ce8b8>] kernel_thread_starter+0x0/0xc
[13355.124762] Last Breaking-Event-Address:
[13355.124764] [<000000000029da72>] __alloc_pages_nodemask+0x2ba/0x10c0
[13355.124764] ---[ end trace 34be38b581c0b585 ]---
This patch reduces the smc constant for the maximum number of allocated
completion queue entries SMC_MAX_CQE by 2 to avoid high round up values
in the mlx5 code, and reduces the number of allocated completion queue
entries even more, if the final allocation for an mlx5 device hits the
MAX_ORDER limit.
Reported-by: Ihnken Menssen <menssen@de.ibm.com>
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-14 18:01:00 +08:00
|
|
|
#define SMC_MAX_CQE 32766 /* max. # of completion queue elements */
|
|
|
|
|
2017-01-09 23:55:20 +08:00
|
|
|
#define SMC_QP_MIN_RNR_TIMER 5
|
|
|
|
#define SMC_QP_TIMEOUT 15 /* 4096 * 2 ** timeout usec */
|
|
|
|
#define SMC_QP_RETRY_CNT 7 /* 7: infinite */
|
|
|
|
#define SMC_QP_RNR_RETRY 7 /* 7: infinite */
|
|
|
|
|
2017-01-09 23:55:14 +08:00
|
|
|
struct smc_ib_devices smc_ib_devices = { /* smc-registered ib devices */
|
2020-07-08 23:05:13 +08:00
|
|
|
.mutex = __MUTEX_INITIALIZER(smc_ib_devices.mutex),
|
2017-01-09 23:55:14 +08:00
|
|
|
.list = LIST_HEAD_INIT(smc_ib_devices.list),
|
|
|
|
};
|
|
|
|
|
2020-02-26 05:41:21 +08:00
|
|
|
u8 local_systemid[SMC_SYSTEMID_LEN]; /* unique system identifier */
|
2017-01-09 23:55:14 +08:00
|
|
|
|
2017-01-09 23:55:20 +08:00
|
|
|
static int smc_ib_modify_qp_init(struct smc_link *lnk)
|
|
|
|
{
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
|
|
|
|
memset(&qp_attr, 0, sizeof(qp_attr));
|
|
|
|
qp_attr.qp_state = IB_QPS_INIT;
|
|
|
|
qp_attr.pkey_index = 0;
|
|
|
|
qp_attr.port_num = lnk->ibport;
|
|
|
|
qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE
|
|
|
|
| IB_ACCESS_REMOTE_WRITE;
|
|
|
|
return ib_modify_qp(lnk->roce_qp, &qp_attr,
|
|
|
|
IB_QP_STATE | IB_QP_PKEY_INDEX |
|
|
|
|
IB_QP_ACCESS_FLAGS | IB_QP_PORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smc_ib_modify_qp_rtr(struct smc_link *lnk)
|
|
|
|
{
|
|
|
|
enum ib_qp_attr_mask qp_attr_mask =
|
|
|
|
IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU | IB_QP_DEST_QPN |
|
|
|
|
IB_QP_RQ_PSN | IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER;
|
|
|
|
struct ib_qp_attr qp_attr;
|
2021-10-16 17:37:48 +08:00
|
|
|
u8 hop_lim = 1;
|
2017-01-09 23:55:20 +08:00
|
|
|
|
|
|
|
memset(&qp_attr, 0, sizeof(qp_attr));
|
|
|
|
qp_attr.qp_state = IB_QPS_RTR;
|
|
|
|
qp_attr.path_mtu = min(lnk->path_mtu, lnk->peer_mtu);
|
2017-04-30 02:41:29 +08:00
|
|
|
qp_attr.ah_attr.type = RDMA_AH_ATTR_TYPE_ROCE;
|
2017-04-30 02:41:28 +08:00
|
|
|
rdma_ah_set_port_num(&qp_attr.ah_attr, lnk->ibport);
|
2021-10-16 17:37:48 +08:00
|
|
|
if (lnk->lgr->smc_version == SMC_V2 && lnk->lgr->uses_gateway)
|
|
|
|
hop_lim = IPV6_DEFAULT_HOPLIMIT;
|
|
|
|
rdma_ah_set_grh(&qp_attr.ah_attr, NULL, 0, lnk->sgid_index, hop_lim, 0);
|
2017-04-30 02:41:28 +08:00
|
|
|
rdma_ah_set_dgid_raw(&qp_attr.ah_attr, lnk->peer_gid);
|
2021-10-16 17:37:48 +08:00
|
|
|
if (lnk->lgr->smc_version == SMC_V2 && lnk->lgr->uses_gateway)
|
|
|
|
memcpy(&qp_attr.ah_attr.roce.dmac, lnk->lgr->nexthop_mac,
|
|
|
|
sizeof(lnk->lgr->nexthop_mac));
|
|
|
|
else
|
|
|
|
memcpy(&qp_attr.ah_attr.roce.dmac, lnk->peer_mac,
|
|
|
|
sizeof(lnk->peer_mac));
|
2017-01-09 23:55:20 +08:00
|
|
|
qp_attr.dest_qp_num = lnk->peer_qpn;
|
|
|
|
qp_attr.rq_psn = lnk->peer_psn; /* starting receive packet seq # */
|
|
|
|
qp_attr.max_dest_rd_atomic = 1; /* max # of resources for incoming
|
|
|
|
* requests
|
|
|
|
*/
|
|
|
|
qp_attr.min_rnr_timer = SMC_QP_MIN_RNR_TIMER;
|
|
|
|
|
|
|
|
return ib_modify_qp(lnk->roce_qp, &qp_attr, qp_attr_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_ib_modify_qp_rts(struct smc_link *lnk)
|
|
|
|
{
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
|
|
|
|
memset(&qp_attr, 0, sizeof(qp_attr));
|
|
|
|
qp_attr.qp_state = IB_QPS_RTS;
|
|
|
|
qp_attr.timeout = SMC_QP_TIMEOUT; /* local ack timeout */
|
|
|
|
qp_attr.retry_cnt = SMC_QP_RETRY_CNT; /* retry count */
|
|
|
|
qp_attr.rnr_retry = SMC_QP_RNR_RETRY; /* RNR retries, 7=infinite */
|
|
|
|
qp_attr.sq_psn = lnk->psn_initial; /* starting send packet seq # */
|
|
|
|
qp_attr.max_rd_atomic = 1; /* # of outstanding RDMA reads and
|
|
|
|
* atomic ops allowed
|
|
|
|
*/
|
|
|
|
return ib_modify_qp(lnk->roce_qp, &qp_attr,
|
|
|
|
IB_QP_STATE | IB_QP_TIMEOUT | IB_QP_RETRY_CNT |
|
|
|
|
IB_QP_SQ_PSN | IB_QP_RNR_RETRY |
|
|
|
|
IB_QP_MAX_QP_RD_ATOMIC);
|
|
|
|
}
|
|
|
|
|
net/smc: fix kernel panic caused by race of smc_sock
A crash occurs when smc_cdc_tx_handler() tries to access smc_sock
but smc_release() has already freed it.
[ 4570.695099] BUG: unable to handle page fault for address: 000000002eae9e88
[ 4570.696048] #PF: supervisor write access in kernel mode
[ 4570.696728] #PF: error_code(0x0002) - not-present page
[ 4570.697401] PGD 0 P4D 0
[ 4570.697716] Oops: 0002 [#1] PREEMPT SMP NOPTI
[ 4570.698228] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-rc4+ #111
[ 4570.699013] Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS 8c24b4c 04/0
[ 4570.699933] RIP: 0010:_raw_spin_lock+0x1a/0x30
<...>
[ 4570.711446] Call Trace:
[ 4570.711746] <IRQ>
[ 4570.711992] smc_cdc_tx_handler+0x41/0xc0
[ 4570.712470] smc_wr_tx_tasklet_fn+0x213/0x560
[ 4570.712981] ? smc_cdc_tx_dismisser+0x10/0x10
[ 4570.713489] tasklet_action_common.isra.17+0x66/0x140
[ 4570.714083] __do_softirq+0x123/0x2f4
[ 4570.714521] irq_exit_rcu+0xc4/0xf0
[ 4570.714934] common_interrupt+0xba/0xe0
Though smc_cdc_tx_handler() checked the existence of smc connection,
smc_release() may have already dismissed and released the smc socket
before smc_cdc_tx_handler() further visits it.
smc_cdc_tx_handler() |smc_release()
if (!conn) |
|
|smc_cdc_tx_dismiss_slots()
| smc_cdc_tx_dismisser()
|
|sock_put(&smc->sk) <- last sock_put,
| smc_sock freed
bh_lock_sock(&smc->sk) (panic) |
To make sure we won't receive any CDC messages after we free the
smc_sock, add a refcount on the smc_connection for inflight CDC
message(posted to the QP but haven't received related CQE), and
don't release the smc_connection until all the inflight CDC messages
haven been done, for both success or failed ones.
Using refcount on CDC messages brings another problem: when the link
is going to be destroyed, smcr_link_clear() will reset the QP, which
then remove all the pending CQEs related to the QP in the CQ. To make
sure all the CQEs will always come back so the refcount on the
smc_connection can always reach 0, smc_ib_modify_qp_reset() was replaced
by smc_ib_modify_qp_error().
And remove the timeout in smc_wr_tx_wait_no_pending_sends() since we
need to wait for all pending WQEs done, or we may encounter use-after-
free when handling CQEs.
For IB device removal routine, we need to wait for all the QPs on that
device been destroyed before we can destroy CQs on the device, or
the refcount on smc_connection won't reach 0 and smc_sock cannot be
released.
Fixes: 5f08318f617b ("smc: connection data control (CDC)")
Reported-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: Dust Li <dust.li@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-12-28 17:03:25 +08:00
|
|
|
int smc_ib_modify_qp_error(struct smc_link *lnk)
|
2017-01-09 23:55:20 +08:00
|
|
|
{
|
|
|
|
struct ib_qp_attr qp_attr;
|
|
|
|
|
|
|
|
memset(&qp_attr, 0, sizeof(qp_attr));
|
net/smc: fix kernel panic caused by race of smc_sock
A crash occurs when smc_cdc_tx_handler() tries to access smc_sock
but smc_release() has already freed it.
[ 4570.695099] BUG: unable to handle page fault for address: 000000002eae9e88
[ 4570.696048] #PF: supervisor write access in kernel mode
[ 4570.696728] #PF: error_code(0x0002) - not-present page
[ 4570.697401] PGD 0 P4D 0
[ 4570.697716] Oops: 0002 [#1] PREEMPT SMP NOPTI
[ 4570.698228] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-rc4+ #111
[ 4570.699013] Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS 8c24b4c 04/0
[ 4570.699933] RIP: 0010:_raw_spin_lock+0x1a/0x30
<...>
[ 4570.711446] Call Trace:
[ 4570.711746] <IRQ>
[ 4570.711992] smc_cdc_tx_handler+0x41/0xc0
[ 4570.712470] smc_wr_tx_tasklet_fn+0x213/0x560
[ 4570.712981] ? smc_cdc_tx_dismisser+0x10/0x10
[ 4570.713489] tasklet_action_common.isra.17+0x66/0x140
[ 4570.714083] __do_softirq+0x123/0x2f4
[ 4570.714521] irq_exit_rcu+0xc4/0xf0
[ 4570.714934] common_interrupt+0xba/0xe0
Though smc_cdc_tx_handler() checked the existence of smc connection,
smc_release() may have already dismissed and released the smc socket
before smc_cdc_tx_handler() further visits it.
smc_cdc_tx_handler() |smc_release()
if (!conn) |
|
|smc_cdc_tx_dismiss_slots()
| smc_cdc_tx_dismisser()
|
|sock_put(&smc->sk) <- last sock_put,
| smc_sock freed
bh_lock_sock(&smc->sk) (panic) |
To make sure we won't receive any CDC messages after we free the
smc_sock, add a refcount on the smc_connection for inflight CDC
message(posted to the QP but haven't received related CQE), and
don't release the smc_connection until all the inflight CDC messages
haven been done, for both success or failed ones.
Using refcount on CDC messages brings another problem: when the link
is going to be destroyed, smcr_link_clear() will reset the QP, which
then remove all the pending CQEs related to the QP in the CQ. To make
sure all the CQEs will always come back so the refcount on the
smc_connection can always reach 0, smc_ib_modify_qp_reset() was replaced
by smc_ib_modify_qp_error().
And remove the timeout in smc_wr_tx_wait_no_pending_sends() since we
need to wait for all pending WQEs done, or we may encounter use-after-
free when handling CQEs.
For IB device removal routine, we need to wait for all the QPs on that
device been destroyed before we can destroy CQs on the device, or
the refcount on smc_connection won't reach 0 and smc_sock cannot be
released.
Fixes: 5f08318f617b ("smc: connection data control (CDC)")
Reported-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: Dust Li <dust.li@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-12-28 17:03:25 +08:00
|
|
|
qp_attr.qp_state = IB_QPS_ERR;
|
2017-01-09 23:55:20 +08:00
|
|
|
return ib_modify_qp(lnk->roce_qp, &qp_attr, IB_QP_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_ib_ready_link(struct smc_link *lnk)
|
|
|
|
{
|
2018-07-23 19:53:10 +08:00
|
|
|
struct smc_link_group *lgr = smc_get_lgr(lnk);
|
2017-01-09 23:55:20 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
rc = smc_ib_modify_qp_init(lnk);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rc = smc_ib_modify_qp_rtr(lnk);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
smc_wr_remember_qp_attr(lnk);
|
|
|
|
rc = ib_req_notify_cq(lnk->smcibdev->roce_cq_recv,
|
|
|
|
IB_CQ_SOLICITED_MASK);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
rc = smc_wr_rx_post_init(lnk);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
smc_wr_remember_qp_attr(lnk);
|
|
|
|
|
|
|
|
if (lgr->role == SMC_SERV) {
|
|
|
|
rc = smc_ib_modify_qp_rts(lnk);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
smc_wr_remember_qp_attr(lnk);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-07-25 22:35:31 +08:00
|
|
|
static int smc_ib_fill_mac(struct smc_ib_device *smcibdev, u8 ibport)
|
2018-06-29 01:05:04 +08:00
|
|
|
{
|
2018-08-18 06:45:51 +08:00
|
|
|
const struct ib_gid_attr *attr;
|
2019-05-02 15:48:06 +08:00
|
|
|
int rc;
|
2018-06-29 01:05:04 +08:00
|
|
|
|
2018-08-18 06:45:51 +08:00
|
|
|
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, 0);
|
|
|
|
if (IS_ERR(attr))
|
2018-06-29 01:05:04 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2019-05-02 15:48:06 +08:00
|
|
|
rc = rdma_read_gid_l2_fields(attr, NULL, smcibdev->mac[ibport - 1]);
|
2018-08-18 06:45:51 +08:00
|
|
|
rdma_put_gid_attr(attr);
|
|
|
|
return rc;
|
2018-06-29 01:05:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create an identifier unique for this instance of SMC-R.
|
|
|
|
* The MAC-address of the first active registered IB device
|
|
|
|
* plus a random 2-byte number is used to create this identifier.
|
|
|
|
* This name is delivered to the peer during connection initialization.
|
|
|
|
*/
|
|
|
|
static inline void smc_ib_define_local_systemid(struct smc_ib_device *smcibdev,
|
|
|
|
u8 ibport)
|
|
|
|
{
|
|
|
|
memcpy(&local_systemid[2], &smcibdev->mac[ibport - 1],
|
|
|
|
sizeof(smcibdev->mac[ibport - 1]));
|
2020-02-26 05:41:21 +08:00
|
|
|
}
|
|
|
|
|
2020-02-26 05:41:22 +08:00
|
|
|
bool smc_ib_is_valid_local_systemid(void)
|
2020-02-26 05:41:21 +08:00
|
|
|
{
|
|
|
|
return !is_zero_ether_addr(&local_systemid[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smc_ib_init_local_systemid(void)
|
|
|
|
{
|
2018-06-29 01:05:04 +08:00
|
|
|
get_random_bytes(&local_systemid[0], 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport)
|
|
|
|
{
|
|
|
|
return smcibdev->pattr[ibport - 1].state == IB_PORT_ACTIVE;
|
|
|
|
}
|
|
|
|
|
2023-10-11 15:48:51 +08:00
|
|
|
int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr,
|
2021-10-16 17:37:45 +08:00
|
|
|
u8 nexthop_mac[], u8 *uses_gateway)
|
|
|
|
{
|
|
|
|
struct neighbour *neigh = NULL;
|
|
|
|
struct rtable *rt = NULL;
|
|
|
|
struct flowi4 fl4 = {
|
|
|
|
.saddr = saddr,
|
|
|
|
.daddr = daddr
|
|
|
|
};
|
|
|
|
|
|
|
|
if (daddr == cpu_to_be32(INADDR_NONE))
|
|
|
|
goto out;
|
2023-10-11 15:48:51 +08:00
|
|
|
rt = ip_route_output_flow(net, &fl4, NULL);
|
2021-10-16 17:37:45 +08:00
|
|
|
if (IS_ERR(rt))
|
|
|
|
goto out;
|
|
|
|
if (rt->rt_uses_gateway && rt->rt_gw_family != AF_INET)
|
2024-05-07 20:53:31 +08:00
|
|
|
goto out_rt;
|
|
|
|
neigh = dst_neigh_lookup(&rt->dst, &fl4.daddr);
|
|
|
|
if (!neigh)
|
|
|
|
goto out_rt;
|
|
|
|
memcpy(nexthop_mac, neigh->ha, ETH_ALEN);
|
|
|
|
*uses_gateway = rt->rt_uses_gateway;
|
|
|
|
neigh_release(neigh);
|
|
|
|
ip_rt_put(rt);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_rt:
|
|
|
|
ip_rt_put(rt);
|
2021-10-16 17:37:45 +08:00
|
|
|
out:
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2021-10-16 17:37:48 +08:00
|
|
|
static int smc_ib_determine_gid_rcu(const struct net_device *ndev,
|
|
|
|
const struct ib_gid_attr *attr,
|
|
|
|
u8 gid[], u8 *sgid_index,
|
|
|
|
struct smc_init_info_smcrv2 *smcrv2)
|
|
|
|
{
|
|
|
|
if (!smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE) {
|
|
|
|
if (gid)
|
|
|
|
memcpy(gid, &attr->gid, SMC_GID_SIZE);
|
|
|
|
if (sgid_index)
|
|
|
|
*sgid_index = attr->index;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP &&
|
|
|
|
smc_ib_gid_to_ipv4((u8 *)&attr->gid) != cpu_to_be32(INADDR_NONE)) {
|
|
|
|
struct in_device *in_dev = __in_dev_get_rcu(ndev);
|
2023-10-11 15:48:51 +08:00
|
|
|
struct net *net = dev_net(ndev);
|
2021-10-16 17:37:48 +08:00
|
|
|
const struct in_ifaddr *ifa;
|
|
|
|
bool subnet_match = false;
|
|
|
|
|
|
|
|
if (!in_dev)
|
|
|
|
goto out;
|
|
|
|
in_dev_for_each_ifa_rcu(ifa, in_dev) {
|
|
|
|
if (!inet_ifa_match(smcrv2->saddr, ifa))
|
|
|
|
continue;
|
|
|
|
subnet_match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!subnet_match)
|
|
|
|
goto out;
|
2023-10-11 15:48:51 +08:00
|
|
|
if (smcrv2->daddr && smc_ib_find_route(net, smcrv2->saddr,
|
2021-10-16 17:37:48 +08:00
|
|
|
smcrv2->daddr,
|
|
|
|
smcrv2->nexthop_mac,
|
|
|
|
&smcrv2->uses_gateway))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (gid)
|
|
|
|
memcpy(gid, &attr->gid, SMC_GID_SIZE);
|
|
|
|
if (sgid_index)
|
|
|
|
*sgid_index = attr->index;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-07-25 22:35:31 +08:00
|
|
|
/* determine the gid for an ib-device port and vlan id */
|
|
|
|
int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
|
2021-10-16 17:37:48 +08:00
|
|
|
unsigned short vlan_id, u8 gid[], u8 *sgid_index,
|
|
|
|
struct smc_init_info_smcrv2 *smcrv2)
|
2018-07-25 22:35:31 +08:00
|
|
|
{
|
2018-08-18 06:45:51 +08:00
|
|
|
const struct ib_gid_attr *attr;
|
2019-05-02 15:48:06 +08:00
|
|
|
const struct net_device *ndev;
|
2018-07-25 22:35:31 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
|
2018-08-18 06:45:51 +08:00
|
|
|
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, i);
|
|
|
|
if (IS_ERR(attr))
|
2018-07-25 22:35:31 +08:00
|
|
|
continue;
|
2018-08-18 06:45:51 +08:00
|
|
|
|
2019-05-02 15:48:06 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
ndev = rdma_read_gid_attr_ndev_rcu(attr);
|
|
|
|
if (!IS_ERR(ndev) &&
|
2020-11-19 05:40:38 +08:00
|
|
|
((!vlan_id && !is_vlan_dev(ndev)) ||
|
|
|
|
(vlan_id && is_vlan_dev(ndev) &&
|
2021-10-16 17:37:48 +08:00
|
|
|
vlan_dev_vlan_id(ndev) == vlan_id))) {
|
|
|
|
if (!smc_ib_determine_gid_rcu(ndev, attr, gid,
|
|
|
|
sgid_index, smcrv2)) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
rdma_put_gid_attr(attr);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-25 22:35:31 +08:00
|
|
|
}
|
2019-05-02 15:48:06 +08:00
|
|
|
rcu_read_unlock();
|
2018-08-18 06:45:51 +08:00
|
|
|
rdma_put_gid_attr(attr);
|
2018-07-25 22:35:31 +08:00
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2021-10-16 17:37:52 +08:00
|
|
|
/* check if gid is still defined on smcibdev */
|
|
|
|
static bool smc_ib_check_link_gid(u8 gid[SMC_GID_SIZE], bool smcrv2,
|
|
|
|
struct smc_ib_device *smcibdev, u8 ibport)
|
|
|
|
{
|
|
|
|
const struct ib_gid_attr *attr;
|
|
|
|
bool rc = false;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; !rc && i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
|
|
|
|
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, i);
|
|
|
|
if (IS_ERR(attr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
if ((!smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE) ||
|
|
|
|
(smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP &&
|
|
|
|
!(ipv6_addr_type((const struct in6_addr *)&attr->gid)
|
|
|
|
& IPV6_ADDR_LINKLOCAL)))
|
|
|
|
if (!memcmp(gid, &attr->gid, SMC_GID_SIZE))
|
|
|
|
rc = true;
|
|
|
|
rcu_read_unlock();
|
|
|
|
rdma_put_gid_attr(attr);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check all links if the gid is still defined on smcibdev */
|
|
|
|
static void smc_ib_gid_check(struct smc_ib_device *smcibdev, u8 ibport)
|
|
|
|
{
|
|
|
|
struct smc_link_group *lgr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_bh(&smc_lgr_list.lock);
|
|
|
|
list_for_each_entry(lgr, &smc_lgr_list.list, list) {
|
|
|
|
if (strncmp(smcibdev->pnetid[ibport - 1], lgr->pnet_id,
|
|
|
|
SMC_MAX_PNETID_LEN))
|
|
|
|
continue; /* lgr is not affected */
|
|
|
|
if (list_empty(&lgr->list))
|
|
|
|
continue;
|
|
|
|
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
|
|
|
|
if (lgr->lnk[i].state == SMC_LNK_UNUSED ||
|
|
|
|
lgr->lnk[i].smcibdev != smcibdev)
|
|
|
|
continue;
|
|
|
|
if (!smc_ib_check_link_gid(lgr->lnk[i].gid,
|
|
|
|
lgr->smc_version == SMC_V2,
|
|
|
|
smcibdev, ibport))
|
|
|
|
smcr_port_err(smcibdev, ibport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&smc_lgr_list.lock);
|
|
|
|
}
|
|
|
|
|
2018-06-29 01:05:04 +08:00
|
|
|
static int smc_ib_remember_port_attr(struct smc_ib_device *smcibdev, u8 ibport)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
memset(&smcibdev->pattr[ibport - 1], 0,
|
|
|
|
sizeof(smcibdev->pattr[ibport - 1]));
|
|
|
|
rc = ib_query_port(smcibdev->ibdev, ibport,
|
|
|
|
&smcibdev->pattr[ibport - 1]);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
/* the SMC protocol requires specification of the RoCE MAC address */
|
2018-07-25 22:35:31 +08:00
|
|
|
rc = smc_ib_fill_mac(smcibdev, ibport);
|
2018-06-29 01:05:04 +08:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
2020-02-26 05:41:21 +08:00
|
|
|
if (!smc_ib_is_valid_local_systemid() &&
|
2018-06-29 01:05:04 +08:00
|
|
|
smc_ib_port_active(smcibdev, ibport))
|
|
|
|
/* create unique system identifier */
|
|
|
|
smc_ib_define_local_systemid(smcibdev, ibport);
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:20 +08:00
|
|
|
/* process context wrapper for might_sleep smc_ib_remember_port_attr */
|
|
|
|
static void smc_ib_port_event_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct smc_ib_device *smcibdev = container_of(
|
|
|
|
work, struct smc_ib_device, port_event_work);
|
|
|
|
u8 port_idx;
|
|
|
|
|
|
|
|
for_each_set_bit(port_idx, &smcibdev->port_event_mask, SMC_MAX_PORTS) {
|
|
|
|
smc_ib_remember_port_attr(smcibdev, port_idx + 1);
|
|
|
|
clear_bit(port_idx, &smcibdev->port_event_mask);
|
2019-10-09 16:07:46 +08:00
|
|
|
if (!smc_ib_port_active(smcibdev, port_idx + 1)) {
|
|
|
|
set_bit(port_idx, smcibdev->ports_going_away);
|
2020-05-01 18:48:08 +08:00
|
|
|
smcr_port_err(smcibdev, port_idx + 1);
|
2019-10-09 16:07:46 +08:00
|
|
|
} else {
|
|
|
|
clear_bit(port_idx, smcibdev->ports_going_away);
|
2020-05-01 18:48:07 +08:00
|
|
|
smcr_port_add(smcibdev, port_idx + 1);
|
2021-10-16 17:37:52 +08:00
|
|
|
smc_ib_gid_check(smcibdev, port_idx + 1);
|
2019-10-09 16:07:46 +08:00
|
|
|
}
|
2017-01-09 23:55:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can be called in IRQ context */
|
|
|
|
static void smc_ib_global_event_handler(struct ib_event_handler *handler,
|
|
|
|
struct ib_event *ibevent)
|
|
|
|
{
|
|
|
|
struct smc_ib_device *smcibdev;
|
2020-02-17 23:24:55 +08:00
|
|
|
bool schedule = false;
|
2017-01-09 23:55:20 +08:00
|
|
|
u8 port_idx;
|
|
|
|
|
|
|
|
smcibdev = container_of(handler, struct smc_ib_device, event_handler);
|
|
|
|
|
|
|
|
switch (ibevent->event) {
|
|
|
|
case IB_EVENT_DEVICE_FATAL:
|
2019-02-12 23:29:55 +08:00
|
|
|
/* terminate all ports on device */
|
2019-10-09 16:07:46 +08:00
|
|
|
for (port_idx = 0; port_idx < SMC_MAX_PORTS; port_idx++) {
|
2019-02-12 23:29:55 +08:00
|
|
|
set_bit(port_idx, &smcibdev->port_event_mask);
|
2020-02-17 23:24:55 +08:00
|
|
|
if (!test_and_set_bit(port_idx,
|
|
|
|
smcibdev->ports_going_away))
|
|
|
|
schedule = true;
|
2019-10-09 16:07:46 +08:00
|
|
|
}
|
2020-02-17 23:24:55 +08:00
|
|
|
if (schedule)
|
|
|
|
schedule_work(&smcibdev->port_event_work);
|
2019-02-12 23:29:55 +08:00
|
|
|
break;
|
2017-01-09 23:55:20 +08:00
|
|
|
case IB_EVENT_PORT_ACTIVE:
|
|
|
|
port_idx = ibevent->element.port_num - 1;
|
2020-02-17 23:24:55 +08:00
|
|
|
if (port_idx >= SMC_MAX_PORTS)
|
|
|
|
break;
|
|
|
|
set_bit(port_idx, &smcibdev->port_event_mask);
|
|
|
|
if (test_and_clear_bit(port_idx, smcibdev->ports_going_away))
|
|
|
|
schedule_work(&smcibdev->port_event_work);
|
|
|
|
break;
|
|
|
|
case IB_EVENT_PORT_ERR:
|
|
|
|
port_idx = ibevent->element.port_num - 1;
|
|
|
|
if (port_idx >= SMC_MAX_PORTS)
|
|
|
|
break;
|
|
|
|
set_bit(port_idx, &smcibdev->port_event_mask);
|
|
|
|
if (!test_and_set_bit(port_idx, smcibdev->ports_going_away))
|
2019-02-12 23:29:55 +08:00
|
|
|
schedule_work(&smcibdev->port_event_work);
|
2020-02-17 23:24:55 +08:00
|
|
|
break;
|
|
|
|
case IB_EVENT_GID_CHANGE:
|
|
|
|
port_idx = ibevent->element.port_num - 1;
|
|
|
|
if (port_idx >= SMC_MAX_PORTS)
|
|
|
|
break;
|
|
|
|
set_bit(port_idx, &smcibdev->port_event_mask);
|
|
|
|
schedule_work(&smcibdev->port_event_work);
|
2017-01-09 23:55:20 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:19 +08:00
|
|
|
void smc_ib_dealloc_protection_domain(struct smc_link *lnk)
|
|
|
|
{
|
2018-01-26 16:28:46 +08:00
|
|
|
if (lnk->roce_pd)
|
|
|
|
ib_dealloc_pd(lnk->roce_pd);
|
2017-01-09 23:55:19 +08:00
|
|
|
lnk->roce_pd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smc_ib_create_protection_domain(struct smc_link *lnk)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2017-07-28 19:56:16 +08:00
|
|
|
lnk->roce_pd = ib_alloc_pd(lnk->smcibdev->ibdev, 0);
|
2017-01-09 23:55:19 +08:00
|
|
|
rc = PTR_ERR_OR_ZERO(lnk->roce_pd);
|
|
|
|
if (IS_ERR(lnk->roce_pd))
|
|
|
|
lnk->roce_pd = NULL;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-12-02 03:20:49 +08:00
|
|
|
static bool smcr_diag_is_dev_critical(struct smc_lgr_list *smc_lgr,
|
|
|
|
struct smc_ib_device *smcibdev)
|
|
|
|
{
|
|
|
|
struct smc_link_group *lgr;
|
|
|
|
bool rc = false;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_bh(&smc_lgr->lock);
|
|
|
|
list_for_each_entry(lgr, &smc_lgr->list, list) {
|
|
|
|
if (lgr->is_smcd)
|
|
|
|
continue;
|
|
|
|
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
|
|
|
|
if (lgr->lnk[i].state == SMC_LNK_UNUSED ||
|
|
|
|
lgr->lnk[i].smcibdev != smcibdev)
|
|
|
|
continue;
|
|
|
|
if (lgr->type == SMC_LGR_SINGLE ||
|
|
|
|
lgr->type == SMC_LGR_ASYMMETRIC_LOCAL) {
|
|
|
|
rc = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
spin_unlock_bh(&smc_lgr->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smc_nl_handle_dev_port(struct sk_buff *skb,
|
|
|
|
struct ib_device *ibdev,
|
|
|
|
struct smc_ib_device *smcibdev,
|
|
|
|
int port)
|
|
|
|
{
|
|
|
|
char smc_pnet[SMC_MAX_PNETID_LEN + 1];
|
|
|
|
struct nlattr *port_attrs;
|
|
|
|
unsigned char port_state;
|
|
|
|
int lnk_count = 0;
|
|
|
|
|
|
|
|
port_attrs = nla_nest_start(skb, SMC_NLA_DEV_PORT + port);
|
|
|
|
if (!port_attrs)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
if (nla_put_u8(skb, SMC_NLA_DEV_PORT_PNET_USR,
|
|
|
|
smcibdev->pnetid_by_user[port]))
|
|
|
|
goto errattr;
|
2021-01-13 00:21:22 +08:00
|
|
|
memcpy(smc_pnet, &smcibdev->pnetid[port], SMC_MAX_PNETID_LEN);
|
|
|
|
smc_pnet[SMC_MAX_PNETID_LEN] = 0;
|
2020-12-02 03:20:49 +08:00
|
|
|
if (nla_put_string(skb, SMC_NLA_DEV_PORT_PNETID, smc_pnet))
|
|
|
|
goto errattr;
|
|
|
|
if (nla_put_u32(skb, SMC_NLA_DEV_PORT_NETDEV,
|
|
|
|
smcibdev->ndev_ifidx[port]))
|
|
|
|
goto errattr;
|
|
|
|
if (nla_put_u8(skb, SMC_NLA_DEV_PORT_VALID, 1))
|
|
|
|
goto errattr;
|
|
|
|
port_state = smc_ib_port_active(smcibdev, port + 1);
|
|
|
|
if (nla_put_u8(skb, SMC_NLA_DEV_PORT_STATE, port_state))
|
|
|
|
goto errattr;
|
|
|
|
lnk_count = atomic_read(&smcibdev->lnk_cnt_by_port[port]);
|
|
|
|
if (nla_put_u32(skb, SMC_NLA_DEV_PORT_LNK_CNT, lnk_count))
|
|
|
|
goto errattr;
|
|
|
|
nla_nest_end(skb, port_attrs);
|
|
|
|
return 0;
|
|
|
|
errattr:
|
|
|
|
nla_nest_cancel(skb, port_attrs);
|
|
|
|
errout:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:10:58 +08:00
|
|
|
static bool smc_nl_handle_pci_values(const struct smc_pci_dev *smc_pci_dev,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev->pci_fid))
|
|
|
|
return false;
|
|
|
|
if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev->pci_pchid))
|
|
|
|
return false;
|
|
|
|
if (nla_put_u16(skb, SMC_NLA_DEV_PCI_VENDOR, smc_pci_dev->pci_vendor))
|
|
|
|
return false;
|
|
|
|
if (nla_put_u16(skb, SMC_NLA_DEV_PCI_DEVICE, smc_pci_dev->pci_device))
|
|
|
|
return false;
|
|
|
|
if (nla_put_string(skb, SMC_NLA_DEV_PCI_ID, smc_pci_dev->pci_id))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-02 03:20:49 +08:00
|
|
|
static int smc_nl_handle_smcr_dev(struct smc_ib_device *smcibdev,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
2021-01-13 00:21:22 +08:00
|
|
|
char smc_ibname[IB_DEVICE_NAME_MAX];
|
2020-12-02 03:20:49 +08:00
|
|
|
struct smc_pci_dev smc_pci_dev;
|
|
|
|
struct pci_dev *pci_dev;
|
|
|
|
unsigned char is_crit;
|
|
|
|
struct nlattr *attrs;
|
|
|
|
void *nlh;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
|
|
|
|
&smc_gen_nl_family, NLM_F_MULTI,
|
|
|
|
SMC_NETLINK_GET_DEV_SMCR);
|
|
|
|
if (!nlh)
|
|
|
|
goto errmsg;
|
|
|
|
attrs = nla_nest_start(skb, SMC_GEN_DEV_SMCR);
|
|
|
|
if (!attrs)
|
|
|
|
goto errout;
|
|
|
|
is_crit = smcr_diag_is_dev_critical(&smc_lgr_list, smcibdev);
|
|
|
|
if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, is_crit))
|
|
|
|
goto errattr;
|
2020-12-15 17:10:58 +08:00
|
|
|
if (smcibdev->ibdev->dev.parent) {
|
|
|
|
memset(&smc_pci_dev, 0, sizeof(smc_pci_dev));
|
|
|
|
pci_dev = to_pci_dev(smcibdev->ibdev->dev.parent);
|
|
|
|
smc_set_pci_values(pci_dev, &smc_pci_dev);
|
|
|
|
if (!smc_nl_handle_pci_values(&smc_pci_dev, skb))
|
|
|
|
goto errattr;
|
|
|
|
}
|
2020-12-02 03:20:49 +08:00
|
|
|
snprintf(smc_ibname, sizeof(smc_ibname), "%s", smcibdev->ibdev->name);
|
|
|
|
if (nla_put_string(skb, SMC_NLA_DEV_IB_NAME, smc_ibname))
|
|
|
|
goto errattr;
|
|
|
|
for (i = 1; i <= SMC_MAX_PORTS; i++) {
|
|
|
|
if (!rdma_is_port_valid(smcibdev->ibdev, i))
|
|
|
|
continue;
|
|
|
|
if (smc_nl_handle_dev_port(skb, smcibdev->ibdev,
|
|
|
|
smcibdev, i - 1))
|
|
|
|
goto errattr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nla_nest_end(skb, attrs);
|
|
|
|
genlmsg_end(skb, nlh);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
errattr:
|
|
|
|
nla_nest_cancel(skb, attrs);
|
|
|
|
errout:
|
|
|
|
genlmsg_cancel(skb, nlh);
|
|
|
|
errmsg:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smc_nl_prep_smcr_dev(struct smc_ib_devices *dev_list,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb);
|
|
|
|
struct smc_ib_device *smcibdev;
|
|
|
|
int snum = cb_ctx->pos[0];
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
mutex_lock(&dev_list->mutex);
|
|
|
|
list_for_each_entry(smcibdev, &dev_list->list, list) {
|
|
|
|
if (num < snum)
|
|
|
|
goto next;
|
|
|
|
if (smc_nl_handle_smcr_dev(smcibdev, skb, cb))
|
|
|
|
goto errout;
|
|
|
|
next:
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
errout:
|
|
|
|
mutex_unlock(&dev_list->mutex);
|
|
|
|
cb_ctx->pos[0] = num;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
smc_nl_prep_smcr_dev(&smc_ib_devices, skb, cb);
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:19 +08:00
|
|
|
static void smc_ib_qp_event_handler(struct ib_event *ibevent, void *priv)
|
|
|
|
{
|
2019-01-31 01:51:07 +08:00
|
|
|
struct smc_link *lnk = (struct smc_link *)priv;
|
|
|
|
struct smc_ib_device *smcibdev = lnk->smcibdev;
|
2018-01-26 16:28:46 +08:00
|
|
|
u8 port_idx;
|
|
|
|
|
2017-01-09 23:55:19 +08:00
|
|
|
switch (ibevent->event) {
|
2019-02-12 23:29:55 +08:00
|
|
|
case IB_EVENT_QP_FATAL:
|
2017-01-09 23:55:19 +08:00
|
|
|
case IB_EVENT_QP_ACCESS_ERR:
|
2019-01-31 01:51:07 +08:00
|
|
|
port_idx = ibevent->element.qp->port - 1;
|
2020-02-17 23:24:55 +08:00
|
|
|
if (port_idx >= SMC_MAX_PORTS)
|
|
|
|
break;
|
|
|
|
set_bit(port_idx, &smcibdev->port_event_mask);
|
|
|
|
if (!test_and_set_bit(port_idx, smcibdev->ports_going_away))
|
2019-02-12 23:29:55 +08:00
|
|
|
schedule_work(&smcibdev->port_event_work);
|
2017-01-09 23:55:19 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void smc_ib_destroy_queue_pair(struct smc_link *lnk)
|
|
|
|
{
|
2018-01-26 16:28:46 +08:00
|
|
|
if (lnk->roce_qp)
|
|
|
|
ib_destroy_qp(lnk->roce_qp);
|
2017-01-09 23:55:19 +08:00
|
|
|
lnk->roce_qp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a queue pair within the protection domain for a link */
|
|
|
|
int smc_ib_create_queue_pair(struct smc_link *lnk)
|
|
|
|
{
|
2021-10-16 17:37:49 +08:00
|
|
|
int sges_per_buf = (lnk->lgr->smc_version == SMC_V2) ? 2 : 1;
|
2017-01-09 23:55:19 +08:00
|
|
|
struct ib_qp_init_attr qp_attr = {
|
|
|
|
.event_handler = smc_ib_qp_event_handler,
|
|
|
|
.qp_context = lnk,
|
|
|
|
.send_cq = lnk->smcibdev->roce_cq_send,
|
|
|
|
.recv_cq = lnk->smcibdev->roce_cq_recv,
|
|
|
|
.srq = NULL,
|
|
|
|
.cap = {
|
|
|
|
/* include unsolicited rdma_writes as well,
|
|
|
|
* there are max. 2 RDMA_WRITE per 1 WR_SEND
|
|
|
|
*/
|
2017-07-28 19:56:17 +08:00
|
|
|
.max_send_wr = SMC_WR_BUF_CNT * 3,
|
2017-01-09 23:55:19 +08:00
|
|
|
.max_recv_wr = SMC_WR_BUF_CNT * 3,
|
|
|
|
.max_send_sge = SMC_IB_MAX_SEND_SGE,
|
2021-10-16 17:37:49 +08:00
|
|
|
.max_recv_sge = sges_per_buf,
|
2022-05-16 13:51:36 +08:00
|
|
|
.max_inline_data = 0,
|
2017-01-09 23:55:19 +08:00
|
|
|
},
|
|
|
|
.sq_sig_type = IB_SIGNAL_REQ_WR,
|
|
|
|
.qp_type = IB_QPT_RC,
|
|
|
|
};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
lnk->roce_qp = ib_create_qp(lnk->roce_pd, &qp_attr);
|
|
|
|
rc = PTR_ERR_OR_ZERO(lnk->roce_qp);
|
|
|
|
if (IS_ERR(lnk->roce_qp))
|
|
|
|
lnk->roce_qp = NULL;
|
|
|
|
else
|
|
|
|
smc_wr_remember_qp_attr(lnk);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-07-28 19:56:16 +08:00
|
|
|
void smc_ib_put_memory_region(struct ib_mr *mr)
|
|
|
|
{
|
|
|
|
ib_dereg_mr(mr);
|
|
|
|
}
|
|
|
|
|
2020-04-29 23:10:40 +08:00
|
|
|
static int smc_ib_map_mr_sg(struct smc_buf_desc *buf_slot, u8 link_idx)
|
2017-07-28 19:56:16 +08:00
|
|
|
{
|
|
|
|
unsigned int offset = 0;
|
|
|
|
int sg_num;
|
|
|
|
|
|
|
|
/* map the largest prefix of a dma mapped SG list */
|
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 17:44:04 +08:00
|
|
|
sg_num = ib_map_mr_sg(buf_slot->mr[link_idx],
|
2020-04-29 23:10:40 +08:00
|
|
|
buf_slot->sgt[link_idx].sgl,
|
|
|
|
buf_slot->sgt[link_idx].orig_nents,
|
2017-07-28 19:56:16 +08:00
|
|
|
&offset, PAGE_SIZE);
|
|
|
|
|
|
|
|
return sg_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a memory region and map the dma mapped SG list of buf_slot */
|
|
|
|
int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
|
2020-04-29 23:10:40 +08:00
|
|
|
struct smc_buf_desc *buf_slot, u8 link_idx)
|
2017-07-28 19:56:16 +08:00
|
|
|
{
|
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 17:44:04 +08:00
|
|
|
if (buf_slot->mr[link_idx])
|
2017-07-28 19:56:16 +08:00
|
|
|
return 0; /* already done */
|
|
|
|
|
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 17:44:04 +08:00
|
|
|
buf_slot->mr[link_idx] =
|
2017-07-28 19:56:16 +08:00
|
|
|
ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, 1 << buf_slot->order);
|
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 17:44:04 +08:00
|
|
|
if (IS_ERR(buf_slot->mr[link_idx])) {
|
2017-07-28 19:56:16 +08:00
|
|
|
int rc;
|
|
|
|
|
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 17:44:04 +08:00
|
|
|
rc = PTR_ERR(buf_slot->mr[link_idx]);
|
|
|
|
buf_slot->mr[link_idx] = NULL;
|
2017-07-28 19:56:16 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
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 17:44:04 +08:00
|
|
|
if (smc_ib_map_mr_sg(buf_slot, link_idx) !=
|
|
|
|
buf_slot->sgt[link_idx].orig_nents)
|
2017-07-28 19:56:16 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-14 17:44:01 +08:00
|
|
|
bool smc_ib_is_sg_need_sync(struct smc_link *lnk,
|
|
|
|
struct smc_buf_desc *buf_slot)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned int i;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
/* for now there is just one DMA address */
|
|
|
|
for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg,
|
|
|
|
buf_slot->sgt[lnk->link_idx].nents, i) {
|
|
|
|
if (!sg_dma_len(sg))
|
|
|
|
break;
|
|
|
|
if (dma_need_sync(lnk->smcibdev->ibdev->dma_device,
|
|
|
|
sg_dma_address(sg))) {
|
|
|
|
ret = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-28 19:56:22 +08:00
|
|
|
/* synchronize buffer usage for cpu access */
|
2020-04-29 23:10:40 +08:00
|
|
|
void smc_ib_sync_sg_for_cpu(struct smc_link *lnk,
|
2017-07-28 19:56:22 +08:00
|
|
|
struct smc_buf_desc *buf_slot,
|
|
|
|
enum dma_data_direction data_direction)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned int i;
|
|
|
|
|
2022-07-14 17:44:01 +08:00
|
|
|
if (!(buf_slot->is_dma_need_sync & (1U << lnk->link_idx)))
|
|
|
|
return;
|
|
|
|
|
2017-07-28 19:56:22 +08:00
|
|
|
/* for now there is just one DMA address */
|
2020-04-29 23:10:40 +08:00
|
|
|
for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg,
|
|
|
|
buf_slot->sgt[lnk->link_idx].nents, i) {
|
2017-07-28 19:56:22 +08:00
|
|
|
if (!sg_dma_len(sg))
|
|
|
|
break;
|
2020-04-29 23:10:40 +08:00
|
|
|
ib_dma_sync_single_for_cpu(lnk->smcibdev->ibdev,
|
2017-07-28 19:56:22 +08:00
|
|
|
sg_dma_address(sg),
|
|
|
|
sg_dma_len(sg),
|
|
|
|
data_direction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* synchronize buffer usage for device access */
|
2020-04-29 23:10:40 +08:00
|
|
|
void smc_ib_sync_sg_for_device(struct smc_link *lnk,
|
2017-07-28 19:56:22 +08:00
|
|
|
struct smc_buf_desc *buf_slot,
|
|
|
|
enum dma_data_direction data_direction)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned int i;
|
|
|
|
|
2022-07-14 17:44:01 +08:00
|
|
|
if (!(buf_slot->is_dma_need_sync & (1U << lnk->link_idx)))
|
|
|
|
return;
|
|
|
|
|
2017-07-28 19:56:22 +08:00
|
|
|
/* for now there is just one DMA address */
|
2020-04-29 23:10:40 +08:00
|
|
|
for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg,
|
|
|
|
buf_slot->sgt[lnk->link_idx].nents, i) {
|
2017-07-28 19:56:22 +08:00
|
|
|
if (!sg_dma_len(sg))
|
|
|
|
break;
|
2020-04-29 23:10:40 +08:00
|
|
|
ib_dma_sync_single_for_device(lnk->smcibdev->ibdev,
|
2017-07-28 19:56:22 +08:00
|
|
|
sg_dma_address(sg),
|
|
|
|
sg_dma_len(sg),
|
|
|
|
data_direction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 19:56:15 +08:00
|
|
|
/* Map a new TX or RX buffer SG-table to DMA */
|
2020-04-29 23:10:40 +08:00
|
|
|
int smc_ib_buf_map_sg(struct smc_link *lnk,
|
2017-07-28 19:56:15 +08:00
|
|
|
struct smc_buf_desc *buf_slot,
|
|
|
|
enum dma_data_direction data_direction)
|
|
|
|
{
|
|
|
|
int mapped_nents;
|
|
|
|
|
2020-04-29 23:10:40 +08:00
|
|
|
mapped_nents = ib_dma_map_sg(lnk->smcibdev->ibdev,
|
|
|
|
buf_slot->sgt[lnk->link_idx].sgl,
|
|
|
|
buf_slot->sgt[lnk->link_idx].orig_nents,
|
2017-07-28 19:56:15 +08:00
|
|
|
data_direction);
|
|
|
|
if (!mapped_nents)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return mapped_nents;
|
|
|
|
}
|
|
|
|
|
2020-04-29 23:10:40 +08:00
|
|
|
void smc_ib_buf_unmap_sg(struct smc_link *lnk,
|
2017-07-28 19:56:15 +08:00
|
|
|
struct smc_buf_desc *buf_slot,
|
|
|
|
enum dma_data_direction data_direction)
|
|
|
|
{
|
2020-04-29 23:10:40 +08:00
|
|
|
if (!buf_slot->sgt[lnk->link_idx].sgl->dma_address)
|
2017-07-28 19:56:15 +08:00
|
|
|
return; /* already unmapped */
|
|
|
|
|
2020-04-29 23:10:40 +08:00
|
|
|
ib_dma_unmap_sg(lnk->smcibdev->ibdev,
|
|
|
|
buf_slot->sgt[lnk->link_idx].sgl,
|
|
|
|
buf_slot->sgt[lnk->link_idx].orig_nents,
|
2017-07-28 19:56:15 +08:00
|
|
|
data_direction);
|
2020-04-29 23:10:40 +08:00
|
|
|
buf_slot->sgt[lnk->link_idx].sgl->dma_address = 0;
|
2017-07-28 19:56:15 +08:00
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:20 +08:00
|
|
|
long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev)
|
|
|
|
{
|
|
|
|
struct ib_cq_init_attr cqattr = {
|
net/smc: pay attention to MAX_ORDER for CQ entries
smc allocates a certain number of CQ entries for used RoCE devices. For
mlx5 devices the chosen constant number results in a large allocation
causing this warning:
[13355.124656] WARNING: CPU: 3 PID: 16535 at mm/page_alloc.c:3883 __alloc_pages_nodemask+0x2be/0x10c0
[13355.124657] Modules linked in: smc_diag(O) smc(O) xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp bridge stp llc ip6table_filter ip6_tables iptable_filter mlx5_ib ib_core sunrpc mlx5_core s390_trng rng_core ghash_s390 prng aes_s390 des_s390 des_generic sha512_s390 sha256_s390 sha1_s390 sha_common ptp pps_core eadm_sch dm_multipath dm_mod vhost_net tun vhost tap sch_fq_codel kvm ip_tables x_tables autofs4 [last unloaded: smc]
[13355.124672] CPU: 3 PID: 16535 Comm: kworker/3:0 Tainted: G O 4.14.0uschi #1
[13355.124673] Hardware name: IBM 3906 M04 704 (LPAR)
[13355.124675] Workqueue: events smc_listen_work [smc]
[13355.124677] task: 00000000e2f22100 task.stack: 0000000084720000
[13355.124678] Krnl PSW : 0704c00180000000 000000000029da76 (__alloc_pages_nodemask+0x2be/0x10c0)
[13355.124681] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[13355.124682] Krnl GPRS: 0000000000000000 00550e00014080c0 0000000000000000 0000000000000001
[13355.124684] 000000000029d8b6 00000000f3bfd710 0000000000000000 00000000014080c0
[13355.124685] 0000000000000009 00000000ec277a00 0000000000200000 0000000000000000
[13355.124686] 0000000000000000 00000000000001ff 000000000029d8b6 0000000084723720
[13355.124708] Krnl Code: 000000000029da6a: a7110200 tmll %r1,512
000000000029da6e: a774ff29 brc 7,29d8c0
#000000000029da72: a7f40001 brc 15,29da74
>000000000029da76: a7f4ff25 brc 15,29d8c0
000000000029da7a: a7380000 lhi %r3,0
000000000029da7e: a7f4fef1 brc 15,29d860
000000000029da82: 5820f0c4 l %r2,196(%r15)
000000000029da86: a53e0048 llilh %r3,72
[13355.124720] Call Trace:
[13355.124722] ([<000000000029d8b6>] __alloc_pages_nodemask+0xfe/0x10c0)
[13355.124724] [<000000000013bd1e>] s390_dma_alloc+0x6e/0x148
[13355.124733] [<000003ff802eeba6>] mlx5_dma_zalloc_coherent_node+0x8e/0xe0 [mlx5_core]
[13355.124740] [<000003ff802eee18>] mlx5_buf_alloc_node+0x70/0x108 [mlx5_core]
[13355.124744] [<000003ff804eb410>] mlx5_ib_create_cq+0x558/0x898 [mlx5_ib]
[13355.124749] [<000003ff80407d40>] ib_create_cq+0x48/0x88 [ib_core]
[13355.124751] [<000003ff80109fba>] smc_ib_setup_per_ibdev+0x52/0x118 [smc]
[13355.124753] [<000003ff8010bcb6>] smc_conn_create+0x65e/0x728 [smc]
[13355.124755] [<000003ff801081a2>] smc_listen_work+0x2d2/0x540 [smc]
[13355.124756] [<0000000000162c66>] process_one_work+0x1be/0x440
[13355.124758] [<0000000000162f40>] worker_thread+0x58/0x458
[13355.124759] [<0000000000169e7e>] kthread+0x14e/0x168
[13355.124760] [<00000000009ce8be>] kernel_thread_starter+0x6/0xc
[13355.124762] [<00000000009ce8b8>] kernel_thread_starter+0x0/0xc
[13355.124762] Last Breaking-Event-Address:
[13355.124764] [<000000000029da72>] __alloc_pages_nodemask+0x2ba/0x10c0
[13355.124764] ---[ end trace 34be38b581c0b585 ]---
This patch reduces the smc constant for the maximum number of allocated
completion queue entries SMC_MAX_CQE by 2 to avoid high round up values
in the mlx5 code, and reduces the number of allocated completion queue
entries even more, if the final allocation for an mlx5 device hits the
MAX_ORDER limit.
Reported-by: Ihnken Menssen <menssen@de.ibm.com>
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-14 18:01:00 +08:00
|
|
|
.cqe = SMC_MAX_CQE, .comp_vector = 0 };
|
|
|
|
int cqe_size_order, smc_order;
|
2017-01-09 23:55:20 +08:00
|
|
|
long rc;
|
|
|
|
|
2020-07-18 21:06:12 +08:00
|
|
|
mutex_lock(&smcibdev->mutex);
|
|
|
|
rc = 0;
|
|
|
|
if (smcibdev->initialized)
|
|
|
|
goto out;
|
net/smc: pay attention to MAX_ORDER for CQ entries
smc allocates a certain number of CQ entries for used RoCE devices. For
mlx5 devices the chosen constant number results in a large allocation
causing this warning:
[13355.124656] WARNING: CPU: 3 PID: 16535 at mm/page_alloc.c:3883 __alloc_pages_nodemask+0x2be/0x10c0
[13355.124657] Modules linked in: smc_diag(O) smc(O) xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp bridge stp llc ip6table_filter ip6_tables iptable_filter mlx5_ib ib_core sunrpc mlx5_core s390_trng rng_core ghash_s390 prng aes_s390 des_s390 des_generic sha512_s390 sha256_s390 sha1_s390 sha_common ptp pps_core eadm_sch dm_multipath dm_mod vhost_net tun vhost tap sch_fq_codel kvm ip_tables x_tables autofs4 [last unloaded: smc]
[13355.124672] CPU: 3 PID: 16535 Comm: kworker/3:0 Tainted: G O 4.14.0uschi #1
[13355.124673] Hardware name: IBM 3906 M04 704 (LPAR)
[13355.124675] Workqueue: events smc_listen_work [smc]
[13355.124677] task: 00000000e2f22100 task.stack: 0000000084720000
[13355.124678] Krnl PSW : 0704c00180000000 000000000029da76 (__alloc_pages_nodemask+0x2be/0x10c0)
[13355.124681] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[13355.124682] Krnl GPRS: 0000000000000000 00550e00014080c0 0000000000000000 0000000000000001
[13355.124684] 000000000029d8b6 00000000f3bfd710 0000000000000000 00000000014080c0
[13355.124685] 0000000000000009 00000000ec277a00 0000000000200000 0000000000000000
[13355.124686] 0000000000000000 00000000000001ff 000000000029d8b6 0000000084723720
[13355.124708] Krnl Code: 000000000029da6a: a7110200 tmll %r1,512
000000000029da6e: a774ff29 brc 7,29d8c0
#000000000029da72: a7f40001 brc 15,29da74
>000000000029da76: a7f4ff25 brc 15,29d8c0
000000000029da7a: a7380000 lhi %r3,0
000000000029da7e: a7f4fef1 brc 15,29d860
000000000029da82: 5820f0c4 l %r2,196(%r15)
000000000029da86: a53e0048 llilh %r3,72
[13355.124720] Call Trace:
[13355.124722] ([<000000000029d8b6>] __alloc_pages_nodemask+0xfe/0x10c0)
[13355.124724] [<000000000013bd1e>] s390_dma_alloc+0x6e/0x148
[13355.124733] [<000003ff802eeba6>] mlx5_dma_zalloc_coherent_node+0x8e/0xe0 [mlx5_core]
[13355.124740] [<000003ff802eee18>] mlx5_buf_alloc_node+0x70/0x108 [mlx5_core]
[13355.124744] [<000003ff804eb410>] mlx5_ib_create_cq+0x558/0x898 [mlx5_ib]
[13355.124749] [<000003ff80407d40>] ib_create_cq+0x48/0x88 [ib_core]
[13355.124751] [<000003ff80109fba>] smc_ib_setup_per_ibdev+0x52/0x118 [smc]
[13355.124753] [<000003ff8010bcb6>] smc_conn_create+0x65e/0x728 [smc]
[13355.124755] [<000003ff801081a2>] smc_listen_work+0x2d2/0x540 [smc]
[13355.124756] [<0000000000162c66>] process_one_work+0x1be/0x440
[13355.124758] [<0000000000162f40>] worker_thread+0x58/0x458
[13355.124759] [<0000000000169e7e>] kthread+0x14e/0x168
[13355.124760] [<00000000009ce8be>] kernel_thread_starter+0x6/0xc
[13355.124762] [<00000000009ce8b8>] kernel_thread_starter+0x0/0xc
[13355.124762] Last Breaking-Event-Address:
[13355.124764] [<000000000029da72>] __alloc_pages_nodemask+0x2ba/0x10c0
[13355.124764] ---[ end trace 34be38b581c0b585 ]---
This patch reduces the smc constant for the maximum number of allocated
completion queue entries SMC_MAX_CQE by 2 to avoid high round up values
in the mlx5 code, and reduces the number of allocated completion queue
entries even more, if the final allocation for an mlx5 device hits the
MAX_ORDER limit.
Reported-by: Ihnken Menssen <menssen@de.ibm.com>
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-14 18:01:00 +08:00
|
|
|
/* the calculated number of cq entries fits to mlx5 cq allocation */
|
|
|
|
cqe_size_order = cache_line_size() == 128 ? 7 : 6;
|
2023-12-28 22:47:04 +08:00
|
|
|
smc_order = MAX_PAGE_ORDER - cqe_size_order;
|
net/smc: pay attention to MAX_ORDER for CQ entries
smc allocates a certain number of CQ entries for used RoCE devices. For
mlx5 devices the chosen constant number results in a large allocation
causing this warning:
[13355.124656] WARNING: CPU: 3 PID: 16535 at mm/page_alloc.c:3883 __alloc_pages_nodemask+0x2be/0x10c0
[13355.124657] Modules linked in: smc_diag(O) smc(O) xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp bridge stp llc ip6table_filter ip6_tables iptable_filter mlx5_ib ib_core sunrpc mlx5_core s390_trng rng_core ghash_s390 prng aes_s390 des_s390 des_generic sha512_s390 sha256_s390 sha1_s390 sha_common ptp pps_core eadm_sch dm_multipath dm_mod vhost_net tun vhost tap sch_fq_codel kvm ip_tables x_tables autofs4 [last unloaded: smc]
[13355.124672] CPU: 3 PID: 16535 Comm: kworker/3:0 Tainted: G O 4.14.0uschi #1
[13355.124673] Hardware name: IBM 3906 M04 704 (LPAR)
[13355.124675] Workqueue: events smc_listen_work [smc]
[13355.124677] task: 00000000e2f22100 task.stack: 0000000084720000
[13355.124678] Krnl PSW : 0704c00180000000 000000000029da76 (__alloc_pages_nodemask+0x2be/0x10c0)
[13355.124681] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[13355.124682] Krnl GPRS: 0000000000000000 00550e00014080c0 0000000000000000 0000000000000001
[13355.124684] 000000000029d8b6 00000000f3bfd710 0000000000000000 00000000014080c0
[13355.124685] 0000000000000009 00000000ec277a00 0000000000200000 0000000000000000
[13355.124686] 0000000000000000 00000000000001ff 000000000029d8b6 0000000084723720
[13355.124708] Krnl Code: 000000000029da6a: a7110200 tmll %r1,512
000000000029da6e: a774ff29 brc 7,29d8c0
#000000000029da72: a7f40001 brc 15,29da74
>000000000029da76: a7f4ff25 brc 15,29d8c0
000000000029da7a: a7380000 lhi %r3,0
000000000029da7e: a7f4fef1 brc 15,29d860
000000000029da82: 5820f0c4 l %r2,196(%r15)
000000000029da86: a53e0048 llilh %r3,72
[13355.124720] Call Trace:
[13355.124722] ([<000000000029d8b6>] __alloc_pages_nodemask+0xfe/0x10c0)
[13355.124724] [<000000000013bd1e>] s390_dma_alloc+0x6e/0x148
[13355.124733] [<000003ff802eeba6>] mlx5_dma_zalloc_coherent_node+0x8e/0xe0 [mlx5_core]
[13355.124740] [<000003ff802eee18>] mlx5_buf_alloc_node+0x70/0x108 [mlx5_core]
[13355.124744] [<000003ff804eb410>] mlx5_ib_create_cq+0x558/0x898 [mlx5_ib]
[13355.124749] [<000003ff80407d40>] ib_create_cq+0x48/0x88 [ib_core]
[13355.124751] [<000003ff80109fba>] smc_ib_setup_per_ibdev+0x52/0x118 [smc]
[13355.124753] [<000003ff8010bcb6>] smc_conn_create+0x65e/0x728 [smc]
[13355.124755] [<000003ff801081a2>] smc_listen_work+0x2d2/0x540 [smc]
[13355.124756] [<0000000000162c66>] process_one_work+0x1be/0x440
[13355.124758] [<0000000000162f40>] worker_thread+0x58/0x458
[13355.124759] [<0000000000169e7e>] kthread+0x14e/0x168
[13355.124760] [<00000000009ce8be>] kernel_thread_starter+0x6/0xc
[13355.124762] [<00000000009ce8b8>] kernel_thread_starter+0x0/0xc
[13355.124762] Last Breaking-Event-Address:
[13355.124764] [<000000000029da72>] __alloc_pages_nodemask+0x2ba/0x10c0
[13355.124764] ---[ end trace 34be38b581c0b585 ]---
This patch reduces the smc constant for the maximum number of allocated
completion queue entries SMC_MAX_CQE by 2 to avoid high round up values
in the mlx5 code, and reduces the number of allocated completion queue
entries even more, if the final allocation for an mlx5 device hits the
MAX_ORDER limit.
Reported-by: Ihnken Menssen <menssen@de.ibm.com>
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-03-14 18:01:00 +08:00
|
|
|
if (SMC_MAX_CQE + 2 > (0x00000001 << smc_order) * PAGE_SIZE)
|
|
|
|
cqattr.cqe = (0x00000001 << smc_order) * PAGE_SIZE - 2;
|
2017-01-09 23:55:20 +08:00
|
|
|
smcibdev->roce_cq_send = ib_create_cq(smcibdev->ibdev,
|
|
|
|
smc_wr_tx_cq_handler, NULL,
|
|
|
|
smcibdev, &cqattr);
|
|
|
|
rc = PTR_ERR_OR_ZERO(smcibdev->roce_cq_send);
|
|
|
|
if (IS_ERR(smcibdev->roce_cq_send)) {
|
|
|
|
smcibdev->roce_cq_send = NULL;
|
2020-07-18 21:06:12 +08:00
|
|
|
goto out;
|
2017-01-09 23:55:20 +08:00
|
|
|
}
|
|
|
|
smcibdev->roce_cq_recv = ib_create_cq(smcibdev->ibdev,
|
|
|
|
smc_wr_rx_cq_handler, NULL,
|
|
|
|
smcibdev, &cqattr);
|
|
|
|
rc = PTR_ERR_OR_ZERO(smcibdev->roce_cq_recv);
|
|
|
|
if (IS_ERR(smcibdev->roce_cq_recv)) {
|
|
|
|
smcibdev->roce_cq_recv = NULL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
smc_wr_add_dev(smcibdev);
|
|
|
|
smcibdev->initialized = 1;
|
2020-07-18 21:06:12 +08:00
|
|
|
goto out;
|
2017-01-09 23:55:20 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
ib_destroy_cq(smcibdev->roce_cq_send);
|
2020-07-18 21:06:12 +08:00
|
|
|
out:
|
|
|
|
mutex_unlock(&smcibdev->mutex);
|
2017-01-09 23:55:20 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smc_ib_cleanup_per_ibdev(struct smc_ib_device *smcibdev)
|
|
|
|
{
|
2020-07-18 21:06:12 +08:00
|
|
|
mutex_lock(&smcibdev->mutex);
|
2017-01-09 23:55:20 +08:00
|
|
|
if (!smcibdev->initialized)
|
2020-07-18 21:06:12 +08:00
|
|
|
goto out;
|
2018-01-26 16:28:46 +08:00
|
|
|
smcibdev->initialized = 0;
|
2017-01-09 23:55:20 +08:00
|
|
|
ib_destroy_cq(smcibdev->roce_cq_recv);
|
|
|
|
ib_destroy_cq(smcibdev->roce_cq_send);
|
2019-11-14 20:02:46 +08:00
|
|
|
smc_wr_remove_dev(smcibdev);
|
2020-07-18 21:06:12 +08:00
|
|
|
out:
|
|
|
|
mutex_unlock(&smcibdev->mutex);
|
2017-01-09 23:55:20 +08:00
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:14 +08:00
|
|
|
static struct ib_client smc_ib_client;
|
|
|
|
|
2020-12-02 03:20:40 +08:00
|
|
|
static void smc_copy_netdev_ifindex(struct smc_ib_device *smcibdev, int port)
|
|
|
|
{
|
|
|
|
struct ib_device *ibdev = smcibdev->ibdev;
|
|
|
|
struct net_device *ndev;
|
|
|
|
|
|
|
|
if (!ibdev->ops.get_netdev)
|
|
|
|
return;
|
|
|
|
ndev = ibdev->ops.get_netdev(ibdev, port + 1);
|
|
|
|
if (ndev) {
|
|
|
|
smcibdev->ndev_ifidx[port] = ndev->ifindex;
|
|
|
|
dev_put(ndev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void smc_ib_ndev_change(struct net_device *ndev, unsigned long event)
|
|
|
|
{
|
|
|
|
struct smc_ib_device *smcibdev;
|
|
|
|
struct ib_device *libdev;
|
|
|
|
struct net_device *lndev;
|
|
|
|
u8 port_cnt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
|
|
|
list_for_each_entry(smcibdev, &smc_ib_devices.list, list) {
|
|
|
|
port_cnt = smcibdev->ibdev->phys_port_cnt;
|
|
|
|
for (i = 0; i < min_t(size_t, port_cnt, SMC_MAX_PORTS); i++) {
|
|
|
|
libdev = smcibdev->ibdev;
|
|
|
|
if (!libdev->ops.get_netdev)
|
|
|
|
continue;
|
|
|
|
lndev = libdev->ops.get_netdev(libdev, i + 1);
|
2021-08-05 19:55:27 +08:00
|
|
|
dev_put(lndev);
|
2020-12-02 03:20:40 +08:00
|
|
|
if (lndev != ndev)
|
|
|
|
continue;
|
|
|
|
if (event == NETDEV_REGISTER)
|
|
|
|
smcibdev->ndev_ifidx[i] = ndev->ifindex;
|
|
|
|
if (event == NETDEV_UNREGISTER)
|
|
|
|
smcibdev->ndev_ifidx[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:14 +08:00
|
|
|
/* callback function for ib_register_client() */
|
2020-04-22 01:24:40 +08:00
|
|
|
static int smc_ib_add_dev(struct ib_device *ibdev)
|
2017-01-09 23:55:14 +08:00
|
|
|
{
|
|
|
|
struct smc_ib_device *smcibdev;
|
2018-06-29 01:05:04 +08:00
|
|
|
u8 port_cnt;
|
|
|
|
int i;
|
2017-01-09 23:55:14 +08:00
|
|
|
|
|
|
|
if (ibdev->node_type != RDMA_NODE_IB_CA)
|
2020-04-22 01:24:40 +08:00
|
|
|
return -EOPNOTSUPP;
|
2017-01-09 23:55:14 +08:00
|
|
|
|
|
|
|
smcibdev = kzalloc(sizeof(*smcibdev), GFP_KERNEL);
|
|
|
|
if (!smcibdev)
|
2020-04-22 01:24:40 +08:00
|
|
|
return -ENOMEM;
|
2017-01-09 23:55:14 +08:00
|
|
|
|
|
|
|
smcibdev->ibdev = ibdev;
|
2017-01-09 23:55:20 +08:00
|
|
|
INIT_WORK(&smcibdev->port_event_work, smc_ib_port_event_work);
|
2019-11-17 00:47:29 +08:00
|
|
|
atomic_set(&smcibdev->lnk_cnt, 0);
|
|
|
|
init_waitqueue_head(&smcibdev->lnks_deleted);
|
2020-07-18 21:06:12 +08:00
|
|
|
mutex_init(&smcibdev->mutex);
|
2020-07-08 23:05:13 +08:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2017-01-09 23:55:14 +08:00
|
|
|
list_add_tail(&smcibdev->list, &smc_ib_devices.list);
|
2020-07-08 23:05:13 +08:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2017-01-09 23:55:14 +08:00
|
|
|
ib_set_client_data(ibdev, &smc_ib_client, smcibdev);
|
2018-06-29 01:05:04 +08:00
|
|
|
INIT_IB_EVENT_HANDLER(&smcibdev->event_handler, smcibdev->ibdev,
|
|
|
|
smc_ib_global_event_handler);
|
|
|
|
ib_register_event_handler(&smcibdev->event_handler);
|
|
|
|
|
|
|
|
/* trigger reading of the port attributes */
|
|
|
|
port_cnt = smcibdev->ibdev->phys_port_cnt;
|
2020-05-05 21:01:20 +08:00
|
|
|
pr_warn_ratelimited("smc: adding ib device %s with port count %d\n",
|
|
|
|
smcibdev->ibdev->name, port_cnt);
|
2018-06-29 01:05:04 +08:00
|
|
|
for (i = 0;
|
|
|
|
i < min_t(size_t, port_cnt, SMC_MAX_PORTS);
|
2018-06-29 01:05:05 +08:00
|
|
|
i++) {
|
2018-06-29 01:05:04 +08:00
|
|
|
set_bit(i, &smcibdev->port_event_mask);
|
2018-06-29 01:05:05 +08:00
|
|
|
/* determine pnetids of the port */
|
2020-04-29 23:10:37 +08:00
|
|
|
if (smc_pnetid_by_dev_port(ibdev->dev.parent, i,
|
|
|
|
smcibdev->pnetid[i]))
|
|
|
|
smc_pnetid_by_table_ib(smcibdev, i + 1);
|
2020-12-02 03:20:40 +08:00
|
|
|
smc_copy_netdev_ifindex(smcibdev, i);
|
2020-05-05 21:01:20 +08:00
|
|
|
pr_warn_ratelimited("smc: ib device %s port %d has pnetid "
|
|
|
|
"%.16s%s\n",
|
|
|
|
smcibdev->ibdev->name, i + 1,
|
|
|
|
smcibdev->pnetid[i],
|
|
|
|
smcibdev->pnetid_by_user[i] ?
|
|
|
|
" (user defined)" :
|
|
|
|
"");
|
2018-06-29 01:05:05 +08:00
|
|
|
}
|
2018-06-29 01:05:04 +08:00
|
|
|
schedule_work(&smcibdev->port_event_work);
|
2020-04-22 01:24:40 +08:00
|
|
|
return 0;
|
2017-01-09 23:55:14 +08:00
|
|
|
}
|
|
|
|
|
2019-11-14 20:02:47 +08:00
|
|
|
/* callback function for ib_unregister_client() */
|
2017-01-09 23:55:14 +08:00
|
|
|
static void smc_ib_remove_dev(struct ib_device *ibdev, void *client_data)
|
|
|
|
{
|
2020-04-08 07:20:09 +08:00
|
|
|
struct smc_ib_device *smcibdev = client_data;
|
2017-01-09 23:55:14 +08:00
|
|
|
|
2020-07-08 23:05:13 +08:00
|
|
|
mutex_lock(&smc_ib_devices.mutex);
|
2017-01-09 23:55:14 +08:00
|
|
|
list_del_init(&smcibdev->list); /* remove from smc_ib_devices */
|
2020-07-08 23:05:13 +08:00
|
|
|
mutex_unlock(&smc_ib_devices.mutex);
|
2020-05-05 21:01:20 +08:00
|
|
|
pr_warn_ratelimited("smc: removing ib device %s\n",
|
|
|
|
smcibdev->ibdev->name);
|
2019-11-14 20:02:47 +08:00
|
|
|
smc_smcr_terminate_all(smcibdev);
|
2017-01-09 23:55:20 +08:00
|
|
|
smc_ib_cleanup_per_ibdev(smcibdev);
|
2018-06-29 01:05:04 +08:00
|
|
|
ib_unregister_event_handler(&smcibdev->event_handler);
|
2020-03-10 16:33:30 +08:00
|
|
|
cancel_work_sync(&smcibdev->port_event_work);
|
2017-01-09 23:55:14 +08:00
|
|
|
kfree(smcibdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ib_client smc_ib_client = {
|
|
|
|
.name = "smc_ib",
|
|
|
|
.add = smc_ib_add_dev,
|
|
|
|
.remove = smc_ib_remove_dev,
|
|
|
|
};
|
|
|
|
|
|
|
|
int __init smc_ib_register_client(void)
|
|
|
|
{
|
2020-02-26 05:41:21 +08:00
|
|
|
smc_ib_init_local_systemid();
|
2017-01-09 23:55:14 +08:00
|
|
|
return ib_register_client(&smc_ib_client);
|
|
|
|
}
|
|
|
|
|
|
|
|
void smc_ib_unregister_client(void)
|
|
|
|
{
|
|
|
|
ib_unregister_client(&smc_ib_client);
|
|
|
|
}
|