From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Alexander Graf <agraf@suse.de>,
Alex Williamson <alex.williamson@redhat.com>,
qemu-ppc@nongnu.org, David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCH v4 12/12] spapr kvm vfio: enable in-kernel acceleration
Date: Fri, 30 Aug 2013 20:15:38 +1000 [thread overview]
Message-ID: <1377857738-14789-13-git-send-email-aik@ozlabs.ru> (raw)
In-Reply-To: <1377857738-14789-1-git-send-email-aik@ozlabs.ru>
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 <aik@ozlabs.ru>
---
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
next prev parent reply other threads:[~2013-08-30 10:16 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-30 10:15 [Qemu-devel] [PATCH v4 00/12] vfio on spapr-ppc64 Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 01/12] vfio: Introduce VFIO address spaces Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 02/12] vfio: Create VFIOAddressSpace objects as needed Alexey Kardashevskiy
2013-09-05 18:24 ` Alex Williamson
2013-09-10 8:09 ` Alexey Kardashevskiy
2013-09-10 21:51 ` Alex Williamson
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 03/12] vfio: Add guest side IOMMU support Alexey Kardashevskiy
2013-09-05 18:49 ` Alex Williamson
2013-09-10 8:22 ` Alexey Kardashevskiy
2013-09-10 22:02 ` Alex Williamson
2013-09-11 6:15 ` Paolo Bonzini
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 04/12] spapr vfio: add vfio_container_spapr_get_info() Alexey Kardashevskiy
2013-09-05 19:01 ` Alex Williamson
2013-09-10 8:36 ` Alexey Kardashevskiy
2013-09-10 22:11 ` Alex Williamson
2013-09-13 10:11 ` Alexey Kardashevskiy
2013-09-25 20:29 ` Alex Williamson
2013-09-26 10:22 ` Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 05/12] spapr_pci: convert init to realize Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 06/12] spapr_pci: add spapr_pci trace Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 07/12] spapr_pci: converts fprintf to error_report Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 08/12] spapr_iommu: introduce SPAPR_TCE_TABLE class Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 09/12] spapr_iommu: add SPAPR VFIO IOMMU Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 10/12] spapr vfio: add spapr-pci-vfio-host-bridge to support vfio Alexey Kardashevskiy
2013-08-30 10:15 ` [Qemu-devel] [PATCH v4 11/12] spapr vfio: enable for spapr Alexey Kardashevskiy
2013-09-05 19:05 ` Alex Williamson
2013-09-10 9:00 ` Alexey Kardashevskiy
2013-09-10 22:13 ` Alex Williamson
2013-09-13 11:34 ` Alexey Kardashevskiy
2013-09-25 20:33 ` Alex Williamson
2013-08-30 10:15 ` Alexey Kardashevskiy [this message]
2013-09-05 6:43 ` [Qemu-devel] [PATCH v4 00/12] vfio on spapr-ppc64 Alexey Kardashevskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377857738-14789-13-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=agraf@suse.de \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).