Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2145438ybb; Sat, 4 Apr 2020 23:38:24 -0700 (PDT) X-Google-Smtp-Source: APiQypLOUXEPR0xPK/n8usWeALTIhZDwM4r1MJlv/yuKIU+BZbCn0/UZmT33TtkZSn+y+ln/VCIO X-Received: by 2002:aca:100e:: with SMTP id 14mr8866341oiq.79.1586068704636; Sat, 04 Apr 2020 23:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586068704; cv=none; d=google.com; s=arc-20160816; b=srV7l+22W1BaF5vMCL0l7Y8n0oQF56eDgScf5kfZoBZ8GSxpF5m1tYdGOez93OWlDR JSvdZ9WCJqBjeDB0nd0600xw63eNVkW1k5ser8c4XJyXdXBLdlgw5PBgauhsPqzHbRE2 UahTnBeieiF0tQaDBIna2cVDrY59/847eNQE+X6Z7DR7CnlK5eYi5HagP2mLZwI6p8Fm DBCSMLbNvdGik86xvIuovPYC58T1K9X19EhOs9CAuYUWdaNSDL5cOM201p8KKTzlcPxG ZAA0rulDoG3AgVaWpS6gdPSB7RPkhFgLqPa9sTXrHr1LokS4//Es+zpbmvE96gGSddRm JxdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=oLJp8gNoJW3dJ3wHholYHDaHHlYLtE5HahLyoRw+fos=; b=wPmVFBXo4mWiTZdIClPtR5RX1IgSG1p/IhNxh85E8JI6EXJtpGYDO1kzsKB9c4Mk5b gH4qMiu4oioRDq+uSffOTVAlpsNOMuLv2zYaVZqUVsuamWOQeMaEGqJqO+XeCJ+fqSr2 92nKLQFLdhMgTs6wbaEIw04eTcSIlkYgn4YXqYyu7Al8gvxkgeYy0Q3IDJZdK0fH5+g4 BJ4mCtzBlxMIzcb+f/kVqAaOd40b9o7D8gcWsuQl/N6pccQTAXLf3J8rNiZV9CizB/pb 6RPvflQ5AI50SlG1QeJkHgth9SJsZVY7UBEUrrL54DyYCUpA8j9ry6oW/Mcko/VcLHlw ligw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H160auRY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si5852636ooq.78.2020.04.04.23.38.02; Sat, 04 Apr 2020 23:38:24 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H160auRY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726396AbgDEGhi (ORCPT + 99 others); Sun, 5 Apr 2020 02:37:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45600 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726250AbgDEGhh (ORCPT ); Sun, 5 Apr 2020 02:37:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586068656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oLJp8gNoJW3dJ3wHholYHDaHHlYLtE5HahLyoRw+fos=; b=H160auRYGqfbU9VGWBbc+TXovOeo4a4OBNE9lD2qV2/hDUvTA/apIWJBE+mDEvzmwD/Pp8 Or9ddiDblf/gy0CxEfjOvELLNSB0l9y4IrAQdPnMnX+srJEZdHhwTdlyg/Tw0NAPbPbnoL 0K/3CeYjT0uGlzf1v7FZsBqQwPhwJQ8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-qk1hOz4oNuOokJeo_SK-nw-1; Sun, 05 Apr 2020 02:37:34 -0400 X-MC-Unique: qk1hOz4oNuOokJeo_SK-nw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 32E22800D50; Sun, 5 Apr 2020 06:37:32 +0000 (UTC) Received: from [10.36.112.58] (ovpn-112-58.ams2.redhat.com [10.36.112.58]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8BA5A5DA66; Sun, 5 Apr 2020 06:37:26 +0000 (UTC) Subject: Re: [PATCH v11 03/10] iommu/vt-d: Use a helper function to skip agaw for SL To: Jacob Pan , Lu Baolu , iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Jean-Philippe Brucker Cc: Yi Liu , "Tian, Kevin" , Raj Ashok , Alex Williamson , Christoph Hellwig , Jonathan Cameron References: <1585939334-21396-1-git-send-email-jacob.jun.pan@linux.intel.com> <1585939334-21396-4-git-send-email-jacob.jun.pan@linux.intel.com> From: Auger Eric Message-ID: <54625f36-909e-405d-fe8d-e80f4314646a@redhat.com> Date: Sun, 5 Apr 2020 08:37:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1585939334-21396-4-git-send-email-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacob, On 4/3/20 8:42 PM, Jacob Pan wrote: > 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 Reviewed-by: Eric Auger Eric > --- > 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); >