Message ID | 20200212134254.11073-4-david@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Ram blocks with resizable anonymous allocations under POSIX | expand |
On Wed, Feb 12, 2020 at 02:42:41PM +0100, David Hildenbrand wrote: > Everybody discards the error. Let's error_report() instead so this error > doesn't get lost. > > Cc: Richard Henderson <rth@twiddle.net> > Cc: Paolo Bonzini <pbonzini@redhat.com> > Cc: Eduardo Habkost <ehabkost@redhat.com> > Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com> > Cc: Alex Williamson <alex.williamson@redhat.com> > Cc: Stefan Hajnoczi <stefanha@redhat.com> > Signed-off-by: David Hildenbrand <david@redhat.com> IMHO error_setg() should be preferred comparing to error_report() because it has a context to be delivered to the caller, so the error has a better chance to be used in a better way (e.g., QMP only supports error_setg()). A better solution is that we deliver the error upper. For example, qemu_vfio_dma_map() is one caller of qemu_vfio_undo_mapping, if you see the callers of qemu_vfio_dma_map() you'll notice most of them has Error** defined (e.g., nvme_init_queue). Then we can link all of them up. Another lazy solution (and especially if vfio-helpers are still mostly used only by advanced users) is we can simply pass in &error_abort for the three callers then they won't be missed... Thanks, > --- > util/vfio-helpers.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c > index d6332522c1..13dd962d95 100644 > --- a/util/vfio-helpers.c > +++ b/util/vfio-helpers.c > @@ -540,8 +540,7 @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size, > /** > * Undo the DMA mapping from @s with VFIO, and remove from mapping list. > */ > -static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping, > - Error **errp) > +static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping) > { > int index; > struct vfio_iommu_type1_dma_unmap unmap = { > @@ -556,7 +555,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping, > assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size)); > assert(index >= 0 && index < s->nr_mappings); > if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) { > - error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno); > + error_report("VFIO_UNMAP_DMA failed: %d", -errno); > } > memmove(mapping, &s->mappings[index + 1], > sizeof(s->mappings[0]) * (s->nr_mappings - index - 1)); > @@ -621,7 +620,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, > assert(qemu_vfio_verify_mappings(s)); > ret = qemu_vfio_do_mapping(s, host, size, iova0); > if (ret) { > - qemu_vfio_undo_mapping(s, mapping, NULL); > + qemu_vfio_undo_mapping(s, mapping); > goto out; > } > s->low_water_mark += size; > @@ -681,7 +680,7 @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host) > if (!m) { > goto out; > } > - qemu_vfio_undo_mapping(s, m, NULL); > + qemu_vfio_undo_mapping(s, m); > out: > qemu_mutex_unlock(&s->lock); > } > @@ -698,7 +697,7 @@ void qemu_vfio_close(QEMUVFIOState *s) > return; > } > while (s->nr_mappings) { > - qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1], NULL); > + qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1]); > } > ram_block_notifier_remove(&s->ram_notifier); > qemu_vfio_reset(s); > -- > 2.24.1 > >
On 18.02.20 23:07, Peter Xu wrote: > On Wed, Feb 12, 2020 at 02:42:41PM +0100, David Hildenbrand wrote: >> Everybody discards the error. Let's error_report() instead so this error >> doesn't get lost. >> >> Cc: Richard Henderson <rth@twiddle.net> >> Cc: Paolo Bonzini <pbonzini@redhat.com> >> Cc: Eduardo Habkost <ehabkost@redhat.com> >> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com> >> Cc: Alex Williamson <alex.williamson@redhat.com> >> Cc: Stefan Hajnoczi <stefanha@redhat.com> >> Signed-off-by: David Hildenbrand <david@redhat.com> > > IMHO error_setg() should be preferred comparing to error_report() > because it has a context to be delivered to the caller, so the error > has a better chance to be used in a better way (e.g., QMP only > supports error_setg()). Please note that I decided to go for error_report() because that's also what's being done in the matching opposite way: qemu_vfio_do_mapping(). > > A better solution is that we deliver the error upper. For example, > qemu_vfio_dma_map() is one caller of qemu_vfio_undo_mapping, if you > see the callers of qemu_vfio_dma_map() you'll notice most of them has > Error** defined (e.g., nvme_init_queue). Then we can link all of them > up. Propagating errors is helpful if the caller can actually do something with the error. If it's a function that's supposed to never fail (which is the case here obviously), then there is not much benefit in doing so. > > Another lazy solution (and especially if vfio-helpers are still mostly > used only by advanced users) is we can simply pass in &error_abort for > the three callers then they won't be missed... I prefer this variant, as it matches qemu_vfio_do_mapping() - except that we don't report -errno - which is fine, because the function is expected to not fail in any sane use case. Thanks!
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index d6332522c1..13dd962d95 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -540,8 +540,7 @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size, /** * Undo the DMA mapping from @s with VFIO, and remove from mapping list. */ -static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping, - Error **errp) +static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping) { int index; struct vfio_iommu_type1_dma_unmap unmap = { @@ -556,7 +555,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping, assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size)); assert(index >= 0 && index < s->nr_mappings); if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) { - error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno); + error_report("VFIO_UNMAP_DMA failed: %d", -errno); } memmove(mapping, &s->mappings[index + 1], sizeof(s->mappings[0]) * (s->nr_mappings - index - 1)); @@ -621,7 +620,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, assert(qemu_vfio_verify_mappings(s)); ret = qemu_vfio_do_mapping(s, host, size, iova0); if (ret) { - qemu_vfio_undo_mapping(s, mapping, NULL); + qemu_vfio_undo_mapping(s, mapping); goto out; } s->low_water_mark += size; @@ -681,7 +680,7 @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host) if (!m) { goto out; } - qemu_vfio_undo_mapping(s, m, NULL); + qemu_vfio_undo_mapping(s, m); out: qemu_mutex_unlock(&s->lock); } @@ -698,7 +697,7 @@ void qemu_vfio_close(QEMUVFIOState *s) return; } while (s->nr_mappings) { - qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1], NULL); + qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1]); } ram_block_notifier_remove(&s->ram_notifier); qemu_vfio_reset(s);
Everybody discards the error. Let's error_report() instead so this error doesn't get lost. Cc: Richard Henderson <rth@twiddle.net> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com> Cc: Alex Williamson <alex.williamson@redhat.com> Cc: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com> --- util/vfio-helpers.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)