net/smc: fixes 2018-02-21
cover net/smc: fixes 2018-02-21
Dave,
here are some smc-patches for net-next. Besides cleanups, the link id field of the LLC confirm link reply is changed to comply with RFC7609.
Thanks, Ursula
Karsten Graul (4):
smc: fix structure size
smc: move netinfo function to file smc_clc.c
smc: remove unused fields from smc structures
smc: use link_id of server in confirm link reply
Stefan Raspl (1):
smc: cleanup smc_llc.h and smc_clc.h headers
net/smc/af_smc.c | 65 ++++++++---------------------------------------------- net/smc/smc.h | 5 +---- net/smc/smc_cdc.c | 2 +- net/smc/smc_cdc.h | 2 +- net/smc/smc_clc.c | 47 +++++++++++++++++++++++++++++++++++++-- net/smc/smc_clc.h | 8 ++----- net/smc/smc_core.c | 8 +++---- net/smc/smc_core.h | 1 - net/smc/smc_llc.c | 32 ++++++++++++++++++++++++++- net/smc/smc_llc.h | 28 ----------------------- 10 files changed, 94 insertions(+), 104 deletions(-)
Signature · 1 line
2.13.5
PATCH 1/5 net/smc: cleanup smc_llc.h and smc_clc.h headers
From: Stefan Raspl <[email protected]>
Remove structures used internal only from headers. And remove an extra function parameter.
--- net/smc/af_smc.c | 8 ++++---- net/smc/smc_clc.c | 3 +++ net/smc/smc_clc.h | 6 ------ net/smc/smc_llc.c | 30 ++++++++++++++++++++++++++++++ net/smc/smc_llc.h | 28 ---------------------------- 5 files changed, 37 insertions(+), 38 deletions(-)
net/smc/af_smc.c +4 -4
@@ -312,7 +312,7 @@ int smc_netinfo_by_tcpsk(struct socket *clcsock,return rc; } -static int smc_clnt_conf_first_link (struct smc_sock *smc,union ib_gid *gid) +static int smc_clnt_conf_first_link (struct smc_sock *smc) {struct smc_link_group *lgr = smc->conn.lgr;struct smc_link *link;
@@ -346,7 +346,8 @@ static int smc_clnt_conf_first_link(struct smc_sock *smc, union ib_gid *gid)/* send CONFIRM LINK response over RoCE fabric */ rc =smc_llc_send_confirm_link (link, link->smcibdev->mac[link->ibport -1 ], - gid,SMC_LLC_RESP ); + &link->smcibdev->gid[link->ibport -1 ], +SMC_LLC_RESP );if (rc <0 )return SMC_CLC_DECL_TCL ;
@@ -498,8 +499,7 @@ static int smc_connect_rdma(struct smc_sock *smc)if (local_contact ==SMC_FIRST_CONTACT ) {/* QP confirmation over RoCE fabric */ - reason_code =smc_clnt_conf_first_link ( - smc, &smcibdev->gid[ibport -1 ]); + reason_code =smc_clnt_conf_first_link (smc);if (reason_code <0 ) { rc = reason_code; goto out_err_unlock;
net/smc/smc_clc.c +3 -0
@@ -22,6 +22,9 @@#include "smc_clc.h" #include "smc_ib.h" +/* eye catcher "SMCR" EBCDIC for CLC messages */ +static const char SMC_EYECATCHER [4 ] = {'\xe2' ,'\xd4' ,'\xc3' ,'\xd9' }; +/* check if received message has a correct header length and contains valid * heading and trailing eyecatchers */
net/smc/smc_clc.h +0 -6
@@ -22,9 +22,6 @@#define SMC_CLC_CONFIRM 0x03#define SMC_CLC_DECLINE 0x04 -/* eye catcher "SMCR" EBCDIC for CLC messages */ -static const char SMC_EYECATCHER [4 ] = {'\xe2' ,'\xd4' ,'\xc3' ,'\xd9' }; -#define SMC_CLC_V1 0x1/* SMC version */ #define CLC_WAIT_TIME (6 * HZ)/* max. wait time on clcsock */ #define SMC_CLC_DECL_MEM 0x01010000/* insufficient memory resources */
@@ -124,9 +121,6 @@ smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc) ((u8 *)pclc +sizeof (*pclc) +ntohs (pclc->iparea_offset)); } -struct smc_sock ; -struct smc_ib_device ; -int smc_clc_wait_msg (struct smc_sock *smc,void *buf,int buflen,u8 expected_type);int smc_clc_send_decline (struct smc_sock *smc,u32 peer_diag_info);
net/smc/smc_llc.c +30 -0
@@ -21,6 +21,36 @@#include "smc_clc.h" #include "smc_llc.h" +#define SMC_LLC_DATA_LEN 40 + +struct smc_llc_hdr { +struct smc_wr_rx_hdr common; +u8 length;/* 44 */ +u8 reserved; +u8 flags; +}; + +struct smc_llc_msg_confirm_link {/* type 0x01 */ +struct smc_llc_hdr hd; +u8 sender_mac[ETH_ALEN ]; +u8 sender_gid[SMC_GID_SIZE ]; +u8 sender_qp_num[3 ]; +u8 link_num; +u8 link_uid[SMC_LGR_ID_SIZE ]; +u8 max_links; +u8 reserved[9 ]; +}; + +union smc_llc_msg { +struct smc_llc_msg_confirm_link confirm_link; +struct { +struct smc_llc_hdr hdr; +u8 data[SMC_LLC_DATA_LEN ]; + } raw; +}; + +#define SMC_LLC_FLAG_RESP 0x80 +/********************************** send *************************************/ struct smc_llc_tx_pend {
net/smc/smc_llc.h +0 -28
@@ -28,34 +28,6 @@ enum smc_llc_msg_type { SMC_LLC_CONFIRM_LINK = 0x01, }; -#define SMC_LLC_DATA_LEN 40 - -struct smc_llc_hdr { -struct smc_wr_rx_hdr common; -u8 length;/* 44 */ -u8 reserved; -u8 flags; -}; - -struct smc_llc_msg_confirm_link {/* type 0x01 */ -struct smc_llc_hdr hd; -u8 sender_mac[ETH_ALEN ]; -u8 sender_gid[SMC_GID_SIZE ]; -u8 sender_qp_num[3 ]; -u8 link_num; -u8 link_uid[SMC_LGR_ID_SIZE ]; -u8 max_links; -u8 reserved[9 ]; -}; - -union smc_llc_msg { -struct smc_llc_msg_confirm_link confirm_link; -struct { -struct smc_llc_hdr hdr; -u8 data[SMC_LLC_DATA_LEN ]; - } raw; -}; -/* transmit */ int smc_llc_send_confirm_link (struct smc_link *lnk,u8 mac[],union ib_gid *gid,enum smc_llc_reqresp reqresp);
Signature · 1 line
2.13.5
PATCH 2/5 net/smc: fix structure size
In reply to Ursula BraunFrom: Karsten Graul <[email protected]>
The struct smc_cdc_msg must be defined as packed, so the size is 44 bytes. And change the structure size check, so sizeof is checked.
--- net/smc/smc_cdc.c | 2 +- net/smc/smc_cdc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/smc/smc_cdc.c +1 -1
@@ -82,7 +82,7 @@ static inline void smc_cdc_add_pending_send(struct smc_connection *conn,sizeof (struct smc_cdc_msg ) >SMC_WR_BUF_SIZE , "must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_cdc_msg)");BUILD_BUG_ON_MSG ( - offsetof(struct smc_cdc_msg , reserved) >SMC_WR_TX_SIZE , +sizeof (struct smc_cdc_msg ) !=SMC_WR_TX_SIZE ,"must adapt SMC_WR_TX_SIZE to sizeof(struct smc_cdc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send()" ); BUILD_BUG_ON_MSG( sizeof(struct smc_cdc_tx_pend) > SMC_WR_TX_PEND_PRIV_SIZE,
net/smc/smc_cdc.h +1 -1
@@ -48,7 +48,7 @@ struct smc_cdc_msg {struct smc_cdc_producer_flags prod_flags;struct smc_cdc_conn_state_flags conn_state_flags;u8 reserved[18 ]; -}__aligned(8) ; +} __packed;/* format defined in RFC7609 */ static inline bool smc_cdc_rxed_any_close (struct smc_connection *conn) {
Signature · 1 line
2.13.5
David Miller
maintainerRe: [PATCH net-next 2/5] net/smc: fix structure size
From: Ursula Braun <[email protected]>
Date: Wed, 21 Feb 2018 12:32:32 +0100
net/smc/smc_cdc.h struct smc_cdc_msg { · line 51
Quoted 10 lines
net/smc/smc_cdc.h +1
-1@@ -48,7 +48,7 @@ struct smc_cdc_msg {struct smc_cdc_producer_flags prod_flags;struct smc_cdc_conn_state_flags conn_state_flags;u8 reserved[18 ]; -}__aligned(8) ; +} __packed;/* format defined in RFC7609 */
Hold on, __packed should only be used as the absolute last possible option to fix structure layout problems.
Also, a sub-structure of smc_cdc_msg, union smc_cdc_cursor, is still marked with __aligned(8). That makes no sense at all.
Please fix this without using __packed, as __packed has a severe detrimental effect on code generation for accessing such structure on several cpu architectures.
Also, if this these are legitimate bug fixes you should target those at 'net' not 'net-next'.
Thank you.
PATCH 3/5 net/smc: move netinfo function to file smc_clc.c
In reply to Ursula BraunFrom: Karsten Graul <[email protected]>
The function smc_netinfo_by_tcpsk() belongs to CLC handling. Move it to smc_clc.c and rename to smc_clc_netinfo_by_tcpsk.
--- net/smc/af_smc.c | 42 +----------------------------------------- net/smc/smc.h | 2 -- net/smc/smc_clc.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- net/smc/smc_clc.h | 2 ++ 4 files changed, 45 insertions(+), 45 deletions(-)
net/smc/af_smc.c +1 -41
@@ -24,7 +24,6 @@#include <linux/module.h> #include <linux/socket.h> -#include <linux/inetdevice.h> #include <linux/workqueue.h> #include <linux/in.h> #include <linux/sched/signal.h>
@@ -273,45 +272,6 @@ static void smc_copy_sock_settings_to_smc(struct smc_sock *smc)smc_copy_sock_settings (&smc->sk, smc->clcsock->sk,SK_FLAGS_CLC_TO_SMC ); } -/* determine subnet and mask of internal TCP socket */ -int smc_netinfo_by_tcpsk (struct socket *clcsock, -__be32 *subnet,u8 *prefix_len) -{ -struct dst_entry *dst =sk_dst_get (clcsock->sk); -struct in_device *in_dev; -struct sockaddr_in addr; -int rc = -ENOENT ; - -if (!dst) { - rc = -ENOTCONN ; - goto out; - } -if (!dst->dev) { - rc = -ENODEV ; - goto out_rel; - } - -/* get address to which the internal TCP socket is bound */ -kernel_getsockname (clcsock, (struct sockaddr *)&addr); -/* analyze IPv4 specific data of net_device belonging to TCP socket */ -rcu_read_lock (); - in_dev =__in_dev_get_rcu (dst->dev); -for_ifa (in_dev) { -if (!inet_ifa_match (addr.sin_addr.s_addr, ifa)) -continue ; - *prefix_len =inet_mask_len (ifa->ifa_mask); - *subnet = ifa->ifa_address & ifa->ifa_mask; - rc =0 ; -break ; - }endfor_ifa (in_dev); -rcu_read_unlock (); - -out_rel: -dst_release (dst); -out: -return rc; -} -static int smc_clnt_conf_first_link (struct smc_sock *smc) {struct smc_link_group *lgr = smc->conn.lgr;
@@ -808,7 +768,7 @@ static void smc_listen_work(struct work_struct *work) }/* determine subnet and mask from internal TCP socket */ - rc =smc_netinfo_by_tcpsk (newclcsock, &subnet, &prefix_len); + rc =smc_clc_netinfo_by_tcpsk (newclcsock, &subnet, &prefix_len);if (rc) { reason_code =SMC_CLC_DECL_CNFERR ;/* configuration error */ goto decline_rdma;
net/smc/smc.h +0 -2
@@ -263,8 +263,6 @@ static inline bool using_ipsec(struct smc_sock *smc)struct smc_clc_msg_local ; -int smc_netinfo_by_tcpsk (struct socket *clcsock,__be32 *subnet, -u8 *prefix_len);void smc_conn_free (struct smc_connection *conn); int smc_conn_create(struct smc_sock *smc, __be32 peer_in_addr, struct smc_ib_device *smcibdev, u8 ibport,
net/smc/smc_clc.c +42 -2
62 lines not on this page · raw message
net/smc/smc_clc.h +2 -0
@@ -121,6 +121,8 @@ smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc) ((u8 *)pclc +sizeof (*pclc) +ntohs (pclc->iparea_offset)); } +int smc_clc_netinfo_by_tcpsk (struct socket *clcsock,__be32 *subnet, +u8 *prefix_len);int smc_clc_wait_msg (struct smc_sock *smc,void *buf,int buflen,u8 expected_type);int smc_clc_send_decline (struct smc_sock *smc,u32 peer_diag_info);
Signature · 1 line
2.13.5
PATCH 4/5 net/smc: remove unused fields from smc structures
In reply to Ursula BraunFrom: Karsten Graul <[email protected]>
The daddr field holds the destination IPv4 address. The field was set but never used and can be removed. The addr field was a left-over from an earlier version of non-blocking connects and can be removed. The result of the call to kernel_getpeername is not used, the call can be removed. Non-blocking connects are working, so remove restriction comment.
--- net/smc/af_smc.c | 15 ++++----------- net/smc/smc.h | 3 +-- net/smc/smc_core.c | 7 +++---- net/smc/smc_core.h | 1 - 4 files changed, 8 insertions(+), 18 deletions(-)
net/smc/af_smc.c +4 -11
@@ -7,7 +7,6 @@* applicable with RoCE-cards only * * Initial restrictions: -* - non-blocking connect postponed * - IPv6 support postponed * - support for alternate links postponed * - partial support for non-blocking sockets only
@@ -345,7 +344,6 @@ static void smc_lgr_forget(struct smc_link_group *lgr)/* setup for RDMA connection of client */ static int smc_connect_rdma (struct smc_sock *smc) { -struct sockaddr_in *inaddr = (struct sockaddr_in *)smc->addr;struct smc_clc_msg_accept_confirm aclc;int local_contact =SMC_FIRST_CONTACT ;struct smc_ib_device *smcibdev;
@@ -399,8 +397,8 @@ static int smc_connect_rdma(struct smc_sock *smc) srv_first_contact = aclc.hdr.flag;mutex_lock (&smc_create_lgr_pending); - local_contact =smc_conn_create (smc, inaddr->sin_addr.s_addr, smcibdev, - ibport, &aclc.lcl, srv_first_contact); + local_contact =smc_conn_create (smc, smcibdev, ibport, &aclc.lcl, + srv_first_contact);if (local_contact <0 ) { rc = local_contact;if (rc == -ENOMEM )
@@ -518,7 +516,6 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, goto out_err;if (addr->sa_family !=AF_INET ) goto out_err; - smc->addr = addr;/* needed for nonblocking connect */ lock_sock (sk);switch (sk->sk_state) {
@@ -726,7 +723,6 @@ static void smc_listen_work(struct work_struct *work)struct sock *newsmcsk = &new_smc->sk;struct smc_clc_msg_proposal *pclc;struct smc_ib_device *smcibdev; -struct sockaddr_in peeraddr;u8 buf[SMC_CLC_MAX_LEN ];struct smc_link *link;int reason_code =0 ;
@@ -782,13 +778,10 @@ static void smc_listen_work(struct work_struct *work) goto decline_rdma; } -/* get address of the peer connected to the internal TCP socket */ -kernel_getpeername (newclcsock, (struct sockaddr *)&peeraddr); -/* allocate connection / link group */ mutex_lock (&smc_create_lgr_pending); - local_contact =smc_conn_create (new_smc, peeraddr.sin_addr.s_addr, - smcibdev, ibport, &pclc->lcl,0 ); + local_contact =smc_conn_create (new_smc, smcibdev, ibport, &pclc->lcl, +0 );if (local_contact <0 ) { rc = local_contact;if (rc == -ENOMEM )
net/smc/smc.h +1 -2
@@ -172,7 +172,6 @@ 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 */ struct work_struct smc_listen_work;/* prepare new accept socket */
@@ -264,7 +263,7 @@ static inline bool using_ipsec(struct smc_sock *smc)struct smc_clc_msg_local ;void smc_conn_free (struct smc_connection *conn); -int smc_conn_create (struct smc_sock *smc,__be32 peer_in_addr, +int smc_conn_create (struct smc_sock *smc,struct smc_ib_device *smcibdev,u8 ibport,struct smc_clc_msg_local *lcl,int srv_first_contact);struct sock *smc_accept_dequeue (struct sock *parent,struct socket *new_sock);
net/smc/smc_core.c +3 -4
@@ -144,7 +144,7 @@ static void smc_lgr_free_work(struct work_struct *work) }/* create a new SMC link group */ -static int smc_lgr_create (struct smc_sock *smc,__be32 peer_in_addr, +static int smc_lgr_create (struct smc_sock *smc,struct smc_ib_device *smcibdev,u8 ibport,char *peer_systemid,unsigned short vlan_id) {
@@ -161,7 +161,6 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr, } lgr->role = smc->listen_smc ?SMC_SERV :SMC_CLNT ; lgr->sync_err = false; - lgr->daddr = peer_in_addr;memcpy (lgr->peer_systemid, peer_systemid,SMC_SYSTEMID_LEN ); lgr->vlan_id = vlan_id;rwlock_init (&lgr->sndbufs_lock);
@@ -400,7 +399,7 @@ static int smc_link_determine_gid(struct smc_link_group *lgr) }/* create a new SMC connection (and a new link group if necessary) */ -int smc_conn_create (struct smc_sock *smc,__be32 peer_in_addr, +int smc_conn_create (struct smc_sock *smc,struct smc_ib_device *smcibdev,u8 ibport,struct smc_clc_msg_local *lcl,int srv_first_contact) {
@@ -457,7 +456,7 @@ int smc_conn_create(struct smc_sock *smc, __be32 peer_in_addr, create:if (local_contact ==SMC_FIRST_CONTACT ) { - rc =smc_lgr_create (smc, peer_in_addr, smcibdev, ibport, + rc =smc_lgr_create (smc, smcibdev, ibport, lcl->id_for_peer, vlan_id);if (rc) goto out;
net/smc/smc_core.h +0 -1
@@ -124,7 +124,6 @@ struct smc_rtoken { /* address/key of remote RMB */struct smc_link_group {struct list_head list;enum smc_lgr_role role;/* client or server */ -__be32 daddr;/* destination ip address */ struct smc_link lnk[SMC_LINKS_PER_LGR_MAX ];/* smc link */ char peer_systemid[SMC_SYSTEMID_LEN ];/* unique system_id of peer */
Signature · 1 line
2.13.5
PATCH 5/5 net/smc: use server link_id in confirm link reply
In reply to Ursula BraunFrom: Karsten Graul <[email protected]>
The CONFIRM LINK reply message must contain the link_id sent by the server. And set the link_id explicitly when initializing the link.
--- net/smc/smc_core.c | 1 + net/smc/smc_llc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
net/smc/smc_core.c +1 -0
@@ -176,6 +176,7 @@ static int smc_lgr_create(struct smc_sock *smc, lnk = &lgr->lnk[SMC_SINGLE_LINK ];/* initialize link */ + lnk->link_id =SMC_SINGLE_LINK ; lnk->smcibdev = smcibdev; lnk->ibport = ibport; lnk->path_mtu = smcibdev->pattr[ibport -1 ].active_mtu;
net/smc/smc_llc.c +1 -1
@@ -122,7 +122,7 @@ int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],memcpy (confllc->sender_mac, mac,ETH_ALEN );memcpy (confllc->sender_gid, gid,SMC_GID_SIZE );hton24 (confllc->sender_qp_num, link->roce_qp->qp_num); -/* confllc->link_num = SMC_SINGLE_LINK; already done by memset above */ + confllc->link_num = link->link_id;memcpy (confllc->link_uid, lgr->id,SMC_LGR_ID_SIZE ); confllc->max_links =SMC_LINKS_PER_LGR_MAX ;/* send llc message */
Signature · 1 line
2.13.5
Quoted 6 lines · Ursula Braun
Dave,
here are some smc-patches for net-next. Besides cleanups, the link id field of the LLC confirm link reply is changed to comply with RFC7609.
Thanks, Ursula
Looks good to me!
Ciao,
Stefan