Skip to contentSkip to conversation

iommu/vt-d: Fix agaw for a supported 48 bit guest address width

PATCH In review Lu Baolu 2 participants 6 messages Aug 16, 2021

Subsystems (2)
lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Fix agaw for a supported 48 bit guest address width

From: Saeed Mirzamohammadi <[email protected]>

[ Upstream commit 327d5b2fee91c404a3956c324193892cf2cc9528 ]

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.

This issue happens on the code path of getting a private domain for a device. A private domain was needed when the domain of an iommu group couldn't meet the requirement of a device. The IOMMU core has been evolved to eliminate the need for private domain, hence this code path has alreay been removed from the upstream since commit 327d5b2fee91c ("iommu/vt-d: Allow 32bit devices to uses DMA domain"). Instead of back porting all patches that are required for removing the private domain, this simply fixes it in the affected stable kernel between v4.16 and v5.7.

[baolu: The orignal patch could be found here
https://lore.kernel.org/linux-iommu/[email protected]/.
I added commit message according to Greg's comments at
https://lore.kernel.org/linux-iommu/YHZ%[email protected]/.]

---
 drivers/iommu/intel-iommu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/intel-iommu.c +4 -3
index 953d86ca6d2b..a2a03df97704 100644
@@ -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);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 55 lines · Lu Baolu

From: Saeed Mirzamohammadi <[email protected]>

[ Upstream commit 327d5b2fee91c404a3956c324193892cf2cc9528 ]

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.

This issue happens on the code path of getting a private domain for a device. A private domain was needed when the domain of an iommu group couldn't meet the requirement of a device. The IOMMU core has been evolved to eliminate the need for private domain, hence this code path has alreay been removed from the upstream since commit 327d5b2fee91c ("iommu/vt-d: Allow 32bit devices to uses DMA domain"). Instead of back porting all patches that are required for removing the private domain, this simply fixes it in the affected stable kernel between v4.16 and v5.7.

[baolu: The orignal patch could be found here
https://lore.kernel.org/linux-iommu/[email protected]/.
I added commit message according to Greg's comments at
https://lore.kernel.org/linux-iommu/YHZ%[email protected]/.]

Quoted 3 lines
---
 drivers/iommu/intel-iommu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

What stable tree(s) is this backport for?

thanks,

greg k-h

author
#3 lore raw

Hi Greg,

Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Lu Baolu

From: Saeed Mirzamohammadi <[email protected]>

[ Upstream commit 327d5b2fee91c404a3956c324193892cf2cc9528 ]

Also, this really does not look like this commit at all :(

This is not a back port. It's a fix for some stable kernels. Sorry for the confusion.

The error happens in a helper function that has been deprecated in the upstream kernel by above commit. I added below explanation in the commit message:

"
This issue happens on the code path of getting a private domain for a device. A private domain was needed when the domain of an iommu group couldn't meet the requirement of a device. The IOMMU core has been evolved to eliminate the need for private domain, hence this code path has already been removed from the upstream since commit 327d5b2fee91c ("iommu/vt-d: Allow 32bit devices to uses DMA domain"). Instead of back porting all patches that are required for removing the private domain, this simply fixes it in the affected stable kernel between v4.16 and v5.7. "

I'm sorry if this is not the right way to do this.

Best regards,
baolu

#4 lore raw
Quoted 29 lines · Lu Baolu

Hi Greg,

Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Lu Baolu

From: Saeed Mirzamohammadi <[email protected]>

[ Upstream commit 327d5b2fee91c404a3956c324193892cf2cc9528 ]

Also, this really does not look like this commit at all :(

This is not a back port. It's a fix for some stable kernels. Sorry for the confusion.

The error happens in a helper function that has been deprecated in the upstream kernel by above commit. I added below explanation in the commit message:

"
This issue happens on the code path of getting a private domain for a device. A private domain was needed when the domain of an iommu group couldn't meet the requirement of a device. The IOMMU core has been evolved to eliminate the need for private domain, hence this code path has already been removed from the upstream since commit 327d5b2fee91c ("iommu/vt-d: Allow 32bit devices to uses DMA domain"). Instead of back porting all patches that are required for removing the private domain, this simply fixes it in the affected stable kernel between v4.16 and v5.7. "

Quoted 1 line

I'm sorry if this is not the right way to do this.

Ah, sorry, I totally missed that. This is fine, now queued up for 4.19.y and 5.4.y.

thanks,

greg k-h

author
#5 lore raw
Quoted 30 lines · Greg Kroah-Hartman
Quoted 29 lines · Lu Baolu

Hi Greg,

Quoted 7 lines · Greg Kroah-Hartman
Quoted 3 lines · Lu Baolu

From: Saeed Mirzamohammadi <[email protected]>

[ Upstream commit 327d5b2fee91c404a3956c324193892cf2cc9528 ]

Also, this really does not look like this commit at all :(

This is not a back port. It's a fix for some stable kernels. Sorry for the confusion.

The error happens in a helper function that has been deprecated in the upstream kernel by above commit. I added below explanation in the commit message:

"
This issue happens on the code path of getting a private domain for a device. A private domain was needed when the domain of an iommu group couldn't meet the requirement of a device. The IOMMU core has been evolved to eliminate the need for private domain, hence this code path has already been removed from the upstream since commit 327d5b2fee91c ("iommu/vt-d: Allow 32bit devices to uses DMA domain"). Instead of back porting all patches that are required for removing the private domain, this simply fixes it in the affected stable kernel between v4.16 and v5.7. "

Quoted 4 lines
Quoted 1 line

I'm sorry if this is not the right way to do this.

Ah, sorry, I totally missed that. This is fine, now queued up for 4.19.y and 5.4.y.

Thank you! Greg.

Best regards,
baolu

Quoted 5 lines

thanks,

greg k-h