Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec53500f authored by Alex Williamson's avatar Alex Williamson Committed by Paolo Bonzini
Browse files

kvm: Add VFIO device



So far we've succeeded at making KVM and VFIO mostly unaware of each
other, but areas are cropping up where a connection beyond eventfds
and irqfds needs to be made.  This patch introduces a KVM-VFIO device
that is meant to be a gateway for such interaction.  The user creates
the device and can add and remove VFIO groups to it via file
descriptors.  When a group is added, KVM verifies the group is valid
and gets a reference to it via the VFIO external user interface.

Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 84cffe49
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
VFIO virtual device
===================

Device types supported:
  KVM_DEV_TYPE_VFIO

Only one VFIO instance may be created per VM.  The created device
tracks VFIO groups in use by the VM and features of those groups
important to the correctness and acceleration of the VM.  As groups
are enabled and disabled for use by the VM, KVM should be updated
about their presence.  When registered with KVM, a reference to the
VFIO-group is held by KVM.

Groups:
  KVM_DEV_VFIO_GROUP

KVM_DEV_VFIO_GROUP attributes:
  KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM device tracking
  KVM_DEV_VFIO_GROUP_DEL: Remove a VFIO group from VFIO-KVM device tracking

For each, kvm_device_attr.addr points to an int32_t file descriptor
for the VFIO group.
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ config KVM
	select PERF_EVENTS
	select HAVE_KVM_MSI
	select HAVE_KVM_CPU_RELAX_INTERCEPT
	select KVM_VFIO
	---help---
	  Support hosting fully virtualized guest machines using hardware
	  virtualization extensions.  You will need a fairly recent
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ KVM := ../../../virt/kvm

kvm-y			+= $(KVM)/kvm_main.o $(KVM)/ioapic.o \
				$(KVM)/coalesced_mmio.o $(KVM)/irq_comm.o \
				$(KVM)/eventfd.o $(KVM)/irqchip.o
				$(KVM)/eventfd.o $(KVM)/irqchip.o $(KVM)/vfio.o
kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)	+= $(KVM)/assigned-dev.o $(KVM)/iommu.o
kvm-$(CONFIG_KVM_ASYNC_PF)	+= $(KVM)/async_pf.o

+1 −0
Original line number Diff line number Diff line
@@ -1058,6 +1058,7 @@ struct kvm_device *kvm_device_from_filp(struct file *filp);

extern struct kvm_device_ops kvm_mpic_ops;
extern struct kvm_device_ops kvm_xics_ops;
extern struct kvm_device_ops kvm_vfio_ops;

#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT

+4 −0
Original line number Diff line number Diff line
@@ -845,6 +845,10 @@ struct kvm_device_attr {
#define KVM_DEV_TYPE_FSL_MPIC_20	1
#define KVM_DEV_TYPE_FSL_MPIC_42	2
#define KVM_DEV_TYPE_XICS		3
#define KVM_DEV_TYPE_VFIO		4
#define  KVM_DEV_VFIO_GROUP			1
#define   KVM_DEV_VFIO_GROUP_ADD			1
#define   KVM_DEV_VFIO_GROUP_DEL			2

/*
 * ioctls for VM fds
Loading