From nobody Tue Feb 10 15:46:32 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; dkim=fail; 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 1504868203149677.9798492173718; Fri, 8 Sep 2017 03:56:43 -0700 (PDT) Received: from localhost ([::1]:44545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqGxm-0003N8-39 for importer@patchew.org; Fri, 08 Sep 2017 06:56:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dqGe4-00028F-R0 for qemu-devel@nongnu.org; Fri, 08 Sep 2017 06:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dqGe0-0003Do-0L for qemu-devel@nongnu.org; Fri, 08 Sep 2017 06:36:20 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:54769) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dqGdz-0003BR-Kz; Fri, 08 Sep 2017 06:36:15 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3xpYdL08BXz9t3F; Fri, 8 Sep 2017 20:36:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1504866966; bh=OgsMIVdFw6kCc/30oweqv63v02jgteI7SQbk4csd1uI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=go1Tc6iBc//srHQyZAG5D/2ZONj1sTydy5nz+3Y4inYyF92U4+2d2PSPtDzlRFARU anonn1L1qgi+0rrza67dMrH9GkW8joWn6JNumHSGcHZC8DM/XyzRqHJXCRtVdkbzNg WTyINfjNkIx4/tJ5MOJ7zpYxOaN7JGVHmUNzmb58= From: David Gibson 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 recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 21/40] 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: qemu-devel@nongnu.org, aik@ozlabs.ru, agraf@suse.de, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, imammedo@redhat.com, sam.bobroff@au1.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alexey Kardashevskiy 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 Signed-off-by: David Gibson --- 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 a75584c947..fa8b969840 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -275,33 +275,26 @@ static void spapr_tce_table_realize(DeviceState *dev,= Error **errp) 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; - } - - if (!need_vfio) { - /* FIXME: We don't support transition back to KVM accelerated - * TCEs yet */ - return; - } + g_assert(need_vfio !=3D tcet->need_vfio); =20 - tcet->need_vfio =3D true; + tcet->need_vfio =3D need_vfio; =20 - if (tcet->fd < 0) { - /* Table is already in userspace, nothing to be do */ - return; - } + oldtable =3D tcet->table; =20 - newtable =3D g_malloc(table_size); - memcpy(newtable, tcet->table, table_size); + 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 - kvmppc_remove_spapr_tce(tcet->table, tcet->fd, tcet->nb_table); + spapr_tce_free_table(oldtable, tcet->fd, tcet->nb_table); =20 - 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.13.5