* [PATCH net-next 0/5] net/smc: fixes 2018-01-26
@ 2018-01-26 8:28 Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 1/5] net/smc: handle device, port, and QP error events Ursula Braun
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ursula Braun @ 2018-01-26 8:28 UTC (permalink / raw)
To: davem
Cc: netdev, linux-s390, linux-rdma, jwi, schwidefsky, heiko.carstens,
raspl, ubraun
Dave,
here are some more smc patches. The first 4 patches take care about
different aspects of smc socket closing, the 5th patch improves
coding style.
Thanks, Ursula
Gustavo A. R. Silva (1):
smc: return booleans instead of integers
Ursula Braun (4):
net/smc: handle device, port, and QP error events
net/smc: smc_poll improvements
net/smc: replace sock_put worker by socket refcounting
net/smc: release clcsock from tcp_listen_worker
net/smc/af_smc.c | 152 ++++++++++++++++++++++++++++++----------------------
net/smc/smc.h | 5 +-
net/smc/smc_cdc.c | 20 +++----
net/smc/smc_close.c | 96 +++++++++++++++++++++------------
net/smc/smc_close.h | 1 -
net/smc/smc_core.c | 6 +--
net/smc/smc_ib.c | 38 ++++++++-----
7 files changed, 191 insertions(+), 127 deletions(-)
--
2.13.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/5] net/smc: handle device, port, and QP error events
2018-01-26 8:28 [PATCH net-next 0/5] net/smc: fixes 2018-01-26 Ursula Braun
@ 2018-01-26 8:28 ` Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 2/5] net/smc: smc_poll improvements Ursula Braun
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ursula Braun @ 2018-01-26 8:28 UTC (permalink / raw)
To: davem
Cc: netdev, linux-s390, linux-rdma, jwi, schwidefsky, heiko.carstens,
raspl, ubraun
RoCE device changes cause an IB event, processed in the global event
handler for the ROCE device. Problems for a certain Queue Pair cause a QP
event, processed in the QP event handler for this QP.
Among those events are port errors and other fatal device errors. All
link groups using such a port or device must be terminated in those cases.
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
---
net/smc/smc_ib.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c
index 90f1a7f9085c..2a8957bd6d38 100644
--- a/net/smc/smc_ib.c
+++ b/net/smc/smc_ib.c
@@ -141,6 +141,17 @@ int smc_ib_ready_link(struct smc_link *lnk)
return rc;
}
+static void smc_ib_port_terminate(struct smc_ib_device *smcibdev, u8 ibport)
+{
+ struct smc_link_group *lgr, *l;
+
+ list_for_each_entry_safe(lgr, l, &smc_lgr_list.list, list) {
+ if (lgr->lnk[SMC_SINGLE_LINK].smcibdev == smcibdev &&
+ lgr->lnk[SMC_SINGLE_LINK].ibport == ibport)
+ smc_lgr_terminate(lgr);
+ }
+}
+
/* process context wrapper for might_sleep smc_ib_remember_port_attr */
static void smc_ib_port_event_work(struct work_struct *work)
{
@@ -151,6 +162,8 @@ static void smc_ib_port_event_work(struct work_struct *work)
for_each_set_bit(port_idx, &smcibdev->port_event_mask, SMC_MAX_PORTS) {
smc_ib_remember_port_attr(smcibdev, port_idx + 1);
clear_bit(port_idx, &smcibdev->port_event_mask);
+ if (!smc_ib_port_active(smcibdev, port_idx + 1))
+ smc_ib_port_terminate(smcibdev, port_idx + 1);
}
}
@@ -165,15 +178,7 @@ static void smc_ib_global_event_handler(struct ib_event_handler *handler,
switch (ibevent->event) {
case IB_EVENT_PORT_ERR:
- port_idx = ibevent->element.port_num - 1;
- set_bit(port_idx, &smcibdev->port_event_mask);
- schedule_work(&smcibdev->port_event_work);
- /* fall through */
case IB_EVENT_DEVICE_FATAL:
- /* tbd in follow-on patch:
- * abnormal close of corresponding connections
- */
- break;
case IB_EVENT_PORT_ACTIVE:
port_idx = ibevent->element.port_num - 1;
set_bit(port_idx, &smcibdev->port_event_mask);
@@ -186,7 +191,8 @@ static void smc_ib_global_event_handler(struct ib_event_handler *handler,
void smc_ib_dealloc_protection_domain(struct smc_link *lnk)
{
- ib_dealloc_pd(lnk->roce_pd);
+ if (lnk->roce_pd)
+ ib_dealloc_pd(lnk->roce_pd);
lnk->roce_pd = NULL;
}
@@ -203,14 +209,18 @@ int smc_ib_create_protection_domain(struct smc_link *lnk)
static void smc_ib_qp_event_handler(struct ib_event *ibevent, void *priv)
{
+ struct smc_ib_device *smcibdev =
+ (struct smc_ib_device *)ibevent->device;
+ u8 port_idx;
+
switch (ibevent->event) {
case IB_EVENT_DEVICE_FATAL:
case IB_EVENT_GID_CHANGE:
case IB_EVENT_PORT_ERR:
case IB_EVENT_QP_ACCESS_ERR:
- /* tbd in follow-on patch:
- * abnormal close of corresponding connections
- */
+ port_idx = ibevent->element.port_num - 1;
+ set_bit(port_idx, &smcibdev->port_event_mask);
+ schedule_work(&smcibdev->port_event_work);
break;
default:
break;
@@ -219,7 +229,8 @@ static void smc_ib_qp_event_handler(struct ib_event *ibevent, void *priv)
void smc_ib_destroy_queue_pair(struct smc_link *lnk)
{
- ib_destroy_qp(lnk->roce_qp);
+ if (lnk->roce_qp)
+ ib_destroy_qp(lnk->roce_qp);
lnk->roce_qp = NULL;
}
@@ -462,6 +473,7 @@ static void smc_ib_cleanup_per_ibdev(struct smc_ib_device *smcibdev)
{
if (!smcibdev->initialized)
return;
+ smcibdev->initialized = 0;
smc_wr_remove_dev(smcibdev);
ib_unregister_event_handler(&smcibdev->event_handler);
ib_destroy_cq(smcibdev->roce_cq_recv);
--
2.13.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/5] net/smc: smc_poll improvements
2018-01-26 8:28 [PATCH net-next 0/5] net/smc: fixes 2018-01-26 Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 1/5] net/smc: handle device, port, and QP error events Ursula Braun
@ 2018-01-26 8:28 ` Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 4/5] net/smc: release clcsock from tcp_listen_worker Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 5/5] net/smc: return booleans instead of integers Ursula Braun
3 siblings, 0 replies; 5+ messages in thread
From: Ursula Braun @ 2018-01-26 8:28 UTC (permalink / raw)
To: davem
Cc: netdev, linux-s390, linux-rdma, jwi, schwidefsky, heiko.carstens,
raspl, ubraun
Increase the socket refcount during poll wait.
Take the socket lock before checking socket state.
For a listening socket return a mask independent of state SMC_ACTIVE and
cover errors or closed state as well.
Get rid of the accept_q loop in smc_accept_poll().
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
---
net/smc/af_smc.c | 74 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 34 deletions(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index cf0e11978b66..90c22a854f28 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -1122,21 +1122,15 @@ static int smc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
static unsigned int smc_accept_poll(struct sock *parent)
{
- struct smc_sock *isk;
- struct sock *sk;
-
- lock_sock(parent);
- list_for_each_entry(isk, &smc_sk(parent)->accept_q, accept_q) {
- sk = (struct sock *)isk;
+ struct smc_sock *isk = smc_sk(parent);
+ int mask = 0;
- if (sk->sk_state == SMC_ACTIVE) {
- release_sock(parent);
- return POLLIN | POLLRDNORM;
- }
- }
- release_sock(parent);
+ spin_lock(&isk->accept_q_lock);
+ if (!list_empty(&isk->accept_q))
+ mask = POLLIN | POLLRDNORM;
+ spin_unlock(&isk->accept_q_lock);
- return 0;
+ return mask;
}
static unsigned int smc_poll(struct file *file, struct socket *sock,
@@ -1147,9 +1141,15 @@ static unsigned int smc_poll(struct file *file, struct socket *sock,
struct smc_sock *smc;
int rc;
+ if (!sk)
+ return POLLNVAL;
+
smc = smc_sk(sock->sk);
+ sock_hold(sk);
+ lock_sock(sk);
if ((sk->sk_state == SMC_INIT) || smc->use_fallback) {
/* delegate to CLC child sock */
+ release_sock(sk);
mask = smc->clcsock->ops->poll(file, smc->clcsock, wait);
/* if non-blocking connect finished ... */
lock_sock(sk);
@@ -1161,37 +1161,43 @@ static unsigned int smc_poll(struct file *file, struct socket *sock,
rc = smc_connect_rdma(smc);
if (rc < 0)
mask |= POLLERR;
- else
- /* success cases including fallback */
- mask |= POLLOUT | POLLWRNORM;
+ /* success cases including fallback */
+ mask |= POLLOUT | POLLWRNORM;
}
}
- release_sock(sk);
} else {
- sock_poll_wait(file, sk_sleep(sk), wait);
- if (sk->sk_state == SMC_LISTEN)
- /* woken up by sk_data_ready in smc_listen_work() */
- mask |= smc_accept_poll(sk);
+ if (sk->sk_state != SMC_CLOSED) {
+ release_sock(sk);
+ sock_poll_wait(file, sk_sleep(sk), wait);
+ lock_sock(sk);
+ }
if (sk->sk_err)
mask |= POLLERR;
- if (atomic_read(&smc->conn.sndbuf_space) ||
- (sk->sk_shutdown & SEND_SHUTDOWN)) {
- mask |= POLLOUT | POLLWRNORM;
- } else {
- 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;
if ((sk->sk_shutdown == SHUTDOWN_MASK) ||
(sk->sk_state == SMC_CLOSED))
mask |= POLLHUP;
- if (sk->sk_shutdown & RCV_SHUTDOWN)
- mask |= POLLIN | POLLRDNORM | POLLRDHUP;
- if (sk->sk_state == SMC_APPCLOSEWAIT1)
- mask |= POLLIN;
+ if (sk->sk_state == SMC_LISTEN) {
+ /* woken up by sk_data_ready in smc_listen_work() */
+ mask = smc_accept_poll(sk);
+ } else {
+ if (atomic_read(&smc->conn.sndbuf_space) ||
+ sk->sk_shutdown & SEND_SHUTDOWN) {
+ mask |= POLLOUT | POLLWRNORM;
+ } else {
+ 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;
+ if (sk->sk_shutdown & RCV_SHUTDOWN)
+ mask |= POLLIN | POLLRDNORM | POLLRDHUP;
+ if (sk->sk_state == SMC_APPCLOSEWAIT1)
+ mask |= POLLIN;
+ }
}
+ release_sock(sk);
+ sock_put(sk);
return mask;
}
--
2.13.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 4/5] net/smc: release clcsock from tcp_listen_worker
2018-01-26 8:28 [PATCH net-next 0/5] net/smc: fixes 2018-01-26 Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 1/5] net/smc: handle device, port, and QP error events Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 2/5] net/smc: smc_poll improvements Ursula Braun
@ 2018-01-26 8:28 ` Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 5/5] net/smc: return booleans instead of integers Ursula Braun
3 siblings, 0 replies; 5+ messages in thread
From: Ursula Braun @ 2018-01-26 8:28 UTC (permalink / raw)
To: davem
Cc: netdev, linux-s390, linux-rdma, jwi, schwidefsky, heiko.carstens,
raspl, ubraun
Closing a listen socket may hit the warning
WARN_ON(sock_owned_by_user(sk)) of tcp_close(), if the wake up of
the smc_tcp_listen_worker has not yet finished.
This patch introduces smc_close_wait_listen_clcsock() making sure
the listening internal clcsock has been closed in smc_tcp_listen_work(),
before the listening external SMC socket finishes closing.
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
---
net/smc/af_smc.c | 13 ++++++++++++-
net/smc/smc_close.c | 33 ++++++++++++++++++++++++---------
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 732a37ddbc21..267e68379110 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -670,6 +670,10 @@ struct sock *smc_accept_dequeue(struct sock *parent,
smc_accept_unlink(new_sk);
if (new_sk->sk_state == SMC_CLOSED) {
+ if (isk->clcsock) {
+ sock_release(isk->clcsock);
+ isk->clcsock = NULL;
+ }
new_sk->sk_prot->unhash(new_sk);
sock_put(new_sk); /* final */
continue;
@@ -969,8 +973,15 @@ static void smc_tcp_listen_work(struct work_struct *work)
}
out:
+ if (lsmc->clcsock) {
+ sock_release(lsmc->clcsock);
+ lsmc->clcsock = NULL;
+ }
release_sock(lsk);
- lsk->sk_data_ready(lsk); /* no more listening, wake accept */
+ /* no more listening, wake up smc_close_wait_listen_clcsock and
+ * accept
+ */
+ lsk->sk_state_change(lsk);
sock_put(&lsmc->sk); /* sock_hold in smc_listen */
}
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index 4339852a8910..e339c0186dcf 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -19,6 +19,8 @@
#include "smc_cdc.h"
#include "smc_close.h"
+#define SMC_CLOSE_WAIT_LISTEN_CLCSOCK_TIME (5 * HZ)
+
static void smc_close_cleanup_listen(struct sock *parent)
{
struct sock *sk;
@@ -28,6 +30,27 @@ static void smc_close_cleanup_listen(struct sock *parent)
smc_close_non_accepted(sk);
}
+static void smc_close_wait_listen_clcsock(struct smc_sock *smc)
+{
+ DEFINE_WAIT_FUNC(wait, woken_wake_function);
+ struct sock *sk = &smc->sk;
+ signed long timeout;
+
+ timeout = SMC_CLOSE_WAIT_LISTEN_CLCSOCK_TIME;
+ add_wait_queue(sk_sleep(sk), &wait);
+ do {
+ release_sock(sk);
+ if (smc->clcsock)
+ timeout = wait_woken(&wait, TASK_UNINTERRUPTIBLE,
+ timeout);
+ sched_annotate_sleep();
+ lock_sock(sk);
+ if (!smc->clcsock)
+ break;
+ } while (timeout);
+ remove_wait_queue(sk_sleep(sk), &wait);
+}
+
/* wait for sndbuf data being transmitted */
static void smc_close_stream_wait(struct smc_sock *smc, long timeout)
{
@@ -114,7 +137,6 @@ static void smc_close_active_abort(struct smc_sock *smc)
break;
case SMC_APPCLOSEWAIT1:
case SMC_APPCLOSEWAIT2:
- sock_release(smc->clcsock);
if (!smc_cdc_rxed_any_close(&smc->conn))
sk->sk_state = SMC_PEERABORTWAIT;
else
@@ -128,7 +150,6 @@ static void smc_close_active_abort(struct smc_sock *smc)
if (!txflags->peer_conn_closed) {
/* just SHUTDOWN_SEND done */
sk->sk_state = SMC_PEERABORTWAIT;
- sock_release(smc->clcsock);
} else {
sk->sk_state = SMC_CLOSED;
}
@@ -136,8 +157,6 @@ static void smc_close_active_abort(struct smc_sock *smc)
break;
case SMC_PROCESSABORT:
case SMC_APPFINCLOSEWAIT:
- if (!txflags->peer_conn_closed)
- sock_release(smc->clcsock);
sk->sk_state = SMC_CLOSED;
break;
case SMC_PEERFINCLOSEWAIT:
@@ -177,8 +196,6 @@ int smc_close_active(struct smc_sock *smc)
switch (sk->sk_state) {
case SMC_INIT:
sk->sk_state = SMC_CLOSED;
- if (smc->smc_listen_work.func)
- cancel_work_sync(&smc->smc_listen_work);
break;
case SMC_LISTEN:
sk->sk_state = SMC_CLOSED;
@@ -187,11 +204,9 @@ int smc_close_active(struct smc_sock *smc)
rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR);
/* wake up kernel_accept of smc_tcp_listen_worker */
smc->clcsock->sk->sk_data_ready(smc->clcsock->sk);
+ smc_close_wait_listen_clcsock(smc);
}
- release_sock(sk);
smc_close_cleanup_listen(sk);
- cancel_work_sync(&smc->smc_listen_work);
- lock_sock(sk);
break;
case SMC_ACTIVE:
smc_close_stream_wait(smc, timeout);
--
2.13.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 5/5] net/smc: return booleans instead of integers
2018-01-26 8:28 [PATCH net-next 0/5] net/smc: fixes 2018-01-26 Ursula Braun
` (2 preceding siblings ...)
2018-01-26 8:28 ` [PATCH net-next 4/5] net/smc: release clcsock from tcp_listen_worker Ursula Braun
@ 2018-01-26 8:28 ` Ursula Braun
3 siblings, 0 replies; 5+ messages in thread
From: Ursula Braun @ 2018-01-26 8:28 UTC (permalink / raw)
To: davem
Cc: netdev, linux-s390, linux-rdma, jwi, schwidefsky, heiko.carstens,
raspl, ubraun
From: Gustavo A. R. Silva <gustavo@embeddedor.com>
Return statements in functions returning bool should use
true/false instead of 1/0.
This issue was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
---
net/smc/smc.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/smc/smc.h b/net/smc/smc.h
index bfbe20234105..9518986c97b1 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -252,12 +252,12 @@ static inline int smc_uncompress_bufsize(u8 compressed)
static inline bool using_ipsec(struct smc_sock *smc)
{
return (smc->clcsock->sk->sk_policy[0] ||
- smc->clcsock->sk->sk_policy[1]) ? 1 : 0;
+ smc->clcsock->sk->sk_policy[1]) ? true : false;
}
#else
static inline bool using_ipsec(struct smc_sock *smc)
{
- return 0;
+ return false;
}
#endif
--
2.13.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-01-26 8:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-26 8:28 [PATCH net-next 0/5] net/smc: fixes 2018-01-26 Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 1/5] net/smc: handle device, port, and QP error events Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 2/5] net/smc: smc_poll improvements Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 4/5] net/smc: release clcsock from tcp_listen_worker Ursula Braun
2018-01-26 8:28 ` [PATCH net-next 5/5] net/smc: return booleans instead of integers Ursula Braun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox