Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1243254ybb; Fri, 20 Mar 2020 16:23:35 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvuH0nchY+20UuOcV9HouG38DIOE460f6K4IICnvux+q+i35dWryeHUlL8HF1FRZqnARiR1 X-Received: by 2002:aca:3dd7:: with SMTP id k206mr8824569oia.63.1584746615660; Fri, 20 Mar 2020 16:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584746615; cv=none; d=google.com; s=arc-20160816; b=KxbPki8Ap5RDjr9/j7pkhPOfEznlOeLrVMNHyXpC3siHzuJRad6x49o22el8AXGjLW M43yVAvEpyNpsAgOegXc6amhcLLNsJaRJQIltSX18or+CQbM2W2kRN48K2sogm+vFzs3 Evj6gzACAJO9top+GxxKCUPNSX9VFzFKn9FpQcPXDr4BydOhEStVQLypa/zxfkfHRHQ2 IEFXyFyGQ1HmlbdeUfa91K/S8meiu/V7jXbmGgkCD5LFgaPhfOY1WRNLuWhF4155WJrF VVWStdXYb6TYjJl51x0RVg5JL0kaUpzv4DeZi9qYDBhumpu4YvI4O+c0Ye2zhp9ed1Fk zQvA== 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=5MP5M3iB/cIaN8r1dYcN6uY9jsfozgmiqMgYzsn5OII=; b=A+AQrqPxdVYwpYhcjkJ7VizVBWBBcopoa/2iXM9G3u8vSshdeJWuOO1sPbsfkvo82H LmqyS1bXPYT0lVzCN6ekIBK101Jkb72MLXGPYCZqYVnOJQg6JbzCO8V0W/wVw6wLggKv M3V5KQwE8CRNjJrS/4q6dlzRRV/sdf9aq5hRJKd6NuBzT5HgACW4JkuaiABZU6HpQj+O Ac8/eDCJrI4i7l8RjGX6LCM7e1WklHjaVm1Ko0le952BD6lKLFzxBHjoCSQlRh0iT+1H kNJQV4cjrDJXpgxHGiEe9cqsVusWDxlw8uV5CmX8gM2+cmSLdPBQhySPOywu3wW6tmhP MPTg== 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 g8si3728420otg.126.2020.03.20.16.23.23; Fri, 20 Mar 2020 16:23:35 -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 S1727534AbgCTXWD (ORCPT + 99 others); Fri, 20 Mar 2020 19:22:03 -0400 Received: from mga18.intel.com ([134.134.136.126]:42258 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgCTXWC (ORCPT ); Fri, 20 Mar 2020 19:22:02 -0400 IronPort-SDR: kRcmsuzTTFKgTZBd1F1rAFYMVLcuitZAlSYuB0LzdazUJHjtMBlT4lkapr6EaDJqUHhbn5e9Di SSgWdeSVB+rQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2020 16:22:01 -0700 IronPort-SDR: zm8+sqo2Y4c3rylIhy759Oscrl2radw/23Wj1LvZqvMxCGDwCLVpDbxwITPW4onYclC77fAA2Y sAvTh6XGuy3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,286,1580803200"; d="scan'208";a="418877227" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga005.jf.intel.com with ESMTP; 20 Mar 2020 16:22:01 -0700 From: Jacob Pan To: "Lu Baolu" , iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Alex Williamson , Jean-Philippe Brucker Cc: "Yi Liu" , "Tian, Kevin" , Raj Ashok , "Christoph Hellwig" , Jonathan Cameron , Eric Auger , Jacob Pan Subject: [PATCH V10 03/11] iommu/vt-d: Add a helper function to skip agaw Date: Fri, 20 Mar 2020 16:27:33 -0700 Message-Id: <1584746861-76386-4-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584746861-76386-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1584746861-76386-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 Signed-off-by: Jacob Pan --- drivers/iommu/intel-pasid.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 22b30f10b396..191508c7c03e 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -500,6 +500,28 @@ 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; + } + } + pr_debug_ratelimited("%s: pgd: %llx, agaw %d d_agaw %d\n", __func__, (u64)*pgd, + iommu->agaw, domain->agaw); + + return agaw; +} + +/* * Set up the scalable mode pasid entry for second only translation type. */ int intel_pasid_setup_second_level(struct intel_iommu *iommu, -- 2.7.4