From patchwork Fri Dec 8 19:02:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan Tan X-Patchwork-Id: 10103187 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 47DA360325 for ; Fri, 8 Dec 2017 19:03:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3683828EB5 for ; Fri, 8 Dec 2017 19:03:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B64828ED1; Fri, 8 Dec 2017 19:03:13 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 6ED2C28EB5 for ; Fri, 8 Dec 2017 19:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752498AbdLHTDL (ORCPT ); Fri, 8 Dec 2017 14:03:11 -0500 Received: from mail-bl2nam02on0070.outbound.protection.outlook.com ([104.47.38.70]:10912 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752338AbdLHTDK (ORCPT ); Fri, 8 Dec 2017 14:03:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=BpsGd3/+0MgJjB43yMaOTfXy0mHMk650AMdnHYhZtXg=; b=XGDdBmf5obhqeA9giWO5AGzsI80MJXaJwICZRMK7CpaizmgWaFfyOnvBEhq5c/Rua5g2+sf3dY0GJlzO2nQp0Hzv0Ma3Uuanv+XS9oA/tGTFq14727BEqqbKe09RqUjx61vnlwAI3BHwLN+oGFlSJOl8mSF43puOaDQDXiw2Rrg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bryantan@vmware.com; Received: from bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com (208.91.1.34) by CY1PR05MB2779.namprd05.prod.outlook.com (10.167.18.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.302.2; Fri, 8 Dec 2017 19:03:07 +0000 Date: Fri, 8 Dec 2017 11:02:57 -0800 From: Bryan Tan To: linux-rdma@vger.kernel.org Subject: [PATCH for-rc 5/6] RDMA/vmw_pvrdma: Use refcount_t instead of atomic_t Message-ID: <20171208190248.GA3039@bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171208185818.GA28514@bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: CY4PR1701CA0006.namprd17.prod.outlook.com (10.171.208.16) To CY1PR05MB2779.namprd05.prod.outlook.com (10.167.18.25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 549acad1-ec6b-4ba1-2ddc-08d53e6e520e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307); SRVR:CY1PR05MB2779; X-Microsoft-Exchange-Diagnostics: 1; CY1PR05MB2779; 3:FMpzY+Fk0CkSm+L1XtYGOjblDj3GA/kcz3oelVbiitV3dk/W3nha1Ztbr0mnHNiwRCtr9/Sfn5jJ7g56EVTp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akFmoUkmC+A60my7nwWDGIL/kVjMqDENvmzvCYEkL0ACU1CqBKC/Ud0Unn3Qp2z53JZW5OiNiMp8g0/cXfoc3kO9wCN6uktg1BjjrL3Uwm8WQTRuu7btEwPq8PSJr+4nUlaspZimSlf+XksLNTugMOokeN6Um/mOiBZbON18nef9Fa6/q35wUndkwbiBzHa/KrFw3mJrmCGeyHiCF3e+OxmbnjnSiTSK6m2OsJL8nFWqG4ShS0aNPlJpdZ2qu; 4:mz2lHcshnrffaxsGKHlMv9OilRcKu7EBYbG8qRS1r75ABX3wJ6NNzFChF5z08p/iZOneoWanou0S3wP7/vFLTTMXkn0syt6J/7s1bVPaYWkjQTJZqPWrTxQn9ktGO5UNRLeRJ5QDJazHcbvQH4XZ/ohRY0iT1r1h71nwwkXZIxyPzzOoE1BepbX5cTxobQONPInFlMr+Y/Uucpw62cfr793F8mi981HSCK9cVmuNUjY613jXvrLwMWlEe+4f5gwkGoUObQVbq4+Pi+U4juSW2t/XS19ZfuA87aR0X9ch4uCVoC2kCCbXPPN7uCj7XKU1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(8121501046)(5005006)(3231022)(3002001)(93006095)(93001095)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(20161123558100)(6072148)(201708071742011); SRVR:CY1PR05MB2779; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY1PR05MB2779; X-Forefront-PRVS: 0515208626 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(366004)(376002)(189003)(199004)(8676002)(47776003)(2361001)(305945005)(106356001)(2351001)(105586002)(5660300001)(55016002)(25786009)(68736007)(1076002)(2906002)(16526018)(33656002)(83506002)(50466002)(66066001)(23726003)(7696005)(3846002)(7736002)(53936002)(52116002)(81166006)(6116002)(97736004)(6666003)(478600001)(575784001)(58126008)(16586007)(8936002)(6916009)(86362001)(316002)(2950100002)(81156014)(18370500001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR05MB2779; H:bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR05MB2779; 23:xYBhXZZPAvEuJI7Zy+x242BXDYfWy1tGhmzLH3iXM?= =?us-ascii?Q?lSlopLgqoBZit/uv+4dJEohexT/nVYRv1suMQUCHAoMwE2Dbp21FpeNVCEah?= =?us-ascii?Q?9bX49HxNccPkHg674sS5TXwwZoUuKBfY9/KGsvl3Tsx6KOnDiN8sT8KKSfdc?= =?us-ascii?Q?Wxky6GCB2Cy38Te+TcQcvhP/k+RHPgTSY+LlPsJxcyrF9ziO4HnwXm4VfNOY?= =?us-ascii?Q?yqjFiak1mWlVBoifu13U33iU8Uyrj0Ydt9zbc4/kBdVaoPAQRMNl5zPV+bz9?= =?us-ascii?Q?046r4pMEXS7vqKrW+YFRR1IFfHz3vNKdTRL3EtTN/UxJStraoCCZAzMeDFdU?= =?us-ascii?Q?csIjK/VLDbfy8bG5cIjJ1pYk/1+mGaeavItCcijBrphuGFpnAXlb3NYOMcM6?= =?us-ascii?Q?C8ZzZusMBajMyKzvbZ3sxKlQTUjiuBm5A1qep7uvryT3pIuO8WM2t8+67rWk?= =?us-ascii?Q?wS6t79p/2YQTBETOdsMSnRMBhLQPVsSEeXIy++qu6lmw/JxI+bJbOx4+xwSf?= =?us-ascii?Q?X411RG4IvlMjszTPSPKMT3x58Nek6c66fCPynvimAknBKHbsx3aAH6HDGFZw?= =?us-ascii?Q?0ZELpt8NQo/i0c5VOWK54S8LTviobTImQNmTZvA/QaSxYMRXAPi5lbDfMVoy?= =?us-ascii?Q?35yx6QJf0U820Eql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Ho9sInU95yERsOScvmn1sk1gUAKE=; 24:VBt9RG0p8YV7iOksaFx5njTlt9XuyjnajeK/pRWBka6lzVFFPCEoHOHOY5LHfwj3VAIILwuPRDuLqGD7aqOLd0qUm1QcXJS5KaE0L4QYonA=; 7:oZsqMAxZYnyZkcOd/gcVVmVBJLbeRfGL1ivIAHjjv+fxi8+y828bVBCeigRTh+bZckD/s4qFK4N1gOX0cS6DfjbgpxdpbL5dRjoaUej7MCh3sNkJ2imFXufbvTLPFa+naVdeOXNo7yy6GPJPn0sjE2KpGUgQBW0HydpGMkbI194Ch+tmGE+27adySy27CnaTn7vOQSGS8GA7/r8/lPRA5J2FK60Z47lPS7vflIRKBkMA2Dk0RyvOFtiYTJSzC6Cx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR05MB2779; 20:aQKQDDL9kUK+y5Q4oMTnF+XpMkQzaHCXnHmX86qvVtWf2rtq6Z8Z3AW3Rdyw0Do1eQsNGAUU24FJnKs2ri6QsdqFinsOrInRa70/MZFrQAaDGfSqQpEhVsXME2ZTB0rIqhU/thL4O7po+7CR0uJZxTf2teRHMpsmsZ7zWTFx8nY= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2017 19:03:07.7403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 549acad1-ec6b-4ba1-2ddc-08d53e6e520e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR05MB2779 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 refcount_t is the preferred type for refcounts. Change the QP and CQ refcnt fields to use refcount_t. Reviewed-by: Adit Ranadive Reviewed-by: Aditya Sarwade Reviewed-by: Jorgen Hansen Signed-off-by: Bryan Tan --- drivers/infiniband/hw/vmw_pvrdma/pvrdma.h | 4 ++-- drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c | 6 +++--- drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 15 ++++++--------- drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c | 6 +++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma.h b/drivers/infiniband/hw/vmw_pvrdma/pvrdma.h index 63bc2ef..07d287e 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma.h +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma.h @@ -93,7 +93,7 @@ struct pvrdma_cq { struct pvrdma_page_dir pdir; u32 cq_handle; bool is_kernel; - atomic_t refcnt; + refcount_t refcnt; wait_queue_head_t wait; }; @@ -196,7 +196,7 @@ struct pvrdma_qp { u8 state; bool is_kernel; struct mutex mutex; /* QP state mutex. */ - atomic_t refcnt; + refcount_t refcnt; wait_queue_head_t wait; }; diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c index 3562c0c..11cda60 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c @@ -178,7 +178,7 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev, else pvrdma_page_dir_insert_umem(&cq->pdir, cq->umem, 0); - atomic_set(&cq->refcnt, 1); + refcount_set(&cq->refcnt, 1); init_waitqueue_head(&cq->wait); spin_lock_init(&cq->cq_lock); @@ -230,8 +230,8 @@ struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev, static void pvrdma_free_cq(struct pvrdma_dev *dev, struct pvrdma_cq *cq) { - atomic_dec(&cq->refcnt); - wait_event(cq->wait, !atomic_read(&cq->refcnt)); + if (!refcount_dec_and_test(&cq->refcnt)) + wait_event(cq->wait, !refcount_read(&cq->refcnt)); if (!cq->is_kernel) ib_umem_release(cq->umem); diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c index 941e324..5cff9fa 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c @@ -333,7 +333,7 @@ static void pvrdma_qp_event(struct pvrdma_dev *dev, u32 qpn, int type) spin_lock_irqsave(&dev->qp_tbl_lock, flags); qp = dev->qp_tbl[qpn % dev->dsr->caps.max_qp]; if (qp) - atomic_inc(&qp->refcnt); + refcount_inc(&qp->refcnt); spin_unlock_irqrestore(&dev->qp_tbl_lock, flags); if (qp && qp->ibqp.event_handler) { @@ -346,8 +346,7 @@ static void pvrdma_qp_event(struct pvrdma_dev *dev, u32 qpn, int type) ibqp->event_handler(&e, ibqp->qp_context); } if (qp) { - atomic_dec(&qp->refcnt); - if (atomic_read(&qp->refcnt) == 0) + if (refcount_dec_and_test(&qp->refcnt)) wake_up(&qp->wait); } } @@ -360,7 +359,7 @@ static void pvrdma_cq_event(struct pvrdma_dev *dev, u32 cqn, int type) spin_lock_irqsave(&dev->cq_tbl_lock, flags); cq = dev->cq_tbl[cqn % dev->dsr->caps.max_cq]; if (cq) - atomic_inc(&cq->refcnt); + refcount_inc(&cq->refcnt); spin_unlock_irqrestore(&dev->cq_tbl_lock, flags); if (cq && cq->ibcq.event_handler) { @@ -373,8 +372,7 @@ static void pvrdma_cq_event(struct pvrdma_dev *dev, u32 cqn, int type) ibcq->event_handler(&e, ibcq->cq_context); } if (cq) { - atomic_dec(&cq->refcnt); - if (atomic_read(&cq->refcnt) == 0) + if (refcount_dec_and_test(&cq->refcnt)) wake_up(&cq->wait); } } @@ -533,14 +531,13 @@ static irqreturn_t pvrdma_intrx_handler(int irq, void *dev_id) spin_lock_irqsave(&dev->cq_tbl_lock, flags); cq = dev->cq_tbl[cqne->info % dev->dsr->caps.max_cq]; if (cq) - atomic_inc(&cq->refcnt); + refcount_inc(&cq->refcnt); spin_unlock_irqrestore(&dev->cq_tbl_lock, flags); if (cq && cq->ibcq.comp_handler) cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context); if (cq) { - atomic_dec(&cq->refcnt); - if (atomic_read(&cq->refcnt)) + if (refcount_dec_and_test(&cq->refcnt)) wake_up(&cq->wait); } pvrdma_idx_ring_inc(&ring->cons_head, ring_slots); diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c index 77e7e57..9745cb1 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c @@ -245,7 +245,7 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd, spin_lock_init(&qp->sq.lock); spin_lock_init(&qp->rq.lock); mutex_init(&qp->mutex); - atomic_set(&qp->refcnt, 1); + refcount_set(&qp->refcnt, 1); init_waitqueue_head(&qp->wait); qp->state = IB_QPS_RESET; @@ -427,8 +427,8 @@ static void pvrdma_free_qp(struct pvrdma_qp *qp) pvrdma_unlock_cqs(scq, rcq, &scq_flags, &rcq_flags); - atomic_dec(&qp->refcnt); - wait_event(qp->wait, !atomic_read(&qp->refcnt)); + if (!refcount_dec_and_test(&qp->refcnt)) + wait_event(qp->wait, !refcount_read(&qp->refcnt)); if (!qp->is_kernel) { if (qp->rumem)