From patchwork Thu Dec 14 00:24:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan Tan X-Patchwork-Id: 10111259 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 0DA9560327 for ; Thu, 14 Dec 2017 00:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F10DF27EED for ; Thu, 14 Dec 2017 00:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E489E28449; Thu, 14 Dec 2017 00:24:34 +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 4541627EED for ; Thu, 14 Dec 2017 00:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750749AbdLNAYd (ORCPT ); Wed, 13 Dec 2017 19:24:33 -0500 Received: from mail-dm3nam03on0063.outbound.protection.outlook.com ([104.47.41.63]:32640 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750737AbdLNAYc (ORCPT ); Wed, 13 Dec 2017 19:24:32 -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=LMEs/UNQp4EPa6kkZqXFnFTSRr80fuuRKFMQ0tEG4aI=; b=JQAA6+B+V7AFi8phj8PqMMoS5Bk2QouOjlCuaY3fuHsTRAPZ3S0jetF3ycHDCJn91CWYyNvwNZhWm1iJLX/kAXAdFOA+HHI9gVdJ+KkrWL6Loupe1NlbvrNB0ps1l/y/ZKtipBoGRE1kj+qHb84fh2i5FXWJCOi0i6qm2+1zDQ8= Received: from bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com (208.91.1.34) by SN2PR05MB2784.namprd05.prod.outlook.com (2603:10b6:804:16::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.302.2; Thu, 14 Dec 2017 00:24:29 +0000 Date: Wed, 13 Dec 2017 16:24:12 -0800 From: Bryan Tan To: linux-rdma@vger.kernel.org Subject: [PATCH v1 for-rc 5/8] RDMA/vmw_pvrdma: Use refcount_t instead of atomic_t Message-ID: <20171214002402.GA16082@bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171214001753.GA9780@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: VI1PR0502CA0007.eurprd05.prod.outlook.com (2603:10a6:803:1::20) To SN2PR05MB2784.namprd05.prod.outlook.com (2603:10b6:804:16::13) X-MS-Office365-Filtering-Correlation-Id: 96206303-d57b-4221-fa92-08d542890b36 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603307); SRVR:SN2PR05MB2784; X-Microsoft-Exchange-Diagnostics: 1; SN2PR05MB2784; 3:SfirgKmlLvrEy5UMGJs4gCURG88cyg6SPeUDxqJ/Zb58wxCIOWjO+jF0QMN6dP9Z6vPOZ4DAJsi1UbY6TW74J7FUqYabPzPEWwrguk4WkzPtt9cTa3lwbyqnLk2qYkDI8t9snNm7JysY7+yqZpZ8LjWin6EnVt0ktf+ZGDUM+KCWOfYd8G7sU4hHTUTTjBLojkTe+jMfq/1MyJl6YUd0BLDUkc38hJnQvpZSAiQyI06pOjuqzLpdFafja38Pr6Qf; 25:o2DD/WMeo4sFY9lhcCEacxJb/kEsbvj5dQW6EL7qSQqE0UuFim3Bs7eaTTyDoae0vm6BOBKVL+8JbJyWpcA6oF5AjbpkU8Tcz+GkG8JZiOLN+hjp0gEE8D6g8N2CJyFE2LgeY1I5Bfy2CDSDZMz/BA5D/ypWeErcQtCZ4Hpkgo3neUHH/UipadyB2xM/2kECgUpFUVMNPUVCPuNFEiiORP8vHUhQcs5r4Ra6Kya2MdUTzdNLs39OnIQAcoEzuHHtDLBqfO9coCHu79iBf0+ltOrIUwgmBuTafQ4/NKtwIY7L20Z/4FJ+PHsFkaXc0vVqJK59YXgZkGVJqLq2W8nc/TEaQZNCzQbVGfRt8xFIRGU=; 31:uSzXH6MkgZIp67CVQO9gSA0yBey0gHWeyTmU4V2qt7oHOcd8GcyLFQ4lfc0RqLVMTZHkNluEEdsXL8nLWOu4gIeJYZATtP0NdutkM/sm5xkZnuD93sNg8ceGlPBnxjtMO1fT0LKcJWzUnjsmEnB+wiFX74e4QK/hSzrYxu6NI52DJv5HSFRjtyUNGkbm859v7ekbtNFwwf/Qr//veQ8Q+x9kCprX7uBNl3umaLzfL6Y= X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN2PR05MB2784: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bryantan@vmware.com; X-Microsoft-Exchange-Diagnostics: 1; SN2PR05MB2784; 20:UlY7Wri8aGkT3a6Xelf553Ar+LK8I6bE3aIbgCidwcjmRidtrZFDuScrEHOJRfzCeb64k9rJ6WZtbLQEwmyqrR33c5SVS04V1fZSrMGrLZB/CwgMSFEEX4FH8HBZ0W8djDUTaYZyLXoLF0TCvvtri6lhhqEUsM4O1w+W8WYkdUcenZukJVi7GJj0TXJqJw9puUoJDajg4eMKJaVrPPu+q7CE3sGbRlHvb9XdgHNx0b1M/aTkrmJAdnAcPWHOUioTnmXtsOm2hpTJbjgIVrzxCPl05otW9H7QfFziejL7w4zUlU9wD4FOXRJUgCHb9apb1Shv0mqduHecX1b8MiMvTZGQ/LmPM9p9SDwNlaR3LSPsbUyX0JeTI6gadMRmU4LbJiBBMHG/0Y4AN16GIMx7OL+PXmEvKvGtXXgJwKePB84S0Dh2iTfYRAZmJWmk/IVh/QuQ+hBnGZshEr3nAPe11ylnpAMG4sP3xlqTwm+Dk0v6stnm3cLTfdDGOh/Whccd; 4:B5TSIyxbEQIz81OIAyxS5LM7MoedEyq0VDouGCTohXdwFdugKS26c8ms1ZYaZpn3F/kX38UEF0FImn3PHAoBb+BK3sWVq5ekXzGaTLWrRca6JA1VzQEkkt9ovyoZ2y6d2fgcJIAc5stV2i6ftUACKMkY7JztIPnK2BJRZCMWgK+M4R65zdJi5KlPXLtsuc73NWgB3wLwvjghXqJL+NZqoHlLFo/+9DLEHPn+ymvYBwh6awh+Zfsn32/QMT4nhBW5WAOl7euDSB6oOEkbGJNcU6WyqGM0LwxZ4YelPDMWGK9eFM19xOL/U/2fkmGrroz+ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(10201501046)(3231023)(3002001)(93006095)(93001095)(6041248)(20161123555025)(20161123562025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(6072148)(201708071742011); SRVR:SN2PR05MB2784; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:SN2PR05MB2784; X-Forefront-PRVS: 05214FD68E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(376002)(366004)(346002)(39860400002)(199004)(189003)(305945005)(7696005)(7736002)(83506002)(386003)(97736004)(47776003)(66066001)(86362001)(316002)(8676002)(478600001)(23726003)(55016002)(3846002)(33656002)(59450400001)(81166006)(81156014)(1076002)(52116002)(6116002)(16586007)(58126008)(25786009)(68736007)(5660300001)(6666003)(50466002)(16526018)(8936002)(53936002)(2351001)(2906002)(6916009)(2950100002)(106356001)(2361001)(105586002)(18370500001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR05MB2784; H:bryantan-devbox.prom.eng.vmware.com.prom.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; SN2PR05MB2784; 23:X24GLNtsbiO92PFoJ/V+qytmCQc6iS+XLuWwUYvst?= =?us-ascii?Q?CyMAhKiT4tMqYdp5XKPq5DFffrFu93flDI/A1kTyssMdTWDczcwbVz4iccYY?= =?us-ascii?Q?CmR20d0gbP4YIhOoTgfa3xeUFdNDL2xIFj010bz5+Cmq/7+c4fqGVZbPAJAO?= =?us-ascii?Q?9wmyk3ETxi8r353qclkRcASqmHDW2GMn2/McK8uWsU3JLSv1GMuZEIfJhYpG?= =?us-ascii?Q?jgPvQQpn6XfYfn8LnOqOWmJn1L+EcUo1upgOgW8O7in90TlAxTcFwWW/AkJu?= =?us-ascii?Q?6TG5LBkYGYklN3MOd6sxYKrC4S1azb47NvPOBel3BhLAKckvgvGiuZGscFXE?= =?us-ascii?Q?RRBjKQlVBqB/p6RxB26ju0wTQ7LNTf+DeDAfRi+maYoQgo2dwbU63pqInlI8?= =?us-ascii?Q?pqZ00+4lp/h0mvgLOYn688235RzNZPfeLfUXlkP80DywCSPiy3iwNFbxdQbZ?= =?us-ascii?Q?DkbOCp8vn+LWDnEyw5k7iLBKi+kDSJwKad42fDOj9PdSemdEibriPrlr5CET?= =?us-ascii?Q?vT1JXBsPB3ezaJNcbvHdulqBYsTjh0wyfUdonl65o8SNgViAnVOnNJp0Sh2h?= =?us-ascii?Q?CdY5nr990BRHZz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iHziSK/oDl96bFP1wWPNaMKC9qDxXx2oV3uOeqa4sW8GeJcDcRSHTV+tpIcongtBSTHlv3tdnGkbEFG9kRHWL81XN2MWADAp72+XfTvmYDQDOdMtHb7HwaZgyn0BCqlFC4lzdyclzp4zCa/0A+P4=; 24:H14iTBa/SC4gm1OHa02XMPXCaupG3bs2+dfugRUK73LIQQ3OKHNxL0vf6iNoc/o2g2HsZEyEYAN4F2XOAZBjE0k8gwW9Sep4cZ2izkBY2/Y=; 7:qcf7KOYenNQ5UdvgPE5TU6aaFPC0aIUd9fo4Ma/Ig1caxY8kVOZRJmUe/mksa7MoZMaGbD1jQ9uqwaFmSmMn/e1FNZ8HAxRZbVZ0iFGCPW0opK5RhLWoD3E45YL+Y0hNtiQihpDyseGz54Yv1Lxp37BgNt7tYb+wIUEG9MjJJB5TiynicGyTKFJqHCH/rWJlziEu1aVkQCJBtgk/86YJpxzVuopc4wpkV2eKr944/VwEnPCTzpau9uw23kA+Gzua SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN2PR05MB2784; 20:87jPUZbaP+OUYV41gUsCleUJHYittA6OfYqlJQ6fMc/DNPX9VQuItuAUg1UD4WDj0wnRiZ30rZCdIltk/ns605b2fEokgXvCpBvneyK665rBkqTarZPnpV5S73pUopMId9wTMjPINh3rbKVtK4SoS4SNRVK6JPR8G6L/NvahGjk= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2017 00:24:29.7960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96206303-d57b-4221-fa92-08d542890b36 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR05MB2784 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 ea8db5e6..9dba949 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c @@ -177,7 +177,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); @@ -229,8 +229,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)