Skip to contentSkip to conversation

iommu/vt-d: Clean up si_domain in the init_dmars() error path

PATCH Superseded Jerry Snitselaar 2 participants 5 messages Oct 10, 2022 – Oct 19, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/vt-d: Clean up si_domain in the init_dmars() error path

A splat from kmem_cache_destroy() was seen with a kernel prior to commit ee2653bbe89d ("iommu/vt-d: Remove domain and devinfo mempool") when there was a failure in init_dmars(), because the iommu_domain cache still had objects. While the mempool code is now gone, there still is a leak of the si_domain memory if init_dmars() fails. So clean up si_domain in the init_dmars() error path.

Cc Lu Baolu <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Will Deacon <[email protected]>
Cc Robin Murphy <[email protected]>
Fixes 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()")
---
 drivers/iommu/intel/iommu.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/intel/iommu.c +2 -0
index 31bc50e538a3..8f1f80a4d0c5 100644
@@ -3042,6 +3042,8 @@ static int __init init_dmars(void)
 		disable_dmar_iommu(iommu);
 		free_dmar_iommu(iommu);
 	}
+	if (si_domain)
+		domain_exit(si_domain);
 
 	return ret;
 }
Signature · 1 line
2.37.2
maintainer
#1 lore raw
Quoted 22 lines · Jerry Snitselaar

A splat from kmem_cache_destroy() was seen with a kernel prior to commit ee2653bbe89d ("iommu/vt-d: Remove domain and devinfo mempool") when there was a failure in init_dmars(), because the iommu_domain cache still had objects. While the mempool code is now gone, there still is a leak of the si_domain memory if init_dmars() fails. So clean up si_domain in the init_dmars() error path.

Cc Lu Baolu <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Will Deacon <[email protected]>
Cc Robin Murphy <[email protected]>
Fixes 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()")
---
  drivers/iommu/intel/iommu.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/iommu/intel/iommu.c +0 -0
index 31bc50e538a3..8f1f80a4d0c5 100644

drivers/iommu/intel/iommu.c static int __init init_dmars(void) · line 3046

Quoted 5 lines
drivers/iommu/intel/iommu.c +2 -0
@@ -3042,6 +3042,8 @@ static int __init init_dmars(void)
  		disable_dmar_iommu(iommu);
  		free_dmar_iommu(iommu);
  	}
+	if (si_domain)
+		domain_exit(si_domain);

Thank you for the patch.

Above requires si_domain to be NULL or a valid pointer. So do you also need to add the following change?

drivers/iommu/intel/iommu.c +1 -0
@@ -2410,6 +2410,7 @@ static int __init si_domain_init(int hw)
 
        if (md_domain_init(si_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
                domain_exit(si_domain);
+               si_domain = NULL;
                return -EFAULT;
        }
 

Best regards,
baolu

#2 lore raw
Quoted 44 lines · Baolu Lu
Quoted 22 lines · Jerry Snitselaar

A splat from kmem_cache_destroy() was seen with a kernel prior to commit ee2653bbe89d ("iommu/vt-d: Remove domain and devinfo mempool") when there was a failure in init_dmars(), because the iommu_domain cache still had objects. While the mempool code is now gone, there still is a leak of the si_domain memory if init_dmars() fails. So clean up si_domain in the init_dmars() error path.

Cc Lu Baolu <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Will Deacon <[email protected]>
Cc Robin Murphy <[email protected]>
Fixes 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()")
---
  drivers/iommu/intel/iommu.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/iommu/intel/iommu.c +0 -0
index 31bc50e538a3..8f1f80a4d0c5 100644

drivers/iommu/intel/iommu.c static int __init init_dmars(void) · line 3046

Quoted 5 lines
drivers/iommu/intel/iommu.c +2 -0
@@ -3042,6 +3042,8 @@ static int __init init_dmars(void)
  		disable_dmar_iommu(iommu);
  		free_dmar_iommu(iommu);
  	}
+	if (si_domain)
+		domain_exit(si_domain);

Thank you for the patch.

Above requires si_domain to be NULL or a valid pointer. So do you also need to add the following change?

drivers/iommu/intel/iommu.c +1 -0
@@ -2410,6 +2410,7 @@ static int __init si_domain_init(int hw)
 
        if (md_domain_init(si_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
                domain_exit(si_domain);
+               si_domain = NULL;
                return -EFAULT;
        }
 
Quoted 2 lines

Best regards,
baolu

Hi Baolu,

Yes. I think should add it after the domain_exit() call I added as well.

Regards,
Jerry

#3 lore raw

PATCH v2 1/1 iommu/vt-d: Clean up si_domain in the init_dmars() error path

In reply to Jerry Snitselaar

A splat from kmem_cache_destroy() was seen with a kernel prior to commit ee2653bbe89d ("iommu/vt-d: Remove domain and devinfo mempool") when there was a failure in init_dmars(), because the iommu_domain cache still had objects. While the mempool code is now gone, there still is a leak of the si_domain memory if init_dmars() fails. So clean up si_domain in the init_dmars() error path.

Cc Lu Baolu <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Will Deacon <[email protected]>
Cc Robin Murphy <[email protected]>
Fixes 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()")

---
v2: Set si_domain to NULL after the memory it points to has been freed.

 drivers/iommu/intel/iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iommu/intel/iommu.c +5 -0
index 31bc50e538a3..ecc0b05b2796 100644
@@ -2400,6 +2400,7 @@ static int __init si_domain_init(int hw)
 
 	if (md_domain_init(si_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
 		domain_exit(si_domain);
+		si_domain = NULL;
 		return -EFAULT;
 	}
 
@@ -3042,6 +3043,10 @@ static int __init init_dmars(void)
 		disable_dmar_iommu(iommu);
 		free_dmar_iommu(iommu);
 	}
+	if (si_domain) {
+		domain_exit(si_domain);
+		si_domain = NULL;
+	}
 
 	return ret;
 }
Signature · 1 line
2.37.2
maintainer
#4 lore raw
Quoted 7 lines · Jerry Snitselaar

A splat from kmem_cache_destroy() was seen with a kernel prior to commit ee2653bbe89d ("iommu/vt-d: Remove domain and devinfo mempool") when there was a failure in init_dmars(), because the iommu_domain cache still had objects. While the mempool code is now gone, there still is a leak of the si_domain memory if init_dmars() fails. So clean up si_domain in the init_dmars() error path.

Quoted 6 lines
Cc Lu Baolu<[email protected]>
Cc Joerg Roedel<[email protected]>
Cc Will Deacon<[email protected]>
Cc Robin Murphy<[email protected]>
Fixes 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()")

Thanks for the patch. It has been queued for v6.1.

https://lore.kernel.org/linux-iommu/[email protected]/

Best regards,
baolu