Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp912367pxf; Wed, 7 Apr 2021 14:54:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+akfaZyhxS/RDSRhJa8WJEFvoUDVoySpHEuQO2pGqWcoQyE+lYOODdxTsWKqH1xpop8of X-Received: by 2002:a17:906:881:: with SMTP id n1mr6420491eje.56.1617832444297; Wed, 07 Apr 2021 14:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617832444; cv=none; d=google.com; s=arc-20160816; b=gOXe1Ssh6VA+qWHgOVD8f8KeyB8fUpUFODzEpNE5vijHmZvWiwDuU08H0phILlS3eL egZN+A/XNTcjqoCgnwu0U+WL0orE9NWuuNz7H7xX+617wH/0gzV/ejQnulbSoow6bElD VPfDXz2PljcDJJAS+T3p5YMvZXpNH0PtJ9Be3OyRUn4Fv4RsurMaIZTBODZoF/ioT0uv Z+uOVXGpZfxg5No0OwMgHFTrnb2fOHEPLsGEBqycoCDLls8A2QneRu4XJGS97QtFnFhs 2OI3XqkIVfOEblRkLUAjwfw0fkdjQQBX6oJth4DSm4f8FL3e+9G6RLYZe7Eu4rn95RU9 4IxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=KPx1i8HsZBkfuRY0kVkoQYhr6na7TQyRPx3R62F91Xg=; b=ws1oAZ7iZTL/dWeLjhlQdUVSVHik2OIMn40BLFkzCevq/9P1qGWhyGdxvBhxQxd9RR 1A4D8GYNnnifyfYrcgki7uNu8O6XbFo+5p3sE9+acJHwMp305406HVRFmVcAq1hYXdmm QGYpRdgjE6wdhcqmnD9zYQOrAfkqhMwvyf58VdcLaAvEFayAKoxVCk0gA6sb5pwLkbGf l93icnA0hZSr0I17DvcIjvE4Za95ZXGD2FXgX71sgPAeGfS6w7zpY/V9CILvYtQapAdq QKAzaSMa15P1hQ2PEazPutpfNmrtTavTkFbVK28XfReBvQkBvADcGzWOdpaz0QbVBd1H PYVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@oracle.com header.s=corp-2020-01-29 header.b=b5Vs9WtD; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si10567386edc.183.2021.04.07.14.53.40; Wed, 07 Apr 2021 14:54:04 -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; dkim=fail header.i=@oracle.com header.s=corp-2020-01-29 header.b=b5Vs9WtD; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344540AbhDGSlV (ORCPT + 99 others); Wed, 7 Apr 2021 14:41:21 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:53442 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233392AbhDGSlQ (ORCPT ); Wed, 7 Apr 2021 14:41:16 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 137IU9Ci128528; Wed, 7 Apr 2021 18:40:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=KPx1i8HsZBkfuRY0kVkoQYhr6na7TQyRPx3R62F91Xg=; b=b5Vs9WtDpOjgb/wWxKH1YNG2GuB+F2H9ER1APxuzuGb7kN6tdQYm1G5RYHeOS/jRnACE AA0Og5qq1J1/vRQJphwWYDaQKszUCn48eWfucgZ2bS18V7EI/6CbdSlTMOed/+bNUVX9 mlDbrJQ7yZC+VEwYr5hMa1wv6kbfiGQTTAbq+ZoYfNtRtPhYKgZjMwpUkLYX7edicRg9 oSd35OOdQX5dlOjtm8NT9KSuD4cHBd2JlZcfgmDgDpas+FVT2022ATB2GJALDrMBs7EA lrvyJjdFmH3GFlgF6hkvpEolTBudio9FH9ulMa7QAtIJHmMcnqGKV1A7XccwIYQhx8ry 4Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 37rvagbjcw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 07 Apr 2021 18:40:43 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 137IP5mL123683; Wed, 7 Apr 2021 18:40:42 GMT Received: from pps.reinject (localhost [127.0.0.1]) by userp3020.oracle.com with ESMTP id 37rvb08d2v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 07 Apr 2021 18:40:42 +0000 Received: from userp3020.oracle.com (userp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 137Ie5rM187571; Wed, 7 Apr 2021 18:40:41 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.147.25.63]) by userp3020.oracle.com with ESMTP id 37rvb08d2k-1; Wed, 07 Apr 2021 18:40:41 +0000 From: Saeed Mirzamohammadi Cc: saeed.mirzamohammadi@oracle.com, Camille Lu , David Woodhouse , Lu Baolu , Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width Date: Wed, 7 Apr 2021 11:40:30 -0700 Message-Id: <20210407184030.21683-1-saeed.mirzamohammadi@oracle.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: Bp2XMF9QP88C9ZSTLBU2LEYqm4b_9R9N X-Proofpoint-ORIG-GUID: Bp2XMF9QP88C9ZSTLBU2LEYqm4b_9R9N X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9947 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104070127 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.27.0