virtio_pci: patches never to apply.
cover virtio_pci: patches never to apply.
This should allow testing when QEMU gets VIRTIO_PCI_CAP_PCI_CFG support, but I'm pretty sure we should never allow these patches upstream.
Tested with lguest (in virtio-next), which supports VIRTIO_PCI_CAP_PCI_CFG.
Rusty Russell (2):
virtio_pci: abstract all MMIO accesses.
virtio: Introducing virtio_pci.no_mmio, the worst boot option in
history.
drivers/virtio/virtio_pci_common.c | 70 +++++++- drivers/virtio/virtio_pci_common.h | 62 ++++++++ drivers/virtio/virtio_pci_legacy.c | 1 + drivers/virtio/virtio_pci_modern.c | 317 ++++++++++++++++++++++++++++++------- 4 files changed, 391 insertions(+), 59 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 virtio_pci: abstract all MMIO accesses.
This is in preparation for testing the virtio pci config mmio backdoor.
--- drivers/virtio/virtio_pci_common.c | 47 ++++++++++++- drivers/virtio/virtio_pci_common.h | 41 +++++++++++ drivers/virtio/virtio_pci_modern.c | 140 ++++++++++++++++++++++++------------- 3 files changed, 177 insertions(+), 51 deletions(-)
drivers/virtio/virtio_pci_common.c +45 -2
@@ -27,6 +27,49 @@ MODULE_PARM_DESC(force_legacy, "Force legacy mode for transitional virtio 1 devices");#endif +u8 vp_read_isr (const struct virtio_pci_device *dev) +{ +return ioread8 (dev->isr); +} + +void vp_write_notify (const struct virtqueue *vq,u16 vqindex) +{ +iowrite16 (vqindex, (void __iomem *)vq->priv); +} + +u32 __vp_read_common32 (const struct virtio_pci_device *dev,size_t offset) +{ +return ioread32 ((void __iomem *)dev->common + offset); +} + +u16 __vp_read_common16 (const struct virtio_pci_device *dev,size_t offset) +{ +return ioread16 ((void __iomem *)dev->common + offset); +} + +u8 __vp_read_common8 (const struct virtio_pci_device *dev,size_t offset) +{ +return ioread8 ((void __iomem *)dev->common + offset); +} + +void __vp_write_common32 (const struct virtio_pci_device *dev, +size_t offset,u32 val) +{ +iowrite32 (val, (void __iomem *)dev->common + offset); +} + +void __vp_write_common16 (const struct virtio_pci_device *dev, +size_t offset,u16 val) +{ +iowrite16 (val, (void __iomem *)dev->common + offset); +} + +void __vp_write_common8 (const struct virtio_pci_device *dev, +size_t offset,u8 val) +{ +iowrite8 (val, (void __iomem *)dev->common + offset); +} +/* wait for pending irq handlers */ void vp_synchronize_vectors (struct virtio_device *vdev) {
@@ -45,7 +88,7 @@ bool vp_notify(struct virtqueue *vq) {/* we write the queue's selector into the notification register to * signal the other end */ -iowrite16 (vq->index, (void __iomem *)vq->priv); +vp_write_notify (vq, vq->index);return true; }
@@ -89,7 +132,7 @@ static irqreturn_t vp_interrupt(int irq, void *opaque)/* reading the ISR has the effect of also clearing it so it's very * important to save off the value. */ - isr =ioread8 (vp_dev->isr); + isr =vp_read_isr (vp_dev);/* It's definitely not us if the ISR was not high */ if (!isr)
drivers/virtio/virtio_pci_common.h +41 -0
47 lines not on this page · raw message
drivers/virtio/virtio_pci_modern.c +91 -49
278 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 1/2 virtio_pci: abstract all MMIO accesses.
In reply to Rusty RussellThis is in preparation for testing the virtio pci config mmio backdoor.
--- drivers/virtio/virtio_pci_common.c | 47 ++++++++++++- drivers/virtio/virtio_pci_common.h | 41 +++++++++++ drivers/virtio/virtio_pci_modern.c | 140 ++++++++++++++++++++++++------------- 3 files changed, 177 insertions(+), 51 deletions(-)
drivers/virtio/virtio_pci_common.c +45 -2
@@ -27,6 +27,49 @@ MODULE_PARM_DESC(force_legacy, "Force legacy mode for transitional virtio 1 devices");#endif +u8 vp_read_isr (const struct virtio_pci_device *dev) +{ +return ioread8 (dev->isr); +} + +void vp_write_notify (const struct virtqueue *vq,u16 vqindex) +{ +iowrite16 (vqindex, (void __iomem *)vq->priv); +} + +u32 __vp_read_common32 (const struct virtio_pci_device *dev,size_t offset) +{ +return ioread32 ((void __iomem *)dev->common + offset); +} + +u16 __vp_read_common16 (const struct virtio_pci_device *dev,size_t offset) +{ +return ioread16 ((void __iomem *)dev->common + offset); +} + +u8 __vp_read_common8 (const struct virtio_pci_device *dev,size_t offset) +{ +return ioread8 ((void __iomem *)dev->common + offset); +} + +void __vp_write_common32 (const struct virtio_pci_device *dev, +size_t offset,u32 val) +{ +iowrite32 (val, (void __iomem *)dev->common + offset); +} + +void __vp_write_common16 (const struct virtio_pci_device *dev, +size_t offset,u16 val) +{ +iowrite16 (val, (void __iomem *)dev->common + offset); +} + +void __vp_write_common8 (const struct virtio_pci_device *dev, +size_t offset,u8 val) +{ +iowrite8 (val, (void __iomem *)dev->common + offset); +} +/* wait for pending irq handlers */ void vp_synchronize_vectors (struct virtio_device *vdev) {
@@ -45,7 +88,7 @@ bool vp_notify(struct virtqueue *vq) {/* we write the queue's selector into the notification register to * signal the other end */ -iowrite16 (vq->index, (void __iomem *)vq->priv); +vp_write_notify (vq, vq->index);return true; }
@@ -89,7 +132,7 @@ static irqreturn_t vp_interrupt(int irq, void *opaque)/* reading the ISR has the effect of also clearing it so it's very * important to save off the value. */ - isr =ioread8 (vp_dev->isr); + isr =vp_read_isr (vp_dev);/* It's definitely not us if the ISR was not high */ if (!isr)
drivers/virtio/virtio_pci_common.h +41 -0
47 lines not on this page · raw message
drivers/virtio/virtio_pci_modern.c +91 -49
278 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 2/2 virtio: Introducing virtio_pci.no_mmio, the worst boot option in history.
In reply to Rusty RussellSometimes, devices are just too damn fast. Wouldn't it be nice if we could (1) have an option to access them in the most baroque way possible, and (2) ensure that even the normal case caused extra bloat?
Well, wish no longer: This patch does exactly that! Since every complaint virtio 1.0 device has to have a capability to allow backdoor access into the BARs, we can use that:
4.1.4.7.1 Device Requirements: PCI configuration access capability
The device MUST present at least one VIRTIO_PCI_CAP_PCI_CFG capability.
Upon detecting driver write access to pci_cfg_data, the device MUST execute a write access at offset cap.offset at BAR selected by cap.bar using the first cap.length bytes from pci_cfg_data.
Upon detecting driver read access to pci_cfg_data, the device MUST execute a read access of length cap.length at offset cap.offset at BAR selected by cap.bar and store the first cap.length bytes in pci_cfg_data.
--- drivers/virtio/virtio_pci_common.c | 31 ++++++- drivers/virtio/virtio_pci_common.h | 21 +++++ drivers/virtio/virtio_pci_legacy.c | 1 + drivers/virtio/virtio_pci_modern.c | 183 ++++++++++++++++++++++++++++++++++--- 4 files changed, 221 insertions(+), 15 deletions(-)
drivers/virtio/virtio_pci_common.c +27 -4
@@ -29,45 +29,68 @@ MODULE_PARM_DESC(force_legacy,u8 vp_read_isr (const struct virtio_pci_device *dev) { +if (dev->no_mmio) +return dev->no_mmio->read8 (dev, dev->isr,0 );return ioread8 (dev->isr); }void vp_write_notify (const struct virtqueue *vq,u16 vqindex) { -iowrite16 (vqindex, (void __iomem *)vq->priv); +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); + +if (vp_dev->no_mmio) + vp_dev->no_mmio->write16 (vp_dev, (void __iomem *)vq->priv, +0 , vqindex); +else +iowrite16 (vqindex, (void __iomem *)vq->priv); }u32 __vp_read_common32 (const struct virtio_pci_device *dev,size_t offset) { +if (dev->no_mmio) +return dev->no_mmio->read32 (dev, dev->common, offset);return ioread32 ((void __iomem *)dev->common + offset); }u16 __vp_read_common16 (const struct virtio_pci_device *dev,size_t offset) { +if (dev->no_mmio) +return dev->no_mmio->read16 (dev, dev->common, offset);return ioread16 ((void __iomem *)dev->common + offset); }u8 __vp_read_common8 (const struct virtio_pci_device *dev,size_t offset) { +if (dev->no_mmio) +return dev->no_mmio->read8 (dev, dev->common, offset);return ioread8 ((void __iomem *)dev->common + offset); }void __vp_write_common32 (const struct virtio_pci_device *dev,size_t offset,u32 val) { -iowrite32 (val, (void __iomem *)dev->common + offset); +if (dev->no_mmio) + dev->no_mmio->write32 (dev, dev->common, offset, val); +else +iowrite32 (val, (void __iomem *)dev->common + offset); }void __vp_write_common16 (const struct virtio_pci_device *dev,size_t offset,u16 val) { -iowrite16 (val, (void __iomem *)dev->common + offset); +if (dev->no_mmio) + dev->no_mmio->write16 (dev, dev->common, offset, val); +else +iowrite16 (val, (void __iomem *)dev->common + offset); }void __vp_write_common8 (const struct virtio_pci_device *dev,size_t offset,u8 val) { -iowrite8 (val, (void __iomem *)dev->common + offset); +if (dev->no_mmio) + dev->no_mmio->write8 (dev, dev->common, offset, val); +else +iowrite8 (val, (void __iomem *)dev->common + offset); }/* wait for pending irq handlers */
drivers/virtio/virtio_pci_common.h +21 -0
@@ -53,6 +53,9 @@ struct virtio_pci_device {struct virtio_device vdev;struct pci_dev *pci_dev; +/* This is only valid for modern devices. */ +const struct virtio_pci_no_mmio_ops *no_mmio; +/* In legacy mode, these two point to within ->legacy. */ /* Where to read and clear interrupt */ u8 __iomem *isr;
@@ -75,6 +78,9 @@ struct virtio_pci_device {/* Multiply queue_notify_off by this value. (non-legacy mode). */ u32 notify_offset_multiplier; +/* PCI config window for BAR access (non-legacy mode). */ +int window; +/* Legacy only field */ /* the IO mapping for the PCI config space */ void __iomem *ioaddr;
@@ -113,6 +119,21 @@ struct virtio_pci_device {u16 (*config_vector)(struct virtio_pci_device *vp_dev,u16 vector); }; +struct virtio_pci_no_mmio_ops { +u8 (*read8)(const struct virtio_pci_device *, +const void __iomem *,size_t ); +u16 (*read16)(const struct virtio_pci_device *, +const void __iomem *,size_t ); +u32 (*read32)(const struct virtio_pci_device *, +const void __iomem *,size_t ); +void (*write8)(const struct virtio_pci_device *, +const void __iomem *,size_t ,u8 ); +void (*write16)(const struct virtio_pci_device *, +const void __iomem *,size_t ,u16 ); +void (*write32)(const struct virtio_pci_device *, +const void __iomem *,size_t ,u32 ); +}; +/* Accessor functions. */ u8 vp_read_isr (const struct virtio_pci_device *dev);void vp_write_notify (const struct virtqueue *vq,u16 vqindex);
drivers/virtio/virtio_pci_legacy.c +1 -0
@@ -226,6 +226,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)return -ENODEV ; } + vp_dev->no_mmio =NULL ; vp_dev->ioaddr =pci_iomap (pci_dev,0 ,0 );if (!vp_dev->ioaddr)return -ENOMEM ;
drivers/virtio/virtio_pci_modern.c +172 -11
266 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 2/2 virtio: Introducing virtio_pci.no_mmio, the worst boot option in history.
In reply to Rusty RussellSometimes, devices are just too damn fast. Wouldn't it be nice if we could (1) have an option to access them in the most baroque way possible, and (2) ensure that even the normal case caused extra bloat?
Well, wish no longer: This patch does exactly that! Since every complaint virtio 1.0 device has to have a capability to allow backdoor access into the BARs, we can use that:
4.1.4.7.1 Device Requirements: PCI configuration access capability
The device MUST present at least one VIRTIO_PCI_CAP_PCI_CFG capability.
Upon detecting driver write access to pci_cfg_data, the device MUST execute a write access at offset cap.offset at BAR selected by cap.bar using the first cap.length bytes from pci_cfg_data.
Upon detecting driver read access to pci_cfg_data, the device MUST execute a read access of length cap.length at offset cap.offset at BAR selected by cap.bar and store the first cap.length bytes in pci_cfg_data.
--- drivers/virtio/virtio_pci_common.c | 31 ++++++- drivers/virtio/virtio_pci_common.h | 21 +++++ drivers/virtio/virtio_pci_legacy.c | 1 + drivers/virtio/virtio_pci_modern.c | 183 ++++++++++++++++++++++++++++++++++--- 4 files changed, 221 insertions(+), 15 deletions(-)
drivers/virtio/virtio_pci_common.c +27 -4
@@ -29,45 +29,68 @@ MODULE_PARM_DESC(force_legacy,u8 vp_read_isr (const struct virtio_pci_device *dev) { +if (dev->no_mmio) +return dev->no_mmio->read8 (dev, dev->isr,0 );return ioread8 (dev->isr); }void vp_write_notify (const struct virtqueue *vq,u16 vqindex) { -iowrite16 (vqindex, (void __iomem *)vq->priv); +struct virtio_pci_device *vp_dev =to_vp_device (vq->vdev); + +if (vp_dev->no_mmio) + vp_dev->no_mmio->write16 (vp_dev, (void __iomem *)vq->priv, +0 , vqindex); +else +iowrite16 (vqindex, (void __iomem *)vq->priv); }u32 __vp_read_common32 (const struct virtio_pci_device *dev,size_t offset) { +if (dev->no_mmio) +return dev->no_mmio->read32 (dev, dev->common, offset);return ioread32 ((void __iomem *)dev->common + offset); }u16 __vp_read_common16 (const struct virtio_pci_device *dev,size_t offset) { +if (dev->no_mmio) +return dev->no_mmio->read16 (dev, dev->common, offset);return ioread16 ((void __iomem *)dev->common + offset); }u8 __vp_read_common8 (const struct virtio_pci_device *dev,size_t offset) { +if (dev->no_mmio) +return dev->no_mmio->read8 (dev, dev->common, offset);return ioread8 ((void __iomem *)dev->common + offset); }void __vp_write_common32 (const struct virtio_pci_device *dev,size_t offset,u32 val) { -iowrite32 (val, (void __iomem *)dev->common + offset); +if (dev->no_mmio) + dev->no_mmio->write32 (dev, dev->common, offset, val); +else +iowrite32 (val, (void __iomem *)dev->common + offset); }void __vp_write_common16 (const struct virtio_pci_device *dev,size_t offset,u16 val) { -iowrite16 (val, (void __iomem *)dev->common + offset); +if (dev->no_mmio) + dev->no_mmio->write16 (dev, dev->common, offset, val); +else +iowrite16 (val, (void __iomem *)dev->common + offset); }void __vp_write_common8 (const struct virtio_pci_device *dev,size_t offset,u8 val) { -iowrite8 (val, (void __iomem *)dev->common + offset); +if (dev->no_mmio) + dev->no_mmio->write8 (dev, dev->common, offset, val); +else +iowrite8 (val, (void __iomem *)dev->common + offset); }/* wait for pending irq handlers */
drivers/virtio/virtio_pci_common.h +21 -0
@@ -53,6 +53,9 @@ struct virtio_pci_device {struct virtio_device vdev;struct pci_dev *pci_dev; +/* This is only valid for modern devices. */ +const struct virtio_pci_no_mmio_ops *no_mmio; +/* In legacy mode, these two point to within ->legacy. */ /* Where to read and clear interrupt */ u8 __iomem *isr;
@@ -75,6 +78,9 @@ struct virtio_pci_device {/* Multiply queue_notify_off by this value. (non-legacy mode). */ u32 notify_offset_multiplier; +/* PCI config window for BAR access (non-legacy mode). */ +int window; +/* Legacy only field */ /* the IO mapping for the PCI config space */ void __iomem *ioaddr;
@@ -113,6 +119,21 @@ struct virtio_pci_device {u16 (*config_vector)(struct virtio_pci_device *vp_dev,u16 vector); }; +struct virtio_pci_no_mmio_ops { +u8 (*read8)(const struct virtio_pci_device *, +const void __iomem *,size_t ); +u16 (*read16)(const struct virtio_pci_device *, +const void __iomem *,size_t ); +u32 (*read32)(const struct virtio_pci_device *, +const void __iomem *,size_t ); +void (*write8)(const struct virtio_pci_device *, +const void __iomem *,size_t ,u8 ); +void (*write16)(const struct virtio_pci_device *, +const void __iomem *,size_t ,u16 ); +void (*write32)(const struct virtio_pci_device *, +const void __iomem *,size_t ,u32 ); +}; +/* Accessor functions. */ u8 vp_read_isr (const struct virtio_pci_device *dev);void vp_write_notify (const struct virtqueue *vq,u16 vqindex);
drivers/virtio/virtio_pci_legacy.c +1 -0
@@ -226,6 +226,7 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)return -ENODEV ; } + vp_dev->no_mmio =NULL ; vp_dev->ioaddr =pci_iomap (pci_dev,0 ,0 );if (!vp_dev->ioaddr)return -ENOMEM ;
drivers/virtio/virtio_pci_modern.c +172 -11
266 lines not on this page · raw message
Signature · 1 line
2.1.0