From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhSqq-000666-FT for qemu-devel@nongnu.org; Wed, 30 Sep 2015 21:40:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhSqn-0005l1-8S for qemu-devel@nongnu.org; Wed, 30 Sep 2015 21:40:04 -0400 Date: Thu, 1 Oct 2015 10:45:44 +1000 From: David Gibson Message-ID: <20151001004544.GI23574@voom> References: <1443584920-23015-1-git-send-email-david@gibson.dropbear.id.au> <1443584920-23015-4-git-send-email-david@gibson.dropbear.id.au> <560BB46B.1090808@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="IR1Y5IvQhrKgS4e6" Content-Disposition: inline In-Reply-To: <560BB46B.1090808@redhat.com> Subject: Re: [Qemu-devel] [PATCH 3/4] spapr_iommu: Provide a function to switch a TCE table to allowing VFIO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: lvivier@redhat.com, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, alex.williamson@redhat.com, qemu-ppc@nongnu.org --IR1Y5IvQhrKgS4e6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 30, 2015 at 12:07:39PM +0200, Thomas Huth wrote: > On 30/09/15 05:48, David Gibson wrote: > > Because of the way non-VFIO guest IOMMU operations are KVM accelerated,= not > > all TCE tables (guest IOMMU contexts) can support VFIO devices. Curren= tly, > > this is decided at creation time. > >=20 > > To support hotplug of VFIO devices, we need to allow a TCE table which > > previously didn't allow VFIO devices to be switched so that it can. Th= is > > patch adds an spapr_tce_set_need_vfio() function to do this, by > > reallocating the table in userspace if necessary. > >=20 > > Currently this doesn't allow the KVM acceleration to be re-enabled if a= ll > > the VFIO devices are removed. That's an optimization for another time. > >=20 > > Signed-off-by: David Gibson > > --- > > hw/ppc/spapr_iommu.c | 32 ++++++++++++++++++++++++++++++++ > > include/hw/ppc/spapr.h | 2 ++ > > 2 files changed, 34 insertions(+) > >=20 > > diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c > > index 5166cde..8d60f8b 100644 > > --- a/hw/ppc/spapr_iommu.c > > +++ b/hw/ppc/spapr_iommu.c > > @@ -168,6 +168,38 @@ static int spapr_tce_table_realize(DeviceState *de= v) > > return 0; > > } > > =20 > > +void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio) > > +{ > > + size_t table_size =3D tcet->nb_table * sizeof(uint64_t); > > + void *newtable; > > + > > + 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; > > + } > > + > > + tcet->need_vfio =3D true; > > + > > + if (tcet->fd < 0) { > > + /* Table is already in userspace, nothing to be do */ > > + return; > > + } > > + > > + newtable =3D g_malloc0(table_size); >=20 > Since you immediately fill the whole table with the memcpy below, you do > not need to zero the memory here, i.e. g_malloc instead of g_malloc0 > should be sufficient. True, I just used malloc0 out of habit. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --IR1Y5IvQhrKgS4e6 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWDII3AAoJEGw4ysog2bOScJwP/3/Ke6zDlzIJ0j6mIQHOySMG l0LpaCTFg1O59EaL0iWKdOatMDxFNalxkhS9cNAH0Ap137VtExUTvTSFCgGB8/BL jB711Y9js64W5ZHUzJcdXfH7w8fteC/3fG6e+UPin5khzlPw9rneMKOnavXvPGGX GR96oLjskyaCBUhDln6p2raEaScl0fptfVDskcl8I34VT/qzBHJYYAfsrhkqnD5i IqZ2XsQupGGzsgj/qt+ICiz0yOP/GyniRNoxPuHKqw1ZTFM4ThPvGGanGccpGIaO podozfu7nD88uO/fnZBg0A8TDTmoE6abiUjyi6i3WjxKQXuNqDjac5R+fVJXl8DW xSSsIyF7OCO9fUut3jD4XSCDgLAFcRdFfiYXWnXWxj8nKfKzXU+U3x2NsIndesRf m3IhGdBduHvNda36lAIUeMExxuCEuZp2tmdM25P5OfVmo/l4HzduWi0vPJy1qq3y OhZBZO1iOD868iGtFScmYJgxCmqueW1JFQv25LJp41RuOjy3Bu6zAFM0pt20JwtZ IIN1wSNc/n5vt33FnXVcgpIaPwBlA34fC/+vNfQ54rwmeZ9QXNXzVhv3lNk4M2Zp q7XP9JrCJz/zvl/3zQVORpmRThzdNCo3noUTuYIwfX7givSyqrJLQSUjQRuyVARM IO/l6igL8BHwJubyEM6s =J0rJ -----END PGP SIGNATURE----- --IR1Y5IvQhrKgS4e6--