mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-24 14:29:32 +07:00
121f80ba68
This allows the host kernel to handle H_PUT_TCE, H_PUT_TCE_INDIRECT and H_STUFF_TCE requests targeted an IOMMU TCE table used for VFIO without passing them to user space which saves time on switching to user space and back. This adds H_PUT_TCE/H_PUT_TCE_INDIRECT/H_STUFF_TCE handlers to KVM. KVM tries to handle a TCE request in the real mode, if failed it passes the request to the virtual mode to complete the operation. If it a virtual mode handler fails, the request is passed to the user space; this is not expected to happen though. To avoid dealing with page use counters (which is tricky in real mode), this only accelerates SPAPR TCE IOMMU v2 clients which are required to pre-register the userspace memory. The very first TCE request will be handled in the VFIO SPAPR TCE driver anyway as the userspace view of the TCE table (iommu_table::it_userspace) is not allocated till the very first mapping happens and we cannot call vmalloc in real mode. If we fail to update a hardware IOMMU table unexpected reason, we just clear it and move on as there is nothing really we can do about it - for example, if we hot plug a VFIO device to a guest, existing TCE tables will be mirrored automatically to the hardware and there is no interface to report to the guest about possible failures. This adds new attribute - KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE - to the VFIO KVM device. It takes a VFIO group fd and SPAPR TCE table fd and associates a physical IOMMU table with the SPAPR TCE table (which is a guest view of the hardware IOMMU table). The iommu_table object is cached and referenced so we do not have to look up for it in real mode. This does not implement the UNSET counterpart as there is no use for it - once the acceleration is enabled, the existing userspace won't disable it unless a VFIO container is destroyed; this adds necessary cleanup to the KVM_DEV_VFIO_GROUP_DEL handler. This advertises the new KVM_CAP_SPAPR_TCE_VFIO capability to the user space. This adds real mode version of WARN_ON_ONCE() as the generic version causes problems with rcu_sched. Since we testing what vmalloc_to_phys() returns in the code, this also adds a check for already existing vmalloc_to_phys() call in kvmppc_rm_h_put_tce_indirect(). This finally makes use of vfio_external_user_iommu_id() which was introduced quite some time ago and was considered for removal. Tests show that this patch increases transmission speed from 220MB/s to 750..1020MB/s on 10Gb network (Chelsea CXGB3 10Gb ethernet card). Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Acked-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
37 lines
1.1 KiB
Plaintext
37 lines
1.1 KiB
Plaintext
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_device_attr.addr points to an int32_t file descriptor
|
|
for the VFIO group.
|
|
KVM_DEV_VFIO_GROUP_DEL: Remove a VFIO group from VFIO-KVM device tracking
|
|
kvm_device_attr.addr points to an int32_t file descriptor
|
|
for the VFIO group.
|
|
KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE: attaches a guest visible TCE table
|
|
allocated by sPAPR KVM.
|
|
kvm_device_attr.addr points to a struct:
|
|
|
|
struct kvm_vfio_spapr_tce {
|
|
__s32 groupfd;
|
|
__s32 tablefd;
|
|
};
|
|
|
|
where
|
|
@groupfd is a file descriptor for a VFIO group;
|
|
@tablefd is a file descriptor for a TCE table allocated via
|
|
KVM_CREATE_SPAPR_TCE.
|