Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp779549ybb; Fri, 3 Apr 2020 11:39:05 -0700 (PDT) X-Google-Smtp-Source: APiQypL/YXLngxF1dSwx6h4tQwGdzqqFTdCJUXFajcaKgB1EQpfy4V1+okBtTuRrom9s6a6Pz7rR X-Received: by 2002:a9d:943:: with SMTP id 61mr7727979otp.3.1585939145516; Fri, 03 Apr 2020 11:39:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585939145; cv=none; d=google.com; s=arc-20160816; b=0BrQKvLzIMXUVyhNiJvFuFqCbJ9jL8kge4kerQfK+JXMAUiuGMwGYA6dEOtJuKFndt lrNwYzRxEpAQ8qpiVgYzuOjooU+GkWye+t/LjXojC93CdkBRdgqCuf/kzqgrxZVRRIeO oFfocG2hErYeYxYVGjaFos0/0V5+EunvDloOCMZSfNmgcpUI41ICs9MZRfnF6xPXcECk CuhV7DwnP0/CkoX0nsxsvt2ofXPjJZ1o6UxmyvDo9/J5goMb/5WrbNKAOTZ4pD95jzyk bl8aTEjYm65fzImgUlo3Mjie6vuMoRxRz/w04cEewu6anKiim+t+UV/mnhRUYwZxiZ97 HH6g== 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=703kHekMyfhHOsxOcN3dJxPcC+eAQmw3CvoX0LYUT44=; b=ViZq+4CgUYoyd4MmyVq1O0qkRgtihPBHmDVQ0v1VxuYwITjdOmBlVNVCwsAQzwAXNT mrhGW3psYUyvxNI7/O4HILQQ0jmGw8nd+a7Yx9ZSbsyCO6WdDisEg2VWFkep+8cJFeku BGIODdX596Wuu8e68qObQqM9UGzWElssfye/BKRe9CLKwbVOPWGFfAajy+dilF8yzAFF 1qAyQU1bWKc+FdRWSWK2Zci/ALXhSUcwKCnpu/X/fPodIGxv9YTPenzS9ECbghU15XtF eXFHnNLK26QIkPqOGhMLqdUVJ01w2zj9pPtXVPum2cInMRyonqdMmSNEcNvzPxBqRxNZ ObFA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m125si3976737oia.240.2020.04.03.11.38.51; Fri, 03 Apr 2020 11:39:05 -0700 (PDT) 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404337AbgDCSg2 (ORCPT + 99 others); Fri, 3 Apr 2020 14:36:28 -0400 Received: from mga17.intel.com ([192.55.52.151]:4674 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404293AbgDCSg2 (ORCPT ); Fri, 3 Apr 2020 14:36:28 -0400 IronPort-SDR: hUVfV5EBrgUxsSk2rIw7FHPs1ILgDqauALL73KvcH+fvLIuxC7vuB3RcPX7f152z6ssAGS5L8u dLEKmCR9yG5A== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 11:36:27 -0700 IronPort-SDR: P+PjU57kf5ZV4+2nDd+GmNLO3ZXL3lNEuDnNL15enVKjxlAHmsrxvCKbUOTEcJgMcNzHVO71VF 7hF1j078GY2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,340,1580803200"; d="scan'208";a="268439814" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga002.jf.intel.com with ESMTP; 03 Apr 2020 11:36:27 -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 v11 03/10] iommu/vt-d: Use a helper function to skip agaw for SL Date: Fri, 3 Apr 2020 11:42:07 -0700 Message-Id: <1585939334-21396-4-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1585939334-21396-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1585939334-21396-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. --- v11 Added Baolu's commit message and squashed 4 & 5 from v10. --- Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu --- drivers/iommu/intel-pasid.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 22b30f10b396..66c364719ad1 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -500,6 +500,26 @@ 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 +542,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