From nobody Wed Feb 11 04:00:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500535571673988.5432392800265; Thu, 20 Jul 2017 00:26:11 -0700 (PDT) Received: from localhost ([::1]:36420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY5qa-0000UE-DG for importer@patchew.org; Thu, 20 Jul 2017 03:26:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY5nH-0006Fe-1C for qemu-devel@nongnu.org; Thu, 20 Jul 2017 03:22:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dY5nC-0002zf-My for qemu-devel@nongnu.org; Thu, 20 Jul 2017 03:22:43 -0400 Received: from ozlabs.ru ([107.173.13.209]:59518) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY5nC-0002xl-GT; Thu, 20 Jul 2017 03:22:38 -0400 Received: from vpl2.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 98B4B3A6006C; Thu, 20 Jul 2017 03:23:27 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Thu, 20 Jul 2017 17:22:29 +1000 Message-Id: <20170720072231.35054-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170720072231.35054-1-aik@ozlabs.ru> References: <20170720072231.35054-1-aik@ozlabs.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 107.173.13.209 Subject: [Qemu-devel] [PATCH qemu v4 1/3] spapr_iommu: Realloc guest visible TCE table when hot(un)plugging vfio-pci X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This replaces g_malloc() with spapr_tce_alloc_table() as this is the standard way of allocating tables and this allows moving the table back to KVM when unplugging a VFIO PCI device and VFIO TCE acceleration support is not present in the KVM. Although spapr_tce_alloc_table() is expected to fail with EBUSY if called when previous fd is not closed yet, in practice we will not see it because cap_spapr_vfio is false at the moment. Signed-off-by: Alexey Kardashevskiy --- hw/ppc/spapr_iommu.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index e614621a83..307dc3021e 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -275,33 +275,26 @@ static int spapr_tce_table_realize(DeviceState *dev) void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio) { size_t table_size =3D tcet->nb_table * sizeof(uint64_t); - void *newtable; + uint64_t *oldtable; + int newfd =3D -1; =20 - if (need_vfio =3D=3D tcet->need_vfio) { - /* Nothing to do */ - return; - } + g_assert(need_vfio !=3D tcet->need_vfio); =20 - if (!need_vfio) { - /* FIXME: We don't support transition back to KVM accelerated - * TCEs yet */ - return; - } + tcet->need_vfio =3D need_vfio; =20 - tcet->need_vfio =3D true; + oldtable =3D tcet->table; =20 - if (tcet->fd < 0) { - /* Table is already in userspace, nothing to be do */ - return; - } + tcet->table =3D spapr_tce_alloc_table(tcet->liobn, + tcet->page_shift, + tcet->bus_offset, + tcet->nb_table, + &newfd, + need_vfio); + memcpy(tcet->table, oldtable, table_size); =20 - newtable =3D g_malloc(table_size); - memcpy(newtable, tcet->table, table_size); + spapr_tce_free_table(oldtable, tcet->fd, tcet->nb_table); =20 - kvmppc_remove_spapr_tce(tcet->table, tcet->fd, tcet->nb_table); - - tcet->fd =3D -1; - tcet->table =3D newtable; + tcet->fd =3D newfd; } =20 sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn) --=20 2.11.0