linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: mst@redhat.com, jasowang@redhat.com,
	virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org
Cc: shahafs@mellanox.com
Subject: [PATCH V2 04/14] virtio-pci: move the notification sanity check to vp_modern_probe()
Date: Thu, 26 Nov 2020 17:25:54 +0800	[thread overview]
Message-ID: <20201126092604.208033-5-jasowang@redhat.com> (raw)
In-Reply-To: <20201126092604.208033-1-jasowang@redhat.com>

This patch moves the notification sanity check to
vp_modern_probe(). This can make sure the logic could be reused by
modules other than virtio-pci.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_pci_modern.c | 34 +++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 02688c3b3fbd..d001c74beefe 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -384,17 +384,6 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
 	vp_iowrite64_twopart(virtqueue_get_used_addr(vq),
 			     &cfg->queue_used_lo, &cfg->queue_used_hi);
 
-	/* offset should not wrap */
-	if ((u64)off * mdev->notify_offset_multiplier + 2
-		> mdev->notify_len) {
-		dev_warn(&vp_dev->pci_dev->dev,
-			 "bad notification offset %u (x %u) "
-			 "for queue %u > %zd",
-			 off, mdev->notify_offset_multiplier,
-			 index, mdev->notify_len);
-		err = -EINVAL;
-		goto err_map_notify;
-	}
 	vq->priv = (void __force *)mdev->notify_base +
 		off * mdev->notify_offset_multiplier;
 
@@ -695,9 +684,11 @@ static inline void check_offsets(void)
 static int vp_modern_probe(struct virtio_pci_modern_device *mdev)
 {
 	struct pci_dev *pci_dev = mdev->pci_dev;
-	int err, common, isr, notify, device;
+	int err, common, isr, notify, device, i;
+	unsigned int num_queues;
 	u32 notify_length;
 	u32 notify_offset;
+	u16 off;
 
 	/* We only own devices >= 0x1000 and <= 0x107f: leave the rest. */
 	if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f)
@@ -796,6 +787,25 @@ static int vp_modern_probe(struct virtio_pci_modern_device *mdev)
 	if (!mdev->notify_base)
 		goto err;
 
+	num_queues = vp_ioread16(&mdev->common->num_queues);
+
+	/* offset should not wrap */
+	for (i = 0; i < num_queues; i++) {
+		vp_iowrite16(i, &mdev->common->queue_select);
+		off = vp_ioread16(&mdev->common->queue_notify_off);
+
+		if ((u64)off * mdev->notify_offset_multiplier + 2
+			> mdev->notify_len) {
+			dev_warn(&pci_dev->dev,
+			 "bad notification offset %u (x %u) "
+			 "for queue %u > %zd",
+			 off, mdev->notify_offset_multiplier,
+			 i, mdev->notify_len);
+			err = -EINVAL;
+			goto err;
+		}
+	}
+
 	/* We don't know how much we should map, but PAGE_SIZE
 	 * is more than enough for all existing devices.
 	 */
-- 
2.25.1


  parent reply	other threads:[~2020-11-26  9:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26  9:25 [PATCH V2 00/14] vDPA driver for virtio-pci device Jason Wang
2020-11-26  9:25 ` [PATCH V2 01/14] virtio-pci: do not access iomem via virtio_pci_device directly Jason Wang
2020-11-26 13:46   ` Michael S. Tsirkin
2020-11-27  2:50     ` Jason Wang
2020-11-26  9:25 ` [PATCH V2 02/14] virtio-pci: switch to use devres for modern devices Jason Wang
2020-11-26 13:57   ` Michael S. Tsirkin
2020-11-27  2:54     ` Jason Wang
2020-11-26  9:25 ` [PATCH V2 03/14] virtio-pci: split out modern device Jason Wang
2020-11-26  9:25 ` Jason Wang [this message]
2020-11-26  9:25 ` [PATCH V2 05/14] virtio-pci-modern: introduce vp_modern_set_queue_vector() Jason Wang
2020-11-26  9:25 ` [PATCH V2 06/14] virtio-pci-modern: introduce vp_modern_queue_address() Jason Wang
2020-11-26  9:25 ` [PATCH V2 07/14] virtio-pci-modern: introduce helper to set/get queue_enable Jason Wang
2020-11-26  9:25 ` [PATCH V2 08/14] virtio-pci-modern: introduce helper for setting/geting queue size Jason Wang
2020-11-26  9:25 ` [PATCH V2 09/14] virtio-pci-modern: introduce helper for getting queue nums Jason Wang
2020-11-26  9:26 ` [PATCH V2 10/14] virtio-pci-modern: introduce helper to get notification offset Jason Wang
2020-11-26  9:26 ` [PATCH V2 11/14] virtio-pci: introduce modern device module Jason Wang
2020-11-26  9:26 ` [PATCH V2 12/14] vdpa: set the virtqueue num during register Jason Wang
2020-11-26  9:26 ` [PATCH V2 13/14] virtio_vdpa: don't warn when fail to disable vq Jason Wang
2020-11-26  9:26 ` [PATCH V2 14/14] vdpa: introduce virtio pci driver Jason Wang

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=20201126092604.208033-5-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=shahafs@mellanox.com \
    --cc=virtualization@lists.linux-foundation.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 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).