From patchwork Tue Aug 24 14:11:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520304 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YnF3pXXc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB0B27vZz9sXk for ; Wed, 25 Aug 2021 00:12:58 +1000 (AEST) Received: from localhost ([::1]:54840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXAe-0005Vr-1L for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:12:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9g-0004xg-N6 for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:11:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34235) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9d-0005Dd-JM for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:11:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814312; 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=yN+5yZGDeAmkt+tWURHTcSbRHTRAgs+im7kId+unuiY=; b=YnF3pXXcIAUB2IwHnowUVJGG8zX4ESWHQYHUQ549HADkN4uVT4wEef+aBdsZqo7dkHhXDa udn0gso3UUCn20HPCeKs1a6uN0t+i43y56AL5hy5FKOPkUNCSE/kGxsX/off9EgI+KWb5a xT+0hJeQ7h9SUkfzPz/mRWQrfd4xS/8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-0WYZPCG8MqqkMqHh1F5iJQ-1; Tue, 24 Aug 2021 10:11:51 -0400 X-MC-Unique: 0WYZPCG8MqqkMqHh1F5iJQ-1 Received: by mail-wr1-f69.google.com with SMTP id b7-20020a5d4d87000000b001575d1053d2so935444wru.23 for ; Tue, 24 Aug 2021 07:11:50 -0700 (PDT) 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=yN+5yZGDeAmkt+tWURHTcSbRHTRAgs+im7kId+unuiY=; b=ibzUN4JQpXmoBfTe5SEpZ4bmvdA4mE29YkZu6vyNdQA0e041vnx94B/0RGnHhddqLw 1jmdMIlKRXgXw3VGMm19IfytBXZ2h9y8ez4H7tlooZwJ65fdpjnC8H8yy6YijIYDTPX5 L9BVmjh38Wb76nVDL+NtX9GVz9fC7nQgDmnDnO3oCf7DXFE9TfHSq0tlC4gPmkTM+CJV uWmRopVSxuLM8BSgg1H8MVJ4iPZqTK55Q29D57qIujet4+RDPc8RTEAqb5ezsa+OEg2u rTxQWjm2q8LbLZoiH/d6QEdB1iDZAdP7e0h6UYrBZYBEl+/U6iX01hsye5FnKOOglVJw oH9A== X-Gm-Message-State: AOAM532YLGYxJecbNm//zbbiUIxHEsW7yLcN86wil4aLyWleWiPwxFVo zsrREe5zNSTUnIJLm9c6/pGAR+9+NdOPhoER+5w0oOw7azTzzQI8F6pLwNWnCaoVDUoUNQ4XNdn DyFvqoPTnZg5Uft17keMxVYwLLhqZp6IhHIm/LGBNHTotSXMCcRkj0Ha14nVir+QH X-Received: by 2002:a05:600c:2947:: with SMTP id n7mr4261436wmd.183.1629814309382; Tue, 24 Aug 2021 07:11:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD74QeeVEmzmUaCLAJuULZlZSXTU6ioFPiP+Ac9H//5fCizH7jH5ZIrSVWkfH6QMs1Bfbimw== X-Received: by 2002:a05:600c:2947:: with SMTP id n7mr4261401wmd.183.1629814309103; Tue, 24 Aug 2021 07:11:49 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id q3sm2320088wmf.37.2021.08.24.07.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:11:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/9] block/nvme: Use safer trace format string Date: Tue, 24 Aug 2021 16:11:34 +0200 Message-Id: <20210824141142.1165291-2-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Fix when building with -Wshorten-64-to-32: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Klaus Jensen --- block/trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/trace-events b/block/trace-events index b3d2b1e62cb..f4f1267c8c0 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 offset 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_context, 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 From patchwork Tue Aug 24 14:11:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520303 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GyBOSfeR; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB096cWlz9sXM for ; Wed, 25 Aug 2021 00:12:57 +1000 (AEST) Received: from localhost ([::1]:54724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXAd-0005R0-N5 for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:12:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9k-00050X-TX for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43619) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9h-0005Fo-EK for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:11:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814316; 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=wErq8/MJBqeGe7FrwWidBXlks9jtibqyP3ZzK8xaUyQ=; b=GyBOSfeRoMUX3YCmnMyVE/eYY2HuHmW4MD68OLVvh2wWqMm+yYXAQqA7IRFIZYByBygrNl LdXUN6Q3+IYIBUdsIR5u5C64LKTcAjgOERkgCy/RMddGC016b0Dr7qPriNMBtNiklF7joN U2jLqUYeJ2DUUdh7ZEPBV0cvq1Rg2fo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-p5EEBF5kMretIXfjsBoP7Q-1; Tue, 24 Aug 2021 10:11:55 -0400 X-MC-Unique: p5EEBF5kMretIXfjsBoP7Q-1 Received: by mail-wr1-f69.google.com with SMTP id 102-20020adf82ef000000b001576e345169so49894wrc.7 for ; Tue, 24 Aug 2021 07:11:55 -0700 (PDT) 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=wErq8/MJBqeGe7FrwWidBXlks9jtibqyP3ZzK8xaUyQ=; b=Sh9hmFwBAPKH5ltN/uQEakXijJCz+LOc/C60gZ93zgAgsfK5HRiUjPI9sk7D6B7jR0 CnUh6TMWcX4su+tVQ6DGUkG6w7AW99Dvy41ZFgMNTQKfn+9kKhDWj70eJdI5PPD1Vsyx HcnkLM+/N0DW7xgnsdY8LYecWyWePp3ufgDwtTdZxke4OFfTP7kK2vpgVNmrKDGk3R3J d6qw5v6nni6WDBJb0L0lThJmpel7C9H45utHmv7FhouCvJoqqD+ZdA99NirkhpzT7izp ANagKJPKIO9Mp0jtUx4kGzxUB7Zxe2ZLJX/QR5SRqbiMGNaoYiBVuEpCVryZ3iaYM60e nv1g== X-Gm-Message-State: AOAM531d/ked2aJZQ6ytD9AoYm2upM9WrlqybzQso2sqoidwTtCzfUTc 4APMXWfxZ0K+LZAR+s10pJkaTBtqlBU+77u2wVPbBWdSxEGgyDflC7+AYsUg7Jk34iAnUnpymp9 rhVnnoJTNA41ZDnLclaGE3YZnqT4Z0wvqWeYYagfm8uANVL7MqQH0syJTU2ftkPm9 X-Received: by 2002:a1c:4c13:: with SMTP id z19mr4309498wmf.132.1629814313975; Tue, 24 Aug 2021 07:11:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8AA5sxjyDrxXS0sY56cNGPL06ePlxg6uRN1Z6eGVLHV4CVS10/SuDdUnWhWD+ZnLRsBJz0w== X-Received: by 2002:a1c:4c13:: with SMTP id z19mr4309476wmf.132.1629814313802; Tue, 24 Aug 2021 07:11:53 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id f18sm2492249wmc.6.2021.08.24.07.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:11:53 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/9] block/nvme: Have nvme_create_queue_pair() report errors consistently Date: Tue, 24 Aug 2021 16:11:35 +0200 Message-Id: <20210824141142.1165291-3-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index e8dbbc23177..6642c104aa4 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -220,6 +220,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, q = 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(BDRVNVMeState *s, qemu_real_host_page_size); q->prp_list_pages = qemu_try_memalign(qemu_real_host_page_size, bytes); if (!q->prp_list_pages) { + error_setg(errp, "Cannot allocate PRP page list"); goto fail; } memset(q->prp_list_pages, 0, bytes); From patchwork Tue Aug 24 14:11:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K9tokYdL; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB1t2kl7z9sWl for ; Wed, 25 Aug 2021 00:14:26 +1000 (AEST) Received: from localhost ([::1]:35132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXC4-0002l2-4O for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:14:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9o-00050g-4P for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9l-0005Io-TX for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814320; 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=rai7h32TrTkDK/wiLtMpSewodwbvjWhnx25D5kPSBpM=; b=K9tokYdLbM9sO0OUWB2N5HSN991XAilrs4WFe4tThz8+tg3yIbsrW8O5c2vIcl6LVYn6qc cPH4h9qUOCqhOHTvWSayp8ppRpq7rp536x3yN0c6gRmnosh/gC/lcKqaNOFHGXU23V7PMF ao8pLLQLJG+/+2RTSWiFe95tREsbm4w= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-oagS4kkhMd62ZW_TE76BsQ-1; Tue, 24 Aug 2021 10:11:59 -0400 X-MC-Unique: oagS4kkhMd62ZW_TE76BsQ-1 Received: by mail-wm1-f69.google.com with SMTP id p5-20020a7bcc85000000b002e7563efc4cso1100506wma.4 for ; Tue, 24 Aug 2021 07:11:59 -0700 (PDT) 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=rai7h32TrTkDK/wiLtMpSewodwbvjWhnx25D5kPSBpM=; b=n5wfdTxVnIHL4jp2lhTOqlWeDA80/KhHpmRuUSVYd+ex1nVvmcmtItOkaBLhiJyUH9 mtFM+tsExy8g7jZxnpAOcpEoiAUG5fWvyDjl5qXGN1tttI//9C0rSk5Ers15iaVO+Gvb Vze6kbTAHP82k7JM5lmoYq1KbPngmce36/nn1DfNY6ebiCuh4VGGlb0N3Rt0yxmY27Xz lA7dXhtH77PCpMRnva5AFbUi2TMnGlnWbUKcftAkuzJJBFTn4GlP8RD7GAzVMu1JitDe XdtIkahqGTvehE2uFETMuKZyozuvioOIIq+PPLk7m6twuSGqXivoyzNrNGAM1it4XXCl BCEA== X-Gm-Message-State: AOAM530x7UHIhHa1W042jtqSroO21rLmquQo3HA65sXtM9DGmztde3/p Em9NPc9nivY7jtjtUZVMTQ7UhUctk/MgC66n2twsb7srQK8r2rkkz7PVmLb5Zt6HcSDcZvXhUaL 3ZrBOI//FakWyxSQJl5lC+XrVcbzN/qRMarIeX6MI2xPsEXng3SemvK1KrFWPRyTR X-Received: by 2002:adf:f743:: with SMTP id z3mr12275643wrp.211.1629814318443; Tue, 24 Aug 2021 07:11:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbkfSVNDCdzjgg5KW9qyinMJbGLgAOUfEcqYQmvPVBmbH0VSbq0b7aHa1mIRyoBnh4hkV1jA== X-Received: by 2002:adf:f743:: with SMTP id z3mr12275624wrp.211.1629814318280; Tue, 24 Aug 2021 07:11:58 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id j1sm15012386wrd.50.2021.08.24.07.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:11:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/9] util/vfio-helpers: Let qemu_vfio_verify_mappings() use error_report() Date: Tue, 24 Aug 2021 16:11:36 +0200 Message-Id: <20210824141142.1165291-4-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead of displaying the error on stderr, use error_report() which also report to the monitor. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- 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 911115b86e6..1d149136299 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 = 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 <= 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; } From patchwork Tue Aug 24 14:11:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520306 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QrnukRnT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB1r4K1Mz9sWl for ; Wed, 25 Aug 2021 00:14:24 +1000 (AEST) Received: from localhost ([::1]:34952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXC2-0002eA-CO for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:14:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9s-00051E-9E for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22011) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIX9q-0005Lu-6U for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814325; 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=yP4txqlPFI2A9kMCd1u6S+dpF5skjJnaUikspGogW/I=; b=QrnukRnTs21Uzf9rE/CzIJoRBawa1l4acqc6ZgzJVqOjaWacvAmL4V2DKhbFyXrxFmwx7m 7Po2PEUsAkpWRTu9qIAuoO6MlTzypo0VQ38aIw78pUF/NEg2D7sPztIn/hlHegKLg2XCxA NRYU6gITWOJvyRO3O9H62Gz8JCEUWV0= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-588-RDbX6Q0gO8u9-IGikIfZGw-1; Tue, 24 Aug 2021 10:12:04 -0400 X-MC-Unique: RDbX6Q0gO8u9-IGikIfZGw-1 Received: by mail-wr1-f70.google.com with SMTP id q11-20020a5d61cb0000b02901550c3fccb5so5772374wrv.14 for ; Tue, 24 Aug 2021 07:12:04 -0700 (PDT) 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=yP4txqlPFI2A9kMCd1u6S+dpF5skjJnaUikspGogW/I=; b=MSDfcURgJOnAv/QpSY2oBF7rZzUzsAKsfiVcVdQjCteySEg38dxpgQfusZfWhLltsk JgfH9FRBXeAfjcfvp7KFC4ksUyevCSxpgmaslGWN0KC+JD2MBkPdsxeDM9Hn+PlNj9xo s7i+2PCQJaAD4BWkhikefs+mS6NEcY19cdofgf832s2NHe9+34WkOx1jSMmSvhAyIDz9 FNQB0ocbf1hOgvrs/lq1bPxJ+b9d6utTOhreMuZWlujst2ODz506j/JSaMS2Q6RYpfKJ rXkfgUIvsFfjiV2RY+nYbCRBSPUNnADY9v1N3Wm3G5BrW5eTav4uiScbdFrSx2KoZZNF DrXQ== X-Gm-Message-State: AOAM533nQyELGF6GSoFjOwN8h5wH6TSBkNbTOcXBuWwpmRRt00kk83W2 BBWX2xG88g35YqErB3DHlbcXCgQ9NVkCgYfa6wTIBuHvcIbWoD61b9ssR5rz75PgG80IMtMvxai 824qhJcToRMH95AXXqp5NF+GoCh3D2doSxOxp2ZW0xxAWeBeXsEbbY/sYQlTbVOEA X-Received: by 2002:adf:fa82:: with SMTP id h2mr5480662wrr.195.1629814323034; Tue, 24 Aug 2021 07:12:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/jkoZN0odgTBflGStoSth7pZwSCKwVVLpg02DsKmprcNGs4MIJDtEyMjzPc9L49Ri0EZkQA== X-Received: by 2002:adf:fa82:: with SMTP id h2mr5480638wrr.195.1629814322884; Tue, 24 Aug 2021 07:12:02 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id f23sm2686543wmc.3.2021.08.24.07.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 4/9] util/vfio-helpers: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD Date: Tue, 24 Aug 2021 16:11:37 +0200 Message-Id: <20210824141142.1165291-5-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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Klaus Jensen --- 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 1d149136299..d956866b4e9 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -735,7 +735,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_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 = qemu_vfio_find_mapping(s, host, &index); if (mapping) { iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host); @@ -778,7 +778,6 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, *iova = iova0; } out: - qemu_mutex_unlock(&s->lock); return ret; } @@ -813,14 +812,12 @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host) } trace_qemu_vfio_dma_unmap(s, host); - qemu_mutex_lock(&s->lock); + QEMU_LOCK_GUARD(&s->lock); m = 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); } static void qemu_vfio_reset(QEMUVFIOState *s) From patchwork Tue Aug 24 14:11:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=daB7olrm; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB1v71j1z9sWl for ; Wed, 25 Aug 2021 00:14:27 +1000 (AEST) Received: from localhost ([::1]:35330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXC5-0002sm-P8 for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:14:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXAA-0005fy-V3 for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56068) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXA9-0005Wa-Ft for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814344; 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=UiR702sKQihvxXmLHPk9PJ+aENXmsbkBYxchZbzfBis=; b=daB7olrmBYkFMwFwjoY8BN1lofFgLTpA1nMUxyGbjpgMMQBp/+Dv6P8AfVmPB0z2dleBA1 aPrhH3hOqmLdcp2nDZ5dsWyoN7jecCmYduVO5Ikj+V3qXyZl5GKqIGMK8B7824Oe8n3EUe m8cKuYXvjqb5eNdZDEXZ4qaOjFkPPMA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-528-qVmdwVN-M_mkwSm6vICpmQ-1; Tue, 24 Aug 2021 10:12:23 -0400 X-MC-Unique: qVmdwVN-M_mkwSm6vICpmQ-1 Received: by mail-wm1-f69.google.com with SMTP id w25-20020a1cf6190000b0290252505ddd56so4161289wmc.3 for ; Tue, 24 Aug 2021 07:12:22 -0700 (PDT) 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=UiR702sKQihvxXmLHPk9PJ+aENXmsbkBYxchZbzfBis=; b=keHq1ucIr37fUBMR9u/ALXi06NIZhEqA4pW5359hRqpELKdrYqsqyVnhZAExBRgl+E Sc5RuwE1qiul70pnGGcTCao89OXhJwLRl2NO80Q2MqjVIo5icW5CBTaq0chjnoejsNju UceT6P9VYXjeL2N19YZvLM/lqgca0G5Z0AqIBx5TzuMwvpDZE/j1MBlhyxGp4EMQuRK8 /dqjvJdX40I+nhgxnajDBxfvQU/YSNXMBWVaMqbZpJmf0BLWG5AaNQ182TeFXTthHDiQ cn1jK1HDdtaKJdlizr8Az1XKzE8zNrlfdqvWEmLcaP1kYSfkMjAfBb+D45adSx90DZyC ixGg== X-Gm-Message-State: AOAM533dsKTmrbDwKdA+xAZZpahPuM/RDmPJVsklYtWrEMq6FCLe7pUQ qN3dO8AuavUBRvesjEXn8a27mQ0Z24vTUuunu6CTxWVfhLeVeF4PrD7uQu9Lf+bRhGhzC+ygFuD YkWcdiY4FHIJ+/KpaGoiR8XFRJTdbsa8Wtq9jy3nz7gzcHnAlvFK+Hzwvccwqv9bW X-Received: by 2002:a05:600c:2256:: with SMTP id a22mr4410959wmm.16.1629814333686; Tue, 24 Aug 2021 07:12:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOd5pQMj8QHbcBH4poQP+7q/dW/ef3X3pm/whLTBk2nKMIHafm4tZDOVByVvH68WYWYq7bBw== X-Received: by 2002:a05:600c:2256:: with SMTP id a22mr4410425wmm.16.1629814327382; Tue, 24 Aug 2021 07:12:07 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id c7sm2317253wmq.13.2021.08.24.07.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:07 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 5/9] util/vfio-helpers: Remove unreachable code in qemu_vfio_dma_map() Date: Tue, 24 Aug 2021 16:11:38 +0200 Message-Id: <20210824141142.1165291-6-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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Klaus Jensen --- util/vfio-helpers.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index d956866b4e9..e7909222cfd 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -751,10 +751,6 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, } mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0); - if (!mapping) { - ret = -ENOMEM; - goto out; - } assert(qemu_vfio_verify_mappings(s)); ret = qemu_vfio_do_mapping(s, host, size, iova0); if (ret) { From patchwork Tue Aug 24 14:11:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DskTsVc3; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB0C45zYz9ssD for ; Wed, 25 Aug 2021 00:12:59 +1000 (AEST) Received: from localhost ([::1]:54938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXAf-0005Zl-8a for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:12:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXA6-0005Od-I3 for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXA1-0005Se-Sl for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:22 -0400 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= 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-457-2IiTihoSNkS1wscuq5pugg-1; Tue, 24 Aug 2021 10:12:16 -0400 X-MC-Unique: 2IiTihoSNkS1wscuq5pugg-1 Received: by mail-wm1-f71.google.com with SMTP id y188-20020a1c7dc5000000b002e80e0b2f87so1317415wmc.1 for ; Tue, 24 Aug 2021 07:12:16 -0700 (PDT) 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=sTYsWD7T1qLAhmoRQKSo03QHn/g//3WNZWHEcvhO20AG1ivj89TIU1QasQhUA/G/Sc muiLlbQGFa+DKS+m1D3Fb4WampUVxRNHEE1UVKT514CeEvA79tdSNieR7IFUJa2prrf1 UL0concmHz0VBmWOtqKpzC9kZsGWUOm52lriDMIADIXCeUcDKBkOkj4E3h8ZRfR9usVT eaHX8EAYjxo3VbbXbLyeSJD1+okuWzOZvlEKkupyMVRD+dyiAYYT0ReJ6+pFuAs7kLQe PiJyGc9t4wsSfa0xEk0mH+yt3OdmjyKyPENLmuphPSbHwsCjQZz+NLm1Rf07qr62DkeL vXjg== X-Gm-Message-State: AOAM533A4XJ97Nzi6eEEanwR7e+X4i2W4BQhK3iPlstClQQL/GbywLM0 r3KN01c3njoK+VVbaPhbagpT/DRpimNAqlF1WoQhHYg4ZvZvyuXHAD3Hzu/S7JdxGiAnmqSIfVZ uwMGeOw1USy/PXlnPcAbjBrcEMBQka1kc66Pt+LbbCuF26BCFZJ0bF8GuGypbKn8I X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr4216063wme.81.1629814334726; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é --- 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, NVMeQueue *q, return false; } memset(q->queue, 0, bytes); - r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova); + r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova, errp); if (r) { - error_setg(errp, "Cannot map queue"); - return false; + error_prepend(errp, "Cannot map queue: "); } - return true; + return r == 0; } static void nvme_free_queue_pair(NVMeQueuePair *q) @@ -239,7 +238,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, qemu_co_queue_init(&q->free_req_queue); q->completion_bh = aio_bh_new(aio_context, nvme_process_completion_bh, q); r = 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 namespace, Error **errp) error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - r = qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova); + r = 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; } @@ -1031,7 +1030,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd, try_map: r = qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, - len, true, &iova); + len, true, &iova, NULL); if (r == -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 size) { int ret; + Error *local_err = NULL; BDRVNVMeState *s = bs->opaque; - ret = qemu_vfio_dma_map(s->vfio, host, size, false, NULL); + ret = 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_unmap * 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: "); } } 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(RAMBlockNotifier *n, void *host, size_t size, size_t max_size) { QEMUVFIOState *s = container_of(n, QEMUVFIOState, ram_notifier); + Error *local_err = NULL; int ret; trace_qemu_vfio_ram_block_added(s, host, max_size); - ret = qemu_vfio_dma_map(s, host, max_size, false, NULL); + ret = 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_size, - strerror(-ret)); + error_reportf_err(local_err, + "qemu_vfio_dma_map(%p, %zu) failed: ", + host, max_size); } } @@ -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 = 0; int index; @@ -774,6 +776,9 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, *iova = iova0; } out: + if (ret) { + error_setg_errno(errp, -ret, "Cannot map buffer for DMA"); + } return ret; } From patchwork Tue Aug 24 14:11:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520310 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ahH9oTLb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB6x0zdcz9sX4 for ; Wed, 25 Aug 2021 00:18:49 +1000 (AEST) Received: from localhost ([::1]:43714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXGI-00006P-Po for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:18:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXA8-0005Wc-Fx for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXA6-0005Vn-QP for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814342; 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=Hf6aQWPomJbErfm8jcxJmMDuWpHIgM/AzBOqCZSkpgc=; b=ahH9oTLbEGVuFaC5kXwk8jU70soC0QxCbP5aFNZGqXaCFF8ie47v6D0d8qHlUKYqfgeYcy tk95+5YRTXoQxKbOSwAYKO3E6IlMSWpJJSFe2xVc6ieHaTAsV6SkWQVzk9wxWRRWEnOVjd K53OemLaRkdSz1XH8ezkbMN7noXPkJc= 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-547-K4JQXDmlOOu09EEZ-YZBqQ-1; Tue, 24 Aug 2021 10:12:21 -0400 X-MC-Unique: K4JQXDmlOOu09EEZ-YZBqQ-1 Received: by mail-wm1-f71.google.com with SMTP id a201-20020a1c7fd2000000b002e748bf0544so1312320wmd.2 for ; Tue, 24 Aug 2021 07:12:20 -0700 (PDT) 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=Hf6aQWPomJbErfm8jcxJmMDuWpHIgM/AzBOqCZSkpgc=; b=IkImtGZGCLm5KLyV8sT6lprKMZP6ssaccnJPKu9E532lkmbJbb8ZLU4gQ28W+/qh8s Ad96Xq6i2cPbhJ5+uO8QACoMdccsWh7bnwPqzcP5BqU/NHJ6x/hNeIaouJcyeZJfD7Pd b03Ac4AL6rtnvDnwTSgCUsnATLIy+6Htbo53ufu4ZBxyhl1p2Bx9E4EFyHK8RFYENli4 pZTRU9YfzP1fGs0otqtD2ftFR53GfId1WsSM37pS+sviDNsUEQVK+/5uH/QssBsC/MTO Hvb3Ut6O37Sj1+c6k7KgrIfetGuFgrC6J3vK5oS3CjOq2Ir/mRtzBCQvSg17vtnuO3pc 3b+A== X-Gm-Message-State: AOAM531YzNyPAi0Y7EjgljdVboJLoEXzRHe+gFNgo3+/fSo/fhO6oEiK Gy5rB9M573jRZRxgpk4NKtP99qst78rMp77S6Vxs0n5FceCNLHJzA9iEBoezQHHsppjRCCuCgEV BPVz2hbgsPJF4s5HQXqlg8VQ2U3VPQ10GF+7azV+gOtbb5BFQbeL2hlhi8A+ArLoe X-Received: by 2002:a05:600c:21d7:: with SMTP id x23mr4379432wmj.10.1629814339299; Tue, 24 Aug 2021 07:12:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVou/zbzkBMq6h96Epkyp0Sqdu0Oiu4DAAwdAQQ+9B2YCLX5S8NCfW4HGYW7QL/9ABYhCP6A== X-Received: by 2002:a05:600c:21d7:: with SMTP id x23mr4379401wmj.10.1629814339081; Tue, 24 Aug 2021 07:12:19 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id g6sm2652347wmq.14.2021.08.24.07.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:18 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 7/9] util/vfio-helpers: Have qemu_vfio_dma_map() propagate Error Date: Tue, 24 Aug 2021 16:11:40 +0200 Message-Id: <20210824141142.1165291-8-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Now that all qemu_vfio_dma_map() callers provide an Error* argument, fill it with relevant / more descriptive message. Reduce 'ret' (returned value) scope by returning errno directly to simplify (removing the goto / 'out' label). Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 1 + util/vfio-helpers.c | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 663e5d918fa..80546b0babd 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -240,6 +240,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes, false, &prp_list_iova, errp); if (r) { + error_prepend(errp, "Cannot map buffer for DMA: "); goto fail; } q->free_req_head = -1; diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 3e1a49bea15..f4c16e1dae5 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -729,7 +729,6 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova) int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, bool temporary, uint64_t *iova, Error **errp) { - int ret = 0; int index; IOVAMapping *mapping; uint64_t iova0; @@ -742,32 +741,34 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, if (mapping) { iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host); } else { + int ret; + if (s->high_water_mark - s->low_water_mark + 1 < size) { - ret = -ENOMEM; - goto out; + error_setg(errp, "iova exhausted (water mark reached)"); + return -ENOMEM; } if (!temporary) { - if (qemu_vfio_find_fixed_iova(s, size, &iova0)) { - ret = -ENOMEM; - goto out; + if (qemu_vfio_find_fixed_iova(s, size, &iova0) < 0) { + error_setg(errp, "iova range not found"); + return -ENOMEM; } mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0); assert(qemu_vfio_verify_mappings(s)); ret = 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)) { - ret = -ENOMEM; - goto out; + error_setg(errp, "iova range not found"); + return -ENOMEM; } ret = qemu_vfio_do_mapping(s, host, size, iova0); - if (ret) { - goto out; + if (ret < 0) { + return ret; } } } @@ -775,11 +776,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, if (iova) { *iova = iova0; } -out: - if (ret) { - error_setg_errno(errp, -ret, "Cannot map buffer for DMA"); - } - return ret; + return 0; } /* Reset the high watermark and free all "temporary" mappings. */ From patchwork Tue Aug 24 14:11:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MQQIpC/i; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvB7j6ppFz9sWl for ; Wed, 25 Aug 2021 00:19:29 +1000 (AEST) Received: from localhost ([::1]:44876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXGx-0000ub-OZ for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:19:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXAD-0005qw-M3 for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58247) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXAA-0005YA-OA for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814346; 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=wjVPj1eNKTQy5fwjblCd47XbInf1YqiKgdyKZG3IkLI=; b=MQQIpC/iZifnhRzTZrXVzwuV3oOVeOABBsA3A+ExtQsdRDFjynl/v7bodI7WJDixJQiWMX MmIUk1kCGw3ydhbrSF1r1Kb+9cwKpnuGKadR+KeQ5PZgiQt+dWlzYy39nQN0Hw5+qCkqgo skyy8sPgVVD9JxMjU5Uq9sLjXA11AZg= 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-47-v5xl1aWSNCiLTwoYzzHuXw-1; Tue, 24 Aug 2021 10:12:25 -0400 X-MC-Unique: v5xl1aWSNCiLTwoYzzHuXw-1 Received: by mail-wr1-f71.google.com with SMTP id h14-20020a056000000e00b001575b00eb08so1164247wrx.13 for ; Tue, 24 Aug 2021 07:12:24 -0700 (PDT) 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=wjVPj1eNKTQy5fwjblCd47XbInf1YqiKgdyKZG3IkLI=; b=ArlqFC4flWhOoiHsCIyD1HvKvXarClxeXNpbI7RGme+8ygr7Bhlng/qWuB9Igy9QMX OV91BWP0RT1mQBMszepY9ojH0mLmXAwnybKLQEEldqamHLzTl2P6QYKwDM9rZloZNKHe 02472gUQlSxTlL1Px6izyh734+rqnPP1cOnZ/PVY7EHOTSzgOo0OwsZiY0vM4zZ+gvYO BFLj2nGNQ2OR9MpQWZ1bUu4Zj4+/1EyEY/YzEko/foeWfjV5yPLOrb1KDA7DoNzo8uF9 NfUGcr68GrU/NrugEcrsgfaNK2QQFwhlufd/ZSniFzkmuHxtaH1lh5uS67uFqHgfxJ3w IL+Q== X-Gm-Message-State: AOAM532ptqPlgXXchR1eIIcb2xw3vAq3qLj+AiCo6jcaClMviuTSBfga +pzy26DAWUwOg6jCkqvz9IKKdFzBHxhncK0XwhOr1OYWKViSZT5m7pfye+pq5RLTV3oxG2D9rfs p0/G0bGdPRmLDTZQ5dBzpI68nEQp7BKWZkxLHPGJIrCZwcZ0+exJRC1V72Y+xi9t6 X-Received: by 2002:a05:600c:21cd:: with SMTP id x13mr4267530wmj.20.1629814343523; Tue, 24 Aug 2021 07:12:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeTRBh+ImxKQMXSnT8/PwHAp10tnbMe29s11g353WVUeJV4jEUnq+F+UxzVXH7Q/QPtR6DeQ== X-Received: by 2002:a05:600c:21cd:: with SMTP id x13mr4267507wmj.20.1629814343368; Tue, 24 Aug 2021 07:12:23 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id z2sm2390454wma.45.2021.08.24.07.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 8/9] util/vfio-helpers: Let qemu_vfio_do_mapping() propagate Error Date: Tue, 24 Aug 2021 16:11:41 +0200 Message-Id: <20210824141142.1165291-9-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Philippe Mathieu-Daudé --- 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 f4c16e1dae5..613f3db3745 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -610,7 +610,7 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s, /* 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 = { .argsz = 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); 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; @@ -755,7 +755,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0); assert(qemu_vfio_verify_mappings(s)); - ret = qemu_vfio_do_mapping(s, host, size, iova0); + ret = qemu_vfio_do_mapping(s, host, size, iova0, errp); if (ret < 0) { qemu_vfio_undo_mapping(s, mapping, NULL); return ret; @@ -766,7 +766,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, error_setg(errp, "iova range not found"); return -ENOMEM; } - ret = qemu_vfio_do_mapping(s, host, size, iova0); + ret = qemu_vfio_do_mapping(s, host, size, iova0, errp); if (ret < 0) { return ret; } From patchwork Tue Aug 24 14:11:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1520312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T9M2zM8U; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GvBBJ4Fy6z9sXM for ; Wed, 25 Aug 2021 00:21:44 +1000 (AEST) Received: from localhost ([::1]:51804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIXJ8-0005bm-4r for incoming@patchwork.ozlabs.org; Tue, 24 Aug 2021 10:21:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXAH-00064u-7L for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIXAF-0005al-2m for qemu-devel@nongnu.org; Tue, 24 Aug 2021 10:12:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814350; 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=iERganKRZ2P65/BHVYzLPkJwsOXEHjYEJ8zC3s7dmRE=; b=T9M2zM8UOx5dV3B1qAsG4tDasXgZIxLsN1NJK+yfl9+1A5sCAHktRqOwET0oSAhVodPRTw sErgj+Urc/f8NYXfbbzvZhtREjRlHi1jKz5fKyqYX5OOX/KnrTjTSkohtKgOva4GddWCFc +8oho5vh2l/yxecJvSZMoB/OUQibIEU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-564-6V4X6VVOPfmiu8AIVQdq3A-1; Tue, 24 Aug 2021 10:12:29 -0400 X-MC-Unique: 6V4X6VVOPfmiu8AIVQdq3A-1 Received: by mail-wm1-f72.google.com with SMTP id m20-20020a7bce14000000b002e6fd85b6dfso4158485wmc.7 for ; Tue, 24 Aug 2021 07:12:29 -0700 (PDT) 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=iERganKRZ2P65/BHVYzLPkJwsOXEHjYEJ8zC3s7dmRE=; b=D4/iDFqOZisk6UriXh44LX+mgC149mLod0AXkg3ZRaiHnGXeh1ETvtMppKraNqdIU1 R4/Z5xUgClOxGb0gFy9ZYTRRM6LuDEjspVpndWsUDyKNKbRmROGMoaGGJKArofdBF/1j RYqXQGxSY+6z6u1f4+BRC+xeNg0VFasGarr2yvAvAdYhFxp5omknHd7Y4sGH1uRKHFIc BAxx4I/MYodZsRR2PHz7DyaWrLvC0BNeAvFlm6pQMC2zAcRF2oxx7ZupDuszaldQrKV8 kb6/2dX1P9EGn1hSjIpBVD021TgOT5fJ3YO4wj+KPl8GAzWpxlpHMmzk76PmeniyzfA8 5xsA== X-Gm-Message-State: AOAM531FNlG5vvkIT/PAZFWbBoSui/csMFzJcDHPCXUzY1WRHacYXvKG QF+N9TtXkJw7ws36eXyp+lwv9X+JmO7z3OeMpWdNLXOfr5N5xABDEekEKjZ1fR1scsrvo6sQyMj sxzlrpBK2YIOzXjCiSJwz2zTcC4nylifa4XRroULR9dsDzK6OK4LaijV9Faci8Ue3 X-Received: by 2002:adf:cd10:: with SMTP id w16mr20305385wrm.404.1629814347918; Tue, 24 Aug 2021 07:12:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeSROUKjC22xINvDw4ImyIwWBMB4OHLuyKqKW+X/Aww8SiwGMKRzJu4jYhEdmLCEmZVlhAkw== X-Received: by 2002:adf:cd10:: with SMTP id w16mr20305347wrm.404.1629814347704; Tue, 24 Aug 2021 07:12:27 -0700 (PDT) Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id t14sm2731627wmj.2.2021.08.24.07.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 9/9] block/nvme: Only report VFIO error on failed retry Date: Tue, 24 Aug 2021 16:11:42 +0200 Message-Id: <20210824141142.1165291-10-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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, 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, Tingting Mao , Auger Eric , Hanna Reitz , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Klaus Jensen --- block/nvme.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 80546b0babd..abfe305baf2 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1019,6 +1019,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd, uint64_t *pagelist = req->prp_list_page; int i, j, r; int entries = 0; + Error *local_err = NULL, **errp = NULL; assert(qiov->size); assert(QEMU_IS_ALIGNED(qiov->size, s->page_size)); @@ -1031,7 +1032,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd, try_map: r = qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, - len, true, &iova, NULL); + len, true, &iova, errp); if (r == -ENOSPC) { /* * In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA @@ -1066,6 +1067,8 @@ try_map: goto fail; } } + errp = &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; }