Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp431340ybz; Tue, 21 Apr 2020 11:50:30 -0700 (PDT) X-Google-Smtp-Source: APiQypLVaTttJEKC7fXLGnF8JZlkQ7ivoyLcIp7OYNFEsaCaTRZJKzKrqAAdZBTghY7nd2Aqv373 X-Received: by 2002:a17:906:cf8a:: with SMTP id um10mr22058601ejb.60.1587495030029; Tue, 21 Apr 2020 11:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587495030; cv=none; d=google.com; s=arc-20160816; b=IEeP0egjkk0h/CsHQhhDvNQH2HiCcAjoL+osjZUEQQleXOWGdENkCfnqjN/67MHv5G qeHcItVunNPmp/jnqn4Cp38YK8tLnJNoV+v7qfElDIkI8/Bvoa92wK7dkaKsiB99GwDu GLuNhN7AzwDPneecFDD103NqCdpdryCFTmimZY73HpFGSi++eevCrGSrLbOIDNVM/ojH 0hAXcUlZ4NZXHZtRyGYd8j6ZmEhFVnoFSMnJed6sJwHccFJrPCulhduwAgJSjG8kqGPX CYzluk0iQLXbEXjVDhvOXZXLXbkzQB5N4LITJwDal8sk23dpNYm8RtLfstGU6PFkeJZE gFmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=P0PliG8JHDt/C4pWVorZTI4b6dXwH21OZrjHutzucJU=; b=G4SXHuseo8gQdRrmNX5PyzB9+SU7851ejbsQwkzbdQSeNoWK/J9wPHoATktBMrOM+l ZO+/wPKxDaz6Gc33Fa06XJtLfvgpgVTc5wr3yNMEIgsem6w5GRgy57/Z4zQbr1VQyuJK b29zwYwj8DKdaivh89YfGUT8F0lM/IsFNmHWvyp5ND5QRWOFnqPVTIrLm/CzsTcPegIn VE1AEDll+2vnDWsru36ufX3Zkyo4Q+gIKpRHFZhBYcZlVg4hDUdYuE3LMa4oxrG4DpkL g7JxHQyqtsmZ7AEwU+fZMyJlJNN262snFa6mOyGp8+UuVbGYVHUobmMxbCEVHJcktTxI Byxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p4si2183373edd.234.2020.04.21.11.50.06; Tue, 21 Apr 2020 11:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbgDUSrK (ORCPT + 99 others); Tue, 21 Apr 2020 14:47:10 -0400 Received: from mga04.intel.com ([192.55.52.120]:22250 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgDUSrH (ORCPT ); Tue, 21 Apr 2020 14:47:07 -0400 IronPort-SDR: 2iaMTvBcDB6uMgGpvwIPzA4/UNYoM4UUR20jfadortNKTNjtQkG9sVmhSRhswLXdPqy9buDvXY A9x9xkIOU0LQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 11:46:48 -0700 IronPort-SDR: OgETf1UfYuKpsNW4x9/79QHlGOz1Irm6c5lqGm2sWcQAb6JK5WIsnQ8g3OezoehAgiXE+vzLSz 1/b8Vhk49iYw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,411,1580803200"; d="scan'208";a="334367866" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga001.jf.intel.com with ESMTP; 21 Apr 2020 11:46:48 -0700 From: Jacob Pan To: "Lu Baolu" , iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Jean-Philippe Brucker , Eric Auger Cc: "Yi Liu" , "Tian, Kevin" , Raj Ashok , Alex Williamson , "Christoph Hellwig" , Jonathan Cameron , Jacob Pan Subject: [PATCH v12 2/8] iommu/vt-d: Use a helper function to skip agaw for SL Date: Tue, 21 Apr 2020 11:52:39 -0700 Message-Id: <1587495165-80096-3-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1587495165-80096-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1587495165-80096-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An Intel iommu domain uses 5-level page table by default. If the iommu that the domain tries to attach supports less page levels, the top level page tables should be skipped. Add a helper to do this so that it could be used in other places. Signed-off-by: Jacob Pan Reviewed-by: Eric Auger --- drivers/iommu/intel-pasid.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 22b30f10b396..d9cea3011b58 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -500,6 +500,25 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu, } /* + * Skip top levels of page tables for iommu which has less agaw + * than default. Unnecessary for PT mode. + */ +static inline int iommu_skip_agaw(struct dmar_domain *domain, + struct intel_iommu *iommu, + struct dma_pte **pgd) +{ + int agaw; + + for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) { + *pgd = phys_to_virt(dma_pte_addr(*pgd)); + if (!dma_pte_present(*pgd)) + return -EINVAL; + } + + return agaw; +} + +/* * Set up the scalable mode pasid entry for second only translation type. */ int intel_pasid_setup_second_level(struct intel_iommu *iommu, @@ -522,17 +541,11 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, return -EINVAL; } - /* - * Skip top levels of page tables for iommu which has less agaw - * than default. Unnecessary for PT mode. - */ pgd = domain->pgd; - for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) { - pgd = phys_to_virt(dma_pte_addr(pgd)); - if (!dma_pte_present(pgd)) { - dev_err(dev, "Invalid domain page table\n"); - return -EINVAL; - } + agaw = iommu_skip_agaw(domain, iommu, &pgd); + if (agaw < 0) { + dev_err(dev, "Invalid domain page table\n"); + return -EINVAL; } pgd_val = virt_to_phys(pgd); -- 2.7.4