From nobody Mon May 6 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814313; cv=none; d=zohomail.com; s=zohoarc; b=iLHasiwM1h5TIy4kv3Q33Kc2B/IrWycfOcQz1xa4xL8koGjeJ3KQlQW53eHQ6RIhJFmo4teg2uQXcHdnFQnibdf2RsA8QKpAWSb6gQzphS4j03iiQ08GGbMwMYM/EgqBY7jIhwtjxSLml9aHmf0JsnQj7/ZGx2UhGbLeBPz8aKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814313; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=yN+5yZGDeAmkt+tWURHTcSbRHTRAgs+im7kId+unuiY=; b=luAr8mWncfSesbgxN4/9IwDJj693h6yNUmG1YQ9UAHtoIkamtUSik9DlmL44afWc2E5JxMDMLHngPb5xX5YkPkFDXUjlo4b0qso7TkfwOkScboHGw8B3RqUZjM0kZUQBZm4K4I6WCLB9BQPh//EMShGMjSUFVYYejisCAkFQFFw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629814313347273.4401712525697; Tue, 24 Aug 2021 07:11:53 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-105-6ov_LER3OZijCzk5DNN-qA-1; Tue, 24 Aug 2021 10:11:50 -0400 Received: by mail-wr1-f71.google.com with SMTP id v18-20020adfe2920000b029013bbfb19640so5754821wri.17 for ; Tue, 24 Aug 2021 07:11:50 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814311; 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=fRDRvMio242yQRiqUUXs3drJNrbMgUsic1cT0c4ZIm+d9zBfDNnC5gj13PIXfsGl9c7foW 54BlVcs7/1cTOuQRwazWwisbDLeXRhDruiDD5DWC6zvFt5d1lviYXhk4AkTV5SGstaj4h3 QO5/CycsyHrW0r/bUZN7u3TCEb8dJDs= X-MC-Unique: 6ov_LER3OZijCzk5DNN-qA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yN+5yZGDeAmkt+tWURHTcSbRHTRAgs+im7kId+unuiY=; b=mbLU9rqFy3sLLbqR/pMkalM2E6lAQEYXVHR/QFbqQAQaqDzlw/v14ylGFrSX5SeJUb Y4JIe1nVqVutriPuf5w9J7EkhqzyZvrwhIaUJJMuK2tqejk04p8W7qYjn+cqEoHCwGjL rp+cvPOgd9gQVfbO9Zv4CU9pSvVlhKPHR5Hq1UqLl04sbw7bzZ0R2HKzymvbYtfl10Xw BoVUke+ql9vnWMAkZe/ijSY1FXGDhHd5x9KubUPPwcj7tHkMo4f4uVaHS+7Z1BWoOkum J5GW//uQhmHbvKmLtpyxRD2y78Iad7jOwYrPGYp0kL16nII+GqnJoMOIJ5PzKqDu7huj 96Kg== X-Gm-Message-State: AOAM531emlaXHimO14HxqRMN648WvIyrDK/bRhBcHAJveJQlR4xqLmKq Zb8/b0wswLMZDijRXtrU/+7WiTp5ewlOMWeNPjF/XKe1YIySFtszW8fZAl6GD1GXjrPLOSAvwm+ S1nQhOMPvc5NLaA== X-Received: by 2002:a05:600c:2947:: with SMTP id n7mr4261417wmd.183.1629814309252; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814315532100001 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=C3=A9 --- 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 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 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814317; cv=none; d=zohomail.com; s=zohoarc; b=OM4UXIoaskgl0+OayYvdCxfMHvIjq/W1CeFhjB7Zd55ktdjTwUUnNCZw5zx7K2Ipj4fvr1sPuqn1Hv0QRU7dI908VUAuMaiUAbPlF0a4V7Ije9bVkOFLCag8Da5YYdw47RAVmkuAIvSAu3ywA9KfwehDabQoD9zXny2XBTQGUdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814317; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=wErq8/MJBqeGe7FrwWidBXlks9jtibqyP3ZzK8xaUyQ=; b=c8ysrQbVanZk9n4bqq9aMR2iqHwnbb1LjT/cZ93yVZC8EO+FL9nZ5nehs0bIU/rCGO+CAOEc2OK82XIu+RKsCbJEA8YCWja60gtUpny4zIypM7P759XfSFoh0ouG0Atp5A8dEHlFDwf8eUGzbMOLX4+/jMs88yfnW6UIDDukvEw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629814317800705.1447127645889; Tue, 24 Aug 2021 07:11:57 -0700 (PDT) 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-169-HHC1jPgZMH2ph0QdvaY3_g-1; Tue, 24 Aug 2021 10:11:55 -0400 Received: by mail-wr1-f70.google.com with SMTP id b7-20020a5d4d87000000b001575d1053d2so935507wru.23 for ; Tue, 24 Aug 2021 07:11:54 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) 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= X-MC-Unique: HHC1jPgZMH2ph0QdvaY3_g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wErq8/MJBqeGe7FrwWidBXlks9jtibqyP3ZzK8xaUyQ=; b=eIJnraxbIxo21XmRPosyzUVgmihsLUTZD0m/UnJivjWWrrSVt+jBFYkWItcxLRvjPN /AywnU8cm7si5LqkTeaDTHCvAXoDDM4jnaxm9MM0bdE5ldY0Dtx7WcCwFQQJVUdByJIa 5a0XcITtNl7CMjbdMwwi2T742fxxPMsRLmD8mIWn15y/q+B0hKI0Xpv3qeUewhmxmEE0 og+y5H01cPzn+0OzDPoiqyqywNguWAxmB+tY37J88LVfDRZfFb90Qdh2Kp6Ex+UG2Uz6 6K4TETiTjOq0JCDoiz7jtqursUAgTtThY61eVW6rV9sW7iOZb7UMUOzXMBZyI3UhU+CU xGvQ== X-Gm-Message-State: AOAM533sN7Fy+p9s8WlLDFTH1jZyYc/JTpJs5KHiwQAH1cgNn4ln64NL 1SBqKNJNA1S8U695lecgHBEumwJ/TXnssaoLMx3nyxRKObyYHJuGyN/A7icshxkZBJY9KFdrsLH /NbCKiU8H4zHU7w== X-Received: by 2002:a1c:4c13:: with SMTP id z19mr4309490wmf.132.1629814313945; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814318764100001 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=C3=A9 --- 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(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); --=20 2.31.1 From nobody Mon May 6 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814321; cv=none; d=zohomail.com; s=zohoarc; b=aeCH7KyE/CkqV3s0Pt9JpUzsG9d6zm3G4EqO+Cmnyowu0J5CLr4CxBmze4HOVx1iz/DtWqS51ppXOJGEd36s+3m67o2nbbTcQSA420f6Cph3FHb45ZYW/93n8uK+f5beE2ZodmGVeKqFEc8h2QPqVy80NtHkQLCwYY8A6gQoNkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814321; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=rai7h32TrTkDK/wiLtMpSewodwbvjWhnx25D5kPSBpM=; b=XxW5NS3NuKlq/LdehNI8VEg3/ZAcYpsEDNyyAL5diFYj4D8TDeBFSMXlZXXwiehSNgjpuZWA0NSMMruQFqjHeMnBpuPzy2ApFD+dVG4+WkL+pMyf6OHSGw82RT20K/x3NgQzo0lmxkinDlMZOmTHtYFNITaKYc2OboRnIP5Wfl0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629814321838566.8388841512236; Tue, 24 Aug 2021 07:12:01 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441--2bE0Xm9MlmfaOaEs8D1Iw-1; Tue, 24 Aug 2021 10:11:59 -0400 Received: by mail-wm1-f71.google.com with SMTP id f19-20020a1c1f13000000b002e6bd83c344so1103399wmf.3 for ; Tue, 24 Aug 2021 07:11:59 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) 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= X-MC-Unique: -2bE0Xm9MlmfaOaEs8D1Iw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rai7h32TrTkDK/wiLtMpSewodwbvjWhnx25D5kPSBpM=; b=qm8Dwtee78arpEw6W5bHU93wo4JcaxBCtjsisZ15vp9YV9pvmgo2X4EiCtQhtLg1fg UPWzvBop/2GzF1U1gKY6DtyFbBX4liuN3eXCnh06P5XcZOPHFVGFRKyyW0I6Um+lhBbj EGX0SYD0WgOndgy9cq+k4NTBAAKlztFz8dBd+DeFlnk0uBGZbqA8lHRML0zksLdpnP7a E7zUT6v+F3Eww8Coaxs+wd3sk1f/I2Tn1ff+XoSoMTuO22jJE55AJU+zEztqpdGEjn7A QMES8sFkmaxKuMQNYKI/tWF+xwc6T+PTm2xSSngvm+atgr/nUgBo9N7fUwsk4+suwtGj iuEA== X-Gm-Message-State: AOAM532hTaC/5kEW9R/nw3L46md/nC2dpstvc1GZpigv5XTRBbOEvCRA gOJJY7Je9qqXa6/SBgyAnndpSDcTLRI9EpyxJKm9wo6A2oCKRwnMs5W4xZ5DAVF63LTECT/lZgp 2CdomEf00foQ8rw== X-Received: by 2002:adf:f743:: with SMTP id z3mr12275640wrp.211.1629814318409; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814323625100003 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=C3=A9 --- 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 =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 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814329; cv=none; d=zohomail.com; s=zohoarc; b=KlyYX9yqTc10TRvkHE3RN4m7/h9dsVceLuahWcpgCVqUyNCyrr6fNl1tKhnLJsDPsBLa0PRsl3x7NW01BLX4HUIGIKFvXr1JRaxbtHfZ1yMXHJAyDUb8zfSCIYivxsMmP8wcKh3CIhSxIhgwm2Nt8dtYMSneNlsY8Uuyyg+RKd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814329; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=yP4txqlPFI2A9kMCd1u6S+dpF5skjJnaUikspGogW/I=; b=WYRfojsxBqheoryjeAXK28kAaiSh2V8h6njndpQn826Hxdwz3J1BG3ZHVn+B46mXB8jC51Y9FvhHZNnDmhz+JVxAQ6arrcFlXkHk+7F2mtw10DB1nGbetXd7UKCpqQLfXe8eeYXImx4pO+zlRedBC38Poi3QHjVjCMHNqfuQ1i0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1629814329646153.74618227319752; Tue, 24 Aug 2021 07:12:09 -0700 (PDT) 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-9-wsevX-NhNJq1tYzq2kYxJA-1; Tue, 24 Aug 2021 10:12:04 -0400 Received: by mail-wm1-f72.google.com with SMTP id j135-20020a1c238d000000b002e87aa95b5aso497249wmj.4 for ; Tue, 24 Aug 2021 07:12:03 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814327; 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=K0oJx9i0PkQMc/xGijbeIuq5SpckH2VxQfYT8wxJPahZc9Mwlkt5QGt6e1W7s0bnWwXjWw bH2cnHZAeu4iaBHv1TeR4wTItF8g1S3chR2rOvTOAI5D8i8boxUyHTD+jNW93pDfE6DvQS 2bfT1ToF2j2zxhgpTvsEeWHidqe0DfE= X-MC-Unique: wsevX-NhNJq1tYzq2kYxJA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yP4txqlPFI2A9kMCd1u6S+dpF5skjJnaUikspGogW/I=; b=l8DmjIRLbCYd7mBaTF+BHwFb7IBWbIehymqafT1t9TAQ93G6b5Q/MeQJtmkPbm6jAE 1nlqegoiO/k3v4VoTJ3E5yVb4fbPnDUfhVVm3yr66kxlFo5d8vyoiIoJluGppLp/hkrr yFojsX/5klEjPKIvkmhhsBXjsPHmvZ6GD0fch634h9iSSGIMbUBvofc5LjaUSlwt8kds yy9H2VZiAW2GukBgh6zOK0GPP+4iIyfTkEWlHwdFBqzt6HWw/89pkla8klFrVjfqP0LV VBo/LCn4YjqyrkS3uDBuEopgzWseTYS+/BRiM/ZicrbyZTUWKFog9rb20/lIyFzv1+GF rFLw== X-Gm-Message-State: AOAM531g10b8v/9gV378o3ZWd86mdnal41HqeeSILxTP7PU9d0SDfpuJ 1TwClFZJCoiZzgWfXE4qyAqmV0PtdPax1CCV9ftUKyfyL9PsG6dDbR+nikECP/hoNl2N2lNVqp1 Te3A1Fp00i+qQfg== X-Received: by 2002:adf:fa82:: with SMTP id h2mr5480657wrr.195.1629814323010; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814330756100001 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=C3=A9 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, 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 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814337; cv=none; d=zohomail.com; s=zohoarc; b=Ni6LdfrX0en75IGiXLLSuknz+ORPSOWT/dXmAHGo4YJXyojwLaE4V3ontBm7TAdQmlBc7y7vyGa6tS7XzbOGtYuIZxSjLUbMzGdm1sRFitHwhOf/kQbmuFBxw8liYuvWxIpohaFC6OlC+ddGp/RvL5hW47whHwX+WxAz6rlEZRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814337; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=UiR702sKQihvxXmLHPk9PJ+aENXmsbkBYxchZbzfBis=; b=kRLbzRjJek+fXXDaLC01qU5onmxBVuq2v6Iv6gUQaXAU3x7klY+K/mtOmO6n+xHnvRpVvkxzsUei86rZMc8B4GbJh0nxcPfbaZQIpsgkn90GApD1HhPid3mZZPIhcTnC0tGG8hPFd9ZBwy42mUolaUKh2l4hgdNMJo7oxzoABwc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 162981433735541.88916424751335; Tue, 24 Aug 2021 07:12:17 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-gY-Z4_FjM_-GHiyA-OmWig-1; Tue, 24 Aug 2021 10:12:13 -0400 Received: by mail-wr1-f71.google.com with SMTP id 102-20020adf82ef000000b001576e345169so50276wrc.7 for ; Tue, 24 Aug 2021 07:12:13 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814336; 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=Kr7WDI9qaoxl2L3BJ4P2MyZEUAHiseChRW2PM9dFutTppfvR43UJIaIUbsDwo5FRD1gfp1 eD3+9tZ9fJE5WTUxjsICMQsNx9MxeIJu+ec4fnOOE822FSSV2nYUdwT3vstrUj4NcOSWOC F5kOGib245dW+rNokBz0H+kLHy6TUIg= X-MC-Unique: gY-Z4_FjM_-GHiyA-OmWig-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UiR702sKQihvxXmLHPk9PJ+aENXmsbkBYxchZbzfBis=; b=gnTWwgDrh7SphzRicURnsl0HzYmUtk/25zZ2iaI7Vu3VmCvsgmQmMWO0LYwldxVrvy 3GA9dB9kjIqudhjA0GUTI6seti3zBsiu89b3MvWmFX2aItD9EeDrpCkCLMxA1BfOFeBV TmBY1/jWlU/nNbz+Axh5s9y7rPOCIxgYwIdamWDrFVcdtjJ4E3n4cujh+h4I7c3HSvHu 0SpqrLxVv3T09/lsLN8YpywWNMq4t8w/T4O5X6p+o8Zlcbf4g2G+52D7mDyXZBkgX8So qzJykoXoupRje3JO1hIdaUAs1x/XNU2ck9qvh+YvsLGvWaeNBvfowYMqf1lgCVrhvcNo 87iQ== X-Gm-Message-State: AOAM530NdAInHFVsfSVBcvLtFjn3IeF3IolVDhbW7+EPhA9zfOocgg4u h6rw9guF13+lQECnnx5oBMJT1oPbYoJ5aI/nMZHG8RrAm7bMrjichMKAChxWRKfyDzMhZ6n+0EB 2ijuXWGG8KvsheQ== X-Received: by 2002:a05:600c:2256:: with SMTP id a22mr4410718wmm.16.1629814330376; Tue, 24 Aug 2021 07:12:10 -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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814339302100001 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=C3=A9 --- 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, 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 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814338; cv=none; d=zohomail.com; s=zohoarc; b=mRcyHwpL++L5KhRcAS5WGrJcITq7SIy1xMyU0yDXKK+gMNl94EmmwO0DHutNDftkzeib+sp8amraWekpTNcmm7YpnXoLeadMm0j90UGS+1FGOnRtf2D4FfQ3hP0iKlJh1aiI3teHB7hXPqpKfq3N6GdEVXBdtgbp/LEDfzHa124= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814338; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=8tCh430uUATzOwz3ufEzgGlQkzhUTqSj3byRu2/z7X4=; b=WoavOoJP6FHhyyx6eCokxbZMVt0Iyxr/aUrg3LOjUAHfznxUUK0cNhVO+Sw93omWnZ1c/HCwku791bgkKaVtS0ojeeq3km1qmZORX8HOg0gS12UJgaQaW2q40PvflYqnAxD7EI+t1KBBc7d70GOGTTNem4Scbt5PMoAtJlmELTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 162981433802124.042761841852894; Tue, 24 Aug 2021 07:12:18 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-uAqldY0uOEyWpRgfmdAk4w-1; Tue, 24 Aug 2021 10:12:15 -0400 Received: by mail-wm1-f70.google.com with SMTP id r125-20020a1c2b830000b0290197a4be97b7so1091658wmr.9 for ; Tue, 24 Aug 2021 07:12:15 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id a77sm2581321wmd.31.2021.08.24.07.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 07:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8tCh430uUATzOwz3ufEzgGlQkzhUTqSj3byRu2/z7X4=; b=DskTsVc3cc1nGK1/sXVWp7PWIJz+ggmJfU+Xp0Xmw8usg1rMbzDoiirsLX9G6QzqgHkiIw gSgOdp4b4P4lLSvIQ2lNJwnkj6igt/48h0DdEqWct7nhimh/lTe2c26OkRIFSblaPir36B DWhyi+PMIQSQbvCseZfXdMLiwrel6KY= X-MC-Unique: uAqldY0uOEyWpRgfmdAk4w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8tCh430uUATzOwz3ufEzgGlQkzhUTqSj3byRu2/z7X4=; b=nyb5pkM7WYafTpu6K5k5llGqYrWoulnyxX4Xgg1FYgweBufGVhE/Hav4t/57fz1/1H qrRo12fYfqynNRpa1zy1JnLQxQGXtOBAkMj/EN8Vg1tx3oBbURb6CbdmxVrmbpvwSwwG v3rIFtK2Xmv20B2jq5+SJTjsGM+WBxdaLrnv7o7e+Cp0Hn21ds67YgX7l0j+xhT+iN1Q +DqQUXoTpOaLvPFO5XqAmD47ZiGDhDv0oA15T/v42DsMH3MS1O/mbtV+feLbIcNmSPXf teKZrjJD7QSJ5KcX8YNxU3m2nMAQvEwBpt0np+p2rkkQArOri1xIxtmXYwQJzwRSkT8M Iukg== X-Gm-Message-State: AOAM532X10avZJmlkj62Qjh0TOrEPGeuOk/Xkfxfb0r6yGmGEIwGG6+d 1qd80l7cFbXmroDncPOW2E5kT20cP5Zql959+VEnZPqy0ux+Y5rPyBzJ44rvgxyYL+oMP1T37Z8 XoqTPircycYthtQ== X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr4216045wme.81.1629814334562; Tue, 24 Aug 2021 07:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx034ZwJJZpiXZvD7xl4RIZ5xJ7ppmHdks4RVo2uA5G1/qHKrfIzfwU73Itb/koCYTEuAfMYg== X-Received: by 2002:a1c:a9d2:: with SMTP id s201mr4216014wme.81.1629814334267; Tue, 24 Aug 2021 07:12:14 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 6/9] util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map() Date: Tue, 24 Aug 2021 16:11:39 +0200 Message-Id: <20210824141142.1165291-7-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210824141142.1165291-1-philmd@redhat.com> References: <20210824141142.1165291-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814339354100002 Currently qemu_vfio_dma_map() displays errors on stderr. When using management interface, this information is simply lost. Pass qemu_vfio_dma_map() an Error** handle so it can propagate the error to callers. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- Changed: - Initialize *err before calling error_prepend (Eric Auger) - use error_reportf_err() in nvme_register_buf() --- include/qemu/vfio-helpers.h | 2 +- block/nvme.c | 20 ++++++++++---------- util/vfio-helpers.c | 13 +++++++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h index 4491c8e1a6e..bde9495b254 100644 --- a/include/qemu/vfio-helpers.h +++ b/include/qemu/vfio-helpers.h @@ -18,7 +18,7 @@ typedef struct QEMUVFIOState QEMUVFIOState; QEMUVFIOState *qemu_vfio_open_pci(const char *device, Error **errp); void qemu_vfio_close(QEMUVFIOState *s); int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, - bool temporary, uint64_t *iova_list); + bool temporary, uint64_t *iova_list, Error **errp); int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s); void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host); void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, diff --git a/block/nvme.c b/block/nvme.c index 6642c104aa4..663e5d918fa 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -176,12 +176,11 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQue= ue *q, return false; } memset(q->queue, 0, bytes); - r =3D qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova); + r =3D qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova, err= p); if (r) { - error_setg(errp, "Cannot map queue"); - return false; + error_prepend(errp, "Cannot map queue: "); } - return true; + return r =3D=3D 0; } =20 static void nvme_free_queue_pair(NVMeQueuePair *q) @@ -239,7 +238,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeSt= ate *s, qemu_co_queue_init(&q->free_req_queue); q->completion_bh =3D aio_bh_new(aio_context, nvme_process_completion_b= h, q); r =3D qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes, - false, &prp_list_iova); + false, &prp_list_iova, errp); if (r) { goto fail; } @@ -533,9 +532,9 @@ static bool nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - r =3D qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova); + r =3D qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova, errp); if (r) { - error_setg(errp, "Cannot map buffer for DMA"); + error_prepend(errp, "Cannot map buffer for DMA: "); goto out; } =20 @@ -1031,7 +1030,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriver= State *bs, NvmeCmd *cmd, try_map: r =3D qemu_vfio_dma_map(s->vfio, qiov->iov[i].iov_base, - len, true, &iova); + len, true, &iova, NULL); if (r =3D=3D -ENOSPC) { /* * In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA @@ -1523,14 +1522,15 @@ static void nvme_aio_unplug(BlockDriverState *bs) static void nvme_register_buf(BlockDriverState *bs, void *host, size_t siz= e) { int ret; + Error *local_err =3D NULL; BDRVNVMeState *s =3D bs->opaque; =20 - ret =3D qemu_vfio_dma_map(s->vfio, host, size, false, NULL); + ret =3D qemu_vfio_dma_map(s->vfio, host, size, false, NULL, &local_err= ); if (ret) { /* FIXME: we may run out of IOVA addresses after repeated * bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_un= map * doesn't reclaim addresses for fixed mappings. */ - error_report("nvme_register_buf failed: %s", strerror(-ret)); + error_reportf_err(local_err, "nvme_register_buf failed: "); } } =20 diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index e7909222cfd..3e1a49bea15 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -463,13 +463,15 @@ static void qemu_vfio_ram_block_added(RAMBlockNotifie= r *n, void *host, size_t size, size_t max_size) { QEMUVFIOState *s =3D container_of(n, QEMUVFIOState, ram_notifier); + Error *local_err =3D NULL; int ret; =20 trace_qemu_vfio_ram_block_added(s, host, max_size); - ret =3D qemu_vfio_dma_map(s, host, max_size, false, NULL); + ret =3D qemu_vfio_dma_map(s, host, max_size, false, NULL, &local_err); if (ret) { - error_report("qemu_vfio_dma_map(%p, %zu) failed: %s", host, max_si= ze, - strerror(-ret)); + error_reportf_err(local_err, + "qemu_vfio_dma_map(%p, %zu) failed: ", + host, max_size); } } =20 @@ -725,7 +727,7 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size,= uint64_t *iova) * mapping status within this area is not allowed). */ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, - bool temporary, uint64_t *iova) + bool temporary, uint64_t *iova, Error **errp) { int ret =3D 0; int index; @@ -774,6 +776,9 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, *iova =3D iova0; } out: + if (ret) { + error_setg_errno(errp, -ret, "Cannot map buffer for DMA"); + } return ret; } =20 --=20 2.31.1 From nobody Mon May 6 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814342; cv=none; d=zohomail.com; s=zohoarc; b=lJSkoo/sj5c5bo5WWpGyPSzbzg2AoxduCITTGxz93NJLCEYkEGxI3kSXD8d5BMkW+DKPYDN5J+PcMhoMFEIGGDgiUYQte+bHEuYzumSzxpiDs1lkUP13ga0runp+jN9P04YDrQRap6sOTFvygia5JBQEJwRAfoZWMZrdARZKJnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814342; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Hf6aQWPomJbErfm8jcxJmMDuWpHIgM/AzBOqCZSkpgc=; b=HnLb4ont3YOoD5ejnno/CaTajzaBS0g41pzlbhvNJJFidRn0pOUfw8Alv7Z2wdxTVzSgKemWzBWuVhKFKWs2lfaLG1ExtzG/AlT4AMe+vfs7pueMovNn8BQ2R/TfnRO7zNpG9QqdLbk4mYlbjCtqb2p1XP0W1EOgUKuGsS52bAc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 162981434268692.10089025885111; Tue, 24 Aug 2021 07:12:22 -0700 (PDT) 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-140-pnvSWIXeMtmpupl8N4DbZg-1; Tue, 24 Aug 2021 10:12:20 -0400 Received: by mail-wr1-f69.google.com with SMTP id a9-20020a0560000509b029015485b95d0cso5799105wrf.5 for ; Tue, 24 Aug 2021 07:12:20 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814341; 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=g5+dqQRFp2GMmMfeht6unmnQSw8a5iltgDN/8VE2k9/wkmlvqNtt5oQ3/6HEIdnjlNOm7k KFX2u+Kumam62Cq3qSSqhFvgZlSyXLCBdU8S5tnXNkUjouAutqGiqA5pjp5ZP1lH39ipiK +7ccmnBTTrIB8P47efngVsTwlrosoY8= X-MC-Unique: pnvSWIXeMtmpupl8N4DbZg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hf6aQWPomJbErfm8jcxJmMDuWpHIgM/AzBOqCZSkpgc=; b=RnywnF0llZMQavyRRdByjgf4hEL2i3gO7yj6aePMo0KzOpV5Fxoo7MtXZbIzgiydji 4/cUfSe1ZvelLtK/StsPiPaYI0GzJV3bCOS/qpePocW1MRWP5Oz8yXxP/nI1l2LKfMOO QxoLJwJyhA4/oO4eKZwu1HLlquUWoGqq1HHMRicGCNmtd9mH71V6gxWxk1hTh8VMquAf 2fRX5TzmtS+27IPAwKtQ+EhzeuqKnQMZPgwx1MoeUg1qH2S342CR0Sa0ewn32uOcGFen JgjXMe1khxJHwyyiKWuURgiPTjAy6tPd/NdM9cRulF0S6U8JdGe6atYXH0GG1d+uO7MU 6tRQ== X-Gm-Message-State: AOAM531kBF4ZwZnu/RP6z/pvtEHJNNd30Z+bfm7lVGcWFCYyv62GwCKI 0NQFadWFA4BiSas7SCLOETWi79cbWhU69Ife3powtdzhm+E7iHbpGp9bl7jlQddoWyYkQzm9/Sx KGZ2mkA3PdTKvxg== X-Received: by 2002:a05:600c:21d7:: with SMTP id x23mr4379418wmj.10.1629814339200; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814344156100001 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=C3=A9 --- 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(BDRVNVMeSt= ate *s, r =3D 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 =3D -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 =3D 0; int index; IOVAMapping *mapping; uint64_t iova0; @@ -742,32 +741,34 @@ 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 (s->high_water_mark - s->low_water_mark + 1 < size) { - ret =3D -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 =3D -ENOMEM; - goto out; + if (qemu_vfio_find_fixed_iova(s, size, &iova0) < 0) { + error_setg(errp, "iova range not found"); + 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)) { - ret =3D -ENOMEM; - goto out; + error_setg(errp, "iova range not found"); + return -ENOMEM; } ret =3D 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, si= ze_t size, if (iova) { *iova =3D iova0; } -out: - if (ret) { - error_setg_errno(errp, -ret, "Cannot map buffer for DMA"); - } - return ret; + return 0; } =20 /* Reset the high watermark and free all "temporary" mappings. */ --=20 2.31.1 From nobody Mon May 6 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814347; cv=none; d=zohomail.com; s=zohoarc; b=FeXC1Fn9t7SnpOZE77d6Knje8D1AxZJUb3jmwlD2NK2hEvx/vjgRv6fTcXFZ1dLpHncLwn333yBCy6/Hwb1kJwgxPyQ87f4mO1IoheF7u5thSojiJVqfKckfH4Nmm2HSLrfHtBmOKUwNnucbLHkb6SB4qDZs1bP+u3HsIYV4K0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814347; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=wjVPj1eNKTQy5fwjblCd47XbInf1YqiKgdyKZG3IkLI=; b=n80kJKMHDMKpb7zpb/+koVZYUOOuMnVTOrupzzBx/qn33LENlculMhPlEtLpHNQJHPZTPJBvXYZZqNJUtZJbv4YcUc1Sh/6aRzxcSNGiEJBkUJwkNAQWsPln/pDBu1YGWT8td1NlZal+frlmZQ3bl9ud1ft9bBJG1aylOD7ZA/U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16298143472609.453658949091846; Tue, 24 Aug 2021 07:12:27 -0700 (PDT) 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-582-xMvzrNx8OZq-kRGejXv2Xw-1; Tue, 24 Aug 2021 10:12:24 -0400 Received: by mail-wm1-f72.google.com with SMTP id x125-20020a1c3183000000b002e73f079eefso1331470wmx.0 for ; Tue, 24 Aug 2021 07:12:24 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) 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= X-MC-Unique: xMvzrNx8OZq-kRGejXv2Xw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wjVPj1eNKTQy5fwjblCd47XbInf1YqiKgdyKZG3IkLI=; b=L9KzHmZh+8h+F1eOu5FdtAgE3Lg6qnWQzWqPnzZiqBHvTJ17+TsWVPrEyGmJj7+M5P oB+tS8OLpsMwRxO6VxPzj6dKbkV7s2ZpcbeB/u3dIBZ07Z0s+WIF+78rVMlReoh15xnp HQSMF0IQ6he7MHTpMOoZgm5dhD1lZLrROGJVGqPXLVxTST8V7XpLuvj9EAyLc++1s8k1 /AIyEAizeK/iRHrGgO5ee5b84Lp8tz9wRMUEgFyCDh3bot0zD/cB+teKIDmCGIXmUMET otbZ8SFqYS4lnb8T+2DNFJiefrtJuxsPdEK4Lp75yyYRCHDQzepIrP79El2bhHgxZibX CU9w== X-Gm-Message-State: AOAM531Zz23t3fOa27WbewDZ9D2tE0TNkU+kDId0xnkcK8rSTVH1W0n6 FdNXSnW1NOotwOejc6/4p0dG9E7VmmG89LH3HBXPDap7mxGs4GLDxLiogB63d3388LIxnDPQiXT JZOaXEqcKdxyfcw== X-Received: by 2002:a05:600c:21cd:: with SMTP id x13mr4267521wmj.20.1629814343500; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng Subject: [PATCH 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629814348824100001 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=C3=A9 --- 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, =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; @@ -755,7 +755,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; @@ -766,7 +766,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, siz= e_t size, error_setg(errp, "iova range not found"); 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 20:14:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629814430; cv=none; d=zohomail.com; s=zohoarc; b=gye8EA1D82C9DDVKewokQRJ4ccSg8TCgsnFAajIvTbUkhYWTehbJp7NmqPsR+L/OeHE/lYXjaXeWosfZfGOTN/PHNQBWU3o3By6Q4eoLH5mFnfHd3NpEQjRvwppEA2bR0cKKnTbY7x7JNAFDz/AcrfP1TnhdJpLYcwjhEs82qY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629814430; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=iERganKRZ2P65/BHVYzLPkJwsOXEHjYEJ8zC3s7dmRE=; b=U1rpvJpBVH0+p9uAGoWF9A76BqeD1IGPDBF3iIqtGZAK2dRXBcAh3dudNNVOwZjaNW2YPCZ8+r6HQXSZoRHBsJWKorDjRdyiS36WXQAww3wwYCCW7S9ZofR0Ur2m4m2XfR7p+UaWmodt1DDnbBnzGx3lU7EhfYaFBT49AperXM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629814430171107.66381961806644; Tue, 24 Aug 2021 07:13:50 -0700 (PDT) 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-147-CVoGoq3bPlmH6vDDlVkuaw-1; Tue, 24 Aug 2021 10:12:30 -0400 Received: by mail-wm1-f69.google.com with SMTP id w25-20020a1cf6190000b0290252505ddd56so4161429wmc.3 for ; Tue, 24 Aug 2021 07:12:29 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814351; 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=LxysC4JVfkw4xnXGr3ZBxpYLw8Zgr3a7e2nQxStp8dEF3oNxMskG5/PN4+5F9WbJBr3McV mogC5rJrTrp+lDUqCAiRmWQPUE1ml308g0L4OpqoeWdlB02eNn5XUeXozU/PghbhA9vb7B UvEBo9b4Mfxv32Fpx2AOuIjZc7jMkyE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629814429; 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=JgyKy9IDROaVAkudZm4kcNhH3exCCx7OMDL3I/uKKrPU0s/CxfFD2xeFlYMWerXEBFmY/n toiDVkjxMfavJUD/pH97hNu9aFd6FrEmwoOU6yiVQ59p/ygwKq0uiALMbqDKGdZgNH0PFG AYW0a/X0X88daIjQkip3O0HVLkijejI= X-MC-Unique: CVoGoq3bPlmH6vDDlVkuaw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iERganKRZ2P65/BHVYzLPkJwsOXEHjYEJ8zC3s7dmRE=; b=fAj7b00w+zF0uuZyJcHMEL6XcmB+RsiYUWztx2UQfLuYMQUxVmWonkUrFl4nH+GZEI q5WPf7wMDVuF2esLpGoyGun9Iu+U8Igznq9BFpKYgNmAr31d/Ney5nYgoOnuT9ejpM6C pz3QnN3g0mmThSbbmzD4W3bv2wTkFzdbnDWgsnovf63BCXOVYwn3689tds3dgmyI+98/ 0bDkKmtyPCJOSUcd06Q4XRvte58uDI16ygZU89PkUzWZyca/IPPBW9xY3yhUOUE+w7CX Ex6vMI3T5G5+APT1jLq2vXKHYwRHl44ovf2fiKE5KyttB5ptSNdAHru1MpYSs/l4ihMN Yl4Q== X-Gm-Message-State: AOAM533ZiKs+afUb3tKlh9judDcXhBTNMzK8eHDwCQG/7zZBYF1dSj4B Zj09rir5GbVJAEPSJIc2ZVZAMIdGaBpnCsWBlL3BTndLHX2zCrjxy59kReE/FAxc+SraYrlJpFf EWLqrmSXMMKds5A== X-Received: by 2002:adf:cd10:: with SMTP id w16mr20305380wrm.404.1629814347890; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Auger Eric , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Fam Zheng , Tingting Mao 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) (identity @redhat.com) X-ZM-MESSAGEID: 1629814431882100001 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=C3=A9 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(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