virtio-blk PCI backend
RFC 1/1 virtio-blk PCI backend
This still needs quite a lot of work but I wanted to post it for reference.
Regards,
Anthony Liguori
qemu/Makefile.target +2 -0
@@ -448,6 +448,8 @@ VL_OBJS += rtl8139.o # PCI Hypercall VL_OBJS+= hypercall.o +VL_OBJS += virtio.o + ifeq ($(TARGET_BASE_ARCH), i386) # Hardware support VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
qemu/hw/pc.c +5 -0
@@ -943,6 +943,11 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, int boot_device,#ifdef USE_HYPERCALL pci_hypercall_init (pci_bus);#endif + +if (1 ) { +virtio_init_pci (pci_bus,"virtio" ,0x5002 ,0x2258 ); + } +if (pci_enabled) {pci_piix3_ide_init (pci_bus, bs_table, piix3_devfn +1 , i8259); }else {
qemu/hw/virtio.c new file +486 -0
486 lines not on this page · raw message
qemu/vl.h +13 -0
@@ -1392,6 +1392,19 @@ typedef struct ADBDevice ADBDevice;void pci_hypercall_init (PCIBus *bus);void vmchannel_init (CharDriverState *hd,uint32_t deviceid,uint32_t index); +/* virtio.c */ + +typedef struct VirtQueue VirtQueue ; +typedef struct VirtIODevice VirtIODevice ; + +VirtIODevice *virtio_init_pci (PCIBus *bus,const char *name, +uint16_t vendorid,uint16_t deviceid); +void virtio_set_id (VirtIODevice *vdev,uint16_t vendor,uint16_t device); +void virtio_add_queue (VirtIODevice *vdev,unsigned int num, +void (*handle_output)(void *,VirtIODevice *,VirtQueue *), +void *opaque); +void virtio_add_config (VirtIODevice *vdev,int type,void *data,size_t size); +/* buf = NULL means polling */ typedef int ADBDeviceRequest (ADBDevice *d,uint8_t *buf_out,const uint8_t *buf,int len);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 11944902733951-git-send-email-aliguori-r/[email protected]
qemu/hw/virtio.c line 213
Quoted 5 lines · Anthony Liguori
qemu/hw/virtio.c new file +4
-0+case VIRTIO_PCI_QUEUE_NOTIFY : +if (val <VIRTIO_PCI_QUEUE_MAX ) +virtio_ring_kick (vdev, &vdev->vq[val]); +break ;
I see you're not using hypercalls for this, presumably for compatibility with -no-kvm. Well I think I have a solution: advertise vmcall, vmmcall, pio to some port, and int $some_vector as hypercall feature bits in cpuid (for kvm, kvm, qemu, and kvm-lite respectively). Early setup code could patch the instruction as appropriate (I hear code patching is now taught in second grade).
(kvm could advertise all four, or maybe just the first two)
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 4732ABA0.5090603-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 11 lines · Avi Kivity
qemu/hw/virtio.c line 213
Quoted 6 lines · Anthony Liguori
qemu/hw/virtio.c new file +4
-0+case VIRTIO_PCI_QUEUE_NOTIFY : +if (val <VIRTIO_PCI_QUEUE_MAX ) +virtio_ring_kick (vdev, &vdev->vq[val]); +break ;I see you're not using hypercalls for this, presumably for compatibility with -no-kvm.
More than just that. By stick to PIO, we are compatible with just about any VMM. For instance, we get Xen support for free. If we used hypercalls, even if we agreed on a way to determine which number to use and how to make those calls, it would still be difficult to implement in something like Xen.
Quoted 6 lines
Well I think I have a solution: advertise vmcall,
vmmcall, pio to some port, and int $some_vector as hypercall feature bits in cpuid (for kvm, kvm, qemu, and kvm-lite respectively). Early setup code could patch the instruction as appropriate (I hear code patching is now taught in second grade).
That ties our device to our particular hypercall implementation. If we were going to do this, I'd prefer to advertise it in the device I think. I really would need to look at the performance though of vmcall and an edge triggered interrupt. It would have to be pretty compelling to warrant the additional complexity I think.
Regards,
Anthony Liguori
Quoted 3 lines
(kvm could advertise all four, or maybe just the first two)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 473315DB.9030803-r/[email protected]
Quoted 9 lines · Anthony Liguori
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Anthony Liguori
qemu/hw/virtio.c new file +4
-0+case VIRTIO_PCI_QUEUE_NOTIFY : +if (val <VIRTIO_PCI_QUEUE_MAX ) +virtio_ring_kick (vdev, &vdev->vq[val]); +break ;
Quoted 9 lines
Quoted 2 lines
I see you're not using hypercalls for this, presumably for compatibility with -no-kvm.
More than just that. By stick to PIO, we are compatible with just about any VMM. For instance, we get Xen support for free. If we used hypercalls, even if we agreed on a way to determine which number to use and how to make those calls, it would still be difficult to implement in something like Xen.
But pio through the config space basically means you're committed to handling it in qemu. We want a more flexible mechanism.
Detecting how to make hypercalls can be left to paravirt_ops.
(for Xen you'd use an event channel; and for kvm the virtio kick hypercall).
Quoted 7 lines
Quoted 6 lines
Well I think I have a solution: advertise vmcall,
vmmcall, pio to some port, and int $some_vector as hypercall feature bits in cpuid (for kvm, kvm, qemu, and kvm-lite respectively). Early setup code could patch the instruction as appropriate (I hear code patching is now taught in second grade).
Quoted 5 lines
That ties our device to our particular hypercall implementation. If we were going to do this, I'd prefer to advertise it in the device I think. I really would need to look at the performance though of vmcall and an edge triggered interrupt. It would have to be pretty compelling to warrant the additional complexity I think.
vmcall costs will go down, and we don't want to use different mechanisms for high bandwidth and low bandwidth devices.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 4733170B.70206-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 21 lines · Avi Kivity
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Avi Kivity
Review
Quoted 5 lines · Anthony Liguori
(quoted diff) +4
-0+ case VIRTIO_PCI_QUEUE_NOTIFY: + if (val < VIRTIO_PCI_QUEUE_MAX) + virtio_ring_kick(vdev, &vdev->vq[val]); + break;I see you're not using hypercalls for this, presumably for compatibility
with -no-kvm.Quoted 6 lines
More than just that. By stick to PIO, we are compatible with just about any VMM. For instance, we get Xen support for free. If we used hypercalls, even if we agreed on a way to determine which number to use and how to make those calls, it would still be difficult to implement in something like Xen.
Quoted 2 lines
But pio through the config space basically means you're committed to handling it in qemu. We want a more flexible mechanism.
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the pci_map function in QEMU to just notify the kernel that it should listen on a particular PIO range.
Quoted 12 lines
Detecting how to make hypercalls can be left to
paravirt_ops.(for Xen you'd use an event channel; and for kvm the virtio kick hypercall).
Quoted 7 lines
Quoted 6 lines
Well I think I have a solution: advertise vmcall,
vmmcall, pio to some port, and int $some_vector as hypercall feature bits in cpuid (for kvm, kvm, qemu, and kvm-lite respectively). Early setup code could patch the instruction as appropriate (I hear code patching is now taught in second grade).
Quoted 8 lines
Quoted 5 lines
That ties our device to our particular hypercall implementation. If we were going to do this, I'd prefer to advertise it in the device I think. I really would need to look at the performance though of vmcall and an edge triggered interrupt. It would have to be pretty compelling to warrant the additional complexity I think.
vmcall costs will go down, and we don't want to use different mechanisms for high bandwidth and low bandwidth devices.
vmcalls will certainly get faster but I doubt that the cost difference between vmcall and pio will ever be greater than a few hundred cycles. The only performance sensitive operation here would be the kick and I don't think a few hundred cycles in the kick path is ever going to be that significant for overall performance.
So why introduce the extra complexity?
Regards,
Anthony Liguori
Quoted 2 lines
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 473326B4.2080307-r/[email protected]
Quoted 30 lines · Anthony Liguori
Quoted 24 lines · Avi Kivity
Quoted 15 lines · Anthony Liguori
Quoted 9 lines · Avi Kivity
Review
Quoted 6 lines · Anthony Liguori
(quoted diff) +4
-0+ case VIRTIO_PCI_QUEUE_NOTIFY: + if (val < VIRTIO_PCI_QUEUE_MAX) + virtio_ring_kick(vdev, &vdev->vq[val]); + break;Quoted 4 lines
I see you're not using hypercalls for this, presumably for compatibility
with -no-kvm.Quoted 7 lines
More than just that. By stick to PIO, we are compatible with just about any VMM. For instance, we get Xen support for free. If we used hypercalls, even if we agreed on a way to determine which number to use and how to make those calls, it would still be difficult to implement in something like Xen.
Quoted 3 lines
But pio through the config space basically means you're committed to handling it in qemu. We want a more flexible mechanism.
Quoted 7 lines
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the
pci_mapfunction in QEMU to just notify the kernel that it should listen on a particular PIO range.
This is a config space write, right? If so, the range is the regular 0xcf8-0xcff and it has to be very specially handled.
Quoted 23 lines
Quoted 13 lines
Detecting how to make hypercalls can be left to
paravirt_ops.(for Xen you'd use an event channel; and for kvm the virtio kick hypercall).
Quoted 7 lines
Quoted 7 lines
Well I think I have a solution: advertise vmcall,
vmmcall, pio to some port, and int $some_vector as hypercall feature bits in cpuid (for kvm, kvm, qemu, and kvm-lite respectively). Early setup code could patch the instruction as appropriate (I hear code patching is now taught in second grade).Quoted 9 lines
Quoted 6 lines
That ties our device to our particular hypercall implementation. If we were going to do this, I'd prefer to advertise it in the device I think. I really would need to look at the performance though of vmcall and an edge triggered interrupt. It would have to be pretty compelling to warrant the additional complexity I think.
vmcall costs will go down, and we don't want to use different mechanisms for high bandwidth and low bandwidth devices.
Quoted 7 lines
vmcalls will certainly get faster but I doubt that the cost difference between vmcall and pio will ever be greater than a few hundred cycles. The only performance sensitive operation here would be the kick and I don't think a few hundred cycles in the kick path is ever going to be that significant for overall performance.
Why do you think the different will be a few hundred cycles? And if you have a large number of devices, searching the list becomes expensive too.
Quoted 2 lines
So why introduce the extra complexity?
Overall I think it reduces comlexity if we have in-kernel devices. Anyway we can add additional signalling methods later.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 473328EC.4090905-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 10 lines · Avi Kivity
Quoted 7 lines
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the
pci_mapfunction in QEMU to just notify the kernel that it should listen on a particular PIO range.This is a config space write, right? If so, the range is the regular 0xcf8-0xcff and it has to be very specially handled.
This is a per-device IO slot and as best as I can tell, the PCI device advertises the size of the region and the OS then identifies a range of PIO space to use and tells the PCI device about it. So we would just need to implement a generic userspace virtio PCI device in QEMU that did an ioctl to the kernel when this happened to tell the kernel what region to listen on for a particular device.
Quoted 9 lines
Quoted 7 lines
vmcalls will certainly get faster but I doubt that the cost difference between vmcall and pio will ever be greater than a few hundred cycles. The only performance sensitive operation here would be the kick and I don't think a few hundred cycles in the kick path is ever going to be that significant for overall performance.
Why do you think the different will be a few hundred cycles?
The only difference in hardware between a PIO exit and a vmcall is that you don't have write out an exit reason in the VMC[SB]. So the performance difference between PIO/vmcall shouldn't be that great (and if it were, the difference would probably be obvious today). That's different from, say, a PF exit because with a PF, you also have to attempt to resolve it by walking the guest page table before determining that you do in fact need to exit.
Quoted 2 lines
And if you have a large number of devices, searching the list
becomes expensive too.
The PIO address space is relatively small. You could do a radix tree or even a direct array lookup if you are concerned about performance.
Quoted 5 lines
Quoted 2 lines
So why introduce the extra complexity?
Overall I think it reduces comlexity if we have in-kernel devices. Anyway we can add additional signalling methods later.
In-kernel virtio backends add quite a lot of complexity. Just the mechanism to setup the device is complicated enough. I suspect that it'll be necessary down the road for performance but I certainly don't think it's a simplification.
Regards,
Anthony Liguori
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 473337B9.8040503-r/[email protected]
Quoted 29 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity
Quoted 4 lines
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the
pci_mapfunction in QEMU to just notify the kernel that it should listen on a particular PIO range.This is a config space write, right? If so, the range is the regular 0xcf8-0xcff and it has to be very specially handled.
This is a per-device IO slot and as best as I can tell, the PCI device advertises the size of the region and the OS then identifies a range of PIO space to use and tells the PCI device about it. So we would just need to implement a generic userspace virtio PCI device in QEMU that did an ioctl to the kernel when this happened to tell the kernel what region to listen on for a particular device.
Quoted 6 lines
Quoted 4 lines
vmcalls will certainly get faster but I doubt that the cost difference between vmcall and pio will ever be greater than a few hundred cycles. The only performance sensitive operation here would be the kick and I don't think a few hundred cycles in the kick path is ever going to be that significant for overall performance.
Why do you think the different will be a few hundred cycles?
The only difference in hardware between a PIO exit and a vmcall is that you don't have write out an exit reason in the VMC[SB]. So the performance difference between PIO/vmcall shouldn't be that great (and if it were, the difference would probably be obvious today). That's different from, say, a PF exit because with a PF, you also have to attempt to resolve it by walking the guest page table before determining that you do in fact need to exit.
Quoted 3 lines
And if you have a large number of devices, searching the list
becomes expensive too.The PIO address space is relatively small. You could do a radix tree or even a direct array lookup if you are concerned about performance.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
So why introduce the extra complexity?
Overall I think it reduces comlexity if we have in-kernel devices. Anyway we can add additional signalling methods later.
In-kernel virtio backends add quite a lot of complexity. Just the mechanism to setup the device is complicated enough. I suspect that it'll be necessary down the road for performance but I certainly don't think it's a simplification.
I believe that the network interface will quickly go to the kernel since copy takes most of the cpu time and qemu does not support scatter gather dma at the moment.
Nevertheless using pio seems good enough, Anthony's suggestion of notifying the kernel using ioctls is logical. If we'll run into troubles further on we can add a hypercall capability and if exist use hypercalls instead of pios.
Quoted 5 lines
Regards,
Anthony Liguori
Quoted 11 lines
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 4733A635.1080004-atKUWr5tajBWk0Htik3J/[email protected]
Am Freitag, 9. November 2007 schrieb Dor Laor:
Quoted 8 lines
I believe that the network interface will quickly go to the kernel since copy takes most of the
cpu time and qemu does not support scatter gather dma at the moment. Nevertheless using pio seems good enough, Anthony's suggestion of notifying the kernel using ioctls
is logical. If we'll run into troubles further on we can add a hypercall capability and if exist use hypercalls
instead of pios.
Sorry for being late in this thread.
We (s390) will need a hypercall as we do not have port I/O. I think it should be possible to default to hypercall on s390 and use pio everywhere else.
Christian
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
A message that is not in the archive (sent off-list or not yet received): 200711200939.19410.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org
Quoted 12 lines · Christian Borntraeger
Am Freitag, 9. November 2007 schrieb Dor Laor:
Quoted 9 lines
I believe that the network interface will quickly go to the kernel since copy takes most of the
cpu time and qemu does not support scatter gather dma at the moment. Nevertheless using pio seems good enough, Anthony's suggestion of notifying the kernel using ioctls
is logical. If we'll run into troubles further on we can add a hypercall capability and if exist use hypercalls
instead of pios.
Quoted 4 lines
Sorry for being late in this thread.
We (s390) will need a hypercall as we do not have port I/O. I think it should be possible to default to hypercall on s390 and use pio everywhere else.
Or be generic: advertise the methods available according to host (kvm/x86, qemu/x86, kvm/s390) and let the guest pick.
Signature · 7 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
A message that is not in the archive (sent off-list or not yet received): 4742B053.8080301-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 9 lines · Avi Kivity
Quoted 6 lines
Sorry for being late in this thread.
We (s390) will need a hypercall as we do not have port I/O. I think it should be possible to default to hypercall on s390 and use pio everywhere else.Or be generic: advertise the methods available according to host (kvm/x86, qemu/x86, kvm/s390) and let the guest pick.
Not sure if I'm following the reasoning here. Shouldn't the method be inherent to the virtio bus driver?
When you use a PCI based virtio bus, the natural choice would be PIO in some way, but you could also have a different virtio implementation on PCI that uses hcalls. This choice is completely up to virtio-pci.
On s390, you have a different virtio backend altogether, so you always use DIAG or hcall instead of whatever virtio-pci does.
The virtio-blk and other high-level drivers don't need to care about what transport the bus uses in the first place.
Arnd <><
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Arnd Bergmann
Not sure if I'm following the reasoning here. Shouldn't the method be inherent to the virtio bus driver?
When you use a PCI based virtio bus, the natural choice would be PIO in some way, but you could also have a different virtio implementation on PCI that uses hcalls. This choice is completely up to virtio-pci.
Quoted 5 lines
On s390, you have a different virtio backend altogether, so you always use DIAG or hcall instead of whatever virtio-pci does.
The virtio-blk and other high-level drivers don't need to care about what transport the bus uses in the first place.
If you look at HPA's virtio PCI bus in lguest, it uses PCI device organization but no other PCI features. That's where we're heading, because we don't want a different virtio backend.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 12 lines · Anthony Liguori
Quoted 10 lines · Avi Kivity
Quoted 7 lines
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the
pci_mapfunction in QEMU to just notify the kernel that it should listen on a particular PIO range.This is a config space write, right? If so, the range is the regular 0xcf8-0xcff and it has to be very specially handled.
Quoted 7 lines
This is a per-device IO slot and as best as I can tell, the PCI device advertises the size of the region and the OS then identifies a range of PIO space to use and tells the PCI device about it. So we would just need to implement a generic userspace virtio PCI device in QEMU that did an ioctl to the kernel when this happened to tell the kernel what region to listen on for a particular device.
I'll just go and read the patches more carefully before making any more stupid remarks about the code.
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
vmcalls will certainly get faster but I doubt that the cost difference between vmcall and pio will ever be greater than a few hundred cycles. The only performance sensitive operation here would be the kick and I don't think a few hundred cycles in the kick path is ever going to be that significant for overall performance.
Why do you think the different will be a few hundred cycles?
Quoted 8 lines
The only difference in hardware between a PIO exit and a vmcall is that you don't have write out an exit reason in the VMC[SB]. So the performance difference between PIO/vmcall shouldn't be that great (and if it were, the difference would probably be obvious today). That's different from, say, a PF exit because with a PF, you also have to attempt to resolve it by walking the guest page table before determining that you do in fact need to exit.
You have to look at the pio bitmaps with pio. Point taken though.
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
So why introduce the extra complexity?
Overall I think it reduces comlexity if we have in-kernel devices. Anyway we can add additional signalling methods later.
In-kernel virtio backends add quite a lot of complexity. Just the mechanism to setup the device is complicated enough. I suspect that it'll be necessary down the road for performance but I certainly don't think it's a simplification.
I didn't mean that in-kernel devices simplify things (they don't), but that using hypercalls is simpler for in-kernel than pio.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
Quoted 18 lines · Anthony Liguori
Quoted 18 lines
Quoted 17 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +4
-0+ case VIRTIO_PCI_QUEUE_NOTIFY: + if (val < VIRTIO_PCI_QUEUE_MAX) + virtio_ring_kick(vdev, &vdev->vq[val]); + break;I see you're not using hypercalls for this, presumably for compatibility
with -no-kvm.More than just that. By stick to PIO, we are compatible with just about any VMM. For instance, we get Xen support for free. If we used hypercalls, even if we agreed on a way to determine which number to use and how to make those calls, it would still be difficult to implement in something like Xen.
Quoted 8 lines
Quoted 2 lines
But pio through the config space basically means you're committed to handling it in qemu. We want a more flexible mechanism.
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the
pci_mapfunction in QEMU to just notify the kernel that it should listen on a particular PIO range.
With my new understanding of what this is all about, I suggest each virtqueue having an ID filled in by the host. This ID is globally unique, and is used as an argument for kick. It would map into a Xen domain id + event channel number, a number to be written into a pio port for kvm-lite or non-hypercall kvm, the argument for a kick hypercall on kvm, or whatever.
This is independent of virtio-pci, which is good.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 47332BB7.2000900-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 28 lines · Avi Kivity
Quoted 18 lines · Anthony Liguori
Quoted 18 lines
Quoted 17 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +4
-0+ case VIRTIO_PCI_QUEUE_NOTIFY: + if (val < VIRTIO_PCI_QUEUE_MAX) + virtio_ring_kick(vdev, &vdev->vq[val]); + break;I see you're not using hypercalls for this, presumably for compatibility
with -no-kvm.More than just that. By stick to PIO, we are compatible with just about any VMM. For instance, we get Xen support for free. If we used hypercalls, even if we agreed on a way to determine which number to use and how to make those calls, it would still be difficult to implement in something like Xen.
Quoted 8 lines
Quoted 2 lines
But pio through the config space basically means you're committed to handling it in qemu. We want a more flexible mechanism.
There's no reason that the PIO operations couldn't be handled in the kernel. You'll already need some level of cooperation in userspace unless you plan on implementing the PCI bus in kernel space too. It's easy enough in the
pci_mapfunction in QEMU to just notify the kernel that it should listen on a particular PIO range.
Quoted 6 lines
With my new understanding of what this is all about, I suggest each virtqueue having an ID filled in by the host. This ID is globally unique, and is used as an argument for kick. It would map into a Xen domain id + event channel number, a number to be written into a pio port for kvm-lite or non-hypercall kvm, the argument for a kick hypercall on kvm, or whatever.
Yeah, right now, I maintain a virtqueue "selector" within virtio-pci and use that for notification. This index is also exposed in the config->find_vq() within virtio. Changing that to an opaque ID would require introducing another mechanism to enumerate the virtqueues since you couldn't just start from 0 and keep going until you hit an invalid virtqueue.
I'm not sure I'm convinced that you couldn't just hide this "id" notion in the virtio-xen implementation if you needed to.
Regards,
Anthony Liguori
Quoted 2 lines
This is independent of virtio-pci, which is good.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
qemu/Makefile.target
Quoted 8 lines · Anthony Liguori
This still needs quite a lot of work but I wanted to post it for reference.
Regards,
Anthony Liguori
qemu/Makefile.target +0
-0
...
Why change Rusty's codding standard? It will be harder to track changes.
Quoted 36 lines
qemu/Makefile.target +36
-0+typedef struct VRingDesc +{ + uint64_t addr; + uint32_t len; + uint16_t flags; + uint16_t next; +} VRingDesc; + +typedef struct VRingAvail +{ + uint16_t flags; + uint16_t idx; + uint16_t ring[0]; +} VRingAvail; + +typedef struct VRingUsedElem +{ + uint32_t id; + uint32_t len; +} VRingUsedElem; + +typedef struct VRingUsed +{ + uint16_t flags; + uint16_t idx; + VRingUsedElem ring[0]; +} VRingUsed; + +typedef struct VRing +{ + unsigned int num; + VRingDesc *desc; + VRingAvail *avail; + VRingUsed *used; +} VRing; +
....
Quoted 7 lines
qemu/Makefile.target +6
-0+static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) +{ + VirtIODevice *vdev = to_virtio_device(opaque); + ram_addr_t pa; + + addr -= vdev->addr;
qemu/Makefile.target
Quoted 10 lines
qemu/Makefile.target +10
-0+ + switch (addr) { + case VIRTIO_PCI_GUEST_FEATURES: + if (vdev->set_features) + vdev->set_features(vdev->opaque, val); + vdev->features = val; + break; + case VIRTIO_PCI_QUEUE_PFN: + pa = (ram_addr_t)val << TARGET_PAGE_BITS; + vdev->vq[vdev->queue_sel].pfn = val;
Some validity checks are missing, you assume you have the queue_sel.
Quoted 4 lines
qemu/Makefile.target +3
-0+ if (pa < (ram_size - TARGET_PAGE_SIZE)) + vring_init(&vdev->vq[vdev->queue_sel], phys_ram_base + pa); + break;
qemu/Makefile.target
Quoted 10 lines
qemu/Makefile.target +10
-0+ case VIRTIO_PCI_QUEUE_SEL: + if (val < VIRTIO_PCI_QUEUE_MAX) + vdev->queue_sel = val; + break; + case VIRTIO_PCI_QUEUE_NOTIFY: + if (val < VIRTIO_PCI_QUEUE_MAX) + virtio_ring_kick(vdev, &vdev->vq[val]); + break; + case VIRTIO_PCI_STATUS: + vdev->status = val & 0xFF;
we should keep another internal status and it will track the initialization of all the above fields (
pfn, queue_sel,..) the device will be active once all of them were initialized by the guest
qemu/Makefile.target
Quoted 9 lines
qemu/Makefile.target +8
-0+ break; + default: + if (addr >= VIRTIO_PCI_CONFIG && vdev->set_config) + vdev->set_config(vdev->opaque, addr - VIRTIO_PCI_CONFIG, val); + break; + } +} +
What about having block/net/9p.. in separate files? It will grow over time.
qemu/Makefile.target
Quoted 13 lines
qemu/Makefile.target +13
-0+#include <linux/virtio_blk.h> +#include <stdbool.h> + +#define BLK_MAX_QUEUE_SIZE 127 + +static bool virtio_blk_handle_request(BlockDriverState *bs, + VirtIODevice *vdev, VirtQueue *vq) +{ + struct iovec iov[vq->vring.num]; + unsigned int head, out_num, in_num, wlen; + struct virtio_blk_inhdr *in; + struct virtio_blk_outhdr *out; +
Great job, Dor.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 4733A917.5000303-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 4 lines · Dor Laor
Quoted 3 lines · Anthony Liguori
This still needs quite a lot of work but I wanted to post it for reference.
Quoted 8 lines
qemu/Makefile.target
Quoted 6 lines
Regards,
Anthony Liguori
qemu/Makefile.target +0
-0...
Why change Rusty's codding standard? It will be harder to track changes.
Because Linux kernel coding standards aren't QEMU coding standards. Besides, this is supposed to be an ABI so it shouldn't be changing all that much :-)
I posted the QEMU bits as soon as I got it working. I still have a lot to do in it however I have addressed some of the things you brought up already.
Quoted 5 lines
qemu/Makefile.target
Quoted 4 lines
qemu/Makefile.target +3
-0+ case VIRTIO_PCI_QUEUE_PFN: + pa = (ram_addr_t)val << TARGET_PAGE_BITS; + vdev->vq[vdev->queue_sel].pfn = val;Some validity checks are missing, you assume you have the
queue_sel.
Yes, the code is carefully written so that queue_sel is always valid.
Quoted 14 lines
Quoted 4 lines
qemu/Makefile.target +3
-0+ if (pa < (ram_size - TARGET_PAGE_SIZE)) + vring_init(&vdev->vq[vdev->queue_sel], phys_ram_base + pa); + break;qemu/Makefile.target
Quoted 10 lines
qemu/Makefile.target +10
-0+ case VIRTIO_PCI_QUEUE_SEL: + if (val < VIRTIO_PCI_QUEUE_MAX) + vdev->queue_sel = val; + break; + case VIRTIO_PCI_QUEUE_NOTIFY: + if (val < VIRTIO_PCI_QUEUE_MAX) + virtio_ring_kick(vdev, &vdev->vq[val]); + break; + case VIRTIO_PCI_STATUS: + vdev->status = val & 0xFF;
Quoted 4 lines
we should keep another internal status and it will track the initialization of all the above fields (
pfn,queue_sel,..) the device will be active once all of them were initialized by the guest
Hrm, I don't follow. The only thing that has to be written to by the guest is the PFN which also has the effect of activating the queue.
Quoted 4 lines
Quoted 4 lines
qemu/Makefile.target +4
-0+ break; + default: + if (addr >= VIRTIO_PCI_CONFIG && vdev->set_config) + vdev->set_config(vdev->opaque, addr - VIRTIO_PCI_CONFIG, val);
Quoted 8 lines
qemu/Makefile.target
Quoted 5 lines
qemu/Makefile.target +4
-0+ break; + } +} +What about having
block/net/9p.. in separate files? It will grow over time.
Yup, already have that in my own queue.
The latest version queue for the kernel side is at
http://hg.codemonkey.ws/virtio-pci (based on the master branch of Rusty's virtio tree). The latest queue for the QEMU side is at
http://hg.codemonkey.ws/qemu-virtio. I have a functioning block and 9p transport. I'll continue cleaning up tomorrow and will hopefully post another set of patches early next week.
Unfortunately, I uncovered a bug in the in-kernel APIC code today so you need to run with -no-kvm-irqchip if you want to use multiple virtio devices at once :-/
Regards,
Anthony Liguori
Quoted 6 lines
Quoted 6 lines
qemu/Makefile.target +6
-0+#include <linux/virtio_blk.h> +#include <stdbool.h> + +#define BLK_MAX_QUEUE_SIZE 127 + +static bool virtio_blk_handle_request(BlockDriverState *bs,
Quoted 8 lines
qemu/Makefile.target
Quoted 7 lines
qemu/Makefile.target +7
-0+ VirtIODevice *vdev, VirtQueue *vq) +{ + struct iovec iov[vq->vring.num]; + unsigned int head, out_num, in_num, wlen; + struct virtio_blk_inhdr *in; + struct virtio_blk_outhdr *out; +Great job, Dor.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/