From nobody Sat Feb 7 09:29:36 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=1603214728; cv=none; d=zohomail.com; s=zohoarc; b=WELNTVVzs0xlJPSdyVGc7prcJHOKaxP4sj9CC6E49LOYApxMtHkMj32Q5MgA08TeHQRPFnHwmkl1ZnPoJEKUON8mZOEmbwbuhNptfcVt9WrdE9blSv6ELyVmjdNk+glyqdSUWmg+bfFSW4c/ccsbgu051/qjc9WbKCVb6zpOpPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603214728; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=MLOm46KfCEikq86Y3pgvNvo5u9OAutjap0o+dhD/k3Y=; b=MSi+54o2NLoXJDaLZRwkl8mdLLQVCAOvqdlfJ2XG4VgbALhaL0dq8jUjMxaPpKa8zS30yRpOIHRzPoYvI3AM7BJMHe5Ve95a/SIVxrubggt2RPz0iFfDePZyJq577/ugvuFM5kWLQp/mo2o59i8xcp8baR4IaFbCntuND8uWkP4= 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 1603214728013831.915510043727; Tue, 20 Oct 2020 10:25:28 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-p2egXAHwM4OZMyFTZIfe-A-1; Tue, 20 Oct 2020 13:25:25 -0400 Received: by mail-wm1-f71.google.com with SMTP id u207so699729wmu.4 for ; Tue, 20 Oct 2020 10:25:25 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id y7sm3579711wmg.40.2020.10.20.10.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 10:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603214727; 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=MLOm46KfCEikq86Y3pgvNvo5u9OAutjap0o+dhD/k3Y=; b=hkmZBmCWu1PaQyueKxe5e6tg9/H+SKaRgmzFTsjYYbutVGKmFyvgdKzFMwhx2vxetn2Uw7 tXFnvglVztsatauvlpJjiKRslTVzHNl3qQmEVD1LHx5iCQ2qtzmYTS9B82q8BFyQCb6QQI 7Z54rTwVfzfIq0q+PCcCu9UIQTSQFZs= X-MC-Unique: p2egXAHwM4OZMyFTZIfe-A-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=MLOm46KfCEikq86Y3pgvNvo5u9OAutjap0o+dhD/k3Y=; b=do4CvcRlzj/BD9wkgymIxgGqRvm01RI+TXZ9N7MBb9Yw2OwmVf/uS/9tNsjdPDsT9S UUNAm1kPAK3NyZvlgpFeiJPKAxpOqzcZcjovQLBntevDenJCJnV893C9G3LfS6r72uWr bXDtmy1zHtEPTvww0BiIKzbYoIZ8LHKcoKmEGIhNPFbyCA1uUTQS2FYaHPlG0KwZ4x7r +oe7qfzkEzVbdJq9vqYxsA6P44IygoDs62WWkOLSKkthjuP53iB9Y3XHzDVhXqEVbe0b xk62WXEJHZel5EmAEwGnbTFzxO4aeDTHnWQNokRew7nqSJ8HOWdF8pGab4sNbf2uP9Fd RsEw== X-Gm-Message-State: AOAM5314l9QAb1Px381aKmYQ/UifoG05TgOUe1/N8SCoLns75cg6ECAT PIynr3Kw1kCJvROvBo1b+DTwaszOSaddrB1pVWhzBA9L+Q2ejzCCDtN92rS7BqaDH3odGqJLJL7 RR74zZB8Bik4gUg== X-Received: by 2002:a7b:c341:: with SMTP id l1mr4171332wmj.80.1603214721817; Tue, 20 Oct 2020 10:25:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4BCYIdH3y+v314ecWJ7QzYvUGZoGOW233TZDHOfC4Nw0fGTCX6iw6Y2XUy6c9lI9/PzLQmQ== X-Received: by 2002:a7b:c341:: with SMTP id l1mr4171309wmj.80.1603214721583; Tue, 20 Oct 2020 10:25:21 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Alex Williamson , Stefan Hajnoczi , Max Reitz , Fam Zheng , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 10/16] util/vfio-helpers: Let qemu_vfio_dma_map() propagate Error Date: Tue, 20 Oct 2020 19:24:22 +0200 Message-Id: <20201020172428.2220726-11-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201020172428.2220726-1-philmd@redhat.com> References: <20201020172428.2220726-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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- 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 5cb346d8e67..4b97a904e93 100644 --- a/include/qemu/vfio-helpers.h +++ b/include/qemu/vfio-helpers.h @@ -19,7 +19,7 @@ QEMUVFIOState *qemu_vfio_open_pci(const char *device, siz= e_t *min_page_size, 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 8335f5d70dd..428cda620df 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 @@ -990,7 +990,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); @@ -1437,7 +1437,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 6a5100f4892..8c075d9aae7 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -486,7 +486,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, @@ -501,6 +501,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; @@ -509,10 +510,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; } @@ -754,7 +756,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