From: Joerg Roedel <[email protected]>
The attachment of deferred devices needs to happen before the check
whether the device is identity mapped or not. Otherwise the check will
return wrong results, cause warnings boot failures in kdump kernels, like
WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70
[...]
Call Trace:
__intel_map_single+0x55/0x190
intel_alloc_coherent+0xac/0x110
dmam_alloc_attrs+0x50/0xa0
ahci_port_start+0xfb/0x1f0 [libahci]
ata_host_start.part.39+0x104/0x1e0 [libata]
With the earlier check the kdump boot succeeds and a crashdump is written.
Signed-off-by: Joerg Roedel <[email protected]>
---
drivers/iommu/intel-iommu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 42cdcce1602e..32f43695a22b 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
static struct dmar_domain *deferred_attach_domain(struct device *dev)
{
- if (unlikely(attach_deferred(dev)))
- do_deferred_attach(dev);
-
return find_domain(dev);
}
@@ -3595,6 +3592,9 @@ static bool iommu_need_mapping(struct device *dev)
if (iommu_dummy(dev))
return false;
+ if (unlikely(attach_deferred(dev)))
+ do_deferred_attach(dev);
+
ret = identity_mapping(dev);
if (ret) {
u64 dma_mask = *dev->dma_mask;
--
2.17.1
On Mon Feb 17 20, Joerg Roedel wrote:
>From: Joerg Roedel <[email protected]>
>
>The attachment of deferred devices needs to happen before the check
>whether the device is identity mapped or not. Otherwise the check will
>return wrong results, cause warnings boot failures in kdump kernels, like
>
> WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70
>
> [...]
>
> Call Trace:
> __intel_map_single+0x55/0x190
> intel_alloc_coherent+0xac/0x110
> dmam_alloc_attrs+0x50/0xa0
> ahci_port_start+0xfb/0x1f0 [libahci]
> ata_host_start.part.39+0x104/0x1e0 [libata]
>
>With the earlier check the kdump boot succeeds and a crashdump is written.
>
>Signed-off-by: Joerg Roedel <[email protected]>
Reviewed-by: Jerry Snitselaar <[email protected]>
Hi Joerg,
Thanks for doing this.
On 2020/2/18 3:38, Joerg Roedel wrote:
> From: Joerg Roedel <[email protected]>
>
> The attachment of deferred devices needs to happen before the check
> whether the device is identity mapped or not. Otherwise the check will
> return wrong results, cause warnings boot failures in kdump kernels, like
>
> WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70
>
> [...]
>
> Call Trace:
> __intel_map_single+0x55/0x190
> intel_alloc_coherent+0xac/0x110
> dmam_alloc_attrs+0x50/0xa0
> ahci_port_start+0xfb/0x1f0 [libahci]
> ata_host_start.part.39+0x104/0x1e0 [libata]
>
> With the earlier check the kdump boot succeeds and a crashdump is written.
>
> Signed-off-by: Joerg Roedel <[email protected]>
> ---
> drivers/iommu/intel-iommu.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index 42cdcce1602e..32f43695a22b 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
>
> static struct dmar_domain *deferred_attach_domain(struct device *dev)
> {
> - if (unlikely(attach_deferred(dev)))
> - do_deferred_attach(dev);
> -
This should also be moved to the call place of deferred_attach_domain()
in bounce_map_single().
bounce_map_single() assumes that devices always use DMA domain, so it
doesn't call iommu_need_mapping(). We could do_deferred_attach() there
manually.
Best regards,
baolu
> return find_domain(dev);
> }
>
> @@ -3595,6 +3592,9 @@ static bool iommu_need_mapping(struct device *dev)
> if (iommu_dummy(dev))
> return false;
>
> + if (unlikely(attach_deferred(dev)))
> + do_deferred_attach(dev);
> +
> ret = identity_mapping(dev);
> if (ret) {
> u64 dma_mask = *dev->dma_mask;
>
Hi Baolu,
On Tue, Feb 18, 2020 at 10:38:14AM +0800, Lu Baolu wrote:
> > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> > index 42cdcce1602e..32f43695a22b 100644
> > --- a/drivers/iommu/intel-iommu.c
> > +++ b/drivers/iommu/intel-iommu.c
> > @@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
> > static struct dmar_domain *deferred_attach_domain(struct device *dev)
> > {
> > - if (unlikely(attach_deferred(dev)))
> > - do_deferred_attach(dev);
> > -
>
> This should also be moved to the call place of deferred_attach_domain()
> in bounce_map_single().
>
> bounce_map_single() assumes that devices always use DMA domain, so it
> doesn't call iommu_need_mapping(). We could do_deferred_attach() there
> manually.
Good point, thanks for your review. Updated patch below.
From 3a5b8a66d288d86ac1fd45092e7d96f842d0cccf Mon Sep 17 00:00:00 2001
From: Joerg Roedel <[email protected]>
Date: Mon, 17 Feb 2020 17:20:59 +0100
Subject: [PATCH 3/5] iommu/vt-d: Do deferred attachment in
iommu_need_mapping()
The attachment of deferred devices needs to happen before the check
whether the device is identity mapped or not. Otherwise the check will
return wrong results, cause warnings boot failures in kdump kernels, like
WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70
[...]
Call Trace:
__intel_map_single+0x55/0x190
intel_alloc_coherent+0xac/0x110
dmam_alloc_attrs+0x50/0xa0
ahci_port_start+0xfb/0x1f0 [libahci]
ata_host_start.part.39+0x104/0x1e0 [libata]
With the earlier check the kdump boot succeeds and a crashdump is written.
Signed-off-by: Joerg Roedel <[email protected]>
---
drivers/iommu/intel-iommu.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 42cdcce1602e..723f615c6e84 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
static struct dmar_domain *deferred_attach_domain(struct device *dev)
{
- if (unlikely(attach_deferred(dev)))
- do_deferred_attach(dev);
-
return find_domain(dev);
}
@@ -3595,6 +3592,9 @@ static bool iommu_need_mapping(struct device *dev)
if (iommu_dummy(dev))
return false;
+ if (unlikely(attach_deferred(dev)))
+ do_deferred_attach(dev);
+
ret = identity_mapping(dev);
if (ret) {
u64 dma_mask = *dev->dma_mask;
@@ -3958,7 +3958,11 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
int prot = 0;
int ret;
+ if (unlikely(attach_deferred(dev)))
+ do_deferred_attach(dev);
+
domain = deferred_attach_domain(dev);
+
if (WARN_ON(dir == DMA_NONE || !domain))
return DMA_MAPPING_ERROR;
--
2.25.0
Hi Joerg,
On 2020/2/18 17:28, Joerg Roedel wrote:
> Hi Baolu,
>
> On Tue, Feb 18, 2020 at 10:38:14AM +0800, Lu Baolu wrote:
>>> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
>>> index 42cdcce1602e..32f43695a22b 100644
>>> --- a/drivers/iommu/intel-iommu.c
>>> +++ b/drivers/iommu/intel-iommu.c
>>> @@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
>>> static struct dmar_domain *deferred_attach_domain(struct device *dev)
>>> {
>>> - if (unlikely(attach_deferred(dev)))
>>> - do_deferred_attach(dev);
>>> -
>>
>> This should also be moved to the call place of deferred_attach_domain()
>> in bounce_map_single().
>>
>> bounce_map_single() assumes that devices always use DMA domain, so it
>> doesn't call iommu_need_mapping(). We could do_deferred_attach() there
>> manually.
>
> Good point, thanks for your review. Updated patch below.
>
Looks good to me now. For all patches in this series,
Acked-by: Lu Baolu <[email protected]>
Best regards,
baolu
> From 3a5b8a66d288d86ac1fd45092e7d96f842d0cccf Mon Sep 17 00:00:00 2001
> From: Joerg Roedel <[email protected]>
> Date: Mon, 17 Feb 2020 17:20:59 +0100
> Subject: [PATCH 3/5] iommu/vt-d: Do deferred attachment in
> iommu_need_mapping()
>
> The attachment of deferred devices needs to happen before the check
> whether the device is identity mapped or not. Otherwise the check will
> return wrong results, cause warnings boot failures in kdump kernels, like
>
> WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70
>
> [...]
>
> Call Trace:
> __intel_map_single+0x55/0x190
> intel_alloc_coherent+0xac/0x110
> dmam_alloc_attrs+0x50/0xa0
> ahci_port_start+0xfb/0x1f0 [libahci]
> ata_host_start.part.39+0x104/0x1e0 [libata]
>
> With the earlier check the kdump boot succeeds and a crashdump is written.
>
> Signed-off-by: Joerg Roedel <[email protected]>
> ---
> drivers/iommu/intel-iommu.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index 42cdcce1602e..723f615c6e84 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
>
> static struct dmar_domain *deferred_attach_domain(struct device *dev)
> {
> - if (unlikely(attach_deferred(dev)))
> - do_deferred_attach(dev);
> -
> return find_domain(dev);
> }
>
> @@ -3595,6 +3592,9 @@ static bool iommu_need_mapping(struct device *dev)
> if (iommu_dummy(dev))
> return false;
>
> + if (unlikely(attach_deferred(dev)))
> + do_deferred_attach(dev);
> +
> ret = identity_mapping(dev);
> if (ret) {
> u64 dma_mask = *dev->dma_mask;
> @@ -3958,7 +3958,11 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
> int prot = 0;
> int ret;
>
> + if (unlikely(attach_deferred(dev)))
> + do_deferred_attach(dev);
> +
> domain = deferred_attach_domain(dev);
> +
> if (WARN_ON(dir == DMA_NONE || !domain))
> return DMA_MAPPING_ERROR;
>
>
On Tue Feb 18 20, Joerg Roedel wrote:
>Hi Baolu,
>
>On Tue, Feb 18, 2020 at 10:38:14AM +0800, Lu Baolu wrote:
>> > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
>> > index 42cdcce1602e..32f43695a22b 100644
>> > --- a/drivers/iommu/intel-iommu.c
>> > +++ b/drivers/iommu/intel-iommu.c
>> > @@ -2541,9 +2541,6 @@ static void do_deferred_attach(struct device *dev)
>> > static struct dmar_domain *deferred_attach_domain(struct device *dev)
>> > {
>> > - if (unlikely(attach_deferred(dev)))
>> > - do_deferred_attach(dev);
>> > -
>>
>> This should also be moved to the call place of deferred_attach_domain()
>> in bounce_map_single().
>>
>> bounce_map_single() assumes that devices always use DMA domain, so it
>> doesn't call iommu_need_mapping(). We could do_deferred_attach() there
>> manually.
>
>Good point, thanks for your review. Updated patch below.
>
>From 3a5b8a66d288d86ac1fd45092e7d96f842d0cccf Mon Sep 17 00:00:00 2001
>From: Joerg Roedel <[email protected]>
>Date: Mon, 17 Feb 2020 17:20:59 +0100
>Subject: [PATCH 3/5] iommu/vt-d: Do deferred attachment in
> iommu_need_mapping()
>
>The attachment of deferred devices needs to happen before the check
>whether the device is identity mapped or not. Otherwise the check will
>return wrong results, cause warnings boot failures in kdump kernels, like
>
> WARNING: CPU: 0 PID: 318 at ../drivers/iommu/intel-iommu.c:592 domain_get_iommu+0x61/0x70
>
> [...]
>
> Call Trace:
> __intel_map_single+0x55/0x190
> intel_alloc_coherent+0xac/0x110
> dmam_alloc_attrs+0x50/0xa0
> ahci_port_start+0xfb/0x1f0 [libahci]
> ata_host_start.part.39+0x104/0x1e0 [libata]
>
>With the earlier check the kdump boot succeeds and a crashdump is written.
>
>Signed-off-by: Joerg Roedel <[email protected]>
Reviewed-by: Jerry Snitselaar <[email protected]>
On Tue, Feb 18, 2020 at 07:54:52PM +0800, Lu Baolu wrote:
> Looks good to me now. For all patches in this series,
>
> Acked-by: Lu Baolu <[email protected]>
Thanks, queued the fixes for v5.6.