From: David Gibson <david@gibson.dropbear.id.au>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
Alex Williamson <alex.williamson@redhat.com>,
Alexander Graf <agraf@suse.de>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH qemu v15 14/17] spapr_iommu, vfio, memory: Notify IOMMU about starting/stopping being used by VFIO
Date: Thu, 28 Apr 2016 11:02:35 +1000 [thread overview]
Message-ID: <20160428010235.GA2269@voom.redhat.com> (raw)
In-Reply-To: <11043dbf-a5de-24c4-5cde-290d2f1a1c10@ozlabs.ru>
[-- Attachment #1: Type: text/plain, Size: 6975 bytes --]
On Wed, Apr 27, 2016 at 07:14:15PM +1000, Alexey Kardashevskiy wrote:
> On 04/27/2016 04:39 PM, David Gibson wrote:
> >On Thu, Apr 21, 2016 at 02:22:01PM +1000, Alexey Kardashevskiy wrote:
> >>On 04/21/2016 01:59 PM, David Gibson wrote:
> >>>On Wed, Apr 20, 2016 at 07:15:15PM +1000, Alexey Kardashevskiy wrote:
> >>>>On 04/07/2016 10:40 AM, David Gibson wrote:
> >>>>>On Mon, Apr 04, 2016 at 07:33:43PM +1000, Alexey Kardashevskiy wrote:
> >>>>>>The sPAPR TCE tables manage 2 copies when VFIO is using an IOMMU -
> >>>>>>a guest view of the table and a hardware TCE table. If there is no VFIO
> >>>>>>presense in the address space, then just the guest view is used, if
> >>>>>>this is the case, it is allocated in the KVM. However since there is no
> >>>>>>support yet for VFIO in KVM TCE hypercalls, when we start using VFIO,
> >>>>>>we need to move the guest view from KVM to the userspace; and we need
> >>>>>>to do this for every IOMMU on a bus with VFIO devices.
> >>>>>>
> >>>>>>This adds vfio_start/vfio_stop callbacks in MemoryRegionIOMMUOps to
> >>>>>>notifiy IOMMU about changing environment so it can reallocate the table
> >>>>>>to/from KVM or (when available) hook the IOMMU groups with the logical
> >>>>>>bus (LIOBN) in the KVM.
> >>>>>>
> >>>>>>This removes explicit spapr_tce_set_need_vfio() call from PCI hotplug
> >>>>>>path as the new callbacks do this better - they notify IOMMU at
> >>>>>>the exact moment when the configuration is changed, and this also
> >>>>>>includes the case of PCI hot unplug.
> >>>>>>
> >>>>>>As there can be multiple containers attached to the same PHB/LIOBN,
> >>>>>>this replaces the @need_vfio flag in sPAPRTCETable with the counter
> >>>>>>of VFIO users.
> >>>>>>
> >>>>>>Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> >>>>>
> >>>>>This looks correct, but there's one remaining ugly.
> >>>>>
> >>>>>>---
> >>>>>>Changes:
> >>>>>>v15:
> >>>>>>* s/need_vfio/vfio-Users/g
> >>>>>>---
> >>>>>> hw/ppc/spapr_iommu.c | 30 ++++++++++++++++++++----------
> >>>>>> hw/ppc/spapr_pci.c | 6 ------
> >>>>>> hw/vfio/common.c | 9 +++++++++
> >>>>>> include/exec/memory.h | 4 ++++
> >>>>>> include/hw/ppc/spapr.h | 2 +-
> >>>>>> 5 files changed, 34 insertions(+), 17 deletions(-)
> >>>>>>
> >>>>>>diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
> >>>>>>index c945dba..ea09414 100644
> >>>>>>--- a/hw/ppc/spapr_iommu.c
> >>>>>>+++ b/hw/ppc/spapr_iommu.c
> >>>>>>@@ -155,6 +155,16 @@ static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu)
> >>>>>> return 1ULL << tcet->page_shift;
> >>>>>> }
> >>>>>>
> >>>>>>+static void spapr_tce_vfio_start(MemoryRegion *iommu)
> >>>>>>+{
> >>>>>>+ spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), true);
> >>>>>>+}
> >>>>>>+
> >>>>>>+static void spapr_tce_vfio_stop(MemoryRegion *iommu)
> >>>>>>+{
> >>>>>>+ spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), false);
> >>>>>>+}
> >>>>>>+
> >>>>>> static void spapr_tce_table_do_enable(sPAPRTCETable *tcet);
> >>>>>> static void spapr_tce_table_do_disable(sPAPRTCETable *tcet);
> >>>>>>
> >>>>>>@@ -239,6 +249,8 @@ static const VMStateDescription vmstate_spapr_tce_table = {
> >>>>>> static MemoryRegionIOMMUOps spapr_iommu_ops = {
> >>>>>> .translate = spapr_tce_translate_iommu,
> >>>>>> .get_page_sizes = spapr_tce_get_page_sizes,
> >>>>>>+ .vfio_start = spapr_tce_vfio_start,
> >>>>>>+ .vfio_stop = spapr_tce_vfio_stop,
> >>>>>
> >>>>>Ok, so AFAICT these callbacks are called whenever a VFIO context is
> >>>>>added / removed from the gIOMMU's address space, and it's up to the
> >>>>>gIOMMU code to ref count that to see if there are any current vfio
> >>>>>users. That makes "vfio_start" and "vfio_stop" not great names.
> >>>>>
> >>>>>But.. better than changing the names would be to move the refcounting
> >>>>>to the generic code if you can manage it, so the individual gIOMMU
> >>>>>backends don't need to - they just told when they need to start / stop
> >>>>>providing VFIO support.
> >>>>
> >>>>Everything is manageable...
> >>>>
> >>>>This referencing is needed for the case of >=2 containers so
> >>>>2xvfio_listener_region_add will create 2xVFIOGuestIOMMU as they are per
> >>>>VFIOContainer so VFIOGuestIOMMU is not the right place for the reference
> >>>>counting, VFIOAddressSpace seems to be that place (=> add list of IOMMU MRs
> >>>>with refcounter). Or even IOMMU MR. Or move VFIOGuestIOMMU list from
> >>>>VFIOContainer to VFIOAddressSpace and then gIOMMU can handle
> >>>>refcounting?
> >>>
> >>>I'm having a lot of trouble parsing that. I think the ref parsing has
> >>>to be per-giommu (because individual giommus could, in theory, be
> >>>mapped or unmapped from an address space).
> >>
> >>
> >>Example 1.
> >>POWER8, no DDW, one QEMU PHB, 2 IOMMU groups, table sharing so just 1
> >>container, one TCE table (aka gIOMMU), one TCE table in KVM, no reference
> >>counting needed at all, simple.
> >>
> >>Example 2.
> >>POWER7, no DDW, one QEMU PHB, 2 IOMMU groups, no table sharing so there are
> >>2 containers but still one IOMMU MR which is added to each container so
> >>there are 2 gIOMMU objects. And there is still one TCE table in KVM (which
> >>is a guest view). Where do I put the reference counter which will count that
> >>there are 2 gIOMMUs per KVM TCE table in this example?
> >
> >Ah.. I'd forgotten that the gIOMMU object is per guest IOMMU window
> >*and* per container, not just per guest IOMMU window.
> >
> >Ultimately it's the code implementing the guest side IOMMU which needs
> >to know if it is supporting VFIO or not, so in generic terms that
> >means per IOMMU-type MemoryRegion.
> >
> >Essentially you need to count the number of VFIOGuestIOMMU objects
> >associated with each (gIOMMU) MemoryRegion, and notify the
> >MemoryRegion if that changes from zero to non-zero or vice versa.
> >
> >I'd prefer if we can maintain that count from just the VFIO code and
> >just notify the gIOMMU code on zero / non-zero changes. But I guess
> >we'd need approval from Paolo to add that count to the MemoryRegion.
>
>
> Why MR? I could wrap MR to "VFIOIOMMUMR", add a counter and keep a list of
> these VFIOIOMMUMRs in VFIOAddressSpace.
Ah, yes I guess we could. It's just kinda ugly to have to keep
another object with the same lifetime around for one extra counter.
> I am adding Paolo, just for the case :)
>
>
> >The fallback would be similar to what you have - instead the
> >MemoryRegion gets notified whenever a VFIOGuestIOMMU is attached or
> >removed, and the MR (i.e. the guest side IOMMU code) has to maintain
> >the count itself.
>
>
>
>
>
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-04-28 1:24 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-04 9:33 [Qemu-devel] [PATCH qemu v15 00/17] spapr: vfio: Enable Dynamic DMA windows (DDW) Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 01/17] memory: Fix IOMMU replay base address Alexey Kardashevskiy
2016-04-05 1:34 ` David Gibson
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 02/17] vmstate: Define VARRAY with VMS_ALLOC Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 03/17] vfio: Check that IOMMU MR translates to system address space Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 04/17] spapr_iommu: Move table allocation to helpers Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 05/17] spapr_iommu: Introduce "enabled" state for TCE table Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 06/17] spapr_iommu: Finish renaming vfio_accel to need_vfio Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 07/17] spapr_iommu: Migrate full state Alexey Kardashevskiy
2016-04-05 5:58 ` David Gibson
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 08/17] spapr_iommu: Add root memory region Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 09/17] spapr_pci: Reset DMA config on PHB reset Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 10/17] memory: Add reporting of supported page sizes Alexey Kardashevskiy
2016-04-06 5:52 ` David Gibson
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 11/17] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering) Alexey Kardashevskiy
2016-04-06 6:05 ` David Gibson
2016-04-20 8:51 ` Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 12/17] spapr_pci: Add and export DMA resetting helper Alexey Kardashevskiy
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 13/17] vfio: Add host side DMA window capabilities Alexey Kardashevskiy
2016-04-06 7:10 ` David Gibson
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 14/17] spapr_iommu, vfio, memory: Notify IOMMU about starting/stopping being used by VFIO Alexey Kardashevskiy
2016-04-07 0:40 ` David Gibson
2016-04-20 9:15 ` Alexey Kardashevskiy
2016-04-21 3:59 ` David Gibson
2016-04-21 4:22 ` Alexey Kardashevskiy
2016-04-26 2:28 ` Alexey Kardashevskiy
2016-04-27 6:39 ` David Gibson
2016-04-27 9:14 ` Alexey Kardashevskiy
2016-04-28 1:02 ` David Gibson [this message]
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 15/17] spapr_pci: Get rid of dma_loibn Alexey Kardashevskiy
2016-04-07 0:50 ` David Gibson
2016-04-07 7:10 ` Alexey Kardashevskiy
2016-04-08 1:34 ` David Gibson
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 16/17] vfio/spapr: Use VFIO_SPAPR_TCE_v2_IOMMU Alexey Kardashevskiy
2016-04-07 1:10 ` David Gibson
2016-04-20 9:43 ` Alexey Kardashevskiy
2016-04-21 4:03 ` David Gibson
2016-04-04 9:33 ` [Qemu-devel] [PATCH qemu v15 17/17] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) 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=20160428010235.GA2269@voom.redhat.com \
--to=david@gibson.dropbear.id.au \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=pbonzini@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.