From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 2B5AD1B512 for ; Fri, 30 Nov 2018 00:13:41 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from yskoh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 30 Nov 2018 01:19:32 +0200 Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx [10.101.0.96]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id wATNCW7c032075; Fri, 30 Nov 2018 01:13:37 +0200 From: Yongseok Koh To: Stephen Hemminger Cc: Ferruh Yigit , dpdk stable Date: Thu, 29 Nov 2018 15:10:32 -0800 Message-Id: <20181129231202.30436-38-yskoh@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181129231202.30436-1-yskoh@mellanox.com> References: <20181129231202.30436-1-yskoh@mellanox.com> Subject: [dpdk-stable] patch 'igb_uio: fix refcount if open returns error' has been queued to LTS release 17.11.5 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: Thu, 29 Nov 2018 23:13:41 -0000 Hi, FYI, your patch has been queued to LTS release 17.11.5 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/01/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. Yongseok --- >>From cd1c4b525915170d1138331e1b2a041c0d21f648 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 --- lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 33 +++++++++++-------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c index 1826adbac..45d70272d 100644 --- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c +++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c @@ -45,8 +45,7 @@ struct rte_uio_pci_dev { struct uio_info info; struct pci_dev *pdev; enum rte_intr_mode mode; - struct mutex lock; - int refcnt; + atomic_t refcnt; }; static char *intr_mode; @@ -338,23 +337,19 @@ igbuio_pci_open(struct uio_info *info, struct inode *inode) struct pci_dev *dev = udev->pdev; 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 */ pci_set_master(dev); /* 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; } static int @@ -363,19 +358,14 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode) struct rte_uio_pci_dev *udev = info->priv; struct pci_dev *dev = udev->pdev; - mutex_lock(&udev->lock); - if (--udev->refcnt > 0) { - mutex_unlock(&udev->lock); - return 0; - } - - /* disable interrupts */ - igbuio_pci_disable_interrupts(udev); + if (atomic_dec_and_test(&udev->refcnt)) { + /* disable interrupts */ + igbuio_pci_disable_interrupts(udev); - /* stop the device from further DMA */ - pci_clear_master(dev); + /* stop the device from further DMA */ + pci_clear_master(dev); + } - mutex_unlock(&udev->lock); return 0; } @@ -496,7 +486,6 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) if (!udev) return -ENOMEM; - mutex_init(&udev->lock); /* * enable device: ask low-level code to enable I/O and * memory @@ -536,6 +525,7 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) udev->info.release = igbuio_pci_release; udev->info.priv = udev; udev->pdev = dev; + atomic_set(&udev->refcnt, 0); err = sysfs_create_group(&dev->dev.kobj, &dev_attr_grp); if (err != 0) @@ -587,7 +577,6 @@ 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); igbuio_pci_release_iomem(&udev->info); -- 2.11.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2018-11-29 15:01:46.924573535 -0800 +++ 0038-igb_uio-fix-refcount-if-open-returns-error.patch 2018-11-29 15:01:45.057966000 -0800 @@ -1,8 +1,10 @@ -From ab856f2947ef0af523eb4d22f4aa8347bbf07391 Mon Sep 17 00:00:00 2001 +From cd1c4b525915170d1138331e1b2a041c0d21f648 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,19 +12,18 @@ 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 --- - kernel/linux/igb_uio/igb_uio.c | 33 +++++++++++---------------------- + lib/librte_eal/linuxapp/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 -@@ -26,8 +26,7 @@ struct rte_uio_pci_dev { +diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c +index 1826adbac..45d70272d 100644 +--- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c ++++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c +@@ -45,8 +45,7 @@ struct rte_uio_pci_dev { struct uio_info info; struct pci_dev *pdev; enum rte_intr_mode mode; @@ -31,8 +32,8 @@ + atomic_t refcnt; }; - static int wc_activate; -@@ -320,23 +319,19 @@ igbuio_pci_open(struct uio_info *info, struct inode *inode) + static char *intr_mode; +@@ -338,23 +337,19 @@ igbuio_pci_open(struct uio_info *info, struct inode *inode) struct pci_dev *dev = udev->pdev; int err; @@ -59,7 +60,7 @@ } static int -@@ -345,19 +340,14 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode) +@@ -363,19 +358,14 @@ igbuio_pci_release(struct uio_info *info, struct inode *inode) struct rte_uio_pci_dev *udev = info->priv; struct pci_dev *dev = udev->pdev; @@ -85,7 +86,7 @@ return 0; } -@@ -489,7 +479,6 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) +@@ -496,7 +486,6 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) if (!udev) return -ENOMEM; @@ -93,7 +94,7 @@ /* * enable device: ask low-level code to enable I/O and * memory -@@ -529,6 +518,7 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) +@@ -536,6 +525,7 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) udev->info.release = igbuio_pci_release; udev->info.priv = udev; udev->pdev = dev; @@ -101,7 +102,7 @@ err = sysfs_create_group(&dev->dev.kobj, &dev_attr_grp); if (err != 0) -@@ -580,7 +570,6 @@ igbuio_pci_remove(struct pci_dev *dev) +@@ -587,7 +577,6 @@ igbuio_pci_remove(struct pci_dev *dev) { struct rte_uio_pci_dev *udev = pci_get_drvdata(dev);