linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled
@ 2020-02-17 19:38 Joerg Roedel
  2020-02-17 19:38 ` [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper Joerg Roedel
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-17 19:38 UTC (permalink / raw)
  To: Lu Baolu, David Woodhouse; +Cc: Joerg Roedel, jroedel, iommu, linux-kernel

Hi,

booting into a crashdump kernel with Intel IOMMU enabled and
configured into passthrough mode does not succeed with the current
kernel. The reason is that the check for identity mappings happen
before the check for deferred device attachments. That results in
wrong results returned from iommu_need_mapping() and subsequently in a
wrong domain-type used in __intel_map_single(). A stripped oops is in
the commit-message of patch 3.

The patch-set fixes the issue and does a few code cleanups along the
way. I have not yet researched the stable and fixes tags, but when the
patches are fine I will add the tags before applying the patches.

Please review.

Thanks,

	Joerg

Joerg Roedel (5):
  iommu/vt-d: Add attach_deferred() helper
  iommu/vt-d: Move deferred device attachment into helper function
  iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  iommu/vt-d: Remove deferred_attach_domain()
  iommu/vt-d: Simplify check in identity_mapping()

 drivers/iommu/intel-iommu.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

-- 
2.17.1


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

* [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper
  2020-02-17 19:38 [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled Joerg Roedel
@ 2020-02-17 19:38 ` Joerg Roedel
  2020-02-17 19:50   ` Jerry Snitselaar
  2020-02-18 17:14   ` Christoph Hellwig
  2020-02-17 19:38 ` [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function Joerg Roedel
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-17 19:38 UTC (permalink / raw)
  To: Lu Baolu, David Woodhouse; +Cc: Joerg Roedel, jroedel, iommu, linux-kernel

From: Joerg Roedel <jroedel@suse.de>

Implement a helper function to check whether a device's attach process
is deferred.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/intel-iommu.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 9dc37672bf89..80f2332a5466 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -762,6 +762,11 @@ static int iommu_dummy(struct device *dev)
 	return dev->archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO;
 }
 
+static bool attach_deferred(struct device *dev)
+{
+	return dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO;
+}
+
 /**
  * is_downstream_to_pci_bridge - test if a device belongs to the PCI
  *				 sub-hierarchy of a candidate PCI-PCI bridge
@@ -2510,8 +2515,7 @@ struct dmar_domain *find_domain(struct device *dev)
 {
 	struct device_domain_info *info;
 
-	if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO ||
-		     dev->archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO))
+	if (unlikely(attach_deferred(dev) || iommu_dummy(dev)))
 		return NULL;
 
 	if (dev_is_pci(dev))
@@ -2527,7 +2531,7 @@ struct dmar_domain *find_domain(struct device *dev)
 
 static struct dmar_domain *deferred_attach_domain(struct device *dev)
 {
-	if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO)) {
+	if (unlikely(attach_deferred(dev))) {
 		struct iommu_domain *domain;
 
 		dev->archdata.iommu = NULL;
@@ -6133,7 +6137,7 @@ intel_iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev)
 static bool intel_iommu_is_attach_deferred(struct iommu_domain *domain,
 					   struct device *dev)
 {
-	return dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO;
+	return attach_deferred(dev);
 }
 
 static int
-- 
2.17.1


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

* [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function
  2020-02-17 19:38 [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled Joerg Roedel
  2020-02-17 19:38 ` [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper Joerg Roedel
@ 2020-02-17 19:38 ` Joerg Roedel
  2020-02-17 19:50   ` Jerry Snitselaar
  2020-02-18 17:16   ` Christoph Hellwig
  2020-02-17 19:38 ` [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping() Joerg Roedel
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-17 19:38 UTC (permalink / raw)
  To: Lu Baolu, David Woodhouse; +Cc: Joerg Roedel, jroedel, iommu, linux-kernel

From: Joerg Roedel <jroedel@suse.de>

Move the code that does the deferred device attachment into a separate
helper function.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/intel-iommu.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 80f2332a5466..42cdcce1602e 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2529,16 +2529,20 @@ struct dmar_domain *find_domain(struct device *dev)
 	return NULL;
 }
 
-static struct dmar_domain *deferred_attach_domain(struct device *dev)
+static void do_deferred_attach(struct device *dev)
 {
-	if (unlikely(attach_deferred(dev))) {
-		struct iommu_domain *domain;
+	struct iommu_domain *domain;
 
-		dev->archdata.iommu = NULL;
-		domain = iommu_get_domain_for_dev(dev);
-		if (domain)
-			intel_iommu_attach_device(domain, dev);
-	}
+	dev->archdata.iommu = NULL;
+	domain = iommu_get_domain_for_dev(dev);
+	if (domain)
+		intel_iommu_attach_device(domain, dev);
+}
+
+static struct dmar_domain *deferred_attach_domain(struct device *dev)
+{
+	if (unlikely(attach_deferred(dev)))
+		do_deferred_attach(dev);
 
 	return find_domain(dev);
 }
-- 
2.17.1


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

* [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-17 19:38 [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled Joerg Roedel
  2020-02-17 19:38 ` [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper Joerg Roedel
  2020-02-17 19:38 ` [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function Joerg Roedel
@ 2020-02-17 19:38 ` Joerg Roedel
  2020-02-17 19:51   ` Jerry Snitselaar
  2020-02-18  2:38   ` Lu Baolu
  2020-02-17 19:38 ` [PATCH 4/5] iommu/vt-d: Remove deferred_attach_domain() Joerg Roedel
  2020-02-17 19:38 ` [PATCH 5/5] iommu/vt-d: Simplify check in identity_mapping() Joerg Roedel
  4 siblings, 2 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-17 19:38 UTC (permalink / raw)
  To: Lu Baolu, David Woodhouse; +Cc: Joerg Roedel, jroedel, iommu, linux-kernel

From: Joerg Roedel <jroedel@suse.de>

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 <jroedel@suse.de>
---
 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


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

* [PATCH 4/5] iommu/vt-d: Remove deferred_attach_domain()
  2020-02-17 19:38 [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled Joerg Roedel
                   ` (2 preceding siblings ...)
  2020-02-17 19:38 ` [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping() Joerg Roedel
@ 2020-02-17 19:38 ` Joerg Roedel
  2020-02-17 19:51   ` Jerry Snitselaar
  2020-02-17 19:38 ` [PATCH 5/5] iommu/vt-d: Simplify check in identity_mapping() Joerg Roedel
  4 siblings, 1 reply; 19+ messages in thread
From: Joerg Roedel @ 2020-02-17 19:38 UTC (permalink / raw)
  To: Lu Baolu, David Woodhouse; +Cc: Joerg Roedel, jroedel, iommu, linux-kernel

From: Joerg Roedel <jroedel@suse.de>

The function is now only a wrapper around find_domain(). Remove the
function and call find_domain() directly at the call-sites.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/intel-iommu.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 32f43695a22b..16e47ca505eb 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2539,11 +2539,6 @@ static void do_deferred_attach(struct device *dev)
 		intel_iommu_attach_device(domain, dev);
 }
 
-static struct dmar_domain *deferred_attach_domain(struct device *dev)
-{
-	return find_domain(dev);
-}
-
 static inline struct device_domain_info *
 dmar_search_domain_by_dev_info(int segment, int bus, int devfn)
 {
@@ -3643,7 +3638,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
 
 	BUG_ON(dir == DMA_NONE);
 
-	domain = deferred_attach_domain(dev);
+	domain = find_domain(dev);
 	if (!domain)
 		return DMA_MAPPING_ERROR;
 
@@ -3863,7 +3858,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
 	if (!iommu_need_mapping(dev))
 		return dma_direct_map_sg(dev, sglist, nelems, dir, attrs);
 
-	domain = deferred_attach_domain(dev);
+	domain = find_domain(dev);
 	if (!domain)
 		return 0;
 
@@ -3958,7 +3953,7 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
 	int prot = 0;
 	int ret;
 
-	domain = deferred_attach_domain(dev);
+	domain = find_domain(dev);
 	if (WARN_ON(dir == DMA_NONE || !domain))
 		return DMA_MAPPING_ERROR;
 
-- 
2.17.1


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

* [PATCH 5/5] iommu/vt-d: Simplify check in identity_mapping()
  2020-02-17 19:38 [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled Joerg Roedel
                   ` (3 preceding siblings ...)
  2020-02-17 19:38 ` [PATCH 4/5] iommu/vt-d: Remove deferred_attach_domain() Joerg Roedel
@ 2020-02-17 19:38 ` Joerg Roedel
  2020-02-17 19:54   ` Jerry Snitselaar
  4 siblings, 1 reply; 19+ messages in thread
From: Joerg Roedel @ 2020-02-17 19:38 UTC (permalink / raw)
  To: Lu Baolu, David Woodhouse; +Cc: Joerg Roedel, jroedel, iommu, linux-kernel

From: Joerg Roedel <jroedel@suse.de>

The function only has one call-site and there it is never called with
dummy or deferred devices. Simplify the check in the function to
account for that.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/intel-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 16e47ca505eb..0b5a0fadbc0c 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2916,7 +2916,7 @@ static int identity_mapping(struct device *dev)
 	struct device_domain_info *info;
 
 	info = dev->archdata.iommu;
-	if (info && info != DUMMY_DEVICE_DOMAIN_INFO && info != DEFER_DEVICE_DOMAIN_INFO)
+	if (info)
 		return (info->domain == si_domain);
 
 	return 0;
-- 
2.17.1


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

* Re: [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper
  2020-02-17 19:38 ` [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper Joerg Roedel
@ 2020-02-17 19:50   ` Jerry Snitselaar
  2020-02-18 17:14   ` Christoph Hellwig
  1 sibling, 0 replies; 19+ messages in thread
From: Jerry Snitselaar @ 2020-02-17 19:50 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

On Mon Feb 17 20, Joerg Roedel wrote:
>From: Joerg Roedel <jroedel@suse.de>
>
>Implement a helper function to check whether a device's attach process
>is deferred.
>
>Signed-off-by: Joerg Roedel <jroedel@suse.de>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function
  2020-02-17 19:38 ` [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function Joerg Roedel
@ 2020-02-17 19:50   ` Jerry Snitselaar
  2020-02-18 17:16   ` Christoph Hellwig
  1 sibling, 0 replies; 19+ messages in thread
From: Jerry Snitselaar @ 2020-02-17 19:50 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

On Mon Feb 17 20, Joerg Roedel wrote:
>From: Joerg Roedel <jroedel@suse.de>
>
>Move the code that does the deferred device attachment into a separate
>helper function.
>
>Signed-off-by: Joerg Roedel <jroedel@suse.de>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-17 19:38 ` [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping() Joerg Roedel
@ 2020-02-17 19:51   ` Jerry Snitselaar
  2020-02-18  2:38   ` Lu Baolu
  1 sibling, 0 replies; 19+ messages in thread
From: Jerry Snitselaar @ 2020-02-17 19:51 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

On Mon Feb 17 20, Joerg Roedel wrote:
>From: Joerg Roedel <jroedel@suse.de>
>
>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 <jroedel@suse.de>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH 4/5] iommu/vt-d: Remove deferred_attach_domain()
  2020-02-17 19:38 ` [PATCH 4/5] iommu/vt-d: Remove deferred_attach_domain() Joerg Roedel
@ 2020-02-17 19:51   ` Jerry Snitselaar
  0 siblings, 0 replies; 19+ messages in thread
From: Jerry Snitselaar @ 2020-02-17 19:51 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

On Mon Feb 17 20, Joerg Roedel wrote:
>From: Joerg Roedel <jroedel@suse.de>
>
>The function is now only a wrapper around find_domain(). Remove the
>function and call find_domain() directly at the call-sites.
>
>Signed-off-by: Joerg Roedel <jroedel@suse.de>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH 5/5] iommu/vt-d: Simplify check in identity_mapping()
  2020-02-17 19:38 ` [PATCH 5/5] iommu/vt-d: Simplify check in identity_mapping() Joerg Roedel
@ 2020-02-17 19:54   ` Jerry Snitselaar
  0 siblings, 0 replies; 19+ messages in thread
From: Jerry Snitselaar @ 2020-02-17 19:54 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

On Mon Feb 17 20, Joerg Roedel wrote:
>From: Joerg Roedel <jroedel@suse.de>
>
>The function only has one call-site and there it is never called with
>dummy or deferred devices. Simplify the check in the function to
>account for that.
>
>Signed-off-by: Joerg Roedel <jroedel@suse.de>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-17 19:38 ` [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping() Joerg Roedel
  2020-02-17 19:51   ` Jerry Snitselaar
@ 2020-02-18  2:38   ` Lu Baolu
  2020-02-18  9:28     ` [PATCH 3/5 v2] " Joerg Roedel
  1 sibling, 1 reply; 19+ messages in thread
From: Lu Baolu @ 2020-02-18  2:38 UTC (permalink / raw)
  To: Joerg Roedel, David Woodhouse; +Cc: jroedel, iommu, linux-kernel

Hi Joerg,

Thanks for doing this.

On 2020/2/18 3:38, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> 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 <jroedel@suse.de>
> ---
>   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;
> 

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

* [PATCH 3/5 v2] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-18  2:38   ` Lu Baolu
@ 2020-02-18  9:28     ` Joerg Roedel
  2020-02-18 11:54       ` Lu Baolu
  2020-02-18 15:53       ` Jerry Snitselaar
  0 siblings, 2 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-18  9:28 UTC (permalink / raw)
  To: Lu Baolu; +Cc: David Woodhouse, jroedel, iommu, linux-kernel

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 <jroedel@suse.de>
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 <jroedel@suse.de>
---
 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


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

* Re: [PATCH 3/5 v2] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-18  9:28     ` [PATCH 3/5 v2] " Joerg Roedel
@ 2020-02-18 11:54       ` Lu Baolu
  2020-02-18 16:22         ` Joerg Roedel
  2020-02-18 15:53       ` Jerry Snitselaar
  1 sibling, 1 reply; 19+ messages in thread
From: Lu Baolu @ 2020-02-18 11:54 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: David Woodhouse, jroedel, iommu, linux-kernel

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 <baolu.lu@linux.intel.com>

Best regards,
baolu

>  From 3a5b8a66d288d86ac1fd45092e7d96f842d0cccf Mon Sep 17 00:00:00 2001
> From: Joerg Roedel <jroedel@suse.de>
> 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 <jroedel@suse.de>
> ---
>   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;
>   
> 

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

* Re: [PATCH 3/5 v2] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-18  9:28     ` [PATCH 3/5 v2] " Joerg Roedel
  2020-02-18 11:54       ` Lu Baolu
@ 2020-02-18 15:53       ` Jerry Snitselaar
  1 sibling, 0 replies; 19+ messages in thread
From: Jerry Snitselaar @ 2020-02-18 15:53 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, iommu, jroedel, David Woodhouse, linux-kernel

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 <jroedel@suse.de>
>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 <jroedel@suse.de>

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH 3/5 v2] iommu/vt-d: Do deferred attachment in iommu_need_mapping()
  2020-02-18 11:54       ` Lu Baolu
@ 2020-02-18 16:22         ` Joerg Roedel
  0 siblings, 0 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-18 16:22 UTC (permalink / raw)
  To: Lu Baolu; +Cc: David Woodhouse, jroedel, iommu, linux-kernel

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 <baolu.lu@linux.intel.com>

Thanks, queued the fixes for v5.6.

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

* Re: [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper
  2020-02-17 19:38 ` [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper Joerg Roedel
  2020-02-17 19:50   ` Jerry Snitselaar
@ 2020-02-18 17:14   ` Christoph Hellwig
  2020-02-19  9:29     ` Joerg Roedel
  1 sibling, 1 reply; 19+ messages in thread
From: Christoph Hellwig @ 2020-02-18 17:14 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

> +static bool attach_deferred(struct device *dev)
> +{
> +	return dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO;
> +}

This is not a very useful helper.

> +
>  /**
>   * is_downstream_to_pci_bridge - test if a device belongs to the PCI
>   *				 sub-hierarchy of a candidate PCI-PCI bridge
> @@ -2510,8 +2515,7 @@ struct dmar_domain *find_domain(struct device *dev)
>  {
>  	struct device_domain_info *info;
>  
> -	if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO ||
> -		     dev->archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO))
> +	if (unlikely(attach_deferred(dev) || iommu_dummy(dev)))
>  		return NULL;

I'd rather kill the iommu_dummy helper as well.  And IIRC I have an
outstanding series somewhere that does just that..

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

* Re: [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function
  2020-02-17 19:38 ` [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function Joerg Roedel
  2020-02-17 19:50   ` Jerry Snitselaar
@ 2020-02-18 17:16   ` Christoph Hellwig
  1 sibling, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2020-02-18 17:16 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Lu Baolu, David Woodhouse, jroedel, iommu, linux-kernel

> +static void do_deferred_attach(struct device *dev)
>  {
> +	struct iommu_domain *domain;
>  
> +	dev->archdata.iommu = NULL;
> +	domain = iommu_get_domain_for_dev(dev);
> +	if (domain)
> +		intel_iommu_attach_device(domain, dev);
> +}
> +
> +static struct dmar_domain *deferred_attach_domain(struct device *dev)
> +{
> +	if (unlikely(attach_deferred(dev)))
> +		do_deferred_attach(dev);
>  
>  	return find_domain(dev);
>  }

Can we start using proper sybmbol prefixes and avoid do_* names where
possible?

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

* Re: [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper
  2020-02-18 17:14   ` Christoph Hellwig
@ 2020-02-19  9:29     ` Joerg Roedel
  0 siblings, 0 replies; 19+ messages in thread
From: Joerg Roedel @ 2020-02-19  9:29 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Joerg Roedel, Lu Baolu, David Woodhouse, iommu, linux-kernel

On Tue, Feb 18, 2020 at 09:14:54AM -0800, Christoph Hellwig wrote:
> > +static bool attach_deferred(struct device *dev)
> > +{
> > +	return dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO;
> > +}
> 
> This is not a very useful helper.

Depends on what one considers useful. I think such helpers make the code
better readable, which is pretty useful to me.

Regards,

	Joerg


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

end of thread, other threads:[~2020-02-19  9:29 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-17 19:38 [PATCH 0/5] iommu/vt-d: Fix kdump boot with VT-d enabled Joerg Roedel
2020-02-17 19:38 ` [PATCH 1/5] iommu/vt-d: Add attach_deferred() helper Joerg Roedel
2020-02-17 19:50   ` Jerry Snitselaar
2020-02-18 17:14   ` Christoph Hellwig
2020-02-19  9:29     ` Joerg Roedel
2020-02-17 19:38 ` [PATCH 2/5] iommu/vt-d: Move deferred device attachment into helper function Joerg Roedel
2020-02-17 19:50   ` Jerry Snitselaar
2020-02-18 17:16   ` Christoph Hellwig
2020-02-17 19:38 ` [PATCH 3/5] iommu/vt-d: Do deferred attachment in iommu_need_mapping() Joerg Roedel
2020-02-17 19:51   ` Jerry Snitselaar
2020-02-18  2:38   ` Lu Baolu
2020-02-18  9:28     ` [PATCH 3/5 v2] " Joerg Roedel
2020-02-18 11:54       ` Lu Baolu
2020-02-18 16:22         ` Joerg Roedel
2020-02-18 15:53       ` Jerry Snitselaar
2020-02-17 19:38 ` [PATCH 4/5] iommu/vt-d: Remove deferred_attach_domain() Joerg Roedel
2020-02-17 19:51   ` Jerry Snitselaar
2020-02-17 19:38 ` [PATCH 5/5] iommu/vt-d: Simplify check in identity_mapping() Joerg Roedel
2020-02-17 19:54   ` Jerry Snitselaar

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).