From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 0DBB01B113 for ; Wed, 21 Nov 2018 17:49:52 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 638A665855; Wed, 21 Nov 2018 16:49:51 +0000 (UTC) Received: from ktraynor.remote.csb (unknown [10.36.118.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C8D65C21E; Wed, 21 Nov 2018 16:49:50 +0000 (UTC) From: Kevin Traynor To: Stephen Hemminger Cc: Ferruh Yigit , dpdk stable Date: Wed, 21 Nov 2018 16:47:28 +0000 Message-Id: <20181121164828.32249-14-ktraynor@redhat.com> In-Reply-To: <20181121164828.32249-1-ktraynor@redhat.com> References: <20181121164828.32249-1-ktraynor@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 21 Nov 2018 16:49:51 +0000 (UTC) Subject: [dpdk-stable] patch 'igb_uio: fix refcount if open returns error' has been queued to stable release 18.08.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Nov 2018 16:49:52 -0000 Hi, FYI, your patch has been queued to stable release 18.08.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/27/18. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. If the code is different (ie: not only metadata diffs), due for example to a change in context or macro names, please double check it. Thanks. Kevin Traynor --- >>From 4fa9cde4881ec5327bcb44a6a9ff36a29d18b621 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 14 Sep 2018 08:30:19 -0700 Subject: [PATCH] igb_uio: fix refcount if open returns error [ upstream commit ab856f2947ef0af523eb4d22f4aa8347bbf07391 ] This fixes the problem of reference count leak if igbuio_pci_enable_interrupts fails. Also, replace mutex and integer with a kernel atomic counter. This is standard pattern for kernel devices. Fixes: 19685d5aa79c ("igb_uio: allow multi-process access") Signed-off-by: Stephen Hemminger Acked-by: Ferruh Yigit --- kernel/linux/igb_uio/igb_uio.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/kernel/linux/igb_uio/igb_uio.c b/kernel/linux/igb_uio/igb_uio.c index 3398eacd3..fede66cf2 100644 --- a/kernel/linux/igb_uio/igb_uio.c +++ b/kernel/linux/igb_uio/igb_uio.c @@ -27,6 +27,5 @@ struct rte_uio_pci_dev { struct pci_dev *pdev; enum rte_intr_mode mode; - struct mutex lock; - int refcnt; + atomic_t refcnt; }; @@ -321,9 +320,6 @@ igbuio_pci_open(struct uio_info *info, struct inode *inode) int err; - mutex_lock(&udev->lock); - if (++udev->refcnt > 1) { - mutex_unlock(&udev->lock); + if (atomic_inc_return(&udev->refcnt) != 1) return 0; - } /* set bus master, which was cleared by the reset function */ @@ -332,10 +328,9 @@ igbuio_pci_open(struct uio_info *info, struct inode *inode) /* enable interrupts */ err = igbuio_pci_enable_interrupts(udev); - mutex_unlock(&udev->lock); if (err) { + atomic_dec(&udev->refcnt); dev_err(&dev->dev, "Enable interrupt fails\n"); - return err; } - return 0; + return err; } @@ -346,17 +341,12 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode) struct pci_dev *dev = udev->pdev; - mutex_lock(&udev->lock); - if (--udev->refcnt > 0) { - mutex_unlock(&udev->lock); - return 0; + if (atomic_dec_and_test(&udev->refcnt)) { + /* disable interrupts */ + igbuio_pci_disable_interrupts(udev); + + /* stop the device from further DMA */ + pci_clear_master(dev); } - /* disable interrupts */ - igbuio_pci_disable_interrupts(udev); - - /* stop the device from further DMA */ - pci_clear_master(dev); - - mutex_unlock(&udev->lock); return 0; } @@ -490,5 +480,4 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) return -ENOMEM; - mutex_init(&udev->lock); /* * enable device: ask low-level code to enable I/O and @@ -530,4 +519,5 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) udev->info.priv = udev; udev->pdev = dev; + atomic_set(&udev->refcnt, 0); err = sysfs_create_group(&dev->dev.kobj, &dev_attr_grp); @@ -581,5 +571,4 @@ igbuio_pci_remove(struct pci_dev *dev) struct rte_uio_pci_dev *udev = pci_get_drvdata(dev); - mutex_destroy(&udev->lock); sysfs_remove_group(&dev->dev.kobj, &dev_attr_grp); uio_unregister_device(&udev->info); -- 2.19.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2018-11-21 16:44:31.308435521 +0000 +++ 0014-igb_uio-fix-refcount-if-open-returns-error.patch 2018-11-21 16:44:30.000000000 +0000 @@ -1,8 +1,10 @@ -From ab856f2947ef0af523eb4d22f4aa8347bbf07391 Mon Sep 17 00:00:00 2001 +From 4fa9cde4881ec5327bcb44a6a9ff36a29d18b621 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 14 Sep 2018 08:30:19 -0700 Subject: [PATCH] igb_uio: fix refcount if open returns error +[ upstream commit ab856f2947ef0af523eb4d22f4aa8347bbf07391 ] + This fixes the problem of reference count leak if igbuio_pci_enable_interrupts fails. @@ -10,7 +12,6 @@ This is standard pattern for kernel devices. Fixes: 19685d5aa79c ("igb_uio: allow multi-process access") -Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger Acked-by: Ferruh Yigit