virtio dataplane: adapt dataplane for virtio Version 1
PATCH v5 1/1 virtio dataplane: adapt dataplane for virtio Version 1
Let dataplane allocate different region for the desc/avail/used ring regions.
Take VIRTIO_RING_F_EVENT_IDX into account to increase the used/avail rings accordingly.
(changed __virtio16 into uint16_t,
map descriptor table and available ring read-only)
---
Changes from V4:
- added comments for VIRTIO_RING_F_EVENT_IDX and mapping
- use uint16_t as in ring definitions instead of __virtio16
- map descriptor table and available ring read-only
Changes from V3:
- added changelog
Changes from V2:
- incorporate the code directly in vring_setup().
- added room for the event indexes used with VIRTIO_RING_F_EVENT_IDX
Changes from v1:
- use a macro to gain LOCs inside of vring_setup()
hw/virtio/dataplane/vring.c | 66 +++++++++++++++++++++++++++++-------- include/hw/virtio/dataplane/vring.h | 4 ++- 2 files changed, 55 insertions(+), 15 deletions(-)
hw/virtio/dataplane/vring.c +52 -14
@@ -67,22 +67,50 @@ static void vring_unmap(void *buffer, bool is_write)/* Map the guest's vring to host memory */ bool vring_setup (Vring *vring,VirtIODevice *vdev,int n) { -hwaddr vring_addr =virtio_queue_get_ring_addr (vdev, n); -hwaddr vring_size =virtio_queue_get_ring_size (vdev, n); -void *vring_ptr; +struct vring *vr = &vring->vr; +hwaddr addr; +hwaddr size; +void *ptr; vring->broken = false; - - vring_ptr =vring_map (&vring->mr, vring_addr, vring_size, true); -if (!vring_ptr) { -error_report ("Failed to map vring " -"addr %#" HWADDR_PRIx" size %" HWADDR_PRIu, - vring_addr, vring_size); - vring->broken = true; -return false; + vr->num =virtio_queue_get_num (vdev, n); + + addr =virtio_queue_get_desc_addr (vdev, n); + size =virtio_queue_get_desc_size (vdev, n); +/* Map the descriptor area as read only */ + ptr =vring_map (&vring->mr_desc, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring desc at %16lx" , + size, addr); + goto out_err_desc; } - -vring_init (&vring->vr,virtio_queue_get_num (vdev, n), vring_ptr,4096 ); + vr->desc = ptr; + + addr =virtio_queue_get_avail_addr (vdev, n); + size =virtio_queue_get_avail_size (vdev, n); +/* Add the size of the used_event_idx */ + size +=sizeof (uint16_t ); +/* Map the driver area as read only */ + ptr =vring_map (&vring->mr_avail, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring avail at %16lx" , + size, addr); + goto out_err_avail; + } + vr->avail = ptr; + + addr =virtio_queue_get_used_addr (vdev, n); + size =virtio_queue_get_used_size (vdev, n); +/* Add the size of the avail_event_idx */ + size +=sizeof (uint16_t ); +/* Map the device area as read-write */ + ptr =vring_map (&vring->mr_used, addr, size, true); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring used at %16lx" , + size, addr); + goto out_err_used; + } + vr->used = ptr; vring->last_avail_idx =virtio_queue_get_last_avail_idx (vdev, n); vring->last_used_idx =vring_get_used_idx (vdev, vring);
@@ -92,6 +120,14 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)trace_vring_setup (virtio_queue_get_ring_addr (vdev, n), vring->vr.desc, vring->vr.avail, vring->vr.used);return true; + +out_err_used: +memory_region_unref (vring->mr_avail); +out_err_avail: +memory_region_unref (vring->mr_desc); +out_err_desc: + vring->broken = true; +return false; }void vring_teardown (Vring *vring,VirtIODevice *vdev,int n)
@@ -99,7 +135,9 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)virtio_queue_set_last_avail_idx (vdev, n, vring->last_avail_idx);virtio_queue_invalidate_signalled_used (vdev, n); -memory_region_unref (vring->mr); +memory_region_unref (vring->mr_desc); +memory_region_unref (vring->mr_avail); +memory_region_unref (vring->mr_used); }/* Disable guest->host notifies */
include/hw/virtio/dataplane/vring.h +3 -1
@@ -22,7 +22,9 @@#include "hw/virtio/virtio.h" typedef struct { - MemoryRegion *mr; /* memory region containing the vring */ + MemoryRegion *mr_desc; /* memory region for the vring desc */ + MemoryRegion *mr_avail; /* memory region for the vring avail */ + MemoryRegion *mr_used; /* memory region for the vring used */ struct vring vr; /* virtqueue vring mapped to host memory */ uint16_t last_avail_idx; /* last processed avail ring index */ uint16_t last_used_idx; /* last processed used ring index */
Signature · 1 line
2.3.0
Quoted 11 lines · On Mon, 7 Sep 2015 13:33:56 +0200 Pierre Morel <[email protected]>…
Let dataplane allocate different region for the desc/avail/used ring regions.
TakeVIRTIO_RING_F_EVENT_IDXinto account to increase the used/avail rings accordingly.Signed-off-by Pierre Morel <[email protected]>(changed
__virtio16intouint16_t,
map descriptor table and available ring read-only)Signed-off-by Greg Kurz <[email protected]>---
I have tested it works on ppc64.
Quoted 128 lines
Changes from V4:
- added comments forVIRTIO_RING_F_EVENT_IDXand mapping
- useuint16_tas in ring definitions instead of__virtio16
- map descriptor table and available ring read-onlyChanges from V3:
- added changelogChanges from V2:
- incorporate the code directly invring_setup().
- added room for the event indexes used withVIRTIO_RING_F_EVENT_IDXChanges from v1:
- use a macro to gain LOCs inside ofvring_setup()hw/virtio/dataplane/vring.c | 66 +++++++++++++++++++++++++++++-------- include/hw/virtio/dataplane/vring.h | 4 ++- 2 files changed, 55 insertions(+), 15 deletions(-)hw/virtio/dataplane/vring.c +52
-14@@ -67,22 +67,50 @@ static void vring_unmap(void *buffer, bool is_write)/* Map the guest's vring to host memory */ bool vring_setup (Vring *vring,VirtIODevice *vdev,int n) { -hwaddr vring_addr =virtio_queue_get_ring_addr (vdev, n); -hwaddr vring_size =virtio_queue_get_ring_size (vdev, n); -void *vring_ptr; +struct vring *vr = &vring->vr; +hwaddr addr; +hwaddr size; +void *ptr; vring->broken = false; - - vring_ptr =vring_map (&vring->mr, vring_addr, vring_size, true); -if (!vring_ptr) { -error_report ("Failed to map vring " -"addr %#" HWADDR_PRIx" size %" HWADDR_PRIu, - vring_addr, vring_size); - vring->broken = true; -return false; + vr->num =virtio_queue_get_num (vdev, n); + + addr =virtio_queue_get_desc_addr (vdev, n); + size =virtio_queue_get_desc_size (vdev, n); +/* Map the descriptor area as read only */ + ptr =vring_map (&vring->mr_desc, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring desc at %16lx" , + size, addr); + goto out_err_desc; } - -vring_init (&vring->vr,virtio_queue_get_num (vdev, n), vring_ptr,4096 ); + vr->desc = ptr; + + addr =virtio_queue_get_avail_addr (vdev, n); + size =virtio_queue_get_avail_size (vdev, n); +/* Add the size of the used_event_idx */ + size +=sizeof (uint16_t ); +/* Map the driver area as read only */ + ptr =vring_map (&vring->mr_avail, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring avail at %16lx" , + size, addr); + goto out_err_avail; + } + vr->avail = ptr; + + addr =virtio_queue_get_used_addr (vdev, n); + size =virtio_queue_get_used_size (vdev, n); +/* Add the size of the avail_event_idx */ + size +=sizeof (uint16_t ); +/* Map the device area as read-write */ + ptr =vring_map (&vring->mr_used, addr, size, true); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring used at %16lx" , + size, addr); + goto out_err_used; + } + vr->used = ptr; vring->last_avail_idx =virtio_queue_get_last_avail_idx (vdev, n); vring->last_used_idx =vring_get_used_idx (vdev, vring);@@ -92,6 +120,14 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)trace_vring_setup (virtio_queue_get_ring_addr (vdev, n), vring->vr.desc, vring->vr.avail, vring->vr.used);return true; + +out_err_used: +memory_region_unref (vring->mr_avail); +out_err_avail: +memory_region_unref (vring->mr_desc); +out_err_desc: + vring->broken = true; +return false; }void vring_teardown (Vring *vring,VirtIODevice *vdev,int n)@@ -99,7 +135,9 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)virtio_queue_set_last_avail_idx (vdev, n, vring->last_avail_idx);virtio_queue_invalidate_signalled_used (vdev, n); -memory_region_unref (vring->mr); +memory_region_unref (vring->mr_desc); +memory_region_unref (vring->mr_avail); +memory_region_unref (vring->mr_used); }/* Disable guest->host notifies */ include/hw/virtio/dataplane/vring.h +3
-1@@ -22,7 +22,9 @@#include "hw/virtio/virtio.h" typedef struct { - MemoryRegion *mr; /* memory region containing the vring */ + MemoryRegion *mr_desc; /* memory region for the vring desc */ + MemoryRegion *mr_avail; /* memory region for the vring avail */ + MemoryRegion *mr_used; /* memory region for the vring used */ struct vring vr; /* virtqueue vring mapped to host memory */ uint16_t last_avail_idx; /* last processed avail ring index */ uint16_t last_used_idx; /* last processed used ring index */
Quoted 11 lines · On Mon, 7 Sep 2015 13:33:56 +0200 Pierre Morel <[email protected]>…
Let dataplane allocate different region for the desc/avail/used ring regions.
TakeVIRTIO_RING_F_EVENT_IDXinto account to increase the used/avail rings accordingly.Signed-off-by Pierre Morel <[email protected]>(changed
__virtio16intouint16_t,
map descriptor table and available ring read-only)Signed-off-by Greg Kurz <[email protected]>---
As suggested by Michael during the review of v2.
--
Greg
Quoted 128 lines
Changes from V4:
- added comments forVIRTIO_RING_F_EVENT_IDXand mapping
- useuint16_tas in ring definitions instead of__virtio16
- map descriptor table and available ring read-onlyChanges from V3:
- added changelogChanges from V2:
- incorporate the code directly invring_setup().
- added room for the event indexes used withVIRTIO_RING_F_EVENT_IDXChanges from v1:
- use a macro to gain LOCs inside ofvring_setup()hw/virtio/dataplane/vring.c | 66 +++++++++++++++++++++++++++++-------- include/hw/virtio/dataplane/vring.h | 4 ++- 2 files changed, 55 insertions(+), 15 deletions(-)hw/virtio/dataplane/vring.c +52
-14@@ -67,22 +67,50 @@ static void vring_unmap(void *buffer, bool is_write)/* Map the guest's vring to host memory */ bool vring_setup (Vring *vring,VirtIODevice *vdev,int n) { -hwaddr vring_addr =virtio_queue_get_ring_addr (vdev, n); -hwaddr vring_size =virtio_queue_get_ring_size (vdev, n); -void *vring_ptr; +struct vring *vr = &vring->vr; +hwaddr addr; +hwaddr size; +void *ptr; vring->broken = false; - - vring_ptr =vring_map (&vring->mr, vring_addr, vring_size, true); -if (!vring_ptr) { -error_report ("Failed to map vring " -"addr %#" HWADDR_PRIx" size %" HWADDR_PRIu, - vring_addr, vring_size); - vring->broken = true; -return false; + vr->num =virtio_queue_get_num (vdev, n); + + addr =virtio_queue_get_desc_addr (vdev, n); + size =virtio_queue_get_desc_size (vdev, n); +/* Map the descriptor area as read only */ + ptr =vring_map (&vring->mr_desc, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring desc at %16lx" , + size, addr); + goto out_err_desc; } - -vring_init (&vring->vr,virtio_queue_get_num (vdev, n), vring_ptr,4096 ); + vr->desc = ptr; + + addr =virtio_queue_get_avail_addr (vdev, n); + size =virtio_queue_get_avail_size (vdev, n); +/* Add the size of the used_event_idx */ + size +=sizeof (uint16_t ); +/* Map the driver area as read only */ + ptr =vring_map (&vring->mr_avail, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring avail at %16lx" , + size, addr); + goto out_err_avail; + } + vr->avail = ptr; + + addr =virtio_queue_get_used_addr (vdev, n); + size =virtio_queue_get_used_size (vdev, n); +/* Add the size of the avail_event_idx */ + size +=sizeof (uint16_t ); +/* Map the device area as read-write */ + ptr =vring_map (&vring->mr_used, addr, size, true); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring used at %16lx" , + size, addr); + goto out_err_used; + } + vr->used = ptr; vring->last_avail_idx =virtio_queue_get_last_avail_idx (vdev, n); vring->last_used_idx =vring_get_used_idx (vdev, vring);@@ -92,6 +120,14 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)trace_vring_setup (virtio_queue_get_ring_addr (vdev, n), vring->vr.desc, vring->vr.avail, vring->vr.used);return true; + +out_err_used: +memory_region_unref (vring->mr_avail); +out_err_avail: +memory_region_unref (vring->mr_desc); +out_err_desc: + vring->broken = true; +return false; }void vring_teardown (Vring *vring,VirtIODevice *vdev,int n)@@ -99,7 +135,9 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)virtio_queue_set_last_avail_idx (vdev, n, vring->last_avail_idx);virtio_queue_invalidate_signalled_used (vdev, n); -memory_region_unref (vring->mr); +memory_region_unref (vring->mr_desc); +memory_region_unref (vring->mr_avail); +memory_region_unref (vring->mr_used); }/* Disable guest->host notifies */ include/hw/virtio/dataplane/vring.h +3
-1@@ -22,7 +22,9 @@#include "hw/virtio/virtio.h" typedef struct { - MemoryRegion *mr; /* memory region containing the vring */ + MemoryRegion *mr_desc; /* memory region for the vring desc */ + MemoryRegion *mr_avail; /* memory region for the vring avail */ + MemoryRegion *mr_used; /* memory region for the vring used */ struct vring vr; /* virtqueue vring mapped to host memory */ uint16_t last_avail_idx; /* last processed avail ring index */ uint16_t last_used_idx; /* last processed used ring index */
Stefan Hajnoczi
AppliedQuoted 23 lines · Pierre Morel
Let dataplane allocate different region for the desc/avail/used ring regions.
TakeVIRTIO_RING_F_EVENT_IDXinto account to increase the used/avail rings accordingly.Signed-off-by Pierre Morel <[email protected]>(changed
__virtio16intouint16_t,
map descriptor table and available ring read-only)Signed-off-by Greg Kurz <[email protected]>---
Changes from V4:
- added comments forVIRTIO_RING_F_EVENT_IDXand mapping
- useuint16_tas in ring definitions instead of__virtio16
- map descriptor table and available ring read-onlyChanges from V3:
- added changelogChanges from V2:
- incorporate the code directly invring_setup().
- added room for the event indexes used withVIRTIO_RING_F_EVENT_IDX
Quoted 6 lines
Changes from v1:
- use a macro to gain LOCs inside ofvring_setup()hw/virtio/dataplane/vring.c | 66 +++++++++++++++++++++++++++++-------- include/hw/virtio/dataplane/vring.h | 4 ++- 2 files changed, 55 insertions(+), 15 deletions(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
Quoted 27 lines · On Wed, 9 Sep 2015 10:29:51 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 26 lines · Pierre Morel
Let dataplane allocate different region for the desc/avail/used ring regions.
TakeVIRTIO_RING_F_EVENT_IDXinto account to increase the used/avail rings accordingly.Signed-off-by Pierre Morel <[email protected]>(changed
__virtio16intouint16_t,
map descriptor table and available ring read-only)Signed-off-by Greg Kurz <[email protected]>---
Changes from V4:
- added comments forVIRTIO_RING_F_EVENT_IDXand mapping
- useuint16_tas in ring definitions instead of__virtio16
- map descriptor table and available ring read-onlyChanges from V3:
- added changelogChanges from V2:
- incorporate the code directly invring_setup().
- added room for the event indexes used withVIRTIO_RING_F_EVENT_IDXChanges from v1:
- use a macro to gain LOCs inside ofvring_setup()
Quoted 9 lines
Quoted 3 lines
hw/virtio/dataplane/vring.c | 66 +++++++++++++++++++++++++++++-------- include/hw/virtio/dataplane/vring.h | 4 ++- 2 files changed, 55 insertions(+), 15 deletions(-)Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/blockStefan
--
Greg
Quoted 9 lines · Pierre Morel
Let dataplane allocate different region for the desc/avail/used ring regions.
TakeVIRTIO_RING_F_EVENT_IDXinto account to increase the used/avail rings accordingly.Signed-off-by Pierre Morel <[email protected]>(changed
__virtio16intouint16_t,
map descriptor table and available ring read-only)Signed-off-by Greg Kurz <[email protected]>
Quoted 132 lines
---
Changes from V4:
- added comments forVIRTIO_RING_F_EVENT_IDXand mapping
- useuint16_tas in ring definitions instead of__virtio16
- map descriptor table and available ring read-onlyChanges from V3:
- added changelogChanges from V2:
- incorporate the code directly invring_setup().
- added room for the event indexes used withVIRTIO_RING_F_EVENT_IDXChanges from v1:
- use a macro to gain LOCs inside ofvring_setup()hw/virtio/dataplane/vring.c | 66 +++++++++++++++++++++++++++++-------- include/hw/virtio/dataplane/vring.h | 4 ++- 2 files changed, 55 insertions(+), 15 deletions(-)hw/virtio/dataplane/vring.c +52
-14@@ -67,22 +67,50 @@ static void vring_unmap(void *buffer, bool is_write)/* Map the guest's vring to host memory */ bool vring_setup (Vring *vring,VirtIODevice *vdev,int n) { -hwaddr vring_addr =virtio_queue_get_ring_addr (vdev, n); -hwaddr vring_size =virtio_queue_get_ring_size (vdev, n); -void *vring_ptr; +struct vring *vr = &vring->vr; +hwaddr addr; +hwaddr size; +void *ptr; vring->broken = false; - - vring_ptr =vring_map (&vring->mr, vring_addr, vring_size, true); -if (!vring_ptr) { -error_report ("Failed to map vring " -"addr %#" HWADDR_PRIx" size %" HWADDR_PRIu, - vring_addr, vring_size); - vring->broken = true; -return false; + vr->num =virtio_queue_get_num (vdev, n); + + addr =virtio_queue_get_desc_addr (vdev, n); + size =virtio_queue_get_desc_size (vdev, n); +/* Map the descriptor area as read only */ + ptr =vring_map (&vring->mr_desc, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring desc at %16lx" , + size, addr); + goto out_err_desc; } - -vring_init (&vring->vr,virtio_queue_get_num (vdev, n), vring_ptr,4096 ); + vr->desc = ptr; + + addr =virtio_queue_get_avail_addr (vdev, n); + size =virtio_queue_get_avail_size (vdev, n); +/* Add the size of the used_event_idx */ + size +=sizeof (uint16_t ); +/* Map the driver area as read only */ + ptr =vring_map (&vring->mr_avail, addr, size, false); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring avail at %16lx" , + size, addr); + goto out_err_avail; + } + vr->avail = ptr; + + addr =virtio_queue_get_used_addr (vdev, n); + size =virtio_queue_get_used_size (vdev, n); +/* Add the size of the avail_event_idx */ + size +=sizeof (uint16_t ); +/* Map the device area as read-write */ + ptr =vring_map (&vring->mr_used, addr, size, true); +if (!ptr) { +error_report ("Failed to map 0x%16lx byte for vring used at %16lx" , + size, addr); + goto out_err_used; + } + vr->used = ptr; vring->last_avail_idx =virtio_queue_get_last_avail_idx (vdev, n); vring->last_used_idx =vring_get_used_idx (vdev, vring);@@ -92,6 +120,14 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)trace_vring_setup (virtio_queue_get_ring_addr (vdev, n), vring->vr.desc, vring->vr.avail, vring->vr.used);return true; + +out_err_used: +memory_region_unref (vring->mr_avail); +out_err_avail: +memory_region_unref (vring->mr_desc); +out_err_desc: + vring->broken = true; +return false; }void vring_teardown (Vring *vring,VirtIODevice *vdev,int n)@@ -99,7 +135,9 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)virtio_queue_set_last_avail_idx (vdev, n, vring->last_avail_idx);virtio_queue_invalidate_signalled_used (vdev, n); -memory_region_unref (vring->mr); +memory_region_unref (vring->mr_desc); +memory_region_unref (vring->mr_avail); +memory_region_unref (vring->mr_used); }/* Disable guest->host notifies */ include/hw/virtio/dataplane/vring.h +3
-1@@ -22,7 +22,9 @@#include "hw/virtio/virtio.h" typedef struct { - MemoryRegion *mr; /* memory region containing the vring */ + MemoryRegion *mr_desc; /* memory region for the vring desc */ + MemoryRegion *mr_avail; /* memory region for the vring avail */ + MemoryRegion *mr_used; /* memory region for the vring used */ struct vring vr; /* virtqueue vring mapped to host memory */ uint16_t last_avail_idx; /* last processed avail ring index */ uint16_t last_used_idx; /* last processed used ring index */Signature · 1 line
2.3.0