From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C9DCC4332B for ; Fri, 20 Mar 2020 06:31:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1FAF20773 for ; Fri, 20 Mar 2020 06:31:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eDF5ThDw"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=tcd-ie.20150623.gappssmtp.com header.i=@tcd-ie.20150623.gappssmtp.com header.b="ALp9alTQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1FAF20773 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=tcd.ie Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8nYPUVN56zDKAECaUszC6A8kNI7U4TdOj+WuHExqDWQ=; b=eDF5ThDwfwchQo e+mnfIKkTJbndGBszkwcmD9m7ZPBzXdamicG9w/l3Ceuj5OZhmJHc7Ay2DNk8Sm1vxYY2I4gd3Fdz plC5Gxca0/SkX6yD4sBBS7cc/ZWGuyMzWYWaibIU3XULX17cp9qSCSkMmRTLQTU94ZrM/Gl6IIcsi uJY/igZD9aHuXl1dquLlEBSFbDnBA0/yozWnKkXseOTIuOXJbLe4o/Ifpu1hrtzEQ2gyZfx3IfkGm ynx5tVZ1h3MJ2ly3iX4K5WyuHzx9zcDu5bayEY5GDYv9vcjgJySz9/Qr4ipqrUSN6LTJ/9E7C+xns MnjLH+wEx+bAt1NnRUkA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jFBBS-0006yC-US; Fri, 20 Mar 2020 06:31:06 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jFBBP-0006wx-JM for linux-mediatek@lists.infradead.org; Fri, 20 Mar 2020 06:31:05 +0000 Received: by mail-io1-xd41.google.com with SMTP id e20so4469878ios.12 for ; Thu, 19 Mar 2020 23:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1/VIn1wtF4hsQJkFxlnmnWv82JMKOrPFn/SqXh1kTXo=; b=ALp9alTQuLJLrtYNnyRjvA8PMiz1K4ZRf5nzLyAi+v2/I3lM5M5naHCyPFAdUU7NU9 wx8SODJR6FU9l1lCyIMN3qqLsbRNFpv0ypNDVGw6BO/60a5FCcILJuKIcbnqlN/29fnY A4sy1/pR6UT8YJDvQK2RN9cauHsQ63ohAuCF3DyO7KtZ0AxycSd7Un2OryglDuoIIt3J YLdR7e5RgpvbG4fcchtVZYh60gsXK5GYIrsKc232S+xWkPGrmZZ90ZhY2oUjJX7P8a3U Qu4cOmU0u7PmBgUf3ublP3r8gsr/zoNScg4QxMSmvJ/EEGXtQ3shCFRNsg4sf6wGEuEt 3H4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1/VIn1wtF4hsQJkFxlnmnWv82JMKOrPFn/SqXh1kTXo=; b=lDPugqeMFE947X1hqbYPUqZTsvjjC506LfibsARCIBtPbGgLK3XoGbrpiUfppmiEIl AL+YfR3xeC5PwibFwWxmq/79lXwIw9bCO7SxHkFgY7NBD3c8WZ+NlOkbdl5evjSjZ8az M9HlnLTShGRYG/iqxn6e4UWUH9LQKETqfl90F8NycY+dulyBDPbOALWsExdTJII+QrLP KmUb3+WS9BnGbC43eQwHhVBxyFj1rWjd15H1vO5Ch4tgou7qEn+9ZOsVpP1iD8Ytsmde DJJ5g9h7ue3gJ//kSP9wU88HdCUvBGgPrmAUgmQ9f7nGRwZ40rrbY52KICdBvKSGPoR8 VCaQ== X-Gm-Message-State: ANhLgQ0OsU2bPrAN1nLMklxkmWlkxp2pJEHeYwATvzT7w7g8r8XKgFiN zFr99IHm+NXi9DzmUbsMctP4L/V6VKnTXzhcU/U13w== X-Google-Smtp-Source: ADFU+vv0RVPDe7OSqYC09UstbxEpj6UJl/ooVVvm+TTFONFef168+lVao+hBMRX+yBG3YxegODoM+L1qUGjcesJyDlI= X-Received: by 2002:a5d:8405:: with SMTP id i5mr5964251ion.197.1584685862390; Thu, 19 Mar 2020 23:31:02 -0700 (PDT) MIME-Version: 1.0 References: <20191221150402.13868-1-murphyt7@tcd.ie> <20191221150402.13868-4-murphyt7@tcd.ie> In-Reply-To: <20191221150402.13868-4-murphyt7@tcd.ie> From: Tom Murphy Date: Thu, 19 Mar 2020 23:30:51 -0700 Message-ID: Subject: Re: [PATCH 3/8] iommu/vt-d: Remove IOVA handling code from non-dma_ops path To: iommu@lists.linux-foundation.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200319_233103_648356_F6FBF54E X-CRM114-Status: GOOD ( 24.11 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , kvm@vger.kernel.org, David Airlie , Joonas Lahtinen , dri-devel@lists.freedesktop.org, Bjorn Andersson , linux-tegra@vger.kernel.org, Julien Grall , Thierry Reding , Will Deacon , Marek Szyprowski , Jean-Philippe Brucker , linux-samsung-soc@vger.kernel.org, Marc Zyngier , Joerg Roedel , Krzysztof Kozlowski , Jonathan Hunter , linux-rockchip@lists.infradead.org, Andy Gross , linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org, Jani Nikula , Eric Auger , Alex Williamson , linux-mediatek@lists.infradead.org, Rodrigo Vivi , Matthias Brugger , Thomas Gleixner , virtualization@lists.linux-foundation.org, Gerald Schaefer , David Woodhouse , Cornelia Huck , Linux Kernel Mailing List , Rob Clark , Kukjin Kim , Daniel Vetter , Robin Murphy , Lu Baolu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Could we merge patch 1-3 from this series? it just cleans up weird code and merging these patches will cover some of the work needed to move the intel iommu driver to the dma-iommu api in the future. On Sat, 21 Dec 2019 at 07:04, Tom Murphy wrote: > > Remove all IOVA handling code from the non-dma_ops path in the intel > iommu driver. > > There's no need for the non-dma_ops path to keep track of IOVAs. The > whole point of the non-dma_ops path is that it allows the IOVAs to be > handled separately. The IOVA handling code removed in this patch is > pointless. > > Signed-off-by: Tom Murphy > --- > drivers/iommu/intel-iommu.c | 89 ++++++++++++++----------------------- > 1 file changed, 33 insertions(+), 56 deletions(-) > > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 64b1a9793daa..8d72ea0fb843 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -1908,7 +1908,8 @@ static void domain_exit(struct dmar_domain *domain) > domain_remove_dev_info(domain); > > /* destroy iovas */ > - put_iova_domain(&domain->iovad); > + if (domain->domain.type == IOMMU_DOMAIN_DMA) > + put_iova_domain(&domain->iovad); > > if (domain->pgd) { > struct page *freelist; > @@ -2671,19 +2672,9 @@ static struct dmar_domain *set_domain_for_dev(struct device *dev, > } > > static int iommu_domain_identity_map(struct dmar_domain *domain, > - unsigned long long start, > - unsigned long long end) > + unsigned long first_vpfn, > + unsigned long last_vpfn) > { > - unsigned long first_vpfn = start >> VTD_PAGE_SHIFT; > - unsigned long last_vpfn = end >> VTD_PAGE_SHIFT; > - > - if (!reserve_iova(&domain->iovad, dma_to_mm_pfn(first_vpfn), > - dma_to_mm_pfn(last_vpfn))) { > - pr_err("Reserving iova failed\n"); > - return -ENOMEM; > - } > - > - pr_debug("Mapping reserved region %llx-%llx\n", start, end); > /* > * RMRR range might have overlap with physical memory range, > * clear it first > @@ -2760,7 +2751,8 @@ static int __init si_domain_init(int hw) > > for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) { > ret = iommu_domain_identity_map(si_domain, > - PFN_PHYS(start_pfn), PFN_PHYS(end_pfn)); > + mm_to_dma_pfn(start_pfn), > + mm_to_dma_pfn(end_pfn)); > if (ret) > return ret; > } > @@ -4593,58 +4585,37 @@ static int intel_iommu_memory_notifier(struct notifier_block *nb, > unsigned long val, void *v) > { > struct memory_notify *mhp = v; > - unsigned long long start, end; > - unsigned long start_vpfn, last_vpfn; > + unsigned long start_vpfn = mm_to_dma_pfn(mhp->start_pfn); > + unsigned long last_vpfn = mm_to_dma_pfn(mhp->start_pfn + > + mhp->nr_pages - 1); > > switch (val) { > case MEM_GOING_ONLINE: > - start = mhp->start_pfn << PAGE_SHIFT; > - end = ((mhp->start_pfn + mhp->nr_pages) << PAGE_SHIFT) - 1; > - if (iommu_domain_identity_map(si_domain, start, end)) { > - pr_warn("Failed to build identity map for [%llx-%llx]\n", > - start, end); > + if (iommu_domain_identity_map(si_domain, start_vpfn, > + last_vpfn)) { > + pr_warn("Failed to build identity map for [%lx-%lx]\n", > + start_vpfn, last_vpfn); > return NOTIFY_BAD; > } > break; > > case MEM_OFFLINE: > case MEM_CANCEL_ONLINE: > - start_vpfn = mm_to_dma_pfn(mhp->start_pfn); > - last_vpfn = mm_to_dma_pfn(mhp->start_pfn + mhp->nr_pages - 1); > - while (start_vpfn <= last_vpfn) { > - struct iova *iova; > + { > struct dmar_drhd_unit *drhd; > struct intel_iommu *iommu; > struct page *freelist; > > - iova = find_iova(&si_domain->iovad, start_vpfn); > - if (iova == NULL) { > - pr_debug("Failed get IOVA for PFN %lx\n", > - start_vpfn); > - break; > - } > - > - iova = split_and_remove_iova(&si_domain->iovad, iova, > - start_vpfn, last_vpfn); > - if (iova == NULL) { > - pr_warn("Failed to split IOVA PFN [%lx-%lx]\n", > - start_vpfn, last_vpfn); > - return NOTIFY_BAD; > - } > - > - freelist = domain_unmap(si_domain, iova->pfn_lo, > - iova->pfn_hi); > + freelist = domain_unmap(si_domain, start_vpfn, > + last_vpfn); > > rcu_read_lock(); > for_each_active_iommu(iommu, drhd) > iommu_flush_iotlb_psi(iommu, si_domain, > - iova->pfn_lo, iova_size(iova), > + start_vpfn, mhp->nr_pages, > !freelist, 0); > rcu_read_unlock(); > dma_free_pagelist(freelist); > - > - start_vpfn = iova->pfn_hi + 1; > - free_iova_mem(iova); > } > break; > } > @@ -4672,8 +4643,9 @@ static void free_all_cpu_cached_iovas(unsigned int cpu) > for (did = 0; did < cap_ndoms(iommu->cap); did++) { > domain = get_iommu_domain(iommu, (u16)did); > > - if (!domain) > + if (!domain || domain->domain.type != IOMMU_DOMAIN_DMA) > continue; > + > free_cpu_cached_iovas(cpu, &domain->iovad); > } > } > @@ -5095,9 +5067,6 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width) > { > int adjust_width; > > - init_iova_domain(&domain->iovad, VTD_PAGE_SIZE, IOVA_START_PFN); > - domain_reserve_special_ranges(domain); > - > /* calculate AGAW */ > domain->gaw = guest_width; > adjust_width = guestwidth_to_adjustwidth(guest_width); > @@ -5116,6 +5085,18 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width) > return 0; > } > > +static void intel_init_iova_domain(struct dmar_domain *dmar_domain) > +{ > + init_iova_domain(&dmar_domain->iovad, VTD_PAGE_SIZE, IOVA_START_PFN); > + copy_reserved_iova(&reserved_iova_list, &dmar_domain->iovad); > + > + if (init_iova_flush_queue(&dmar_domain->iovad, iommu_flush_iova, > + iova_entry_free)) { > + pr_warn("iova flush queue initialization failed\n"); > + intel_iommu_strict = 1; > + } > +} > + > static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) > { > struct dmar_domain *dmar_domain; > @@ -5136,12 +5117,8 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) > return NULL; > } > > - if (type == IOMMU_DOMAIN_DMA && > - init_iova_flush_queue(&dmar_domain->iovad, > - iommu_flush_iova, iova_entry_free)) { > - pr_warn("iova flush queue initialization failed\n"); > - intel_iommu_strict = 1; > - } > + if (type == IOMMU_DOMAIN_DMA) > + intel_init_iova_domain(dmar_domain); > > domain_update_iommu_cap(dmar_domain); > > -- > 2.20.1 > _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek