snits · GitHub

I'm not sure that there is a solution to this, but wanted to report it. I was backporting a kernel patch from upstream, and git cherry-pick applies it correctly, but stg pick finds a match in a different spot for one chunk and applies it there. I can see how it chose that location, so I'm not sure what the solution would be, but there was no indication of modified when it applied the patch.

# git --no-pager show 620bf9f981365c18cc2766c53d92bf8131c63f32
commit 620bf9f981365c18cc2766c53d92bf8131c63f32 (tag: iommu-fixes-v6.1-rc1, iommu/next, iommu/iommu/fixes)
Author: Jerry Snitselaar <jsnitsel@redhat.com>
Date:   Wed Oct 19 08:44:47 2022 +0800
    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 <baolu.lu@linux.intel.com>
    Cc: Joerg Roedel <joro@8bytes.org>
    Cc: Will Deacon <will@kernel.org>
    Cc: Robin Murphy <robin.murphy@arm.com>
    Fixes: 86080ccc223a ("iommu/vt-d: Allocate si_domain in init_dmars()")
    Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
    Link: https://lore.kernel.org/r/20221010144842.308890-1-jsnitsel@redhat.com
    Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
    Signed-off-by: Joerg Roedel <jroedel@suse.de>
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index b3cf0f991e29..48cdcd0a5cf3 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -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;
 	}
@@ -3052,6 +3053,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;
 }

git cherry pick case:

# git cpk 620bf9f98136
Auto-merging drivers/iommu/intel/iommu.c
[testing4 4f8cca10f877] iommu/vt-d: Clean up si_domain in the init_dmars() error path
 Date: Wed Oct 19 08:44:47 2022 +0800
 1 file changed, 5 insertions(+)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2a29bc08c7bd..17fbcbf0ea21 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2837,6 +2837,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;
 	}
@@ -3487,6 +3488,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;
+	}
 	kfree(g_iommus);

stg pick case:

# stg pick -x 620bf9f981365c18cc2766c53d92bf8131c63f32
- iommu-vt-d-Clean-up-si_domain-in-the-init_dmars-error-path
> iommu-vt-d-Clean-up-si_domain-in-the-init_dmars-error-path
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2a29bc08c7bd..8c625c6776fa 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2837,6 +2837,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;
 	}
@@ -4027,6 +4028,10 @@ int dmar_iommu_hotplug(struct dmar_drhd_unit *dmaru, bool insert)
 		disable_dmar_iommu(iommu);
 		free_dmar_iommu(iommu);
 	}
+	if (si_domain) {
+		domain_exit(si_domain);
+		si_domain = NULL;
+	}
 	return ret;
 }

So in the stg case, it applied it to the dmar_iommu_hotplug() instead of init_dmars().

Read the original on github.com ↗