qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Alexander Graf <agraf@suse.de>,
	Michael Roth <mdroth@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org,
	Alex Williamson <alex.williamson@redhat.com>,
	qemu-ppc@nongnu.org, David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH qemu v7 06/14] spapr_iommu: Introduce "enabled" state for TCE table
Date: Tue, 26 May 2015 01:05:56 +1000	[thread overview]
Message-ID: <55633A54.8080807@ozlabs.ru> (raw)
In-Reply-To: <1429964684-23872-7-git-send-email-aik@ozlabs.ru>

Hi Paolo,

I have had a conversation with Mike and it turns out I am not allowed to 
create/remove memory regions dynamically (docs/memory.txt:101); otherwise 
"destroying regions during reset causes assertion in RCU thread during 
PHB/IOMMU unplug/unparent". Is it because patch just missing some 
unref()/unparent() call or it is totally wrong and I have to implement 
subregions (on a PCI bus address space) myself if I want dynamic DMA 
windows? Thanks!




On 04/25/2015 10:24 PM, Alexey Kardashevskiy wrote:
> Currently TCE tables are created once at start and their size never
> changes. 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 stub object. 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 and allocates
> a guest view of the TCE table (in the user space or KVM).
> spapr_tce_table_disable() disposes the table.
>
> Follow up patches will disable+enable tables on reset (system reset
> or DDW 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 migration 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 has all the properties set after the migration.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> Changes:
> v7:
> * s'tmp[64]'tmp[32]' as we need less than 64bytes and more than 16 bytes
> and 32 is the closest power-of-two (just looks nices to have power-of-two
> values)
> * updated commit log about having spapr_tce_table_do_enable() splitted
> from spapr_tce_table_enable()
>
> v6:
> * got rid of set_props()
> ---
>   hw/ppc/spapr_iommu.c    | 104 +++++++++++++++++++++++++++++++-----------------
>   hw/ppc/spapr_pci.c      |  16 +++++---
>   hw/ppc/spapr_pci_vfio.c |  10 ++---
>   hw/ppc/spapr_vio.c      |   9 ++---
>   include/hw/ppc/spapr.h  |  11 ++---
>   5 files changed, 93 insertions(+), 57 deletions(-)
>
> diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
> index a14cdc4..a3f2b83 100644
> --- a/hw/ppc/spapr_iommu.c
> +++ b/hw/ppc/spapr_iommu.c
> @@ -126,8 +126,47 @@ static MemoryRegionIOMMUOps spapr_iommu_ops = {
>   static int spapr_tce_table_realize(DeviceState *dev)
>   {
>       sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev);
> +
> +    QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list);
> +
> +    vmstate_register(DEVICE(tcet), tcet->liobn, &vmstate_spapr_tce_table,
> +                     tcet);
> +
> +    return 0;
> +}
> +
> +sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn)
> +{
> +    sPAPRTCETable *tcet;
> +    char tmp[32];
> +
> +    if (spapr_tce_find_by_liobn(liobn)) {
> +        fprintf(stderr, "Attempted to create TCE table with duplicate"
> +                " LIOBN 0x%x\n", liobn);
> +        return NULL;
> +    }
> +
> +    tcet = SPAPR_TCE_TABLE(object_new(TYPE_SPAPR_TCE_TABLE));
> +    tcet->liobn = liobn;
> +
> +    snprintf(tmp, sizeof(tmp), "tce-table-%x", liobn);
> +    object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL);
> +
> +    object_property_set_bool(OBJECT(tcet), true, "realized", NULL);
> +
> +    trace_spapr_iommu_new_table(tcet->liobn, tcet, tcet->table, tcet->fd);
> +
> +    return tcet;
> +}
> +
> +static void spapr_tce_table_do_enable(sPAPRTCETable *tcet)
> +{
>       uint64_t window_size = (uint64_t)tcet->nb_table << tcet->page_shift;
>
> +    if (!tcet->nb_table) {
> +        return;
> +    }
> +
>       if (kvm_enabled() && !(window_size >> 32)) {
>           tcet->table = kvmppc_create_spapr_tce(tcet->liobn,
>                                                 window_size,
> @@ -140,65 +179,56 @@ static int spapr_tce_table_realize(DeviceState *dev)
>           tcet->table = g_malloc0(table_size);
>       }
>
> -    trace_spapr_iommu_new_table(tcet->liobn, tcet, tcet->table, tcet->fd);
> -
> -    memory_region_init_iommu(&tcet->iommu, OBJECT(dev), &spapr_iommu_ops,
> +    memory_region_init_iommu(&tcet->iommu, OBJECT(tcet), &spapr_iommu_ops,
>                                "iommu-spapr",
>                                (uint64_t)tcet->nb_table << tcet->page_shift);
>
> -    QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list);
> -
> -    vmstate_register(DEVICE(tcet), tcet->liobn, &vmstate_spapr_tce_table,
> -                     tcet);
> -
> -    return 0;
> +    tcet->enabled = true;
>   }
>
> -sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
> -                                   uint64_t bus_offset,
> -                                   uint32_t page_shift,
> -                                   uint32_t nb_table,
> -                                   bool vfio_accel)
> +void spapr_tce_table_enable(sPAPRTCETable *tcet,
> +                            uint64_t bus_offset, uint32_t page_shift,
> +                            uint32_t nb_table, bool vfio_accel)
>   {
> -    sPAPRTCETable *tcet;
> -    char tmp[64];
> -
> -    if (spapr_tce_find_by_liobn(liobn)) {
> -        fprintf(stderr, "Attempted to create TCE table with duplicate"
> -                " LIOBN 0x%x\n", liobn);
> -        return NULL;
> -    }
> -
> -    if (!nb_table) {
> -        return NULL;
> +    if (tcet->enabled) {
> +        return;
>       }
>
> -    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->vfio_accel = vfio_accel;
>
> -    snprintf(tmp, sizeof(tmp), "tce-table-%x", liobn);
> -    object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL);
> -
> -    object_property_set_bool(OBJECT(tcet), true, "realized", NULL);
> -
> -    return tcet;
> +    spapr_tce_table_do_enable(tcet);
>   }
>
> -static void spapr_tce_table_unrealize(DeviceState *dev, Error **errp)
> +void spapr_tce_table_disable(sPAPRTCETable *tcet)
>   {
> -    sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev);
> -
> -    QLIST_REMOVE(tcet, list);
> +    if (!tcet->enabled) {
> +        return;
> +    }
>
>       if (!kvm_enabled() ||
>           (kvmppc_remove_spapr_tce(tcet->table, tcet->fd,
>                                    tcet->nb_table) != 0)) {
> +        tcet->fd = -1;
>           g_free(tcet->table);
>       }
> +    tcet->table = NULL;
> +    tcet->enabled = false;
> +    tcet->bus_offset = 0;
> +    tcet->page_shift = 0;
> +    tcet->nb_table = 0;
> +    tcet->vfio_accel = false;
> +}
> +
> +static void spapr_tce_table_unrealize(DeviceState *dev, Error **errp)
> +{
> +    sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev);
> +
> +    QLIST_REMOVE(tcet, list);
> +
> +    spapr_tce_table_disable(tcet);
>   }
>
>   MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet)
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 8c0d2eb..c3410b8 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -881,6 +881,12 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>           sphb->lsi_table[i].irq = irq;
>       }
>
> +    tcet = spapr_tce_new_table(DEVICE(sphb), sphb->dma_liobn);
> +    if (!tcet) {
> +            error_setg(errp, "failed to create TCE table");
> +            return;
> +    }
> +
>       info->dma_capabilities_update(sphb);
>       info->dma_init_window(sphb, sphb->dma_liobn, SPAPR_TCE_PAGE_SHIFT,
>                             sphb->dma32_window_size);
> @@ -908,13 +914,13 @@ static int spapr_phb_dma_init_window(sPAPRPHBState *sphb,
>                                        uint64_t window_size)
>   {
>       uint64_t bus_offset = sphb->dma32_window_start;
> -    sPAPRTCETable *tcet;
> +    sPAPRTCETable *tcet = spapr_tce_find_by_liobn(liobn);
>
> -    tcet = spapr_tce_new_table(DEVICE(sphb), liobn, bus_offset, page_shift,
> -                               window_size >> page_shift,
> -                               false);
> +    spapr_tce_table_enable(tcet, bus_offset, page_shift,
> +                           window_size >> page_shift,
> +                           false);
>
> -    return tcet ? 0 : -1;
> +    return 0;
>   }
>
>   static int spapr_phb_children_reset(Object *child, void *opaque)
> diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
> index f1dd28c..a5b97d0 100644
> --- a/hw/ppc/spapr_pci_vfio.c
> +++ b/hw/ppc/spapr_pci_vfio.c
> @@ -49,13 +49,13 @@ static int spapr_phb_vfio_dma_init_window(sPAPRPHBState *sphb,
>                                             uint64_t window_size)
>   {
>       uint64_t bus_offset = sphb->dma32_window_start;
> -    sPAPRTCETable *tcet;
> +    sPAPRTCETable *tcet = spapr_tce_find_by_liobn(liobn);
>
> -    tcet = spapr_tce_new_table(DEVICE(sphb), liobn, bus_offset, page_shift,
> -                               window_size >> page_shift,
> -                               true);
> +    spapr_tce_table_enable(tcet, bus_offset, page_shift,
> +                           window_size >> page_shift,
> +                           true);
>
> -    return tcet ? 0 : -1;
> +    return 0;
>   }
>
>   static void spapr_phb_vfio_reset(DeviceState *qdev)
> diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
> index 174033d..3e28835 100644
> --- a/hw/ppc/spapr_vio.c
> +++ b/hw/ppc/spapr_vio.c
> @@ -479,11 +479,10 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
>           memory_region_add_subregion_overlap(&dev->mrroot, 0, &dev->mrbypass, 1);
>           address_space_init(&dev->as, &dev->mrroot, qdev->id);
>
> -        dev->tcet = spapr_tce_new_table(qdev, liobn,
> -                                        0,
> -                                        SPAPR_TCE_PAGE_SHIFT,
> -                                        pc->rtce_window_size >>
> -                                        SPAPR_TCE_PAGE_SHIFT, false);
> +        dev->tcet = spapr_tce_new_table(qdev, liobn);
> +        spapr_tce_table_enable(dev->tcet, 0, SPAPR_TCE_PAGE_SHIFT,
> +                               pc->rtce_window_size >> SPAPR_TCE_PAGE_SHIFT,
> +                               false);
>           dev->tcet->vdev = dev;
>           memory_region_add_subregion_overlap(&dev->mrroot, 0,
>                                               spapr_tce_get_iommu(dev->tcet), 2);
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index 7d9ab9d..074d837 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -498,6 +498,7 @@ typedef struct sPAPRTCETable sPAPRTCETable;
>
>   struct sPAPRTCETable {
>       DeviceState parent;
> +    bool enabled;
>       uint32_t liobn;
>       uint32_t nb_table;
>       uint64_t bus_offset;
> @@ -515,11 +516,11 @@ sPAPRTCETable *spapr_tce_find_by_liobn(uint32_t liobn);
>   void spapr_events_init(sPAPREnvironment *spapr);
>   void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
>   int spapr_h_cas_compose_response(target_ulong addr, target_ulong size);
> -sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
> -                                   uint64_t bus_offset,
> -                                   uint32_t page_shift,
> -                                   uint32_t nb_table,
> -                                   bool vfio_accel);
> +sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn);
> +void spapr_tce_table_enable(sPAPRTCETable *tcet,
> +                            uint64_t bus_offset, uint32_t page_shift,
> +                            uint32_t nb_table, bool vfio_accel);
> +void spapr_tce_table_disable(sPAPRTCETable *tcet);
>   MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet);
>   int spapr_dma_dt(void *fdt, int node_off, const char *propname,
>                    uint32_t liobn, uint64_t window, uint32_t size);
>


-- 
Alexey

  parent reply	other threads:[~2015-05-25 15:06 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-25 12:24 [Qemu-devel] [PATCH qemu v7 00/14] spapr: vfio: Enable Dynamic DMA windows (DDW) Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 01/14] spapr_pci: Finish making find_phb()/find_dev() public Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 02/14] vmstate: Define VARRAY with VMS_ALLOC Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 03/14] vfio: spapr: Move SPAPR-related code to a separate file Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 04/14] spapr_pci_vfio: Enable multiple groups per container Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 05/14] spapr_pci: Convert finish_realize() to dma_capabilities_update()+dma_init_window() Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 06/14] spapr_iommu: Introduce "enabled" state for TCE table Alexey Kardashevskiy
2015-05-05 12:28   ` David Gibson
2015-05-25 15:05   ` Alexey Kardashevskiy [this message]
2015-05-26  2:46     ` David Gibson
2015-05-26  8:58       ` Paolo Bonzini
2015-05-26  9:01         ` Alexander Graf
2015-05-26  9:16           ` Paolo Bonzini
2015-05-26 10:15         ` Alexey Kardashevskiy
2015-05-26 10:16           ` Paolo Bonzini
2015-05-26 12:33             ` Alexey Kardashevskiy
2015-05-26 12:50               ` Paolo Bonzini
2015-05-26 13:28                 ` Alexey Kardashevskiy
2015-05-26 13:31                   ` Paolo Bonzini
2015-05-26 13:42                     ` Alexey Kardashevskiy
2015-05-26 13:48                       ` Paolo Bonzini
2015-05-26 14:00                         ` Alexey Kardashevskiy
2015-05-26 14:03                           ` Paolo Bonzini
2015-05-26 14:17                             ` Alexey Kardashevskiy
2015-05-26 14:24                               ` Paolo Bonzini
2015-05-26 14:55                                 ` Michael Roth
2015-05-26 14:58                                   ` Paolo Bonzini
2015-05-26 15:49                                     ` Alexey Kardashevskiy
2015-05-26 15:51                                       ` Paolo Bonzini
2015-05-26 23:55                                         ` Alexey Kardashevskiy
2015-05-27  7:05                                           ` Paolo Bonzini
2015-07-04  1:12                                             ` Alexey Kardashevskiy
2015-07-06  0:52                                               ` Alexey Kardashevskiy
2015-07-06 11:16                                               ` Paolo Bonzini
2015-05-26 15:00                                 ` Alexey Kardashevskiy
2015-05-26 15:08                                   ` Paolo Bonzini
2015-05-26 15:49                                     ` Alexey Kardashevskiy
2015-05-26 14:36                               ` Michael Roth
2015-05-27  2:54         ` David Gibson
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 07/14] spapr_iommu: Add root memory region Alexey Kardashevskiy
2015-05-05 12:31   ` David Gibson
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 08/14] spapr_pci: Do complete reset of DMA config when resetting PHB Alexey Kardashevskiy
2015-05-05 12:34   ` David Gibson
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 09/14] spapr_vfio_pci: Remove redundant spapr-pci-vfio-host-bridge Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 10/14] linux headers update for DDW on SPAPR Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 11/14] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering) Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 12/14] spapr: Add pseries-2.4 machine Alexey Kardashevskiy
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 13/14] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) Alexey Kardashevskiy
2015-05-05 12:49   ` David Gibson
2015-06-18 11:35     ` Alexey Kardashevskiy
2015-06-19  1:45       ` David Gibson
2015-06-19  6:49         ` Markus Armbruster
2015-06-22  2:00           ` David Gibson
2015-04-25 12:24 ` [Qemu-devel] [PATCH qemu v7 14/14] vfio: Enable DDW ioctls to VFIO IOMMU driver Alexey Kardashevskiy
2015-05-05 12:50   ` David Gibson
2015-05-05  9:30 ` [Qemu-devel] [PATCH qemu v7 00/14] spapr: vfio: Enable 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=55633A54.8080807@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=agraf@suse.de \
    --cc=alex.williamson@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=mdroth@linux.vnet.ibm.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 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).