[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH v4 12/12] spapr kvm vfio: enable in-kernel acceleratio
From: |
Alexey Kardashevskiy |
Subject: |
[Qemu-ppc] [PATCH v4 12/12] spapr kvm vfio: enable in-kernel acceleration |
Date: |
Fri, 30 Aug 2013 20:15:38 +1000 |
This enables in-kernel support for DMA operations on VFIO PHBs.
This creates a "SPAPR TCE IOMMU" KVM device and initializes it
with LIOBN and IOMMU fd. Once enabled, it keeps H_PUT_TCE,
H_PUT_TCE_INDIRECT, H_STUFF_TCE hypercalls in the kernel so
their QEMU handlers won't be called.
Signed-off-by: Alexey Kardashevskiy <address@hidden>
---
hw/ppc/spapr_iommu.c | 4 ++++
target-ppc/kvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
target-ppc/kvm_ppc.h | 13 +++++++++++++
3 files changed, 64 insertions(+)
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index d91dee5..32255fc 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -258,6 +258,7 @@ sPAPRTCETable *spapr_vfio_new_table(DeviceState *owner,
uint32_t liobn,
int group_fd)
{
sPAPRTCETable *tcet;
+ int fd;
if (spapr_tce_find_by_liobn(liobn)) {
fprintf(stderr, "Attempted to create TCE table with duplicate"
@@ -265,8 +266,11 @@ sPAPRTCETable *spapr_vfio_new_table(DeviceState *owner,
uint32_t liobn,
return NULL;
}
+ fd = kvmppc_create_spapr_tce_iommu(liobn, group_fd);
+
tcet = SPAPR_TCE_TABLE(object_new(TYPE_SPAPR_TCE_TABLE_VFIO));
tcet->liobn = liobn;
+ tcet->fd = fd;
object_property_add_child(OBJECT(owner), "tce-table", OBJECT(tcet), NULL);
object_property_set_bool(OBJECT(tcet), true, "realized", NULL);
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 5e72c22..ec7556f 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -60,6 +60,7 @@ static int cap_booke_sregs;
static int cap_ppc_smt;
static int cap_ppc_rma;
static int cap_spapr_tce;
+static int cap_spapr_tce_iommu;
static int cap_hior;
static int cap_one_reg;
static int cap_epr;
@@ -96,6 +97,7 @@ int kvm_arch_init(KVMState *s)
cap_ppc_smt = kvm_check_extension(s, KVM_CAP_PPC_SMT);
cap_ppc_rma = kvm_check_extension(s, KVM_CAP_PPC_RMA);
cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE);
+ cap_spapr_tce_iommu = kvm_check_extension(s, KVM_CAP_SPAPR_TCE_IOMMU);
cap_one_reg = kvm_check_extension(s, KVM_CAP_ONE_REG);
cap_hior = kvm_check_extension(s, KVM_CAP_PPC_HIOR);
cap_epr = kvm_check_extension(s, KVM_CAP_PPC_EPR);
@@ -1662,6 +1664,51 @@ int kvmppc_remove_spapr_tce(void *table, int fd,
uint32_t window_size)
return 0;
}
+int kvmppc_create_spapr_tce_iommu(uint32_t liobn, int group_fd)
+{
+ int rc;
+ struct kvm_create_spapr_tce_iommu_linkage args = {
+ .liobn = liobn,
+ .fd = group_fd
+ };
+ struct kvm_device_attr attr = {
+ .flags = 0,
+ .group = KVM_DEV_SPAPR_TCE_IOMMU_ATTR_LINKAGE,
+ .addr = (uint64_t)(uintptr_t)&args,
+ };
+ struct kvm_create_device kcd = {
+ .type = KVM_DEV_TYPE_SPAPR_TCE_IOMMU,
+ .flags = 0,
+ };
+
+ if (!kvm_enabled() || !cap_spapr_tce_iommu) {
+ fprintf(stderr, "KVM VFIO: TCE IOMMU capability is not present, DMA
may be slow\n");
+ return -1;
+ }
+
+ rc = kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &kcd);
+ if (rc < 0) {
+ fprintf(stderr, "Error on KVM_CREATE_DEVICE for SPAPR TCE IOMMU\n");
+ return rc;
+ }
+ rc = ioctl(kcd.fd, KVM_SET_DEVICE_ATTR, &attr);
+ if (rc < 0) {
+ fprintf(stderr, "KVM VFIO: Failed to create TCE table for liobn 0x%x,
ret = %d, DMA may be slow\n",
+ liobn, rc);
+ }
+
+ return kcd.fd;
+}
+
+int kvmppc_remove_spapr_tce_iommu(int fd)
+{
+ if (fd < 0) {
+ return -1;
+ }
+
+ return close(fd);
+}
+
int kvmppc_reset_htab(int shift_hint)
{
uint32_t shift = shift_hint;
diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h
index 5f78e4b..35d3325 100644
--- a/target-ppc/kvm_ppc.h
+++ b/target-ppc/kvm_ppc.h
@@ -33,6 +33,8 @@ int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
off_t kvmppc_alloc_rma(const char *name, MemoryRegion *sysmem);
void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd);
int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
+int kvmppc_create_spapr_tce_iommu(uint32_t liobn, int group_fd);
+int kvmppc_remove_spapr_tce_iommu(int fd);
int kvmppc_reset_htab(int shift_hint);
uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
#endif /* !CONFIG_USER_ONLY */
@@ -137,6 +139,17 @@ static inline int kvmppc_remove_spapr_tce(void *table, int
pfd,
return -1;
}
+static inline int kvmppc_create_spapr_tce_iommu(uint32_t liobn,
+ uint32_t iommu_id)
+{
+ return -1;
+}
+
+static inline int kvmppc_remove_spapr_tce_iommu(int fd)
+{
+ return -1;
+}
+
static inline int kvmppc_reset_htab(int shift_hint)
{
return -1;
--
1.8.4.rc4
- [Qemu-ppc] [PATCH v4 09/12] spapr_iommu: add SPAPR VFIO IOMMU, (continued)
- [Qemu-ppc] [PATCH v4 09/12] spapr_iommu: add SPAPR VFIO IOMMU, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 04/12] spapr vfio: add vfio_container_spapr_get_info(), Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 10/12] spapr vfio: add spapr-pci-vfio-host-bridge to support vfio, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 08/12] spapr_iommu: introduce SPAPR_TCE_TABLE class, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 05/12] spapr_pci: convert init to realize, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 07/12] spapr_pci: converts fprintf to error_report, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 02/12] vfio: Create VFIOAddressSpace objects as needed, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 11/12] spapr vfio: enable for spapr, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 03/12] vfio: Add guest side IOMMU support, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 01/12] vfio: Introduce VFIO address spaces, Alexey Kardashevskiy, 2013/08/30
- [Qemu-ppc] [PATCH v4 12/12] spapr kvm vfio: enable in-kernel acceleration,
Alexey Kardashevskiy <=