From patchwork Thu Dec 16 12:35:57 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: 12681073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8FA11C433F5 for ; Thu, 16 Dec 2021 12:56:32 +0000 (UTC) Received: from localhost ([::1]:35286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxqJD-0002pX-Bd for qemu-devel@archiver.kernel.org; Thu, 16 Dec 2021 07:56:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxq08-00029S-6b for qemu-devel@nongnu.org; Thu, 16 Dec 2021 07:36:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxq06-0004bq-08 for qemu-devel@nongnu.org; Thu, 16 Dec 2021 07:36:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639658204; 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=sVs/ItDUtTUaUH7BuhHvQPHC0PdKVqniEjcG6RP0pL0=; b=UC7kihorAyUcvV3QgX0kmDIPhzzeM/564Q3Jp2hIBUnbuJBi/63XUOvrnHcT5r/qUhEOPa Pr+UjhzU1WD2ajTRKi/buaErvEgtnk6y/XK/6BugwmYGCsb4CDOtf/jVNBBp+Qg139PhdE wRKRgBm3vEs3NUwfUpWXN+R3mAZjj8o= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-122-KFuK0FDuPjeznoqpgmcTZQ-1; Thu, 16 Dec 2021 07:36:43 -0500 X-MC-Unique: KFuK0FDuPjeznoqpgmcTZQ-1 Received: by mail-wm1-f72.google.com with SMTP id bg20-20020a05600c3c9400b0033a9300b44bso10236715wmb.2 for ; Thu, 16 Dec 2021 04:36:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sVs/ItDUtTUaUH7BuhHvQPHC0PdKVqniEjcG6RP0pL0=; b=B/YUaRWw2y+2E2PPeE0/Y79bny50LUnKQjFw27WNvsBMZW+XWE3rZB+hyvs8F9HK2A puXxc437VjdkQB4F7ZCNG63vigFlvrsWWC6Spcyk6W9RpeNvIewux2KkrxsrLEnCzjMp Z4QRR7TGZYeEyLG26CKsTIrVEleNnTTUKp9oD6+UlqN/tCOxBal1KSV53yXFTPSGYnL7 NTCe1P5bohFpOCl4Z7cJVF1OCjxv6Wp88jSNpO+mtsTv92Adr4WucT6eGU3q7MWrRBmk Rh1o3/le2J6ypxMoeTVv+Waut18w+Oke2vY40JJJTkKKMkfu2kGXophohuEWfhD1HrxY hTAQ== X-Gm-Message-State: AOAM530ILFcY3EdivhwNkhzTXPcftvPMaSQoRJ6BcyFUJMdKAJH+aF0C F67VNEqBuDS9UTMyY5Vnba0ohmWBJxB1u7Cvamu0uKyk1XHiMGJRJK5qu0VzJUWSXPSNPWZSXLe j7UX4OAC1rqjQZuAIF/cpkZNDnU8v0dOxo2Rw6dDFwdZk5ZkSSUk5DHe9BRXfQffq X-Received: by 2002:a5d:4311:: with SMTP id h17mr8567145wrq.677.1639658202094; Thu, 16 Dec 2021 04:36:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4AZ6EgVgfmx4C5LaKnvqF5PNDBHp+KScJwd5/UulMjh5g+OnpgvH+UrO5LF3xjMEPEmAfMw== X-Received: by 2002:a5d:4311:: with SMTP id h17mr8567112wrq.677.1639658201813; Thu, 16 Dec 2021 04:36:41 -0800 (PST) Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id b19sm8834949wmb.38.2021.12.16.04.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 04:36:41 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 7/8] dma: Let dma_buf_rw() propagate MemTxResult Date: Thu, 16 Dec 2021 13:35:57 +0100 Message-Id: <20211216123558.799425-8-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211216123558.799425-1-philmd@redhat.com> References: <20211216123558.799425-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.718, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Hannes Reinecke , qemu-block@nongnu.org, David Hildenbrand , John Snow , Jason Wang , "Michael S. Tsirkin" , Li Qiang , Qiuhao Li , Peter Xu , Keith Busch , Alexander Bulekov , Gerd Hoffmann , Klaus Jensen , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" dma_memory_rw() returns a MemTxResult type. Do not discard it, return it to the caller. Since dma_buf_rw() was previously returning the QEMUSGList size not consumed, add an extra argument where this size can be stored. Update the 2 callers. Signed-off-by: Philippe Mathieu-Daudé --- softmmu/dma-helpers.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index a391773c296..b0be1564797 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -294,12 +294,14 @@ BlockAIOCB *dma_blk_write(BlockBackend *blk, } -static uint64_t dma_buf_rw(void *buf, int32_t len, QEMUSGList *sg, - DMADirection dir, MemTxAttrs attrs) +static MemTxResult dma_buf_rw(void *buf, int32_t len, uint64_t *residp, + QEMUSGList *sg, DMADirection dir, + MemTxAttrs attrs) { uint8_t *ptr = buf; uint64_t resid; int sg_cur_index; + MemTxResult res = MEMTX_OK; resid = sg->size; sg_cur_index = 0; @@ -307,23 +309,34 @@ static uint64_t dma_buf_rw(void *buf, int32_t len, QEMUSGList *sg, while (len > 0) { ScatterGatherEntry entry = sg->sg[sg_cur_index++]; int32_t xfer = MIN(len, entry.len); - dma_memory_rw(sg->as, entry.base, ptr, xfer, dir, attrs); + res |= dma_memory_rw(sg->as, entry.base, ptr, xfer, dir, attrs); ptr += xfer; len -= xfer; resid -= xfer; } - return resid; + if (residp) { + *residp = resid; + } + return res; } uint64_t dma_buf_read(void *ptr, int32_t len, QEMUSGList *sg, MemTxAttrs attrs) { - return dma_buf_rw(ptr, len, sg, DMA_DIRECTION_FROM_DEVICE, attrs); + uint64_t resid; + + dma_buf_rw(ptr, len, &resid, sg, DMA_DIRECTION_FROM_DEVICE, attrs); + + return resid; } uint64_t dma_buf_write(void *ptr, int32_t len, QEMUSGList *sg, MemTxAttrs attrs) { - return dma_buf_rw(ptr, len, sg, DMA_DIRECTION_TO_DEVICE, attrs); + uint64_t resid; + + dma_buf_rw(ptr, len, &resid, sg, DMA_DIRECTION_TO_DEVICE, attrs); + + return resid; } void dma_acct_start(BlockBackend *blk, BlockAcctCookie *cookie,