From patchwork Tue Oct 10 14:50:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9996453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 75767601AE for ; Tue, 10 Oct 2017 14:56:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66A272863B for ; Tue, 10 Oct 2017 14:56:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BB5F2863F; Tue, 10 Oct 2017 14:56:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C30A32863B for ; Tue, 10 Oct 2017 14:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932316AbdJJO4d (ORCPT ); Tue, 10 Oct 2017 10:56:33 -0400 Received: from mga01.intel.com ([192.55.52.88]:10931 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932087AbdJJO4c (ORCPT ); Tue, 10 Oct 2017 10:56:32 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2017 07:56:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,505,1500966000"; d="scan'208";a="908549891" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by FMSMGA003.fm.intel.com with ESMTP; 10 Oct 2017 07:56:30 -0700 Subject: [PATCH v8 12/14] iommu/vt-d: use iommu_num_sg_pages From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Ashok Raj , linux-rdma@vger.kernel.org, linux-api@vger.kernel.org, Joerg Roedel , linux-xfs@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, David Woodhouse Date: Tue, 10 Oct 2017 07:50:05 -0700 Message-ID: <150764700544.16882.8780240398561523090.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <150764693502.16882.15848797003793552156.stgit@dwillia2-desk3.amr.corp.intel.com> References: <150764693502.16882.15848797003793552156.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the common helper for accounting the size of the IOVA range for a scatterlist so that iommu and dma apis agree on the size of a scatterlist. This is in support for using iommu_unmap() in advance of dma_unmap_sg() to invalidate an io-mapping in advance of the IOVA range being deallocated. MAP_DIRECT needs this functionality for force revoking RDMA access to a DAX mapping when userspace fails to respond to within a lease break timeout period. Cc: Ashok Raj Cc: David Woodhouse Cc: Joerg Roedel Signed-off-by: Dan Williams --- drivers/iommu/intel-iommu.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index f3f4939cebad..94a5fbe62fb8 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -3785,14 +3785,9 @@ static void intel_unmap_sg(struct device *dev, struct scatterlist *sglist, unsigned long attrs) { dma_addr_t startaddr = sg_dma_address(sglist) & PAGE_MASK; - unsigned long nrpages = 0; - struct scatterlist *sg; - int i; - - for_each_sg(sglist, sg, nelems, i) { - nrpages += aligned_nrpages(sg_dma_address(sg), sg_dma_len(sg)); - } + unsigned long nrpages; + nrpages = iommu_sg_num_pages(dev, sglist, nelems); intel_unmap(dev, startaddr, nrpages << VTD_PAGE_SHIFT); } @@ -3813,14 +3808,12 @@ static int intel_nontranslate_map_sg(struct device *hddev, static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, unsigned long attrs) { - int i; struct dmar_domain *domain; size_t size = 0; int prot = 0; unsigned long iova_pfn; int ret; - struct scatterlist *sg; - unsigned long start_vpfn; + unsigned long start_vpfn, npages; struct intel_iommu *iommu; BUG_ON(dir == DMA_NONE); @@ -3833,11 +3826,9 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele iommu = domain_get_iommu(domain); - for_each_sg(sglist, sg, nelems, i) - size += aligned_nrpages(sg->offset, sg->length); + npages = iommu_sg_num_pages(dev, sglist, nelems); - iova_pfn = intel_alloc_iova(dev, domain, dma_to_mm_pfn(size), - *dev->dma_mask); + iova_pfn = intel_alloc_iova(dev, domain, npages, *dev->dma_mask); if (!iova_pfn) { sglist->dma_length = 0; return 0;