dataplane: use endian-aware memory accessors
cover dataplane: use endian-aware memory accessors
In commit 0f5d1d2a49778863db54b4b1ac2dc008a8f21f11 ("virtio: memory accessors for endian-ambivalent targets") endian-aware memory accessors were added to support bi-endian targets like recent ppc64 systems.
The dataplane vring.c code does not use these accessors and is therefore unable to emulate virtio devices when the endianness differs between the device and host.
These patches modify vring.c to use the endian-aware accessors.
I have tested that x86_64 guests still function correctly.
I have only compile-tested on ppc64 and require help testing that dataplane works. If you have access to a bi-endian system, please try:
qemu ... -object iothread,id=iothread0 \
-drive if=none,id=drive0,file=... \
-device virtio-blk-pci,iothread=iothread0,drive=drive0Stefan Hajnoczi (2):
dataplane: move vring_more_avail() into vring.c
dataplane: use virtio_ld/st_p() for endian-aware memory access
hw/block/dataplane/virtio-blk.c | 2 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 69 ++++++++++++++++++++++++++----------- include/hw/virtio/dataplane/vring.h | 9 ++--- 6 files changed, 55 insertions(+), 31 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 dataplane: move vring_more_avail() into vring.c
vring_more_avail() was an inline function in vring.h. No external callers use it so it's not necessary to export it.
Furthermore, we'll need virtio-access.h for endian-aware memory accesses but that only works in per-target object files (obj-y) and not build-once object files (common-obj-y) like the virtio-blk and virtio-scsi devices.
Move vring_more_avail() into vring.c so that virtio devices like virtio-blk and virtio-scsi can continue to use vring.h without being built once per target.
--- hw/virtio/dataplane/vring.c | 6 ++++++ include/hw/virtio/dataplane/vring.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-)
hw/virtio/dataplane/vring.c +6 -0
@@ -21,6 +21,12 @@#include "hw/virtio/dataplane/vring.h" #include "qemu/error-report.h" +/* Are there more descriptors available? */ +static inline bool vring_more_avail (Vring *vring) +{ +return vring->vr.avail->idx != vring->last_avail_idx; +} +/* vring_map can be coupled with vring_unmap or (if you still have the * value returned in *mr) memory_region_unref. */
include/hw/virtio/dataplane/vring.h +0 -6
@@ -36,12 +36,6 @@ static inline unsigned int vring_get_num(Vring *vring)return vring->vr.num; } -/* Are there more descriptors available? */ -static inline bool vring_more_avail (Vring *vring) -{ -return vring->vr.avail->idx != vring->last_avail_idx; -} -/* Fail future vring_pop() and vring_push() calls until reset */ static inline void vring_set_broken (Vring *vring) {
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 1/2] dataplane: move vring_more_avail() into vring.c
Quoted 8 lines · Stefan Hajnoczi
vring_more_avail()was an inline function invring.h. No external callers use it so it's not necessary to export it.Furthermore, we'll need
virtio-access.hfor endian-aware memory accesses but that only works in per-target object files (obj-y) and not build-once object files (common-obj-y) like the virtio-blk and virtio-scsi devices.
Quoted 5 lines
Move
vring_more_avail()intovring.cso that virtio devices like virtio-blk and virtio-scsi can continue to usevring.hwithout being built once per target.Signed-off-by Stefan Hajnoczi <[email protected]>
Looks sensible to me.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH 1/2] dataplane: move vring_more_avail() into vring.c
In reply to Stefan HajnocziQuoted 8 lines · On Mon, 19 Jan 2015 17:04:36 +0000 Stefan Hajnoczi <[email protected]> wrote:
vring_more_avail()was an inline function invring.h. No external callers use it so it's not necessary to export it.Furthermore, we'll need
virtio-access.hfor endian-aware memory accesses but that only works in per-target object files (obj-y) and not build-once object files (common-obj-y) like the virtio-blk and virtio-scsi devices.
Quoted 6 lines
Move
vring_more_avail()intovring.cso that virtio devices like virtio-blk and virtio-scsi can continue to usevring.hwithout being built once per target.Signed-off-by Stefan Hajnoczi <[email protected]>---
Yes, this function should definitely be declared in more appropriate scope. And BTW I remember Cornelia had the same concern in the virtio-1 serie. :)
Quoted 38 lines
hw/virtio/dataplane/vring.c | 6 ++++++ include/hw/virtio/dataplane/vring.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-)hw/virtio/dataplane/vring.c +6
-0@@ -21,6 +21,12 @@#include "hw/virtio/dataplane/vring.h" #include "qemu/error-report.h" +/* Are there more descriptors available? */ +static inline bool vring_more_avail (Vring *vring) +{ +return vring->vr.avail->idx != vring->last_avail_idx; +} +/* vring_map can be coupled with vring_unmap or (if you still have the * value returned in *mr) memory_region_unref. */ include/hw/virtio/dataplane/vring.h +0
-6@@ -36,12 +36,6 @@ static inline unsigned int vring_get_num(Vring *vring)return vring->vr.num; } -/* Are there more descriptors available? */ -static inline bool vring_more_avail (Vring *vring) -{ -return vring->vr.avail->idx != vring->last_avail_idx; -} -/* Fail future vring_pop() and vring_push() calls until reset */ static inline void vring_set_broken (Vring *vring) {
PATCH 2/2 dataplane: use virtio_ld/st_p() for endian-aware memory access
In reply to Stefan HajnocziThe vring.c code was written under the assumption that virtio devices have the same endianness as the host.
This is wrong when emulating targets that differ in endianness from the host.
It is also wrong when emulating bi-endian targets like POWER 8 processors, which support both little- and big-endian at run-time. In this case the virtio device knows which endianness to use.
This change requires the virtio-access.h APIs and therefore builds vring.o for each target (obj-y instead of common-obj-y).
Note that $(CONFIG_VIRTIO) for dataplane/ was dropped in hw/virtio/Makefile.objs because hw/Makefile.objs conditionally includes hw/virtio/ on $(CONFIG_VIRTIO) already.
Only a small change is needed to the vring.h interface: vring_push() now takes a VirtIODevice *vdev argument.
--- hw/block/dataplane/virtio-blk.c | 2 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 67 +++++++++++++++++++++++++------------ include/hw/virtio/dataplane/vring.h | 3 +- 6 files changed, 51 insertions(+), 27 deletions(-)
hw/block/dataplane/virtio-blk.c +1 -1
@@ -75,7 +75,7 @@ static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)VirtIOBlockDataPlane *s = req->dev->dataplane;stb_p (&req->in->status, status); -vring_push (&req->dev->dataplane->vring, &req->elem, +vring_push (s->vdev, &req->dev->dataplane->vring, &req->elem, req->qiov.size +sizeof (*req->in));/* Suppress notification to guest by BH and its scheduled
hw/scsi/virtio-scsi-dataplane.c +1 -1
@@ -94,7 +94,7 @@ void virtio_scsi_vring_push_notify(VirtIOSCSIReq *req) {VirtIODevice *vdev =VIRTIO_DEVICE (req->vring->parent); -vring_push (&req->vring->vring, &req->elem, +vring_push (vdev, &req->vring->vring, &req->elem, req->qsgl.size + req->resp_iov.size);if (vring_should_notify (vdev, &req->vring->vring)) {
hw/virtio/Makefile.objs +1 -1
@@ -2,7 +2,7 @@ common-obj-y += virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o common-obj-y += virtio-bus.o common-obj-y += virtio-mmio.o -common-obj-$(CONFIG_VIRTIO) += dataplane/ obj-y += virtio.o virtio-balloon.o obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o +obj-y += dataplane/
hw/virtio/dataplane/Makefile.objs +1 -1
@@ -1 +1 @@ -common-obj-y += vring.o +obj-y += vring.o
hw/virtio/dataplane/vring.c +45 -22
178 lines not on this page · raw message
include/hw/virtio/dataplane/vring.h +2 -1
@@ -48,6 +48,7 @@ void vring_disable_notification(VirtIODevice *vdev, Vring *vring);bool vring_enable_notification (VirtIODevice *vdev,Vring *vring);bool vring_should_notify (VirtIODevice *vdev,Vring *vring);int vring_pop (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem); -void vring_push (Vring *vring,VirtQueueElement *elem,int len); +void vring_push (VirtIODevice *vdev,Vring *vring, +VirtQueueElement *elem,int len);#endif /* VRING_H */
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 2/2] dataplane: use virtio_ld/st_p() for endian-aware memory access
Quoted 17 lines · Stefan Hajnoczi
The
vring.ccode was written under the assumption that virtio devices have the same endianness as the host.This is wrong when emulating targets that differ in endianness from the host.
It is also wrong when emulating bi-endian targets like POWER 8 processors, which support both little- and big-endian at run-time. In this case the virtio device knows which endianness to use.
This change requires the
virtio-access.hAPIs and therefore builds vring.o for each target (obj-y instead of common-obj-y).Note that $(CONFIG_VIRTIO) for dataplane/ was dropped in hw/virtio/Makefile.objs because hw/Makefile.objs conditionally includes hw/virtio/ on $(CONFIG_VIRTIO) already.
Quoted 6 lines
Only a small change is needed to the
vring.hinterface:vring_push()now takes a VirtIODevice *vdev argument.Cc Paolo Bonzini <[email protected]>Cc Fam Zheng <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>
Without this patch adding an iothread to a secondary virtio-blk disk caused the kernel to jam up during boot. With this patch it booted up and I was able to do things with the disk.
I'm still not able to add an iothread to a primary virtio-blk device:
SLOF (guest firmware) gets errors attempting to read the kernel to boot. However, SLOF is always big endian, so I think that's an unrelated bug.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 9 lines · On Mon, 19 Jan 2015 17:04:35 +0000 Stefan Hajnoczi <[email protected]> wrote:
In commit
0f5d1d2a49778863db54b4b1ac2dc008a8f21f11("virtio: memory accessors for endian-ambivalent targets") endian-aware memory accessors were added to support bi-endian targets like recent ppc64 systems.The dataplane
vring.ccode does not use these accessors and is therefore unable to emulate virtio devices when the endianness differs between the device and host.These patches modify
vring.cto use the endian-aware accessors.
I had modified the accesses in vring.c to consider endianness for virtio-1 support as well. I wonder whether we can find some common ground there?
It's been a while since I have had time to work on this, but searching for "dataplane: allow virtio-1 devices" should lead you to the relevant patch.
Stefan Hajnoczi
NAKQuoted 23 lines · Stefan Hajnoczi
In commit
0f5d1d2a49778863db54b4b1ac2dc008a8f21f11("virtio: memory accessors for endian-ambivalent targets") endian-aware memory accessors were added to support bi-endian targets like recent ppc64 systems.The dataplane
vring.ccode does not use these accessors and is therefore unable to emulate virtio devices when the endianness differs between the device and host.These patches modify
vring.cto use the endian-aware accessors.I have tested that
x86_64guests still function correctly.I have only compile-tested on ppc64 and require help testing that dataplane works. If you have access to a bi-endian system, please try:
qemu ... -object iothread,id=iothread0 \ -drive if=none,id=drive0,file=... \ -device virtio-blk-pci,iothread=iothread0,drive=drive0Stefan Hajnoczi (2):
dataplane: movevring_more_avail()intovring.c
dataplane: use virtio_ld/st_p() for endian-aware memory access
Quoted 7 lines
hw/block/dataplane/virtio-blk.c | 2 +- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/virtio/Makefile.objs | 2 +- hw/virtio/dataplane/Makefile.objs | 2 +- hw/virtio/dataplane/vring.c | 69 ++++++++++++++++++++++++++----------- include/hw/virtio/dataplane/vring.h | 9 ++--- 6 files changed, 55 insertions(+), 31 deletions(-)
NACK
Cornelia Huck already has an equivalent patch.