From patchwork Mon May 7 22:20:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 10384905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E62060318 for ; Mon, 7 May 2018 22:22:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 881D128AA5 for ; Mon, 7 May 2018 22:22:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CF1C28B79; Mon, 7 May 2018 22:22:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23A7428B7A for ; Mon, 7 May 2018 22:22:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753377AbeEGWVo (ORCPT ); Mon, 7 May 2018 18:21:44 -0400 Received: from a2nlsmtp01-05.prod.iad2.secureserver.net ([198.71.225.49]:60958 "EHLO a2nlsmtp01-05.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753061AbeEGWVl (ORCPT ); Mon, 7 May 2018 18:21:41 -0400 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id FoUqfFkdVHUQCFoUqfKVhe; Mon, 07 May 2018 15:20:40 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.89_1) (envelope-from ) id 1fFoUq-0005QM-Ji; Mon, 07 May 2018 15:20:40 -0700 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 Cc: Long Li Subject: [PATCH 5/7] cifs: smbd: Protect memory registration using RCU Date: Mon, 7 May 2018 15:20:04 -0700 Message-Id: <20180507222006.20781-5-longli@linuxonhyperv.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180507222006.20781-1-longli@linuxonhyperv.com> References: <20180507222006.20781-1-longli@linuxonhyperv.com> Reply-To: longli@microsoft.com X-CMAE-Envelope: MS4wfEeXLCCZzDJVI+Otos8+83JuGgCZsKXFXKajynRtz11DXItDlP+WWcIN4DyltSGUTqJaUfGPRrnyzGFSf2zmcvUTrRrue7/fhe7JicFKNf/zRqKJ/VbA RYltrYR5TbwdLhIw32Lo7MyP0ZXQA4ZxCKXRhteisBIGWjXkCEkkJDfRdhb6wkMAiqRB0eNGDFSQXPKiYbYxuIxx4Uqa5Abmg6q/uQc3d0SeS1YNVBPDfq7d Bjxr4zB+GlDlArQSeGwVdpoU/XJMHa4AY7lV0/JIBxH74Sm3ALnenrlKlMwGX+F6VHwwp7adVyL6GgpGbgs0WhEppiBciDXTfXgFdDgGv1RKTX5ZGFaLPKR9 pJeEHeo3gN08SAq6Q8hTZ8eJpwouYvPiKhD/ViHXEChwUWB6E12rihbdcxWiHwIe85dgbpI6 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Long Li Unlike packet I/O sending path, the memory registration is not locked. They need to be protected when doing transport reconnect or shutdown. It's not necessary to lock for memory deregistration, since at the time the transport is already destroyed so it's impossible to pick up the wrong transport. Signed-off-by: Long Li --- fs/cifs/smb2pdu.c | 6 ++++++ fs/cifs/smbdirect.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 8cd164e..09ca098 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2609,10 +2609,13 @@ smb2_new_read_req(void **buf, unsigned int *total_len, bool need_invalidate = io_parms->tcon->ses->server->dialect == SMB30_PROT_ID; + rcu_read_lock(); + rcu_dereference(server->smbd_conn); rdata->mr = smbd_register_mr( server->smbd_conn, rdata->pages, rdata->nr_pages, rdata->tailsz, true, need_invalidate); + rcu_read_unlock(); if (!rdata->mr) return -ENOBUFS; @@ -2986,10 +2989,13 @@ smb2_async_writev(struct cifs_writedata *wdata, struct smbd_buffer_descriptor_v1 *v1; bool need_invalidate = server->dialect == SMB30_PROT_ID; + rcu_read_lock(); + rcu_dereference(server->smbd_conn); wdata->mr = smbd_register_mr( server->smbd_conn, wdata->pages, wdata->nr_pages, wdata->tailsz, false, need_invalidate); + rcu_read_unlock(); if (!wdata->mr) { rc = -ENOBUFS; goto async_writev_out; diff --git a/fs/cifs/smbdirect.c b/fs/cifs/smbdirect.c index 74620f5..8c46898 100644 --- a/fs/cifs/smbdirect.c +++ b/fs/cifs/smbdirect.c @@ -1482,6 +1482,9 @@ void smbd_destroy(struct TCP_Server_Info *server) info->transport_status = SMBD_DESTROYED; + rcu_assign_pointer(server->smbd_conn, NULL); + synchronize_rcu(); + destroy_workqueue(info->workqueue); kfree(info); }