Clean up virtio device object handling [was Re: [PATCH] virtio: make PCI devices take a virtio_pci module ref]
Get series with b4
b4 am 1228931096.5384.63.camel@blaaVersions newest first
- v1 Latest6 patches 9 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | virtio: add PCI device release() functiondrivers/ | +15 | 0 replies | |
| 2/6 | virtio: add register_virtio_root_device()drivers/ include/ | +81 | 35 replies | |
| 3/6 | virtio: do not statically allocate root devicedrivers/ | +7 | 0 replies | |
| 4/6 | lguest: do not statically allocate root devicedrivers/ | +4 | 0 replies | |
| 5/6 | kvm-s390: use register_virtio_root_device()drivers/ | +2 | 3 replies | |
| 6/6 | lguest: struct device - replace bus_id with dev_name()drivers/ | +1 | 0 replies |
Reviews trailers per patch
1 of 6 patches has a Reviewed-by or Acked-by.
| Patch | Cornelia Huck | Rusty Russell |
|---|---|---|
| 1/6 | ||
| 2/6 | A-b A-b A-b A-b | A-b A-b |
| 3/6 | ||
| 4/6 | ||
| 5/6 | ||
| 6/6 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/6] Clean up virtio device object handling [was Re: [PATCH] virtio: make PCI devices take a virtio_pci module ref]
(Moved from kvm@vger to virtualization@linux-foundation, changed subject, cleaned up cc list)
Quoted 96 lines · Kay Sievers
Quoted 86 lines · Mark McLoughlin
Quoted 77 lines · Kay Sievers
Quoted 76 lines · Mark McLoughlin
Quoted 47 lines · Anthony Liguori
Quoted 46 lines · Mark McLoughlin
Quoted 13 lines · Rusty Russell
Quoted 11 lines · On Saturday 06 December 2008 01:37:06 Mark McLoughlin wrote:
Another example of a lack of an explicit dependency causing problems is Fedora's mkinitrd having this hack:
if echo $PWD | grep -q /virtio-pci/ ; then
findmodulevirtio_pci
fiwhich basically says "if this is a virtio device, don't forget to include
virtio_pciin the initrd too!". Now, mkinitrd is full of hacks, but this is a particularly unusual one.Quoted 6 lines
Um, I don't know what this does, sorry.
I have no idea how Fedora chooses what to put in an initrd; I can't think of a sensible way of deciding what goes in and what doesn't other than lists and heuristics.
Fedora's mkinitrd creates an initrd suitable to boot the machine you run mkinitrd on, rather than creating an initrd suitable to boot any machine.
So, it goes "ah, / is mounted from
/dev/vda, we need to includevirtio_blkand it's dependencies". It does that in a generic way that works well for most setups:1) Find the device name (e.g. vda) below
/sys/block2) Follow the 'device' link to e.g.
/sys/devices/virtio-pci/virtio13) Find the module need for this through either 'modalias' or the 'driver/module' symlink
4) Use modprobe to list any dependencies of that module
Clearly, virtio-pci won't be pulled in by any of this so we've added a hack to say "oh, it's a virtio device, let's include
virtio_pcijust in case".It's not even the case that mkinitrd needs to know how to include the the module for the bus, because in our case that's virtio.ko ... we've pretty effectively hidden the the bus *implementation* from userspace.
Quoted 6 lines
Quoted 4 lines
I don't think this is worth wasting too much time fixing, that's why I'm thinking we should just make
virtio_pcibuilt-in by default withCONFIG_KVM_GUEST.What if we have multiple virtio transports?
I don't think that's so much an an issue (just build in any transport supported by KVM), but rather that you might build a non-pv_ops kernel to run on QEMU which would benefit from using virtio drivers ...
Quoted 4 lines
Is there a way that we can
expose the relationship with virtio-blk and virtio-pci in sysfs? We have a struct device for the PCI device, it's just a matter of making the link visible.It feels a bit like busy work to generalise this since only
virtio_pcican be built as a module, but here's a patch.The mkinitrd hack turns into:
# Handle finding virtio bus implementations if [ -L ./virtio_module ] ; then
findmodule $(basename $(readlink ./virtio_module))
else if echo $PWD | grep -q /virtio-pci/ ; then
findmodulevirtio_pci
fi; fiQuoted 4 lines
Quoted 1 line
[PATCH] virtio: add a '
virtio_module' sysfs symlinkDoesn't the device have a "driver" link already? If yes, the driver it points to should have a "module" link.
The virtio bus is an abstraction that has several different backend implementations - currently virtio-pci, lguest and kvm-s390.
Quoted 8 lines
So yes, the driver/module link gives us the device driver, but the
virtio_modulelink is to the virtio bus driver (aka implementation, transport, backend, ...):$> basename $(readlink
virtio_module)
virtio_pci
$> basename $(readlink driver/module)
virtio_net
Quoted 8 lines
I see. But why not just call it "module", like we do in all other places, when it points to
/sys/module/.To find dependent modules, you would walk up the chain of parents, and include everything that is found by looking for "driver/module" and "module" links?
Wouldn't that make it completely generic, without any virtio specific hacks?
Yeah, that sounds much better - a minor detail is that it'd be better to hang the symlink off each virtio implementation's root object rather than off each device.
To that end, I've hacked up register_virtio_root_device() which fixes the fact that we statically allocate root objects and gives us a sane place to add this generic symlink.
It might make sense to add this to the core, though - e.g. device_register_root() - and that would also allow us use the same approach as module_add_driver() to add the module symlink for built-in modules.
Cheers,
Mark.