mbox series

[kvmtool,00/24] Virtio v1 support

Message ID 20220607170239.120084-1-jean-philippe.brucker@arm.com (mailing list archive)
Headers show
Series Virtio v1 support | expand

Message

Jean-Philippe Brucker June 7, 2022, 5:02 p.m. UTC
Add support for version 1 of the virtio transport to kvmtool. Based on a
RFC by Sasha Levin [1], I've been trying to complete it here and there.
It's long overdue and is quite painful to rebase, so let's get it
merged.

Several reasons why the legacy transport needs to be replaced:

* Only 32 feature bits are supported. Most importantly
  VIRTIO_F_ACCESS_PLATFORM, which forces a Linux guest to use the DMA
  API, cannot be enabled. So we can't support private guests that
  decrypt or share only their DMA memory with the host.

* Legacy virtqueue address is a 32-bit pfn, aligned on 4kB. Since Linux
  guests bypass the DMA API they can't support large GPAs.

* New devices types (iommu, crypto, memory, etc) and new features cannot
  be supported.

* New guests won't implement the legacy transport. Existing guests will
  eventually drop legacy support.

Support for modern transport becomes the default and legacy is enabled
with --virtio-legacy.

I only tested what I could: vsock, scsi and vhost-net are currently
broken and can be fixed later (they have issues with mem regions and
feature mask, among other things). I also haven't tested big-endian.

Find the series at https://jpbrucker.net/git/kvmtool/ virtio/devel

[1] https://lore.kernel.org/all/1447823472-17047-1-git-send-email-sasha.levin@oracle.com/
    The SOB was kept in patch 21

Jean-Philippe Brucker (24):
  virtio: Add NEEDS_RESET to the status mask
  virtio: Remove redundant test
  virtio/vsock: Remove redundant state tracking
  virtio: Factor virtqueue initialization
  virtio: Support modern virtqueue addresses
  virtio: Add config access helpers
  virtio: Fix device-specific config endianness
  virtio/console: Remove unused callback
  virtio: Remove set_guest_features() device op
  Add memcpy_fromiovec_safe
  virtio/net: Offload vnet header endianness conversion to tap
  virtio/net: Prepare for modern virtio
  virtio/net: Implement VIRTIO_F_ANY_LAYOUT feature
  virtio/console: Add VIRTIO_F_ANY_LAYOUT feature
  virtio/blk: Implement VIRTIO_F_ANY_LAYOUT feature
  virtio/pci: Factor MSI route creation
  virtio/pci: Delete MSI routes
  virtio: Extract init_vq() for PCI and MMIO
  virtio/pci: Make doorbell offset dynamic
  virtio: Move PCI transport to pci-legacy
  virtio: Add support for modern virtio-pci
  virtio: Move MMIO transport to mmio-legacy
  virtio: Add support for modern virtio-mmio
  virtio/pci: Initialize all vectors to VIRTIO_MSI_NO_VECTOR

 Makefile                          |   4 +
 arm/include/arm-common/kvm-arch.h |   6 +-
 include/kvm/disk-image.h          |   3 +-
 include/kvm/iovec.h               |   2 +
 include/kvm/kvm-config.h          |   1 +
 include/kvm/kvm.h                 |   6 +
 include/kvm/pci.h                 |  11 +
 include/kvm/virtio-9p.h           |   2 +-
 include/kvm/virtio-mmio.h         |  29 ++-
 include/kvm/virtio-pci-dev.h      |   4 +
 include/kvm/virtio-pci.h          |  48 +++-
 include/kvm/virtio.h              |  52 ++--
 mips/include/kvm/kvm-arch.h       |   2 -
 powerpc/include/kvm/kvm-arch.h    |   2 -
 x86/include/kvm/kvm-arch.h        |   2 -
 builtin-run.c                     |   2 +
 disk/core.c                       |  26 +-
 net/uip/core.c                    |  71 ++++--
 util/iovec.c                      |  31 +++
 virtio/9p.c                       |  27 +--
 virtio/balloon.c                  |  46 ++--
 virtio/blk.c                      | 102 ++++----
 virtio/console.c                  |  33 +--
 virtio/core.c                     |  82 ++++++-
 virtio/mmio-legacy.c              | 150 ++++++++++++
 virtio/mmio-modern.c              | 157 ++++++++++++
 virtio/mmio.c                     | 202 ++--------------
 virtio/net.c                      | 122 +++++-----
 virtio/pci-legacy.c               | 205 ++++++++++++++++
 virtio/pci-modern.c               | 386 ++++++++++++++++++++++++++++++
 virtio/pci.c                      | 361 ++++++----------------------
 virtio/rng.c                      |  15 +-
 virtio/scsi.c                     |  44 ++--
 virtio/vsock.c                    |  39 ++-
 34 files changed, 1490 insertions(+), 785 deletions(-)
 create mode 100644 virtio/mmio-legacy.c
 create mode 100644 virtio/mmio-modern.c
 create mode 100644 virtio/pci-legacy.c
 create mode 100644 virtio/pci-modern.c

Comments

Will Deacon June 9, 2022, 12:39 p.m. UTC | #1
On Tue, Jun 07, 2022 at 06:02:15PM +0100, Jean-Philippe Brucker wrote:
> Add support for version 1 of the virtio transport to kvmtool. Based on a
> RFC by Sasha Levin [1], I've been trying to complete it here and there.
> It's long overdue and is quite painful to rebase, so let's get it
> merged.
> 
> Several reasons why the legacy transport needs to be replaced:
> 
> * Only 32 feature bits are supported. Most importantly
>   VIRTIO_F_ACCESS_PLATFORM, which forces a Linux guest to use the DMA
>   API, cannot be enabled. So we can't support private guests that
>   decrypt or share only their DMA memory with the host.

Woohoo!

> * Legacy virtqueue address is a 32-bit pfn, aligned on 4kB. Since Linux
>   guests bypass the DMA API they can't support large GPAs.
> 
> * New devices types (iommu, crypto, memory, etc) and new features cannot
>   be supported.
> 
> * New guests won't implement the legacy transport. Existing guests will
>   eventually drop legacy support.
> 
> Support for modern transport becomes the default and legacy is enabled
> with --virtio-legacy.
> 
> I only tested what I could: vsock, scsi and vhost-net are currently
> broken and can be fixed later (they have issues with mem regions and
> feature mask, among other things). I also haven't tested big-endian.

If these are broken, then shall we default to legacy mode and have the
modern transport be opt-in? Otherwise we're regressing people in a
confusing way.

Will
Will Deacon June 9, 2022, 12:50 p.m. UTC | #2
On Tue, 7 Jun 2022 18:02:15 +0100, Jean-Philippe Brucker wrote:
> Add support for version 1 of the virtio transport to kvmtool. Based on a
> RFC by Sasha Levin [1], I've been trying to complete it here and there.
> It's long overdue and is quite painful to rebase, so let's get it
> merged.
> 
> Several reasons why the legacy transport needs to be replaced:
> 
> [...]

Applied patches 1-16 to kvmtool (master), thanks!

[01/24] virtio: Add NEEDS_RESET to the status mask
        https://git.kernel.org/will/kvmtool/c/7efc2622d5ee
[02/24] virtio: Remove redundant test
        https://git.kernel.org/will/kvmtool/c/3a1e36e4bf49
[03/24] virtio/vsock: Remove redundant state tracking
        https://git.kernel.org/will/kvmtool/c/a8e397bb9dd9
[04/24] virtio: Factor virtqueue initialization
        https://git.kernel.org/will/kvmtool/c/fd41cde06617
[05/24] virtio: Support modern virtqueue addresses
        https://git.kernel.org/will/kvmtool/c/609ee9066879
[06/24] virtio: Add config access helpers
        https://git.kernel.org/will/kvmtool/c/15e6c4e74d06
[07/24] virtio: Fix device-specific config endianness
        https://git.kernel.org/will/kvmtool/c/867b15ccd7da
[08/24] virtio/console: Remove unused callback
        https://git.kernel.org/will/kvmtool/c/17ad9fd6ce37
[09/24] virtio: Remove set_guest_features() device op
        https://git.kernel.org/will/kvmtool/c/902a8ecb3877
[10/24] Add memcpy_fromiovec_safe
        https://git.kernel.org/will/kvmtool/c/c492534f3ac9
[11/24] virtio/net: Offload vnet header endianness conversion to tap
        https://git.kernel.org/will/kvmtool/c/8b27bcff44fd
[12/24] virtio/net: Prepare for modern virtio
        https://git.kernel.org/will/kvmtool/c/b231683c3361
[13/24] virtio/net: Implement VIRTIO_F_ANY_LAYOUT feature
        https://git.kernel.org/will/kvmtool/c/6daffe57762c
[14/24] virtio/console: Add VIRTIO_F_ANY_LAYOUT feature
        https://git.kernel.org/will/kvmtool/c/e74b56e1495c
[15/24] virtio/blk: Implement VIRTIO_F_ANY_LAYOUT feature
        https://git.kernel.org/will/kvmtool/c/484278913807
[16/24] virtio/pci: Factor MSI route creation
        https://git.kernel.org/will/kvmtool/c/f44af23e3a62

Cheers,
Jean-Philippe Brucker June 10, 2022, 4:31 p.m. UTC | #3
On Thu, Jun 09, 2022 at 01:39:48PM +0100, Will Deacon wrote:
> On Tue, Jun 07, 2022 at 06:02:15PM +0100, Jean-Philippe Brucker wrote:
> > Add support for version 1 of the virtio transport to kvmtool. Based on a
> > RFC by Sasha Levin [1], I've been trying to complete it here and there.
> > It's long overdue and is quite painful to rebase, so let's get it
> > merged.
> >
> > Several reasons why the legacy transport needs to be replaced:
> >
> > * Only 32 feature bits are supported. Most importantly
> >   VIRTIO_F_ACCESS_PLATFORM, which forces a Linux guest to use the DMA
> >   API, cannot be enabled. So we can't support private guests that
> >   decrypt or share only their DMA memory with the host.
> 
> Woohoo!
> 
> > * Legacy virtqueue address is a 32-bit pfn, aligned on 4kB. Since Linux
> >   guests bypass the DMA API they can't support large GPAs.
> >
> > * New devices types (iommu, crypto, memory, etc) and new features cannot
> >   be supported.
> >
> > * New guests won't implement the legacy transport. Existing guests will
> >   eventually drop legacy support.
> >
> > Support for modern transport becomes the default and legacy is enabled
> > with --virtio-legacy.
> >
> > I only tested what I could: vsock, scsi and vhost-net are currently
> > broken and can be fixed later (they have issues with mem regions and
> > feature mask, among other things). I also haven't tested big-endian.
> 
> If these are broken, then shall we default to legacy mode and have the
> modern transport be opt-in? Otherwise we're regressing people in a
> confusing way.

What I meant was that even without these patches, I wasn't able to use any
of the vhost devices, they already had several bugs. But now that I spent
a little more time trying to fix them, it looks like the modern transport
does add one regression (vhost ioeventfd is set on I/O port but modern
transport uses MMIO).

I'll sort this out and resend. Thanks for picking up the base patches!

Thanks,
Jean