qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Alex Williamson <alex.williamson@redhat.com>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH qemu v13 04/16] spapr_iommu: Introduce "enabled" state for TCE table
Date: Tue, 15 Mar 2016 16:32:14 +1100	[thread overview]
Message-ID: <20160315053214.GG15272@voom.fritz.box> (raw)
In-Reply-To: <56E124BB.4010207@ozlabs.ru>

[-- Attachment #1: Type: text/plain, Size: 7111 bytes --]

On Thu, Mar 10, 2016 at 06:39:39PM +1100, Alexey Kardashevskiy wrote:
> On 03/03/2016 02:00 PM, David Gibson wrote:
> >On Tue, Mar 01, 2016 at 08:10:29PM +1100, Alexey Kardashevskiy wrote:
> >>Currently TCE tables are created once at start and their sizes never
> >>change. We are going to change that by introducing a Dynamic DMA windows
> >>support where DMA configuration may change during the guest execution.
> >>
> >>This changes spapr_tce_new_table() to create an empty zero-size IOMMU
> >>memory region (IOMMU MR). Only LIOBN is assigned by the time of creation.
> >>It still will be called once at the owner object (VIO or PHB) creation.
> >>
> >>This introduces an "enabled" state for TCE table objects with two
> >>helper functions - spapr_tce_table_enable()/spapr_tce_table_disable().
> >>- spapr_tce_table_enable() receives TCE table parameters, allocates
> >>a guest view of the TCE table (in the user space or KVM) and
> >>sets the correct size on the IOMMU MR.
> >>- spapr_tce_table_disable() disposes the table and resets the IOMMU MR
> >>size.
> >>
> >>This changes the PHB reset handler to do the default DMA initialization
> >>instead of spapr_phb_realize(). This does not make differenct now but
> >>later with more than just one DMA window, we will have to remove them all
> >>and create the default one on a system reset.
> >>
> >>No visible change in behaviour is expected except the actual table
> >>will be reallocated every reset. We might optimize this later.
> >>
> >>The other way to implement this would be dynamically create/remove
> >>the TCE table QOM objects but this would make migration impossible
> >>as the migration code expects all QOM objects to exist at the receiver
> >>so we have to have TCE table objects created when migration begins.
> >>
> >>spapr_tce_table_do_enable() is separated from from spapr_tce_table_enable()
> >>as later it will be called at the sPAPRTCETable post-migration stage when
> >>it already has all the properties set after the migration.
> >>
> >>Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> >
> >Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> >
> >Although there's one nit that could be improved:
> >
> >
> >>---
> >>  hw/ppc/spapr_iommu.c   | 80 +++++++++++++++++++++++++++++++++++---------------
> >>  hw/ppc/spapr_pci.c     | 21 +++++++++----
> >>  hw/ppc/spapr_vio.c     |  9 +++---
> >>  include/hw/ppc/spapr.h | 10 +++----
> >>  4 files changed, 80 insertions(+), 40 deletions(-)
> >>
> >>diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
> >>index 8132f64..e66e128 100644
> >>--- a/hw/ppc/spapr_iommu.c
> >>+++ b/hw/ppc/spapr_iommu.c
> >>@@ -174,15 +174,8 @@ static int spapr_tce_table_realize(DeviceState *dev)
> >>      sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev);
> >>
> >>      tcet->fd = -1;
> >>-    tcet->table = spapr_tce_alloc_table(tcet->liobn,
> >>-                                        tcet->page_shift,
> >>-                                        tcet->nb_table,
> >>-                                        &tcet->fd,
> >>-                                        tcet->need_vfio);
> >>-
> >>      memory_region_init_iommu(&tcet->iommu, OBJECT(dev), &spapr_iommu_ops,
> >>-                             "iommu-spapr",
> >>-                             (uint64_t)tcet->nb_table << tcet->page_shift);
> >>+                             "iommu-spapr", 0);
> >>
> >>      QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list);
> >>
> >>@@ -224,14 +217,10 @@ void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio)
> >>      tcet->table = newtable;
> >>  }
> >>
> >>-sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
> >>-                                   uint64_t bus_offset,
> >>-                                   uint32_t page_shift,
> >>-                                   uint32_t nb_table,
> >>-                                   bool need_vfio)
> >>+sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn)
> >>  {
> >>      sPAPRTCETable *tcet;
> >>-    char tmp[64];
> >>+    char tmp[32];
> >>
> >>      if (spapr_tce_find_by_liobn(liobn)) {
> >>          fprintf(stderr, "Attempted to create TCE table with duplicate"
> >>@@ -239,16 +228,8 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
> >>          return NULL;
> >>      }
> >>
> >>-    if (!nb_table) {
> >>-        return NULL;
> >>-    }
> >>-
> >>      tcet = SPAPR_TCE_TABLE(object_new(TYPE_SPAPR_TCE_TABLE));
> >>      tcet->liobn = liobn;
> >>-    tcet->bus_offset = bus_offset;
> >>-    tcet->page_shift = page_shift;
> >>-    tcet->nb_table = nb_table;
> >>-    tcet->need_vfio = need_vfio;
> >>
> >>      snprintf(tmp, sizeof(tmp), "tce-table-%x", liobn);
> >>      object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL);
> >>@@ -258,14 +239,65 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
> >>      return tcet;
> >>  }
> >>
> >>+static void spapr_tce_table_do_enable(sPAPRTCETable *tcet)
> >>+{
> >>+    if (!tcet->nb_table) {
> >>+        return;
> >>+    }
> >>+
> >>+    tcet->table = spapr_tce_alloc_table(tcet->liobn,
> >>+                                        tcet->page_shift,
> >>+                                        tcet->nb_table,
> >>+                                        &tcet->fd,
> >>+                                        tcet->need_vfio);
> >>+
> >>+    memory_region_set_size(&tcet->iommu,
> >>+                           (uint64_t)tcet->nb_table << tcet->page_shift);
> >>+
> >>+    tcet->enabled = true;
> >>+}
> >>+
> >>+void spapr_tce_table_enable(sPAPRTCETable *tcet,
> >>+                            uint32_t page_shift, uint64_t bus_offset,
> >>+                            uint32_t nb_table, bool need_vfio)
> >>+{
> >>+    if (tcet->enabled) {
> >>+        return;
> >
> >If the given parameters are different from the current ones, treating
> >this as a no-op is rather misleading.  I gather that to resize the
> >window you're expected to disable, then re-enable.  In which case I
> >think it would be safer to actually throw some kind of error on a
> >double enable.
> 
> I'll add here
> 
>  error_report("Warning: trying to enable already enabled TCE table");
> 
> ...
> 
> 
> 
> 
> >
> >
> >>+    }
> >>+
> >>+    tcet->bus_offset = bus_offset;
> >>+    tcet->page_shift = page_shift;
> >>+    tcet->nb_table = nb_table;
> >>+    tcet->need_vfio = need_vfio;
> >>+
> >>+    spapr_tce_table_do_enable(tcet);
> >>+}
> >>+
> >>+static void spapr_tce_table_disable(sPAPRTCETable *tcet)
> >>+{
> >>+    if (!tcet->enabled) {
> 
> ...and
> 
> error_report("Warning: trying to disable already disabled TCE table");

That sounds good.

> or g_assert()?

Erm.. only if this can't be triggered by user actions.

-- 
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 --]

  reply	other threads:[~2016-03-15  6:29 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01  9:10 [Qemu-devel] [PATCH qemu v13 00/16] spapr: vfio: Enable Dynamic DMA windows (DDW) Alexey Kardashevskiy
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 01/16] memory: Fix IOMMU replay base address Alexey Kardashevskiy
2016-03-03  1:34   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 02/16] spapr_pci: Move DMA window enablement to a helper Alexey Kardashevskiy
2016-03-03  1:40   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-10  5:47     ` Alexey Kardashevskiy
2016-03-15  5:30       ` David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 03/16] spapr_iommu: Move table allocation to helpers Alexey Kardashevskiy
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 04/16] spapr_iommu: Introduce "enabled" state for TCE table Alexey Kardashevskiy
2016-03-03  3:00   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-10  7:39     ` Alexey Kardashevskiy
2016-03-15  5:32       ` David Gibson [this message]
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 05/16] spapr_iommu: Add root memory region Alexey Kardashevskiy
2016-03-04  4:08   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 06/16] spapr_pci: Reset DMA config on PHB reset Alexey Kardashevskiy
2016-03-03  3:02   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 07/16] vfio, memory: Notify IOMMU about starting/stopping being used by VFIO Alexey Kardashevskiy
2016-03-03  5:28   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-03  6:01     ` Alexey Kardashevskiy
2016-03-04  4:01       ` David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 08/16] memory: Add reporting of supported page sizes Alexey Kardashevskiy
2016-03-03  5:33   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 09/16] vfio: Generalize IOMMU memory listener Alexey Kardashevskiy
2016-03-03  5:36   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-03  6:07     ` Alexey Kardashevskiy
2016-03-04  3:44       ` David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 10/16] vfio: Use different page size for different IOMMU types Alexey Kardashevskiy
2016-03-03  6:08   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 11/16] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering) Alexey Kardashevskiy
2016-03-03  6:30   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-15  2:53     ` Alexey Kardashevskiy
2016-03-15  5:42       ` David Gibson
2016-03-17  5:04         ` Alexey Kardashevskiy
2016-03-17  6:10           ` David Gibson
2016-03-17  9:23             ` Alexey Kardashevskiy
2016-03-21  4:53               ` David Gibson
2016-03-21  6:08                 ` Alexey Kardashevskiy
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 12/16] vmstate: Define VARRAY with VMS_ALLOC Alexey Kardashevskiy
2016-03-03  6:31   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 13/16] spapr_iommu: Remove need_vfio flag from sPAPRTCETable Alexey Kardashevskiy
2016-03-03  6:38   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 14/16] spapr_pci: Add and export DMA resetting helper Alexey Kardashevskiy
2016-03-03  6:39   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 15/16] vfio: Move iova_pgsizes from container to guest IOMMU Alexey Kardashevskiy
2016-03-03 11:22   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-04  0:02     ` Alexey Kardashevskiy
2016-03-01  9:10 ` [Qemu-devel] [PATCH qemu v13 16/16] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) Alexey Kardashevskiy
2016-03-04  4:51   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-11  9:03     ` Alexey Kardashevskiy
2016-03-15  5:53       ` David Gibson

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=20160315053214.GG15272@voom.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=alex.williamson@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 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).