qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 02/11] vfio/spapr: Use iommu memory region's get_attr()
Date: Mon, 05 Feb 2018 11:56:58 -0700	[thread overview]
Message-ID: <20180205185658.14391.12745.stgit@gimli.home> (raw)
In-Reply-To: <20180205185416.14391.5739.stgit@gimli.home>

From: Alexey Kardashevskiy <aik@ozlabs.ru>

In order to enable TCE operations support in KVM, we have to inform
the KVM about VFIO groups being attached to specific LIOBNs. The KVM
already knows about VFIO groups, the only bit missing is which
in-kernel TCE table (the one with user visible TCEs) should update
the attached broups. There is an KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE
attribute of the VFIO KVM device which receives a groupfd/tablefd couple.

This uses a new memory_region_iommu_get_attr() helper to get the IOMMU fd
and calls KVM to establish the link.

As get_attr() is not implemented yet, this should cause no behavioural
change.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/common.c     |   27 +++++++++++++++++++++++++++
 hw/vfio/trace-events |    1 +
 2 files changed, 28 insertions(+)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index b77be3a8b36b..ec41f93b7479 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -457,6 +457,33 @@ static void vfio_listener_region_add(MemoryListener *listener,
         vfio_host_win_add(container, section->offset_within_address_space,
                           section->offset_within_address_space +
                           int128_get64(section->size) - 1, pgsize);
+#ifdef CONFIG_KVM
+        if (kvm_enabled()) {
+            VFIOGroup *group;
+            IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
+            struct kvm_vfio_spapr_tce param;
+            struct kvm_device_attr attr = {
+                .group = KVM_DEV_VFIO_GROUP,
+                .attr = KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE,
+                .addr = (uint64_t)(unsigned long)&param,
+            };
+
+            if (!memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_SPAPR_TCE_FD,
+                                              &param.tablefd)) {
+                QLIST_FOREACH(group, &container->group_list, container_next) {
+                    param.groupfd = group->fd;
+                    if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
+                        error_report("vfio: failed to setup fd %d "
+                                     "for a group with fd %d: %s",
+                                     param.tablefd, param.groupfd,
+                                     strerror(errno));
+                        return;
+                    }
+                    trace_vfio_spapr_group_attach(param.groupfd, param.tablefd);
+                }
+            }
+        }
+#endif
     }
 
     hostwin_found = false;
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index fae096c0724f..3d34fe8a93f1 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -123,3 +123,4 @@ vfio_prereg_register(uint64_t va, uint64_t size, int ret) "va=0x%"PRIx64" size=0
 vfio_prereg_unregister(uint64_t va, uint64_t size, int ret) "va=0x%"PRIx64" size=0x%"PRIx64" ret=%d"
 vfio_spapr_create_window(int ps, uint64_t ws, uint64_t off) "pageshift=0x%x winsize=0x%"PRIx64" offset=0x%"PRIx64
 vfio_spapr_remove_window(uint64_t off) "offset=0x%"PRIx64
+vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn fd %d"

  parent reply	other threads:[~2018-02-05 18:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-05 18:56 [Qemu-devel] [PULL 00/11] VFIO updates 2018-02-05 Alex Williamson
2018-02-05 18:56 ` [Qemu-devel] [PULL 01/11] memory/iommu: Add get_attr() Alex Williamson
2018-02-05 18:56 ` Alex Williamson [this message]
2018-02-05 18:57 ` [Qemu-devel] [PULL 03/11] spapr/iommu: Enable in-kernel TCE acceleration via VFIO KVM device Alex Williamson
2018-02-05 18:57 ` [Qemu-devel] [PULL 04/11] vfio/pci: Fixup VFIOMSIXInfo comment Alex Williamson
2018-02-05 18:57 ` [Qemu-devel] [PULL 05/11] vfio/pci: Add base BAR MemoryRegion Alex Williamson
2018-02-05 18:57 ` [Qemu-devel] [PULL 06/11] vfio/pci: Emulate BARs Alex Williamson
2018-02-05 18:57 ` [Qemu-devel] [PULL 07/11] qapi: Create DEFINE_PROP_OFF_AUTO_PCIBAR Alex Williamson
2018-02-05 18:57 ` [Qemu-devel] [PULL 08/11] vfio/pci: Allow relocating MSI-X MMIO Alex Williamson
2018-02-05 18:58 ` [Qemu-devel] [PULL 09/11] hw/vfio/platform: Init the interrupt mutex Alex Williamson
2018-02-05 18:58 ` [Qemu-devel] [PULL 10/11] vfio/common: Remove redundant copy of local variable Alex Williamson
2018-02-05 18:58 ` [Qemu-devel] [PULL 11/11] vfio/pci: Add option to disable GeForce quirks Alex Williamson
2018-02-06 17:34 ` [Qemu-devel] [PULL 00/11] VFIO updates 2018-02-05 Peter Maydell
2018-02-06 18:04   ` Alex Williamson
  -- strict thread matches above, loose matches on Subject: below --
2018-02-06 18:42 [Qemu-devel] [PULL 00/11] VFIO updates 2018-02-06 Alex Williamson
2018-02-06 18:43 ` [Qemu-devel] [PULL 02/11] vfio/spapr: Use iommu memory region's get_attr() Alex Williamson

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=20180205185658.14391.12745.stgit@gimli.home \
    --to=alex.williamson@redhat.com \
    --cc=qemu-devel@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).