From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: linuxppc-dev@lists.ozlabs.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Paul Mackerras <paulus@samba.org>,
Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH QEMU 12/12] vfio: Enable in-kernel acceleration via VFIO KVM device
Date: Tue, 15 Jul 2014 19:39:44 +1000 [thread overview]
Message-ID: <1405417184-14333-13-git-send-email-aik@ozlabs.ru> (raw)
In-Reply-To: <1405417184-14333-1-git-send-email-aik@ozlabs.ru>
TCE hypercalls (H_PUT_TCE, H_PUT_TCE_INDIRECT, H_STUFF_TCE) use a logical bus
number (LIOBN) to identify which TCE table the request is addressed to.
However VFIO kernel driver operates with IOMMU group IDs and has no idea
about which LIOBN corresponds to which group. If the host kernel supports
in-kernel acceleration for TCE calls, we have to provide the LIOBN to IOMMU
mapping information.
This makes use of a VFIO KVM device's
KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE_LIOBN attribute to set the link
between LIOBN and IOMMU group.
The vfio_container_spapr_set_liobn() helper is implemented completely
in vfio.c because kvm_vfio_spapr_tce_liobn needs a group fd and
we do not want to share resources likes that outside vfio.c.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
hw/misc/vfio.c | 41 +++++++++++++++++++++++++++++++++++++++++
hw/ppc/spapr_iommu.c | 1 +
hw/ppc/spapr_pci_vfio.c | 22 ++++++++++++++++++++++
include/hw/misc/vfio.h | 5 +++++
4 files changed, 69 insertions(+)
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index e7b4d6e..6e9919a 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -4450,3 +4450,44 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
return vfio_container_do_ioctl(as, groupid, req, param);
}
+
+int vfio_container_spapr_set_liobn(AddressSpace *as,
+ int32_t groupid,
+ uint64_t liobn,
+ uint64_t start_addr)
+{
+#ifdef CONFIG_KVM
+ VFIOGroup *group;
+ int ret;
+ struct kvm_vfio_spapr_tce_liobn param = {
+ .argsz = sizeof(param),
+ .liobn = liobn,
+ .start_addr = start_addr
+ };
+ struct kvm_device_attr attr = {
+ .group = KVM_DEV_VFIO_GROUP,
+ .attr = KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE_LIOBN,
+ .addr = (uint64_t)(unsigned long)¶m,
+ };
+
+ if (vfio_kvm_device_fd < 0) {
+ return 0;
+ }
+
+ group = vfio_get_group(groupid, as);
+ if (!group) {
+ return -1;
+ }
+
+ param.fd = group->fd;
+ ret = ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr);
+ if (ret) {
+ error_report("vfio: failed to setup liobn for a group: %s",
+ strerror(errno));
+ }
+
+ return ret;
+#else
+ return 0;
+#endif
+}
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 1710595..3c2a9c9 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -126,6 +126,7 @@ static int spapr_tce_table_realize(DeviceState *dev)
if (!tcet->table) {
size_t table_size = tcet->nb_table * sizeof(uint64_t);
tcet->table = g_malloc0(table_size);
+ tcet->vfio_accel = false;
}
trace_spapr_iommu_new_table(tcet->liobn, tcet, tcet->table, tcet->fd);
diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
index b72aff0..06b4e02 100644
--- a/hw/ppc/spapr_pci_vfio.c
+++ b/hw/ppc/spapr_pci_vfio.c
@@ -21,6 +21,7 @@
#include "hw/pci-host/spapr.h"
#include "linux/vfio.h"
#include "hw/misc/vfio.h"
+#include "qemu/error-report.h"
static Property spapr_phb_vfio_properties[] = {
DEFINE_PROP_INT32("iommu", sPAPRPHBVFIOState, iommugroupid, -1),
@@ -69,6 +70,17 @@ static void spapr_phb_vfio_finish_realize(sPAPRPHBState *sphb, Error **errp)
/* Register default 32bit DMA window */
memory_region_add_subregion(&sphb->iommu_root, tcet->bus_offset,
spapr_tce_get_iommu(tcet));
+
+ if (!tcet->vfio_accel) {
+ return;
+ }
+ ret = vfio_container_spapr_set_liobn(&svphb->phb.iommu_as,
+ svphb->iommugroupid,
+ tcet->liobn,
+ tcet->bus_offset);
+ if (ret) {
+ error_report("spapr-vfio: failed to create link to IOMMU");
+ }
}
static int spapr_pci_vfio_ddw_query(sPAPRPHBState *sphb,
@@ -116,6 +128,16 @@ static int spapr_pci_vfio_ddw_create(sPAPRPHBState *sphb, uint32_t page_shift,
memory_region_add_subregion(&sphb->iommu_root, (*ptcet)->bus_offset,
spapr_tce_get_iommu(*ptcet));
+ if (!(*ptcet)->vfio_accel) {
+ return 0;
+ }
+ ret = vfio_container_spapr_set_liobn(&sphb->iommu_as, svphb->iommugroupid,
+ liobn, (*ptcet)->bus_offset);
+ if (ret) {
+ error_report("spapr-vfio: failed to create link to IOMMU");
+ ret = 0;
+ }
+
return ret;
}
diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
index 0b26cd8..8f248e2 100644
--- a/include/hw/misc/vfio.h
+++ b/include/hw/misc/vfio.h
@@ -6,4 +6,9 @@
extern int vfio_container_ioctl(AddressSpace *as, int32_t groupid,
int req, void *param);
+extern int vfio_container_spapr_set_liobn(AddressSpace *as,
+ int32_t groupid,
+ uint64_t liobn,
+ uint64_t start_addr);
+
#endif
--
2.0.0
prev parent reply other threads:[~2014-07-15 9:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 9:39 [PATCH QEMU 00/12] vfio: pci: Enable DDW and in-kernel acceleration Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 01/12] spapr_iommu: Disable in-kernel IOMMU tables for >4GB windows Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 02/12] spapr_pci: Make find_phb()/find_dev() public Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 03/12] spapr_iommu: Make spapr_tce_find_by_liobn() public Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 04/12] linux headers update for DDW Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 05/12] spapr_rtas: Add Dynamic DMA windows (DDW) RTAS calls support Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 06/12] spapr: Add "ddw" machine option Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 07/12] spapr_pci: Enable DDW Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 08/12] spapr_pci_vfio: " Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 09/12] vfio: Enable DDW ioctls to VFIO IOMMU driver Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 10/12] headers: update for KVM_CAP_SPAPR_TCE_64 and VFIO KVM device Alexey Kardashevskiy
2014-07-15 9:39 ` [PATCH QEMU 11/12] target-ppc: kvm: make use of KVM_CREATE_SPAPR_TCE_64 Alexey Kardashevskiy
2014-07-15 9:39 ` Alexey Kardashevskiy [this message]
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=1405417184-14333-13-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=gwshan@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.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).