[dpdk-stable] patch 'igb_uio: fix refcount if open returns error' has been queued to LTS release 17.11.5
Yongseok Koh
yskoh at mellanox.com
Fri Nov 30 00:10:32 CET 2018
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 <stephen at networkplumber.org>
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 <stephen at networkplumber.org>
Acked-by: Ferruh Yigit <ferruh.yigit at intel.com>
---
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 <stephen at networkplumber.org>
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 at dpdk.org
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Ferruh Yigit <ferruh.yigit at intel.com>
---
- 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);
More information about the stable
mailing list