From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795990389; b=cQoc+MCuXUmFtnXsUpilhbYBuhR1uujcjDLQLTppkxDRYEG6s1uqwyAOuAqLtfVNmvIa 5iU1qmlyGPjjoTWlA+pz3zb1lIIWsWqEI0cJnImHkbduZODZ0r6AeArV0Vn5F/LcDkVi3 NKh9f0zxJ4dkBaBPKFZrz9yXGB+OoyaN5jRSJexDrEev/5mEIkvJQ1w9SzKW/3X4lc8Kb TInqBfjhqh2RQrsc2b1zj/Li27nTOY4loeZeiY0Klv3G44Az8pS30oKCJwRT6m1PYgfVg My+EiOTZBdGcB9uiHhbvpaeibeSCHPV0DL1wlvAyApe0XrhRyphb4zNEGDueCnGOsuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795990389; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=cfMR1BGMakHlkTt5sRrodvjaQPofLCO2w+qtffXL1fk=; b=AfOg550oyRJZHYarwrjbAR7K050PbL3AtBiyTxNpbMwmGpLmdsS8erhyyeXIACgO3Tpt XdX7gDTbWrDeWGsvtEdirercldox/er5dqYWzgkShIJB2wnLGAEf42EQ6A0j1+sW5ixUr Z2xwbGU54q9yohaMSFEEUfnf/+eEAz6KbRKOOmcdzacwsUOH8ZnLybCfXIJsV1N1R+RW5 0pNBCD1v0CPuUmn/yrj3SAsHWkuqjp7wA316a+1Qrdq9IRhFRktrKSAM+HQI4rldMib1s LjXQpmuvdi3S+aBp0DYNz0Pn8j0uMlAXGHhx6h1J+PD2TxOXMCNCCVOb58jQXm7b/1A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eY4skEhi; arc=none smtp.remote-ip=209.85.161.46 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF221606A325 for ; Sun, 29 Nov 2026 22:13:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF221606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eY4skEhi Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-71aea92f666so6323482eaf.2 for ; Sun, 29 Nov 2026 14:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795990388; x=1796595188; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=cfMR1BGMakHlkTt5sRrodvjaQPofLCO2w+qtffXL1fk=; b=eY4skEhikMu+6CU/z6wkTodfnIGzP3+6ezMPRr1xaelSBYvAKZqwNZg74Pa1zNK3es PfuRtqkx89j3Y7Vugpx0h+5URfpyyAzb0s5Uz7kCGjFLXGwgQyslFhkL7Ac2YJ9FJup5 ScieYGx69nf+E2igVNIY4OMaefH8D3ET5GJgmuBCaZ+y0JbKK9A/guYjBtLHlDYv7ktZ hXOaS9ejDOXQTz4sRRckYgHWxNfO5QL+kLFG2CxIqNHabSuVdTgEotK6oEHJUe1HPzDc BsW5XipDJsJ2CqRvHnJyz6Sw9as1Gn3ywqZELgk4uFIMRXGIfl8RwMVUK5IruXCSFVuo +g/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795990388; x=1796595188; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cfMR1BGMakHlkTt5sRrodvjaQPofLCO2w+qtffXL1fk=; b=voO7wIeBO1P0JDD9TWYSMr6e803RRu9Let3md0G9XiBcdlreupNxm+nXyPMbgYtFJm LzQG+Rg0lWkwKzAUVseNyaSRDE7WwgABPKxhiaaCBuPgyneSe84nb/ze28Cp9lWKrr+i AMWNVermcnRKDPHYsXDz/B+uMHQhBSWYzQ7B2rBb1WLNP5I+AXo+D00jOGlvA7SUlRgV aAKXQh5210jGox+rNiUDY9Juy3qplPGiKNCOGGiaSekvUKC6BoalvhS2Mc3teYkVBxI+ v5pMeoROL2mZOaAky7jmaJB4SymNSms/VQPcypcg+bVPa3bPSTz++lDOQDBbuBd6HWKY DLSg== X-Forwarded-Encrypted: i=1; AL+hErEC8KfXEoME2jnMOv2/PAe1gtMmAvR7kqz6rrMI0mfHduAYbWs+4GZpPEw59Yj5mprjID2sy3N6LHQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/JBV6RxIGkqK0ZdjpVpzxlXMLaG3Kxgz+rsmb5VDhFDAqU0HZT woQcKd+uervpK5txDzFychDym6Ur+HWxu/kk7xlwJFYu8sP5HZbr7qQ= X-Gm-Gg: AZFdTZfGIqwD+z29hg91HnN2Ruu1fsRgBmQ5RWqYGdxdh3IJdMksHC9DR9T5EY2maDj Ci1KM3qAxGcs6I0idIe0fveN0B8h4upzr8l+W3xRv8j434yNq+vBYlvmrxBQmc3J9Qbf8meSJ/Z St9e0mpte4d0V+80eGGu7BwInlggQzdynVtymEUeC3KtMyDqfP9G5A849NatIrG2mGYGwb8ZNhJ qyyEC14/ceQ4CInZjBS3tZM+bt2B2Y3oefYE3p0rct6sRaExC9AR1+D2jJ6eL0s7T4BBipTVKqa JYCHUIspiQOVFLs/8dVTptPBeOfq0Ntl4iAiNzkJnsqlQ+o9+xCRISoE9GTogagiAY4k1g4b98r 0Ynr6qqQPaGn4M/Nw8alNguEIsDBQ/Nti6+jTUat29AQAkpMZEwFLUc/3cqq4EnxLcbgeppCZI6 Glc2BkXHwIYP74BMACm1Weh8HCo5ImkgniGfRwvE06cDV9w+CeHFf1owBzDAUrUwUKaf1Bev6W+ QET50F8/PV8dyeajMtfU9HmfaLPK5q8aUweCq0lSnQK8ntJ5lWgJm8QBsxBYbRLiQf0JRjcDrJs kno509iOheuDDPA6gjcizgO7jl+7uuTZ9zh/GeOXTS38d699NAlWmUuQbRYh7N51eLVxhCnxClr 3H7hszkrliK+lEP0LRc9stllSTFQGRpgWb7mEqdmccd68+XMccyB0VPlPq7AJHa3Sj8Tl5HxPfh Thy8P9rbnDkDUG X-Received: by 2002:a4a:ec44:0:b0:703:4766:16c with SMTP id 006d021491bc7-71b3929439cmr26712960eaf.1.1795990387589; Sun, 29 Nov 2026 14:13:07 -0800 (PST) Received: from [192.168.75.157] (162-232-235-235.lightspeed.livnmi.sbcglobal.net. [162.232.235.235]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc6108104esm26623482fac.14.2026.11.29.14.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 14:13:06 -0800 (PST) Message-ID: <308f5aff56453bbaaff95d79a1cd78e45f0dc93b.camel@gmail.com> Subject: Re: [PATCH v3 3/3] xprtrdma: Wake connect worker on device removal From: Trond Myklebust To: lixiasong1@huawei.com Cc: cel@kernel.org, jlayton@kernel.org, neil@brown.name, okorniev@redhat.com, Dai.Ngo@oracle.com, tom@talpey.com, anna@kernel.org, linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org, stable@vger.kernel.org, yuehaibing@huawei.com, zhangchangzhong@huawei.com, weiyongjun1@huawei.com Date: Sun, 29 Nov 2026 17:13:03 -0500 In-Reply-To: <20261124021842.130141-4-lixiasong1@huawei.com> References: <20261124021842.130141-4-lixiasong1@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Tue, 24 Nov 2026 10:18:42 +0800, Li Xiasong wrote: > diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c > index b8dfdabd8a5a..1f2a3cea073f 100644 > --- a/net/sunrpc/xprtrdma/verbs.c > +++ b/net/sunrpc/xprtrdma/verbs.c [ ... ] > case RDMA_CM_EVENT_ESTABLISHED: > - rpcrdma_ep_get(ep); > - ep->re_connect_status =3D 1; > + if (READ_ONCE(ep->re_connect_status)) > + return 0; > rpcrdma_update_cm_private(ep, &event->param.conn); [ ... ] > case RDMA_CM_EVENT_DISCONNECTED: > - ep->re_connect_status =3D -ECONNABORTED; > - rpcrdma_force_disconnect(ep); > - return rpcrdma_ep_put(ep); > + rpcrdma_ep_disconnect(ep, -ECONNABORTED, true); > + return 0; [ ... ] > @@ -369,6 +385,7 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt, > static void rpcrdma_ep_destroy(struct kref *kref) > { > struct rpcrdma_ep *ep =3D container_of(kref, struct rpcrdma_ep, re_kref); > + struct ib_device *device =3D ep->re_id->device; > =20 > if (ep->re_id->qp) { > rdma_destroy_qp(ep->re_id); With the ESTABLISHED reference gone, rdma_destroy_qp() now runs from rpcrdma_xprt_disconnect() right after rdma_disconnect() and the drain, while the connection is still closing. On iWARP devices, can this block until the iWARP close completes? rdma_disconnect() starts a graceful close there with iw_cm_disconnect(id, 0), and the iw_cm holds a QP reference from iw_cm_connect() until the IW_CM_EVENT_CLOSE upcall or iw_destroy_cm_id(): drivers/infiniband/core/iwcm.c:iw_cm_connect() { ... cm_id->device->ops.iw_add_ref(qp); cm_id_priv->qp =3D qp; ... } Provider destroy paths wait for that reference, for example: drivers/infiniband/hw/cxgb4/qp.c:c4iw_destroy_qp() { ... c4iw_qp_rem_ref(ib_qp); wait_for_completion(&qhp->qp_rel_comp); ... } rdma_destroy_id() would drop the iw_cm reference, but it now runs after rdma_destroy_qp(): xprt_autoclose() xprt_rdma_close() rpcrdma_xprt_disconnect() <- takes rx_unmap_rwsem for write rdma_disconnect() <- graceful iWARP close starts rpcrdma_xprt_drain() rpcrdma_ep_put() rpcrdma_ep_destroy() rdma_destroy_qp() c4iw_destroy_qp() <- waits for IW_CM_EVENT_CLOSE rdma_destroy_id() On cxgb4 the close upcall arrives when the peer completes the TCP close, or from the endpoint timer (ep_timeout_secs, 60 seconds by default) when the peer does not answer. XPRT_LOCKED and rx_unmap_rwsem stay held for that time, so reconnects and frwr_unmap_sync() wait as well. Before this patch, the DISCONNECTED handler made the final put after cm_close_handler() had already dropped the iw_cm QP reference. Commit e28ce90083f0 ("xprtrdma: kmalloc rpcrdma_ep separate from rpcrdma_xprt") describes that as intended: Change the rpcrdma_xprt_disconnect() function so that it no longer waits for the DISCONNECTED event. This prevents blocking if the remote is unresponsive. Is the synchronous wait on iWARP intended? IB and RoCE do not appear to be affected, since cm_destroy_id() cancels an outstanding DREQ and enters timewait without waiting for the DREP. [ ... ] I've kept 1/3 and 2/3 in my testing branch, but dropped this one for now. On Mon, Nov 23, 2026 08:53 PM, Li Xiasong wrote: > Device removal only forces a transport disconnect, leaving a connect > worker asleep while re_connect_status is zero and blocking endpoint > cleanup. >=20 > Set -ENODEV and wake pending connects on removal. Give -ENODEV > precedence over other failures so late CM events cannot mask device > removal. Force established connections to disconnect and use atomic > transitions to prevent late ESTABLISHED events from overwriting > errors. > Handle REJECTED with an atomic status update. Wake the connect worker > if the connection is still pending, or force an established > connection > to disconnect without relying on CQ flushes. >=20 > The final endpoint put can free id->context before rdma_destroy_id() > synchronizes with CM callbacks. Destroy the CM ID in the endpoint > destructor before freeing its context to close this window. Remove > the > CM callback get/put pairs so final puts occur outside CM callbacks. > Initialize the connect waitqueue before notification registration. >=20 > If transport pinning fails, fail and wake a pending connect under the > device mutex before skipping the notification. The final transport > put > can be waiting for that worker to release XPRT_LOCKED. >=20 > Translate -ENODEV from the connection status to -ENOTCONN so pending > RPCs retry on a hard mount when the device disappears during setup. >=20 > Fixes: 3f4eb9ff9234 ("xprtrdma: Handle device removal outside of the > CM event handler") > Signed-off-by: Li Xiasong > --- > =C2=A0net/sunrpc/xprtrdma/transport.c |=C2=A0 =C2=A02 +- > =C2=A0net/sunrpc/xprtrdma/verbs.c=C2=A0 =C2=A0 =C2=A0| 120 ++++++++++++++= ++++++---------- > -- > =C2=A02 files changed, 75 insertions(+), 47 deletions(-) >=20 > diff --git a/net/sunrpc/xprtrdma/transport.c > b/net/sunrpc/xprtrdma/transport.c > index e38637c2ec78..88bf9c9d9cf5 100644 > --- a/net/sunrpc/xprtrdma/transport.c > +++ b/net/sunrpc/xprtrdma/transport.c > @@ -488,7 +488,7 @@ xprt_rdma_connect(struct rpc_xprt *xprt, struct > rpc_task *task) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, r= _xprt)); >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 delay =3D 0; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ep && ep->re_connect_status !=3D 0) { > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ep && READ_ONCE(ep->re_connect_status)) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 delay =3D xprt_re= connect_delay(xprt); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 xprt_reconnect_ba= ckoff(xprt, RPCRDMA_INIT_REEST_TO); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > diff --git a/net/sunrpc/xprtrdma/verbs.c > b/net/sunrpc/xprtrdma/verbs.c > index b8dfdabd8a5a..1f2a3cea073f 100644 > --- a/net/sunrpc/xprtrdma/verbs.c > +++ b/net/sunrpc/xprtrdma/verbs.c > @@ -75,7 +75,7 @@ static void rpcrdma_reps_unmap(struct rpcrdma_xprt > *r_xprt); > =C2=A0static void rpcrdma_mrs_create(struct rpcrdma_xprt *r_xprt); > =C2=A0static void rpcrdma_mrs_destroy(struct rpcrdma_xprt *r_xprt); > =C2=A0static void rpcrdma_ep_get(struct rpcrdma_ep *ep); > -static int rpcrdma_ep_put(struct rpcrdma_ep *ep); > +static void rpcrdma_ep_put(struct rpcrdma_ep *ep); > =C2=A0static struct rpcrdma_regbuf * > =C2=A0rpcrdma_regbuf_alloc_node(size_t size, enum dma_data_direction > direction, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 int node); > @@ -124,6 +124,23 @@ void rpcrdma_force_disconnect(struct rpcrdma_ep > *ep) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 xprt_force_discon= nect(ep->re_xprt); > =C2=A0} >=20 > +/* Device removal takes precedence over other connection failures. > */ > +static void rpcrdma_ep_disconnect(struct rpcrdma_ep *ep, int status, > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool force_disconnect) > +{ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0int old =3D READ_ONCE(ep->re_connect_status); > + > +=C2=A0 =C2=A0 =C2=A0 =C2=A0do { > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (old =3D=3D -E= NODEV || (old < 0 && status !=3D -ENODEV)) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0} while (!try_cmpxchg(&ep->re_connect_status,= &old, status)); > + > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!old) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0wake_up_all(&ep->= re_connect_wait); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0else if (old =3D=3D 1 && force_disconnect) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_force_dis= connect(ep); > +} > + > =C2=A0/** > =C2=A0 * rpcrdma_flush_disconnect - Disconnect on flushed completion > =C2=A0 * @r_xprt: transport to disconnect > @@ -222,13 +239,14 @@ static void rpcrdma_update_cm_private(struct > rpcrdma_ep *ep, > =C2=A0 * @id: rdma_cm_id on which an event has occurred > =C2=A0 * @event: details of the event > =C2=A0 * > - * Called with @id's mutex held. Returns 1 if caller should > - * destroy @id, otherwise 0. > + * Called with @id's mutex held. Always returns 0: the endpoint > owner > + * destroys @id and waits for these callbacks before freeing @id's > context. > =C2=A0 */ > =C2=A0static int > =C2=A0rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_even= t > *event) > =C2=A0{ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct rpcrdma_ep *ep =3D id->context; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0int status; >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 might_sleep(); >=20 > @@ -247,41 +265,32 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, > struct rdma_cm_event *event) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 complete(&ep->re_= done); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 case RDMA_CM_EVENT_ADDR_CHANGE: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0switch (xchg(&ep-= >re_connect_status, -ENODEV)) { > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0case 0: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0goto wake_connect_worker; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0case 1: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0/* The later DISCONNECTED event balances the > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 * ESTABLISHED get; do not put here. > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 */ > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0rpcrdma_force_disconnect(ep); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return 0; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_discon= nect(ep, -ENODEV, true); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 case RDMA_CM_EVENT_ESTABLISHED: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_get(ep= ); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ep->re_connect_st= atus =3D 1; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (READ_ONCE(ep-= >re_connect_status)) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rpcrdma_update_cm= _private(ep, &event->param.conn); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (cmpxchg(&ep->= re_connect_status, 0, 1)) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 trace_xprtrdma_in= line_thresh(ep); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wake_up_all(&ep->= re_connect_wait); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 case RDMA_CM_EVENT_CONNECT_ERROR: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ep->re_connect_st= atus =3D -ENOTCONN; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto wake_connect= _worker; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_discon= nect(ep, -ENOTCONN, true); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 case RDMA_CM_EVENT_UNREACHABLE: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ep->re_connect_st= atus =3D -ENETUNREACH; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto wake_connect= _worker; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_discon= nect(ep, -ENETUNREACH, true); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 case RDMA_CM_EVENT_REJECTED: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ep->re_connect_st= atus =3D -ECONNREFUSED; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0status =3D -ECONN= REFUSED; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (event->status= =3D=3D IB_CM_REJ_STALE_CONN) > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0ep->re_connect_status =3D -ENOTCONN; > -wake_connect_worker: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0wake_up_all(&ep->= re_connect_wait); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0status =3D -ENOTCONN; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_discon= nect(ep, status, true); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 case RDMA_CM_EVENT_DISCONNECTED: > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ep->re_connect_st= atus =3D -ECONNABORTED; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_force_dis= connect(ep); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return rpcrdma_ep= _put(ep); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_discon= nect(ep, -ECONNABORTED, true); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 default: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > @@ -308,11 +317,18 @@ static void rpcrdma_ep_removal_done(struct > rpcrdma_notification *rn, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* for the connect worker, which may nee= d the mutex to > unregister. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 xprt =3D xprt_get(ep->re_xprt); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!xprt) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!xprt) { > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * The final xprt= _put() can be waiting for the > connect worker's > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * XPRT_LOCKED bi= t. The device mutex protects @ep > until > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * unregister. Wa= ke pending connects without using > the transport. > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_discon= nect(ep, -ENODEV, false); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 release->release =3D rpcrdma_xprt_removal_put= ; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 release->data =3D xprt; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_force_disconnect(ep); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_disconnect(ep, -ENODEV, true); > =C2=A0} >=20 > =C2=A0static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt > *r_xprt, > @@ -369,6 +385,7 @@ static struct rdma_cm_id > *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt, > =C2=A0static void rpcrdma_ep_destroy(struct kref *kref) > =C2=A0{ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct rpcrdma_ep *ep =3D container_of(kref, = struct rpcrdma_ep, > re_kref); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0struct ib_device *device =3D ep->re_id->devic= e; >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ep->re_id->qp) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rdma_destroy_qp(e= p->re_id); > @@ -386,7 +403,14 @@ static void rpcrdma_ep_destroy(struct kref > *kref) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ib_dealloc_pd(ep-= >re_pd); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep->re_pd =3D NULL; >=20 > -=C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_rn_unregister(ep->re_id->device, &ep-= >re_rn); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Removal callbacks also access re_id, inclu= ding from > tracepoints. */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_rn_unregister(device, &ep->re_rn); > + > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 * All puts occur outside CM callbacks. Fence= queued and > running > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 * callbacks before freeing the context, even= if no > connection formed. > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0rdma_destroy_id(ep->re_id); >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 kfree(ep); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 module_put(THIS_MODULE); > @@ -397,13 +421,10 @@ static noinline void rpcrdma_ep_get(struct > rpcrdma_ep *ep) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 kref_get(&ep->re_kref); > =C2=A0} >=20 > -/* Returns: > - *=C2=A0 =C2=A0 =C2=A0%0 if @ep still has a positive kref count, or > - *=C2=A0 =C2=A0 =C2=A0%1 if @ep was destroyed successfully. > - */ > -static noinline int rpcrdma_ep_put(struct rpcrdma_ep *ep) > +/* Must not be called from an RDMA CM event handler. */ > +static noinline void rpcrdma_ep_put(struct rpcrdma_ep *ep) > =C2=A0{ > -=C2=A0 =C2=A0 =C2=A0 =C2=A0return kref_put(&ep->re_kref, rpcrdma_ep_dest= roy); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0kref_put(&ep->re_kref, rpcrdma_ep_destroy); > =C2=A0} >=20 > =C2=A0static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) > @@ -419,6 +440,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt > *r_xprt) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -ENOTCONN; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep->re_xprt =3D &r_xprt->rx_xprt; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 kref_init(&ep->re_kref); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0init_waitqueue_head(&ep->re_connect_wait); >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 id =3D rpcrdma_create_id(r_xprt, ep); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (IS_ERR(id)) { > @@ -446,7 +468,6 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt > *r_xprt) >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep->re_send_batch =3D ep->re_max_requests >> = 3; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep->re_send_count =3D ep->re_send_batch; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0init_waitqueue_head(&ep->re_connect_wait); >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep->re_attr.send_cq =3D ib_alloc_cq_any(devic= e, r_xprt, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 ep- > >re_attr.cap.max_send_wr, > @@ -514,7 +535,6 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt > *r_xprt) >=20 > =C2=A0out_destroy: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 rpcrdma_ep_put(ep); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0rdma_destroy_id(id); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 return rc; > =C2=A0} >=20 > @@ -550,12 +570,17 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt > *r_xprt) >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (xprt->reestablish_timeout < RPCRDMA_INIT_= REEST_TO) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 xprt->reestablish= _timeout =3D RPCRDMA_INIT_REEST_TO; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0wait_event_interruptible(ep->re_connect_wait, > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep->re_connect_status !=3D 0); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ep->re_connect_status <=3D 0) { > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rc =3D ep->re_con= nect_status; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0rc =3D wait_event_interruptible(ep->re_connec= t_wait, > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0READ_ONCE(ep- > >re_connect_status)); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rc) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* The ESTABLISHED cmpxchg publishes the nego= tiated CM > parameters. */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0rc =3D smp_load_acquire(&ep->re_connect_statu= s); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Let pending RPC tasks retry after the devi= ce disappears. > */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rc =3D=3D -ENODEV) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rc =3D -ENOTCONN; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rc < 0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto out; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0} >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D rpcrdma_sendctxs_create(r_xprt); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (rc) { > @@ -622,8 +647,11 @@ void rpcrdma_xprt_disconnect(struct rpcrdma_xprt > *r_xprt) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 rpcrdma_reqs_reset(r_xprt); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 rpcrdma_mrs_destroy(r_xprt); >=20 > -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rpcrdma_ep_put(ep)) > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rdma_destroy_id(i= d); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0/* > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 * The destructor destroys the CM ID, fencing= any callback > still > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 * returning before the endpoint context is f= reed. > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 */ > +=C2=A0 =C2=A0 =C2=A0 =C2=A0rpcrdma_ep_put(ep); >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 r_xprt->rx_ep =3D NULL; >=20 > @@ -920,7 +948,7 @@ void rpcrdma_mrs_refresh(struct rpcrdma_xprt > *r_xprt) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* If there is no underlying connection, it's= no use > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* to wake the refresh worker. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/ > -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (ep->re_connect_status !=3D 1) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0if (READ_ONCE(ep->re_connect_status) !=3D 1) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 queue_work(system_highpri_wq, &buf->rb_refres= h_worker); > =C2=A0} > --=20 > 2.34.1 >=20 >=20 --=20 Trond Myklebust Linux NFS client maintainer, Hammerspace trondmy@kernel.org, trond.myklebust@hammerspace.com