Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3724450imu; Fri, 18 Jan 2019 16:12:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN6+4b1LqOnfclRme9HO9vUS35pSlVPyuzlerlnezquriaUTuiy7kd4TrpZc9M3PK+6tVPT5 X-Received: by 2002:a62:8985:: with SMTP id n5mr21565135pfk.255.1547856722315; Fri, 18 Jan 2019 16:12:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547856722; cv=none; d=google.com; s=arc-20160816; b=Qrgy4rWY1sCw17uZ2qGu1Knx5Lt6eBZNDrycjcPo0YFMyd+DDdEF1ozdCaczwk6+hH pm4fopFtrwmWyoiE5uZzwblKfxsE7SgtODcYLcnFo4H3pCRqNzgHOGpFKVOavAeUsqGK QocVu43ly4Gx3O+1C6h69VaZF4q27bFOgo3O6nJjekGz/waI92gkHTnkzkewAHkS4kRB FHNIh7pluTUvTeLl+uQm93FFK8xlvvLNtxUckNCsTm8H7lKOEZelMmE5nTg7xDGvfis6 vLeZQFRfSgSToLoP6FSQH7TfypdBkAzzd8uYKkaZuLFNNogyNEC+z25A6HLxb4ycuaha ePYg== 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 :mime-version:message-id:date:cc:to:from; bh=oy05jd/mDficB+bkELYeFQjot/M8h9txJenuNXHZ3uA=; b=acEMkB9PfPp6mph3NSz/5fEpTK9SFcuAnq46Nk/AhrnPFTmyVVwLTQvjB0Swt+0Lbi 3GBoqEqzCdZVa/qYWy17paNKl9OcvdFGBc2fQNli5o4Cue99nrw3rzjPJLuORivZyWtp DRE9QgZeadc8XC8C0AMy8YUEe7DUQ/sX2hZqUJskX4NbzZXt3QD2D2CoQTwqdPpkyLPO XyxeNtkqhZINGQXCCMyQbUP2xmXeLQr9gmGrQngNQaum/V/75ibbrjsf7qB0V9h0TPEv YQgdgmDKBXnS+LGoLztEo7jL2mEN/iYBrdVwzWhtGTDNUp+5W/EonJk21cWEwT+ww1zG 60UA== 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 o14si2624088pgj.59.2019.01.18.16.11.43; Fri, 18 Jan 2019 16:12:02 -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 S1730168AbfASAKK (ORCPT + 99 others); Fri, 18 Jan 2019 19:10:10 -0500 Received: from ale.deltatee.com ([207.54.116.67]:53618 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730125AbfASAKK (ORCPT ); Fri, 18 Jan 2019 19:10:10 -0500 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gkeDA-0002BS-RN; Fri, 18 Jan 2019 17:10:09 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1gkeD9-0003Po-4G; Fri, 18 Jan 2019 17:10:07 -0700 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com Cc: Logan Gunthorpe , Jon Mason , Dave Jiang , Allen Hubbe Date: Fri, 18 Jan 2019 17:10:01 -0700 Message-Id: <20190119001001.13087-1-logang@deltatee.com> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com, logang@deltatee.com, jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com X-SA-Exim-Mail-From: gunthorp@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.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH] NTB: ntb_transport: Ensure the destination buffer is mapped for TX DMA 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 Presently, when ntb_transport is used with DMA and the IOMMU turned on, it fails with errors from the IOMMU such as: DMAR: DRHD: handling fault status reg 202 DMAR: [DMA Write] Request device [00:04.0] fault addr 381fc0340000 [fault reason 05] PTE Write access is not set This is because ntb_transport does not map the BAR space with the IOMMU. To fix this, we map the entire MW region for each QP after we assign the DMA channel. This prevents needing an extra DMA map in the fast path. Link: https://lore.kernel.org/linux-pci/499934e7-3734-1aee-37dd-b42a5d2a2608@intel.com/ Signed-off-by: Logan Gunthorpe Cc: Jon Mason Cc: Dave Jiang Cc: Allen Hubbe --- drivers/ntb/ntb_transport.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c index 3bfdb4562408..526b65afc16a 100644 --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c @@ -144,7 +144,9 @@ struct ntb_transport_qp { struct list_head tx_free_q; spinlock_t ntb_tx_free_q_lock; void __iomem *tx_mw; - dma_addr_t tx_mw_phys; + phys_addr_t tx_mw_phys; + size_t tx_mw_size; + dma_addr_t tx_mw_dma_addr; unsigned int tx_index; unsigned int tx_max_entry; unsigned int tx_max_frame; @@ -1049,6 +1051,7 @@ static int ntb_transport_init_queue(struct ntb_transport_ctx *nt, tx_size = (unsigned int)mw_size / num_qps_mw; qp_offset = tx_size * (qp_num / mw_count); + qp->tx_mw_size = tx_size; qp->tx_mw = nt->mw_vec[mw_num].vbase + qp_offset; if (!qp->tx_mw) return -EINVAL; @@ -1644,7 +1647,7 @@ static int ntb_async_tx_submit(struct ntb_transport_qp *qp, dma_cookie_t cookie; device = chan->device; - dest = qp->tx_mw_phys + qp->tx_max_frame * entry->tx_index; + dest = qp->tx_mw_dma_addr + qp->tx_max_frame * entry->tx_index; buff_off = (size_t)buf & ~PAGE_MASK; dest_off = (size_t)dest & ~PAGE_MASK; @@ -1863,6 +1866,18 @@ ntb_transport_create_queue(void *data, struct device *client_dev, qp->rx_dma_chan = NULL; } + if (qp->tx_dma_chan) { + qp->tx_mw_dma_addr = + dma_map_resource(qp->tx_dma_chan->device->dev, + qp->tx_mw_phys, qp->tx_mw_size, + DMA_FROM_DEVICE, 0); + if (dma_mapping_error(qp->tx_dma_chan->device->dev, + qp->tx_mw_dma_addr)) { + qp->tx_mw_dma_addr = 0; + goto err1; + } + } + dev_dbg(&pdev->dev, "Using %s memcpy for TX\n", qp->tx_dma_chan ? "DMA" : "CPU"); @@ -1904,6 +1919,10 @@ ntb_transport_create_queue(void *data, struct device *client_dev, qp->rx_alloc_entry = 0; while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q))) kfree(entry); + if (qp->tx_mw_dma_addr) + dma_unmap_resource(qp->tx_dma_chan->device->dev, + qp->tx_mw_dma_addr, qp->tx_mw_size, + DMA_FROM_DEVICE, 0); if (qp->tx_dma_chan) dma_release_channel(qp->tx_dma_chan); if (qp->rx_dma_chan) @@ -1945,6 +1964,11 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp) */ dma_sync_wait(chan, qp->last_cookie); dmaengine_terminate_all(chan); + + dma_unmap_resource(chan->device->dev, + qp->tx_mw_dma_addr, qp->tx_mw_size, + DMA_FROM_DEVICE, 0); + dma_release_channel(chan); } -- 2.19.0