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 17:07:57 +03:00
/* SPDX-License-Identifier: GPL-2.0 */
2017-01-09 18:55:13 +03:00
/*
* Shared Memory Communications over RDMA ( SMC - R ) and RoCE
*
* Definitions for the SMC module ( socket related )
*
* Copyright IBM Corp . 2016
*
* Author ( s ) : Ursula Braun < ubraun @ linux . vnet . ibm . com >
*/
# ifndef __SMC_H
# define __SMC_H
# include <linux/socket.h>
# include <linux/types.h>
2017-01-09 18:55:19 +03:00
# include <linux/compiler.h> /* __aligned */
2022-02-10 12:11:38 +03:00
# include <net/genetlink.h>
2017-01-09 18:55:13 +03:00
# include <net/sock.h>
2017-01-09 18:55:17 +03:00
# include "smc_ib.h"
2020-09-10 19:48:21 +03:00
# define SMC_V1 1 /* SMC version V1 */
2020-09-26 13:44:27 +03:00
# define SMC_V2 2 /* SMC version V2 */
2020-09-26 13:44:28 +03:00
# define SMC_RELEASE 0
2020-09-10 19:48:21 +03:00
2018-03-16 17:06:41 +03:00
# define SMCPROTO_SMC 0 /* SMC protocol, IPv4 */
# define SMCPROTO_SMC6 1 /* SMC protocol, IPv6 */
2017-01-09 18:55:13 +03:00
2020-09-26 13:44:23 +03:00
# define SMC_MAX_ISM_DEVS 8 / * max # of proposed non-native ISM
* devices
*/
2022-03-01 12:43:57 +03:00
# define SMC_AUTOCORKING_DEFAULT_SIZE 0x10000 /* 64K by default */
2020-09-26 13:44:23 +03:00
2017-01-09 18:55:26 +03:00
extern struct proto smc_proto ;
2018-03-16 17:06:41 +03:00
extern struct proto smc_proto6 ;
2017-01-09 18:55:26 +03:00
2017-01-09 18:55:22 +03:00
# ifdef ATOMIC64_INIT
# define KERNEL_HAS_ATOMIC64
# endif
2017-01-09 18:55:13 +03:00
enum smc_state { /* possible states of an SMC socket */
SMC_ACTIVE = 1 ,
SMC_INIT = 2 ,
SMC_CLOSED = 7 ,
SMC_LISTEN = 10 ,
2017-01-09 18:55:25 +03:00
/* normal close */
SMC_PEERCLOSEWAIT1 = 20 ,
SMC_PEERCLOSEWAIT2 = 21 ,
SMC_APPFINCLOSEWAIT = 24 ,
SMC_APPCLOSEWAIT1 = 22 ,
SMC_APPCLOSEWAIT2 = 23 ,
SMC_PEERFINCLOSEWAIT = 25 ,
/* abnormal close */
SMC_PEERABORTWAIT = 26 ,
SMC_PROCESSABORT = 27 ,
2017-01-09 18:55:13 +03:00
} ;
2017-01-09 18:55:17 +03:00
struct smc_link_group ;
2017-01-09 18:55:19 +03:00
struct smc_wr_rx_hdr { /* common prefix part of LLC and CDC to demultiplex */
2021-10-16 12:37:50 +03:00
union {
u8 type ;
# if defined(__BIG_ENDIAN_BITFIELD)
struct {
u8 llc_version : 4 ,
llc_type : 4 ;
} ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
struct {
u8 llc_type : 4 ,
llc_version : 4 ;
} ;
# endif
} ;
2017-01-09 18:55:19 +03:00
} __aligned ( 1 ) ;
2017-01-09 18:55:22 +03:00
struct smc_cdc_conn_state_flags {
# if defined(__BIG_ENDIAN_BITFIELD)
u8 peer_done_writing : 1 ; /* Sending done indicator */
u8 peer_conn_closed : 1 ; /* Peer connection closed indicator */
u8 peer_conn_abort : 1 ; /* Abnormal close indicator */
u8 reserved : 5 ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 reserved : 5 ;
u8 peer_conn_abort : 1 ;
u8 peer_conn_closed : 1 ;
u8 peer_done_writing : 1 ;
# endif
} ;
struct smc_cdc_producer_flags {
# if defined(__BIG_ENDIAN_BITFIELD)
u8 write_blocked : 1 ; /* Writing Blocked, no rx buf space */
u8 urg_data_pending : 1 ; /* Urgent Data Pending */
u8 urg_data_present : 1 ; /* Urgent Data Present */
u8 cons_curs_upd_req : 1 ; /* cursor update requested */
u8 failover_validation : 1 ; /* message replay due to failover */
u8 reserved : 3 ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 reserved : 3 ;
u8 failover_validation : 1 ;
u8 cons_curs_upd_req : 1 ;
u8 urg_data_present : 1 ;
u8 urg_data_pending : 1 ;
u8 write_blocked : 1 ;
# endif
} ;
/* in host byte order */
union smc_host_cursor { /* SMC cursor - an offset in an RMBE */
struct {
u16 reserved ;
u16 wrap ; /* window wrap sequence number */
u32 count ; /* cursor (= offset) part */
} ;
# ifdef KERNEL_HAS_ATOMIC64
atomic64_t acurs ; /* for atomic processing */
# else
u64 acurs ; /* for atomic processing */
# endif
} __aligned ( 8 ) ;
/* in host byte order, except for flag bitfields in network byte order */
struct smc_host_cdc_msg { /* Connection Data Control message */
struct smc_wr_rx_hdr common ; /* .type = 0xFE */
u8 len ; /* length = 44 */
u16 seqno ; /* connection seq # */
u32 token ; /* alert_token */
union smc_host_cursor prod ; /* producer cursor */
union smc_host_cursor cons ; /* consumer cursor,
* piggy backed " ack "
*/
struct smc_cdc_producer_flags prod_flags ; /* conn. tx/rx status */
struct smc_cdc_conn_state_flags conn_state_flags ; /* peer conn. status*/
u8 reserved [ 18 ] ;
} __aligned ( 8 ) ;
2018-05-23 17:38:11 +03:00
enum smc_urg_state {
2019-02-21 14:56:54 +03:00
SMC_URG_VALID = 1 , /* data present */
SMC_URG_NOTYET = 2 , /* data pending */
SMC_URG_READ = 3 , /* data was already read */
2018-05-23 17:38:11 +03:00
} ;
net/smc: Forward wakeup to smc socket waitqueue after fallback
When we replace TCP with SMC and a fallback occurs, there may be
some socket waitqueue entries remaining in smc socket->wq, such
as eppoll_entries inserted by userspace applications.
After the fallback, data flows over TCP/IP and only clcsocket->wq
will be woken up. Applications can't be notified by the entries
which were inserted in smc socket->wq before fallback. So we need
a mechanism to wake up smc socket->wq at the same time if some
entries remaining in it.
The current workaround is to transfer the entries from smc socket->wq
to clcsock->wq during the fallback. But this may cause a crash
like this:
general protection fault, probably for non-canonical address 0xdead000000000100: 0000 [#1] PREEMPT SMP PTI
CPU: 3 PID: 0 Comm: swapper/3 Kdump: loaded Tainted: G E 5.16.0+ #107
RIP: 0010:__wake_up_common+0x65/0x170
Call Trace:
<IRQ>
__wake_up_common_lock+0x7a/0xc0
sock_def_readable+0x3c/0x70
tcp_data_queue+0x4a7/0xc40
tcp_rcv_established+0x32f/0x660
? sk_filter_trim_cap+0xcb/0x2e0
tcp_v4_do_rcv+0x10b/0x260
tcp_v4_rcv+0xd2a/0xde0
ip_protocol_deliver_rcu+0x3b/0x1d0
ip_local_deliver_finish+0x54/0x60
ip_local_deliver+0x6a/0x110
? tcp_v4_early_demux+0xa2/0x140
? tcp_v4_early_demux+0x10d/0x140
ip_sublist_rcv_finish+0x49/0x60
ip_sublist_rcv+0x19d/0x230
ip_list_rcv+0x13e/0x170
__netif_receive_skb_list_core+0x1c2/0x240
netif_receive_skb_list_internal+0x1e6/0x320
napi_complete_done+0x11d/0x190
mlx5e_napi_poll+0x163/0x6b0 [mlx5_core]
__napi_poll+0x3c/0x1b0
net_rx_action+0x27c/0x300
__do_softirq+0x114/0x2d2
irq_exit_rcu+0xb4/0xe0
common_interrupt+0xba/0xe0
</IRQ>
<TASK>
The crash is caused by privately transferring waitqueue entries from
smc socket->wq to clcsock->wq. The owners of these entries, such as
epoll, have no idea that the entries have been transferred to a
different socket wait queue and still use original waitqueue spinlock
(smc socket->wq.wait.lock) to make the entries operation exclusive,
but it doesn't work. The operations to the entries, such as removing
from the waitqueue (now is clcsock->wq after fallback), may cause a
crash when clcsock waitqueue is being iterated over at the moment.
This patch tries to fix this by no longer transferring wait queue
entries privately, but introducing own implementations of clcsock's
callback functions in fallback situation. The callback functions will
forward the wakeup to smc socket->wq if clcsock->wq is actually woken
up and smc socket->wq has remaining entries.
Fixes: 2153bd1e3d3d ("net/smc: Transfer remaining wait queue entries during fallback")
Suggested-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Acked-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-01-26 18:33:04 +03:00
struct smc_mark_woken {
bool woken ;
void * key ;
wait_queue_entry_t wait_entry ;
} ;
2017-01-09 18:55:17 +03:00
struct smc_connection {
struct rb_node alert_node ;
struct smc_link_group * lgr ; /* link group of connection */
2020-04-29 18:10:40 +03:00
struct smc_link * lnk ; /* assigned SMC-R link */
2017-01-09 18:55:17 +03:00
u32 alert_token_local ; /* unique conn. id */
2018-05-18 10:34:12 +03:00
u8 peer_rmbe_idx ; /* from tcp handshake */
2017-01-09 18:55:18 +03:00
int peer_rmbe_size ; /* size of peer rx buffer */
atomic_t peer_rmbe_space ; /* remaining free bytes in peer
* rmbe
*/
2017-01-09 18:55:20 +03:00
int rtoken_idx ; /* idx to peer RMB rkey/addr */
2017-01-09 18:55:18 +03:00
struct smc_buf_desc * sndbuf_desc ; /* send buffer descriptor */
struct smc_buf_desc * rmb_desc ; /* RMBE descriptor */
int rmbe_size_short ; /* compressed notation */
2017-01-09 18:55:24 +03:00
int rmbe_update_limit ;
/* lower limit for consumer
* cursor update
*/
2017-01-09 18:55:22 +03:00
struct smc_host_cdc_msg local_tx_ctrl ; /* host byte order staging
* buffer for CDC msg send
* . prod cf . TCP snd_nxt
* . cons cf . TCP sends ack
*/
2020-05-04 15:18:37 +03:00
union smc_host_cursor local_tx_ctrl_fin ;
/* prod crsr - confirmed by peer
*/
2017-01-09 18:55:22 +03:00
union smc_host_cursor tx_curs_prep ; /* tx - prepared data
* snd_max . . wmem_alloc
*/
union smc_host_cursor tx_curs_sent ; /* tx - sent data
* snd_nxt ?
*/
union smc_host_cursor tx_curs_fin ; /* tx - confirmed by peer
* snd - wnd - begin ?
*/
atomic_t sndbuf_space ; /* remaining space in sndbuf */
u16 tx_cdc_seq ; /* sequence # for CDC send */
2020-05-04 15:18:37 +03:00
u16 tx_cdc_seq_fin ; /* sequence # - tx completed */
2017-01-09 18:55:22 +03:00
spinlock_t send_lock ; /* protect wr_sends */
net/smc: fix kernel panic caused by race of smc_sock
A crash occurs when smc_cdc_tx_handler() tries to access smc_sock
but smc_release() has already freed it.
[ 4570.695099] BUG: unable to handle page fault for address: 000000002eae9e88
[ 4570.696048] #PF: supervisor write access in kernel mode
[ 4570.696728] #PF: error_code(0x0002) - not-present page
[ 4570.697401] PGD 0 P4D 0
[ 4570.697716] Oops: 0002 [#1] PREEMPT SMP NOPTI
[ 4570.698228] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-rc4+ #111
[ 4570.699013] Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS 8c24b4c 04/0
[ 4570.699933] RIP: 0010:_raw_spin_lock+0x1a/0x30
<...>
[ 4570.711446] Call Trace:
[ 4570.711746] <IRQ>
[ 4570.711992] smc_cdc_tx_handler+0x41/0xc0
[ 4570.712470] smc_wr_tx_tasklet_fn+0x213/0x560
[ 4570.712981] ? smc_cdc_tx_dismisser+0x10/0x10
[ 4570.713489] tasklet_action_common.isra.17+0x66/0x140
[ 4570.714083] __do_softirq+0x123/0x2f4
[ 4570.714521] irq_exit_rcu+0xc4/0xf0
[ 4570.714934] common_interrupt+0xba/0xe0
Though smc_cdc_tx_handler() checked the existence of smc connection,
smc_release() may have already dismissed and released the smc socket
before smc_cdc_tx_handler() further visits it.
smc_cdc_tx_handler() |smc_release()
if (!conn) |
|
|smc_cdc_tx_dismiss_slots()
| smc_cdc_tx_dismisser()
|
|sock_put(&smc->sk) <- last sock_put,
| smc_sock freed
bh_lock_sock(&smc->sk) (panic) |
To make sure we won't receive any CDC messages after we free the
smc_sock, add a refcount on the smc_connection for inflight CDC
message(posted to the QP but haven't received related CQE), and
don't release the smc_connection until all the inflight CDC messages
haven been done, for both success or failed ones.
Using refcount on CDC messages brings another problem: when the link
is going to be destroyed, smcr_link_clear() will reset the QP, which
then remove all the pending CQEs related to the QP in the CQ. To make
sure all the CQEs will always come back so the refcount on the
smc_connection can always reach 0, smc_ib_modify_qp_reset() was replaced
by smc_ib_modify_qp_error().
And remove the timeout in smc_wr_tx_wait_no_pending_sends() since we
need to wait for all pending WQEs done, or we may encounter use-after-
free when handling CQEs.
For IB device removal routine, we need to wait for all the QPs on that
device been destroyed before we can destroy CQs on the device, or
the refcount on smc_connection won't reach 0 and smc_sock cannot be
released.
Fixes: 5f08318f617b ("smc: connection data control (CDC)")
Reported-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: Dust Li <dust.li@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-12-28 12:03:25 +03:00
atomic_t cdc_pend_tx_wr ; /* number of pending tx CDC wqe
* - inc when post wqe ,
* - dec on polled tx cqe
*/
wait_queue_head_t cdc_pend_tx_wq ; /* wakeup on no cdc_pend_tx_wr*/
2022-03-01 12:43:57 +03:00
atomic_t tx_pushing ; /* nr_threads trying tx push */
2017-09-21 10:16:33 +03:00
struct delayed_work tx_work ; /* retry of smc_cdc_msg_send */
2018-05-18 10:34:13 +03:00
u32 tx_off ; /* base offset in peer rmb */
2017-01-09 18:55:22 +03:00
struct smc_host_cdc_msg local_rx_ctrl ; /* filled during event_handl.
* . prod cf . TCP rcv_nxt
* . cons cf . TCP snd_una
*/
union smc_host_cursor rx_curs_confirmed ; /* confirmed to peer
* source of snd_una ?
*/
2018-05-23 17:38:11 +03:00
union smc_host_cursor urg_curs ; /* points at urgent byte */
enum smc_urg_state urg_state ;
bool urg_tx_pend ; /* urgent data staged */
bool urg_rx_skip_pend ;
/* indicate urgent oob data
* read , but previous regular
* data still pending
*/
char urg_rx_byte ; /* urgent byte */
2022-03-01 12:44:02 +03:00
bool tx_in_release_sock ;
/* flush pending tx data in
* sock release_cb ( )
*/
2017-01-09 18:55:22 +03:00
atomic_t bytes_to_rcv ; /* arrived data,
* not yet received
*/
2018-05-03 19:12:39 +03:00
atomic_t splice_pending ; /* number of spliced bytes
* pending processing
*/
2017-01-09 18:55:22 +03:00
# ifndef KERNEL_HAS_ATOMIC64
spinlock_t acurs_lock ; /* protect cursors */
# endif
2017-04-10 15:58:01 +03:00
struct work_struct close_work ; /* peer sent some closing */
2020-05-04 15:18:40 +03:00
struct work_struct abort_work ; /* abort the connection */
2018-06-28 20:05:10 +03:00
struct tasklet_struct rx_tsklet ; /* Receiver tasklet for SMC-D */
u8 rx_off ; /* receive offset:
* 0 for SMC - R , 32 for SMC - D
*/
u64 peer_token ; /* SMC-D token of peer */
2019-10-21 17:13:08 +03:00
u8 killed : 1 ; /* abnormal termination */
2022-01-13 11:36:40 +03:00
u8 freed : 1 ; /* normal termiation */
2020-05-04 15:18:40 +03:00
u8 out_of_sync : 1 ; /* out of sync with peer */
2017-01-09 18:55:17 +03:00
} ;
2017-01-09 18:55:13 +03:00
struct smc_sock { /* smc sock container */
struct sock sk ;
struct socket * clcsock ; /* internal tcp socket */
net/smc: Forward wakeup to smc socket waitqueue after fallback
When we replace TCP with SMC and a fallback occurs, there may be
some socket waitqueue entries remaining in smc socket->wq, such
as eppoll_entries inserted by userspace applications.
After the fallback, data flows over TCP/IP and only clcsocket->wq
will be woken up. Applications can't be notified by the entries
which were inserted in smc socket->wq before fallback. So we need
a mechanism to wake up smc socket->wq at the same time if some
entries remaining in it.
The current workaround is to transfer the entries from smc socket->wq
to clcsock->wq during the fallback. But this may cause a crash
like this:
general protection fault, probably for non-canonical address 0xdead000000000100: 0000 [#1] PREEMPT SMP PTI
CPU: 3 PID: 0 Comm: swapper/3 Kdump: loaded Tainted: G E 5.16.0+ #107
RIP: 0010:__wake_up_common+0x65/0x170
Call Trace:
<IRQ>
__wake_up_common_lock+0x7a/0xc0
sock_def_readable+0x3c/0x70
tcp_data_queue+0x4a7/0xc40
tcp_rcv_established+0x32f/0x660
? sk_filter_trim_cap+0xcb/0x2e0
tcp_v4_do_rcv+0x10b/0x260
tcp_v4_rcv+0xd2a/0xde0
ip_protocol_deliver_rcu+0x3b/0x1d0
ip_local_deliver_finish+0x54/0x60
ip_local_deliver+0x6a/0x110
? tcp_v4_early_demux+0xa2/0x140
? tcp_v4_early_demux+0x10d/0x140
ip_sublist_rcv_finish+0x49/0x60
ip_sublist_rcv+0x19d/0x230
ip_list_rcv+0x13e/0x170
__netif_receive_skb_list_core+0x1c2/0x240
netif_receive_skb_list_internal+0x1e6/0x320
napi_complete_done+0x11d/0x190
mlx5e_napi_poll+0x163/0x6b0 [mlx5_core]
__napi_poll+0x3c/0x1b0
net_rx_action+0x27c/0x300
__do_softirq+0x114/0x2d2
irq_exit_rcu+0xb4/0xe0
common_interrupt+0xba/0xe0
</IRQ>
<TASK>
The crash is caused by privately transferring waitqueue entries from
smc socket->wq to clcsock->wq. The owners of these entries, such as
epoll, have no idea that the entries have been transferred to a
different socket wait queue and still use original waitqueue spinlock
(smc socket->wq.wait.lock) to make the entries operation exclusive,
but it doesn't work. The operations to the entries, such as removing
from the waitqueue (now is clcsock->wq after fallback), may cause a
crash when clcsock waitqueue is being iterated over at the moment.
This patch tries to fix this by no longer transferring wait queue
entries privately, but introducing own implementations of clcsock's
callback functions in fallback situation. The callback functions will
forward the wakeup to smc socket->wq if clcsock->wq is actually woken
up and smc socket->wq has remaining entries.
Fixes: 2153bd1e3d3d ("net/smc: Transfer remaining wait queue entries during fallback")
Suggested-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Acked-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-01-26 18:33:04 +03:00
void ( * clcsk_state_change ) ( struct sock * sk ) ;
/* original stat_change fct. */
2020-09-10 19:48:20 +03:00
void ( * clcsk_data_ready ) ( struct sock * sk ) ;
net/smc: Forward wakeup to smc socket waitqueue after fallback
When we replace TCP with SMC and a fallback occurs, there may be
some socket waitqueue entries remaining in smc socket->wq, such
as eppoll_entries inserted by userspace applications.
After the fallback, data flows over TCP/IP and only clcsocket->wq
will be woken up. Applications can't be notified by the entries
which were inserted in smc socket->wq before fallback. So we need
a mechanism to wake up smc socket->wq at the same time if some
entries remaining in it.
The current workaround is to transfer the entries from smc socket->wq
to clcsock->wq during the fallback. But this may cause a crash
like this:
general protection fault, probably for non-canonical address 0xdead000000000100: 0000 [#1] PREEMPT SMP PTI
CPU: 3 PID: 0 Comm: swapper/3 Kdump: loaded Tainted: G E 5.16.0+ #107
RIP: 0010:__wake_up_common+0x65/0x170
Call Trace:
<IRQ>
__wake_up_common_lock+0x7a/0xc0
sock_def_readable+0x3c/0x70
tcp_data_queue+0x4a7/0xc40
tcp_rcv_established+0x32f/0x660
? sk_filter_trim_cap+0xcb/0x2e0
tcp_v4_do_rcv+0x10b/0x260
tcp_v4_rcv+0xd2a/0xde0
ip_protocol_deliver_rcu+0x3b/0x1d0
ip_local_deliver_finish+0x54/0x60
ip_local_deliver+0x6a/0x110
? tcp_v4_early_demux+0xa2/0x140
? tcp_v4_early_demux+0x10d/0x140
ip_sublist_rcv_finish+0x49/0x60
ip_sublist_rcv+0x19d/0x230
ip_list_rcv+0x13e/0x170
__netif_receive_skb_list_core+0x1c2/0x240
netif_receive_skb_list_internal+0x1e6/0x320
napi_complete_done+0x11d/0x190
mlx5e_napi_poll+0x163/0x6b0 [mlx5_core]
__napi_poll+0x3c/0x1b0
net_rx_action+0x27c/0x300
__do_softirq+0x114/0x2d2
irq_exit_rcu+0xb4/0xe0
common_interrupt+0xba/0xe0
</IRQ>
<TASK>
The crash is caused by privately transferring waitqueue entries from
smc socket->wq to clcsock->wq. The owners of these entries, such as
epoll, have no idea that the entries have been transferred to a
different socket wait queue and still use original waitqueue spinlock
(smc socket->wq.wait.lock) to make the entries operation exclusive,
but it doesn't work. The operations to the entries, such as removing
from the waitqueue (now is clcsock->wq after fallback), may cause a
crash when clcsock waitqueue is being iterated over at the moment.
This patch tries to fix this by no longer transferring wait queue
entries privately, but introducing own implementations of clcsock's
callback functions in fallback situation. The callback functions will
forward the wakeup to smc socket->wq if clcsock->wq is actually woken
up and smc socket->wq has remaining entries.
Fixes: 2153bd1e3d3d ("net/smc: Transfer remaining wait queue entries during fallback")
Suggested-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Acked-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-01-26 18:33:04 +03:00
/* original data_ready fct. */
void ( * clcsk_write_space ) ( struct sock * sk ) ;
/* original write_space fct. */
void ( * clcsk_error_report ) ( struct sock * sk ) ;
/* original error_report fct. */
2017-01-09 18:55:17 +03:00
struct smc_connection conn ; /* smc connection */
2017-01-09 18:55:16 +03:00
struct smc_sock * listen_smc ; /* listen parent */
2018-06-27 18:59:50 +03:00
struct work_struct connect_work ; /* handle non-blocking connect*/
2017-01-09 18:55:16 +03:00
struct work_struct tcp_listen_work ; /* handle tcp socket accepts */
struct work_struct smc_listen_work ; /* prepare new accept socket */
struct list_head accept_q ; /* sockets to be accepted */
spinlock_t accept_q_lock ; /* protects accept_q */
2022-02-10 12:11:37 +03:00
bool limit_smc_hs ; /* put constraint on handshake */
2017-01-09 18:55:13 +03:00
bool use_fallback ; /* fallback to tcp */
2018-07-25 17:35:32 +03:00
int fallback_rsn ; /* reason for fallback */
u32 peer_diagnosis ; /* decline reason from peer */
net/smc: Limit backlog connections
Current implementation does not handling backlog semantics, one
potential risk is that server will be flooded by infinite amount
connections, even if client was SMC-incapable.
This patch works to put a limit on backlog connections, referring to the
TCP implementation, we divides SMC connections into two categories:
1. Half SMC connection, which includes all TCP established while SMC not
connections.
2. Full SMC connection, which includes all SMC established connections.
For half SMC connection, since all half SMC connections starts with TCP
established, we can achieve our goal by put a limit before TCP
established. Refer to the implementation of TCP, this limits will based
on not only the half SMC connections but also the full connections,
which is also a constraint on full SMC connections.
For full SMC connections, although we know exactly where it starts, it's
quite hard to put a limit before it. The easiest way is to block wait
before receive SMC confirm CLC message, while it's under protection by
smc_server_lgr_pending, a global lock, which leads this limit to the
entire host instead of a single listen socket. Another way is to drop
the full connections, but considering the cast of SMC connections, we
prefer to keep full SMC connections.
Even so, the limits of full SMC connections still exists, see commits
about half SMC connection below.
After this patch, the limits of backend connection shows like:
For SMC:
1. Client with SMC-capability can makes 2 * backlog full SMC connections
or 1 * backlog half SMC connections and 1 * backlog full SMC
connections at most.
2. Client without SMC-capability can only makes 1 * backlog half TCP
connections and 1 * backlog full TCP connections.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-02-10 12:11:35 +03:00
atomic_t queued_smc_hs ; /* queued smc handshakes */
struct inet_connection_sock_af_ops af_ops ;
const struct inet_connection_sock_af_ops * ori_af_ops ;
/* original af ops */
2018-04-26 18:18:23 +03:00
int sockopt_defer_accept ;
/* sockopt TCP_DEFER_ACCEPT
* value
*/
2017-01-09 18:55:25 +03:00
u8 wait_close_tx_prepared : 1 ;
/* shutdown wr or close
* started , waiting for unsent
* data to be sent
*/
2019-04-12 13:57:23 +03:00
u8 connect_nonblock : 1 ;
/* non-blocking connect in
* flight
*/
2018-12-18 20:02:25 +03:00
struct mutex clcsock_release_lock ;
/* protects clcsock of a listen
* socket
* */
2017-01-09 18:55:13 +03:00
} ;
2023-03-17 18:55:36 +03:00
# define smc_sk(ptr) container_of_const(ptr, struct smc_sock, sk)
2017-01-09 18:55:13 +03:00
2022-04-22 10:56:18 +03:00
static inline void smc_init_saved_callbacks ( struct smc_sock * smc )
{
smc - > clcsk_state_change = NULL ;
smc - > clcsk_data_ready = NULL ;
smc - > clcsk_write_space = NULL ;
smc - > clcsk_error_report = NULL ;
}
net/smc: Limit backlog connections
Current implementation does not handling backlog semantics, one
potential risk is that server will be flooded by infinite amount
connections, even if client was SMC-incapable.
This patch works to put a limit on backlog connections, referring to the
TCP implementation, we divides SMC connections into two categories:
1. Half SMC connection, which includes all TCP established while SMC not
connections.
2. Full SMC connection, which includes all SMC established connections.
For half SMC connection, since all half SMC connections starts with TCP
established, we can achieve our goal by put a limit before TCP
established. Refer to the implementation of TCP, this limits will based
on not only the half SMC connections but also the full connections,
which is also a constraint on full SMC connections.
For full SMC connections, although we know exactly where it starts, it's
quite hard to put a limit before it. The easiest way is to block wait
before receive SMC confirm CLC message, while it's under protection by
smc_server_lgr_pending, a global lock, which leads this limit to the
entire host instead of a single listen socket. Another way is to drop
the full connections, but considering the cast of SMC connections, we
prefer to keep full SMC connections.
Even so, the limits of full SMC connections still exists, see commits
about half SMC connection below.
After this patch, the limits of backend connection shows like:
For SMC:
1. Client with SMC-capability can makes 2 * backlog full SMC connections
or 1 * backlog half SMC connections and 1 * backlog full SMC
connections at most.
2. Client without SMC-capability can only makes 1 * backlog half TCP
connections and 1 * backlog full TCP connections.
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-02-10 12:11:35 +03:00
static inline struct smc_sock * smc_clcsock_user_data ( const struct sock * clcsk )
net/smc: Forward wakeup to smc socket waitqueue after fallback
When we replace TCP with SMC and a fallback occurs, there may be
some socket waitqueue entries remaining in smc socket->wq, such
as eppoll_entries inserted by userspace applications.
After the fallback, data flows over TCP/IP and only clcsocket->wq
will be woken up. Applications can't be notified by the entries
which were inserted in smc socket->wq before fallback. So we need
a mechanism to wake up smc socket->wq at the same time if some
entries remaining in it.
The current workaround is to transfer the entries from smc socket->wq
to clcsock->wq during the fallback. But this may cause a crash
like this:
general protection fault, probably for non-canonical address 0xdead000000000100: 0000 [#1] PREEMPT SMP PTI
CPU: 3 PID: 0 Comm: swapper/3 Kdump: loaded Tainted: G E 5.16.0+ #107
RIP: 0010:__wake_up_common+0x65/0x170
Call Trace:
<IRQ>
__wake_up_common_lock+0x7a/0xc0
sock_def_readable+0x3c/0x70
tcp_data_queue+0x4a7/0xc40
tcp_rcv_established+0x32f/0x660
? sk_filter_trim_cap+0xcb/0x2e0
tcp_v4_do_rcv+0x10b/0x260
tcp_v4_rcv+0xd2a/0xde0
ip_protocol_deliver_rcu+0x3b/0x1d0
ip_local_deliver_finish+0x54/0x60
ip_local_deliver+0x6a/0x110
? tcp_v4_early_demux+0xa2/0x140
? tcp_v4_early_demux+0x10d/0x140
ip_sublist_rcv_finish+0x49/0x60
ip_sublist_rcv+0x19d/0x230
ip_list_rcv+0x13e/0x170
__netif_receive_skb_list_core+0x1c2/0x240
netif_receive_skb_list_internal+0x1e6/0x320
napi_complete_done+0x11d/0x190
mlx5e_napi_poll+0x163/0x6b0 [mlx5_core]
__napi_poll+0x3c/0x1b0
net_rx_action+0x27c/0x300
__do_softirq+0x114/0x2d2
irq_exit_rcu+0xb4/0xe0
common_interrupt+0xba/0xe0
</IRQ>
<TASK>
The crash is caused by privately transferring waitqueue entries from
smc socket->wq to clcsock->wq. The owners of these entries, such as
epoll, have no idea that the entries have been transferred to a
different socket wait queue and still use original waitqueue spinlock
(smc socket->wq.wait.lock) to make the entries operation exclusive,
but it doesn't work. The operations to the entries, such as removing
from the waitqueue (now is clcsock->wq after fallback), may cause a
crash when clcsock waitqueue is being iterated over at the moment.
This patch tries to fix this by no longer transferring wait queue
entries privately, but introducing own implementations of clcsock's
callback functions in fallback situation. The callback functions will
forward the wakeup to smc socket->wq if clcsock->wq is actually woken
up and smc socket->wq has remaining entries.
Fixes: 2153bd1e3d3d ("net/smc: Transfer remaining wait queue entries during fallback")
Suggested-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Acked-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-01-26 18:33:04 +03:00
{
return ( struct smc_sock * )
( ( uintptr_t ) clcsk - > sk_user_data & ~ SK_USER_DATA_NOCOPY ) ;
}
2022-04-22 10:56:18 +03:00
/* save target_cb in saved_cb, and replace target_cb with new_cb */
static inline void smc_clcsock_replace_cb ( void ( * * target_cb ) ( struct sock * ) ,
void ( * new_cb ) ( struct sock * ) ,
void ( * * saved_cb ) ( struct sock * ) )
{
/* only save once */
if ( ! * saved_cb )
* saved_cb = * target_cb ;
* target_cb = new_cb ;
}
/* restore target_cb to saved_cb, and reset saved_cb to NULL */
static inline void smc_clcsock_restore_cb ( void ( * * target_cb ) ( struct sock * ) ,
void ( * * saved_cb ) ( struct sock * ) )
{
if ( ! * saved_cb )
return ;
* target_cb = * saved_cb ;
* saved_cb = NULL ;
}
2020-09-10 19:48:29 +03:00
extern struct workqueue_struct * smc_hs_wq ; /* wq for handshake work */
extern struct workqueue_struct * smc_close_wq ; /* wq for close work */
2017-01-09 18:55:14 +03:00
# define SMC_SYSTEMID_LEN 8
extern u8 local_systemid [ SMC_SYSTEMID_LEN ] ; /* unique system identifier */
2020-09-26 13:44:28 +03:00
# define ntohll(x) be64_to_cpu(x)
# define htonll(x) cpu_to_be64(x)
2017-01-09 18:55:17 +03:00
/* convert an u32 value into network byte order, store it into a 3 byte field */
static inline void hton24 ( u8 * net , u32 host )
{
__be32 t ;
t = cpu_to_be32 ( host ) ;
memcpy ( net , ( ( u8 * ) & t ) + 1 , 3 ) ;
}
/* convert a received 3 byte field into host byte order*/
static inline u32 ntoh24 ( u8 * net )
{
__be32 t = 0 ;
memcpy ( ( ( u8 * ) & t ) + 1 , net , 3 ) ;
return be32_to_cpu ( t ) ;
}
2017-01-09 18:55:16 +03:00
# ifdef CONFIG_XFRM
static inline bool using_ipsec ( struct smc_sock * smc )
{
return ( smc - > clcsock - > sk - > sk_policy [ 0 ] | |
2018-01-26 11:28:50 +03:00
smc - > clcsock - > sk - > sk_policy [ 1 ] ) ? true : false ;
2017-01-09 18:55:16 +03:00
}
# else
static inline bool using_ipsec ( struct smc_sock * smc )
{
2018-01-26 11:28:50 +03:00
return false ;
2017-01-09 18:55:16 +03:00
}
# endif
2021-10-16 12:37:50 +03:00
struct smc_gidlist ;
2017-01-09 18:55:25 +03:00
struct sock * smc_accept_dequeue ( struct sock * parent , struct socket * new_sock ) ;
void smc_close_non_accepted ( struct sock * sk ) ;
2021-10-16 12:37:50 +03:00
void smc_fill_gid_list ( struct smc_link_group * lgr ,
struct smc_gidlist * gidlist ,
struct smc_ib_device * known_dev , u8 * known_gid ) ;
2017-01-09 18:55:16 +03:00
2022-02-10 12:11:38 +03:00
/* smc handshake limitation interface for netlink */
int smc_nl_dump_hs_limitation ( struct sk_buff * skb , struct netlink_callback * cb ) ;
int smc_nl_enable_hs_limitation ( struct sk_buff * skb , struct genl_info * info ) ;
int smc_nl_disable_hs_limitation ( struct sk_buff * skb , struct genl_info * info ) ;
2017-01-09 18:55:13 +03:00
# endif /* __SMC_H */