{"id":811539,"url":"http://patchwork.ozlabs.org/api/patches/811539/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170908103558.31632-22-david@gibson.dropbear.id.au/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170908103558.31632-22-david@gibson.dropbear.id.au>","list_archive_url":null,"date":"2017-09-08T10:35:39","name":"[PULL,21/40] spapr_iommu: Realloc guest visible TCE table when hot(un)plugging vfio-pci","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"fc3e728dae7569e074e6cb08f6fef9c649216646","submitter":{"id":47,"url":"http://patchwork.ozlabs.org/api/people/47/?format=json","name":"David Gibson","email":"david@gibson.dropbear.id.au"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170908103558.31632-22-david@gibson.dropbear.id.au/mbox/","series":[{"id":2179,"url":"http://patchwork.ozlabs.org/api/series/2179/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2179","date":"2017-09-08T10:35:20","name":"[PULL,01/40] hw/ppc/spapr_drc.c: change spapr_drc_needed to use drc->dev","version":1,"mbox":"http://patchwork.ozlabs.org/series/2179/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811539/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811539/checks/","tags":{},"related":[],"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\" (1024-bit key;\n\tunprotected) header.d=gibson.dropbear.id.au\n\theader.i=@gibson.dropbear.id.au header.b=\"go1Tc6iB\"; \n\tdkim-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 3xpZhs183Hz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 21:24:13 +1000 (AEST)","from localhost ([::1]:44536 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 1dqGwo-0002rz-8E\n\tfor incoming@patchwork.ozlabs.org; Fri, 08 Sep 2017 06:55:42 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:58656)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dqGe4-00028F-R0\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 06:36:29 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dqGe0-0003Do-0L\n\tfor qemu-devel@nongnu.org; Fri, 08 Sep 2017 06:36:20 -0400","from ozlabs.org ([2401:3900:2:1::2]:54769)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <dgibson@ozlabs.org>)\n\tid 1dqGdz-0003BR-Kz; Fri, 08 Sep 2017 06:36:15 -0400","by ozlabs.org (Postfix, from userid 1007)\n\tid 3xpYdL08BXz9t3F; Fri,  8 Sep 2017 20:36:04 +1000 (AEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=gibson.dropbear.id.au; s=201602; t=1504866966;\n\tbh=OgsMIVdFw6kCc/30oweqv63v02jgteI7SQbk4csd1uI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=go1Tc6iBc//srHQyZAG5D/2ZONj1sTydy5nz+3Y4inYyF92U4+2d2PSPtDzlRFARU\n\tanonn1L1qgi+0rrza67dMrH9GkW8joWn6JNumHSGcHZC8DM/XyzRqHJXCRtVdkbzNg\n\tWTyINfjNkIx4/tJ5MOJ7zpYxOaN7JGVHmUNzmb58=","From":"David Gibson <david@gibson.dropbear.id.au>","To":"peter.maydell@linaro.org","Date":"Fri,  8 Sep 2017 20:35:39 +1000","Message-Id":"<20170908103558.31632-22-david@gibson.dropbear.id.au>","X-Mailer":"git-send-email 2.13.5","In-Reply-To":"<20170908103558.31632-1-david@gibson.dropbear.id.au>","References":"<20170908103558.31632-1-david@gibson.dropbear.id.au>","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2401:3900:2:1::2","Subject":"[Qemu-devel] [PULL 21/40] spapr_iommu: Realloc guest visible TCE\n\ttable when hot(un)plugging vfio-pci","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":"qemu-devel@nongnu.org, aik@ozlabs.ru, agraf@suse.de,\n\tmdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org,\n\timammedo@redhat.com, sam.bobroff@au1.ibm.com,\n\tDavid Gibson <david@gibson.dropbear.id.au>","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>"},"content":"From: Alexey Kardashevskiy <aik@ozlabs.ru>\n\nThis replaces g_malloc() with spapr_tce_alloc_table() as this is\nthe standard way of allocating tables and this allows moving the table\nback to KVM when unplugging a VFIO PCI device and VFIO TCE acceleration\nsupport is not present in the KVM.\n\nAlthough spapr_tce_alloc_table() is expected to fail with EBUSY\nif called when previous fd is not closed yet, in practice we will not\nsee it because cap_spapr_vfio is false at the moment.\n\nSigned-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>\nSigned-off-by: David Gibson <david@gibson.dropbear.id.au>\n---\n hw/ppc/spapr_iommu.c | 35 ++++++++++++++---------------------\n 1 file changed, 14 insertions(+), 21 deletions(-)","diff":"diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c\nindex a75584c947..fa8b969840 100644\n--- a/hw/ppc/spapr_iommu.c\n+++ b/hw/ppc/spapr_iommu.c\n@@ -275,33 +275,26 @@ static void spapr_tce_table_realize(DeviceState *dev, Error **errp)\n void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio)\n {\n     size_t table_size = tcet->nb_table * sizeof(uint64_t);\n-    void *newtable;\n+    uint64_t *oldtable;\n+    int newfd = -1;\n \n-    if (need_vfio == tcet->need_vfio) {\n-        /* Nothing to do */\n-        return;\n-    }\n-\n-    if (!need_vfio) {\n-        /* FIXME: We don't support transition back to KVM accelerated\n-         * TCEs yet */\n-        return;\n-    }\n+    g_assert(need_vfio != tcet->need_vfio);\n \n-    tcet->need_vfio = true;\n+    tcet->need_vfio = need_vfio;\n \n-    if (tcet->fd < 0) {\n-        /* Table is already in userspace, nothing to be do */\n-        return;\n-    }\n+    oldtable = tcet->table;\n \n-    newtable = g_malloc(table_size);\n-    memcpy(newtable, tcet->table, table_size);\n+    tcet->table = spapr_tce_alloc_table(tcet->liobn,\n+                                        tcet->page_shift,\n+                                        tcet->bus_offset,\n+                                        tcet->nb_table,\n+                                        &newfd,\n+                                        need_vfio);\n+    memcpy(tcet->table, oldtable, table_size);\n \n-    kvmppc_remove_spapr_tce(tcet->table, tcet->fd, tcet->nb_table);\n+    spapr_tce_free_table(oldtable, tcet->fd, tcet->nb_table);\n \n-    tcet->fd = -1;\n-    tcet->table = newtable;\n+    tcet->fd = newfd;\n }\n \n sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn)\n","prefixes":["PULL","21/40"]}