iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width
@ 2021-04-12 20:27 Saeed Mirzamohammadi
  2021-04-13  7:32 ` Greg KH
  2021-04-14  6:41 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Saeed Mirzamohammadi @ 2021-04-12 20:27 UTC (permalink / raw)
  Cc: saeed.mirzamohammadi, Camille Lu, linux-kernel, stable, iommu,
	David Woodhouse

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.

Cc: stable@vger.kernel.org
Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
Tested-by: Camille Lu <camille.lu@hpe.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

---

Change in v2:
- Added cap_width to calculate AGAW based on the minimum value of MGAW and AGAW.

Changes in v3:
- Added Lu's Reviewed-by.
- Added stable list.
---
 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

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width
  2021-04-12 20:27 [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width Saeed Mirzamohammadi
@ 2021-04-13  7:32 ` Greg KH
  2021-04-13 17:53   ` Saeed Mirzamohammadi
  2021-04-13 18:05   ` Saeed Mirzamohammadi
  2021-04-14  6:41 ` Greg KH
  1 sibling, 2 replies; 6+ messages in thread
From: Greg KH @ 2021-04-13  7:32 UTC (permalink / raw)
  To: Saeed Mirzamohammadi
  Cc: saeed.mirzamohammadi, Camille Lu, linux-kernel, stable, iommu,
	David Woodhouse

<meta comment, please fix your email client to put proper things in the
 To: line so that we can correctly respond to patches...>

On Mon, Apr 12, 2021 at 01:27:35PM -0700, 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.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
> Tested-by: Camille Lu <camille.lu@hpe.com>
> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

What is the git commit id of this patch in Linus's tree?

thanks,

greg k-h
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width
  2021-04-13  7:32 ` Greg KH
@ 2021-04-13 17:53   ` Saeed Mirzamohammadi
  2021-04-13 18:05   ` Saeed Mirzamohammadi
  1 sibling, 0 replies; 6+ messages in thread
From: Saeed Mirzamohammadi @ 2021-04-13 17:53 UTC (permalink / raw)
  To: Greg KH
  Cc: Saeed Mirzamohammadi, Camille Lu, Linux Kernel Mailing List,
	# v4 . 16+,
	iommu, David Woodhouse


[-- Attachment #1.1: Type: text/plain, Size: 2422 bytes --]

Hi Greg,

I don’t have any commit ID since the fix is not in mainline or any Linus’ tree yet. The driver has completely changed for newer stable versions (and also mainline) and the fix only applies for 5.4, 4.19, and 4.14 stable kernels.

Thanks,
Saeed


> On Apr 13, 2021, at 12:32 AM, Greg KH <gregkh@linuxfoundation.org> wrote:
> 
> <meta comment, please fix your email client to put proper things in the
> To: line so that we can correctly respond to patches...>
> 
> On Mon, Apr 12, 2021 at 01:27:35PM -0700, 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.
>> 
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
>> Tested-by: Camille Lu <camille.lu@hpe.com>
>> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
> 
> What is the git commit id of this patch in Linus's tree?
> 
> thanks,
> 
> greg k-h


[-- Attachment #1.2: Type: text/html, Size: 9287 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width
  2021-04-13  7:32 ` Greg KH
  2021-04-13 17:53   ` Saeed Mirzamohammadi
@ 2021-04-13 18:05   ` Saeed Mirzamohammadi
  2021-04-14  5:36     ` Greg KH
  1 sibling, 1 reply; 6+ messages in thread
From: Saeed Mirzamohammadi @ 2021-04-13 18:05 UTC (permalink / raw)
  To: Greg KH
  Cc: Camille Lu, Linux Kernel Mailing List, # v4 . 16+,
	iommu, David Woodhouse

Hi Greg,

I don’t have any commit ID since the fix is not in mainline or any Linus’ tree yet. The driver has completely changed for newer stable versions (and also mainline) and the fix only applies for 5.4, 4.19, and 4.14 stable kernels.

Thanks,
Saeed


> On Apr 13, 2021, at 12:32 AM, Greg KH <gregkh@linuxfoundation.org> wrote:
> 
> 
> On Mon, Apr 12, 2021 at 01:27:35PM -0700, 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.
>> 
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
>> Tested-by: Camille Lu <camille.lu@hpe.com>
>> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
> 
> What is the git commit id of this patch in Linus's tree?
> 
> thanks,
> 
> greg k-h

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width
  2021-04-13 18:05   ` Saeed Mirzamohammadi
@ 2021-04-14  5:36     ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-04-14  5:36 UTC (permalink / raw)
  To: Saeed Mirzamohammadi
  Cc: Camille Lu, Linux Kernel Mailing List, # v4 . 16+,
	iommu, David Woodhouse

On Tue, Apr 13, 2021 at 11:05:34AM -0700, Saeed Mirzamohammadi wrote:
> Hi Greg,
> 
> I don’t have any commit ID since the fix is not in mainline or any Linus’ tree yet. The driver has completely changed for newer stable versions (and also mainline) and the fix only applies for 5.4, 4.19, and 4.14 stable kernels.

Why can we not just take what is in mainline?

And if not, then you need to document the heck out of this in the
changelog text, and get all of the related maintainers in the area to
sign off on this.  Diverging from Linus's tree creates a big burden over
time, you have to make this really really obvious why you are doing
this, and what you are doing here so that everyone agrees with it.

Remember, 90% of all of these types of "do it differently than Linus's
tree" are buggy and cause problems, be very careful.

Please fix up and resend.

thanks,

greg k-h
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width
  2021-04-12 20:27 [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width Saeed Mirzamohammadi
  2021-04-13  7:32 ` Greg KH
@ 2021-04-14  6:41 ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-04-14  6:41 UTC (permalink / raw)
  To: Saeed Mirzamohammadi
  Cc: saeed.mirzamohammadi, Camille Lu, linux-kernel, stable, iommu,
	David Woodhouse

On Mon, Apr 12, 2021 at 01:27:35PM -0700, 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.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
> Tested-by: Camille Lu <camille.lu@hpe.com>
> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
> 
> ---

Also when you resend this, please state the commit that this fixes, as
this must be a regression, right?  What kernel version did this previous
work for?

thanks,

greg k-h
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-14  6:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 20:27 [PATCH 5.4 v3 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width Saeed Mirzamohammadi
2021-04-13  7:32 ` Greg KH
2021-04-13 17:53   ` Saeed Mirzamohammadi
2021-04-13 18:05   ` Saeed Mirzamohammadi
2021-04-14  5:36     ` Greg KH
2021-04-14  6:41 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).