* [PATCH] virtio_pci: fix capability format, comments
@ 2013-05-28 8:08 Michael S. Tsirkin
2013-05-30 1:33 ` Rusty Russell
0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2013-05-28 8:08 UTC (permalink / raw)
To: virtualization, kvm
Cc: Rusty Russell, Paul E. McKenney, David Howells, Dave Jones,
linux-kernel
- queue size can actually be 0 which is not a power of 2
- fix capability format. PCI spec says:
The layout of the information is vendor specific, except that the byte
immediately following the “Next” pointer in the capability structure is
defined to be a length field.
This length field provides the number of bytes in the capability
structure (including the ID and Next pointer bytes).
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
This patch is on top of the new layout branch, too
include/uapi/linux/virtio_pci.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pci.h
index cda688f..a5ef8cd 100644
--- a/include/uapi/linux/virtio_pci.h
+++ b/include/uapi/linux/virtio_pci.h
@@ -129,6 +129,7 @@
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 cfg_type; /* One of the VIRTIO_PCI_CAP_*_CFG. */
__u8 bar; /* Where to find it. */
__le32 offset; /* Offset within bar. */
@@ -154,7 +155,7 @@ struct virtio_pci_common_cfg {
/* About a specific virtqueue. */
__le16 queue_select; /* read-write */
- __le16 queue_size; /* read-write, power of 2. */
+ __le16 queue_size; /* read-write, power of 2, or 0. */
__le16 queue_msix_vector; /* read-write */
__le16 queue_enable; /* read-write */
__le16 queue_notify_off; /* read-only */
--
MST
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] virtio_pci: fix capability format, comments
2013-05-28 8:08 [PATCH] virtio_pci: fix capability format, comments Michael S. Tsirkin
@ 2013-05-30 1:33 ` Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2013-05-30 1:33 UTC (permalink / raw)
To: Michael S. Tsirkin, virtualization, kvm
Cc: Paul E. McKenney, David Howells, Dave Jones, linux-kernel
"Michael S. Tsirkin" <mst@redhat.com> writes:
> - queue size can actually be 0 which is not a power of 2
Actually, that points to a flaw in the code. When we shut down the
queue, we should ideally reset it to what the device started with,
rather than 0.
See below.
> - fix capability format. PCI spec says:
> The layout of the information is vendor specific, except that the byte
> immediately following the “Next” pointer in the capability structure is
> defined to be a length field.
> This length field provides the number of bytes in the capability
> structure (including the ID and Next pointer bytes).
That part's definitely correct: applied.
Thanks,
Rusty.
Subjet: virtio_pci: save the desired ringsize.
MST points out that 0 isn't a power of 2. This means we can't re-open
a virtio device once we write 0 into the queue length.
We should restore the amount the device originally asked for.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
diff --git a/drivers/virtio/virtio_pci-common.h b/drivers/virtio/virtio_pci-common.h
index ba1bf81..0e3143b 100644
--- a/drivers/virtio/virtio_pci-common.h
+++ b/drivers/virtio/virtio_pci-common.h
@@ -82,6 +82,9 @@ struct virtio_pci_vq_info {
/* MSI-X vector (or none) */
unsigned msix_vector;
+
+ /* What size did the device *want* this to be? */
+ u16 desired_num;
};
/* the notify function used when creating a virt queue */
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 0f0e3a6..8b35c2e 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -230,6 +230,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
return ERR_PTR(-ENOMEM);
info->msix_vector = msix_vec;
+ info->desired_num = num;
/* get offset of notification word for this vq (shouldn't wrap) */
off = ioread16(&vp_dev->common->queue_notify_off);
@@ -350,7 +351,7 @@ static void del_vq(struct virtqueue *vq)
vring_del_virtqueue(vq);
/* This is for our own benefit, not the device's! */
- iowrite16(0, &vp_dev->common->queue_size);
+ iowrite16(info->desired_num, &vp_dev->common->queue_size);
iowrite64_twopart(0, &vp_dev->common->queue_desc);
iowrite64_twopart(0, &vp_dev->common->queue_avail);
iowrite64_twopart(0, &vp_dev->common->queue_used);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-30 5:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-28 8:08 [PATCH] virtio_pci: fix capability format, comments Michael S. Tsirkin
2013-05-30 1:33 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).