mm: export use_mm/unuse_mm to modules
Subsystems (11)
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 2 lines · Avi Kivity
Example: feature negotiation. If it happens in userspace, it's easy to limit what features we expose to the guest. If it happens in the kernel, we need to add an interface to let the kernel know which features it should expose to the guest. We also need to add an interface to let userspace know which features were negotiated, if we want to implement live migration. Something fairly trivial bloats rapidly.
btw, we have this issue with kvm reporting cpuid bits to the guest. Instead of letting kvm talk directly to the hardware and the guest, kvm gets the cpuid bits from the hardware, strips away features it doesn't support, exposes that to userspace, and expects userspace to program the cpuid bits it wants to expose to the guest (which may be different than what kvm exposed to userspace, and different from guest to guest).
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 8 lines · Avi Kivity
Example: feature negotiation. If it happens in userspace, it's easy to limit what features we expose to the guest. If it happens in the kernel, we need to add an interface to let the kernel know which features it should expose to the guest. We also need to add an interface to let userspace know which features were negotiated, if we want to implement live migration. Something fairly trivial bloats rapidly.
btw, we have this issue with kvm reporting cpuid bits to the guest. Instead of letting kvm talk directly to the hardware and the guest, kvm gets the cpuid bits from the hardware, strips away features it doesn't support, exposes that to userspace, and expects userspace to program the cpuid bits it wants to expose to the guest (which may be different than what kvm exposed to userspace, and different from guest to guest).
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 23 lines · Avi Kivity
Quoted 14 lines · Gregory Haskins
Quoted 14 lines
Quoted 14 lines
There are various aspects about designing high-performance virtual devices such as providing the shortest paths possible between the physical resources and the consumers. Conversely, we also need to ensure that we meet proper isolation/protection guarantees at the same time. What this means is there are various aspects to any high-performance PV design that require to be placed in-kernel to maximize the performance yet properly isolate the guest.
For instance, you are required to have your signal-path (interrupts and hypercalls), your memory-path (gpa translation), and addressing/isolation model in-kernel to maximize performance.
Quoted 7 lines
Quoted 2 lines
Exactly. That's what vhost puts into the kernel and nothing more.
Actually, no. Generally, _KVM_ puts those things into the kernel, and vhost consumes them. Without KVM (or something equivalent), vhost is incomplete. One of my goals with vbus is to generalize the "something equivalent" part here.
Quoted 6 lines
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
Going back to our stack diagrams, you could think of a vhost solution like this:
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| ? undefined-1 ?
--------------------------
| vhost
--------------------------
and you could think of a vbus solution like this
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| bus-interface
--------------------------
| ? undefined-2 ?
--------------------------
| bus-model
--------------------------
| virtio-net-device (vhost ported to vbus model? :)
--------------------------
So the difference between vhost and vbus in this particular context is that you need to have "undefined-1" do device discovery/hotswap, config-space, address-decode/isolation, signal-path routing, memory-path routing, etc. Today this function is filled by things like virtio-pci, pci-bus, KVM/ioeventfd, and QEMU for x86. I am not as familiar with lguest, but presumably it is filled there by components like virtio-lguest, lguest-bus, lguest.ko, and lguest-launcher. And to use more contemporary examples, we might have virtio-domino, domino-bus, domino.ko, and domino-launcher as well as virtio-ira, ira-bus, ira.ko, and ira-launcher.
Contrast this to the vbus stack: The bus-X components (when optionally employed by the connector designer) do device-discovery, hotswap, config-space, address-decode/isolation, signal-path and memory-path routing, etc in a general (and pv-centric) way. The "undefined-2" portion is the "connector", and just needs to convey messages like "DEVCALL" and "SHMSIGNAL". The rest is handled in other parts of the stack.
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack. And, as eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
Vbus accomplishes its in-kernel isolation model by providing a "container" concept, where objects are placed into this container by userspace. The host kernel enforces isolation/protection by using a namespace to identify objects that is only relevant within a specific container's context (namely, a "u32 dev-id"). The guest addresses the objects by its dev-id, and the kernel ensures that the guest can't access objects outside of its dev-id namespace.
vhost manages to accomplish this without any kernel support.
Quoted 7 lines
Quoted 4 lines
No, vhost manages to accomplish this because of KVMs kernel support
(ioeventfd, etc). Without a KVM-like in-kernel support, vhost is a
merely a kind of "tuntap"-like clone signalled by eventfds.Without a vbus-connector-falling-dominos, vbus-venet can't do anything either.
Mostly covered above...
However, I was addressing your assertion that vhost somehow magically accomplishes this "container/addressing" function without any specific kernel support. This is incorrect. I contend that this kernel support is required and present. The difference is that its defined elsewhere (and typically in a transport/arch specific way).
IOW: You can basically think of the programmed PIO addresses as forming its "container". Only addresses explicitly added are visible, and everything else is inaccessible. This whole discussion is merely a question of what's been generalized verses what needs to be re-implemented each time.
Quoted 1 line
Both vhost and vbus need an interface,
Agreed
Quoted 1 line
vhost's is just narrower since it doesn't do configuration or enumeration.
I would say that makes vhost solution's interface wider, not narrower. With the vbus kvm-connector, simple vbus device instantiation implicitly registers it in the address/enumeration namespace, and transmits a devadd event. It does all that with no more interface complexity than instantiating a vhost device. However, vhost has to then also separately configure its address/enumeration space with other subsystems (e.g. pci, ioeventfd, msi, etc), and define its config-space twice.
This means something in userspace has to proxy and/or refactor requests.
This also means that the userspace component has to have some knowledge
of _how_ to proxy/refactor said requests (i.e. splitting the design), which is another example of where the current vhost model really falls apart IMO.
Quoted 10 lines
Quoted 7 lines
This goes directly to my rebuttal of your claim that vbus places too much in the kernel. I state that, one way or the other, address decode and isolation _must_ be in the kernel for performance. Vbus does this with a devid/container scheme. vhost+virtio-pci+kvm does it with pci+pio+ioeventfd.
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
That is not correct. vbus does its own native address decoding in the fast path, such as here:
The connector delivers a SHMSIGNAL(id) message, and its decoded generically by an rcu protected radix tree.
I think what you are thinking of is that my KVM-connector in AlacrityVM uses PIO/ioeventfd (*) as part of its transport to deliver that SHMSIGNAL message. In this sense, I am doing two address-decodes (one for the initial pio, one for the subsequent shmsignal), but this is an implementation detail of the KVM connector.
(Also note that its an implementation detail that the KVM maintainer forced me into ;) The original vbus design utilized a global hypercall in place of the PIO, and thus the shmsignal was the only real decode occurring)
(*) actually I dropped ioeventfd in my latest tree, but this is a separate topic. I still use KVM's pio-bus, however.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
The guest
simply has not access to any vhost resources other than theguest->hostdoorbell, which is handed to the guest outside vhost (so it's somebody else's problem, in userspace).You mean _controlled_ by userspace, right? Obviously, the other side of the kernel still needs to be programmed (ioeventfd, etc). Otherwise, vhost would be pointless: e.g. just use vanilla tuntap if you don't need fast in-kernel decoding.
Quoted 3 lines
Yes (though for something like level-triggered interrupts we're probably keeping it in userspace, enjoying the benefits of vhost data path while paying more for signalling).
Thats fine. I am primarily interested in the high-performance IO, so low-perf/legacy components can fall back to something else like userspace if that best serves them.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
All that is required is a way to transport a message with a "devid" attribute as an address (such as DEVCALL(devid)) and the framework provides the rest of the decode+execute function.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
vhost avoids that.
No, it doesn't avoid it. It just doesn't specify how its done, and relies on something else to do it on its behalf.
That someone else can be in userspace, apart from the actual fast path.
No, this "devcall" like decoding _is_ fast path and it can't be in userspace if you care about performance. And if you don't care about performance, you can use existing facilities (like QEMU+tuntap) so vhost and vbus alike would become unnecessary in that scenario.
Quoted 10 lines
Quoted 5 lines
Conversely, vbus specifies how its done, but not how to transport the verb "across the wire". That is the role of the vbus-connector abstraction.
So again, vbus does everything in the kernel (since it's so easy and cheap) but expects a vbus-connector. vhost does configuration in userspace (since it's so clunky and fragile) but expects a couple of eventfds.
Well, we are talking about fast-path here, so I am not sure why config-space is coming up in this context. I digress. I realize you are being sarcastic, but your easy+cheap/clunky+fragile assessment is more accurate than you perhaps realize.
You keep extolling that vhost does most things in userspace and that is an advantage. But the simple fact is that they both functionally do almost the same amount in-kernel, because they _have_ to. This includes the obvious stuff like signal and memory routing, but also the less obvious stuff like most of config-space. Ultimately, most of config-space needs to terminate at the device-model (the one exception is perhaps "read-only attributes", like "MACQUERY"). Therefore, even if you use a vhost like model, most of your parameters will invariably be a translation from one config space to another and passed on (e.g. pci config-cycle to ioctl()).
The disparity of in-kernel vs userspace functionality that remains between the two implementations are basically the enumeration/hotswap and read-only attribute functions. These functions are prohibitively complex in the vhost+virtio-pci+kvm model (full ICH/pci chipset emulation, etc), so I understand why we wouldnt want to move those in-kernel. However, vbus was designed from scratch specifically for PV to be flexible and simple. As a result, the remaining functions in the kvm-connector take advantage of this simplicity and just ride on the existing model that we needed for fast-path anyway. What this means is there are of no significant consequence to do these few minor details in-kernel, other than this long discussion.
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Contrast this to vhost+virtio-pci (called simply "vhost" from here).
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It's the wrong name. vhost implements only the data path.
Understood, but vhost+virtio-pci is what I am contrasting, and I use "vhost" for short from that point on because I am too lazy to type the whole name over and over ;)
If you #define A A+B+C don't expect intelligent conversation afterwards.
Fair enough, but I did attempt to declare the definition before using it. Sorry again for the confusion.
Quoted 26 lines
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
It is not immune to requiring in-kernel addressing support either, but rather it just does it differently (and its not as you might expect via qemu).
Quoted 8 lines
Quoted 4 lines
Vhost relies on QEMU to render PCI objects to the guest, which the guest
assigns resources (such as BARs, interrupts, etc).vhost does not rely on qemu. It relies on its user to handle configuration. In one important case it's qemu+pci. It could just as well be the lguest launcher.
I meant vhost=vhost+virtio-pci here. Sorry for the confusion.
The point I am making specifically is that vhost in general relies on other in-kernel components to function. I.e. It cannot function without having something like the PCI model to build an IO namespace. That namespace (in this case, pio addresses+data tuples) are used for the in-kernel addressing function under KVM + virtio-pci.
The case of the lguest launcher is a good one to highlight. Yes, you can presumably also use lguest with vhost, if the requisite facilities are exposed to lguest-bus, and some eventfd based thing like ioeventfd is written for the host (if it doesnt exist already).
Quoted 6 lines
Quoted 3 lines
And when the next virt design "foo" comes out, it can make a "foo-bus" model, and implement foo-eventfd on the backend, etc, etc.
It's exactly the same with vbus needing additional connectors for additional transports.
No, see my reply above.
Quoted 7 lines
Quoted 5 lines
Ira can make ira-bus, and ira-eventfd, etc, etc.
Each iteration will invariably introduce duplicated parts of the stack.
Invariably?
As in "always"
Quoted 1 line
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
For the N+1th time, no. vhost is perfectly usable without pci. Can we stop raising and debunking this point?
Quoted 7 lines
Again, I understand vhost is decoupled from PCI, and I don't mean to imply anything different. I use PCI as an example here because a) its the only working example of vhost today (to my knowledge), and b) you have stated in the past that PCI is the only "right" way here, to paraphrase. Perhaps you no longer feel that way, so I apologize if you feel you already recanted your position on PCI and I missed it.
Quoted 1 line
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 10 lines
I was talking about the two
lguest users and Ira.Quoted 6 lines
I digress. My point here isn't PCI. The point here is the missing component for when PCI is not present. The component that is partially satisfied by vbus's devid addressing scheme. If you are going to use vhost, and you don't have PCI, you've gotta build something to replace it.
Quoted 3 lines
Yes, that's why people have keyboards. They'll write that glue code if they need it. If it turns out to be a hit an people start having virtio transport module writing parties, they'll figure out a way to share code.
Sigh... The party has already started. I tried to invite you months ago...
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
All you really need is a simple decode+execute mechanism, and a way to program it from userspace control. vbus tries to do just that:
commoditize it so all you need is the transport of the control messages (likeDEVCALL()), but the decode+execute itself is reuseable, even across various environments (like KVM or Iras rig).If you think it should be "commodotized", write libvhostconfig.so.
Quoted 8 lines
Quoted 3 lines
I know you are probably being facetious here, but what do you propose for the parts that must be in-kernel?
On the guest side, virtio-shmem.ko can unify the ring access. It probably makes sense even today. On the host side I eventfd is the kernel interface and libvhostconfig.so can provide the configuration when an existing ABI is not imposed.
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 7 lines
And your argument, I believe, is that vbus allows both to be implemented
in the kernel (though to reiterate, its optional) and is therefore a bad
design, so lets discuss that.Quoted 11 lines
I believe the assertion is that things like config-space are best left to userspace, and we should only relegate fast-path duties to the kernel. The problem is that, in my experience, a good deal of config-space actually influences the fast-path and thus needs to interact with the fast-path mechanism eventually anyway. Whats left
over that doesn't fall into this category may cheaply ride on existing plumbing, so its not like we created something new or unnatural just to support this subclass of config-space.Flexibility is reduced, because changing code in the kernel is more expensive than in userspace, and kernel/user interfaces aren't typically as wide as pure userspace interfaces. Security is reduced, since a bug in the kernel affects the host, while a bug in userspace affects just on guest.
Quoted 7 lines
Quoted 4 lines
For a mac-address attribute? Thats all we are really talking about here. These points you raise, while true of any kernel code I suppose, are a bit of a stretch in this context.
Look at the virtio-net feature negotiation. There's a lot more there than the MAC address, and it's going to grow.
Agreed, but note that makes my point. That feature negotiation almost invariably influences the device-model, not some config-space shim.
IOW: terminating config-space at some userspace shim is pointless. The model ultimately needs the result of whatever transpires during that negotiation anyway.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Example: feature negotiation. If it happens in userspace, it's easy to limit what features we expose to the guest.
Its not any harder in the kernel. I do this today.
Quoted 8 lines
Quoted 5 lines
And when you are done negotiating said features, you will generally have to turn around and program the feature into the backend anyway (e.g.
ioctl()to vhost module). Now you have to maintain some knowledge of that particular feature and how to program it in two places.No, you can leave it enabled unconditionally in vhost (the guest won't use what it doesn't know about).
Perhaps, but IMO sending a "feature-mask"-like object down is far easier then proxying/refactoring config-space and sending that down. I'd still chalk the win here to the vbus model used in AlacrityVM.
FWIW: venet has the ability to enable/disable features on the host side, so clearly userspace config-space is not required for the basic premise.
Quoted 7 lines
Quoted 5 lines
Conversely, I am eliminating the (unnecessary) middleman by letting the feature negotiating take place directly between the two entities that will consume it.
The middleman is necessary, if you want to support live migration
Orchestrating live-migration has nothing to do with whether config-space is serviced by a middle-man or not. It shouldn't be required to have device-specific knowledge at all beyond what was initially needed to create/config the object at boot time.
IOW, the orchestrator merely needs to know that a device-model object is present and a method to serialize and reconstitute its state (if appropriate).
, or to
Quoted 1 line
restrict a guest to a subset of your features.
No, that is incorrect. We are not talking about directly exposing something like HW cpuid here. These are all virtual models, and they can optionally expose as much or as little as we want. They do this under administrative control by userspace, and independent of the location of the config-space handler.
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
If it happens in the
kernel, we need to add an interface to let the kernel know which features it should expose to the guest.You need this already either way for both models anyway. As an added bonus, vbus has generalized that interface using sysfs attributes, so all models are handled in a similar and community accepted way.
vhost doesn't need it since userspace takes care of it.
Ok, but see my related reply above.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
We also need to add an
interface to let userspace know which features were negotiated, if we want to implement live migration. Something fairly trivial bloats rapidly.Can you elaborate on the requirements for live-migration? Wouldnt an opaque save/restore model work here? (e.g. why does userspace need to be able to interpret the in-kernel state, just pass it along as a blob to the new instance).
Quoted 3 lines
A blob would work, if you commit to forward and backward compatibility in the kernel side (i.e. an older kernel must be able to accept a blob from a newer one).
Thats understood and acceptable.
Quoted 1 line
I don't like blobs though, they tie you to the implemenetation.
What would you suggest otherwise?
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
As you can see above, userspace needs to be involved in this, and the number of interfaces required is smaller if it's in userspace:
Actually, no. My experience has been the opposite. Anytime I sat down and tried to satisfy your request to move things to the userspace, things got ugly and duplicative really quick. I suspect part of the reason you may think its easier because you already have part of virtio-net in userspace and its surrounding support, but that is not the case moving forward for new device types.
Quoted 2 lines
I can't comment on your experience, but we'll definitely build on existing code for new device types.
Fair enough. I'll build on my experience, either reusing existing code or implementing new designs where appropriate. If you or anyone else want to join me in my efforts, the more the merrier.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
you only
need to know which features the kernel supports (they can be enabled unconditionally, just not exposed).Further, some devices are perfectly happy to be implemented in userspace, so we need userspace configuration support anyway. Why reimplement it in the kernel?
Quoted 7 lines
Quoted 5 lines
Thats fine. vbus is targetted for high-performance IO. So if you have a robust userspace (like KVM+QEMU) and low-performance constraints (say, for a console or something), put it in userspace and vbus is not involved. I don't care.
So now the hypothetical non-pci hypervisor needs to support two busses.
No. The hypothetical hypervisor only needs to decide where low-performance devices should live. If that is best served by making/reusing a unique bus for them, I have no specific problem with that. Systems are typically composed of multiple buses anyway.
Conversely, there is nothing wrong with putting low-performance devices on a bus designed for high-performance either, and vbus can accommodate both types. The latter is what I would advocate for simplicity's sake, but its not a requirement.
Kind Regards,
-Greg
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 23 lines · Avi Kivity
Quoted 14 lines · Gregory Haskins
Quoted 14 lines
Quoted 14 lines
There are various aspects about designing high-performance virtual devices such as providing the shortest paths possible between the physical resources and the consumers. Conversely, we also need to ensure that we meet proper isolation/protection guarantees at the same time. What this means is there are various aspects to any high-performance PV design that require to be placed in-kernel to maximize the performance yet properly isolate the guest.
For instance, you are required to have your signal-path (interrupts and hypercalls), your memory-path (gpa translation), and addressing/isolation model in-kernel to maximize performance.
Quoted 7 lines
Quoted 2 lines
Exactly. That's what vhost puts into the kernel and nothing more.
Actually, no. Generally, _KVM_ puts those things into the kernel, and vhost consumes them. Without KVM (or something equivalent), vhost is incomplete. One of my goals with vbus is to generalize the "something equivalent" part here.
Quoted 6 lines
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
Going back to our stack diagrams, you could think of a vhost solution like this:
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| ? undefined-1 ?
--------------------------
| vhost
--------------------------
and you could think of a vbus solution like this
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| bus-interface
--------------------------
| ? undefined-2 ?
--------------------------
| bus-model
--------------------------
| virtio-net-device (vhost ported to vbus model? :)
--------------------------
So the difference between vhost and vbus in this particular context is that you need to have "undefined-1" do device discovery/hotswap, config-space, address-decode/isolation, signal-path routing, memory-path routing, etc. Today this function is filled by things like virtio-pci, pci-bus, KVM/ioeventfd, and QEMU for x86. I am not as familiar with lguest, but presumably it is filled there by components like virtio-lguest, lguest-bus, lguest.ko, and lguest-launcher. And to use more contemporary examples, we might have virtio-domino, domino-bus, domino.ko, and domino-launcher as well as virtio-ira, ira-bus, ira.ko, and ira-launcher.
Contrast this to the vbus stack: The bus-X components (when optionally employed by the connector designer) do device-discovery, hotswap, config-space, address-decode/isolation, signal-path and memory-path routing, etc in a general (and pv-centric) way. The "undefined-2" portion is the "connector", and just needs to convey messages like "DEVCALL" and "SHMSIGNAL". The rest is handled in other parts of the stack.
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack. And, as eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
Vbus accomplishes its in-kernel isolation model by providing a "container" concept, where objects are placed into this container by userspace. The host kernel enforces isolation/protection by using a namespace to identify objects that is only relevant within a specific container's context (namely, a "u32 dev-id"). The guest addresses the objects by its dev-id, and the kernel ensures that the guest can't access objects outside of its dev-id namespace.
vhost manages to accomplish this without any kernel support.
Quoted 7 lines
Quoted 4 lines
No, vhost manages to accomplish this because of KVMs kernel support
(ioeventfd, etc). Without a KVM-like in-kernel support, vhost is a
merely a kind of "tuntap"-like clone signalled by eventfds.Without a vbus-connector-falling-dominos, vbus-venet can't do anything either.
Mostly covered above...
However, I was addressing your assertion that vhost somehow magically accomplishes this "container/addressing" function without any specific kernel support. This is incorrect. I contend that this kernel support is required and present. The difference is that its defined elsewhere (and typically in a transport/arch specific way).
IOW: You can basically think of the programmed PIO addresses as forming its "container". Only addresses explicitly added are visible, and everything else is inaccessible. This whole discussion is merely a question of what's been generalized verses what needs to be re-implemented each time.
Quoted 1 line
Both vhost and vbus need an interface,
Agreed
Quoted 1 line
vhost's is just narrower since it doesn't do configuration or enumeration.
I would say that makes vhost solution's interface wider, not narrower. With the vbus kvm-connector, simple vbus device instantiation implicitly registers it in the address/enumeration namespace, and transmits a devadd event. It does all that with no more interface complexity than instantiating a vhost device. However, vhost has to then also separately configure its address/enumeration space with other subsystems (e.g. pci, ioeventfd, msi, etc), and define its config-space twice.
This means something in userspace has to proxy and/or refactor requests.
This also means that the userspace component has to have some knowledge
of _how_ to proxy/refactor said requests (i.e. splitting the design), which is another example of where the current vhost model really falls apart IMO.
Quoted 10 lines
Quoted 7 lines
This goes directly to my rebuttal of your claim that vbus places too much in the kernel. I state that, one way or the other, address decode and isolation _must_ be in the kernel for performance. Vbus does this with a devid/container scheme. vhost+virtio-pci+kvm does it with pci+pio+ioeventfd.
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
That is not correct. vbus does its own native address decoding in the fast path, such as here:
The connector delivers a SHMSIGNAL(id) message, and its decoded generically by an rcu protected radix tree.
I think what you are thinking of is that my KVM-connector in AlacrityVM uses PIO/ioeventfd (*) as part of its transport to deliver that SHMSIGNAL message. In this sense, I am doing two address-decodes (one for the initial pio, one for the subsequent shmsignal), but this is an implementation detail of the KVM connector.
(Also note that its an implementation detail that the KVM maintainer forced me into ;) The original vbus design utilized a global hypercall in place of the PIO, and thus the shmsignal was the only real decode occurring)
(*) actually I dropped ioeventfd in my latest tree, but this is a separate topic. I still use KVM's pio-bus, however.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
The guest
simply has not access to any vhost resources other than theguest->hostdoorbell, which is handed to the guest outside vhost (so it's somebody else's problem, in userspace).You mean _controlled_ by userspace, right? Obviously, the other side of the kernel still needs to be programmed (ioeventfd, etc). Otherwise, vhost would be pointless: e.g. just use vanilla tuntap if you don't need fast in-kernel decoding.
Quoted 3 lines
Yes (though for something like level-triggered interrupts we're probably keeping it in userspace, enjoying the benefits of vhost data path while paying more for signalling).
Thats fine. I am primarily interested in the high-performance IO, so low-perf/legacy components can fall back to something else like userspace if that best serves them.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
All that is required is a way to transport a message with a "devid" attribute as an address (such as DEVCALL(devid)) and the framework provides the rest of the decode+execute function.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
vhost avoids that.
No, it doesn't avoid it. It just doesn't specify how its done, and relies on something else to do it on its behalf.
That someone else can be in userspace, apart from the actual fast path.
No, this "devcall" like decoding _is_ fast path and it can't be in userspace if you care about performance. And if you don't care about performance, you can use existing facilities (like QEMU+tuntap) so vhost and vbus alike would become unnecessary in that scenario.
Quoted 10 lines
Quoted 5 lines
Conversely, vbus specifies how its done, but not how to transport the verb "across the wire". That is the role of the vbus-connector abstraction.
So again, vbus does everything in the kernel (since it's so easy and cheap) but expects a vbus-connector. vhost does configuration in userspace (since it's so clunky and fragile) but expects a couple of eventfds.
Well, we are talking about fast-path here, so I am not sure why config-space is coming up in this context. I digress. I realize you are being sarcastic, but your easy+cheap/clunky+fragile assessment is more accurate than you perhaps realize.
You keep extolling that vhost does most things in userspace and that is an advantage. But the simple fact is that they both functionally do almost the same amount in-kernel, because they _have_ to. This includes the obvious stuff like signal and memory routing, but also the less obvious stuff like most of config-space. Ultimately, most of config-space needs to terminate at the device-model (the one exception is perhaps "read-only attributes", like "MACQUERY"). Therefore, even if you use a vhost like model, most of your parameters will invariably be a translation from one config space to another and passed on (e.g. pci config-cycle to ioctl()).
The disparity of in-kernel vs userspace functionality that remains between the two implementations are basically the enumeration/hotswap and read-only attribute functions. These functions are prohibitively complex in the vhost+virtio-pci+kvm model (full ICH/pci chipset emulation, etc), so I understand why we wouldnt want to move those in-kernel. However, vbus was designed from scratch specifically for PV to be flexible and simple. As a result, the remaining functions in the kvm-connector take advantage of this simplicity and just ride on the existing model that we needed for fast-path anyway. What this means is there are of no significant consequence to do these few minor details in-kernel, other than this long discussion.
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Contrast this to vhost+virtio-pci (called simply "vhost" from here).
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It's the wrong name. vhost implements only the data path.
Understood, but vhost+virtio-pci is what I am contrasting, and I use "vhost" for short from that point on because I am too lazy to type the whole name over and over ;)
If you #define A A+B+C don't expect intelligent conversation afterwards.
Fair enough, but I did attempt to declare the definition before using it. Sorry again for the confusion.
Quoted 26 lines
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
It is not immune to requiring in-kernel addressing support either, but rather it just does it differently (and its not as you might expect via qemu).
Quoted 8 lines
Quoted 4 lines
Vhost relies on QEMU to render PCI objects to the guest, which the guest
assigns resources (such as BARs, interrupts, etc).vhost does not rely on qemu. It relies on its user to handle configuration. In one important case it's qemu+pci. It could just as well be the lguest launcher.
I meant vhost=vhost+virtio-pci here. Sorry for the confusion.
The point I am making specifically is that vhost in general relies on other in-kernel components to function. I.e. It cannot function without having something like the PCI model to build an IO namespace. That namespace (in this case, pio addresses+data tuples) are used for the in-kernel addressing function under KVM + virtio-pci.
The case of the lguest launcher is a good one to highlight. Yes, you can presumably also use lguest with vhost, if the requisite facilities are exposed to lguest-bus, and some eventfd based thing like ioeventfd is written for the host (if it doesnt exist already).
Quoted 6 lines
Quoted 3 lines
And when the next virt design "foo" comes out, it can make a "foo-bus" model, and implement foo-eventfd on the backend, etc, etc.
It's exactly the same with vbus needing additional connectors for additional transports.
No, see my reply above.
Quoted 7 lines
Quoted 5 lines
Ira can make ira-bus, and ira-eventfd, etc, etc.
Each iteration will invariably introduce duplicated parts of the stack.
Invariably?
As in "always"
Quoted 1 line
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
For the N+1th time, no. vhost is perfectly usable without pci. Can we stop raising and debunking this point?
Quoted 7 lines
Again, I understand vhost is decoupled from PCI, and I don't mean to imply anything different. I use PCI as an example here because a) its the only working example of vhost today (to my knowledge), and b) you have stated in the past that PCI is the only "right" way here, to paraphrase. Perhaps you no longer feel that way, so I apologize if you feel you already recanted your position on PCI and I missed it.
Quoted 1 line
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 10 lines
I was talking about the two
lguest users and Ira.Quoted 6 lines
I digress. My point here isn't PCI. The point here is the missing component for when PCI is not present. The component that is partially satisfied by vbus's devid addressing scheme. If you are going to use vhost, and you don't have PCI, you've gotta build something to replace it.
Quoted 3 lines
Yes, that's why people have keyboards. They'll write that glue code if they need it. If it turns out to be a hit an people start having virtio transport module writing parties, they'll figure out a way to share code.
Sigh... The party has already started. I tried to invite you months ago...
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
All you really need is a simple decode+execute mechanism, and a way to program it from userspace control. vbus tries to do just that:
commoditize it so all you need is the transport of the control messages (likeDEVCALL()), but the decode+execute itself is reuseable, even across various environments (like KVM or Iras rig).If you think it should be "commodotized", write libvhostconfig.so.
Quoted 8 lines
Quoted 3 lines
I know you are probably being facetious here, but what do you propose for the parts that must be in-kernel?
On the guest side, virtio-shmem.ko can unify the ring access. It probably makes sense even today. On the host side I eventfd is the kernel interface and libvhostconfig.so can provide the configuration when an existing ABI is not imposed.
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 7 lines
And your argument, I believe, is that vbus allows both to be implemented
in the kernel (though to reiterate, its optional) and is therefore a bad
design, so lets discuss that.Quoted 11 lines
I believe the assertion is that things like config-space are best left to userspace, and we should only relegate fast-path duties to the kernel. The problem is that, in my experience, a good deal of config-space actually influences the fast-path and thus needs to interact with the fast-path mechanism eventually anyway. Whats left
over that doesn't fall into this category may cheaply ride on existing plumbing, so its not like we created something new or unnatural just to support this subclass of config-space.Flexibility is reduced, because changing code in the kernel is more expensive than in userspace, and kernel/user interfaces aren't typically as wide as pure userspace interfaces. Security is reduced, since a bug in the kernel affects the host, while a bug in userspace affects just on guest.
Quoted 7 lines
Quoted 4 lines
For a mac-address attribute? Thats all we are really talking about here. These points you raise, while true of any kernel code I suppose, are a bit of a stretch in this context.
Look at the virtio-net feature negotiation. There's a lot more there than the MAC address, and it's going to grow.
Agreed, but note that makes my point. That feature negotiation almost invariably influences the device-model, not some config-space shim.
IOW: terminating config-space at some userspace shim is pointless. The model ultimately needs the result of whatever transpires during that negotiation anyway.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Example: feature negotiation. If it happens in userspace, it's easy to limit what features we expose to the guest.
Its not any harder in the kernel. I do this today.
Quoted 8 lines
Quoted 5 lines
And when you are done negotiating said features, you will generally have to turn around and program the feature into the backend anyway (e.g.
ioctl()to vhost module). Now you have to maintain some knowledge of that particular feature and how to program it in two places.No, you can leave it enabled unconditionally in vhost (the guest won't use what it doesn't know about).
Perhaps, but IMO sending a "feature-mask"-like object down is far easier then proxying/refactoring config-space and sending that down. I'd still chalk the win here to the vbus model used in AlacrityVM.
FWIW: venet has the ability to enable/disable features on the host side, so clearly userspace config-space is not required for the basic premise.
Quoted 7 lines
Quoted 5 lines
Conversely, I am eliminating the (unnecessary) middleman by letting the feature negotiating take place directly between the two entities that will consume it.
The middleman is necessary, if you want to support live migration
Orchestrating live-migration has nothing to do with whether config-space is serviced by a middle-man or not. It shouldn't be required to have device-specific knowledge at all beyond what was initially needed to create/config the object at boot time.
IOW, the orchestrator merely needs to know that a device-model object is present and a method to serialize and reconstitute its state (if appropriate).
, or to
Quoted 1 line
restrict a guest to a subset of your features.
No, that is incorrect. We are not talking about directly exposing something like HW cpuid here. These are all virtual models, and they can optionally expose as much or as little as we want. They do this under administrative control by userspace, and independent of the location of the config-space handler.
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
If it happens in the
kernel, we need to add an interface to let the kernel know which features it should expose to the guest.You need this already either way for both models anyway. As an added bonus, vbus has generalized that interface using sysfs attributes, so all models are handled in a similar and community accepted way.
vhost doesn't need it since userspace takes care of it.
Ok, but see my related reply above.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
We also need to add an
interface to let userspace know which features were negotiated, if we want to implement live migration. Something fairly trivial bloats rapidly.Can you elaborate on the requirements for live-migration? Wouldnt an opaque save/restore model work here? (e.g. why does userspace need to be able to interpret the in-kernel state, just pass it along as a blob to the new instance).
Quoted 3 lines
A blob would work, if you commit to forward and backward compatibility in the kernel side (i.e. an older kernel must be able to accept a blob from a newer one).
Thats understood and acceptable.
Quoted 1 line
I don't like blobs though, they tie you to the implemenetation.
What would you suggest otherwise?
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
As you can see above, userspace needs to be involved in this, and the number of interfaces required is smaller if it's in userspace:
Actually, no. My experience has been the opposite. Anytime I sat down and tried to satisfy your request to move things to the userspace, things got ugly and duplicative really quick. I suspect part of the reason you may think its easier because you already have part of virtio-net in userspace and its surrounding support, but that is not the case moving forward for new device types.
Quoted 2 lines
I can't comment on your experience, but we'll definitely build on existing code for new device types.
Fair enough. I'll build on my experience, either reusing existing code or implementing new designs where appropriate. If you or anyone else want to join me in my efforts, the more the merrier.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
you only
need to know which features the kernel supports (they can be enabled unconditionally, just not exposed).Further, some devices are perfectly happy to be implemented in userspace, so we need userspace configuration support anyway. Why reimplement it in the kernel?
Quoted 7 lines
Quoted 5 lines
Thats fine. vbus is targetted for high-performance IO. So if you have a robust userspace (like KVM+QEMU) and low-performance constraints (say, for a console or something), put it in userspace and vbus is not involved. I don't care.
So now the hypothetical non-pci hypervisor needs to support two busses.
No. The hypothetical hypervisor only needs to decide where low-performance devices should live. If that is best served by making/reusing a unique bus for them, I have no specific problem with that. Systems are typically composed of multiple buses anyway.
Conversely, there is nothing wrong with putting low-performance devices on a bus designed for high-performance either, and vbus can accommodate both types. The latter is what I would advocate for simplicity's sake, but its not a requirement.
Kind Regards,
-Greg
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 10 lines · Avi Kivity
Quoted 8 lines · Avi Kivity
Example: feature negotiation. If it happens in userspace, it's easy to limit what features we expose to the guest. If it happens in the kernel, we need to add an interface to let the kernel know which features it should expose to the guest. We also need to add an interface to let userspace know which features were negotiated, if we want to implement live migration. Something fairly trivial bloats rapidly.
Quoted 7 lines
btw, we have this issue with kvm reporting cpuid bits to the guest. Instead of letting kvm talk directly to the hardware and the guest, kvm gets the cpuid bits from the hardware, strips away features it doesn't support, exposes that to userspace, and expects userspace to program the cpuid bits it wants to expose to the guest (which may be different than what kvm exposed to userspace, and different from guest to guest).
This issue doesn't exist in the model I am referring to, as these are all virtual-devices anyway. See my last reply
-Greg
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 10 lines · Avi Kivity
Quoted 8 lines · Avi Kivity
Example: feature negotiation. If it happens in userspace, it's easy to limit what features we expose to the guest. If it happens in the kernel, we need to add an interface to let the kernel know which features it should expose to the guest. We also need to add an interface to let userspace know which features were negotiated, if we want to implement live migration. Something fairly trivial bloats rapidly.
Quoted 7 lines
btw, we have this issue with kvm reporting cpuid bits to the guest. Instead of letting kvm talk directly to the hardware and the guest, kvm gets the cpuid bits from the hardware, strips away features it doesn't support, exposes that to userspace, and expects userspace to program the cpuid bits it wants to expose to the guest (which may be different than what kvm exposed to userspace, and different from guest to guest).
This issue doesn't exist in the model I am referring to, as these are all virtual-devices anyway. See my last reply
-Greg
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 140 lines · Avi Kivity
Quoted 14 lines · Gregory Haskins
Quoted 14 lines
Quoted 14 lines
There are various aspects about designing high-performance virtual devices such as providing the shortest paths possible between the physical resources and the consumers. Conversely, we also need to ensure that we meet proper isolation/protection guarantees at the same time. What this means is there are various aspects to any high-performance PV design that require to be placed in-kernel to maximize the performance yet properly isolate the guest.
For instance, you are required to have your signal-path (interrupts and hypercalls), your memory-path (gpa translation), and addressing/isolation model in-kernel to maximize performance.
Quoted 7 lines
Quoted 2 lines
Exactly. That's what vhost puts into the kernel and nothing more.
Actually, no. Generally, _KVM_ puts those things into the kernel, and vhost consumes them. Without KVM (or something equivalent), vhost is incomplete. One of my goals with vbus is to generalize the "something equivalent" part here.
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Vbus accomplishes its in-kernel isolation model by providing a "container" concept, where objects are placed into this container by userspace. The host kernel enforces isolation/protection by using a namespace to identify objects that is only relevant within a specific container's context (namely, a "u32 dev-id"). The guest addresses the objects by its dev-id, and the kernel ensures that the guest can't access objects outside of its dev-id namespace.
Quoted 6 lines
Quoted 2 lines
vhost manages to accomplish this without any kernel support.
No, vhost manages to accomplish this because of KVMs kernel support
(ioeventfd, etc). Without a KVM-like in-kernel support, vhost is a
merely a kind of "tuntap"-like clone signalled by eventfds.Without a vbus-connector-falling-dominos, vbus-venet can't do anything either. Both vhost and vbus need an interface, vhost's is just narrower since it doesn't do configuration or enumeration.
Quoted 6 lines
This goes directly to my rebuttal of your claim that vbus places too much in the kernel. I state that, one way or the other, address decode and isolation _must_ be in the kernel for performance. Vbus does this with a devid/container scheme. vhost+virtio-pci+kvm does it with pci+pio+ioeventfd.
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
Quoted 10 lines
Quoted 5 lines
The guest
simply has not access to any vhost resources other than theguest->hostdoorbell, which is handed to the guest outside vhost (so it's somebody else's problem, in userspace).You mean _controlled_ by userspace, right? Obviously, the other side of the kernel still needs to be programmed (ioeventfd, etc). Otherwise, vhost would be pointless: e.g. just use vanilla tuntap if you don't need fast in-kernel decoding.
Yes (though for something like level-triggered interrupts we're probably keeping it in userspace, enjoying the benefits of vhost data path while paying more for signalling).
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
All that is required is a way to transport a message with a "devid" attribute as an address (such as DEVCALL(devid)) and the framework provides the rest of the decode+execute function.
vhost avoids that.
No, it doesn't avoid it. It just doesn't specify how its done, and relies on something else to do it on its behalf.
That someone else can be in userspace, apart from the actual fast path.
Quoted 3 lines
Conversely, vbus specifies how its done, but not how to transport the verb "across the wire". That is the role of the vbus-connector abstraction.
So again, vbus does everything in the kernel (since it's so easy and cheap) but expects a vbus-connector. vhost does configuration in userspace (since it's so clunky and fragile) but expects a couple of eventfds.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Contrast this to vhost+virtio-pci (called simply "vhost" from here).
It's the wrong name. vhost implements only the data path.
Understood, but vhost+virtio-pci is what I am contrasting, and I use "vhost" for short from that point on because I am too lazy to type the whole name over and over ;)
If you #define A A+B+C don't expect intelligent conversation afterwards.
Quoted 19 lines
Quoted 11 lines
Quoted 7 lines
It is not immune to requiring in-kernel addressing support either, but rather it just does it differently (and its not as you might expect via qemu).
Vhost relies on QEMU to render PCI objects to the guest, which the guest assigns resources (such as BARs, interrupts, etc).
vhost does not rely on qemu. It relies on its user to handle configuration. In one important case it's qemu+pci. It could just as well be the lguest launcher.
I meant vhost=vhost+virtio-pci here. Sorry for the confusion.
The point I am making specifically is that vhost in general relies on other in-kernel components to function. I.e. It cannot function without having something like the PCI model to build an IO namespace. That namespace (in this case, pio addresses+data tuples) are used for the in-kernel addressing function under KVM + virtio-pci.
Quoted 8 lines
The case of the lguest launcher is a good one to highlight. Yes, you can presumably also use lguest with vhost, if the requisite facilities are exposed to lguest-bus, and some eventfd based thing like ioeventfd is written for the host (if it doesnt exist already).
And when the next virt design "foo" comes out, it can make a "foo-bus" model, and implement foo-eventfd on the backend, etc, etc.
It's exactly the same with vbus needing additional connectors for additional transports.
Quoted 7 lines
Quoted 4 lines
Ira can make ira-bus, and ira-eventfd, etc, etc.
Each iteration will invariably introduce duplicated parts of the stack.
Invariably? Use libraries (virtio-shmem.ko, libvhost.so).
Referencing libraries that don't yet exist doesn't seem like a good argument against vbus from my point of view. I'm not speficially advocating for vbus; I'm just letting you know how it looks to another developer in the trenches.
If you'd like to see the amount of duplication present, look at the code I'm currently working on. It mostly works at this point, though I haven't finished my userspace, nor figured out how to actually transfer data.
The current question I have (just to let you know where I am in development) is:
I have the physical address of the remote data, but how do I get it into a userspace buffer, so I can pass it to tun?
http://www.mmarray.org/~iws/virtio-phys/
Ira
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 140 lines · Avi Kivity
Quoted 14 lines · Gregory Haskins
Quoted 14 lines
Quoted 14 lines
There are various aspects about designing high-performance virtual devices such as providing the shortest paths possible between the physical resources and the consumers. Conversely, we also need to ensure that we meet proper isolation/protection guarantees at the same time. What this means is there are various aspects to any high-performance PV design that require to be placed in-kernel to maximize the performance yet properly isolate the guest.
For instance, you are required to have your signal-path (interrupts and hypercalls), your memory-path (gpa translation), and addressing/isolation model in-kernel to maximize performance.
Quoted 7 lines
Quoted 2 lines
Exactly. That's what vhost puts into the kernel and nothing more.
Actually, no. Generally, _KVM_ puts those things into the kernel, and vhost consumes them. Without KVM (or something equivalent), vhost is incomplete. One of my goals with vbus is to generalize the "something equivalent" part here.
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Vbus accomplishes its in-kernel isolation model by providing a "container" concept, where objects are placed into this container by userspace. The host kernel enforces isolation/protection by using a namespace to identify objects that is only relevant within a specific container's context (namely, a "u32 dev-id"). The guest addresses the objects by its dev-id, and the kernel ensures that the guest can't access objects outside of its dev-id namespace.
Quoted 6 lines
Quoted 2 lines
vhost manages to accomplish this without any kernel support.
No, vhost manages to accomplish this because of KVMs kernel support
(ioeventfd, etc). Without a KVM-like in-kernel support, vhost is a
merely a kind of "tuntap"-like clone signalled by eventfds.Without a vbus-connector-falling-dominos, vbus-venet can't do anything either. Both vhost and vbus need an interface, vhost's is just narrower since it doesn't do configuration or enumeration.
Quoted 6 lines
This goes directly to my rebuttal of your claim that vbus places too much in the kernel. I state that, one way or the other, address decode and isolation _must_ be in the kernel for performance. Vbus does this with a devid/container scheme. vhost+virtio-pci+kvm does it with pci+pio+ioeventfd.
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
Quoted 10 lines
Quoted 5 lines
The guest
simply has not access to any vhost resources other than theguest->hostdoorbell, which is handed to the guest outside vhost (so it's somebody else's problem, in userspace).You mean _controlled_ by userspace, right? Obviously, the other side of the kernel still needs to be programmed (ioeventfd, etc). Otherwise, vhost would be pointless: e.g. just use vanilla tuntap if you don't need fast in-kernel decoding.
Yes (though for something like level-triggered interrupts we're probably keeping it in userspace, enjoying the benefits of vhost data path while paying more for signalling).
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
All that is required is a way to transport a message with a "devid" attribute as an address (such as DEVCALL(devid)) and the framework provides the rest of the decode+execute function.
vhost avoids that.
No, it doesn't avoid it. It just doesn't specify how its done, and relies on something else to do it on its behalf.
That someone else can be in userspace, apart from the actual fast path.
Quoted 3 lines
Conversely, vbus specifies how its done, but not how to transport the verb "across the wire". That is the role of the vbus-connector abstraction.
So again, vbus does everything in the kernel (since it's so easy and cheap) but expects a vbus-connector. vhost does configuration in userspace (since it's so clunky and fragile) but expects a couple of eventfds.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Contrast this to vhost+virtio-pci (called simply "vhost" from here).
It's the wrong name. vhost implements only the data path.
Understood, but vhost+virtio-pci is what I am contrasting, and I use "vhost" for short from that point on because I am too lazy to type the whole name over and over ;)
If you #define A A+B+C don't expect intelligent conversation afterwards.
Quoted 19 lines
Quoted 11 lines
Quoted 7 lines
It is not immune to requiring in-kernel addressing support either, but rather it just does it differently (and its not as you might expect via qemu).
Vhost relies on QEMU to render PCI objects to the guest, which the guest assigns resources (such as BARs, interrupts, etc).
vhost does not rely on qemu. It relies on its user to handle configuration. In one important case it's qemu+pci. It could just as well be the lguest launcher.
I meant vhost=vhost+virtio-pci here. Sorry for the confusion.
The point I am making specifically is that vhost in general relies on other in-kernel components to function. I.e. It cannot function without having something like the PCI model to build an IO namespace. That namespace (in this case, pio addresses+data tuples) are used for the in-kernel addressing function under KVM + virtio-pci.
Quoted 8 lines
The case of the lguest launcher is a good one to highlight. Yes, you can presumably also use lguest with vhost, if the requisite facilities are exposed to lguest-bus, and some eventfd based thing like ioeventfd is written for the host (if it doesnt exist already).
And when the next virt design "foo" comes out, it can make a "foo-bus" model, and implement foo-eventfd on the backend, etc, etc.
It's exactly the same with vbus needing additional connectors for additional transports.
Quoted 7 lines
Quoted 4 lines
Ira can make ira-bus, and ira-eventfd, etc, etc.
Each iteration will invariably introduce duplicated parts of the stack.
Invariably? Use libraries (virtio-shmem.ko, libvhost.so).
Referencing libraries that don't yet exist doesn't seem like a good argument against vbus from my point of view. I'm not speficially advocating for vbus; I'm just letting you know how it looks to another developer in the trenches.
If you'd like to see the amount of duplication present, look at the code I'm currently working on. It mostly works at this point, though I haven't finished my userspace, nor figured out how to actually transfer data.
The current question I have (just to let you know where I am in development) is:
I have the physical address of the remote data, but how do I get it into a userspace buffer, so I can pass it to tun?
http://www.mmarray.org/~iws/virtio-phys/
Ira
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Ira W. SnyderQuoted 5 lines · Ira W. Snyder
Quoted 5 lines
Quoted 5 lines
Ira can make ira-bus, and ira-eventfd, etc, etc.
Each iteration will invariably introduce duplicated parts of the stack.
Quoted 8 lines
Quoted 3 lines
Invariably? Use libraries (virtio-shmem.ko, libvhost.so).
Referencing libraries that don't yet exist doesn't seem like a good argument against vbus from my point of view. I'm not speficially advocating for vbus; I'm just letting you know how it looks to another developer in the trenches.
My argument is that we shouldn't write a new framework instead of fixing or extending an existing one.
Quoted 2 lines
If you'd like to see the amount of duplication present, look at the code I'm currently working on.
Yes, virtio-phys-guest looks pretty much duplicated. Looks like it should be pretty easy to deduplicate.
Quoted 10 lines
It mostly works at this point, though I
haven't finished my userspace, nor figured out how to actually transfer data.The current question I have (just to let you know where I am in development) is:
I have the physical address of the remote data, but how do I get it into a userspace buffer, so I can pass it to tun?
vhost does guest physical address to host userspace address (it your scenario, remote physical to local virtual) using a table of memory slots; there's an ioctl that allows userspace to initialize that table.
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Ira W. SnyderQuoted 5 lines · Ira W. Snyder
Quoted 5 lines
Quoted 5 lines
Ira can make ira-bus, and ira-eventfd, etc, etc.
Each iteration will invariably introduce duplicated parts of the stack.
Quoted 8 lines
Quoted 3 lines
Invariably? Use libraries (virtio-shmem.ko, libvhost.so).
Referencing libraries that don't yet exist doesn't seem like a good argument against vbus from my point of view. I'm not speficially advocating for vbus; I'm just letting you know how it looks to another developer in the trenches.
My argument is that we shouldn't write a new framework instead of fixing or extending an existing one.
Quoted 2 lines
If you'd like to see the amount of duplication present, look at the code I'm currently working on.
Yes, virtio-phys-guest looks pretty much duplicated. Looks like it should be pretty easy to deduplicate.
Quoted 10 lines
It mostly works at this point, though I
haven't finished my userspace, nor figured out how to actually transfer data.The current question I have (just to let you know where I am in development) is:
I have the physical address of the remote data, but how do I get it into a userspace buffer, so I can pass it to tun?
vhost does guest physical address to host userspace address (it your scenario, remote physical to local virtual) using a table of memory slots; there's an ioctl that allows userspace to initialize that table.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 8 lines · Gregory Haskins
Quoted 8 lines
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
Quoted 7 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands. But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt (there's a limit how far you can take this, not imposed by the code, but by virtio's charter as a virtual device driver framework).
Quoted 45 lines
Going back to our stack diagrams, you could think of a vhost solution like this:
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| ? undefined-1 ?
--------------------------
| vhost
--------------------------and you could think of a vbus solution like this
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| bus-interface
--------------------------
| ? undefined-2 ?
--------------------------
| bus-model
--------------------------
| virtio-net-device (vhost ported to vbus model? :)
--------------------------So the difference between vhost and vbus in this particular context is that you need to have "undefined-1" do device discovery/hotswap, config-space, address-decode/isolation, signal-path routing, memory-path routing, etc. Today this function is filled by things like virtio-pci, pci-bus, KVM/ioeventfd, and QEMU for x86. I am not as familiar with lguest, but presumably it is filled there by components like virtio-lguest, lguest-bus, lguest.ko, and lguest-launcher. And to use more contemporary examples, we might have virtio-domino, domino-bus, domino.ko, and domino-launcher as well as virtio-ira, ira-bus, ira.ko, and ira-launcher.
Quoted 8 lines
Contrast this to the vbus stack: The bus-X components (when optionally employed by the connector designer) do device-discovery, hotswap, config-space, address-decode/isolation, signal-path and memory-path routing, etc in a general (and pv-centric) way. The "undefined-2" portion is the "connector", and just needs to convey messages like "DEVCALL" and "SHMSIGNAL". The rest is handled in other parts of the stack.
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
Quoted 3 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
Quoted 5 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.
Only theoretically. The existing installed base would have to be thrown away, or we'd need to support both.
Quoted 11 lines
Quoted 3 lines
Without a vbus-connector-falling-dominos, vbus-venet can't do anything either.
Mostly covered above...
However, I was addressing your assertion that vhost somehow magically accomplishes this "container/addressing" function without any specific kernel support. This is incorrect. I contend that this kernel support is required and present. The difference is that its defined elsewhere (and typically in a transport/arch specific way).
Quoted 6 lines
IOW: You can basically think of the programmed PIO addresses as forming its "container". Only addresses explicitly added are visible, and everything else is inaccessible. This whole discussion is merely a question of what's been generalized verses what needs to be re-implemented each time.
Sorry, this is too abstract for me.
Quoted 9 lines
Quoted 3 lines
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
That is not correct. vbus does its own native address decoding in the fast path, such as here:
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
Quoted 6 lines
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
It doesn't have just virtio-net, it has userspace-based hostplug and a bunch of other devices impemented in userspace. Currently qemu has virtio bindings for pci and syborg (whatever that is), and device models for baloon, block, net, and console, so it seems implementing device support in userspace is not as disasterous as you make it to be.
Quoted 4 lines
Quoted 2 lines
Invariably?
As in "always"
Refactor instead of duplicating.
Quoted 8 lines
Quoted 3 lines
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Refactor instead of rewriting.
Quoted 9 lines
Quoted 2 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
Quoted 6 lines
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux); Xen has to tunnel xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.
"PCI is a dead end" could not be more wrong, it's what guests support. An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I digress. My point here isn't PCI. The point here is the missing component for when PCI is not present. The component that is partially satisfied by vbus's devid addressing scheme. If you are going to use vhost, and you don't have PCI, you've gotta build something to replace it.
Quoted 6 lines
Quoted 4 lines
Yes, that's why people have keyboards. They'll write that glue code if they need it. If it turns out to be a hit an people start having virtio transport module writing parties, they'll figure out a way to share code.
Sigh... The party has already started. I tried to invite you months ago...
I've been voting virtio since 2007.
Quoted 9 lines
Quoted 5 lines
On the guest side, virtio-shmem.ko can unify the ring access. It probably makes sense even today. On the host side I eventfd is the kernel interface and libvhostconfig.so can provide the configuration when an existing ABI is not imposed.
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
vbus needs the same thing so it cancels out.
Quoted 9 lines
Quoted 3 lines
Look at the virtio-net feature negotiation. There's a lot more there than the MAC address, and it's going to grow.
Agreed, but note that makes my point. That feature negotiation almost invariably influences the device-model, not some config-space shim.
IOW: terminating config-space at some userspace shim is pointless. The model ultimately needs the result of whatever transpires during that negotiation anyway.
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
- do all that from an unprivileged process
- securely wrt other unprivileged processes
?
What are your plans here?
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 8 lines · Gregory Haskins
Quoted 8 lines
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
Quoted 7 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands. But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt (there's a limit how far you can take this, not imposed by the code, but by virtio's charter as a virtual device driver framework).
Quoted 45 lines
Going back to our stack diagrams, you could think of a vhost solution like this:
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| ? undefined-1 ?
--------------------------
| vhost
--------------------------and you could think of a vbus solution like this
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| bus-interface
--------------------------
| ? undefined-2 ?
--------------------------
| bus-model
--------------------------
| virtio-net-device (vhost ported to vbus model? :)
--------------------------So the difference between vhost and vbus in this particular context is that you need to have "undefined-1" do device discovery/hotswap, config-space, address-decode/isolation, signal-path routing, memory-path routing, etc. Today this function is filled by things like virtio-pci, pci-bus, KVM/ioeventfd, and QEMU for x86. I am not as familiar with lguest, but presumably it is filled there by components like virtio-lguest, lguest-bus, lguest.ko, and lguest-launcher. And to use more contemporary examples, we might have virtio-domino, domino-bus, domino.ko, and domino-launcher as well as virtio-ira, ira-bus, ira.ko, and ira-launcher.
Quoted 8 lines
Contrast this to the vbus stack: The bus-X components (when optionally employed by the connector designer) do device-discovery, hotswap, config-space, address-decode/isolation, signal-path and memory-path routing, etc in a general (and pv-centric) way. The "undefined-2" portion is the "connector", and just needs to convey messages like "DEVCALL" and "SHMSIGNAL". The rest is handled in other parts of the stack.
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
Quoted 3 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
Quoted 5 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.
Only theoretically. The existing installed base would have to be thrown away, or we'd need to support both.
Quoted 11 lines
Quoted 3 lines
Without a vbus-connector-falling-dominos, vbus-venet can't do anything either.
Mostly covered above...
However, I was addressing your assertion that vhost somehow magically accomplishes this "container/addressing" function without any specific kernel support. This is incorrect. I contend that this kernel support is required and present. The difference is that its defined elsewhere (and typically in a transport/arch specific way).
Quoted 6 lines
IOW: You can basically think of the programmed PIO addresses as forming its "container". Only addresses explicitly added are visible, and everything else is inaccessible. This whole discussion is merely a question of what's been generalized verses what needs to be re-implemented each time.
Sorry, this is too abstract for me.
Quoted 9 lines
Quoted 3 lines
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
That is not correct. vbus does its own native address decoding in the fast path, such as here:
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
Quoted 6 lines
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
It doesn't have just virtio-net, it has userspace-based hostplug and a bunch of other devices impemented in userspace. Currently qemu has virtio bindings for pci and syborg (whatever that is), and device models for baloon, block, net, and console, so it seems implementing device support in userspace is not as disasterous as you make it to be.
Quoted 4 lines
Quoted 2 lines
Invariably?
As in "always"
Refactor instead of duplicating.
Quoted 8 lines
Quoted 3 lines
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Refactor instead of rewriting.
Quoted 9 lines
Quoted 2 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
Quoted 6 lines
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux); Xen has to tunnel xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.
"PCI is a dead end" could not be more wrong, it's what guests support. An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I digress. My point here isn't PCI. The point here is the missing component for when PCI is not present. The component that is partially satisfied by vbus's devid addressing scheme. If you are going to use vhost, and you don't have PCI, you've gotta build something to replace it.
Quoted 6 lines
Quoted 4 lines
Yes, that's why people have keyboards. They'll write that glue code if they need it. If it turns out to be a hit an people start having virtio transport module writing parties, they'll figure out a way to share code.
Sigh... The party has already started. I tried to invite you months ago...
I've been voting virtio since 2007.
Quoted 9 lines
Quoted 5 lines
On the guest side, virtio-shmem.ko can unify the ring access. It probably makes sense even today. On the host side I eventfd is the kernel interface and libvhostconfig.so can provide the configuration when an existing ABI is not imposed.
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
vbus needs the same thing so it cancels out.
Quoted 9 lines
Quoted 3 lines
Look at the virtio-net feature negotiation. There's a lot more there than the MAC address, and it's going to grow.
Agreed, but note that makes my point. That feature negotiation almost invariably influences the device-model, not some config-space shim.
IOW: terminating config-space at some userspace shim is pointless. The model ultimately needs the result of whatever transpires during that negotiation anyway.
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
- do all that from an unprivileged process
- securely wrt other unprivileged processes
?
What are your plans here?
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Michael S. TsirkinQuoted 974 lines · Michael S. Tsirkin
What it is: vhost net is a character device that can be used to reduce the number of system calls involved in virtio networking. Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for migration)
- support memory table and not just an offset (needed for kvm)common virtio related code has been put in a separate file
vhost.cand can be made into a separate module if/when more backends appear. I used Rusty'slguest.cas the source for developing this part : this supplied me with witty comments I wouldn't be able to write myself.What it is not: vhost net is not a bus, and not a generic new system call. No assumptions are made on how guest performs hypercalls. Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by userspace) to a backend. The backend could be a network device, or a tun-like device. In this version I only support raw socket as a backend, which can be bound to e.g. SR IOV, or to macvlan device. Backend is also configured by userspace, including vlan/mac etc.
Status:
This works for me, and I haven't see any crashes.
I have done some light benchmarking (with v4), compared to userspace, I see improved latency (as I save up to 4 system calls per packet) but not bandwidth/CPU (as TSO and interrupt mitigation are not supported). For ping benchmark (where there's no TSO) troughput is also improved.Features that I plan to look at in the future:
- tap support
- TSO
- interrupt mitigation
- zero copyAcked-by Arnd Bergmann <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- MAINTAINERS | 10 + arch/x86/kvm/Kconfig | 1 + drivers/Makefile | 1 + drivers/vhost/Kconfig | 11 + drivers/vhost/Makefile | 2 + drivers/vhost/net.c | 475 ++++++++++++++++++++++++++++++ drivers/vhost/vhost.c | 688 ++++++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 122 ++++++++ include/linux/Kbuild | 1 + include/linux/miscdevice.h | 1 + include/linux/vhost.h | 101 +++++++ 11 files changed, 1413 insertions(+), 0 deletions(-) create mode 100644 drivers/vhost/Kconfig create mode 100644 drivers/vhost/Makefile create mode 100644 drivers/vhost/net.c create mode 100644 drivers/vhost/vhost.c create mode 100644 drivers/vhost/vhost.h create mode 100644 include/linux/vhost.hMAINTAINERS +10
-0@@ -5431,6 +5431,16 @@ S: Maintained F: Documentation/filesystems/vfat.txt F: fs/fat/ +VIRTIO HOST (VHOST) +P: Michael S. Tsirkin +M: [email protected] +L: [email protected] +L: [email protected] +L: [email protected] +S: Maintained +F: drivers/vhost/ +F: include/linux/vhost.h + VIA RHINE NETWORK DRIVER M: Roger Luethi <[email protected]> S: Maintainedarch/x86/kvm/Kconfig +1
-0@@ -64,6 +64,7 @@ config KVM_AMD # OK, it's a little counter-intuitive to do this, but it puts it neatly under # the virtualization menu. +source drivers/vhost/Kconfig source drivers/lguest/Kconfig source drivers/virtio/Kconfigdrivers/Makefile +1
-0@@ -105,6 +105,7 @@ obj-$(CONFIG_HID) += hid/ obj-$(CONFIG_PPC_PS3) += ps3/ obj-$(CONFIG_OF) += of/ obj-$(CONFIG_SSB) += ssb/ +obj-$(CONFIG_VHOST_NET) += vhost/ obj-$(CONFIG_VIRTIO) += virtio/ obj-$(CONFIG_VLYNQ) += vlynq/ obj-$(CONFIG_STAGING) += staging/drivers/vhost/Kconfig new file +11
-0@@ -0,0 +1,11 @@ +config VHOST_NET + tristate "Host kernel accelerator for virtio net" + depends on NET && EVENTFD + ---help--- + This kernel module can be loaded in host kernel to accelerate + guest networking with virtio_net. Not to be confused with virtio_net + module itself which needs to be loaded in guest kernel. + + To compile this driver as a module, choose M here: the module will + be called vhost_net. +drivers/vhost/Makefile new file +2
-0@@ -0,0 +1,2 @@ +obj-$(CONFIG_VHOST_NET) += vhost_net.o +vhost_net-y := vhost.o net.odrivers/vhost/net.c new file +475
-0@@ -0,0 +1,475 @@ +/* Copyright (C) 2009 Red Hat, Inc. +* Author: Michael S. Tsirkin <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. +* +* virtio-net server in host kernel. +*/ + +#include <linux/compat.h> +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <linux/mmu_context.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/rcupdate.h> +#include <linux/file.h> + +#include <linux/net.h> +#include <linux/if_packet.h> +#include <linux/if_arp.h> + +#include <net/sock.h> + +#include "vhost.h" + +enum { +VHOST_NET_VQ_RX =0 , +VHOST_NET_VQ_TX =1 , +VHOST_NET_VQ_MAX =2 , +}; + +struct vhost_net { +struct vhost_dev dev; +struct vhost_virtqueue vqs[VHOST_NET_VQ_MAX ]; +/* We use a kind of RCU to access sock pointer. +* All readers access it from workqueue, which makes it possible to +* flush the workqueue instead of synchronize_rcu. Therefore readers do +* not need to call rcu_read_lock/rcu_read_unlock: the beginning of +* work item execution acts instead of rcu_read_lock() and the end of +* work item execution acts instead of rcu_read_lock(). +* Writers use device mutex. */ +struct socket *sock; +struct vhost_poll poll[VHOST_NET_VQ_MAX ]; +}; + +/* Pop first len bytes from iovec. Return number of segments used. */ +static int move_iovec_hdr (struct iovec *from,struct iovec *to, +size_t len,int iov_count) +{ +int seg =0 ; +size_t size; +while (len && seg < iov_count) { + size =min (from->iov_len, len); + to->iov_base = from->iov_base; + to->iov_len = size; + from->iov_len -= size; + from->iov_base += size; + len -= size; + ++from; + ++to; + ++seg; + } +return seg; +} + +/* Expects to be always run from workqueue - which acts as +* read-size critical section for our kind of RCU. */ +static void handle_tx (struct vhost_net *net) +{ +struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_TX ]; +unsigned head, out, in, s; +struct msghdr msg = { + .msg_name =NULL , + .msg_namelen =0 , + .msg_control =NULL , + .msg_controllen =0 , + .msg_iov = vq->iov, + .msg_flags =MSG_DONTWAIT , + }; +size_t len; +int err; +struct socket *sock =rcu_dereference (net->sock); +if (!sock || !sock_writeable (sock->sk)) +return ; + +use_mm (net->dev.mm); +mutex_lock (&vq->mutex); +for (;;) { + head =vhost_get_vq_desc (&net->dev, vq, vq->iov, &out, &in); +/* Nothing new? Wait for eventfd to tell us they refilled. */ +if (head == vq->num) +break ; +if (in) { +vq_err (vq,"Unexpected descriptor format for TX: " +"out %d, int %d\n" , out, in); +break ; + } +/* Skip header. TODO: support TSO. */ + s =move_iovec_hdr (vq->iov, vq->hdr, +sizeof (struct virtio_net_hdr ), out); + msg.msg_iovlen = out; + len =iov_length (vq->iov, out); +/* Sanity check */ +if (!len) { +vq_err (vq,"Unexpected header len for TX: " +"%ld expected %zd\n" , +iov_length (vq->hdr, s), +sizeof (struct virtio_net_hdr )); +break ; + } +/* TODO: Check specific error and bomb out unless ENOBUFS? */ + err = sock->ops->sendmsg (NULL , sock, &msg, len); +if (err <0 ) { +vhost_discard_vq_desc (vq); +break ; + } +if (err != len) +pr_err ("Truncated TX packet: " +" len %d != %zd\n" , err, len); +vhost_add_used_and_trigger (&net->dev, vq, head,0 ); + } + +mutex_unlock (&vq->mutex); +unuse_mm (net->dev.mm); +} + +/* Expects to be always run from workqueue - which acts as +* read-size critical section for our kind of RCU. */ +static void handle_rx (struct vhost_net *net) +{ +struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_RX ]; +unsigned head, out, in, s; +struct msghdr msg = { + .msg_name =NULL , + .msg_namelen =0 , + .msg_control =NULL ,/* FIXME: get and handle RX aux data. */ + .msg_controllen =0 , + .msg_iov = vq->iov, + .msg_flags =MSG_DONTWAIT , + }; + +struct virtio_net_hdr hdr = { + .flags =0 , + .gso_type =VIRTIO_NET_HDR_GSO_NONE + }; + +size_t len; +int err; +struct socket *sock =rcu_dereference (net->sock); +if (!sock ||skb_queue_empty (&sock->sk->sk_receive_queue)) +return ; + +use_mm (net->dev.mm); +mutex_lock (&vq->mutex); +vhost_no_notify (vq); + +for (;;) { + head =vhost_get_vq_desc (&net->dev, vq, vq->iov, &out, &in); +/* OK, now we need to know about added descriptors. */ +if (head == vq->num &&vhost_notify (vq)) +/* They could have slipped one in as we were doing that: +* check again. */ +continue ; +/* Nothing new? Wait for eventfd to tell us they refilled. */ +if (head == vq->num) +break ; +/* We don't need to be notified again. */ +vhost_no_notify (vq); +if (out) { +vq_err (vq,"Unexpected descriptor format for RX: " +"out %d, int %d\n" , + out, in); +break ; + } +/* Skip header. TODO: support TSO/mergeable rx buffers. */ + s =move_iovec_hdr (vq->iov, vq->hdr,sizeof hdr, in); + msg.msg_iovlen = in; + len =iov_length (vq->iov, in); +/* Sanity check */ +if (!len) { +vq_err (vq,"Unexpected header len for RX: " +"%zd expected %zd\n" , +iov_length (vq->hdr, s),sizeof hdr); +break ; + } + err = sock->ops->recvmsg (NULL , sock, &msg, + len,MSG_DONTWAIT |MSG_TRUNC ); +/* TODO: Check specific error and bomb out unless EAGAIN? */ +if (err <0 ) { +vhost_discard_vq_desc (vq); +break ; + } +/* TODO: Should check and handle checksum. */ +if (err > len) { +pr_err ("Discarded truncated rx packet: " +" len %d > %zd\n" , err, len); +vhost_discard_vq_desc (vq); +continue ; + } + len = err; + err =memcpy_toiovec (vq->hdr, (unsigned char *)&hdr,sizeof hdr); +if (err) { +vq_err (vq,"Unable to write vnet_hdr at addr %p: %d\n" , + vq->iov->iov_base, err); +break ; + } +vhost_add_used_and_trigger (&net->dev, vq, head, + len +sizeof hdr); + } + +mutex_unlock (&vq->mutex); +unuse_mm (net->dev.mm); +} + +static void handle_tx_kick (struct work_struct *work) +{ +struct vhost_virtqueue *vq; +struct vhost_net *net; + vq = container_of(work, struct vhost_virtqueue, poll.work); + net = container_of(vq->dev, struct vhost_net, dev); +handle_tx (net); +} + +static void handle_rx_kick (struct work_struct *work) +{ +struct vhost_virtqueue *vq; +struct vhost_net *net; + vq = container_of(work, struct vhost_virtqueue, poll.work); + net = container_of(vq->dev, struct vhost_net, dev); +handle_rx (net); +} + +static void handle_tx_net (struct work_struct *work) +{ +struct vhost_net *net; + net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_TX].work); +handle_tx (net); +} + +static void handle_rx_net (struct work_struct *work) +{ +struct vhost_net *net; + net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_RX].work); +handle_rx (net); +} + +static int vhost_net_open (struct inode *inode,struct file *f) +{ +struct vhost_net *n =kzalloc (sizeof *n,GFP_KERNEL ); +int r; +if (!n) +return -ENOMEM ; + f->private_data = n; + n->vqs[VHOST_NET_VQ_TX ].handle_kick = handle_tx_kick; + n->vqs[VHOST_NET_VQ_RX ].handle_kick = handle_rx_kick; + r =vhost_dev_init (&n->dev, n->vqs,VHOST_NET_VQ_MAX ); +if (r <0 ) { +kfree (n); +return r; + } + +vhost_poll_init (n->poll +VHOST_NET_VQ_TX , handle_tx_net,POLLOUT ); +vhost_poll_init (n->poll +VHOST_NET_VQ_RX , handle_rx_net,POLLIN ); +return 0 ; +} + +static struct socket *vhost_net_stop (struct vhost_net *n) +{ +struct socket *sock = n->sock; +rcu_assign_pointer (n->sock,NULL ); +if (sock) { +vhost_poll_flush (n->poll +VHOST_NET_VQ_TX ); +vhost_poll_flush (n->poll +VHOST_NET_VQ_RX ); + } +return sock; +} + +static int vhost_net_release (struct inode *inode,struct file *f) +{ +struct vhost_net *n = f->private_data; +struct socket *sock; + + sock =vhost_net_stop (n); +vhost_dev_cleanup (&n->dev); +if (sock) +fput (sock->file); +kfree (n); +return 0 ; +} + +static void vhost_net_flush (struct vhost_net *n) +{ +vhost_poll_flush (n->poll +VHOST_NET_VQ_TX ); +vhost_poll_flush (n->poll +VHOST_NET_VQ_RX ); +vhost_poll_flush (&n->dev.vqs[VHOST_NET_VQ_TX ].poll); +vhost_poll_flush (&n->dev.vqs[VHOST_NET_VQ_RX ].poll); +} + +static long vhost_net_set_socket (struct vhost_net *n,int fd) +{ +struct { +struct sockaddr_ll sa; +char buf[MAX_ADDR_LEN ]; + } uaddr; +struct socket *sock, *oldsock =NULL ; +int uaddr_len =sizeof uaddr, r; + +mutex_lock (&n->dev.mutex); + r =vhost_dev_check_owner (&n->dev); +if (r) + goto done; + +if (fd ==-1 ) { +/* Disconnect from socket and device. */ + oldsock =vhost_net_stop (n); + goto done; + } + + sock =sockfd_lookup (fd, &r); +if (!sock) { + r = -ENOTSOCK ; + goto done; + } + +/* Parameter checking */ +if (sock->sk->sk_type !=SOCK_RAW ) { + r = -ESOCKTNOSUPPORT ; + goto done; + } + + r = sock->ops->getname (sock, (struct sockaddr *)&uaddr.sa, + &uaddr_len,0 ); +if (r) + goto done; + +if (uaddr.sa.sll_family !=AF_PACKET ) { + r = -EPFNOSUPPORT ; + goto done; + } + +/* start polling new socket */ +if (sock == oldsock) + goto done; + +if (oldsock) { +vhost_poll_stop (n->poll +VHOST_NET_VQ_TX ); +vhost_poll_stop (n->poll +VHOST_NET_VQ_RX ); + } + oldsock = n->sock; +rcu_assign_pointer (n->sock, sock); +vhost_poll_start (n->poll +VHOST_NET_VQ_TX , sock->file); +vhost_poll_start (n->poll +VHOST_NET_VQ_RX , sock->file); +done: +mutex_unlock (&n->dev.mutex); +if (oldsock) { +vhost_net_flush (n); +fput (oldsock->file); + } +return r; +} + +static long vhost_net_reset_owner (struct vhost_net *n) +{ +struct socket *sock =NULL ; +long r; +mutex_lock (&n->dev.mutex); + r =vhost_dev_check_owner (&n->dev); +if (r) + goto done; + sock =vhost_net_stop (n); + r =vhost_dev_reset_owner (&n->dev); +done: +mutex_unlock (&n->dev.mutex); +if (sock) +fput (sock->file); +return r; +} + +static void vhost_net_set_features (struct vhost_net *n,u64 features) +{ +mutex_unlock (&n->dev.mutex); + n->dev.acked_features = features; +mutex_unlock (&n->dev.mutex); +vhost_net_flush (n); +} + +static long vhost_net_ioctl (struct file *f,unsigned int ioctl, +unsigned long arg) +{ +struct vhost_net *n = f->private_data; +void __user *argp = (void __user *)arg; +u32 __user *featurep = argp; +int __user *fdp = argp; +u64 features; +int fd, r; +switch (ioctl) { +case VHOST_NET_SET_SOCKET : + r =get_user (fd, fdp); +if (r <0 ) +return r; +return vhost_net_set_socket (n, fd); +case VHOST_GET_FEATURES : + features =VHOST_FEATURES ; +return put_user (features, featurep); +case VHOST_ACK_FEATURES : + r =get_user (features, featurep); +/* No features for now */ +if (r <0 ) +return r; +if (features & ~VHOST_FEATURES ) +return -EOPNOTSUPP ; +vhost_net_set_features (n, features); +return 0 ; +case VHOST_RESET_OWNER : +return vhost_net_reset_owner (n); +default : +return vhost_dev_ioctl (&n->dev, ioctl, arg); + } +} + +#ifdef CONFIG_COMPAT +static long vhost_net_compat_ioctl (struct file *f,unsigned int ioctl, +unsigned long arg) +{ +return vhost_net_ioctl (f, ioctl, (unsigned long )compat_ptr (arg)); +} +#endif + +const static struct file_operations vhost_net_fops = { + .owner =THIS_MODULE , + .release = vhost_net_release, + .unlocked_ioctl = vhost_net_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = vhost_net_compat_ioctl, +#endif + .open = vhost_net_open, +}; + +static struct miscdevice vhost_net_misc = { +VHOST_NET_MINOR , +"vhost-net" , + &vhost_net_fops, +}; + +int vhost_net_init (void ) +{ +int r =vhost_init (); +if (r) + goto err_init; + r =misc_register (&vhost_net_misc); +if (r) + goto err_reg; +return 0 ; +err_reg: +vhost_cleanup (); +err_init: +return r; + +} +module_init (vhost_net_init); + +void vhost_net_exit (void ) +{ +misc_deregister (&vhost_net_misc); +vhost_cleanup (); +} +module_exit (vhost_net_exit); + +MODULE_VERSION ("0.0.1" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Michael S. Tsirkin" ); +MODULE_DESCRIPTION ("Host kernel accelerator for virtio net" );drivers/vhost/vhost.c new file +357
-0@@ -0,0 +1,688 @@ +/* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +* +* Generic code for virtio server in host kernel. +*/ + +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <linux/mm.h> +#include <linux/miscdevice.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/rcupdate.h> +#include <linux/poll.h> +#include <linux/file.h> + +#include <linux/net.h> +#include <linux/if_packet.h> +#include <linux/if_arp.h> + +#include <net/sock.h> + +#include "vhost.h" + +enum { +VHOST_MEMORY_MAX_NREGIONS =64 , +}; + +static struct workqueue_struct *vhost_workqueue; + +static void vhost_poll_func (struct file *file,wait_queue_head_t *wqh, +poll_table *pt) +{ +struct vhost_poll *poll; + poll = container_of(pt, struct vhost_poll, table); + + poll->wqh = wqh; +add_wait_queue (wqh, &poll->wait); +} + +static int vhost_poll_wakeup (wait_queue_t *wait,unsigned mode,int sync, +void *key) +{ +struct vhost_poll *poll; + poll = container_of(wait, struct vhost_poll, wait); +if (!((unsigned long )key & poll->mask)) +return 0 ; + +queue_work (vhost_workqueue, &poll->work); +return 0 ; +} + +/* Init poll structure */ +void vhost_poll_init (struct vhost_poll *poll,work_func_t func, +unsigned long mask) +{ +INIT_WORK (&poll->work, func); +init_waitqueue_func_entry (&poll->wait, vhost_poll_wakeup); +init_poll_funcptr (&poll->table, vhost_poll_func); + poll->mask = mask; +} + +/* Start polling a file. We add ourselves to file's wait queue. The caller must +* keep a reference to a file until after vhost_poll_stop is called. */ +void vhost_poll_start (struct vhost_poll *poll,struct file *file) +{ +unsigned long mask; + mask = file->f_op->poll (file, &poll->table); +if (mask) +vhost_poll_wakeup (&poll->wait,0 ,0 , (void *)mask); +} + +/* Stop polling a file. After this function returns, it becomes safe to drop the +* file reference. You must also flush afterwards. */ +void vhost_poll_stop (struct vhost_poll *poll) +{ +remove_wait_queue (poll->wqh, &poll->wait); +} + +/* Flush any work that has been scheduled. When calling this, don't hold any +* locks that are also used by the callback. */ +void vhost_poll_flush (struct vhost_poll *poll) +{ +flush_work (&poll->work); +} + +long vhost_dev_init (struct vhost_dev *dev, +struct vhost_virtqueue *vqs,int nvqs) +{ +int i; + dev->vqs = vqs; + dev->nvqs = nvqs; +mutex_init (&dev->mutex); + +for (i =0 ; i < dev->nvqs; ++i) { + dev->vqs[i].dev = dev; +mutex_init (&dev->vqs[i].mutex); +if (dev->vqs[i].handle_kick) +vhost_poll_init (&dev->vqs[i].poll, + dev->vqs[i].handle_kick, +POLLIN ); + } +return 0 ; +} + +/* Caller should have device mutex */ +long vhost_dev_check_owner (struct vhost_dev *dev) +{ +/* Are you the owner? If not, I don't think you mean to do that */ +return dev->mm == current->mm ?0 : -EPERM ; +} + +/* Caller should have device mutex */ +static long vhost_dev_set_owner (struct vhost_dev *dev) +{ +/* Is there an owner already? */ +if (dev->mm) +return -EBUSY ; +/* No owner, become one */ + dev->mm =get_task_mm (current); +return 0 ; +} + +/* Caller should have device mutex */ +long vhost_dev_reset_owner (struct vhost_dev *dev) +{ +struct vhost_memory *memory; + +/* Restore memory to default 1:1 mapping. */ + memory =kmalloc (offsetof(struct vhost_memory , regions) + +2 *sizeof *memory->regions,GFP_KERNEL ); +if (!memory) +return -ENOMEM ; + +vhost_dev_cleanup (dev); + + memory->nregions =2 ; + memory->regions[0 ].guest_phys_addr =1 ; + memory->regions[0 ].userspace_addr =1 ; + memory->regions[0 ].memory_size = ~0ULL ; + memory->regions[1 ].guest_phys_addr =0 ; + memory->regions[1 ].userspace_addr =0 ; + memory->regions[1 ].memory_size =1 ; + dev->memory = memory; +return 0 ; +} + +/* Caller should have device mutex */ +void vhost_dev_cleanup (struct vhost_dev *dev) +{ +int i; +for (i =0 ; i < dev->nvqs; ++i) { +if (dev->vqs[i].kick && dev->vqs[i].handle_kick) { +vhost_poll_stop (&dev->vqs[i].poll); +vhost_poll_flush (&dev->vqs[i].poll); + } +if (dev->vqs[i].error_ctx) +eventfd_ctx_put (dev->vqs[i].error_ctx); +if (dev->vqs[i].error) +fput (dev->vqs[i].error); +if (dev->vqs[i].kick) +fput (dev->vqs[i].kick); +if (dev->vqs[i].call_ctx) +eventfd_ctx_put (dev->vqs[i].call_ctx); +if (dev->vqs[i].call) +fput (dev->vqs[i].call); + dev->vqs[i].error_ctx =NULL ; + dev->vqs[i].error =NULL ; + dev->vqs[i].kick =NULL ; + dev->vqs[i].call_ctx =NULL ; + dev->vqs[i].call =NULL ; + } +/* No one will access memory at this point */ +kfree (dev->memory); + dev->memory =NULL ; +if (dev->mm) +mmput (dev->mm); + dev->mm =NULL ; +} + +static long vhost_set_memory (struct vhost_dev *d,struct vhost_memory __user *m) +{ +struct vhost_memory mem, *newmem, *oldmem; +unsigned long size = offsetof(struct vhost_memory , regions); +long r; + r =copy_from_user (&mem, m, size); +if (r) +return r; +if (mem.padding) +return -EOPNOTSUPP ; +if (mem.nregions >VHOST_MEMORY_MAX_NREGIONS ) +return -E2BIG ; + newmem =kmalloc (size + mem.nregions *sizeof *m->regions,GFP_KERNEL ); +if (!newmem) +return -ENOMEM ; + +memcpy (newmem, &mem, size); + r =copy_from_user (newmem->regions, m->regions, + mem.nregions *sizeof *m->regions); +if (r) { +kfree (newmem); +return r; + } + oldmem = d->memory; +rcu_assign_pointer (d->memory, newmem); +synchronize_rcu (); +kfree (oldmem); +return 0 ; +} + +static int init_used (struct vhost_virtqueue *vq) +{ +int r =put_user (vq->used_flags, &vq->used->flags); +if (r) +return r; +return get_user (vq->last_used_idx, &vq->used->idx); +} + +static long vhost_set_vring (struct vhost_dev *d,int ioctl,void __user *argp) +{ +struct file *eventfp, *filep =NULL , + *pollstart =NULL , *pollstop =NULL ; +struct eventfd_ctx *ctx =NULL ; +u32 __user *idxp = argp; +struct vhost_virtqueue *vq; +struct vhost_vring_state s; +struct vhost_vring_file f; +struct vhost_vring_addr a; +u32 idx; +long r; + + r =get_user (idx, idxp); +if (r <0 ) +return r; +if (idx > d->nvqs) +return -ENOBUFS ; + + vq = d->vqs + idx; + +mutex_lock (&vq->mutex); + +switch (ioctl) { +case VHOST_SET_VRING_NUM : + r =copy_from_user (&s, argp,sizeof s); +if (r <0 ) +break ; +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + } + vq->num = s.num; +break ; +case VHOST_SET_VRING_BASE : + r =copy_from_user (&s, argp,sizeof s); +if (r <0 ) +break ; +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + } + vq->avail_idx = vq->last_avail_idx = s.num; +break ; +case VHOST_GET_VRING_BASE : + s.index = idx; + s.num = vq->last_avail_idx; + r =copy_to_user (argp, &s,sizeof s); +break ; +case VHOST_SET_VRING_DESC : + r =copy_from_user (&a, argp,sizeof a); +if (r <0 ) +break ; +if (a.padding) { + r = -EOPNOTSUPP ; +break ; + } +if ((u64 )(long )a.user_addr != a.user_addr) { + r = -EFAULT ; +break ; + } + vq->desc = (void __user *)(long )a.user_addr; +break ; +case VHOST_SET_VRING_AVAIL : + r =copy_from_user (&a, argp,sizeof a); +if (r <0 ) +break ; +if (a.padding) { + r = -EOPNOTSUPP ; +break ; + } +if ((u64 )(long )a.user_addr != a.user_addr) { + r = -EFAULT ; +break ; + } + vq->avail = (void __user *)(long )a.user_addr; +/* Forget the cached index value. */ + vq->avail_idx = vq->last_avail_idx; +break ; +case VHOST_SET_VRING_USED : + r =copy_from_user (&a, argp,sizeof a); +if (r <0 ) +break ; +if (a.padding) { + r = -EOPNOTSUPP ; +break ; + } +if ((u64 )(long )a.user_addr != a.user_addr) { + r = -EFAULT ; +break ; + } + vq->used = (void __user *)(long )a.user_addr; + r =init_used (vq); +if (r) +break ; +break ; +case VHOST_SET_VRING_KICK : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->kick) { + pollstop = filep = vq->kick; + pollstart = vq->kick = eventfp; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_CALL : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->call) { + filep = vq->call; + ctx = vq->call_ctx; + vq->call = eventfp; + vq->call_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_ERR : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp))
drivers/vhost/vhost.c line 367
Quoted 10 lines
drivers/vhost/vhost.c new file +10
-0+return PTR_ERR (eventfp); +if (eventfp != vq->error) { + filep = vq->error; + vq->error = eventfp; + ctx = vq->error_ctx; + vq->error_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ;
I'm not sure how these eventfd's save a trip to userspace.
AFAICT, eventfd's cannot be used to signal another part of the kernel, they can only be used to wake up userspace.
In my system, when an IRQ for kick() comes in, I have an eventfd which gets signalled to notify userspace. When I want to send a call(), I have to use a special ioctl(), just like lguest does.
Doesn't this mean that for call(), vhost is just going to signal an eventfd to wake up userspace, which is then going to call ioctl(), and then we're back in kernelspace. Seems like a wasted userspace round-trip.
Or am I mis-reading this code?
PS - you can see my current code at:
http://www.mmarray.org/~iws/virtio-phys/
Thanks,
Ira
Quoted 586 lines
drivers/vhost/vhost.c new file +321
-0+default : + r = -ENOIOCTLCMD ; + } + +if (pollstop && vq->handle_kick) +vhost_poll_stop (&vq->poll); + +if (ctx) +eventfd_ctx_put (ctx); +if (filep) +fput (filep); + +if (pollstart && vq->handle_kick) +vhost_poll_start (&vq->poll, vq->kick); + +mutex_unlock (&vq->mutex); + +if (pollstop && vq->handle_kick) +vhost_poll_flush (&vq->poll); +return 0 ; +} + +long vhost_dev_ioctl (struct vhost_dev *d,unsigned int ioctl,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +long r; + +mutex_lock (&d->mutex); +/* If you are not the owner, you can become one */ +if (ioctl ==VHOST_SET_OWNER ) { + r =vhost_dev_set_owner (d); + goto done; + } + +/* You must be the owner to do anything else */ + r =vhost_dev_check_owner (d); +if (r) + goto done; + +switch (ioctl) { +case VHOST_SET_MEM_TABLE : + r =vhost_set_memory (d, argp); +break ; +default : + r =vhost_set_vring (d, ioctl, argp); +break ; + } +done: +mutex_unlock (&d->mutex); +return r; +} + +static const struct vhost_memory_region *find_region (struct vhost_memory *mem, +__u64 addr,__u32 len) +{ +struct vhost_memory_region *reg; +int i; +/* linear search is not brilliant, but we really have on the order of 6 +* regions in practice */ +for (i =0 ; i < mem->nregions; ++i) { + reg = mem->regions + i; +if (reg->guest_phys_addr <= addr && + reg->guest_phys_addr + reg->memory_size -1 >= addr) +return reg; + } +return NULL ; +} + +int translate_desc (struct vhost_dev *dev,u64 addr,u32 len, +struct iovec iov[],int iov_size) +{ +const struct vhost_memory_region *reg; +struct vhost_memory *mem; +struct iovec *_iov; +u64 s =0 ; +int ret =0 ; + +rcu_read_lock (); + + mem =rcu_dereference (dev->memory); +while ((u64 )len > s) { +u64 size; +if (ret >= iov_size) { + ret = -ENOBUFS ; +break ; + } + reg =find_region (mem, addr, len); +if (!reg) { + ret = -EFAULT ; +break ; + } + _iov = iov + ret; + size = reg->memory_size - addr + reg->guest_phys_addr; + _iov->iov_len =min ((u64 )len, size); + _iov->iov_base = (void *) + (reg->userspace_addr + addr - reg->guest_phys_addr); + s += size; + addr += size; + ++ret; + } + +rcu_read_unlock (); +return ret; +} + +/* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. */ +static unsigned next_desc (struct vhost_virtqueue *vq,struct vring_desc *desc) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc->flags &VRING_DESC_F_NEXT )) +return vq->num; + +/* Check they're not leading us off end of descriptors. */ + next = desc->next; +/* Make sure compiler knows to grab that: we don't want it changing! */ +/* We will use the result as an index in an array, so most +* architectures only need a compiler barrier here. */ +read_barrier_depends (); + +if (next >= vq->num) { +vq_err (vq,"Desc next is %u > %u" , next, vq->num); +return vq->num; + } + +return next; +} + +/* This looks in the virtqueue and for the first available buffer, and converts +* it to an iovec for convenient access. Since descriptors consist of some +* number of output then some number of input descriptors, it's actually two +* iovecs, but we pack them into one and note how many of each there were. +* +* This function returns the descriptor number found, or vq->num (which +* is never a valid descriptor number) if none was found. */ +unsigned vhost_get_vq_desc (struct vhost_dev *dev,struct vhost_virtqueue *vq, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head; +u16 last_avail_idx; +int ret; + +/* Check it isn't doing very strange things with descriptor numbers. */ + last_avail_idx = vq->last_avail_idx; +if (get_user (vq->avail_idx, &vq->avail->idx)) { +vq_err (vq,"Failed to access avail idx at %p\n" , + &vq->avail->idx); +return vq->num; + } + +if ((u16)(vq->avail_idx - last_avail_idx) > vq->num) { +vq_err (vq,"Guest moved used index from %u to %u" , + last_avail_idx, vq->avail_idx); +return vq->num; + } + +/* If there's nothing new since last we looked, return invalid. */ +if (vq->avail_idx == last_avail_idx) +return vq->num; + +/* Grab the next descriptor number they're advertising, and increment +* the index we've seen. */ +if (get_user (head, &vq->avail->ring[last_avail_idx % vq->num])) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return vq->num; + } + +/* If their number is silly, that's an error. */ +if (head >= vq->num) { +vq_err (vq,"Guest says index %u > %u is available" , + head, vq->num); +return vq->num; + } + + vq->last_avail_idx++; + +/* When we start there are none of either input nor output. */ + *out_num = *in_num =0 ; + + i = head; +do { +unsigned iov_count = *in_num + *out_num; +if (copy_from_user (&desc, vq->desc + i,sizeof desc)) { +vq_err (vq,"Failed to get descriptor: idx %d addr %p\n" , + i, vq->desc + i); +return vq->num; + } + ret =translate_desc (dev, desc.addr, desc.len, iov + iov_count, +VHOST_NET_MAX_SG - iov_count); +if (ret <0 ) { +vq_err (vq,"Translation failure %d descriptor idx %d\n" , + ret, i); +return vq->num; + } +/* If this is an input descriptor, increment that count. */ +if (desc.flags &VRING_DESC_F_WRITE ) + *in_num += ret; +else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (*in_num) { +vq_err (vq,"Descriptor has out after in: " +"idx %d\n" , i); +return vq->num; + } + *out_num += ret; + } + }while ((i =next_desc (vq, &desc)) != vq->num); +return head; +} + +/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ +void vhost_discard_vq_desc (struct vhost_virtqueue *vq) +{ + vq->last_avail_idx--; +} + +/* After we've used one of their buffers, we tell them about it. We'll then +* want to send them an interrupt, using vq->call. */ +int vhost_add_used (struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +struct vring_used_elem *used; + +/* The virtqueue contains a ring of used buffers. Get a pointer to the +* next entry in that used ring. */ + used = &vq->used->ring[vq->last_used_idx % vq->num]; +if (put_user (head, &used->id)) { +vq_err (vq,"Failed to write used id" ); +return -EFAULT ; + } +if (put_user (len, &used->len)) { +vq_err (vq,"Failed to write used len" ); +return -EFAULT ; + } +/* Make sure buffer is written before we update index. */ +wmb (); +if (put_user (vq->last_used_idx +1 , &vq->used->idx)) { +vq_err (vq,"Failed to increment used idx" ); +return -EFAULT ; + } + vq->last_used_idx++; +return 0 ; +} + +/* This actually sends the interrupt for this virtqueue */ +void vhost_trigger_irq (struct vhost_dev *dev,struct vhost_virtqueue *vq) +{ +__u16 flags =0 ; +if (get_user (flags, &vq->avail->flags)) { +vq_err (vq,"Failed to get flags" ); +return ; + } + +/* If they don't want an interrupt, don't send one, unless empty. */ +if ((flags &VRING_AVAIL_F_NO_INTERRUPT ) && + (!vhost_has_feature (dev,VIRTIO_F_NOTIFY_ON_EMPTY ) || + vq->avail_idx != vq->last_avail_idx)) +return ; + +/* Send the Guest an interrupt tell them we used something up. */ +if (vq->call_ctx) +eventfd_signal (vq->call_ctx,1 ); +} + +/* And here's the combo meal deal. Supersize me! */ +void vhost_add_used_and_trigger (struct vhost_dev *dev, +struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +vhost_add_used (vq, head, len); +vhost_trigger_irq (dev, vq); +} + +/* OK, now we need to know about added descriptors. */ +bool vhost_notify (struct vhost_virtqueue *vq) +{ +int r; +if (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )) +return false; + vq->used_flags &= ~VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to disable notification: %d\n" , r); +/* They could have slipped one in as we were doing that: make +* sure it's written, tell caller it needs to check again. */ +mb (); +return true; +} + +/* We don't need to be notified again. */ +void vhost_no_notify (struct vhost_virtqueue *vq) +{ +int r; +if (vq->used_flags &VRING_USED_F_NO_NOTIFY ) +return ; + vq->used_flags |=VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to enable notification: %d\n" , r); +} + +int vhost_init (void ) +{ + vhost_workqueue =create_workqueue ("vhost" ); +if (!vhost_workqueue) +return -ENOMEM ; +return 0 ; +} + +void vhost_cleanup (void ) +{ +destroy_workqueue (vhost_workqueue); +}drivers/vhost/vhost.h new file +122
-0@@ -0,0 +1,122 @@ +#ifndef _VHOST_H +#define _VHOST_H + +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/mm.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/poll.h> +#include <linux/file.h> +#include <linux/skbuff.h> +#include <linux/uio.h> +#include <linux/virtio_config.h> + +struct vhost_device ; + +enum { +VHOST_NET_MAX_SG =MAX_SKB_FRAGS +2 , +}; + +/* Poll a file (eventfd or socket) */ +/* Note: there's nothing vhost specific about this structure. */ +struct vhost_poll { +poll_table table; +wait_queue_head_t *wqh; +wait_queue_t wait; +/* struct which will handle all actual work. */ +struct work_struct work; +unsigned long mask; +}; + +void vhost_poll_init (struct vhost_poll *poll,work_func_t func, +unsigned long mask); +void vhost_poll_start (struct vhost_poll *poll,struct file *file); +void vhost_poll_stop (struct vhost_poll *poll); +void vhost_poll_flush (struct vhost_poll *poll); + +/* The virtqueue structure describes a queue attached to a device. */ +struct vhost_virtqueue { +struct vhost_dev *dev; + +/* The actual ring of buffers. */ +struct mutex mutex; +unsigned int num; +struct vring_desc __user *desc; +struct vring_avail __user *avail; +struct vring_used __user *used; +struct file *kick; +struct file *call; +struct file *error; +struct eventfd_ctx *call_ctx; +struct eventfd_ctx *error_ctx; + +struct vhost_poll poll; + +/* The routine to call when the Guest pings us, or timeout. */ +work_func_t handle_kick; + +/* Last available index we saw. */ +u16 last_avail_idx; + +/* Caches available index value from user. */ +u16 avail_idx; + +/* Last index we used. */ +u16 last_used_idx; + +/* Used flags */ +u16 used_flags; + +struct iovec iov[VHOST_NET_MAX_SG ]; +struct iovec hdr[VHOST_NET_MAX_SG ]; +}; + +struct vhost_dev { +/* Readers use RCU to access memory table pointer. +* Writers use mutex below.*/ +struct vhost_memory *memory; +struct mm_struct *mm; +struct vhost_virtqueue *vqs; +int nvqs; +struct mutex mutex; +unsigned acked_features; +}; + +long vhost_dev_init (struct vhost_dev *,struct vhost_virtqueue *vqs,int nvqs); +long vhost_dev_check_owner (struct vhost_dev *); +long vhost_dev_reset_owner (struct vhost_dev *); +void vhost_dev_cleanup (struct vhost_dev *); +long vhost_dev_ioctl (struct vhost_dev *,unsigned int ioctl,unsigned long arg); + +unsigned vhost_get_vq_desc (struct vhost_dev *,struct vhost_virtqueue *, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num); +void vhost_discard_vq_desc (struct vhost_virtqueue *); + +int vhost_add_used (struct vhost_virtqueue *,unsigned int head,int len); +void vhost_trigger_irq (struct vhost_dev *,struct vhost_virtqueue *); +void vhost_add_used_and_trigger (struct vhost_dev *,struct vhost_virtqueue *, +unsigned int head,int len); +void vhost_no_notify (struct vhost_virtqueue *); +bool vhost_notify (struct vhost_virtqueue *); + +int vhost_init (void ); +void vhost_cleanup (void ); + +#define vq_err (vq, fmt, ...) do { \ + pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ + if ((vq)->error_ctx) \ + eventfd_signal((vq)->error_ctx, 1);\ + } while (0) + +enum { +VHOST_FEATURES =1 <<VIRTIO_F_NOTIFY_ON_EMPTY , +}; + +static inline int vhost_has_feature (struct vhost_dev *dev,int bit) +{ +return dev->acked_features & (1 << bit); +} + +#endif include/linux/Kbuild +1
-0@@ -360,6 +360,7 @@ unifdef-y += uio.h unifdef-y += unistd.h unifdef-y += usbdevice_fs.h unifdef-y += utsname.h +unifdef-y += vhost.h unifdef-y += videodev2.h unifdef-y += videodev.h unifdef-y += virtio_config.hinclude/linux/miscdevice.h +1
-0@@ -30,6 +30,7 @@#define HPET_MINOR 228#define FUSE_MINOR 229#define KVM_MINOR 232 +#define VHOST_NET_MINOR 233#define MISC_DYNAMIC_MINOR 255struct device ;include/linux/vhost.h new file +101
-0@@ -0,0 +1,101 @@ +#ifndef _LINUX_VHOST_H +#define _LINUX_VHOST_H +/* Userspace interface for in-kernel virtio accelerators. */ + +/* vhost is used to reduce the number of system calls involved in virtio. +* +* Existing virtio net code is used in the guest without modification. +* +* This header includes interface used by userspace hypervisor for +* device configuration. +*/ + +#include <linux/types.h> +#include <linux/compiler.h> +#include <linux/ioctl.h> +#include <linux/virtio_config.h> +#include <linux/virtio_ring.h> + +struct vhost_vring_state { +unsigned int index; +unsigned int num; +}; + +struct vhost_vring_file { +unsigned int index; +int fd; +}; + +struct vhost_vring_addr { +unsigned int index; +unsigned int padding; +__u64 user_addr; +}; + +struct vhost_memory_region { +__u64 guest_phys_addr; +__u64 memory_size;/* bytes */ +__u64 userspace_addr; +__u64 padding;/* read/write protection? */ +}; + +struct vhost_memory { +__u32 nregions; +__u32 padding; +struct vhost_memory_region regions[0 ]; +}; + +/* ioctls */ + +#define VHOST_VIRTIO 0xAF + +/* Features bitmask for forward compatibility. Transport bits are used for +* vhost specific features. */ +#define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) +#define VHOST_ACK_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) + +/* Set current process as the (exclusive) owner of this file descriptor. This +* must be called before any other vhost command. Further calls to +* VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ +#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) +/* Give up ownership, and reset the device to default values. +* Allows subsequent call to VHOST_OWNER_SET to succeed. */ +#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) + +/* Set up/modify memory layout */ +#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) + +/* Ring setup. These parameters can not be modified while ring is running +* (bound to a device). */ +/* Set number of descriptors in ring */ +#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) +/* Start of array of descriptors (virtually contiguous) */ +#define VHOST_SET_VRING_DESC _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) +/* Used structure address */ +#define VHOST_SET_VRING_USED _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_addr) +/* Available structure address */ +#define VHOST_SET_VRING_AVAIL _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_addr) +/* Base value where queue looks for available descriptors */ +#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) +/* Get accessor: reads index, writes value in num */ +#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x14, struct vhost_vring_state) + +/* The following ioctls use eventfd file descriptors to signal and poll +* for events. */ + +/* Set eventfd to poll for added buffers */ +#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) +/* Set eventfd to signal when buffers have beed used */ +#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) +/* Set eventfd to signal an error */ +#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) + +/* VHOST_NET specific defines */ + +/* Attach virtio net device to a raw socket. The socket must be already +* bound to an ethernet device, this device will be used for transmit. +* Pass -1 to unbind from the socket and the transmit device. +* This can be used to stop the device (e.g. for migration). */ +#define VHOST_NET_SET_SOCKET _IOW(VHOST_VIRTIO, 0x30, int) + +#endif Signature · 5 lines
1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Michael S. TsirkinQuoted 974 lines · Michael S. Tsirkin
What it is: vhost net is a character device that can be used to reduce the number of system calls involved in virtio networking. Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for migration)
- support memory table and not just an offset (needed for kvm)common virtio related code has been put in a separate file
vhost.cand can be made into a separate module if/when more backends appear. I used Rusty'slguest.cas the source for developing this part : this supplied me with witty comments I wouldn't be able to write myself.What it is not: vhost net is not a bus, and not a generic new system call. No assumptions are made on how guest performs hypercalls. Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by userspace) to a backend. The backend could be a network device, or a tun-like device. In this version I only support raw socket as a backend, which can be bound to e.g. SR IOV, or to macvlan device. Backend is also configured by userspace, including vlan/mac etc.
Status:
This works for me, and I haven't see any crashes.
I have done some light benchmarking (with v4), compared to userspace, I see improved latency (as I save up to 4 system calls per packet) but not bandwidth/CPU (as TSO and interrupt mitigation are not supported). For ping benchmark (where there's no TSO) troughput is also improved.Features that I plan to look at in the future:
- tap support
- TSO
- interrupt mitigation
- zero copyAcked-by Arnd Bergmann <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- MAINTAINERS | 10 + arch/x86/kvm/Kconfig | 1 + drivers/Makefile | 1 + drivers/vhost/Kconfig | 11 + drivers/vhost/Makefile | 2 + drivers/vhost/net.c | 475 ++++++++++++++++++++++++++++++ drivers/vhost/vhost.c | 688 ++++++++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.h | 122 ++++++++ include/linux/Kbuild | 1 + include/linux/miscdevice.h | 1 + include/linux/vhost.h | 101 +++++++ 11 files changed, 1413 insertions(+), 0 deletions(-) create mode 100644 drivers/vhost/Kconfig create mode 100644 drivers/vhost/Makefile create mode 100644 drivers/vhost/net.c create mode 100644 drivers/vhost/vhost.c create mode 100644 drivers/vhost/vhost.h create mode 100644 include/linux/vhost.hMAINTAINERS +10
-0@@ -5431,6 +5431,16 @@ S: Maintained F: Documentation/filesystems/vfat.txt F: fs/fat/ +VIRTIO HOST (VHOST) +P: Michael S. Tsirkin +M: [email protected] +L: [email protected] +L: [email protected] +L: [email protected] +S: Maintained +F: drivers/vhost/ +F: include/linux/vhost.h + VIA RHINE NETWORK DRIVER M: Roger Luethi <[email protected]> S: Maintainedarch/x86/kvm/Kconfig +1
-0@@ -64,6 +64,7 @@ config KVM_AMD # OK, it's a little counter-intuitive to do this, but it puts it neatly under # the virtualization menu. +source drivers/vhost/Kconfig source drivers/lguest/Kconfig source drivers/virtio/Kconfigdrivers/Makefile +1
-0@@ -105,6 +105,7 @@ obj-$(CONFIG_HID) += hid/ obj-$(CONFIG_PPC_PS3) += ps3/ obj-$(CONFIG_OF) += of/ obj-$(CONFIG_SSB) += ssb/ +obj-$(CONFIG_VHOST_NET) += vhost/ obj-$(CONFIG_VIRTIO) += virtio/ obj-$(CONFIG_VLYNQ) += vlynq/ obj-$(CONFIG_STAGING) += staging/drivers/vhost/Kconfig new file +11
-0@@ -0,0 +1,11 @@ +config VHOST_NET + tristate "Host kernel accelerator for virtio net" + depends on NET && EVENTFD + ---help--- + This kernel module can be loaded in host kernel to accelerate + guest networking with virtio_net. Not to be confused with virtio_net + module itself which needs to be loaded in guest kernel. + + To compile this driver as a module, choose M here: the module will + be called vhost_net. +drivers/vhost/Makefile new file +2
-0@@ -0,0 +1,2 @@ +obj-$(CONFIG_VHOST_NET) += vhost_net.o +vhost_net-y := vhost.o net.odrivers/vhost/net.c new file +475
-0@@ -0,0 +1,475 @@ +/* Copyright (C) 2009 Red Hat, Inc. +* Author: Michael S. Tsirkin <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. +* +* virtio-net server in host kernel. +*/ + +#include <linux/compat.h> +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <linux/mmu_context.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/rcupdate.h> +#include <linux/file.h> + +#include <linux/net.h> +#include <linux/if_packet.h> +#include <linux/if_arp.h> + +#include <net/sock.h> + +#include "vhost.h" + +enum { +VHOST_NET_VQ_RX =0 , +VHOST_NET_VQ_TX =1 , +VHOST_NET_VQ_MAX =2 , +}; + +struct vhost_net { +struct vhost_dev dev; +struct vhost_virtqueue vqs[VHOST_NET_VQ_MAX ]; +/* We use a kind of RCU to access sock pointer. +* All readers access it from workqueue, which makes it possible to +* flush the workqueue instead of synchronize_rcu. Therefore readers do +* not need to call rcu_read_lock/rcu_read_unlock: the beginning of +* work item execution acts instead of rcu_read_lock() and the end of +* work item execution acts instead of rcu_read_lock(). +* Writers use device mutex. */ +struct socket *sock; +struct vhost_poll poll[VHOST_NET_VQ_MAX ]; +}; + +/* Pop first len bytes from iovec. Return number of segments used. */ +static int move_iovec_hdr (struct iovec *from,struct iovec *to, +size_t len,int iov_count) +{ +int seg =0 ; +size_t size; +while (len && seg < iov_count) { + size =min (from->iov_len, len); + to->iov_base = from->iov_base; + to->iov_len = size; + from->iov_len -= size; + from->iov_base += size; + len -= size; + ++from; + ++to; + ++seg; + } +return seg; +} + +/* Expects to be always run from workqueue - which acts as +* read-size critical section for our kind of RCU. */ +static void handle_tx (struct vhost_net *net) +{ +struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_TX ]; +unsigned head, out, in, s; +struct msghdr msg = { + .msg_name =NULL , + .msg_namelen =0 , + .msg_control =NULL , + .msg_controllen =0 , + .msg_iov = vq->iov, + .msg_flags =MSG_DONTWAIT , + }; +size_t len; +int err; +struct socket *sock =rcu_dereference (net->sock); +if (!sock || !sock_writeable (sock->sk)) +return ; + +use_mm (net->dev.mm); +mutex_lock (&vq->mutex); +for (;;) { + head =vhost_get_vq_desc (&net->dev, vq, vq->iov, &out, &in); +/* Nothing new? Wait for eventfd to tell us they refilled. */ +if (head == vq->num) +break ; +if (in) { +vq_err (vq,"Unexpected descriptor format for TX: " +"out %d, int %d\n" , out, in); +break ; + } +/* Skip header. TODO: support TSO. */ + s =move_iovec_hdr (vq->iov, vq->hdr, +sizeof (struct virtio_net_hdr ), out); + msg.msg_iovlen = out; + len =iov_length (vq->iov, out); +/* Sanity check */ +if (!len) { +vq_err (vq,"Unexpected header len for TX: " +"%ld expected %zd\n" , +iov_length (vq->hdr, s), +sizeof (struct virtio_net_hdr )); +break ; + } +/* TODO: Check specific error and bomb out unless ENOBUFS? */ + err = sock->ops->sendmsg (NULL , sock, &msg, len); +if (err <0 ) { +vhost_discard_vq_desc (vq); +break ; + } +if (err != len) +pr_err ("Truncated TX packet: " +" len %d != %zd\n" , err, len); +vhost_add_used_and_trigger (&net->dev, vq, head,0 ); + } + +mutex_unlock (&vq->mutex); +unuse_mm (net->dev.mm); +} + +/* Expects to be always run from workqueue - which acts as +* read-size critical section for our kind of RCU. */ +static void handle_rx (struct vhost_net *net) +{ +struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_RX ]; +unsigned head, out, in, s; +struct msghdr msg = { + .msg_name =NULL , + .msg_namelen =0 , + .msg_control =NULL ,/* FIXME: get and handle RX aux data. */ + .msg_controllen =0 , + .msg_iov = vq->iov, + .msg_flags =MSG_DONTWAIT , + }; + +struct virtio_net_hdr hdr = { + .flags =0 , + .gso_type =VIRTIO_NET_HDR_GSO_NONE + }; + +size_t len; +int err; +struct socket *sock =rcu_dereference (net->sock); +if (!sock ||skb_queue_empty (&sock->sk->sk_receive_queue)) +return ; + +use_mm (net->dev.mm); +mutex_lock (&vq->mutex); +vhost_no_notify (vq); + +for (;;) { + head =vhost_get_vq_desc (&net->dev, vq, vq->iov, &out, &in); +/* OK, now we need to know about added descriptors. */ +if (head == vq->num &&vhost_notify (vq)) +/* They could have slipped one in as we were doing that: +* check again. */ +continue ; +/* Nothing new? Wait for eventfd to tell us they refilled. */ +if (head == vq->num) +break ; +/* We don't need to be notified again. */ +vhost_no_notify (vq); +if (out) { +vq_err (vq,"Unexpected descriptor format for RX: " +"out %d, int %d\n" , + out, in); +break ; + } +/* Skip header. TODO: support TSO/mergeable rx buffers. */ + s =move_iovec_hdr (vq->iov, vq->hdr,sizeof hdr, in); + msg.msg_iovlen = in; + len =iov_length (vq->iov, in); +/* Sanity check */ +if (!len) { +vq_err (vq,"Unexpected header len for RX: " +"%zd expected %zd\n" , +iov_length (vq->hdr, s),sizeof hdr); +break ; + } + err = sock->ops->recvmsg (NULL , sock, &msg, + len,MSG_DONTWAIT |MSG_TRUNC ); +/* TODO: Check specific error and bomb out unless EAGAIN? */ +if (err <0 ) { +vhost_discard_vq_desc (vq); +break ; + } +/* TODO: Should check and handle checksum. */ +if (err > len) { +pr_err ("Discarded truncated rx packet: " +" len %d > %zd\n" , err, len); +vhost_discard_vq_desc (vq); +continue ; + } + len = err; + err =memcpy_toiovec (vq->hdr, (unsigned char *)&hdr,sizeof hdr); +if (err) { +vq_err (vq,"Unable to write vnet_hdr at addr %p: %d\n" , + vq->iov->iov_base, err); +break ; + } +vhost_add_used_and_trigger (&net->dev, vq, head, + len +sizeof hdr); + } + +mutex_unlock (&vq->mutex); +unuse_mm (net->dev.mm); +} + +static void handle_tx_kick (struct work_struct *work) +{ +struct vhost_virtqueue *vq; +struct vhost_net *net; + vq = container_of(work, struct vhost_virtqueue, poll.work); + net = container_of(vq->dev, struct vhost_net, dev); +handle_tx (net); +} + +static void handle_rx_kick (struct work_struct *work) +{ +struct vhost_virtqueue *vq; +struct vhost_net *net; + vq = container_of(work, struct vhost_virtqueue, poll.work); + net = container_of(vq->dev, struct vhost_net, dev); +handle_rx (net); +} + +static void handle_tx_net (struct work_struct *work) +{ +struct vhost_net *net; + net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_TX].work); +handle_tx (net); +} + +static void handle_rx_net (struct work_struct *work) +{ +struct vhost_net *net; + net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_RX].work); +handle_rx (net); +} + +static int vhost_net_open (struct inode *inode,struct file *f) +{ +struct vhost_net *n =kzalloc (sizeof *n,GFP_KERNEL ); +int r; +if (!n) +return -ENOMEM ; + f->private_data = n; + n->vqs[VHOST_NET_VQ_TX ].handle_kick = handle_tx_kick; + n->vqs[VHOST_NET_VQ_RX ].handle_kick = handle_rx_kick; + r =vhost_dev_init (&n->dev, n->vqs,VHOST_NET_VQ_MAX ); +if (r <0 ) { +kfree (n); +return r; + } + +vhost_poll_init (n->poll +VHOST_NET_VQ_TX , handle_tx_net,POLLOUT ); +vhost_poll_init (n->poll +VHOST_NET_VQ_RX , handle_rx_net,POLLIN ); +return 0 ; +} + +static struct socket *vhost_net_stop (struct vhost_net *n) +{ +struct socket *sock = n->sock; +rcu_assign_pointer (n->sock,NULL ); +if (sock) { +vhost_poll_flush (n->poll +VHOST_NET_VQ_TX ); +vhost_poll_flush (n->poll +VHOST_NET_VQ_RX ); + } +return sock; +} + +static int vhost_net_release (struct inode *inode,struct file *f) +{ +struct vhost_net *n = f->private_data; +struct socket *sock; + + sock =vhost_net_stop (n); +vhost_dev_cleanup (&n->dev); +if (sock) +fput (sock->file); +kfree (n); +return 0 ; +} + +static void vhost_net_flush (struct vhost_net *n) +{ +vhost_poll_flush (n->poll +VHOST_NET_VQ_TX ); +vhost_poll_flush (n->poll +VHOST_NET_VQ_RX ); +vhost_poll_flush (&n->dev.vqs[VHOST_NET_VQ_TX ].poll); +vhost_poll_flush (&n->dev.vqs[VHOST_NET_VQ_RX ].poll); +} + +static long vhost_net_set_socket (struct vhost_net *n,int fd) +{ +struct { +struct sockaddr_ll sa; +char buf[MAX_ADDR_LEN ]; + } uaddr; +struct socket *sock, *oldsock =NULL ; +int uaddr_len =sizeof uaddr, r; + +mutex_lock (&n->dev.mutex); + r =vhost_dev_check_owner (&n->dev); +if (r) + goto done; + +if (fd ==-1 ) { +/* Disconnect from socket and device. */ + oldsock =vhost_net_stop (n); + goto done; + } + + sock =sockfd_lookup (fd, &r); +if (!sock) { + r = -ENOTSOCK ; + goto done; + } + +/* Parameter checking */ +if (sock->sk->sk_type !=SOCK_RAW ) { + r = -ESOCKTNOSUPPORT ; + goto done; + } + + r = sock->ops->getname (sock, (struct sockaddr *)&uaddr.sa, + &uaddr_len,0 ); +if (r) + goto done; + +if (uaddr.sa.sll_family !=AF_PACKET ) { + r = -EPFNOSUPPORT ; + goto done; + } + +/* start polling new socket */ +if (sock == oldsock) + goto done; + +if (oldsock) { +vhost_poll_stop (n->poll +VHOST_NET_VQ_TX ); +vhost_poll_stop (n->poll +VHOST_NET_VQ_RX ); + } + oldsock = n->sock; +rcu_assign_pointer (n->sock, sock); +vhost_poll_start (n->poll +VHOST_NET_VQ_TX , sock->file); +vhost_poll_start (n->poll +VHOST_NET_VQ_RX , sock->file); +done: +mutex_unlock (&n->dev.mutex); +if (oldsock) { +vhost_net_flush (n); +fput (oldsock->file); + } +return r; +} + +static long vhost_net_reset_owner (struct vhost_net *n) +{ +struct socket *sock =NULL ; +long r; +mutex_lock (&n->dev.mutex); + r =vhost_dev_check_owner (&n->dev); +if (r) + goto done; + sock =vhost_net_stop (n); + r =vhost_dev_reset_owner (&n->dev); +done: +mutex_unlock (&n->dev.mutex); +if (sock) +fput (sock->file); +return r; +} + +static void vhost_net_set_features (struct vhost_net *n,u64 features) +{ +mutex_unlock (&n->dev.mutex); + n->dev.acked_features = features; +mutex_unlock (&n->dev.mutex); +vhost_net_flush (n); +} + +static long vhost_net_ioctl (struct file *f,unsigned int ioctl, +unsigned long arg) +{ +struct vhost_net *n = f->private_data; +void __user *argp = (void __user *)arg; +u32 __user *featurep = argp; +int __user *fdp = argp; +u64 features; +int fd, r; +switch (ioctl) { +case VHOST_NET_SET_SOCKET : + r =get_user (fd, fdp); +if (r <0 ) +return r; +return vhost_net_set_socket (n, fd); +case VHOST_GET_FEATURES : + features =VHOST_FEATURES ; +return put_user (features, featurep); +case VHOST_ACK_FEATURES : + r =get_user (features, featurep); +/* No features for now */ +if (r <0 ) +return r; +if (features & ~VHOST_FEATURES ) +return -EOPNOTSUPP ; +vhost_net_set_features (n, features); +return 0 ; +case VHOST_RESET_OWNER : +return vhost_net_reset_owner (n); +default : +return vhost_dev_ioctl (&n->dev, ioctl, arg); + } +} + +#ifdef CONFIG_COMPAT +static long vhost_net_compat_ioctl (struct file *f,unsigned int ioctl, +unsigned long arg) +{ +return vhost_net_ioctl (f, ioctl, (unsigned long )compat_ptr (arg)); +} +#endif + +const static struct file_operations vhost_net_fops = { + .owner =THIS_MODULE , + .release = vhost_net_release, + .unlocked_ioctl = vhost_net_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = vhost_net_compat_ioctl, +#endif + .open = vhost_net_open, +}; + +static struct miscdevice vhost_net_misc = { +VHOST_NET_MINOR , +"vhost-net" , + &vhost_net_fops, +}; + +int vhost_net_init (void ) +{ +int r =vhost_init (); +if (r) + goto err_init; + r =misc_register (&vhost_net_misc); +if (r) + goto err_reg; +return 0 ; +err_reg: +vhost_cleanup (); +err_init: +return r; + +} +module_init (vhost_net_init); + +void vhost_net_exit (void ) +{ +misc_deregister (&vhost_net_misc); +vhost_cleanup (); +} +module_exit (vhost_net_exit); + +MODULE_VERSION ("0.0.1" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Michael S. Tsirkin" ); +MODULE_DESCRIPTION ("Host kernel accelerator for virtio net" );drivers/vhost/vhost.c new file +357
-0@@ -0,0 +1,688 @@ +/* Copyright (C) 2009 Red Hat, Inc. +* Copyright (C) 2006 Rusty Russell IBM Corporation +* +* Author: Michael S. Tsirkin <[email protected]> +* +* Inspiration, some code, and most witty comments come from +* Documentation/lguest/lguest.c, by Rusty Russell +* +* This work is licensed under the terms of the GNU GPL, version 2. +* +* Generic code for virtio server in host kernel. +*/ + +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/virtio_net.h> +#include <linux/mm.h> +#include <linux/miscdevice.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/rcupdate.h> +#include <linux/poll.h> +#include <linux/file.h> + +#include <linux/net.h> +#include <linux/if_packet.h> +#include <linux/if_arp.h> + +#include <net/sock.h> + +#include "vhost.h" + +enum { +VHOST_MEMORY_MAX_NREGIONS =64 , +}; + +static struct workqueue_struct *vhost_workqueue; + +static void vhost_poll_func (struct file *file,wait_queue_head_t *wqh, +poll_table *pt) +{ +struct vhost_poll *poll; + poll = container_of(pt, struct vhost_poll, table); + + poll->wqh = wqh; +add_wait_queue (wqh, &poll->wait); +} + +static int vhost_poll_wakeup (wait_queue_t *wait,unsigned mode,int sync, +void *key) +{ +struct vhost_poll *poll; + poll = container_of(wait, struct vhost_poll, wait); +if (!((unsigned long )key & poll->mask)) +return 0 ; + +queue_work (vhost_workqueue, &poll->work); +return 0 ; +} + +/* Init poll structure */ +void vhost_poll_init (struct vhost_poll *poll,work_func_t func, +unsigned long mask) +{ +INIT_WORK (&poll->work, func); +init_waitqueue_func_entry (&poll->wait, vhost_poll_wakeup); +init_poll_funcptr (&poll->table, vhost_poll_func); + poll->mask = mask; +} + +/* Start polling a file. We add ourselves to file's wait queue. The caller must +* keep a reference to a file until after vhost_poll_stop is called. */ +void vhost_poll_start (struct vhost_poll *poll,struct file *file) +{ +unsigned long mask; + mask = file->f_op->poll (file, &poll->table); +if (mask) +vhost_poll_wakeup (&poll->wait,0 ,0 , (void *)mask); +} + +/* Stop polling a file. After this function returns, it becomes safe to drop the +* file reference. You must also flush afterwards. */ +void vhost_poll_stop (struct vhost_poll *poll) +{ +remove_wait_queue (poll->wqh, &poll->wait); +} + +/* Flush any work that has been scheduled. When calling this, don't hold any +* locks that are also used by the callback. */ +void vhost_poll_flush (struct vhost_poll *poll) +{ +flush_work (&poll->work); +} + +long vhost_dev_init (struct vhost_dev *dev, +struct vhost_virtqueue *vqs,int nvqs) +{ +int i; + dev->vqs = vqs; + dev->nvqs = nvqs; +mutex_init (&dev->mutex); + +for (i =0 ; i < dev->nvqs; ++i) { + dev->vqs[i].dev = dev; +mutex_init (&dev->vqs[i].mutex); +if (dev->vqs[i].handle_kick) +vhost_poll_init (&dev->vqs[i].poll, + dev->vqs[i].handle_kick, +POLLIN ); + } +return 0 ; +} + +/* Caller should have device mutex */ +long vhost_dev_check_owner (struct vhost_dev *dev) +{ +/* Are you the owner? If not, I don't think you mean to do that */ +return dev->mm == current->mm ?0 : -EPERM ; +} + +/* Caller should have device mutex */ +static long vhost_dev_set_owner (struct vhost_dev *dev) +{ +/* Is there an owner already? */ +if (dev->mm) +return -EBUSY ; +/* No owner, become one */ + dev->mm =get_task_mm (current); +return 0 ; +} + +/* Caller should have device mutex */ +long vhost_dev_reset_owner (struct vhost_dev *dev) +{ +struct vhost_memory *memory; + +/* Restore memory to default 1:1 mapping. */ + memory =kmalloc (offsetof(struct vhost_memory , regions) + +2 *sizeof *memory->regions,GFP_KERNEL ); +if (!memory) +return -ENOMEM ; + +vhost_dev_cleanup (dev); + + memory->nregions =2 ; + memory->regions[0 ].guest_phys_addr =1 ; + memory->regions[0 ].userspace_addr =1 ; + memory->regions[0 ].memory_size = ~0ULL ; + memory->regions[1 ].guest_phys_addr =0 ; + memory->regions[1 ].userspace_addr =0 ; + memory->regions[1 ].memory_size =1 ; + dev->memory = memory; +return 0 ; +} + +/* Caller should have device mutex */ +void vhost_dev_cleanup (struct vhost_dev *dev) +{ +int i; +for (i =0 ; i < dev->nvqs; ++i) { +if (dev->vqs[i].kick && dev->vqs[i].handle_kick) { +vhost_poll_stop (&dev->vqs[i].poll); +vhost_poll_flush (&dev->vqs[i].poll); + } +if (dev->vqs[i].error_ctx) +eventfd_ctx_put (dev->vqs[i].error_ctx); +if (dev->vqs[i].error) +fput (dev->vqs[i].error); +if (dev->vqs[i].kick) +fput (dev->vqs[i].kick); +if (dev->vqs[i].call_ctx) +eventfd_ctx_put (dev->vqs[i].call_ctx); +if (dev->vqs[i].call) +fput (dev->vqs[i].call); + dev->vqs[i].error_ctx =NULL ; + dev->vqs[i].error =NULL ; + dev->vqs[i].kick =NULL ; + dev->vqs[i].call_ctx =NULL ; + dev->vqs[i].call =NULL ; + } +/* No one will access memory at this point */ +kfree (dev->memory); + dev->memory =NULL ; +if (dev->mm) +mmput (dev->mm); + dev->mm =NULL ; +} + +static long vhost_set_memory (struct vhost_dev *d,struct vhost_memory __user *m) +{ +struct vhost_memory mem, *newmem, *oldmem; +unsigned long size = offsetof(struct vhost_memory , regions); +long r; + r =copy_from_user (&mem, m, size); +if (r) +return r; +if (mem.padding) +return -EOPNOTSUPP ; +if (mem.nregions >VHOST_MEMORY_MAX_NREGIONS ) +return -E2BIG ; + newmem =kmalloc (size + mem.nregions *sizeof *m->regions,GFP_KERNEL ); +if (!newmem) +return -ENOMEM ; + +memcpy (newmem, &mem, size); + r =copy_from_user (newmem->regions, m->regions, + mem.nregions *sizeof *m->regions); +if (r) { +kfree (newmem); +return r; + } + oldmem = d->memory; +rcu_assign_pointer (d->memory, newmem); +synchronize_rcu (); +kfree (oldmem); +return 0 ; +} + +static int init_used (struct vhost_virtqueue *vq) +{ +int r =put_user (vq->used_flags, &vq->used->flags); +if (r) +return r; +return get_user (vq->last_used_idx, &vq->used->idx); +} + +static long vhost_set_vring (struct vhost_dev *d,int ioctl,void __user *argp) +{ +struct file *eventfp, *filep =NULL , + *pollstart =NULL , *pollstop =NULL ; +struct eventfd_ctx *ctx =NULL ; +u32 __user *idxp = argp; +struct vhost_virtqueue *vq; +struct vhost_vring_state s; +struct vhost_vring_file f; +struct vhost_vring_addr a; +u32 idx; +long r; + + r =get_user (idx, idxp); +if (r <0 ) +return r; +if (idx > d->nvqs) +return -ENOBUFS ; + + vq = d->vqs + idx; + +mutex_lock (&vq->mutex); + +switch (ioctl) { +case VHOST_SET_VRING_NUM : + r =copy_from_user (&s, argp,sizeof s); +if (r <0 ) +break ; +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + } + vq->num = s.num; +break ; +case VHOST_SET_VRING_BASE : + r =copy_from_user (&s, argp,sizeof s); +if (r <0 ) +break ; +if (s.num >0xffff ) { + r = -EINVAL ; +break ; + } + vq->avail_idx = vq->last_avail_idx = s.num; +break ; +case VHOST_GET_VRING_BASE : + s.index = idx; + s.num = vq->last_avail_idx; + r =copy_to_user (argp, &s,sizeof s); +break ; +case VHOST_SET_VRING_DESC : + r =copy_from_user (&a, argp,sizeof a); +if (r <0 ) +break ; +if (a.padding) { + r = -EOPNOTSUPP ; +break ; + } +if ((u64 )(long )a.user_addr != a.user_addr) { + r = -EFAULT ; +break ; + } + vq->desc = (void __user *)(long )a.user_addr; +break ; +case VHOST_SET_VRING_AVAIL : + r =copy_from_user (&a, argp,sizeof a); +if (r <0 ) +break ; +if (a.padding) { + r = -EOPNOTSUPP ; +break ; + } +if ((u64 )(long )a.user_addr != a.user_addr) { + r = -EFAULT ; +break ; + } + vq->avail = (void __user *)(long )a.user_addr; +/* Forget the cached index value. */ + vq->avail_idx = vq->last_avail_idx; +break ; +case VHOST_SET_VRING_USED : + r =copy_from_user (&a, argp,sizeof a); +if (r <0 ) +break ; +if (a.padding) { + r = -EOPNOTSUPP ; +break ; + } +if ((u64 )(long )a.user_addr != a.user_addr) { + r = -EFAULT ; +break ; + } + vq->used = (void __user *)(long )a.user_addr; + r =init_used (vq); +if (r) +break ; +break ; +case VHOST_SET_VRING_KICK : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->kick) { + pollstop = filep = vq->kick; + pollstart = vq->kick = eventfp; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_CALL : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->call) { + filep = vq->call; + ctx = vq->call_ctx; + vq->call = eventfp; + vq->call_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_ERR : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp))
drivers/vhost/vhost.c line 367
Quoted 10 lines
drivers/vhost/vhost.c new file +10
-0+return PTR_ERR (eventfp); +if (eventfp != vq->error) { + filep = vq->error; + vq->error = eventfp; + ctx = vq->error_ctx; + vq->error_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ;
I'm not sure how these eventfd's save a trip to userspace.
AFAICT, eventfd's cannot be used to signal another part of the kernel, they can only be used to wake up userspace.
In my system, when an IRQ for kick() comes in, I have an eventfd which gets signalled to notify userspace. When I want to send a call(), I have to use a special ioctl(), just like lguest does.
Doesn't this mean that for call(), vhost is just going to signal an eventfd to wake up userspace, which is then going to call ioctl(), and then we're back in kernelspace. Seems like a wasted userspace round-trip.
Or am I mis-reading this code?
PS - you can see my current code at:
http://www.mmarray.org/~iws/virtio-phys/
Thanks,
Ira
Quoted 586 lines
drivers/vhost/vhost.c new file +321
-0+default : + r = -ENOIOCTLCMD ; + } + +if (pollstop && vq->handle_kick) +vhost_poll_stop (&vq->poll); + +if (ctx) +eventfd_ctx_put (ctx); +if (filep) +fput (filep); + +if (pollstart && vq->handle_kick) +vhost_poll_start (&vq->poll, vq->kick); + +mutex_unlock (&vq->mutex); + +if (pollstop && vq->handle_kick) +vhost_poll_flush (&vq->poll); +return 0 ; +} + +long vhost_dev_ioctl (struct vhost_dev *d,unsigned int ioctl,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +long r; + +mutex_lock (&d->mutex); +/* If you are not the owner, you can become one */ +if (ioctl ==VHOST_SET_OWNER ) { + r =vhost_dev_set_owner (d); + goto done; + } + +/* You must be the owner to do anything else */ + r =vhost_dev_check_owner (d); +if (r) + goto done; + +switch (ioctl) { +case VHOST_SET_MEM_TABLE : + r =vhost_set_memory (d, argp); +break ; +default : + r =vhost_set_vring (d, ioctl, argp); +break ; + } +done: +mutex_unlock (&d->mutex); +return r; +} + +static const struct vhost_memory_region *find_region (struct vhost_memory *mem, +__u64 addr,__u32 len) +{ +struct vhost_memory_region *reg; +int i; +/* linear search is not brilliant, but we really have on the order of 6 +* regions in practice */ +for (i =0 ; i < mem->nregions; ++i) { + reg = mem->regions + i; +if (reg->guest_phys_addr <= addr && + reg->guest_phys_addr + reg->memory_size -1 >= addr) +return reg; + } +return NULL ; +} + +int translate_desc (struct vhost_dev *dev,u64 addr,u32 len, +struct iovec iov[],int iov_size) +{ +const struct vhost_memory_region *reg; +struct vhost_memory *mem; +struct iovec *_iov; +u64 s =0 ; +int ret =0 ; + +rcu_read_lock (); + + mem =rcu_dereference (dev->memory); +while ((u64 )len > s) { +u64 size; +if (ret >= iov_size) { + ret = -ENOBUFS ; +break ; + } + reg =find_region (mem, addr, len); +if (!reg) { + ret = -EFAULT ; +break ; + } + _iov = iov + ret; + size = reg->memory_size - addr + reg->guest_phys_addr; + _iov->iov_len =min ((u64 )len, size); + _iov->iov_base = (void *) + (reg->userspace_addr + addr - reg->guest_phys_addr); + s += size; + addr += size; + ++ret; + } + +rcu_read_unlock (); +return ret; +} + +/* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. */ +static unsigned next_desc (struct vhost_virtqueue *vq,struct vring_desc *desc) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc->flags &VRING_DESC_F_NEXT )) +return vq->num; + +/* Check they're not leading us off end of descriptors. */ + next = desc->next; +/* Make sure compiler knows to grab that: we don't want it changing! */ +/* We will use the result as an index in an array, so most +* architectures only need a compiler barrier here. */ +read_barrier_depends (); + +if (next >= vq->num) { +vq_err (vq,"Desc next is %u > %u" , next, vq->num); +return vq->num; + } + +return next; +} + +/* This looks in the virtqueue and for the first available buffer, and converts +* it to an iovec for convenient access. Since descriptors consist of some +* number of output then some number of input descriptors, it's actually two +* iovecs, but we pack them into one and note how many of each there were. +* +* This function returns the descriptor number found, or vq->num (which +* is never a valid descriptor number) if none was found. */ +unsigned vhost_get_vq_desc (struct vhost_dev *dev,struct vhost_virtqueue *vq, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head; +u16 last_avail_idx; +int ret; + +/* Check it isn't doing very strange things with descriptor numbers. */ + last_avail_idx = vq->last_avail_idx; +if (get_user (vq->avail_idx, &vq->avail->idx)) { +vq_err (vq,"Failed to access avail idx at %p\n" , + &vq->avail->idx); +return vq->num; + } + +if ((u16)(vq->avail_idx - last_avail_idx) > vq->num) { +vq_err (vq,"Guest moved used index from %u to %u" , + last_avail_idx, vq->avail_idx); +return vq->num; + } + +/* If there's nothing new since last we looked, return invalid. */ +if (vq->avail_idx == last_avail_idx) +return vq->num; + +/* Grab the next descriptor number they're advertising, and increment +* the index we've seen. */ +if (get_user (head, &vq->avail->ring[last_avail_idx % vq->num])) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return vq->num; + } + +/* If their number is silly, that's an error. */ +if (head >= vq->num) { +vq_err (vq,"Guest says index %u > %u is available" , + head, vq->num); +return vq->num; + } + + vq->last_avail_idx++; + +/* When we start there are none of either input nor output. */ + *out_num = *in_num =0 ; + + i = head; +do { +unsigned iov_count = *in_num + *out_num; +if (copy_from_user (&desc, vq->desc + i,sizeof desc)) { +vq_err (vq,"Failed to get descriptor: idx %d addr %p\n" , + i, vq->desc + i); +return vq->num; + } + ret =translate_desc (dev, desc.addr, desc.len, iov + iov_count, +VHOST_NET_MAX_SG - iov_count); +if (ret <0 ) { +vq_err (vq,"Translation failure %d descriptor idx %d\n" , + ret, i); +return vq->num; + } +/* If this is an input descriptor, increment that count. */ +if (desc.flags &VRING_DESC_F_WRITE ) + *in_num += ret; +else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (*in_num) { +vq_err (vq,"Descriptor has out after in: " +"idx %d\n" , i); +return vq->num; + } + *out_num += ret; + } + }while ((i =next_desc (vq, &desc)) != vq->num); +return head; +} + +/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ +void vhost_discard_vq_desc (struct vhost_virtqueue *vq) +{ + vq->last_avail_idx--; +} + +/* After we've used one of their buffers, we tell them about it. We'll then +* want to send them an interrupt, using vq->call. */ +int vhost_add_used (struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +struct vring_used_elem *used; + +/* The virtqueue contains a ring of used buffers. Get a pointer to the +* next entry in that used ring. */ + used = &vq->used->ring[vq->last_used_idx % vq->num]; +if (put_user (head, &used->id)) { +vq_err (vq,"Failed to write used id" ); +return -EFAULT ; + } +if (put_user (len, &used->len)) { +vq_err (vq,"Failed to write used len" ); +return -EFAULT ; + } +/* Make sure buffer is written before we update index. */ +wmb (); +if (put_user (vq->last_used_idx +1 , &vq->used->idx)) { +vq_err (vq,"Failed to increment used idx" ); +return -EFAULT ; + } + vq->last_used_idx++; +return 0 ; +} + +/* This actually sends the interrupt for this virtqueue */ +void vhost_trigger_irq (struct vhost_dev *dev,struct vhost_virtqueue *vq) +{ +__u16 flags =0 ; +if (get_user (flags, &vq->avail->flags)) { +vq_err (vq,"Failed to get flags" ); +return ; + } + +/* If they don't want an interrupt, don't send one, unless empty. */ +if ((flags &VRING_AVAIL_F_NO_INTERRUPT ) && + (!vhost_has_feature (dev,VIRTIO_F_NOTIFY_ON_EMPTY ) || + vq->avail_idx != vq->last_avail_idx)) +return ; + +/* Send the Guest an interrupt tell them we used something up. */ +if (vq->call_ctx) +eventfd_signal (vq->call_ctx,1 ); +} + +/* And here's the combo meal deal. Supersize me! */ +void vhost_add_used_and_trigger (struct vhost_dev *dev, +struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +vhost_add_used (vq, head, len); +vhost_trigger_irq (dev, vq); +} + +/* OK, now we need to know about added descriptors. */ +bool vhost_notify (struct vhost_virtqueue *vq) +{ +int r; +if (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )) +return false; + vq->used_flags &= ~VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to disable notification: %d\n" , r); +/* They could have slipped one in as we were doing that: make +* sure it's written, tell caller it needs to check again. */ +mb (); +return true; +} + +/* We don't need to be notified again. */ +void vhost_no_notify (struct vhost_virtqueue *vq) +{ +int r; +if (vq->used_flags &VRING_USED_F_NO_NOTIFY ) +return ; + vq->used_flags |=VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to enable notification: %d\n" , r); +} + +int vhost_init (void ) +{ + vhost_workqueue =create_workqueue ("vhost" ); +if (!vhost_workqueue) +return -ENOMEM ; +return 0 ; +} + +void vhost_cleanup (void ) +{ +destroy_workqueue (vhost_workqueue); +}drivers/vhost/vhost.h new file +122
-0@@ -0,0 +1,122 @@ +#ifndef _VHOST_H +#define _VHOST_H + +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/mm.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/poll.h> +#include <linux/file.h> +#include <linux/skbuff.h> +#include <linux/uio.h> +#include <linux/virtio_config.h> + +struct vhost_device ; + +enum { +VHOST_NET_MAX_SG =MAX_SKB_FRAGS +2 , +}; + +/* Poll a file (eventfd or socket) */ +/* Note: there's nothing vhost specific about this structure. */ +struct vhost_poll { +poll_table table; +wait_queue_head_t *wqh; +wait_queue_t wait; +/* struct which will handle all actual work. */ +struct work_struct work; +unsigned long mask; +}; + +void vhost_poll_init (struct vhost_poll *poll,work_func_t func, +unsigned long mask); +void vhost_poll_start (struct vhost_poll *poll,struct file *file); +void vhost_poll_stop (struct vhost_poll *poll); +void vhost_poll_flush (struct vhost_poll *poll); + +/* The virtqueue structure describes a queue attached to a device. */ +struct vhost_virtqueue { +struct vhost_dev *dev; + +/* The actual ring of buffers. */ +struct mutex mutex; +unsigned int num; +struct vring_desc __user *desc; +struct vring_avail __user *avail; +struct vring_used __user *used; +struct file *kick; +struct file *call; +struct file *error; +struct eventfd_ctx *call_ctx; +struct eventfd_ctx *error_ctx; + +struct vhost_poll poll; + +/* The routine to call when the Guest pings us, or timeout. */ +work_func_t handle_kick; + +/* Last available index we saw. */ +u16 last_avail_idx; + +/* Caches available index value from user. */ +u16 avail_idx; + +/* Last index we used. */ +u16 last_used_idx; + +/* Used flags */ +u16 used_flags; + +struct iovec iov[VHOST_NET_MAX_SG ]; +struct iovec hdr[VHOST_NET_MAX_SG ]; +}; + +struct vhost_dev { +/* Readers use RCU to access memory table pointer. +* Writers use mutex below.*/ +struct vhost_memory *memory; +struct mm_struct *mm; +struct vhost_virtqueue *vqs; +int nvqs; +struct mutex mutex; +unsigned acked_features; +}; + +long vhost_dev_init (struct vhost_dev *,struct vhost_virtqueue *vqs,int nvqs); +long vhost_dev_check_owner (struct vhost_dev *); +long vhost_dev_reset_owner (struct vhost_dev *); +void vhost_dev_cleanup (struct vhost_dev *); +long vhost_dev_ioctl (struct vhost_dev *,unsigned int ioctl,unsigned long arg); + +unsigned vhost_get_vq_desc (struct vhost_dev *,struct vhost_virtqueue *, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num); +void vhost_discard_vq_desc (struct vhost_virtqueue *); + +int vhost_add_used (struct vhost_virtqueue *,unsigned int head,int len); +void vhost_trigger_irq (struct vhost_dev *,struct vhost_virtqueue *); +void vhost_add_used_and_trigger (struct vhost_dev *,struct vhost_virtqueue *, +unsigned int head,int len); +void vhost_no_notify (struct vhost_virtqueue *); +bool vhost_notify (struct vhost_virtqueue *); + +int vhost_init (void ); +void vhost_cleanup (void ); + +#define vq_err (vq, fmt, ...) do { \ + pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ + if ((vq)->error_ctx) \ + eventfd_signal((vq)->error_ctx, 1);\ + } while (0) + +enum { +VHOST_FEATURES =1 <<VIRTIO_F_NOTIFY_ON_EMPTY , +}; + +static inline int vhost_has_feature (struct vhost_dev *dev,int bit) +{ +return dev->acked_features & (1 << bit); +} + +#endif include/linux/Kbuild +1
-0@@ -360,6 +360,7 @@ unifdef-y += uio.h unifdef-y += unistd.h unifdef-y += usbdevice_fs.h unifdef-y += utsname.h +unifdef-y += vhost.h unifdef-y += videodev2.h unifdef-y += videodev.h unifdef-y += virtio_config.hinclude/linux/miscdevice.h +1
-0@@ -30,6 +30,7 @@#define HPET_MINOR 228#define FUSE_MINOR 229#define KVM_MINOR 232 +#define VHOST_NET_MINOR 233#define MISC_DYNAMIC_MINOR 255struct device ;include/linux/vhost.h new file +101
-0@@ -0,0 +1,101 @@ +#ifndef _LINUX_VHOST_H +#define _LINUX_VHOST_H +/* Userspace interface for in-kernel virtio accelerators. */ + +/* vhost is used to reduce the number of system calls involved in virtio. +* +* Existing virtio net code is used in the guest without modification. +* +* This header includes interface used by userspace hypervisor for +* device configuration. +*/ + +#include <linux/types.h> +#include <linux/compiler.h> +#include <linux/ioctl.h> +#include <linux/virtio_config.h> +#include <linux/virtio_ring.h> + +struct vhost_vring_state { +unsigned int index; +unsigned int num; +}; + +struct vhost_vring_file { +unsigned int index; +int fd; +}; + +struct vhost_vring_addr { +unsigned int index; +unsigned int padding; +__u64 user_addr; +}; + +struct vhost_memory_region { +__u64 guest_phys_addr; +__u64 memory_size;/* bytes */ +__u64 userspace_addr; +__u64 padding;/* read/write protection? */ +}; + +struct vhost_memory { +__u32 nregions; +__u32 padding; +struct vhost_memory_region regions[0 ]; +}; + +/* ioctls */ + +#define VHOST_VIRTIO 0xAF + +/* Features bitmask for forward compatibility. Transport bits are used for +* vhost specific features. */ +#define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) +#define VHOST_ACK_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) + +/* Set current process as the (exclusive) owner of this file descriptor. This +* must be called before any other vhost command. Further calls to +* VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ +#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) +/* Give up ownership, and reset the device to default values. +* Allows subsequent call to VHOST_OWNER_SET to succeed. */ +#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) + +/* Set up/modify memory layout */ +#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) + +/* Ring setup. These parameters can not be modified while ring is running +* (bound to a device). */ +/* Set number of descriptors in ring */ +#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) +/* Start of array of descriptors (virtually contiguous) */ +#define VHOST_SET_VRING_DESC _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) +/* Used structure address */ +#define VHOST_SET_VRING_USED _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_addr) +/* Available structure address */ +#define VHOST_SET_VRING_AVAIL _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_addr) +/* Base value where queue looks for available descriptors */ +#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) +/* Get accessor: reads index, writes value in num */ +#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x14, struct vhost_vring_state) + +/* The following ioctls use eventfd file descriptors to signal and poll +* for events. */ + +/* Set eventfd to poll for added buffers */ +#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) +/* Set eventfd to signal when buffers have beed used */ +#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) +/* Set eventfd to signal an error */ +#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) + +/* VHOST_NET specific defines */ + +/* Attach virtio net device to a raw socket. The socket must be already +* bound to an ethernet device, this device will be used for transmit. +* Pass -1 to unbind from the socket and the transmit device. +* This can be used to stop the device (e.g. for migration). */ +#define VHOST_NET_SET_SOCKET _IOW(VHOST_VIRTIO, 0x30, int) + +#endif Signature · 5 lines
1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 18 lines · Avi Kivity
Quoted 8 lines · Gregory Haskins
Quoted 8 lines
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
Quoted 7 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
Quoted 2 lines
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands.
Thanks for finally starting to acknowledge there's a benefit, at least.
To be more precise, IMO virtio is designed to be a performance oriented ring-based driver interface that supports all types of hypervisors (e.g. shmem based kvm, and non-shmem based Xen). vbus is designed to be a high-performance generic shared-memory interconnect (for rings or otherwise) framework for environments where linux is the underpinning "host" (physical or virtual). They are distinctly different, but complementary (the former addresses the part of the front-end, and latter addresses the back-end, and a different part of the front-end).
In addition, the kvm-connector used in AlacrityVM's design strives to add value and improve performance via other mechanisms, such as dynamic
allocation, interrupt coalescing (thus reducing exit-ratio, which is a
serious issue in KVM) and priortizable/nestable signals.
Today there is a large performance disparity between what a KVM guest sees and what a native linux application sees on that same host. Just take a look at some of my graphs between "virtio", and "native", for example:
http://developer.novell.com/wiki/images/b/b7/31-rc4_throughput.png
A dominant vbus design principle is to try to achieve the same IO performance for all "linux applications" whether they be literally userspace applications, or things like KVM vcpus or Ira's physical boards. It also aims to solve problems not previously expressible with current technologies (even virtio), like nested real-time.
And even though you repeatedly insist otherwise, the neat thing here is that the two technologies mesh (at least under certain circumstances, like when virtio is deployed on a shared-memory friendly linux backend like KVM). I hope that my stack diagram below depicts that clearly.
Quoted 2 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
Quoted 59 lines
(there's a limit how far you
can take this, not imposed by the code, but by virtio's charter as a virtual device driver framework).Quoted 45 lines
Going back to our stack diagrams, you could think of a vhost solution like this:
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| ? undefined-1 ?
--------------------------
| vhost
--------------------------and you could think of a vbus solution like this
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| bus-interface
--------------------------
| ? undefined-2 ?
--------------------------
| bus-model
--------------------------
| virtio-net-device (vhost ported to vbus model? :)
--------------------------So the difference between vhost and vbus in this particular context is that you need to have "undefined-1" do device discovery/hotswap, config-space, address-decode/isolation, signal-path routing, memory-path routing, etc. Today this function is filled by things like virtio-pci, pci-bus, KVM/ioeventfd, and QEMU for x86. I am not as familiar with lguest, but presumably it is filled there by components like virtio-lguest, lguest-bus, lguest.ko, and lguest-launcher. And to use more contemporary examples, we might have virtio-domino, domino-bus, domino.ko, and domino-launcher as well as virtio-ira, ira-bus, ira.ko, and ira-launcher.
Quoted 9 lines
Contrast this to the vbus stack: The bus-X components (when optionally employed by the connector designer) do device-discovery, hotswap, config-space, address-decode/isolation, signal-path and memory-path routing, etc in a general (and pv-centric) way. The "undefined-2" portion is the "connector", and just needs to convey messages like "DEVCALL" and "SHMSIGNAL". The rest is handled in other parts of the stack.
Quoted 3 lines
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
No, virtio doesn't assume that. It's stack provides the "virtio-bus" abstraction and what it does assume is that it will be wired up to something underneath. Kvm/x86 conveniently has pci, so the virtio-pci adapter was created to reuse much of that facility. For other things like lguest and s360, something new had to be created underneath to make up for the lack of pci-like support.
vbus, in conjunction with the kvm-connector, tries to unify that process a little more by creating a PV-optimized bus. The idea is that it can be reused in that situation instead of creating a new hypervisor specific bus each time. It's also designed for high-performance, so you get that important trait for free simply by tying into it.
Quoted 7 lines
Quoted 4 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
First of all, thats incorrect. If you want to use the "native" mechanisms (via the way the vbus-connector is implemented, for instance) you at least still have the benefit that the backend design is more broadly re-useable in more environments (like non-virt, for instance), because vbus does a proper job of defining the requisite layers/abstractions compared to vhost. So it adds value even in that situation.
Second of all, with PV there is no such thing as "native". It's software so it can be whatever we want. Sure, you could argue that the guest may have built-in support for something like PCI protocol. However, PCI protocol itself isn't suitable for high-performance PV out of the can. So you will therefore invariably require new software layers on top anyway, even if part of the support is already included.
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree /sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
In summary, vbus is simply one more bus of many, purpose built to support high-end IO in a virt-like model, giving controlled access to the linux-host underneath it. You can write a high-performance layer below the OS bus-model (vbus), or above it (virtio-pci) but either way you are modifying the stack to add these capabilities, so we might as well try to get this right.
With all due respect, you are making a big deal out of a minor issue.
Quoted 9 lines
Quoted 6 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.Only theoretically. The existing installed base would have to be thrown away
"Thrown away" is pure hyperbole. The installed base, worse case, needs to load a new driver for a missing device. This is pretty much how every machine works today, anyway. And if loading a driver was actually some insurmountable hurdle, as its sometimes implied (but its not in reality), you can alternatively make vbus look like a legacy bus if you are willing to sacrifice some of features, like exit-ratio reduction and priority.
FWIW: AlacrityVM isn't willing to sacrifice those features, so we will provide a Linux and Windows driver for explicit bus support, as well as open-specs and community development assistance to any other guest that wants to add support in the future.
Quoted 3 lines
or we'd need to support both.
No matter what model we talk about, there's always going to be a "both" since the userspace virtio models are probably not going to go away (nor should they).
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
Without a vbus-connector-falling-dominos, vbus-venet can't do anything either.
Mostly covered above...
However, I was addressing your assertion that vhost somehow magically accomplishes this "container/addressing" function without any specific kernel support. This is incorrect. I contend that this kernel support is required and present. The difference is that its defined elsewhere (and typically in a transport/arch specific way).
Quoted 8 lines
Quoted 6 lines
IOW: You can basically think of the programmed PIO addresses as forming its "container". Only addresses explicitly added are visible, and everything else is inaccessible. This whole discussion is merely a question of what's been generalized verses what needs to be re-implemented each time.
Sorry, this is too abstract for me.
With all due respect, understanding my point above is required to have any kind of meaningful discussion here.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
That is not correct. vbus does its own native address decoding in the fast path, such as here:
Quoted 7 lines
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
How the connector message is delivered is really not relevant. Some architectures will simply deliver the message point-to-point (like the original hypercall design for KVM, or something like Ira's rig), and some will need additional demuxing (like pci-bridge/pio based KVM). It's an implementation detail of the connector.
However, the real point here is that something needs to establish a scoped namespace mechanism, add items to that namespace, and advertise the presence of the items to the guest. vbus has this facility built in to its stack. vhost doesn't, so it must come from elsewhere.
Quoted 10 lines
Quoted 7 lines
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
It doesn't have just virtio-net, it has userspace-based hostplug
vbus has hotplug too: mkdir and rmdir
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Afaict, qemu can't do either of those things.
Quoted 1 line
and a bunch of other devices impemented in userspace.
Thats fine. I am primarily interested in the high-performance components, so most of those other items can stay there in userspace if that is their ideal location.
Quoted 4 lines
Currently qemu has
virtio bindings for pci and syborg (whatever that is), and device models for baloon, block, net, and console, so it seems implementing device support in userspace is not as disasterous as you make it to be.
I intentionally qualified "device" with "new" in my statement. And in that context I was talking about ultimately developing/supporting in-kernel models, not pure legacy userspace ones. I have no doubt the implementation of the original userpsace devices was not a difficult or horrific endeavor.
Requiring new models to be implemented (at least) twice is a poor design IMO, however. Requiring them to split such a minor portion of their functionality (like read-only attributes) is a poor design, too. I have already demonstrated there are other ways to achieve the same high-performance goals without requiring two models developed/tested each time and for each manager. For the times I went and tried to satisfy your request in this manner, developing the code and managing the resources in two places, for lack of a better description, made me want to wretch. So I gave up, resolved that my original design was better, and hoped that I could convince you and the community of the same.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Invariably?
As in "always"
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Refactor instead of rewriting.
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
Quoted 20 lines
Quoted 13 lines
Quoted 5 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
Quoted 6 lines
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 2 lines
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux);
vmware only cares about x86 iiuc, so probably not a good example.
Quoted 4 lines
Xen has to tunnel
xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.
So pick any other hypervisor, and the situation is often similar.
Quoted 2 lines
"PCI is a dead end" could not be more wrong, it's what guests support.
It's what _some_ guests support. Even for the guests that support it, it's not well designed for PV. Therefore, you have to do a bunch of dancing and waste resources on top to squeeze every last drop of performance out of your platform. In addition, it has a bunch of baggage that goes with it that is not necessary to do the job in a software environment. It is therefore burdensome to recreate if you don't already have something to leverage, like QEMU, just for the sake of creating the illusion that its there.
Sounds pretty dead to me, sorry. We don't need it.
Alternatively, you can just try to set a stake in the ground for looking forward and fixing those PV-specific problems hopefully once and for all, like vbus and the kvm-connector tries to do. Sure, there will be some degree of pain first as we roll out the subsystem and deploy support, but thats true for lots of things. It's simply a platform investment.
Quoted 4 lines
An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
vbus is not interested in userspace devices. The charter is to provide facilities for utilizing the host linux kernel's IO capabilities in the most efficient, yet safe, manner possible. Those devices that fit outside that charter can ride on legacy mechanisms if that suits them best.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
I digress. My point here isn't PCI. The point here is the missing component for when PCI is not present. The component that is partially satisfied by vbus's devid addressing scheme. If you are going to use vhost, and you don't have PCI, you've gotta build something to replace it.
Yes, that's why people have keyboards. They'll write that glue code if they need it. If it turns out to be a hit an people start having virtio transport module writing parties, they'll figure out a way to share code.
Quoted 5 lines
Quoted 3 lines
Sigh... The party has already started. I tried to invite you months ago...
I've been voting virtio since 2007.
That doesn't have much to do with whats underneath it, since it doesn't define these layers. See my stack diagram's for details.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
On the guest side, virtio-shmem.ko can unify the ring access. It probably makes sense even today. On the host side I eventfd is the kernel interface and libvhostconfig.so can provide the configuration when an existing ABI is not imposed.
Quoted 6 lines
Quoted 4 lines
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
vbus needs the same thing so it cancels out.
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
Per queue/device addressing is handled by the same conceptual namespace
as the one that would trigger eventfds in the model you mention. And that namespace is built in to the vbus stack, and objects are registered automatically as they are created.
Contrast that to vhost, which requires some other kernel interface to exist, and to be managed manually for each object that is created. Your libvhostconfig would need to somehow know how to perform this registration operation, and there would have to be something in the kernel to receive it, presumably on a per platform basis. Solving this problem generally would probably end up looking eerily like vbus, because thats what vbus does.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Look at the virtio-net feature negotiation. There's a lot more there than the MAC address, and it's going to grow.
Agreed, but note that makes my point. That feature negotiation almost invariably influences the device-model, not some config-space shim.
IOW: terminating config-space at some userspace shim is pointless. The model ultimately needs the result of whatever transpires during that negotiation anyway.
Quoted 4 lines
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
yes, its in sysfs.
Quoted 2 lines
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
yes, its in sysfs.
Quoted 2 lines
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
no, but we can easily add ->save()/->restore() to the model going forward, and the negotiated features are just a subcomponent if its serialized stream.
Quoted 2 lines
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
that would be the function of the ->restore() deserializer.
Quoted 1 line
- do all that from an unprivileged process
yes, in the upcoming alacrityvm v0.3 with the ioctl based control plane.
Quoted 1 line
- securely wrt other unprivileged processes
yes, same mechanism plus it has a fork-inheritance model.
Bottom line: vbus isn't done, especially w.r.t. live-migration..but that is not an valid argument against the idea if you believe in release-early/release-often. kvm wasn't (isn't) done either when it was proposed/merged.
Kind Regards,
-Greg
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 18 lines · Avi Kivity
Quoted 8 lines · Gregory Haskins
Quoted 8 lines
I don't really see how vhost and vbus are different here. vhost expects signalling to happen through a couple of eventfds and requires someone to supply them and implement kernel support (if needed). vbus requires someone to write a connector to provide the signalling implementation. Neither will work out-of-the-box when implementing virtio-net over falling dominos, for example.
Quoted 7 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
Quoted 2 lines
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands.
Thanks for finally starting to acknowledge there's a benefit, at least.
To be more precise, IMO virtio is designed to be a performance oriented ring-based driver interface that supports all types of hypervisors (e.g. shmem based kvm, and non-shmem based Xen). vbus is designed to be a high-performance generic shared-memory interconnect (for rings or otherwise) framework for environments where linux is the underpinning "host" (physical or virtual). They are distinctly different, but complementary (the former addresses the part of the front-end, and latter addresses the back-end, and a different part of the front-end).
In addition, the kvm-connector used in AlacrityVM's design strives to add value and improve performance via other mechanisms, such as dynamic
allocation, interrupt coalescing (thus reducing exit-ratio, which is a
serious issue in KVM) and priortizable/nestable signals.
Today there is a large performance disparity between what a KVM guest sees and what a native linux application sees on that same host. Just take a look at some of my graphs between "virtio", and "native", for example:
http://developer.novell.com/wiki/images/b/b7/31-rc4_throughput.png
A dominant vbus design principle is to try to achieve the same IO performance for all "linux applications" whether they be literally userspace applications, or things like KVM vcpus or Ira's physical boards. It also aims to solve problems not previously expressible with current technologies (even virtio), like nested real-time.
And even though you repeatedly insist otherwise, the neat thing here is that the two technologies mesh (at least under certain circumstances, like when virtio is deployed on a shared-memory friendly linux backend like KVM). I hope that my stack diagram below depicts that clearly.
Quoted 2 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
Quoted 59 lines
(there's a limit how far you
can take this, not imposed by the code, but by virtio's charter as a virtual device driver framework).Quoted 45 lines
Going back to our stack diagrams, you could think of a vhost solution like this:
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| ? undefined-1 ?
--------------------------
| vhost
--------------------------and you could think of a vbus solution like this
--------------------------
| virtio-net
--------------------------
| virtio-ring
--------------------------
| virtio-bus
--------------------------
| bus-interface
--------------------------
| ? undefined-2 ?
--------------------------
| bus-model
--------------------------
| virtio-net-device (vhost ported to vbus model? :)
--------------------------So the difference between vhost and vbus in this particular context is that you need to have "undefined-1" do device discovery/hotswap, config-space, address-decode/isolation, signal-path routing, memory-path routing, etc. Today this function is filled by things like virtio-pci, pci-bus, KVM/ioeventfd, and QEMU for x86. I am not as familiar with lguest, but presumably it is filled there by components like virtio-lguest, lguest-bus, lguest.ko, and lguest-launcher. And to use more contemporary examples, we might have virtio-domino, domino-bus, domino.ko, and domino-launcher as well as virtio-ira, ira-bus, ira.ko, and ira-launcher.
Quoted 9 lines
Contrast this to the vbus stack: The bus-X components (when optionally employed by the connector designer) do device-discovery, hotswap, config-space, address-decode/isolation, signal-path and memory-path routing, etc in a general (and pv-centric) way. The "undefined-2" portion is the "connector", and just needs to convey messages like "DEVCALL" and "SHMSIGNAL". The rest is handled in other parts of the stack.
Quoted 3 lines
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
No, virtio doesn't assume that. It's stack provides the "virtio-bus" abstraction and what it does assume is that it will be wired up to something underneath. Kvm/x86 conveniently has pci, so the virtio-pci adapter was created to reuse much of that facility. For other things like lguest and s360, something new had to be created underneath to make up for the lack of pci-like support.
vbus, in conjunction with the kvm-connector, tries to unify that process a little more by creating a PV-optimized bus. The idea is that it can be reused in that situation instead of creating a new hypervisor specific bus each time. It's also designed for high-performance, so you get that important trait for free simply by tying into it.
Quoted 7 lines
Quoted 4 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
First of all, thats incorrect. If you want to use the "native" mechanisms (via the way the vbus-connector is implemented, for instance) you at least still have the benefit that the backend design is more broadly re-useable in more environments (like non-virt, for instance), because vbus does a proper job of defining the requisite layers/abstractions compared to vhost. So it adds value even in that situation.
Second of all, with PV there is no such thing as "native". It's software so it can be whatever we want. Sure, you could argue that the guest may have built-in support for something like PCI protocol. However, PCI protocol itself isn't suitable for high-performance PV out of the can. So you will therefore invariably require new software layers on top anyway, even if part of the support is already included.
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree /sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
In summary, vbus is simply one more bus of many, purpose built to support high-end IO in a virt-like model, giving controlled access to the linux-host underneath it. You can write a high-performance layer below the OS bus-model (vbus), or above it (virtio-pci) but either way you are modifying the stack to add these capabilities, so we might as well try to get this right.
With all due respect, you are making a big deal out of a minor issue.
Quoted 9 lines
Quoted 6 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.Only theoretically. The existing installed base would have to be thrown away
"Thrown away" is pure hyperbole. The installed base, worse case, needs to load a new driver for a missing device. This is pretty much how every machine works today, anyway. And if loading a driver was actually some insurmountable hurdle, as its sometimes implied (but its not in reality), you can alternatively make vbus look like a legacy bus if you are willing to sacrifice some of features, like exit-ratio reduction and priority.
FWIW: AlacrityVM isn't willing to sacrifice those features, so we will provide a Linux and Windows driver for explicit bus support, as well as open-specs and community development assistance to any other guest that wants to add support in the future.
Quoted 3 lines
or we'd need to support both.
No matter what model we talk about, there's always going to be a "both" since the userspace virtio models are probably not going to go away (nor should they).
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
Without a vbus-connector-falling-dominos, vbus-venet can't do anything either.
Mostly covered above...
However, I was addressing your assertion that vhost somehow magically accomplishes this "container/addressing" function without any specific kernel support. This is incorrect. I contend that this kernel support is required and present. The difference is that its defined elsewhere (and typically in a transport/arch specific way).
Quoted 8 lines
Quoted 6 lines
IOW: You can basically think of the programmed PIO addresses as forming its "container". Only addresses explicitly added are visible, and everything else is inaccessible. This whole discussion is merely a question of what's been generalized verses what needs to be re-implemented each time.
Sorry, this is too abstract for me.
With all due respect, understanding my point above is required to have any kind of meaningful discussion here.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
vbus doesn't do kvm guest address decoding for the fast path. It's still done by ioeventfd.
That is not correct. vbus does its own native address decoding in the fast path, such as here:
Quoted 7 lines
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
How the connector message is delivered is really not relevant. Some architectures will simply deliver the message point-to-point (like the original hypercall design for KVM, or something like Ira's rig), and some will need additional demuxing (like pci-bridge/pio based KVM). It's an implementation detail of the connector.
However, the real point here is that something needs to establish a scoped namespace mechanism, add items to that namespace, and advertise the presence of the items to the guest. vbus has this facility built in to its stack. vhost doesn't, so it must come from elsewhere.
Quoted 10 lines
Quoted 7 lines
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
It doesn't have just virtio-net, it has userspace-based hostplug
vbus has hotplug too: mkdir and rmdir
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Afaict, qemu can't do either of those things.
Quoted 1 line
and a bunch of other devices impemented in userspace.
Thats fine. I am primarily interested in the high-performance components, so most of those other items can stay there in userspace if that is their ideal location.
Quoted 4 lines
Currently qemu has
virtio bindings for pci and syborg (whatever that is), and device models for baloon, block, net, and console, so it seems implementing device support in userspace is not as disasterous as you make it to be.
I intentionally qualified "device" with "new" in my statement. And in that context I was talking about ultimately developing/supporting in-kernel models, not pure legacy userspace ones. I have no doubt the implementation of the original userpsace devices was not a difficult or horrific endeavor.
Requiring new models to be implemented (at least) twice is a poor design IMO, however. Requiring them to split such a minor portion of their functionality (like read-only attributes) is a poor design, too. I have already demonstrated there are other ways to achieve the same high-performance goals without requiring two models developed/tested each time and for each manager. For the times I went and tried to satisfy your request in this manner, developing the code and managing the resources in two places, for lack of a better description, made me want to wretch. So I gave up, resolved that my original design was better, and hoped that I could convince you and the community of the same.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Invariably?
As in "always"
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Refactor instead of rewriting.
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
Quoted 20 lines
Quoted 13 lines
Quoted 5 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
Quoted 6 lines
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 2 lines
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux);
vmware only cares about x86 iiuc, so probably not a good example.
Quoted 4 lines
Xen has to tunnel
xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.
So pick any other hypervisor, and the situation is often similar.
Quoted 2 lines
"PCI is a dead end" could not be more wrong, it's what guests support.
It's what _some_ guests support. Even for the guests that support it, it's not well designed for PV. Therefore, you have to do a bunch of dancing and waste resources on top to squeeze every last drop of performance out of your platform. In addition, it has a bunch of baggage that goes with it that is not necessary to do the job in a software environment. It is therefore burdensome to recreate if you don't already have something to leverage, like QEMU, just for the sake of creating the illusion that its there.
Sounds pretty dead to me, sorry. We don't need it.
Alternatively, you can just try to set a stake in the ground for looking forward and fixing those PV-specific problems hopefully once and for all, like vbus and the kvm-connector tries to do. Sure, there will be some degree of pain first as we roll out the subsystem and deploy support, but thats true for lots of things. It's simply a platform investment.
Quoted 4 lines
An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
vbus is not interested in userspace devices. The charter is to provide facilities for utilizing the host linux kernel's IO capabilities in the most efficient, yet safe, manner possible. Those devices that fit outside that charter can ride on legacy mechanisms if that suits them best.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
I digress. My point here isn't PCI. The point here is the missing component for when PCI is not present. The component that is partially satisfied by vbus's devid addressing scheme. If you are going to use vhost, and you don't have PCI, you've gotta build something to replace it.
Yes, that's why people have keyboards. They'll write that glue code if they need it. If it turns out to be a hit an people start having virtio transport module writing parties, they'll figure out a way to share code.
Quoted 5 lines
Quoted 3 lines
Sigh... The party has already started. I tried to invite you months ago...
I've been voting virtio since 2007.
That doesn't have much to do with whats underneath it, since it doesn't define these layers. See my stack diagram's for details.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
On the guest side, virtio-shmem.ko can unify the ring access. It probably makes sense even today. On the host side I eventfd is the kernel interface and libvhostconfig.so can provide the configuration when an existing ABI is not imposed.
Quoted 6 lines
Quoted 4 lines
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
vbus needs the same thing so it cancels out.
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
Per queue/device addressing is handled by the same conceptual namespace
as the one that would trigger eventfds in the model you mention. And that namespace is built in to the vbus stack, and objects are registered automatically as they are created.
Contrast that to vhost, which requires some other kernel interface to exist, and to be managed manually for each object that is created. Your libvhostconfig would need to somehow know how to perform this registration operation, and there would have to be something in the kernel to receive it, presumably on a per platform basis. Solving this problem generally would probably end up looking eerily like vbus, because thats what vbus does.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Look at the virtio-net feature negotiation. There's a lot more there than the MAC address, and it's going to grow.
Agreed, but note that makes my point. That feature negotiation almost invariably influences the device-model, not some config-space shim.
IOW: terminating config-space at some userspace shim is pointless. The model ultimately needs the result of whatever transpires during that negotiation anyway.
Quoted 4 lines
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
yes, its in sysfs.
Quoted 2 lines
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
yes, its in sysfs.
Quoted 2 lines
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
no, but we can easily add ->save()/->restore() to the model going forward, and the negotiated features are just a subcomponent if its serialized stream.
Quoted 2 lines
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
that would be the function of the ->restore() deserializer.
Quoted 1 line
- do all that from an unprivileged process
yes, in the upcoming alacrityvm v0.3 with the ioctl based control plane.
Quoted 1 line
- securely wrt other unprivileged processes
yes, same mechanism plus it has a fork-inheritance model.
Bottom line: vbus isn't done, especially w.r.t. live-migration..but that is not an valid argument against the idea if you believe in release-early/release-often. kvm wasn't (isn't) done either when it was proposed/merged.
Kind Regards,
-Greg
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Ira W. SnyderQuoted 48 lines · Ira W. Snyder
Quoted 35 lines
drivers/vhost/vhost.c new file +35
-0+case VHOST_SET_VRING_KICK : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->kick) { + pollstop = filep = vq->kick; + pollstart = vq->kick = eventfp; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_CALL : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->call) { + filep = vq->call; + ctx = vq->call_ctx; + vq->call = eventfp; + vq->call_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_ERR : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp))drivers/vhost/vhost.c line 367
Quoted 10 lines
drivers/vhost/vhost.c new file +10
-0+return PTR_ERR (eventfp); +if (eventfp != vq->error) { + filep = vq->error; + vq->error = eventfp; + ctx = vq->error_ctx; + vq->error_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ;I'm not sure how these eventfd's save a trip to userspace.
Quoted 2 lines
AFAICT, eventfd's cannot be used to signal another part of the kernel, they can only be used to wake up userspace.
Yes, they can. See irqfd code in virt/kvm/eventfd.c.
Quoted 10 lines
In my system, when an IRQ for
kick()comes in, I have an eventfd which gets signalled to notify userspace. When I want to send acall(), I have to use a specialioctl(), just like lguest does.Doesn't this mean that for
call(), vhost is just going to signal an eventfd to wake up userspace, which is then going to callioctl(), and then we're back in kernelspace. Seems like a wasted userspace round-trip.Or am I mis-reading this code?
Yes. Kernel can poll eventfd and deliver an interrupt directly without involving userspace.
Quoted 584 lines
PS - you can see my current code at:
http://www.mmarray.org/~iws/virtio-phys/Thanks,
IraQuoted 578 lines
drivers/vhost/vhost.c new file +321
-0+default : + r = -ENOIOCTLCMD ; + } + +if (pollstop && vq->handle_kick) +vhost_poll_stop (&vq->poll); + +if (ctx) +eventfd_ctx_put (ctx); +if (filep) +fput (filep); + +if (pollstart && vq->handle_kick) +vhost_poll_start (&vq->poll, vq->kick); + +mutex_unlock (&vq->mutex); + +if (pollstop && vq->handle_kick) +vhost_poll_flush (&vq->poll); +return 0 ; +} + +long vhost_dev_ioctl (struct vhost_dev *d,unsigned int ioctl,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +long r; + +mutex_lock (&d->mutex); +/* If you are not the owner, you can become one */ +if (ioctl ==VHOST_SET_OWNER ) { + r =vhost_dev_set_owner (d); + goto done; + } + +/* You must be the owner to do anything else */ + r =vhost_dev_check_owner (d); +if (r) + goto done; + +switch (ioctl) { +case VHOST_SET_MEM_TABLE : + r =vhost_set_memory (d, argp); +break ; +default : + r =vhost_set_vring (d, ioctl, argp); +break ; + } +done: +mutex_unlock (&d->mutex); +return r; +} + +static const struct vhost_memory_region *find_region (struct vhost_memory *mem, +__u64 addr,__u32 len) +{ +struct vhost_memory_region *reg; +int i; +/* linear search is not brilliant, but we really have on the order of 6 +* regions in practice */ +for (i =0 ; i < mem->nregions; ++i) { + reg = mem->regions + i; +if (reg->guest_phys_addr <= addr && + reg->guest_phys_addr + reg->memory_size -1 >= addr) +return reg; + } +return NULL ; +} + +int translate_desc (struct vhost_dev *dev,u64 addr,u32 len, +struct iovec iov[],int iov_size) +{ +const struct vhost_memory_region *reg; +struct vhost_memory *mem; +struct iovec *_iov; +u64 s =0 ; +int ret =0 ; + +rcu_read_lock (); + + mem =rcu_dereference (dev->memory); +while ((u64 )len > s) { +u64 size; +if (ret >= iov_size) { + ret = -ENOBUFS ; +break ; + } + reg =find_region (mem, addr, len); +if (!reg) { + ret = -EFAULT ; +break ; + } + _iov = iov + ret; + size = reg->memory_size - addr + reg->guest_phys_addr; + _iov->iov_len =min ((u64 )len, size); + _iov->iov_base = (void *) + (reg->userspace_addr + addr - reg->guest_phys_addr); + s += size; + addr += size; + ++ret; + } + +rcu_read_unlock (); +return ret; +} + +/* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. */ +static unsigned next_desc (struct vhost_virtqueue *vq,struct vring_desc *desc) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc->flags &VRING_DESC_F_NEXT )) +return vq->num; + +/* Check they're not leading us off end of descriptors. */ + next = desc->next; +/* Make sure compiler knows to grab that: we don't want it changing! */ +/* We will use the result as an index in an array, so most +* architectures only need a compiler barrier here. */ +read_barrier_depends (); + +if (next >= vq->num) { +vq_err (vq,"Desc next is %u > %u" , next, vq->num); +return vq->num; + } + +return next; +} + +/* This looks in the virtqueue and for the first available buffer, and converts +* it to an iovec for convenient access. Since descriptors consist of some +* number of output then some number of input descriptors, it's actually two +* iovecs, but we pack them into one and note how many of each there were. +* +* This function returns the descriptor number found, or vq->num (which +* is never a valid descriptor number) if none was found. */ +unsigned vhost_get_vq_desc (struct vhost_dev *dev,struct vhost_virtqueue *vq, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head; +u16 last_avail_idx; +int ret; + +/* Check it isn't doing very strange things with descriptor numbers. */ + last_avail_idx = vq->last_avail_idx; +if (get_user (vq->avail_idx, &vq->avail->idx)) { +vq_err (vq,"Failed to access avail idx at %p\n" , + &vq->avail->idx); +return vq->num; + } + +if ((u16)(vq->avail_idx - last_avail_idx) > vq->num) { +vq_err (vq,"Guest moved used index from %u to %u" , + last_avail_idx, vq->avail_idx); +return vq->num; + } + +/* If there's nothing new since last we looked, return invalid. */ +if (vq->avail_idx == last_avail_idx) +return vq->num; + +/* Grab the next descriptor number they're advertising, and increment +* the index we've seen. */ +if (get_user (head, &vq->avail->ring[last_avail_idx % vq->num])) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return vq->num; + } + +/* If their number is silly, that's an error. */ +if (head >= vq->num) { +vq_err (vq,"Guest says index %u > %u is available" , + head, vq->num); +return vq->num; + } + + vq->last_avail_idx++; + +/* When we start there are none of either input nor output. */ + *out_num = *in_num =0 ; + + i = head; +do { +unsigned iov_count = *in_num + *out_num; +if (copy_from_user (&desc, vq->desc + i,sizeof desc)) { +vq_err (vq,"Failed to get descriptor: idx %d addr %p\n" , + i, vq->desc + i); +return vq->num; + } + ret =translate_desc (dev, desc.addr, desc.len, iov + iov_count, +VHOST_NET_MAX_SG - iov_count); +if (ret <0 ) { +vq_err (vq,"Translation failure %d descriptor idx %d\n" , + ret, i); +return vq->num; + } +/* If this is an input descriptor, increment that count. */ +if (desc.flags &VRING_DESC_F_WRITE ) + *in_num += ret; +else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (*in_num) { +vq_err (vq,"Descriptor has out after in: " +"idx %d\n" , i); +return vq->num; + } + *out_num += ret; + } + }while ((i =next_desc (vq, &desc)) != vq->num); +return head; +} + +/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ +void vhost_discard_vq_desc (struct vhost_virtqueue *vq) +{ + vq->last_avail_idx--; +} + +/* After we've used one of their buffers, we tell them about it. We'll then +* want to send them an interrupt, using vq->call. */ +int vhost_add_used (struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +struct vring_used_elem *used; + +/* The virtqueue contains a ring of used buffers. Get a pointer to the +* next entry in that used ring. */ + used = &vq->used->ring[vq->last_used_idx % vq->num]; +if (put_user (head, &used->id)) { +vq_err (vq,"Failed to write used id" ); +return -EFAULT ; + } +if (put_user (len, &used->len)) { +vq_err (vq,"Failed to write used len" ); +return -EFAULT ; + } +/* Make sure buffer is written before we update index. */ +wmb (); +if (put_user (vq->last_used_idx +1 , &vq->used->idx)) { +vq_err (vq,"Failed to increment used idx" ); +return -EFAULT ; + } + vq->last_used_idx++; +return 0 ; +} + +/* This actually sends the interrupt for this virtqueue */ +void vhost_trigger_irq (struct vhost_dev *dev,struct vhost_virtqueue *vq) +{ +__u16 flags =0 ; +if (get_user (flags, &vq->avail->flags)) { +vq_err (vq,"Failed to get flags" ); +return ; + } + +/* If they don't want an interrupt, don't send one, unless empty. */ +if ((flags &VRING_AVAIL_F_NO_INTERRUPT ) && + (!vhost_has_feature (dev,VIRTIO_F_NOTIFY_ON_EMPTY ) || + vq->avail_idx != vq->last_avail_idx)) +return ; + +/* Send the Guest an interrupt tell them we used something up. */ +if (vq->call_ctx) +eventfd_signal (vq->call_ctx,1 ); +} + +/* And here's the combo meal deal. Supersize me! */ +void vhost_add_used_and_trigger (struct vhost_dev *dev, +struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +vhost_add_used (vq, head, len); +vhost_trigger_irq (dev, vq); +} + +/* OK, now we need to know about added descriptors. */ +bool vhost_notify (struct vhost_virtqueue *vq) +{ +int r; +if (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )) +return false; + vq->used_flags &= ~VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to disable notification: %d\n" , r); +/* They could have slipped one in as we were doing that: make +* sure it's written, tell caller it needs to check again. */ +mb (); +return true; +} + +/* We don't need to be notified again. */ +void vhost_no_notify (struct vhost_virtqueue *vq) +{ +int r; +if (vq->used_flags &VRING_USED_F_NO_NOTIFY ) +return ; + vq->used_flags |=VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to enable notification: %d\n" , r); +} + +int vhost_init (void ) +{ + vhost_workqueue =create_workqueue ("vhost" ); +if (!vhost_workqueue) +return -ENOMEM ; +return 0 ; +} + +void vhost_cleanup (void ) +{ +destroy_workqueue (vhost_workqueue); +}drivers/vhost/vhost.h new file +122
-0@@ -0,0 +1,122 @@ +#ifndef _VHOST_H +#define _VHOST_H + +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/mm.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/poll.h> +#include <linux/file.h> +#include <linux/skbuff.h> +#include <linux/uio.h> +#include <linux/virtio_config.h> + +struct vhost_device ; + +enum { +VHOST_NET_MAX_SG =MAX_SKB_FRAGS +2 , +}; + +/* Poll a file (eventfd or socket) */ +/* Note: there's nothing vhost specific about this structure. */ +struct vhost_poll { +poll_table table; +wait_queue_head_t *wqh; +wait_queue_t wait; +/* struct which will handle all actual work. */ +struct work_struct work; +unsigned long mask; +}; + +void vhost_poll_init (struct vhost_poll *poll,work_func_t func, +unsigned long mask); +void vhost_poll_start (struct vhost_poll *poll,struct file *file); +void vhost_poll_stop (struct vhost_poll *poll); +void vhost_poll_flush (struct vhost_poll *poll); + +/* The virtqueue structure describes a queue attached to a device. */ +struct vhost_virtqueue { +struct vhost_dev *dev; + +/* The actual ring of buffers. */ +struct mutex mutex; +unsigned int num; +struct vring_desc __user *desc; +struct vring_avail __user *avail; +struct vring_used __user *used; +struct file *kick; +struct file *call; +struct file *error; +struct eventfd_ctx *call_ctx; +struct eventfd_ctx *error_ctx; + +struct vhost_poll poll; + +/* The routine to call when the Guest pings us, or timeout. */ +work_func_t handle_kick; + +/* Last available index we saw. */ +u16 last_avail_idx; + +/* Caches available index value from user. */ +u16 avail_idx; + +/* Last index we used. */ +u16 last_used_idx; + +/* Used flags */ +u16 used_flags; + +struct iovec iov[VHOST_NET_MAX_SG ]; +struct iovec hdr[VHOST_NET_MAX_SG ]; +}; + +struct vhost_dev { +/* Readers use RCU to access memory table pointer. +* Writers use mutex below.*/ +struct vhost_memory *memory; +struct mm_struct *mm; +struct vhost_virtqueue *vqs; +int nvqs; +struct mutex mutex; +unsigned acked_features; +}; + +long vhost_dev_init (struct vhost_dev *,struct vhost_virtqueue *vqs,int nvqs); +long vhost_dev_check_owner (struct vhost_dev *); +long vhost_dev_reset_owner (struct vhost_dev *); +void vhost_dev_cleanup (struct vhost_dev *); +long vhost_dev_ioctl (struct vhost_dev *,unsigned int ioctl,unsigned long arg); + +unsigned vhost_get_vq_desc (struct vhost_dev *,struct vhost_virtqueue *, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num); +void vhost_discard_vq_desc (struct vhost_virtqueue *); + +int vhost_add_used (struct vhost_virtqueue *,unsigned int head,int len); +void vhost_trigger_irq (struct vhost_dev *,struct vhost_virtqueue *); +void vhost_add_used_and_trigger (struct vhost_dev *,struct vhost_virtqueue *, +unsigned int head,int len); +void vhost_no_notify (struct vhost_virtqueue *); +bool vhost_notify (struct vhost_virtqueue *); + +int vhost_init (void ); +void vhost_cleanup (void ); + +#define vq_err (vq, fmt, ...) do { \ + pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ + if ((vq)->error_ctx) \ + eventfd_signal((vq)->error_ctx, 1);\ + } while (0) + +enum { +VHOST_FEATURES =1 <<VIRTIO_F_NOTIFY_ON_EMPTY , +}; + +static inline int vhost_has_feature (struct vhost_dev *dev,int bit) +{ +return dev->acked_features & (1 << bit); +} + +#endif include/linux/Kbuild +1
-0@@ -360,6 +360,7 @@ unifdef-y += uio.h unifdef-y += unistd.h unifdef-y += usbdevice_fs.h unifdef-y += utsname.h +unifdef-y += vhost.h unifdef-y += videodev2.h unifdef-y += videodev.h unifdef-y += virtio_config.hinclude/linux/miscdevice.h +1
-0@@ -30,6 +30,7 @@#define HPET_MINOR 228#define FUSE_MINOR 229#define KVM_MINOR 232 +#define VHOST_NET_MINOR 233#define MISC_DYNAMIC_MINOR 255struct device ;include/linux/vhost.h new file +99
-0@@ -0,0 +1,101 @@ +#ifndef _LINUX_VHOST_H +#define _LINUX_VHOST_H +/* Userspace interface for in-kernel virtio accelerators. */ + +/* vhost is used to reduce the number of system calls involved in virtio. +* +* Existing virtio net code is used in the guest without modification. +* +* This header includes interface used by userspace hypervisor for +* device configuration. +*/ + +#include <linux/types.h> +#include <linux/compiler.h> +#include <linux/ioctl.h> +#include <linux/virtio_config.h> +#include <linux/virtio_ring.h> + +struct vhost_vring_state { +unsigned int index; +unsigned int num; +}; + +struct vhost_vring_file { +unsigned int index; +int fd; +}; + +struct vhost_vring_addr { +unsigned int index; +unsigned int padding; +__u64 user_addr; +}; + +struct vhost_memory_region { +__u64 guest_phys_addr; +__u64 memory_size;/* bytes */ +__u64 userspace_addr; +__u64 padding;/* read/write protection? */ +}; + +struct vhost_memory { +__u32 nregions; +__u32 padding; +struct vhost_memory_region regions[0 ]; +}; + +/* ioctls */ + +#define VHOST_VIRTIO 0xAF + +/* Features bitmask for forward compatibility. Transport bits are used for +* vhost specific features. */ +#define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) +#define VHOST_ACK_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) + +/* Set current process as the (exclusive) owner of this file descriptor. This +* must be called before any other vhost command. Further calls to +* VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ +#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) +/* Give up ownership, and reset the device to default values. +* Allows subsequent call to VHOST_OWNER_SET to succeed. */ +#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) + +/* Set up/modify memory layout */ +#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) + +/* Ring setup. These parameters can not be modified while ring is running +* (bound to a device). */ +/* Set number of descriptors in ring */ +#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) +/* Start of array of descriptors (virtually contiguous) */ +#define VHOST_SET_VRING_DESC _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) +/* Used structure address */ +#define VHOST_SET_VRING_USED _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_addr) +/* Available structure address */ +#define VHOST_SET_VRING_AVAIL _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_addr) +/* Base value where queue looks for available descriptors */ +#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) +/* Get accessor: reads index, writes value in num */ +#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x14, struct vhost_vring_state) + +/* The following ioctls use eventfd file descriptors to signal and poll +* for events. */ + +/* Set eventfd to poll for added buffers */ +#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) +/* Set eventfd to signal when buffers have beed used */ +#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) +/* Set eventfd to signal an error */ +#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) + +/* VHOST_NET specific defines */ + +/* Attach virtio net device to a raw socket. The socket must be already +* bound to an ethernet device, this device will be used for transmit. +* Pass -1 to unbind from the socket and the transmit device. +* This can be used to stop the device (e.g. for migration). */ +#define VHOST_NET_SET_SOCKET _IOW(VHOST_VIRTIO, 0x30, int)
Quoted 8 lines
Quoted 8 lines
include/linux/vhost.h new file +2
-0+ +#endif Signature · 5 lines
1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michael S. Tsirkin
maintainerRe: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Ira W. SnyderQuoted 48 lines · Ira W. Snyder
Quoted 35 lines
drivers/vhost/vhost.c new file +35
-0+case VHOST_SET_VRING_KICK : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->kick) { + pollstop = filep = vq->kick; + pollstart = vq->kick = eventfp; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_CALL : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp)) +return PTR_ERR (eventfp); +if (eventfp != vq->call) { + filep = vq->call; + ctx = vq->call_ctx; + vq->call = eventfp; + vq->call_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ; +case VHOST_SET_VRING_ERR : + r =copy_from_user (&f, argp,sizeof f); +if (r <0 ) +break ; + eventfp = f.fd ==-1 ?NULL :eventfd_fget (f.fd); +if (IS_ERR (eventfp))drivers/vhost/vhost.c line 367
Quoted 10 lines
drivers/vhost/vhost.c new file +10
-0+return PTR_ERR (eventfp); +if (eventfp != vq->error) { + filep = vq->error; + vq->error = eventfp; + ctx = vq->error_ctx; + vq->error_ctx = eventfp ? +eventfd_ctx_fileget (eventfp) :NULL ; + }else + filep = eventfp; +break ;I'm not sure how these eventfd's save a trip to userspace.
Quoted 2 lines
AFAICT, eventfd's cannot be used to signal another part of the kernel, they can only be used to wake up userspace.
Yes, they can. See irqfd code in virt/kvm/eventfd.c.
Quoted 10 lines
In my system, when an IRQ for
kick()comes in, I have an eventfd which gets signalled to notify userspace. When I want to send acall(), I have to use a specialioctl(), just like lguest does.Doesn't this mean that for
call(), vhost is just going to signal an eventfd to wake up userspace, which is then going to callioctl(), and then we're back in kernelspace. Seems like a wasted userspace round-trip.Or am I mis-reading this code?
Yes. Kernel can poll eventfd and deliver an interrupt directly without involving userspace.
Quoted 592 lines
PS - you can see my current code at:
http://www.mmarray.org/~iws/virtio-phys/Thanks,
IraQuoted 586 lines
drivers/vhost/vhost.c new file +321
-0+default : + r = -ENOIOCTLCMD ; + } + +if (pollstop && vq->handle_kick) +vhost_poll_stop (&vq->poll); + +if (ctx) +eventfd_ctx_put (ctx); +if (filep) +fput (filep); + +if (pollstart && vq->handle_kick) +vhost_poll_start (&vq->poll, vq->kick); + +mutex_unlock (&vq->mutex); + +if (pollstop && vq->handle_kick) +vhost_poll_flush (&vq->poll); +return 0 ; +} + +long vhost_dev_ioctl (struct vhost_dev *d,unsigned int ioctl,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +long r; + +mutex_lock (&d->mutex); +/* If you are not the owner, you can become one */ +if (ioctl ==VHOST_SET_OWNER ) { + r =vhost_dev_set_owner (d); + goto done; + } + +/* You must be the owner to do anything else */ + r =vhost_dev_check_owner (d); +if (r) + goto done; + +switch (ioctl) { +case VHOST_SET_MEM_TABLE : + r =vhost_set_memory (d, argp); +break ; +default : + r =vhost_set_vring (d, ioctl, argp); +break ; + } +done: +mutex_unlock (&d->mutex); +return r; +} + +static const struct vhost_memory_region *find_region (struct vhost_memory *mem, +__u64 addr,__u32 len) +{ +struct vhost_memory_region *reg; +int i; +/* linear search is not brilliant, but we really have on the order of 6 +* regions in practice */ +for (i =0 ; i < mem->nregions; ++i) { + reg = mem->regions + i; +if (reg->guest_phys_addr <= addr && + reg->guest_phys_addr + reg->memory_size -1 >= addr) +return reg; + } +return NULL ; +} + +int translate_desc (struct vhost_dev *dev,u64 addr,u32 len, +struct iovec iov[],int iov_size) +{ +const struct vhost_memory_region *reg; +struct vhost_memory *mem; +struct iovec *_iov; +u64 s =0 ; +int ret =0 ; + +rcu_read_lock (); + + mem =rcu_dereference (dev->memory); +while ((u64 )len > s) { +u64 size; +if (ret >= iov_size) { + ret = -ENOBUFS ; +break ; + } + reg =find_region (mem, addr, len); +if (!reg) { + ret = -EFAULT ; +break ; + } + _iov = iov + ret; + size = reg->memory_size - addr + reg->guest_phys_addr; + _iov->iov_len =min ((u64 )len, size); + _iov->iov_base = (void *) + (reg->userspace_addr + addr - reg->guest_phys_addr); + s += size; + addr += size; + ++ret; + } + +rcu_read_unlock (); +return ret; +} + +/* Each buffer in the virtqueues is actually a chain of descriptors. This +* function returns the next descriptor in the chain, or vq->vring.num if we're +* at the end. */ +static unsigned next_desc (struct vhost_virtqueue *vq,struct vring_desc *desc) +{ +unsigned int next; + +/* If this descriptor says it doesn't chain, we're done. */ +if (!(desc->flags &VRING_DESC_F_NEXT )) +return vq->num; + +/* Check they're not leading us off end of descriptors. */ + next = desc->next; +/* Make sure compiler knows to grab that: we don't want it changing! */ +/* We will use the result as an index in an array, so most +* architectures only need a compiler barrier here. */ +read_barrier_depends (); + +if (next >= vq->num) { +vq_err (vq,"Desc next is %u > %u" , next, vq->num); +return vq->num; + } + +return next; +} + +/* This looks in the virtqueue and for the first available buffer, and converts +* it to an iovec for convenient access. Since descriptors consist of some +* number of output then some number of input descriptors, it's actually two +* iovecs, but we pack them into one and note how many of each there were. +* +* This function returns the descriptor number found, or vq->num (which +* is never a valid descriptor number) if none was found. */ +unsigned vhost_get_vq_desc (struct vhost_dev *dev,struct vhost_virtqueue *vq, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num) +{ +struct vring_desc desc; +unsigned int i, head; +u16 last_avail_idx; +int ret; + +/* Check it isn't doing very strange things with descriptor numbers. */ + last_avail_idx = vq->last_avail_idx; +if (get_user (vq->avail_idx, &vq->avail->idx)) { +vq_err (vq,"Failed to access avail idx at %p\n" , + &vq->avail->idx); +return vq->num; + } + +if ((u16)(vq->avail_idx - last_avail_idx) > vq->num) { +vq_err (vq,"Guest moved used index from %u to %u" , + last_avail_idx, vq->avail_idx); +return vq->num; + } + +/* If there's nothing new since last we looked, return invalid. */ +if (vq->avail_idx == last_avail_idx) +return vq->num; + +/* Grab the next descriptor number they're advertising, and increment +* the index we've seen. */ +if (get_user (head, &vq->avail->ring[last_avail_idx % vq->num])) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return vq->num; + } + +/* If their number is silly, that's an error. */ +if (head >= vq->num) { +vq_err (vq,"Guest says index %u > %u is available" , + head, vq->num); +return vq->num; + } + + vq->last_avail_idx++; + +/* When we start there are none of either input nor output. */ + *out_num = *in_num =0 ; + + i = head; +do { +unsigned iov_count = *in_num + *out_num; +if (copy_from_user (&desc, vq->desc + i,sizeof desc)) { +vq_err (vq,"Failed to get descriptor: idx %d addr %p\n" , + i, vq->desc + i); +return vq->num; + } + ret =translate_desc (dev, desc.addr, desc.len, iov + iov_count, +VHOST_NET_MAX_SG - iov_count); +if (ret <0 ) { +vq_err (vq,"Translation failure %d descriptor idx %d\n" , + ret, i); +return vq->num; + } +/* If this is an input descriptor, increment that count. */ +if (desc.flags &VRING_DESC_F_WRITE ) + *in_num += ret; +else { +/* If it's an output descriptor, they're all supposed +* to come before any input descriptors. */ +if (*in_num) { +vq_err (vq,"Descriptor has out after in: " +"idx %d\n" , i); +return vq->num; + } + *out_num += ret; + } + }while ((i =next_desc (vq, &desc)) != vq->num); +return head; +} + +/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ +void vhost_discard_vq_desc (struct vhost_virtqueue *vq) +{ + vq->last_avail_idx--; +} + +/* After we've used one of their buffers, we tell them about it. We'll then +* want to send them an interrupt, using vq->call. */ +int vhost_add_used (struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +struct vring_used_elem *used; + +/* The virtqueue contains a ring of used buffers. Get a pointer to the +* next entry in that used ring. */ + used = &vq->used->ring[vq->last_used_idx % vq->num]; +if (put_user (head, &used->id)) { +vq_err (vq,"Failed to write used id" ); +return -EFAULT ; + } +if (put_user (len, &used->len)) { +vq_err (vq,"Failed to write used len" ); +return -EFAULT ; + } +/* Make sure buffer is written before we update index. */ +wmb (); +if (put_user (vq->last_used_idx +1 , &vq->used->idx)) { +vq_err (vq,"Failed to increment used idx" ); +return -EFAULT ; + } + vq->last_used_idx++; +return 0 ; +} + +/* This actually sends the interrupt for this virtqueue */ +void vhost_trigger_irq (struct vhost_dev *dev,struct vhost_virtqueue *vq) +{ +__u16 flags =0 ; +if (get_user (flags, &vq->avail->flags)) { +vq_err (vq,"Failed to get flags" ); +return ; + } + +/* If they don't want an interrupt, don't send one, unless empty. */ +if ((flags &VRING_AVAIL_F_NO_INTERRUPT ) && + (!vhost_has_feature (dev,VIRTIO_F_NOTIFY_ON_EMPTY ) || + vq->avail_idx != vq->last_avail_idx)) +return ; + +/* Send the Guest an interrupt tell them we used something up. */ +if (vq->call_ctx) +eventfd_signal (vq->call_ctx,1 ); +} + +/* And here's the combo meal deal. Supersize me! */ +void vhost_add_used_and_trigger (struct vhost_dev *dev, +struct vhost_virtqueue *vq, +unsigned int head,int len) +{ +vhost_add_used (vq, head, len); +vhost_trigger_irq (dev, vq); +} + +/* OK, now we need to know about added descriptors. */ +bool vhost_notify (struct vhost_virtqueue *vq) +{ +int r; +if (!(vq->used_flags &VRING_USED_F_NO_NOTIFY )) +return false; + vq->used_flags &= ~VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to disable notification: %d\n" , r); +/* They could have slipped one in as we were doing that: make +* sure it's written, tell caller it needs to check again. */ +mb (); +return true; +} + +/* We don't need to be notified again. */ +void vhost_no_notify (struct vhost_virtqueue *vq) +{ +int r; +if (vq->used_flags &VRING_USED_F_NO_NOTIFY ) +return ; + vq->used_flags |=VRING_USED_F_NO_NOTIFY ; + r =put_user (vq->used_flags, &vq->used->flags); +if (r) +vq_err (vq,"Failed to enable notification: %d\n" , r); +} + +int vhost_init (void ) +{ + vhost_workqueue =create_workqueue ("vhost" ); +if (!vhost_workqueue) +return -ENOMEM ; +return 0 ; +} + +void vhost_cleanup (void ) +{ +destroy_workqueue (vhost_workqueue); +}drivers/vhost/vhost.h new file +122
-0@@ -0,0 +1,122 @@ +#ifndef _VHOST_H +#define _VHOST_H + +#include <linux/eventfd.h> +#include <linux/vhost.h> +#include <linux/mm.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/poll.h> +#include <linux/file.h> +#include <linux/skbuff.h> +#include <linux/uio.h> +#include <linux/virtio_config.h> + +struct vhost_device ; + +enum { +VHOST_NET_MAX_SG =MAX_SKB_FRAGS +2 , +}; + +/* Poll a file (eventfd or socket) */ +/* Note: there's nothing vhost specific about this structure. */ +struct vhost_poll { +poll_table table; +wait_queue_head_t *wqh; +wait_queue_t wait; +/* struct which will handle all actual work. */ +struct work_struct work; +unsigned long mask; +}; + +void vhost_poll_init (struct vhost_poll *poll,work_func_t func, +unsigned long mask); +void vhost_poll_start (struct vhost_poll *poll,struct file *file); +void vhost_poll_stop (struct vhost_poll *poll); +void vhost_poll_flush (struct vhost_poll *poll); + +/* The virtqueue structure describes a queue attached to a device. */ +struct vhost_virtqueue { +struct vhost_dev *dev; + +/* The actual ring of buffers. */ +struct mutex mutex; +unsigned int num; +struct vring_desc __user *desc; +struct vring_avail __user *avail; +struct vring_used __user *used; +struct file *kick; +struct file *call; +struct file *error; +struct eventfd_ctx *call_ctx; +struct eventfd_ctx *error_ctx; + +struct vhost_poll poll; + +/* The routine to call when the Guest pings us, or timeout. */ +work_func_t handle_kick; + +/* Last available index we saw. */ +u16 last_avail_idx; + +/* Caches available index value from user. */ +u16 avail_idx; + +/* Last index we used. */ +u16 last_used_idx; + +/* Used flags */ +u16 used_flags; + +struct iovec iov[VHOST_NET_MAX_SG ]; +struct iovec hdr[VHOST_NET_MAX_SG ]; +}; + +struct vhost_dev { +/* Readers use RCU to access memory table pointer. +* Writers use mutex below.*/ +struct vhost_memory *memory; +struct mm_struct *mm; +struct vhost_virtqueue *vqs; +int nvqs; +struct mutex mutex; +unsigned acked_features; +}; + +long vhost_dev_init (struct vhost_dev *,struct vhost_virtqueue *vqs,int nvqs); +long vhost_dev_check_owner (struct vhost_dev *); +long vhost_dev_reset_owner (struct vhost_dev *); +void vhost_dev_cleanup (struct vhost_dev *); +long vhost_dev_ioctl (struct vhost_dev *,unsigned int ioctl,unsigned long arg); + +unsigned vhost_get_vq_desc (struct vhost_dev *,struct vhost_virtqueue *, +struct iovec iov[], +unsigned int *out_num,unsigned int *in_num); +void vhost_discard_vq_desc (struct vhost_virtqueue *); + +int vhost_add_used (struct vhost_virtqueue *,unsigned int head,int len); +void vhost_trigger_irq (struct vhost_dev *,struct vhost_virtqueue *); +void vhost_add_used_and_trigger (struct vhost_dev *,struct vhost_virtqueue *, +unsigned int head,int len); +void vhost_no_notify (struct vhost_virtqueue *); +bool vhost_notify (struct vhost_virtqueue *); + +int vhost_init (void ); +void vhost_cleanup (void ); + +#define vq_err (vq, fmt, ...) do { \ + pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ + if ((vq)->error_ctx) \ + eventfd_signal((vq)->error_ctx, 1);\ + } while (0) + +enum { +VHOST_FEATURES =1 <<VIRTIO_F_NOTIFY_ON_EMPTY , +}; + +static inline int vhost_has_feature (struct vhost_dev *dev,int bit) +{ +return dev->acked_features & (1 << bit); +} + +#endif include/linux/Kbuild +1
-0@@ -360,6 +360,7 @@ unifdef-y += uio.h unifdef-y += unistd.h unifdef-y += usbdevice_fs.h unifdef-y += utsname.h +unifdef-y += vhost.h unifdef-y += videodev2.h unifdef-y += videodev.h unifdef-y += virtio_config.hinclude/linux/miscdevice.h +1
-0@@ -30,6 +30,7 @@#define HPET_MINOR 228#define FUSE_MINOR 229#define KVM_MINOR 232 +#define VHOST_NET_MINOR 233#define MISC_DYNAMIC_MINOR 255struct device ;include/linux/vhost.h new file +101
-0@@ -0,0 +1,101 @@ +#ifndef _LINUX_VHOST_H +#define _LINUX_VHOST_H +/* Userspace interface for in-kernel virtio accelerators. */ + +/* vhost is used to reduce the number of system calls involved in virtio. +* +* Existing virtio net code is used in the guest without modification. +* +* This header includes interface used by userspace hypervisor for +* device configuration. +*/ + +#include <linux/types.h> +#include <linux/compiler.h> +#include <linux/ioctl.h> +#include <linux/virtio_config.h> +#include <linux/virtio_ring.h> + +struct vhost_vring_state { +unsigned int index; +unsigned int num; +}; + +struct vhost_vring_file { +unsigned int index; +int fd; +}; + +struct vhost_vring_addr { +unsigned int index; +unsigned int padding; +__u64 user_addr; +}; + +struct vhost_memory_region { +__u64 guest_phys_addr; +__u64 memory_size;/* bytes */ +__u64 userspace_addr; +__u64 padding;/* read/write protection? */ +}; + +struct vhost_memory { +__u32 nregions; +__u32 padding; +struct vhost_memory_region regions[0 ]; +}; + +/* ioctls */ + +#define VHOST_VIRTIO 0xAF + +/* Features bitmask for forward compatibility. Transport bits are used for +* vhost specific features. */ +#define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) +#define VHOST_ACK_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) + +/* Set current process as the (exclusive) owner of this file descriptor. This +* must be called before any other vhost command. Further calls to +* VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ +#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) +/* Give up ownership, and reset the device to default values. +* Allows subsequent call to VHOST_OWNER_SET to succeed. */ +#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) + +/* Set up/modify memory layout */ +#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) + +/* Ring setup. These parameters can not be modified while ring is running +* (bound to a device). */ +/* Set number of descriptors in ring */ +#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) +/* Start of array of descriptors (virtually contiguous) */ +#define VHOST_SET_VRING_DESC _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) +/* Used structure address */ +#define VHOST_SET_VRING_USED _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_addr) +/* Available structure address */ +#define VHOST_SET_VRING_AVAIL _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_addr) +/* Base value where queue looks for available descriptors */ +#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) +/* Get accessor: reads index, writes value in num */ +#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x14, struct vhost_vring_state) + +/* The following ioctls use eventfd file descriptors to signal and poll +* for events. */ + +/* Set eventfd to poll for added buffers */ +#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) +/* Set eventfd to signal when buffers have beed used */ +#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) +/* Set eventfd to signal an error */ +#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) + +/* VHOST_NET specific defines */ + +/* Attach virtio net device to a raw socket. The socket must be already +* bound to an ethernet device, this device will be used for transmit. +* Pass -1 to unbind from the socket and the transmit device. +* This can be used to stop the device (e.g. for migration). */ +#define VHOST_NET_SET_SOCKET _IOW(VHOST_VIRTIO, 0x30, int) + +#endif Signature · 5 lines
1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 10 lines · Gregory Haskins
Quoted 10 lines
Quoted 9 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
Quoted 5 lines
Quoted 3 lines
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands.
Thanks for finally starting to acknowledge there's a benefit, at least.
I think I've mentioned vbus' finer grained layers as helpful here, though I doubt the value of this. Hypervisors are added rarely, while devices and drivers are added (and modified) much more often. I don't buy the anything-to-anything promise.
Quoted 9 lines
To be more precise, IMO virtio is designed to be a performance oriented ring-based driver interface that supports all types of hypervisors (e.g. shmem based kvm, and non-shmem based Xen). vbus is designed to be a high-performance generic shared-memory interconnect (for rings or otherwise) framework for environments where linux is the underpinning "host" (physical or virtual). They are distinctly different, but complementary (the former addresses the part of the front-end, and latter addresses the back-end, and a different part of the front-end).
They're not truly complementary since they're incompatible. A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work over vbus. Further, non-shmem virtio can't work over vbus. Since virtio is guest-oriented and host-agnostic, it can't ignore non-shared-memory hosts (even though it's unlikely virtio will be adopted there).
Quoted 4 lines
In addition, the kvm-connector used in AlacrityVM's design strives to add value and improve performance via other mechanisms, such as dynamic
allocation, interrupt coalescing (thus reducing exit-ratio, which is a
serious issue in KVM)
Do you have measurements of inter-interrupt coalescing rates (excluding intra-interrupt coalescing).
Quoted 2 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Quoted 7 lines
Today there is a large performance disparity between what a KVM guest sees and what a native linux application sees on that same host. Just take a look at some of my graphs between "virtio", and "native", for example:
http://developer.novell.com/wiki/images/b/b7/31-rc4_throughput.png
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
Quoted 11 lines
A dominant vbus design principle is to try to achieve the same IO performance for all "linux applications" whether they be literally userspace applications, or things like KVM vcpus or Ira's physical boards. It also aims to solve problems not previously expressible with current technologies (even virtio), like nested real-time.
And even though you repeatedly insist otherwise, the neat thing here is that the two technologies mesh (at least under certain circumstances, like when virtio is deployed on a shared-memory friendly linux backend like KVM). I hope that my stack diagram below depicts that clearly.
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Quoted 7 lines
Quoted 3 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
As vhost-net shows, you can do that without vbus and without breaking compatibility.
Quoted 11 lines
Quoted 4 lines
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
No, virtio doesn't assume that. It's stack provides the "virtio-bus" abstraction and what it does assume is that it will be wired up to something underneath. Kvm/x86 conveniently has pci, so the virtio-pci adapter was created to reuse much of that facility. For other things like lguest and s360, something new had to be created underneath to make up for the lack of pci-like support.
Right, I was wrong there. But it does allow you to have a 1:1 mapping between native devices and virtio devices.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
Quoted 8 lines
First of all, thats incorrect. If you want to use the "native" mechanisms (via the way the vbus-connector is implemented, for instance) you at least still have the benefit that the backend design is more broadly re-useable in more environments (like non-virt, for instance), because vbus does a proper job of defining the requisite layers/abstractions compared to vhost. So it adds value even in that situation.
Maybe. If vhost-net isn't sufficient I'm sure there will be patches sent.
Quoted 7 lines
Second of all, with PV there is no such thing as "native". It's software so it can be whatever we want. Sure, you could argue that the guest may have built-in support for something like PCI protocol. However, PCI protocol itself isn't suitable for high-performance PV out of the can. So you will therefore invariably require new software layers on top anyway, even if part of the support is already included.
Of course there is such a thing as native, a pci-ready guest has tons of support built into it that doesn't need to be retrofitted. Since practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.
Quoted 8 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
The short answer is "compatibility".
Quoted 9 lines
In summary, vbus is simply one more bus of many, purpose built to support high-end IO in a virt-like model, giving controlled access to the linux-host underneath it. You can write a high-performance layer below the OS bus-model (vbus), or above it (virtio-pci) but either way you are modifying the stack to add these capabilities, so we might as well try to get this right.
With all due respect, you are making a big deal out of a minor issue.
It's not minor to me.
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.Only theoretically. The existing installed base would have to be thrown away
"Thrown away" is pure hyperbole. The installed base, worse case, needs to load a new driver for a missing device.
Yes, we all know how fun this is. Especially if the device changed is your boot disk. You may not care about the pain caused to users, but I do, so I will continue to insist on compatibility.
Quoted 8 lines
Quoted 4 lines
or we'd need to support both.
No matter what model we talk about, there's always going to be a "both" since the userspace virtio models are probably not going to go away (nor should they).
virtio allows you to have userspace-only, kernel-only, or start-with-userspace-and-move-to-kernel-later, all transparent to the guest. In many cases we'll stick with userspace-only.
Quoted 9 lines
Quoted 3 lines
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
How the connector message is delivered is really not relevant. Some architectures will simply deliver the message point-to-point (like the original hypercall design for KVM, or something like Ira's rig), and some will need additional demuxing (like pci-bridge/pio based KVM). It's an implementation detail of the connector.
Quoted 5 lines
However, the real point here is that something needs to establish a scoped namespace mechanism, add items to that namespace, and advertise the presence of the items to the guest. vbus has this facility built in to its stack. vhost doesn't, so it must come from elsewhere.
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode), vhost needs userspace to instantiate the devices and program the addresses.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
Quoted 4 lines
Quoted 2 lines
It doesn't have just virtio-net, it has userspace-based hostplug
vbus has hotplug too: mkdir and rmdir
Does that work from nonprivileged processes? Does it work on Windows?
Quoted 9 lines
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Afaict, qemu can't do either of those things.
We've seen that herring before, and it's redder than ever.
Quoted 5 lines
Quoted 2 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
So define them if they're missing.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Quoted 9 lines
Quoted 2 lines
Refactor instead of rewriting.
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
It's not compatible. If you were truly worried about code duplication in virtio, you'd refactor it to remove the duplication, without affecting existing guests.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 5 lines
Quoted 3 lines
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux);
vmware only cares about x86 iiuc, so probably not a good example.
Well, you brought it up. Between you and me, I only care about x86 too.
Quoted 7 lines
Quoted 5 lines
Xen has to tunnel
xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.So pick any other hypervisor, and the situation is often similar.
The situation is often pci.
Quoted 11 lines
Quoted 6 lines
An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
vbus is not interested in userspace devices. The charter is to provide facilities for utilizing the host linux kernel's IO capabilities in the most efficient, yet safe, manner possible. Those devices that fit outside that charter can ride on legacy mechanisms if that suits them best.
vbus isn't, but I am. I would prefer not to have to expose implementation decisions (kernel vs userspace) to the guest (vbus vs pci).
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
vbus needs the same thing so it cancels out.
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
That's ioeventfd. So far so similar.
Quoted 5 lines
Per queue/device addressing is handled by the same conceptual namespace
as the one that would trigger eventfds in the model you mention. And that namespace is built in to the vbus stack, and objects are registered automatically as they are created.
Quoted 8 lines
Contrast that to vhost, which requires some other kernel interface to exist, and to be managed manually for each object that is created. Your libvhostconfig would need to somehow know how to perform this registration operation, and there would have to be something in the kernel to receive it, presumably on a per platform basis. Solving this problem generally would probably end up looking eerily like vbus, because thats what vbus does.
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
Quoted 5 lines
Quoted 5 lines
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
Quoted 8 lines
yes, its in sysfs.
Quoted 3 lines
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
yes, its in sysfs.
Per-device? non-privileged-user capable?
Quoted 11 lines
Quoted 3 lines
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
no, but we can easily add ->save()/->restore() to the model going forward, and the negotiated features are just a subcomponent if its serialized stream.
Quoted 3 lines
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
Quoted 7 lines
that would be the function of the ->restore() deserializer.
Quoted 2 lines
- do all that from an unprivileged process
yes, in the upcoming alacrityvm v0.3 with the ioctl based control plane.
Ah, so you have two control planes.
Quoted 6 lines
Bottom line: vbus isn't done, especially w.r.t. live-migration..but that is not an valid argument against the idea if you believe in release-early/release-often. kvm wasn't (isn't) done either when it was proposed/merged.
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 10 lines · Gregory Haskins
Quoted 10 lines
Quoted 9 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
Quoted 5 lines
Quoted 3 lines
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands.
Thanks for finally starting to acknowledge there's a benefit, at least.
I think I've mentioned vbus' finer grained layers as helpful here, though I doubt the value of this. Hypervisors are added rarely, while devices and drivers are added (and modified) much more often. I don't buy the anything-to-anything promise.
Quoted 9 lines
To be more precise, IMO virtio is designed to be a performance oriented ring-based driver interface that supports all types of hypervisors (e.g. shmem based kvm, and non-shmem based Xen). vbus is designed to be a high-performance generic shared-memory interconnect (for rings or otherwise) framework for environments where linux is the underpinning "host" (physical or virtual). They are distinctly different, but complementary (the former addresses the part of the front-end, and latter addresses the back-end, and a different part of the front-end).
They're not truly complementary since they're incompatible. A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work over vbus. Further, non-shmem virtio can't work over vbus. Since virtio is guest-oriented and host-agnostic, it can't ignore non-shared-memory hosts (even though it's unlikely virtio will be adopted there).
Quoted 4 lines
In addition, the kvm-connector used in AlacrityVM's design strives to add value and improve performance via other mechanisms, such as dynamic
allocation, interrupt coalescing (thus reducing exit-ratio, which is a
serious issue in KVM)
Do you have measurements of inter-interrupt coalescing rates (excluding intra-interrupt coalescing).
Quoted 2 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Quoted 7 lines
Today there is a large performance disparity between what a KVM guest sees and what a native linux application sees on that same host. Just take a look at some of my graphs between "virtio", and "native", for example:
http://developer.novell.com/wiki/images/b/b7/31-rc4_throughput.png
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
Quoted 11 lines
A dominant vbus design principle is to try to achieve the same IO performance for all "linux applications" whether they be literally userspace applications, or things like KVM vcpus or Ira's physical boards. It also aims to solve problems not previously expressible with current technologies (even virtio), like nested real-time.
And even though you repeatedly insist otherwise, the neat thing here is that the two technologies mesh (at least under certain circumstances, like when virtio is deployed on a shared-memory friendly linux backend like KVM). I hope that my stack diagram below depicts that clearly.
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Quoted 7 lines
Quoted 3 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
As vhost-net shows, you can do that without vbus and without breaking compatibility.
Quoted 11 lines
Quoted 4 lines
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
No, virtio doesn't assume that. It's stack provides the "virtio-bus" abstraction and what it does assume is that it will be wired up to something underneath. Kvm/x86 conveniently has pci, so the virtio-pci adapter was created to reuse much of that facility. For other things like lguest and s360, something new had to be created underneath to make up for the lack of pci-like support.
Right, I was wrong there. But it does allow you to have a 1:1 mapping between native devices and virtio devices.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
Quoted 8 lines
First of all, thats incorrect. If you want to use the "native" mechanisms (via the way the vbus-connector is implemented, for instance) you at least still have the benefit that the backend design is more broadly re-useable in more environments (like non-virt, for instance), because vbus does a proper job of defining the requisite layers/abstractions compared to vhost. So it adds value even in that situation.
Maybe. If vhost-net isn't sufficient I'm sure there will be patches sent.
Quoted 7 lines
Second of all, with PV there is no such thing as "native". It's software so it can be whatever we want. Sure, you could argue that the guest may have built-in support for something like PCI protocol. However, PCI protocol itself isn't suitable for high-performance PV out of the can. So you will therefore invariably require new software layers on top anyway, even if part of the support is already included.
Of course there is such a thing as native, a pci-ready guest has tons of support built into it that doesn't need to be retrofitted. Since practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.
Quoted 8 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
The short answer is "compatibility".
Quoted 9 lines
In summary, vbus is simply one more bus of many, purpose built to support high-end IO in a virt-like model, giving controlled access to the linux-host underneath it. You can write a high-performance layer below the OS bus-model (vbus), or above it (virtio-pci) but either way you are modifying the stack to add these capabilities, so we might as well try to get this right.
With all due respect, you are making a big deal out of a minor issue.
It's not minor to me.
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.Only theoretically. The existing installed base would have to be thrown away
"Thrown away" is pure hyperbole. The installed base, worse case, needs to load a new driver for a missing device.
Yes, we all know how fun this is. Especially if the device changed is your boot disk. You may not care about the pain caused to users, but I do, so I will continue to insist on compatibility.
Quoted 8 lines
Quoted 4 lines
or we'd need to support both.
No matter what model we talk about, there's always going to be a "both" since the userspace virtio models are probably not going to go away (nor should they).
virtio allows you to have userspace-only, kernel-only, or start-with-userspace-and-move-to-kernel-later, all transparent to the guest. In many cases we'll stick with userspace-only.
Quoted 9 lines
Quoted 3 lines
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
How the connector message is delivered is really not relevant. Some architectures will simply deliver the message point-to-point (like the original hypercall design for KVM, or something like Ira's rig), and some will need additional demuxing (like pci-bridge/pio based KVM). It's an implementation detail of the connector.
Quoted 5 lines
However, the real point here is that something needs to establish a scoped namespace mechanism, add items to that namespace, and advertise the presence of the items to the guest. vbus has this facility built in to its stack. vhost doesn't, so it must come from elsewhere.
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode), vhost needs userspace to instantiate the devices and program the addresses.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
In fact, it's actually a simpler design to unify things this way because you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
Quoted 4 lines
Quoted 2 lines
It doesn't have just virtio-net, it has userspace-based hostplug
vbus has hotplug too: mkdir and rmdir
Does that work from nonprivileged processes? Does it work on Windows?
Quoted 9 lines
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Afaict, qemu can't do either of those things.
We've seen that herring before, and it's redder than ever.
Quoted 5 lines
Quoted 2 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
So define them if they're missing.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Use libraries (virtio-shmem.ko, libvhost.so).
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Quoted 9 lines
Quoted 2 lines
Refactor instead of rewriting.
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
It's not compatible. If you were truly worried about code duplication in virtio, you'd refactor it to remove the duplication, without affecting existing guests.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 5 lines
Quoted 3 lines
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux);
vmware only cares about x86 iiuc, so probably not a good example.
Well, you brought it up. Between you and me, I only care about x86 too.
Quoted 7 lines
Quoted 5 lines
Xen has to tunnel
xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.So pick any other hypervisor, and the situation is often similar.
The situation is often pci.
Quoted 11 lines
Quoted 6 lines
An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
vbus is not interested in userspace devices. The charter is to provide facilities for utilizing the host linux kernel's IO capabilities in the most efficient, yet safe, manner possible. Those devices that fit outside that charter can ride on legacy mechanisms if that suits them best.
vbus isn't, but I am. I would prefer not to have to expose implementation decisions (kernel vs userspace) to the guest (vbus vs pci).
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
vbus needs the same thing so it cancels out.
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
That's ioeventfd. So far so similar.
Quoted 5 lines
Per queue/device addressing is handled by the same conceptual namespace
as the one that would trigger eventfds in the model you mention. And that namespace is built in to the vbus stack, and objects are registered automatically as they are created.
Quoted 8 lines
Contrast that to vhost, which requires some other kernel interface to exist, and to be managed manually for each object that is created. Your libvhostconfig would need to somehow know how to perform this registration operation, and there would have to be something in the kernel to receive it, presumably on a per platform basis. Solving this problem generally would probably end up looking eerily like vbus, because thats what vbus does.
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
Quoted 5 lines
Quoted 5 lines
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
Quoted 8 lines
yes, its in sysfs.
Quoted 3 lines
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
yes, its in sysfs.
Per-device? non-privileged-user capable?
Quoted 11 lines
Quoted 3 lines
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
no, but we can easily add ->save()/->restore() to the model going forward, and the negotiated features are just a subcomponent if its serialized stream.
Quoted 3 lines
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
Quoted 7 lines
that would be the function of the ->restore() deserializer.
Quoted 2 lines
- do all that from an unprivileged process
yes, in the upcoming alacrityvm v0.3 with the ioctl based control plane.
Ah, so you have two control planes.
Quoted 6 lines
Bottom line: vbus isn't done, especially w.r.t. live-migration..but that is not an valid argument against the idea if you believe in release-early/release-often. kvm wasn't (isn't) done either when it was proposed/merged.
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 14 lines · Avi Kivity
Quoted 13 lines · Gregory Haskins
Quoted 13 lines
Quoted 9 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands.
Quoted 7 lines
Quoted 2 lines
Thanks for finally starting to acknowledge there's a benefit, at least.
I think I've mentioned vbus' finer grained layers as helpful here, though I doubt the value of this. Hypervisors are added rarely, while devices and drivers are added (and modified) much more often. I don't buy the anything-to-anything promise.
The ease in which a new hypervisor should be able to integrate into the stack is only one of vbus's many benefits.
Quoted 11 lines
Quoted 10 lines
To be more precise, IMO virtio is designed to be a performance oriented ring-based driver interface that supports all types of hypervisors (e.g. shmem based kvm, and non-shmem based Xen). vbus is designed to be a high-performance generic shared-memory interconnect (for rings or otherwise) framework for environments where linux is the underpinning "host" (physical or virtual). They are distinctly different, but complementary (the former addresses the part of the front-end, and latter addresses the back-end, and a different part of the front-end).
Quoted 1 line
They're not truly complementary since they're incompatible.
No, that is incorrect. Not to be rude, but for clarity:
Complementary \Com`ple*men"ta*ry\, a.
Serving to fill out or to complete; as, complementary numbers.
[1913 Webster]
Citation: www.dict.org
IOW: Something being complementary has nothing to do with guest/host binary compatibility. virtio-pci and virtio-vbus are both equally complementary to virtio since they fill in the bottom layer of the virtio stack.
So yes, vbus is truly complementary to virtio afaict.
Quoted 2 lines
A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work over vbus.
Binary compatibility with existing virtio drivers, while nice to have, is not a specific requirement nor goal. We will simply load an updated KMP/MSI into those guests and they will work again. As previously discussed, this is how more or less any system works today. It's like we are removing an old adapter card and adding a new one to "uprev the silicon".
Quoted 1 line
Further, non-shmem virtio can't work over vbus.
Actually I misspoke earlier when I said virtio works over non-shmem. Thinking about it some more, both virtio and vbus fundamentally require shared-memory, since sharing their metadata concurrently on both sides is their raison d'être.
The difference is that virtio utilizes a pre-translation/mapping (via ->add_buf) from the guest side. OTOH, vbus uses a post translation scheme (via memctx) from the host-side. If anything, vbus is actually more flexible because it doesn't assume the entire guest address space is directly mappable.
In summary, your statement is incorrect (though it is my fault for putting that idea in your head).
Quoted 4 lines
Since
virtio is guest-oriented and host-agnostic, it can't ignore non-shared-memory hosts (even though it's unlikely virtio will be adopted there)
Well, to be fair no one said it has to ignore them. Either virtio-vbus transport is present and available to the virtio stack, or it isn't. If its present, it may or may not publish objects for consumption. Providing a virtio-vbus transport in no way limits or degrades the existing capabilities of the virtio stack. It only enhances them.
I digress. The whole point is moot since I realized that the non-shmem distinction isn't accurate anyway. They both require shared-memory for the metadata, and IIUC virtio requires the entire address space to be mappable whereas vbus only assumes the metadata is.
Quoted 8 lines
Quoted 5 lines
In addition, the kvm-connector used in AlacrityVM's design strives to add value and improve performance via other mechanisms, such as dynamic
allocation, interrupt coalescing (thus reducing exit-ratio, which is a
serious issue in KVM)Do you have measurements of inter-interrupt coalescing rates (excluding intra-interrupt coalescing).
I actually do not have a rig setup to explicitly test inter-interrupt rates at the moment. Once things stabilize for me, I will try to re-gather some numbers here. Last time I looked, however, there were some decent savings for inter as well.
Inter rates are interesting because they are what tends to ramp up with IO load more than intra since guest interrupt mitigation techniques like NAPI often quell intra-rates naturally. This is especially true for data-center, cloud, hpc-grid, etc, kind of workloads (vs vanilla desktops, etc) that tend to have multiple IO ports (multi-homed nics, disk-io, etc). Those various ports tend to be workload-related to one another (e.g. 3-tier web stack may use multi-homed network and disk-io at the same time, trigged by one IO event).
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
In any case, here is an example run of a simple single-homed guest over standard GigE. Whats interesting here is that .qnotify to .notify ratio, as this is the interrupt-to-signal ratio. In this case, its 170047/151918, which comes out to about 11% savings in interrupt injections:
vbus-guest:/home/ghaskins # netperf -H dev
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to dev.laurelwood.net (192.168.1.10) port 0 AF_INET
Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
1048576 16384 16384 10.01 940.77
vbus-guest:/home/ghaskins # cat /sys/kernel/debug/pci-to-vbus-bridge
.events : 170048
.qnotify : 151918
.qinject : 0
.notify : 170047
.inject : 18238
.bridgecalls : 18
.buscalls : 12
vbus-guest:/home/ghaskins # cat /proc/interrupts
CPU0
0: 87 IO-APIC-edge timer
1: 6 IO-APIC-edge i8042
4: 733 IO-APIC-edge serial
6: 2 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 0 IO-APIC-edge rtc0
9: 0 IO-APIC-fasteoi acpi
10: 0 IO-APIC-fasteoi virtio1
12: 90 IO-APIC-edge i8042
14: 3041 IO-APIC-edge ata_piix
15: 1008 IO-APIC-edge ata_piix
24: 151933 PCI-MSI-edge vbus
25: 0 PCI-MSI-edge virtio0-config
26: 190 PCI-MSI-edge virtio0-input
27: 28 PCI-MSI-edge virtio0-output
NMI: 0 Non-maskable interrupts
LOC: 9854 Local timer interrupts
SPU: 0 Spurious interrupts
CNT: 0 Performance counter interrupts
PND: 0 Performance pending work
RES: 0 Rescheduling interrupts
CAL: 0 Function call interrupts
TLB: 0 TLB shootdowns
TRM: 0 Thermal event interrupts
THR: 0 Threshold APIC interrupts
MCE: 0 Machine check exceptions
MCP: 1 Machine check polls ERR: 0
MIS: 0
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
Looking at some external stats paints an even bleaker picture: "exits" as reported by kvm_stat for virtio-pci based virtio-net tip the scales at 65k/s vs 36k/s for vbus based venet. And virtio is consuming ~30% of my quad-core's cpu, vs 19% for venet during the test. Its hard to know which innovation or innovations may be responsible for the entire reduction, but certainly the interrupt-to-signal ratio mentioned above is probably helping.
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Quoted 5 lines
Quoted 3 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
PCI is somewhat of an outlier in that regard afaict. Its actually a nice feature of PCI when its used within its design spec (HW). For SW/PV, 1:1 suffers from, among other issues, that "triple-exit scaling" issue in the signal path I mentioned above. This is one of the many reasons I think PCI is not the best choice for PV.
Quoted 6 lines
Quoted 6 lines
Today there is a large performance disparity between what a KVM guest sees and what a native linux application sees on that same host. Just take a look at some of my graphs between "virtio", and "native", for example:
Quoted 6 lines
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
That's pure speculation. I would advise you to reserve such statements until after a proper bakeoff can be completed. This is not to mention that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.
Quoted 7 lines
Quoted 7 lines
A dominant vbus design principle is to try to achieve the same IO performance for all "linux applications" whether they be literally userspace applications, or things like KVM vcpus or Ira's physical boards. It also aims to solve problems not previously expressible with current technologies (even virtio), like nested real-time.
Quoted 8 lines
Quoted 5 lines
And even though you repeatedly insist otherwise, the neat thing here is that the two technologies mesh (at least under certain circumstances, like when virtio is deployed on a shared-memory friendly linux backend like KVM). I hope that my stack diagram below depicts that clearly.
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Where doesn't it fit?
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
As vhost-net shows, you can do that without vbus
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
Quoted 1 line
and without breaking compatibility.
Compatibility with what? vhost hasn't even been officially deployed in KVM environments afaict, nevermind non-virt. Therefore, how could it possibly have compatibility constraints with something non-virt already?
Citation please.
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
Quoted 7 lines
No, virtio doesn't assume that. It's stack provides the "virtio-bus" abstraction and what it does assume is that it will be wired up to something underneath. Kvm/x86 conveniently has pci, so the virtio-pci adapter was created to reuse much of that facility. For other things like lguest and s360, something new had to be created underneath to make up for the lack of pci-like support.
Quoted 2 lines
Right, I was wrong there. But it does allow you to have a 1:1 mapping between native devices and virtio devices.
vbus allows you to have 1:1 if that is what you want, but we strive to do better.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
Quoted 8 lines
First of all, thats incorrect. If you want to use the "native" mechanisms (via the way the vbus-connector is implemented, for instance) you at least still have the benefit that the backend design is more broadly re-useable in more environments (like non-virt, for instance), because vbus does a proper job of defining the requisite layers/abstractions compared to vhost. So it adds value even in that situation.
Quoted 1 line
Maybe. If vhost-net isn't sufficient I'm sure there will be patches sent.
It isn't, and I've already done that.
Quoted 4 lines
Quoted 4 lines
Second of all, with PV there is no such thing as "native". It's software so it can be whatever we want. Sure, you could argue that the guest may have built-in support for something like PCI protocol.
[1]
Quoted 7 lines
Quoted 4 lines
However, PCI protocol itself isn't suitable for high-performance PV out of the can. So you will therefore invariably require new software layers on top anyway, even if part of the support is already included.
Of course there is such a thing as native, a pci-ready guest has tons of support built into it
I specifically mentioned that already ([1]).
You are also overstating its role, since the basic OS is what implements the native support for bus-objects, hotswap, etc, _not_ PCI. PCI just rides underneath and feeds trivial events up, as do other bus-types (usb, scsi, vbus, etc). And once those events are fed, you still need a PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.
Quoted 1 line
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
Not to mention there are things you just plain can't do in PCI today, like dynamically assign signal-paths, priority, and coalescing, etc.
Quoted 3 lines
Since
practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.
Actually IIUC, I think Xen bridges to their own bus as well (and only where they have to), just like vbus. They don't use PCI natively. PCI is perfectly suited as a bridge transport for PV, as I think the Xen and vbus examples have demonstrated. Its the 1:1 device-model where PCI has the most problems.
Quoted 12 lines
Quoted 11 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
Quoted 1 line
The short answer is "compatibility".
There was a point in time where the same could be said for virtio-pci based drivers vs realtek and e1000, so that argument is demonstrably silly. No one tried to make virtio work in a binary compatible way with realtek emulation, yet we all survived the requirement for loading a virtio driver to my knowledge.
The bottom line is: Binary device compatibility is not required in any other system (as long as you follow sensible versioning/id rules), so why is KVM considered special?
The fact is, it isn't special (at least not in this regard). What _is_ required is "support" and we fully intend to support these proposed components. I assure you that at least the users that care about maximum performance will not generally mind loading a driver. Most of them would have to anyway if they want to get beyond realtek emulation.
Quoted 9 lines
Quoted 9 lines
In summary, vbus is simply one more bus of many, purpose built to support high-end IO in a virt-like model, giving controlled access to the linux-host underneath it. You can write a high-performance layer below the OS bus-model (vbus), or above it (virtio-pci) but either way you are modifying the stack to add these capabilities, so we might as well try to get this right.
Quoted 4 lines
Quoted 2 lines
With all due respect, you are making a big deal out of a minor issue.
It's not minor to me.
I am certainly in no position to tell you how to feel, but this declaration would seem from my perspective to be more of a means to an end than a legitimate concern. Otherwise we would never have had virtio support in the first place, since it was not "compatible" with previous releases.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Only theoretically. The existing installed base would have to be thrown away
"Thrown away" is pure hyperbole. The installed base, worse case, needs to load a new driver for a missing device.
Yes, we all know how fun this is.
Making systems perform 5x faster _is_ fun, yes. I love what I do for a living.
Quoted 1 line
Especially if the device changed is your boot disk.
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
Quoted 2 lines
You may not care about the pain caused to users, but I do, so I will
continue to insist on compatibility.
No, you are incorrect on two counts.
1) Of course I care about pain to users or I wouldn't be funded. Right now the pain from my perspective is caused to users in the high-performance community who want to deploy KVM based solutions. They are unable to do so due to its performance disparity compared to bare-metal, outside of pass-through hardware which is not widely available in a lot of existing deployments. I aim to fix that disparity while reusing the existing hardware investment by writing smarter software, and I assure you that these users won't mind loading a driver in the guest to take advantage of it.
For the users that don't care about maximum performance, there is no change (and thus zero pain) required. They can use realtek or virtio if they really want to. Neither is going away to my knowledge, and lets face it: 2.6Gb/s out of virtio to userspace isn't *that* bad. But "good enough" isn't good enough, and I won't rest till we get to native performance. Additionally, I want to support previously unavailable modes of operations (e.g. real-time) and advanced fabrics (e.g. IB).
2) True pain to users is not caused by lack of binary compatibility. Its caused by lack of support. And its a good thing or we would all be emulating 8086 architecture forever...
..oh wait, I guess we kind of do that already ;). But at least we can slip in something more advanced once in a while (APIC vs PIC, USB vs uart, iso9660 vs floppy, for instance) and update the guest stack instead of insisting it must look like ISA forever for compatibility's sake.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
or we'd need to support both.
Quoted 8 lines
Quoted 4 lines
No matter what model we talk about, there's always going to be a "both" since the userspace virtio models are probably not going to go away (nor should they).
virtio allows you to have userspace-only, kernel-only, or start-with-userspace-and-move-to-kernel-later, all transparent to the guest. In many cases we'll stick with userspace-only.
The user will not care where the model lives, per se. Only that it is supported, and it works well.
Likewise, I know from experience that the developer will not like writing the same code twice, so the "runs in both" model is not necessarily a great design trait either.
Quoted 16 lines
Quoted 10 lines
Quoted 4 lines
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
How the connector message is delivered is really not relevant. Some architectures will simply deliver the message point-to-point (like the original hypercall design for KVM, or something like Ira's rig), and some will need additional demuxing (like pci-bridge/pio based KVM). It's an implementation detail of the connector.
Quoted 5 lines
However, the real point here is that something needs to establish a scoped namespace mechanism, add items to that namespace, and advertise the presence of the items to the guest. vbus has this facility built in to its stack. vhost doesn't, so it must come from elsewhere.
Quoted 3 lines
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode)
First of all, bus-decode is substantially easier than per-device decode (you have to track all those per-device/per-signal fds somewhere, integrate with hotswap, etc), and its only done once per guest at startup and left alone. So its already not apples to apples.
Second, while its true that the general kvm-connector bus-decode needs to be programmed, that is a function of adapting to the environment that _you_ created for me. The original kvm-connector was discovered via cpuid and hypercalls, and didn't need userspace at all to set it up.
Therefore it would be entirely unfair of you to turn around and somehow
try to use that trait of the design against me since you yourself imposed it.
As an additional data point, our other connectors have no such bus-decode programming requirement. Therefore, this is clearly just a property of the KVM environment, not a function of the overall vbus design.
Quoted 2 lines
vhost needs userspace to instantiate the devices and program the addresses.
Right. And among other shortcomings it also requires a KVM-esque memory model (which is not always going to work as we recently discussed), and a redundant device-model to back it up in userspace, which is a development and maintenance burden, and an external bus-model (filled by pio-bus in KVM today).
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
In fact, it's actually a simpler design to unify things this way because
you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It doesn't have just virtio-net, it has userspace-based hostplug
vbus has hotplug too: mkdir and rmdir
Does that work from nonprivileged processes?
It will with the ioctl based control interface that I'll merge shortly.
Quoted 1 line
Does it work on Windows?
This question doesn't make sense. Hotswap control occurs on the host, which is always Linux.
If you were asking about whether a windows guest will support hotswap:
the answer is "yes". Our windows driver presents a unique PDO/FDO pair for each logical device instance that is pushed out (just like the built in usb, pci, scsi bus drivers that windows supports natively).
Quoted 8 lines
Quoted 8 lines
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Quoted 4 lines
Quoted 2 lines
Afaict, qemu can't do either of those things.
We've seen that herring before,
Citation?
Quoted 1 line
and it's redder than ever.
This is more hyperbole. I doubt that there would be many that would argue that a modular architecture (that we get for free with LKM support) is not desirable, even if its never used dynamically with a running guest. OTOH, I actually use this dynamic feature all the time as I test my components, so its at least useful to me.
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
So define them if they're missing.
I just did.
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Use libraries (virtio-shmem.ko, libvhost.so).
Quoted 8 lines
Quoted 6 lines
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Refactor instead of rewriting.
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
Quoted 6 lines
Quoted 4 lines
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
It's not compatible.
No, that is incorrect. What you are apparently not understanding is that not only is vbus that library, but its extensible. So even if compatibility is your goal (it doesn't need to be IMO) it can be accommodated by how you interface to the library.
Quoted 2 lines
If you were truly worried about code duplication
in virtio, you'd refactor it to remove the duplication,
My primary objective is creating an extensible, high-performance, shared-memory interconnect for systems that utilize a Linux host as their IO-hub. It just so happens that virtio can sit nicely on top of such a model because shmem-rings are a subclass of shmem. As a result of its design, vbus also helps to reduce code duplication in the stack for new environments due to its extensible nature.
However, vbus also has goals beyond what virtio is providing today that are of more concern, and part of that is designing a connector/bus that eliminates the shortcomings in the current pci-based design.
Quoted 1 line
without affecting existing guests.
Already covered above.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux);
vmware only cares about x86 iiuc, so probably not a good example.
Well, you brought it up. Between you and me, I only care about x86 too.
Fair enough.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Xen has to tunnel
xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.So pick any other hypervisor, and the situation is often similar.
The situation is often pci.
Even if that were true, which is debatable, do not confuse "convenient" with "optimal". If you don't care about maximum performance and advanced features like QOS, sure go ahead and use PCI. Why not.
Quoted 22 lines
Quoted 7 lines
Quoted 7 lines
An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
Quoted 6 lines
vbus is not interested in userspace devices. The charter is to provide facilities for utilizing the host linux kernel's IO capabilities in the most efficient, yet safe, manner possible. Those devices that fit outside that charter can ride on legacy mechanisms if that suits them best.
vbus isn't, but I am. I would prefer not to have to expose implementation decisions (kernel vs userspace) to the guest (vbus vs pci).
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
vbus needs the same thing so it cancels out.
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
That's ioeventfd. So far so similar.
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire guest->host.
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Quoted 15 lines
Quoted 6 lines
Per queue/device addressing is handled by the same conceptual namespace
as the one that would trigger eventfds in the model you mention. And that namespace is built in to the vbus stack, and objects are registered automatically as they are created.Quoted 8 lines
Contrast that to vhost, which requires some other kernel interface to exist, and to be managed manually for each object that is created. Your libvhostconfig would need to somehow know how to perform this registration operation, and there would have to be something in the kernel to receive it, presumably on a per platform basis. Solving this problem generally would probably end up looking eerily like vbus, because thats what vbus does.
Quoted 4 lines
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
No, that is incorrect. The amount of "work" that a guest does is actually the same in both cases, since the guest OS peforms the hotswap handling natively for all bus types (at least for Linux and Windows). You still need to have a PV layer to interface with those objects in both cases, as well, so there is no such thing as "native interface" for PV. Its only a matter of where it occurs in the stack.
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
yes, its in sysfs.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
yes, its in sysfs.
Per-device?
Yes, see /sys/vbus/devices/$dev/ to get per-instance attributes
Quoted 1 line
non-privileged-user capable?
The short answer is "not yet (I think)". I need to write a patch to properly set the mode attribute in sysfs, but I think this will be trivial.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
no, but we can easily add ->save()/->restore() to the model going forward, and the negotiated features are just a subcomponent if its serialized stream.
Quoted 3 lines
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
that would be the function of the ->restore() deserializer.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
- do all that from an unprivileged process
yes, in the upcoming alacrityvm v0.3 with the ioctl based control plane.
Ah, so you have two control planes.
So what? If anything, it goes to show how extensible the framework is that a new plane could be added in 119 lines of code:
~/git/linux-2.6> stg show vbus-add-admin-ioctls.patch | diffstat
Makefile | 3 - config-ioctl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)
if and when having two control planes exceeds its utility, I will submit a simple patch that removes the useless one.
Quoted 11 lines
Quoted 7 lines
Bottom line: vbus isn't done, especially w.r.t. live-migration..but that is not an valid argument against the idea if you believe in release-early/release-often. kvm wasn't (isn't) done either when it was proposed/merged.
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
And likewise, neither does vbus.
Kind Regards,
-Greg
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 14 lines · Avi Kivity
Quoted 13 lines · Gregory Haskins
Quoted 13 lines
Quoted 9 lines
I realize in retrospect that my choice of words above implies vbus _is_ complete, but this is not what I was saying. What I was trying to convey is that vbus is _more_ complete. Yes, in either case some kind of glue needs to be written. The difference is that vbus implements more of the glue generally, and leaves less required to be customized for each iteration.
No argument there. Since you care about non-virt scenarios and virtio doesn't, naturally vbus is a better fit for them as the code stands.
Quoted 7 lines
Quoted 2 lines
Thanks for finally starting to acknowledge there's a benefit, at least.
I think I've mentioned vbus' finer grained layers as helpful here, though I doubt the value of this. Hypervisors are added rarely, while devices and drivers are added (and modified) much more often. I don't buy the anything-to-anything promise.
The ease in which a new hypervisor should be able to integrate into the stack is only one of vbus's many benefits.
Quoted 11 lines
Quoted 10 lines
To be more precise, IMO virtio is designed to be a performance oriented ring-based driver interface that supports all types of hypervisors (e.g. shmem based kvm, and non-shmem based Xen). vbus is designed to be a high-performance generic shared-memory interconnect (for rings or otherwise) framework for environments where linux is the underpinning "host" (physical or virtual). They are distinctly different, but complementary (the former addresses the part of the front-end, and latter addresses the back-end, and a different part of the front-end).
Quoted 1 line
They're not truly complementary since they're incompatible.
No, that is incorrect. Not to be rude, but for clarity:
Complementary \Com`ple*men"ta*ry\, a.
Serving to fill out or to complete; as, complementary numbers.
[1913 Webster]
Citation: www.dict.org
IOW: Something being complementary has nothing to do with guest/host binary compatibility. virtio-pci and virtio-vbus are both equally complementary to virtio since they fill in the bottom layer of the virtio stack.
So yes, vbus is truly complementary to virtio afaict.
Quoted 2 lines
A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work over vbus.
Binary compatibility with existing virtio drivers, while nice to have, is not a specific requirement nor goal. We will simply load an updated KMP/MSI into those guests and they will work again. As previously discussed, this is how more or less any system works today. It's like we are removing an old adapter card and adding a new one to "uprev the silicon".
Quoted 1 line
Further, non-shmem virtio can't work over vbus.
Actually I misspoke earlier when I said virtio works over non-shmem. Thinking about it some more, both virtio and vbus fundamentally require shared-memory, since sharing their metadata concurrently on both sides is their raison d'être.
The difference is that virtio utilizes a pre-translation/mapping (via ->add_buf) from the guest side. OTOH, vbus uses a post translation scheme (via memctx) from the host-side. If anything, vbus is actually more flexible because it doesn't assume the entire guest address space is directly mappable.
In summary, your statement is incorrect (though it is my fault for putting that idea in your head).
Quoted 4 lines
Since
virtio is guest-oriented and host-agnostic, it can't ignore non-shared-memory hosts (even though it's unlikely virtio will be adopted there)
Well, to be fair no one said it has to ignore them. Either virtio-vbus transport is present and available to the virtio stack, or it isn't. If its present, it may or may not publish objects for consumption. Providing a virtio-vbus transport in no way limits or degrades the existing capabilities of the virtio stack. It only enhances them.
I digress. The whole point is moot since I realized that the non-shmem distinction isn't accurate anyway. They both require shared-memory for the metadata, and IIUC virtio requires the entire address space to be mappable whereas vbus only assumes the metadata is.
Quoted 8 lines
Quoted 5 lines
In addition, the kvm-connector used in AlacrityVM's design strives to add value and improve performance via other mechanisms, such as dynamic
allocation, interrupt coalescing (thus reducing exit-ratio, which is a
serious issue in KVM)Do you have measurements of inter-interrupt coalescing rates (excluding intra-interrupt coalescing).
I actually do not have a rig setup to explicitly test inter-interrupt rates at the moment. Once things stabilize for me, I will try to re-gather some numbers here. Last time I looked, however, there were some decent savings for inter as well.
Inter rates are interesting because they are what tends to ramp up with IO load more than intra since guest interrupt mitigation techniques like NAPI often quell intra-rates naturally. This is especially true for data-center, cloud, hpc-grid, etc, kind of workloads (vs vanilla desktops, etc) that tend to have multiple IO ports (multi-homed nics, disk-io, etc). Those various ports tend to be workload-related to one another (e.g. 3-tier web stack may use multi-homed network and disk-io at the same time, trigged by one IO event).
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
In any case, here is an example run of a simple single-homed guest over standard GigE. Whats interesting here is that .qnotify to .notify ratio, as this is the interrupt-to-signal ratio. In this case, its 170047/151918, which comes out to about 11% savings in interrupt injections:
vbus-guest:/home/ghaskins # netperf -H dev
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to dev.laurelwood.net (192.168.1.10) port 0 AF_INET
Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
1048576 16384 16384 10.01 940.77
vbus-guest:/home/ghaskins # cat /sys/kernel/debug/pci-to-vbus-bridge
.events : 170048
.qnotify : 151918
.qinject : 0
.notify : 170047
.inject : 18238
.bridgecalls : 18
.buscalls : 12
vbus-guest:/home/ghaskins # cat /proc/interrupts
CPU0
0: 87 IO-APIC-edge timer
1: 6 IO-APIC-edge i8042
4: 733 IO-APIC-edge serial
6: 2 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 0 IO-APIC-edge rtc0
9: 0 IO-APIC-fasteoi acpi
10: 0 IO-APIC-fasteoi virtio1
12: 90 IO-APIC-edge i8042
14: 3041 IO-APIC-edge ata_piix
15: 1008 IO-APIC-edge ata_piix
24: 151933 PCI-MSI-edge vbus
25: 0 PCI-MSI-edge virtio0-config
26: 190 PCI-MSI-edge virtio0-input
27: 28 PCI-MSI-edge virtio0-output
NMI: 0 Non-maskable interrupts
LOC: 9854 Local timer interrupts
SPU: 0 Spurious interrupts
CNT: 0 Performance counter interrupts
PND: 0 Performance pending work
RES: 0 Rescheduling interrupts
CAL: 0 Function call interrupts
TLB: 0 TLB shootdowns
TRM: 0 Thermal event interrupts
THR: 0 Threshold APIC interrupts
MCE: 0 Machine check exceptions
MCP: 1 Machine check polls ERR: 0
MIS: 0
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
Looking at some external stats paints an even bleaker picture: "exits" as reported by kvm_stat for virtio-pci based virtio-net tip the scales at 65k/s vs 36k/s for vbus based venet. And virtio is consuming ~30% of my quad-core's cpu, vs 19% for venet during the test. Its hard to know which innovation or innovations may be responsible for the entire reduction, but certainly the interrupt-to-signal ratio mentioned above is probably helping.
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Quoted 5 lines
Quoted 3 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
PCI is somewhat of an outlier in that regard afaict. Its actually a nice feature of PCI when its used within its design spec (HW). For SW/PV, 1:1 suffers from, among other issues, that "triple-exit scaling" issue in the signal path I mentioned above. This is one of the many reasons I think PCI is not the best choice for PV.
Quoted 6 lines
Quoted 6 lines
Today there is a large performance disparity between what a KVM guest sees and what a native linux application sees on that same host. Just take a look at some of my graphs between "virtio", and "native", for example:
Quoted 6 lines
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
That's pure speculation. I would advise you to reserve such statements until after a proper bakeoff can be completed. This is not to mention that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.
Quoted 7 lines
Quoted 7 lines
A dominant vbus design principle is to try to achieve the same IO performance for all "linux applications" whether they be literally userspace applications, or things like KVM vcpus or Ira's physical boards. It also aims to solve problems not previously expressible with current technologies (even virtio), like nested real-time.
Quoted 8 lines
Quoted 5 lines
And even though you repeatedly insist otherwise, the neat thing here is that the two technologies mesh (at least under certain circumstances, like when virtio is deployed on a shared-memory friendly linux backend like KVM). I hope that my stack diagram below depicts that clearly.
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Where doesn't it fit?
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
As vhost-net shows, you can do that without vbus
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
Quoted 1 line
and without breaking compatibility.
Compatibility with what? vhost hasn't even been officially deployed in KVM environments afaict, nevermind non-virt. Therefore, how could it possibly have compatibility constraints with something non-virt already?
Citation please.
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Right. virtio assumes that it's in a virt scenario and that the guest architecture already has enumeration and hotplug mechanisms which it would prefer to use. That happens to be the case for kvm/x86.
Quoted 7 lines
No, virtio doesn't assume that. It's stack provides the "virtio-bus" abstraction and what it does assume is that it will be wired up to something underneath. Kvm/x86 conveniently has pci, so the virtio-pci adapter was created to reuse much of that facility. For other things like lguest and s360, something new had to be created underneath to make up for the lack of pci-like support.
Quoted 2 lines
Right, I was wrong there. But it does allow you to have a 1:1 mapping between native devices and virtio devices.
vbus allows you to have 1:1 if that is what you want, but we strive to do better.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
So to answer your question, the difference is that the part that has to be customized in vbus should be a fraction of what needs to be customized with vhost because it defines more of the stack.
But if you want to use the native mechanisms, vbus doesn't have any added value.
Quoted 8 lines
First of all, thats incorrect. If you want to use the "native" mechanisms (via the way the vbus-connector is implemented, for instance) you at least still have the benefit that the backend design is more broadly re-useable in more environments (like non-virt, for instance), because vbus does a proper job of defining the requisite layers/abstractions compared to vhost. So it adds value even in that situation.
Quoted 1 line
Maybe. If vhost-net isn't sufficient I'm sure there will be patches sent.
It isn't, and I've already done that.
Quoted 4 lines
Quoted 4 lines
Second of all, with PV there is no such thing as "native". It's software so it can be whatever we want. Sure, you could argue that the guest may have built-in support for something like PCI protocol.
[1]
Quoted 7 lines
Quoted 4 lines
However, PCI protocol itself isn't suitable for high-performance PV out of the can. So you will therefore invariably require new software layers on top anyway, even if part of the support is already included.
Of course there is such a thing as native, a pci-ready guest has tons of support built into it
I specifically mentioned that already ([1]).
You are also overstating its role, since the basic OS is what implements the native support for bus-objects, hotswap, etc, _not_ PCI. PCI just rides underneath and feeds trivial events up, as do other bus-types (usb, scsi, vbus, etc). And once those events are fed, you still need a PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.
Quoted 1 line
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
Not to mention there are things you just plain can't do in PCI today, like dynamically assign signal-paths, priority, and coalescing, etc.
Quoted 3 lines
Since
practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.
Actually IIUC, I think Xen bridges to their own bus as well (and only where they have to), just like vbus. They don't use PCI natively. PCI is perfectly suited as a bridge transport for PV, as I think the Xen and vbus examples have demonstrated. Its the 1:1 device-model where PCI has the most problems.
Quoted 12 lines
Quoted 11 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
Quoted 1 line
The short answer is "compatibility".
There was a point in time where the same could be said for virtio-pci based drivers vs realtek and e1000, so that argument is demonstrably silly. No one tried to make virtio work in a binary compatible way with realtek emulation, yet we all survived the requirement for loading a virtio driver to my knowledge.
The bottom line is: Binary device compatibility is not required in any other system (as long as you follow sensible versioning/id rules), so why is KVM considered special?
The fact is, it isn't special (at least not in this regard). What _is_ required is "support" and we fully intend to support these proposed components. I assure you that at least the users that care about maximum performance will not generally mind loading a driver. Most of them would have to anyway if they want to get beyond realtek emulation.
Quoted 9 lines
Quoted 9 lines
In summary, vbus is simply one more bus of many, purpose built to support high-end IO in a virt-like model, giving controlled access to the linux-host underneath it. You can write a high-performance layer below the OS bus-model (vbus), or above it (virtio-pci) but either way you are modifying the stack to add these capabilities, so we might as well try to get this right.
Quoted 4 lines
Quoted 2 lines
With all due respect, you are making a big deal out of a minor issue.
It's not minor to me.
I am certainly in no position to tell you how to feel, but this declaration would seem from my perspective to be more of a means to an end than a legitimate concern. Otherwise we would never have had virtio support in the first place, since it was not "compatible" with previous releases.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
And, as
eluded to in my diagram, both virtio-net and vhost (with some modifications to fit into the vbus framework) are potentially complementary, not competitors.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Only theoretically. The existing installed base would have to be thrown away
"Thrown away" is pure hyperbole. The installed base, worse case, needs to load a new driver for a missing device.
Yes, we all know how fun this is.
Making systems perform 5x faster _is_ fun, yes. I love what I do for a living.
Quoted 1 line
Especially if the device changed is your boot disk.
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
Quoted 2 lines
You may not care about the pain caused to users, but I do, so I will
continue to insist on compatibility.
No, you are incorrect on two counts.
1) Of course I care about pain to users or I wouldn't be funded. Right now the pain from my perspective is caused to users in the high-performance community who want to deploy KVM based solutions. They are unable to do so due to its performance disparity compared to bare-metal, outside of pass-through hardware which is not widely available in a lot of existing deployments. I aim to fix that disparity while reusing the existing hardware investment by writing smarter software, and I assure you that these users won't mind loading a driver in the guest to take advantage of it.
For the users that don't care about maximum performance, there is no change (and thus zero pain) required. They can use realtek or virtio if they really want to. Neither is going away to my knowledge, and lets face it: 2.6Gb/s out of virtio to userspace isn't *that* bad. But "good enough" isn't good enough, and I won't rest till we get to native performance. Additionally, I want to support previously unavailable modes of operations (e.g. real-time) and advanced fabrics (e.g. IB).
2) True pain to users is not caused by lack of binary compatibility. Its caused by lack of support. And its a good thing or we would all be emulating 8086 architecture forever...
..oh wait, I guess we kind of do that already ;). But at least we can slip in something more advanced once in a while (APIC vs PIC, USB vs uart, iso9660 vs floppy, for instance) and update the guest stack instead of insisting it must look like ISA forever for compatibility's sake.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
or we'd need to support both.
Quoted 8 lines
Quoted 4 lines
No matter what model we talk about, there's always going to be a "both" since the userspace virtio models are probably not going to go away (nor should they).
virtio allows you to have userspace-only, kernel-only, or start-with-userspace-and-move-to-kernel-later, all transparent to the guest. In many cases we'll stick with userspace-only.
The user will not care where the model lives, per se. Only that it is supported, and it works well.
Likewise, I know from experience that the developer will not like writing the same code twice, so the "runs in both" model is not necessarily a great design trait either.
Quoted 16 lines
Quoted 10 lines
Quoted 4 lines
All this is after kvm has decoded that vbus is addresses. It can't work without someone outside vbus deciding that.
How the connector message is delivered is really not relevant. Some architectures will simply deliver the message point-to-point (like the original hypercall design for KVM, or something like Ira's rig), and some will need additional demuxing (like pci-bridge/pio based KVM). It's an implementation detail of the connector.
Quoted 5 lines
However, the real point here is that something needs to establish a scoped namespace mechanism, add items to that namespace, and advertise the presence of the items to the guest. vbus has this facility built in to its stack. vhost doesn't, so it must come from elsewhere.
Quoted 3 lines
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode)
First of all, bus-decode is substantially easier than per-device decode (you have to track all those per-device/per-signal fds somewhere, integrate with hotswap, etc), and its only done once per guest at startup and left alone. So its already not apples to apples.
Second, while its true that the general kvm-connector bus-decode needs to be programmed, that is a function of adapting to the environment that _you_ created for me. The original kvm-connector was discovered via cpuid and hypercalls, and didn't need userspace at all to set it up.
Therefore it would be entirely unfair of you to turn around and somehow
try to use that trait of the design against me since you yourself imposed it.
As an additional data point, our other connectors have no such bus-decode programming requirement. Therefore, this is clearly just a property of the KVM environment, not a function of the overall vbus design.
Quoted 2 lines
vhost needs userspace to instantiate the devices and program the addresses.
Right. And among other shortcomings it also requires a KVM-esque memory model (which is not always going to work as we recently discussed), and a redundant device-model to back it up in userspace, which is a development and maintenance burden, and an external bus-model (filled by pio-bus in KVM today).
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
In fact, it's actually a simpler design to unify things this way because
you avoid splitting the device model up. Consider how painful the vhost implementation would be if it didn't already have the userspace virtio-net to fall-back on. This is effectively what we face for new devices going forward if that model is to persist.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It doesn't have just virtio-net, it has userspace-based hostplug
vbus has hotplug too: mkdir and rmdir
Does that work from nonprivileged processes?
It will with the ioctl based control interface that I'll merge shortly.
Quoted 1 line
Does it work on Windows?
This question doesn't make sense. Hotswap control occurs on the host, which is always Linux.
If you were asking about whether a windows guest will support hotswap:
the answer is "yes". Our windows driver presents a unique PDO/FDO pair for each logical device instance that is pushed out (just like the built in usb, pci, scsi bus drivers that windows supports natively).
Quoted 8 lines
Quoted 8 lines
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Quoted 4 lines
Quoted 2 lines
Afaict, qemu can't do either of those things.
We've seen that herring before,
Citation?
Quoted 1 line
and it's redder than ever.
This is more hyperbole. I doubt that there would be many that would argue that a modular architecture (that we get for free with LKM support) is not desirable, even if its never used dynamically with a running guest. OTOH, I actually use this dynamic feature all the time as I test my components, so its at least useful to me.
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
So define them if they're missing.
I just did.
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Use libraries (virtio-shmem.ko, libvhost.so).
Quoted 8 lines
Quoted 6 lines
What do you suppose vbus is? vbus-proxy.ko = virtio-shmem.ko, and you dont need libvhost.so per se since you can just use standard kernel interfaces (like configfs/sysfs). I could create an .so going forward for the new ioctl-based interface, I suppose.
Refactor instead of rewriting.
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
Quoted 6 lines
Quoted 4 lines
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
It's not compatible.
No, that is incorrect. What you are apparently not understanding is that not only is vbus that library, but its extensible. So even if compatibility is your goal (it doesn't need to be IMO) it can be accommodated by how you interface to the library.
Quoted 2 lines
If you were truly worried about code duplication
in virtio, you'd refactor it to remove the duplication,
My primary objective is creating an extensible, high-performance, shared-memory interconnect for systems that utilize a Linux host as their IO-hub. It just so happens that virtio can sit nicely on top of such a model because shmem-rings are a subclass of shmem. As a result of its design, vbus also helps to reduce code duplication in the stack for new environments due to its extensible nature.
However, vbus also has goals beyond what virtio is providing today that are of more concern, and part of that is designing a connector/bus that eliminates the shortcomings in the current pci-based design.
Quoted 1 line
without affecting existing guests.
Already covered above.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
For kvm/x86 pci definitely remains king.
For full virtualization, sure. I agree. However, we are talking about PV here. For PV, PCI is not a requirement and is a technical dead-end IMO.
KVM seems to be the only virt solution that thinks otherwise (*), but I believe that is primarily a condition of its maturity. I aim to help advance things here.
(*) citation: xen has xenbus, lguest has lguest-bus, vmware has some vmi-esq thing (I forget what its called) to name a few. Love 'em or hate 'em, most other hypervisors do something along these lines. I'd like to try to create one for KVM, but to unify them all (at least for the Linux-based host designs).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
VMware are throwing VMI away (won't be supported in their new product, and they've sent a patch to rip it off from Linux);
vmware only cares about x86 iiuc, so probably not a good example.
Well, you brought it up. Between you and me, I only care about x86 too.
Fair enough.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Xen has to tunnel
xenbus in pci for full virtualization (which is where Windows is, and where Linux will be too once people realize it's faster). lguest is meant as an example hypervisor, not an attempt to take over the world.So pick any other hypervisor, and the situation is often similar.
The situation is often pci.
Even if that were true, which is debatable, do not confuse "convenient" with "optimal". If you don't care about maximum performance and advanced features like QOS, sure go ahead and use PCI. Why not.
Quoted 22 lines
Quoted 7 lines
Quoted 7 lines
An right now you can have a guest using pci to access a mix of userspace-emulated devices, userspace-emulated-but-kernel-accelerated virtio devices, and real host devices. All on one dead-end bus. Try that with vbus.
Quoted 6 lines
vbus is not interested in userspace devices. The charter is to provide facilities for utilizing the host linux kernel's IO capabilities in the most efficient, yet safe, manner possible. Those devices that fit outside that charter can ride on legacy mechanisms if that suits them best.
vbus isn't, but I am. I would prefer not to have to expose implementation decisions (kernel vs userspace) to the guest (vbus vs pci).
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
That won't cut it. For one, creating an eventfd is only part of the equation. I.e. you need to have originate/terminate somewhere interesting (and in-kernel, otherwise use tuntap).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
vbus needs the same thing so it cancels out.
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
That's ioeventfd. So far so similar.
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire guest->host.
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Quoted 15 lines
Quoted 6 lines
Per queue/device addressing is handled by the same conceptual namespace
as the one that would trigger eventfds in the model you mention. And that namespace is built in to the vbus stack, and objects are registered automatically as they are created.Quoted 8 lines
Contrast that to vhost, which requires some other kernel interface to exist, and to be managed manually for each object that is created. Your libvhostconfig would need to somehow know how to perform this registration operation, and there would have to be something in the kernel to receive it, presumably on a per platform basis. Solving this problem generally would probably end up looking eerily like vbus, because thats what vbus does.
Quoted 4 lines
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
No, that is incorrect. The amount of "work" that a guest does is actually the same in both cases, since the guest OS peforms the hotswap handling natively for all bus types (at least for Linux and Windows). You still need to have a PV layer to interface with those objects in both cases, as well, so there is no such thing as "native interface" for PV. Its only a matter of where it occurs in the stack.
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Well, let's see. Can vbus today:
- let userspace know which features are available (so it can decide if live migration is possible)
yes, its in sysfs.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
- let userspace limit which features are exposed to the guest (so it can make live migration possible among hosts of different capabilities)
yes, its in sysfs.
Per-device?
Yes, see /sys/vbus/devices/$dev/ to get per-instance attributes
Quoted 1 line
non-privileged-user capable?
The short answer is "not yet (I think)". I need to write a patch to properly set the mode attribute in sysfs, but I think this will be trivial.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
- let userspace know which features were negotiated (so it can transfer them to the other host during live migration)
no, but we can easily add ->save()/->restore() to the model going forward, and the negotiated features are just a subcomponent if its serialized stream.
Quoted 3 lines
- let userspace tell the kernel which features were negotiated (when live migration completes, to avoid requiring the guest to re-negotiate)
that would be the function of the ->restore() deserializer.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
- do all that from an unprivileged process
yes, in the upcoming alacrityvm v0.3 with the ioctl based control plane.
Ah, so you have two control planes.
So what? If anything, it goes to show how extensible the framework is that a new plane could be added in 119 lines of code:
~/git/linux-2.6> stg show vbus-add-admin-ioctls.patch | diffstat
Makefile | 3 - config-ioctl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)
if and when having two control planes exceeds its utility, I will submit a simple patch that removes the useless one.
Quoted 11 lines
Quoted 7 lines
Bottom line: vbus isn't done, especially w.r.t. live-migration..but that is not an valid argument against the idea if you believe in release-early/release-often. kvm wasn't (isn't) done either when it was proposed/merged.
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
And likewise, neither does vbus.
Kind Regards,
-Greg
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 10 lines · Gregory Haskins
Quoted 3 lines
A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work over vbus.
Binary compatibility with existing virtio drivers, while nice to have, is not a specific requirement nor goal. We will simply load an updated KMP/MSI into those guests and they will work again. As previously discussed, this is how more or less any system works today. It's like we are removing an old adapter card and adding a new one to "uprev the silicon".
Virtualization is about not doing that. Sometimes it's necessary (when you have made unfixable design mistakes), but just to replace a bus, with no advantages to the guest that has to be changed (other hypervisors or hypervisorless deployment scenarios aren't).
Quoted 7 lines
Quoted 2 lines
Further, non-shmem virtio can't work over vbus.
Actually I misspoke earlier when I said virtio works over non-shmem. Thinking about it some more, both virtio and vbus fundamentally require shared-memory, since sharing their metadata concurrently on both sides is their raison d'Aatre.
Quoted 9 lines
The difference is that virtio utilizes a pre-translation/mapping (via ->add_buf) from the guest side. OTOH, vbus uses a post translation scheme (via memctx) from the host-side. If anything, vbus is actually more flexible because it doesn't assume the entire guest address space is directly mappable.
In summary, your statement is incorrect (though it is my fault for putting that idea in your head).
Well, Xen requires pre-translation (since the guest has to give the host (which is just another guest) permissions to access the data). So neither is a superset of the other, they're just different.
It doesn't really matter since Xen is unlikely to adopt virtio.
Quoted 10 lines
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
You can simply use the same vector for both rx and tx and poll both at every interrupt.
Quoted 54 lines
In any case, here is an example run of a simple single-homed guest over standard GigE. Whats interesting here is that .qnotify to .notify ratio, as this is the interrupt-to-signal ratio. In this case, its 170047/151918, which comes out to about 11% savings in interrupt injections:
vbus-guest:/home/ghaskins # netperf -H dev
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto dev.laurelwood.net (192.168.1.10) port 0AF_INETRecv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec1048576 16384 16384 10.01 940.77
vbus-guest:/home/ghaskins # cat/sys/kernel/debug/pci-to-vbus-bridge.events : 170048 .qnotify : 151918 .qinject : 0 .notify : 170047 .inject : 18238 .bridgecalls : 18 .buscalls : 12vbus-guest:/home/ghaskins # cat
/proc/interrupts
CPU0
0: 87 IO-APIC-edge timer
1: 6 IO-APIC-edge i8042
4: 733 IO-APIC-edge serial
6: 2 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 0 IO-APIC-edge rtc0
9: 0 IO-APIC-fasteoi acpi10: 0 IO-APIC-fasteoi virtio1 12: 90 IO-APIC-edge i8042 14: 3041 IO-APIC-edge ata_piix 15: 1008 IO-APIC-edge ata_piix 24: 151933 PCI-MSI-edge vbus 25: 0 PCI-MSI-edge virtio0-config 26: 190 PCI-MSI-edge virtio0-input 27: 28 PCI-MSI-edge virtio0-output NMI: 0 Non-maskable interrupts LOC: 9854 Local timer interrupts SPU: 0 Spurious interrupts CNT: 0 Performance counter interrupts PND: 0 Performance pending work RES: 0 Rescheduling interrupts CAL: 0 Function call interrupts TLB: 0 TLB shootdowns TRM: 0 Thermal event interrupts THR: 0 Threshold APIC interrupts MCE: 0 Machine check exceptions MCP: 1 Machine check pollsERR: 0
MIS: 0
Quoted 9 lines
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
(irq window exits should only be required on a small percentage of interrupt injections, since the guest will try to disable interrupts for short periods only)
Quoted 8 lines
Looking at some external stats paints an even bleaker picture: "exits" as reported by
kvm_statfor virtio-pci based virtio-net tip the scales at 65k/s vs 36k/s for vbus based venet. And virtio is consuming ~30% of my quad-core's cpu, vs 19% for venet during the test. Its hard to know which innovation or innovations may be responsible for the entire reduction, but certainly the interrupt-to-signal ratio mentioned above is probably helping.
Can you please stop comparing userspace-based virtio hosts to kernel-based venet hosts? We know the userspace implementation sucks.
Quoted 5 lines
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Requiring all three exits means the guest is spending most of its time with interrupts disabled; that's unlikely.
Thanks for the numbers. Are those 11% attributable to rx/tx piggybacking from the same interface?
Also, 170K interupts -> 17K interrupts/sec -> 55kbit/interrupt -> 6.8kB/interrupt. Ignoring interrupt merging and assuming equal rx/tx distribution, that's about 13kB/interrupt. Seems rather low for a saturated link.
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
With standard PCI, they do not. But all modern host adapters support MSI and they will happily give you one interrupt per queue.
Quoted 6 lines
PCI is somewhat of an outlier in that regard afaict. Its actually a nice feature of PCI when its used within its design spec (HW). For SW/PV, 1:1 suffers from, among other issues, that "triple-exit scaling" issue in the signal path I mentioned above. This is one of the many reasons I think PCI is not the best choice for PV.
Look at the vmxnet3 submission (recently posted on virtualization@). It's a perfectly ordinary PCI NIC driver, apart from having so many 'V's in the code. 16 rx queues, 8 tx queues, 25 MSIs, BARs for the registers. So while the industry as a whole might disagree with me, it seems VMware does not.
Quoted 9 lines
Quoted 7 lines
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
That's pure speculation. I would advise you to reserve such statements until after a proper bakeoff can be completed.
Let's do that then. Please reserve the corresponding comparisons from your side as well.
Quoted 4 lines
This is not to mention
that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.
What are scheduler coordination and non-802.x fabrics?
Quoted 5 lines
Quoted 3 lines
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Where doesn't it fit?
(avoiding infinite loop)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
Quoted 5 lines
Quoted 2 lines
As vhost-net shows, you can do that without vbus
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
I think Ira said he can make vhost work?
Quoted 7 lines
Quoted 2 lines
and without breaking compatibility.
Compatibility with what? vhost hasn't even been officially deployed in KVM environments afaict, nevermind non-virt. Therefore, how could it possibly have compatibility constraints with something non-virt already?
Citation please.
virtio-net over pci is deployed. Replacing the backend with vhost-net will require no guest modifications. Replacing the frontend with venet or virt-net/vbus-pci will require guest modifications.
Obviously virtio-net isn't deployed in non-virt. But if we adopt vbus, we have to migrate guests.
Quoted 9 lines
Quoted 3 lines
Of course there is such a thing as native, a pci-ready guest has tons of support built into it
I specifically mentioned that already ([1]).
You are also overstating its role, since the basic OS is what implements the native support for bus-objects, hotswap, etc, _not_ PCI. PCI just rides underneath and feeds trivial events up, as do other bus-types (usb, scsi, vbus, etc).
But we have to implement vbus for each guest we want to support. That includes Windows and older Linux which has a different internal API, so we have to port the code multiple times, to get existing functionality.
Quoted 4 lines
And once those events are fed, you still need a
PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.
virtio-net doesn't use any pv layer.
Quoted 7 lines
Quoted 2 lines
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
virtio-net doesn't modify the PCI model. And if you look at vmxnet3, they mention that it conforms to somthing called UPT, which allows hardware vendors to implement parts of their NIC model. So vmxnet3 is apparently suitable to both hardware and software implementations.
Quoted 2 lines
Not to mention there are things you just plain can't do in PCI today, like dynamically assign signal-paths,
You can have dynamic MSI/queue routing with virtio, and each MSI can be routed to a vcpu at will.
Quoted 2 lines
priority, and coalescing, etc.
Do you mean interrupt priority? Well, apic allows interrupt priorities and Windows uses them; Linux doesn't. I don't see a reason to provide more than native hardware.
Quoted 10 lines
Quoted 4 lines
Since
practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.Actually IIUC, I think Xen bridges to their own bus as well (and only where they have to), just like vbus. They don't use PCI natively. PCI is perfectly suited as a bridge transport for PV, as I think the Xen and vbus examples have demonstrated. Its the 1:1 device-model where PCI has the most problems.
N:1 breaks down on large guests since one vcpu will have to process all events. You could do N:M, with commands to change routings, but where's your userspace interface? you can't tell from /proc/interrupts which vbus interupts are active, and irqbalance can't steer them towards less busy cpus since they're invisible to the interrupt controller.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
Quoted 8 lines
Quoted 2 lines
The short answer is "compatibility".
There was a point in time where the same could be said for virtio-pci based drivers vs realtek and e1000, so that argument is demonstrably silly. No one tried to make virtio work in a binary compatible way with realtek emulation, yet we all survived the requirement for loading a virtio driver to my knowledge.
The larger your installed base, the more difficult it is. Of course it's doable, but I prefer not doing it and instead improving things in a binary backwards compatible manner. If there is no choice we will bow to the inevitable and make our users upgrade. But at this point there is a choice, and I prefer to stick with vhost-net until it is proven that it won't work.
Quoted 4 lines
The bottom line is: Binary device compatibility is not required in any other system (as long as you follow sensible versioning/id rules), so why is KVM considered special?
One of the benefits of virtualization is that the guest model is stable. You can live-migrate guests and upgrade the hardware underneath. You can have a single guest image that you clone to provision new guests. If you switch to a new model, you give up those benefits, or you support both models indefinitely.
Note even hardware nowadays is binary compatible. One e1000 driver supports a ton of different cards, and I think (not sure) newer cards will work with older drivers, just without all their features.
Quoted 6 lines
The fact is, it isn't special (at least not in this regard). What _is_ required is "support" and we fully intend to support these proposed components. I assure you that at least the users that care about maximum performance will not generally mind loading a driver. Most of them would have to anyway if they want to get beyond realtek emulation.
For a new install, sure. I'm talking about existing deployments (and those that will exist by the time vbus is ready for roll out).
Quoted 6 lines
I am certainly in no position to tell you how to feel, but this declaration would seem from my perspective to be more of a means to an end than a legitimate concern. Otherwise we would never have had virtio support in the first place, since it was not "compatible" with previous releases.
virtio was certainly not pain free, needing Windows drivers, updates to management tools (you can't enable it by default, so you have to offer it as a choice), mkinitrd, etc. I'd rather not have to go through that again.
Quoted 6 lines
Quoted 2 lines
Especially if the device changed is your boot disk.
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
No, you have to update the driver in your initrd (for Linux) or properly install the new driver (for Windows). It's especially difficult for Windows.
Quoted 9 lines
Quoted 3 lines
You may not care about the pain caused to users, but I do, so I will
continue to insist on compatibility.For the users that don't care about maximum performance, there is no change (and thus zero pain) required. They can use realtek or virtio if they really want to. Neither is going away to my knowledge, and lets face it: 2.6Gb/s out of virtio to userspace isn't *that* bad. But "good enough" isn't good enough, and I won't rest till we get to native performance.
I don't want to support both virtio and vbus in parallel. There's enough work already. If we adopt vbus, we'll have to deprecate and eventually kill off virtio.
Quoted 9 lines
2) True pain to users is not caused by lack of binary compatibility. Its caused by lack of support. And its a good thing or we would all be emulating 8086 architecture forever...
..oh wait, I guess we kind of do that already ;). But at least we can slip in something more advanced once in a while (APIC vs PIC, USB vs uart, iso9660 vs floppy, for instance) and update the guest stack instead of insisting it must look like ISA forever for compatibility's sake.
PCI is continuously updated, with MSI, MSI-X, and IOMMU support being some recent updates. I'd like to ride on top of that instead of having to clone it for every guest I support.
Quoted 9 lines
Quoted 4 lines
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode)
First of all, bus-decode is substantially easier than per-device decode (you have to track all those per-device/per-signal fds somewhere, integrate with hotswap, etc), and its only done once per guest at startup and left alone. So its already not apples to apples.
Right, it means you can hand off those eventfds to other qemus or other pure userspace servers. It's more flexible.
Quoted 8 lines
Second, while its true that the general kvm-connector bus-decode needs to be programmed, that is a function of adapting to the environment that _you_ created for me. The original kvm-connector was discovered via cpuid and hypercalls, and didn't need userspace at all to set it up.
Therefore it would be entirely unfair of you to turn around and somehow
try to use that trait of the design against me since you yourself imposed it.
No kvm feature will ever be exposed to a guest without userspace intervention. It's a basic requirement. If it causes complexity (and it does) we have to live with it.
Quoted 10 lines
Quoted 2 lines
Does it work on Windows?
This question doesn't make sense. Hotswap control occurs on the host, which is always Linux.
If you were asking about whether a windows guest will support hotswap:
the answer is "yes". Our windows driver presents a unique PDO/FDO pair for each logical device instance that is pushed out (just like the built in usb, pci, scsi bus drivers that windows supports natively).
Ah, you have a Windows venet driver?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Afaict, qemu can't do either of those things.
We've seen that herring before,
Citation?
It's the compare venet-in-kernel to virtio-in-userspace thing again. Let's defer that until mst complete vhost-net mergable buffers, it which time we can compare vhost-net to venet and see how much vbus contributes to performance and how much of it comes from being in-kernel.
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
So define them if they're missing.
I just did.
Since this is getting confusing to me, I'll start from scratch looking at the vbus layers, top to bottom:
Guest side:
1. venet guest kernel driver - AFAICT, duplicates the virtio-net guest driver functionality
2. vbus guest driver (config and hotplug) - duplicates pci, or if you need non-pci support, virtio config and its pci bindings; needs reimplementation for all supported guests
3. vbus guest driver (interrupt coalescing, priority) - if needed, should be implemented as an irqchip (and be totally orthogonal to the driver); needs reimplementation for all supported guests
4. vbus guest driver (shm/ioq) - finder grained layering than virtio (which only supports the combination, due to the need for Xen support); can be retrofitted to virtio at some cost
Host side:
1. venet host kernel driver - is duplicated by vhost-net; doesn't support live migration, unprivileged users, or slirp
2. vbus host driver (config and hotplug) - duplicates pci support in userspace (which will need to be kept in any case); already has two userspace interfaces
3. vbus host driver (interrupt coalescing, priority) - if we think we need it (and I don't), should be part of kvm core, not a bus
4. vbus host driver (shm) - partially duplicated by vhost memory slots
5. vbus host driver (ioq) - duplicates userspace virtio, duplicated by vhost
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
Quoted 7 lines
Quoted 2 lines
It's not compatible.
No, that is incorrect. What you are apparently not understanding is that not only is vbus that library, but its extensible. So even if compatibility is your goal (it doesn't need to be IMO) it can be accommodated by how you interface to the library.
To me, compatible means I can live migrate an image to a new system without the user knowing about the change. You'll be able to do that with vhost-net.
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
That's ioeventfd. So far so similar.
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire
guest->host.
You'll probably need to change that as you start running smp guests.
Quoted 4 lines
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Please post your issues. I see ioeventfd/irqfd as critical kvm interfaces.
Quoted 6 lines
Quoted 5 lines
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
Quoted 7 lines
No, that is incorrect. The amount of "work" that a guest does is actually the same in both cases, since the guest OS peforms the hotswap handling natively for all bus types (at least for Linux and Windows). You still need to have a PV layer to interface with those objects in both cases, as well, so there is no such thing as "native interface" for PV. Its only a matter of where it occurs in the stack.
I'm missing something. Where's the pv layer for virtio-net?
Linux drivers have an abstraction layer to deal with non-pci. But the Windows drivers are ordinary pci drivers with nothing that looks pv-ish. You could implement virtio-net hardware if you wanted to.
Quoted 6 lines
Quoted 2 lines
non-privileged-user capable?
The short answer is "not yet (I think)". I need to write a patch to properly set the mode attribute in sysfs, but I think this will be trivial.
(and selinux label)
Quoted 5 lines
Quoted 2 lines
Ah, so you have two control planes.
So what? If anything, it goes to show how extensible the framework is that a new plane could be added in 119 lines of code:
Quoted 9 lines
~/git/linux-2.6> stg show vbus-add-admin-ioctls.patch | diffstat
Makefile | 3 - config-ioctl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)if and when having two control planes exceeds its utility, I will submit a simple patch that removes the useless one.
It always begins with a 119-line patch and then grows, that's life.
Quoted 6 lines
Quoted 3 lines
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
And likewise, neither does vbus.
For virt uses, I don't see the need. For non-virt, I have no opinion.
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 10 lines · Gregory Haskins
Quoted 3 lines
A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work over vbus.
Binary compatibility with existing virtio drivers, while nice to have, is not a specific requirement nor goal. We will simply load an updated KMP/MSI into those guests and they will work again. As previously discussed, this is how more or less any system works today. It's like we are removing an old adapter card and adding a new one to "uprev the silicon".
Virtualization is about not doing that. Sometimes it's necessary (when you have made unfixable design mistakes), but just to replace a bus, with no advantages to the guest that has to be changed (other hypervisors or hypervisorless deployment scenarios aren't).
Quoted 7 lines
Quoted 2 lines
Further, non-shmem virtio can't work over vbus.
Actually I misspoke earlier when I said virtio works over non-shmem. Thinking about it some more, both virtio and vbus fundamentally require shared-memory, since sharing their metadata concurrently on both sides is their raison d'être.
Quoted 9 lines
The difference is that virtio utilizes a pre-translation/mapping (via ->add_buf) from the guest side. OTOH, vbus uses a post translation scheme (via memctx) from the host-side. If anything, vbus is actually more flexible because it doesn't assume the entire guest address space is directly mappable.
In summary, your statement is incorrect (though it is my fault for putting that idea in your head).
Well, Xen requires pre-translation (since the guest has to give the host (which is just another guest) permissions to access the data). So neither is a superset of the other, they're just different.
It doesn't really matter since Xen is unlikely to adopt virtio.
Quoted 10 lines
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
You can simply use the same vector for both rx and tx and poll both at every interrupt.
Quoted 54 lines
In any case, here is an example run of a simple single-homed guest over standard GigE. Whats interesting here is that .qnotify to .notify ratio, as this is the interrupt-to-signal ratio. In this case, its 170047/151918, which comes out to about 11% savings in interrupt injections:
vbus-guest:/home/ghaskins # netperf -H dev
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto dev.laurelwood.net (192.168.1.10) port 0AF_INETRecv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec1048576 16384 16384 10.01 940.77
vbus-guest:/home/ghaskins # cat/sys/kernel/debug/pci-to-vbus-bridge.events : 170048 .qnotify : 151918 .qinject : 0 .notify : 170047 .inject : 18238 .bridgecalls : 18 .buscalls : 12vbus-guest:/home/ghaskins # cat
/proc/interrupts
CPU0
0: 87 IO-APIC-edge timer
1: 6 IO-APIC-edge i8042
4: 733 IO-APIC-edge serial
6: 2 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 0 IO-APIC-edge rtc0
9: 0 IO-APIC-fasteoi acpi10: 0 IO-APIC-fasteoi virtio1 12: 90 IO-APIC-edge i8042 14: 3041 IO-APIC-edge ata_piix 15: 1008 IO-APIC-edge ata_piix 24: 151933 PCI-MSI-edge vbus 25: 0 PCI-MSI-edge virtio0-config 26: 190 PCI-MSI-edge virtio0-input 27: 28 PCI-MSI-edge virtio0-output NMI: 0 Non-maskable interrupts LOC: 9854 Local timer interrupts SPU: 0 Spurious interrupts CNT: 0 Performance counter interrupts PND: 0 Performance pending work RES: 0 Rescheduling interrupts CAL: 0 Function call interrupts TLB: 0 TLB shootdowns TRM: 0 Thermal event interrupts THR: 0 Threshold APIC interrupts MCE: 0 Machine check exceptions MCP: 1 Machine check pollsERR: 0
MIS: 0
Quoted 9 lines
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
(irq window exits should only be required on a small percentage of interrupt injections, since the guest will try to disable interrupts for short periods only)
Quoted 8 lines
Looking at some external stats paints an even bleaker picture: "exits" as reported by
kvm_statfor virtio-pci based virtio-net tip the scales at 65k/s vs 36k/s for vbus based venet. And virtio is consuming ~30% of my quad-core's cpu, vs 19% for venet during the test. Its hard to know which innovation or innovations may be responsible for the entire reduction, but certainly the interrupt-to-signal ratio mentioned above is probably helping.
Can you please stop comparing userspace-based virtio hosts to kernel-based venet hosts? We know the userspace implementation sucks.
Quoted 5 lines
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Requiring all three exits means the guest is spending most of its time with interrupts disabled; that's unlikely.
Thanks for the numbers. Are those 11% attributable to rx/tx piggybacking from the same interface?
Also, 170K interupts -> 17K interrupts/sec -> 55kbit/interrupt -> 6.8kB/interrupt. Ignoring interrupt merging and assuming equal rx/tx distribution, that's about 13kB/interrupt. Seems rather low for a saturated link.
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
With standard PCI, they do not. But all modern host adapters support MSI and they will happily give you one interrupt per queue.
Quoted 6 lines
PCI is somewhat of an outlier in that regard afaict. Its actually a nice feature of PCI when its used within its design spec (HW). For SW/PV, 1:1 suffers from, among other issues, that "triple-exit scaling" issue in the signal path I mentioned above. This is one of the many reasons I think PCI is not the best choice for PV.
Look at the vmxnet3 submission (recently posted on virtualization@). It's a perfectly ordinary PCI NIC driver, apart from having so many 'V's in the code. 16 rx queues, 8 tx queues, 25 MSIs, BARs for the registers. So while the industry as a whole might disagree with me, it seems VMware does not.
Quoted 9 lines
Quoted 7 lines
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
That's pure speculation. I would advise you to reserve such statements until after a proper bakeoff can be completed.
Let's do that then. Please reserve the corresponding comparisons from your side as well.
Quoted 4 lines
This is not to mention
that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.
What are scheduler coordination and non-802.x fabrics?
Quoted 5 lines
Quoted 3 lines
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Where doesn't it fit?
(avoiding infinite loop)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
Quoted 5 lines
Quoted 2 lines
As vhost-net shows, you can do that without vbus
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
I think Ira said he can make vhost work?
Quoted 7 lines
Quoted 2 lines
and without breaking compatibility.
Compatibility with what? vhost hasn't even been officially deployed in KVM environments afaict, nevermind non-virt. Therefore, how could it possibly have compatibility constraints with something non-virt already?
Citation please.
virtio-net over pci is deployed. Replacing the backend with vhost-net will require no guest modifications. Replacing the frontend with venet or virt-net/vbus-pci will require guest modifications.
Obviously virtio-net isn't deployed in non-virt. But if we adopt vbus, we have to migrate guests.
Quoted 9 lines
Quoted 3 lines
Of course there is such a thing as native, a pci-ready guest has tons of support built into it
I specifically mentioned that already ([1]).
You are also overstating its role, since the basic OS is what implements the native support for bus-objects, hotswap, etc, _not_ PCI. PCI just rides underneath and feeds trivial events up, as do other bus-types (usb, scsi, vbus, etc).
But we have to implement vbus for each guest we want to support. That includes Windows and older Linux which has a different internal API, so we have to port the code multiple times, to get existing functionality.
Quoted 4 lines
And once those events are fed, you still need a
PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.
virtio-net doesn't use any pv layer.
Quoted 7 lines
Quoted 2 lines
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
virtio-net doesn't modify the PCI model. And if you look at vmxnet3, they mention that it conforms to somthing called UPT, which allows hardware vendors to implement parts of their NIC model. So vmxnet3 is apparently suitable to both hardware and software implementations.
Quoted 2 lines
Not to mention there are things you just plain can't do in PCI today, like dynamically assign signal-paths,
You can have dynamic MSI/queue routing with virtio, and each MSI can be routed to a vcpu at will.
Quoted 2 lines
priority, and coalescing, etc.
Do you mean interrupt priority? Well, apic allows interrupt priorities and Windows uses them; Linux doesn't. I don't see a reason to provide more than native hardware.
Quoted 10 lines
Quoted 4 lines
Since
practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.Actually IIUC, I think Xen bridges to their own bus as well (and only where they have to), just like vbus. They don't use PCI natively. PCI is perfectly suited as a bridge transport for PV, as I think the Xen and vbus examples have demonstrated. Its the 1:1 device-model where PCI has the most problems.
N:1 breaks down on large guests since one vcpu will have to process all events. You could do N:M, with commands to change routings, but where's your userspace interface? you can't tell from /proc/interrupts which vbus interupts are active, and irqbalance can't steer them towards less busy cpus since they're invisible to the interrupt controller.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.
Quoted 8 lines
Quoted 2 lines
The short answer is "compatibility".
There was a point in time where the same could be said for virtio-pci based drivers vs realtek and e1000, so that argument is demonstrably silly. No one tried to make virtio work in a binary compatible way with realtek emulation, yet we all survived the requirement for loading a virtio driver to my knowledge.
The larger your installed base, the more difficult it is. Of course it's doable, but I prefer not doing it and instead improving things in a binary backwards compatible manner. If there is no choice we will bow to the inevitable and make our users upgrade. But at this point there is a choice, and I prefer to stick with vhost-net until it is proven that it won't work.
Quoted 4 lines
The bottom line is: Binary device compatibility is not required in any other system (as long as you follow sensible versioning/id rules), so why is KVM considered special?
One of the benefits of virtualization is that the guest model is stable. You can live-migrate guests and upgrade the hardware underneath. You can have a single guest image that you clone to provision new guests. If you switch to a new model, you give up those benefits, or you support both models indefinitely.
Note even hardware nowadays is binary compatible. One e1000 driver supports a ton of different cards, and I think (not sure) newer cards will work with older drivers, just without all their features.
Quoted 6 lines
The fact is, it isn't special (at least not in this regard). What _is_ required is "support" and we fully intend to support these proposed components. I assure you that at least the users that care about maximum performance will not generally mind loading a driver. Most of them would have to anyway if they want to get beyond realtek emulation.
For a new install, sure. I'm talking about existing deployments (and those that will exist by the time vbus is ready for roll out).
Quoted 6 lines
I am certainly in no position to tell you how to feel, but this declaration would seem from my perspective to be more of a means to an end than a legitimate concern. Otherwise we would never have had virtio support in the first place, since it was not "compatible" with previous releases.
virtio was certainly not pain free, needing Windows drivers, updates to management tools (you can't enable it by default, so you have to offer it as a choice), mkinitrd, etc. I'd rather not have to go through that again.
Quoted 6 lines
Quoted 2 lines
Especially if the device changed is your boot disk.
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
No, you have to update the driver in your initrd (for Linux) or properly install the new driver (for Windows). It's especially difficult for Windows.
Quoted 9 lines
Quoted 3 lines
You may not care about the pain caused to users, but I do, so I will
continue to insist on compatibility.For the users that don't care about maximum performance, there is no change (and thus zero pain) required. They can use realtek or virtio if they really want to. Neither is going away to my knowledge, and lets face it: 2.6Gb/s out of virtio to userspace isn't *that* bad. But "good enough" isn't good enough, and I won't rest till we get to native performance.
I don't want to support both virtio and vbus in parallel. There's enough work already. If we adopt vbus, we'll have to deprecate and eventually kill off virtio.
Quoted 9 lines
2) True pain to users is not caused by lack of binary compatibility. Its caused by lack of support. And its a good thing or we would all be emulating 8086 architecture forever...
..oh wait, I guess we kind of do that already ;). But at least we can slip in something more advanced once in a while (APIC vs PIC, USB vs uart, iso9660 vs floppy, for instance) and update the guest stack instead of insisting it must look like ISA forever for compatibility's sake.
PCI is continuously updated, with MSI, MSI-X, and IOMMU support being some recent updates. I'd like to ride on top of that instead of having to clone it for every guest I support.
Quoted 9 lines
Quoted 4 lines
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode)
First of all, bus-decode is substantially easier than per-device decode (you have to track all those per-device/per-signal fds somewhere, integrate with hotswap, etc), and its only done once per guest at startup and left alone. So its already not apples to apples.
Right, it means you can hand off those eventfds to other qemus or other pure userspace servers. It's more flexible.
Quoted 8 lines
Second, while its true that the general kvm-connector bus-decode needs to be programmed, that is a function of adapting to the environment that _you_ created for me. The original kvm-connector was discovered via cpuid and hypercalls, and didn't need userspace at all to set it up.
Therefore it would be entirely unfair of you to turn around and somehow
try to use that trait of the design against me since you yourself imposed it.
No kvm feature will ever be exposed to a guest without userspace intervention. It's a basic requirement. If it causes complexity (and it does) we have to live with it.
Quoted 10 lines
Quoted 2 lines
Does it work on Windows?
This question doesn't make sense. Hotswap control occurs on the host, which is always Linux.
If you were asking about whether a windows guest will support hotswap:
the answer is "yes". Our windows driver presents a unique PDO/FDO pair for each logical device instance that is pushed out (just like the built in usb, pci, scsi bus drivers that windows supports natively).
Ah, you have a Windows venet driver?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
As an added bonus, its device-model is modular. A developer can write a new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking the guest down, and while eating QEMU based IO solutions for breakfast performance wise.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Afaict, qemu can't do either of those things.
We've seen that herring before,
Citation?
It's the compare venet-in-kernel to virtio-in-userspace thing again. Let's defer that until mst complete vhost-net mergable buffers, it which time we can compare vhost-net to venet and see how much vbus contributes to performance and how much of it comes from being in-kernel.
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't define these layers.
So define them if they're missing.
I just did.
Since this is getting confusing to me, I'll start from scratch looking at the vbus layers, top to bottom:
Guest side:
1. venet guest kernel driver - AFAICT, duplicates the virtio-net guest driver functionality
2. vbus guest driver (config and hotplug) - duplicates pci, or if you need non-pci support, virtio config and its pci bindings; needs reimplementation for all supported guests
3. vbus guest driver (interrupt coalescing, priority) - if needed, should be implemented as an irqchip (and be totally orthogonal to the driver); needs reimplementation for all supported guests
4. vbus guest driver (shm/ioq) - finder grained layering than virtio (which only supports the combination, due to the need for Xen support); can be retrofitted to virtio at some cost
Host side:
1. venet host kernel driver - is duplicated by vhost-net; doesn't support live migration, unprivileged users, or slirp
2. vbus host driver (config and hotplug) - duplicates pci support in userspace (which will need to be kept in any case); already has two userspace interfaces
3. vbus host driver (interrupt coalescing, priority) - if we think we need it (and I don't), should be part of kvm core, not a bus
4. vbus host driver (shm) - partially duplicated by vhost memory slots
5. vbus host driver (ioq) - duplicates userspace virtio, duplicated by vhost
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
Quoted 7 lines
Quoted 2 lines
It's not compatible.
No, that is incorrect. What you are apparently not understanding is that not only is vbus that library, but its extensible. So even if compatibility is your goal (it doesn't need to be IMO) it can be accommodated by how you interface to the library.
To me, compatible means I can live migrate an image to a new system without the user knowing about the change. You'll be able to do that with vhost-net.
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
That's ioeventfd. So far so similar.
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire
guest->host.
You'll probably need to change that as you start running smp guests.
Quoted 4 lines
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Please post your issues. I see ioeventfd/irqfd as critical kvm interfaces.
Quoted 6 lines
Quoted 5 lines
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
Quoted 7 lines
No, that is incorrect. The amount of "work" that a guest does is actually the same in both cases, since the guest OS peforms the hotswap handling natively for all bus types (at least for Linux and Windows). You still need to have a PV layer to interface with those objects in both cases, as well, so there is no such thing as "native interface" for PV. Its only a matter of where it occurs in the stack.
I'm missing something. Where's the pv layer for virtio-net?
Linux drivers have an abstraction layer to deal with non-pci. But the Windows drivers are ordinary pci drivers with nothing that looks pv-ish. You could implement virtio-net hardware if you wanted to.
Quoted 6 lines
Quoted 2 lines
non-privileged-user capable?
The short answer is "not yet (I think)". I need to write a patch to properly set the mode attribute in sysfs, but I think this will be trivial.
(and selinux label)
Quoted 5 lines
Quoted 2 lines
Ah, so you have two control planes.
So what? If anything, it goes to show how extensible the framework is that a new plane could be added in 119 lines of code:
Quoted 9 lines
~/git/linux-2.6> stg show vbus-add-admin-ioctls.patch | diffstat
Makefile | 3 - config-ioctl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)if and when having two control planes exceeds its utility, I will submit a simple patch that removes the useless one.
It always begins with a 119-line patch and then grows, that's life.
Quoted 6 lines
Quoted 3 lines
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
And likewise, neither does vbus.
For virt uses, I don't see the need. For non-virt, I have no opinion.
Signature · 6 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. _______________________________________________ Virtualization mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 6 lines · Avi Kivity
Quoted 4 lines
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Please post your issues. I see ioeventfd/irqfd as critical kvm interfaces.
I second that. AFAIK ioeventfd/irqfd got exposed to userspace in 2.6.32-rc1, if there are issues we better nail them before 2.6.32 is out. And yes, please start a different thread.
Signature · 7 lines
MST -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michael S. Tsirkin
maintainerRe: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 6 lines · Avi Kivity
Quoted 4 lines
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Please post your issues. I see ioeventfd/irqfd as critical kvm interfaces.
I second that. AFAIK ioeventfd/irqfd got exposed to userspace in 2.6.32-rc1, if there are issues we better nail them before 2.6.32 is out. And yes, please start a different thread.
Signature · 1 line
MST
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 15 lines · Avi Kivity
Quoted 11 lines · Gregory Haskins
Quoted 4 lines
A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work
over vbus.Binary compatibility with existing virtio drivers, while nice to have, is not a specific requirement nor goal. We will simply load an updated KMP/MSI into those guests and they will work again. As previously discussed, this is how more or less any system works today. It's like we are removing an old adapter card and adding a new one to "uprev the silicon".
Quoted 4 lines
Virtualization is about not doing that. Sometimes it's necessary (when you have made unfixable design mistakes), but just to replace a bus, with no advantages to the guest that has to be changed (other hypervisors or hypervisorless deployment scenarios aren't).
The problem is that your continued assertion that there is no advantage to the guest is a completely unsubstantiated claim. As it stands right now, I have a public git tree that, to my knowledge, is the fastest KVM PV networking implementation around. It also has capabilities that are demonstrably not found elsewhere, such as the ability to render generic shared-memory interconnects (scheduling, timers), interrupt-priority (qos), and interrupt-coalescing (exit-ratio reduction). I designed each of these capabilities after carefully analyzing where KVM was coming up short.
Those are facts.
I can't easily prove which of my new features alone are what makes it special per se, because I don't have unit tests for each part that breaks it down. What I _can_ state is that its the fastest and most feature rich KVM-PV tree that I am aware of, and others may download and test it themselves to verify my claims.
The disproof, on the other hand, would be in a counter example that still meets all the performance and feature criteria under all the same conditions while maintaining the existing ABI. To my knowledge, this doesn't exist.
Therefore, if you believe my work is irrelevant, show me a git tree that accomplishes the same feats in a binary compatible way, and I'll rethink my position. Until then, complaining about lack of binary compatibility is pointless since it is not an insurmountable proposition, and the one and only available solution declares it a required casualty.
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines
Further, non-shmem virtio can't work over vbus.
Actually I misspoke earlier when I said virtio works over non-shmem. Thinking about it some more, both virtio and vbus fundamentally require shared-memory, since sharing their metadata concurrently on both sides is their raison d'être.
The difference is that virtio utilizes a pre-translation/mapping (via ->add_buf) from the guest side. OTOH, vbus uses a post translation scheme (via memctx) from the host-side. If anything, vbus is actually more flexible because it doesn't assume the entire guest address space is directly mappable.
Quoted 6 lines
Quoted 3 lines
In summary, your statement is incorrect (though it is my fault for putting that idea in your head).
Well, Xen requires pre-translation (since the guest has to give the host (which is just another guest) permissions to access the data).
Actually I am not sure that it does require pre-translation. You might be able to use the memctx->copy_to/copy_from scheme in post translation as well, since those would be able to communicate to something like the xen kernel. But I suppose either method would result in extra exits, so there is no distinct benefit using vbus there..as you say below "they're just different".
The biggest difference is that my proposed model gets around the notion that the entire guest address space can be represented by an arbitrary pointer. For instance, the copy_to/copy_from routines take a GPA, but may use something indirect like a DMA controller to access that GPA. On the other hand, virtio fully expects a viable pointer to come out of the interface iiuc. This is in part what makes vbus more adaptable to non-virt.
Quoted 3 lines
So neither is a superset of the other, they're just different.
It doesn't really matter since Xen is unlikely to adopt virtio.
Agreed.
Quoted 12 lines
Quoted 11 lines
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
Quoted 2 lines
You can simply use the same vector for both rx and tx and poll both at every interrupt.
Yes, but that has its own problems: e.g. additional exits or at least additional overhead figuring out what happens each time. This is even more important as we scale out to MQ which may have dozens of queue pairs. You really want finer grained signal-path decode if you want peak performance.
Quoted 66 lines
Quoted 56 lines
In any case, here is an example run of a simple single-homed guest over standard GigE. Whats interesting here is that .qnotify to .notify ratio, as this is the interrupt-to-signal ratio. In this case, its 170047/151918, which comes out to about 11% savings in interrupt injections:
vbus-guest:/home/ghaskins # netperf -H dev
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto dev.laurelwood.net (192.168.1.10) port 0AF_INETRecv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec1048576 16384 16384 10.01 940.77
vbus-guest:/home/ghaskins # cat/sys/kernel/debug/pci-to-vbus-bridge.events : 170048 .qnotify : 151918 .qinject : 0 .notify : 170047 .inject : 18238 .bridgecalls : 18 .buscalls : 12vbus-guest:/home/ghaskins # cat
/proc/interrupts
CPU0
0: 87 IO-APIC-edge timer
1: 6 IO-APIC-edge i8042
4: 733 IO-APIC-edge serial
6: 2 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 0 IO-APIC-edge rtc0
9: 0 IO-APIC-fasteoi acpi10: 0 IO-APIC-fasteoi virtio1 12: 90 IO-APIC-edge i8042 14: 3041 IO-APIC-edge ata_piix 15: 1008 IO-APIC-edge ata_piix 24: 151933 PCI-MSI-edge vbus 25: 0 PCI-MSI-edge virtio0-config 26: 190 PCI-MSI-edge virtio0-input 27: 28 PCI-MSI-edge virtio0-output NMI: 0 Non-maskable interrupts LOC: 9854 Local timer interrupts SPU: 0 Spurious interrupts CNT: 0 Performance counter interrupts PND: 0 Performance pending work RES: 0 Rescheduling interrupts CAL: 0 Function call interrupts TLB: 0 TLB shootdowns TRM: 0 Thermal event interrupts THR: 0 Threshold APIC interrupts MCE: 0 Machine check exceptions MCP: 1 Machine check pollsERR: 0
MIS: 0Quoted 9 lines
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
Quoted 3 lines
(irq window exits should only be required on a small percentage of interrupt injections, since the guest will try to disable interrupts for short periods only)
Good point. You are probably right. Certainly the other 2 remain, however.
Ultimately, the fastest exit is the one you do not take. That is what I am trying to achieve.
Quoted 10 lines
Quoted 9 lines
Looking at some external stats paints an even bleaker picture: "exits" as reported by
kvm_statfor virtio-pci based virtio-net tip the scales at 65k/s vs 36k/s for vbus based venet. And virtio is consuming ~30% of my quad-core's cpu, vs 19% for venet during the test. Its hard to know which innovation or innovations may be responsible for the entire reduction, but certainly the interrupt-to-signal ratio mentioned above is probably helping.
Quoted 2 lines
Can you please stop comparing userspace-based virtio hosts to kernel-based venet hosts? We know the userspace implementation sucks.
Sorry, but its all I have right now. Last time I tried vhost it required a dedicated adapter which was a non-starter for my lab rig since I share it with others. I didn't want to tear apart the bridge setup, especially since mst told me the performance was worse than userspace. Therefore, there was no real point in working hard to get it running. I figured I would wait till the config and performance issues were resolved and there is a git tree to pull in.
Quoted 9 lines
Quoted 6 lines
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Requiring all three exits means the guest is spending most of its time with interrupts disabled; that's unlikely.
(see "softirqs" above)
Quoted 3 lines
Thanks for the numbers. Are those 11% attributable to rx/tx piggybacking from the same interface?
Its hard to tell, since I am not instrumented to discern the difference in this run. I do know from previous traces on the 10GE rig that the chelsio T3 that I am running reaps the pending-tx ring at the same time as a rx polling, so its very likely that both events are often coincident at least there.
Quoted 5 lines
Also, 170K interupts -> 17K interrupts/sec -> 55kbit/interrupt -> 6.8kB/interrupt. Ignoring interrupt merging and assuming equal rx/tx distribution, that's about 13kB/interrupt. Seems rather low for a saturated link.
I am not following: Do you suspect that I have too few interrupts to represent 940Mb/s, or that I have too little data/interrupt and this ratio should be improved?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Quoted 8 lines
Quoted 5 lines
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
With standard PCI, they do not. But all modern host adapters support MSI and they will happily give you one interrupt per queue.
While MSI is a good technological advancement for PCI, I was referring to signal:IDT ratio. MSI would still classify as 1:1.
Quoted 8 lines
Quoted 7 lines
PCI is somewhat of an outlier in that regard afaict. Its actually a nice feature of PCI when its used within its design spec (HW). For SW/PV, 1:1 suffers from, among other issues, that "triple-exit scaling" issue in the signal path I mentioned above. This is one of the many reasons I think PCI is not the best choice for PV.
Quoted 5 lines
Look at the vmxnet3 submission (recently posted on virtualization@). It's a perfectly ordinary PCI NIC driver, apart from having so many 'V's in the code. 16 rx queues, 8 tx queues, 25 MSIs, BARs for the registers. So while the industry as a whole might disagree with me, it seems VMware does not.
At the very least, BARs for the registers is worrisome, but I will reserve judgment until I see the numbers and review the code.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
Quoted 5 lines
Quoted 2 lines
That's pure speculation. I would advise you to reserve such statements until after a proper bakeoff can be completed.
Let's do that then. Please reserve the corresponding comparisons from your side as well.
That is quite the odd request. My graphs are all built using readily available code and open tools and do not speculate as to what someone else may come up with in the future. They reflect what is available today. Do you honestly think I should wait indefinitely for a competing idea to try to catch up before I talk about my results? That's certainly an interesting perspective.
With all due respect, the only red-herring is your unsubstantiated claims that my results do not matter.
Quoted 7 lines
Quoted 5 lines
This is not to mention
that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.What are scheduler coordination and non-802.x fabrics?
We are working on real-time, IB and QOS, for examples, in addition to the now well known 802.x venet driver.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Where doesn't it fit?
(avoiding infinite loop)
I'm serious. Where doesn't it fit? Point me at a URL if its already discussed.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
As vhost-net shows, you can do that without vbus
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
I think Ira said he can make vhost work?
Not exactly. It kind of works for 802.x only (albeit awkwardly) because there is no strong distinction between "resource" and "consumer" with ethernet. So you can run it inverted without any serious consequences (at least, not from consequences of the inversion). Since the x86 boards are the actual resource providers in his system, other device types will fail to map to the vhost model properly, like disk-io or consoles for instance.
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
and without breaking compatibility.
Compatibility with what? vhost hasn't even been officially deployed in KVM environments afaict, nevermind non-virt. Therefore, how could it possibly have compatibility constraints with something non-virt already?
Citation please.virtio-net over pci is deployed. Replacing the backend with vhost-net will require no guest modifications.
That _is_ a nice benefit, I agree. I just do not agree its a hard requirement.
Quoted 1 line
Replacing the frontend with venet or virt-net/vbus-pci will require guest modifications.
Understood, and I am ok with that. I think its necessary to gain critical performance enhancing features, and I think it will help in the long term to support more guests. I have not yet been proven wrong.
Quoted 3 lines
Obviously virtio-net isn't deployed in non-virt. But if we adopt vbus, we have to migrate guests.
As a first step, lets just shoot for "support" instead of "adopt".
Ill continue to push patches to you that help interfacing with the guest in a vbus neutral way (like irqfd/ioeventfd) and we can go from there. Are you open to this work assuming it passes normal review cycles, etc?
It would presumably be of use to others that want to interface to a
guest (e.g. vhost) as well.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Of course there is such a thing as native, a pci-ready guest has tons of support built into it
I specifically mentioned that already ([1]).
Quoted 8 lines
Quoted 4 lines
You are also overstating its role, since the basic OS is what implements the native support for bus-objects, hotswap, etc, _not_ PCI. PCI just rides underneath and feeds trivial events up, as do other bus-types (usb, scsi, vbus, etc).
But we have to implement vbus for each guest we want to support. That includes Windows and older Linux which has a different internal API, so we have to port the code multiple times, to get existing functionality.
Perhaps, but in reality its not very bad. The windows driver will already support any recent version that matters (at least back to 2000/XP), and the Linux side doesn't do anything weird so I know it works at least back to 2.6.16 iirc, and probably further.
Quoted 7 lines
Quoted 5 lines
And once those events are fed, you still need a
PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.virtio-net doesn't use any pv layer.
Well, it does when you really look closely at how it works. For one, it has the virtqueues library that would be (or at least _should be_) common for all virtio-X adapters, etc etc. Even if this layer is collapsed into each driver on the Windows platform, its still there nonetheless.
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
virtio-net doesn't modify the PCI model.
Sure it does. It doesn't use MMIO/PIO bars for registers, it uses vq->kick(). It doesn't use pci-config-space, it uses virtio->features.
It doesn't use PCI interrupts, it uses a callback on the vq etc, etc.
You would never use raw "registers", as the exit rate would crush you. You would never use raw interrupts, as you need a shared-memory based mitigation scheme.
IOW: Virtio has a device model layer that tunnels over PCI. It doesn't actually use PCI directly. This is in fact what allows the linux version to work over lguest, s390 and vbus in addition to PCI.
Quoted 5 lines
And if you look at vmxnet3,
they mention that it conforms to somthing called UPT, which allows hardware vendors to implement parts of their NIC model. So vmxnet3 is apparently suitable to both hardware and software implementations.
That's interesting and all, but the charter for vbus is for optimal software-to-software interfaces to a linux host, so I don't mind if my spec doesn't look conducive to a hardware implementation. As it turns out, I'm sure it would work there as well, but some of the optimizations wouldn't matter as much since hardware behaves differently.
Quoted 5 lines
Quoted 2 lines
Not to mention there are things you just plain can't do in PCI today, like dynamically assign signal-paths,
You can have dynamic MSI/queue routing with virtio, and each MSI can be routed to a vcpu at will.
Can you arbitrarily create a new MSI/queue on a per-device basis on the
fly? We want to do this for some upcoming designs. Or do you need to
predeclare the vectors when the device is hot-added?
Quoted 7 lines
Quoted 3 lines
priority, and coalescing, etc.
Do you mean interrupt priority? Well, apic allows interrupt priorities and Windows uses them; Linux doesn't. I don't see a reason to provide more than native hardware.
The APIC model is not optimal for PV given the exits required for a basic operation like an interrupt injection, and has scaling/flexibility issues with its 16:16 priority mapping.
OTOH, you don't necessarily want to rip it out because of all the additional features it has like the IPI facility and the handling of many low-performance data-paths. Therefore, I am of the opinion that the optimal placement for advanced signal handling is directly at the bus that provides the high-performance resources. I could be convinced otherwise with a compelling argument, but I think this is the path of least resistance.
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Since
practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.Quoted 6 lines
Actually IIUC, I think Xen bridges to their own bus as well (and only where they have to), just like vbus. They don't use PCI natively. PCI is perfectly suited as a bridge transport for PV, as I think the Xen and vbus examples have demonstrated. Its the 1:1 device-model where PCI has the most problems.
Quoted 2 lines
N:1 breaks down on large guests since one vcpu will have to process all events.
Well, first of all that is not necessarily true. Some high performance buses like SCSI and FC work fine with an aggregated model, so its not a foregone conclusion that aggregation kills SMP IO performance. This is especially true when you adding coalescing on top, like AlacrityVM does.
I do agree that other subsystems, like networking for instance, may sometimes benefit from flexible signal-routing because of multiqueue, etc, for particularly large guests. However, the decision to make the current kvm-connector used in AlacrityVM aggregate one priority FIFO per IRQ was an intentional design tradeoff. My experience with my target user base is that these data-centers are typically deploying 1-4 vcpu guests, so I optimized for that. YMMV, so we can design a different connector, or a different mode of the existing connector, to accommodate large guests as well if that was something desirable.
Quoted 2 lines
You could do N:M, with commands to change routings, but where's your userspace interface?
Well, we should be able to add that when/if its needed. I just don't think the need is there yet. KVM tops out at 16 IIUC anyway.
Quoted 2 lines
you can't tell from
/proc/interruptswhich
vbus interupts are active
This should be trivial to add some kind of *fs display. I will fix this shortly.
Quoted 2 lines
and irqbalance can't steer them towards less
busy cpus since they're invisible to the interrupt controller.
(see N:M above)
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.Quoted 8 lines
Quoted 2 lines
The short answer is "compatibility".
There was a point in time where the same could be said for virtio-pci based drivers vs realtek and e1000, so that argument is demonstrably silly. No one tried to make virtio work in a binary compatible way with realtek emulation, yet we all survived the requirement for loading a virtio driver to my knowledge.
Quoted 6 lines
The larger your installed base, the more difficult it is. Of course it's doable, but I prefer not doing it and instead improving things in a binary backwards compatible manner. If there is no choice we will bow to the inevitable and make our users upgrade. But at this point there is a choice, and I prefer to stick with vhost-net until it is proven that it won't work.
Fair enough. But note you are likely going to need to respin your existing drivers anyway to gain peak performance, since there are known shortcomings in the virtio-pci ABI today (like queue identification in the interrupt hotpath) as it stands. So that pain is coming one way or the other.
Quoted 11 lines
Quoted 5 lines
The bottom line is: Binary device compatibility is not required in any other system (as long as you follow sensible versioning/id rules), so why is KVM considered special?
One of the benefits of virtualization is that the guest model is stable. You can live-migrate guests and upgrade the hardware underneath. You can have a single guest image that you clone to provision new guests. If you switch to a new model, you give up those benefits, or you support both models indefinitely.
I understand what you are saying, but I don't buy it. If you add a new feature to an existing model even without something as drastic as a new bus, you still have the same exact dilemma: The migration target needs feature parity with consumed features in the guest. Its really the same no matter what unless you never add guest-visible features.
Quoted 4 lines
Note even hardware nowadays is binary compatible. One e1000 driver supports a ton of different cards, and I think (not sure) newer cards will work with older drivers, just without all their features.
Noted, but that is not really the same thing. Thats more like adding a feature bit to virtio, not replacing GigE with 10GE.
Quoted 10 lines
Quoted 7 lines
The fact is, it isn't special (at least not in this regard). What _is_ required is "support" and we fully intend to support these proposed components. I assure you that at least the users that care about maximum performance will not generally mind loading a driver. Most of them would have to anyway if they want to get beyond realtek emulation.
For a new install, sure. I'm talking about existing deployments (and those that will exist by the time vbus is ready for roll out).
The user will either specify "-net nic,model=venet", or they won't. Its their choice. Changing those parameters, vbus or otherwise, has ramifications w.r.t. what drivers must be loaded, and the user will understand this.
Quoted 8 lines
Quoted 7 lines
I am certainly in no position to tell you how to feel, but this declaration would seem from my perspective to be more of a means to an end than a legitimate concern. Otherwise we would never have had virtio support in the first place, since it was not "compatible" with previous releases.
Quoted 4 lines
virtio was certainly not pain free, needing Windows drivers, updates to management tools (you can't enable it by default, so you have to offer it as a choice), mkinitrd, etc. I'd rather not have to go through that again.
No general argument here, other than to reiterate that the driver is going to have to be redeployed anyway, since it will likely need new feature bits to fix the current ABI.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Especially if the device changed is your boot disk.
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
No, you have to update the driver in your initrd (for Linux)
Thats fine, the distros generally do this automatically when you load the updated KMP package.
Quoted 2 lines
or properly install the new driver (for Windows). It's especially difficult for Windows.
What is difficult here? I never seem to have any problems and I have all kinds of guests from XP to Win7.
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
You may not care about the pain caused to users, but I do, so I will
continue to insist on compatibility.For the users that don't care about maximum performance, there is no change (and thus zero pain) required. They can use realtek or virtio if they really want to. Neither is going away to my knowledge, and lets face it: 2.6Gb/s out of virtio to userspace isn't *that* bad. But "good enough" isn't good enough, and I won't rest till we get to native performance.
Quoted 2 lines
I don't want to support both virtio and vbus in parallel. There's enough work already.
Until I find some compelling reason that indicates I was wrong about all of this, I will continue building a community around the vbus code base and developing support for its components anyway. So that effort is going to happen in parallel regardless.
This is purely a question about whether you will work with me to make vbus an available option in upstream KVM or not.
Quoted 1 line
If we adopt vbus, we'll have to deprecate and eventually kill off virtio.
Thats more hyperbole. virtio is technically fine and complementary as it is. No one says you have to do anything drastic w.r.t. virtio. If you _did_ adopt vbus, perhaps you would want to optionally deprecate vhost or possibly the virtio-pci adapter, but that is about it. The rest of the infrastructure should be preserved if it was designed properly.
Quoted 12 lines
Quoted 11 lines
2) True pain to users is not caused by lack of binary compatibility. Its caused by lack of support. And its a good thing or we would all be emulating 8086 architecture forever...
..oh wait, I guess we kind of do that already ;). But at least we can slip in something more advanced once in a while (APIC vs PIC, USB vs uart, iso9660 vs floppy, for instance) and update the guest stack instead of insisting it must look like ISA forever for compatibility's sake.
Quoted 3 lines
PCI is continuously updated, with MSI, MSI-X, and IOMMU support being some recent updates. I'd like to ride on top of that instead of having to clone it for every guest I support.
While a noble goal, one of the points I keep making though, as someone who has built the stack both ways, is almost none of the PCI stack is actually needed to get the PV job done. The part you do need is primarily a function of the generic OS stack and trivial to interface with anyway.
Plus, as a lesser point: it doesn't work everywhere so you end up solving the same kind of vbus-like design problem again and again when PCI is missing.
Quoted 23 lines
Quoted 10 lines
Quoted 5 lines
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode)
First of all, bus-decode is substantially easier than per-device decode (you have to track all those per-device/per-signal fds somewhere, integrate with hotswap, etc), and its only done once per guest at startup and left alone. So its already not apples to apples.
Right, it means you can hand off those eventfds to other qemus or other pure userspace servers. It's more flexible.
Quoted 8 lines
Second, while its true that the general kvm-connector bus-decode needs to be programmed, that is a function of adapting to the environment that _you_ created for me. The original kvm-connector was discovered via cpuid and hypercalls, and didn't need userspace at all to set it up.
Therefore it would be entirely unfair of you to turn around and somehow
try to use that trait of the design against me since you yourself imposed it.
Quoted 3 lines
No kvm feature will ever be exposed to a guest without userspace intervention. It's a basic requirement. If it causes complexity (and it does) we have to live with it.
Right. cpuid is exposed by userspace, so that was the control point in the original design. The presence of the PCI_BRIDGE in the new code (again exported by userspace) is what controls it now. From there, there are various mechanisms we employ to control that features the guest may see, such as the sysfs/attribute system, the revision of the bridge, and the feature bits that it and its subordinate devices expose.
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Does it work on Windows?
This question doesn't make sense. Hotswap control occurs on the host, which is always Linux.
Quoted 7 lines
Quoted 5 lines
If you were asking about whether a windows guest will support hotswap:
the answer is "yes". Our windows driver presents a unique PDO/FDO pair for each logical device instance that is pushed out (just like the built in usb, pci, scsi bus drivers that windows supports natively).Ah, you have a Windows venet driver?
Almost. It's WIP, but hopefully soon, along with core support for the bus, etc.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
As an added bonus, its device-model is modular. A developer can write a
new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking
the guest down, and while eating QEMU based IO solutions for breakfast performance wise.Afaict, qemu can't do either of those things.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
We've seen that herring before,
Citation?
It's the compare venet-in-kernel to virtio-in-userspace thing again.
No, you said KVM has "userspace hotplug". I retorted that vbus not only has hotplug, it also has a modular architecture. You then countered that this feature is a red-herring. If this was previously discussed and rejected for some reason, I would like to know the history. Or did I misunderstand you?
Or if you are somehow implying that the lack of modularity has to do with virtio-in-userspace, I beg to differ. Even with vhost, you still have to have a paired model in qemu, so it will not be a modular architecture by virtue of the vhost patch series either. You would need qemu to support modular devices as well, which I've been told that isn't going to happen any time soon.
Quoted 3 lines
Let's defer that until mst complete vhost-net mergable buffers, it which time we can compare vhost-net to venet and see how much vbus contributes to performance and how much of it comes from being in-kernel.
I look forward to it.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't
define these layers.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
So define them if they're missing.
I just did.
Since this is getting confusing to me, I'll start from scratch looking at the vbus layers, top to bottom:
I wouldn't describe it like this
Quoted 14 lines
Guest side:
1. venet guest kernel driver - AFAICT, duplicates the virtio-net guest driver functionality
2. vbus guest driver (config and hotplug) - duplicates pci, or if you need non-pci support, virtio config and its pci bindings; needs reimplementation for all supported guests
3. vbus guest driver (interrupt coalescing, priority) - if needed, should be implemented as an irqchip (and be totally orthogonal to the driver); needs reimplementation for all supported guests
4. vbus guest driver (shm/ioq) - finder grained layering than virtio (which only supports the combination, due to the need for Xen support); can be retrofitted to virtio at some cost
Quoted 11 lines
Host side:
1. venet host kernel driver - is duplicated by vhost-net; doesn't support live migration, unprivileged users, or slirp
2. vbus host driver (config and hotplug) - duplicates pci support in userspace (which will need to be kept in any case); already has two userspace interfaces
3. vbus host driver (interrupt coalescing, priority) - if we think we need it (and I don't), should be part of kvm core, not a bus
4. vbus host driver (shm) - partially duplicated by vhost memory slots
5. vbus host driver (ioq) - duplicates userspace virtio, duplicated by vhost
For one, we have the common layer of shm-signal, and IOQ. These libraries were designed to be reused on both sides of the link. Generally shm-signal has no counterpart in the existing model, though its functionality is integrated into the virtqueue. IOQ is duplicated by virtqueue, but I think its a better design at least in this role, so I use it pervasively throughout the stack. We can discuss that in a separate thread.
From there, going down the stack, it looks like
(guest-side)
|-------------------------
| venet (competes with virtio-net)
|-------------------------
| vbus-proxy (competes with pci-bus, config+hotplug, sync/async)
|-------------------------
| vbus-pcibridge (interrupt coalescing + priority, fastpath)
|-------------------------
|
|-------------------------
| vbus-kvmconnector (interrupt coalescing + priority, fast-path)
|-------------------------
| vbus-core (hotplug, address decoding, etc)
|-------------------------
| venet-device (ioq frame/deframe to tap/macvlan/vmdq, etc)
|-------------------------If you want to use virtio, insert a virtio layer between the "driver" and "device" components at the outer edges of the stack.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
Quoted 7 lines
Quoted 2 lines
It's not compatible.
No, that is incorrect. What you are apparently not understanding is that not only is vbus that library, but its extensible. So even if compatibility is your goal (it doesn't need to be IMO) it can be accommodated by how you interface to the library.
Quoted 3 lines
To me, compatible means I can live migrate an image to a new system without the user knowing about the change. You'll be able to do that with vhost-net.
As soon as you add any new guest-visible feature, you are in the same exact boat.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
That's ioeventfd. So far so similar.
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire
guest->host.You'll probably need to change that as you start running smp guests.
The hypercall channel is already SMP optimized over a single PIO path, so I think we are covered there. See "fastcall" in my code for details:
It just passes the cpuid into the PIO write so we can have parallel, lockless "hypercalls". This forms the basis of our guest scheduler support, for instance.
Quoted 7 lines
Quoted 5 lines
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Please post your issues. I see ioeventfd/irqfd as critical kvm interfaces.
Will do. It would be nice to come back to this interface.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
Quoted 7 lines
No, that is incorrect. The amount of "work" that a guest does is actually the same in both cases, since the guest OS peforms the hotswap handling natively for all bus types (at least for Linux and Windows). You still need to have a PV layer to interface with those objects in both cases, as well, so there is no such thing as "native interface" for PV. Its only a matter of where it occurs in the stack.
Quoted 1 line
I'm missing something. Where's the pv layer for virtio-net?
covered above
Quoted 4 lines
Linux drivers have an abstraction layer to deal with non-pci. But the Windows drivers are ordinary pci drivers with nothing that looks pv-ish.
They certainly do not have to be since Windows supports a similar notion as the LDM in Linux. In fact, we are exploiting that Windows facility in our drivers. It's rather unfortunate if its true that your drivers were not designed this way, since virtio has a rather nice stack model on Linux that could work in Windows as well.
Quoted 1 line
You could implement virtio-net hardware if you wanted to.
Technically you could build vbus in hardware too, I suppose, since the bridge is PCI compliant. I would never advocate it, however, since many of our tricks do not matter if its real hardware (e.g. they are optimized for the costs associated with VM).
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
non-privileged-user capable?
The short answer is "not yet (I think)". I need to write a patch to properly set the mode attribute in sysfs, but I think this will be trivial.
(and selinux label)
If any of these things that are problems, they can simply be exposed via the new ioctl admin interface, I suppose.
Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Ah, so you have two control planes.
So what? If anything, it goes to show how extensible the framework is that a new plane could be added in 119 lines of code:
~/git/linux-2.6> stg show vbus-add-admin-ioctls.patch | diffstat
Makefile | 3 - config-ioctl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 3 lines
if and when having two control planes exceeds its utility, I will submit a simple patch that removes the useless one.
It always begins with a 119-line patch and then grows, that's life.
I can't argue with that.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
And likewise, neither does vbus.
For virt uses, I don't see the need. For non-virt, I have no opinion.
Well, I hope to change your mind on both counts, then.
Kind Regards,
-Greg
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Avi KivityQuoted 15 lines · Avi Kivity
Quoted 11 lines · Gregory Haskins
Quoted 4 lines
A 2.6.27 guest, or Windows guest with the existing virtio drivers, won't work
over vbus.Binary compatibility with existing virtio drivers, while nice to have, is not a specific requirement nor goal. We will simply load an updated KMP/MSI into those guests and they will work again. As previously discussed, this is how more or less any system works today. It's like we are removing an old adapter card and adding a new one to "uprev the silicon".
Quoted 4 lines
Virtualization is about not doing that. Sometimes it's necessary (when you have made unfixable design mistakes), but just to replace a bus, with no advantages to the guest that has to be changed (other hypervisors or hypervisorless deployment scenarios aren't).
The problem is that your continued assertion that there is no advantage to the guest is a completely unsubstantiated claim. As it stands right now, I have a public git tree that, to my knowledge, is the fastest KVM PV networking implementation around. It also has capabilities that are demonstrably not found elsewhere, such as the ability to render generic shared-memory interconnects (scheduling, timers), interrupt-priority (qos), and interrupt-coalescing (exit-ratio reduction). I designed each of these capabilities after carefully analyzing where KVM was coming up short.
Those are facts.
I can't easily prove which of my new features alone are what makes it special per se, because I don't have unit tests for each part that breaks it down. What I _can_ state is that its the fastest and most feature rich KVM-PV tree that I am aware of, and others may download and test it themselves to verify my claims.
The disproof, on the other hand, would be in a counter example that still meets all the performance and feature criteria under all the same conditions while maintaining the existing ABI. To my knowledge, this doesn't exist.
Therefore, if you believe my work is irrelevant, show me a git tree that accomplishes the same feats in a binary compatible way, and I'll rethink my position. Until then, complaining about lack of binary compatibility is pointless since it is not an insurmountable proposition, and the one and only available solution declares it a required casualty.
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines
Further, non-shmem virtio can't work over vbus.
Actually I misspoke earlier when I said virtio works over non-shmem. Thinking about it some more, both virtio and vbus fundamentally require shared-memory, since sharing their metadata concurrently on both sides is their raison d'être.
The difference is that virtio utilizes a pre-translation/mapping (via ->add_buf) from the guest side. OTOH, vbus uses a post translation scheme (via memctx) from the host-side. If anything, vbus is actually more flexible because it doesn't assume the entire guest address space is directly mappable.
Quoted 6 lines
Quoted 3 lines
In summary, your statement is incorrect (though it is my fault for putting that idea in your head).
Well, Xen requires pre-translation (since the guest has to give the host (which is just another guest) permissions to access the data).
Actually I am not sure that it does require pre-translation. You might be able to use the memctx->copy_to/copy_from scheme in post translation as well, since those would be able to communicate to something like the xen kernel. But I suppose either method would result in extra exits, so there is no distinct benefit using vbus there..as you say below "they're just different".
The biggest difference is that my proposed model gets around the notion that the entire guest address space can be represented by an arbitrary pointer. For instance, the copy_to/copy_from routines take a GPA, but may use something indirect like a DMA controller to access that GPA. On the other hand, virtio fully expects a viable pointer to come out of the interface iiuc. This is in part what makes vbus more adaptable to non-virt.
Quoted 3 lines
So neither is a superset of the other, they're just different.
It doesn't really matter since Xen is unlikely to adopt virtio.
Agreed.
Quoted 12 lines
Quoted 11 lines
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
Quoted 2 lines
You can simply use the same vector for both rx and tx and poll both at every interrupt.
Yes, but that has its own problems: e.g. additional exits or at least additional overhead figuring out what happens each time. This is even more important as we scale out to MQ which may have dozens of queue pairs. You really want finer grained signal-path decode if you want peak performance.
Quoted 66 lines
Quoted 56 lines
In any case, here is an example run of a simple single-homed guest over standard GigE. Whats interesting here is that .qnotify to .notify ratio, as this is the interrupt-to-signal ratio. In this case, its 170047/151918, which comes out to about 11% savings in interrupt injections:
vbus-guest:/home/ghaskins # netperf -H dev
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto dev.laurelwood.net (192.168.1.10) port 0AF_INETRecv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec1048576 16384 16384 10.01 940.77
vbus-guest:/home/ghaskins # cat/sys/kernel/debug/pci-to-vbus-bridge.events : 170048 .qnotify : 151918 .qinject : 0 .notify : 170047 .inject : 18238 .bridgecalls : 18 .buscalls : 12vbus-guest:/home/ghaskins # cat
/proc/interrupts
CPU0
0: 87 IO-APIC-edge timer
1: 6 IO-APIC-edge i8042
4: 733 IO-APIC-edge serial
6: 2 IO-APIC-edge floppy
7: 0 IO-APIC-edge parport0
8: 0 IO-APIC-edge rtc0
9: 0 IO-APIC-fasteoi acpi10: 0 IO-APIC-fasteoi virtio1 12: 90 IO-APIC-edge i8042 14: 3041 IO-APIC-edge ata_piix 15: 1008 IO-APIC-edge ata_piix 24: 151933 PCI-MSI-edge vbus 25: 0 PCI-MSI-edge virtio0-config 26: 190 PCI-MSI-edge virtio0-input 27: 28 PCI-MSI-edge virtio0-output NMI: 0 Non-maskable interrupts LOC: 9854 Local timer interrupts SPU: 0 Spurious interrupts CNT: 0 Performance counter interrupts PND: 0 Performance pending work RES: 0 Rescheduling interrupts CAL: 0 Function call interrupts TLB: 0 TLB shootdowns TRM: 0 Thermal event interrupts THR: 0 Threshold APIC interrupts MCE: 0 Machine check exceptions MCP: 1 Machine check pollsERR: 0
MIS: 0Quoted 9 lines
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
Quoted 3 lines
(irq window exits should only be required on a small percentage of interrupt injections, since the guest will try to disable interrupts for short periods only)
Good point. You are probably right. Certainly the other 2 remain, however.
Ultimately, the fastest exit is the one you do not take. That is what I am trying to achieve.
Quoted 10 lines
Quoted 9 lines
Looking at some external stats paints an even bleaker picture: "exits" as reported by
kvm_statfor virtio-pci based virtio-net tip the scales at 65k/s vs 36k/s for vbus based venet. And virtio is consuming ~30% of my quad-core's cpu, vs 19% for venet during the test. Its hard to know which innovation or innovations may be responsible for the entire reduction, but certainly the interrupt-to-signal ratio mentioned above is probably helping.
Quoted 2 lines
Can you please stop comparing userspace-based virtio hosts to kernel-based venet hosts? We know the userspace implementation sucks.
Sorry, but its all I have right now. Last time I tried vhost it required a dedicated adapter which was a non-starter for my lab rig since I share it with others. I didn't want to tear apart the bridge setup, especially since mst told me the performance was worse than userspace. Therefore, there was no real point in working hard to get it running. I figured I would wait till the config and performance issues were resolved and there is a git tree to pull in.
Quoted 9 lines
Quoted 6 lines
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Requiring all three exits means the guest is spending most of its time with interrupts disabled; that's unlikely.
(see "softirqs" above)
Quoted 3 lines
Thanks for the numbers. Are those 11% attributable to rx/tx piggybacking from the same interface?
Its hard to tell, since I am not instrumented to discern the difference in this run. I do know from previous traces on the 10GE rig that the chelsio T3 that I am running reaps the pending-tx ring at the same time as a rx polling, so its very likely that both events are often coincident at least there.
Quoted 5 lines
Also, 170K interupts -> 17K interrupts/sec -> 55kbit/interrupt -> 6.8kB/interrupt. Ignoring interrupt merging and assuming equal rx/tx distribution, that's about 13kB/interrupt. Seems rather low for a saturated link.
I am not following: Do you suspect that I have too few interrupts to represent 940Mb/s, or that I have too little data/interrupt and this ratio should be improved?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
and priortizable/nestable signals.
That doesn't belong in a bus.
Quoted 8 lines
Quoted 5 lines
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
With standard PCI, they do not. But all modern host adapters support MSI and they will happily give you one interrupt per queue.
While MSI is a good technological advancement for PCI, I was referring to signal:IDT ratio. MSI would still classify as 1:1.
Quoted 8 lines
Quoted 7 lines
PCI is somewhat of an outlier in that regard afaict. Its actually a nice feature of PCI when its used within its design spec (HW). For SW/PV, 1:1 suffers from, among other issues, that "triple-exit scaling" issue in the signal path I mentioned above. This is one of the many reasons I think PCI is not the best choice for PV.
Quoted 5 lines
Look at the vmxnet3 submission (recently posted on virtualization@). It's a perfectly ordinary PCI NIC driver, apart from having so many 'V's in the code. 16 rx queues, 8 tx queues, 25 MSIs, BARs for the registers. So while the industry as a whole might disagree with me, it seems VMware does not.
At the very least, BARs for the registers is worrisome, but I will reserve judgment until I see the numbers and review the code.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
That's a red herring. The problem is not with virtio as an ABI, but with its implementation in userspace. vhost-net should offer equivalent performance to vbus.
Quoted 5 lines
Quoted 2 lines
That's pure speculation. I would advise you to reserve such statements until after a proper bakeoff can be completed.
Let's do that then. Please reserve the corresponding comparisons from your side as well.
That is quite the odd request. My graphs are all built using readily available code and open tools and do not speculate as to what someone else may come up with in the future. They reflect what is available today. Do you honestly think I should wait indefinitely for a competing idea to try to catch up before I talk about my results? That's certainly an interesting perspective.
With all due respect, the only red-herring is your unsubstantiated claims that my results do not matter.
Quoted 7 lines
Quoted 5 lines
This is not to mention
that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.What are scheduler coordination and non-802.x fabrics?
We are working on real-time, IB and QOS, for examples, in addition to the now well known 802.x venet driver.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Where doesn't it fit?
(avoiding infinite loop)
I'm serious. Where doesn't it fit? Point me at a URL if its already discussed.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
But that's not a strong argument for vbus; instead of adding vbus you could make virtio more friendly to non-virt
Actually, it _is_ a strong argument then because adding vbus is what helps makes virtio friendly to non-virt, at least for when performance matters.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
As vhost-net shows, you can do that without vbus
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
I think Ira said he can make vhost work?
Not exactly. It kind of works for 802.x only (albeit awkwardly) because there is no strong distinction between "resource" and "consumer" with ethernet. So you can run it inverted without any serious consequences (at least, not from consequences of the inversion). Since the x86 boards are the actual resource providers in his system, other device types will fail to map to the vhost model properly, like disk-io or consoles for instance.
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
and without breaking compatibility.
Compatibility with what? vhost hasn't even been officially deployed in KVM environments afaict, nevermind non-virt. Therefore, how could it possibly have compatibility constraints with something non-virt already?
Citation please.virtio-net over pci is deployed. Replacing the backend with vhost-net will require no guest modifications.
That _is_ a nice benefit, I agree. I just do not agree its a hard requirement.
Quoted 1 line
Replacing the frontend with venet or virt-net/vbus-pci will require guest modifications.
Understood, and I am ok with that. I think its necessary to gain critical performance enhancing features, and I think it will help in the long term to support more guests. I have not yet been proven wrong.
Quoted 3 lines
Obviously virtio-net isn't deployed in non-virt. But if we adopt vbus, we have to migrate guests.
As a first step, lets just shoot for "support" instead of "adopt".
Ill continue to push patches to you that help interfacing with the guest in a vbus neutral way (like irqfd/ioeventfd) and we can go from there. Are you open to this work assuming it passes normal review cycles, etc?
It would presumably be of use to others that want to interface to a
guest (e.g. vhost) as well.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Of course there is such a thing as native, a pci-ready guest has tons of support built into it
I specifically mentioned that already ([1]).
Quoted 8 lines
Quoted 4 lines
You are also overstating its role, since the basic OS is what implements the native support for bus-objects, hotswap, etc, _not_ PCI. PCI just rides underneath and feeds trivial events up, as do other bus-types (usb, scsi, vbus, etc).
But we have to implement vbus for each guest we want to support. That includes Windows and older Linux which has a different internal API, so we have to port the code multiple times, to get existing functionality.
Perhaps, but in reality its not very bad. The windows driver will already support any recent version that matters (at least back to 2000/XP), and the Linux side doesn't do anything weird so I know it works at least back to 2.6.16 iirc, and probably further.
Quoted 7 lines
Quoted 5 lines
And once those events are fed, you still need a
PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.virtio-net doesn't use any pv layer.
Well, it does when you really look closely at how it works. For one, it has the virtqueues library that would be (or at least _should be_) common for all virtio-X adapters, etc etc. Even if this layer is collapsed into each driver on the Windows platform, its still there nonetheless.
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
virtio-net doesn't modify the PCI model.
Sure it does. It doesn't use MMIO/PIO bars for registers, it uses vq->kick(). It doesn't use pci-config-space, it uses virtio->features.
It doesn't use PCI interrupts, it uses a callback on the vq etc, etc.
You would never use raw "registers", as the exit rate would crush you. You would never use raw interrupts, as you need a shared-memory based mitigation scheme.
IOW: Virtio has a device model layer that tunnels over PCI. It doesn't actually use PCI directly. This is in fact what allows the linux version to work over lguest, s390 and vbus in addition to PCI.
Quoted 5 lines
And if you look at vmxnet3,
they mention that it conforms to somthing called UPT, which allows hardware vendors to implement parts of their NIC model. So vmxnet3 is apparently suitable to both hardware and software implementations.
That's interesting and all, but the charter for vbus is for optimal software-to-software interfaces to a linux host, so I don't mind if my spec doesn't look conducive to a hardware implementation. As it turns out, I'm sure it would work there as well, but some of the optimizations wouldn't matter as much since hardware behaves differently.
Quoted 5 lines
Quoted 2 lines
Not to mention there are things you just plain can't do in PCI today, like dynamically assign signal-paths,
You can have dynamic MSI/queue routing with virtio, and each MSI can be routed to a vcpu at will.
Can you arbitrarily create a new MSI/queue on a per-device basis on the
fly? We want to do this for some upcoming designs. Or do you need to
predeclare the vectors when the device is hot-added?
Quoted 7 lines
Quoted 3 lines
priority, and coalescing, etc.
Do you mean interrupt priority? Well, apic allows interrupt priorities and Windows uses them; Linux doesn't. I don't see a reason to provide more than native hardware.
The APIC model is not optimal for PV given the exits required for a basic operation like an interrupt injection, and has scaling/flexibility issues with its 16:16 priority mapping.
OTOH, you don't necessarily want to rip it out because of all the additional features it has like the IPI facility and the handling of many low-performance data-paths. Therefore, I am of the opinion that the optimal placement for advanced signal handling is directly at the bus that provides the high-performance resources. I could be convinced otherwise with a compelling argument, but I think this is the path of least resistance.
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Since
practically everyone (including Xen) does their paravirt drivers atop pci, the claim that pci isn't suitable for high performance is incorrect.Quoted 6 lines
Actually IIUC, I think Xen bridges to their own bus as well (and only where they have to), just like vbus. They don't use PCI natively. PCI is perfectly suited as a bridge transport for PV, as I think the Xen and vbus examples have demonstrated. Its the 1:1 device-model where PCI has the most problems.
Quoted 2 lines
N:1 breaks down on large guests since one vcpu will have to process all events.
Well, first of all that is not necessarily true. Some high performance buses like SCSI and FC work fine with an aggregated model, so its not a foregone conclusion that aggregation kills SMP IO performance. This is especially true when you adding coalescing on top, like AlacrityVM does.
I do agree that other subsystems, like networking for instance, may sometimes benefit from flexible signal-routing because of multiqueue, etc, for particularly large guests. However, the decision to make the current kvm-connector used in AlacrityVM aggregate one priority FIFO per IRQ was an intentional design tradeoff. My experience with my target user base is that these data-centers are typically deploying 1-4 vcpu guests, so I optimized for that. YMMV, so we can design a different connector, or a different mode of the existing connector, to accommodate large guests as well if that was something desirable.
Quoted 2 lines
You could do N:M, with commands to change routings, but where's your userspace interface?
Well, we should be able to add that when/if its needed. I just don't think the need is there yet. KVM tops out at 16 IIUC anyway.
Quoted 2 lines
you can't tell from
/proc/interruptswhich
vbus interupts are active
This should be trivial to add some kind of *fs display. I will fix this shortly.
Quoted 2 lines
and irqbalance can't steer them towards less
busy cpus since they're invisible to the interrupt controller.
(see N:M above)
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
And lastly, why would you _need_ to use the so called "native" mechanism? The short answer is, "you don't". Any given system (guest or bare-metal) already have a wide-range of buses (try running "tree
/sys/bus" in Linux). More importantly, the concept of adding new buses is widely supported in both the Windows and Linux driver model (and probably any other guest-type that matters). Therefore, despite claims to the contrary, its not hard or even unusual to add a new bus to the mix.Quoted 8 lines
Quoted 2 lines
The short answer is "compatibility".
There was a point in time where the same could be said for virtio-pci based drivers vs realtek and e1000, so that argument is demonstrably silly. No one tried to make virtio work in a binary compatible way with realtek emulation, yet we all survived the requirement for loading a virtio driver to my knowledge.
Quoted 6 lines
The larger your installed base, the more difficult it is. Of course it's doable, but I prefer not doing it and instead improving things in a binary backwards compatible manner. If there is no choice we will bow to the inevitable and make our users upgrade. But at this point there is a choice, and I prefer to stick with vhost-net until it is proven that it won't work.
Fair enough. But note you are likely going to need to respin your existing drivers anyway to gain peak performance, since there are known shortcomings in the virtio-pci ABI today (like queue identification in the interrupt hotpath) as it stands. So that pain is coming one way or the other.
Quoted 11 lines
Quoted 5 lines
The bottom line is: Binary device compatibility is not required in any other system (as long as you follow sensible versioning/id rules), so why is KVM considered special?
One of the benefits of virtualization is that the guest model is stable. You can live-migrate guests and upgrade the hardware underneath. You can have a single guest image that you clone to provision new guests. If you switch to a new model, you give up those benefits, or you support both models indefinitely.
I understand what you are saying, but I don't buy it. If you add a new feature to an existing model even without something as drastic as a new bus, you still have the same exact dilemma: The migration target needs feature parity with consumed features in the guest. Its really the same no matter what unless you never add guest-visible features.
Quoted 4 lines
Note even hardware nowadays is binary compatible. One e1000 driver supports a ton of different cards, and I think (not sure) newer cards will work with older drivers, just without all their features.
Noted, but that is not really the same thing. Thats more like adding a feature bit to virtio, not replacing GigE with 10GE.
Quoted 10 lines
Quoted 7 lines
The fact is, it isn't special (at least not in this regard). What _is_ required is "support" and we fully intend to support these proposed components. I assure you that at least the users that care about maximum performance will not generally mind loading a driver. Most of them would have to anyway if they want to get beyond realtek emulation.
For a new install, sure. I'm talking about existing deployments (and those that will exist by the time vbus is ready for roll out).
The user will either specify "-net nic,model=venet", or they won't. Its their choice. Changing those parameters, vbus or otherwise, has ramifications w.r.t. what drivers must be loaded, and the user will understand this.
Quoted 8 lines
Quoted 7 lines
I am certainly in no position to tell you how to feel, but this declaration would seem from my perspective to be more of a means to an end than a legitimate concern. Otherwise we would never have had virtio support in the first place, since it was not "compatible" with previous releases.
Quoted 4 lines
virtio was certainly not pain free, needing Windows drivers, updates to management tools (you can't enable it by default, so you have to offer it as a choice), mkinitrd, etc. I'd rather not have to go through that again.
No general argument here, other than to reiterate that the driver is going to have to be redeployed anyway, since it will likely need new feature bits to fix the current ABI.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Especially if the device changed is your boot disk.
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
No, you have to update the driver in your initrd (for Linux)
Thats fine, the distros generally do this automatically when you load the updated KMP package.
Quoted 2 lines
or properly install the new driver (for Windows). It's especially difficult for Windows.
What is difficult here? I never seem to have any problems and I have all kinds of guests from XP to Win7.
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
You may not care about the pain caused to users, but I do, so I will
continue to insist on compatibility.For the users that don't care about maximum performance, there is no change (and thus zero pain) required. They can use realtek or virtio if they really want to. Neither is going away to my knowledge, and lets face it: 2.6Gb/s out of virtio to userspace isn't *that* bad. But "good enough" isn't good enough, and I won't rest till we get to native performance.
Quoted 2 lines
I don't want to support both virtio and vbus in parallel. There's enough work already.
Until I find some compelling reason that indicates I was wrong about all of this, I will continue building a community around the vbus code base and developing support for its components anyway. So that effort is going to happen in parallel regardless.
This is purely a question about whether you will work with me to make vbus an available option in upstream KVM or not.
Quoted 1 line
If we adopt vbus, we'll have to deprecate and eventually kill off virtio.
Thats more hyperbole. virtio is technically fine and complementary as it is. No one says you have to do anything drastic w.r.t. virtio. If you _did_ adopt vbus, perhaps you would want to optionally deprecate vhost or possibly the virtio-pci adapter, but that is about it. The rest of the infrastructure should be preserved if it was designed properly.
Quoted 12 lines
Quoted 11 lines
2) True pain to users is not caused by lack of binary compatibility. Its caused by lack of support. And its a good thing or we would all be emulating 8086 architecture forever...
..oh wait, I guess we kind of do that already ;). But at least we can slip in something more advanced once in a while (APIC vs PIC, USB vs uart, iso9660 vs floppy, for instance) and update the guest stack instead of insisting it must look like ISA forever for compatibility's sake.
Quoted 3 lines
PCI is continuously updated, with MSI, MSI-X, and IOMMU support being some recent updates. I'd like to ride on top of that instead of having to clone it for every guest I support.
While a noble goal, one of the points I keep making though, as someone who has built the stack both ways, is almost none of the PCI stack is actually needed to get the PV job done. The part you do need is primarily a function of the generic OS stack and trivial to interface with anyway.
Plus, as a lesser point: it doesn't work everywhere so you end up solving the same kind of vbus-like design problem again and again when PCI is missing.
Quoted 23 lines
Quoted 10 lines
Quoted 5 lines
So we have: vbus needs a connector, vhost needs a connector. vbus doesn't need userspace to program the addresses (but does need userspace to instantiate the devices and to program the bus address decode)
First of all, bus-decode is substantially easier than per-device decode (you have to track all those per-device/per-signal fds somewhere, integrate with hotswap, etc), and its only done once per guest at startup and left alone. So its already not apples to apples.
Right, it means you can hand off those eventfds to other qemus or other pure userspace servers. It's more flexible.
Quoted 8 lines
Second, while its true that the general kvm-connector bus-decode needs to be programmed, that is a function of adapting to the environment that _you_ created for me. The original kvm-connector was discovered via cpuid and hypercalls, and didn't need userspace at all to set it up.
Therefore it would be entirely unfair of you to turn around and somehow
try to use that trait of the design against me since you yourself imposed it.
Quoted 3 lines
No kvm feature will ever be exposed to a guest without userspace intervention. It's a basic requirement. If it causes complexity (and it does) we have to live with it.
Right. cpuid is exposed by userspace, so that was the control point in the original design. The presence of the PCI_BRIDGE in the new code (again exported by userspace) is what controls it now. From there, there are various mechanisms we employ to control that features the guest may see, such as the sysfs/attribute system, the revision of the bridge, and the feature bits that it and its subordinate devices expose.
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Does it work on Windows?
This question doesn't make sense. Hotswap control occurs on the host, which is always Linux.
Quoted 7 lines
Quoted 5 lines
If you were asking about whether a windows guest will support hotswap:
the answer is "yes". Our windows driver presents a unique PDO/FDO pair for each logical device instance that is pushed out (just like the built in usb, pci, scsi bus drivers that windows supports natively).Ah, you have a Windows venet driver?
Almost. It's WIP, but hopefully soon, along with core support for the bus, etc.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
As an added bonus, its device-model is modular. A developer can write a
new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking
the guest down, and while eating QEMU based IO solutions for breakfast performance wise.Afaict, qemu can't do either of those things.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
We've seen that herring before,
Citation?
It's the compare venet-in-kernel to virtio-in-userspace thing again.
No, you said KVM has "userspace hotplug". I retorted that vbus not only has hotplug, it also has a modular architecture. You then countered that this feature is a red-herring. If this was previously discussed and rejected for some reason, I would like to know the history. Or did I misunderstand you?
Or if you are somehow implying that the lack of modularity has to do with virtio-in-userspace, I beg to differ. Even with vhost, you still have to have a paired model in qemu, so it will not be a modular architecture by virtue of the vhost patch series either. You would need qemu to support modular devices as well, which I've been told that isn't going to happen any time soon.
Quoted 3 lines
Let's defer that until mst complete vhost-net mergable buffers, it which time we can compare vhost-net to venet and see how much vbus contributes to performance and how much of it comes from being in-kernel.
I look forward to it.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Refactor instead of duplicating.
There is no duplicating. vbus has no equivalent today as virtio doesn't
define these layers.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
So define them if they're missing.
I just did.
Since this is getting confusing to me, I'll start from scratch looking at the vbus layers, top to bottom:
I wouldn't describe it like this
Quoted 14 lines
Guest side:
1. venet guest kernel driver - AFAICT, duplicates the virtio-net guest driver functionality
2. vbus guest driver (config and hotplug) - duplicates pci, or if you need non-pci support, virtio config and its pci bindings; needs reimplementation for all supported guests
3. vbus guest driver (interrupt coalescing, priority) - if needed, should be implemented as an irqchip (and be totally orthogonal to the driver); needs reimplementation for all supported guests
4. vbus guest driver (shm/ioq) - finder grained layering than virtio (which only supports the combination, due to the need for Xen support); can be retrofitted to virtio at some cost
Quoted 11 lines
Host side:
1. venet host kernel driver - is duplicated by vhost-net; doesn't support live migration, unprivileged users, or slirp
2. vbus host driver (config and hotplug) - duplicates pci support in userspace (which will need to be kept in any case); already has two userspace interfaces
3. vbus host driver (interrupt coalescing, priority) - if we think we need it (and I don't), should be part of kvm core, not a bus
4. vbus host driver (shm) - partially duplicated by vhost memory slots
5. vbus host driver (ioq) - duplicates userspace virtio, duplicated by vhost
For one, we have the common layer of shm-signal, and IOQ. These libraries were designed to be reused on both sides of the link. Generally shm-signal has no counterpart in the existing model, though its functionality is integrated into the virtqueue. IOQ is duplicated by virtqueue, but I think its a better design at least in this role, so I use it pervasively throughout the stack. We can discuss that in a separate thread.
From there, going down the stack, it looks like
(guest-side)
|-------------------------
| venet (competes with virtio-net)
|-------------------------
| vbus-proxy (competes with pci-bus, config+hotplug, sync/async)
|-------------------------
| vbus-pcibridge (interrupt coalescing + priority, fastpath)
|-------------------------
|
|-------------------------
| vbus-kvmconnector (interrupt coalescing + priority, fast-path)
|-------------------------
| vbus-core (hotplug, address decoding, etc)
|-------------------------
| venet-device (ioq frame/deframe to tap/macvlan/vmdq, etc)
|-------------------------If you want to use virtio, insert a virtio layer between the "driver" and "device" components at the outer edges of the stack.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
There is no rewriting. vbus has no equivalent today as virtio doesn't define these layers.
By your own admission, you said if you wanted that capability, use a library. What I think you are not understanding is vbus _is_ that library. So what is the problem, exactly?
Quoted 7 lines
Quoted 2 lines
It's not compatible.
No, that is incorrect. What you are apparently not understanding is that not only is vbus that library, but its extensible. So even if compatibility is your goal (it doesn't need to be IMO) it can be accommodated by how you interface to the library.
Quoted 3 lines
To me, compatible means I can live migrate an image to a new system without the user knowing about the change. You'll be able to do that with vhost-net.
As soon as you add any new guest-visible feature, you are in the same exact boat.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
No, it does not. vbus just needs a relatively simple single message pipe between the guest and host (think "hypercall tunnel", if you will).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
That's ioeventfd. So far so similar.
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire
guest->host.You'll probably need to change that as you start running smp guests.
The hypercall channel is already SMP optimized over a single PIO path, so I think we are covered there. See "fastcall" in my code for details:
It just passes the cpuid into the PIO write so we can have parallel, lockless "hypercalls". This forms the basis of our guest scheduler support, for instance.
Quoted 7 lines
Quoted 5 lines
Second, I do not use ioeventfd anymore because it has too many problems with the surrounding technology. However, that is a topic for a different thread.
Please post your issues. I see ioeventfd/irqfd as critical kvm interfaces.
Will do. It would be nice to come back to this interface.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
vbus devices aren't magically instantiated. Userspace needs to instantiate them too. Sure, there's less work on the host side since you're using vbus instead of the native interface, but more work on the guest side since you're using vbus instead of the native interface.
Quoted 7 lines
No, that is incorrect. The amount of "work" that a guest does is actually the same in both cases, since the guest OS peforms the hotswap handling natively for all bus types (at least for Linux and Windows). You still need to have a PV layer to interface with those objects in both cases, as well, so there is no such thing as "native interface" for PV. Its only a matter of where it occurs in the stack.
Quoted 1 line
I'm missing something. Where's the pv layer for virtio-net?
covered above
Quoted 4 lines
Linux drivers have an abstraction layer to deal with non-pci. But the Windows drivers are ordinary pci drivers with nothing that looks pv-ish.
They certainly do not have to be since Windows supports a similar notion as the LDM in Linux. In fact, we are exploiting that Windows facility in our drivers. It's rather unfortunate if its true that your drivers were not designed this way, since virtio has a rather nice stack model on Linux that could work in Windows as well.
Quoted 1 line
You could implement virtio-net hardware if you wanted to.
Technically you could build vbus in hardware too, I suppose, since the bridge is PCI compliant. I would never advocate it, however, since many of our tricks do not matter if its real hardware (e.g. they are optimized for the costs associated with VM).
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
non-privileged-user capable?
The short answer is "not yet (I think)". I need to write a patch to properly set the mode attribute in sysfs, but I think this will be trivial.
(and selinux label)
If any of these things that are problems, they can simply be exposed via the new ioctl admin interface, I suppose.
Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Ah, so you have two control planes.
So what? If anything, it goes to show how extensible the framework is that a new plane could be added in 119 lines of code:
~/git/linux-2.6> stg show vbus-add-admin-ioctls.patch | diffstat
Makefile | 3 - config-ioctl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 3 lines
if and when having two control planes exceeds its utility, I will submit a simple patch that removes the useless one.
It always begins with a 119-line patch and then grows, that's life.
I can't argue with that.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
kvm didn't have an existing counterpart in Linux when it was proposed/merged.
And likewise, neither does vbus.
For virt uses, I don't see the need. For non-virt, I have no opinion.
Well, I hope to change your mind on both counts, then.
Kind Regards,
-Greg
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 16 lines · Gregory Haskins
Quoted 6 lines
Virtualization is about not doing that. Sometimes it's necessary (when you have made unfixable design mistakes), but just to replace a bus, with no advantages to the guest that has to be changed (other hypervisors or hypervisorless deployment scenarios aren't).
The problem is that your continued assertion that there is no advantage to the guest is a completely unsubstantiated claim. As it stands right now, I have a public git tree that, to my knowledge, is the fastest KVM PV networking implementation around. It also has capabilities that are demonstrably not found elsewhere, such as the ability to render generic shared-memory interconnects (scheduling, timers), interrupt-priority (qos), and interrupt-coalescing (exit-ratio reduction). I designed each of these capabilities after carefully analyzing where KVM was coming up short.
Quoted 8 lines
Those are facts.
I can't easily prove which of my new features alone are what makes it special per se, because I don't have unit tests for each part that breaks it down. What I _can_ state is that its the fastest and most feature rich KVM-PV tree that I am aware of, and others may download and test it themselves to verify my claims.
If you wish to introduce a feature which has downsides (and to me, vbus has downsides) then you must prove it is necessary on its own merits. venet is pretty cool but I need proof before I believe its performance is due to vbus and not to venet-host.
Quoted 5 lines
The disproof, on the other hand, would be in a counter example that still meets all the performance and feature criteria under all the same conditions while maintaining the existing ABI. To my knowledge, this doesn't exist.
mst is working on it and we should have it soon.
Quoted 6 lines
Therefore, if you believe my work is irrelevant, show me a git tree that accomplishes the same feats in a binary compatible way, and I'll rethink my position. Until then, complaining about lack of binary compatibility is pointless since it is not an insurmountable proposition, and the one and only available solution declares it a required casualty.
Fine, let's defer it until vhost-net is up and running.
Quoted 10 lines
Quoted 3 lines
Well, Xen requires pre-translation (since the guest has to give the host (which is just another guest) permissions to access the data).
Actually I am not sure that it does require pre-translation. You might be able to use the memctx->copy_to/copy_from scheme in post translation as well, since those would be able to communicate to something like the xen kernel. But I suppose either method would result in extra exits, so there is no distinct benefit using vbus there..as you say below "they're just different".
Quoted 7 lines
The biggest difference is that my proposed model gets around the notion that the entire guest address space can be represented by an arbitrary pointer. For instance, the copy_to/copy_from routines take a GPA, but may use something indirect like a DMA controller to access that GPA. On the other hand, virtio fully expects a viable pointer to come out of the interface iiuc. This is in part what makes vbus more adaptable to non-virt.
No, virtio doesn't expect a pointer (this is what makes Xen possible). vhost does; but nothing prevents an interested party from adapting it.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
Quoted 5 lines
Quoted 3 lines
You can simply use the same vector for both rx and tx and poll both at every interrupt.
Yes, but that has its own problems: e.g. additional exits or at least additional overhead figuring out what happens each time.
If you're just coalescing tx and rx, it's an additional memory read (which you have anyway in the vbus interrupt queue).
Quoted 5 lines
This is even
more important as we scale out to MQ which may have dozens of queue pairs. You really want finer grained signal-path decode if you want peak performance.
MQ definitely wants per-queue or per-queue-pair vectors, and it definitely doesn't want all interrupts to be serviced by a single interrupt queue (you could/should make the queue per-vcpu).
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
Quoted 7 lines
Quoted 4 lines
(irq window exits should only be required on a small percentage of interrupt injections, since the guest will try to disable interrupts for short periods only)
Good point. You are probably right. Certainly the other 2 remain, however.
You can easily eliminate most of the EOI exits by patching ack_APIC_irq() to do the following:
if (atomic_inc_return(&vapic->eoi_count) < 0)
null_hypercall();Where eoi_count is a per-cpu shared counter that indicates how many EOIs were performed by the guest, with the sign bit a signal from the hypervisor that an lower-priority interrupt is pending.
We do something similar for the TPR, which is heavily exercised by Windows XP.
Note that svm provides a mechanism to queue interrupts without requiring the interrupt window; we don't use it in kvm (primarily because only a small fraction of injections would benefit).
Quoted 3 lines
Ultimately, the fastest exit is the one you do not take. That is what I am trying to achieve.
The problem is that all those paravirtualizations bring their own problems and are quickly obsoleted by hardware advances. Intel and AMD also see what you're seeing. Sure, it takes hardware a long time to propagate to the field, but the same holds for software.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Quoted 5 lines
Quoted 3 lines
Requiring all three exits means the guest is spending most of its time with interrupts disabled; that's unlikely.
(see "softirqs" above)
There are no softirqs above, please clarify.
Quoted 9 lines
Quoted 3 lines
Thanks for the numbers. Are those 11% attributable to rx/tx piggybacking from the same interface?
Its hard to tell, since I am not instrumented to discern the difference in this run. I do know from previous traces on the 10GE rig that the chelsio T3 that I am running reaps the pending-tx ring at the same time as a rx polling, so its very likely that both events are often coincident at least there.
I assume you had only two active interrupts? In that case, tx and rx mitigation should have prevented the same interrupt from coalescing with itself, so that leaves rx/tx coalescing as the only option?
Quoted 9 lines
Quoted 5 lines
Also, 170K interupts -> 17K interrupts/sec -> 55kbit/interrupt -> 6.8kB/interrupt. Ignoring interrupt merging and assuming equal rx/tx distribution, that's about 13kB/interrupt. Seems rather low for a saturated link.
I am not following: Do you suspect that I have too few interrupts to represent 940Mb/s, or that I have too little data/interrupt and this ratio should be improved?
Too few bits/interrupt. With tso, your "packets" should be 64KB at least, and you should expect multiple packets per tx interrupt. Maybe these are all acks?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
Quoted 6 lines
Quoted 3 lines
With standard PCI, they do not. But all modern host adapters support MSI and they will happily give you one interrupt per queue.
While MSI is a good technological advancement for PCI, I was referring to signal:IDT ratio. MSI would still classify as 1:1.
I meant, a multiqueue SCSI or network adapter is not N:1 but N:M since each queue would get its own interrupt. So it looks like modern cards try to disaggregate, not aggregate. Previously, non-MSI PCI forced them to aggregate by providing a small amount of irq pins.
Quoted 10 lines
Quoted 3 lines
Let's do that then. Please reserve the corresponding comparisons from your side as well.
That is quite the odd request. My graphs are all built using readily available code and open tools and do not speculate as to what someone else may come up with in the future. They reflect what is available today. Do you honestly think I should wait indefinitely for a competing idea to try to catch up before I talk about my results? That's certainly an interesting perspective.
You results are excellent and I'm not asking you hide them. But you can't compare (more) complete code to incomplete code and state that this proves you are right, or to use results for an entire stack as proof that one component is what made it possible.
Quoted 3 lines
With all due respect, the only red-herring is your unsubstantiated claims that my results do not matter.
My claim is that your results are mostly due to venet-host. I don't have a proof but you don't have a counterproof. That is why I ask you to wait for vhost-net, it will give us more data so we can see what's what.
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
This is not to mention
that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.What are scheduler coordination and non-802.x fabrics?
We are working on real-time, IB and QOS, for examples, in addition to the now well known 802.x venet driver.
Won't QoS require a departure from aggregated interrupts? Suppose an low priority interrupt arrives and the guest starts processing, then a high priority interrupt. Don't you need a real (IDT) interrupt to make the guest process the high-priority event?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Where doesn't it fit?
(avoiding infinite loop)
I'm serious. Where doesn't it fit? Point me at a URL if its already discussed.
Sorry, I lost the context; also my original comment wasn't very constructive, consider it retracted.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
I think Ira said he can make vhost work?
Quoted 8 lines
Not exactly. It kind of works for 802.x only (albeit awkwardly) because there is no strong distinction between "resource" and "consumer" with ethernet. So you can run it inverted without any serious consequences (at least, not from consequences of the inversion). Since the x86 boards are the actual resource providers in his system, other device types will fail to map to the vhost model properly, like disk-io or consoles for instance.
In that case vhost will have to be adapted or they will have to use something else.
Quoted 6 lines
Quoted 3 lines
virtio-net over pci is deployed. Replacing the backend with vhost-net will require no guest modifications.
That _is_ a nice benefit, I agree. I just do not agree its a hard requirement.
Consider a cloud where the hypervisor is updated without the knowledge of the guest admins. Either we break the guests and require the guest admins to login (without networking) to upgrade their drivers during production and then look for a new cloud, or we maintain both device models and ask the guest admins to upgrade their drivers so we can drop support for the old device, a request which they will rightly ignore.
Quoted 5 lines
Quoted 3 lines
Obviously virtio-net isn't deployed in non-virt. But if we adopt vbus, we have to migrate guests.
As a first step, lets just shoot for "support" instead of "adopt".
"support" means eventually "adopt", it isn't viable to maintain two models in parallel.
Quoted 6 lines
Ill continue to push patches to you that help interfacing with the guest in a vbus neutral way (like irqfd/ioeventfd) and we can go from there. Are you open to this work assuming it passes normal review cycles, etc?
It would presumably be of use to others that want to interface to a
guest (e.g. vhost) as well.
Neutral interfaces are great, and I've already received feedback from third parties that they ought to work well for their uses. I don't really like xinterface since I think it's too intrusive locking wise, especially when there's currently churn in kvm memory management. But feel free to post your ideas or patches, maybe we can work something out.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
And once those events are fed, you still need a
PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.
Quoted 8 lines
Quoted 2 lines
virtio-net doesn't use any pv layer.
Well, it does when you really look closely at how it works. For one, it has the virtqueues library that would be (or at least
_shouldbe_) common for all virtio-X adapters, etc etc. Even if this layer is collapsed into each driver on the Windows platform, its still there nonetheless.
By "pv layer" I meant something that is visible along the guest/host interface. virtio devices are completely independent from one another and (using virtio-pci) only talk through interfaces exposed by the relevant card. If you wanted to, you could implement a virtio-pci card in silicon.
Practically the only difference between ordinary NICs and virtio-net is that interrupt status and enable/disable are stored in memory instead of NIC registers, but a real NIC could have done it the virtio way.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
Quoted 4 lines
Quoted 2 lines
virtio-net doesn't modify the PCI model.
Sure it does. It doesn't use MMIO/PIO bars for registers, it uses
vq->kick().
Which translates to a BAR register.
Quoted 2 lines
It doesn't use pci-config-space, it uses
virtio->features.
Which translates to a BAR.
Quoted 9 lines
It doesn't use PCI interrupts, it uses a callback on the vq etc, etc.
You would never use raw "registers", as the exit rate would crush you. You would never use raw interrupts, as you need a shared-memory based mitigation scheme.IOW: Virtio has a device model layer that tunnels over PCI. It doesn't actually use PCI directly. This is in fact what allows the linux version to work over lguest, s390 and vbus in addition to PCI.
That's just a nice way to reuse the driver across multiple busses. Kind of like isa/pci drivers that might even still exist in the source tree. On x86, virtio doesn't bypass PCI, just adds a layer above it.
Quoted 7 lines
Quoted 3 lines
You can have dynamic MSI/queue routing with virtio, and each MSI can be routed to a vcpu at will.
Can you arbitrarily create a new MSI/queue on a per-device basis on the
fly? We want to do this for some upcoming designs. Or do you need to
predeclare the vectors when the device is hot-added?
You need to predeclare the number of vectors, but queue/interrupt assignment is runtime.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
priority, and coalescing, etc.
Do you mean interrupt priority? Well, apic allows interrupt priorities and Windows uses them; Linux doesn't. I don't see a reason to provide more than native hardware.
The APIC model is not optimal for PV given the exits required for a basic operation like an interrupt injection, and has scaling/flexibility issues with its 16:16 priority mapping.
Quoted 8 lines
OTOH, you don't necessarily want to rip it out because of all the additional features it has like the IPI facility and the handling of many low-performance data-paths. Therefore, I am of the opinion that the optimal placement for advanced signal handling is directly at the bus that provides the high-performance resources. I could be convinced otherwise with a compelling argument, but I think this is the path of least resistance.
With EOI PV you can reduce the cost of interrupt injection to slightly more than one exit/interrupt. vbus might reduce it to slightly less than one exit/interrupt.
wrt priority, if you have 12 or fewer realtime interrupt sources you can map them to available priorities. If you have more then you take extra interrupts, but at a ratio of 12:1 (so 24 realtime interrupts mean you may take a single extra exit). The advantages of this is that all interrupts (not just vbus) are prioritized, and bare metal benefits as well.
If 12 is too low for you, pressure Intel to increase the TPR to 8 r/w bits, too bad they missed a chance with x2apic (which btw reduces the apic exit costs significantly).
Quoted 8 lines
Quoted 3 lines
N:1 breaks down on large guests since one vcpu will have to process all events.
Well, first of all that is not necessarily true. Some high performance buses like SCSI and FC work fine with an aggregated model, so its not a foregone conclusion that aggregation kills SMP IO performance. This is especially true when you adding coalescing on top, like AlacrityVM does.
Nevertheless, the high performance adaptors provide multiqueue and MSI; one of the reasons is to distribute processing.
Quoted 11 lines
I do agree that other subsystems, like networking for instance, may sometimes benefit from flexible signal-routing because of multiqueue, etc, for particularly large guests. However, the decision to make the current kvm-connector used in AlacrityVM aggregate one priority FIFO per IRQ was an intentional design tradeoff. My experience with my target user base is that these data-centers are typically deploying 1-4 vcpu guests, so I optimized for that. YMMV, so we can design a different connector, or a different mode of the existing connector, to accommodate large guests as well if that was something desirable.
Quoted 6 lines
Quoted 3 lines
You could do N:M, with commands to change routings, but where's your userspace interface?
Well, we should be able to add that when/if its needed. I just don't think the need is there yet. KVM tops out at 16 IIUC anyway.
My feeling is that 16 will definitely need multiqueue, and perhaps even 4.
(we can probably up the 16, certainly with Marcelo's srcu work).
Quoted 6 lines
Quoted 3 lines
you can't tell from
/proc/interruptswhich
vbus interupts are activeThis should be trivial to add some kind of *fs display. I will fix this shortly.
And update irqbalance and other tools? What about the Windows equivalent? What happens when (say) Linux learns to migrate interrupts to where they're actually used?
This should really be done at the irqchip level, but before that, we need to be 100% certain it's worthwhile.
Quoted 7 lines
Quoted 7 lines
The larger your installed base, the more difficult it is. Of course it's doable, but I prefer not doing it and instead improving things in a binary backwards compatible manner. If there is no choice we will bow to the inevitable and make our users upgrade. But at this point there is a choice, and I prefer to stick with vhost-net until it is proven that it won't work.
Quoted 6 lines
Fair enough. But note you are likely going to need to respin your existing drivers anyway to gain peak performance, since there are known shortcomings in the virtio-pci ABI today (like queue identification in the interrupt hotpath) as it stands. So that pain is coming one way or the other.
We'll update the drivers but we won't require users to update. The majority will not notice an upgrade; those who are interested in getting more performance will update their drivers (at their own schedule).
Quoted 6 lines
Quoted 6 lines
One of the benefits of virtualization is that the guest model is stable. You can live-migrate guests and upgrade the hardware underneath. You can have a single guest image that you clone to provision new guests. If you switch to a new model, you give up those benefits, or you support both models indefinitely.
Quoted 6 lines
I understand what you are saying, but I don't buy it. If you add a new feature to an existing model even without something as drastic as a new bus, you still have the same exact dilemma: The migration target needs feature parity with consumed features in the guest. Its really the same no matter what unless you never add guest-visible features.
When you upgrade your data center, you start upgrading your hypervisors (one by one, with live migration making it transparent) and certainly not exposing new features to running guests. Once you are done you can expose the new features, and guests which can interested in them can upgrade their drivers and see them.
Quoted 7 lines
Quoted 4 lines
Note even hardware nowadays is binary compatible. One e1000 driver supports a ton of different cards, and I think (not sure) newer cards will work with older drivers, just without all their features.
Noted, but that is not really the same thing. Thats more like adding a feature bit to virtio, not replacing GigE with 10GE.
Right, and that's what virtio-net changes look like.
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
No, you have to update the driver in your initrd (for Linux)
Thats fine, the distros generally do this automatically when you load the updated KMP package.
So it's not invisible to the user. You update your hypervisor and now need to tell your users to add the new driver to their initrd and reboot. They're not going to like you.
Quoted 6 lines
Quoted 3 lines
or properly install the new driver (for Windows). It's especially difficult for Windows.
What is difficult here? I never seem to have any problems and I have all kinds of guests from XP to Win7.
If you accidentally reboot before you install the new driver, you won't boot; and there are issues with loading a new driver without the hardware present (not sure what exactly).
Quoted 11 lines
Quoted 3 lines
I don't want to support both virtio and vbus in parallel. There's enough work already.
Until I find some compelling reason that indicates I was wrong about all of this, I will continue building a community around the vbus code base and developing support for its components anyway. So that effort is going to happen in parallel regardless.
This is purely a question about whether you will work with me to make vbus an available option in upstream KVM or not.
Without xinterface there's no need for vbus support in kvm, so nothing's blocking you there. I'm open to extending the host-side kvm interfaces to improve kernel integration. However I still think vbus is the wrong design and shouldn't be merged.
Quoted 8 lines
Quoted 2 lines
If we adopt vbus, we'll have to deprecate and eventually kill off virtio.
Thats more hyperbole. virtio is technically fine and complementary as it is. No one says you have to do anything drastic w.r.t. virtio. If you _did_ adopt vbus, perhaps you would want to optionally deprecate vhost or possibly the virtio-pci adapter, but that is about it. The rest of the infrastructure should be preserved if it was designed properly.
virtio-pci is what makes existing guests work (and vhost-net will certainly need to be killed off). But I really don't see the point of layering virtio on top of vbus.
Quoted 10 lines
Quoted 4 lines
PCI is continuously updated, with MSI, MSI-X, and IOMMU support being some recent updates. I'd like to ride on top of that instead of having to clone it for every guest I support.
While a noble goal, one of the points I keep making though, as someone who has built the stack both ways, is almost none of the PCI stack is actually needed to get the PV job done. The part you do need is primarily a function of the generic OS stack and trivial to interface with anyway.
PCI doesn't stand in the way of pv, and allows us to have a uniform interface to purely emulated, pv, and assigned devices, with minimal changes to the guest. To me that's the path of least resistance.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
As an added bonus, its device-model is modular. A developer can write a
new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking
the guest down, and while eating QEMU based IO solutions for breakfast performance wise.Quoted 7 lines
Quoted 4 lines
Afaict, qemu can't do either of those things.
We've seen that herring before,
Citation?
Quoted 8 lines
Quoted 2 lines
It's the compare venet-in-kernel to virtio-in-userspace thing again.
No, you said KVM has "userspace hotplug". I retorted that vbus not only has hotplug, it also has a modular architecture. You then countered that this feature is a red-herring. If this was previously discussed and rejected for some reason, I would like to know the history. Or did I misunderstand you?
I was talking about your breakfast (the performance comparison again).
Quoted 4 lines
For one, we have the common layer of shm-signal, and IOQ. These libraries were designed to be reused on both sides of the link. Generally shm-signal has no counterpart in the existing model, though its functionality is integrated into the virtqueue.
I agree that ioq/shm separation is a nice feature.
Quoted 19 lines
From there, going down the stack, it looks like
(guest-side)
|------------------------- | venet (competes with virtio-net) |------------------------- | vbus-proxy (competes with pci-bus, config+hotplug, sync/async) |------------------------- | vbus-pcibridge (interrupt coalescing + priority, fastpath) |------------------------- | |------------------------- | vbus-kvmconnector (interrupt coalescing + priority, fast-path) |------------------------- | vbus-core (hotplug, address decoding, etc) |------------------------- | venet-device (ioq frame/deframe to tap/macvlan/vmdq, etc) |-------------------------
Quoted 3 lines
If you want to use virtio, insert a virtio layer between the "driver" and "device" components at the outer edges of the stack.
But then it adds no value. It's just another shim.
Quoted 7 lines
Quoted 4 lines
To me, compatible means I can live migrate an image to a new system without the user knowing about the change. You'll be able to do that with vhost-net.
As soon as you add any new guest-visible feature, you are in the same exact boat.
No. You support two-way migration while hiding new features. You support one-way migration if you expose new features (suitable for data center upgrade). You don't support any migration if you switch models.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire
guest->host.You'll probably need to change that as you start running smp guests.
Quoted 9 lines
The hypercall channel is already SMP optimized over a single PIO path, so I think we are covered there. See "fastcall" in my code for details:
It just passes the cpuid into the PIO write so we can have parallel, lockless "hypercalls". This forms the basis of our guest scheduler support, for instance.
This is... wierd. Scheduler support should be part of kvm core and done using ordinary hypercalls, not as part of a bus model.
Quoted 7 lines
Quoted 2 lines
You could implement virtio-net hardware if you wanted to.
Technically you could build vbus in hardware too, I suppose, since the bridge is PCI compliant. I would never advocate it, however, since many of our tricks do not matter if its real hardware (e.g. they are optimized for the costs associated with VM).
No, you can't. You won't get the cpuid in your pio writes, for one. And if multiple vbus cards are plugged into different PCI slots, they either lost inter-card interrupt coalescing, or you have to connect them in a side-channel.
Signature · 7 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv5 3/3] vhost_net: a kernel-level virtio server
In reply to Gregory HaskinsQuoted 16 lines · Gregory Haskins
Quoted 6 lines
Virtualization is about not doing that. Sometimes it's necessary (when you have made unfixable design mistakes), but just to replace a bus, with no advantages to the guest that has to be changed (other hypervisors or hypervisorless deployment scenarios aren't).
The problem is that your continued assertion that there is no advantage to the guest is a completely unsubstantiated claim. As it stands right now, I have a public git tree that, to my knowledge, is the fastest KVM PV networking implementation around. It also has capabilities that are demonstrably not found elsewhere, such as the ability to render generic shared-memory interconnects (scheduling, timers), interrupt-priority (qos), and interrupt-coalescing (exit-ratio reduction). I designed each of these capabilities after carefully analyzing where KVM was coming up short.
Quoted 8 lines
Those are facts.
I can't easily prove which of my new features alone are what makes it special per se, because I don't have unit tests for each part that breaks it down. What I _can_ state is that its the fastest and most feature rich KVM-PV tree that I am aware of, and others may download and test it themselves to verify my claims.
If you wish to introduce a feature which has downsides (and to me, vbus has downsides) then you must prove it is necessary on its own merits. venet is pretty cool but I need proof before I believe its performance is due to vbus and not to venet-host.
Quoted 5 lines
The disproof, on the other hand, would be in a counter example that still meets all the performance and feature criteria under all the same conditions while maintaining the existing ABI. To my knowledge, this doesn't exist.
mst is working on it and we should have it soon.
Quoted 6 lines
Therefore, if you believe my work is irrelevant, show me a git tree that accomplishes the same feats in a binary compatible way, and I'll rethink my position. Until then, complaining about lack of binary compatibility is pointless since it is not an insurmountable proposition, and the one and only available solution declares it a required casualty.
Fine, let's defer it until vhost-net is up and running.
Quoted 10 lines
Quoted 3 lines
Well, Xen requires pre-translation (since the guest has to give the host (which is just another guest) permissions to access the data).
Actually I am not sure that it does require pre-translation. You might be able to use the memctx->copy_to/copy_from scheme in post translation as well, since those would be able to communicate to something like the xen kernel. But I suppose either method would result in extra exits, so there is no distinct benefit using vbus there..as you say below "they're just different".
Quoted 7 lines
The biggest difference is that my proposed model gets around the notion that the entire guest address space can be represented by an arbitrary pointer. For instance, the copy_to/copy_from routines take a GPA, but may use something indirect like a DMA controller to access that GPA. On the other hand, virtio fully expects a viable pointer to come out of the interface iiuc. This is in part what makes vbus more adaptable to non-virt.
No, virtio doesn't expect a pointer (this is what makes Xen possible). vhost does; but nothing prevents an interested party from adapting it.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
An interesting thing here is that you don't even need a fancy multi-homed setup to see the effects of my exit-ratio reduction work:
even single port configurations suffer from the phenomenon since many devices have multiple signal-flows (e.g. network adapters tend to have at least 3 flows: rx-ready, tx-complete, and control-events (link-state, etc). Whats worse, is that the flows often are indirectly related (for instance, many host adapters will free tx skbs during rx operations, so you tend to get bursts of tx-completes at the same time as rx-ready. If the flows map 1:1 with IDT, they will suffer the same problem.
Quoted 5 lines
Quoted 3 lines
You can simply use the same vector for both rx and tx and poll both at every interrupt.
Yes, but that has its own problems: e.g. additional exits or at least additional overhead figuring out what happens each time.
If you're just coalescing tx and rx, it's an additional memory read (which you have anyway in the vbus interrupt queue).
Quoted 5 lines
This is even
more important as we scale out to MQ which may have dozens of queue pairs. You really want finer grained signal-path decode if you want peak performance.
MQ definitely wants per-queue or per-queue-pair vectors, and it definitely doesn't want all interrupts to be serviced by a single interrupt queue (you could/should make the queue per-vcpu).
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Its important to note here that we are actually looking at the interrupt rate, not the exit rate (which is usually a multiple of the interrupt rate, since you have to factor in as many as three exits per interrupt (IPI, window, EOI). Therefore we saved about 18k interrupts in this 10 second burst, but we may have actually saved up to 54k exits in the process. This is only over a 10 second window at GigE rates, so YMMV. These numbers get even more dramatic on higher end hardware, but I haven't had a chance to generate new numbers yet.
Quoted 7 lines
Quoted 4 lines
(irq window exits should only be required on a small percentage of interrupt injections, since the guest will try to disable interrupts for short periods only)
Good point. You are probably right. Certainly the other 2 remain, however.
You can easily eliminate most of the EOI exits by patching ack_APIC_irq() to do the following:
if (atomic_inc_return(&vapic->eoi_count) < 0)
null_hypercall();Where eoi_count is a per-cpu shared counter that indicates how many EOIs were performed by the guest, with the sign bit a signal from the hypervisor that an lower-priority interrupt is pending.
We do something similar for the TPR, which is heavily exercised by Windows XP.
Note that svm provides a mechanism to queue interrupts without requiring the interrupt window; we don't use it in kvm (primarily because only a small fraction of injections would benefit).
Quoted 3 lines
Ultimately, the fastest exit is the one you do not take. That is what I am trying to achieve.
The problem is that all those paravirtualizations bring their own problems and are quickly obsoleted by hardware advances. Intel and AMD also see what you're seeing. Sure, it takes hardware a long time to propagate to the field, but the same holds for software.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The even worse news for 1:1 models is that the ratio of exits-per-interrupt climbs with load (exactly when it hurts the most) since that is when the probability that the vcpu will need all three exits is the highest.
Quoted 5 lines
Quoted 3 lines
Requiring all three exits means the guest is spending most of its time with interrupts disabled; that's unlikely.
(see "softirqs" above)
There are no softirqs above, please clarify.
Quoted 9 lines
Quoted 3 lines
Thanks for the numbers. Are those 11% attributable to rx/tx piggybacking from the same interface?
Its hard to tell, since I am not instrumented to discern the difference in this run. I do know from previous traces on the 10GE rig that the chelsio T3 that I am running reaps the pending-tx ring at the same time as a rx polling, so its very likely that both events are often coincident at least there.
I assume you had only two active interrupts? In that case, tx and rx mitigation should have prevented the same interrupt from coalescing with itself, so that leaves rx/tx coalescing as the only option?
Quoted 9 lines
Quoted 5 lines
Also, 170K interupts -> 17K interrupts/sec -> 55kbit/interrupt -> 6.8kB/interrupt. Ignoring interrupt merging and assuming equal rx/tx distribution, that's about 13kB/interrupt. Seems rather low for a saturated link.
I am not following: Do you suspect that I have too few interrupts to represent 940Mb/s, or that I have too little data/interrupt and this ratio should be improved?
Too few bits/interrupt. With tso, your "packets" should be 64KB at least, and you should expect multiple packets per tx interrupt. Maybe these are all acks?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Everyone is of course entitled to an opinion, but the industry as a whole would disagree with you. Signal path routing (1:1, aggregated, etc) is at the discretion of the bus designer. Most buses actually do _not_ support 1:1 with IDT (think USB, SCSI, IDE, etc).
Quoted 6 lines
Quoted 3 lines
With standard PCI, they do not. But all modern host adapters support MSI and they will happily give you one interrupt per queue.
While MSI is a good technological advancement for PCI, I was referring to signal:IDT ratio. MSI would still classify as 1:1.
I meant, a multiqueue SCSI or network adapter is not N:1 but N:M since each queue would get its own interrupt. So it looks like modern cards try to disaggregate, not aggregate. Previously, non-MSI PCI forced them to aggregate by providing a small amount of irq pins.
Quoted 10 lines
Quoted 3 lines
Let's do that then. Please reserve the corresponding comparisons from your side as well.
That is quite the odd request. My graphs are all built using readily available code and open tools and do not speculate as to what someone else may come up with in the future. They reflect what is available today. Do you honestly think I should wait indefinitely for a competing idea to try to catch up before I talk about my results? That's certainly an interesting perspective.
You results are excellent and I'm not asking you hide them. But you can't compare (more) complete code to incomplete code and state that this proves you are right, or to use results for an entire stack as proof that one component is what made it possible.
Quoted 3 lines
With all due respect, the only red-herring is your unsubstantiated claims that my results do not matter.
My claim is that your results are mostly due to venet-host. I don't have a proof but you don't have a counterproof. That is why I ask you to wait for vhost-net, it will give us more data so we can see what's what.
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
This is not to mention
that vhost-net does nothing to address our other goals, like scheduler coordination and non-802.x fabrics.What are scheduler coordination and non-802.x fabrics?
We are working on real-time, IB and QOS, for examples, in addition to the now well known 802.x venet driver.
Won't QoS require a departure from aggregated interrupts? Suppose an low priority interrupt arrives and the guest starts processing, then a high priority interrupt. Don't you need a real (IDT) interrupt to make the guest process the high-priority event?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Right, when you ignore the points where they don't fit, it's a perfect mesh.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Where doesn't it fit?
(avoiding infinite loop)
I'm serious. Where doesn't it fit? Point me at a URL if its already discussed.
Sorry, I lost the context; also my original comment wasn't very constructive, consider it retracted.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Citation please. Afaict, the one use case that we looked at for vhost outside of KVM failed to adapt properly, so I do not see how this is true.
I think Ira said he can make vhost work?
Quoted 8 lines
Not exactly. It kind of works for 802.x only (albeit awkwardly) because there is no strong distinction between "resource" and "consumer" with ethernet. So you can run it inverted without any serious consequences (at least, not from consequences of the inversion). Since the x86 boards are the actual resource providers in his system, other device types will fail to map to the vhost model properly, like disk-io or consoles for instance.
In that case vhost will have to be adapted or they will have to use something else.
Quoted 6 lines
Quoted 3 lines
virtio-net over pci is deployed. Replacing the backend with vhost-net will require no guest modifications.
That _is_ a nice benefit, I agree. I just do not agree its a hard requirement.
Consider a cloud where the hypervisor is updated without the knowledge of the guest admins. Either we break the guests and require the guest admins to login (without networking) to upgrade their drivers during production and then look for a new cloud, or we maintain both device models and ask the guest admins to upgrade their drivers so we can drop support for the old device, a request which they will rightly ignore.
Quoted 5 lines
Quoted 3 lines
Obviously virtio-net isn't deployed in non-virt. But if we adopt vbus, we have to migrate guests.
As a first step, lets just shoot for "support" instead of "adopt".
"support" means eventually "adopt", it isn't viable to maintain two models in parallel.
Quoted 6 lines
Ill continue to push patches to you that help interfacing with the guest in a vbus neutral way (like irqfd/ioeventfd) and we can go from there. Are you open to this work assuming it passes normal review cycles, etc?
It would presumably be of use to others that want to interface to a
guest (e.g. vhost) as well.
Neutral interfaces are great, and I've already received feedback from third parties that they ought to work well for their uses. I don't really like xinterface since I think it's too intrusive locking wise, especially when there's currently churn in kvm memory management. But feel free to post your ideas or patches, maybe we can work something out.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
And once those events are fed, you still need a
PV layer to actually handle the bus interface in a high-performance manner so its not like you really have a "native" stack in either case.
Quoted 8 lines
Quoted 2 lines
virtio-net doesn't use any pv layer.
Well, it does when you really look closely at how it works. For one, it has the virtqueues library that would be (or at least
_shouldbe_) common for all virtio-X adapters, etc etc. Even if this layer is collapsed into each driver on the Windows platform, its still there nonetheless.
By "pv layer" I meant something that is visible along the guest/host interface. virtio devices are completely independent from one another and (using virtio-pci) only talk through interfaces exposed by the relevant card. If you wanted to, you could implement a virtio-pci card in silicon.
Practically the only difference between ordinary NICs and virtio-net is that interrupt status and enable/disable are stored in memory instead of NIC registers, but a real NIC could have done it the virtio way.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
that doesn't need to be retrofitted.
No, that is incorrect. You have to heavily modify the pci model with layers on top to get any kind of performance out of it. Otherwise, we would just use realtek emulation, which is technically the native PCI you are apparently so enamored with.
Quoted 4 lines
Quoted 2 lines
virtio-net doesn't modify the PCI model.
Sure it does. It doesn't use MMIO/PIO bars for registers, it uses
vq->kick().
Which translates to a BAR register.
Quoted 2 lines
It doesn't use pci-config-space, it uses
virtio->features.
Which translates to a BAR.
Quoted 9 lines
It doesn't use PCI interrupts, it uses a callback on the vq etc, etc.
You would never use raw "registers", as the exit rate would crush you. You would never use raw interrupts, as you need a shared-memory based mitigation scheme.IOW: Virtio has a device model layer that tunnels over PCI. It doesn't actually use PCI directly. This is in fact what allows the linux version to work over lguest, s390 and vbus in addition to PCI.
That's just a nice way to reuse the driver across multiple busses. Kind of like isa/pci drivers that might even still exist in the source tree. On x86, virtio doesn't bypass PCI, just adds a layer above it.
Quoted 7 lines
Quoted 3 lines
You can have dynamic MSI/queue routing with virtio, and each MSI can be routed to a vcpu at will.
Can you arbitrarily create a new MSI/queue on a per-device basis on the
fly? We want to do this for some upcoming designs. Or do you need to
predeclare the vectors when the device is hot-added?
You need to predeclare the number of vectors, but queue/interrupt assignment is runtime.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
priority, and coalescing, etc.
Do you mean interrupt priority? Well, apic allows interrupt priorities and Windows uses them; Linux doesn't. I don't see a reason to provide more than native hardware.
The APIC model is not optimal for PV given the exits required for a basic operation like an interrupt injection, and has scaling/flexibility issues with its 16:16 priority mapping.
Quoted 8 lines
OTOH, you don't necessarily want to rip it out because of all the additional features it has like the IPI facility and the handling of many low-performance data-paths. Therefore, I am of the opinion that the optimal placement for advanced signal handling is directly at the bus that provides the high-performance resources. I could be convinced otherwise with a compelling argument, but I think this is the path of least resistance.
With EOI PV you can reduce the cost of interrupt injection to slightly more than one exit/interrupt. vbus might reduce it to slightly less than one exit/interrupt.
wrt priority, if you have 12 or fewer realtime interrupt sources you can map them to available priorities. If you have more then you take extra interrupts, but at a ratio of 12:1 (so 24 realtime interrupts mean you may take a single extra exit). The advantages of this is that all interrupts (not just vbus) are prioritized, and bare metal benefits as well.
If 12 is too low for you, pressure Intel to increase the TPR to 8 r/w bits, too bad they missed a chance with x2apic (which btw reduces the apic exit costs significantly).
Quoted 8 lines
Quoted 3 lines
N:1 breaks down on large guests since one vcpu will have to process all events.
Well, first of all that is not necessarily true. Some high performance buses like SCSI and FC work fine with an aggregated model, so its not a foregone conclusion that aggregation kills SMP IO performance. This is especially true when you adding coalescing on top, like AlacrityVM does.
Nevertheless, the high performance adaptors provide multiqueue and MSI; one of the reasons is to distribute processing.
Quoted 11 lines
I do agree that other subsystems, like networking for instance, may sometimes benefit from flexible signal-routing because of multiqueue, etc, for particularly large guests. However, the decision to make the current kvm-connector used in AlacrityVM aggregate one priority FIFO per IRQ was an intentional design tradeoff. My experience with my target user base is that these data-centers are typically deploying 1-4 vcpu guests, so I optimized for that. YMMV, so we can design a different connector, or a different mode of the existing connector, to accommodate large guests as well if that was something desirable.
Quoted 6 lines
Quoted 3 lines
You could do N:M, with commands to change routings, but where's your userspace interface?
Well, we should be able to add that when/if its needed. I just don't think the need is there yet. KVM tops out at 16 IIUC anyway.
My feeling is that 16 will definitely need multiqueue, and perhaps even 4.
(we can probably up the 16, certainly with Marcelo's srcu work).
Quoted 6 lines
Quoted 3 lines
you can't tell from
/proc/interruptswhich
vbus interupts are activeThis should be trivial to add some kind of *fs display. I will fix this shortly.
And update irqbalance and other tools? What about the Windows equivalent? What happens when (say) Linux learns to migrate interrupts to where they're actually used?
This should really be done at the irqchip level, but before that, we need to be 100% certain it's worthwhile.
Quoted 7 lines
Quoted 7 lines
The larger your installed base, the more difficult it is. Of course it's doable, but I prefer not doing it and instead improving things in a binary backwards compatible manner. If there is no choice we will bow to the inevitable and make our users upgrade. But at this point there is a choice, and I prefer to stick with vhost-net until it is proven that it won't work.
Quoted 6 lines
Fair enough. But note you are likely going to need to respin your existing drivers anyway to gain peak performance, since there are known shortcomings in the virtio-pci ABI today (like queue identification in the interrupt hotpath) as it stands. So that pain is coming one way or the other.
We'll update the drivers but we won't require users to update. The majority will not notice an upgrade; those who are interested in getting more performance will update their drivers (at their own schedule).
Quoted 6 lines
Quoted 6 lines
One of the benefits of virtualization is that the guest model is stable. You can live-migrate guests and upgrade the hardware underneath. You can have a single guest image that you clone to provision new guests. If you switch to a new model, you give up those benefits, or you support both models indefinitely.
Quoted 6 lines
I understand what you are saying, but I don't buy it. If you add a new feature to an existing model even without something as drastic as a new bus, you still have the same exact dilemma: The migration target needs feature parity with consumed features in the guest. Its really the same no matter what unless you never add guest-visible features.
When you upgrade your data center, you start upgrading your hypervisors (one by one, with live migration making it transparent) and certainly not exposing new features to running guests. Once you are done you can expose the new features, and guests which can interested in them can upgrade their drivers and see them.
Quoted 7 lines
Quoted 4 lines
Note even hardware nowadays is binary compatible. One e1000 driver supports a ton of different cards, and I think (not sure) newer cards will work with older drivers, just without all their features.
Noted, but that is not really the same thing. Thats more like adding a feature bit to virtio, not replacing GigE with 10GE.
Right, and that's what virtio-net changes look like.
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
If and when that becomes a priority concern, that would be a function transparently supported in the BIOS shipped with the hypervisor, and would thus be invisible to the user.
No, you have to update the driver in your initrd (for Linux)
Thats fine, the distros generally do this automatically when you load the updated KMP package.
So it's not invisible to the user. You update your hypervisor and now need to tell your users to add the new driver to their initrd and reboot. They're not going to like you.
Quoted 6 lines
Quoted 3 lines
or properly install the new driver (for Windows). It's especially difficult for Windows.
What is difficult here? I never seem to have any problems and I have all kinds of guests from XP to Win7.
If you accidentally reboot before you install the new driver, you won't boot; and there are issues with loading a new driver without the hardware present (not sure what exactly).
Quoted 11 lines
Quoted 3 lines
I don't want to support both virtio and vbus in parallel. There's enough work already.
Until I find some compelling reason that indicates I was wrong about all of this, I will continue building a community around the vbus code base and developing support for its components anyway. So that effort is going to happen in parallel regardless.
This is purely a question about whether you will work with me to make vbus an available option in upstream KVM or not.
Without xinterface there's no need for vbus support in kvm, so nothing's blocking you there. I'm open to extending the host-side kvm interfaces to improve kernel integration. However I still think vbus is the wrong design and shouldn't be merged.
Quoted 8 lines
Quoted 2 lines
If we adopt vbus, we'll have to deprecate and eventually kill off virtio.
Thats more hyperbole. virtio is technically fine and complementary as it is. No one says you have to do anything drastic w.r.t. virtio. If you _did_ adopt vbus, perhaps you would want to optionally deprecate vhost or possibly the virtio-pci adapter, but that is about it. The rest of the infrastructure should be preserved if it was designed properly.
virtio-pci is what makes existing guests work (and vhost-net will certainly need to be killed off). But I really don't see the point of layering virtio on top of vbus.
Quoted 10 lines
Quoted 4 lines
PCI is continuously updated, with MSI, MSI-X, and IOMMU support being some recent updates. I'd like to ride on top of that instead of having to clone it for every guest I support.
While a noble goal, one of the points I keep making though, as someone who has built the stack both ways, is almost none of the PCI stack is actually needed to get the PV job done. The part you do need is primarily a function of the generic OS stack and trivial to interface with anyway.
PCI doesn't stand in the way of pv, and allows us to have a uniform interface to purely emulated, pv, and assigned devices, with minimal changes to the guest. To me that's the path of least resistance.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
As an added bonus, its device-model is modular. A developer can write a
new device model, compile it, insmod it to the host kernel, hotplug it to the running guest with mkdir/ln, and the come back out again (hotunplug with rmdir, rmmod, etc). They may do this all without taking
the guest down, and while eating QEMU based IO solutions for breakfast performance wise.Quoted 7 lines
Quoted 4 lines
Afaict, qemu can't do either of those things.
We've seen that herring before,
Citation?
Quoted 8 lines
Quoted 2 lines
It's the compare venet-in-kernel to virtio-in-userspace thing again.
No, you said KVM has "userspace hotplug". I retorted that vbus not only has hotplug, it also has a modular architecture. You then countered that this feature is a red-herring. If this was previously discussed and rejected for some reason, I would like to know the history. Or did I misunderstand you?
I was talking about your breakfast (the performance comparison again).
Quoted 4 lines
For one, we have the common layer of shm-signal, and IOQ. These libraries were designed to be reused on both sides of the link. Generally shm-signal has no counterpart in the existing model, though its functionality is integrated into the virtqueue.
I agree that ioq/shm separation is a nice feature.
Quoted 19 lines
From there, going down the stack, it looks like
(guest-side)
|------------------------- | venet (competes with virtio-net) |------------------------- | vbus-proxy (competes with pci-bus, config+hotplug, sync/async) |------------------------- | vbus-pcibridge (interrupt coalescing + priority, fastpath) |------------------------- | |------------------------- | vbus-kvmconnector (interrupt coalescing + priority, fast-path) |------------------------- | vbus-core (hotplug, address decoding, etc) |------------------------- | venet-device (ioq frame/deframe to tap/macvlan/vmdq, etc) |-------------------------
Quoted 3 lines
If you want to use virtio, insert a virtio layer between the "driver" and "device" components at the outer edges of the stack.
But then it adds no value. It's just another shim.
Quoted 7 lines
Quoted 4 lines
To me, compatible means I can live migrate an image to a new system without the user knowing about the change. You'll be able to do that with vhost-net.
As soon as you add any new guest-visible feature, you are in the same exact boat.
No. You support two-way migration while hiding new features. You support one-way migration if you expose new features (suitable for data center upgrade). You don't support any migration if you switch models.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
No, that is incorrect. For one, vhost uses them on a per-signal path basis, whereas vbus only has one channel for the entire
guest->host.You'll probably need to change that as you start running smp guests.
Quoted 9 lines
The hypercall channel is already SMP optimized over a single PIO path, so I think we are covered there. See "fastcall" in my code for details:
It just passes the cpuid into the PIO write so we can have parallel, lockless "hypercalls". This forms the basis of our guest scheduler support, for instance.
This is... wierd. Scheduler support should be part of kvm core and done using ordinary hypercalls, not as part of a bus model.
Quoted 7 lines
Quoted 2 lines
You could implement virtio-net hardware if you wanted to.
Technically you could build vbus in hardware too, I suppose, since the bridge is PCI compliant. I would never advocate it, however, since many of our tricks do not matter if its real hardware (e.g. they are optimized for the costs associated with VM).
No, you can't. You won't get the cpuid in your pio writes, for one. And if multiple vbus cards are plugged into different PCI slots, they either lost inter-card interrupt coalescing, or you have to connect them in a side-channel.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.