From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A784BC4338F for ; Wed, 25 Aug 2021 13:31:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 33AE660EB0 for ; Wed, 25 Aug 2021 13:31:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 33AE660EB0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:58848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIszl-0002wA-84 for qemu-devel@archiver.kernel.org; Wed, 25 Aug 2021 09:31:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIsdm-0005DZ-6c for qemu-devel@nongnu.org; Wed, 25 Aug 2021 09:08:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34460) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIsdj-0004Ps-AZ for qemu-devel@nongnu.org; Wed, 25 Aug 2021 09:08:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629896902; 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=/XN5neVw2d+R0zNDa36dSoNCaG/h6QV9hhlRj8AeZko=; b=Am1DcLglsk5E+eRMyg8u3EuHuhPPn4DytL6t+5J/C+wFjpb1BGJhxFe8MoiWPA/BkVPpvq EM12ti+0vpkiH02VdajDoMxcXFgKhf71O8/YoHveftFaAeiZBTLAUv1S1xc4IstJyeSINi ulWCshdJFPA4Vc/Pe0N3QO68kes21TY= 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-417-xGBPoxdjMT-8x4oUGTv9lw-1; Wed, 25 Aug 2021 09:08:20 -0400 X-MC-Unique: xGBPoxdjMT-8x4oUGTv9lw-1 Received: by mail-wm1-f72.google.com with SMTP id m33-20020a05600c3b2100b002e87a0542efso1205903wms.2 for ; Wed, 25 Aug 2021 06:08: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:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/XN5neVw2d+R0zNDa36dSoNCaG/h6QV9hhlRj8AeZko=; b=G+JTHNX9eOX3BfKBTRj1l0g7rNNy2NxzT7Vm/l5L0lkHRsJl/TPzPR+o30pREpwbmO CuzLSVW4DJkhiZEES80crfgaWKm0CUFFXlaOFH+5kZtnfp/K14FZb/N35f13LiY0z4mX sLnkV0pAfxaXn2bF6uuXNt6h5DXAt1D1oC6M2ZHPjWzCEnfsZ923polJlTprHIiZA6U1 ih5h+h8eFmILEPY1OL9YFeXOxtb+O4S5umut6DFHTQvNPqq5UggZyQaeAqKZvx7Tx4uj kq7E8PJdrpjj1cFF1qrZ58U/r6BDOu55Czrlb3WSLhdu9k/s23PlbPd1w59+9NBm1Ggn Ugzw== X-Gm-Message-State: AOAM532wyC2CN/QFoyrGywlQNxRPH/NFCz75SQxxHRMlO+M+m73fM/ju PMyFsZ3ejy26jP5j4Ig9wHTgkPjNYFM0JtVyMMQ/89iOxNkNKRDgd2Mh0NuXPl+HgIpaCezw4Bg f0yHIcG/bZnBtJ1M= X-Received: by 2002:adf:e901:: with SMTP id f1mr25280563wrm.13.1629896899579; Wed, 25 Aug 2021 06:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzppWrsqCGGlT/gGnvsu92LrixUY3RUsdWrRY2/0KiZ5/DesYg/N5wS170RcEcjlziwgiytuA== X-Received: by 2002:adf:e901:: with SMTP id f1mr25280525wrm.13.1629896899344; Wed, 25 Aug 2021 06:08:19 -0700 (PDT) Received: from [192.168.1.36] (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id y1sm5717112wmq.43.2021.08.25.06.08.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Aug 2021 06:08:18 -0700 (PDT) Subject: Re: [PATCH 7/9] util/vfio-helpers: Have qemu_vfio_dma_map() propagate Error To: Klaus Jensen References: <20210824141142.1165291-1-philmd@redhat.com> <20210824141142.1165291-8-philmd@redhat.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <45edae8d-5c41-5159-dbb6-1a15f0164aa4@redhat.com> Date: Wed, 25 Aug 2021 15:08:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: 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-Language: en-US Content-Transfer-Encoding: 8bit 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: -57 X-Spam_score: -5.8 X-Spam_bar: ----- X-Spam_report: (-5.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.745, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-2.24, 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, qemu-devel@nongnu.org, Auger Eric , Hanna Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 8/25/21 1:34 PM, Klaus Jensen wrote: > On Aug 24 16:11, Philippe Mathieu-Daudé wrote: >> 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: "); > > Ah. Here is the missing error message that I noticed in patch 2 ;) So I should use error_setg() in patch 2 and replace it with error_prepend() here? I'm trying to address Eric's comments from: https://lore.kernel.org/qemu-devel/2cbd5471-4611-ae6b-d79f-db6ff19db5bf@redhat.com/ https://lore.kernel.org/qemu-devel/bd1cc1c9-3553-d252-3ca9-a23bc1035170@redhat.com/ > >> 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; > > Just curious. > > Previously this did error_setg_errno in out. Why don't we want to do that here? I didn't thought about it but indeed you are right. Thanks for the review! Phil.