Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1010342pxf; Wed, 7 Apr 2021 17:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJwmSkyVHzoS2/2u7goINe55xMkSSDtYMu8QKvyFTbe2zha8w78R5lq1JhMS9dnbiQXX7Z X-Received: by 2002:a17:90b:1e0f:: with SMTP id pg15mr5834720pjb.51.1617842153443; Wed, 07 Apr 2021 17:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617842153; cv=none; d=google.com; s=arc-20160816; b=RgfxfsPp4+VqIciu5YskhlJ+JPeQluIWcFmubi3K2fb/YLvJl2Y/rix/MgvU4EPzOE eqlC1JTqB4duFD8LERJd9ksmbAjFJ+/DKAzS1UAOV9fdGt/VZ7roeCuFYKWmlRDIMcQk 8ZX7CzRblaUL9R75n9dI4M32KHMdBPkAq5WUzpycKuEfxsfTL19FK253LUBbKnvBbo8o krdJHMKMMJM/CYEDGHJ8VkJ6f/hwmv9H6Um3V8DmGTI+XGemGAMS+OFycTVtjvbmW0oa 7Y/Gyap6q5ZiWj2bcJaRN6oNiwaZtLOPzmz+tKdwiL7ZlZHpecbY9v9Ag+hcHrjmXA3B lsaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:cc:ironport-sdr:ironport-sdr; bh=zX/O+XoIqLV0I5wGghYaOqmrN1z9gVcNZ/Wwnr5WjTc=; b=0VjrYOrpVWL9ZPsb7TArqfZSof5bqw3ve32gQw+ulD1XYVOKEh0qEf+i609s9V4WWq D7tU5zN1883fRApYvPBUrBcohk6a1KuXwQQF3AnB4ZGMTqna7DN2yycks+FVLij/Hg2U ZkEGzVMZ1O2KiYUcGVfdyZHDgAf/y+d+Iho7dhXcl4v04ICGmG4gRcRfZbSsCbmTKrVL BUfSFcpDHd457J0p6ruTuVFA/i6ZSfWyZHfdHz+jeC19SYMWdmwhtRX1pQ7PCcy40IEP +FDdy7bqPsx0fHypScCZofySo7aUmesUPInfzdHr479/peSw/JqdQhqBmVBJTByUkIkR jBvQ== 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 o24si24483531pgl.48.2021.04.07.17.35.39; Wed, 07 Apr 2021 17:35:53 -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 S229510AbhDHAfB (ORCPT + 99 others); Wed, 7 Apr 2021 20:35:01 -0400 Received: from mga01.intel.com ([192.55.52.88]:44590 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbhDHAfA (ORCPT ); Wed, 7 Apr 2021 20:35:00 -0400 IronPort-SDR: PDz4yJSpWmcduwWP4KsNY1zyS7DaxN3P9NXT/7cw28sleJYsjKjMzhmdDWQij6ihKtlVMmrYQE pV8Y4CCeU6iw== X-IronPort-AV: E=McAfee;i="6000,8403,9947"; a="213826014" X-IronPort-AV: E=Sophos;i="5.82,204,1613462400"; d="scan'208";a="213826014" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2021 17:34:50 -0700 IronPort-SDR: sLPkzggneG9Bd7YbF1P15EUwYK8JjveJoenwDPDjHo0k+cVdUC8jDg+GRQN7hlP2C8YZReP7l5 8Ka1G4LW8fSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,204,1613462400"; d="scan'208";a="441526391" Received: from allen-box.sh.intel.com (HELO [10.239.159.128]) ([10.239.159.128]) by fmsmga004.fm.intel.com with ESMTP; 07 Apr 2021 17:34:48 -0700 Cc: baolu.lu@linux.intel.com, Camille Lu , David Woodhouse , Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width To: Saeed Mirzamohammadi References: <20210407184030.21683-1-saeed.mirzamohammadi@oracle.com> From: Lu Baolu Message-ID: Date: Thu, 8 Apr 2021 08:25:19 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210407184030.21683-1-saeed.mirzamohammadi@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/8/21 2:40 AM, Saeed Mirzamohammadi wrote: > The IOMMU driver calculates the guest addressability for a DMA request > based on the value of the mgaw reported from the IOMMU. However, this > is a fused value and as mentioned in the spec, the guest width > should be calculated based on the minimum of supported adjusted guest > address width (SAGAW) and MGAW. > > This is from specification: > "Guest addressability for a given DMA request is limited to the > minimum of the value reported through this field and the adjusted > guest address width of the corresponding page-table structure. > (Adjusted guest address widths supported by hardware are reported > through the SAGAW field)." > > This causes domain initialization to fail and following > errors appear for EHCI PCI driver: > > [ 2.486393] ehci-pci 0000:01:00.4: EHCI Host Controller > [ 2.486624] ehci-pci 0000:01:00.4: new USB bus registered, assigned bus > number 1 > [ 2.489127] ehci-pci 0000:01:00.4: DMAR: Allocating domain failed > [ 2.489350] ehci-pci 0000:01:00.4: DMAR: 32bit DMA uses non-identity > mapping > [ 2.489359] ehci-pci 0000:01:00.4: can't setup: -12 > [ 2.489531] ehci-pci 0000:01:00.4: USB bus 1 deregistered > [ 2.490023] ehci-pci 0000:01:00.4: init 0000:01:00.4 fail, -12 > [ 2.490358] ehci-pci: probe of 0000:01:00.4 failed with error -12 > > This issue happens when the value of the sagaw corresponds to a > 48-bit agaw. This fix updates the calculation of the agaw based on > the minimum of IOMMU's sagaw value and MGAW. > > Signed-off-by: Saeed Mirzamohammadi > Tested-by: Camille Lu > --- > > Change in v2: > - Added cap_width to calculate AGAW based on the minimum value of MGAW and AGAW. > --- > drivers/iommu/intel-iommu.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 953d86ca6d2b..a2a03df97704 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -1853,7 +1853,7 @@ static inline int guestwidth_to_adjustwidth(int gaw) > static int domain_init(struct dmar_domain *domain, struct intel_iommu *iommu, > int guest_width) > { > - int adjust_width, agaw; > + int adjust_width, agaw, cap_width; > unsigned long sagaw; > int err; > > @@ -1867,8 +1867,9 @@ static int domain_init(struct dmar_domain *domain, struct intel_iommu *iommu, > domain_reserve_special_ranges(domain); > > /* calculate AGAW */ > - if (guest_width > cap_mgaw(iommu->cap)) > - guest_width = cap_mgaw(iommu->cap); > + cap_width = min_t(int, cap_mgaw(iommu->cap), agaw_to_width(iommu->agaw)); > + if (guest_width > cap_width) > + guest_width = cap_width; > domain->gaw = guest_width; > adjust_width = guestwidth_to_adjustwidth(guest_width); > agaw = width_to_agaw(adjust_width); > Reviewed-by: Lu Baolu Best regards, baolu