From patchwork Mon Mar 7 19:25:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8522101 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 967EBC0553 for ; Mon, 7 Mar 2016 19:38:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5EB1202B8 for ; Mon, 7 Mar 2016 19:38:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBCDD20295 for ; Mon, 7 Mar 2016 19:38:26 +0000 (UTC) Received: from localhost ([::1]:58005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad0z4-0000sj-7a for patchwork-qemu-devel@patchwork.kernel.org; Mon, 07 Mar 2016 14:38:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad0nB-0004Cu-CO for qemu-devel@nongnu.org; Mon, 07 Mar 2016 14:26:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ad0n8-00040H-D5 for qemu-devel@nongnu.org; Mon, 07 Mar 2016 14:26:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad0n8-0003zy-4X for qemu-devel@nongnu.org; Mon, 07 Mar 2016 14:26:06 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id C09492546; Mon, 7 Mar 2016 19:26:05 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-61.ams2.redhat.com [10.36.116.61]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u27JQ19o010774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 7 Mar 2016 14:26:04 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DB32130052FD; Mon, 7 Mar 2016 20:25:57 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 7 Mar 2016 20:25:46 +0100 Message-Id: <1457378754-21649-35-git-send-email-armbru@redhat.com> In-Reply-To: <1457378754-21649-1-git-send-email-armbru@redhat.com> References: <1457378754-21649-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: claudio.fontana@huawei.com, cam@cs.ualberta.ca, mlureau@redhat.com, david.marchand@6wind.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 34/42] ivshmem: Simplify memory regions for BAR 2 (shared memory) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ivshmem_realize() puts the shared memory region in a container region. Used to be necessary to permit delayed mapping of the shared memory. However, we recently moved to synchronous mapping, in "ivshmem: Receive shared memory synchronously in realize()" and the commit following it. The container is redundant since then. Drop it. Signed-off-by: Markus Armbruster Reviewed-by: Marc-André Lureau --- hw/misc/ivshmem.c | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 747f9c3..6a52a62 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -82,12 +82,8 @@ typedef struct IVShmemState { CharDriverState *server_chr; MemoryRegion ivshmem_mmio; - /* We might need to register the BAR before we actually have the memory. - * So prepare a container MemoryRegion for the BAR immediately and - * add a subregion when we have the memory. - */ - MemoryRegion bar; - MemoryRegion ivshmem; + MemoryRegion *ivshmem_bar2; /* BAR 2 (shared memory) */ + MemoryRegion server_bar2; /* used with server_chr */ size_t ivshmem_size; /* size of shared memory region */ uint32_t ivshmem_64bit; @@ -487,7 +483,7 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) Error *err = NULL; void *ptr; - if (memory_region_is_mapped(&s->ivshmem)) { + if (s->ivshmem_bar2) { error_setg(errp, "server sent unexpected shared memory message"); close(fd); return; @@ -506,11 +502,10 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) close(fd); return; } - memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), + memory_region_init_ram_ptr(&s->server_bar2, OBJECT(s), "ivshmem.bar2", s->ivshmem_size, ptr); - qemu_set_ram_fd(s->ivshmem.ram_addr, fd); - vmstate_register_ram(&s->ivshmem, DEVICE(s)); - memory_region_add_subregion(&s->bar, 0, &s->ivshmem); + qemu_set_ram_fd(s->server_bar2.ram_addr, fd); + s->ivshmem_bar2 = &s->server_bar2; } static void process_msg_disconnect(IVShmemState *s, uint16_t posn, @@ -696,7 +691,7 @@ static void ivshmem_recv_setup(IVShmemState *s, Error **errp) } } while (msg != -1); - assert(memory_region_is_mapped(&s->ivshmem)); + assert(s->ivshmem_bar2); } /* Select the MSI-X vectors used by device. @@ -899,7 +894,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ivshmem_mmio); - memory_region_init(&s->bar, OBJECT(s), "ivshmem-bar2-container", s->ivshmem_size); if (s->ivshmem_64bit) { attr |= PCI_BASE_ADDRESS_MEM_TYPE_64; } @@ -909,15 +903,10 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) } if (s->hostmem != NULL) { - MemoryRegion *mr; - IVSHMEM_DPRINTF("using hostmem\n"); - mr = host_memory_backend_get_memory(MEMORY_BACKEND(s->hostmem), - &error_abort); - vmstate_register_ram(mr, DEVICE(s)); - memory_region_add_subregion(&s->bar, 0, mr); - pci_register_bar(PCI_DEVICE(s), 2, attr, &s->bar); + s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem, + &error_abort); } else { IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", s->server_chr->filename); @@ -925,8 +914,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) /* we allocate enough space for 16 peers and grow as needed */ resize_peers(s, 16); - pci_register_bar(dev, 2, attr, &s->bar); - /* * Receive setup messages from server synchronously. * Older versions did it asynchronously, but that creates a @@ -947,6 +934,9 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) } } + vmstate_register_ram(s->ivshmem_bar2, DEVICE(s)); + pci_register_bar(PCI_DEVICE(s), 2, attr, s->ivshmem_bar2); + if (s->role_val == IVSHMEM_PEER) { error_setg(&s->migration_blocker, "Migration is disabled when using feature 'peer mode' in device 'ivshmem'"); @@ -964,22 +954,19 @@ static void pci_ivshmem_exit(PCIDevice *dev) error_free(s->migration_blocker); } - if (memory_region_is_mapped(&s->ivshmem)) { + if (memory_region_is_mapped(s->ivshmem_bar2)) { if (!s->hostmem) { - void *addr = memory_region_get_ram_ptr(&s->ivshmem); - int fd; + void *addr = memory_region_get_ram_ptr(s->ivshmem_bar2); if (munmap(addr, s->ivshmem_size) == -1) { error_report("Failed to munmap shared memory %s", strerror(errno)); } - if ((fd = qemu_get_ram_fd(s->ivshmem.ram_addr)) != -1) - close(fd); + close(qemu_get_ram_fd(s->ivshmem_bar2->ram_addr)); } - vmstate_unregister_ram(&s->ivshmem, DEVICE(dev)); - memory_region_del_subregion(&s->bar, &s->ivshmem); + vmstate_unregister_ram(s->ivshmem_bar2, DEVICE(dev)); } if (s->peers) {