All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, qemu-devel@nongnu.org,
	alex.williamson@redhat.com, peterx@redhat.com,
	eric.auger@redhat.com, aik@ozlabs.ru
Subject: [PATCH 1/3] vfio/pci: Pull BAR mapping setup from read-write path
Date: Wed, 28 Feb 2018 13:14:46 -0700	[thread overview]
Message-ID: <20180228201446.25283.82272.stgit@gimli.home> (raw)
In-Reply-To: <20180228195504.25283.45666.stgit@gimli.home>

This creates a common helper that we'll use for ioeventfd setup.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/pci/vfio_pci_rdwr.c |   39 ++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index 357243d76f10..5f2b376dcebd 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -113,6 +113,30 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf,
 	return done;
 }
 
+static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar)
+{
+	struct pci_dev *pdev = vdev->pdev;
+	int ret;
+	void __iomem *io;
+
+	if (vdev->barmap[bar])
+		return 0;
+
+	ret = pci_request_selected_regions(pdev, 1 << bar, "vfio");
+	if (ret)
+		return ret;
+
+	io = pci_iomap(pdev, bar, 0);
+	if (!io) {
+		pci_release_selected_regions(pdev, 1 << bar);
+		return -ENOMEM;
+	}
+
+	vdev->barmap[bar] = io;
+
+	return 0;
+}
+
 ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
 			size_t count, loff_t *ppos, bool iswrite)
 {
@@ -147,22 +171,13 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
 		if (!io)
 			return -ENOMEM;
 		x_end = end;
-	} else if (!vdev->barmap[bar]) {
-		int ret;
-
-		ret = pci_request_selected_regions(pdev, 1 << bar, "vfio");
+	} else {
+		int ret = vfio_pci_setup_barmap(vdev, bar);
 		if (ret)
 			return ret;
 
-		io = pci_iomap(pdev, bar, 0);
-		if (!io) {
-			pci_release_selected_regions(pdev, 1 << bar);
-			return -ENOMEM;
-		}
-
-		vdev->barmap[bar] = io;
-	} else
 		io = vdev->barmap[bar];
+	}
 
 	if (bar == vdev->msix_bar) {
 		x_start = vdev->msix_offset;

WARNING: multiple messages have this Message-ID (diff)
From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, qemu-devel@nongnu.org,
	alex.williamson@redhat.com, peterx@redhat.com,
	eric.auger@redhat.com, aik@ozlabs.ru
Subject: [Qemu-devel] [PATCH 1/3] vfio/pci: Pull BAR mapping setup from read-write path
Date: Wed, 28 Feb 2018 13:14:46 -0700	[thread overview]
Message-ID: <20180228201446.25283.82272.stgit@gimli.home> (raw)
In-Reply-To: <20180228195504.25283.45666.stgit@gimli.home>

This creates a common helper that we'll use for ioeventfd setup.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/pci/vfio_pci_rdwr.c |   39 ++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index 357243d76f10..5f2b376dcebd 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -113,6 +113,30 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf,
 	return done;
 }
 
+static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar)
+{
+	struct pci_dev *pdev = vdev->pdev;
+	int ret;
+	void __iomem *io;
+
+	if (vdev->barmap[bar])
+		return 0;
+
+	ret = pci_request_selected_regions(pdev, 1 << bar, "vfio");
+	if (ret)
+		return ret;
+
+	io = pci_iomap(pdev, bar, 0);
+	if (!io) {
+		pci_release_selected_regions(pdev, 1 << bar);
+		return -ENOMEM;
+	}
+
+	vdev->barmap[bar] = io;
+
+	return 0;
+}
+
 ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
 			size_t count, loff_t *ppos, bool iswrite)
 {
@@ -147,22 +171,13 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
 		if (!io)
 			return -ENOMEM;
 		x_end = end;
-	} else if (!vdev->barmap[bar]) {
-		int ret;
-
-		ret = pci_request_selected_regions(pdev, 1 << bar, "vfio");
+	} else {
+		int ret = vfio_pci_setup_barmap(vdev, bar);
 		if (ret)
 			return ret;
 
-		io = pci_iomap(pdev, bar, 0);
-		if (!io) {
-			pci_release_selected_regions(pdev, 1 << bar);
-			return -ENOMEM;
-		}
-
-		vdev->barmap[bar] = io;
-	} else
 		io = vdev->barmap[bar];
+	}
 
 	if (bar == vdev->msix_bar) {
 		x_start = vdev->msix_offset;

  reply	other threads:[~2018-02-28 20:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 20:14 [PATCH 0/3] vfio/pci: ioeventfd support Alex Williamson
2018-02-28 20:14 ` [Qemu-devel] " Alex Williamson
2018-02-28 20:14 ` Alex Williamson [this message]
2018-02-28 20:14   ` [Qemu-devel] [PATCH 1/3] vfio/pci: Pull BAR mapping setup from read-write path Alex Williamson
2018-03-07  7:11   ` Peter Xu
2018-03-07  7:11     ` [Qemu-devel] " Peter Xu
2018-03-13 12:21   ` Auger Eric
2018-03-13 12:21     ` [Qemu-devel] " Auger Eric
2018-02-28 20:14 ` [PATCH 2/3] vfio/pci: Use endian neutral helpers Alex Williamson
2018-02-28 20:14   ` [Qemu-devel] " Alex Williamson
2018-02-28 20:15 ` [PATCH 3/3] vfio/pci: Add ioeventfd support Alex Williamson
2018-02-28 20:15   ` [Qemu-devel] " Alex Williamson
2018-03-06  6:54   ` kbuild test robot
2018-03-06  6:54     ` [Qemu-devel] " kbuild test robot
2018-03-07  5:56   ` Peter Xu
2018-03-07  5:56     ` [Qemu-devel] " Peter Xu
2018-03-15 21:12     ` Alex Williamson
2018-03-15 21:12       ` [Qemu-devel] " Alex Williamson
2018-03-13 13:12   ` Auger Eric
2018-03-13 13:12     ` [Qemu-devel] " Auger Eric
2018-03-15 21:07     ` Alex Williamson
2018-03-15 21:07       ` [Qemu-devel] " Alex Williamson
2018-03-02  7:08 ` [PATCH 0/3] vfio/pci: " Tian, Kevin
2018-03-02  7:08   ` [Qemu-devel] " Tian, Kevin
2018-03-02 18:02   ` Alex Williamson
2018-03-02 18:02     ` [Qemu-devel] " Alex Williamson
2018-03-03  0:43     ` Tian, Kevin
2018-03-03  0:43       ` [Qemu-devel] " Tian, Kevin

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=20180228201446.25283.82272.stgit@gimli.home \
    --to=alex.williamson@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.