2021-04-07 21:54:04

by Saeed Mirzamohammadi

[permalink] [raw]
Subject: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width

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 <[email protected]>
Tested-by: Camille Lu <[email protected]>
---

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


2021-04-08 00:35:53

by Baolu Lu

[permalink] [raw]
Subject: Re: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width

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 <[email protected]>
> Tested-by: Camille Lu <[email protected]>
> ---
>
> 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 <[email protected]>

Best regards,
baolu

2021-04-12 00:08:10

by Baolu Lu

[permalink] [raw]
Subject: Re: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width

I guess you need to ask Greg KH <[email protected]> with this
Cc-ing to [email protected].

Best regards,
baolu

On 2021/4/12 3:36, Saeed Mirzamohammadi wrote:
> Hi Lu,
>
> Thanks for the review. May I know when do we expect this to be applied
> to 5.4?
>
> Thanks,
> Saeed
>
>> On Apr 7, 2021, at 5:25 PM, Lu Baolu <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> 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 <[email protected]
>>> <mailto:[email protected]>>
>>> Tested-by: Camille Lu <[email protected] <mailto:[email protected]>>
>>> ---
>>> 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 <[email protected]
>> <mailto:[email protected]>>
>>
>> Best regards,
>> baolu
>

2021-04-13 06:41:27

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width

On Mon, Apr 12, 2021 at 06:25:44PM +0000, Saeed Mirzamohammadi wrote:
> Hi Greg,
>
> This patch fixes an issue with the IOMMU driver and it only applies to 5.4, 4.19, and 4.14 stable kernels. May I know when this patch would be available in the stable kernels?
>
> Subject: iommu/vt-d: Fix agaw for a supported 48 bit guest address width
>


<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

2021-04-13 11:00:21

by Saeed Mirzamohammadi

[permalink] [raw]
Subject: Re: [PATCH 5.4 v2 1/1] iommu/vt-d: Fix agaw for a supported 48 bit guest address width

Hi Greg,

This patch fixes an issue with the IOMMU driver and it only applies to 5.4, 4.19, and 4.14 stable kernels. May I know when this patch would be available in the stable kernels?

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

Thanks,
Saeed


> On Apr 11, 2021, at 4:49 PM, Lu Baolu <[email protected]> wrote:
>
> I guess you need to ask Greg KH <[email protected]> with this
> Cc-ing to [email protected].
>
> Best regards,
> baolu
>
> On 2021/4/12 3:36, Saeed Mirzamohammadi wrote:
>> Hi Lu,
>> Thanks for the review. May I know when do we expect this to be applied to 5.4?
>> Thanks,
>> Saeed
>>> On Apr 7, 2021, at 5:25 PM, Lu Baolu <[email protected] <mailto:[email protected]>> wrote:
>>>
>>> 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 <[email protected] <mailto:[email protected]>>
>>>> Tested-by: Camille Lu <[email protected] <mailto:[email protected]>>
>>>> ---
>>>> 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 <[email protected] <mailto:[email protected]>>
>>>
>>> Best regards,
>>> baolu