Skip to contentSkip to conversation

virtio-pci: towards virtio 1.0 guest support

PATCH In review Michael S. Tsirkin 6 participants 52 messages Jan 14, 2015 – Jan 23, 2015

Subsystems (18)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

v3 cover virtio-pci: towards virtio 1.0 guest support

Changes since v2:
handling for devices without config space (e.g. rng) reduce # of mappings for VQs

These patches seem to work fine on my virtio-1.0 qemu branch. There haven't been any bugs since v2: just minor cleanups and enhancements.
QEMU side is still undergoing polishing, but is already testable.

Rusty, what do you think? Let's merge these for 3.20? Also - will you be doing that merge window, or should I?

Michael S. Tsirkin (14):
virtio_pci: drop virtio_config dependency virtio/9p: verify device has config space virtio/blk: verify device has config space virtio/console: verify device has config space virtio/net: verify device has config space virtio/scsi: verify device has config space virtio/balloon: verify device has config space
mn10300: drop dead code
pci: add pci_iomap_range
s390: add pci_iomap_range
virtio_pci: move probe/remove code to common
virtio_pci: modern driver
virtio_pci_modern: reduce number of mappings
virtio_pci_modern: support devices with no config

Rusty Russell (2):
virtio-pci: define layout for virtio 1.0
virtio_pci: macros for PCI layout offsets

 arch/s390/include/asm/pci_io.h        |   1 +
 drivers/virtio/virtio_pci_common.h    |  33 +-
 include/asm-generic/pci_iomap.h       |  10 +
 include/uapi/linux/virtio_pci.h       |  94 ++++-
 arch/mn10300/unit-asb2305/pci-iomap.c |  35 --
 arch/s390/pci/pci.c                   |  34 +-
 drivers/block/virtio_blk.c            |   6 +
 drivers/char/virtio_console.c         |   6 +
 drivers/net/virtio_net.c              |   6 +
 drivers/scsi/virtio_scsi.c            |   6 +
 drivers/virtio/virtio_balloon.c       |   6 +
 drivers/virtio/virtio_pci_common.c    |  79 +++-
 drivers/virtio/virtio_pci_legacy.c    |  76 +---
 drivers/virtio/virtio_pci_modern.c    | 706 ++++++++++++++++++++++++++++++++++
 lib/pci_iomap.c                       |  35 +-
 net/9p/trans_virtio.c                 |   6 +
 drivers/virtio/Makefile               |   2 +-
 17 files changed, 1016 insertions(+), 125 deletions(-)
 delete mode 100644 arch/mn10300/unit-asb2305/pci-iomap.c
 create mode 100644 drivers/virtio/virtio_pci_modern.c
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH v3 1/16 virtio_pci: drop virtio_config dependency

virtio_pci does not depend on virtio_config:
let's not include it, users can pull it in as necessary.

---
 include/uapi/linux/virtio_pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/virtio_pci.h +1 -1
index 35b552c..509d630 100644
@@ -39,7 +39,7 @@
 #ifndef _LINUX_VIRTIO_PCI_H
 #define _LINUX_VIRTIO_PCI_H
 
-#include <linux/virtio_config.h>
+#include <linux/types.h>
 
 #ifndef VIRTIO_PCI_NO_LEGACY
 
Signature · 1 line
MST
author maintainer
#2 lore raw

PATCH v3 2/16 virtio/9p: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/9p needs config space access so make it fail gracefully if not there.

---
 net/9p/trans_virtio.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/9p/trans_virtio.c +6 -0
index daa749c..d8e376a 100644
@@ -524,6 +524,12 @@ static int p9_virtio_probe(struct virtio_device *vdev)
 	int err;
 	struct virtio_chan *chan;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL);
 	if (!chan) {
 		pr_err("Failed to allocate virtio 9P channel\n");
Signature · 1 line
MST
author maintainer
#3 lore raw

PATCH v3 3/16 virtio/blk: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/blk needs config space access so make it fail gracefully if not there.

---
 drivers/block/virtio_blk.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/block/virtio_blk.c +6 -0
index 7ef7c09..7164da8 100644
@@ -575,6 +575,12 @@ static int virtblk_probe(struct virtio_device *vdev)
 	u16 min_io_size;
 	u8 physical_block_exp, alignment_offset;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	err = ida_simple_get(&vd_index_ida, 0, minor_to_index(1 << MINORBITS),
 			     GFP_KERNEL);
 	if (err < 0)
Signature · 1 line
MST
author maintainer
#4 lore raw

PATCH v3 4/16 virtio/console: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/console needs config space access so make it fail gracefully if not there.

---
 drivers/char/virtio_console.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/char/virtio_console.c +6 -0
index de03df9..26afb56 100644
@@ -1986,6 +1986,12 @@ static int virtcons_probe(struct virtio_device *vdev)
 	bool multiport;
 	bool early = early_put_chars != NULL;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	/* Ensure to read early_put_chars now */
 	barrier();
 
Signature · 1 line
MST
#5 lore raw

Re: [PATCH v3 04/16] virtio/console: verify device has config space

Quoted 4 lines · Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/console needs config space access so make it fail gracefully if not there.

Do we know any such devices? Wondering what prompted this patch. If it's just theoretical, I'd rather let it be like this, and pull this in when there's a device that doesn't have config space.

Also, just the console functionality (i.e. F_MULTIPORT is unset) is available w/o config space access. In fact, getting this patch in would mean remoteproc wouldn't even run in its pre-config days...

Quoted 5 lines
drivers/char/virtio_console.c +0 -0
index de03df9..26afb56 100644

drivers/char/virtio_console.c static int virtcons_probe(struct virtio_device *vdev) · line 1994

Quoted 9 lines
drivers/char/virtio_console.c +6 -0
@@ -1986,6 +1986,12 @@ static int virtcons_probe(struct virtio_device *vdev)
 	bool multiport;
 	bool early = early_put_chars != NULL;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+

Amit

author maintainer
#6 lore raw

Re: [PATCH v3 04/16] virtio/console: verify device has config space

Quoted 9 lines · Amit Shah
Quoted 4 lines · Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/console needs config space access so make it fail gracefully if not there.

Do we know any such devices? Wondering what prompted this patch. If it's just theoretical, I'd rather let it be like this, and pull this in when there's a device that doesn't have config space.

Yes, with virtio 1.0 config space can be in a separate BAR now. If that's not enabled by BIOS (e.g. out of space), we won't have config space.

Quoted 2 lines

Also, just the console functionality (i.e. F_MULTIPORT is unset) is available w/o config space access.

Supporting this by gracefully disabling F_MULTIPORT would require getting this info from driver before features are finalized.
Alternatively, check F_MULTIPORT and only fail if set? Let me know, I'll cook up a patch.

Quoted 2 lines

In fact, getting this patch in
would mean remoteproc wouldn't even run in its pre-config days...

It seems to have get callback unconditionally now - or did I miss something?

Quoted 17 lines
Quoted 5 lines
drivers/char/virtio_console.c +0 -0
index de03df9..26afb56 100644

drivers/char/virtio_console.c static int virtcons_probe(struct virtio_device *vdev) · line 1994

Quoted 9 lines
drivers/char/virtio_console.c +6 -0
@@ -1986,6 +1986,12 @@ static int virtcons_probe(struct virtio_device *vdev)
 	bool multiport;
 	bool early = early_put_chars != NULL;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+

Amit

#7 lore raw

Re: [PATCH v3 04/16] virtio/console: verify device has config space

Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Amit Shah
Quoted 4 lines · Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/console needs config space access so make it fail gracefully if not there.

Quoted 7 lines
Quoted 3 lines

Do we know any such devices? Wondering what prompted this patch. If it's just theoretical, I'd rather let it be like this, and pull this in when there's a device that doesn't have config space.

Yes, with virtio 1.0 config space can be in a separate BAR now. If that's not enabled by BIOS (e.g. out of space), we won't have config space.

I'm still not sure whether we should pull in this patch before actually seeing a failure.

You do have a dev_err which tells why the probe failed, so it's an acceptable compromise I suppose.

Quoted 8 lines
Quoted 2 lines

Also, just the console functionality (i.e. F_MULTIPORT is unset) is available w/o config space access.

Supporting this by gracefully disabling F_MULTIPORT would require getting this info from driver before features are finalized.
Alternatively, check F_MULTIPORT and only fail if set? Let me know, I'll cook up a patch.

Yes, failing only if F_MULTIPORT is set is a better option (if we have to fail).

Quoted 5 lines
Quoted 2 lines

In fact, getting this patch in
would mean remoteproc wouldn't even run in its pre-config days...

It seems to have get callback unconditionally now - or did I miss something?

What I meant was remoteproc doesn't depend on the config space, only uses the console functionality. If remoteproc devices didn't expose a config space, this patch would cause it to lose its console functionality for no apparent reason.

Amit

author maintainer
#8 lore raw

Re: [PATCH v3 04/16] virtio/console: verify device has config space

Quoted 25 lines · Amit Shah
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Amit Shah
Quoted 4 lines · Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/console needs config space access so make it fail gracefully if not there.

Quoted 7 lines
Quoted 3 lines

Do we know any such devices? Wondering what prompted this patch. If it's just theoretical, I'd rather let it be like this, and pull this in when there's a device that doesn't have config space.

Yes, with virtio 1.0 config space can be in a separate BAR now. If that's not enabled by BIOS (e.g. out of space), we won't have config space.

I'm still not sure whether we should pull in this patch before actually seeing a failure.

You do have a dev_err which tells why the probe failed, so it's an acceptable compromise I suppose.

Quoted 3 lines
Quoted 2 lines

Also, just the console functionality (i.e. F_MULTIPORT is unset) is available w/o config space access.

Quoted 8 lines
Quoted 5 lines

Supporting this by gracefully disabling F_MULTIPORT would require getting this info from driver before features are finalized.
Alternatively, check F_MULTIPORT and only fail if set? Let me know, I'll cook up a patch.

Yes, failing only if F_MULTIPORT is set is a better option (if we have to fail).

OK, that's easy I think - will send a patch on top.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

In fact, getting this patch in
would mean remoteproc wouldn't even run in its pre-config days...

It seems to have get callback unconditionally now - or did I miss something?

Quoted 7 lines

What I meant was remoteproc doesn't depend on the config space, only uses the console functionality. If remoteproc devices didn't expose a config space, this patch would cause it to lose its console functionality for no apparent reason.

Amit

Better than crashing on jump to NULL?

Signature · 1 line
MST
author maintainer
#9 lore raw

PATCH v3 5/16 virtio/net: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/net needs config space access so make it fail gracefully if not there.

---
 drivers/net/virtio_net.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/virtio_net.c +6 -0
index 5ca9771..9bc1072 100644
@@ -1713,6 +1713,12 @@ static int virtnet_probe(struct virtio_device *vdev)
 	struct virtnet_info *vi;
 	u16 max_queue_pairs;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	if (!virtnet_validate_features(vdev))
 		return -EINVAL;
 
Signature · 1 line
MST
author maintainer
#10 lore raw

PATCH v3 5/16 virtio/net: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/net needs config space access so make it fail gracefully if not there.

---
 drivers/net/virtio_net.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/virtio_net.c +6 -0
index 5ca9771..9bc1072 100644
@@ -1713,6 +1713,12 @@ static int virtnet_probe(struct virtio_device *vdev)
 	struct virtnet_info *vi;
 	u16 max_queue_pairs;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	if (!virtnet_validate_features(vdev))
 		return -EINVAL;
 
Signature · 1 line
MST
author maintainer
#11 lore raw

PATCH v3 6/16 virtio/scsi: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/scsi needs config space access so make it fail gracefully if not there.

---
 drivers/scsi/virtio_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/scsi/virtio_scsi.c +6 -0
index c52bb5d..f164f24 100644
@@ -950,6 +950,12 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	u32 num_queues;
 	struct scsi_host_template *hostt;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	/* We need to know how many queues before we allocate. */
 	num_queues = virtscsi_config_get(vdev, num_queues) ? : 1;
 
Signature · 1 line
MST
author maintainer
#12 lore raw

PATCH v3 6/16 virtio/scsi: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/scsi needs config space access so make it fail gracefully if not there.

---
 drivers/scsi/virtio_scsi.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/scsi/virtio_scsi.c +6 -0
index c52bb5d..f164f24 100644
@@ -950,6 +950,12 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	u32 num_queues;
 	struct scsi_host_template *hostt;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	/* We need to know how many queues before we allocate. */
 	num_queues = virtscsi_config_get(vdev, num_queues) ? : 1;
 
Signature · 1 line
MST
author maintainer
#13 lore raw

PATCH v3 7/16 virtio/balloon: verify device has config space

In reply to Michael S. Tsirkin

Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/balloon needs config space access so make it fail gracefully if not there.

---
 drivers/virtio/virtio_balloon.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/virtio/virtio_balloon.c +6 -0
index 50c5f42..3176ea4 100644
@@ -466,6 +466,12 @@ static int virtballoon_probe(struct virtio_device *vdev)
 	struct virtio_balloon *vb;
 	int err;
 
+	if (!vdev->config->get) {
+		dev_err(&vdev->dev, "%s failure: config access disabled\n",
+			__func__);
+		return -EINVAL;
+	}
+
 	vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
 	if (!vb) {
 		err = -ENOMEM;
Signature · 1 line
MST
author maintainer
#14 lore raw

PATCH v3 8/16 mn10300: drop dead code

In reply to Michael S. Tsirkin

pci-iomap.c was (apparently, mistakenly) reintroduced as part of commit 83c2dc15ce824450e7044b9f90cd529c25747ae0
MN10300: Handle cacheable PCI regions in pci_iomap()
probably as side-effect of forward-porting the patch from an old kernel.

It's not really needed: the generic pci_iomap does the right thing here.

The new file isn't compiled so it's safe to drop.

---

Can relevant people please ack this for merging through virtio tree?

 arch/mn10300/unit-asb2305/pci-iomap.c | 35 -----------------------------------
 1 file changed, 35 deletions(-)
 delete mode 100644 arch/mn10300/unit-asb2305/pci-iomap.c
arch/mn10300/unit-asb2305/pci-iomap.c deleted +0 -35
deleted file mode 100644
index bd65dae..0000000
@@ -1,35 +0,0 @@
-/* ASB2305 PCI I/O mapping handler
- *
- * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells ([email protected])
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public Licence
- * as published by the Free Software Foundation; either version
- * 2 of the Licence, or (at your option) any later version.
- */
-#include <linux/pci.h>
-#include <linux/module.h>
-
-/*
- * Create a virtual mapping cookie for a PCI BAR (memory or IO)
- */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
-{
-	resource_size_t start = pci_resource_start(dev, bar);
-	resource_size_t len = pci_resource_len(dev, bar);
-	unsigned long flags = pci_resource_flags(dev, bar);
-
-	if (!len || !start)
-		return NULL;
-
-	if ((flags & IORESOURCE_IO) || (flags & IORESOURCE_MEM)) {
-		if (flags & IORESOURCE_CACHEABLE && !(flags & IORESOURCE_IO))
-			return ioremap(start, len);
-		else
-			return ioremap_nocache(start, len);
-	}
-
-	return NULL;
-}
-EXPORT_SYMBOL(pci_iomap);
Signature · 1 line
MST
author maintainer
#15 lore raw

PATCH v3 8/16 mn10300: drop dead code

In reply to Michael S. Tsirkin

pci-iomap.c was (apparently, mistakenly) reintroduced as part of commit 83c2dc15ce824450e7044b9f90cd529c25747ae0
MN10300: Handle cacheable PCI regions in pci_iomap()
probably as side-effect of forward-porting the patch from an old kernel.

It's not really needed: the generic pci_iomap does the right thing here.

The new file isn't compiled so it's safe to drop.

---

Can relevant people please ack this for merging through virtio tree?

 arch/mn10300/unit-asb2305/pci-iomap.c | 35 -----------------------------------
 1 file changed, 35 deletions(-)
 delete mode 100644 arch/mn10300/unit-asb2305/pci-iomap.c
arch/mn10300/unit-asb2305/pci-iomap.c deleted +0 -35
deleted file mode 100644
index bd65dae..0000000
@@ -1,35 +0,0 @@
-/* ASB2305 PCI I/O mapping handler
- *
- * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells ([email protected])
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public Licence
- * as published by the Free Software Foundation; either version
- * 2 of the Licence, or (at your option) any later version.
- */
-#include <linux/pci.h>
-#include <linux/module.h>
-
-/*
- * Create a virtual mapping cookie for a PCI BAR (memory or IO)
- */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
-{
-	resource_size_t start = pci_resource_start(dev, bar);
-	resource_size_t len = pci_resource_len(dev, bar);
-	unsigned long flags = pci_resource_flags(dev, bar);
-
-	if (!len || !start)
-		return NULL;
-
-	if ((flags & IORESOURCE_IO) || (flags & IORESOURCE_MEM)) {
-		if (flags & IORESOURCE_CACHEABLE && !(flags & IORESOURCE_IO))
-			return ioremap(start, len);
-		else
-			return ioremap_nocache(start, len);
-	}
-
-	return NULL;
-}
-EXPORT_SYMBOL(pci_iomap);
Signature · 1 line
MST
maintainer Acked-by on v3 8/16
#16 lore raw

Re: [PATCH v3 08/16] mn10300: drop dead code

Quoted 8 lines · Michael S. Tsirkin

pci-iomap.c was (apparently, mistakenly) reintroduced as part of commit 83c2dc15ce824450e7044b9f90cd529c25747ae0
MN10300: Handle cacheable PCI regions in pci_iomap()
probably as side-effect of forward-porting the patch from an old kernel.

It's not really needed: the generic pci_iomap does the right thing here.

Quoted 7 lines

The new file isn't compiled so it's safe to drop.

Quoted 52 lines

---

Can relevant people please ack this for merging through virtio tree?

 arch/mn10300/unit-asb2305/pci-iomap.c | 35 -----------------------------------
 1 file changed, 35 deletions(-)
 delete mode 100644 arch/mn10300/unit-asb2305/pci-iomap.c
arch/mn10300/unit-asb2305/pci-iomap.c deleted +0 -35
deleted file mode 100644
index bd65dae..0000000
@@ -1,35 +0,0 @@
-/* ASB2305 PCI I/O mapping handler
- *
- * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells ([email protected])
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public Licence
- * as published by the Free Software Foundation; either version
- * 2 of the Licence, or (at your option) any later version.
- */
-#include <linux/pci.h>
-#include <linux/module.h>
-
-/*
- * Create a virtual mapping cookie for a PCI BAR (memory or IO)
- */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
-{
-	resource_size_t start = pci_resource_start(dev, bar);
-	resource_size_t len = pci_resource_len(dev, bar);
-	unsigned long flags = pci_resource_flags(dev, bar);
-
-	if (!len || !start)
-		return NULL;
-
-	if ((flags & IORESOURCE_IO) || (flags & IORESOURCE_MEM)) {
-		if (flags & IORESOURCE_CACHEABLE && !(flags & IORESOURCE_IO))
-			return ioremap(start, len);
-		else
-			return ioremap_nocache(start, len);
-	}
-
-	return NULL;
-}
-EXPORT_SYMBOL(pci_iomap);
Signature · 1 line
MST
author maintainer
#17 lore raw

PATCH v3 9/16 pci: add pci_iomap_range

In reply to Michael S. Tsirkin

Virtio drivers should map the part of the BAR they need, not necessarily all of it.

---

Bjorn, can you please ack this for merging through the virtio tree?

 include/asm-generic/pci_iomap.h | 10 ++++++++++
 lib/pci_iomap.c                 | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)
include/asm-generic/pci_iomap.h +10 -0
index ce37349..7389c87 100644
@@ -15,6 +15,9 @@ struct pci_dev;
 #ifdef CONFIG_PCI
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+				     unsigned long offset,
+				     unsigned long maxlen);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
@@ -30,6 +33,13 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lon
 {
 	return NULL;
 }
+
+static inline void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+					    unsigned long offset,
+					    unsigned long maxlen)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __ASM_GENERIC_IO_H */
lib/pci_iomap.c +30 -5
index 0d83ea8..bcce5f1 100644
@@ -10,10 +10,11 @@
 
 #ifdef CONFIG_PCI
 /**
- * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
  * @dev: PCI device that owns the BAR
  * @bar: BAR number
- * @maxlen: length of the memory to map
+ * @offset: map memory at the given offset in BAR
+ * @maxlen: max length of the memory to map
  *
  * Using this function you will get a __iomem address to your device BAR.
  * You can access it using ioread*() and iowrite*(). These functions hide
@@ -21,16 +22,21 @@
  * you expect from them in the correct way.
  *
  * @maxlen specifies the maximum length to map. If you want to get access to
- * the complete BAR without checking for its length first, pass %0 here.
+ * the complete BAR from offset to the end, pass %0 here.
  * */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomem *pci_iomap_range(struct pci_dev *dev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long maxlen)
 {
 	resource_size_t start = pci_resource_start(dev, bar);
 	resource_size_t len = pci_resource_len(dev, bar);
 	unsigned long flags = pci_resource_flags(dev, bar);
 
-	if (!len || !start)
+	if (len <= offset || !start)
 		return NULL;
+	len -= offset;
+	start += offset;
 	if (maxlen && len > maxlen)
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
@@ -43,6 +49,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	/* What? */
 	return NULL;
 }
+EXPORT_SYMBOL(pci_iomap_range);
 
+/**
+ * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of the memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using ioread*() and iowrite*(). These functions hide
+ * the details if this is a MMIO or PIO address space and will just do what
+ * you expect from them in the correct way.
+ *
+ * @maxlen specifies the maximum length to map. If you want to get access to
+ * the complete BAR without checking for its length first, pass %0 here.
+ * */
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
 EXPORT_SYMBOL(pci_iomap);
 #endif /* CONFIG_PCI */
Signature · 1 line
MST
maintainer Acked-by on v3 9/16
#18 lore raw

Re: [PATCH v3 09/16] pci: add pci_iomap_range

Quoted 8 lines · Michael S. Tsirkin

Virtio drivers should map the part of the BAR they need, not necessarily all of it.

Sorry it took so long for me to notice these!

Quoted 108 lines

---

Bjorn, can you please ack this for merging through the virtio tree?

 include/asm-generic/pci_iomap.h | 10 ++++++++++
 lib/pci_iomap.c                 | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)
include/asm-generic/pci_iomap.h +10 -0
index ce37349..7389c87 100644
@@ -15,6 +15,9 @@ struct pci_dev;
 #ifdef CONFIG_PCI
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+				     unsigned long offset,
+				     unsigned long maxlen);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
@@ -30,6 +33,13 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lon
 {
 	return NULL;
 }
+
+static inline void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+					    unsigned long offset,
+					    unsigned long maxlen)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __ASM_GENERIC_IO_H */
lib/pci_iomap.c +30 -5
index 0d83ea8..bcce5f1 100644
@@ -10,10 +10,11 @@
 
 #ifdef CONFIG_PCI
 /**
- * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
  * @dev: PCI device that owns the BAR
  * @bar: BAR number
- * @maxlen: length of the memory to map
+ * @offset: map memory at the given offset in BAR
+ * @maxlen: max length of the memory to map
  *
  * Using this function you will get a __iomem address to your device BAR.
  * You can access it using ioread*() and iowrite*(). These functions hide
@@ -21,16 +22,21 @@
  * you expect from them in the correct way.
  *
  * @maxlen specifies the maximum length to map. If you want to get access to
- * the complete BAR without checking for its length first, pass %0 here.
+ * the complete BAR from offset to the end, pass %0 here.
  * */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomem *pci_iomap_range(struct pci_dev *dev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long maxlen)
 {
 	resource_size_t start = pci_resource_start(dev, bar);
 	resource_size_t len = pci_resource_len(dev, bar);
 	unsigned long flags = pci_resource_flags(dev, bar);
 
-	if (!len || !start)
+	if (len <= offset || !start)
 		return NULL;
+	len -= offset;
+	start += offset;
 	if (maxlen && len > maxlen)
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
@@ -43,6 +49,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	/* What? */
 	return NULL;
 }
+EXPORT_SYMBOL(pci_iomap_range);
 
+/**
+ * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of the memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using ioread*() and iowrite*(). These functions hide
+ * the details if this is a MMIO or PIO address space and will just do what
+ * you expect from them in the correct way.
+ *
+ * @maxlen specifies the maximum length to map. If you want to get access to
+ * the complete BAR without checking for its length first, pass %0 here.
+ * */
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
 EXPORT_SYMBOL(pci_iomap);
 #endif /* CONFIG_PCI */
Signature · 1 line
MST
maintainer Acked-by on v3 9/16
#19 lore raw

Re: [PATCH v3 09/16] pci: add pci_iomap_range

In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

Virtio drivers should map the part of the BAR they need, not necessarily all of it.

Sorry it took so long for me to notice these!

Quoted 108 lines

---

Bjorn, can you please ack this for merging through the virtio tree?

 include/asm-generic/pci_iomap.h | 10 ++++++++++
 lib/pci_iomap.c                 | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)
include/asm-generic/pci_iomap.h +10 -0
index ce37349..7389c87 100644
@@ -15,6 +15,9 @@ struct pci_dev;
 #ifdef CONFIG_PCI
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+				     unsigned long offset,
+				     unsigned long maxlen);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
@@ -30,6 +33,13 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lon
 {
 	return NULL;
 }
+
+static inline void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+					    unsigned long offset,
+					    unsigned long maxlen)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __ASM_GENERIC_IO_H */
lib/pci_iomap.c +30 -5
index 0d83ea8..bcce5f1 100644
@@ -10,10 +10,11 @@
 
 #ifdef CONFIG_PCI
 /**
- * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
  * @dev: PCI device that owns the BAR
  * @bar: BAR number
- * @maxlen: length of the memory to map
+ * @offset: map memory at the given offset in BAR
+ * @maxlen: max length of the memory to map
  *
  * Using this function you will get a __iomem address to your device BAR.
  * You can access it using ioread*() and iowrite*(). These functions hide
@@ -21,16 +22,21 @@
  * you expect from them in the correct way.
  *
  * @maxlen specifies the maximum length to map. If you want to get access to
- * the complete BAR without checking for its length first, pass %0 here.
+ * the complete BAR from offset to the end, pass %0 here.
  * */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomem *pci_iomap_range(struct pci_dev *dev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long maxlen)
 {
 	resource_size_t start = pci_resource_start(dev, bar);
 	resource_size_t len = pci_resource_len(dev, bar);
 	unsigned long flags = pci_resource_flags(dev, bar);
 
-	if (!len || !start)
+	if (len <= offset || !start)
 		return NULL;
+	len -= offset;
+	start += offset;
 	if (maxlen && len > maxlen)
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
@@ -43,6 +49,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	/* What? */
 	return NULL;
 }
+EXPORT_SYMBOL(pci_iomap_range);
 
+/**
+ * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of the memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using ioread*() and iowrite*(). These functions hide
+ * the details if this is a MMIO or PIO address space and will just do what
+ * you expect from them in the correct way.
+ *
+ * @maxlen specifies the maximum length to map. If you want to get access to
+ * the complete BAR without checking for its length first, pass %0 here.
+ * */
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
 EXPORT_SYMBOL(pci_iomap);
 #endif /* CONFIG_PCI */
Signature · 1 line
MST
author maintainer
#20 lore raw

PATCH v3 9/16 pci: add pci_iomap_range

In reply to Michael S. Tsirkin

Virtio drivers should map the part of the BAR they need, not necessarily all of it.

---

Bjorn, can you please ack this for merging through the virtio tree?

 include/asm-generic/pci_iomap.h | 10 ++++++++++
 lib/pci_iomap.c                 | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 5 deletions(-)
include/asm-generic/pci_iomap.h +10 -0
index ce37349..7389c87 100644
@@ -15,6 +15,9 @@ struct pci_dev;
 #ifdef CONFIG_PCI
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+				     unsigned long offset,
+				     unsigned long maxlen);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
@@ -30,6 +33,13 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lon
 {
 	return NULL;
 }
+
+static inline void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
+					    unsigned long offset,
+					    unsigned long maxlen)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __ASM_GENERIC_IO_H */
lib/pci_iomap.c +30 -5
index 0d83ea8..bcce5f1 100644
@@ -10,10 +10,11 @@
 
 #ifdef CONFIG_PCI
 /**
- * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
  * @dev: PCI device that owns the BAR
  * @bar: BAR number
- * @maxlen: length of the memory to map
+ * @offset: map memory at the given offset in BAR
+ * @maxlen: max length of the memory to map
  *
  * Using this function you will get a __iomem address to your device BAR.
  * You can access it using ioread*() and iowrite*(). These functions hide
@@ -21,16 +22,21 @@
  * you expect from them in the correct way.
  *
  * @maxlen specifies the maximum length to map. If you want to get access to
- * the complete BAR without checking for its length first, pass %0 here.
+ * the complete BAR from offset to the end, pass %0 here.
  * */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomem *pci_iomap_range(struct pci_dev *dev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long maxlen)
 {
 	resource_size_t start = pci_resource_start(dev, bar);
 	resource_size_t len = pci_resource_len(dev, bar);
 	unsigned long flags = pci_resource_flags(dev, bar);
 
-	if (!len || !start)
+	if (len <= offset || !start)
 		return NULL;
+	len -= offset;
+	start += offset;
 	if (maxlen && len > maxlen)
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
@@ -43,6 +49,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 	/* What? */
 	return NULL;
 }
+EXPORT_SYMBOL(pci_iomap_range);
 
+/**
+ * pci_iomap - create a virtual mapping cookie for a PCI BAR
+ * @dev: PCI device that owns the BAR
+ * @bar: BAR number
+ * @maxlen: length of the memory to map
+ *
+ * Using this function you will get a __iomem address to your device BAR.
+ * You can access it using ioread*() and iowrite*(). These functions hide
+ * the details if this is a MMIO or PIO address space and will just do what
+ * you expect from them in the correct way.
+ *
+ * @maxlen specifies the maximum length to map. If you want to get access to
+ * the complete BAR without checking for its length first, pass %0 here.
+ * */
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
 EXPORT_SYMBOL(pci_iomap);
 #endif /* CONFIG_PCI */
Signature · 1 line
MST
author maintainer
#21 lore raw

PATCH v3 10/16 s390: add pci_iomap_range

In reply to Michael S. Tsirkin

Virtio drivers should map the part of the range they need, not necessarily all of it.
To this end, support mapping ranges within BAR on s390. Since multiple ranges can now be mapped within a BAR, we keep track of the number of mappings created, and only clear out the mapping for a BAR when this number reaches 0.

---

Heiko, Martin, can you please ack merging this through the virtio tree? This was lightly tested by Sebastian Ott.

 arch/s390/include/asm/pci_io.h |  1 +
 arch/s390/pci/pci.c            | 34 +++++++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)
arch/s390/include/asm/pci_io.h +1 -0
index f664e96..1a9a98d 100644
@@ -16,6 +16,7 @@
 struct zpci_iomap_entry {
 	u32 fh;
 	u8 bar;
+	u16 count;
 };
 
 extern struct zpci_iomap_entry *zpci_iomap_start;
arch/s390/pci/pci.c +27 -7
index 3290f11..753a567 100644
@@ -259,7 +259,10 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
 }
 
 /* Create a virtual mapping cookie for a PCI BAR */
-void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
+void __iomem *pci_iomap_range(struct pci_dev *pdev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long max)
 {
 	struct zpci_dev *zdev =	get_zdev(pdev);
 	u64 addr;
@@ -270,14 +273,27 @@ void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
 
 	idx = zdev->bars[bar].map_idx;
 	spin_lock(&zpci_iomap_lock);
-	zpci_iomap_start[idx].fh = zdev->fh;
-	zpci_iomap_start[idx].bar = bar;
+	if (zpci_iomap_start[idx].count++) {
+		BUG_ON(zpci_iomap_start[idx].fh != zdev->fh ||
+		       zpci_iomap_start[idx].bar != bar);
+	} else {
+		zpci_iomap_start[idx].fh = zdev->fh;
+		zpci_iomap_start[idx].bar = bar;
+	}
+	/* Detect overrun */
+	BUG_ON(!zpci_iomap_start[idx].count);
 	spin_unlock(&zpci_iomap_lock);
 
 	addr = ZPCI_IOMAP_ADDR_BASE | ((u64) idx << 48);
-	return (void __iomem *) addr;
+	return (void __iomem *) addr + offset;
 }
-EXPORT_SYMBOL_GPL(pci_iomap);
+EXPORT_SYMBOL_GPL(pci_iomap_range);
+
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
+EXPORT_SYMBOL(pci_iomap);
 
 void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
 {
@@ -285,8 +301,12 @@ void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
 
 	idx = (((__force u64) addr) & ~ZPCI_IOMAP_ADDR_BASE) >> 48;
 	spin_lock(&zpci_iomap_lock);
-	zpci_iomap_start[idx].fh = 0;
-	zpci_iomap_start[idx].bar = 0;
+	/* Detect underrun */
+	BUG_ON(!zpci_iomap_start[idx].count);
+	if (!--zpci_iomap_start[idx].count) {
+		zpci_iomap_start[idx].fh = 0;
+		zpci_iomap_start[idx].bar = 0;
+	}
 	spin_unlock(&zpci_iomap_lock);
 }
 EXPORT_SYMBOL_GPL(pci_iounmap);
Signature · 1 line
MST
Acked-by on v3 10/16
#22 lore raw

Re: [PATCH v3 10/16] s390: add pci_iomap_range

Quoted 67 lines · Michael S. Tsirkin

Virtio drivers should map the part of the range they need, not necessarily all of it.
To this end, support mapping ranges within BAR on s390. Since multiple ranges can now be mapped within a BAR, we keep track of the number of mappings created, and only clear out the mapping for a BAR when this number reaches 0.

---

Heiko, Martin, can you please ack merging this through the virtio tree? This was lightly tested by Sebastian Ott.

 arch/s390/include/asm/pci_io.h |  1 +
 arch/s390/pci/pci.c            | 34 +++++++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)
arch/s390/include/asm/pci_io.h +1 -0
index f664e96..1a9a98d 100644
@@ -16,6 +16,7 @@
 struct zpci_iomap_entry {
 	u32 fh;
 	u8 bar;
+	u16 count;
 };
 
 extern struct zpci_iomap_entry *zpci_iomap_start;
arch/s390/pci/pci.c +13 -4
index 3290f11..753a567 100644
@@ -259,7 +259,10 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
 }
 
 /* Create a virtual mapping cookie for a PCI BAR */
-void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
+void __iomem *pci_iomap_range(struct pci_dev *pdev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long max)
 {
 	struct zpci_dev *zdev =	get_zdev(pdev);
 	u64 addr;
@@ -270,14 +273,27 @@ void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
 
 	idx = zdev->bars[bar].map_idx;
 	spin_lock(&zpci_iomap_lock);
-	zpci_iomap_start[idx].fh = zdev->fh;
-	zpci_iomap_start[idx].bar = bar;
+	if (zpci_iomap_start[idx].count++) {
+		BUG_ON(zpci_iomap_start[idx].fh != zdev->fh ||
+		       zpci_iomap_start[idx].bar != bar);
+	} else {
+		zpci_iomap_start[idx].fh = zdev->fh;
+		zpci_iomap_start[idx].bar = bar;
+	}
+	/* Detect overrun */
+	BUG_ON(!zpci_iomap_start[idx].count);
 	spin_unlock(&zpci_iomap_lock);
 
 	addr = ZPCI_IOMAP_ADDR_BASE | ((u64) idx << 48);
-	return (void __iomem *) addr;

arch/s390/pci/pci.c void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max) · line 296

Quoted 10 lines
arch/s390/pci/pci.c +8 -1
+	return (void __iomem *) addr + offset;
 }
-EXPORT_SYMBOL_GPL(pci_iomap);
+EXPORT_SYMBOL_GPL(pci_iomap_range);
+
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
+EXPORT_SYMBOL(pci_iomap);

As discussed earlier, could you please leave that as EXPORT_SYMBOL_GPL. If there's a reason to have these interfaces as EXPORT_SYMBOL, we could change all of them in an extra patch.

With this change integrated you can add

Regards,
Sebastian

Quoted 22 lines
arch/s390/pci/pci.c +6 -2
 void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
 {
@@ -285,8 +301,12 @@ void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
 
 	idx = (((__force u64) addr) & ~ZPCI_IOMAP_ADDR_BASE) >> 48;
 	spin_lock(&zpci_iomap_lock);
-	zpci_iomap_start[idx].fh = 0;
-	zpci_iomap_start[idx].bar = 0;
+	/* Detect underrun */
+	BUG_ON(!zpci_iomap_start[idx].count);
+	if (!--zpci_iomap_start[idx].count) {
+		zpci_iomap_start[idx].fh = 0;
+		zpci_iomap_start[idx].bar = 0;
+	}
 	spin_unlock(&zpci_iomap_lock);
 }
 EXPORT_SYMBOL_GPL(pci_iounmap);
Signature · 1 line
MST
#23 lore raw

Re: [PATCH v3 10/16] s390: add pci_iomap_range

Quoted 15 lines · Sebastian Ott

arch/s390/pci/pci.c void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max) · line 296

Quoted 9 lines · Michael S. Tsirkin

}

arch/s390/pci/pci.c +7 -1
-EXPORT_SYMBOL_GPL(pci_iomap);
+EXPORT_SYMBOL_GPL(pci_iomap_range);
+
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
+EXPORT_SYMBOL(pci_iomap);

As discussed earlier, could you please leave that as EXPORT_SYMBOL_GPL. If there's a reason to have these interfaces as EXPORT_SYMBOL, we could change all of them in an extra patch.

Quoted 2 lines

With this change integrated you can add

OK, I've gone back and rebased virtio-next to fix this (I don't really want to think too hard about the legal consequences of having a version which isn't EXPORT_SYMBOL_GPL).

Thanks,
Rusty.

Acked-by on v3 10/16
#24 lore raw

Re: [PATCH v3 10/16] s390: add pci_iomap_range

In reply to Michael S. Tsirkin
Quoted 67 lines · Michael S. Tsirkin

Virtio drivers should map the part of the range they need, not necessarily all of it.
To this end, support mapping ranges within BAR on s390. Since multiple ranges can now be mapped within a BAR, we keep track of the number of mappings created, and only clear out the mapping for a BAR when this number reaches 0.

---

Heiko, Martin, can you please ack merging this through the virtio tree? This was lightly tested by Sebastian Ott.

 arch/s390/include/asm/pci_io.h |  1 +
 arch/s390/pci/pci.c            | 34 +++++++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)
arch/s390/include/asm/pci_io.h +1 -0
index f664e96..1a9a98d 100644
@@ -16,6 +16,7 @@
 struct zpci_iomap_entry {
 	u32 fh;
 	u8 bar;
+	u16 count;
 };
 
 extern struct zpci_iomap_entry *zpci_iomap_start;
arch/s390/pci/pci.c +13 -4
index 3290f11..753a567 100644
@@ -259,7 +259,10 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
 }
 
 /* Create a virtual mapping cookie for a PCI BAR */
-void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
+void __iomem *pci_iomap_range(struct pci_dev *pdev,
+			      int bar,
+			      unsigned long offset,
+			      unsigned long max)
 {
 	struct zpci_dev *zdev =	get_zdev(pdev);
 	u64 addr;
@@ -270,14 +273,27 @@ void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
 
 	idx = zdev->bars[bar].map_idx;
 	spin_lock(&zpci_iomap_lock);
-	zpci_iomap_start[idx].fh = zdev->fh;
-	zpci_iomap_start[idx].bar = bar;
+	if (zpci_iomap_start[idx].count++) {
+		BUG_ON(zpci_iomap_start[idx].fh != zdev->fh ||
+		       zpci_iomap_start[idx].bar != bar);
+	} else {
+		zpci_iomap_start[idx].fh = zdev->fh;
+		zpci_iomap_start[idx].bar = bar;
+	}
+	/* Detect overrun */
+	BUG_ON(!zpci_iomap_start[idx].count);
 	spin_unlock(&zpci_iomap_lock);
 
 	addr = ZPCI_IOMAP_ADDR_BASE | ((u64) idx << 48);
-	return (void __iomem *) addr;

arch/s390/pci/pci.c void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max) · line 296

Quoted 10 lines
arch/s390/pci/pci.c +8 -1
+	return (void __iomem *) addr + offset;
 }
-EXPORT_SYMBOL_GPL(pci_iomap);
+EXPORT_SYMBOL_GPL(pci_iomap_range);
+
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+	return pci_iomap_range(dev, bar, 0, maxlen);
+}
+EXPORT_SYMBOL(pci_iomap);

As discussed earlier, could you please leave that as EXPORT_SYMBOL_GPL. If there's a reason to have these interfaces as EXPORT_SYMBOL, we could change all of them in an extra patch.

With this change integrated you can add

Regards,
Sebastian

Quoted 22 lines
arch/s390/pci/pci.c +6 -2
 void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
 {
@@ -285,8 +301,12 @@ void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
 
 	idx = (((__force u64) addr) & ~ZPCI_IOMAP_ADDR_BASE) >> 48;
 	spin_lock(&zpci_iomap_lock);
-	zpci_iomap_start[idx].fh = 0;
-	zpci_iomap_start[idx].bar = 0;
+	/* Detect underrun */
+	BUG_ON(!zpci_iomap_start[idx].count);
+	if (!--zpci_iomap_start[idx].count) {
+		zpci_iomap_start[idx].fh = 0;
+		zpci_iomap_start[idx].bar = 0;
+	}
 	spin_unlock(&zpci_iomap_lock);
 }
 EXPORT_SYMBOL_GPL(pci_iounmap);
Signature · 1 line
MST
author maintainer
#25 lore raw

PATCH v3 11/16 virtio_pci: move probe/remove code to common

In reply to Michael S. Tsirkin

Most of initialization is device-independent.
Let's move it to common.

---
 drivers/virtio/virtio_pci_common.h |  5 +--
 drivers/virtio/virtio_pci_common.c | 69 +++++++++++++++++++++++++++++++++-
 drivers/virtio/virtio_pci_legacy.c | 76 ++++----------------------------------
 3 files changed, 77 insertions(+), 73 deletions(-)
drivers/virtio/virtio_pci_common.h +2 -3
index 5a49728..2b1e70d 100644
@@ -127,8 +127,7 @@ const char *vp_bus_name(struct virtio_device *vdev);
  */
 int vp_set_vq_affinity(struct virtqueue *vq, int cpu);
 
-int virtio_pci_legacy_probe(struct pci_dev *pci_dev,
-			    const struct pci_device_id *id);
-void virtio_pci_legacy_remove(struct pci_dev *pci_dev);
+int virtio_pci_legacy_probe(struct virtio_pci_device *);
+void virtio_pci_legacy_remove(struct virtio_pci_device *);
 
 #endif
drivers/virtio/virtio_pci_common.c +67 -2

82 lines not on this page · raw message

drivers/virtio/virtio_pci_legacy.c +8 -68

108 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#26 lore raw

PATCH v3 12/16 virtio-pci: define layout for virtio 1.0

In reply to Michael S. Tsirkin

From: Rusty Russell <[email protected]>

Based on patches by Michael S. Tsirkin <[email protected]>, but I found it hard to follow so changed to use structures which are more self-documenting.

---
 include/uapi/linux/virtio_pci.h | 62 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
include/uapi/linux/virtio_pci.h +62 -0
index 509d630..4e05423 100644
@@ -99,4 +99,66 @@
 /* Vector value used to disable MSI for queue */
 #define VIRTIO_MSI_NO_VECTOR            0xffff
 
+#ifndef VIRTIO_PCI_NO_MODERN
+
+/* IDs for different capabilities.  Must all exist. */
+
+/* Common configuration */
+#define VIRTIO_PCI_CAP_COMMON_CFG	1
+/* Notifications */
+#define VIRTIO_PCI_CAP_NOTIFY_CFG	2
+/* ISR access */
+#define VIRTIO_PCI_CAP_ISR_CFG		3
+/* Device specific confiuration */
+#define VIRTIO_PCI_CAP_DEVICE_CFG	4
+
+/* This is the PCI capability header: */
+struct virtio_pci_cap {
+	__u8 cap_vndr;		/* Generic PCI field: PCI_CAP_ID_VNDR */
+	__u8 cap_next;		/* Generic PCI field: next ptr. */
+	__u8 cap_len;		/* Generic PCI field: capability length */
+	__u8 type_and_bar;	/* Upper 3 bits: bar.
+				 * Lower 3 is VIRTIO_PCI_CAP_*_CFG. */
+	__le32 offset;		/* Offset within bar. */
+	__le32 length;		/* Length. */
+};
+
+#define VIRTIO_PCI_CAP_BAR_SHIFT	5
+#define VIRTIO_PCI_CAP_BAR_MASK		0x7
+#define VIRTIO_PCI_CAP_TYPE_SHIFT	0
+#define VIRTIO_PCI_CAP_TYPE_MASK	0x7
+
+struct virtio_pci_notify_cap {
+	struct virtio_pci_cap cap;
+	__le32 notify_off_multiplier;	/* Multiplier for queue_notify_off. */
+};
+
+/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
+struct virtio_pci_common_cfg {
+	/* About the whole device. */
+	__le32 device_feature_select;	/* read-write */
+	__le32 device_feature;		/* read-only */
+	__le32 guest_feature_select;	/* read-write */
+	__le32 guest_feature;		/* read-write */
+	__le16 msix_config;		/* read-write */
+	__le16 num_queues;		/* read-only */
+	__u8 device_status;		/* read-write */
+	__u8 config_generation;		/* read-only */
+
+	/* About a specific virtqueue. */
+	__le16 queue_select;		/* read-write */
+	__le16 queue_size;		/* read-write, power of 2. */
+	__le16 queue_msix_vector;	/* read-write */
+	__le16 queue_enable;		/* read-write */
+	__le16 queue_notify_off;	/* read-only */
+	__le32 queue_desc_lo;		/* read-write */
+	__le32 queue_desc_hi;		/* read-write */
+	__le32 queue_avail_lo;		/* read-write */
+	__le32 queue_avail_hi;		/* read-write */
+	__le32 queue_used_lo;		/* read-write */
+	__le32 queue_used_hi;		/* read-write */
+};
+
+#endif /* VIRTIO_PCI_NO_MODERN */
+
 #endif
Signature · 1 line
MST
author maintainer
#27 lore raw

PATCH v3 13/16 virtio_pci: modern driver

In reply to Michael S. Tsirkin

Lightly tested against qemu.

One thing *not* implemented here is separate mappings for descriptor/avail/used rings. That's nice to have, will be done later after we have core support.

This also exposes the PCI layout to userspace, and adds macros for PCI layout offsets:

QEMU wants it, so why not? Trust, but verify.

---
 drivers/virtio/virtio_pci_common.h |  25 +-
 drivers/virtio/virtio_pci_common.c |  14 +-
 drivers/virtio/virtio_pci_modern.c | 592 +++++++++++++++++++++++++++++++++++++
 drivers/virtio/Makefile            |   2 +-
 4 files changed, 627 insertions(+), 6 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_modern.c
drivers/virtio/virtio_pci_common.h +22 -3
index 2b1e70d..610c43f 100644
@@ -53,12 +53,29 @@ struct virtio_pci_device {
 	struct virtio_device vdev;
 	struct pci_dev *pci_dev;
 
+	/* In legacy mode, these two point to within ->legacy. */
+	/* Where to read and clear interrupt */
+	u8 __iomem *isr;
+
+	/* Modern only fields */
+	/* The IO mapping for the PCI config space (non-legacy mode) */
+	struct virtio_pci_common_cfg __iomem *common;
+	/* Device-specific data (non-legacy mode)  */
+	void __iomem *device;
+
+	/* So we can sanity-check accesses. */
+	size_t device_len;
+
+	/* Capability for when we need to map notifications per-vq. */
+	int notify_map_cap;
+
+	/* Multiply queue_notify_off by this value. (non-legacy mode). */
+	u32 notify_offset_multiplier;
+
+	/* Legacy only field */
 	/* the IO mapping for the PCI config space */
 	void __iomem *ioaddr;
 
-	/* the IO mapping for ISR operation */
-	void __iomem *isr;
-
 	/* a list of queues so we can dispatch IRQs */
 	spinlock_t lock;
 	struct list_head virtqueues;
@@ -129,5 +146,7 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu);
 
 int virtio_pci_legacy_probe(struct virtio_pci_device *);
 void virtio_pci_legacy_remove(struct virtio_pci_device *);
+int virtio_pci_modern_probe(struct virtio_pci_device *);
+void virtio_pci_modern_remove(struct virtio_pci_device *);
 
 #endif
drivers/virtio/virtio_pci_common.c +12 -2
index 457cbe2..20c7638 100644
@@ -505,6 +505,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	if (rc)
 		goto err_request_regions;
 
+	rc = virtio_pci_modern_probe(vp_dev);
+	if (rc != -ENODEV)
+		return rc;
+
 	rc = virtio_pci_legacy_probe(vp_dev);
 	if (rc)
 		goto err_probe;
@@ -518,7 +522,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err_register:
-	virtio_pci_legacy_remove(vp_dev);
+	if (vp_dev->ioaddr)
+	     virtio_pci_legacy_remove(vp_dev);
+	else
+	     virtio_pci_modern_remove(vp_dev);
 err_probe:
 	pci_release_regions(pci_dev);
 err_request_regions:
@@ -534,7 +541,10 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
 	unregister_virtio_device(&vp_dev->vdev);
 
-	virtio_pci_legacy_remove(pci_dev);
+	if (vp_dev->ioaddr)
+		virtio_pci_legacy_remove(vp_dev);
+	else
+		virtio_pci_modern_remove(vp_dev);
 
 	pci_release_regions(pci_dev);
 	pci_disable_device(pci_dev);
drivers/virtio/virtio_pci_modern.c new file +592 -0

592 lines not on this page · raw message

drivers/virtio/Makefile +1 -1
index bf5104b..bd230d1 100644
@@ -1,5 +1,5 @@
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
-virtio_pci-y := virtio_pci_legacy.o virtio_pci_common.o
+virtio_pci-y := virtio_pci_modern.o virtio_pci_legacy.o virtio_pci_common.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
Signature · 1 line
MST
author maintainer
#28 lore raw

PATCH v3 13/16 virtio_pci: modern driver

In reply to Michael S. Tsirkin

Lightly tested against qemu.

One thing *not* implemented here is separate mappings for descriptor/avail/used rings. That's nice to have, will be done later after we have core support.

This also exposes the PCI layout to userspace, and adds macros for PCI layout offsets:

QEMU wants it, so why not? Trust, but verify.

---
 drivers/virtio/virtio_pci_common.h |  25 +-
 drivers/virtio/virtio_pci_common.c |  14 +-
 drivers/virtio/virtio_pci_modern.c | 592 +++++++++++++++++++++++++++++++++++++
 drivers/virtio/Makefile            |   2 +-
 4 files changed, 627 insertions(+), 6 deletions(-)
 create mode 100644 drivers/virtio/virtio_pci_modern.c
drivers/virtio/virtio_pci_common.h +22 -3
index 2b1e70d..610c43f 100644
@@ -53,12 +53,29 @@ struct virtio_pci_device {
 	struct virtio_device vdev;
 	struct pci_dev *pci_dev;
 
+	/* In legacy mode, these two point to within ->legacy. */
+	/* Where to read and clear interrupt */
+	u8 __iomem *isr;
+
+	/* Modern only fields */
+	/* The IO mapping for the PCI config space (non-legacy mode) */
+	struct virtio_pci_common_cfg __iomem *common;
+	/* Device-specific data (non-legacy mode)  */
+	void __iomem *device;
+
+	/* So we can sanity-check accesses. */
+	size_t device_len;
+
+	/* Capability for when we need to map notifications per-vq. */
+	int notify_map_cap;
+
+	/* Multiply queue_notify_off by this value. (non-legacy mode). */
+	u32 notify_offset_multiplier;
+
+	/* Legacy only field */
 	/* the IO mapping for the PCI config space */
 	void __iomem *ioaddr;
 
-	/* the IO mapping for ISR operation */
-	void __iomem *isr;
-
 	/* a list of queues so we can dispatch IRQs */
 	spinlock_t lock;
 	struct list_head virtqueues;
@@ -129,5 +146,7 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu);
 
 int virtio_pci_legacy_probe(struct virtio_pci_device *);
 void virtio_pci_legacy_remove(struct virtio_pci_device *);
+int virtio_pci_modern_probe(struct virtio_pci_device *);
+void virtio_pci_modern_remove(struct virtio_pci_device *);
 
 #endif
drivers/virtio/virtio_pci_common.c +12 -2
index 457cbe2..20c7638 100644
@@ -505,6 +505,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	if (rc)
 		goto err_request_regions;
 
+	rc = virtio_pci_modern_probe(vp_dev);
+	if (rc != -ENODEV)
+		return rc;
+
 	rc = virtio_pci_legacy_probe(vp_dev);
 	if (rc)
 		goto err_probe;
@@ -518,7 +522,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err_register:
-	virtio_pci_legacy_remove(vp_dev);
+	if (vp_dev->ioaddr)
+	     virtio_pci_legacy_remove(vp_dev);
+	else
+	     virtio_pci_modern_remove(vp_dev);
 err_probe:
 	pci_release_regions(pci_dev);
 err_request_regions:
@@ -534,7 +541,10 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 
 	unregister_virtio_device(&vp_dev->vdev);
 
-	virtio_pci_legacy_remove(pci_dev);
+	if (vp_dev->ioaddr)
+		virtio_pci_legacy_remove(vp_dev);
+	else
+		virtio_pci_modern_remove(vp_dev);
 
 	pci_release_regions(pci_dev);
 	pci_disable_device(pci_dev);
drivers/virtio/virtio_pci_modern.c new file +592 -0

592 lines not on this page · raw message

drivers/virtio/Makefile +1 -1
index bf5104b..bd230d1 100644
@@ -1,5 +1,5 @@
 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
-virtio_pci-y := virtio_pci_legacy.o virtio_pci_common.o
+virtio_pci-y := virtio_pci_modern.o virtio_pci_legacy.o virtio_pci_common.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
Signature · 1 line
MST
author maintainer
#29 lore raw

PATCH v3 14/16 virtio_pci: macros for PCI layout offsets

In reply to Michael S. Tsirkin

From: Rusty Russell <[email protected]>

QEMU wants it, so why not? Trust, but verify.

---
 include/uapi/linux/virtio_pci.h    | 30 ++++++++++++++++++++
 drivers/virtio/virtio_pci_modern.c | 58 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 87 insertions(+), 1 deletion(-)
include/uapi/linux/virtio_pci.h +30 -0
index 4e05423..e841edd 100644
@@ -159,6 +159,36 @@ struct virtio_pci_common_cfg {
 	__le32 queue_used_hi;		/* read-write */
 };
 
+/* Macro versions of offsets for the Old Timers! */
+#define VIRTIO_PCI_CAP_VNDR		0
+#define VIRTIO_PCI_CAP_NEXT		1
+#define VIRTIO_PCI_CAP_LEN		2
+#define VIRTIO_PCI_CAP_TYPE_AND_BAR	3
+#define VIRTIO_PCI_CAP_OFFSET		4
+#define VIRTIO_PCI_CAP_LENGTH		8
+
+#define VIRTIO_PCI_NOTIFY_CAP_MULT	12
+
+#define VIRTIO_PCI_COMMON_DFSELECT	0
+#define VIRTIO_PCI_COMMON_DF		4
+#define VIRTIO_PCI_COMMON_GFSELECT	8
+#define VIRTIO_PCI_COMMON_GF		12
+#define VIRTIO_PCI_COMMON_MSIX		16
+#define VIRTIO_PCI_COMMON_NUMQ		18
+#define VIRTIO_PCI_COMMON_STATUS	20
+#define VIRTIO_PCI_COMMON_CFGGENERATION	21
+#define VIRTIO_PCI_COMMON_Q_SELECT	22
+#define VIRTIO_PCI_COMMON_Q_SIZE	24
+#define VIRTIO_PCI_COMMON_Q_MSIX	26
+#define VIRTIO_PCI_COMMON_Q_ENABLE	28
+#define VIRTIO_PCI_COMMON_Q_NOFF	30
+#define VIRTIO_PCI_COMMON_Q_DESCLO	32
+#define VIRTIO_PCI_COMMON_Q_DESCHI	36
+#define VIRTIO_PCI_COMMON_Q_AVAILLO	40
+#define VIRTIO_PCI_COMMON_Q_AVAILHI	44
+#define VIRTIO_PCI_COMMON_Q_USEDLO	48
+#define VIRTIO_PCI_COMMON_Q_USEDHI	52
+
 #endif /* VIRTIO_PCI_NO_MODERN */
 
 #endif
drivers/virtio/virtio_pci_modern.c +57 -1

66 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#30 lore raw

PATCH v3 14/16 virtio_pci: macros for PCI layout offsets

In reply to Michael S. Tsirkin

From: Rusty Russell <[email protected]>

QEMU wants it, so why not? Trust, but verify.

---
 include/uapi/linux/virtio_pci.h    | 30 ++++++++++++++++++++
 drivers/virtio/virtio_pci_modern.c | 58 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 87 insertions(+), 1 deletion(-)
include/uapi/linux/virtio_pci.h +30 -0
index 4e05423..e841edd 100644
@@ -159,6 +159,36 @@ struct virtio_pci_common_cfg {
 	__le32 queue_used_hi;		/* read-write */
 };
 
+/* Macro versions of offsets for the Old Timers! */
+#define VIRTIO_PCI_CAP_VNDR		0
+#define VIRTIO_PCI_CAP_NEXT		1
+#define VIRTIO_PCI_CAP_LEN		2
+#define VIRTIO_PCI_CAP_TYPE_AND_BAR	3
+#define VIRTIO_PCI_CAP_OFFSET		4
+#define VIRTIO_PCI_CAP_LENGTH		8
+
+#define VIRTIO_PCI_NOTIFY_CAP_MULT	12
+
+#define VIRTIO_PCI_COMMON_DFSELECT	0
+#define VIRTIO_PCI_COMMON_DF		4
+#define VIRTIO_PCI_COMMON_GFSELECT	8
+#define VIRTIO_PCI_COMMON_GF		12
+#define VIRTIO_PCI_COMMON_MSIX		16
+#define VIRTIO_PCI_COMMON_NUMQ		18
+#define VIRTIO_PCI_COMMON_STATUS	20
+#define VIRTIO_PCI_COMMON_CFGGENERATION	21
+#define VIRTIO_PCI_COMMON_Q_SELECT	22
+#define VIRTIO_PCI_COMMON_Q_SIZE	24
+#define VIRTIO_PCI_COMMON_Q_MSIX	26
+#define VIRTIO_PCI_COMMON_Q_ENABLE	28
+#define VIRTIO_PCI_COMMON_Q_NOFF	30
+#define VIRTIO_PCI_COMMON_Q_DESCLO	32
+#define VIRTIO_PCI_COMMON_Q_DESCHI	36
+#define VIRTIO_PCI_COMMON_Q_AVAILLO	40
+#define VIRTIO_PCI_COMMON_Q_AVAILHI	44
+#define VIRTIO_PCI_COMMON_Q_USEDLO	48
+#define VIRTIO_PCI_COMMON_Q_USEDHI	52
+
 #endif /* VIRTIO_PCI_NO_MODERN */
 
 #endif
drivers/virtio/virtio_pci_modern.c +57 -1

66 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#31 lore raw

PATCH v3 15/16 virtio_pci_modern: reduce number of mappings

In reply to Michael S. Tsirkin

We don't know the # of VQs that drivers are going to use so it's hard to predict how much memory we'll need to map. However, the relevant capability does give us an upper limit.
If that's below a page, we can reduce the number of required mappings by mapping it all once ahead of the time.

---
 drivers/virtio/virtio_pci_common.h |  3 ++
 drivers/virtio/virtio_pci_modern.c | 57 ++++++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 8 deletions(-)
drivers/virtio/virtio_pci_common.h +3 -0
index 610c43f..d391805 100644
@@ -62,8 +62,11 @@ struct virtio_pci_device {
 	struct virtio_pci_common_cfg __iomem *common;
 	/* Device-specific data (non-legacy mode)  */
 	void __iomem *device;
+	/* Base of vq notifications (non-legacy mode). */
+	void __iomem *notify_base;
 
 	/* So we can sanity-check accesses. */
+	size_t notify_len;
 	size_t device_len;
 
 	/* Capability for when we need to map notifications per-vq. */
drivers/virtio/virtio_pci_modern.c +49 -8

104 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#32 lore raw

PATCH v3 15/16 virtio_pci_modern: reduce number of mappings

In reply to Michael S. Tsirkin

We don't know the # of VQs that drivers are going to use so it's hard to predict how much memory we'll need to map. However, the relevant capability does give us an upper limit.
If that's below a page, we can reduce the number of required mappings by mapping it all once ahead of the time.

---
 drivers/virtio/virtio_pci_common.h |  3 ++
 drivers/virtio/virtio_pci_modern.c | 57 ++++++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 8 deletions(-)
drivers/virtio/virtio_pci_common.h +3 -0
index 610c43f..d391805 100644
@@ -62,8 +62,11 @@ struct virtio_pci_device {
 	struct virtio_pci_common_cfg __iomem *common;
 	/* Device-specific data (non-legacy mode)  */
 	void __iomem *device;
+	/* Base of vq notifications (non-legacy mode). */
+	void __iomem *notify_base;
 
 	/* So we can sanity-check accesses. */
+	size_t notify_len;
 	size_t device_len;
 
 	/* Capability for when we need to map notifications per-vq. */
drivers/virtio/virtio_pci_modern.c +49 -8

104 lines not on this page · raw message

Signature · 1 line
MST
author maintainer
#33 lore raw

PATCH v3 16/16 virtio_pci_modern: support devices with no config

In reply to Michael S. Tsirkin

Virtio 1.0 spec lists device config as optional. Set get/set callbacks to NULL. Drivers can check that and fail gracefully.

---
 drivers/virtio/virtio_pci_modern.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +19 -2
index 9c000e9a..b877705 100644
@@ -425,6 +425,21 @@ static void del_vq(struct virtio_pci_vq_info *info)
 	free_pages_exact(info->queue, vring_pci_size(info->num));
 }
 
+static const struct virtio_config_ops virtio_pci_config_nodev_ops = {
+	.get		= NULL,
+	.set		= NULL,
+	.generation	= vp_generation,
+	.get_status	= vp_get_status,
+	.set_status	= vp_set_status,
+	.reset		= vp_reset,
+	.find_vqs	= vp_modern_find_vqs,
+	.del_vqs	= vp_del_vqs,
+	.get_features	= vp_get_features,
+	.finalize_features = vp_finalize_features,
+	.bus_name	= vp_bus_name,
+	.set_vq_affinity = vp_set_vq_affinity,
+};
+
 static const struct virtio_config_ops virtio_pci_config_ops = {
 	.get		= vp_get,
 	.set		= vp_set,
@@ -655,9 +670,11 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)
 						&vp_dev->device_len);
 		if (!vp_dev->device)
 			goto err_map_device;
-	}
 
-	vp_dev->vdev.config = &virtio_pci_config_ops;
+		vp_dev->vdev.config = &virtio_pci_config_ops;
+	} else {
+		vp_dev->vdev.config = &virtio_pci_config_nodev_ops;
+	}
 
 	vp_dev->config_vector = vp_config_vector;
 	vp_dev->setup_vq = setup_vq;
Signature · 1 line
MST
author maintainer
#34 lore raw

PATCH v3 16/16 virtio_pci_modern: support devices with no config

In reply to Michael S. Tsirkin

Virtio 1.0 spec lists device config as optional. Set get/set callbacks to NULL. Drivers can check that and fail gracefully.

---
 drivers/virtio/virtio_pci_modern.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +19 -2
index 9c000e9a..b877705 100644
@@ -425,6 +425,21 @@ static void del_vq(struct virtio_pci_vq_info *info)
 	free_pages_exact(info->queue, vring_pci_size(info->num));
 }
 
+static const struct virtio_config_ops virtio_pci_config_nodev_ops = {
+	.get		= NULL,
+	.set		= NULL,
+	.generation	= vp_generation,
+	.get_status	= vp_get_status,
+	.set_status	= vp_set_status,
+	.reset		= vp_reset,
+	.find_vqs	= vp_modern_find_vqs,
+	.del_vqs	= vp_del_vqs,
+	.get_features	= vp_get_features,
+	.finalize_features = vp_finalize_features,
+	.bus_name	= vp_bus_name,
+	.set_vq_affinity = vp_set_vq_affinity,
+};
+
 static const struct virtio_config_ops virtio_pci_config_ops = {
 	.get		= vp_get,
 	.set		= vp_set,
@@ -655,9 +670,11 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)
 						&vp_dev->device_len);
 		if (!vp_dev->device)
 			goto err_map_device;
-	}
 
-	vp_dev->vdev.config = &virtio_pci_config_ops;
+		vp_dev->vdev.config = &virtio_pci_config_ops;
+	} else {
+		vp_dev->vdev.config = &virtio_pci_config_nodev_ops;
+	}
 
 	vp_dev->config_vector = vp_config_vector;
 	vp_dev->setup_vq = setup_vq;
Signature · 1 line
MST
author maintainer
#35 lore raw

PATCH v3 16/16 virtio_pci_modern: support devices with no config

In reply to Michael S. Tsirkin

Virtio 1.0 spec lists device config as optional. Set get/set callbacks to NULL. Drivers can check that and fail gracefully.

---
 drivers/virtio/virtio_pci_modern.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +19 -2
index 9c000e9a..b877705 100644
@@ -425,6 +425,21 @@ static void del_vq(struct virtio_pci_vq_info *info)
 	free_pages_exact(info->queue, vring_pci_size(info->num));
 }
 
+static const struct virtio_config_ops virtio_pci_config_nodev_ops = {
+	.get		= NULL,
+	.set		= NULL,
+	.generation	= vp_generation,
+	.get_status	= vp_get_status,
+	.set_status	= vp_set_status,
+	.reset		= vp_reset,
+	.find_vqs	= vp_modern_find_vqs,
+	.del_vqs	= vp_del_vqs,
+	.get_features	= vp_get_features,
+	.finalize_features = vp_finalize_features,
+	.bus_name	= vp_bus_name,
+	.set_vq_affinity = vp_set_vq_affinity,
+};
+
 static const struct virtio_config_ops virtio_pci_config_ops = {
 	.get		= vp_get,
 	.set		= vp_set,
@@ -655,9 +670,11 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)
 						&vp_dev->device_len);
 		if (!vp_dev->device)
 			goto err_map_device;
-	}
 
-	vp_dev->vdev.config = &virtio_pci_config_ops;
+		vp_dev->vdev.config = &virtio_pci_config_ops;
+	} else {
+		vp_dev->vdev.config = &virtio_pci_config_nodev_ops;
+	}
 
 	vp_dev->config_vector = vp_config_vector;
 	vp_dev->setup_vq = setup_vq;
Signature · 1 line
MST
author maintainer
#36 lore raw

PATCH v3 16/16 virtio_pci_modern: support devices with no config

In reply to Michael S. Tsirkin

Virtio 1.0 spec lists device config as optional. Set get/set callbacks to NULL. Drivers can check that and fail gracefully.

---
 drivers/virtio/virtio_pci_modern.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_modern.c +19 -2
index 9c000e9a..b877705 100644
@@ -425,6 +425,21 @@ static void del_vq(struct virtio_pci_vq_info *info)
 	free_pages_exact(info->queue, vring_pci_size(info->num));
 }
 
+static const struct virtio_config_ops virtio_pci_config_nodev_ops = {
+	.get		= NULL,
+	.set		= NULL,
+	.generation	= vp_generation,
+	.get_status	= vp_get_status,
+	.set_status	= vp_set_status,
+	.reset		= vp_reset,
+	.find_vqs	= vp_modern_find_vqs,
+	.del_vqs	= vp_del_vqs,
+	.get_features	= vp_get_features,
+	.finalize_features = vp_finalize_features,
+	.bus_name	= vp_bus_name,
+	.set_vq_affinity = vp_set_vq_affinity,
+};
+
 static const struct virtio_config_ops virtio_pci_config_ops = {
 	.get		= vp_get,
 	.set		= vp_set,
@@ -655,9 +670,11 @@ int virtio_pci_modern_probe(struct virtio_pci_device *vp_dev)
 						&vp_dev->device_len);
 		if (!vp_dev->device)
 			goto err_map_device;
-	}
 
-	vp_dev->vdev.config = &virtio_pci_config_ops;
+		vp_dev->vdev.config = &virtio_pci_config_ops;
+	} else {
+		vp_dev->vdev.config = &virtio_pci_config_nodev_ops;
+	}
 
 	vp_dev->config_vector = vp_config_vector;
 	vp_dev->setup_vq = setup_vq;
Signature · 1 line
MST
#37 lore raw
In reply to Michael S. Tsirkin

Hi,

Quoted 1 line

QEMU side is still undergoing polishing, but is already testable.

Looked art the qemu side for now, commenting here due to qemu patches not being posted to the list yet (guess that is at least partly already on your todo list):

* Both legacy and modern should be switchable. Modern needs to be switchable _anyway_ for backward compatibility with old qemu versions. But legacy should be too, for testing purposes and for new device types which don't need legacy in the first place.

* I'd like to see some more flexibility in the pci bar layout. Stuff I have in mind:
- New devices which don't need a legacy bar can use bar 0 for modern.
- One MMIO bar is enough, we can place both virtio regions and msi-x regions there. I'd suggest to add msi-x sub-regions to the modern bar.

* What is the reason for making the modern bar 8M in size? Looks a bit excessive, given that only 64k or so of that are actually used ...

virtio-scsi seems to be broken, at least my usual fedora guest didn't boot up from virtio-scsi disk when using a guest kernel with this patch series applied.

cheers,
Gerd

author maintainer
#38 lore raw
Quoted 7 lines · Gerd Hoffmann

Hi,

Quoted 1 line

QEMU side is still undergoing polishing, but is already testable.

Looked art the qemu side for now, commenting here due to qemu patches not being posted to the list yet (guess that is at least partly already on your todo list):

Absolutely.

Quoted 4 lines

* Both legacy and modern should be switchable. Modern needs to be switchable _anyway_ for backward compatibility with old qemu versions. But legacy should be too, for testing purposes and for new device types which don't need legacy in the first place.

I agree.

Quoted 7 lines

* I'd like to see some more flexibility in the pci bar layout. Stuff I have in mind:
- New devices which don't need a legacy bar can use bar 0 for modern.
- One MMIO bar is enough, we can place both virtio regions and msi-x regions there. I'd suggest to add msi-x sub-regions to the modern bar.

Why exactly? It seems simpler to separate things, extra BARs have no cost.

Quoted 2 lines

* What is the reason for making the modern bar 8M in size? Looks a bit excessive, given that only 64k or so of that are actually used ...

I use a page per VQ for architectures that can locate the offset of the accessed page that triggered EPT violation faster than the offset within page. I think this is the case for SVM.

Quoted 7 lines

virtio-scsi seems to be broken, at least my usual fedora guest didn't boot up from virtio-scsi disk when using a guest kernel with this patch series applied.

cheers,
Gerd

I'll re-test. Do other devices work for you? Thanks!

#39 lore raw

Hi,

Quoted 10 lines
Quoted 7 lines

* I'd like to see some more flexibility in the pci bar layout. Stuff I have in mind:
- New devices which don't need a legacy bar can use bar 0 for modern.
- One MMIO bar is enough, we can place both virtio regions and msi-x regions there. I'd suggest to add msi-x sub-regions to the modern bar.

Why exactly? It seems simpler to separate things, extra BARs have no cost.

Well, there are only six BARs. legacy bar, modern mmio bar, msi-x bar, modern io bar (for fast isr). That already four out of six ...

We have a mmio bar, which we partition into subregions for virtio-1.0 anyway. Also placing msi-x there is a single msix_init() call. xhci is doing that too:

    00000000febf0000-00000000febf3fff (prio 1, RW): xhci
      00000000febf0000-00000000febf003f (prio 0, RW): capabilities
      00000000febf0040-00000000febf043f (prio 0, RW): operational
      00000000febf0440-00000000febf044f (prio 0, RW): usb3 port #1
      00000000febf0450-00000000febf045f (prio 0, RW): usb3 port #2
      00000000febf0460-00000000febf046f (prio 0, RW): usb3 port #3
      00000000febf0470-00000000febf047f (prio 0, RW): usb3 port #4
      00000000febf0480-00000000febf048f (prio 0, RW): usb2 port #1
      00000000febf0490-00000000febf049f (prio 0, RW): usb2 port #2
      00000000febf04a0-00000000febf04af (prio 0, RW): usb2 port #3
      00000000febf04b0-00000000febf04bf (prio 0, RW): usb2 port #4
      00000000febf1000-00000000febf121f (prio 0, RW): runtime
      00000000febf2000-00000000febf281f (prio 0, RW): doorbell
      00000000febf3000-00000000febf30ff (prio 0, RW): msix-table
      00000000febf3800-00000000febf3807 (prio 0, RW): msix-pba
Quoted 6 lines
Quoted 2 lines

* What is the reason for making the modern bar 8M in size? Looks a bit excessive, given that only 64k or so of that are actually used ...

I use a page per VQ for architectures that can locate the offset of the accessed page that triggered EPT violation faster than the offset within page. I think this is the case for SVM.

8M still looks excessive, given that we typically have a small number of queues per device. Do you allocate address space for the maximum possible number of queues unconditionally?

Quoted 5 lines
Quoted 3 lines

virtio-scsi seems to be broken, at least my usual fedora guest didn't boot up from virtio-scsi disk when using a guest kernel with this patch series applied.

I'll re-test. Do other devices work for you? Thanks!

Didn't came very far yet in my testing due to the guest not booting. I plan to try other storage for the image, but didn't found the time yet.

I've tried to boot a F21 live iso with virtio-net (legacy guest driver obviously), which seems to work ok in light testing.

BTW: is there a tool (or pciutils patch) which can decode the virtio capabilities?

cheers,
Gerd

author maintainer
#40 lore raw
Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 8 lines
Quoted 7 lines

* I'd like to see some more flexibility in the pci bar layout. Stuff I have in mind:
- New devices which don't need a legacy bar can use bar 0 for modern.
- One MMIO bar is enough, we can place both virtio regions and msi-x regions there. I'd suggest to add msi-x sub-regions to the modern bar.

Quoted 5 lines
Quoted 2 lines

Why exactly? It seems simpler to separate things, extra BARs have no cost.

Well, there are only six BARs. legacy bar, modern mmio bar, msi-x bar, modern io bar (for fast isr). That already four out of six ...

So? If we need to add another bar, we'll change things.

Quoted 4 lines

We have a mmio bar, which we partition into subregions for virtio-1.0 anyway. Also placing msi-x there is a single msix_init() call. xhci is doing that too:

Quoted 16 lines
    00000000febf0000-00000000febf3fff (prio 1, RW): xhci
      00000000febf0000-00000000febf003f (prio 0, RW): capabilities
      00000000febf0040-00000000febf043f (prio 0, RW): operational
      00000000febf0440-00000000febf044f (prio 0, RW): usb3 port #1
      00000000febf0450-00000000febf045f (prio 0, RW): usb3 port #2
      00000000febf0460-00000000febf046f (prio 0, RW): usb3 port #3
      00000000febf0470-00000000febf047f (prio 0, RW): usb3 port #4
      00000000febf0480-00000000febf048f (prio 0, RW): usb2 port #1
      00000000febf0490-00000000febf049f (prio 0, RW): usb2 port #2
      00000000febf04a0-00000000febf04af (prio 0, RW): usb2 port #3
      00000000febf04b0-00000000febf04bf (prio 0, RW): usb2 port #4
      00000000febf1000-00000000febf121f (prio 0, RW): runtime
      00000000febf2000-00000000febf281f (prio 0, RW): doorbell
      00000000febf3000-00000000febf30ff (prio 0, RW): msix-table
      00000000febf3800-00000000febf3807 (prio 0, RW): msix-pba

However that one is non prefetheable, and I prefer putting virtio caps in a prefetcheable bar.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

* What is the reason for making the modern bar 8M in size? Looks a bit excessive, given that only 64k or so of that are actually used ...

I use a page per VQ for architectures that can locate the offset of the accessed page that triggered EPT violation faster than the offset within page. I think this is the case for SVM.

8M still looks excessive, given that we typically have a small number of queues per device. Do you allocate address space for the maximum possible number of queues unconditionally?

Yes, simpler this way. I'll check if I can find the real # of VQs.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

virtio-scsi seems to be broken, at least my usual fedora guest didn't boot up from virtio-scsi disk when using a guest kernel with this patch series applied.

I'll re-test. Do other devices work for you? Thanks!

Didn't came very far yet in my testing due to the guest not booting.

Try virtio-blk - that worked for me.

Quoted 12 lines

I
plan to try other storage for the image, but didn't found the time yet.

I've tried to boot a F21 live iso with virtio-net (legacy guest driver obviously), which seems to work ok in light testing.

BTW: is there a tool (or pciutils patch) which can decode the virtio capabilities?

cheers,
Gerd

#41 lore raw

Hi,

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

virtio-scsi seems to be broken, at least my usual fedora guest didn't boot up from virtio-scsi disk when using a guest kernel with this patch series applied.

I'll re-test. Do other devices work for you? Thanks!

Didn't came very far yet in my testing due to the guest not booting.

Try virtio-blk - that worked for me.

Nope. Booted from ide now, looked in /sys/bus/virtio/devices:

lrwxrwxrwx. 1 root root 0 Jan 16 14:15 virtio0 -> ../../../devices/pci0000:00/0000:00:0b.0/virtio0

lspci:

00:09.0 Ethernet controller: Red Hat, Inc Virtio network device 00:0a.0 Communication controller: Red Hat, Inc Virtio console 00:0b.0 Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon

net + serial are missing ...

I'm running 3.19-rc4 with this series applied in the guest, maybe I need more?

On the qemu side it is your virtio-1.0 branch from yesterday, rebased to master.

cheers,
Gerd

#42 lore raw

Hi,

Quoted 2 lines

I'm running 3.19-rc4 with this series applied in the guest, maybe I need more?

Tried your vhost branch, rebased to 3.19-rc5 -- same result. Hmm.

cheers,
Gerd

author maintainer
#43 lore raw
Quoted 10 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

I'm running 3.19-rc4 with this series applied in the guest, maybe I need more?

Tried your vhost branch, rebased to 3.19-rc5 -- same result. Hmm.

cheers,
Gerd

Yes, it was all completely broken.
Looks like after making what looked like cosmetic changes, I run legacy driver on new qemu and new driver on legacy qemu, but never new driver on new qemu.

And sure enough, the "cosmetic" change inverted the logic testing probe routine for success.

Sorry about that :(

I now posted fixed up patches: seem to work with net and block for me.

The easiest way to get the is probably from my git trees.

Thanks a lot for the reports!

Signature · 1 line
MST
#44 lore raw
In reply to Gerd Hoffmann

Hi,

Quoted 2 lines

BTW: is there a tool (or pciutils patch) which can decode the virtio capabilities?

Searched for a patch today, and all google found me was this mail asking for one :-o

So I went ahead and coded one up. Attached.

While hacking it up I've noticed spec doesn't match reality. The "Virtio Structure PCI Capabilities" section here ...

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

... doesn't match what qemu is doing. Huh?

Also note:

[root@fedora ~]# ~kraxel/projects/pciutils/lspci -vvsa 00:0a.0 Communication controller: Red Hat, Inc Virtio console [ ... ]

	Capabilities: [64] VirtIO: Notify
		BAR=2 offset=00003000 size=00400000
		multiplier=00010000

[ ... ]

Why multiplier is 64k instead of 4k? Just a tyops?

cheers,
Gerd

From 0d5d99c20b079c986128c3d98c4bbaba51ebe65c Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Mon, 19 Jan 2015 11:46:37 +0100
Subject: [PATCH] add virtio vendor caps

---
 Makefile         |  2 +-
 ls-caps-vendor.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ls-caps.c        |  9 ++++++++-
 lspci.h          |  4 ++++
 4 files changed, 70 insertions(+), 2 deletions(-)
 create mode 100644 ls-caps-vendor.c
Makefile +1 -1
index 8d49afa..39a07d1 100644
@@ -69,7 +69,7 @@ force:
 lib/config.h lib/config.mk:
 	cd lib && ./configure
 
-lspci: lspci.o ls-vpd.o ls-caps.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o common.o lib/$(PCILIB)
+lspci: lspci.o ls-vpd.o ls-caps.o ls-caps-vendor.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o common.o lib/$(PCILIB)
 setpci: setpci.o common.o lib/$(PCILIB)
 
 LSPCIINC=lspci.h pciutils.h $(PCIINC)
ls-caps-vendor.c new file +57 -0

57 lines not on this page · raw message

ls-caps.c +8 -1
index 7de55ef..438b580 100644
@@ -1315,7 +1315,14 @@ show_caps(struct device *d, int where)
 	      cap_ht(d, where, cap);
 	      break;
 	    case PCI_CAP_ID_VNDR:
-	      printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+              switch (get_conf_word(d, PCI_VENDOR_ID)) {
+              case 0x1af4: /* Red Hat, devices 0x1000 -> 0x107f are virtio */
+                show_vendor_caps_virtio(d, where, cap);
+                break;
+              default:
+                printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+                break;
+              }
 	      break;
 	    case PCI_CAP_ID_DBG:
 	      cap_debug_port(cap);
lspci.h +4 -0
index 86429b2..5ca9899 100644
@@ -70,6 +70,10 @@ void show_caps(struct device *d, int where);
 
 void show_ext_caps(struct device *d);
 
+/* ls-caps-vendor.c */
+
+void show_vendor_caps_virtio(struct device *d, int where, int cap);
+
 /* ls-kernel.c */
 
 void show_kernel_machine(struct device *d UNUSED);
Signature · 1 line
1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author maintainer
#45 lore raw
Quoted 8 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

BTW: is there a tool (or pciutils patch) which can decode the virtio capabilities?

Searched for a patch today, and all google found me was this mail asking for one :-o

Quoted 8 lines

So I went ahead and coded one up. Attached.

While hacking it up I've noticed spec doesn't match reality. The "Virtio Structure PCI Capabilities" section here ...

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

... doesn't match what qemu is doing. Huh?

Wow! And I made the same bug in the guest too.
Good catch, will fix both up.

Quoted 9 lines

Also note:

[root@fedora ~]# ~kraxel/projects/pciutils/lspci -vvsa 00:0a.0 Communication controller: Red Hat, Inc Virtio console [ ... ]

	Capabilities: [64] VirtIO: Notify
		BAR=2 offset=00003000 size=00400000
		multiplier=00010000
Quoted 8 lines

[ ... ]

Why multiplier is 64k instead of 4k? Just a tyops?

cheers,
Gerd

Just in case :) I'll make it smaller, will address your concerns about BAR size in a simple way.

Quoted 127 lines
Quoted 1 line

From 0d5d99c20b079c986128c3d98c4bbaba51ebe65c Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Mon, 19 Jan 2015 11:46:37 +0100
Subject: [PATCH] add virtio vendor caps

---
 Makefile         |  2 +-
 ls-caps-vendor.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ls-caps.c        |  9 ++++++++-
 lspci.h          |  4 ++++
 4 files changed, 70 insertions(+), 2 deletions(-)
 create mode 100644 ls-caps-vendor.c
Makefile +1 -1
index 8d49afa..39a07d1 100644
@@ -69,7 +69,7 @@ force:
 lib/config.h lib/config.mk:
 	cd lib && ./configure
 
-lspci: lspci.o ls-vpd.o ls-caps.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o common.o lib/$(PCILIB)
+lspci: lspci.o ls-vpd.o ls-caps.o ls-caps-vendor.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o common.o lib/$(PCILIB)
 setpci: setpci.o common.o lib/$(PCILIB)
 
 LSPCIINC=lspci.h pciutils.h $(PCIINC)
ls-caps-vendor.c new file +57 -0
new file mode 100644
index 0000000..5f8b3e1
@@ -0,0 +1,57 @@
+/*
+ *	The PCI Utilities -- Show Vendor-specific Capabilities
+ *
+ *	Copyright (c) 2014 Gerd Hoffmann <[email protected]>
+ *
+ *	Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "lspci.h"
+
+void
+show_vendor_caps_virtio(struct device *d, int where, int cap)
+{
+  int length = BITS(cap, 0, 8);
+  int type = BITS(cap, 8, 5);
+  int bar = BITS(cap, 13, 3);
+  char *tname;
+
+  if (length < 12)
+    return;
+  if (!config_fetch(d, where, length))
+    return;
+
+  switch (type) {
+  case 1:
+      tname = "CommonCfg";
+      break;
+  case 2:
+      tname = "Notify";
+      break;
+  case 3:
+      tname = "ISR";
+      break;
+  case 4:
+      tname = "DeviceCfg";
+      break;
+  default:
+      tname = "<unknown>";
+      break;
+  }
+
+  printf("VirtIO: %s\n", tname);
+
+  if (verbose < 2)
+    return;
+
+  printf("\t\tBAR=%d offset=%08x size=%08x\n", bar,
+         get_conf_long(d, where+4),
+         get_conf_long(d, where+8));
+  if (type != 2 || length < 16)
+    return;
+  printf("\t\tmultiplier=%08x\n",
+         get_conf_long(d, where+12));
+}
ls-caps.c +8 -1
index 7de55ef..438b580 100644
@@ -1315,7 +1315,14 @@ show_caps(struct device *d, int where)
 	      cap_ht(d, where, cap);
 	      break;
 	    case PCI_CAP_ID_VNDR:
-	      printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+              switch (get_conf_word(d, PCI_VENDOR_ID)) {
+              case 0x1af4: /* Red Hat, devices 0x1000 -> 0x107f are virtio */
+                show_vendor_caps_virtio(d, where, cap);
+                break;
+              default:
+                printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+                break;
+              }
 	      break;
 	    case PCI_CAP_ID_DBG:
 	      cap_debug_port(cap);
lspci.h +4 -0
index 86429b2..5ca9899 100644
@@ -70,6 +70,10 @@ void show_caps(struct device *d, int where);
 
 void show_ext_caps(struct device *d);
 
+/* ls-caps-vendor.c */
+
+void show_vendor_caps_virtio(struct device *d, int where, int cap);
+
 /* ls-kernel.c */
 
 void show_kernel_machine(struct device *d UNUSED);
Signature · 1 line
1.8.3.1
author maintainer
#46 lore raw
In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

BTW: is there a tool (or pciutils patch) which can decode the virtio capabilities?

Searched for a patch today, and all google found me was this mail asking for one :-o

Quoted 8 lines

So I went ahead and coded one up. Attached.

While hacking it up I've noticed spec doesn't match reality. The "Virtio Structure PCI Capabilities" section here ...

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

... doesn't match what qemu is doing. Huh?

Thanks a lot for the report, and the tool!
I sent patches to fix this all up.
You can try my qemu and linux virtio-net branches now, they should be spec compliant.

Signature · 1 line
MST
#47 lore raw

Hi,

Quoted 8 lines
Quoted 6 lines

While hacking it up I've noticed spec doesn't match reality. The "Virtio Structure PCI Capabilities" section here ...

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

... doesn't match what qemu is doing. Huh?

Thanks a lot for the report, and the tool!

pciutils patch needs an update too (because I've made it decode the broken qemu capabilities). Will come as separate mail with proper commit message in a moment.

Quoted 3 lines

I sent patches to fix this all up.
You can try my qemu and linux virtio-net branches now, they should be spec compliant.

Yep, much better. caps match spec, the system boots fine from virtio-scsi, and the nfs-mounts (using virtio-net) are there too.

cheers,
Gerd

#48 lore raw
In reply to Michael S. Tsirkin

Hi,

Quoted 8 lines
Quoted 6 lines

While hacking it up I've noticed spec doesn't match reality. The "Virtio Structure PCI Capabilities" section here ...

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

... doesn't match what qemu is doing. Huh?

Thanks a lot for the report, and the tool!

pciutils patch needs an update too (because I've made it decode the broken qemu capabilities). Will come as separate mail with proper commit message in a moment.

Quoted 3 lines

I sent patches to fix this all up.
You can try my qemu and linux virtio-net branches now, they should be spec compliant.

Yep, much better. caps match spec, the system boots fine from virtio-scsi, and the nfs-mounts (using virtio-net) are there too.

cheers,
Gerd

author maintainer
#49 lore raw
Quoted 19 lines · Gerd Hoffmann

Hi,

Quoted 8 lines
Quoted 6 lines

While hacking it up I've noticed spec doesn't match reality. The "Virtio Structure PCI Capabilities" section here ...

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

... doesn't match what qemu is doing. Huh?

Thanks a lot for the report, and the tool!

pciutils patch needs an update too (because I've made it decode the broken qemu capabilities). Will come as separate mail with proper commit message in a moment.

Quoted 3 lines

I sent patches to fix this all up.
You can try my qemu and linux virtio-net branches now, they should be spec compliant.

Quoted 5 lines

Yep, much better. caps match spec, the system boots fine from virtio-scsi, and the nfs-mounts (using virtio-net) are there too.

cheers,
Gerd

Thanks!
Want to respond to the patches with a tested-by tag?

#50 lore raw
Quoted 1 line · Michael S. Tsirkin

Want to respond to the patches with a tested-by tag?

Done.

Making multiplier smaller isn't in there yet, right?

cheers,
Gerd

author maintainer
#51 lore raw
Quoted 9 lines · Gerd Hoffmann
Quoted 1 line · Michael S. Tsirkin

Want to respond to the patches with a tested-by tag?

Done.

Making multiplier smaller isn't in there yet, right?

cheers,
Gerd

No - but I'll make sure to address this before I
post a new version.

Signature · 1 line
MST