Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751889AbdH2Tb5 (ORCPT ); Tue, 29 Aug 2017 15:31:57 -0400 Received: from a2nlsmtp01-02.prod.iad2.secureserver.net ([198.71.225.36]:33218 "EHLO a2nlsmtp01-02.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751788AbdH2Taw (ORCPT ); Tue, 29 Aug 2017 15:30:52 -0400 x-originating-ip: 107.180.71.197 From: Long Li To: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Christoph Hellwig , Tom Talpey , Matthew Wilcox Cc: Long Li Subject: [Patch v3 18/19] CIFS: SMBD: Deregister memory when finishing SMB read Date: Tue, 29 Aug 2017 12:29:14 -0700 Message-Id: <20170829192915.26251-19-longli@exchange.microsoft.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170829192915.26251-1-longli@exchange.microsoft.com> References: <20170829192915.26251-1-longli@exchange.microsoft.com> X-CMAE-Envelope: MS4wfIh2Fs1etSV5aCTp//cYrLIIF95Y61AWTK9zJxs7MXj+vGEykDh99Lw6EAbJwcfAcVHK3fIAmXJYSeY8X1WSxMdtPGCFqBquML06cwwwmC0388AAJ3eB Tor3wpZH+iR026t3IqWnV40xkqWWR9Wq3u3VIF0ox9SCWnWULovj1WLVkIjHrgw5zdByK7GZi0grHNyL+kC9C7Td+I0MFEkhJtUW+RLWgCvT9tuDGFLd3Ro9 XYk44GXUP9uCz+rrnBvGFmfnOEPI/UJ6N1+mxOL7HL7s58FF2J1+4qZz5A7B0/rpLMP/fK2dGJXQJnU+A3iFl5B3FG53CUEAiL4SSYusnj2ZiStW19eg3XDj OA/wvTfgBTKpO593DukNu6sD86lf6Ymn4VTiHbVNpbvldeq4GamkwkDWVTR3OBCPRIZZ+n+YkHy+1ERnXr1V6qlFFYRgPS+oDf5n3DKKghhLsFXoNiFDCpQr STiHFkvEc4CLVbEQ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1561 Lines: 54 From: Long Li When SMB read is finished, deregister the memory regions if RDMA write is used for this SMB read. smbd_deregister_mr may need to do local invalidation and sleep, if server remote invalidation is not used. There are situations where the MID may not be created on I/O failure, under which memory region is deregistered when read data context is released. Signed-off-by: Long Li --- fs/cifs/file.c | 5 +++++ fs/cifs/smb2pdu.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 41460a5..5a6df25 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2910,6 +2910,11 @@ cifs_readdata_release(struct kref *refcount) struct cifs_readdata *rdata = container_of(refcount, struct cifs_readdata, refcount); + if (rdata->mr) { + smbd_deregister_mr(rdata->mr); + rdata->mr = NULL; + } + if (rdata->cfile) cifsFileInfo_put(rdata->cfile); diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 1f08c75..43a7b60 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2504,6 +2504,16 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->result = -EIO; } + /* + * If this rdata has a memmory registered, the MR can be freed + * MR needs to be freed as soon as I/O finishes to prevent deadlock + * because they have limited number and are used for future I/Os + */ + if (rdata->mr) { + smbd_deregister_mr(rdata->mr); + rdata->mr = NULL; + } + if (rdata->result) cifs_stats_fail_inc(tcon, SMB2_READ_HE); -- 2.7.4