[{"id":1764939,"web_url":"http://patchwork.ozlabs.org/comment/1764939/","msgid":"<7aa3f6a4-b4d7-5b04-1bb4-2c766b8de355@amsat.org>","list_archive_url":null,"date":"2017-09-07T20:53:31","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":70924,"url":"http://patchwork.ozlabs.org/api/people/70924/","name":"Philippe Mathieu-Daudé","email":"f4bug@amsat.org"},"content":"On 09/07/2017 06:20 AM, Alexey Kardashevskiy wrote:\n> This allows sharing flat views between address spaces when the same root\n> memory region is used when creating a new address space.\n> \n> This adds a global list of flat views and a list of attached address\n> spaces per a flat view. Each address space references a flat view.\n> \n> This hard codes the dispatch tree building instead of doing so via\n> a memory listener.\n> \n> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>\n> ---\n> \n> This was suggested by Paolo in\n> https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg05011.html\n> \n> I am not putting \"Suggested-by\" as I want to make sure that this is doing\n> what was actually suggested.\n> ---\n>   include/exec/memory-internal.h |   6 +-\n>   include/exec/memory.h          |   9 +-\n>   exec.c                         |  58 ++--------\n>   hw/pci/pci.c                   |   3 +-\n>   memory.c                       | 253 +++++++++++++++++++++++++++--------------\n>   5 files changed, 187 insertions(+), 142 deletions(-)\n> \n> diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h\n> index fb467acdba..8516e0b48f 100644\n> --- a/include/exec/memory-internal.h\n> +++ b/include/exec/memory-internal.h\n> @@ -22,9 +22,11 @@\n>   #ifndef CONFIG_USER_ONLY\n>   typedef struct AddressSpaceDispatch AddressSpaceDispatch;\n>   \n> -void address_space_init_dispatch(AddressSpace *as);\n>   void address_space_unregister(AddressSpace *as);\n> -void address_space_destroy_dispatch(AddressSpace *as);\n> +void address_space_dispatch_free(AddressSpaceDispatch *d);\n> +AddressSpaceDispatch *mem_begin(void);\n> +void mem_commit(AddressSpaceDispatch *d);\n> +void mem_add(AddressSpaceDispatch *d, MemoryRegionSection *section);\n>   \n>   extern const MemoryRegionOps unassigned_mem_ops;\n>   \n> diff --git a/include/exec/memory.h b/include/exec/memory.h\n> index 83e82e90d5..41ab165302 100644\n> --- a/include/exec/memory.h\n> +++ b/include/exec/memory.h\n> @@ -27,6 +27,7 @@\n>   #include \"qemu/rcu.h\"\n>   #include \"hw/qdev-core.h\"\n>   \n> +typedef struct AddressSpaceDispatch AddressSpaceDispatch;\n>   #define RAM_ADDR_INVALID (~(ram_addr_t)0)\n>   \n>   #define MAX_PHYS_ADDR_SPACE_BITS 62\n> @@ -312,6 +313,7 @@ struct MemoryListener {\n>   };\n>   \n>   AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as);\n> +MemoryRegion *address_space_root(AddressSpace *as);\n>   \n>   /**\n>    * AddressSpace: describes a mapping of addresses to #MemoryRegion objects\n> @@ -320,20 +322,17 @@ struct AddressSpace {\n>       /* All fields are private. */\n>       struct rcu_head rcu;\n>       char *name;\n> -    MemoryRegion *root;\n> -    int ref_count;\n> -    bool malloced;\n>   \n>       /* Accessed via RCU.  */\n>       struct FlatView *current_map;\n>   \n>       int ioeventfd_nb;\n>       struct MemoryRegionIoeventfd *ioeventfds;\n> -    struct AddressSpaceDispatch *dispatch;\n> -    struct AddressSpaceDispatch *next_dispatch;\n> +\n>       MemoryListener dispatch_listener;\n>       QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners;\n>       QTAILQ_ENTRY(AddressSpace) address_spaces_link;\n> +    QTAILQ_ENTRY(AddressSpace) flat_view_link;\n>   };\n>   \n>   /**\n> diff --git a/exec.c b/exec.c\n> index 66f01f5fce..51243f57f4 100644\n> --- a/exec.c\n> +++ b/exec.c\n> @@ -188,15 +188,12 @@ typedef struct PhysPageMap {\n>   } PhysPageMap;\n>   \n>   struct AddressSpaceDispatch {\n> -    struct rcu_head rcu;\n> -\n>       MemoryRegionSection *mru_section;\n>       /* This is a multi-level map on the physical address space.\n>        * The bottom level has pointers to MemoryRegionSections.\n>        */\n>       PhysPageEntry phys_map;\n>       PhysPageMap map;\n> -    AddressSpace *as;\n>   };\n>   \n>   typedef struct AddressSpaceDispatch AddressSpaceDispatch;\n> @@ -240,11 +237,6 @@ struct DirtyBitmapSnapshot {\n>       unsigned long dirty[];\n>   };\n>   \n> -AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)\n> -{\n> -    return atomic_rcu_read(&as->dispatch);\n> -}\n> -\n>   #endif\n>   \n>   #if !defined(CONFIG_USER_ONLY)\n> @@ -1354,10 +1346,8 @@ static void register_multipage(AddressSpaceDispatch *d,\n>       phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_index);\n>   }\n>   \n> -static void mem_add(MemoryListener *listener, MemoryRegionSection *section)\n> +void mem_add(AddressSpaceDispatch *d, MemoryRegionSection *section)\n>   {\n> -    AddressSpace *as = container_of(listener, AddressSpace, dispatch_listener);\n> -    AddressSpaceDispatch *d = as->next_dispatch;\n>       MemoryRegionSection now = *section, remain = *section;\n>       Int128 page_size = int128_make64(TARGET_PAGE_SIZE);\n>   \n> @@ -2680,9 +2670,8 @@ static void io_mem_init(void)\n>                             NULL, UINT64_MAX);\n>   }\n>   \n> -static void mem_begin(MemoryListener *listener)\n> +AddressSpaceDispatch *mem_begin(void)\n>   {\n> -    AddressSpace *as = container_of(listener, AddressSpace, dispatch_listener);\n>       AddressSpaceDispatch *d = g_new0(AddressSpaceDispatch, 1);\n>       uint16_t n;\n>   \n> @@ -2696,27 +2685,19 @@ static void mem_begin(MemoryListener *listener)\n>       assert(n == PHYS_SECTION_WATCH);\n>   \n>       d->phys_map  = (PhysPageEntry) { .ptr = PHYS_MAP_NODE_NIL, .skip = 1 };\n> -    as->next_dispatch = d;\n> +\n> +    return d;\n>   }\n>   \n> -static void address_space_dispatch_free(AddressSpaceDispatch *d)\n> +void address_space_dispatch_free(AddressSpaceDispatch *d)\n>   {\n>       phys_sections_free(&d->map);\n>       g_free(d);\n>   }\n>   \n> -static void mem_commit(MemoryListener *listener)\n> +void mem_commit(AddressSpaceDispatch *d)\n>   {\n> -    AddressSpace *as = container_of(listener, AddressSpace, dispatch_listener);\n> -    AddressSpaceDispatch *cur = as->dispatch;\n> -    AddressSpaceDispatch *next = as->next_dispatch;\n> -\n> -    phys_page_compact_all(next, next->map.nodes_nb);\n> -\n> -    atomic_rcu_set(&as->dispatch, next);\n> -    if (cur) {\n> -        call_rcu(cur, address_space_dispatch_free, rcu);\n> -    }\n> +    phys_page_compact_all(d, d->map.nodes_nb);\n>   }\n>   \n>   static void tcg_commit(MemoryListener *listener)\n> @@ -2732,39 +2713,16 @@ static void tcg_commit(MemoryListener *listener)\n>        * We reload the dispatch pointer now because cpu_reloading_memory_map()\n>        * may have split the RCU critical section.\n>        */\n> -    d = atomic_rcu_read(&cpuas->as->dispatch);\n> +    d = address_space_to_dispatch(cpuas->as);\n>       atomic_rcu_set(&cpuas->memory_dispatch, d);\n>       tlb_flush(cpuas->cpu);\n>   }\n>   \n> -void address_space_init_dispatch(AddressSpace *as)\n> -{\n> -    as->dispatch = NULL;\n> -    as->dispatch_listener = (MemoryListener) {\n> -        .begin = mem_begin,\n> -        .commit = mem_commit,\n> -        .region_add = mem_add,\n> -        .region_nop = mem_add,\n> -        .priority = 0,\n> -    };\n> -    memory_listener_register(&as->dispatch_listener, as);\n> -}\n> -\n>   void address_space_unregister(AddressSpace *as)\n>   {\n>       memory_listener_unregister(&as->dispatch_listener);\n>   }\n>   \n> -void address_space_destroy_dispatch(AddressSpace *as)\n> -{\n> -    AddressSpaceDispatch *d = as->dispatch;\n> -\n> -    atomic_rcu_set(&as->dispatch, NULL);\n> -    if (d) {\n> -        call_rcu(d, address_space_dispatch_free, rcu);\n> -    }\n> -}\n> -\n>   static void memory_map_init(void)\n>   {\n>       system_memory = g_malloc(sizeof(*system_memory));\n> diff --git a/hw/pci/pci.c b/hw/pci/pci.c\n> index 258fbe51e2..86b9e419fd 100644\n> --- a/hw/pci/pci.c\n> +++ b/hw/pci/pci.c\n> @@ -88,7 +88,8 @@ static void pci_init_bus_master(PCIDevice *pci_dev)\n>   \n>       memory_region_init_alias(&pci_dev->bus_master_enable_region,\n>                                OBJECT(pci_dev), \"bus master\",\n> -                             dma_as->root, 0, memory_region_size(dma_as->root));\n> +                             address_space_root(dma_as), 0,\n> +                             memory_region_size(address_space_root(dma_as)));\n>       memory_region_set_enabled(&pci_dev->bus_master_enable_region, false);\n>       memory_region_add_subregion(&pci_dev->bus_master_container_region, 0,\n>                                   &pci_dev->bus_master_enable_region);\n> diff --git a/memory.c b/memory.c\n> index c6904a7deb..385a507511 100644\n> --- a/memory.c\n> +++ b/memory.c\n> @@ -47,6 +47,9 @@ static QTAILQ_HEAD(memory_listeners, MemoryListener) memory_listeners\n>   static QTAILQ_HEAD(, AddressSpace) address_spaces\n>       = QTAILQ_HEAD_INITIALIZER(address_spaces);\n>   \n> +static QTAILQ_HEAD(FlatViewList, FlatView) flat_views\n> +    = QTAILQ_HEAD_INITIALIZER(flat_views);\n> +\n>   typedef struct AddrRange AddrRange;\n>   \n>   /*\n> @@ -230,6 +233,11 @@ struct FlatView {\n>       FlatRange *ranges;\n>       unsigned nr;\n>       unsigned nr_allocated;\n> +    MemoryRegion *root;\n> +    struct AddressSpaceDispatch *dispatch;\n> +\n> +    QTAILQ_ENTRY(FlatView) flat_views_link;\n> +    QTAILQ_HEAD(address_spaces, AddressSpace) address_spaces;\n>   };\n>   \n>   typedef struct AddressSpaceOps AddressSpaceOps;\n> @@ -259,12 +267,19 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b)\n>           && a->readonly == b->readonly;\n>   }\n>   \n> -static void flatview_init(FlatView *view)\n> +static void flatview_ref(FlatView *view);\n> +\n> +static FlatView *flatview_alloc(MemoryRegion *mr_root)\n>   {\n> +    FlatView *view;\n> +\n> +    view = g_new0(FlatView, 1);\n>       view->ref = 1;\n> -    view->ranges = NULL;\n> -    view->nr = 0;\n> -    view->nr_allocated = 0;\n> +    view->root = mr_root;\n> +    memory_region_ref(mr_root);\n> +    QTAILQ_INIT(&view->address_spaces);\n> +\n> +    return view;\n>   }\n>   \n>   /* Insert a range into a given position.  Caller is responsible for maintaining\n> @@ -292,6 +307,10 @@ static void flatview_destroy(FlatView *view)\n>           memory_region_unref(view->ranges[i].mr);\n>       }\n>       g_free(view->ranges);\n> +    if (view->dispatch) {\n> +        address_space_dispatch_free(view->dispatch);\n> +    }\n> +    memory_region_unref(view->root);\n>       g_free(view);\n>   }\n>   \n> @@ -303,7 +322,7 @@ static void flatview_ref(FlatView *view)\n>   static void flatview_unref(FlatView *view)\n>   {\n>       if (atomic_fetch_dec(&view->ref) == 1) {\n> -        flatview_destroy(view);\n> +        call_rcu(view, flatview_destroy, rcu);\n>       }\n>   }\n>   \n> @@ -608,7 +627,7 @@ static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)\n>           mr = mr->container;\n>       }\n>       QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {\n> -        if (mr == as->root) {\n> +        if (mr == as->current_map->root) {\n>               return as;\n>           }\n>       }\n> @@ -702,23 +721,6 @@ static void render_memory_region(FlatView *view,\n>       }\n>   }\n>   \n> -/* Render a memory topology into a list of disjoint absolute ranges. */\n> -static FlatView *generate_memory_topology(MemoryRegion *mr)\n> -{\n> -    FlatView *view;\n> -\n> -    view = g_new(FlatView, 1);\n> -    flatview_init(view);\n> -\n> -    if (mr) {\n> -        render_memory_region(view, mr, int128_zero(),\n> -                             addrrange_make(int128_zero(), int128_2_64()), false);\n> -    }\n> -    flatview_simplify(view);\n> -\n> -    return view;\n> -}\n> -\n>   static void address_space_add_del_ioeventfds(AddressSpace *as,\n>                                                MemoryRegionIoeventfd *fds_new,\n>                                                unsigned fds_new_nb,\n> @@ -769,12 +771,10 @@ static void address_space_add_del_ioeventfds(AddressSpace *as,\n>       }\n>   }\n>   \n> -static FlatView *address_space_get_flatview(AddressSpace *as)\n> +static FlatView *flatview_get(FlatView *view)\n>   {\n> -    FlatView *view;\n> -\n>       rcu_read_lock();\n> -    view = atomic_rcu_read(&as->current_map);\n> +    view = atomic_rcu_read(&view);\n>       flatview_ref(view);\n>       rcu_read_unlock();\n>       return view;\n> @@ -789,7 +789,7 @@ static void address_space_update_ioeventfds(AddressSpace *as)\n>       AddrRange tmp;\n>       unsigned i;\n>   \n> -    view = address_space_get_flatview(as);\n> +    view = flatview_get(as->current_map);\n>       FOR_EACH_FLAT_RANGE(fr, view) {\n>           for (i = 0; i < fr->mr->ioeventfd_nb; ++i) {\n>               tmp = addrrange_shift(fr->mr->ioeventfds[i].addr,\n> @@ -881,28 +881,89 @@ static void address_space_update_topology_pass(AddressSpace *as,\n>       }\n>   }\n>   \n> -\n> -static void address_space_update_topology(AddressSpace *as)\n> +static FlatView *address_space_update_flatview(FlatView *view)\n>   {\n> -    FlatView *old_view = address_space_get_flatview(as);\n> -    FlatView *new_view = generate_memory_topology(as->root);\n> +    AddressSpace *as, *asnext;\n> +    FlatView *old_view = flatview_get(view);\n> +    MemoryRegion *root = old_view->root;\n> +    FlatView *new_view = flatview_alloc(root);\n> +    unsigned iold, inew;\n> +    FlatRange *frold, *frnew;\n>   \n> -    address_space_update_topology_pass(as, old_view, new_view, false);\n> -    address_space_update_topology_pass(as, old_view, new_view, true);\n> +    if (root) {\n> +        render_memory_region(new_view, root, int128_zero(),\n> +                             addrrange_make(int128_zero(), int128_2_64()),\n> +                             false);\n> +        flatview_simplify(new_view);\n> +    }\n>   \n> -    /* Writes are protected by the BQL.  */\n> -    atomic_rcu_set(&as->current_map, new_view);\n> -    call_rcu(old_view, flatview_unref, rcu);\n> +    new_view->dispatch = mem_begin();\n>   \n> -    /* Note that all the old MemoryRegions are still alive up to this\n> -     * point.  This relieves most MemoryListeners from the need to\n> -     * ref/unref the MemoryRegions they get---unless they use them\n> -     * outside the iothread mutex, in which case precise reference\n> -     * counting is necessary.\n> +    /*\n> +     * FIXME: this is cut-n-paste from address_space_update_topology_pass,\n> +     * simplify it\n>        */\n> +    iold = inew = 0;\n> +    while (iold < old_view->nr || inew < new_view->nr) {\n> +        if (iold < old_view->nr) {\n> +            frold = &old_view->ranges[iold];\n> +        } else {\n> +            frold = NULL;\n> +        }\n> +        if (inew < new_view->nr) {\n> +            frnew = &new_view->ranges[inew];\n> +        } else {\n> +            frnew = NULL;\n> +        }\n> +\n> +        if (frold\n> +            && (!frnew\n> +                || int128_lt(frold->addr.start, frnew->addr.start)\n> +                || (int128_eq(frold->addr.start, frnew->addr.start)\n> +                    && !flatrange_equal(frold, frnew)))) {\n> +            ++iold;\n> +        } else if (frold && frnew && flatrange_equal(frold, frnew)) {\n> +            /* In both and unchanged (except logging may have changed) */\n> +            MemoryRegionSection mrs = section_from_flat_range(frnew,\n> +                    new_view->dispatch);\n> +\n> +            mem_add(new_view->dispatch, &mrs);\n> +\n> +            ++iold;\n> +            ++inew;\n> +        } else {\n> +            /* In new */\n> +            MemoryRegionSection mrs = section_from_flat_range(frnew,\n> +                    new_view->dispatch);\n> +\n> +            mem_add(new_view->dispatch, &mrs);\n> +\n> +            ++inew;\n> +        }\n> +    }\n> +\n> +    mem_commit(new_view->dispatch);\n> +\n> +    QTAILQ_FOREACH(as, &old_view->address_spaces, flat_view_link) {\n> +        address_space_update_topology_pass(as, old_view, new_view, false);\n> +        address_space_update_topology_pass(as, old_view, new_view, true);\n> +    }\n> +\n> +    QTAILQ_FOREACH_SAFE(as, &old_view->address_spaces, flat_view_link, asnext) {\n> +        QTAILQ_REMOVE(&old_view->address_spaces, as, flat_view_link);\n> +        flatview_unref(old_view);\n> +\n> +        atomic_rcu_set(&as->current_map, new_view);\n> +\n> +        flatview_ref(new_view);\n> +        QTAILQ_INSERT_TAIL(&new_view->address_spaces, as, flat_view_link);\n> +\n> +        address_space_update_ioeventfds(as);\n> +    }\n> +\n>       flatview_unref(old_view);\n>   \n> -    address_space_update_ioeventfds(as);\n> +    return new_view;\n>   }\n>   \n>   void memory_region_transaction_begin(void)\n> @@ -921,11 +982,31 @@ void memory_region_transaction_commit(void)\n>       --memory_region_transaction_depth;\n>       if (!memory_region_transaction_depth) {\n>           if (memory_region_update_pending) {\n> +            FlatView *view, *vnext;\n> +            struct FlatViewList fwstmp = QTAILQ_HEAD_INITIALIZER(fwstmp);\n> +\n>               MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);\n>   \n> -            QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {\n> -                address_space_update_topology(as);\n> +            QTAILQ_FOREACH_SAFE(view, &flat_views, flat_views_link, vnext) {\n> +                FlatView *old_view, *new_view;\n> +\n> +                old_view = flatview_get(view);\n> +                new_view = address_space_update_flatview(old_view);\n> +\n> +                QTAILQ_REMOVE(&flat_views, old_view, flat_views_link);\n> +                flatview_unref(old_view);\n> +                flatview_unref(old_view);\n> +\n> +                QTAILQ_INSERT_HEAD(&fwstmp, new_view, flat_views_link);\n> +\n> +                flatview_unref(new_view);\n>               }\n> +\n> +            QTAILQ_FOREACH_SAFE(view, &fwstmp, flat_views_link, vnext) {\n> +                QTAILQ_REMOVE(&fwstmp, view, flat_views_link);\n> +                QTAILQ_INSERT_HEAD(&flat_views, view, flat_views_link);\n> +            }\n> +\n>               memory_region_update_pending = false;\n>               MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);\n>           } else if (ioeventfd_update_pending) {\n> @@ -1834,7 +1915,7 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr)\n>               continue;\n>           }\n>           as = listener->address_space;\n> -        view = address_space_get_flatview(as);\n> +        view = flatview_get(as->current_map);\n>           FOR_EACH_FLAT_RANGE(fr, view) {\n>               if (fr->mr == mr) {\n>                   MemoryRegionSection mrs = section_from_flat_range(fr,\n> @@ -1938,7 +2019,7 @@ static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpa\n>       AddrRange tmp;\n>       MemoryRegionSection section;\n>   \n> -    view = address_space_get_flatview(as);\n> +    view = flatview_get(as->current_map);\n>       FOR_EACH_FLAT_RANGE(fr, view) {\n>           if (fr->mr == mr) {\n>               section = (MemoryRegionSection) {\n> @@ -2350,7 +2431,7 @@ void memory_global_dirty_log_sync(void)\n>               continue;\n>           }\n>           as = listener->address_space;\n> -        view = address_space_get_flatview(as);\n> +        view = flatview_get(as->current_map);\n>           FOR_EACH_FLAT_RANGE(fr, view) {\n>               if (fr->dirty_log_mask) {\n>                   MemoryRegionSection mrs = section_from_flat_range(fr,\n> @@ -2436,7 +2517,7 @@ static void listener_add_address_space(MemoryListener *listener,\n>           }\n>       }\n>   \n> -    view = address_space_get_flatview(as);\n> +    view = flatview_get(as->current_map);\n>       FOR_EACH_FLAT_RANGE(fr, view) {\n>           MemoryRegionSection section = {\n>               .mr = fr->mr,\n> @@ -2615,67 +2696,72 @@ void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset,\n>   \n>   void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)\n>   {\n> -    memory_region_ref(root);\n> -    memory_region_transaction_begin();\n> -    as->ref_count = 1;\n> -    as->root = root;\n> -    as->malloced = false;\n> -    as->current_map = g_new(FlatView, 1);\n> -    flatview_init(as->current_map);\n> +    FlatView *view;\n> +\n> +    as->current_map = NULL;\n>       as->ioeventfd_nb = 0;\n>       as->ioeventfds = NULL;\n>       QTAILQ_INIT(&as->listeners);\n>       QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);\n>       as->name = g_strdup(name ? name : \"anonymous\");\n> -    address_space_init_dispatch(as);\n> -    memory_region_update_pending |= root->enabled;\n> -    memory_region_transaction_commit();\n> +\n> +    QTAILQ_FOREACH(view, &flat_views, flat_views_link) {\n> +        assert(root);\n> +        if (view->root == root) {\n> +            as->current_map = flatview_get(view);\n> +            break;\n> +        }\n> +    }\n> +\n> +    if (!as->current_map) {\n> +        as->current_map = flatview_alloc(root);\n> +\n> +        QTAILQ_INSERT_TAIL(&flat_views, as->current_map, flat_views_link);\n> +    }\n> +\n> +    QTAILQ_INSERT_TAIL(&as->current_map->address_spaces, as, flat_view_link);\n> +}\n> +\n> +MemoryRegion *address_space_root(AddressSpace *as)\n> +{\n> +    return as->current_map->root;\n> +}\n> +\n> +AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)\n> +{\n> +    return atomic_rcu_read(&as->current_map)->dispatch;\n>   }\n>   \n>   static void do_address_space_destroy(AddressSpace *as)\n>   {\n> -    bool do_free = as->malloced;\n> +    FlatView *view = flatview_get(as->current_map);\n>   \n> -    address_space_destroy_dispatch(as);\n>       assert(QTAILQ_EMPTY(&as->listeners));\n>   \n> -    flatview_unref(as->current_map);\n> +    QTAILQ_REMOVE(&view->address_spaces, as, flat_view_link);\n> +    flatview_unref(view);\n> +\n> +    flatview_unref(view);\n\nincorrect copy/paste?\n\n> +\n>       g_free(as->name);\n>       g_free(as->ioeventfds);\n> -    memory_region_unref(as->root);\n> -    if (do_free) {\n> -        g_free(as);\n> -    }\n> +    g_free(as);\n>   }\n>   \n>   AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name)\n>   {\n>       AddressSpace *as;\n>   \n> -    QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {\n> -        if (root == as->root && as->malloced) {\n> -            as->ref_count++;\n> -            return as;\n> -        }\n> -    }\n> -\n>       as = g_malloc0(sizeof *as);\n>       address_space_init(as, root, name);\n> -    as->malloced = true;\n> +\n>       return as;\n>   }\n>   \n>   void address_space_destroy(AddressSpace *as)\n>   {\n> -    MemoryRegion *root = as->root;\n> -\n> -    as->ref_count--;\n> -    if (as->ref_count) {\n> -        return;\n> -    }\n>       /* Flush out anything from MemoryListeners listening in on this */\n>       memory_region_transaction_begin();\n> -    as->root = NULL;\n>       memory_region_transaction_commit();\n>       QTAILQ_REMOVE(&address_spaces, as, address_spaces_link);\n>       address_space_unregister(as);\n> @@ -2684,7 +2770,6 @@ void address_space_destroy(AddressSpace *as)\n>        * entries that the guest should never use.  Wait for the old\n>        * values to expire before freeing the data.\n>        */\n> -    as->root = root;\n>       call_rcu(as, do_address_space_destroy, rcu);\n>   }\n>   \n> @@ -2816,7 +2901,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,\n>   static void mtree_print_flatview(fprintf_function p, void *f,\n>                                    AddressSpace *as)\n>   {\n> -    FlatView *view = address_space_get_flatview(as);\n> +    FlatView *view = flatview_get(as->current_map);\n>       FlatRange *range = &view->ranges[0];\n>       MemoryRegion *mr;\n>       int n = view->nr;\n> @@ -2873,7 +2958,7 @@ void mtree_info(fprintf_function mon_printf, void *f, bool flatview)\n>   \n>       QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {\n>           mon_printf(f, \"address-space: %s\\n\", as->name);\n> -        mtree_print_mr(mon_printf, f, as->root, 1, 0, &ml_head);\n> +        mtree_print_mr(mon_printf, f, as->current_map->root, 1, 0, &ml_head);\n>           mon_printf(f, \"\\n\");\n>       }\n>   \n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"L40iRmO9\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpCPK100Vz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 06:54:25 +1000 (AEST)","from localhost ([::1]:42246 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dq3oc-0000Yt-20\n\tfor incoming@patchwork.ozlabs.org; Thu, 07 Sep 2017 16:54:22 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:56495)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dq3nz-0000YG-4y\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 16:53:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dq3ns-0007TN-N8\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 16:53:43 -0400","from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:33609)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dq3ns-0007T4-Gr\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 16:53:36 -0400","by mail-qk0-x243.google.com with SMTP id g128so496209qke.0\n\tfor <qemu-devel@nongnu.org>; Thu, 07 Sep 2017 13:53:36 -0700 (PDT)","from [192.168.1.10] ([181.93.89.178])\n\tby smtp.gmail.com with ESMTPSA id\n\tv32sm167852qtc.66.2017.09.07.13.53.32\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 07 Sep 2017 13:53:34 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=sender:subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=gxGoYacJOxz8xyGwRRzy72A8+fsdh1/MQldtqhiLDj4=;\n\tb=L40iRmO9cfNfgvchHWi0zUL+GLGdEggBOuiKbMZXmBhMNjvoIWy9pkSEOT3BnIKCtI\n\tQwZz6aiha0cBDjc6hYIBiPnmnRv0ugbl6bCdeLnJnFIUHDyxf5ICU5L98P1xWg7N9suS\n\taz/ic1TJChbx9r9QSXM1V6IZRZhYnJ8xsyhPCc2/a6Yw1qIzlXR6CMy+1NQwEPRHCzGw\n\t0yMm3H6T0g+3XOqkY9H6CFMMoAVzdDzn1scCDp1p3c3i9NRFciwLxNALqt2gV07pFppz\n\tcoDzq/w2Pa/NpY8Tm4qcRTufGV60h8MChwJuv/eVOSeJWG84iHKXr6UjzSV/B8I6RZ9f\n\tQdtQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:subject:to:cc:references:from:message-id\n\t:date:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=gxGoYacJOxz8xyGwRRzy72A8+fsdh1/MQldtqhiLDj4=;\n\tb=BTYqRJrJAEUFN3fjyILLZB947WXWQm3Jf4w13T5egzh9hqjw6c4YtK/jQLpvyuD/Xs\n\tZ1M+syPCWbQ6aao1cE6LgDh/9WmOlHtRFRy0af6WQCfqUT4rIfViWIUHUQvzAeSgzbFg\n\thG2y3NVELF9Q74lll/p/0hSRz4Vz+KlJa8wyNFwKFVvH4u4snqzihYxFxzSylP7i9UMz\n\tQlL21UiJimsAEdDnkIdm0/EKZwuIPq8/l5yMEViU6+IlYSpAqaltzrk2jChmr2o/a/1r\n\tdwJDkHixB8kOzQKLyLhoiXJpND0/hRM9UVQMZPbupPDrGbDViSA0lAqw6B7UE7SKJEFH\n\td/Aw==","X-Gm-Message-State":"AHPjjUg3w++1G4Io09z1nTZP1AfW7JI4xdxil3PlyoaymM+zgMc0WsKM\n\tFr/VdYUvSaKfvg==","X-Google-Smtp-Source":"AOwi7QDjRRo/8OrDdVm1wTGTRMnD9DR1IKeQN5MnC5g1tATa/wpgrEYksPHuqsSwv+tRXz+vcJrgZg==","X-Received":"by 10.233.244.1 with SMTP id y1mr808530qkl.231.1504817615468;\n\tThu, 07 Sep 2017 13:53:35 -0700 (PDT)","To":"Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>","From":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <f4bug@amsat.org>","Message-ID":"<7aa3f6a4-b4d7-5b04-1bb4-2c766b8de355@amsat.org>","Date":"Thu, 7 Sep 2017 17:53:31 -0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170907092010.3605-4-aik@ozlabs.ru>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400d:c09::243","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>,\n\tPaolo Bonzini <pbonzini@redhat.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tStefan Hajnoczi <stefanha@gmail.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1764978,"web_url":"http://patchwork.ozlabs.org/comment/1764978/","msgid":"<477c18d4-bdfb-2b44-ea52-059a17b0190b@ozlabs.ru>","list_archive_url":null,"date":"2017-09-07T22:18:53","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":7621,"url":"http://patchwork.ozlabs.org/api/people/7621/","name":"Alexey Kardashevskiy","email":"aik@ozlabs.ru"},"content":"On 08/09/17 06:53, Philippe Mathieu-Daudé wrote:\n> On 09/07/2017 06:20 AM, Alexey Kardashevskiy wrote:\n>> This allows sharing flat views between address spaces when the same root\n>> memory region is used when creating a new address space.\n>>\n>> This adds a global list of flat views and a list of attached address\n>> spaces per a flat view. Each address space references a flat view.\n>>\n>> This hard codes the dispatch tree building instead of doing so via\n>> a memory listener.\n>>\n>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>\n>> ---\n>>\n>> This was suggested by Paolo in\n>> https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg05011.html\n>>\n>> I am not putting \"Suggested-by\" as I want to make sure that this is doing\n>> what was actually suggested.\n>> ---\n>>   include/exec/memory-internal.h |   6 +-\n>>   include/exec/memory.h          |   9 +-\n>>   exec.c                         |  58 ++--------\n>>   hw/pci/pci.c                   |   3 +-\n>>   memory.c                       | 253\n>> +++++++++++++++++++++++++++--------------\n>>   5 files changed, 187 insertions(+), 142 deletions(-)\n>>\n>> diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h\n>> index fb467acdba..8516e0b48f 100644\n>> --- a/include/exec/memory-internal.h\n>> +++ b/include/exec/memory-internal.h\n>> @@ -22,9 +22,11 @@\n>>   #ifndef CONFIG_USER_ONLY\n>>   typedef struct AddressSpaceDispatch AddressSpaceDispatch;\n>>   -void address_space_init_dispatch(AddressSpace *as);\n>>   void address_space_unregister(AddressSpace *as);\n>> -void address_space_destroy_dispatch(AddressSpace *as);\n>> +void address_space_dispatch_free(AddressSpaceDispatch *d);\n>> +AddressSpaceDispatch *mem_begin(void);\n>> +void mem_commit(AddressSpaceDispatch *d);\n>> +void mem_add(AddressSpaceDispatch *d, MemoryRegionSection *section);\n>>     extern const MemoryRegionOps unassigned_mem_ops;\n>>   diff --git a/include/exec/memory.h b/include/exec/memory.h\n>> index 83e82e90d5..41ab165302 100644\n>> --- a/include/exec/memory.h\n>> +++ b/include/exec/memory.h\n>> @@ -27,6 +27,7 @@\n>>   #include \"qemu/rcu.h\"\n>>   #include \"hw/qdev-core.h\"\n>>   +typedef struct AddressSpaceDispatch AddressSpaceDispatch;\n>>   #define RAM_ADDR_INVALID (~(ram_addr_t)0)\n>>     #define MAX_PHYS_ADDR_SPACE_BITS 62\n>> @@ -312,6 +313,7 @@ struct MemoryListener {\n>>   };\n>>     AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as);\n>> +MemoryRegion *address_space_root(AddressSpace *as);\n>>     /**\n>>    * AddressSpace: describes a mapping of addresses to #MemoryRegion objects\n>> @@ -320,20 +322,17 @@ struct AddressSpace {\n>>       /* All fields are private. */\n>>       struct rcu_head rcu;\n>>       char *name;\n>> -    MemoryRegion *root;\n>> -    int ref_count;\n>> -    bool malloced;\n>>         /* Accessed via RCU.  */\n>>       struct FlatView *current_map;\n>>         int ioeventfd_nb;\n>>       struct MemoryRegionIoeventfd *ioeventfds;\n>> -    struct AddressSpaceDispatch *dispatch;\n>> -    struct AddressSpaceDispatch *next_dispatch;\n>> +\n>>       MemoryListener dispatch_listener;\n>>       QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners;\n>>       QTAILQ_ENTRY(AddressSpace) address_spaces_link;\n>> +    QTAILQ_ENTRY(AddressSpace) flat_view_link;\n>>   };\n>>     /**\n>> diff --git a/exec.c b/exec.c\n>> index 66f01f5fce..51243f57f4 100644\n>> --- a/exec.c\n>> +++ b/exec.c\n>> @@ -188,15 +188,12 @@ typedef struct PhysPageMap {\n>>   } PhysPageMap;\n>>     struct AddressSpaceDispatch {\n>> -    struct rcu_head rcu;\n>> -\n>>       MemoryRegionSection *mru_section;\n>>       /* This is a multi-level map on the physical address space.\n>>        * The bottom level has pointers to MemoryRegionSections.\n>>        */\n>>       PhysPageEntry phys_map;\n>>       PhysPageMap map;\n>> -    AddressSpace *as;\n>>   };\n>>     typedef struct AddressSpaceDispatch AddressSpaceDispatch;\n>> @@ -240,11 +237,6 @@ struct DirtyBitmapSnapshot {\n>>       unsigned long dirty[];\n>>   };\n>>   -AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)\n>> -{\n>> -    return atomic_rcu_read(&as->dispatch);\n>> -}\n>> -\n>>   #endif\n>>     #if !defined(CONFIG_USER_ONLY)\n>> @@ -1354,10 +1346,8 @@ static void\n>> register_multipage(AddressSpaceDispatch *d,\n>>       phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages,\n>> section_index);\n>>   }\n>>   -static void mem_add(MemoryListener *listener, MemoryRegionSection\n>> *section)\n>> +void mem_add(AddressSpaceDispatch *d, MemoryRegionSection *section)\n>>   {\n>> -    AddressSpace *as = container_of(listener, AddressSpace,\n>> dispatch_listener);\n>> -    AddressSpaceDispatch *d = as->next_dispatch;\n>>       MemoryRegionSection now = *section, remain = *section;\n>>       Int128 page_size = int128_make64(TARGET_PAGE_SIZE);\n>>   @@ -2680,9 +2670,8 @@ static void io_mem_init(void)\n>>                             NULL, UINT64_MAX);\n>>   }\n>>   -static void mem_begin(MemoryListener *listener)\n>> +AddressSpaceDispatch *mem_begin(void)\n>>   {\n>> -    AddressSpace *as = container_of(listener, AddressSpace,\n>> dispatch_listener);\n>>       AddressSpaceDispatch *d = g_new0(AddressSpaceDispatch, 1);\n>>       uint16_t n;\n>>   @@ -2696,27 +2685,19 @@ static void mem_begin(MemoryListener *listener)\n>>       assert(n == PHYS_SECTION_WATCH);\n>>         d->phys_map  = (PhysPageEntry) { .ptr = PHYS_MAP_NODE_NIL, .skip\n>> = 1 };\n>> -    as->next_dispatch = d;\n>> +\n>> +    return d;\n>>   }\n>>   -static void address_space_dispatch_free(AddressSpaceDispatch *d)\n>> +void address_space_dispatch_free(AddressSpaceDispatch *d)\n>>   {\n>>       phys_sections_free(&d->map);\n>>       g_free(d);\n>>   }\n>>   -static void mem_commit(MemoryListener *listener)\n>> +void mem_commit(AddressSpaceDispatch *d)\n>>   {\n>> -    AddressSpace *as = container_of(listener, AddressSpace,\n>> dispatch_listener);\n>> -    AddressSpaceDispatch *cur = as->dispatch;\n>> -    AddressSpaceDispatch *next = as->next_dispatch;\n>> -\n>> -    phys_page_compact_all(next, next->map.nodes_nb);\n>> -\n>> -    atomic_rcu_set(&as->dispatch, next);\n>> -    if (cur) {\n>> -        call_rcu(cur, address_space_dispatch_free, rcu);\n>> -    }\n>> +    phys_page_compact_all(d, d->map.nodes_nb);\n>>   }\n>>     static void tcg_commit(MemoryListener *listener)\n>> @@ -2732,39 +2713,16 @@ static void tcg_commit(MemoryListener *listener)\n>>        * We reload the dispatch pointer now because\n>> cpu_reloading_memory_map()\n>>        * may have split the RCU critical section.\n>>        */\n>> -    d = atomic_rcu_read(&cpuas->as->dispatch);\n>> +    d = address_space_to_dispatch(cpuas->as);\n>>       atomic_rcu_set(&cpuas->memory_dispatch, d);\n>>       tlb_flush(cpuas->cpu);\n>>   }\n>>   -void address_space_init_dispatch(AddressSpace *as)\n>> -{\n>> -    as->dispatch = NULL;\n>> -    as->dispatch_listener = (MemoryListener) {\n>> -        .begin = mem_begin,\n>> -        .commit = mem_commit,\n>> -        .region_add = mem_add,\n>> -        .region_nop = mem_add,\n>> -        .priority = 0,\n>> -    };\n>> -    memory_listener_register(&as->dispatch_listener, as);\n>> -}\n>> -\n>>   void address_space_unregister(AddressSpace *as)\n>>   {\n>>       memory_listener_unregister(&as->dispatch_listener);\n>>   }\n>>   -void address_space_destroy_dispatch(AddressSpace *as)\n>> -{\n>> -    AddressSpaceDispatch *d = as->dispatch;\n>> -\n>> -    atomic_rcu_set(&as->dispatch, NULL);\n>> -    if (d) {\n>> -        call_rcu(d, address_space_dispatch_free, rcu);\n>> -    }\n>> -}\n>> -\n>>   static void memory_map_init(void)\n>>   {\n>>       system_memory = g_malloc(sizeof(*system_memory));\n>> diff --git a/hw/pci/pci.c b/hw/pci/pci.c\n>> index 258fbe51e2..86b9e419fd 100644\n>> --- a/hw/pci/pci.c\n>> +++ b/hw/pci/pci.c\n>> @@ -88,7 +88,8 @@ static void pci_init_bus_master(PCIDevice *pci_dev)\n>>         memory_region_init_alias(&pci_dev->bus_master_enable_region,\n>>                                OBJECT(pci_dev), \"bus master\",\n>> -                             dma_as->root, 0,\n>> memory_region_size(dma_as->root));\n>> +                             address_space_root(dma_as), 0,\n>> +                            \n>> memory_region_size(address_space_root(dma_as)));\n>>       memory_region_set_enabled(&pci_dev->bus_master_enable_region, false);\n>>       memory_region_add_subregion(&pci_dev->bus_master_container_region, 0,\n>>                                   &pci_dev->bus_master_enable_region);\n>> diff --git a/memory.c b/memory.c\n>> index c6904a7deb..385a507511 100644\n>> --- a/memory.c\n>> +++ b/memory.c\n>> @@ -47,6 +47,9 @@ static QTAILQ_HEAD(memory_listeners, MemoryListener)\n>> memory_listeners\n>>   static QTAILQ_HEAD(, AddressSpace) address_spaces\n>>       = QTAILQ_HEAD_INITIALIZER(address_spaces);\n>>   +static QTAILQ_HEAD(FlatViewList, FlatView) flat_views\n>> +    = QTAILQ_HEAD_INITIALIZER(flat_views);\n>> +\n>>   typedef struct AddrRange AddrRange;\n>>     /*\n>> @@ -230,6 +233,11 @@ struct FlatView {\n>>       FlatRange *ranges;\n>>       unsigned nr;\n>>       unsigned nr_allocated;\n>> +    MemoryRegion *root;\n>> +    struct AddressSpaceDispatch *dispatch;\n>> +\n>> +    QTAILQ_ENTRY(FlatView) flat_views_link;\n>> +    QTAILQ_HEAD(address_spaces, AddressSpace) address_spaces;\n>>   };\n>>     typedef struct AddressSpaceOps AddressSpaceOps;\n>> @@ -259,12 +267,19 @@ static bool flatrange_equal(FlatRange *a, FlatRange\n>> *b)\n>>           && a->readonly == b->readonly;\n>>   }\n>>   -static void flatview_init(FlatView *view)\n>> +static void flatview_ref(FlatView *view);\n>> +\n>> +static FlatView *flatview_alloc(MemoryRegion *mr_root)\n>>   {\n>> +    FlatView *view;\n>> +\n>> +    view = g_new0(FlatView, 1);\n>>       view->ref = 1;\n>> -    view->ranges = NULL;\n>> -    view->nr = 0;\n>> -    view->nr_allocated = 0;\n>> +    view->root = mr_root;\n>> +    memory_region_ref(mr_root);\n>> +    QTAILQ_INIT(&view->address_spaces);\n>> +\n>> +    return view;\n>>   }\n>>     /* Insert a range into a given position.  Caller is responsible for\n>> maintaining\n>> @@ -292,6 +307,10 @@ static void flatview_destroy(FlatView *view)\n>>           memory_region_unref(view->ranges[i].mr);\n>>       }\n>>       g_free(view->ranges);\n>> +    if (view->dispatch) {\n>> +        address_space_dispatch_free(view->dispatch);\n>> +    }\n>> +    memory_region_unref(view->root);\n>>       g_free(view);\n>>   }\n>>   @@ -303,7 +322,7 @@ static void flatview_ref(FlatView *view)\n>>   static void flatview_unref(FlatView *view)\n>>   {\n>>       if (atomic_fetch_dec(&view->ref) == 1) {\n>> -        flatview_destroy(view);\n>> +        call_rcu(view, flatview_destroy, rcu);\n>>       }\n>>   }\n>>   @@ -608,7 +627,7 @@ static AddressSpace\n>> *memory_region_to_address_space(MemoryRegion *mr)\n>>           mr = mr->container;\n>>       }\n>>       QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {\n>> -        if (mr == as->root) {\n>> +        if (mr == as->current_map->root) {\n>>               return as;\n>>           }\n>>       }\n>> @@ -702,23 +721,6 @@ static void render_memory_region(FlatView *view,\n>>       }\n>>   }\n>>   -/* Render a memory topology into a list of disjoint absolute ranges. */\n>> -static FlatView *generate_memory_topology(MemoryRegion *mr)\n>> -{\n>> -    FlatView *view;\n>> -\n>> -    view = g_new(FlatView, 1);\n>> -    flatview_init(view);\n>> -\n>> -    if (mr) {\n>> -        render_memory_region(view, mr, int128_zero(),\n>> -                             addrrange_make(int128_zero(),\n>> int128_2_64()), false);\n>> -    }\n>> -    flatview_simplify(view);\n>> -\n>> -    return view;\n>> -}\n>> -\n>>   static void address_space_add_del_ioeventfds(AddressSpace *as,\n>>                                                MemoryRegionIoeventfd\n>> *fds_new,\n>>                                                unsigned fds_new_nb,\n>> @@ -769,12 +771,10 @@ static void\n>> address_space_add_del_ioeventfds(AddressSpace *as,\n>>       }\n>>   }\n>>   -static FlatView *address_space_get_flatview(AddressSpace *as)\n>> +static FlatView *flatview_get(FlatView *view)\n>>   {\n>> -    FlatView *view;\n>> -\n>>       rcu_read_lock();\n>> -    view = atomic_rcu_read(&as->current_map);\n>> +    view = atomic_rcu_read(&view);\n>>       flatview_ref(view);\n>>       rcu_read_unlock();\n>>       return view;\n>> @@ -789,7 +789,7 @@ static void\n>> address_space_update_ioeventfds(AddressSpace *as)\n>>       AddrRange tmp;\n>>       unsigned i;\n>>   -    view = address_space_get_flatview(as);\n>> +    view = flatview_get(as->current_map);\n>>       FOR_EACH_FLAT_RANGE(fr, view) {\n>>           for (i = 0; i < fr->mr->ioeventfd_nb; ++i) {\n>>               tmp = addrrange_shift(fr->mr->ioeventfds[i].addr,\n>> @@ -881,28 +881,89 @@ static void\n>> address_space_update_topology_pass(AddressSpace *as,\n>>       }\n>>   }\n>>   -\n>> -static void address_space_update_topology(AddressSpace *as)\n>> +static FlatView *address_space_update_flatview(FlatView *view)\n>>   {\n>> -    FlatView *old_view = address_space_get_flatview(as);\n>> -    FlatView *new_view = generate_memory_topology(as->root);\n>> +    AddressSpace *as, *asnext;\n>> +    FlatView *old_view = flatview_get(view);\n>> +    MemoryRegion *root = old_view->root;\n>> +    FlatView *new_view = flatview_alloc(root);\n>> +    unsigned iold, inew;\n>> +    FlatRange *frold, *frnew;\n>>   -    address_space_update_topology_pass(as, old_view, new_view, false);\n>> -    address_space_update_topology_pass(as, old_view, new_view, true);\n>> +    if (root) {\n>> +        render_memory_region(new_view, root, int128_zero(),\n>> +                             addrrange_make(int128_zero(), int128_2_64()),\n>> +                             false);\n>> +        flatview_simplify(new_view);\n>> +    }\n>>   -    /* Writes are protected by the BQL.  */\n>> -    atomic_rcu_set(&as->current_map, new_view);\n>> -    call_rcu(old_view, flatview_unref, rcu);\n>> +    new_view->dispatch = mem_begin();\n>>   -    /* Note that all the old MemoryRegions are still alive up to this\n>> -     * point.  This relieves most MemoryListeners from the need to\n>> -     * ref/unref the MemoryRegions they get---unless they use them\n>> -     * outside the iothread mutex, in which case precise reference\n>> -     * counting is necessary.\n>> +    /*\n>> +     * FIXME: this is cut-n-paste from address_space_update_topology_pass,\n>> +     * simplify it\n>>        */\n>> +    iold = inew = 0;\n>> +    while (iold < old_view->nr || inew < new_view->nr) {\n>> +        if (iold < old_view->nr) {\n>> +            frold = &old_view->ranges[iold];\n>> +        } else {\n>> +            frold = NULL;\n>> +        }\n>> +        if (inew < new_view->nr) {\n>> +            frnew = &new_view->ranges[inew];\n>> +        } else {\n>> +            frnew = NULL;\n>> +        }\n>> +\n>> +        if (frold\n>> +            && (!frnew\n>> +                || int128_lt(frold->addr.start, frnew->addr.start)\n>> +                || (int128_eq(frold->addr.start, frnew->addr.start)\n>> +                    && !flatrange_equal(frold, frnew)))) {\n>> +            ++iold;\n>> +        } else if (frold && frnew && flatrange_equal(frold, frnew)) {\n>> +            /* In both and unchanged (except logging may have changed) */\n>> +            MemoryRegionSection mrs = section_from_flat_range(frnew,\n>> +                    new_view->dispatch);\n>> +\n>> +            mem_add(new_view->dispatch, &mrs);\n>> +\n>> +            ++iold;\n>> +            ++inew;\n>> +        } else {\n>> +            /* In new */\n>> +            MemoryRegionSection mrs = section_from_flat_range(frnew,\n>> +                    new_view->dispatch);\n>> +\n>> +            mem_add(new_view->dispatch, &mrs);\n>> +\n>> +            ++inew;\n>> +        }\n>> +    }\n>> +\n>> +    mem_commit(new_view->dispatch);\n>> +\n>> +    QTAILQ_FOREACH(as, &old_view->address_spaces, flat_view_link) {\n>> +        address_space_update_topology_pass(as, old_view, new_view, false);\n>> +        address_space_update_topology_pass(as, old_view, new_view, true);\n>> +    }\n>> +\n>> +    QTAILQ_FOREACH_SAFE(as, &old_view->address_spaces, flat_view_link,\n>> asnext) {\n>> +        QTAILQ_REMOVE(&old_view->address_spaces, as, flat_view_link);\n>> +        flatview_unref(old_view);\n>> +\n>> +        atomic_rcu_set(&as->current_map, new_view);\n>> +\n>> +        flatview_ref(new_view);\n>> +        QTAILQ_INSERT_TAIL(&new_view->address_spaces, as, flat_view_link);\n>> +\n>> +        address_space_update_ioeventfds(as);\n>> +    }\n>> +\n>>       flatview_unref(old_view);\n>>   -    address_space_update_ioeventfds(as);\n>> +    return new_view;\n>>   }\n>>     void memory_region_transaction_begin(void)\n>> @@ -921,11 +982,31 @@ void memory_region_transaction_commit(void)\n>>       --memory_region_transaction_depth;\n>>       if (!memory_region_transaction_depth) {\n>>           if (memory_region_update_pending) {\n>> +            FlatView *view, *vnext;\n>> +            struct FlatViewList fwstmp = QTAILQ_HEAD_INITIALIZER(fwstmp);\n>> +\n>>               MEMORY_LISTENER_CALL_GLOBAL(begin, Forward);\n>>   -            QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {\n>> -                address_space_update_topology(as);\n>> +            QTAILQ_FOREACH_SAFE(view, &flat_views, flat_views_link,\n>> vnext) {\n>> +                FlatView *old_view, *new_view;\n>> +\n>> +                old_view = flatview_get(view);\n>> +                new_view = address_space_update_flatview(old_view);\n>> +\n>> +                QTAILQ_REMOVE(&flat_views, old_view, flat_views_link);\n>> +                flatview_unref(old_view);\n>> +                flatview_unref(old_view);\n>> +\n>> +                QTAILQ_INSERT_HEAD(&fwstmp, new_view, flat_views_link);\n>> +\n>> +                flatview_unref(new_view);\n>>               }\n>> +\n>> +            QTAILQ_FOREACH_SAFE(view, &fwstmp, flat_views_link, vnext) {\n>> +                QTAILQ_REMOVE(&fwstmp, view, flat_views_link);\n>> +                QTAILQ_INSERT_HEAD(&flat_views, view, flat_views_link);\n>> +            }\n>> +\n>>               memory_region_update_pending = false;\n>>               MEMORY_LISTENER_CALL_GLOBAL(commit, Forward);\n>>           } else if (ioeventfd_update_pending) {\n>> @@ -1834,7 +1915,7 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr)\n>>               continue;\n>>           }\n>>           as = listener->address_space;\n>> -        view = address_space_get_flatview(as);\n>> +        view = flatview_get(as->current_map);\n>>           FOR_EACH_FLAT_RANGE(fr, view) {\n>>               if (fr->mr == mr) {\n>>                   MemoryRegionSection mrs = section_from_flat_range(fr,\n>> @@ -1938,7 +2019,7 @@ static void\n>> memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpa\n>>       AddrRange tmp;\n>>       MemoryRegionSection section;\n>>   -    view = address_space_get_flatview(as);\n>> +    view = flatview_get(as->current_map);\n>>       FOR_EACH_FLAT_RANGE(fr, view) {\n>>           if (fr->mr == mr) {\n>>               section = (MemoryRegionSection) {\n>> @@ -2350,7 +2431,7 @@ void memory_global_dirty_log_sync(void)\n>>               continue;\n>>           }\n>>           as = listener->address_space;\n>> -        view = address_space_get_flatview(as);\n>> +        view = flatview_get(as->current_map);\n>>           FOR_EACH_FLAT_RANGE(fr, view) {\n>>               if (fr->dirty_log_mask) {\n>>                   MemoryRegionSection mrs = section_from_flat_range(fr,\n>> @@ -2436,7 +2517,7 @@ static void\n>> listener_add_address_space(MemoryListener *listener,\n>>           }\n>>       }\n>>   -    view = address_space_get_flatview(as);\n>> +    view = flatview_get(as->current_map);\n>>       FOR_EACH_FLAT_RANGE(fr, view) {\n>>           MemoryRegionSection section = {\n>>               .mr = fr->mr,\n>> @@ -2615,67 +2696,72 @@ void\n>> memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset,\n>>     void address_space_init(AddressSpace *as, MemoryRegion *root, const\n>> char *name)\n>>   {\n>> -    memory_region_ref(root);\n>> -    memory_region_transaction_begin();\n>> -    as->ref_count = 1;\n>> -    as->root = root;\n>> -    as->malloced = false;\n>> -    as->current_map = g_new(FlatView, 1);\n>> -    flatview_init(as->current_map);\n>> +    FlatView *view;\n>> +\n>> +    as->current_map = NULL;\n>>       as->ioeventfd_nb = 0;\n>>       as->ioeventfds = NULL;\n>>       QTAILQ_INIT(&as->listeners);\n>>       QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);\n>>       as->name = g_strdup(name ? name : \"anonymous\");\n>> -    address_space_init_dispatch(as);\n>> -    memory_region_update_pending |= root->enabled;\n>> -    memory_region_transaction_commit();\n>> +\n>> +    QTAILQ_FOREACH(view, &flat_views, flat_views_link) {\n>> +        assert(root);\n>> +        if (view->root == root) {\n>> +            as->current_map = flatview_get(view);\n>> +            break;\n>> +        }\n>> +    }\n>> +\n>> +    if (!as->current_map) {\n>> +        as->current_map = flatview_alloc(root);\n>> +\n>> +        QTAILQ_INSERT_TAIL(&flat_views, as->current_map, flat_views_link);\n>> +    }\n>> +\n>> +    QTAILQ_INSERT_TAIL(&as->current_map->address_spaces, as,\n>> flat_view_link);\n>> +}\n>> +\n>> +MemoryRegion *address_space_root(AddressSpace *as)\n>> +{\n>> +    return as->current_map->root;\n>> +}\n>> +\n>> +AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)\n>> +{\n>> +    return atomic_rcu_read(&as->current_map)->dispatch;\n>>   }\n>>     static void do_address_space_destroy(AddressSpace *as)\n>>   {\n>> -    bool do_free = as->malloced;\n>> +    FlatView *view = flatview_get(as->current_map);\n>>   -    address_space_destroy_dispatch(as);\n>>       assert(QTAILQ_EMPTY(&as->listeners));\n>>   -    flatview_unref(as->current_map);\n>> +    QTAILQ_REMOVE(&view->address_spaces, as, flat_view_link);\n>> +    flatview_unref(view);\n>> +\n>> +    flatview_unref(view);\n\n\nThis one removes a reference after unlinking an address space from the\nflatview.\n\n> \n> incorrect copy/paste?\n\nNope, this one pairs flatview_get() from few lines above.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ozlabs-ru.20150623.gappssmtp.com\n\theader.i=@ozlabs-ru.20150623.gappssmtp.com\n\theader.b=\"gz9yhXC4\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpFHg2S1sz9sCZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 08:19:39 +1000 (AEST)","from localhost ([::1]:42458 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dq595-0006dY-UV\n\tfor incoming@patchwork.ozlabs.org; Thu, 07 Sep 2017 18:19:35 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:40827)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1dq58e-0006bk-MB\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:19:15 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1dq58Y-0007lk-4y\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:19:08 -0400","from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33774)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <aik@ozlabs.ru>) id 1dq58X-0007kx-Po\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:19:02 -0400","by mail-pf0-x242.google.com with SMTP id h4so491936pfk.0\n\tfor <qemu-devel@nongnu.org>; Thu, 07 Sep 2017 15:19:01 -0700 (PDT)","from [192.168.10.22] (124-171-136-142.dyn.iinet.net.au.\n\t[124.171.136.142]) by smtp.googlemail.com with ESMTPSA id\n\ts184sm754625pfb.123.2017.09.07.15.18.56\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 07 Sep 2017 15:18:58 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ozlabs-ru.20150623.gappssmtp.com; s=20150623;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=LltaMgrh0u/jm3h3ZT4dzcF4PNHqd0xfsmUVJeHyaHQ=;\n\tb=gz9yhXC4JNF3llnG0H5ED5Hso0IsVQAAqpGrOiRJPhRkQFSNyRzcwfyTxQvVPTPdFW\n\teUMONEOYoKPNIiIL9BPs8yMdBFJNyJpU6Y8RVf7gtyJeikaZrCI0qPCsUIQ7x1fwUErF\n\tUVSmwDNFQQoR0v6VLWkId71YNcJKBJDkiMrcX2kSad1uZdtsjguib7LZQ1OTNz/iEZe8\n\tL5yZpv8I7Fu+aldS8qVoixNssC7xN55YJSAeXlt8dcWproHItZkoFA85SWsM2Z7e7ZVX\n\tPyFE0ysEo3jScFEdk7UnIdyOeMhpFvJkv+c3nWPVW5QqOVcC4ahIVUESu4b7obu5Z8ed\n\tJiLQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=LltaMgrh0u/jm3h3ZT4dzcF4PNHqd0xfsmUVJeHyaHQ=;\n\tb=fl/qq33+nh6cCr2cDnQzwm0Fonvi7X7tZQTTlvz+K3L/0I1I/47Ji+sriC3hJCU7bv\n\txXV/cPkwdxlpnpnxz9j6TDLFJkbzLcHKM1wWoiq7V9SLss/qK+yyxggXtsq6+cSUt/qQ\n\to8GvMUANyM7nMUFQ4vDc5AVidMbSjafhcv+g82ECOcLiQ6N6v4F7e4nQ4yVe7t55+yQp\n\twxuFh4HOSkUFO0FHz0FwlLkkYJrNP3C+cq0ynrIWW2G9SqXX6DcPgPp92V2551PX+ucq\n\t9p4ExwtR1Bf0pmZb01gvv8XFy910y1oRsMlmAvYHCoGRuMqgUv473zCA84S32lPGEUXO\n\tZDfQ==","X-Gm-Message-State":"AHPjjUiYz+IXLhA3xe8mnH0nibdXxGcyCArK2OXIbPK8q9jsGTGTmdNE\n\tTmnr1mG19O5au6ZV","X-Google-Smtp-Source":"ADKCNb469HxwWxbV7hymOR8WujM9S3oH+F/c6Cl++oF/A3HBIVHbMUf0RHvu6tpk1jyZhzKKfrV5Jg==","X-Received":"by 10.84.210.107 with SMTP id z98mr983693plh.182.1504822739658; \n\tThu, 07 Sep 2017 15:18:59 -0700 (PDT)","To":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <f4bug@amsat.org>,\n\tqemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<7aa3f6a4-b4d7-5b04-1bb4-2c766b8de355@amsat.org>","From":"Alexey Kardashevskiy <aik@ozlabs.ru>","Message-ID":"<477c18d4-bdfb-2b44-ea52-059a17b0190b@ozlabs.ru>","Date":"Fri, 8 Sep 2017 08:18:53 +1000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<7aa3f6a4-b4d7-5b04-1bb4-2c766b8de355@amsat.org>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-AU","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400e:c00::242","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Peter Maydell <peter.maydell@linaro.org>,\n\tPaolo Bonzini <pbonzini@redhat.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tStefan Hajnoczi <stefanha@gmail.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766100,"web_url":"http://patchwork.ozlabs.org/comment/1766100/","msgid":"<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>","list_archive_url":null,"date":"2017-09-11T07:40:06","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":2701,"url":"http://patchwork.ozlabs.org/api/people/2701/","name":"Paolo Bonzini","email":"pbonzini@redhat.com"},"content":"On 07/09/2017 11:20, Alexey Kardashevskiy wrote:\n>  \n>      /* Accessed via RCU.  */\n>      struct FlatView *current_map;\n>  \n>      int ioeventfd_nb;\n>      struct MemoryRegionIoeventfd *ioeventfds;\n> -    struct AddressSpaceDispatch *dispatch;\n> -    struct AddressSpaceDispatch *next_dispatch;\n> +\n\nThe rough idea of the patch matches my suggestion indeed.  However, I am\nnot sure why all of the changes in patch 2 are needed.\n\nOnce you have built the FlatView and the dispatch within it, you can\nstill cache its dispatch tree in as->dispatch, and free it with RCU from\nflatview_destroy.  This removes the need to use call_rcu from\nflatview_unref.\n\nIn addition, you could change the computation of FlatView's root to\nresolve 2^64-sized aliases; also set it to NULL if the AddressSpace's\nroot is disabled or the alias it resolves to is disabled (and so on\nrecursively until a non-alias is found).  This should remove the need\nfor address_space_root() and the change to pci_init_bus_master.\n\nPaolo","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrKby0JwBz9s83\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 17:41:02 +1000 (AEST)","from localhost ([::1]:55963 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drJL2-0004Qe-6d\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 03:41:00 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:44638)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drJKI-00049r-O6\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 03:40:15 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drJKF-00019u-L2\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 03:40:14 -0400","from mail-wm0-f43.google.com ([74.125.82.43]:43898)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <pbonzini@redhat.com>) id 1drJKF-00017I-E9\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 03:40:11 -0400","by mail-wm0-f43.google.com with SMTP id a137so6313859wma.0\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 00:40:09 -0700 (PDT)","from [10.32.181.85] (nat-pool-mxp-t.redhat.com. [149.6.153.186])\n\tby smtp.gmail.com with ESMTPSA id\n\tp46sm9100064wrb.46.2017.09.11.00.40.07\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 11 Sep 2017 00:40:07 -0700 (PDT)"],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=8sa7sOH1lS8YUxD8YwaB0GBOOsUabwsOxhA2ML/w5gc=;\n\tb=HfSiPpHJd2Sui/SjdmndLESFy7OArDJrPehb0Pbrghso7nofeSGwKk9e4rNSg9Go94\n\t8ec4LX2hP0aOkmqXVNcz3dmozGVntgy5uMS9fyD8QQOjeHgLSy4xz9s0AdMg6J0eKqLZ\n\taiglBlUBEf/cpSobLsGwLD9XO3PQka63fWaR7d1Gixp3DImg0WN7BF9FlqUqBrZKXdnD\n\t9AHDx2Nx9ng1hWPggqvERYZDMv2E3/9ymK++HNjA9K97xKKJMwkbBYM7wxXvWq6QGon1\n\ttqReCo/KQShGiWNapt8Ilegu4ERx0znwGJeQR8VY7zKh4UAITm2Qyd7kIsNtEZuMUC0s\n\trXsQ==","X-Gm-Message-State":"AHPjjUiPR7xXXK0l71VM2abxW7eomxxpg0AGePXW/BtxrGeg3loAv0td\n\thOCQ/3LIwZFsxsj+","X-Google-Smtp-Source":"AOwi7QCKxx/JEuiNKXnb7rWnp3IFc6ZCI8uFbjZCeApxsSQXjSuQdUmrz4hddQE5g6MJsvPpmbbHuA==","X-Received":"by 10.28.230.3 with SMTP id d3mr6464628wmh.54.1505115608805;\n\tMon, 11 Sep 2017 00:40:08 -0700 (PDT)","To":"Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>","From":"Paolo Bonzini <pbonzini@redhat.com>","Message-ID":"<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>","Date":"Mon, 11 Sep 2017 09:40:06 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<20170907092010.3605-4-aik@ozlabs.ru>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"74.125.82.43","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766146,"web_url":"http://patchwork.ozlabs.org/comment/1766146/","msgid":"<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>","list_archive_url":null,"date":"2017-09-11T09:06:10","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":7621,"url":"http://patchwork.ozlabs.org/api/people/7621/","name":"Alexey Kardashevskiy","email":"aik@ozlabs.ru"},"content":"On 11/09/17 17:40, Paolo Bonzini wrote:\n> On 07/09/2017 11:20, Alexey Kardashevskiy wrote:\n>>  \n>>      /* Accessed via RCU.  */\n>>      struct FlatView *current_map;\n>>  \n>>      int ioeventfd_nb;\n>>      struct MemoryRegionIoeventfd *ioeventfds;\n>> -    struct AddressSpaceDispatch *dispatch;\n>> -    struct AddressSpaceDispatch *next_dispatch;\n>> +\n> \n> The rough idea of the patch matches my suggestion indeed.  However, I am\n> not sure why all of the changes in patch 2 are needed.\n\nFor this:\n\n struct MemoryRegionSection {\n     MemoryRegion *mr;\n-    AddressSpace *address_space;\n+    AddressSpaceDispatch *dispatch;\n\nas there are many ASes attached to the same flatview/dispatch.\n\nAnd because of that, there is also:\n\n struct IOMMUTLBEntry {\n-    AddressSpace    *target_as;\n+    AddressSpaceDispatch *target_dispatch;\n\nas the \"section\" in address_space_get_iotlb_entry() does not have\naddress_space any more, even though the only user of it -\nvhost_device_iotlb_miss() - only checks if (iotlb.target_dispatch != NULL).\n\n\n> Once you have built the FlatView and the dispatch within it, you can\n> still cache its dispatch tree in as->dispatch, and free it with RCU from\n> flatview_destroy.  This removes the need to use call_rcu from\n> flatview_unref.\n\nOk, I will do that.\n\n> In addition, you could change the computation of FlatView's root to\n> resolve 2^64-sized aliases;\n\nHere we reached the boundary of my english :)\n\nRoots are given when AS/Flatview is created, and aliases are resolved already.\n\n> also set it to NULL if the AddressSpace's\n> root is disabled or the alias it resolves to is disabled (and so on\n> recursively until a non-alias is found).  This should remove the need\n> for address_space_root() and the change to pci_init_bus_master.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ozlabs-ru.20150623.gappssmtp.com\n\theader.i=@ozlabs-ru.20150623.gappssmtp.com\n\theader.b=\"E0AWJmHr\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrMVv3J7Yz9rxm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 19:06:45 +1000 (AEST)","from localhost ([::1]:56243 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drKfz-000615-MA\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 05:06:43 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38606)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1drKfe-00060P-Sn\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 05:06:26 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1drKfZ-0000kr-O1\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 05:06:22 -0400","from mail-it0-x243.google.com ([2607:f8b0:4001:c0b::243]:32981)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <aik@ozlabs.ru>) id 1drKfZ-0000kd-FR\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 05:06:17 -0400","by mail-it0-x243.google.com with SMTP id f64so3827141itf.0\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 02:06:17 -0700 (PDT)","from [10.61.2.175] ([122.99.82.10])\n\tby smtp.googlemail.com with ESMTPSA id\n\ts66sm4358087itd.25.2017.09.11.02.06.13\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 11 Sep 2017 02:06:16 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ozlabs-ru.20150623.gappssmtp.com; s=20150623;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=z+i29CC26SCmiGMXvQY33QrZpGugc6Vz1DZjlgUCORE=;\n\tb=E0AWJmHrsmSvYXKo1SswMEWZ5xecj64PWdLNhq02PAcIqHgjPcOZQBmvFnZFpPVKyN\n\tuFS6QQkjjMBGd2KhbXb5Tir5GfzCpU6FNFCG/NaOQtGr1z/EbWun+W8yLQybTahd35Ex\n\tTzp+9BQXwHzfJ9IL3cVkoKKBFGJMp3h1dGFNHLAeIrxxE4RJqsUQ+W+mrEeMv/IuQzqN\n\t8h1aRxBsRM2ye2g14rWE6Rn3dHn99JQJTkOCWMJthkYJLKXdT5drAGUfegh2/V34e/sC\n\teJzO6bcGL2vQ27eJ5dTSf00N6bEq0lprxqVfeq94gOQMx10oxHGGyLpLzACM4pOaRpF9\n\t8KzQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=z+i29CC26SCmiGMXvQY33QrZpGugc6Vz1DZjlgUCORE=;\n\tb=PglL2iZyPyPPKB0okH3yo/bM/GxzNrhSNzo6ad0rd6bSMG3bO5J2YI1CviysLjAKNY\n\tMYRH1r7kFEgPn9wJ18rdUYNCO0Lpi9RgKIQmJO4h8qzxU2SmzwpDz34P9+lntFDtAy6B\n\t0Ct5Xfmrrd7xDBBzO8ciwEkWeV+o15wzE2L9+6CLWc6YZdOhp2uDWKze/rmRvPPWjVOg\n\tYtdWisry4msas1z0RwzHBlHGM6a56ijPXFdcJLoemm6vUOW57sTNFIubhFMNmpppFNtc\n\tysZ/S4bQ4MtMCbpiolAcMDjsac0bHA2sWGAnmEFi5XOs5zMJFLSo89Z3iSGLeoLXcae8\n\t7tqw==","X-Gm-Message-State":"AHPjjUg8gt56KAyP+p4lC11Um+Phv5Dglpiq047HDMFIs+IFhIoq7/SI\n\tlwyWHFvfVDZZ61UJv8Jqbxi/Gw==","X-Google-Smtp-Source":"ADKCNb4b41DZeNG1W5BmRkh+rLoalJMS7Re0Xbn2aIPzLiD6JM/k2EVIfZQshZ5YHPqUS8iJwp3LQQ==","X-Received":"by 10.36.189.14 with SMTP id x14mr11178328ite.30.1505120776755; \n\tMon, 11 Sep 2017 02:06:16 -0700 (PDT)","To":"Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>","From":"Alexey Kardashevskiy <aik@ozlabs.ru>","Message-ID":"<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>","Date":"Mon, 11 Sep 2017 19:06:10 +1000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-AU","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4001:c0b::243","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766174,"web_url":"http://patchwork.ozlabs.org/comment/1766174/","msgid":"<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>","list_archive_url":null,"date":"2017-09-11T09:37:41","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":2701,"url":"http://patchwork.ozlabs.org/api/people/2701/","name":"Paolo Bonzini","email":"pbonzini@redhat.com"},"content":"On 11/09/2017 11:06, Alexey Kardashevskiy wrote:\n> On 11/09/17 17:40, Paolo Bonzini wrote:\n>> On 07/09/2017 11:20, Alexey Kardashevskiy wrote:\n>>>  \n>>>      /* Accessed via RCU.  */\n>>>      struct FlatView *current_map;\n>>>  \n>>>      int ioeventfd_nb;\n>>>      struct MemoryRegionIoeventfd *ioeventfds;\n>>> -    struct AddressSpaceDispatch *dispatch;\n>>> -    struct AddressSpaceDispatch *next_dispatch;\n>>> +\n>>\n>> The rough idea of the patch matches my suggestion indeed.  However, I am\n>> not sure why all of the changes in patch 2 are needed.\n> \n> For this:\n> \n>  struct MemoryRegionSection {\n>      MemoryRegion *mr;\n> -    AddressSpace *address_space;\n> +    AddressSpaceDispatch *dispatch;\n> \n> as there are many ASes attached to the same flatview/dispatch.\n\nOk, this makes sense.  Maybe it should be a flatview rather than an\nAddressSpaceDispatch (a FlatView is essentially a list of\nMemoryRegionSections; attaching the ASD to the FlatView is more or less\nan implementation detail).\n\n\n> And because of that, there is also:\n> \n>  struct IOMMUTLBEntry {\n> -    AddressSpace    *target_as;\n> +    AddressSpaceDispatch *target_dispatch;\n> \n> as the \"section\" in address_space_get_iotlb_entry() does not have\n> address_space any more, even though the only user of it -\n> vhost_device_iotlb_miss() - only checks if (iotlb.target_dispatch != NULL).\n\nYou could change address_space_do_translate's \"as\" to AddressSpace **as.\n Then, address_space_get_iotlb_entry can populate the .target_as from\nthe output value of the argument.\n\n>> In addition, you could change the computation of FlatView's root to\n>> resolve 2^64-sized aliases;\n> \n> Here we reached the boundary of my english :)\n> \n> Roots are given when AS/Flatview is created, and aliases are resolved already.\n> \n\nCurrently, you're doing\n\n+        if (view->root == root) {\n+            as->current_map = flatview_get(view);\n+            break;\n+        }\n\n(and by the way the above doesn't resolve aliases; aliases are only\nresolved by render_memory_region).\n\nInstead, the FlatViews should be shared at transaction commit time.  At\nthe beginning of commit, the list of flat views is empty.  As you\nprocess each AddressSpace, you resolve the root alias(*) and search for\nthe resulting MemoryRegion in the list of FlatViews.  If you find it,\nyou do flatview_ref and point as->current_map to the FlatView you just\nfound.  Otherwise, you do generate_memory_topology etc. as in the old code.\n\n(*) something like\n\n\tMemoryRegion *mr = as->root;\n\tMemoryRegion *root_mr;\n\twhile (mr->alias && !mr->alias_offset &&\n\t       int128_ge(mr->size, mr->alias->size)) {\n\t    /* The alias is included in its entirety.  Use it as\n\t     * the \"real\" root, so that we can share more FlatViews.\n\t     */\n\t    mr = mr->alias;\n\t}\t\n\n\t/* We found the \"real\" root, but maybe we can use a shared empty\n\t * FlatView instead?\n\t */\n        for (root_mr = mr; root_mr; root_mr = root_mr->alias) {\n\t    if (!root_mr->enabled) {\n\t\t/* Use a shared empty FlatView.  */\n\t\treturn NULL;\n\t    }\n        }\n\n        return mr;\n\nAlso:\n\n> +static FlatView *flatview_get(FlatView *view)\n>  {\n> -    FlatView *view;\n> -\n>      rcu_read_lock();\n> -    view = atomic_rcu_read(&as->current_map);\n> +    view = atomic_rcu_read(&view);\n\nThis is \"view = view\" so it makes little sense, and then in the caller\n\n+    view = flatview_get(as->current_map);\n\nas->current_map is accessed without atomic_rcu_read.  So\naddress_space_get_flatview must stay.  Probably this will solve itself\nwhen you do the rest.\n\nPaolo\n\n>> also set it to NULL if the AddressSpace's\n>> root is disabled or the alias it resolves to is disabled (and so on\n>> recursively until a non-alias is found).  This should remove the need\n>> for address_space_root() and the change to pci_init_bus_master.\n> \n> \n> \n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=pbonzini@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrNCF0jvVz9s7G\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 19:38:15 +1000 (AEST)","from localhost ([::1]:56367 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drLAS-0006TF-CS\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 05:38:12 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:47468)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drLA4-0006Sz-Mn\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 05:37:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drLA1-0008G8-Gp\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 05:37:48 -0400","from mx1.redhat.com ([209.132.183.28]:43076)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pbonzini@redhat.com>) id 1drLA1-0008FX-83\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 05:37:45 -0400","from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 2852A33B5F9;\n\tMon, 11 Sep 2017 09:37:44 +0000 (UTC)","from [10.32.181.85] (unknown [10.32.181.85])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 0AFA05DA60;\n\tMon, 11 Sep 2017 09:37:42 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 2852A33B5F9","To":"Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>\n\t<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>","From":"Paolo Bonzini <pbonzini@redhat.com>","Message-ID":"<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>","Date":"Mon, 11 Sep 2017 11:37:41 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.14","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.30]);\n\tMon, 11 Sep 2017 09:37:44 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766258,"web_url":"http://patchwork.ozlabs.org/comment/1766258/","msgid":"<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>","list_archive_url":null,"date":"2017-09-11T12:08:32","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":7621,"url":"http://patchwork.ozlabs.org/api/people/7621/","name":"Alexey Kardashevskiy","email":"aik@ozlabs.ru"},"content":"On 11/09/17 19:37, Paolo Bonzini wrote:\n> On 11/09/2017 11:06, Alexey Kardashevskiy wrote:\n>> On 11/09/17 17:40, Paolo Bonzini wrote:\n>>> On 07/09/2017 11:20, Alexey Kardashevskiy wrote:\n>>>>  \n>>>>      /* Accessed via RCU.  */\n>>>>      struct FlatView *current_map;\n>>>>  \n>>>>      int ioeventfd_nb;\n>>>>      struct MemoryRegionIoeventfd *ioeventfds;\n>>>> -    struct AddressSpaceDispatch *dispatch;\n>>>> -    struct AddressSpaceDispatch *next_dispatch;\n>>>> +\n>>>\n>>> The rough idea of the patch matches my suggestion indeed.  However, I am\n>>> not sure why all of the changes in patch 2 are needed.\n>>\n>> For this:\n>>\n>>  struct MemoryRegionSection {\n>>      MemoryRegion *mr;\n>> -    AddressSpace *address_space;\n>> +    AddressSpaceDispatch *dispatch;\n>>\n>> as there are many ASes attached to the same flatview/dispatch.\n> \n> Ok, this makes sense.  Maybe it should be a flatview rather than an\n> AddressSpaceDispatch (a FlatView is essentially a list of\n> MemoryRegionSections; attaching the ASD to the FlatView is more or less\n> an implementation detail).\n\nThe helpers I converted from AddressSpace to AddressSpaceDispatch do use\ndispatch structure only and do not use FlatView so it seemed logical.\n\nbtw this address_space in MemoryRegionSection - it does not seem to make\nmuch sense in the PhysPageMap::sections array, it only makes sense when\nMemoryRegionSection uses as a temporary object when calling listeners. Will\nit make sense if we enforce MemoryRegionSection::address_space to be NULL\nin the array and not NULL when used temporary?\n\n\n> \n> \n>> And because of that, there is also:\n>>\n>>  struct IOMMUTLBEntry {\n>> -    AddressSpace    *target_as;\n>> +    AddressSpaceDispatch *target_dispatch;\n>>\n>> as the \"section\" in address_space_get_iotlb_entry() does not have\n>> address_space any more, even though the only user of it -\n>> vhost_device_iotlb_miss() - only checks if (iotlb.target_dispatch != NULL).\n> \n> You could change address_space_do_translate's \"as\" to AddressSpace **as.\n>  Then, address_space_get_iotlb_entry can populate the .target_as from\n> the output value of the argument.\n\nOk, since this seems better.\n\n\n> \n>>> In addition, you could change the computation of FlatView's root to\n>>> resolve 2^64-sized aliases;\n>>\n>> Here we reached the boundary of my english :)\n>>\n>> Roots are given when AS/Flatview is created, and aliases are resolved already.\n>>\n> \n> Currently, you're doing\n> \n> +        if (view->root == root) {\n> +            as->current_map = flatview_get(view);\n> +            break;\n> +        }\n> \n> (and by the way the above doesn't resolve aliases; aliases are only\n> resolved by render_memory_region).\n\nI am learning as we speak :)\n\n\n> \n> Instead, the FlatViews should be shared at transaction commit time.  At\n> the beginning of commit, the list of flat views is empty.  As you\n> process each AddressSpace, you resolve the root alias(*) and search for\n> the resulting MemoryRegion in the list of FlatViews.  If you find it,\n> you do flatview_ref and point as->current_map to the FlatView you just\n> found.  Otherwise, you do generate_memory_topology etc. as in the old code.\n> \n> (*) something like\n> \n> \tMemoryRegion *mr = as->root;\n> \tMemoryRegion *root_mr;\n> \twhile (mr->alias && !mr->alias_offset &&\n> \t       int128_ge(mr->size, mr->alias->size)) {\n> \t    /* The alias is included in its entirety.  Use it as\n> \t     * the \"real\" root, so that we can share more FlatViews.\n> \t     */\n> \t    mr = mr->alias;\n> \t}\t\n> \n> \t/* We found the \"real\" root, but maybe we can use a shared empty\n> \t * FlatView instead?\n> \t */\n>         for (root_mr = mr; root_mr; root_mr = root_mr->alias) {\n> \t    if (!root_mr->enabled) {\n> \t\t/* Use a shared empty FlatView.  */\n> \t\treturn NULL;\n> \t    }\n>         }\n> \n>         return mr;\n\n\nAh, makes sense now, thanks.\n\n> \n> Also:\n> \n>> +static FlatView *flatview_get(FlatView *view)\n>>  {\n>> -    FlatView *view;\n>> -\n>>      rcu_read_lock();\n>> -    view = atomic_rcu_read(&as->current_map);\n>> +    view = atomic_rcu_read(&view);\n> \n> This is \"view = view\" so it makes little sense, and then in the caller\n> \n> +    view = flatview_get(as->current_map);\n> \n> as->current_map is accessed without atomic_rcu_read.  So\n> address_space_get_flatview must stay.  Probably this will solve itself\n> when you do the rest.\n> \n> Paolo\n> \n>>> also set it to NULL if the AddressSpace's\n>>> root is disabled or the alias it resolves to is disabled (and so on\n>>> recursively until a non-alias is found).  This should remove the need\n>>> for address_space_root() and the change to pci_init_bus_master.\n>>\n>>\n>>\n>>\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ozlabs-ru.20150623.gappssmtp.com\n\theader.i=@ozlabs-ru.20150623.gappssmtp.com\n\theader.b=\"V0G7M/yc\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrRrt5Mggz9s71\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 22:22:38 +1000 (AEST)","from localhost ([::1]:57315 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drNWh-0006yv-QS\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 08:09:19 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:37597)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1drNWB-0006vZ-6f\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 08:08:52 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1drNW5-0000g6-V3\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 08:08:47 -0400","from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:36272)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <aik@ozlabs.ru>) id 1drNW5-0000dT-NR\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 08:08:41 -0400","by mail-it0-x244.google.com with SMTP id e134so1107416ite.3\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 05:08:39 -0700 (PDT)","from [192.168.10.22] (124-171-134-202.dyn.iinet.net.au.\n\t[124.171.134.202]) by smtp.googlemail.com with ESMTPSA id\n\t185sm4365484iov.60.2017.09.11.05.08.35\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 11 Sep 2017 05:08:37 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ozlabs-ru.20150623.gappssmtp.com; s=20150623;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=ynPfOQXYIaWLiYrcMYMu28/DUPf8mCEK4TXELiMFef4=;\n\tb=V0G7M/ycNK6fYuGuoMprl72dmZIemi7b7gG+srxwBl64GPW2jwjKsGcSVeqgm6CH7c\n\t/3HrLtt/xzk14h5U9R43Yvz8oKGKduskCspDYPaVKWItWLnsEfxov39QuIBWF3QWk1cv\n\tPHGvGiZqmLpQv6fTt6VntQfaFv1Jza+Ob6OYtx2s6P37Gb8nbaX1ft/Ppy91VE0Ax5rd\n\tzbAYiHmXFgwaaT/77+78pkqTVQ5xb9pNIo1RE8oNOCzYiXK/WZm3HiAB04TPX7KrO9KF\n\tSTZcONoXU5J6YYTOYvgzsbFGtbtK5mgy1rKaFejBN36lylVXmqckerOm2xx+nfL9mP5F\n\tFU5g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=ynPfOQXYIaWLiYrcMYMu28/DUPf8mCEK4TXELiMFef4=;\n\tb=s9+EH4im9vimy9uPP5cV2B7ACuMuVnKQMzrC6LU0rCPkbPVs5s6j2JXzcU/2dELuQ4\n\t7tN1uWkae0JODd8cNIpKwP5tj7AA1GEI+p0dFW5y7TLdQrJ22dLaS64THSqFs2Ry5Ks/\n\tiuyZPAXkECARK8FcX/K8CJNtthCTfZ3yqPhTiPOdlU7dx01CRfHCaoZwAE41rroW+GNM\n\t50YyMgILSafYezH6A4QAd8Kd6BFclfk9GNIqyU+9ArUo6H3Y/N7lqmEjZZaKG7LSIopz\n\tsI3q19uhGfjcNZL5Niy9lyvVyiwk3lcekyX9RkTNrQuTzPtoz52GcvwAYpKcDEG8GeeW\n\tIvOg==","X-Gm-Message-State":"AHPjjUhm0KwZWQKSsnrPy5M7WeP86r5y51V0msdNy83o7BHFqezo9zH+\n\th3fvc6I+k6CIA/5J","X-Google-Smtp-Source":"AOwi7QBgF2J1z6X6aA7cwPmwFDiJjCNp8RIVifg6XBoJ2UDtiISmJEaQ7R6TlZoHU44yKgXEE1MBOg==","X-Received":"by 10.36.57.71 with SMTP id l68mr2209251ita.138.1505131718290;\n\tMon, 11 Sep 2017 05:08:38 -0700 (PDT)","To":"Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>\n\t<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>\n\t<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>","From":"Alexey Kardashevskiy <aik@ozlabs.ru>","Message-ID":"<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>","Date":"Mon, 11 Sep 2017 22:08:32 +1000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-AU","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4001:c0b::244","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766367,"web_url":"http://patchwork.ozlabs.org/comment/1766367/","msgid":"<15727777-9a90-3da9-dfa0-17a717dcab15@redhat.com>","list_archive_url":null,"date":"2017-09-11T15:30:40","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":2701,"url":"http://patchwork.ozlabs.org/api/people/2701/","name":"Paolo Bonzini","email":"pbonzini@redhat.com"},"content":"On 11/09/2017 14:08, Alexey Kardashevskiy wrote:\n>> Ok, this makes sense.  Maybe it should be a flatview rather than an\n>> AddressSpaceDispatch (a FlatView is essentially a list of\n>> MemoryRegionSections; attaching the ASD to the FlatView is more or less\n>> an implementation detail).\n> The helpers I converted from AddressSpace to AddressSpaceDispatch do use\n> dispatch structure only and do not use FlatView so it seemed logical.\n\nUnderstood, but from a design POV FlatView makes more sense.\n\n> btw this address_space in MemoryRegionSection - it does not seem to make\n> much sense in the PhysPageMap::sections array, it only makes sense when\n> MemoryRegionSection uses as a temporary object when calling listeners. Will\n> it make sense if we enforce MemoryRegionSection::address_space to be NULL\n> in the array and not NULL when used temporary?\n\nmemory_region_section_get_iotlb needs to access the AddressSpaceDispatch\nfor sections stored in the PhysPageMap array, because\nmemory_region_section_get_iotlb uses the ASD to compute the section index.\n\nPaolo","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=pbonzini@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrXLF5qydz9s7B\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 01:44:53 +1000 (AEST)","from localhost ([::1]:58513 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drQtH-0006qO-Sy\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 11:44:51 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:52174)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drQfj-0003h8-G5\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 11:30:55 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drQfe-00069J-Jb\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 11:30:51 -0400","from mx1.redhat.com ([209.132.183.28]:5676)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pbonzini@redhat.com>) id 1drQfe-00067E-Bm\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 11:30:46 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 74D7E1A2270;\n\tMon, 11 Sep 2017 15:30:44 +0000 (UTC)","from [10.36.117.6] (ovpn-117-6.ams2.redhat.com [10.36.117.6])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 070D960F8A;\n\tMon, 11 Sep 2017 15:30:42 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 74D7E1A2270","To":"Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>\n\t<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>\n\t<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>\n\t<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>","From":"Paolo Bonzini <pbonzini@redhat.com>","Message-ID":"<15727777-9a90-3da9-dfa0-17a717dcab15@redhat.com>","Date":"Mon, 11 Sep 2017 17:30:40 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.26]);\n\tMon, 11 Sep 2017 15:30:44 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766692,"web_url":"http://patchwork.ozlabs.org/comment/1766692/","msgid":"<7fff3fb3-0d55-9c80-6269-ceb693ba93f0@ozlabs.ru>","list_archive_url":null,"date":"2017-09-12T05:55:14","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":7621,"url":"http://patchwork.ozlabs.org/api/people/7621/","name":"Alexey Kardashevskiy","email":"aik@ozlabs.ru"},"content":"On 12/09/17 01:30, Paolo Bonzini wrote:\n> On 11/09/2017 14:08, Alexey Kardashevskiy wrote:\n>>> Ok, this makes sense.  Maybe it should be a flatview rather than an\n>>> AddressSpaceDispatch (a FlatView is essentially a list of\n>>> MemoryRegionSections; attaching the ASD to the FlatView is more or less\n>>> an implementation detail).\n>> The helpers I converted from AddressSpace to AddressSpaceDispatch do use\n>> dispatch structure only and do not use FlatView so it seemed logical.\n> \n> Understood, but from a design POV FlatView makes more sense.\n> \n>> btw this address_space in MemoryRegionSection - it does not seem to make\n>> much sense in the PhysPageMap::sections array, it only makes sense when\n>> MemoryRegionSection uses as a temporary object when calling listeners. Will\n>> it make sense if we enforce MemoryRegionSection::address_space to be NULL\n>> in the array and not NULL when used temporary?\n> \n> memory_region_section_get_iotlb needs to access the AddressSpaceDispatch\n> for sections stored in the PhysPageMap array, because\n> memory_region_section_get_iotlb uses the ASD to compute the section index.\n\nOhhh, not extremely trivial, out of curiosity - is that iotlb encoding\ndescribed anywhere?\n\nAnyway, this can be simplified (or rather made more straightforward?) -\ntlb_set_page_with_attrs() can calculate the section index and pass it to\nmemory_region_section_get_iotlb(). Still does not make much sense? It just\nlooks quite useless to keep that address_space pointer alive just for one\ncase which can easily avoid using this pointer.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ozlabs-ru.20150623.gappssmtp.com\n\theader.i=@ozlabs-ru.20150623.gappssmtp.com\n\theader.b=\"xDa3wJXD\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrvD64FX1z9s7g\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 15:55:49 +1000 (AEST)","from localhost ([::1]:33771 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dreAg-0001h8-60\n\tfor incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 01:55:42 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:51266)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1dreAO-0001gp-A7\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 01:55:25 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1dreAL-0006Ky-9I\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 01:55:24 -0400","from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]:35837)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <aik@ozlabs.ru>) id 1dreAL-0006KU-3K\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 01:55:21 -0400","by mail-io0-x242.google.com with SMTP id d16so6342975ioj.2\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 22:55:20 -0700 (PDT)","from [10.61.2.175] ([122.99.82.10])\n\tby smtp.googlemail.com with ESMTPSA id\n\to137sm4366070iod.88.2017.09.11.22.55.17\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 11 Sep 2017 22:55:19 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ozlabs-ru.20150623.gappssmtp.com; s=20150623;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=irKg4VRb9Xu59inet119OS0rQonsNZJkKQHo0z1hUCQ=;\n\tb=xDa3wJXDgDNQuAWB8mojzlyPKY8+B0O0km9fZtRA5XhPvTfvCtNGyOrqNoxCIoQ+jl\n\taDoSPgXrTb+uKyqhda/ldw40X4vCiJjvhPiyNx1X0ny+JTW3oYBVaRDtgFsBh5ONu48l\n\tzJtq1w54f5cmphydKtUEXnTPr4HHrmBD6skzd89/OLtDS4ggCZFUEJ8NVeqPF0Qr1X9m\n\tMooTTcXErO1j4PvmALtGX4iUIPWHYYyPC3lmUW45zxelCFk7GeV5Yww84cHK+1nDXp8+\n\tQzmdohjKS8C93Q0zKQ6gO+P9zCoByCkIUZu3SmV3X3+9B1YwVZLdq6lw74fVBRtAxDPB\n\tPw5Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=irKg4VRb9Xu59inet119OS0rQonsNZJkKQHo0z1hUCQ=;\n\tb=OKc9TJuInhbP4siDK04OwufpZD4tuvyFOpl7AM4qOyQ22CtmWuve86Hvye98OmgOZz\n\ttDgkKnIuLG4l8O2xFavnTs5XJ75ezzcImijBvvUFoE5cBnHyQVOSmM3FZ4gvjf0UBkhX\n\twdaaS/Cl3OBDVxCyYnxbwOIZ0W1nQMkCr/1zKT/wIeI84wenk1GPwS2Rj3/QhVcHPgg2\n\tAVkMFzrtfaVkRO68Wq2xFzQ8DpV90XnX5MDlGIRYB6IfAg6VQpC7/og7amCVqYay5Cao\n\teWG6IXH2ShMx4U43V77fRxqvOLo/b637ORTkU2Vb14SXQvFbCinf2dWmKV9IFaVTZcOM\n\tx/Gg==","X-Gm-Message-State":"AHPjjUhGJUiqKIJrzifugCwkZdAqt0FoFxDQc9kXYO1bZRvsUIYKdpK4\n\t4/9IgUNN+mQHo4WK","X-Google-Smtp-Source":"ADKCNb5puktteH8moSqRj42bXmMoocVSw6OQx6ocT222baCy6XNclHoWPL0kwNGExtFrzU82DV8MGQ==","X-Received":"by 10.107.107.25 with SMTP id g25mr18770777ioc.78.1505195720077; \n\tMon, 11 Sep 2017 22:55:20 -0700 (PDT)","To":"Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>\n\t<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>\n\t<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>\n\t<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>\n\t<15727777-9a90-3da9-dfa0-17a717dcab15@redhat.com>","From":"Alexey Kardashevskiy <aik@ozlabs.ru>","Message-ID":"<7fff3fb3-0d55-9c80-6269-ceb693ba93f0@ozlabs.ru>","Date":"Tue, 12 Sep 2017 15:55:14 +1000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<15727777-9a90-3da9-dfa0-17a717dcab15@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-AU","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4001:c06::242","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766713,"web_url":"http://patchwork.ozlabs.org/comment/1766713/","msgid":"<adb82532-59fc-5eed-0976-0a08fea56601@redhat.com>","list_archive_url":null,"date":"2017-09-12T07:12:47","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":2701,"url":"http://patchwork.ozlabs.org/api/people/2701/","name":"Paolo Bonzini","email":"pbonzini@redhat.com"},"content":"On 12/09/2017 07:55, Alexey Kardashevskiy wrote:\n> On 12/09/17 01:30, Paolo Bonzini wrote:\n>> On 11/09/2017 14:08, Alexey Kardashevskiy wrote:\n>>>> Ok, this makes sense.  Maybe it should be a flatview rather than an\n>>>> AddressSpaceDispatch (a FlatView is essentially a list of\n>>>> MemoryRegionSections; attaching the ASD to the FlatView is more or less\n>>>> an implementation detail).\n>>> The helpers I converted from AddressSpace to AddressSpaceDispatch do use\n>>> dispatch structure only and do not use FlatView so it seemed logical.\n>>\n>> Understood, but from a design POV FlatView makes more sense.\n>>\n>>> btw this address_space in MemoryRegionSection - it does not seem to make\n>>> much sense in the PhysPageMap::sections array, it only makes sense when\n>>> MemoryRegionSection uses as a temporary object when calling listeners. Will\n>>> it make sense if we enforce MemoryRegionSection::address_space to be NULL\n>>> in the array and not NULL when used temporary?\n>>\n>> memory_region_section_get_iotlb needs to access the AddressSpaceDispatch\n>> for sections stored in the PhysPageMap array, because\n>> memory_region_section_get_iotlb uses the ASD to compute the section index.\n> \n> Ohhh, not extremely trivial, out of curiosity - is that iotlb encoding\n> described anywhere?\n\nNo, I don't think so.\n\n> Anyway, this can be simplified (or rather made more straightforward?) -\n> tlb_set_page_with_attrs() can calculate the section index and pass it to\n> memory_region_section_get_iotlb(). Still does not make much sense? It just\n> looks quite useless to keep that address_space pointer alive just for one\n> case which can easily avoid using this pointer.\n\nHmm I suppose address_space_translate_for_iotlb knows the ASD and could\nalso return the index, basically combining it and\nmemory_region_section_get_iotlb() into one function.\n\nPaolo","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=pbonzini@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrwxZ1x9Hz9s83\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 17:13:21 +1000 (AEST)","from localhost ([::1]:34007 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drfNm-0004ok-Dw\n\tfor incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 03:13:18 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38783)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drfNT-0004nB-3T\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 03:13:00 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pbonzini@redhat.com>) id 1drfNO-0006eh-4X\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 03:12:59 -0400","from mx1.redhat.com ([209.132.183.28]:47644)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pbonzini@redhat.com>) id 1drfNN-0006eP-UV\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 03:12:54 -0400","from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 9E127C0587C9;\n\tTue, 12 Sep 2017 07:12:52 +0000 (UTC)","from [10.36.117.43] (ovpn-117-43.ams2.redhat.com [10.36.117.43])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id B400F6C522;\n\tTue, 12 Sep 2017 07:12:50 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 9E127C0587C9","To":"Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>\n\t<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>\n\t<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>\n\t<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>\n\t<15727777-9a90-3da9-dfa0-17a717dcab15@redhat.com>\n\t<7fff3fb3-0d55-9c80-6269-ceb693ba93f0@ozlabs.ru>","From":"Paolo Bonzini <pbonzini@redhat.com>","Message-ID":"<adb82532-59fc-5eed-0976-0a08fea56601@redhat.com>","Date":"Tue, 12 Sep 2017 09:12:47 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<7fff3fb3-0d55-9c80-6269-ceb693ba93f0@ozlabs.ru>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.14","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.32]);\n\tTue, 12 Sep 2017 07:12:53 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1766832,"web_url":"http://patchwork.ozlabs.org/comment/1766832/","msgid":"<f6ef4cf1-d60f-e05d-a2c0-79dae240b0f6@ozlabs.ru>","list_archive_url":null,"date":"2017-09-12T09:47:04","subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","submitter":{"id":7621,"url":"http://patchwork.ozlabs.org/api/people/7621/","name":"Alexey Kardashevskiy","email":"aik@ozlabs.ru"},"content":"On 12/09/17 17:12, Paolo Bonzini wrote:\n> On 12/09/2017 07:55, Alexey Kardashevskiy wrote:\n>> On 12/09/17 01:30, Paolo Bonzini wrote:\n>>> On 11/09/2017 14:08, Alexey Kardashevskiy wrote:\n>>>>> Ok, this makes sense.  Maybe it should be a flatview rather than an\n>>>>> AddressSpaceDispatch (a FlatView is essentially a list of\n>>>>> MemoryRegionSections; attaching the ASD to the FlatView is more or less\n>>>>> an implementation detail).\n>>>> The helpers I converted from AddressSpace to AddressSpaceDispatch do use\n>>>> dispatch structure only and do not use FlatView so it seemed logical.\n>>>\n>>> Understood, but from a design POV FlatView makes more sense.\n>>>\n>>>> btw this address_space in MemoryRegionSection - it does not seem to make\n>>>> much sense in the PhysPageMap::sections array, it only makes sense when\n>>>> MemoryRegionSection uses as a temporary object when calling listeners. Will\n>>>> it make sense if we enforce MemoryRegionSection::address_space to be NULL\n>>>> in the array and not NULL when used temporary?\n>>>\n>>> memory_region_section_get_iotlb needs to access the AddressSpaceDispatch\n>>> for sections stored in the PhysPageMap array, because\n>>> memory_region_section_get_iotlb uses the ASD to compute the section index.\n>>\n>> Ohhh, not extremely trivial, out of curiosity - is that iotlb encoding\n>> described anywhere?\n> \n> No, I don't think so.\n> \n>> Anyway, this can be simplified (or rather made more straightforward?) -\n>> tlb_set_page_with_attrs() can calculate the section index and pass it to\n>> memory_region_section_get_iotlb(). Still does not make much sense? It just\n>> looks quite useless to keep that address_space pointer alive just for one\n>> case which can easily avoid using this pointer.\n> \n> Hmm I suppose address_space_translate_for_iotlb knows the ASD and could\n> also return the index, basically combining it and\n> memory_region_section_get_iotlb() into one function.\n\nOk, good.\n\nOne more question - how do we decide what goes to exec.c and what goes to\nmemory.c? I have a temptation to simply embed AddressSpaceDispatch into\nFlatView instead of allocating it and storing the pointer (I'll probably\navoid doing so for now anyway but still curios).\n\nThe header comment for exec.c says it is \"Virtual page mapping\" but\nAddressSpaceDispatch is a physical address space map and it seems to fit\ninto the memory.c's \"Physical memory management\" header comment.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ozlabs-ru.20150623.gappssmtp.com\n\theader.i=@ozlabs-ru.20150623.gappssmtp.com\n\theader.b=\"Q6bA1A4s\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xs0N369dNz9sNV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 19:48:03 +1000 (AEST)","from localhost ([::1]:34582 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drhnV-0006oZ-VH\n\tfor incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 05:48:02 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:52395)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1drhmk-0006lA-0e\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 05:47:19 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <aik@ozlabs.ru>) id 1drhmg-0007S3-VB\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 05:47:14 -0400","from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:34653)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <aik@ozlabs.ru>) id 1drhmg-0007Rq-N6\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 05:47:10 -0400","by mail-io0-x244.google.com with SMTP id g32so5851051ioj.1\n\tfor <qemu-devel@nongnu.org>; Tue, 12 Sep 2017 02:47:10 -0700 (PDT)","from [10.61.2.175] ([122.99.82.10])\n\tby smtp.googlemail.com with ESMTPSA id\n\th184sm3931455ioe.44.2017.09.12.02.47.07\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 12 Sep 2017 02:47:09 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ozlabs-ru.20150623.gappssmtp.com; s=20150623;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=0fxe5vo7lekQ1iLInxhnQhh8oj4o8Yoqja85b/6wa14=;\n\tb=Q6bA1A4sAPb0apEYfWVZtTmFRpz6mVrWGEiysAWKPc0za9OeZxiQgsGO7zljkl1e0l\n\tJbRJwUD8IMdKc3WFxpdDIWZnuQ6M0732nnRKZ1ojLlMkKMT44OfMIoGzS6TbCZlo1Qir\n\tNEPRAYLcLgdkrLF0Ez/v1SPgFiD24X/qsF0AcorID0gaMBXRuIp+kPRZLb25vTws0YAa\n\tM5FxxJWEANy5Ok+XDJBOo53dUArjQdx/9PiKeoORgrwfJeq68pFRWCdqo4TumbZ+zTN6\n\tPB1O3yijH59pCYE4+9UJ+Mc+P7cF1BxWFwjoIwdTrh73f5sGRsknXyHbQ54bPI4eo8bn\n\tr/IQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=0fxe5vo7lekQ1iLInxhnQhh8oj4o8Yoqja85b/6wa14=;\n\tb=djtEzFNGk6PJbTLYKEiVJ94JQ3sqb/Tdys5s+Ggp1AG3TLyI86IXi1RpDSPrlEPKQy\n\to07dyqHO2pvnTjF4YRrLT+W9L5S7PxUtAkBE0HL9giT9iTEBh57SvfiB4IdWm89EIzje\n\tniAcL7i9hwjwSMBpWa5OiR0mL/DBj8QRK1hHefbd5aQ55i1l3W1f0WxZCdhbZ+q9Itnp\n\tVfC6ukzJawqgzm1OmRVgfD+H+1zJS5IYuf99yQMQHsemriw5ydOAlBDhwRmGcQaT1D76\n\tH/Q5JIs/VvbMZB+uPB3Sqy5PMy7elitUTOUp/T8NNSbSuTrklv5IA2z/+qcfysCVVKY6\n\tm4TA==","X-Gm-Message-State":"AHPjjUh4WUUpvs6dEmXCIFjLxlgv5I5i6yZyZLC+jqG4x4Np7sCqLpGz\n\tOb3gak5Q9HSmVRl8","X-Google-Smtp-Source":"ADKCNb71o01oHQV2W9BpjO/0FeMImiMpffSdxkkeHD+Nvwv3Bhq0oZ2SIyX6PVzJ3zGkeTukRAPADw==","X-Received":"by 10.107.130.226 with SMTP id\n\tm95mr13794726ioi.273.1505209629981; \n\tTue, 12 Sep 2017 02:47:09 -0700 (PDT)","To":"Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org","References":"<20170907092010.3605-1-aik@ozlabs.ru>\n\t<20170907092010.3605-4-aik@ozlabs.ru>\n\t<984ae4a4-3045-e880-b39e-da846b1e2821@redhat.com>\n\t<b0ddd613-701c-4814-8241-d15d6917643f@ozlabs.ru>\n\t<32ae1779-0d00-0d1b-194f-130477531fdc@redhat.com>\n\t<38a55868-aea6-b0ef-3785-6d3621c2ab78@ozlabs.ru>\n\t<15727777-9a90-3da9-dfa0-17a717dcab15@redhat.com>\n\t<7fff3fb3-0d55-9c80-6269-ceb693ba93f0@ozlabs.ru>\n\t<adb82532-59fc-5eed-0976-0a08fea56601@redhat.com>","From":"Alexey Kardashevskiy <aik@ozlabs.ru>","Message-ID":"<f6ef4cf1-d60f-e05d-a2c0-79dae240b0f6@ozlabs.ru>","Date":"Tue, 12 Sep 2017 19:47:04 +1000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<adb82532-59fc-5eed-0976-0a08fea56601@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-AU","Content-Transfer-Encoding":"7bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:4001:c06::244","Subject":"Re: [Qemu-devel] [RFC PATCH qemu 3/4] memory: Share flat views and\n\tdispatch trees between address spaces","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Stefan Hajnoczi <stefanha@gmail.com>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tPeter Maydell <peter.maydell@linaro.org>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]