Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp418622ybx; Wed, 6 Nov 2019 19:46:48 -0800 (PST) X-Google-Smtp-Source: APXvYqwfc7qysWqVGMBJeMYdeFqILpFU2AEgRfFwYWHzerXweXTIs1S7IxAMdbv03FYkdcNh9vK9 X-Received: by 2002:a17:906:2584:: with SMTP id m4mr1012826ejb.287.1573098408536; Wed, 06 Nov 2019 19:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573098408; cv=none; d=google.com; s=arc-20160816; b=0RA1COzAbFRXj+PS+8TKymlZEoqAdAm2s5XSrugLyt4wGxRe1EWbJIWA0K54jUzq8m nHHZt/FyZOJR/GrYRz5yKwEeRazJbweC4cNuvyJleDZQeorI1Mbmm2EWKMDkbOVCNpid G8AVr4h5Y/n/a8ttVW9gTQeqRNxfU9n/flBzoe84x7Fpv2O03qeFvtxa6uHT8nqnZ7m4 yXszdqia8mPmNfW+Mty7Qoy4RrJkuZWbnwn8oYf5tieMPG5HgToSZOnqcCyFYDVYLub3 i1lXeWQfPK16F/A9zGm3A6yrrOglaqmPhdlVWHckzYV3VWt40E7sAqY26gVvzVsq5tzT aT/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=qcEqP9UgxXW3W/lnjNyN5Phe4Kb9+fHQeZNpj2muaZ4=; b=xvd8ZZAXO4oT1JxmThSOW0WvwyGLPz9U1wiexrE/XShSwlto5jo39Jppq/2/ewiSDc bPFLBFgtccHfh14+6ywUe5QbrFO3eb0gu/J2e8AgmwMJ5FDe+2KaAurz+To/NbhCVAFI dVBALD1d+TUaZCZP/klwpyO3wFHPegWHCLvFPOIYuxsVsLQA0WI21uhFU7nKxrnjeE2W AZQjmyc8K0gzPvV+Z+l8FWXo06/R/zWYGwWVR032EnrvEcODYhNBWfwdwdqcdI3BCx2/ TnJ09Krm+fgziKDAOZMRzUtoLYp01Eq9YyB1IWCHoE/GugmDRhB8U5z+s0y5N4SwUWsA chNw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hygon.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si496670eda.433.2019.11.06.19.46.25; Wed, 06 Nov 2019 19:46:48 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hygon.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733144AbfKGDmi (ORCPT + 99 others); Wed, 6 Nov 2019 22:42:38 -0500 Received: from spam01.hygon.cn ([110.188.70.11]:46345 "EHLO spam1.hygon.cn" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1733028AbfKGDmh (ORCPT ); Wed, 6 Nov 2019 22:42:37 -0500 Received: from MK-FE.hygon.cn ([172.23.18.61]) by spam1.hygon.cn with ESMTP id xA73ckpw000963; Thu, 7 Nov 2019 11:38:46 +0800 (GMT-8) (envelope-from linjiasen@hygon.cn) Received: from cncheex01.Hygon.cn ([172.23.18.10]) by MK-FE.hygon.cn with ESMTP id xA73cf1v094565; Thu, 7 Nov 2019 11:38:41 +0800 (GMT-8) (envelope-from linjiasen@hygon.cn) Received: from ubuntu.localdomain (172.23.18.44) by cncheex01.Hygon.cn (172.23.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Thu, 7 Nov 2019 11:38:42 +0800 From: Jiasen Lin To: , , CC: , , Subject: [PATCH] NTB: ntb_perf: Fix address err in perf_copy_chunk Date: Wed, 6 Nov 2019 19:38:33 -0800 Message-ID: <1573097913-104555-1-git-send-email-linjiasen@hygon.cn> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.23.18.44] X-ClientProxiedBy: cncheex01.Hygon.cn (172.23.18.10) To cncheex01.Hygon.cn (172.23.18.10) X-MAIL: spam1.hygon.cn xA73ckpw000963 X-DNSRBL: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. 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, -- 2.7.4