Received: from eggs.gnu.org ([2001:4830:134:3::10]:46280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abCYP-00017E-OH for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:35:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abCYM-0001tb-Df for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:35:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46212) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abCYM-0001tM-5z for qemu-devel@nongnu.org; Wed, 02 Mar 2016 14:35:22 -0500 From: Markus Armbruster References: <1456771254-17511-1-git-send-email-armbru@redhat.com> <1456771254-17511-25-git-send-email-armbru@redhat.com> Date: Wed, 02 Mar 2016 20:35:17 +0100 In-Reply-To: (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Wed, 2 Mar 2016 19:27:09 +0100") Message-ID: <87fuw8d66i.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 24/38] ivshmem: Propagate errors through ivshmem_recv_setup() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: Paolo Bonzini , cam , Claudio Fontana , QEMU , David Marchand Marc-Andr=C3=A9 Lureau writes: > On Mon, Feb 29, 2016 at 7:40 PM, Markus Armbruster wr= ote: >> This kills off the funny state described in the previous commit. >> >> Simplify ivshmem_io_read() accordingly, and update documentation. >> >> Signed-off-by: Markus Armbruster >> --- >> docs/specs/ivshmem-spec.txt | 20 ++++---- >> hw/misc/ivshmem.c | 121 +++++++++++++++++++++++++++----------= ------- >> qemu-doc.texi | 9 +--- >> 3 files changed, 87 insertions(+), 63 deletions(-) >> >> diff --git a/docs/specs/ivshmem-spec.txt b/docs/specs/ivshmem-spec.txt >> index 4fc6f37..3eb8c97 100644 >> --- a/docs/specs/ivshmem-spec.txt >> +++ b/docs/specs/ivshmem-spec.txt >> @@ -62,11 +62,11 @@ There are two ways to use this device: >> likely want to write a kernel driver to handle interrupts. Requires >> the device to be configured for interrupts, obviously. >> >> -If the device is configured for interrupts, BAR2 is initially invalid. >> -It becomes safely accessible only after the ivshmem server provided >> -the shared memory. Guest software should wait for the IVPosition >> -register (described below) to become non-negative before accessing >> -BAR2. >> +Before QEMU 2.6.0, BAR2 can initially be invalid if the device is >> +configured for interrupts. It becomes safely accessible only after >> +the ivshmem server provided the shared memory. Guest software should >> +wait for the IVPosition register (described below) to become >> +non-negative before accessing BAR2. >> >> The device is not capable to tell guest software whether it is >> configured for interrupts. >> @@ -82,7 +82,7 @@ BAR 0 contains the following registers: >> 4 4 read/write 0 Interrupt Status >> bit 0: peer interrupt >> bit 1..31: reserved >> - 8 4 read-only 0 or -1 IVPosition >> + 8 4 read-only 0 or ID IVPosition >> 12 4 write-only N/A Doorbell >> bit 0..15: vector >> bit 16..31: peer ID >> @@ -100,12 +100,14 @@ when an interrupt request from a peer is received.= Reading the >> register clears it. >> >> IVPosition Register: if the device is not configured for interrupts, >> -this is zero. Else, it's -1 for a short while after reset, then >> -changes to the device's ID (between 0 and 65535). >> +this is zero. Else, it is the device's ID (between 0 and 65535). >> + >> +Before QEMU 2.6.0, the register may read -1 for a short while after >> +reset. >> >> There is no good way for software to find out whether the device is >> configured for interrupts. A positive IVPosition means interrupts, >> -but zero could be either. The initial -1 cannot be reliably observed. >> +but zero could be either. >> >> Doorbell Register: writing this register requests to interrupt a peer. >> The written value's high 16 bits are the ID of the peer to interrupt, >> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c >> index 352937f..831da53 100644 >> --- a/hw/misc/ivshmem.c >> +++ b/hw/misc/ivshmem.c >> @@ -234,12 +234,7 @@ static uint64_t ivshmem_io_read(void *opaque, hwadd= r addr, >> break; >> >> case IVPOSITION: >> - /* return my VM ID if the memory is mapped */ >> - if (memory_region_is_mapped(&s->ivshmem)) { >> - ret =3D s->vm_id; >> - } else { >> - ret =3D -1; >> - } >> + ret =3D s->vm_id; >> break; >> >> default: >> @@ -511,7 +506,8 @@ static bool fifo_update_and_get_i64(IVShmemState *s, >> return false; >> } >> >> -static int ivshmem_add_kvm_msi_virq(IVShmemState *s, int vector) >> +static void ivshmem_add_kvm_msi_virq(IVShmemState *s, int vector, >> + Error **errp) > > I prefer to return -1 in case of error, even if Error** is also returned. You know, I'd prefer that, too, and I've argued for it unsuccessfully. As it is, we fairly consistently return void when the function returns errors through Error ** and has no non-error value. >> { >> PCIDevice *pdev =3D PCI_DEVICE(s); >> MSIMessage msg =3D msix_get_message(pdev, vector); >> @@ -522,22 +518,21 @@ static int ivshmem_add_kvm_msi_virq(IVShmemState *= s, int vector) >> >> ret =3D kvm_irqchip_add_msi_route(kvm_state, msg, pdev); >> if (ret < 0) { >> - error_report("ivshmem: kvm_irqchip_add_msi_route failed"); >> - return -1; >> + error_setg(errp, "kvm_irqchip_add_msi_route failed"); >> + return; >> } >> >> s->msi_vectors[vector].virq =3D ret; >> s->msi_vectors[vector].pdev =3D pdev; >> - >> - return 0; >> } >> >> -static void setup_interrupt(IVShmemState *s, int vector) >> +static void setup_interrupt(IVShmemState *s, int vector, Error **errp) >> { >> EventNotifier *n =3D &s->peers[s->vm_id].eventfds[vector]; >> bool with_irqfd =3D kvm_msi_via_irqfd_enabled() && >> ivshmem_has_feature(s, IVSHMEM_MSI); >> PCIDevice *pdev =3D PCI_DEVICE(s); >> + Error *err =3D NULL; >> >> IVSHMEM_DPRINTF("setting up interrupt for vector: %d\n", vector); >> >> @@ -546,13 +541,16 @@ static void setup_interrupt(IVShmemState *s, int v= ector) >> watch_vector_notifier(s, n, vector); >> } else if (msix_enabled(pdev)) { >> IVSHMEM_DPRINTF("with irqfd\n"); >> - if (ivshmem_add_kvm_msi_virq(s, vector) < 0) { >> + ivshmem_add_kvm_msi_virq(s, vector, &err); >> + if (err) { >> + error_propagate(errp, err); >> return; > > That would make this simpler, avoiding local err variables, and > propagate. But you seem to prefer that form. I don't know if there is > any conventions (I am used to glib conventions, and usually a bool > success is returned, even if the function takes a GError) Does GLib spell out this convention somewhere? I can perhaps try to cook up a patch to demonstrate the advantages of returning a success/failure value even with Error **, and try to get our convention changed. Until then, we better stick to the existing convention, whether we like it or not. Thanks! [...]