From patchwork Tue Apr 22 11:22:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shamir Rabinovitch X-Patchwork-Id: 4031111 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 48A52BFF02 for ; Tue, 22 Apr 2014 11:22:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5AE1520211 for ; Tue, 22 Apr 2014 11:22:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BE4820260 for ; Tue, 22 Apr 2014 11:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932250AbaDVLWO (ORCPT ); Tue, 22 Apr 2014 07:22:14 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:30627 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932096AbaDVLWN (ORCPT ); Tue, 22 Apr 2014 07:22:13 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s3MBMCEq001874 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Apr 2014 11:22:12 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3MBMBj6017292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 22 Apr 2014 11:22:12 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3MBMB2C017285 for ; Tue, 22 Apr 2014 11:22:11 GMT Received: from shamir-pc (/10.175.51.110) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 22 Apr 2014 04:22:11 -0700 Date: Tue, 22 Apr 2014 14:22:06 +0300 From: shamir rabinovitch To: linux-rdma@vger.kernel.org Subject: [PATCH] librdmacm: Fix verbs leak due to reentrancy issue Message-ID: <20140422112202.GA7440@shamir-pc> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Sean, I was out of work so I tested the patch "librdmacm: lazy initialization for ib devices" today. The patch works fine for my test case. The only concern I have is that I think the patch might leak verbs context. I think that any call to ucma_init_device must be done with mutex locked. Please correct me if I am wrong. Thanks, Shamir Signed-off-by: shamir rabinovitch --- src/cma.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cma.c b/src/cma.c index 0dc229e..42769cf 100644 --- a/src/cma.c +++ b/src/cma.c @@ -416,10 +416,13 @@ static int ucma_get_device(struct cma_id_private *id_priv, uint64_t guid) return ERR(ENODEV); match: - if ((ret = ucma_init_device(cma_dev))) + pthread_mutex_lock(&mut); + + if ((ret = ucma_init_device(cma_dev))) { + pthread_mutex_unlock(&mut); return ret; + } - pthread_mutex_lock(&mut); if (!cma_dev->refcnt++) { cma_dev->pd = ibv_alloc_pd(cma_dev->verbs); if (!cma_dev->pd) {