From nobody Mon Feb 9 15:46:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814338; cv=none; d=zohomail.com; s=zohoarc; b=mRcyHwpL++L5KhRcAS5WGrJcITq7SIy1xMyU0yDXKK+gMNl94EmmwO0DHutNDftkzeib+sp8amraWekpTNcmm7YpnXoLeadMm0j90UGS+1FGOnRtf2D4FfQ3hP0iKlJh1aiI3teHB7hXPqpKfq3N6GdEVXBdtgbp/LEDfzHa124= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814338; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=8tCh430uUATzOwz3ufEzgGlQkzhUTqSj3byRu2/z7X4=; b=WoavOoJP6FHhyyx6eCokxbZMVt0Iyxr/aUrg3LOjUAHfznxUUK0cNhVO+Sw93omWnZ1c/HCwku791bgkKaVtS0ojeeq3km1qmZORX8HOg0gS12UJgaQaW2q40PvflYqnAxD7EI+t1KBBc7d70GOGTTNem4Scbt5PMoAtJlmELTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 162981433802124.042761841852894; Tue, 24 Aug 2021 07:12:18 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-uAqldY0uOEyWpRgfmdAk4w-1; Tue, 24 Aug 2021 10:12:15 -0400 Received: by mail-wm1-f70.google.com with SMTP id r125-20020a1c2b830000b0290197a4be97b7so1091658wmr.9 for ; Tue, 24 Aug 2021 07:12:15 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id a77sm2581321wmd.31.2021.08.24.07.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8tCh430uUATzOwz3ufEzgGlQkzhUTqSj3byRu2/z7X4=; b=DskTsVc3cc1nGK1/sXVWp7PWIJz+ggmJfU+Xp0Xmw8usg1rMbzDoiirsLX9G6QzqgHkiIw gSgOdp4b4P4lLSvIQ2lNJwnkj6igt/48h0DdEqWct7nhimh/lTe2c26OkRIFSblaPir36B DWhyi+PMIQSQbvCseZfXdMLiwrel6KY= X-MC-Unique: uAqldY0uOEyWpRgfmdAk4w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8tCh430uUATzOwz3ufEzgGlQkzhUTqSj3byRu2/z7X4=; b=nyb5pkM7WYafTpu6K5k5llGqYrWoulnyxX4Xgg1FYgweBufGVhE/Hav4t/57fz1/1H qrRo12fYfqynNRpa1zy1JnLQxQGXtOBAkMj/EN8Vg1tx3oBbURb6CbdmxVrmbpvwSwwG v3rIFtK2Xmv20B2jq5+SJTjsGM+WBxdaLrnv7o7e+Cp0Hn21ds67YgX7l0j+xhT+iN1Q +DqQUXoTpOaLvPFO5XqAmD47ZiGDhDv0oA15T/v42DsMH3MS1O/mbtV+feLbIcNmSPXf teKZrjJD7QSJ5KcX8YNxU3m2nMAQvEwBpt0np+p2rkkQArOri1xIxtmXYwQJzwRSkT8M Iukg== X-Gm-Message-State: AOAM532X10avZJmlkj62Qjh0TOrEPGeuOk/Xkfxfb0r6yGmGEIwGG6+d 1qd80l7cFbXmroDncPOW2E5kT20cP5Zql959+VEnZPqy0ux+Y5rPyBzJ44rvgxyYL+oMP1T37Z8 XoqTPircycYthtQ== X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr4216045wme.81.1629814334562; Tue, 24 Aug 2021 07:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx034ZwJJZpiXZvD7xl4RIZ5xJ7ppmHdks4RVo2uA5G1/qHKrfIzfwU73Itb/koCYTEuAfMYg== X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr4216014wme.81.1629814334267; Tue, 24 Aug 2021 07:12:14 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 6/9] util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map() Date: Tue, 24 Aug 2021 16:11:39 +0200 Message-Id: <20210824141142.1165291-7-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210824141142.1165291-1-philmd@redhat.com> References: <20210824141142.1165291-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814339354100002 Currently qemu_vfio_dma_map() displays errors on stderr. When using management interface, this information is simply lost. Pass qemu_vfio_dma_map() an Error** handle so it can propagate the error to callers. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- Changed: - Initialize *err before calling error_prepend (Eric Auger) - use error_reportf_err() in nvme_register_buf() --- include/qemu/vfio-helpers.h | 2 +- block/nvme.c | 20 ++++++++++---------- util/vfio-helpers.c | 13 +++++++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h index 4491c8e1a6e..bde9495b254 100644 --- a/include/qemu/vfio-helpers.h +++ b/include/qemu/vfio-helpers.h @@ -18,7 +18,7 @@ typedef struct QEMUVFIOState QEMUVFIOState; QEMUVFIOState *qemu_vfio_open_pci(const char *device, Error **errp); void qemu_vfio_close(QEMUVFIOState *s); int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, - bool temporary, uint64_t *iova_list); + bool temporary, uint64_t *iova_list, Error **errp); int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s); void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host); void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, diff --git a/block/nvme.c b/block/nvme.c index 6642c104aa4..663e5d918fa 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -176,12 +176,11 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQue= ue *q, return false; } memset(q->queue, 0, bytes); - r =3D qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova); + r =3D qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova, err= p); if (r) { - error_setg(errp, "Cannot map queue"); - return false; + error_prepend(errp, "Cannot map queue: "); } - return true; + return r =3D=3D 0; } =20 static void nvme_free_queue_pair(NVMeQueuePair *q) @@ -239,7 +238,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, qemu_co_queue_init(&q->free_req_queue); q->completion_bh =3D aio_bh_new(aio_context, nvme_process_completion_b= h, q); r =3D qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes, - false, &prp_list_iova); + false, &prp_list_iova, errp); if (r) { goto fail; } @@ -533,9 +532,9 @@ static bool nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - r =3D qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova); + r =3D qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova, errp); if (r) { - error_setg(errp, "Cannot map buffer for DMA"); + error_prepend(errp, "Cannot map buffer for DMA: "); goto out; } =20 @@ -1031,7 +1030,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriver= State *bs, NvmeCmd *cmd, try_map: r =3D qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, - len, true, &iova); + len, true, &iova, NULL); if (r =3D=3D -ENOSPC) { /* * In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA @@ -1523,14 +1522,15 @@ static void nvme_aio_unplug(BlockDriverState *bs) static void nvme_register_buf(BlockDriverState *bs, void *host, size_t siz= e) { int ret; + Error *local_err =3D NULL; BDRVNVMeState *s =3D bs->opaque; =20 - ret =3D qemu_vfio_dma_map(s->vfio, host, size, false, NULL); + ret =3D qemu_vfio_dma_map(s->vfio, host, size, false, NULL, &local_err= ); if (ret) { /* FIXME: we may run out of IOVA addresses after repeated * bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_un= map * doesn't reclaim addresses for fixed mappings. */ - error_report("nvme_register_buf failed: %s", strerror(-ret)); + error_reportf_err(local_err, "nvme_register_buf failed: "); } } =20 diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index e7909222cfd..3e1a49bea15 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -463,13 +463,15 @@ static void qemu_vfio_ram_block_added(RAMBlockNotifie= r *n, void *host, size_t size, size_t max_size) { QEMUVFIOState *s =3D container_of(n, QEMUVFIOState, ram_notifier); + Error *local_err =3D NULL; int ret; =20 trace_qemu_vfio_ram_block_added(s, host, max_size); - ret =3D qemu_vfio_dma_map(s, host, max_size, false, NULL); + ret =3D qemu_vfio_dma_map(s, host, max_size, false, NULL, &local_err); if (ret) { - error_report("qemu_vfio_dma_map(%p, %zu) failed: %s", host, max_si= ze, - strerror(-ret)); + error_reportf_err(local_err, + "qemu_vfio_dma_map(%p, %zu) failed: ", + host, max_size); } } =20 @@ -725,7 +727,7 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size,= uint64_t *iova) * mapping status within this area is not allowed). */ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, - bool temporary, uint64_t *iova) + bool temporary, uint64_t *iova, Error **errp) { int ret =3D 0; int index; @@ -774,6 +776,9 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, *iova =3D iova0; } out: + if (ret) { + error_setg_errno(errp, -ret, "Cannot map buffer for DMA"); + } return ret; } =20 --=20 2.31.1