Skip to contentSkip to conversation

virtio_pci modern driver fixups

PATCH In review Michael S. Tsirkin 3 participants 9 messages Jan 20, 2015 – Jan 21, 2015

Subsystems (2)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover virtio_pci modern driver fixups

These are fixup patches for virtio pci modern. I think it's best to simply squash them in the appropriate original patches - rebase -i and then apply, then rebase -i --autosquash to do this automatically.

You can also find how your branch looks with patches applied
but before the rebase -i --autosquash in my tree:
git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git virtio-next
or after rebase -i --autosquash:
git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git vhost-next

Last patch is a cleanup, does not have to be squashed.

Or if it's all too much bother, I can repost the whole series after fixups.

Michael S. Tsirkin (15):
fixup! virtio_pci: modern driver
fixup! virtio_pci: modern driver
fixup! virtio_pci: macros for PCI layout offsets fixup! virtio_pci: add module param to force legacy mode
virtio_pci_modern: drop an unused function

Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH 1/5 fixup! virtio_pci: modern driver

virtio_pci_modern: fix up vendor capability

Gerd Hoffmann noticed that we implemented capability layout from an old draft. Unfortunately the code was copied to host as well, so we didn't notice.

Luckily we caught this in time.

This fixes commit "virtio_pci: modern driver" and should be smashed with it.

---
 include/uapi/linux/virtio_pci.h    |  7 ++++---
 drivers/virtio/virtio_pci_modern.c | 23 +++++++++--------------
 2 files changed, 13 insertions(+), 17 deletions(-)
include/uapi/linux/virtio_pci.h +4 -3
index 4e05423..a2b2e13 100644
@@ -117,10 +117,11 @@ 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. */
+	__u8 cfg_type;		/* Identifies the structure. */
+	__u8 bar;		/* Where to find it. */
+	__u8 padding[3];	/* Pad to full dword. */
 	__le32 offset;		/* Offset within bar. */
-	__le32 length;		/* Length. */
+	__le32 length;		/* Length of the structure, in bytes. */
 };
 
 #define VIRTIO_PCI_CAP_BAR_SHIFT	5
drivers/virtio/virtio_pci_modern.c +9 -14
index e2f41c9..a3d8101 100644
@@ -26,13 +26,13 @@ static void __iomem *map_capability(struct pci_dev *dev, int off,
 				    u32 start, u32 size,
 				    size_t *len)
 {
-	u8 type_and_bar, bar;
+	u8 bar;
 	u32 offset, length;
 	void __iomem *p;
 
 	pci_read_config_byte(dev, off + offsetof(struct virtio_pci_cap,
-						 type_and_bar),
-			     &type_and_bar);
+						 bar),
+			     &bar);
 	pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, offset),
 			     &offset);
 	pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, length),
@@ -76,9 +76,6 @@ static void __iomem *map_capability(struct pci_dev *dev, int off,
 	if (len)
 		*len = length;
 
-	bar = (type_and_bar >> VIRTIO_PCI_CAP_BAR_SHIFT) &
-		VIRTIO_PCI_CAP_BAR_MASK;
-
 	if (minlen + offset < minlen ||
 	    minlen + offset > pci_resource_len(dev, bar)) {
 		dev_err(&dev->dev,
@@ -438,15 +435,13 @@ static inline int virtio_pci_find_capability(struct pci_dev *dev, u8 cfg_type,
 	for (pos = pci_find_capability(dev, PCI_CAP_ID_VNDR);
 	     pos > 0;
 	     pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_VNDR)) {
-		u8 type_and_bar, type, bar;
+		u8 type, bar;
 		pci_read_config_byte(dev, pos + offsetof(struct virtio_pci_cap,
-							 type_and_bar),
-				     &type_and_bar);
-
-		type = (type_and_bar >> VIRTIO_PCI_CAP_TYPE_SHIFT) &
-			VIRTIO_PCI_CAP_TYPE_MASK;
-		bar = (type_and_bar >> VIRTIO_PCI_CAP_BAR_SHIFT) &
-			VIRTIO_PCI_CAP_BAR_MASK;
+							 cfg_type),
+				     &type);
+		pci_read_config_byte(dev, pos + offsetof(struct virtio_pci_cap,
+							 bar),
+				     &bar);
 
 		/* Ignore structures with reserved BAR values */
 		if (bar > 0x5)
Signature · 1 line
MST
author maintainer
#2 lore raw

PATCH 2/5 fixup! virtio_pci: modern driver

In reply to Michael S. Tsirkin

virtio modern: fix up fallback logic

This bails out if modern driver succeeds - not what we wanted.

---
 drivers/virtio/virtio_pci_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/virtio/virtio_pci_common.c +2 -4
index 20c7638..8ae34a3 100644
@@ -506,10 +506,8 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 		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 == -ENODEV)
+		rc = virtio_pci_legacy_probe(vp_dev);
 	if (rc)
 		goto err_probe;
 
Signature · 1 line
MST
author maintainer
#3 lore raw

PATCH 3/5 fixup! virtio_pci: macros for PCI layout offsets

In reply to Michael S. Tsirkin

virtio_pci_modern: fix up vendor capability macros

Gerd Hoffmann noticed that we implemented capability layout from an old draft. Unfortunately the code was copied to host as well, so we didn't notice.

Luckily we caught this in time.

This fixes commit "virtio_pci: macros for PCI layout offsets" and should be smashed with it.

---
 include/uapi/linux/virtio_pci.h    | 14 +++++---------
 drivers/virtio/virtio_pci_modern.c |  6 ++++--
 2 files changed, 9 insertions(+), 11 deletions(-)
include/uapi/linux/virtio_pci.h +5 -9
index 0911c62..3b7e4d2 100644
@@ -124,11 +124,6 @@ struct virtio_pci_cap {
 	__le32 length;		/* Length of the structure, in bytes. */
 };
 
-#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. */
@@ -164,11 +159,12 @@ struct virtio_pci_common_cfg {
 #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_CAP_CFG_TYPE		3
+#define VIRTIO_PCI_CAP_BAR		4
+#define VIRTIO_PCI_CAP_OFFSET		8
+#define VIRTIO_PCI_CAP_LENGTH		12
 
-#define VIRTIO_PCI_NOTIFY_CAP_MULT	12
+#define VIRTIO_PCI_NOTIFY_CAP_MULT	16
 
 #define VIRTIO_PCI_COMMON_DFSELECT	0
 #define VIRTIO_PCI_COMMON_DF		4
drivers/virtio/virtio_pci_modern.c +4 -2
index c86594e..b2e707ad 100644
@@ -474,8 +474,10 @@ static inline void check_offsets(void)
 		     offsetof(struct virtio_pci_cap, cap_next));
 	BUILD_BUG_ON(VIRTIO_PCI_CAP_LEN !=
 		     offsetof(struct virtio_pci_cap, cap_len));
-	BUILD_BUG_ON(VIRTIO_PCI_CAP_TYPE_AND_BAR !=
-		     offsetof(struct virtio_pci_cap, type_and_bar));
+	BUILD_BUG_ON(VIRTIO_PCI_CAP_CFG_TYPE !=
+		     offsetof(struct virtio_pci_cap, cfg_type));
+	BUILD_BUG_ON(VIRTIO_PCI_CAP_BAR !=
+		     offsetof(struct virtio_pci_cap, bar));
 	BUILD_BUG_ON(VIRTIO_PCI_CAP_OFFSET !=
 		     offsetof(struct virtio_pci_cap, offset));
 	BUILD_BUG_ON(VIRTIO_PCI_CAP_LENGTH !=
Signature · 1 line
MST
author maintainer
#4 lore raw

PATCH 4/5 fixup! virtio_pci: add module param to force legacy mode

In reply to Michael S. Tsirkin

virtio modern: fix up fallback logic with force_legacy

This bails out if legacy driver succeeds - not what we wanted.

---
 drivers/virtio/virtio_pci_common.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/virtio/virtio_pci_common.c +4 -8
index 0f87b99..e894eb2 100644
@@ -516,18 +516,14 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	if (force_legacy) {
 		rc = virtio_pci_legacy_probe(vp_dev);
 		/* Also try modern mode if we can't map BAR0 (no IO space). */
-		if (rc != -ENODEV && rc != -ENOMEM)
-			return rc;
-
-		rc = virtio_pci_modern_probe(vp_dev);
+		if (rc == -ENODEV || rc == -ENOMEM)
+			rc = virtio_pci_modern_probe(vp_dev);
 		if (rc)
 			goto err_probe;
 	} else {
 		rc = virtio_pci_modern_probe(vp_dev);
-		if (rc != -ENODEV)
-			return rc;
-
-		rc = virtio_pci_legacy_probe(vp_dev);
+		if (rc == -ENODEV)
+			rc = virtio_pci_legacy_probe(vp_dev);
 		if (rc)
 			goto err_probe;
 	}
Signature · 1 line
MST
author maintainer
#5 lore raw

PATCH 5/5 virtio_pci_modern: drop an unused function

In reply to Michael S. Tsirkin

release function in modern driver is unused:
it's a left-over from when each driver had
to have its own release.

---
 drivers/virtio/virtio_pci_modern.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/virtio/virtio_pci_modern.c +0 -8
index 68ebc20..f16e462 100644
@@ -489,14 +489,6 @@ static inline int virtio_pci_find_capability(struct pci_dev *dev, u8 cfg_type,
 	return 0;
 }
 
-static void virtio_pci_release_dev(struct device *_d)
-{
-	struct virtio_device *vdev = dev_to_virtio(_d);
-	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-
-	kfree(vp_dev);
-}
-
 /* This is part of the ABI.  Don't screw with it. */
 static inline void check_offsets(void)
 {
Signature · 1 line
MST
author maintainer
#6 lore raw

PATCH 5/5 virtio_pci_modern: drop an unused function

In reply to Michael S. Tsirkin

release function in modern driver is unused:
it's a left-over from when each driver had
to have its own release.

---
 drivers/virtio/virtio_pci_modern.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/virtio/virtio_pci_modern.c +0 -8
index 68ebc20..f16e462 100644
@@ -489,14 +489,6 @@ static inline int virtio_pci_find_capability(struct pci_dev *dev, u8 cfg_type,
 	return 0;
 }
 
-static void virtio_pci_release_dev(struct device *_d)
-{
-	struct virtio_device *vdev = dev_to_virtio(_d);
-	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-
-	kfree(vp_dev);
-}
-
 /* This is part of the ABI.  Don't screw with it. */
 static inline void check_offsets(void)
 {
Signature · 1 line
MST
#8 lore raw
In reply to Michael S. Tsirkin
Quoted 4 lines · Michael S. Tsirkin

These are fixup patches for virtio pci modern. I think it's best to simply squash them in the appropriate original patches - rebase -i and then apply, then rebase -i --autosquash to do this automatically.

I do not like rebasing virtio-next. However, as I've already done it once today, I've rebased again.

These kind of issues have made it more urgent that I get virtio-1.0-pci working with lguest, to see if we are at least bug-compatible.

Thanks,
Rusty.