From nobody Mon Feb 9 11:51:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1603709765; cv=none; d=zohomail.com; s=zohoarc; b=TAedjx1N0J6m3Eqp/Rn20CnN9tUW1KHmql1Fo+pqkM9Oj+7MzwXyIc3ZYdZz0koBx4hnv/o8jNxoDaK4fpWbi0sXR8lkS8i+Vi/80oYDFwu+OY/JBRgVQGPZCn7/dxLyjA5ea3ZQxsvK+aSlFLPBH7Wl8hAREjpomcp1Yos4HiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603709765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=nFpAvnhzKFUahLqtIDcPSll9W0TpjYlTTuISswcMLmQ=; b=mo253RgiamExc0dCbT22/HsIyj72xkVKLNT22adufnLcQ5BUxwKgOO3jZfTf/2Bh6t4X6uzBkdSgzqV54XmgC7EDmmLT27MzbjeAtPVzp8fvUkB7rnq/wQ7BfpJHXuhI58OwIohEDUKgplMo76UBG4kMAGrQ+Us3eaXFpnzmRKI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603709765230108.89756600069188; Mon, 26 Oct 2020 03:56:05 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-7bp0afYLNumwHuEqhnhnIg-1; Mon, 26 Oct 2020 06:56:02 -0400 Received: by mail-wr1-f71.google.com with SMTP id n14so8189825wrp.1 for ; Mon, 26 Oct 2020 03:56:02 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id n6sm22440143wrj.60.2020.10.26.03.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 03:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603709764; 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=nFpAvnhzKFUahLqtIDcPSll9W0TpjYlTTuISswcMLmQ=; b=cGfTRYWibqZhesj9PkPKcCmPuCHPxzMklLOpWTctCn0HqM65VNYTVqOmBXLXoGGoClT5h0 BJtEkGgFEleouBfJGhLKWmU9et4eyn58pnBqQa173zC+8nuK83rd6VWh2j9CYTjnKq3MKP 5/WC3ep5zFxvAg1QlMP/UUP38JZuApI= X-MC-Unique: 7bp0afYLNumwHuEqhnhnIg-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=nFpAvnhzKFUahLqtIDcPSll9W0TpjYlTTuISswcMLmQ=; b=d0/LWVEIgo3UtxKZqG443tAWbaYqZwVDqI+rtNUCO2W0UUddZ4gFYmA8v7Sr/zuBCc bFX7JI9WnNw+AwJmEqFPq/P5YpHYDTJgk/wwhFjYWwiGVqrPcJ6P0vP4R37kGjExjf4Y 0s0C1AWLWd1vxKu6kkpsE/AWL4y960i4wnIBY2XAwQ5rU+3yCPcjQrn/DLPC+OVOJq7g THoVGf3OEHe65KPIUprzOa68fsDKOs+LV/Y6oO95gRdaf27sEz3aqtQVttSCQjROw9y8 +Lczu4u37KVGY7pxx9otEoAeviDNdmmQK7hFrLgSQwsnVK5sbzmmpZq7pQeca+uwfCof tUEw== X-Gm-Message-State: AOAM5305V5xvuLPJlaT4bFZEBCIqInm/1MQkxWT/6zf7k7L5fmXEh4S5 ZWy4Tct1miM1qd254jKipf/opbNCoFoiitMo0Mi6NmIuemjyXwW+GQn4e6B5ioyYRzDoYDHBXKe i95RBGwauljvL5w== X-Received: by 2002:adf:a50e:: with SMTP id i14mr17333463wrb.121.1603709760358; Mon, 26 Oct 2020 03:56:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8GK1OLplsiLuQMJxuiurJRsDQasKsAKfLItgMABPsNy9NlED7VnK9OxF8sRAIiKLQ26jIdA== X-Received: by 2002:adf:a50e:: with SMTP id i14mr17333431wrb.121.1603709760085; Mon, 26 Oct 2020 03:56:00 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eric Auger , Alex Williamson , qemu-block@nongnu.org, Fam Zheng , Max Reitz , Stefan Hajnoczi , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 11/19] util/vfio-helpers: Let qemu_vfio_dma_map() propagate Error Date: Mon, 26 Oct 2020 11:54:56 +0100 Message-Id: <20201026105504.4023620-12-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026105504.4023620-1-philmd@redhat.com> References: <20201026105504.4023620-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) 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* argument so it can propagate the error to callers. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/vfio-helpers.h | 2 +- block/nvme.c | 14 +++++++------- util/vfio-helpers.c | 12 +++++++----- 3 files changed, 15 insertions(+), 13 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 3b6d3972ec2..6f1ebdf031f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -167,9 +167,9 @@ static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue= *q, return; } 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"); + error_prepend(errp, "Cannot map queue: "); } } =20 @@ -223,7 +223,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, 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, s->page_size * NVME_NUM_REQS, - false, &prp_list_iova); + false, &prp_list_iova, errp); if (r) { goto fail; } @@ -514,9 +514,9 @@ static void 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, sizeof(*id), true, &iova); + r =3D qemu_vfio_dma_map(s->vfio, id, sizeof(*id), true, &iova, errp); if (r) { - error_setg(errp, "Cannot map buffer for DMA"); + error_prepend(errp, "Cannot map buffer for DMA: "); goto out; } =20 @@ -1003,7 +1003,7 @@ try_map: r =3D qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, qiov->iov[i].iov_len, - true, &iova); + true, &iova, NULL); if (r =3D=3D -ENOMEM && retry) { retry =3D false; trace_nvme_dma_flush_queue_wait(s); @@ -1450,7 +1450,7 @@ static void nvme_register_buf(BlockDriverState *bs, v= oid *host, size_t size) int ret; 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, NULL); if (ret) { /* FIXME: we may run out of IOVA addresses after repeated * bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_un= map diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 73f7bfa7540..c03fe0b7156 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -462,7 +462,7 @@ static void qemu_vfio_ram_block_added(RAMBlockNotifier = *n, { QEMUVFIOState *s =3D container_of(n, QEMUVFIOState, ram_notifier); trace_qemu_vfio_ram_block_added(s, host, size); - qemu_vfio_dma_map(s, host, size, false, NULL); + qemu_vfio_dma_map(s, host, size, false, NULL, NULL); } =20 static void qemu_vfio_ram_block_removed(RAMBlockNotifier *n, @@ -477,6 +477,7 @@ static void qemu_vfio_ram_block_removed(RAMBlockNotifie= r *n, =20 static int qemu_vfio_init_ramblock(RAMBlock *rb, void *opaque) { + Error *local_err =3D NULL; void *host_addr =3D qemu_ram_get_host_addr(rb); ram_addr_t length =3D qemu_ram_get_used_length(rb); int ret; @@ -485,10 +486,11 @@ static int qemu_vfio_init_ramblock(RAMBlock *rb, void= *opaque) if (!host_addr) { return 0; } - ret =3D qemu_vfio_dma_map(s, host_addr, length, false, NULL); + ret =3D qemu_vfio_dma_map(s, host_addr, length, false, NULL, &local_er= r); if (ret) { - fprintf(stderr, "qemu_vfio_init_ramblock: failed %p %" PRId64 "\n", - host_addr, (uint64_t)length); + error_reportf_err(local_err, + "qemu_vfio_init_ramblock: failed %p %" PRId64 ":= ", + host_addr, (uint64_t)length); } return 0; } @@ -724,7 +726,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; --=20 2.26.2