linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/vt-d: Clean up si_domain in the init_dmars() error path
@ 2022-10-10  6:56 Jerry Snitselaar
  2022-10-10 11:32 ` Baolu Lu
  2022-10-10 14:48 ` [PATCH v2] " Jerry Snitselaar
  0 siblings, 2 replies; 5+ messages in thread
From: Jerry Snitselaar @ 2022-10-10  6:56 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: Lu Baolu, Joerg Roedel, Will Deacon, Robin Murphy

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>
---
 drivers/iommu/intel/iommu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 31bc50e538a3..8f1f80a4d0c5 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -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;
 }
-- 
2.37.2


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

* Re: [PATCH] iommu/vt-d: Clean up si_domain in the init_dmars() error path
  2022-10-10  6:56 [PATCH] iommu/vt-d: Clean up si_domain in the init_dmars() error path Jerry Snitselaar
@ 2022-10-10 11:32 ` Baolu Lu
  2022-10-10 14:33   ` Jerry Snitselaar
  2022-10-10 14:48 ` [PATCH v2] " Jerry Snitselaar
  1 sibling, 1 reply; 5+ messages in thread
From: Baolu Lu @ 2022-10-10 11:32 UTC (permalink / raw)
  To: Jerry Snitselaar, iommu, linux-kernel
  Cc: baolu.lu, Joerg Roedel, Will Deacon, Robin Murphy

On 2022/10/10 14:56, Jerry Snitselaar wrote:
> 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>
> ---
>   drivers/iommu/intel/iommu.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index 31bc50e538a3..8f1f80a4d0c5 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -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?

--- 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;
         }

Best regards,
baolu

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

* Re: [PATCH] iommu/vt-d: Clean up si_domain in the init_dmars() error path
  2022-10-10 11:32 ` Baolu Lu
@ 2022-10-10 14:33   ` Jerry Snitselaar
  0 siblings, 0 replies; 5+ messages in thread
From: Jerry Snitselaar @ 2022-10-10 14:33 UTC (permalink / raw)
  To: Baolu Lu; +Cc: iommu, linux-kernel, Joerg Roedel, Will Deacon, Robin Murphy

On Mon, Oct 10, 2022 at 07:32:43PM +0800, Baolu Lu wrote:
> On 2022/10/10 14:56, Jerry Snitselaar wrote:
> > 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>
> > ---
> >   drivers/iommu/intel/iommu.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> > index 31bc50e538a3..8f1f80a4d0c5 100644
> > --- a/drivers/iommu/intel/iommu.c
> > +++ b/drivers/iommu/intel/iommu.c
> > @@ -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?
> 
> --- 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;
>         }
> 
> Best regards,
> baolu

Hi Baolu,

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

Regards,
Jerry


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

* [PATCH v2] iommu/vt-d: Clean up si_domain in the init_dmars() error path
  2022-10-10  6:56 [PATCH] iommu/vt-d: Clean up si_domain in the init_dmars() error path Jerry Snitselaar
  2022-10-10 11:32 ` Baolu Lu
@ 2022-10-10 14:48 ` Jerry Snitselaar
  2022-10-19  0:54   ` Baolu Lu
  1 sibling, 1 reply; 5+ messages in thread
From: Jerry Snitselaar @ 2022-10-10 14:48 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: Lu Baolu, Joerg Roedel, Will Deacon, Robin Murphy

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>
---
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(+)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 31bc50e538a3..ecc0b05b2796 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -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;
 }
-- 
2.37.2


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

* Re: [PATCH v2] iommu/vt-d: Clean up si_domain in the init_dmars() error path
  2022-10-10 14:48 ` [PATCH v2] " Jerry Snitselaar
@ 2022-10-19  0:54   ` Baolu Lu
  0 siblings, 0 replies; 5+ messages in thread
From: Baolu Lu @ 2022-10-19  0:54 UTC (permalink / raw)
  To: Jerry Snitselaar, iommu, linux-kernel
  Cc: baolu.lu, Joerg Roedel, Will Deacon, Robin Murphy

On 10/10/22 10:48 PM, Jerry Snitselaar wrote:
> 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>

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

https://lore.kernel.org/linux-iommu/20221019004447.4563-1-baolu.lu@linux.intel.com/

Best regards,
baolu

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

end of thread, other threads:[~2022-10-19  1:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10  6:56 [PATCH] iommu/vt-d: Clean up si_domain in the init_dmars() error path Jerry Snitselaar
2022-10-10 11:32 ` Baolu Lu
2022-10-10 14:33   ` Jerry Snitselaar
2022-10-10 14:48 ` [PATCH v2] " Jerry Snitselaar
2022-10-19  0:54   ` Baolu Lu

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