net/smc: Shared Memory Communications - RDMA
Subsystems (6)
v2 cover net/smc: Shared Memory Communications - RDMA
Dave,
here is now V2 of the SMC-R patches having processed your August feedback plus reported coccinelle findings. The most important change is the removal of xchg() calls, I had wrongly used for atomic updates of 64-bit values. I still see a need for atomic reads and updates of 64-bit SMC-cursors. If type atomic64_t is not supported, I use plain u64 for SMC-cursors and add locking when reading or writing the cursors.
V2 changes:
Patch 0002: Add SMC versions for family key strings in net/core/sock.c. Patch 0006: initialize rb_tree.
Patch 0007: Get rid of unneeded use of xchg() in smc_sndbuf_unuse() and
smc_rmb_unuse().
Patch 0008: Correct error checking logic for ib_function calls.
Define struct smc_link field wr_tx_id as atomic_long_t. Use "do_div" instead of "%" to be architecture-independent.
Patch 0009: Correct error checking logic for ib_function calls. Patch 0011: Remove xchg() calls in cursor handling. Use atomic64_t for cursor
overlays on 64-bit architectures. If not available, use plain u64 and add locking for cursor reading and writing. Implement smc_curs_add() without modulo operator "%".
Patch 0012: Remove xchg() calls in cursor handling.
Implement smc_tx_rdma_writes() without module operator "%".
Patch 0013: Remove xchg() calls in cursor handling.
Patch 0014: Return type bool in smc_wr_tx_has_pending().
Remove unneeded semicolon in smc_close_shutdown_write(). Call smc_close_active() in non-fallback case only. Get rid of duplicate schedule of sock_put_work(). Take nested sock_lock in smc_listen_work().
Start close stream_wait in case of prepared sends only.
Patch 0015: Remove unneeded socket ref_count in smc_proc_seq_show().
Take lock before list_empty check in smc_proc_sock_list_del().
These patches are the initial part of the implementation of the "Shared Memory Communications-RDMA" (SMC-R) protocol as defined in RFC7609 [1]. While SMC-R does not aim to replace TCP,
it taps a wealth of existing data center TCP socket applications to become more efficient without the need for rewriting them. SMC-R uses RDMA over Converged Ethernet (RoCE) to save CPU consumption. For instance, when running 10 parallel connections with uperf, we measured a decrease of 60% in CPU consumption with SMC-R compared to TCP/IP (with throughput and latency comparable;
measured on x86_64 with the same RoCE card and port).
SMC-R does not require an RDMA communication manager (RDMA CM).
SMC-R inherits TCP qualities such as reliable connections, host-based firewall packet filtering (on connection establishment) and unmodified application of communication encryption such as TLS (transport layer security) or SSL (secure sockets layer). Since original TCP is used to establish SMC-R connections, load balancers and packet inspection based on TCP/IP connection establishment continue to work for SMC-R.
On the other hand, using SMC-R implies:
- either involving a preload library when invoking the unchanged TCP-application or slightly modifying the source by simply changing the socket family in the socket() call
- accepting extra overhead and latency in connection establishment due to SMC Connection Layer Control (CLC) handshake
- explicit coupling of RoCE ports with Ethernet ports
- not routable as currently built on RoCE V1
- bypassing of packet-based networking features
- filtering (netfilter)
- sniffing (libpcap, packet sockets, (E)BPF)
- traffic control (scheduling, shaping)
- bypassing of IP-header based socket options
- bypassing of memory buffer (pressure) management
- unusable together with IPsec
Overview of the SMC-R Protocol described in informational RFC 7609
SMC-R is an open protocol that provides RDMA capabilities over RoCE transparently for applications exploiting TCP sockets.
A new socket protocol family PF_SMC is introduced.
There are no changes required to applications using the sockets API for TCP stream sockets other than the specification of the new socket family AF_SMC. Unmodified applications can be used by means of a dynamic preload shared library which rewrites the socket API callsocket(AF_INET, SOCK_STREAM, IPPROTO_TCP) intosocket(AF_SMC, SOCK_STREAM, IPPROTO_TCP).
SMC-R re-uses the address family AF_INET for all addressing purposes around struct sockaddr.
SMC-R system architecture layers:
+=============================================================================+ | | unmodified TCP application | | native SMC application +--------------------------------------+ | | dynamic preload shared library | +=============================================================================+ | SMC socket | +-----------------------------------------------------------------------------+ | | TCP socket (for connection establishment and fallback) | | IB verbs +--------------------------------------------------------+ | | IP | +--------------------+--------------------------------------------------------+ | RoCE device driver | some network device driver | +=============================================================================+
Terms:
A link group is determined by an ordered peer pair of TCP client and TCP server (IP addresses and subnet). Reversed client server roles cause an own link group. A link is a logical point-to-point connection based on an infiniband reliable connected queue pair (RC-QP) between two RoCE ports (MACs and GIDs) of a peer pair.
A link group can have 1..8 links for failover and load balancing. This initial Linux implementation always has 1 link per link group. Each link group on a peer can have 1..255 remote memory buffers (RMBs). If more RMBs are needed, a peer can open another link group
(this initial Linux implementation) or fall back to TCP.
Each RMB has its own particular size and its own (R)DMA mapping and credentials (rtoken consisting of rkey and RDMA "virtual address").
This initial Linux implementation uses physically contiguous memory for RMBs but we are working towards scattered memory because of memory fragmentation. Each RMB has 1..255 RMB elements (RMBEs) of equal size
to provide multiplexing of connections within an RMB.
An RMBE is the RDMA Write destination organized as wrapping ring buffer for data transmit of a particular connection in one direction (duplex by means of mirror symmetry as with TCP).
This initial Linux implementation always has 1 RMBE per RMB
and thus an individual RMB for each connection.
SMC-R connection establishment with subsequent data transfer:
CLIENT SERVER
TCP three-way handshake:
regular TCP SYN
-------------------------------------------------------->
regular TCP SYN ACK
<--------------------------------------------------------
regular TCP ACK
-------------------------------------------------------->
SMC Connection Layer Control (CLC) handshake exchanges RDMA credentials between peers:
via above TCP connection: SMC CLC Proposal
-------------------------------------------------------->
via above TCP connection: SMC CLC Accept
<--------------------------------------------------------
via above TCP connection: SMC CLC Confirm
-------------------------------------------------------->
SMC Link Layer Control (LLC) (only once per link, i.e. 1st conn. of link group):
RoCE RC-QP: SMC LLC Confirm Link
<========================================================
RoCE RC-QP: SMC LLC Confirm Link response
========================================================>
SMC data transmission (incl. SMC Connection Data Control (CDC) message):
RoCE RC-QP: RDMA Write
========================================================>
RoCE RC-QP: SMC CDC message (flow control)
========================================================>
...
RoCE RC-QP: RDMA Write
<========================================================
RoCE RC-QP: SMC CDC message (flow control)
<========================================================
...Data flow within an established connection:
+----------------------------------------------------------------------------
| SENDER
| sendmsg()
| |
| | produces into sndbuf [sender's process context]
| v
| +--------+
| | sndbuf | [ring buffer]
| +--------+
| |
| | consumes from sndbuf and produces into receiver's RMBE [any context]
| | by sending RDMA Write followed by SMC CDC message over RoCE RC-QP
| |
+----|-----------------------------------------------------------------------
|
+----|-----------------------------------------------------------------------
| v RECEIVER
| +------+
| | RMBE | [ring buffer, can have size different from sender's sndbuf]
| | | [RMBE represents rcvbuf, no further de-coupling as on sender side]
| +------+
| |
| | consumes from RMBE [receiver's process context]
| v
| recvmsg()
+----------------------------------------------------------------------------Flow control ("cursor" updates) by means of SMC CDC messages:
SENDER RECEIVER
sends updates via CDC-------------+ sends updates via CDC
on consuming from sndbuf | on consuming from RMBE
and producing into RMBE | by means of recvmsg()
| |
| |
+-----------------------------------|------------+
| |
+--v-------------------------+ +--v-----------------------+
| receiver's consumer cursor | | sender's producer cursor----+
+----------------|-----------+ +--------------------------+ |
| |
| receiver's RMBE |
| +--------------------------+ |
| | | |
+--------------------------------+ | |
| | | |
| v | |
| +------------| |
|-------------+////////////| |
|//RDMA data written by////| |
|////sender that is////////| |
|/available to be consumed/| |
|///////// +---------------| |
|----------+^ | |
| | | |
| +-----------------+
| |
+--------------------------+Sending updates of the producer cursor is immediate for low latency; something like Nagle's algorithm (absence of TCP_NODELAY) is optional and currently not part of this initial Linux implementation. Sending updates of the consumer cursor is conditional to avoid the silly window syndrome.
Normal connection termination:
Normal connection termination starts transitioning from socket state ACTIVE via either "Active Close" or "Passive Close".
shutdown rdwr +-----------------+
or close, +-------------->| INIT / CLOSED |<-------------+
send PeerCon|nClosed +-----------------+ | PeerConnClosed
| | | received
| connection | established |
| V |
+----------------+ +-----------------+ +----------------+
|AppFinCloseWait | | ACTIVE | |PeerFinCloseWait|
+----------------+ +-----------------+ +----------------+
| | | |
| Active Close: | |Passive Close: |
| close or | |PeerConnClosed or |
| shutdown wr or| |PeerDoneWriting |
| shutdown rdwr | |received |
| V V |
PeerConnClo|sed +--------------+ +-------------+ | close or
received +--<----|PeerCloseWait1| |AppCloseWait1|--->----+ shutdown rdwr,
| +--------------+ +-------------+ | send
| PeerDoneWri|ting | shutdown wr, | PeerConnClosed
| received | send Pee|rDoneWriting |
| V V |
| +--------------+ +-------------+ |
+--<----|PeerCloseWait2| |AppCloseWait2|--->----+
+--------------+ +-------------+In state CLOSED, the socket can be destructed only, once the application has issued a close().
Abnormal connection termination:
+-----------------+
+-------------->| INIT / CLOSED |<-------------+
| +-----------------+ |
| |
| +-----------------------+ |
| | Any state | |
PeerConnAbo|rt | (before setting | | send
received | | PeerConnClosed | | PeerConnAbort
| | indicator in | |
| | peer's RMBE) | |
| +-----------------------+ |
| | | |
| Active Abort: | | Passive Abort: |
| problem, | | PeerConnAbort |
| send | | received, |
| PeerConnAbort,| | ECONNRESET |
| ECONNABORTED | | |
| V V |
| +--------------+ +--------------+ |
+-------|PeerAbortWait | | ProcessAbort |------+
+--------------+ +--------------+Implementation notes beyond RFC 7609:
A PNET table in sysfs provides the mapping between network device names and RoCE Infiniband device names for the transparent switch of data communication. A PNET table can contain an arbitrary number of PNETIDs.
Each PNETID contains exactly one (Ethernet) network device name and one or more RoCE Infiniband device names.
Each device name can only exist in at most one PNETID (no overlapping). This initial Linux implementation allows at most one RoCE Infiniband device name per PNETID.
After a new TCP connection is established, the network device name used for egress traffic with the TCP connection's local source IP address is used as key to lookup the unique PNETID, and the RoCE Infiniband device of this PNETID is used to switch data communication from TCP to RDMA during SMC CLC handshake.
Problem determination:
A protocol dissector is available with upstream wireshark for formatting SMC-R related RoCE LAN traffic.
[https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob;f=epan/dissectors/packet-smcr.c]
We are working on enhancing the Linux implementation to cover:
- Improve default socket closing asynchronicity
- Address corner cases with many parallel connections
- Tracing
- Integrated load balancing and fail-over within a link group
- Splice and sendpage support
- IPv6 addressing support
- Keepalive, Cork
- Namespaces support
- Urgent data
- More socket options
- Diagnostics
- Statistics support
- SNMP support
References:
[1] SMC-R Informational RFC: http://www.rfc-editor.org/info/rfc7609
Thomas Richter (1):
smc: establish pnet table management
Ursula Braun (14):
net: introduce keepalive function in struct proto
smc: establish new socket family
smc: introduce SMC as an IB-client
smc: CLC handshake (incl. preparation steps)
smc: connection and link group creation
smc: remote memory buffers (RMBs)
smc: work request (WR) base for use by LLC and CDC
smc: initialize IB transport incl. PD, MR, QP, CQ, event, WR
smc: link layer control (LLC)
smc: connection data control (CDC)
smc: send data (through RDMA)
smc: receive data from RMBE
smc: socket closing and linkgroup cleanup
smc: proc-fs interface for smc connections
MAINTAINERS | 7 + include/linux/socket.h | 7 +- include/net/sock.h | 1 + net/Kconfig | 1 + net/Makefile | 1 + net/core/sock.c | 13 +- net/ipv4/tcp_ipv4.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/tcp_ipv6.c | 1 + net/smc/Kconfig | 11 + net/smc/Makefile | 3 + net/smc/af_smc.c | 1380 ++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc.h | 269 ++++++++++ net/smc/smc_cdc.c | 302 +++++++++++ net/smc/smc_cdc.h | 217 ++++++++ net/smc/smc_clc.c | 276 ++++++++++ net/smc/smc_clc.h | 113 ++++ net/smc/smc_close.c | 435 +++++++++++++++ net/smc/smc_close.h | 27 + net/smc/smc_core.c | 704 ++++++++++++++++++++++++ net/smc/smc_core.h | 178 +++++++ net/smc/smc_ib.c | 485 +++++++++++++++++ net/smc/smc_ib.h | 67 +++ net/smc/smc_llc.c | 158 ++++++ net/smc/smc_llc.h | 63 +++ net/smc/smc_pnet.c | 611 +++++++++++++++++++++ net/smc/smc_pnet.h | 26 + net/smc/smc_proc.c | 247 +++++++++ net/smc/smc_proc.h | 19 + net/smc/smc_rx.c | 216 ++++++++ net/smc/smc_rx.h | 22 + net/smc/smc_tx.c | 482 +++++++++++++++++ net/smc/smc_tx.h | 35 ++ net/smc/smc_wr.c | 612 +++++++++++++++++++++ net/smc/smc_wr.h | 103 ++++ 35 files changed, 7085 insertions(+), 9 deletions(-) create mode 100644 net/smc/Kconfig create mode 100644 net/smc/Makefile create mode 100644 net/smc/af_smc.c create mode 100644 net/smc/smc.h create mode 100644 net/smc/smc_cdc.c create mode 100644 net/smc/smc_cdc.h create mode 100644 net/smc/smc_clc.c create mode 100644 net/smc/smc_clc.h create mode 100644 net/smc/smc_close.c create mode 100644 net/smc/smc_close.h create mode 100644 net/smc/smc_core.c create mode 100644 net/smc/smc_core.h create mode 100644 net/smc/smc_ib.c create mode 100644 net/smc/smc_ib.h create mode 100644 net/smc/smc_llc.c create mode 100644 net/smc/smc_llc.h create mode 100644 net/smc/smc_pnet.c create mode 100644 net/smc/smc_pnet.h create mode 100644 net/smc/smc_proc.c create mode 100644 net/smc/smc_proc.h create mode 100644 net/smc/smc_rx.c create mode 100644 net/smc/smc_rx.h create mode 100644 net/smc/smc_tx.c create mode 100644 net/smc/smc_tx.h create mode 100644 net/smc/smc_wr.c create mode 100644 net/smc/smc_wr.h
Signature · 1 line
2.8.4
PATCH v2 1/15 net: introduce keepalive function in struct proto
Direct call of tcp_set_keepalive() function from protocol-agnostic sock_setsockopt() function in net/core/sock.c violates network layering. And newly introduced protocol (SMC-R) will need its own keepalive function. Therefore, add "keepalive" function pointer to "struct proto", and call it from sock_setsockopt() via this pointer.
--- include/net/sock.h | 1 + net/core/sock.c | 7 ++----- net/ipv4/tcp_ipv4.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/tcp_ipv6.c | 1 + 5 files changed, 6 insertions(+), 5 deletions(-)
include/net/sock.h +1 -0
@@ -988,6 +988,7 @@ struct proto {int (*getsockopt)(struct sock *sk,int level,int optname,char __user *optval,int __user *option); +void (*keepalive)(struct sock *sk,int valbool);#ifdef CONFIG_COMPAT int (*compat_setsockopt)(struct sock *sk, int level,
net/core/sock.c +2 -5
@@ -761,11 +761,8 @@ set_rcvbuf: goto set_rcvbuf;case SO_KEEPALIVE : -#ifdef CONFIG_INET -if (sk->sk_protocol ==IPPROTO_TCP && - sk->sk_type ==SOCK_STREAM ) -tcp_set_keepalive (sk, valbool); -#endif +if (sk->sk_prot->keepalive) + sk->sk_prot->keepalive (sk, valbool);sock_valbool_flag (sk,SOCK_KEEPOPEN , valbool);break ;
net/ipv4/tcp_ipv4.c +1 -0
@@ -2361,6 +2361,7 @@ struct proto tcp_prot = { .shutdown = tcp_shutdown, .setsockopt = tcp_setsockopt, .getsockopt = tcp_getsockopt, + .keepalive = tcp_set_keepalive, .recvmsg = tcp_recvmsg, .sendmsg = tcp_sendmsg, .sendpage = tcp_sendpage,
net/ipv4/tcp_timer.c +1 -0
@@ -613,6 +613,7 @@ void tcp_set_keepalive(struct sock *sk, int val)else if (!val)inet_csk_delete_keepalive_timer (sk); } +EXPORT_SYMBOL (tcp_set_keepalive);static void tcp_keepalive_timer (unsigned long data)
net/ipv6/tcp_ipv6.c +1 -0
@@ -1876,6 +1876,7 @@ struct proto tcpv6_prot = { .shutdown = tcp_shutdown, .setsockopt = tcp_setsockopt, .getsockopt = tcp_getsockopt, + .keepalive = tcp_set_keepalive, .recvmsg = tcp_recvmsg, .sendmsg = tcp_sendmsg, .sendpage = tcp_sendpage,
Signature · 1 line
2.8.4
PATCH v2 2/15 smc: establish new socket family
In reply to Ursula Braun * enable smc module loading and unloading
* register new socket family
* basic smc socket creation and deletion
* use backing TCP socket to run CLC (Connection Layer Control) handshake of SMC protocol
* Setup for infiniband traffic is implemented in follow-on patches. For now fallback to TCP socket is always used.
--- MAINTAINERS | 7 + include/linux/socket.h | 7 +- net/Kconfig | 1 + net/Makefile | 1 + net/core/sock.c | 6 +- net/smc/Kconfig | 11 + net/smc/Makefile | 2 + net/smc/af_smc.c | 623 +++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc.h | 36 +++ 9 files changed, 690 insertions(+), 4 deletions(-) create mode 100644 net/smc/Kconfig create mode 100644 net/smc/Makefile create mode 100644 net/smc/af_smc.c create mode 100644 net/smc/smc.h
MAINTAINERS +7 -0
@@ -10331,6 +10331,13 @@ S: Maintained F: Documentation/devicetree/bindings/serial/ F: drivers/tty/serial/ +SHARED MEMORY COMMUNICATIONS (SMC) SOCKETS +M: Ursula Braun <[email protected]> +L: [email protected] +W: http://www.ibm.com/developerworks/linux/linux390/ +S: Supported +F: net/smc/ + SYNOPSYS DESIGNWARE DMAC DRIVER M: Viresh Kumar <[email protected]> M: Andy Shevchenko <[email protected]>
include/linux/socket.h +6 -1
@@ -202,8 +202,12 @@ struct ucred {#define AF_VSOCK 40/* vSockets */ #define AF_KCM 41/* Kernel Connection Multiplexor*/ #define AF_QIPCRTR 42/* Qualcomm IPC Router */ +#define AF_SMC 43/* smc sockets: reserve number for +* PF_SMC protocol family that +* reuses AF_INET address family +*/ -#define AF_MAX 43/* For now.. */ +#define AF_MAX 44/* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC
@@ -251,6 +255,7 @@ struct ucred {#define PF_VSOCK AF_VSOCK#define PF_KCM AF_KCM#define PF_QIPCRTR AF_QIPCRTR +#define PF_SMC AF_SMC#define PF_MAX AF_MAX/* Maximum queue length specifiable by listen. */
net/Kconfig +1 -0
@@ -57,6 +57,7 @@ source "net/packet/Kconfig" source "net/unix/Kconfig" source "net/xfrm/Kconfig" source "net/iucv/Kconfig" +source "net/smc/Kconfig" config INET bool "TCP/IP networking"
net/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_MAC80211) += mac80211/ obj-$(CONFIG_TIPC) += tipc/ obj-$(CONFIG_NETLABEL) += netlabel/ obj-$(CONFIG_IUCV) += iucv/ +obj-$(CONFIG_SMC) += smc/ obj-$(CONFIG_RFKILL) += rfkill/ obj-$(CONFIG_NET_9P) += 9p/ obj-$(CONFIG_CAIF) += caif/
net/core/sock.c +3 -3
@@ -222,7 +222,7 @@ static const char *const af_family_key_strings[AF_MAX+1] = {"sk_lock-AF_RXRPC" ,"sk_lock-AF_ISDN" ,"sk_lock-AF_PHONET" ,"sk_lock-AF_IEEE802154" ,"sk_lock-AF_CAIF" ,"sk_lock-AF_ALG" ,"sk_lock-AF_NFC" ,"sk_lock-AF_VSOCK" ,"sk_lock-AF_KCM" , -"sk_lock-AF_MAX" +"sk_lock-AF_SMC" ,"sk_lock-AF_MAX" };static const char *const af_family_slock_key_strings[AF_MAX +1 ] = { "slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" ,
@@ -239,7 +239,7 @@ static const char *const af_family_slock_key_strings[AF_MAX+1] = {"slock-AF_RXRPC" ,"slock-AF_ISDN" ,"slock-AF_PHONET" ,"slock-AF_IEEE802154" ,"slock-AF_CAIF" ,"slock-AF_ALG" ,"slock-AF_NFC" ,"slock-AF_VSOCK" ,"slock-AF_KCM" , -"slock-AF_MAX" +"slock-AF_SMC" ,"slock-AF_MAX" };static const char *const af_family_clock_key_strings[AF_MAX +1 ] = { "clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" ,
@@ -256,7 +256,7 @@ static const char *const af_family_clock_key_strings[AF_MAX+1] = {"clock-AF_RXRPC" ,"clock-AF_ISDN" ,"clock-AF_PHONET" ,"clock-AF_IEEE802154" ,"clock-AF_CAIF" ,"clock-AF_ALG" ,"clock-AF_NFC" ,"clock-AF_VSOCK" ,"clock-AF_KCM" , -"clock-AF_MAX" +"closck-AF_smc" ,"clock-AF_MAX" };/*
net/smc/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +config SMC + tristate "SMC socket protocol family" + depends on INET && INFINIBAND + ---help--- + SMC-R provides a "sockets over RDMA" solution making use of + RDMA over Converged Ethernet (RoCE) technology to upgrade + AF_INET TCP connections transparently. + The Linux implementation of the SMC-R solution is designed as + a separate socket family SMC. + + Select this option if you want to run SMC socket applications
net/smc/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_SMC) += smc.o +smc-y := af_smc.o
net/smc/af_smc.c new file +623 -0
623 lines not on this page · raw message
net/smc/smc.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Definitions for the SMC module (socket related) +* +* Copyright IBM Corp. 2016 +* +* Author(s): Ursula Braun <[email protected]> +*/ +#ifndef _SMC_H +#define _SMC_H + +#include <linux/socket.h> +#include <linux/types.h> +#include <net/sock.h> + +#define SMCPROTO_SMC 0/* SMC protocol */ + +enum smc_state {/* possible states of an SMC socket */ +SMC_ACTIVE =1 , +SMC_INIT =2 , +SMC_CLOSED =7 , +SMC_LISTEN =10 , +}; + +struct smc_sock {/* smc sock container */ +struct sock sk; +struct socket *clcsock;/* internal tcp socket */ +u8 use_fallback :1 ;/* fallback to tcp */ +}; + +static inline struct smc_sock *smc_sk (const struct sock *sk) +{ +return (struct smc_sock *)sk; +} +#endif /* _SMC_H */
Signature · 1 line
2.8.4
PATCH v2 3/15 smc: establish pnet table management
In reply to Ursula BraunFrom: Thomas Richter <[email protected]>
Connection creation with SMC-R starts through an internal TCP-connection. The Ethernet interface for this TCP-connection is not restricted to the Ethernet interface of a RoCE device. Any existing Ethernet interface belonging to the same physical net can be used, as long as there is a defined relation between the Ethernet interface and some RoCE devices. This relation is defined with the help of an identification string called "Physical Net ID" or short "pnet ID". Information about defined pnet IDs and their related Ethernet interfaces and RoCE devices is stored in the SMC-R pnet table.
This patch adds pnet table configuration support as a set of sysfs files listed under /sys/kernel/smc. Attribute files exist to add and delete pnet IDs and to map RoCE devices and ethernet interfaces to an individual pnet ID.
There is no cross check if ethernet interfaces or infiniband devices really exist in the system. This enables the configuration of the pnet table after module load even if interfaces or devices might not yet be available.
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 11 +- net/smc/smc_pnet.c | 510 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_pnet.h | 19 ++ 4 files changed, 539 insertions(+), 3 deletions(-) create mode 100644 net/smc/smc_pnet.c create mode 100644 net/smc/smc_pnet.h
net/smc/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_SMC) += smc.o -smc-y := af_smc.o +smc-y := af_smc.o smc_pnet.o
net/smc/af_smc.c +9 -2
@@ -20,6 +20,7 @@#include <net/sock.h> #include "smc.h" +#include "smc_pnet.h" static void smc_set_keepalive (struct sock *sk,int val) {
@@ -588,10 +589,14 @@ static int __init smc_init(void) {int rc; + rc =smc_pnet_init (); +if (rc) +return rc; + rc =proto_register (&smc_proto,1 );if (rc) {pr_err ("%s: proto_register fails with %d\n" , __func__, rc); - goto out; + goto out_pnet; } rc =sock_register (&smc_sock_family_ops);
@@ -604,7 +609,8 @@ static int __init smc_init(void) out_proto:proto_unregister (&smc_proto); -out: +out_pnet: +smc_pnet_exit ();return rc; }
@@ -612,6 +618,7 @@ static void __exit smc_exit(void) {sock_unregister (PF_SMC );proto_unregister (&smc_proto); +smc_pnet_exit (); }module_init (smc_init);
net/smc/smc_pnet.c new file +510 -0
510 lines not on this page · raw message
net/smc/smc_pnet.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* PNET table queries +* +* Copyright IBM Corp. 2016 +* +* Author(s): Thomas Richter <[email protected]> +*/ + +#ifndef _SMC_PNET_H +#define _SMC_PNET_H + +#define SMC_MAX_PORTS 2/* Max # of ports */ + +int smc_pnet_init (void )__init ; +void smc_pnet_exit (void ); + +#endif
Signature · 1 line
2.8.4
PATCH v2 4/15 smc: introduce SMC as an IB-client
In reply to Ursula Braun* create a list of SMC IB-devices (IB-devices mentioned in PNET table)
* determine RoCE device and port belonging to used internal TCP interface according to the PNET table definitions
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 10 ++++ net/smc/smc.h | 5 ++ net/smc/smc_ib.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_ib.h | 40 ++++++++++++++ net/smc/smc_pnet.c | 98 +++++++++++++++++++++++++++++++++ net/smc/smc_pnet.h | 7 +++ 7 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 net/smc/smc_ib.c create mode 100644 net/smc/smc_ib.h
net/smc/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_SMC) += smc.o -smc-y := af_smc.o smc_pnet.o +smc-y := af_smc.o smc_pnet.o smc_ib.o
net/smc/af_smc.c +10 -0
@@ -20,6 +20,7 @@#include <net/sock.h> #include "smc.h" +#include "smc_ib.h" #include "smc_pnet.h" static void smc_set_keepalive (struct sock *sk,int val)
@@ -605,8 +606,16 @@ static int __init smc_init(void) goto out_proto; } + rc =smc_ib_register_client (); +if (rc) { +pr_err ("%s: ib_register fails with %d\n" , __func__, rc); + goto out_sock; + } +return 0 ; +out_sock: +sock_unregister (PF_SMC ); out_proto:proto_unregister (&smc_proto); out_pnet:
@@ -616,6 +625,7 @@ out_pnet: static void __exit smc_exit(void) { +smc_ib_unregister_client ();sock_unregister (PF_SMC );proto_unregister (&smc_proto);smc_pnet_exit ();
net/smc/smc.h +5 -0
@@ -33,4 +33,9 @@ static inline struct smc_sock *smc_sk(const struct sock *sk) {return (struct smc_sock *)sk; } + +#define SMC_SYSTEMID_LEN 8 + +extern u8 local_systemid[SMC_SYSTEMID_LEN ];/* unique system identifier */ +#endif /* _SMC_H */
net/smc/smc_ib.c new file +157 -0
157 lines not on this page · raw message
net/smc/smc_ib.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Definitions for IB environment +* +* Copyright IBM Corp. 2016 +* +* Author(s): Ursula Braun <Ursula [email protected]> +*/ + +#ifndef _SMC_IB_H +#define _SMC_IB_H + +#include <rdma/ib_verbs.h> + +#define SMC_MAX_PORTS 2/* Max # of ports */ +#define SMC_GID_SIZE sizeof(union ib_gid) + +struct smc_ib_devices {/* list of smc ib devices definition */ +struct list_head list; +spinlock_t lock;/* protects list of smc ib devices */ +}; + +extern struct smc_ib_devices smc_ib_devices;/* list of smc ib devices */ + +struct smc_ib_device {/* ib-device infos for smc */ +struct list_head list; +struct ib_device *ibdev; +struct ib_port_attr pattr[SMC_MAX_PORTS ];/* ib dev. port attrs */ +char mac[SMC_MAX_PORTS ][6 ];/* mac address per port*/ +union ib_gid gid[SMC_MAX_PORTS ];/* gid per port */ +u8 initialized :1 ;/* ib dev CQ, evthdl done */ +}; + +int smc_ib_register_client (void )__init ; +void smc_ib_unregister_client (void ); +bool smc_ib_port_active (struct smc_ib_device *,u8 ); +int smc_ib_remember_port_attr (struct smc_ib_device *,u8 ); + +#endif
net/smc/smc_pnet.c +98 -0
123 lines not on this page · raw message
net/smc/smc_pnet.h +7 -0
@@ -13,6 +13,13 @@#define SMC_MAX_PORTS 2/* Max # of ports */ +#include <net/sock.h> + +struct smc_ib_device ; + +bool smc_pnet_exists_in_table (struct smc_ib_device *,u8 ); +void smc_pnet_find_roce_resource (struct sock *,struct smc_ib_device **,u8 *); +int smc_pnet_init (void )__init ;void smc_pnet_exit (void );
Signature · 1 line
2.8.4
PATCH v2 5/15 smc: CLC handshake (incl. preparation steps)
In reply to Ursula Braun* CLC (Connection Layer Control) handshake
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 467 ++++++++++++++++++++++++++++++++++++++++++++++++++---- net/smc/smc.h | 24 ++- net/smc/smc_clc.c | 251 +++++++++++++++++++++++++++++ net/smc/smc_clc.h | 111 +++++++++++++ 5 files changed, 824 insertions(+), 31 deletions(-) create mode 100644 net/smc/smc_clc.c create mode 100644 net/smc/smc_clc.h
net/smc/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_SMC) += smc.o -smc-y := af_smc.o smc_pnet.o smc_ib.o +smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o
net/smc/af_smc.c +438 -29
578 lines not on this page · raw message
net/smc/smc.h +23 -1
@@ -26,7 +26,14 @@ enum smc_state { /* possible states of an SMC socket */struct smc_sock {/* smc sock container */ struct sock sk;struct socket *clcsock;/* internal tcp socket */ -u8 use_fallback :1 ;/* fallback to tcp */ +struct sockaddr *addr;/* inet connect address */ +struct smc_sock *listen_smc;/* listen parent */ +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 */ +u8 use_fallback :1 ,/* fallback to tcp */ + clc_started :1 ;/* smc_connect_rdma ran */ };static inline struct smc_sock *smc_sk (const struct sock *sk)
@@ -38,4 +45,19 @@ static inline struct smc_sock *smc_sk(const struct sock *sk)extern u8 local_systemid[SMC_SYSTEMID_LEN ];/* unique system identifier */ +#ifdef CONFIG_XFRM +static inline bool using_ipsec (struct smc_sock *smc) +{ +return (smc->clcsock->sk->sk_policy[0 ] || + smc->clcsock->sk->sk_policy[1 ]) ?1 :0 ; +} +#else +static inline bool using_ipsec (struct smc_sock *smc) +{ +return 0 ; +} +#endif + +int smc_netinfo_by_tcpsk (struct socket *,__be32 *,u8 *); +#endif /* _SMC_H */
net/smc/smc_clc.c new file +251 -0
251 lines not on this page · raw message
net/smc/smc_clc.h new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v2 6/15 smc: connection and link group creation
In reply to Ursula Braun* create smc_connection for SMC-sockets
* determine suitable link group for a connection
* create a new link group if necessary
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 103 +++++++++++++-- net/smc/smc.h | 35 ++++++ net/smc/smc_clc.c | 31 ++++- net/smc/smc_clc.h | 2 +- net/smc/smc_core.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_core.h | 105 ++++++++++++++++ 7 files changed, 621 insertions(+), 16 deletions(-) create mode 100644 net/smc/smc_core.c create mode 100644 net/smc/smc_core.h
net/smc/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_SMC) += smc.o -smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o +smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o
net/smc/af_smc.c +94 -9
201 lines not on this page · raw message
net/smc/smc.h +35 -0
@@ -14,6 +14,8 @@#include <linux/types.h> #include <net/sock.h> +#include "smc_ib.h" +#define SMCPROTO_SMC 0/* SMC protocol */ enum smc_state {/* possible states of an SMC socket */
@@ -23,9 +25,19 @@ enum smc_state { /* possible states of an SMC socket */ SMC_LISTEN = 10, }; +struct smc_link_group ; + +struct smc_connection { +struct rb_node alert_node; +struct smc_link_group *lgr;/* link group of connection */ +u32 alert_token_local;/* unique conn. id */ +u8 peer_conn_idx;/* from tcp handshake */ +}; +struct smc_sock {/* smc sock container */ struct sock sk;struct socket *clcsock;/* internal tcp socket */ +struct smc_connection conn;/* smc connection */ struct sockaddr *addr;/* inet connect address */ struct smc_sock *listen_smc;/* listen parent */ struct work_struct tcp_listen_work;/* handle tcp socket accepts */
@@ -45,6 +57,24 @@ static inline struct smc_sock *smc_sk(const struct sock *sk)extern u8 local_systemid[SMC_SYSTEMID_LEN ];/* unique system identifier */ +/* 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); +} +#ifdef CONFIG_XFRM static inline bool using_ipsec (struct smc_sock *smc) {
@@ -58,6 +88,11 @@ static inline bool using_ipsec(struct smc_sock *smc) }#endif +struct smc_clc_msg_local ; +int smc_netinfo_by_tcpsk (struct socket *,__be32 *,u8 *); +void smc_conn_free (struct smc_connection *); +int smc_conn_create (struct smc_sock *,__be32 ,struct smc_ib_device *,u8 , +struct smc_clc_msg_local *,int );#endif /* _SMC_H */
net/smc/smc_clc.c +26 -5
@@ -13,6 +13,7 @@#include <net/tcp.h> #include "smc.h" +#include "smc_core.h" #include "smc_clc.h" #include "smc_ib.h"
@@ -174,12 +175,15 @@ int smc_clc_send_proposal(struct smc_sock *smc,/* send CLC CONFIRM message across internal TCP socket */ int smc_clc_send_confirm (struct smc_sock *smc) { +struct smc_connection *conn = &smc->conn;struct smc_clc_msg_accept_confirm cclc; +struct smc_link *link;int reason_code =0 ;struct msghdr msg;struct kvec vec;int len; + link = &conn->lgr->lnk[SMC_SINGLE_LINK ];/* send SMC Confirm CLC msg */ memset (&cclc,0 ,sizeof (cclc));memcpy (cclc.hdr.eyecatcher,SMC_EYECATCHER ,sizeof (SMC_EYECATCHER ));
@@ -187,12 +191,18 @@ int smc_clc_send_confirm(struct smc_sock *smc) cclc.hdr.length =htons (sizeof (cclc)); cclc.hdr.version =SMC_CLC_V1 ;/* SMC version */ memcpy (cclc.lcl.id_for_peer, local_systemid,sizeof (local_systemid)); - -/* tbd in follow-on patch: fill in link-related values */ +memcpy (&cclc.lcl.gid, &link->smcibdev->gid[link->ibport -1 ], +SMC_GID_SIZE ); +memcpy (&cclc.lcl.mac, &link->smcibdev->mac[link->ibport -1 ], +sizeof (link->smcibdev->mac));/* tbd in follow-on patch: fill in rmb-related values */ +hton24 (cclc.qpn, link->roce_qp->qp_num); cclc.conn_idx =1 ;/* for now: 1 RMB = 1 RMBE */ + cclc.rmbe_alert_token =htonl (conn->alert_token_local); + cclc.qp_mtu =min (link->path_mtu, link->peer_mtu); +hton24 (cclc.psn, link->psn_initial);memcpy (cclc.trl.eyecatcher,SMC_EYECATCHER ,sizeof (SMC_EYECATCHER ));
@@ -213,26 +223,37 @@ int smc_clc_send_confirm(struct smc_sock *smc) }/* send CLC ACCEPT message across internal TCP socket */ -int smc_clc_send_accept (struct smc_sock *new_smc) +int smc_clc_send_accept (struct smc_sock *new_smc,int srv_first_contact) { +struct smc_connection *conn = &new_smc->conn;struct smc_clc_msg_accept_confirm aclc; +struct smc_link *link;struct msghdr msg;struct kvec vec;int rc =0 ;int len; + link = &conn->lgr->lnk[SMC_SINGLE_LINK ];memset (&aclc,0 ,sizeof (aclc));memcpy (aclc.hdr.eyecatcher,SMC_EYECATCHER ,sizeof (SMC_EYECATCHER )); aclc.hdr.type =SMC_CLC_ACCEPT ; aclc.hdr.length =htons (sizeof (aclc)); aclc.hdr.version =SMC_CLC_V1 ;/* SMC version */ +if (srv_first_contact) + aclc.hdr.flag =1 ;memcpy (aclc.lcl.id_for_peer, local_systemid,sizeof (local_systemid)); - -/* tbd in follow-on patch: fill in link-related values */ +memcpy (&aclc.lcl.gid, &link->smcibdev->gid[link->ibport -1 ], +SMC_GID_SIZE ); +memcpy (&aclc.lcl.mac, link->smcibdev->mac[link->ibport -1 ], +sizeof (link->smcibdev->mac[link->ibport -1 ]));/* tbd in follow-on patch: fill in rmb-related values */ +hton24 (aclc.qpn, link->roce_qp->qp_num); aclc.conn_idx =1 ;/* as long as 1 RMB = 1 RMBE */ + aclc.rmbe_alert_token =htonl (conn->alert_token_local); + aclc.qp_mtu = link->path_mtu; +hton24 (aclc.psn, link->psn_initial);memcpy (aclc.trl.eyecatcher,SMC_EYECATCHER ,sizeof (SMC_EYECATCHER ));memset (&msg,0 ,sizeof (msg));
net/smc/smc_clc.h +1 -1
@@ -106,6 +106,6 @@ int smc_clc_wait_msg(struct smc_sock *, void *, int, u8);int smc_clc_send_decline (struct smc_sock *,u32 ,u8 );int smc_clc_send_proposal (struct smc_sock *,struct smc_ib_device *,u8 );int smc_clc_send_confirm (struct smc_sock *); -int smc_clc_send_accept (struct smc_sock *); +int smc_clc_send_accept (struct smc_sock *,int );#endif
net/smc/smc_core.c new file +359 -0
359 lines not on this page · raw message
net/smc/smc_core.h new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v2 7/15 smc: remote memory buffers (RMBs)
In reply to Ursula Braun* allocate data RMB memory for sending and receiving
* size depends on the maximum socket send and receive buffers
* allocated RMBs are kept during life time of the owning link group
* map the allocated RMBs to DMA
--- net/smc/af_smc.c | 29 ++++++- net/smc/smc.h | 45 +++++++++++ net/smc/smc_clc.c | 6 +- net/smc/smc_core.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++- net/smc/smc_core.h | 20 +++++ net/smc/smc_ib.c | 19 +++++ net/smc/smc_ib.h | 5 ++ 7 files changed, 340 insertions(+), 7 deletions(-)
net/smc/af_smc.c +26 -3
@@ -256,6 +256,8 @@ static void smc_conn_save_peer_info(struct smc_sock *smc, struct smc_clc_msg_accept_confirm *clc) { smc->conn.peer_conn_idx = clc->conn_idx; + smc->conn.peer_rmbe_len =smc_uncompress_bufsize (clc->rmbe_size); +atomic_set (&smc->conn.peer_rmbe_space, smc->conn.peer_rmbe_len); } static void smc_link_save_peer_info(struct smc_link *link,
@@ -334,6 +336,18 @@ static int smc_connect_rdma(struct smc_sock *smc) link = &smc->conn.lgr->lnk[SMC_SINGLE_LINK ];smc_conn_save_peer_info (smc, &aclc); + + rc =smc_sndbuf_create (smc); +if (rc) { + reason_code =SMC_CLC_DECL_MEM ; + goto decline_rdma_unlock; + } + rc =smc_rmb_create (smc); +if (rc) { + reason_code =SMC_CLC_DECL_MEM ; + goto decline_rdma_unlock; + } +if (local_contact ==SMC_FIRST_CONTACT )smc_link_save_peer_info (link, &aclc);/* tbd in follow-on patch: more steps to setup RDMA communcication,
@@ -609,9 +623,16 @@ static void smc_listen_work(struct work_struct *work) } link = &new_smc->conn.lgr->lnk[SMC_SINGLE_LINK ]; -/* tbd in follow-on patch: more steps to setup RDMA communcication, -* create rmbs, map rmbs -*/ + rc =smc_sndbuf_create (new_smc); +if (rc) { + reason_code =SMC_CLC_DECL_MEM ; + goto decline_rdma; + } + rc =smc_rmb_create (new_smc); +if (rc) { + reason_code =SMC_CLC_DECL_MEM ; + goto decline_rdma; + } rc =smc_clc_send_accept (new_smc, local_contact);if (rc)
@@ -1058,6 +1079,8 @@ static int smc_create(struct net *net, struct socket *sock, int protocol, IPPROTO_TCP, &smc->clcsock);if (rc)sk_common_release (sk); + smc->sk.sk_sndbuf =max (smc->clcsock->sk->sk_sndbuf,SMC_BUF_MIN_SIZE ); + smc->sk.sk_rcvbuf =max (smc->clcsock->sk->sk_rcvbuf,SMC_BUF_MIN_SIZE ); out:return rc;
net/smc/smc.h +45 -0
57 lines not on this page · raw message
net/smc/smc_clc.c +3 -3
@@ -246,13 +246,13 @@ int smc_clc_send_accept(struct smc_sock *new_smc, int srv_first_contact) SMC_GID_SIZE);memcpy (&aclc.lcl.mac, link->smcibdev->mac[link->ibport -1 ],sizeof (link->smcibdev->mac[link->ibport -1 ])); - -/* tbd in follow-on patch: fill in rmb-related values */ -hton24 (aclc.qpn, link->roce_qp->qp_num); aclc.conn_idx =1 ;/* as long as 1 RMB = 1 RMBE */ aclc.rmbe_alert_token =htonl (conn->alert_token_local); aclc.qp_mtu = link->path_mtu; + aclc.rmbe_size = conn->rmbe_size_short, + aclc.rmb_dma_addr = +cpu_to_be64 ((u64 )conn->rmb_desc->dma_addr[SMC_SINGLE_LINK ]);hton24 (aclc.psn, link->psn_initial);memcpy (aclc.trl.eyecatcher,SMC_EYECATCHER ,sizeof (SMC_EYECATCHER ));
net/smc/smc_core.c +222 -1
265 lines not on this page · raw message
net/smc/smc_core.h +20 -0
@@ -16,6 +16,8 @@#include "smc.h" #include "smc_ib.h" +#define SMC_RMBS_PER_LGR_MAX 255/* max. # of RMBs per link group */ +struct smc_lgr_list {/* list of link group definition */ struct list_head list;spinlock_t lock;/* protects list of link groups */
@@ -52,6 +54,15 @@ struct smc_link {#define SMC_FIRST_CONTACT 1/* first contact to a peer */ #define SMC_REUSE_CONTACT 0/* follow-on contact to a peer*/ +/* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */ +struct smc_buf_desc { +struct list_head list; +u64 dma_addr[SMC_LINKS_PER_LGR_MAX ]; +/* mapped address of buffer */ +void *cpu_addr;/* virtual address of buffer */ +u32 used;/* currently used / unused */ +}; +struct smc_link_group {struct list_head list;enum smc_lgr_role role;/* client or server */
@@ -63,6 +74,11 @@ struct smc_link_group {rwlock_t conns_lock;/* protects conns_all */ unsigned int conns_num;/* current # of connections */ unsigned short vlan_id;/* vlan id of link group */ + +struct list_head sndbufs[SMC_RMBE_SIZES ];/* tx buffers */ +rwlock_t sndbufs_lock;/* protects tx buffers */ +struct list_head rmbs[SMC_RMBE_SIZES ];/* rx buffers */ +rwlock_t rmbs_lock;/* protects rx buffers */ struct delayed_work free_work;/* delayed freeing of an lgr */ };
@@ -99,7 +115,11 @@ static inline struct smc_connection *smc_lgr_find_conn( return res; } +struct smc_clc_msg_accept_confirm ; +void smc_lgr_free (struct smc_link_group *);void smc_lgr_terminate (struct smc_link_group *); +int smc_sndbuf_create (struct smc_sock *); +int smc_rmb_create (struct smc_sock *);#endif
net/smc/smc_ib.c +19 -0
@@ -16,6 +16,7 @@#include "smc_pnet.h" #include "smc_ib.h" +#include "smc_core.h" #include "smc.h" struct smc_ib_devices smc_ib_devices = {/* smc-registered ib devices */
@@ -29,6 +30,24 @@ u8 local_systemid[SMC_SYSTEMID_LEN] = SMC_LOCAL_SYSTEMID_RESET; /* unique system* identifier */ +/* map a new TX or RX buffer to DMA */ +int smc_ib_buf_map (struct smc_ib_device *smcibdev,int buf_size, +struct smc_buf_desc *buf_slot, +enum dma_data_direction data_direction) +{ +int rc =0 ; + +if (buf_slot->dma_addr[SMC_SINGLE_LINK ]) +return rc;/* already mapped */ + buf_slot->dma_addr[SMC_SINGLE_LINK ] = +ib_dma_map_single (smcibdev->ibdev, buf_slot->cpu_addr, + buf_size, data_direction); +if (ib_dma_mapping_error (smcibdev->ibdev, + buf_slot->dma_addr[SMC_SINGLE_LINK ])) + rc = -EIO ; +return rc; +} +static int smc_ib_fill_gid_and_mac (struct smc_ib_device *smcibdev,u8 ibport) {struct net_device *ndev;
net/smc/smc_ib.h +5 -0
@@ -32,9 +32,14 @@ struct smc_ib_device { /* ib-device infos for smc */ u8 initialized : 1; /* ib dev CQ, evthdl done */ }; +struct smc_sock ; +struct smc_buf_desc ; +int smc_ib_register_client (void )__init ;void smc_ib_unregister_client (void );bool smc_ib_port_active (struct smc_ib_device *,u8 );int smc_ib_remember_port_attr (struct smc_ib_device *,u8 ); +int smc_ib_buf_map (struct smc_ib_device *,int ,struct smc_buf_desc *, +enum dma_data_direction );#endif
Signature · 1 line
2.8.4
PATCH v2 8/15 smc: work request (WR) base for use by LLC and CDC
In reply to Ursula BraunThe base containers for RDMA transport are work requests and completion queue entries processed through Infiniband verbs:
* allocate and initialize these areas
* map these areas to DMA
* implement the basic communication consisting of work request posting and receival of completion queue events
--- net/smc/Makefile | 2 +- net/smc/smc.h | 4 + net/smc/smc_core.c | 11 ++ net/smc/smc_core.h | 30 +++ net/smc/smc_ib.c | 73 +++++++ net/smc/smc_ib.h | 11 ++ net/smc/smc_wr.c | 562 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_wr.h | 93 +++++++++ 8 files changed, 785 insertions(+), 1 deletion(-) create mode 100644 net/smc/smc_wr.c create mode 100644 net/smc/smc_wr.h
net/smc/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_SMC) += smc.o -smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o +smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o
net/smc/smc.h +4 -0
@@ -27,6 +27,10 @@ enum smc_state { /* possible states of an SMC socket */struct smc_link_group ; +struct smc_wr_rx_hdr {/* common prefix part of LLC and CDC to demultiplex */ +u8 type; +} __packed; +struct smc_connection {struct rb_node alert_node;struct smc_link_group *lgr;/* link group of connection */
net/smc/smc_core.c +11 -0
@@ -20,6 +20,7 @@#include "smc_clc.h" #include "smc_core.h" #include "smc_ib.h" +#include "smc_wr.h" #define SMC_LGR_FREE_DELAY (600 * HZ)
@@ -159,12 +160,20 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr, lnk->path_mtu = smcibdev->pattr[ibport -1 ].active_mtu;get_random_bytes (rndvec,sizeof (rndvec)); lnk->psn_initial = rndvec[0 ] + (rndvec[1 ] <<8 ) + (rndvec[2 ] <<16 ); + rc =smc_wr_alloc_link_mem (lnk); +if (rc) + goto free_lgr; +init_waitqueue_head (&lnk->wr_tx_wait); smc->conn.lgr = lgr;rwlock_init (&lgr->conns_lock);spin_lock_bh (&smc_lgr_list.lock);list_add_tail (&lgr->list, &smc_lgr_list.list);spin_unlock_bh (&smc_lgr_list.lock); +return 0 ; + +free_lgr: +kfree (lgr); out:return rc; }
@@ -200,6 +209,8 @@ void smc_conn_free(struct smc_connection *conn)static void smc_link_clear (struct smc_link *lnk) { lnk->peer_qpn =0 ; +smc_wr_free_link (lnk); +smc_wr_free_link_mem (lnk); }static void smc_lgr_free_sndbufs (struct smc_link_group *lgr)
net/smc/smc_core.h +30 -0
@@ -11,6 +11,7 @@#ifndef _SMC_CORE_H#define _SMC_CORE_H +#include <linux/atomic.h> #include <rdma/ib_verbs.h> #include "smc.h"
@@ -30,11 +31,40 @@ enum smc_lgr_role { /* possible roles of a link group */SMC_SERV /* server */ }; +#define SMC_WR_BUF_SIZE 48/* size of work request buffer */ + +struct smc_wr_buf { +u8 raw[SMC_WR_BUF_SIZE ]; +} __packed; +struct smc_link {struct smc_ib_device *smcibdev;/* ib-device */ u8 ibport;/* port - values 1 | 2 */ +struct ib_pd *roce_pd;/* IB protection domain, +* unique for every RoCE QP +*/ struct ib_qp *roce_qp;/* IB queue pair */ struct ib_qp_attr qp_attr;/* IB queue pair attributes */ + +struct smc_wr_buf *wr_tx_bufs;/* WR send payload buffers */ +struct ib_send_wr *wr_tx_ibs;/* WR send meta data */ +struct ib_sge *wr_tx_sges;/* WR send gather meta data */ +struct smc_wr_tx_pend *wr_tx_pends;/* WR send waiting for CQE */ +/* above four vectors have wr_tx_cnt elements and use the same index */ +dma_addr_t wr_tx_dma_addr;/* DMA address of wr_tx_bufs */ +atomic_long_t wr_tx_id;/* seq # of last sent WR */ +unsigned long *wr_tx_mask;/* bit mask of used indexes */ +u32 wr_tx_cnt;/* number of WR send buffers */ +wait_queue_head_t wr_tx_wait;/* wait for free WR send buf */ + +struct smc_wr_buf *wr_rx_bufs;/* WR recv payload buffers */ +struct ib_recv_wr *wr_rx_ibs;/* WR recv meta data */ +struct ib_sge *wr_rx_sges;/* WR recv scatter meta data */ +/* above three vectors have wr_rx_cnt elements and use the same index */ +dma_addr_t wr_rx_dma_addr;/* DMA address of wr_rx_bufs */ +u64 wr_rx_id;/* seq # of last recv WR */ +u32 wr_rx_cnt;/* number of WR recv buffers */ +union ib_gid gid;/* gid matching used vlan id */ u32 peer_qpn;/* QP number of peer */ enum ib_mtu path_mtu;/* used mtu */
net/smc/smc_ib.c +73 -0
85 lines not on this page · raw message
net/smc/smc_ib.h +11 -0
@@ -16,6 +16,8 @@#define SMC_MAX_PORTS 2/* Max # of ports */ #define SMC_GID_SIZE sizeof(union ib_gid) +#define SMC_IB_MAX_SEND_SGE 2 +struct smc_ib_devices {/* list of smc ib devices definition */ struct list_head list;spinlock_t lock;/* protects list of smc ib devices */
@@ -27,6 +29,10 @@ struct smc_ib_device { /* ib-device infos for smc */struct list_head list;struct ib_device *ibdev;struct ib_port_attr pattr[SMC_MAX_PORTS ];/* ib dev. port attrs */ +struct ib_cq *roce_cq_send;/* send completion queue */ +struct ib_cq *roce_cq_recv;/* recv completion queue */ +struct tasklet_struct send_tasklet;/* called by send cq handler */ +struct tasklet_struct recv_tasklet;/* called by recv cq handler */ char mac[SMC_MAX_PORTS ][6 ];/* mac address per port*/ union ib_gid gid[SMC_MAX_PORTS ];/* gid per port */ u8 initialized : 1; /* ib dev CQ, evthdl done */
@@ -34,6 +40,7 @@ struct smc_ib_device { /* ib-device infos for smc */struct smc_sock ;struct smc_buf_desc ; +struct smc_link ;int smc_ib_register_client (void )__init ;void smc_ib_unregister_client (void );
@@ -41,5 +48,9 @@ bool smc_ib_port_active(struct smc_ib_device *, u8);int smc_ib_remember_port_attr (struct smc_ib_device *,u8 );int smc_ib_buf_map (struct smc_ib_device *,int ,struct smc_buf_desc *,enum dma_data_direction ); +void smc_ib_dealloc_protection_domain (struct smc_link *); +int smc_ib_create_protection_domain (struct smc_link *); +void smc_ib_destroy_queue_pair (struct smc_link *); +int smc_ib_create_queue_pair (struct smc_link *);#endif
net/smc/smc_wr.c new file +562 -0
562 lines not on this page · raw message
net/smc/smc_wr.h new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v2 9/15 smc: initialize IB transport incl. PD, MR, QP, CQ, event, WR
In reply to Ursula BraunPrepare the link for RDMA transport:
Create a queue pair (QP) and move it into the state Ready-To-Receive (RTR).
--- net/smc/af_smc.c | 34 ++++++-- net/smc/smc.h | 1 + net/smc/smc_clc.c | 10 ++- net/smc/smc_core.c | 80 ++++++++++++++++++ net/smc/smc_core.h | 19 +++++ net/smc/smc_ib.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_ib.h | 11 +++ net/smc/smc_pnet.c | 3 + net/smc/smc_wr.c | 2 + 9 files changed, 387 insertions(+), 9 deletions(-)
net/smc/af_smc.c +28 -6
@@ -350,9 +350,20 @@ static int smc_connect_rdma(struct smc_sock *smc)if (local_contact ==SMC_FIRST_CONTACT )smc_link_save_peer_info (link, &aclc); -/* tbd in follow-on patch: more steps to setup RDMA communcication, -* create rmbs, map rmbs, rtoken_handling, modify_qp -*/ + + rc =smc_rmb_rtoken_handling (&smc->conn, &aclc); +if (rc) { + reason_code =SMC_CLC_DECL_INTERR ; + goto decline_rdma_unlock; + } + +if (local_contact ==SMC_FIRST_CONTACT ) { + rc =smc_ib_ready_link (link); +if (rc) { + reason_code =SMC_CLC_DECL_INTERR ; + goto decline_rdma_unlock; + } + } rc =smc_clc_send_confirm (smc);if (rc)
@@ -649,9 +660,20 @@ static void smc_listen_work(struct work_struct *work)if (local_contact ==SMC_FIRST_CONTACT )smc_link_save_peer_info (link, &cclc); -/* tbd in follow-on patch: more steps to setup RDMA communcication, -* rtoken_handling, modify_qp -*/ + rc =smc_rmb_rtoken_handling (&new_smc->conn, &cclc); +if (rc) { + reason_code =SMC_CLC_DECL_INTERR ; + goto decline_rdma; + } + +/* tbd in follow-on patch: modify_qp, llc_confirm */ +if (local_contact ==SMC_FIRST_CONTACT ) { + rc =smc_ib_ready_link (link); +if (rc) { + reason_code =SMC_CLC_DECL_INTERR ; + goto decline_rdma; + } + } out_connected:sk_refcnt_debug_inc (newsmcsk);
net/smc/smc.h +1 -0
@@ -40,6 +40,7 @@ struct smc_connection {atomic_t peer_rmbe_space;/* remaining free bytes in peer * rmbe */ +int rtoken_idx;/* idx to peer RMB rkey/addr */ struct smc_buf_desc *sndbuf_desc;/* send buffer descriptor */ int sndbuf_size;/* sndbuf size <== sock wmem */
net/smc/smc_clc.c +7 -3
@@ -195,13 +195,15 @@ int smc_clc_send_confirm(struct smc_sock *smc) SMC_GID_SIZE);memcpy (&cclc.lcl.mac, &link->smcibdev->mac[link->ibport -1 ],sizeof (link->smcibdev->mac)); - -/* tbd in follow-on patch: fill in rmb-related values */ -hton24 (cclc.qpn, link->roce_qp->qp_num); + cclc.rmb_rkey = +htonl (conn->rmb_desc->mr_rx[SMC_SINGLE_LINK ]->rkey); cclc.conn_idx =1 ;/* for now: 1 RMB = 1 RMBE */ cclc.rmbe_alert_token =htonl (conn->alert_token_local); cclc.qp_mtu =min (link->path_mtu, link->peer_mtu); + cclc.rmbe_size = conn->rmbe_size_short; + cclc.rmb_dma_addr = +cpu_to_be64 ((u64 )conn->rmb_desc->dma_addr[SMC_SINGLE_LINK ]);hton24 (cclc.psn, link->psn_initial);memcpy (cclc.trl.eyecatcher,SMC_EYECATCHER ,sizeof (SMC_EYECATCHER ));
@@ -247,6 +249,8 @@ int smc_clc_send_accept(struct smc_sock *new_smc, int srv_first_contact)memcpy (&aclc.lcl.mac, link->smcibdev->mac[link->ibport -1 ],sizeof (link->smcibdev->mac[link->ibport -1 ]));hton24 (aclc.qpn, link->roce_qp->qp_num); + aclc.rmb_rkey = +htonl (conn->rmb_desc->mr_rx[SMC_SINGLE_LINK ]->rkey); aclc.conn_idx =1 ;/* as long as 1 RMB = 1 RMBE */ aclc.rmbe_alert_token =htonl (conn->alert_token_local); aclc.qp_mtu = link->path_mtu;
net/smc/smc_core.c +80 -0
120 lines not on this page · raw message
net/smc/smc_core.h +19 -0
@@ -46,6 +46,8 @@ struct smc_link {struct ib_qp *roce_qp;/* IB queue pair */ struct ib_qp_attr qp_attr;/* IB queue pair attributes */ +struct ib_mr *mr_tx;/* send IB DMA memory region */ +struct smc_wr_buf *wr_tx_bufs;/* WR send payload buffers */ struct ib_send_wr *wr_tx_ibs;/* WR send meta data */ struct ib_sge *wr_tx_sges;/* WR send gather meta data */
@@ -90,9 +92,17 @@ struct smc_buf_desc {u64 dma_addr[SMC_LINKS_PER_LGR_MAX ];/* mapped address of buffer */ void *cpu_addr;/* virtual address of buffer */ +struct ib_mr *mr_rx[SMC_LINKS_PER_LGR_MAX ];/* for rmb only: +* rkey provided to peer +*/ u32 used;/* currently used / unused */ }; +struct smc_rtoken {/* address/key of remote RMB */ +u64 dma_addr; +u32 rkey; +}; +struct smc_link_group {struct list_head list;enum smc_lgr_role role;/* client or server */
@@ -109,6 +119,13 @@ struct smc_link_group {rwlock_t sndbufs_lock;/* protects tx buffers */ struct list_head rmbs[SMC_RMBE_SIZES ];/* rx buffers */ rwlock_t rmbs_lock;/* protects rx buffers */ +struct smc_rtoken rtokens[SMC_RMBS_PER_LGR_MAX ] + [SMC_LINKS_PER_LGR_MAX ]; +/* remote addr/key pairs */ +unsigned long rtokens_used_mask[BITS_TO_LONGS ( +SMC_RMBS_PER_LGR_MAX )]; +/* used rtoken elements */ +struct delayed_work free_work;/* delayed freeing of an lgr */ };
@@ -151,5 +168,7 @@ void smc_lgr_free(struct smc_link_group *);void smc_lgr_terminate (struct smc_link_group *);int smc_sndbuf_create (struct smc_sock *);int smc_rmb_create (struct smc_sock *); +int smc_rmb_rtoken_handling (struct smc_connection *, +struct smc_clc_msg_accept_confirm *);#endif
net/smc/smc_ib.c +236 -0
284 lines not on this page · raw message
net/smc/smc_ib.h +11 -0
@@ -29,6 +29,7 @@ struct smc_ib_device { /* ib-device infos for smc */struct list_head list;struct ib_device *ibdev;struct ib_port_attr pattr[SMC_MAX_PORTS ];/* ib dev. port attrs */ +struct ib_event_handler event_handler;/* global ib_event handler */ struct ib_cq *roce_cq_send;/* send completion queue */ struct ib_cq *roce_cq_recv;/* recv completion queue */ struct tasklet_struct send_tasklet;/* called by send cq handler */
@@ -36,6 +37,8 @@ struct smc_ib_device { /* ib-device infos for smc */char mac[SMC_MAX_PORTS ][6 ];/* mac address per port*/ union ib_gid gid[SMC_MAX_PORTS ];/* gid per port */ u8 initialized : 1; /* ib dev CQ, evthdl done */ +struct work_struct port_event_work; +unsigned long port_event_mask; };struct smc_sock ;
@@ -48,9 +51,17 @@ bool smc_ib_port_active(struct smc_ib_device *, u8);int smc_ib_remember_port_attr (struct smc_ib_device *,u8 );int smc_ib_buf_map (struct smc_ib_device *,int ,struct smc_buf_desc *,enum dma_data_direction ); +void smc_ib_buf_unmap (struct smc_ib_device *,int ,struct smc_buf_desc *, +enum dma_data_direction );void smc_ib_dealloc_protection_domain (struct smc_link *);int smc_ib_create_protection_domain (struct smc_link *);void smc_ib_destroy_queue_pair (struct smc_link *);int smc_ib_create_queue_pair (struct smc_link *); +void smc_ib_dereg_memory_region (struct ib_mr *); +int smc_ib_get_memory_region (struct ib_pd *,int ,struct ib_mr **); +int smc_ib_ready_link (struct smc_link *); +int smc_ib_modify_qp_rts (struct smc_link *); +int smc_ib_modify_qp_reset (struct smc_link *); +long smc_ib_setup_per_ibdev (struct smc_ib_device *);#endif
net/smc/smc_pnet.c +3 -0
@@ -223,6 +223,9 @@ out: pnetelem->ib_port);if (rc)return rc; + rc =smc_ib_setup_per_ibdev (smcibdev); +if (rc) +return rc; smcibdev->initialized =1 ; }return rc;
net/smc/smc_wr.c +2 -0
@@ -391,6 +391,7 @@ static void smc_wr_init_sge(struct smc_link *lnk) lnk->wr_tx_sges[i].addr = lnk->wr_tx_dma_addr + i *SMC_WR_BUF_SIZE ; lnk->wr_tx_sges[i].length =SMC_WR_TX_SIZE ; + lnk->wr_tx_sges[i].lkey = lnk->mr_tx->lkey; lnk->wr_tx_ibs[i].next =NULL ; lnk->wr_tx_ibs[i].sg_list = &lnk->wr_tx_sges[i]; lnk->wr_tx_ibs[i].num_sge =1 ;
@@ -402,6 +403,7 @@ static void smc_wr_init_sge(struct smc_link *lnk) lnk->wr_rx_sges[i].addr = lnk->wr_rx_dma_addr + i *SMC_WR_BUF_SIZE ; lnk->wr_rx_sges[i].length =SMC_WR_BUF_SIZE ; + lnk->wr_rx_sges[i].lkey = lnk->mr_tx->lkey; lnk->wr_rx_ibs[i].next =NULL ; lnk->wr_rx_ibs[i].sg_list = &lnk->wr_rx_sges[i]; lnk->wr_rx_ibs[i].num_sge =1 ;
Signature · 1 line
2.8.4
PATCH v2 10/15 smc: link layer control (LLC)
In reply to Ursula Braunsend and receive LLC messages CONFIRM_LINK (via IB message send and CQE)
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 94 ++++++++++++++++++++++++++++++- net/smc/smc_clc.h | 2 + net/smc/smc_core.c | 8 +++ net/smc/smc_core.h | 4 ++ net/smc/smc_llc.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_llc.h | 63 +++++++++++++++++++++ 7 files changed, 328 insertions(+), 3 deletions(-) create mode 100644 net/smc/smc_llc.c create mode 100644 net/smc/smc_llc.h
net/smc/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_SMC) += smc.o -smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o +smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o
net/smc/af_smc.c +92 -2
136 lines not on this page · raw message
net/smc/smc_clc.h +2 -0
@@ -33,6 +33,8 @@ static const char SMC_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xd9'};#define SMC_CLC_DECL_SYNCERR 0x04000000/* synchronization error */ #define SMC_CLC_DECL_REPLY 0x06000000/* reply to a received decline */ #define SMC_CLC_DECL_INTERR 0x99990000/* internal error */ +#define SMC_CLC_DECL_TCL 0x02040000/* timeout w4 QP confirm */ +#define SMC_CLC_DECL_SEND 0x07000000/* sending problem */ struct smc_clc_msg_hdr {/* header1 of clc messages */ u8 eyecatcher[4 ];/* eye catcher */
net/smc/smc_core.c +8 -0
@@ -21,9 +21,13 @@#include "smc_core.h" #include "smc_ib.h" #include "smc_wr.h" +#include "smc_llc.h" +#define SMC_LGR_NUM_INCR 256#define SMC_LGR_FREE_DELAY (600 * HZ) +static u32 smc_lgr_num;/* unique link group number */ +/* Register connection's alert token in our lookup structure. * To use rbtrees we have to implement our own insert core. * Requires @conns_lock
@@ -150,6 +154,8 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr,INIT_LIST_HEAD (&lgr->sndbufs[i]);INIT_LIST_HEAD (&lgr->rmbs[i]); } + smc_lgr_num +=SMC_LGR_NUM_INCR ; + lgr->id = smc_lgr_num;INIT_DELAYED_WORK (&lgr->free_work, smc_lgr_free_work); lgr->conns_all =RB_ROOT ;
@@ -177,6 +183,8 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr, rc =smc_wr_create_link (lnk);if (rc) goto destroy_qp; +init_completion (&lnk->llc_confirm); +init_completion (&lnk->llc_confirm_resp); smc->conn.lgr = lgr;rwlock_init (&lgr->conns_lock);
net/smc/smc_core.h +4 -0
@@ -75,6 +75,9 @@ struct smc_link {u32 peer_psn;/* QP rx initial packet seqno */ u8 peer_mac[ETH_ALEN ];/* = gid[8:10||13:15] */ u8 peer_gid[sizeof (union ib_gid )];/* gid of peer*/ +u8 link_id;/* unique # within link group */ +struct completion llc_confirm;/* wait for rx of conf link */ +struct completion llc_confirm_resp;/* wait 4 rx of cnf lnk rsp */ };/* For now we just allow one parallel link per link group. The SMC protocol
@@ -126,6 +129,7 @@ struct smc_link_group { SMC_RMBS_PER_LGR_MAX)];/* used rtoken elements */ +u32 id;/* unique lgr id */ struct delayed_work free_work;/* delayed freeing of an lgr */ };
net/smc/smc_llc.c new file +158 -0
158 lines not on this page · raw message
net/smc/smc_llc.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v2 11/15 smc: connection data control (CDC)
In reply to Ursula Braunsend and receive CDC messages (via IB message send and CQE)
--- net/smc/Makefile | 1 + net/smc/af_smc.c | 8 ++ net/smc/smc.h | 97 ++++++++++++++++++ net/smc/smc_cdc.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_cdc.h | 216 ++++++++++++++++++++++++++++++++++++++++ net/smc/smc_core.c | 9 ++ net/smc/smc_wr.c | 19 ++++ net/smc/smc_wr.h | 8 ++ 8 files changed, 646 insertions(+) create mode 100644 net/smc/smc_cdc.c create mode 100644 net/smc/smc_cdc.h
net/smc/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_SMC) += smc.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o +smc-y += smc_cdc.o
net/smc/af_smc.c +8 -0
@@ -32,6 +32,7 @@#include "smc.h" #include "smc_clc.h" #include "smc_llc.h" +#include "smc_cdc.h" #include "smc_core.h" #include "smc_ib.h" #include "smc_pnet.h"
@@ -292,6 +293,7 @@ static void smc_conn_save_peer_info(struct smc_sock *smc, struct smc_clc_msg_accept_confirm *clc) { smc->conn.peer_conn_idx = clc->conn_idx; + smc->conn.local_tx_ctrl.token =ntohl (clc->rmbe_alert_token); smc->conn.peer_rmbe_len =smc_uncompress_bufsize (clc->rmbe_size);atomic_set (&smc->conn.peer_rmbe_space, smc->conn.peer_rmbe_len); }
@@ -1212,6 +1214,12 @@ static int __init smc_init(void) goto out_pnet; } + rc =smc_cdc_init (); +if (rc) { +pr_err ("%s: smc_cdc_init fails with %d\n" , __func__, rc); + goto out_pnet; + } + rc =proto_register (&smc_proto,1 );if (rc) {pr_err ("%s: proto_register fails with %d\n" , __func__, rc);
net/smc/smc.h +97 -0
115 lines not on this page · raw message
net/smc/smc_cdc.c new file +288 -0
288 lines not on this page · raw message
net/smc/smc_cdc.h new file +216 -0
216 lines not on this page · raw message
net/smc/smc_core.c +9 -0
@@ -22,6 +22,7 @@#include "smc_ib.h" #include "smc_wr.h" #include "smc_llc.h" +#include "smc_cdc.h" #define SMC_LGR_NUM_INCR 256#define SMC_LGR_FREE_DELAY (600 * HZ)
@@ -230,6 +231,7 @@ void smc_conn_free(struct smc_connection *conn)if (!lgr)return ; +smc_cdc_tx_dismiss_slots (conn);smc_lgr_unregister_conn (conn);smc_rmb_unuse (conn);smc_sndbuf_unuse (conn);
@@ -461,6 +463,11 @@ int smc_conn_create(struct smc_sock *smc, __be32 peer_in_addr,smc_lgr_register_conn (conn);/* add smc conn to lgr */ rc =smc_link_determine_gid (conn->lgr); } + conn->local_tx_ctrl.common.type =SMC_CDC_MSG_TYPE ; + conn->local_tx_ctrl.len =sizeof (struct smc_cdc_msg ); +#ifndef KERNEL_HAS_ATOMIC64 +spin_lock_init (&conn->acurs_lock); +#endif out:return rc ? rc : local_contact;
@@ -561,6 +568,7 @@ int smc_sndbuf_create(struct smc_sock *smc) conn->sndbuf_desc = sndbuf_desc; conn->sndbuf_size = tmp_bufsize; smc->sk.sk_sndbuf = tmp_bufsize *2 ; +atomic_set (&conn->sndbuf_space, tmp_bufsize);return 0 ; }else {return -ENOMEM ;
@@ -637,6 +645,7 @@ int smc_rmb_create(struct smc_sock *smc) conn->rmbe_size = tmp_bufsize; conn->rmbe_size_short = tmp_bufsize_short; smc->sk.sk_rcvbuf = tmp_bufsize *2 ; +atomic_set (&conn->bytes_to_rcv,0 );return 0 ; }else {return -ENOMEM ;
net/smc/smc_wr.c +19 -0
@@ -235,6 +235,25 @@ int smc_wr_tx_send(struct smc_link *link, struct smc_wr_tx_pend_priv *priv)return rc; } +void smc_wr_tx_dismiss_slots (struct smc_link *link,u8 wr_rx_hdr_type, +smc_wr_tx_filter filter, +smc_wr_tx_dismisser dismisser, +unsigned long data) +{ +struct smc_wr_tx_pend_priv *tx_pend; +struct smc_wr_rx_hdr *wr_rx; +int i; + +for_each_set_bit (i, link->wr_tx_mask, link->wr_tx_cnt) { + wr_rx = (struct smc_wr_rx_hdr *)&link->wr_rx_bufs[i]; +if (wr_rx->type != wr_rx_hdr_type) +continue ; + tx_pend = &link->wr_tx_pends[i].priv; +if (filter (tx_pend, data)) +dismisser (tx_pend); + } +} +/****************************** receive queue ********************************/ int smc_wr_rx_register_handler (struct smc_wr_rx_handler *handler)
net/smc/smc_wr.h +8 -0
@@ -36,6 +36,11 @@ typedef void (*smc_wr_tx_handler)(struct smc_wr_tx_pend_priv *, struct smc_link *, enum ib_wc_status); +typedef bool (*smc_wr_tx_filter )(struct smc_wr_tx_pend_priv *, +unsigned long ); + +typedef void (*smc_wr_tx_dismisser )(struct smc_wr_tx_pend_priv *); +struct smc_wr_rx_handler {struct hlist_node list;/* hash table collision resolution */ void (*handler)(struct ib_wc *,void *);
@@ -85,6 +90,9 @@ int smc_wr_tx_get_free_slot(struct smc_link *, smc_wr_tx_handler,int smc_wr_tx_put_slot (struct smc_link *,struct smc_wr_tx_pend_priv *);int smc_wr_tx_send (struct smc_link *,struct smc_wr_tx_pend_priv *);void smc_wr_tx_cq_handler (struct ib_cq *,void *); +void smc_wr_tx_dismiss_slots (struct smc_link *,u8 , +smc_wr_tx_filter ,smc_wr_tx_dismisser , +unsigned long );int smc_wr_rx_register_handler (struct smc_wr_rx_handler *);int smc_wr_rx_post_init (struct smc_link *);
Signature · 1 line
2.8.4
PATCH v2 12/15 smc: send data (through RDMA)
In reply to Ursula Brauncopy data to kernel send buffer, and trigger RDMA write
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 13 +- net/smc/smc.h | 1 + net/smc/smc_cdc.c | 7 +- net/smc/smc_tx.c | 437 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_tx.h | 34 +++++ 6 files changed, 490 insertions(+), 4 deletions(-) create mode 100644 net/smc/smc_tx.c create mode 100644 net/smc/smc_tx.h
net/smc/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SMC) += smc.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o -smc-y += smc_cdc.o +smc-y += smc_cdc.o smc_tx.o
net/smc/af_smc.c +12 -1
@@ -36,6 +36,7 @@#include "smc_core.h" #include "smc_ib.h" #include "smc_pnet.h" +#include "smc_tx.h" static DEFINE_MUTEX (smc_create_lgr_pending);/* serialize link group * creation
@@ -420,6 +421,8 @@ static int smc_connect_rdma(struct smc_sock *smc) }mutex_unlock (&smc_create_lgr_pending); +smc_tx_init (smc); + out_connected:smc_copy_sock_settings_to_clc (smc); smc->sk.sk_state =SMC_ACTIVE ;
@@ -761,6 +764,8 @@ static void smc_listen_work(struct work_struct *work) goto decline_rdma; } +smc_tx_init (new_smc); + out_connected:sk_refcnt_debug_inc (newsmcsk); newsmcsk->sk_state =SMC_ACTIVE ;
@@ -934,7 +939,7 @@ static int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)if (smc->use_fallback) rc = smc->clcsock->ops->sendmsg (smc->clcsock, msg, len);else - rc =sock_no_sendmsg (sock, msg, len); + rc =smc_tx_sendmsg (smc, msg, len); out:release_sock (sk);return rc;
@@ -1015,6 +1020,12 @@ static unsigned int smc_poll(struct file *file, struct socket *sock, mask |=smc_accept_poll (sk);if (sk->sk_err) mask |=POLLERR ; +if (atomic_read (&smc->conn.sndbuf_space)) { + mask |=POLLOUT |POLLWRNORM ; + }else { +sk_set_bit (SOCKWQ_ASYNC_NOSPACE , sk); +set_bit (SOCK_NOSPACE , &sk->sk_socket->flags); + }/* for now - to be enhanced in follow-on patch */ }
net/smc/smc.h +1 -0
@@ -130,6 +130,7 @@ struct smc_connection {atomic_t sndbuf_space;/* remaining space in sndbuf */ u16 tx_cdc_seq;/* sequence # for CDC send */ spinlock_t send_lock;/* protect wr_sends */ +struct work_struct tx_work;/* retry of smc_cdc_msg_send */ struct smc_host_cdc_msg local_rx_ctrl;/* filled during event_handl. * .prod cf. TCP rcv_nxt
net/smc/smc_cdc.c +5 -2
@@ -14,6 +14,7 @@#include "smc.h" #include "smc_wr.h" #include "smc_cdc.h" +#include "smc_tx.h" /********************************** send *************************************/
@@ -52,7 +53,7 @@ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd,smc_curs_read (&cdcpend->cursor, cdcpend->conn), cdcpend->conn); } -/* subsequent patch: wake if send buffer space available */ +smc_tx_sndbuf_nonfull (smc);bh_unlock_sock (&smc->sk); }
@@ -208,7 +209,9 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc, }/* piggy backed tx info */ -/* subsequent patch: wake receivers if receive buffer space available */ +/* trigger sndbuf consumer: RDMA write into peer RMBE and CDC */ +if (diff_cons &&smc_tx_prepared_sends (conn)) +smc_tx_sndbuf_nonempty (conn);/* subsequent patch: trigger socket release if connection closed */
net/smc/smc_tx.c new file +437 -0
437 lines not on this page · raw message
net/smc/smc_tx.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Manage send buffer +* +* Copyright IBM Corp. 2016 +* +* Author(s): Ursula Braun <[email protected]> +*/ + +#ifndef SMC_TX_H +#define SMC_TX_H + +#include <linux/socket.h> +#include <linux/types.h> + +#include "smc.h" +#include "smc_cdc.h" + +static inline int smc_tx_prepared_sends (struct smc_connection *conn) +{ +union smc_host_cursor sent, prep; + +smc_curs_write (&sent,smc_curs_read (&conn->tx_curs_sent, conn), conn); +smc_curs_write (&prep,smc_curs_read (&conn->tx_curs_prep, conn), conn); +return smc_curs_diff (conn->sndbuf_size, &sent, &prep); +} + +void smc_tx_init (struct smc_sock *); +int smc_tx_sendmsg (struct smc_sock *,struct msghdr *,size_t ); +int smc_tx_sndbuf_nonempty (struct smc_connection *); +void smc_tx_sndbuf_nonfull (struct smc_sock *); + +#endif /* SMC_TX_H */
Signature · 1 line
2.8.4
PATCH v2 13/15 smc: receive data from RMBE
In reply to Ursula Braunmove RMBE data into user space buffer and update managing cursors
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 7 +- net/smc/smc.h | 4 + net/smc/smc_cdc.c | 6 +- net/smc/smc_core.c | 10 +++ net/smc/smc_rx.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_rx.h | 22 ++++++ net/smc/smc_tx.c | 37 +++++++++ net/smc/smc_tx.h | 1 + 9 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 net/smc/smc_rx.c create mode 100644 net/smc/smc_rx.h
net/smc/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SMC) += smc.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o -smc-y += smc_cdc.o smc_tx.o +smc-y += smc_cdc.o smc_tx.o smc_rx.o
net/smc/af_smc.c +6 -1
@@ -37,6 +37,7 @@#include "smc_ib.h" #include "smc_pnet.h" #include "smc_tx.h" +#include "smc_rx.h" static DEFINE_MUTEX (smc_create_lgr_pending);/* serialize link group * creation
@@ -422,6 +423,7 @@ static int smc_connect_rdma(struct smc_sock *smc)mutex_unlock (&smc_create_lgr_pending);smc_tx_init (smc); +smc_rx_init (smc); out_connected:smc_copy_sock_settings_to_clc (smc);
@@ -765,6 +767,7 @@ static void smc_listen_work(struct work_struct *work) }smc_tx_init (new_smc); +smc_rx_init (new_smc); out_connected:sk_refcnt_debug_inc (newsmcsk);
@@ -960,7 +963,7 @@ static int smc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,if (smc->use_fallback) rc = smc->clcsock->ops->recvmsg (smc->clcsock, msg, len, flags);else - rc =sock_no_recvmsg (sock, msg, len, flags); + rc =smc_rx_recvmsg (smc, msg, len, flags); out:release_sock (sk);return rc;
@@ -1026,6 +1029,8 @@ static unsigned int smc_poll(struct file *file, struct socket *sock,sk_set_bit (SOCKWQ_ASYNC_NOSPACE , sk);set_bit (SOCK_NOSPACE , &sk->sk_socket->flags); } +if (atomic_read (&smc->conn.bytes_to_rcv)) + mask |=POLLIN |POLLRDNORM ;/* for now - to be enhanced in follow-on patch */ }
net/smc/smc.h +4 -0
@@ -112,6 +112,10 @@ struct smc_connection {struct smc_buf_desc *rmb_desc;/* RMBE descriptor */ int rmbe_size;/* RMBE size <== sock rmem */ int rmbe_size_short;/* compressed notation */ +int rmbe_update_limit; +/* lower limit for consumer +* cursor update +*/ struct smc_host_cdc_msg local_tx_ctrl;/* host byte order staging * buffer for CDC msg send
net/smc/smc_cdc.c +5 -1
@@ -15,6 +15,7 @@#include "smc_wr.h" #include "smc_cdc.h" #include "smc_tx.h" +#include "smc_rx.h" /********************************** send *************************************/
@@ -197,6 +198,7 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,atomic_add (diff_prod, &conn->bytes_to_rcv);/* guarantee 0 <= bytes_to_rcv <= rmbe_size */ smp_mb__after_atomic (); + smc->sk.sk_data_ready (&smc->sk); }if (conn->local_rx_ctrl.conn_state_flags.peer_conn_abort)
@@ -220,7 +222,9 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,return ;/* data available */ -/* subsequent patch: send delayed ack, wake receivers */ +if ((conn->local_rx_ctrl.prod_flags.write_blocked) || + (conn->local_rx_ctrl.prod_flags.cons_curs_upd_req)) +smc_tx_consumer_update (conn); }/* called under tasklet context */
net/smc/smc_core.c +10 -0
@@ -515,6 +515,15 @@ struct smc_buf_desc *smc_rmb_get_slot(struct smc_link_group *lgr,return NULL ; } +/* one of the conditions for announcing a receiver's current window size is +* that it "results in a minimum increase in the window size of 10% of the +* receive buffer space" [RFC7609] +*/ +static inline int smc_rmb_wnd_update_limit (int rmbe_size) +{ +return min_t (int, rmbe_size /10 ,SOCK_MIN_SNDBUF /2 ); +} +/* create the tx buffer for an SMC socket */ int smc_sndbuf_create (struct smc_sock *smc) {
@@ -646,6 +655,7 @@ int smc_rmb_create(struct smc_sock *smc) conn->rmbe_size_short = tmp_bufsize_short; smc->sk.sk_rcvbuf = tmp_bufsize *2 ;atomic_set (&conn->bytes_to_rcv,0 ); + conn->rmbe_update_limit =smc_rmb_wnd_update_limit (tmp_bufsize);return 0 ; }else {return -ENOMEM ;
net/smc/smc_rx.c new file +216 -0
216 lines not on this page · raw message
net/smc/smc_rx.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Manage RMBE +* +* Copyright IBM Corp. 2016 +* +* Author(s): Ursula Braun <[email protected]> +*/ + +#ifndef SMC_RX_H +#define SMC_RX_H + +#include <linux/socket.h> +#include <linux/types.h> + +#include "smc.h" + +void smc_rx_init (struct smc_sock *); +int smc_rx_recvmsg (struct smc_sock *,struct msghdr *,size_t ,int ); + +#endif /* SMC_RX_H */
net/smc/smc_tx.c +37 -0
@@ -426,6 +426,43 @@ static void smc_tx_work(struct work_struct *work)release_sock (&smc->sk); } +void smc_tx_consumer_update (struct smc_connection *conn) +{ +union smc_host_cursor cfed, cons; +struct smc_cdc_tx_pend *pend; +struct smc_wr_buf *wr_buf; +int to_confirm, rc; + +smc_curs_write (&cons, +smc_curs_read (&conn->local_tx_ctrl.cons, conn), + conn); +smc_curs_write (&cfed, +smc_curs_read (&conn->rx_curs_confirmed, conn), + conn); + to_confirm =smc_curs_diff (conn->rmbe_size, &cfed, &cons); + +if (conn->local_rx_ctrl.prod_flags.cons_curs_upd_req || + ((to_confirm > conn->rmbe_update_limit) && + ((to_confirm > (conn->rmbe_size /2 )) || + conn->local_rx_ctrl.prod_flags.write_blocked))) { + rc =smc_cdc_get_free_slot (&conn->lgr->lnk[SMC_SINGLE_LINK ], + &wr_buf, &pend); +if (!rc) + rc =smc_cdc_msg_send (conn, wr_buf, pend); +if (rc <0 ) { +schedule_work (&conn->tx_work); +return ; + } +smc_curs_write (&conn->rx_curs_confirmed, +smc_curs_read (&conn->local_tx_ctrl.cons, conn), + conn); + conn->local_rx_ctrl.prod_flags.cons_curs_upd_req =0 ; + } +if (conn->local_rx_ctrl.prod_flags.write_blocked && + !atomic_read (&conn->bytes_to_rcv)) + conn->local_rx_ctrl.prod_flags.write_blocked =0 ; +} +/***************************** send initialize *******************************/ /* Initialize send properties on connection establishment. NB: not __init! */
net/smc/smc_tx.h +1 -0
@@ -30,5 +30,6 @@ void smc_tx_init(struct smc_sock *);int smc_tx_sendmsg (struct smc_sock *,struct msghdr *,size_t );int smc_tx_sndbuf_nonempty (struct smc_connection *);void smc_tx_sndbuf_nonfull (struct smc_sock *); +void smc_tx_consumer_update (struct smc_connection *);#endif /* SMC_TX_H */
Signature · 1 line
2.8.4
PATCH v2 14/15 smc: socket closing and linkgroup cleanup
In reply to Ursula Braunsmc_shutdown() and smc_release() handling
delayed linkgroup cleanup for linkgroups without connections
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 105 +++++++++++-- net/smc/smc.h | 20 ++- net/smc/smc_cdc.c | 33 ++-- net/smc/smc_cdc.h | 1 + net/smc/smc_close.c | 435 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_close.h | 27 ++++ net/smc/smc_core.c | 6 + net/smc/smc_tx.c | 8 + net/smc/smc_wr.c | 47 ++++-- net/smc/smc_wr.h | 2 + 11 files changed, 646 insertions(+), 40 deletions(-) create mode 100644 net/smc/smc_close.c create mode 100644 net/smc/smc_close.h
net/smc/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SMC) += smc.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o -smc-y += smc_cdc.o smc_tx.o smc_rx.o +smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o
net/smc/af_smc.c +89 -16
213 lines not on this page · raw message
net/smc/smc.h +19 -1
@@ -27,6 +27,16 @@ enum smc_state { /* possible states of an SMC socket */SMC_INIT =2 ,SMC_CLOSED =7 ,SMC_LISTEN =10 , +/* 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, };struct smc_link_group ;
@@ -161,8 +171,14 @@ struct smc_sock { /* smc sock container */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 */ +struct delayed_work sock_put_work;/* final socket freeing */ u8 use_fallback : 1, /* fallback to tcp */ - clc_started : 1;/* smc_connect_rdma ran */ + clc_started : 1,/* smc_connect_rdma ran */ + wait_close_tx_prepared : 1; +/* shutdown wr or close +* started, waiting for unsent +* data to be sent +*/ };static inline struct smc_sock *smc_sk (const struct sock *sk)
@@ -246,5 +262,7 @@ int smc_netinfo_by_tcpsk(struct socket *, __be32 *, u8 *);void smc_conn_free (struct smc_connection *);int smc_conn_create (struct smc_sock *,__be32 ,struct smc_ib_device *,u8 ,struct smc_clc_msg_local *,int ); +struct sock *smc_accept_dequeue (struct sock *,struct socket *); +void smc_close_non_accepted (struct sock *);#endif /* _SMC_H */
net/smc/smc_cdc.c +20 -13
@@ -16,6 +16,7 @@#include "smc_cdc.h" #include "smc_tx.h" #include "smc_rx.h" +#include "smc_close.h" /********************************** send *************************************/
@@ -55,6 +56,9 @@ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd, cdcpend->conn); }smc_tx_sndbuf_nonfull (smc); +if (smc->sk.sk_state !=SMC_ACTIVE ) +/* wake up smc_close_wait_tx_pends() */ + smc->sk.sk_state_change (&smc->sk);bh_unlock_sock (&smc->sk); }
@@ -149,6 +153,14 @@ void smc_cdc_tx_dismiss_slots(struct smc_connection *conn) (unsigned long)conn); } +bool smc_cdc_tx_has_pending (struct smc_connection *conn) +{ +struct smc_link *link = &conn->lgr->lnk[SMC_SINGLE_LINK ]; + +return smc_wr_tx_has_pending (link,SMC_CDC_MSG_TYPE , + smc_cdc_tx_filter, (unsigned long )conn); +} +/********************************* receive ***********************************/ static inline bool smc_cdc_before (u16 seq1,u16 seq2)
@@ -201,21 +213,20 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc, smc->sk.sk_data_ready (&smc->sk); } -if (conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) +if (conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) { smc->sk.sk_err =ECONNRESET ; -if (smc_cdc_rxed_any_close_or_senddone (conn)) { - smc->sk.sk_shutdown |=RCV_SHUTDOWN ; -sock_set_flag (&smc->sk,SOCK_DONE ); - -/* subsequent patch: terminate connection */ + conn->local_tx_ctrl.conn_state_flags.peer_conn_abort =1 ; } +if (smc_cdc_rxed_any_close_or_senddone (conn)) +smc_close_passive_received (smc);/* piggy backed tx info */ /* trigger sndbuf consumer: RDMA write into peer RMBE and CDC */ -if (diff_cons &&smc_tx_prepared_sends (conn)) +if (diff_cons &&smc_tx_prepared_sends (conn)) {smc_tx_sndbuf_nonempty (conn); - -/* subsequent patch: trigger socket release if connection closed */ +/* trigger socket release if connection closed */ +smc_close_wake_tx_prepared (smc); + }/* socket connected but not accepted */ if (!smc->sk.sk_socket)
@@ -244,10 +255,6 @@ static inline void smc_cdc_msg_recv(struct smc_cdc_msg *cdc,return ; } smc = container_of(connection, struct smc_sock, conn); -if (smc->sk.sk_state ==SMC_CLOSED ) { -read_unlock_bh (&lgr->conns_lock); -return ; - }sock_hold (&smc->sk);read_unlock_bh (&lgr->conns_lock);bh_lock_sock (&smc->sk);
net/smc/smc_cdc.h +1 -0
@@ -211,6 +211,7 @@ void smc_cdc_tx_dismiss_slots(struct smc_connection *);int smc_cdc_msg_send (struct smc_connection *,struct smc_wr_buf *,struct smc_cdc_tx_pend *);int smc_cdc_get_slot_and_msg_send (struct smc_connection *); +bool smc_cdc_tx_has_pending (struct smc_connection *);int smc_cdc_init (void )__init ;#endif /* SMC_CDC_H */
net/smc/smc_close.c new file +435 -0
435 lines not on this page · raw message
net/smc/smc_close.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Socket Closing +* +* Copyright IBM Corp. 2016 +* +* Author(s): Ursula Braun <[email protected]> +*/ + +#ifndef SMC_CLOSE_H +#define SMC_CLOSE_H + +#include <linux/workqueue.h> + +#include "smc.h" + +#define SMC_CLOSE_SOCK_PUT_DELAY HZ + +void smc_close_wake_tx_prepared (struct smc_sock *); +void smc_close_active_abort (struct smc_sock *); +int smc_close_active (struct smc_sock *); +void smc_close_passive_received (struct smc_sock *); +void smc_close_sock_put_work (struct work_struct *); +int smc_close_shutdown_write (struct smc_sock *); + +#endif /* SMC_CLOSE_H */
net/smc/smc_core.c +6 -0
@@ -23,6 +23,7 @@#include "smc_wr.h" #include "smc_llc.h" #include "smc_cdc.h" +#include "smc_close.h" #define SMC_LGR_NUM_INCR 256#define SMC_LGR_FREE_DELAY (600 * HZ)
@@ -297,6 +298,7 @@ void smc_lgr_free(struct smc_link_group *lgr)void smc_lgr_terminate (struct smc_link_group *lgr) {struct smc_connection *conn; +struct smc_sock *smc;struct rb_node *node;spin_lock_bh (&smc_lgr_list.lock);
@@ -313,7 +315,11 @@ void smc_lgr_terminate(struct smc_link_group *lgr) node =rb_first (&lgr->conns_all);while (node) { conn = rb_entry(node, struct smc_connection, alert_node); + smc = container_of(conn, struct smc_sock, conn); +sock_hold (&smc->sk);__smc_lgr_unregister_conn (conn); +smc_close_active_abort (smc); +sock_put (&smc->sk); node =rb_first (&lgr->conns_all); }write_unlock_bh (&lgr->conns_lock);
net/smc/smc_tx.c +8 -0
@@ -138,6 +138,7 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)if (sk->sk_state ==SMC_INIT )return -ENOTCONN ;if (smc->sk.sk_shutdown &SEND_SHUTDOWN || + (smc->sk.sk_err ==ECONNABORTED ) || conn->local_tx_ctrl.conn_state_flags.peer_conn_abort)return -EPIPE ;if (smc_cdc_rxed_any_close (conn))
@@ -391,6 +392,13 @@ int smc_tx_sndbuf_nonempty(struct smc_connection *conn) &pend);if (rc <0 ) {if (rc == -EBUSY ) { +struct smc_sock *smc = + container_of(conn, struct smc_sock, conn); + +if (smc->sk.sk_err ==ECONNABORTED ) { + rc =sock_error (&smc->sk); + goto out_unlock; + } rc =0 ;schedule_work (&conn->tx_work); }
net/smc/smc_wr.c +38 -9
82 lines not on this page · raw message
net/smc/smc_wr.h +2 -0
@@ -90,6 +90,8 @@ int smc_wr_tx_get_free_slot(struct smc_link *, smc_wr_tx_handler,int smc_wr_tx_put_slot (struct smc_link *,struct smc_wr_tx_pend_priv *);int smc_wr_tx_send (struct smc_link *,struct smc_wr_tx_pend_priv *);void smc_wr_tx_cq_handler (struct ib_cq *,void *); +bool smc_wr_tx_has_pending (struct smc_link *,u8 , +smc_wr_tx_filter ,unsigned long );void smc_wr_tx_dismiss_slots (struct smc_link *,u8 ,smc_wr_tx_filter ,smc_wr_tx_dismisser ,unsigned long );
Signature · 1 line
2.8.4
PATCH v2 15/15 smc: proc-fs interface for smc connections
In reply to Ursula BraunMaintain a list of SMC sockets and display important SMC socket information in /proc/net/smc.
--- net/smc/Makefile | 2 +- net/smc/af_smc.c | 14 +++ net/smc/smc.h | 1 + net/smc/smc_proc.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_proc.h | 19 +++++ 5 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 net/smc/smc_proc.c create mode 100644 net/smc/smc_proc.h
net/smc/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SMC) += smc.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o -smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o +smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_proc.o
net/smc/af_smc.c +14 -0
@@ -39,6 +39,7 @@#include "smc_tx.h" #include "smc_rx.h" #include "smc_close.h" +#include "smc_proc.h" static DEFINE_MUTEX (smc_create_lgr_pending);/* serialize link group * creation
@@ -118,11 +119,14 @@ out:static void smc_destruct (struct sock *sk) { +struct smc_sock *smc =smc_sk (sk); +if (sk->sk_state !=SMC_CLOSED )return ;if (!sock_flag (sk,SOCK_DEAD ))return ; +smc_proc_sock_list_del (smc);sk_refcnt_debug_dec (sk); }
@@ -151,6 +155,7 @@ static struct sock *smc_sock_alloc(struct net *net, struct socket *sock)INIT_LIST_HEAD (&smc->accept_q);spin_lock_init (&smc->accept_q_lock);INIT_DELAYED_WORK (&smc->sock_put_work, smc_close_sock_put_work); +smc_proc_sock_list_add (smc);return sk; }
@@ -1327,8 +1332,16 @@ static int __init smc_init(void) goto out_sock; } + rc =smc_proc_init (); +if (rc) { +pr_err ("%s: smc_proc_init fails with %d\n" , __func__, rc); + goto out_ibclient; + } +return 0 ; +out_ibclient: +smc_ib_unregister_client (); out_sock:sock_unregister (PF_SMC ); out_proto:
@@ -1351,6 +1364,7 @@ static void __exit smc_exit(void)list_del_init (&lgr->list);smc_lgr_free (lgr);/* free link group */ } +smc_proc_exit ();smc_ib_unregister_client ();sock_unregister (PF_SMC );proto_unregister (&smc_proto);
net/smc/smc.h +1 -0
@@ -163,6 +163,7 @@ struct smc_connection {struct smc_sock {/* smc sock container */ struct sock sk; +struct list_head proc_list;/* smc socket list */ struct socket *clcsock;/* internal tcp socket */ struct smc_connection conn;/* smc connection */ struct sockaddr *addr;/* inet connect address */
net/smc/smc_proc.c new file +247 -0
247 lines not on this page · raw message
net/smc/smc_proc.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Shared Memory Communications over RDMA (SMC-R) and RoCE +* +* Handle /proc entries for SMC sockets +* +* Copyright IBM Corp. 2016 +* +* Author(s): Ursula Braun <[email protected]> +*/ + +#ifndef SMC_PROC_H +#define SMC_PROC_H + +void smc_proc_sock_list_add (struct smc_sock *); +void smc_proc_sock_list_del (struct smc_sock *); +int smc_proc_init (void )__init ; +void smc_proc_exit (void ); + +#endif /* SMC_PROC_H */
Signature · 1 line
2.8.4
David Miller
maintainerRe: [PATCH V2 net-next 15/15] smc: proc-fs interface for smc connections
From: Ursula Braun <[email protected]>
Date: Tue, 27 Sep 2016 18:41:56 +0200
Quoted 4 lines
Maintain a list of SMC sockets and display important SMC socket information in
/proc/net/smc.Signed-off-by Ursula Braun <[email protected]>
Dumping internal tables and information via /procfs is strongly deprecated.
Please use a more modern mechanism (such as netlink) to expose this information to the user.
You'll be most likely to succeed in your submission if you make use of or design a generic facility that allows other drivers similar to your's to provide this kind of information as well.
I'm sorry if this is frustrating, but this is a huge piece of infrastructure, therefore you can expect lots of pieces to get feedback and require changes like this.
Re: [PATCH V2 net-next 15/15] smc: proc-fs interface for smc connections
Hi Dave,
thank you for your feedback. Following your guidance I studied the inet_diag/tcp_diag kernel code for AF_INET sockets. It could make sense to create an smc_diag module with an smc_diag_handler to provide SMC-socket data to userspace. Userspace tools could exploit this by receiving the SMC-socket data via AF_NETLINK sockets of protocol NETLINK_SOCK_DIAG.
Please let me know, if this is the right direction.
Regards, Ursula
Quoted 23 lines · David Miller
From: Ursula Braun <[email protected]>
Date: Tue, 27 Sep 2016 18:41:56 +0200Quoted 4 lines
Maintain a list of SMC sockets and display important SMC socket information in
/proc/net/smc.Signed-off-by Ursula Braun <[email protected]>Dumping internal tables and information via /procfs is strongly deprecated.
Please use a more modern mechanism (such as netlink) to expose this information to the user.
You'll be most likely to succeed in your submission if you make use of or design a generic facility that allows other drivers similar to your's to provide this kind of information as well.
I'm sorry if this is frustrating, but this is a huge piece of infrastructure, therefore you can expect lots of pieces to get feedback and require changes like this.