From patchwork Thu Jul 17 14:01:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 4575901 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2394B9F1D6 for ; Thu, 17 Jul 2014 14:39:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 34E2D20122 for ; Thu, 17 Jul 2014 14:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44B052017D for ; Thu, 17 Jul 2014 14:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932880AbaGQOje (ORCPT ); Thu, 17 Jul 2014 10:39:34 -0400 Received: from cmexedge2.ext.emulex.com ([138.239.224.100]:40434 "EHLO CMEXEDGE2.ext.emulex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933064AbaGQOjS (ORCPT ); Thu, 17 Jul 2014 10:39:18 -0400 Received: from CMEXHTCAS2.ad.emulex.com (138.239.115.218) by CMEXEDGE2.ext.emulex.com (138.239.224.100) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 17 Jul 2014 07:39:21 -0700 Received: from neo01-el64.lab.bg.emulex.com (10.192.204.8) by smtp.emulex.com (138.239.115.208) with Microsoft SMTP Server id 14.3.174.1; Thu, 17 Jul 2014 07:38:59 -0700 From: Devesh Sharma To: CC: , Devesh Sharma Subject: [for-next 1/2] xprtrdma: take reference of rdma provider module Date: Thu, 17 Jul 2014 19:31:36 +0530 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1405605697-11583-1-git-send-email-devesh.sharma@emulex.com> References: <1405605697-11583-1-git-send-email-devesh.sharma@emulex.com> MIME-Version: 1.0 Message-ID: <3e39e90f-7095-4eb9-a844-516672a355ad@CMEXHTCAS2.ad.emulex.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If verndor driver is attempted for removal while xprtrdma still has an active mount, the removal of driver may never complete and can cause unseen races or in worst case system crash. To solve this, xprtrdma module should get reference of struct ib_device structure for every mount. Reference is taken after local device address resolution is completed successfuly. reference to the struct ib_device pointer is put just before cm_id destruction. Signed-off-by: Devesh Sharma --- net/sunrpc/xprtrdma/verbs.c | 17 +++++++++++++++-- net/sunrpc/xprtrdma/xprt_rdma.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 6ead5df..b00e55e 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -457,6 +457,11 @@ rpcrdma_create_id(struct rpcrdma_xprt *xprt, } wait_for_completion_interruptible_timeout(&ia->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1); + if (!ia->ri_async_rc && !try_module_get(id->device->owner)) { + dprintk("RPC: %s: Failed to get device module\n", + __func__); + ia->ri_async_rc = -ENODEV; + } rc = ia->ri_async_rc; if (rc) goto out; @@ -466,16 +471,18 @@ rpcrdma_create_id(struct rpcrdma_xprt *xprt, if (rc) { dprintk("RPC: %s: rdma_resolve_route() failed %i\n", __func__, rc); - goto out; + goto out_put; } wait_for_completion_interruptible_timeout(&ia->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1); rc = ia->ri_async_rc; if (rc) - goto out; + goto out_put; return id; +out_put: + module_put(id->device->owner); out: rdma_destroy_id(id); return ERR_PTR(rc); @@ -613,6 +620,7 @@ rpcrdma_ia_open(struct rpcrdma_xprt *xprt, struct sockaddr *addr, int memreg) rwlock_init(&ia->ri_qplock); return 0; out2: + module_put(ia->ri_id->device->owner); rdma_destroy_id(ia->ri_id); ia->ri_id = NULL; out1: @@ -638,9 +646,11 @@ rpcrdma_ia_close(struct rpcrdma_ia *ia) if (ia->ri_id != NULL && !IS_ERR(ia->ri_id)) { if (ia->ri_id->qp) rdma_destroy_qp(ia->ri_id); + module_put(ia->ri_id->device->owner); rdma_destroy_id(ia->ri_id); ia->ri_id = NULL; } + if (ia->ri_pd != NULL && !IS_ERR(ia->ri_pd)) { rc = ib_dealloc_pd(ia->ri_pd); dprintk("RPC: %s: ib_dealloc_pd returned %i\n", @@ -886,6 +896,7 @@ retry: if (ia->ri_id->device != id->device) { printk("RPC: %s: can't reconnect on " "different device!\n", __func__); + module_put(id->device->owner); rdma_destroy_id(id); rc = -ENETUNREACH; goto out; @@ -895,6 +906,7 @@ retry: if (rc) { dprintk("RPC: %s: rdma_create_qp failed %i\n", __func__, rc); + module_put(id->device->owner); rdma_destroy_id(id); rc = -ENETUNREACH; goto out; @@ -906,6 +918,7 @@ retry: write_unlock(&ia->ri_qplock); rdma_destroy_qp(old); + module_put(old->device->owner); rdma_destroy_id(old); } else { dprintk("RPC: %s: connecting...\n", __func__); diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h index c419498..b35fa21 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -44,6 +44,7 @@ #include /* spinlock_t, etc */ #include /* atomic_t, etc */ #include /* struct work_struct */ +#include /* try_module_get()/module_put() */ #include /* RDMA connection api */ #include /* RDMA verbs api */