DPDK patches and discussions
 help / color / mirror / Atom feed
From: Xiao Wang <xiao.w.wang@intel.com>
To: ferruh.yigit@intel.com
Cc: dev@dpdk.org, tiwei.bie@intel.com, stephen@networkplumber.org,
	Xiao Wang <xiao.w.wang@intel.com>
Subject: [dpdk-dev] [PATCH v4] igb_uio: allow multi-process access
Date: Mon,  1 Jan 2018 14:00:10 -0800	[thread overview]
Message-ID: <1514844010-39793-1-git-send-email-xiao.w.wang@intel.com> (raw)
In-Reply-To: <1513706293-133528-1-git-send-email-xiao.w.wang@intel.com>

In some case, one device are accessed by different processes via
different BARs, so one uio device may be opened by more than one
process, for this case we just need to enable interrupt once, and
pci_clear_master only when the last process closed.

Fixes: 5f6ff30dc507 ("igb_uio: fix interrupt enablement after FLR in VM")

Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
---
v4:
- Make open/release function atomic, to ensure that other call
  won't return until the setup is really done.

v3:
- Use atomic_inc_return instead of atomic_inc and atomic_read.
- Ditto for atomic_dec.

v2:
- Make uio reference counter operation atomic.
---
 lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
index a3a98c1..1826adb 100644
--- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
+++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
@@ -45,6 +45,8 @@ struct rte_uio_pci_dev {
 	struct uio_info info;
 	struct pci_dev *pdev;
 	enum rte_intr_mode mode;
+	struct mutex lock;
+	int refcnt;
 };
 
 static char *intr_mode;
@@ -336,11 +338,18 @@ struct rte_uio_pci_dev {
 	struct pci_dev *dev = udev->pdev;
 	int err;
 
+	mutex_lock(&udev->lock);
+	if (++udev->refcnt > 1) {
+		mutex_unlock(&udev->lock);
+		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) {
 		dev_err(&dev->dev, "Enable interrupt fails\n");
 		return err;
@@ -354,12 +363,19 @@ struct rte_uio_pci_dev {
 	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);
 
 	/* stop the device from further DMA */
 	pci_clear_master(dev);
 
+	mutex_unlock(&udev->lock);
 	return 0;
 }
 
@@ -480,6 +496,7 @@ struct rte_uio_pci_dev {
 	if (!udev)
 		return -ENOMEM;
 
+	mutex_init(&udev->lock);
 	/*
 	 * enable device: ask low-level code to enable I/O and
 	 * memory
@@ -570,6 +587,7 @@ struct rte_uio_pci_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);
-- 
1.8.3.1

  parent reply	other threads:[~2018-01-01 13:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09  1:57 [dpdk-dev] [PATCH] " Xiao Wang
2017-12-12  1:38 ` Stephen Hemminger
2017-12-18 15:53   ` Wang, Xiao W
2017-12-19 15:42 ` [dpdk-dev] [PATCH v2] " Xiao Wang
2017-12-19  9:04   ` Tiwei Bie
2017-12-19  9:23     ` Wang, Xiao W
2017-12-19 15:39   ` Stephen Hemminger
2017-12-19 17:58   ` [dpdk-dev] [PATCH v3] " Xiao Wang
2017-12-20  2:17     ` Tiwei Bie
2018-01-01 22:00     ` Xiao Wang [this message]
2018-01-16 19:43       ` [dpdk-dev] [PATCH v4] " Ferruh Yigit
2018-01-16 23:37         ` Thomas Monjalon
2018-03-08 21:17 ` [dpdk-dev] [PATCH] " Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514844010-39793-1-git-send-email-xiao.w.wang@intel.com \
    --to=xiao.w.wang@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=tiwei.bie@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).