From e8f879bf372d48d2fce0fd28191c9c59fc84e833 Mon Sep 17 00:00:00 2001 From: Eldad Zinger Date: Tue, 12 Oct 2010 10:22:05 +0200 Subject: [PATCH] sdp: ZCopy doesn't support multithreading - warning & kernel panic protection Correspond to BUG 2147. Signed-off-by: Eldad Zinger --- drivers/infiniband/ulp/sdp/sdp_main.c | 1 + drivers/infiniband/ulp/sdp/sdp_zcopy.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/ulp/sdp/sdp_main.c b/drivers/infiniband/ulp/sdp/sdp_main.c index ac8fc1c90575..43e18d769f6d 100644 --- a/drivers/infiniband/ulp/sdp/sdp_main.c +++ b/drivers/infiniband/ulp/sdp/sdp_main.c @@ -1927,6 +1927,7 @@ static int sdp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, sdp_dbg_data(sk, "%s size = 0x%zx\n", __func__, size); posts_handler_get(ssk); + SDP_WARN_ON(ssk->tx_sa); flags = msg->msg_flags; timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); diff --git a/drivers/infiniband/ulp/sdp/sdp_zcopy.c b/drivers/infiniband/ulp/sdp/sdp_zcopy.c index 5f975c578f19..6cdfc9644eb7 100644 --- a/drivers/infiniband/ulp/sdp/sdp_zcopy.c +++ b/drivers/infiniband/ulp/sdp/sdp_zcopy.c @@ -55,7 +55,17 @@ static int sdp_post_srcavail(struct sock *sk, struct tx_srcavail_state *tx_sa) int off, len; struct ib_umem_chunk *chunk; - SDP_WARN_ON(ssk->tx_sa); + if (ssk->tx_sa) { + /* ssk->tx_sa might already be there in a case of + * multithreading: user thread initiated Zcopy and went to + * sleep, and now another user thread tries to ZCopy. + * Fallback to BCopy - data might be mixed. + * TODO: Fix it. fallback to BCopy is not enough because recv + * side has seq warnings. + */ + sdp_dbg_data(sk, "user already initiated ZCopy transmission\n"); + return -EAGAIN; + } BUG_ON(!tx_sa); BUG_ON(!tx_sa->fmr || !tx_sa->fmr->fmr->lkey); @@ -644,7 +654,7 @@ static int do_sdp_sendmsg_zcopy(struct sock *sk, struct tx_srcavail_state *tx_sa rc = sdp_post_srcavail(sk, tx_sa); if (unlikely(rc)) { - sdp_dbg(sk, "Error posting SrcAvail\n"); + sdp_dbg(sk, "Error posting SrcAvail: %d\n", rc); goto err_abort_send; } -- 2.50.1