Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2773131ybx; Fri, 8 Nov 2019 09:07:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzGjMmfqREZcN7bGbznT4X4w6+Bj+b7eT49kT8WlRd+NXiFR1EPICWMRRM56UdSDpaNZzep X-Received: by 2002:a1c:7f54:: with SMTP id a81mr9374058wmd.48.1573232866921; Fri, 08 Nov 2019 09:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573232866; cv=none; d=google.com; s=arc-20160816; b=uyzJZt6EKS+QmPo02vrnaX3gs4ybnVVQyNpUtdyg3Dxu3inljkc6fyotq8JDmwJ6HO I6GlTUygVtsCWHLwYSUcwhcKE1wUvrN1wpkVb3EVGVEVYcHuv7Q1k+8xvL6/LSEMvwZ1 MRIjoPexuUVWblqBL7PJve2ln23Uy3sweG8DOj9W/lF3rzv0oLv6fBg4vtJwkbF3kVll s7TiDha5EiYAF4mBeuM85ZXGsuyiXgpkPD4RalIRpM/7gbYX/cHpSEMItVS3wyHZiGB8 If2/8bniVpA1ZoXNxeR1LVKn/8QjSwdaqRjgMa1okJXB4E9u35r1bz0aExPIwpF0S6Ti HoMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to; bh=cgH3aozGm4E9aIHiSFohm2d0YvfWAi5w8+jpCri6jVg=; b=Iu5Swy2ddqN0CKgBuZI9UhqUFvoF92j9GAwas7Y+aLeR2d03+O+WXfAfP1pCkJqF0h Z3ouor+GRe4YG5ubSPe6KJSe1txyLzKNdzOd+aP835I6FQnR/bwWK3HW/lzfxe/ngej2 UxJt5NGU2hIs2IuhU6Eq8rtKWeg76R1KrJoY27rszrDUS/mjUPUK6+WemyHB9ovbsTEl iaOZR4UwLwYInJw90ggFAPpANiahI5TsuLfh+csJFztgDjlZB2zx0FKZZ/1JCA8cDZVF Y6yB2JVZZMbylMe6iWwka7reqLXqfgvMyuCBJogs5UjlSFPuvX1BMR8FOznidjL4+v+a 4nBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d44si4786744ede.149.2019.11.08.09.07.23; Fri, 08 Nov 2019 09:07:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730319AbfKHREm (ORCPT + 99 others); Fri, 8 Nov 2019 12:04:42 -0500 Received: from ale.deltatee.com ([207.54.116.67]:46266 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729847AbfKHREl (ORCPT ); Fri, 8 Nov 2019 12:04:41 -0500 Received: from s0106ac1f6bb1ecac.cg.shawcable.net ([70.73.163.230] helo=[192.168.11.155]) by ale.deltatee.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1iT7ga-0008P8-D6; Fri, 08 Nov 2019 10:04:37 -0700 To: Jiasen Lin , linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com, jdmason@kudzu.us Cc: allenbh@gmail.com, dave.jiang@intel.com References: <1573097913-104555-1-git-send-email-linjiasen@hygon.cn> From: Logan Gunthorpe Message-ID: <7ea7ef5d-7e46-396a-8d70-2c6c333a4508@deltatee.com> Date: Fri, 8 Nov 2019 10:04:26 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <1573097913-104555-1-git-send-email-linjiasen@hygon.cn> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.73.163.230 X-SA-Exim-Rcpt-To: dave.jiang@intel.com, allenbh@gmail.com, jdmason@kudzu.us, linux-ntb@googlegroups.com, linux-kernel@vger.kernel.org, linjiasen@hygon.cn X-SA-Exim-Mail-From: logang@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [PATCH] NTB: ntb_perf: Fix address err in perf_copy_chunk X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-11-06 8:38 p.m., Jiasen Lin wrote: > peer->outbuf is a virtual address which is get by ioremap, it can not > be converted to a physical address by virt_to_page and page_to_phys. > This conversion will result in DMA error, because the destination address > which is converted by page_to_phys is invalid. Hmm, yes, ntb_perf is obviously wrong. I never noticed this, how did this ever work? > We Save the physical address in perf_setup_peer_mw, it is MMIO address > of NTB BARx. Then fill the destination address of DMA descriptor with > this physical address to guarantee that the address of memory write > requests fall in memory window of NBT BARx. Using the physical address directly is also wrong and will not work in the presence of an IOMMU. You should use dma_map_resource() for this. See what was done in ntb_transport[1]. Thanks, Logan [1] c59666bb32b9 ("NTB: ntb_transport: Ensure the destination buffer is mapped for TX DMA") > Signed-off-by: Jiasen Lin > --- > drivers/ntb/test/ntb_perf.c | 28 +++++++++++++++++++++++----- > 1 file changed, 23 insertions(+), 5 deletions(-) > > diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c > index e9b7c2d..1c2fd1a 100644 > --- a/drivers/ntb/test/ntb_perf.c > +++ b/drivers/ntb/test/ntb_perf.c > @@ -149,6 +149,7 @@ struct perf_peer { > u64 outbuf_xlat; > resource_size_t outbuf_size; > void __iomem *outbuf; > + phys_addr_t out_phys_addr; > > /* Inbound MW params */ > dma_addr_t inbuf_xlat; > @@ -776,7 +777,8 @@ static void perf_dma_copy_callback(void *data) > } > > static int perf_copy_chunk(struct perf_thread *pthr, > - void __iomem *dst, void *src, size_t len) > + void __iomem *dst, void *src, size_t len, > + phys_addr_t dst_phys_addr) > { > struct dma_async_tx_descriptor *tx; > struct dmaengine_unmap_data *unmap; > @@ -807,8 +809,7 @@ static int perf_copy_chunk(struct perf_thread *pthr, > } > unmap->to_cnt = 1; > > - unmap->addr[1] = dma_map_page(dma_dev, virt_to_page(dst), > - offset_in_page(dst), len, DMA_FROM_DEVICE); > + unmap->addr[1] = dst_phys_addr; > if (dma_mapping_error(dma_dev, unmap->addr[1])) { > ret = -EIO; > goto err_free_resource; > @@ -901,6 +902,8 @@ static int perf_run_test(struct perf_thread *pthr) > u64 total_size, chunk_size; > void *flt_src; > int ret = 0; > + phys_addr_t flt_phys_addr; > + phys_addr_t bnd_phys_addr; > > total_size = 1ULL << total_order; > chunk_size = 1ULL << chunk_order; > @@ -909,12 +912,15 @@ static int perf_run_test(struct perf_thread *pthr) > flt_src = pthr->src; > bnd_dst = peer->outbuf + peer->outbuf_size; > flt_dst = peer->outbuf; > + bnd_phys_addr = peer->out_phys_addr + peer->outbuf_size; > + flt_phys_addr = peer->out_phys_addr; > > pthr->duration = ktime_get(); > > /* Copied field is cleared on test launch stage */ > while (pthr->copied < total_size) { > - ret = perf_copy_chunk(pthr, flt_dst, flt_src, chunk_size); > + ret = perf_copy_chunk(pthr, flt_dst, flt_src, chunk_size, > + flt_phys_addr); > if (ret) { > dev_err(&perf->ntb->dev, "%d: Got error %d on test\n", > pthr->tidx, ret); > @@ -925,8 +931,15 @@ static int perf_run_test(struct perf_thread *pthr) > > flt_dst += chunk_size; > flt_src += chunk_size; > - if (flt_dst >= bnd_dst || flt_dst < peer->outbuf) { > + flt_phys_addr += chunk_size; > + > + if (flt_dst >= bnd_dst || > + flt_dst < peer->outbuf || > + flt_phys_addr >= bnd_phys_addr || > + flt_phys_addr < peer->out_phys_addr) { > + > flt_dst = peer->outbuf; > + flt_phys_addr = peer->out_phys_addr; > flt_src = pthr->src; > } > > @@ -1195,6 +1208,9 @@ static ssize_t perf_dbgfs_read_info(struct file *filep, char __user *ubuf, > "\tOut buffer addr 0x%pK\n", peer->outbuf); > > pos += scnprintf(buf + pos, buf_size - pos, > + "\tOut buff phys addr %pa[p]\n", &peer->out_phys_addr); > + > + pos += scnprintf(buf + pos, buf_size - pos, > "\tOut buffer size %pa\n", &peer->outbuf_size); > > pos += scnprintf(buf + pos, buf_size - pos, > @@ -1388,6 +1404,8 @@ static int perf_setup_peer_mw(struct perf_peer *peer) > if (!peer->outbuf) > return -ENOMEM; > > + peer->out_phys_addr = phys_addr; > + > if (max_mw_size && peer->outbuf_size > max_mw_size) { > peer->outbuf_size = max_mw_size; > dev_warn(&peer->perf->ntb->dev, >