From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631002603962168.25105507774822; Tue, 7 Sep 2021 01:16:43 -0700 (PDT) Received: from localhost ([::1]:44680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWHa-0007lh-02 for importer@patchew.org; Tue, 07 Sep 2021 04:16:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFI-0004jc-72 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53092) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFG-0005i1-M7 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-FYb3yVYFNPCOYLacVcnUcA-1; Tue, 07 Sep 2021 04:14:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CA038A8F1C; Tue, 7 Sep 2021 08:14:07 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5709761154; Tue, 7 Sep 2021 08:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002456; 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=pYjpySR/nm9LaUlAXzni6GWsTcvcpIzsjvvTl/Y6LC4=; b=gKiBPr46kt0oX0XKkIqcn3Z5MevI9VJTsQgRQASVjvyms2Gb3DhDexGAuN+NgOfv5e2NOR TfxyOzRKmsjuA0v8Guwa7SZG578ttP6NKWcqH6NOitIhTLbEBPQLSDXi6q69myzFRJd14V pgnDpsFGGX3qxj4LS+AH37eqBogBTNw= X-MC-Unique: FYb3yVYFNPCOYLacVcnUcA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 01/11] block/nvme: Use safer trace format string Date: Tue, 7 Sep 2021 09:13:53 +0100 Message-Id: <20210907081403.816404-2-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631002606187100001 From: Philippe Mathieu-Daud=C3=A9 Fix when building with -Wshorten-64-to-32: warning: implicit conversion loses integer precision: 'unsigned long' to = 'int' [-Wshorten-64-to-32] Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-2-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- block/trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/trace-events b/block/trace-events index b3d2b1e62c..f4f1267c8c 100644 --- a/block/trace-events +++ b/block/trace-events @@ -156,7 +156,7 @@ nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %= p offset 0x%"PRIx64" byte nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p off= set 0x%"PRIx64" bytes %"PRId64" ret %d" nvme_dma_map_flush(void *s) "s %p" nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u" -nvme_create_queue_pair(unsigned q_index, void *q, unsigned size, void *aio= _context, int fd) "index %u q %p size %u aioctx %p fd %d" +nvme_create_queue_pair(unsigned q_index, void *q, size_t size, void *aio_c= ontext, int fd) "index %u q %p size %zu aioctx %p fd %d" nvme_free_queue_pair(unsigned q_index, void *q) "index %u q %p" nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) = "s %p cmd %p req %p qiov %p entries %d" nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"= PRIx64 --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631002740611632.8604170473321; Tue, 7 Sep 2021 01:19:00 -0700 (PDT) Received: from localhost ([::1]:53054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWJn-0004x4-LV for importer@patchew.org; Tue, 07 Sep 2021 04:18:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFM-0004o2-5F for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFJ-0005kR-Or for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-508-Nn9qrgH2N7aaK2UoYc59Rg-1; Tue, 07 Sep 2021 04:14:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 581621009479; Tue, 7 Sep 2021 08:14:08 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00E3460C05; Tue, 7 Sep 2021 08:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002459; 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=q8g8l8Ml+nsGpirhpofSC2EU1nlgTx2mwvEh928NtqY=; b=XNGPF7EuRkvWAmNuPGnp73yT4yMW5BvWoUDgbaOccdmICdSJubsiu0ftNfOk2bj7eLqSg5 nIBuJuiDcxABZQ1syosFcDlFaLyWt7d5jYTecx/lJGjTGRTAE0Ta5BwZRCAuBSP3ILqtDJ kPAOqi94/QF/Ti7rD4spUf4gohdo0MM= X-MC-Unique: Nn9qrgH2N7aaK2UoYc59Rg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 02/11] util/vfio-helpers: Let qemu_vfio_verify_mappings() use error_report() Date: Tue, 7 Sep 2021 09:13:54 +0100 Message-Id: <20210907081403.816404-3-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631002741587100001 From: Philippe Mathieu-Daud=C3=A9 Instead of displaying the error on stderr, use error_report() which also report to the monitor. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-3-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 911115b86e..1d14913629 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -660,13 +660,13 @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *= s) if (QEMU_VFIO_DEBUG) { for (i =3D 0; i < s->nr_mappings - 1; ++i) { if (!(s->mappings[i].host < s->mappings[i + 1].host)) { - fprintf(stderr, "item %d not sorted!\n", i); + error_report("item %d not sorted!", i); qemu_vfio_dump_mappings(s); return false; } if (!(s->mappings[i].host + s->mappings[i].size <=3D s->mappings[i + 1].host)) { - fprintf(stderr, "item %d overlap with next!\n", i); + error_report("item %d overlap with next!", i); qemu_vfio_dump_mappings(s); return false; } --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631002692699422.53821262869076; Tue, 7 Sep 2021 01:18:12 -0700 (PDT) Received: from localhost ([::1]:49808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWJ1-0002kl-KF for importer@patchew.org; Tue, 07 Sep 2021 04:18:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFN-0004pH-O7 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFK-0005mT-Bb for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-TLs9K12_P4e1YhaVcvgxMQ-1; Tue, 07 Sep 2021 04:14:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F76383DC26; Tue, 7 Sep 2021 08:14:11 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BD6B7AB7B; Tue, 7 Sep 2021 08:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002461; 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=93rYJKlNrN2jvApOZPJ4Zj4TVrJ6PatDI633zamzLMQ=; b=O4tB/SkeBX7nr+zyVz4sDtrSrY0f0JqsuMwBBpQgX14NBcWH2BZpgTNIw6l1TZl3wBjjIR 0RgLFGNZmbvTyRBXpK4NVZ7T4Jqre02SaKCqQwDvvVv+liLJ/xxfogKd46SFUoAS0Mgv3h UzkIX333Sq20NUu9w6Iecc0Va/cYZf4= X-MC-Unique: TLs9K12_P4e1YhaVcvgxMQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 03/11] util/vfio-helpers: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD Date: Tue, 7 Sep 2021 09:13:55 +0100 Message-Id: <20210907081403.816404-4-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631002693816100001 From: Philippe Mathieu-Daud=C3=A9 Simplify qemu_vfio_dma_[un]map() handlers by replacing a pair of qemu_mutex_lock/qemu_mutex_unlock calls by the WITH_QEMU_LOCK_GUARD macro. Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-4-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 1d14913629..d956866b4e 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -735,7 +735,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size)); assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size)); trace_qemu_vfio_dma_map(s, host, size, temporary, iova); - qemu_mutex_lock(&s->lock); + QEMU_LOCK_GUARD(&s->lock); mapping =3D qemu_vfio_find_mapping(s, host, &index); if (mapping) { iova0 =3D mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->h= ost); @@ -778,7 +778,6 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, *iova =3D iova0; } out: - qemu_mutex_unlock(&s->lock); return ret; } =20 @@ -813,14 +812,12 @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host) } =20 trace_qemu_vfio_dma_unmap(s, host); - qemu_mutex_lock(&s->lock); + QEMU_LOCK_GUARD(&s->lock); m =3D qemu_vfio_find_mapping(s, host, &index); if (!m) { - goto out; + return; } qemu_vfio_undo_mapping(s, m, NULL); -out: - qemu_mutex_unlock(&s->lock); } =20 static void qemu_vfio_reset(QEMUVFIOState *s) --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631002894832535.3734144340328; Tue, 7 Sep 2021 01:21:34 -0700 (PDT) Received: from localhost ([::1]:59148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWMH-0000ba-RA for importer@patchew.org; Tue, 07 Sep 2021 04:21:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFO-0004pK-0V for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41482) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFM-0005o4-H0 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-MhCyrZMxMbKp-Ejz21F9Ww-1; Tue, 07 Sep 2021 04:14:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95C04107B45C; Tue, 7 Sep 2021 08:14:12 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C72B10074FD; Tue, 7 Sep 2021 08:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002463; 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=F4TSYJ6B2xP43vTwV5cv2ROnd8HH8ATBHprZ6uaO1XU=; b=evZHRuqR7eRSaf+9NrgdKlT17jPGRfrrOLWBgsjB0GOjoRzepq2kpix6Y1NLKmNd/ATxst K2KkZbTMloXgpbMenwuvCXpiNrwgX/rGT6kY+0KBqtYWsKZT3WCNvp+dK9GBMen51cYSGL hjjCYo1Y0pO6VxN7YWuC7JImQz5pQlw= X-MC-Unique: MhCyrZMxMbKp-Ejz21F9Ww-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 04/11] util/vfio-helpers: Remove unreachable code in qemu_vfio_dma_map() Date: Tue, 7 Sep 2021 09:13:56 +0100 Message-Id: <20210907081403.816404-5-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631002896764100001 From: Philippe Mathieu-Daud=C3=A9 qemu_vfio_add_mapping() returns a pointer to an indexed entry in pre-allocated QEMUVFIOState::mappings[], thus can not be NULL. Remove the pointless check. Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-5-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index d956866b4e..e7909222cf 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -751,10 +751,6 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, si= ze_t size, } =20 mapping =3D qemu_vfio_add_mapping(s, host, size, index + 1, io= va0); - if (!mapping) { - ret =3D -ENOMEM; - goto out; - } assert(qemu_vfio_verify_mappings(s)); ret =3D qemu_vfio_do_mapping(s, host, size, iova0); if (ret) { --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163100301764822.50621885434623; Tue, 7 Sep 2021 01:23:37 -0700 (PDT) Received: from localhost ([::1]:37842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWOG-0005KE-Hy for importer@patchew.org; Tue, 07 Sep 2021 04:23:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFP-0004s4-7q for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFN-0005nm-5v for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:26 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-563-lXO7294KO1CVUAxvpzPuFQ-1; Tue, 07 Sep 2021 04:14:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13C7F89BBA1; Tue, 7 Sep 2021 08:14:14 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id A776D177F1; Tue, 7 Sep 2021 08:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002463; 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=4Q3OEfmaPDOcp6CCZdLDj/9GuQmW79EFAPMEgAKzZP0=; b=agVUaidRZqrnY2W7uVPRYZ9bgwUzIPawSrSsqxPYsvNi0o6Boq0TG4LWJ0eVzZ4hpcGKxj U7XnMbrTK5Dw5++QhLWGzSk4XfYV8oB04GiQNY/utYz3T0hOttLA/V7m2g7e+ANm2qj/KY gCmNzTjkkAwqHSJgIckXvP+PULy80yA= X-MC-Unique: lXO7294KO1CVUAxvpzPuFQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 05/11] block/nvme: Have nvme_create_queue_pair() report errors consistently Date: Tue, 7 Sep 2021 09:13:57 +0100 Message-Id: <20210907081403.816404-6-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631003019329100001 From: Philippe Mathieu-Daud=C3=A9 nvme_create_queue_pair() does not return a boolean value (indicating eventual error) but a pointer, and is inconsistent in how it fills the error handler. To fulfill callers expectations, always set an error message on failure. Reported-by: Auger Eric Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-6-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- block/nvme.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index e8dbbc2317..0786c501e4 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -220,6 +220,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, =20 q =3D g_try_new0(NVMeQueuePair, 1); if (!q) { + error_setg(errp, "Cannot allocate queue pair"); return NULL; } trace_nvme_create_queue_pair(idx, q, size, aio_context, @@ -228,6 +229,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, qemu_real_host_page_size); q->prp_list_pages =3D qemu_try_memalign(qemu_real_host_page_size, byte= s); if (!q->prp_list_pages) { + error_setg(errp, "Cannot allocate PRP page list"); goto fail; } memset(q->prp_list_pages, 0, bytes); @@ -239,6 +241,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, r =3D qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes, false, &prp_list_iova); if (r) { + error_setg_errno(errp, -r, "Cannot map buffer for DMA"); goto fail; } q->free_req_head =3D -1; --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631002881344758.7681549328086; Tue, 7 Sep 2021 01:21:21 -0700 (PDT) Received: from localhost ([::1]:58208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWM4-0008NX-7b for importer@patchew.org; Tue, 07 Sep 2021 04:21:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFR-0004vI-Fm for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFO-0005q8-Pe for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-2Pkiad-4PySQlHBoWMGU1Q-1; Tue, 07 Sep 2021 04:14:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A192F8464CE; Tue, 7 Sep 2021 08:14:15 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3367760C05; Tue, 7 Sep 2021 08:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002466; 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=7HQiZUpQzhTafhnBU6B6Q8PRTOlVoSxJAHMWZjU5/K0=; b=M+Jsc037r+dhWvNOxR6hYLMBmP4VKBU150uXSZSEdBRF4kjQdWjoipcW7ZJo3/qOtHLua0 SgmNoc1wwbJHgPZDEtA7jwelZQIp/SRkUAA0aoYlf3ngnT+u1R5cjns8CvYbZ31lJhv8/y 9ncWtxeCc7hDmC5cUlEQ+WOTq4c/+EI= X-MC-Unique: 2Pkiad-4PySQlHBoWMGU1Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 06/11] util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map() Date: Tue, 7 Sep 2021 09:13:58 +0100 Message-Id: <20210907081403.816404-7-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631002883378100001 From: Philippe Mathieu-Daud=C3=A9 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 Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-7-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- include/qemu/vfio-helpers.h | 2 +- block/nvme.c | 22 +++++++++++----------- util/vfio-helpers.c | 10 ++++++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h index 4491c8e1a6..bde9495b25 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 0786c501e4..80546b0bab 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,9 +238,9 @@ 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) { - error_setg_errno(errp, -r, "Cannot map buffer for DMA"); + error_prepend(errp, "Cannot map buffer for DMA: "); goto fail; } q->free_req_head =3D -1; @@ -534,9 +533,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 @@ -1032,7 +1031,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 @@ -1524,14 +1523,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 e7909222cf..77cdec845d 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; --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631003160115502.8189729316357; Tue, 7 Sep 2021 01:26:00 -0700 (PDT) Received: from localhost ([::1]:44506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWQZ-0001RG-4z for importer@patchew.org; Tue, 07 Sep 2021 04:25:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFS-0004vQ-Ts for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFQ-0005qZ-B9 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-02Z_m-cdPgmgbPDOxSXSgw-1; Tue, 07 Sep 2021 04:14:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2DA8689841C; Tue, 7 Sep 2021 08:14:17 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAF575C25D; Tue, 7 Sep 2021 08:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002466; 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=hXpFeGMVgxi61M/SQMqA46qcKx93VZOyZUrQKfOfgAA=; b=JbYjWn+LMgIzbEJ1uJv+ugGY18zX9BaUroA2oV8hhrJSxw3IwrDPKgr56r9rKoUXf/jFvo rguY+dnn/23qOLs2H1CXzb/mvnsbFXwRGGeUnc/1R2FPspzgCUtkHxTXA8R5Vsn3DcxPXD fpj7Ta7q+m0p7C0q6uIsTiTpMPm0Yrk= X-MC-Unique: 02Z_m-cdPgmgbPDOxSXSgw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached() Date: Tue, 7 Sep 2021 09:13:59 +0100 Message-Id: <20210907081403.816404-8-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631003161190100001 From: Philippe Mathieu-Daud=C3=A9 Extract qemu_vfio_water_mark_reached() for readability, and have it provide an error hint it its Error* handle. Suggested-by: Klaus Jensen Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-8-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 77cdec845d..306b5a83e4 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -721,6 +721,21 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size= , uint64_t *iova) return -ENOMEM; } =20 +/** + * qemu_vfio_water_mark_reached: + * + * Returns %true if high watermark has been reached, %false otherwise. + */ +static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size, + Error **errp) +{ + if (s->high_water_mark - s->low_water_mark + 1 < size) { + error_setg(errp, "iova exhausted (water mark reached)"); + return true; + } + return false; +} + /* Map [host, host + size) area into a contiguous IOVA address space, and = store * the result in @iova if not NULL. The caller need to make sure the area = is * aligned to page size, and mustn't overlap with existing mapping areas (= split @@ -742,7 +757,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, if (mapping) { iova0 =3D mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->h= ost); } else { - if (s->high_water_mark - s->low_water_mark + 1 < size) { + if (qemu_vfio_water_mark_reached(s, size, errp)) { ret =3D -ENOMEM; goto out; } --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631003007901647.3454289326743; Tue, 7 Sep 2021 01:23:27 -0700 (PDT) Received: from localhost ([::1]:37036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWO6-0004nh-IR for importer@patchew.org; Tue, 07 Sep 2021 04:23:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFU-0004wY-I4 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25368) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFT-0005te-2O for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-247-02Rf7tJrPnyN-LpcnB4s7A-1; Tue, 07 Sep 2021 04:14:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB4A1824FAE; Tue, 7 Sep 2021 08:14:18 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 341346F13F; Tue, 7 Sep 2021 08:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002470; 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=hNN7PPEs3xVOszyd4cdrMYFkm/QD494M6a2Ii9NVsH8=; b=gKjYTYxs9s+XisYOx99A0QD6oWUvKmBMUZnpBozmkeY4kBW/Pkka2cjZh8T/oLWdnlmxhN 7Qgzxa76gEVQQ8FfQTsTKJCWongD/l8ysIPbRYDLgrQ1Top9JbHXrgpIuVFJxzwd06WhRQ KgpfF+VqgN7L1S4vArJrzLACGyHE8uI= X-MC-Unique: 02Rf7tJrPnyN-LpcnB4s7A-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 08/11] util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova Date: Tue, 7 Sep 2021 09:14:00 +0100 Message-Id: <20210907081403.816404-9-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631003008261100001 From: Philippe Mathieu-Daud=C3=A9 Both qemu_vfio_find_fixed_iova() and qemu_vfio_find_temp_iova() return an errno which is unused (or overwritten). Have them propagate eventual errors to callers, returning a boolean (which is what the Error API recommends, see commit e3fe3988d78 "error: Document Error API usage rules" for rationale). Suggested-by: Klaus Jensen Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-9-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 306b5a83e4..b93a3d3578 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -677,8 +677,8 @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s) return true; } =20 -static int -qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova) +static bool qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, + uint64_t *iova, Error **errp) { int i; =20 @@ -693,14 +693,16 @@ qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t si= ze, uint64_t *iova) s->usable_iova_ranges[i].end - s->low_water_mark + 1 =3D=3D 0)= { *iova =3D s->low_water_mark; s->low_water_mark +=3D size; - return 0; + return true; } } - return -ENOMEM; + error_setg(errp, "fixed iova range not found"); + + return false; } =20 -static int -qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova) +static bool qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, + uint64_t *iova, Error **errp) { int i; =20 @@ -715,10 +717,12 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t siz= e, uint64_t *iova) s->high_water_mark - s->usable_iova_ranges[i].start + 1 =3D=3D= 0) { *iova =3D s->high_water_mark - size; s->high_water_mark =3D *iova; - return 0; + return true; } } - return -ENOMEM; + error_setg(errp, "temporary iova range not found"); + + return false; } =20 /** @@ -762,7 +766,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, goto out; } if (!temporary) { - if (qemu_vfio_find_fixed_iova(s, size, &iova0)) { + if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) { ret =3D -ENOMEM; goto out; } @@ -776,7 +780,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, } qemu_vfio_dump_mappings(s); } else { - if (qemu_vfio_find_temp_iova(s, size, &iova0)) { + if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) { ret =3D -ENOMEM; goto out; } --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631002644249540.8663689158999; Tue, 7 Sep 2021 01:17:24 -0700 (PDT) Received: from localhost ([::1]:47574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWIF-0001HR-1q for importer@patchew.org; Tue, 07 Sep 2021 04:17:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFa-0004zG-4h for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43867) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFY-0005yS-3J for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-9xTmU7nnMK6AcyVwzrHiqQ-1; Tue, 07 Sep 2021 04:14:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F206C88CE52; Tue, 7 Sep 2021 08:14:19 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9971C5C25D; Tue, 7 Sep 2021 08:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002475; 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=8Z217EBN92D/0PCJMeZ1/Pib2j2Ln3Fdgndik+fQpxg=; b=RX7PjZq5r/0wE3u+ptK6a2C8ib2Yrt/AeKExUfREn2Z7bWnZ6cug6/lXDFMOnkZ+pXpe2W hTENAVbrAGDyG6Rej20PqSiVatWEKGqIsbe+llASA/j+XfZ4n7QnnrzipIvwDK+6kdDkDa RCLcmYpnKtEDWAIzwKL941rb7tBiAA4= X-MC-Unique: 9xTmU7nnMK6AcyVwzrHiqQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 09/11] util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly Date: Tue, 7 Sep 2021 09:14:01 +0100 Message-Id: <20210907081403.816404-10-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631002645899100001 From: Philippe Mathieu-Daud=C3=A9 To simplify qemu_vfio_dma_map(): - reduce 'ret' (returned value) scope by returning errno directly, - remove the goto 'out' label. Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-10-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index b93a3d3578..66148bd381 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -748,7 +748,6 @@ static bool qemu_vfio_water_mark_reached(QEMUVFIOState = *s, size_t size, int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, bool temporary, uint64_t *iova, Error **errp) { - int ret =3D 0; int index; IOVAMapping *mapping; uint64_t iova0; @@ -761,32 +760,31 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, s= ize_t size, if (mapping) { iova0 =3D mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->h= ost); } else { + int ret; + if (qemu_vfio_water_mark_reached(s, size, errp)) { - ret =3D -ENOMEM; - goto out; + return -ENOMEM; } if (!temporary) { if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) { - ret =3D -ENOMEM; - goto out; + return -ENOMEM; } =20 mapping =3D qemu_vfio_add_mapping(s, host, size, index + 1, io= va0); assert(qemu_vfio_verify_mappings(s)); ret =3D qemu_vfio_do_mapping(s, host, size, iova0); - if (ret) { + if (ret < 0) { qemu_vfio_undo_mapping(s, mapping, NULL); - goto out; + return ret; } qemu_vfio_dump_mappings(s); } else { if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) { - ret =3D -ENOMEM; - goto out; + return -ENOMEM; } ret =3D qemu_vfio_do_mapping(s, host, size, iova0); - if (ret) { - goto out; + if (ret < 0) { + return ret; } } } @@ -794,8 +792,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, if (iova) { *iova =3D iova0; } -out: - return ret; + return 0; } =20 /* Reset the high watermark and free all "temporary" mappings. */ --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631003131673314.06064045944083; Tue, 7 Sep 2021 01:25:31 -0700 (PDT) Received: from localhost ([::1]:43400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWQ6-0000dC-MY for importer@patchew.org; Tue, 07 Sep 2021 04:25:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFb-00051C-ES for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFZ-0005zl-Rv for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-Pn9dAEKAOV-BfyTY9DHozQ-1; Tue, 07 Sep 2021 04:14:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3E1956AD5; Tue, 7 Sep 2021 08:14:21 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 209937D45B; Tue, 7 Sep 2021 08:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002477; 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=e/3whkJTrFbB+0ZrHaFpObf/KPohjSDNvAbENg1Wsas=; b=C6kBwoH/oDwKGhUwkkpIB3imzVGzPlhzVvQWadLKNU/PHAs02WzSPMtrxxgIhoYqglvx22 71za7boaHY2sSU3IlUO3qXV0VwYYbNlG1UOwfWoxC/fb8Po7p/Ym7SlTH5gv/EZzuz9rgI J09oabf4lmt0o3h8SExIdmqlPql8Drw= X-MC-Unique: Pn9dAEKAOV-BfyTY9DHozQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 10/11] util/vfio-helpers: Let qemu_vfio_do_mapping() propagate Error Date: Tue, 7 Sep 2021 09:14:02 +0100 Message-Id: <20210907081403.816404-11-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631003133646100001 From: Philippe Mathieu-Daud=C3=A9 Pass qemu_vfio_do_mapping() an Error* argument so it can propagate any error to callers. Replace error_report() which only report to the monitor by the more generic error_setg_errno(). Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-11-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vfio-helpers.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 66148bd381..00a80431a0 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -610,7 +610,7 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState= *s, =20 /* Do the DMA mapping with VFIO. */ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size, - uint64_t iova) + uint64_t iova, Error **errp) { struct vfio_iommu_type1_dma_map dma_map =3D { .argsz =3D sizeof(dma_map), @@ -622,7 +622,7 @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void = *host, size_t size, trace_qemu_vfio_do_mapping(s, host, iova, size); =20 if (ioctl(s->container, VFIO_IOMMU_MAP_DMA, &dma_map)) { - error_report("VFIO_MAP_DMA failed: %s", strerror(errno)); + error_setg_errno(errp, errno, "VFIO_MAP_DMA failed"); return -errno; } return 0; @@ -772,7 +772,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, =20 mapping =3D qemu_vfio_add_mapping(s, host, size, index + 1, io= va0); assert(qemu_vfio_verify_mappings(s)); - ret =3D qemu_vfio_do_mapping(s, host, size, iova0); + ret =3D qemu_vfio_do_mapping(s, host, size, iova0, errp); if (ret < 0) { qemu_vfio_undo_mapping(s, mapping, NULL); return ret; @@ -782,7 +782,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) { return -ENOMEM; } - ret =3D qemu_vfio_do_mapping(s, host, size, iova0); + ret =3D qemu_vfio_do_mapping(s, host, size, iova0, errp); if (ret < 0) { return ret; } --=20 2.31.1 From nobody Mon May 6 23:47:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163100328989046.494363278640435; Tue, 7 Sep 2021 01:28:09 -0700 (PDT) Received: from localhost ([::1]:49732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNWSe-00050L-Qd for importer@patchew.org; Tue, 07 Sep 2021 04:28:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFe-0005Cm-SA for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNWFd-00062W-1N for qemu-devel@nongnu.org; Tue, 07 Sep 2021 04:14:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-409-7MG771uWMHWFu50t4sX1fA-1; Tue, 07 Sep 2021 04:14:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07BA81020C53; Tue, 7 Sep 2021 08:14:23 +0000 (UTC) Received: from localhost (unknown [10.39.194.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id A61EF1B5C1; Tue, 7 Sep 2021 08:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631002480; 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=KGJG/Cv2iUbtf3xyS49RMJu5hUyBKS31W5r+ddrVYUo=; b=QdIHNxO/dia6HMb/QNV6sqVEe/eDNy44QKqVeYh2zv84URbSX7f7U4G8yDt78Jw+nGpxPa fDh8qEKi5HSZh5f7tSd67JDbyCSufHAfpNEGnwVXyl9IPwtBuIL/5c9zeiQHwOXmq51jG1 sVPeRam0twIiJmQvp3vVISMx/4uZOwM= X-MC-Unique: 7MG771uWMHWFu50t4sX1fA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 11/11] block/nvme: Only report VFIO error on failed retry Date: Tue, 7 Sep 2021 09:14:03 +0100 Message-Id: <20210907081403.816404-12-stefanha@redhat.com> In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com> References: <20210907081403.816404-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Tingting Mao , Klaus Jensen , Hanna Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631003292237100001 From: Philippe Mathieu-Daud=C3=A9 We expect the first qemu_vfio_dma_map() to fail (indicating DMA mappings exhaustion, see commit 15a730e7a3a). Do not report the first failure as error, since we are going to flush the mappings and retry. This removes spurious error message displayed on the monitor: (qemu) c (qemu) qemu-kvm: VFIO_MAP_DMA failed: No space left on device (qemu) info status VM status: running Reported-by: Tingting Mao Reviewed-by: Klaus Jensen Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20210902070025.197072-12-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- block/nvme.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 80546b0bab..abfe305baf 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1019,6 +1019,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriver= State *bs, NvmeCmd *cmd, uint64_t *pagelist =3D req->prp_list_page; int i, j, r; int entries =3D 0; + Error *local_err =3D NULL, **errp =3D NULL; =20 assert(qiov->size); assert(QEMU_IS_ALIGNED(qiov->size, s->page_size)); @@ -1031,7 +1032,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, NULL); + len, true, &iova, errp); if (r =3D=3D -ENOSPC) { /* * In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA @@ -1066,6 +1067,8 @@ try_map: goto fail; } } + errp =3D &local_err; + goto try_map; } if (r) { @@ -1109,6 +1112,9 @@ fail: * because they are already mapped before calling this function; for * temporary mappings, a later nvme_cmd_(un)map_qiov will reclaim by * calling qemu_vfio_dma_reset_temporary when necessary. */ + if (local_err) { + error_reportf_err(local_err, "Cannot map buffer for DMA: "); + } return r; } =20 --=20 2.31.1