Received: from eggs.gnu.org ([2001:4830:134:3::10]:39582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btTcF-00074m-2q for qemu-devel@nongnu.org; Mon, 10 Oct 2016 01:59:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btTcB-0004Sy-Rh for qemu-devel@nongnu.org; Mon, 10 Oct 2016 01:59:10 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:51287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btTcA-0004SJ-SO for qemu-devel@nongnu.org; Mon, 10 Oct 2016 01:59:07 -0400 Date: Mon, 10 Oct 2016 16:34:07 +1100 From: David Gibson Message-ID: <20161010053407.GH22498@umbus.fritz.box> References: <1475770058-20409-1-git-send-email-eric.auger@redhat.com> <1475770058-20409-9-git-send-email-eric.auger@redhat.com> <87vax4abi8.fsf@dusky.pond.sub.org> <8e31bba2-5659-0796-8efd-8b66da46a232@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ZYOWEO2dMm2Af3e3" Content-Disposition: inline In-Reply-To: <8e31bba2-5659-0796-8efd-8b66da46a232@redhat.com> Subject: Re: [Qemu-devel] [PATCH v5 08/17] vfio: Pass an Error object to vfio_connect_container List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Auger Eric Cc: Markus Armbruster , alex.williamson@redhat.com, qemu-devel@nongnu.org, eric.auger.pro@gmail.com, aik@ozlabs.ru --ZYOWEO2dMm2Af3e3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 07, 2016 at 09:36:09AM +0200, Auger Eric wrote: > Hi, >=20 > On 07/10/2016 09:01, Markus Armbruster wrote: > > Eric Auger writes: > >=20 > >> The error is currently simply reported in vfio_get_group. Don't > >> bother too much with the prefix which will be handled at upper level, > >> later on. > >> > >> Also return an error value in case container->error is not 0 and > >> the container is teared down. > >=20 > > "torn down", I think. >=20 > Sure. I had a wrong feeling when writing this ... > >=20 > > Is this a bug fix? See also below. > >=20 > >> On vfio_spapr_remove_window failure, we also report an error whereas > >> it was silent before. > >> > >> Signed-off-by: Eric Auger > >> Reviewed-by: Markus Armbruster > >> > >> --- > >> > >> v4 -> v5: > >> - set ret to container->error > >> - mention error report on vfio_spapr_remove_window failure in the comm= it > >> message > >> --- > >> hw/vfio/common.c | 40 +++++++++++++++++++++++++--------------- > >> 1 file changed, 25 insertions(+), 15 deletions(-) > >> > >> diff --git a/hw/vfio/common.c b/hw/vfio/common.c > >> index 29188a1..85a7759 100644 > >> --- a/hw/vfio/common.c > >> +++ b/hw/vfio/common.c > >> @@ -34,6 +34,7 @@ > >> #include "qemu/range.h" > >> #include "sysemu/kvm.h" > >> #include "trace.h" > >> +#include "qapi/error.h" > >> =20 > >> struct vfio_group_head vfio_group_list =3D > >> QLIST_HEAD_INITIALIZER(vfio_group_list); > >> @@ -900,7 +901,8 @@ static void vfio_put_address_space(VFIOAddressSpac= e *space) > >> } > >> } > >> =20 > >> -static int vfio_connect_container(VFIOGroup *group, AddressSpace *as) > >> +static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, > >> + Error **errp) > >> { > >> VFIOContainer *container; > >> int ret, fd; > >> @@ -918,15 +920,15 @@ static int vfio_connect_container(VFIOGroup *gro= up, AddressSpace *as) > >> =20 > >> fd =3D qemu_open("/dev/vfio/vfio", O_RDWR); > >> if (fd < 0) { > >> - error_report("vfio: failed to open /dev/vfio/vfio: %m"); > >> + error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio"= ); > >> ret =3D -errno; > >> goto put_space_exit; > >> } > >> =20 > >> ret =3D ioctl(fd, VFIO_GET_API_VERSION); > >> if (ret !=3D VFIO_API_VERSION) { > >> - error_report("vfio: supported vfio version: %d, " > >> - "reported version: %d", VFIO_API_VERSION, ret); > >> + error_setg(errp, "supported vfio version: %d, " > >> + "reported version: %d", VFIO_API_VERSION, ret); > >> ret =3D -EINVAL; > >> goto close_fd_exit; > >> } > >> @@ -941,7 +943,7 @@ static int vfio_connect_container(VFIOGroup *group= , AddressSpace *as) > >> =20 > >> ret =3D ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd); > >> if (ret) { > >> - error_report("vfio: failed to set group container: %m"); > >> + error_setg_errno(errp, errno, "failed to set group contai= ner"); > >> ret =3D -errno; > >> goto free_container_exit; > >> } > >> @@ -949,7 +951,7 @@ static int vfio_connect_container(VFIOGroup *group= , AddressSpace *as) > >> container->iommu_type =3D v2 ? VFIO_TYPE1v2_IOMMU : VFIO_TYPE= 1_IOMMU; > >> ret =3D ioctl(fd, VFIO_SET_IOMMU, container->iommu_type); > >> if (ret) { > >> - error_report("vfio: failed to set iommu for container: %m= "); > >> + error_setg_errno(errp, errno, "failed to set iommu for co= ntainer"); > >> ret =3D -errno; > >> goto free_container_exit; > >> } > >> @@ -976,7 +978,7 @@ static int vfio_connect_container(VFIOGroup *group= , AddressSpace *as) > >> =20 > >> ret =3D ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd); > >> if (ret) { > >> - error_report("vfio: failed to set group container: %m"); > >> + error_setg_errno(errp, errno, "failed to set group contai= ner"); > >> ret =3D -errno; > >> goto free_container_exit; > >> } > >> @@ -984,7 +986,7 @@ static int vfio_connect_container(VFIOGroup *group= , AddressSpace *as) > >> v2 ? VFIO_SPAPR_TCE_v2_IOMMU : VFIO_SPAPR_TCE_IOMMU; > >> ret =3D ioctl(fd, VFIO_SET_IOMMU, container->iommu_type); > >> if (ret) { > >> - error_report("vfio: failed to set iommu for container: %m= "); > >> + error_setg_errno(errp, errno, "failed to set iommu for co= ntainer"); > >> ret =3D -errno; > >> goto free_container_exit; > >> } > >> @@ -997,7 +999,7 @@ static int vfio_connect_container(VFIOGroup *group= , AddressSpace *as) > >> if (!v2) { > >> ret =3D ioctl(fd, VFIO_IOMMU_ENABLE); > >> if (ret) { > >> - error_report("vfio: failed to enable container: %m"); > >> + error_setg_errno(errp, errno, "failed to enable conta= iner"); > >> ret =3D -errno; > >> goto free_container_exit; > >> } > >> @@ -1008,7 +1010,9 @@ static int vfio_connect_container(VFIOGroup *gro= up, AddressSpace *as) > >> &address_space_memory); > >> if (container->error) { > >=20 > > I tried to see where non-zero container->error comes from, but failed. > > Can you help? >=20 > Added Alexey in CC >=20 > It is set in vfio_prereg_listener_region_add (spapr.c) > There is a comment there saying: > /* > * On the initfn path, store the first error in the container so we > * can gracefully fail. Runtime, there's not much we can do other > * than throw a hardware error. > */ > 1) by the way I should also s/initfn/realize now. > 2) by gracefully fail I understand the error should be properly > cascaded. Also when looking at the other vfio_memory_listener > registration below, ret is set to container->error. > 3) I could use error_setg_errno ... >=20 > David, Alexey, could you confirm we should set the returned value to the > container->error below? I think the right approach is to change container->error from an int to an Error *. As now, we stash the first error from the listener in there. realize() would check for a non-NULL error in the container after registering the listener, and if present, propagate it up to the caller. >=20 > Thanks >=20 > Eric >=20 >=20 > >=20 > >> memory_listener_unregister(&container->prereg_listene= r); > >> - error_report("vfio: RAM memory listener initializatio= n failed for container"); > >> + ret =3D container->error; > >> + error_setg(errp, > >> + "RAM memory listener initialization failed for co= ntainer"); > >> goto free_container_exit; > >> } > >> } > >> @@ -1016,7 +1020,8 @@ static int vfio_connect_container(VFIOGroup *gro= up, AddressSpace *as) > >> info.argsz =3D sizeof(info); > >> ret =3D ioctl(fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &info); > >> if (ret) { > >> - error_report("vfio: VFIO_IOMMU_SPAPR_TCE_GET_INFO failed:= %m"); > >> + error_setg_errno(errp, errno, > >> + "VFIO_IOMMU_SPAPR_TCE_GET_INFO failed"); > >> ret =3D -errno; > >> if (v2) { > >> memory_listener_unregister(&container->prereg_listene= r); > >> @@ -1033,6 +1038,8 @@ static int vfio_connect_container(VFIOGroup *gro= up, AddressSpace *as) > >> */ > >> ret =3D vfio_spapr_remove_window(container, info.dma32_wi= ndow_start); > >> if (ret) { > >> + error_setg_errno(errp, -ret, > >> + "failed to remove existing window"); > >> goto free_container_exit; > >> } > >> } else { > >> @@ -1043,7 +1050,7 @@ static int vfio_connect_container(VFIOGroup *gro= up, AddressSpace *as) > >> 0x1000); > >> } > >> } else { > >> - error_report("vfio: No available IOMMU models"); > >> + error_setg(errp, "No available IOMMU models"); > >> ret =3D -EINVAL; > >> goto free_container_exit; > >> } > >> @@ -1054,7 +1061,8 @@ static int vfio_connect_container(VFIOGroup *gro= up, AddressSpace *as) > >> =20 > >> if (container->error) { > >> ret =3D container->error; > >> - error_report("vfio: memory listener initialization failed for= container"); > >> + error_setg_errno(errp, -ret, > >> + "memory listener initialization failed for c= ontainer"); > >> goto listener_release_exit; > >> } > >> =20 > >> @@ -1120,6 +1128,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSp= ace *as) > >> VFIOGroup *group; > >> char path[32]; > >> struct vfio_group_status status =3D { .argsz =3D sizeof(status) }; > >> + Error *err =3D NULL; > >> =20 > >> QLIST_FOREACH(group, &vfio_group_list, next) { > >> if (group->groupid =3D=3D groupid) { > >> @@ -1158,8 +1167,9 @@ VFIOGroup *vfio_get_group(int groupid, AddressSp= ace *as) > >> group->groupid =3D groupid; > >> QLIST_INIT(&group->device_list); > >> =20 > >> - if (vfio_connect_container(group, as)) { > >> - error_report("vfio: failed to setup container for group %d", = groupid); > >> + if (vfio_connect_container(group, as, &err)) { > >> + error_reportf_err(err, "vfio: failed to setup container for g= roup %d", > >> + groupid); > >> goto close_fd_exit; > >> } > >=20 >=20 --=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 --ZYOWEO2dMm2Af3e3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX+yhPAAoJEGw4ysog2bOSwrUP/3tL+7plNPL4SHEXvcuZvMMf eDNWCPEZChw9RgTRTx2Nbpx4HTnCjwg//i2RyI9iqBIQxPV6gRHJqbzBlFa4vyyH G+gYplaNWffx0dnA356B5Ra7FeiNyI7vgvZlDEFZr3P9olt9Nqflb4bQZh6MU+/S YYZH8VySwMQG2cBLpwEr6c6zPb4hShsL00ZmfnD/bsb/P1DdP+T73X4/OQUs4x2L sGUs5F1S/5lR2uccYhwf/wefIl5iryr4ktmk9v5EVbRoGmyEIzjva4e/x2T4Cnax 5gd6dj9JEWUX4/WZzrxLki3x8sfHUI2JaSqretxOnP+JMGqGnKSAkNDCzE75vB4f 3VaSEtPo+9PlUpd+rDSeHIKutdK39kkqsB6LumQHYJR7hjqSuSXeKBXZr62cyZ6F KQLnAeuXmG6UcdmMeuehmEiHZqyj0ufnZqoUSgCjDD0whTxEwxfv/HTCpkxaD76J MmsYuNATQcm1PO/7BoMQIbO0rfZHWOsxsMUJ2LMP+37mH+njTYAAKNyn8nLd8N/N yXZZJbuLJgdmear1Y441Eiysy+XjixYLo0eNsg3AqgBoBv1r6NY//N5Bep6dHy6b qxErY0Pwcx1WGlUWJ05pPhBc72gnU2Ba13kbqO5+DSc9lHP9htkhKdpvKiohP0Ab fhUIZePAhPB/IecR6j0u =nRiv -----END PGP SIGNATURE----- --ZYOWEO2dMm2Af3e3--