spapr/iommu: Enable in-kernel TCE acceleration via VFIO KVM device
In order to enable TCE operations support in KVM, we have to inform the KVM about VFIO groups being attached to specific LIOBNs; the necessary bits are implemented already by IOMMU MR and VFIO. This defines get_attr() for the SPAPR TCE IOMMU MR which makes VFIO call the KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE ioctl and establish LIOBN-to-IOMMU link. This changes spapr_tce_set_need_vfio() to avoid TCE table reallocation if the kernel supports the TCE acceleration. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> [aw - remove unnecessary sys/ioctl.h include] Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
07bc681a33
commit
9ded780c4c
@ -160,6 +160,19 @@ static uint64_t spapr_tce_get_min_page_size(IOMMUMemoryRegion *iommu)
|
|||||||
return 1ULL << tcet->page_shift;
|
return 1ULL << tcet->page_shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int spapr_tce_get_attr(IOMMUMemoryRegion *iommu,
|
||||||
|
enum IOMMUMemoryRegionAttr attr, void *data)
|
||||||
|
{
|
||||||
|
sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu);
|
||||||
|
|
||||||
|
if (attr == IOMMU_ATTR_SPAPR_TCE_FD && kvmppc_has_cap_spapr_vfio()) {
|
||||||
|
*(int *) data = tcet->fd;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
static void spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
|
static void spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu,
|
||||||
IOMMUNotifierFlag old,
|
IOMMUNotifierFlag old,
|
||||||
IOMMUNotifierFlag new)
|
IOMMUNotifierFlag new)
|
||||||
@ -284,6 +297,10 @@ void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio)
|
|||||||
|
|
||||||
tcet->need_vfio = need_vfio;
|
tcet->need_vfio = need_vfio;
|
||||||
|
|
||||||
|
if (!need_vfio || (tcet->fd != -1 && kvmppc_has_cap_spapr_vfio())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
oldtable = tcet->table;
|
oldtable = tcet->table;
|
||||||
|
|
||||||
tcet->table = spapr_tce_alloc_table(tcet->liobn,
|
tcet->table = spapr_tce_alloc_table(tcet->liobn,
|
||||||
@ -643,6 +660,7 @@ static void spapr_iommu_memory_region_class_init(ObjectClass *klass, void *data)
|
|||||||
imrc->translate = spapr_tce_translate_iommu;
|
imrc->translate = spapr_tce_translate_iommu;
|
||||||
imrc->get_min_page_size = spapr_tce_get_min_page_size;
|
imrc->get_min_page_size = spapr_tce_get_min_page_size;
|
||||||
imrc->notify_flag_changed = spapr_tce_notify_flag_changed;
|
imrc->notify_flag_changed = spapr_tce_notify_flag_changed;
|
||||||
|
imrc->get_attr = spapr_tce_get_attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo spapr_iommu_memory_region_info = {
|
static const TypeInfo spapr_iommu_memory_region_info = {
|
||||||
|
@ -137,7 +137,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
|
|||||||
cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE);
|
cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE);
|
||||||
cap_spapr_tce_64 = kvm_check_extension(s, KVM_CAP_SPAPR_TCE_64);
|
cap_spapr_tce_64 = kvm_check_extension(s, KVM_CAP_SPAPR_TCE_64);
|
||||||
cap_spapr_multitce = kvm_check_extension(s, KVM_CAP_SPAPR_MULTITCE);
|
cap_spapr_multitce = kvm_check_extension(s, KVM_CAP_SPAPR_MULTITCE);
|
||||||
cap_spapr_vfio = false;
|
cap_spapr_vfio = kvm_vm_check_extension(s, KVM_CAP_SPAPR_TCE_VFIO);
|
||||||
cap_one_reg = kvm_check_extension(s, KVM_CAP_ONE_REG);
|
cap_one_reg = kvm_check_extension(s, KVM_CAP_ONE_REG);
|
||||||
cap_hior = kvm_check_extension(s, KVM_CAP_PPC_HIOR);
|
cap_hior = kvm_check_extension(s, KVM_CAP_PPC_HIOR);
|
||||||
cap_epr = kvm_check_extension(s, KVM_CAP_PPC_EPR);
|
cap_epr = kvm_check_extension(s, KVM_CAP_PPC_EPR);
|
||||||
@ -2514,6 +2514,11 @@ int kvmppc_get_cap_safe_indirect_branch(void)
|
|||||||
return cap_ppc_safe_indirect_branch;
|
return cap_ppc_safe_indirect_branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool kvmppc_has_cap_spapr_vfio(void)
|
||||||
|
{
|
||||||
|
return cap_spapr_vfio;
|
||||||
|
}
|
||||||
|
|
||||||
PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
|
PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
|
||||||
{
|
{
|
||||||
uint32_t host_pvr = mfpvr();
|
uint32_t host_pvr = mfpvr();
|
||||||
|
@ -46,6 +46,7 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
|
|||||||
int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
|
int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
|
||||||
int kvmppc_reset_htab(int shift_hint);
|
int kvmppc_reset_htab(int shift_hint);
|
||||||
uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
|
uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
|
||||||
|
bool kvmppc_has_cap_spapr_vfio(void);
|
||||||
#endif /* !CONFIG_USER_ONLY */
|
#endif /* !CONFIG_USER_ONLY */
|
||||||
bool kvmppc_has_cap_epr(void);
|
bool kvmppc_has_cap_epr(void);
|
||||||
int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
|
int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
|
||||||
@ -232,6 +233,11 @@ static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool kvmppc_has_cap_spapr_vfio(void)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_USER_ONLY */
|
#endif /* !CONFIG_USER_ONLY */
|
||||||
|
|
||||||
static inline bool kvmppc_has_cap_epr(void)
|
static inline bool kvmppc_has_cap_epr(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user