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:21 +08:00
/*
* Shared Memory Communications over RDMA ( SMC - R ) and RoCE
*
* Link Layer Control ( LLC )
*
* Copyright IBM Corp . 2016
*
* Author ( s ) : Klaus Wacker < Klaus . Wacker @ de . ibm . com >
* Ursula Braun < ubraun @ linux . vnet . ibm . com >
*/
# include <net/tcp.h>
# include <rdma/ib_verbs.h>
# include "smc.h"
# include "smc_core.h"
# include "smc_clc.h"
# include "smc_llc.h"
2020-05-03 20:38:40 +08:00
# include "smc_pnet.h"
2017-01-09 23:55:21 +08:00
2018-03-01 20:51:26 +08:00
# define SMC_LLC_DATA_LEN 40
struct smc_llc_hdr {
struct smc_wr_rx_hdr common ;
2021-10-16 17:37:50 +08:00
union {
struct {
u8 length ; /* 44 */
# if defined(__BIG_ENDIAN_BITFIELD)
u8 reserved : 4 ,
add_link_rej_rsn : 4 ;
2018-03-01 20:51:32 +08:00
# elif defined(__LITTLE_ENDIAN_BITFIELD)
2021-10-16 17:37:50 +08:00
u8 add_link_rej_rsn : 4 ,
reserved : 4 ;
2018-03-01 20:51:32 +08:00
# endif
2021-10-16 17:37:50 +08:00
} ;
u16 length_v2 ; /* 44 - 8192*/
} ;
2018-03-01 20:51:26 +08:00
u8 flags ;
2021-10-16 17:37:50 +08:00
} __packed ; /* format defined in
* IBM Shared Memory Communications Version 2
* ( https : //www.ibm.com/support/pages/node/6326337)
*/
2018-03-01 20:51:26 +08:00
2018-03-01 20:51:31 +08:00
# define SMC_LLC_FLAG_NO_RMBE_EYEC 0x03
2018-03-01 20:51:26 +08:00
struct smc_llc_msg_confirm_link { /* type 0x01 */
struct smc_llc_hdr hd ;
u8 sender_mac [ ETH_ALEN ] ;
u8 sender_gid [ SMC_GID_SIZE ] ;
u8 sender_qp_num [ 3 ] ;
u8 link_num ;
u8 link_uid [ SMC_LGR_ID_SIZE ] ;
u8 max_links ;
2023-08-17 21:20:30 +08:00
u8 max_conns ;
u8 reserved [ 8 ] ;
2018-03-01 20:51:26 +08:00
} ;
2018-03-01 20:51:32 +08:00
# define SMC_LLC_FLAG_ADD_LNK_REJ 0x40
# define SMC_LLC_REJ_RSN_NO_ALT_PATH 1
struct smc_llc_msg_add_link { /* type 0x02 */
struct smc_llc_hdr hd ;
u8 sender_mac [ ETH_ALEN ] ;
u8 reserved2 [ 2 ] ;
u8 sender_gid [ SMC_GID_SIZE ] ;
u8 sender_qp_num [ 3 ] ;
u8 link_num ;
2020-05-01 18:48:04 +08:00
# if defined(__BIG_ENDIAN_BITFIELD)
u8 reserved3 : 4 ,
qp_mtu : 4 ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 qp_mtu : 4 ,
reserved3 : 4 ;
# endif
2018-03-01 20:51:32 +08:00
u8 initial_psn [ 3 ] ;
u8 reserved [ 8 ] ;
} ;
2020-05-03 20:38:41 +08:00
struct smc_llc_msg_add_link_cont_rt {
__be32 rmb_key ;
__be32 rmb_key_new ;
__be64 rmb_vaddr_new ;
} ;
2021-10-16 17:37:50 +08:00
struct smc_llc_msg_add_link_v2_ext {
# if defined(__BIG_ENDIAN_BITFIELD)
u8 v2_direct : 1 ,
reserved : 7 ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 reserved : 7 ,
v2_direct : 1 ;
# endif
u8 reserved2 ;
u8 client_target_gid [ SMC_GID_SIZE ] ;
u8 reserved3 [ 8 ] ;
u16 num_rkeys ;
struct smc_llc_msg_add_link_cont_rt rt [ ] ;
} __packed ; /* format defined in
* IBM Shared Memory Communications Version 2
* ( https : //www.ibm.com/support/pages/node/6326337)
*/
struct smc_llc_msg_req_add_link_v2 {
struct smc_llc_hdr hd ;
u8 reserved [ 20 ] ;
u8 gid_cnt ;
u8 reserved2 [ 3 ] ;
u8 gid [ ] [ SMC_GID_SIZE ] ;
} ;
2020-05-03 20:38:41 +08:00
# define SMC_LLC_RKEYS_PER_CONT_MSG 2
struct smc_llc_msg_add_link_cont { /* type 0x03 */
struct smc_llc_hdr hd ;
u8 link_num ;
u8 num_rkeys ;
u8 reserved2 [ 2 ] ;
struct smc_llc_msg_add_link_cont_rt rt [ SMC_LLC_RKEYS_PER_CONT_MSG ] ;
u8 reserved [ 4 ] ;
} __packed ; /* format defined in RFC7609 */
2018-03-01 20:51:32 +08:00
# define SMC_LLC_FLAG_DEL_LINK_ALL 0x40
# define SMC_LLC_FLAG_DEL_LINK_ORDERLY 0x20
struct smc_llc_msg_del_link { /* type 0x04 */
struct smc_llc_hdr hd ;
u8 link_num ;
__be32 reason ;
u8 reserved [ 35 ] ;
} __packed ; /* format defined in RFC7609 */
2018-03-01 20:51:29 +08:00
struct smc_llc_msg_test_link { /* type 0x07 */
struct smc_llc_hdr hd ;
u8 user_data [ 16 ] ;
u8 reserved [ 24 ] ;
} ;
2018-03-01 20:51:30 +08:00
struct smc_rmb_rtoken {
union {
u8 num_rkeys ; /* first rtoken byte of CONFIRM LINK msg */
/* is actually the num of rtokens, first */
/* rtoken is always for the current link */
u8 link_id ; /* link id of the rtoken */
} ;
__be32 rmb_key ;
__be64 rmb_vaddr ;
} __packed ; /* format defined in RFC7609 */
2021-10-16 17:37:50 +08:00
# define SMC_LLC_RKEYS_PER_MSG 3
# define SMC_LLC_RKEYS_PER_MSG_V2 255
2018-03-01 20:51:30 +08:00
struct smc_llc_msg_confirm_rkey { /* type 0x06 */
struct smc_llc_hdr hd ;
struct smc_rmb_rtoken rtoken [ SMC_LLC_RKEYS_PER_MSG ] ;
u8 reserved ;
} ;
# define SMC_LLC_DEL_RKEY_MAX 8
2020-04-30 21:55:48 +08:00
# define SMC_LLC_FLAG_RKEY_RETRY 0x10
2018-03-01 20:51:30 +08:00
# define SMC_LLC_FLAG_RKEY_NEG 0x20
struct smc_llc_msg_delete_rkey { /* type 0x09 */
struct smc_llc_hdr hd ;
u8 num_rkeys ;
u8 err_mask ;
u8 reserved [ 2 ] ;
__be32 rkey [ 8 ] ;
u8 reserved2 [ 4 ] ;
} ;
2021-10-16 17:37:50 +08:00
struct smc_llc_msg_delete_rkey_v2 { /* type 0x29 */
struct smc_llc_hdr hd ;
u8 num_rkeys ;
u8 num_inval_rkeys ;
u8 reserved [ 2 ] ;
__be32 rkey [ ] ;
} ;
2018-03-01 20:51:26 +08:00
union smc_llc_msg {
struct smc_llc_msg_confirm_link confirm_link ;
2018-03-01 20:51:32 +08:00
struct smc_llc_msg_add_link add_link ;
2021-10-16 17:37:50 +08:00
struct smc_llc_msg_req_add_link_v2 req_add_link ;
2020-05-03 20:38:41 +08:00
struct smc_llc_msg_add_link_cont add_link_cont ;
2018-03-01 20:51:32 +08:00
struct smc_llc_msg_del_link delete_link ;
2018-03-01 20:51:30 +08:00
struct smc_llc_msg_confirm_rkey confirm_rkey ;
struct smc_llc_msg_delete_rkey delete_rkey ;
2018-03-01 20:51:29 +08:00
struct smc_llc_msg_test_link test_link ;
2018-03-01 20:51:26 +08:00
struct {
struct smc_llc_hdr hdr ;
u8 data [ SMC_LLC_DATA_LEN ] ;
} raw ;
} ;
# define SMC_LLC_FLAG_RESP 0x80
2020-04-29 23:10:46 +08:00
struct smc_llc_qentry {
struct list_head list ;
struct smc_link * link ;
union smc_llc_msg msg ;
} ;
2020-05-03 20:38:50 +08:00
static void smc_llc_enqueue ( struct smc_link * link , union smc_llc_msg * llc ) ;
2020-04-30 21:55:38 +08:00
struct smc_llc_qentry * smc_llc_flow_qentry_clr ( struct smc_llc_flow * flow )
{
struct smc_llc_qentry * qentry = flow - > qentry ;
flow - > qentry = NULL ;
return qentry ;
}
void smc_llc_flow_qentry_del ( struct smc_llc_flow * flow )
{
struct smc_llc_qentry * qentry ;
if ( flow - > qentry ) {
qentry = flow - > qentry ;
flow - > qentry = NULL ;
kfree ( qentry ) ;
}
}
static inline void smc_llc_flow_qentry_set ( struct smc_llc_flow * flow ,
struct smc_llc_qentry * qentry )
{
flow - > qentry = qentry ;
}
2020-07-08 23:05:11 +08:00
static void smc_llc_flow_parallel ( struct smc_link_group * lgr , u8 flow_type ,
struct smc_llc_qentry * qentry )
{
2021-10-16 17:37:50 +08:00
u8 msg_type = qentry - > msg . raw . hdr . common . llc_type ;
2020-07-08 23:05:11 +08:00
if ( ( msg_type = = SMC_LLC_ADD_LINK | | msg_type = = SMC_LLC_DELETE_LINK ) & &
flow_type ! = msg_type & & ! lgr - > delayed_event ) {
lgr - > delayed_event = qentry ;
return ;
}
/* drop parallel or already-in-progress llc requests */
if ( flow_type ! = msg_type )
2021-12-28 21:06:11 +08:00
pr_warn_once ( " smc: SMC-R lg %*phN net %llu dropped parallel "
2020-07-08 23:05:11 +08:00
" LLC msg: msg %d flow %d role %d \n " ,
SMC_LGR_ID_SIZE , & lgr - > id ,
2021-12-28 21:06:11 +08:00
lgr - > net - > net_cookie ,
2020-07-08 23:05:11 +08:00
qentry - > msg . raw . hdr . common . type ,
flow_type , lgr - > role ) ;
kfree ( qentry ) ;
}
2020-04-30 21:55:38 +08:00
/* try to start a new llc flow, initiated by an incoming llc msg */
static bool smc_llc_flow_start ( struct smc_llc_flow * flow ,
struct smc_llc_qentry * qentry )
{
struct smc_link_group * lgr = qentry - > link - > lgr ;
spin_lock_bh ( & lgr - > llc_flow_lock ) ;
if ( flow - > type ) {
/* a flow is already active */
2020-07-08 23:05:11 +08:00
smc_llc_flow_parallel ( lgr , flow - > type , qentry ) ;
2020-04-30 21:55:38 +08:00
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
return false ;
}
2021-10-16 17:37:50 +08:00
switch ( qentry - > msg . raw . hdr . common . llc_type ) {
2020-04-30 21:55:38 +08:00
case SMC_LLC_ADD_LINK :
flow - > type = SMC_LLC_FLOW_ADD_LINK ;
break ;
case SMC_LLC_DELETE_LINK :
flow - > type = SMC_LLC_FLOW_DEL_LINK ;
break ;
case SMC_LLC_CONFIRM_RKEY :
case SMC_LLC_DELETE_RKEY :
flow - > type = SMC_LLC_FLOW_RKEY ;
break ;
default :
flow - > type = SMC_LLC_FLOW_NONE ;
}
smc_llc_flow_qentry_set ( flow , qentry ) ;
2020-07-08 23:05:11 +08:00
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
2020-04-30 21:55:38 +08:00
return true ;
}
/* start a new local llc flow, wait till current flow finished */
int smc_llc_flow_initiate ( struct smc_link_group * lgr ,
enum smc_llc_flowtype type )
{
enum smc_llc_flowtype allowed_remote = SMC_LLC_FLOW_NONE ;
int rc ;
/* all flows except confirm_rkey and delete_rkey are exclusive,
* confirm / delete rkey flows can run concurrently ( local and remote )
*/
if ( type = = SMC_LLC_FLOW_RKEY )
allowed_remote = SMC_LLC_FLOW_RKEY ;
again :
if ( list_empty ( & lgr - > list ) )
return - ENODEV ;
spin_lock_bh ( & lgr - > llc_flow_lock ) ;
if ( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_NONE & &
( lgr - > llc_flow_rmt . type = = SMC_LLC_FLOW_NONE | |
lgr - > llc_flow_rmt . type = = allowed_remote ) ) {
lgr - > llc_flow_lcl . type = type ;
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
return 0 ;
}
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
2020-07-08 23:05:11 +08:00
rc = wait_event_timeout ( lgr - > llc_flow_waiter , ( list_empty ( & lgr - > list ) | |
( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_NONE & &
( lgr - > llc_flow_rmt . type = = SMC_LLC_FLOW_NONE | |
lgr - > llc_flow_rmt . type = = allowed_remote ) ) ) ,
SMC_LLC_WAIT_TIME * 10 ) ;
2020-04-30 21:55:38 +08:00
if ( ! rc )
return - ETIMEDOUT ;
goto again ;
}
/* finish the current llc flow */
void smc_llc_flow_stop ( struct smc_link_group * lgr , struct smc_llc_flow * flow )
{
spin_lock_bh ( & lgr - > llc_flow_lock ) ;
memset ( flow , 0 , sizeof ( * flow ) ) ;
flow - > type = SMC_LLC_FLOW_NONE ;
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
if ( ! list_empty ( & lgr - > list ) & & lgr - > delayed_event & &
flow = = & lgr - > llc_flow_lcl )
schedule_work ( & lgr - > llc_event_work ) ;
else
2020-07-08 23:05:11 +08:00
wake_up ( & lgr - > llc_flow_waiter ) ;
2020-04-30 21:55:38 +08:00
}
/* lnk is optional and used for early wakeup when link goes down, useful in
* cases where we wait for a response on the link after we sent a request
*/
struct smc_llc_qentry * smc_llc_wait ( struct smc_link_group * lgr ,
struct smc_link * lnk ,
int time_out , u8 exp_msg )
{
struct smc_llc_flow * flow = & lgr - > llc_flow_lcl ;
2020-07-08 23:05:11 +08:00
u8 rcv_msg ;
2020-04-30 21:55:38 +08:00
2020-07-08 23:05:11 +08:00
wait_event_timeout ( lgr - > llc_msg_waiter ,
( flow - > qentry | |
( lnk & & ! smc_link_usable ( lnk ) ) | |
list_empty ( & lgr - > list ) ) ,
time_out ) ;
2020-04-30 21:55:38 +08:00
if ( ! flow - > qentry | |
( lnk & & ! smc_link_usable ( lnk ) ) | | list_empty ( & lgr - > list ) ) {
smc_llc_flow_qentry_del ( flow ) ;
goto out ;
}
2021-10-16 17:37:50 +08:00
rcv_msg = flow - > qentry - > msg . raw . hdr . common . llc_type ;
2020-07-08 23:05:11 +08:00
if ( exp_msg & & rcv_msg ! = exp_msg ) {
2020-04-30 21:55:38 +08:00
if ( exp_msg = = SMC_LLC_ADD_LINK & &
2020-07-08 23:05:11 +08:00
rcv_msg = = SMC_LLC_DELETE_LINK ) {
2020-04-30 21:55:38 +08:00
/* flow_start will delay the unexpected msg */
smc_llc_flow_start ( & lgr - > llc_flow_lcl ,
smc_llc_flow_qentry_clr ( flow ) ) ;
return NULL ;
}
2021-12-28 21:06:11 +08:00
pr_warn_once ( " smc: SMC-R lg %*phN net %llu dropped unexpected LLC msg: "
2020-07-08 23:05:11 +08:00
" msg %d exp %d flow %d role %d flags %x \n " ,
2021-12-28 21:06:11 +08:00
SMC_LGR_ID_SIZE , & lgr - > id , lgr - > net - > net_cookie ,
rcv_msg , exp_msg ,
2020-07-08 23:05:11 +08:00
flow - > type , lgr - > role ,
flow - > qentry - > msg . raw . hdr . flags ) ;
2020-04-30 21:55:38 +08:00
smc_llc_flow_qentry_del ( flow ) ;
}
out :
return flow - > qentry ;
}
2017-01-09 23:55:21 +08:00
/********************************** send *************************************/
struct smc_llc_tx_pend {
} ;
/* handler for send/transmission completion of an LLC msg */
static void smc_llc_tx_handler ( struct smc_wr_tx_pend_priv * pend ,
struct smc_link * link ,
enum ib_wc_status wc_status )
{
/* future work: handle wc_status error for recovery and failover */
}
/**
* smc_llc_add_pending_send ( ) - add LLC control message to pending WQE transmits
* @ link : Pointer to SMC link used for sending LLC control message .
* @ wr_buf : Out variable returning pointer to work request payload buffer .
* @ pend : Out variable returning pointer to private pending WR tracking .
* It ' s the context the transmit complete handler will get .
*
* Reserves and pre - fills an entry for a pending work request send / tx .
* Used by mid - level smc_llc_send_msg ( ) to prepare for later actual send / tx .
* Can sleep due to smc_get_ctrl_buf ( if not in softirq context ) .
*
* Return : 0 on success , otherwise an error value .
*/
static int smc_llc_add_pending_send ( struct smc_link * link ,
struct smc_wr_buf * * wr_buf ,
struct smc_wr_tx_pend_priv * * pend )
{
int rc ;
2019-02-04 20:44:44 +08:00
rc = smc_wr_tx_get_free_slot ( link , smc_llc_tx_handler , wr_buf , NULL ,
pend ) ;
2017-01-09 23:55:21 +08:00
if ( rc < 0 )
return rc ;
BUILD_BUG_ON_MSG (
sizeof ( union smc_llc_msg ) > SMC_WR_BUF_SIZE ,
" must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg) " ) ;
BUILD_BUG_ON_MSG (
sizeof ( union smc_llc_msg ) ! = SMC_WR_TX_SIZE ,
" must adapt SMC_WR_TX_SIZE to sizeof(struct smc_llc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send() " ) ;
BUILD_BUG_ON_MSG (
sizeof ( struct smc_llc_tx_pend ) > SMC_WR_TX_PEND_PRIV_SIZE ,
" must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend) " ) ;
return 0 ;
}
2021-10-16 17:37:50 +08:00
static int smc_llc_add_pending_send_v2 ( struct smc_link * link ,
struct smc_wr_v2_buf * * wr_buf ,
struct smc_wr_tx_pend_priv * * pend )
{
int rc ;
rc = smc_wr_tx_get_v2_slot ( link , smc_llc_tx_handler , wr_buf , pend ) ;
if ( rc < 0 )
return rc ;
return 0 ;
}
static void smc_llc_init_msg_hdr ( struct smc_llc_hdr * hdr ,
struct smc_link_group * lgr , size_t len )
{
if ( lgr - > smc_version = = SMC_V2 ) {
hdr - > common . llc_version = SMC_V2 ;
hdr - > length_v2 = len ;
} else {
hdr - > common . llc_version = 0 ;
hdr - > length = len ;
}
}
2017-01-09 23:55:21 +08:00
/* high-level API to send LLC confirm link */
2018-07-25 22:35:30 +08:00
int smc_llc_send_confirm_link ( struct smc_link * link ,
2017-01-09 23:55:21 +08:00
enum smc_llc_reqresp reqresp )
{
struct smc_llc_msg_confirm_link * confllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
return - ENOLINK ;
2017-01-09 23:55:21 +08:00
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2017-01-09 23:55:21 +08:00
confllc = ( struct smc_llc_msg_confirm_link * ) wr_buf ;
memset ( confllc , 0 , sizeof ( * confllc ) ) ;
2021-10-16 17:37:50 +08:00
confllc - > hd . common . llc_type = SMC_LLC_CONFIRM_LINK ;
smc_llc_init_msg_hdr ( & confllc - > hd , link - > lgr , sizeof ( * confllc ) ) ;
2018-03-01 20:51:31 +08:00
confllc - > hd . flags | = SMC_LLC_FLAG_NO_RMBE_EYEC ;
2017-01-09 23:55:21 +08:00
if ( reqresp = = SMC_LLC_RESP )
confllc - > hd . flags | = SMC_LLC_FLAG_RESP ;
2018-07-25 22:35:30 +08:00
memcpy ( confllc - > sender_mac , link - > smcibdev - > mac [ link - > ibport - 1 ] ,
ETH_ALEN ) ;
2018-07-25 22:35:31 +08:00
memcpy ( confllc - > sender_gid , link - > gid , SMC_GID_SIZE ) ;
2017-01-09 23:55:21 +08:00
hton24 ( confllc - > sender_qp_num , link - > roce_qp - > qp_num ) ;
2018-02-28 19:44:08 +08:00
confllc - > link_num = link - > link_id ;
2020-05-04 20:18:47 +08:00
memcpy ( confllc - > link_uid , link - > link_uid , SMC_LGR_ID_SIZE ) ;
2023-08-17 21:20:31 +08:00
confllc - > max_links = SMC_LINKS_ADD_LNK_MAX ;
2023-08-17 21:20:30 +08:00
if ( link - > lgr - > smc_version = = SMC_V2 & &
2023-08-17 21:20:31 +08:00
link - > lgr - > peer_smc_release > = SMC_RELEASE_1 ) {
2023-08-17 21:20:30 +08:00
confllc - > max_conns = link - > lgr - > max_conns ;
2023-08-17 21:20:31 +08:00
confllc - > max_links = link - > lgr - > max_links ;
}
2018-03-01 20:51:32 +08:00
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
2021-10-07 22:14:40 +08:00
put_out :
smc_wr_tx_link_put ( link ) ;
2018-03-01 20:51:32 +08:00
return rc ;
}
2018-05-15 23:04:55 +08:00
/* send LLC confirm rkey request */
2020-04-30 21:55:44 +08:00
static int smc_llc_send_confirm_rkey ( struct smc_link * send_link ,
2018-05-15 23:04:55 +08:00
struct smc_buf_desc * rmb_desc )
{
struct smc_llc_msg_confirm_rkey * rkeyllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
2020-04-30 21:55:44 +08:00
struct smc_link * link ;
int i , rc , rtok_ix ;
2018-05-15 23:04:55 +08:00
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( send_link ) )
return - ENOLINK ;
2020-04-30 21:55:44 +08:00
rc = smc_llc_add_pending_send ( send_link , & wr_buf , & pend ) ;
2018-05-15 23:04:55 +08:00
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2018-05-15 23:04:55 +08:00
rkeyllc = ( struct smc_llc_msg_confirm_rkey * ) wr_buf ;
memset ( rkeyllc , 0 , sizeof ( * rkeyllc ) ) ;
2021-10-16 17:37:50 +08:00
rkeyllc - > hd . common . llc_type = SMC_LLC_CONFIRM_RKEY ;
smc_llc_init_msg_hdr ( & rkeyllc - > hd , send_link - > lgr , sizeof ( * rkeyllc ) ) ;
2020-04-30 21:55:44 +08:00
rtok_ix = 1 ;
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + ) {
link = & send_link - > lgr - > lnk [ i ] ;
2020-07-18 21:06:16 +08:00
if ( smc_link_active ( link ) & & link ! = send_link ) {
2020-04-30 21:55:44 +08:00
rkeyllc - > rtoken [ rtok_ix ] . link_id = link - > link_id ;
rkeyllc - > rtoken [ rtok_ix ] . rmb_key =
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
htonl ( rmb_desc - > mr [ link - > link_idx ] - > rkey ) ;
rkeyllc - > rtoken [ rtok_ix ] . rmb_vaddr = rmb_desc - > is_vm ?
cpu_to_be64 ( ( uintptr_t ) rmb_desc - > cpu_addr ) :
cpu_to_be64 ( ( u64 ) sg_dma_address
( rmb_desc - > sgt [ link - > link_idx ] . sgl ) ) ;
2020-04-30 21:55:44 +08:00
rtok_ix + + ;
}
}
/* rkey of send_link is in rtoken[0] */
rkeyllc - > rtoken [ 0 ] . num_rkeys = rtok_ix - 1 ;
2018-05-15 23:04:55 +08:00
rkeyllc - > rtoken [ 0 ] . rmb_key =
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
htonl ( rmb_desc - > mr [ send_link - > link_idx ] - > rkey ) ;
rkeyllc - > rtoken [ 0 ] . rmb_vaddr = rmb_desc - > is_vm ?
cpu_to_be64 ( ( uintptr_t ) rmb_desc - > cpu_addr ) :
cpu_to_be64 ( ( u64 ) sg_dma_address
( rmb_desc - > sgt [ send_link - > link_idx ] . sgl ) ) ;
2018-05-15 23:04:55 +08:00
/* send llc message */
2020-04-30 21:55:44 +08:00
rc = smc_wr_tx_send ( send_link , pend ) ;
2021-10-07 22:14:40 +08:00
put_out :
smc_wr_tx_link_put ( send_link ) ;
2018-05-15 23:04:55 +08:00
return rc ;
}
2018-11-22 17:26:42 +08:00
/* send LLC delete rkey request */
static int smc_llc_send_delete_rkey ( struct smc_link * link ,
struct smc_buf_desc * rmb_desc )
{
struct smc_llc_msg_delete_rkey * rkeyllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
return - ENOLINK ;
2018-11-22 17:26:42 +08:00
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2018-11-22 17:26:42 +08:00
rkeyllc = ( struct smc_llc_msg_delete_rkey * ) wr_buf ;
memset ( rkeyllc , 0 , sizeof ( * rkeyllc ) ) ;
2021-10-16 17:37:50 +08:00
rkeyllc - > hd . common . llc_type = SMC_LLC_DELETE_RKEY ;
smc_llc_init_msg_hdr ( & rkeyllc - > hd , link - > lgr , sizeof ( * rkeyllc ) ) ;
2018-11-22 17:26:42 +08:00
rkeyllc - > num_rkeys = 1 ;
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
rkeyllc - > rkey [ 0 ] = htonl ( rmb_desc - > mr [ link - > link_idx ] - > rkey ) ;
2018-11-22 17:26:42 +08:00
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
2021-10-07 22:14:40 +08:00
put_out :
smc_wr_tx_link_put ( link ) ;
2018-11-22 17:26:42 +08:00
return rc ;
}
2021-10-16 17:37:50 +08:00
/* return first buffer from any of the next buf lists */
static struct smc_buf_desc * _smc_llc_get_next_rmb ( struct smc_link_group * lgr ,
int * buf_lst )
{
struct smc_buf_desc * buf_pos ;
while ( * buf_lst < SMC_RMBE_SIZES ) {
buf_pos = list_first_entry_or_null ( & lgr - > rmbs [ * buf_lst ] ,
struct smc_buf_desc , list ) ;
if ( buf_pos )
return buf_pos ;
( * buf_lst ) + + ;
}
return NULL ;
}
/* return next rmb from buffer lists */
static struct smc_buf_desc * smc_llc_get_next_rmb ( struct smc_link_group * lgr ,
int * buf_lst ,
struct smc_buf_desc * buf_pos )
{
struct smc_buf_desc * buf_next ;
2023-05-26 19:49:00 +08:00
if ( ! buf_pos )
return _smc_llc_get_next_rmb ( lgr , buf_lst ) ;
if ( list_is_last ( & buf_pos - > list , & lgr - > rmbs [ * buf_lst ] ) ) {
2021-10-16 17:37:50 +08:00
( * buf_lst ) + + ;
return _smc_llc_get_next_rmb ( lgr , buf_lst ) ;
}
buf_next = list_next_entry ( buf_pos , list ) ;
return buf_next ;
}
static struct smc_buf_desc * smc_llc_get_first_rmb ( struct smc_link_group * lgr ,
int * buf_lst )
{
* buf_lst = 0 ;
return smc_llc_get_next_rmb ( lgr , buf_lst , NULL ) ;
}
static int smc_llc_fill_ext_v2 ( struct smc_llc_msg_add_link_v2_ext * ext ,
struct smc_link * link , struct smc_link * link_new )
{
struct smc_link_group * lgr = link - > lgr ;
struct smc_buf_desc * buf_pos ;
int prim_lnk_idx , lnk_idx , i ;
struct smc_buf_desc * rmb ;
int len = sizeof ( * ext ) ;
int buf_lst ;
ext - > v2_direct = ! lgr - > uses_gateway ;
memcpy ( ext - > client_target_gid , link_new - > gid , SMC_GID_SIZE ) ;
prim_lnk_idx = link - > link_idx ;
lnk_idx = link_new - > link_idx ;
2023-02-02 16:26:42 +08:00
down_write ( & lgr - > rmbs_lock ) ;
2021-10-16 17:37:50 +08:00
ext - > num_rkeys = lgr - > conns_num ;
if ( ! ext - > num_rkeys )
goto out ;
buf_pos = smc_llc_get_first_rmb ( lgr , & buf_lst ) ;
for ( i = 0 ; i < ext - > num_rkeys ; i + + ) {
2023-05-26 19:49:01 +08:00
while ( buf_pos & & ! ( buf_pos ) - > used )
buf_pos = smc_llc_get_next_rmb ( lgr , & buf_lst , buf_pos ) ;
2021-10-16 17:37:50 +08:00
if ( ! buf_pos )
break ;
rmb = buf_pos ;
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
ext - > rt [ i ] . rmb_key = htonl ( rmb - > mr [ prim_lnk_idx ] - > rkey ) ;
ext - > rt [ i ] . rmb_key_new = htonl ( rmb - > mr [ lnk_idx ] - > rkey ) ;
ext - > rt [ i ] . rmb_vaddr_new = rmb - > is_vm ?
cpu_to_be64 ( ( uintptr_t ) rmb - > cpu_addr ) :
2021-10-16 17:37:50 +08:00
cpu_to_be64 ( ( u64 ) sg_dma_address ( rmb - > sgt [ lnk_idx ] . sgl ) ) ;
buf_pos = smc_llc_get_next_rmb ( lgr , & buf_lst , buf_pos ) ;
}
len + = i * sizeof ( ext - > rt [ 0 ] ) ;
out :
2023-02-02 16:26:42 +08:00
up_write ( & lgr - > rmbs_lock ) ;
2021-10-16 17:37:50 +08:00
return len ;
}
2018-03-01 20:51:32 +08:00
/* send ADD LINK request or response */
2018-07-25 22:35:31 +08:00
int smc_llc_send_add_link ( struct smc_link * link , u8 mac [ ] , u8 gid [ ] ,
2020-05-01 18:48:04 +08:00
struct smc_link * link_new ,
2018-03-01 20:51:32 +08:00
enum smc_llc_reqresp reqresp )
{
2021-10-16 17:37:50 +08:00
struct smc_llc_msg_add_link_v2_ext * ext = NULL ;
2018-03-01 20:51:32 +08:00
struct smc_llc_msg_add_link * addllc ;
struct smc_wr_tx_pend_priv * pend ;
2021-10-16 17:37:50 +08:00
int len = sizeof ( * addllc ) ;
2018-03-01 20:51:32 +08:00
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
return - ENOLINK ;
2021-10-16 17:37:50 +08:00
if ( link - > lgr - > smc_version = = SMC_V2 ) {
struct smc_wr_v2_buf * wr_buf ;
rc = smc_llc_add_pending_send_v2 ( link , & wr_buf , & pend ) ;
if ( rc )
goto put_out ;
addllc = ( struct smc_llc_msg_add_link * ) wr_buf ;
ext = ( struct smc_llc_msg_add_link_v2_ext * )
& wr_buf - > raw [ sizeof ( * addllc ) ] ;
memset ( ext , 0 , SMC_WR_TX_SIZE ) ;
} else {
struct smc_wr_buf * wr_buf ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
goto put_out ;
addllc = ( struct smc_llc_msg_add_link * ) wr_buf ;
}
2020-05-01 18:48:04 +08:00
memset ( addllc , 0 , sizeof ( * addllc ) ) ;
2021-10-16 17:37:50 +08:00
addllc - > hd . common . llc_type = SMC_LLC_ADD_LINK ;
2020-05-01 18:48:04 +08:00
if ( reqresp = = SMC_LLC_RESP )
addllc - > hd . flags | = SMC_LLC_FLAG_RESP ;
memcpy ( addllc - > sender_mac , mac , ETH_ALEN ) ;
memcpy ( addllc - > sender_gid , gid , SMC_GID_SIZE ) ;
if ( link_new ) {
addllc - > link_num = link_new - > link_id ;
hton24 ( addllc - > sender_qp_num , link_new - > roce_qp - > qp_num ) ;
hton24 ( addllc - > initial_psn , link_new - > psn_initial ) ;
if ( reqresp = = SMC_LLC_REQ )
addllc - > qp_mtu = link_new - > path_mtu ;
else
addllc - > qp_mtu = min ( link_new - > path_mtu ,
link_new - > peer_mtu ) ;
}
2021-10-16 17:37:50 +08:00
if ( ext & & link_new )
len + = smc_llc_fill_ext_v2 ( ext , link , link_new ) ;
smc_llc_init_msg_hdr ( & addllc - > hd , link - > lgr , len ) ;
2018-03-01 20:51:32 +08:00
/* send llc message */
2021-10-16 17:37:50 +08:00
if ( link - > lgr - > smc_version = = SMC_V2 )
rc = smc_wr_tx_v2_send ( link , pend , len ) ;
else
rc = smc_wr_tx_send ( link , pend ) ;
2021-10-07 22:14:40 +08:00
put_out :
smc_wr_tx_link_put ( link ) ;
2018-03-01 20:51:32 +08:00
return rc ;
}
/* send DELETE LINK request or response */
2020-05-01 18:48:04 +08:00
int smc_llc_send_delete_link ( struct smc_link * link , u8 link_del_id ,
enum smc_llc_reqresp reqresp , bool orderly ,
u32 reason )
2018-03-01 20:51:32 +08:00
{
struct smc_llc_msg_del_link * delllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
return - ENOLINK ;
2018-03-01 20:51:32 +08:00
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2018-03-01 20:51:32 +08:00
delllc = ( struct smc_llc_msg_del_link * ) wr_buf ;
2020-05-01 18:48:04 +08:00
memset ( delllc , 0 , sizeof ( * delllc ) ) ;
2021-10-16 17:37:50 +08:00
delllc - > hd . common . llc_type = SMC_LLC_DELETE_LINK ;
smc_llc_init_msg_hdr ( & delllc - > hd , link - > lgr , sizeof ( * delllc ) ) ;
2020-05-01 18:48:04 +08:00
if ( reqresp = = SMC_LLC_RESP )
delllc - > hd . flags | = SMC_LLC_FLAG_RESP ;
if ( orderly )
delllc - > hd . flags | = SMC_LLC_FLAG_DEL_LINK_ORDERLY ;
if ( link_del_id )
delllc - > link_num = link_del_id ;
else
delllc - > hd . flags | = SMC_LLC_FLAG_DEL_LINK_ALL ;
delllc - > reason = htonl ( reason ) ;
2017-01-09 23:55:21 +08:00
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
2021-10-07 22:14:40 +08:00
put_out :
smc_wr_tx_link_put ( link ) ;
2017-01-09 23:55:21 +08:00
return rc ;
}
2018-05-15 23:04:57 +08:00
/* send LLC test link request */
static int smc_llc_send_test_link ( struct smc_link * link , u8 user_data [ 16 ] )
2018-03-01 20:51:29 +08:00
{
struct smc_llc_msg_test_link * testllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
return - ENOLINK ;
2018-03-01 20:51:29 +08:00
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2018-03-01 20:51:29 +08:00
testllc = ( struct smc_llc_msg_test_link * ) wr_buf ;
memset ( testllc , 0 , sizeof ( * testllc ) ) ;
2021-10-16 17:37:50 +08:00
testllc - > hd . common . llc_type = SMC_LLC_TEST_LINK ;
smc_llc_init_msg_hdr ( & testllc - > hd , link - > lgr , sizeof ( * testllc ) ) ;
2018-03-01 20:51:29 +08:00
memcpy ( testllc - > user_data , user_data , sizeof ( testllc - > user_data ) ) ;
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
2021-10-07 22:14:40 +08:00
put_out :
smc_wr_tx_link_put ( link ) ;
2018-03-01 20:51:29 +08:00
return rc ;
}
2020-04-29 23:10:46 +08:00
/* schedule an llc send on link, may wait for buffers */
static int smc_llc_send_message ( struct smc_link * link , void * llcbuf )
2018-03-01 20:51:30 +08:00
{
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
2020-04-29 23:10:46 +08:00
return - ENOLINK ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
2018-03-01 20:51:30 +08:00
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2020-04-29 23:10:46 +08:00
memcpy ( wr_buf , llcbuf , sizeof ( union smc_llc_msg ) ) ;
2021-10-07 22:14:40 +08:00
rc = smc_wr_tx_send ( link , pend ) ;
put_out :
smc_wr_tx_link_put ( link ) ;
return rc ;
2018-03-01 20:51:30 +08:00
}
2020-05-04 20:18:42 +08:00
/* schedule an llc send on link, may wait for buffers,
* and wait for send completion notification .
* @ return 0 on success
*/
static int smc_llc_send_message_wait ( struct smc_link * link , void * llcbuf )
{
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
2020-05-04 20:18:42 +08:00
return - ENOLINK ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2020-05-04 20:18:42 +08:00
memcpy ( wr_buf , llcbuf , sizeof ( union smc_llc_msg ) ) ;
2021-10-07 22:14:40 +08:00
rc = smc_wr_tx_send_wait ( link , pend , SMC_LLC_WAIT_TIME ) ;
put_out :
smc_wr_tx_link_put ( link ) ;
return rc ;
2020-05-04 20:18:42 +08:00
}
2017-01-09 23:55:21 +08:00
/********************************* receive ***********************************/
2020-05-03 20:38:40 +08:00
static int smc_llc_alloc_alt_link ( struct smc_link_group * lgr ,
enum smc_lgr_type lgr_new_t )
{
int i ;
if ( lgr - > type = = SMC_LGR_SYMMETRIC | |
( lgr - > type ! = SMC_LGR_SINGLE & &
( lgr_new_t = = SMC_LGR_ASYMMETRIC_LOCAL | |
lgr_new_t = = SMC_LGR_ASYMMETRIC_PEER ) ) )
return - EMLINK ;
if ( lgr_new_t = = SMC_LGR_ASYMMETRIC_LOCAL | |
lgr_new_t = = SMC_LGR_ASYMMETRIC_PEER ) {
for ( i = SMC_LINKS_PER_LGR_MAX - 1 ; i > = 0 ; i - - )
if ( lgr - > lnk [ i ] . state = = SMC_LNK_UNUSED )
return i ;
} else {
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + )
if ( lgr - > lnk [ i ] . state = = SMC_LNK_UNUSED )
return i ;
}
return - EMLINK ;
}
2020-05-03 20:38:41 +08:00
/* send one add_link_continue msg */
static int smc_llc_add_link_cont ( struct smc_link * link ,
struct smc_link * link_new , u8 * num_rkeys_todo ,
int * buf_lst , struct smc_buf_desc * * buf_pos )
{
struct smc_llc_msg_add_link_cont * addc_llc ;
struct smc_link_group * lgr = link - > lgr ;
int prim_lnk_idx , lnk_idx , i , rc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
struct smc_buf_desc * rmb ;
u8 n ;
2021-10-07 22:14:40 +08:00
if ( ! smc_wr_tx_link_hold ( link ) )
return - ENOLINK ;
2020-05-03 20:38:41 +08:00
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
2021-10-07 22:14:40 +08:00
goto put_out ;
2020-05-03 20:38:41 +08:00
addc_llc = ( struct smc_llc_msg_add_link_cont * ) wr_buf ;
memset ( addc_llc , 0 , sizeof ( * addc_llc ) ) ;
prim_lnk_idx = link - > link_idx ;
lnk_idx = link_new - > link_idx ;
addc_llc - > link_num = link_new - > link_id ;
addc_llc - > num_rkeys = * num_rkeys_todo ;
n = * num_rkeys_todo ;
for ( i = 0 ; i < min_t ( u8 , n , SMC_LLC_RKEYS_PER_CONT_MSG ) ; i + + ) {
2023-06-01 16:41:52 +08:00
while ( * buf_pos & & ! ( * buf_pos ) - > used )
* buf_pos = smc_llc_get_next_rmb ( lgr , buf_lst , * buf_pos ) ;
2020-05-03 20:38:41 +08:00
if ( ! * buf_pos ) {
addc_llc - > num_rkeys = addc_llc - > num_rkeys -
* num_rkeys_todo ;
* num_rkeys_todo = 0 ;
break ;
}
rmb = * buf_pos ;
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
addc_llc - > rt [ i ] . rmb_key = htonl ( rmb - > mr [ prim_lnk_idx ] - > rkey ) ;
addc_llc - > rt [ i ] . rmb_key_new = htonl ( rmb - > mr [ lnk_idx ] - > rkey ) ;
addc_llc - > rt [ i ] . rmb_vaddr_new = rmb - > is_vm ?
cpu_to_be64 ( ( uintptr_t ) rmb - > cpu_addr ) :
2020-05-03 20:38:41 +08:00
cpu_to_be64 ( ( u64 ) sg_dma_address ( rmb - > sgt [ lnk_idx ] . sgl ) ) ;
( * num_rkeys_todo ) - - ;
* buf_pos = smc_llc_get_next_rmb ( lgr , buf_lst , * buf_pos ) ;
}
2021-10-16 17:37:50 +08:00
addc_llc - > hd . common . llc_type = SMC_LLC_ADD_LINK_CONT ;
2020-05-03 20:38:41 +08:00
addc_llc - > hd . length = sizeof ( struct smc_llc_msg_add_link_cont ) ;
if ( lgr - > role = = SMC_CLNT )
addc_llc - > hd . flags | = SMC_LLC_FLAG_RESP ;
2021-10-07 22:14:40 +08:00
rc = smc_wr_tx_send ( link , pend ) ;
put_out :
smc_wr_tx_link_put ( link ) ;
return rc ;
2020-05-03 20:38:41 +08:00
}
static int smc_llc_cli_rkey_exchange ( struct smc_link * link ,
struct smc_link * link_new )
{
struct smc_llc_msg_add_link_cont * addc_llc ;
struct smc_link_group * lgr = link - > lgr ;
u8 max , num_rkeys_send , num_rkeys_recv ;
struct smc_llc_qentry * qentry ;
struct smc_buf_desc * buf_pos ;
int buf_lst ;
int rc = 0 ;
int i ;
2023-02-02 16:26:42 +08:00
down_write ( & lgr - > rmbs_lock ) ;
2020-05-03 20:38:41 +08:00
num_rkeys_send = lgr - > conns_num ;
buf_pos = smc_llc_get_first_rmb ( lgr , & buf_lst ) ;
do {
qentry = smc_llc_wait ( lgr , NULL , SMC_LLC_WAIT_TIME ,
SMC_LLC_ADD_LINK_CONT ) ;
if ( ! qentry ) {
rc = - ETIMEDOUT ;
break ;
}
addc_llc = & qentry - > msg . add_link_cont ;
num_rkeys_recv = addc_llc - > num_rkeys ;
max = min_t ( u8 , num_rkeys_recv , SMC_LLC_RKEYS_PER_CONT_MSG ) ;
for ( i = 0 ; i < max ; i + + ) {
smc_rtoken_set ( lgr , link - > link_idx , link_new - > link_idx ,
addc_llc - > rt [ i ] . rmb_key ,
addc_llc - > rt [ i ] . rmb_vaddr_new ,
addc_llc - > rt [ i ] . rmb_key_new ) ;
num_rkeys_recv - - ;
}
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
rc = smc_llc_add_link_cont ( link , link_new , & num_rkeys_send ,
& buf_lst , & buf_pos ) ;
if ( rc )
break ;
} while ( num_rkeys_send | | num_rkeys_recv ) ;
2023-02-02 16:26:42 +08:00
up_write ( & lgr - > rmbs_lock ) ;
2020-05-03 20:38:41 +08:00
return rc ;
}
2020-05-03 20:38:40 +08:00
/* prepare and send an add link reject response */
static int smc_llc_cli_add_link_reject ( struct smc_llc_qentry * qentry )
{
qentry - > msg . raw . hdr . flags | = SMC_LLC_FLAG_RESP ;
qentry - > msg . raw . hdr . flags | = SMC_LLC_FLAG_ADD_LNK_REJ ;
qentry - > msg . raw . hdr . add_link_rej_rsn = SMC_LLC_REJ_RSN_NO_ALT_PATH ;
2021-10-16 17:37:50 +08:00
smc_llc_init_msg_hdr ( & qentry - > msg . raw . hdr , qentry - > link - > lgr ,
sizeof ( qentry - > msg ) ) ;
2020-05-03 20:38:40 +08:00
return smc_llc_send_message ( qentry - > link , & qentry - > msg ) ;
}
2020-05-03 20:38:42 +08:00
static int smc_llc_cli_conf_link ( struct smc_link * link ,
struct smc_init_info * ini ,
struct smc_link * link_new ,
enum smc_lgr_type lgr_new_t )
{
struct smc_link_group * lgr = link - > lgr ;
struct smc_llc_qentry * qentry = NULL ;
int rc = 0 ;
/* receive CONFIRM LINK request over RoCE fabric */
qentry = smc_llc_wait ( lgr , NULL , SMC_LLC_WAIT_FIRST_TIME , 0 ) ;
if ( ! qentry ) {
rc = smc_llc_send_delete_link ( link , link_new - > link_id ,
SMC_LLC_REQ , false ,
SMC_LLC_DEL_LOST_PATH ) ;
return - ENOLINK ;
}
2021-10-16 17:37:50 +08:00
if ( qentry - > msg . raw . hdr . common . llc_type ! = SMC_LLC_CONFIRM_LINK ) {
2020-05-03 20:38:42 +08:00
/* received DELETE_LINK instead */
qentry - > msg . raw . hdr . flags | = SMC_LLC_FLAG_RESP ;
smc_llc_send_message ( link , & qentry - > msg ) ;
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
return - ENOLINK ;
}
2020-05-04 20:18:48 +08:00
smc_llc_save_peer_uid ( qentry ) ;
2020-05-03 20:38:42 +08:00
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
rc = smc_ib_modify_qp_rts ( link_new ) ;
if ( rc ) {
smc_llc_send_delete_link ( link , link_new - > link_id , SMC_LLC_REQ ,
false , SMC_LLC_DEL_LOST_PATH ) ;
return - ENOLINK ;
}
smc_wr_remember_qp_attr ( link_new ) ;
rc = smcr_buf_reg_lgr ( link_new ) ;
if ( rc ) {
smc_llc_send_delete_link ( link , link_new - > link_id , SMC_LLC_REQ ,
false , SMC_LLC_DEL_LOST_PATH ) ;
return - ENOLINK ;
}
/* send CONFIRM LINK response over RoCE fabric */
rc = smc_llc_send_confirm_link ( link_new , SMC_LLC_RESP ) ;
if ( rc ) {
smc_llc_send_delete_link ( link , link_new - > link_id , SMC_LLC_REQ ,
false , SMC_LLC_DEL_LOST_PATH ) ;
return - ENOLINK ;
}
smc_llc_link_active ( link_new ) ;
2020-05-04 20:18:44 +08:00
if ( lgr_new_t = = SMC_LGR_ASYMMETRIC_LOCAL | |
lgr_new_t = = SMC_LGR_ASYMMETRIC_PEER )
smcr_lgr_set_type_asym ( lgr , lgr_new_t , link_new - > link_idx ) ;
else
smcr_lgr_set_type ( lgr , lgr_new_t ) ;
2020-05-03 20:38:42 +08:00
return 0 ;
}
2021-10-16 17:37:50 +08:00
static void smc_llc_save_add_link_rkeys ( struct smc_link * link ,
struct smc_link * link_new )
{
struct smc_llc_msg_add_link_v2_ext * ext ;
struct smc_link_group * lgr = link - > lgr ;
int max , i ;
ext = ( struct smc_llc_msg_add_link_v2_ext * ) ( ( u8 * ) lgr - > wr_rx_buf_v2 +
SMC_WR_TX_SIZE ) ;
max = min_t ( u8 , ext - > num_rkeys , SMC_LLC_RKEYS_PER_MSG_V2 ) ;
2023-02-02 16:26:42 +08:00
down_write ( & lgr - > rmbs_lock ) ;
2021-10-16 17:37:50 +08:00
for ( i = 0 ; i < max ; i + + ) {
smc_rtoken_set ( lgr , link - > link_idx , link_new - > link_idx ,
ext - > rt [ i ] . rmb_key ,
ext - > rt [ i ] . rmb_vaddr_new ,
ext - > rt [ i ] . rmb_key_new ) ;
}
2023-02-02 16:26:42 +08:00
up_write ( & lgr - > rmbs_lock ) ;
2021-10-16 17:37:50 +08:00
}
2020-05-03 20:38:40 +08:00
static void smc_llc_save_add_link_info ( struct smc_link * link ,
struct smc_llc_msg_add_link * add_llc )
{
link - > peer_qpn = ntoh24 ( add_llc - > sender_qp_num ) ;
memcpy ( link - > peer_gid , add_llc - > sender_gid , SMC_GID_SIZE ) ;
memcpy ( link - > peer_mac , add_llc - > sender_mac , ETH_ALEN ) ;
link - > peer_psn = ntoh24 ( add_llc - > initial_psn ) ;
link - > peer_mtu = add_llc - > qp_mtu ;
}
/* as an SMC client, process an add link request */
int smc_llc_cli_add_link ( struct smc_link * link , struct smc_llc_qentry * qentry )
{
struct smc_llc_msg_add_link * llc = & qentry - > msg . add_link ;
enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC ;
struct smc_link_group * lgr = smc_get_lgr ( link ) ;
2021-10-16 17:37:43 +08:00
struct smc_init_info * ini = NULL ;
2020-05-03 20:38:40 +08:00
struct smc_link * lnk_new = NULL ;
int lnk_idx , rc = 0 ;
2020-09-04 03:53:15 +08:00
if ( ! llc - > qp_mtu )
goto out_reject ;
2021-10-16 17:37:43 +08:00
ini = kzalloc ( sizeof ( * ini ) , GFP_KERNEL ) ;
if ( ! ini ) {
rc = - ENOMEM ;
goto out_reject ;
}
2023-08-17 21:20:31 +08:00
if ( lgr - > type = = SMC_LGR_SINGLE & & lgr - > max_links < = 1 ) {
rc = 0 ;
goto out_reject ;
}
2021-10-16 17:37:43 +08:00
ini - > vlan_id = lgr - > vlan_id ;
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 ) {
ini - > check_smcrv2 = true ;
ini - > smcrv2 . saddr = lgr - > saddr ;
ini - > smcrv2 . daddr = smc_ib_gid_to_ipv4 ( llc - > sender_gid ) ;
}
2021-10-16 17:37:43 +08:00
smc_pnet_find_alt_roce ( lgr , ini , link - > smcibdev ) ;
2020-05-03 20:38:40 +08:00
if ( ! memcmp ( llc - > sender_gid , link - > peer_gid , SMC_GID_SIZE ) & &
2021-10-16 17:37:50 +08:00
( lgr - > smc_version = = SMC_V2 | |
! memcmp ( llc - > sender_mac , link - > peer_mac , ETH_ALEN ) ) ) {
if ( ! ini - > ib_dev & & ! ini - > smcrv2 . ib_dev_v2 )
2020-05-03 20:38:40 +08:00
goto out_reject ;
lgr_new_t = SMC_LGR_ASYMMETRIC_PEER ;
}
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 & & ! ini - > smcrv2 . ib_dev_v2 ) {
lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL ;
ini - > smcrv2 . ib_dev_v2 = link - > smcibdev ;
ini - > smcrv2 . ib_port_v2 = link - > ibport ;
} else if ( lgr - > smc_version < SMC_V2 & & ! ini - > ib_dev ) {
2020-05-03 20:38:40 +08:00
lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL ;
2021-10-16 17:37:43 +08:00
ini - > ib_dev = link - > smcibdev ;
ini - > ib_port = link - > ibport ;
2020-05-03 20:38:40 +08:00
}
lnk_idx = smc_llc_alloc_alt_link ( lgr , lgr_new_t ) ;
if ( lnk_idx < 0 )
goto out_reject ;
lnk_new = & lgr - > lnk [ lnk_idx ] ;
2021-10-16 17:37:43 +08:00
rc = smcr_link_init ( lgr , lnk_new , lnk_idx , ini ) ;
2020-05-03 20:38:40 +08:00
if ( rc )
goto out_reject ;
smc_llc_save_add_link_info ( lnk_new , llc ) ;
2020-05-04 20:18:47 +08:00
lnk_new - > link_id = llc - > link_num ; /* SMC server assigns link id */
smc_llc_link_set_uid ( lnk_new ) ;
2020-05-03 20:38:40 +08:00
rc = smc_ib_ready_link ( lnk_new ) ;
if ( rc )
goto out_clear_lnk ;
rc = smcr_buf_map_lgr ( lnk_new ) ;
if ( rc )
goto out_clear_lnk ;
rc = smc_llc_send_add_link ( link ,
2021-10-16 17:37:50 +08:00
lnk_new - > smcibdev - > mac [ lnk_new - > ibport - 1 ] ,
2020-05-03 20:38:40 +08:00
lnk_new - > gid , lnk_new , SMC_LLC_RESP ) ;
if ( rc )
goto out_clear_lnk ;
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 ) {
smc_llc_save_add_link_rkeys ( link , lnk_new ) ;
} else {
rc = smc_llc_cli_rkey_exchange ( link , lnk_new ) ;
if ( rc ) {
rc = 0 ;
goto out_clear_lnk ;
}
2020-05-03 20:38:40 +08:00
}
2021-10-16 17:37:43 +08:00
rc = smc_llc_cli_conf_link ( link , ini , lnk_new , lgr_new_t ) ;
2020-05-03 20:38:40 +08:00
if ( ! rc )
goto out ;
out_clear_lnk :
2021-08-09 17:05:56 +08:00
lnk_new - > state = SMC_LNK_INACTIVE ;
2020-05-05 21:01:20 +08:00
smcr_link_clear ( lnk_new , false ) ;
2020-05-03 20:38:40 +08:00
out_reject :
smc_llc_cli_add_link_reject ( qentry ) ;
out :
2021-10-16 17:37:43 +08:00
kfree ( ini ) ;
2020-05-03 20:38:40 +08:00
kfree ( qentry ) ;
return rc ;
}
2021-10-16 17:37:50 +08:00
static void smc_llc_send_request_add_link ( struct smc_link * link )
{
struct smc_llc_msg_req_add_link_v2 * llc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_v2_buf * wr_buf ;
struct smc_gidlist gidlist ;
int rc , len , i ;
if ( ! smc_wr_tx_link_hold ( link ) )
return ;
if ( link - > lgr - > type = = SMC_LGR_SYMMETRIC | |
link - > lgr - > type = = SMC_LGR_ASYMMETRIC_PEER )
goto put_out ;
smc_fill_gid_list ( link - > lgr , & gidlist , link - > smcibdev , link - > gid ) ;
if ( gidlist . len < = 1 )
goto put_out ;
rc = smc_llc_add_pending_send_v2 ( link , & wr_buf , & pend ) ;
if ( rc )
goto put_out ;
llc = ( struct smc_llc_msg_req_add_link_v2 * ) wr_buf ;
memset ( llc , 0 , SMC_WR_TX_SIZE ) ;
llc - > hd . common . llc_type = SMC_LLC_REQ_ADD_LINK ;
for ( i = 0 ; i < gidlist . len ; i + + )
memcpy ( llc - > gid [ i ] , gidlist . list [ i ] , sizeof ( gidlist . list [ 0 ] ) ) ;
llc - > gid_cnt = gidlist . len ;
len = sizeof ( * llc ) + ( gidlist . len * sizeof ( gidlist . list [ 0 ] ) ) ;
smc_llc_init_msg_hdr ( & llc - > hd , link - > lgr , len ) ;
rc = smc_wr_tx_v2_send ( link , pend , len ) ;
if ( ! rc )
/* set REQ_ADD_LINK flow and wait for response from peer */
link - > lgr - > llc_flow_lcl . type = SMC_LLC_FLOW_REQ_ADD_LINK ;
put_out :
smc_wr_tx_link_put ( link ) ;
}
2020-07-18 21:06:14 +08:00
/* as an SMC client, invite server to start the add_link processing */
static void smc_llc_cli_add_link_invite ( struct smc_link * link ,
struct smc_llc_qentry * qentry )
{
struct smc_link_group * lgr = smc_get_lgr ( link ) ;
2021-10-16 17:37:43 +08:00
struct smc_init_info * ini = NULL ;
2020-07-18 21:06:14 +08:00
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 ) {
smc_llc_send_request_add_link ( link ) ;
goto out ;
}
2020-07-18 21:06:14 +08:00
if ( lgr - > type = = SMC_LGR_SYMMETRIC | |
lgr - > type = = SMC_LGR_ASYMMETRIC_PEER )
goto out ;
2023-08-17 21:20:31 +08:00
if ( lgr - > type = = SMC_LGR_SINGLE & & lgr - > max_links < = 1 )
goto out ;
2021-10-16 17:37:43 +08:00
ini = kzalloc ( sizeof ( * ini ) , GFP_KERNEL ) ;
if ( ! ini )
goto out ;
ini - > vlan_id = lgr - > vlan_id ;
smc_pnet_find_alt_roce ( lgr , ini , link - > smcibdev ) ;
if ( ! ini - > ib_dev )
2020-07-18 21:06:14 +08:00
goto out ;
2021-10-16 17:37:43 +08:00
smc_llc_send_add_link ( link , ini - > ib_dev - > mac [ ini - > ib_port - 1 ] ,
ini - > ib_gid , NULL , SMC_LLC_REQ ) ;
2020-07-18 21:06:14 +08:00
out :
2021-10-16 17:37:43 +08:00
kfree ( ini ) ;
2020-07-18 21:06:14 +08:00
kfree ( qentry ) ;
}
2020-09-04 03:53:15 +08:00
static bool smc_llc_is_empty_llc_message ( union smc_llc_msg * llc )
{
int i ;
for ( i = 0 ; i < ARRAY_SIZE ( llc - > raw . data ) ; i + + )
if ( llc - > raw . data [ i ] )
return false ;
return true ;
}
2020-07-18 21:06:14 +08:00
static bool smc_llc_is_local_add_link ( union smc_llc_msg * llc )
{
2021-10-16 17:37:50 +08:00
if ( llc - > raw . hdr . common . llc_type = = SMC_LLC_ADD_LINK & &
2020-09-04 03:53:15 +08:00
smc_llc_is_empty_llc_message ( llc ) )
2020-07-18 21:06:14 +08:00
return true ;
return false ;
}
2020-05-03 20:38:42 +08:00
static void smc_llc_process_cli_add_link ( struct smc_link_group * lgr )
{
struct smc_llc_qentry * qentry ;
qentry = smc_llc_flow_qentry_clr ( & lgr - > llc_flow_lcl ) ;
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
down_write ( & lgr - > llc_conf_mutex ) ;
2020-07-18 21:06:14 +08:00
if ( smc_llc_is_local_add_link ( & qentry - > msg ) )
smc_llc_cli_add_link_invite ( qentry - > link , qentry ) ;
else
smc_llc_cli_add_link ( qentry - > link , qentry ) ;
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
up_write ( & lgr - > llc_conf_mutex ) ;
2020-05-03 20:38:42 +08:00
}
2020-05-03 20:38:48 +08:00
static int smc_llc_active_link_count ( struct smc_link_group * lgr )
{
int i , link_count = 0 ;
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + ) {
2020-07-18 21:06:16 +08:00
if ( ! smc_link_active ( & lgr - > lnk [ i ] ) )
2020-05-03 20:38:48 +08:00
continue ;
link_count + + ;
}
return link_count ;
}
2020-05-03 20:38:46 +08:00
/* find the asymmetric link when 3 links are established */
static struct smc_link * smc_llc_find_asym_link ( struct smc_link_group * lgr )
{
int asym_idx = - ENOENT ;
int i , j , k ;
bool found ;
/* determine asymmetric link */
found = false ;
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + ) {
for ( j = i + 1 ; j < SMC_LINKS_PER_LGR_MAX ; j + + ) {
if ( ! smc_link_usable ( & lgr - > lnk [ i ] ) | |
! smc_link_usable ( & lgr - > lnk [ j ] ) )
continue ;
if ( ! memcmp ( lgr - > lnk [ i ] . gid , lgr - > lnk [ j ] . gid ,
SMC_GID_SIZE ) ) {
found = true ; /* asym_lnk is i or j */
break ;
}
}
if ( found )
break ;
}
if ( ! found )
goto out ; /* no asymmetric link */
for ( k = 0 ; k < SMC_LINKS_PER_LGR_MAX ; k + + ) {
if ( ! smc_link_usable ( & lgr - > lnk [ k ] ) )
continue ;
if ( k ! = i & &
! memcmp ( lgr - > lnk [ i ] . peer_gid , lgr - > lnk [ k ] . peer_gid ,
SMC_GID_SIZE ) ) {
asym_idx = i ;
break ;
}
if ( k ! = j & &
! memcmp ( lgr - > lnk [ j ] . peer_gid , lgr - > lnk [ k ] . peer_gid ,
SMC_GID_SIZE ) ) {
asym_idx = j ;
break ;
}
}
out :
return ( asym_idx < 0 ) ? NULL : & lgr - > lnk [ asym_idx ] ;
}
static void smc_llc_delete_asym_link ( struct smc_link_group * lgr )
{
struct smc_link * lnk_new = NULL , * lnk_asym ;
struct smc_llc_qentry * qentry ;
int rc ;
lnk_asym = smc_llc_find_asym_link ( lgr ) ;
if ( ! lnk_asym )
return ; /* no asymmetric link */
if ( ! smc_link_downing ( & lnk_asym - > state ) )
return ;
2020-05-04 20:18:38 +08:00
lnk_new = smc_switch_conns ( lgr , lnk_asym , false ) ;
2020-05-03 20:38:46 +08:00
smc_wr_tx_wait_no_pending_sends ( lnk_asym ) ;
if ( ! lnk_new )
goto out_free ;
/* change flow type from ADD_LINK into DEL_LINK */
lgr - > llc_flow_lcl . type = SMC_LLC_FLOW_DEL_LINK ;
rc = smc_llc_send_delete_link ( lnk_new , lnk_asym - > link_id , SMC_LLC_REQ ,
true , SMC_LLC_DEL_NO_ASYM_NEEDED ) ;
if ( rc ) {
smcr_link_down_cond ( lnk_new ) ;
goto out_free ;
}
qentry = smc_llc_wait ( lgr , lnk_new , SMC_LLC_WAIT_TIME ,
SMC_LLC_DELETE_LINK ) ;
if ( ! qentry ) {
smcr_link_down_cond ( lnk_new ) ;
goto out_free ;
}
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
out_free :
2020-05-05 21:01:20 +08:00
smcr_link_clear ( lnk_asym , true ) ;
2020-05-03 20:38:46 +08:00
}
2020-05-03 20:38:44 +08:00
static int smc_llc_srv_rkey_exchange ( struct smc_link * link ,
struct smc_link * link_new )
{
struct smc_llc_msg_add_link_cont * addc_llc ;
struct smc_link_group * lgr = link - > lgr ;
u8 max , num_rkeys_send , num_rkeys_recv ;
struct smc_llc_qentry * qentry = NULL ;
struct smc_buf_desc * buf_pos ;
int buf_lst ;
int rc = 0 ;
int i ;
2023-02-02 16:26:42 +08:00
down_write ( & lgr - > rmbs_lock ) ;
2020-05-03 20:38:44 +08:00
num_rkeys_send = lgr - > conns_num ;
buf_pos = smc_llc_get_first_rmb ( lgr , & buf_lst ) ;
do {
smc_llc_add_link_cont ( link , link_new , & num_rkeys_send ,
& buf_lst , & buf_pos ) ;
qentry = smc_llc_wait ( lgr , link , SMC_LLC_WAIT_TIME ,
SMC_LLC_ADD_LINK_CONT ) ;
if ( ! qentry ) {
rc = - ETIMEDOUT ;
goto out ;
}
addc_llc = & qentry - > msg . add_link_cont ;
num_rkeys_recv = addc_llc - > num_rkeys ;
max = min_t ( u8 , num_rkeys_recv , SMC_LLC_RKEYS_PER_CONT_MSG ) ;
for ( i = 0 ; i < max ; i + + ) {
smc_rtoken_set ( lgr , link - > link_idx , link_new - > link_idx ,
addc_llc - > rt [ i ] . rmb_key ,
addc_llc - > rt [ i ] . rmb_vaddr_new ,
addc_llc - > rt [ i ] . rmb_key_new ) ;
num_rkeys_recv - - ;
}
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
} while ( num_rkeys_send | | num_rkeys_recv ) ;
out :
2023-02-02 16:26:42 +08:00
up_write ( & lgr - > rmbs_lock ) ;
2020-05-03 20:38:44 +08:00
return rc ;
}
2020-05-03 20:38:45 +08:00
static int smc_llc_srv_conf_link ( struct smc_link * link ,
struct smc_link * link_new ,
enum smc_lgr_type lgr_new_t )
{
struct smc_link_group * lgr = link - > lgr ;
struct smc_llc_qentry * qentry = NULL ;
int rc ;
/* send CONFIRM LINK request over the RoCE fabric */
rc = smc_llc_send_confirm_link ( link_new , SMC_LLC_REQ ) ;
if ( rc )
return - ENOLINK ;
/* receive CONFIRM LINK response over the RoCE fabric */
2020-07-18 21:06:09 +08:00
qentry = smc_llc_wait ( lgr , link , SMC_LLC_WAIT_FIRST_TIME , 0 ) ;
if ( ! qentry | |
2021-10-16 17:37:50 +08:00
qentry - > msg . raw . hdr . common . llc_type ! = SMC_LLC_CONFIRM_LINK ) {
2020-05-03 20:38:45 +08:00
/* send DELETE LINK */
smc_llc_send_delete_link ( link , link_new - > link_id , SMC_LLC_REQ ,
false , SMC_LLC_DEL_LOST_PATH ) ;
2020-07-18 21:06:09 +08:00
if ( qentry )
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
2020-05-03 20:38:45 +08:00
return - ENOLINK ;
}
2020-05-04 20:18:48 +08:00
smc_llc_save_peer_uid ( qentry ) ;
2020-05-03 20:38:45 +08:00
smc_llc_link_active ( link_new ) ;
2020-05-04 20:18:44 +08:00
if ( lgr_new_t = = SMC_LGR_ASYMMETRIC_LOCAL | |
lgr_new_t = = SMC_LGR_ASYMMETRIC_PEER )
smcr_lgr_set_type_asym ( lgr , lgr_new_t , link_new - > link_idx ) ;
else
smcr_lgr_set_type ( lgr , lgr_new_t ) ;
2020-05-03 20:38:45 +08:00
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
return 0 ;
}
2021-10-16 17:37:50 +08:00
static void smc_llc_send_req_add_link_response ( struct smc_llc_qentry * qentry )
{
qentry - > msg . raw . hdr . flags | = SMC_LLC_FLAG_RESP ;
smc_llc_init_msg_hdr ( & qentry - > msg . raw . hdr , qentry - > link - > lgr ,
sizeof ( qentry - > msg ) ) ;
memset ( & qentry - > msg . raw . data , 0 , sizeof ( qentry - > msg . raw . data ) ) ;
smc_llc_send_message ( qentry - > link , & qentry - > msg ) ;
}
int smc_llc_srv_add_link ( struct smc_link * link ,
struct smc_llc_qentry * req_qentry )
2020-05-03 20:38:43 +08:00
{
enum smc_lgr_type lgr_new_t = SMC_LGR_SYMMETRIC ;
struct smc_link_group * lgr = link - > lgr ;
struct smc_llc_msg_add_link * add_llc ;
struct smc_llc_qentry * qentry = NULL ;
2021-10-16 17:37:50 +08:00
bool send_req_add_link_resp = false ;
2021-10-16 17:37:43 +08:00
struct smc_link * link_new = NULL ;
2021-10-16 17:37:50 +08:00
struct smc_init_info * ini = NULL ;
2020-05-03 20:38:43 +08:00
int lnk_idx , rc = 0 ;
2021-10-16 17:37:50 +08:00
if ( req_qentry & &
req_qentry - > msg . raw . hdr . common . llc_type = = SMC_LLC_REQ_ADD_LINK )
send_req_add_link_resp = true ;
2021-10-16 17:37:43 +08:00
ini = kzalloc ( sizeof ( * ini ) , GFP_KERNEL ) ;
2021-10-16 17:37:50 +08:00
if ( ! ini ) {
rc = - ENOMEM ;
goto out ;
}
2021-10-16 17:37:43 +08:00
2023-08-17 21:20:31 +08:00
if ( lgr - > type = = SMC_LGR_SINGLE & & lgr - > max_links < = 1 ) {
rc = 0 ;
goto out ;
}
2020-05-03 20:38:43 +08:00
/* ignore client add link recommendation, start new flow */
2021-10-16 17:37:43 +08:00
ini - > vlan_id = lgr - > vlan_id ;
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 ) {
ini - > check_smcrv2 = true ;
ini - > smcrv2 . saddr = lgr - > saddr ;
if ( send_req_add_link_resp ) {
struct smc_llc_msg_req_add_link_v2 * req_add =
& req_qentry - > msg . req_add_link ;
ini - > smcrv2 . daddr = smc_ib_gid_to_ipv4 ( req_add - > gid [ 0 ] ) ;
}
}
2021-10-16 17:37:43 +08:00
smc_pnet_find_alt_roce ( lgr , ini , link - > smcibdev ) ;
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 & & ! ini - > smcrv2 . ib_dev_v2 ) {
lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL ;
ini - > smcrv2 . ib_dev_v2 = link - > smcibdev ;
ini - > smcrv2 . ib_port_v2 = link - > ibport ;
} else if ( lgr - > smc_version < SMC_V2 & & ! ini - > ib_dev ) {
2020-05-03 20:38:43 +08:00
lgr_new_t = SMC_LGR_ASYMMETRIC_LOCAL ;
2021-10-16 17:37:43 +08:00
ini - > ib_dev = link - > smcibdev ;
ini - > ib_port = link - > ibport ;
2020-05-03 20:38:43 +08:00
}
lnk_idx = smc_llc_alloc_alt_link ( lgr , lgr_new_t ) ;
2021-10-16 17:37:43 +08:00
if ( lnk_idx < 0 ) {
rc = 0 ;
goto out ;
}
2020-05-03 20:38:43 +08:00
2021-10-16 17:37:43 +08:00
rc = smcr_link_init ( lgr , & lgr - > lnk [ lnk_idx ] , lnk_idx , ini ) ;
2020-05-03 20:38:43 +08:00
if ( rc )
2021-10-16 17:37:43 +08:00
goto out ;
2020-05-03 20:38:43 +08:00
link_new = & lgr - > lnk [ lnk_idx ] ;
2021-10-16 17:37:50 +08:00
rc = smcr_buf_map_lgr ( link_new ) ;
if ( rc )
goto out_err ;
2020-05-03 20:38:43 +08:00
rc = smc_llc_send_add_link ( link ,
2021-10-16 17:37:50 +08:00
link_new - > smcibdev - > mac [ link_new - > ibport - 1 ] ,
2020-05-03 20:38:43 +08:00
link_new - > gid , link_new , SMC_LLC_REQ ) ;
if ( rc )
goto out_err ;
2021-10-16 17:37:50 +08:00
send_req_add_link_resp = false ;
2020-05-03 20:38:43 +08:00
/* receive ADD LINK response over the RoCE fabric */
qentry = smc_llc_wait ( lgr , link , SMC_LLC_WAIT_TIME , SMC_LLC_ADD_LINK ) ;
if ( ! qentry ) {
rc = - ETIMEDOUT ;
goto out_err ;
}
add_llc = & qentry - > msg . add_link ;
if ( add_llc - > hd . flags & SMC_LLC_FLAG_ADD_LNK_REJ ) {
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
rc = - ENOLINK ;
goto out_err ;
}
if ( lgr - > type = = SMC_LGR_SINGLE & &
( ! memcmp ( add_llc - > sender_gid , link - > peer_gid , SMC_GID_SIZE ) & &
2021-10-16 17:37:50 +08:00
( lgr - > smc_version = = SMC_V2 | |
! memcmp ( add_llc - > sender_mac , link - > peer_mac , ETH_ALEN ) ) ) ) {
2020-05-03 20:38:43 +08:00
lgr_new_t = SMC_LGR_ASYMMETRIC_PEER ;
}
smc_llc_save_add_link_info ( link_new , add_llc ) ;
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
rc = smc_ib_ready_link ( link_new ) ;
if ( rc )
goto out_err ;
rc = smcr_buf_reg_lgr ( link_new ) ;
if ( rc )
goto out_err ;
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 ) {
smc_llc_save_add_link_rkeys ( link , link_new ) ;
} else {
rc = smc_llc_srv_rkey_exchange ( link , link_new ) ;
if ( rc )
goto out_err ;
}
2020-05-03 20:38:45 +08:00
rc = smc_llc_srv_conf_link ( link , link_new , lgr_new_t ) ;
2020-05-03 20:38:43 +08:00
if ( rc )
goto out_err ;
2021-10-16 17:37:43 +08:00
kfree ( ini ) ;
2020-05-03 20:38:43 +08:00
return 0 ;
out_err :
2021-10-16 17:37:43 +08:00
if ( link_new ) {
link_new - > state = SMC_LNK_INACTIVE ;
smcr_link_clear ( link_new , false ) ;
}
out :
kfree ( ini ) ;
2021-10-16 17:37:50 +08:00
if ( send_req_add_link_resp )
smc_llc_send_req_add_link_response ( req_qentry ) ;
2020-05-03 20:38:43 +08:00
return rc ;
}
static void smc_llc_process_srv_add_link ( struct smc_link_group * lgr )
{
struct smc_link * link = lgr - > llc_flow_lcl . qentry - > link ;
2021-10-16 17:37:50 +08:00
struct smc_llc_qentry * qentry ;
2020-05-03 20:38:43 +08:00
int rc ;
2021-10-16 17:37:50 +08:00
qentry = smc_llc_flow_qentry_clr ( & lgr - > llc_flow_lcl ) ;
2020-05-03 20:38:43 +08:00
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
down_write ( & lgr - > llc_conf_mutex ) ;
2021-10-16 17:37:50 +08:00
rc = smc_llc_srv_add_link ( link , qentry ) ;
2020-05-03 20:38:43 +08:00
if ( ! rc & & lgr - > type = = SMC_LGR_SYMMETRIC ) {
/* delete any asymmetric link */
2020-05-03 20:38:46 +08:00
smc_llc_delete_asym_link ( lgr ) ;
2020-05-03 20:38:43 +08:00
}
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
up_write ( & lgr - > llc_conf_mutex ) ;
2021-10-16 17:37:50 +08:00
kfree ( qentry ) ;
2020-05-03 20:38:43 +08:00
}
2020-07-18 21:06:14 +08:00
/* enqueue a local add_link req to trigger a new add_link flow */
void smc_llc_add_link_local ( struct smc_link * link )
2020-05-03 20:38:50 +08:00
{
2020-10-08 20:19:29 +08:00
struct smc_llc_msg_add_link add_llc = { } ;
2020-05-03 20:38:50 +08:00
2021-10-16 17:37:50 +08:00
add_llc . hd . common . llc_type = SMC_LLC_ADD_LINK ;
smc_llc_init_msg_hdr ( & add_llc . hd , link - > lgr , sizeof ( add_llc ) ) ;
2020-07-18 21:06:14 +08:00
/* no dev and port needed */
2020-05-03 20:38:50 +08:00
smc_llc_enqueue ( link , ( union smc_llc_msg * ) & add_llc ) ;
}
2020-05-01 18:48:13 +08:00
/* worker to process an add link message */
static void smc_llc_add_link_work ( struct work_struct * work )
{
struct smc_link_group * lgr = container_of ( work , struct smc_link_group ,
llc_add_link_work ) ;
if ( list_empty ( & lgr - > list ) ) {
/* link group is terminating */
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
goto out ;
}
2020-05-03 20:38:42 +08:00
if ( lgr - > role = = SMC_CLNT )
smc_llc_process_cli_add_link ( lgr ) ;
2020-05-03 20:38:43 +08:00
else
smc_llc_process_srv_add_link ( lgr ) ;
2020-05-01 18:48:13 +08:00
out :
2021-10-16 17:37:50 +08:00
if ( lgr - > llc_flow_lcl . type ! = SMC_LLC_FLOW_REQ_ADD_LINK )
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_lcl ) ;
2020-05-01 18:48:13 +08:00
}
2020-05-03 20:38:50 +08:00
/* enqueue a local del_link msg to trigger a new del_link flow,
* called only for role SMC_SERV
*/
void smc_llc_srv_delete_link_local ( struct smc_link * link , u8 del_link_id )
{
2020-10-08 20:19:29 +08:00
struct smc_llc_msg_del_link del_llc = { } ;
2020-05-03 20:38:50 +08:00
2021-10-16 17:37:50 +08:00
del_llc . hd . common . llc_type = SMC_LLC_DELETE_LINK ;
smc_llc_init_msg_hdr ( & del_llc . hd , link - > lgr , sizeof ( del_llc ) ) ;
2020-05-03 20:38:50 +08:00
del_llc . link_num = del_link_id ;
del_llc . reason = htonl ( SMC_LLC_DEL_LOST_PATH ) ;
del_llc . hd . flags | = SMC_LLC_FLAG_DEL_LINK_ORDERLY ;
smc_llc_enqueue ( link , ( union smc_llc_msg * ) & del_llc ) ;
}
2020-05-03 20:38:48 +08:00
static void smc_llc_process_cli_delete_link ( struct smc_link_group * lgr )
{
struct smc_link * lnk_del = NULL , * lnk_asym , * lnk ;
struct smc_llc_msg_del_link * del_llc ;
struct smc_llc_qentry * qentry ;
int active_links ;
int lnk_idx ;
qentry = smc_llc_flow_qentry_clr ( & lgr - > llc_flow_lcl ) ;
lnk = qentry - > link ;
del_llc = & qentry - > msg . delete_link ;
if ( del_llc - > hd . flags & SMC_LLC_FLAG_DEL_LINK_ALL ) {
smc_lgr_terminate_sched ( lgr ) ;
goto out ;
}
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
down_write ( & lgr - > llc_conf_mutex ) ;
2020-05-03 20:38:48 +08:00
/* delete single link */
for ( lnk_idx = 0 ; lnk_idx < SMC_LINKS_PER_LGR_MAX ; lnk_idx + + ) {
if ( lgr - > lnk [ lnk_idx ] . link_id ! = del_llc - > link_num )
continue ;
lnk_del = & lgr - > lnk [ lnk_idx ] ;
break ;
}
del_llc - > hd . flags | = SMC_LLC_FLAG_RESP ;
if ( ! lnk_del ) {
/* link was not found */
del_llc - > reason = htonl ( SMC_LLC_DEL_NOLNK ) ;
smc_llc_send_message ( lnk , & qentry - > msg ) ;
goto out_unlock ;
}
lnk_asym = smc_llc_find_asym_link ( lgr ) ;
del_llc - > reason = 0 ;
smc_llc_send_message ( lnk , & qentry - > msg ) ; /* response */
2021-08-09 17:05:56 +08:00
if ( smc_link_downing ( & lnk_del - > state ) )
smc_switch_conns ( lgr , lnk_del , false ) ;
2020-05-05 21:01:20 +08:00
smcr_link_clear ( lnk_del , true ) ;
2020-05-03 20:38:48 +08:00
active_links = smc_llc_active_link_count ( lgr ) ;
if ( lnk_del = = lnk_asym ) {
/* expected deletion of asym link, don't change lgr state */
} else if ( active_links = = 1 ) {
2020-05-04 20:18:44 +08:00
smcr_lgr_set_type ( lgr , SMC_LGR_SINGLE ) ;
2020-05-03 20:38:48 +08:00
} else if ( ! active_links ) {
2020-05-04 20:18:44 +08:00
smcr_lgr_set_type ( lgr , SMC_LGR_NONE ) ;
2020-05-03 20:38:48 +08:00
smc_lgr_terminate_sched ( lgr ) ;
}
out_unlock :
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
up_write ( & lgr - > llc_conf_mutex ) ;
2020-05-03 20:38:48 +08:00
out :
kfree ( qentry ) ;
}
2020-05-04 20:18:42 +08:00
/* try to send a DELETE LINK ALL request on any active link,
* waiting for send completion
*/
void smc_llc_send_link_delete_all ( struct smc_link_group * lgr , bool ord , u32 rsn )
{
2020-10-08 20:19:28 +08:00
struct smc_llc_msg_del_link delllc = { } ;
2020-05-04 20:18:42 +08:00
int i ;
2021-10-16 17:37:50 +08:00
delllc . hd . common . llc_type = SMC_LLC_DELETE_LINK ;
smc_llc_init_msg_hdr ( & delllc . hd , lgr , sizeof ( delllc ) ) ;
2020-05-04 20:18:42 +08:00
if ( ord )
delllc . hd . flags | = SMC_LLC_FLAG_DEL_LINK_ORDERLY ;
delllc . hd . flags | = SMC_LLC_FLAG_DEL_LINK_ALL ;
delllc . reason = htonl ( rsn ) ;
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + ) {
2021-12-28 17:03:24 +08:00
if ( ! smc_link_sendable ( & lgr - > lnk [ i ] ) )
2020-05-04 20:18:42 +08:00
continue ;
if ( ! smc_llc_send_message_wait ( & lgr - > lnk [ i ] , & delllc ) )
break ;
}
}
2020-05-03 20:38:49 +08:00
static void smc_llc_process_srv_delete_link ( struct smc_link_group * lgr )
{
struct smc_llc_msg_del_link * del_llc ;
struct smc_link * lnk , * lnk_del ;
struct smc_llc_qentry * qentry ;
int active_links ;
int i ;
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
down_write ( & lgr - > llc_conf_mutex ) ;
2020-05-03 20:38:49 +08:00
qentry = smc_llc_flow_qentry_clr ( & lgr - > llc_flow_lcl ) ;
lnk = qentry - > link ;
del_llc = & qentry - > msg . delete_link ;
if ( qentry - > msg . delete_link . hd . flags & SMC_LLC_FLAG_DEL_LINK_ALL ) {
/* delete entire lgr */
2020-05-04 20:18:42 +08:00
smc_llc_send_link_delete_all ( lgr , true , ntohl (
qentry - > msg . delete_link . reason ) ) ;
2020-05-03 20:38:49 +08:00
smc_lgr_terminate_sched ( lgr ) ;
goto out ;
}
/* delete single link */
lnk_del = NULL ;
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + ) {
if ( lgr - > lnk [ i ] . link_id = = del_llc - > link_num ) {
lnk_del = & lgr - > lnk [ i ] ;
break ;
}
}
if ( ! lnk_del )
goto out ; /* asymmetric link already deleted */
if ( smc_link_downing ( & lnk_del - > state ) ) {
2020-07-08 23:05:12 +08:00
if ( smc_switch_conns ( lgr , lnk_del , false ) )
smc_wr_tx_wait_no_pending_sends ( lnk_del ) ;
2020-05-03 20:38:49 +08:00
}
if ( ! list_empty ( & lgr - > list ) ) {
/* qentry is either a request from peer (send it back to
* initiate the DELETE_LINK processing ) , or a locally
* enqueued DELETE_LINK request ( forward it )
*/
if ( ! smc_llc_send_message ( lnk , & qentry - > msg ) ) {
struct smc_llc_qentry * qentry2 ;
qentry2 = smc_llc_wait ( lgr , lnk , SMC_LLC_WAIT_TIME ,
SMC_LLC_DELETE_LINK ) ;
2020-05-07 22:24:06 +08:00
if ( qentry2 )
2020-05-03 20:38:49 +08:00
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
}
}
2020-05-05 21:01:20 +08:00
smcr_link_clear ( lnk_del , true ) ;
2020-05-03 20:38:49 +08:00
active_links = smc_llc_active_link_count ( lgr ) ;
if ( active_links = = 1 ) {
2020-05-04 20:18:44 +08:00
smcr_lgr_set_type ( lgr , SMC_LGR_SINGLE ) ;
2020-05-03 20:38:49 +08:00
} else if ( ! active_links ) {
2020-05-04 20:18:44 +08:00
smcr_lgr_set_type ( lgr , SMC_LGR_NONE ) ;
2020-05-03 20:38:49 +08:00
smc_lgr_terminate_sched ( lgr ) ;
}
if ( lgr - > type = = SMC_LGR_SINGLE & & ! list_empty ( & lgr - > list ) ) {
/* trigger setup of asymm alt link */
2020-07-18 21:06:14 +08:00
smc_llc_add_link_local ( lnk ) ;
2020-05-03 20:38:49 +08:00
}
out :
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
up_write ( & lgr - > llc_conf_mutex ) ;
2020-05-03 20:38:49 +08:00
kfree ( qentry ) ;
}
2020-05-03 20:38:47 +08:00
static void smc_llc_delete_link_work ( struct work_struct * work )
2018-03-01 20:51:32 +08:00
{
2020-05-03 20:38:47 +08:00
struct smc_link_group * lgr = container_of ( work , struct smc_link_group ,
llc_del_link_work ) ;
2018-03-01 20:51:32 +08:00
2020-05-03 20:38:47 +08:00
if ( list_empty ( & lgr - > list ) ) {
/* link group is terminating */
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
goto out ;
2018-03-01 20:51:32 +08:00
}
2020-05-03 20:38:48 +08:00
if ( lgr - > role = = SMC_CLNT )
smc_llc_process_cli_delete_link ( lgr ) ;
2020-05-03 20:38:49 +08:00
else
smc_llc_process_srv_delete_link ( lgr ) ;
2020-05-03 20:38:47 +08:00
out :
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_lcl ) ;
2018-03-01 20:51:32 +08:00
}
2020-04-30 21:55:48 +08:00
/* process a confirm_rkey request from peer, remote flow */
static void smc_llc_rmt_conf_rkey ( struct smc_link_group * lgr )
2018-03-01 20:51:30 +08:00
{
2020-04-30 21:55:48 +08:00
struct smc_llc_msg_confirm_rkey * llc ;
struct smc_llc_qentry * qentry ;
struct smc_link * link ;
int num_entries ;
int rk_idx ;
int i ;
qentry = lgr - > llc_flow_rmt . qentry ;
llc = & qentry - > msg . confirm_rkey ;
link = qentry - > link ;
num_entries = llc - > rtoken [ 0 ] . num_rkeys ;
2021-10-16 17:37:50 +08:00
if ( num_entries > SMC_LLC_RKEYS_PER_MSG )
goto out_err ;
2020-04-30 21:55:48 +08:00
/* first rkey entry is for receiving link */
rk_idx = smc_rtoken_add ( link ,
llc - > rtoken [ 0 ] . rmb_vaddr ,
llc - > rtoken [ 0 ] . rmb_key ) ;
if ( rk_idx < 0 )
goto out_err ;
for ( i = 1 ; i < = min_t ( u8 , num_entries , SMC_LLC_RKEYS_PER_MSG - 1 ) ; i + + )
smc_rtoken_set2 ( lgr , rk_idx , llc - > rtoken [ i ] . link_id ,
llc - > rtoken [ i ] . rmb_vaddr ,
llc - > rtoken [ i ] . rmb_key ) ;
/* max links is 3 so there is no need to support conf_rkey_cont msgs */
goto out ;
out_err :
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_NEG ;
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_RETRY ;
out :
2020-04-29 23:10:47 +08:00
llc - > hd . flags | = SMC_LLC_FLAG_RESP ;
2021-10-16 17:37:50 +08:00
smc_llc_init_msg_hdr ( & llc - > hd , link - > lgr , sizeof ( * llc ) ) ;
2020-04-30 21:55:48 +08:00
smc_llc_send_message ( link , & qentry - > msg ) ;
smc_llc_flow_qentry_del ( & lgr - > llc_flow_rmt ) ;
2018-03-01 20:51:30 +08:00
}
2020-04-30 21:55:49 +08:00
/* process a delete_rkey request from peer, remote flow */
static void smc_llc_rmt_delete_rkey ( struct smc_link_group * lgr )
2018-03-01 20:51:30 +08:00
{
2020-04-30 21:55:49 +08:00
struct smc_llc_msg_delete_rkey * llc ;
struct smc_llc_qentry * qentry ;
struct smc_link * link ;
2018-03-01 20:51:30 +08:00
u8 err_mask = 0 ;
int i , max ;
2020-04-30 21:55:49 +08:00
qentry = lgr - > llc_flow_rmt . qentry ;
llc = & qentry - > msg . delete_rkey ;
link = qentry - > link ;
2021-10-16 17:37:50 +08:00
if ( lgr - > smc_version = = SMC_V2 ) {
struct smc_llc_msg_delete_rkey_v2 * llcv2 ;
memcpy ( lgr - > wr_rx_buf_v2 , llc , sizeof ( * llc ) ) ;
llcv2 = ( struct smc_llc_msg_delete_rkey_v2 * ) lgr - > wr_rx_buf_v2 ;
llcv2 - > num_inval_rkeys = 0 ;
max = min_t ( u8 , llcv2 - > num_rkeys , SMC_LLC_RKEYS_PER_MSG_V2 ) ;
for ( i = 0 ; i < max ; i + + ) {
if ( smc_rtoken_delete ( link , llcv2 - > rkey [ i ] ) )
llcv2 - > num_inval_rkeys + + ;
}
memset ( & llc - > rkey [ 0 ] , 0 , sizeof ( llc - > rkey ) ) ;
memset ( & llc - > reserved2 , 0 , sizeof ( llc - > reserved2 ) ) ;
smc_llc_init_msg_hdr ( & llc - > hd , link - > lgr , sizeof ( * llc ) ) ;
if ( llcv2 - > num_inval_rkeys ) {
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_NEG ;
llc - > err_mask = llcv2 - > num_inval_rkeys ;
}
goto finish ;
}
2020-04-29 23:10:47 +08:00
max = min_t ( u8 , llc - > num_rkeys , SMC_LLC_DEL_RKEY_MAX ) ;
for ( i = 0 ; i < max ; i + + ) {
if ( smc_rtoken_delete ( link , llc - > rkey [ i ] ) )
err_mask | = 1 < < ( SMC_LLC_DEL_RKEY_MAX - 1 - i ) ;
}
if ( err_mask ) {
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_NEG ;
llc - > err_mask = err_mask ;
2018-03-01 20:51:30 +08:00
}
2021-10-16 17:37:50 +08:00
finish :
2020-04-30 21:55:49 +08:00
llc - > hd . flags | = SMC_LLC_FLAG_RESP ;
smc_llc_send_message ( link , & qentry - > msg ) ;
smc_llc_flow_qentry_del ( & lgr - > llc_flow_rmt ) ;
}
2020-04-29 23:10:47 +08:00
2020-05-04 20:18:45 +08:00
static void smc_llc_protocol_violation ( struct smc_link_group * lgr , u8 type )
{
2021-12-28 21:06:11 +08:00
pr_warn_ratelimited ( " smc: SMC-R lg %*phN net %llu LLC protocol violation: "
" llc_type %d \n " , SMC_LGR_ID_SIZE , & lgr - > id ,
lgr - > net - > net_cookie , type ) ;
2020-05-04 20:18:45 +08:00
smc_llc_set_termination_rsn ( lgr , SMC_LLC_DEL_PROT_VIOL ) ;
smc_lgr_terminate_sched ( lgr ) ;
}
2020-04-29 23:10:46 +08:00
/* flush the llc event queue */
2020-04-29 23:10:49 +08:00
static void smc_llc_event_flush ( struct smc_link_group * lgr )
2017-01-09 23:55:21 +08:00
{
2020-04-29 23:10:46 +08:00
struct smc_llc_qentry * qentry , * q ;
spin_lock_bh ( & lgr - > llc_event_q_lock ) ;
list_for_each_entry_safe ( qentry , q , & lgr - > llc_event_q , list ) {
list_del_init ( & qentry - > list ) ;
kfree ( qentry ) ;
}
spin_unlock_bh ( & lgr - > llc_event_q_lock ) ;
}
static void smc_llc_event_handler ( struct smc_llc_qentry * qentry )
{
union smc_llc_msg * llc = & qentry - > msg ;
struct smc_link * link = qentry - > link ;
2020-04-30 21:55:43 +08:00
struct smc_link_group * lgr = link - > lgr ;
2017-01-09 23:55:21 +08:00
2020-04-29 23:10:43 +08:00
if ( ! smc_link_usable ( link ) )
2020-04-29 23:10:46 +08:00
goto out ;
2018-03-01 20:51:29 +08:00
2021-10-16 17:37:50 +08:00
switch ( llc - > raw . hdr . common . llc_type ) {
2018-03-01 20:51:29 +08:00
case SMC_LLC_TEST_LINK :
2020-04-30 21:55:46 +08:00
llc - > test_link . hd . flags | = SMC_LLC_FLAG_RESP ;
smc_llc_send_message ( link , llc ) ;
2018-03-01 20:51:29 +08:00
break ;
2018-03-01 20:51:32 +08:00
case SMC_LLC_ADD_LINK :
2020-04-30 21:55:43 +08:00
if ( list_empty ( & lgr - > list ) )
goto out ; /* lgr is terminating */
if ( lgr - > role = = SMC_CLNT ) {
2020-07-18 21:06:14 +08:00
if ( smc_llc_is_local_add_link ( llc ) ) {
if ( lgr - > llc_flow_lcl . type = =
SMC_LLC_FLOW_ADD_LINK )
break ; /* add_link in progress */
if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl ,
qentry ) ) {
schedule_work ( & lgr - > llc_add_link_work ) ;
}
return ;
}
if ( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_ADD_LINK & &
! lgr - > llc_flow_lcl . qentry ) {
2020-04-30 21:55:43 +08:00
/* a flow is waiting for this message */
smc_llc_flow_qentry_set ( & lgr - > llc_flow_lcl ,
qentry ) ;
2020-07-08 23:05:11 +08:00
wake_up ( & lgr - > llc_msg_waiter ) ;
2021-10-16 17:37:50 +08:00
return ;
}
if ( lgr - > llc_flow_lcl . type = =
SMC_LLC_FLOW_REQ_ADD_LINK ) {
/* server started add_link processing */
lgr - > llc_flow_lcl . type = SMC_LLC_FLOW_ADD_LINK ;
smc_llc_flow_qentry_set ( & lgr - > llc_flow_lcl ,
qentry ) ;
schedule_work ( & lgr - > llc_add_link_work ) ;
return ;
}
if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl , qentry ) ) {
2020-05-01 18:48:13 +08:00
schedule_work ( & lgr - > llc_add_link_work ) ;
2020-04-30 21:55:43 +08:00
}
} else if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl , qentry ) ) {
/* as smc server, handle client suggestion */
2020-05-01 18:48:13 +08:00
schedule_work ( & lgr - > llc_add_link_work ) ;
2020-04-30 21:55:43 +08:00
}
return ;
case SMC_LLC_CONFIRM_LINK :
2020-05-03 20:38:41 +08:00
case SMC_LLC_ADD_LINK_CONT :
2020-04-30 21:55:43 +08:00
if ( lgr - > llc_flow_lcl . type ! = SMC_LLC_FLOW_NONE ) {
/* a flow is waiting for this message */
smc_llc_flow_qentry_set ( & lgr - > llc_flow_lcl , qentry ) ;
2020-07-08 23:05:11 +08:00
wake_up ( & lgr - > llc_msg_waiter ) ;
2020-04-30 21:55:43 +08:00
return ;
}
2018-03-01 20:51:32 +08:00
break ;
case SMC_LLC_DELETE_LINK :
2020-07-18 21:06:15 +08:00
if ( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_ADD_LINK & &
! lgr - > llc_flow_lcl . qentry ) {
/* DEL LINK REQ during ADD LINK SEQ */
smc_llc_flow_qentry_set ( & lgr - > llc_flow_lcl , qentry ) ;
wake_up ( & lgr - > llc_msg_waiter ) ;
} else if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl , qentry ) ) {
schedule_work ( & lgr - > llc_del_link_work ) ;
2020-05-03 20:38:47 +08:00
}
return ;
2018-03-01 20:51:30 +08:00
case SMC_LLC_CONFIRM_RKEY :
2020-04-30 21:55:48 +08:00
/* new request from remote, assign to remote flow */
if ( smc_llc_flow_start ( & lgr - > llc_flow_rmt , qentry ) ) {
/* process here, does not wait for more llc msgs */
smc_llc_rmt_conf_rkey ( lgr ) ;
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_rmt ) ;
}
return ;
2018-03-01 20:51:30 +08:00
case SMC_LLC_CONFIRM_RKEY_CONT :
2020-04-30 21:55:50 +08:00
/* not used because max links is 3, and 3 rkeys fit into
* one CONFIRM_RKEY message
*/
2018-03-01 20:51:30 +08:00
break ;
case SMC_LLC_DELETE_RKEY :
2020-04-30 21:55:49 +08:00
/* new request from remote, assign to remote flow */
if ( smc_llc_flow_start ( & lgr - > llc_flow_rmt , qentry ) ) {
/* process here, does not wait for more llc msgs */
smc_llc_rmt_delete_rkey ( lgr ) ;
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_rmt ) ;
}
return ;
2021-10-16 17:37:50 +08:00
case SMC_LLC_REQ_ADD_LINK :
/* handle response here, smc_llc_flow_stop() cannot be called
* in tasklet context
*/
if ( lgr - > role = = SMC_CLNT & &
lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_REQ_ADD_LINK & &
( llc - > raw . hdr . flags & SMC_LLC_FLAG_RESP ) ) {
smc_llc_flow_stop ( link - > lgr , & lgr - > llc_flow_lcl ) ;
} else if ( lgr - > role = = SMC_SERV ) {
if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl , qentry ) ) {
/* as smc server, handle client suggestion */
lgr - > llc_flow_lcl . type = SMC_LLC_FLOW_ADD_LINK ;
schedule_work ( & lgr - > llc_add_link_work ) ;
}
return ;
}
break ;
2020-05-04 20:18:45 +08:00
default :
smc_llc_protocol_violation ( lgr , llc - > raw . hdr . common . type ) ;
break ;
2018-03-01 20:51:29 +08:00
}
2020-04-29 23:10:46 +08:00
out :
kfree ( qentry ) ;
}
/* worker to process llc messages on the event queue */
static void smc_llc_event_work ( struct work_struct * work )
{
struct smc_link_group * lgr = container_of ( work , struct smc_link_group ,
llc_event_work ) ;
struct smc_llc_qentry * qentry ;
2020-04-30 21:55:38 +08:00
if ( ! lgr - > llc_flow_lcl . type & & lgr - > delayed_event ) {
2020-10-15 01:43:27 +08:00
qentry = lgr - > delayed_event ;
lgr - > delayed_event = NULL ;
if ( smc_link_usable ( qentry - > link ) )
smc_llc_event_handler ( qentry ) ;
else
2020-04-30 21:55:38 +08:00
kfree ( qentry ) ;
}
2020-04-29 23:10:46 +08:00
again :
spin_lock_bh ( & lgr - > llc_event_q_lock ) ;
if ( ! list_empty ( & lgr - > llc_event_q ) ) {
qentry = list_first_entry ( & lgr - > llc_event_q ,
struct smc_llc_qentry , list ) ;
list_del_init ( & qentry - > list ) ;
spin_unlock_bh ( & lgr - > llc_event_q_lock ) ;
smc_llc_event_handler ( qentry ) ;
goto again ;
}
spin_unlock_bh ( & lgr - > llc_event_q_lock ) ;
}
2020-04-29 23:10:47 +08:00
/* process llc responses in tasklet context */
2020-04-30 21:55:39 +08:00
static void smc_llc_rx_response ( struct smc_link * link ,
struct smc_llc_qentry * qentry )
2020-04-29 23:10:47 +08:00
{
2020-07-18 21:06:13 +08:00
enum smc_llc_flowtype flowtype = link - > lgr - > llc_flow_lcl . type ;
struct smc_llc_flow * flow = & link - > lgr - > llc_flow_lcl ;
2021-10-16 17:37:50 +08:00
u8 llc_type = qentry - > msg . raw . hdr . common . llc_type ;
2020-04-29 23:10:47 +08:00
2020-04-30 21:55:39 +08:00
switch ( llc_type ) {
2020-04-29 23:10:47 +08:00
case SMC_LLC_TEST_LINK :
2020-07-18 21:06:16 +08:00
if ( smc_link_active ( link ) )
2020-04-29 23:10:47 +08:00
complete ( & link - > llc_testlink_resp ) ;
break ;
case SMC_LLC_ADD_LINK :
2020-05-03 20:38:41 +08:00
case SMC_LLC_ADD_LINK_CONT :
2020-07-18 21:06:13 +08:00
case SMC_LLC_CONFIRM_LINK :
if ( flowtype ! = SMC_LLC_FLOW_ADD_LINK | | flow - > qentry )
break ; /* drop out-of-flow response */
goto assign ;
case SMC_LLC_DELETE_LINK :
if ( flowtype ! = SMC_LLC_FLOW_DEL_LINK | | flow - > qentry )
break ; /* drop out-of-flow response */
goto assign ;
2020-04-30 21:55:44 +08:00
case SMC_LLC_CONFIRM_RKEY :
2020-04-30 21:55:45 +08:00
case SMC_LLC_DELETE_RKEY :
2020-07-18 21:06:13 +08:00
if ( flowtype ! = SMC_LLC_FLOW_RKEY | | flow - > qentry )
break ; /* drop out-of-flow response */
goto assign ;
2020-04-29 23:10:47 +08:00
case SMC_LLC_CONFIRM_RKEY_CONT :
2020-04-30 21:55:50 +08:00
/* not used because max links is 3 */
2020-04-29 23:10:47 +08:00
break ;
2020-05-04 20:18:45 +08:00
default :
2021-10-16 17:37:50 +08:00
smc_llc_protocol_violation ( link - > lgr ,
qentry - > msg . raw . hdr . common . type ) ;
2020-05-04 20:18:45 +08:00
break ;
2020-04-29 23:10:47 +08:00
}
2020-04-30 21:55:39 +08:00
kfree ( qentry ) ;
2020-07-18 21:06:13 +08:00
return ;
assign :
/* assign responses to the local flow, we requested them */
smc_llc_flow_qentry_set ( & link - > lgr - > llc_flow_lcl , qentry ) ;
wake_up ( & link - > lgr - > llc_msg_waiter ) ;
2020-04-29 23:10:47 +08:00
}
2020-04-30 21:55:39 +08:00
static void smc_llc_enqueue ( struct smc_link * link , union smc_llc_msg * llc )
2020-04-29 23:10:46 +08:00
{
struct smc_link_group * lgr = link - > lgr ;
struct smc_llc_qentry * qentry ;
unsigned long flags ;
qentry = kmalloc ( sizeof ( * qentry ) , GFP_ATOMIC ) ;
if ( ! qentry )
return ;
qentry - > link = link ;
INIT_LIST_HEAD ( & qentry - > list ) ;
memcpy ( & qentry - > msg , llc , sizeof ( union smc_llc_msg ) ) ;
2020-04-30 21:55:39 +08:00
/* process responses immediately */
2021-10-16 17:37:50 +08:00
if ( ( llc - > raw . hdr . flags & SMC_LLC_FLAG_RESP ) & &
llc - > raw . hdr . common . llc_type ! = SMC_LLC_REQ_ADD_LINK ) {
2020-04-30 21:55:39 +08:00
smc_llc_rx_response ( link , qentry ) ;
return ;
}
/* add requests to event queue */
2020-04-29 23:10:46 +08:00
spin_lock_irqsave ( & lgr - > llc_event_q_lock , flags ) ;
list_add_tail ( & qentry - > list , & lgr - > llc_event_q ) ;
spin_unlock_irqrestore ( & lgr - > llc_event_q_lock , flags ) ;
2020-09-11 00:48:29 +08:00
queue_work ( system_highpri_wq , & lgr - > llc_event_work ) ;
2017-01-09 23:55:21 +08:00
}
2020-04-30 21:55:39 +08:00
/* copy received msg and add it to the event queue */
static void smc_llc_rx_handler ( struct ib_wc * wc , void * buf )
{
struct smc_link * link = ( struct smc_link * ) wc - > qp - > qp_context ;
union smc_llc_msg * llc = buf ;
if ( wc - > byte_len < sizeof ( * llc ) )
return ; /* short message */
2021-10-16 17:37:50 +08:00
if ( ! llc - > raw . hdr . common . llc_version ) {
if ( llc - > raw . hdr . length ! = sizeof ( * llc ) )
return ; /* invalid message */
} else {
if ( llc - > raw . hdr . length_v2 < sizeof ( * llc ) )
return ; /* invalid message */
}
2020-04-30 21:55:39 +08:00
smc_llc_enqueue ( link , llc ) ;
}
2018-05-15 23:04:55 +08:00
/***************************** worker, utils *********************************/
2018-05-02 22:56:44 +08:00
static void smc_llc_testlink_work ( struct work_struct * work )
{
struct smc_link * link = container_of ( to_delayed_work ( work ) ,
struct smc_link , llc_testlink_wrk ) ;
unsigned long next_interval ;
unsigned long expire_time ;
u8 user_data [ 16 ] = { 0 } ;
int rc ;
2020-07-18 21:06:16 +08:00
if ( ! smc_link_active ( link ) )
2018-05-02 22:56:44 +08:00
return ; /* don't reschedule worker */
expire_time = link - > wr_rx_tstamp + link - > llc_testlink_time ;
if ( time_is_after_jiffies ( expire_time ) ) {
next_interval = expire_time - jiffies ;
goto out ;
}
reinit_completion ( & link - > llc_testlink_resp ) ;
2018-05-15 23:04:57 +08:00
smc_llc_send_test_link ( link , user_data ) ;
2018-05-02 22:56:44 +08:00
/* receive TEST LINK response over RoCE fabric */
rc = wait_for_completion_interruptible_timeout ( & link - > llc_testlink_resp ,
SMC_LLC_WAIT_TIME ) ;
2020-07-18 21:06:16 +08:00
if ( ! smc_link_active ( link ) )
2020-04-29 23:10:44 +08:00
return ; /* link state changed */
2018-05-02 22:56:44 +08:00
if ( rc < = 0 ) {
2020-05-01 18:48:09 +08:00
smcr_link_down_cond_sched ( link ) ;
2018-05-02 22:56:44 +08:00
return ;
}
next_interval = link - > llc_testlink_time ;
out :
2020-04-29 23:10:44 +08:00
schedule_delayed_work ( & link - > llc_testlink_wrk , next_interval ) ;
2018-05-02 22:56:44 +08:00
}
2020-04-29 23:10:49 +08:00
void smc_llc_lgr_init ( struct smc_link_group * lgr , struct smc_sock * smc )
{
struct net * net = sock_net ( smc - > clcsock - > sk ) ;
INIT_WORK ( & lgr - > llc_event_work , smc_llc_event_work ) ;
2020-05-01 18:48:13 +08:00
INIT_WORK ( & lgr - > llc_add_link_work , smc_llc_add_link_work ) ;
2020-05-03 20:38:47 +08:00
INIT_WORK ( & lgr - > llc_del_link_work , smc_llc_delete_link_work ) ;
2020-04-29 23:10:49 +08:00
INIT_LIST_HEAD ( & lgr - > llc_event_q ) ;
spin_lock_init ( & lgr - > llc_event_q_lock ) ;
2020-04-30 21:55:38 +08:00
spin_lock_init ( & lgr - > llc_flow_lock ) ;
2020-07-08 23:05:11 +08:00
init_waitqueue_head ( & lgr - > llc_flow_waiter ) ;
init_waitqueue_head ( & lgr - > llc_msg_waiter ) ;
net/smc: llc_conf_mutex refactor, replace it with rw_semaphore
llc_conf_mutex was used to protect links and link related configurations
in the same link group, for example, add or delete links. However,
in most cases, the protected critical area has only read semantics and
with no write semantics at all, such as obtaining a usable link or an
available rmb_desc.
This patch do simply code refactoring, replace mutex with rw_semaphore,
replace mutex_lock with down_write and replace mutex_unlock with
up_write.
Theoretically, this replacement is equivalent, but after this patch,
we can distinguish lock granularity according to different semantics
of critical areas.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-02 16:26:39 +08:00
init_rwsem ( & lgr - > llc_conf_mutex ) ;
2022-09-20 17:52:21 +08:00
lgr - > llc_testlink_time = READ_ONCE ( net - > smc . sysctl_smcr_testlink_time ) ;
2020-04-29 23:10:49 +08:00
}
/* called after lgr was removed from lgr_list */
void smc_llc_lgr_clear ( struct smc_link_group * lgr )
{
smc_llc_event_flush ( lgr ) ;
2020-07-08 23:05:11 +08:00
wake_up_all ( & lgr - > llc_flow_waiter ) ;
wake_up_all ( & lgr - > llc_msg_waiter ) ;
2020-04-29 23:10:49 +08:00
cancel_work_sync ( & lgr - > llc_event_work ) ;
2020-05-01 18:48:13 +08:00
cancel_work_sync ( & lgr - > llc_add_link_work ) ;
2020-05-03 20:38:47 +08:00
cancel_work_sync ( & lgr - > llc_del_link_work ) ;
2020-04-30 21:55:38 +08:00
if ( lgr - > delayed_event ) {
kfree ( lgr - > delayed_event ) ;
lgr - > delayed_event = NULL ;
}
2020-04-29 23:10:49 +08:00
}
2018-05-15 23:04:59 +08:00
int smc_llc_link_init ( struct smc_link * link )
2018-05-02 22:56:44 +08:00
{
init_completion ( & link - > llc_testlink_resp ) ;
INIT_DELAYED_WORK ( & link - > llc_testlink_wrk , smc_llc_testlink_work ) ;
2018-05-15 23:04:59 +08:00
return 0 ;
2018-05-15 23:04:58 +08:00
}
2020-04-29 23:10:49 +08:00
void smc_llc_link_active ( struct smc_link * link )
2018-05-15 23:04:58 +08:00
{
2021-12-28 21:06:11 +08:00
pr_warn_ratelimited ( " smc: SMC-R lg %*phN net %llu link added: id %*phN, "
2020-05-05 21:01:20 +08:00
" peerid %*phN, ibdev %s, ibport %d \n " ,
SMC_LGR_ID_SIZE , & link - > lgr - > id ,
2021-12-28 21:06:11 +08:00
link - > lgr - > net - > net_cookie ,
2020-05-05 21:01:20 +08:00
SMC_LGR_ID_SIZE , & link - > link_uid ,
SMC_LGR_ID_SIZE , & link - > peer_link_uid ,
link - > smcibdev - > ibdev - > name , link - > ibport ) ;
2018-05-02 22:56:44 +08:00
link - > state = SMC_LNK_ACTIVE ;
2020-04-29 23:10:49 +08:00
if ( link - > lgr - > llc_testlink_time ) {
2021-10-28 15:13:45 +08:00
link - > llc_testlink_time = link - > lgr - > llc_testlink_time ;
2020-04-29 23:10:44 +08:00
schedule_delayed_work ( & link - > llc_testlink_wrk ,
link - > llc_testlink_time ) ;
2018-05-02 22:56:44 +08:00
}
}
/* called in worker context */
2020-05-05 21:01:20 +08:00
void smc_llc_link_clear ( struct smc_link * link , bool log )
2018-05-02 22:56:44 +08:00
{
2020-05-05 21:01:20 +08:00
if ( log )
2021-12-28 21:06:11 +08:00
pr_warn_ratelimited ( " smc: SMC-R lg %*phN net %llu link removed: id %*phN "
2020-05-05 21:01:20 +08:00
" , peerid %*phN, ibdev %s, ibport %d \n " ,
SMC_LGR_ID_SIZE , & link - > lgr - > id ,
2021-12-28 21:06:11 +08:00
link - > lgr - > net - > net_cookie ,
2020-05-05 21:01:20 +08:00
SMC_LGR_ID_SIZE , & link - > link_uid ,
SMC_LGR_ID_SIZE , & link - > peer_link_uid ,
link - > smcibdev - > ibdev - > name , link - > ibport ) ;
2020-04-29 23:10:45 +08:00
complete ( & link - > llc_testlink_resp ) ;
cancel_delayed_work_sync ( & link - > llc_testlink_wrk ) ;
2018-05-02 22:56:44 +08:00
}
2020-04-30 21:55:44 +08:00
/* register a new rtoken at the remote peer (for all links) */
int smc_llc_do_confirm_rkey ( struct smc_link * send_link ,
2018-05-15 23:04:55 +08:00
struct smc_buf_desc * rmb_desc )
{
2020-04-30 21:55:44 +08:00
struct smc_link_group * lgr = send_link - > lgr ;
struct smc_llc_qentry * qentry = NULL ;
int rc = 0 ;
2018-05-15 23:04:55 +08:00
2020-04-30 21:55:44 +08:00
rc = smc_llc_send_confirm_rkey ( send_link , rmb_desc ) ;
if ( rc )
goto out ;
2018-05-15 23:04:55 +08:00
/* receive CONFIRM RKEY response from server over RoCE fabric */
2020-04-30 21:55:44 +08:00
qentry = smc_llc_wait ( lgr , send_link , SMC_LLC_WAIT_TIME ,
SMC_LLC_CONFIRM_RKEY ) ;
if ( ! qentry | | ( qentry - > msg . raw . hdr . flags & SMC_LLC_FLAG_RKEY_NEG ) )
rc = - EFAULT ;
out :
if ( qentry )
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
return rc ;
2018-05-15 23:04:55 +08:00
}
2018-11-22 17:26:42 +08:00
/* unregister an rtoken at the remote peer */
2020-04-30 21:55:45 +08:00
int smc_llc_do_delete_rkey ( struct smc_link_group * lgr ,
2018-11-22 17:26:42 +08:00
struct smc_buf_desc * rmb_desc )
{
2020-04-30 21:55:45 +08:00
struct smc_llc_qentry * qentry = NULL ;
struct smc_link * send_link ;
2019-11-14 20:02:47 +08:00
int rc = 0 ;
2018-11-22 17:26:42 +08:00
2020-04-30 21:55:45 +08:00
send_link = smc_llc_usable_link ( lgr ) ;
if ( ! send_link )
return - ENOLINK ;
/* protected by llc_flow control */
rc = smc_llc_send_delete_rkey ( send_link , rmb_desc ) ;
2018-11-22 17:26:42 +08:00
if ( rc )
goto out ;
/* receive DELETE RKEY response from server over RoCE fabric */
2020-04-30 21:55:45 +08:00
qentry = smc_llc_wait ( lgr , send_link , SMC_LLC_WAIT_TIME ,
SMC_LLC_DELETE_RKEY ) ;
if ( ! qentry | | ( qentry - > msg . raw . hdr . flags & SMC_LLC_FLAG_RKEY_NEG ) )
2018-11-22 17:26:42 +08:00
rc = - EFAULT ;
out :
2020-04-30 21:55:45 +08:00
if ( qentry )
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
2018-11-22 17:26:42 +08:00
return rc ;
}
2020-05-04 20:18:47 +08:00
void smc_llc_link_set_uid ( struct smc_link * link )
{
__be32 link_uid ;
link_uid = htonl ( * ( ( u32 * ) link - > lgr - > id ) + link - > link_id ) ;
memcpy ( link - > link_uid , & link_uid , SMC_LGR_ID_SIZE ) ;
}
2020-05-04 20:18:48 +08:00
/* save peers link user id, used for debug purposes */
void smc_llc_save_peer_uid ( struct smc_llc_qentry * qentry )
{
memcpy ( qentry - > link - > peer_link_uid , qentry - > msg . confirm_link . link_uid ,
SMC_LGR_ID_SIZE ) ;
}
2020-04-30 21:55:41 +08:00
/* evaluate confirm link request or response */
int smc_llc_eval_conf_link ( struct smc_llc_qentry * qentry ,
enum smc_llc_reqresp type )
{
2020-05-04 20:18:47 +08:00
if ( type = = SMC_LLC_REQ ) { /* SMC server assigns link_id */
2020-04-30 21:55:41 +08:00
qentry - > link - > link_id = qentry - > msg . confirm_link . link_num ;
2020-05-04 20:18:47 +08:00
smc_llc_link_set_uid ( qentry - > link ) ;
}
2020-04-30 21:55:41 +08:00
if ( ! ( qentry - > msg . raw . hdr . flags & SMC_LLC_FLAG_NO_RMBE_EYEC ) )
return - ENOTSUPP ;
return 0 ;
}
2017-01-09 23:55:21 +08:00
/***************************** init, exit, misc ******************************/
static struct smc_wr_rx_handler smc_llc_rx_handlers [ ] = {
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_LINK
} ,
2018-03-01 20:51:29 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_TEST_LINK
} ,
2018-03-01 20:51:32 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_ADD_LINK
} ,
2020-05-03 20:38:41 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_ADD_LINK_CONT
} ,
2018-03-01 20:51:32 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_DELETE_LINK
} ,
2018-03-01 20:51:30 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_RKEY
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_RKEY_CONT
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_DELETE_RKEY
} ,
2021-10-16 17:37:50 +08:00
/* V2 types */
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_LINK_V2
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_TEST_LINK_V2
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_ADD_LINK_V2
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_DELETE_LINK_V2
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_REQ_ADD_LINK_V2
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_RKEY_V2
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_DELETE_RKEY_V2
} ,
2017-01-09 23:55:21 +08:00
{
. handler = NULL ,
}
} ;
int __init smc_llc_init ( void )
{
struct smc_wr_rx_handler * handler ;
int rc = 0 ;
for ( handler = smc_llc_rx_handlers ; handler - > handler ; handler + + ) {
INIT_HLIST_NODE ( & handler - > list ) ;
rc = smc_wr_rx_register_handler ( handler ) ;
if ( rc )
break ;
}
return rc ;
}