All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Ju Zhou via iommu <iommu@lists.linux-foundation.org>
To: <iommu@lists.linux-foundation.org>
Cc: Alexander.Deucher@amd.com, Yin.Wang@amd.com, will@kernel.org,
	PengJu.Zhou@amd.com
Subject: [PATCH] iommu/iova: kmemleak when disable SRIOV.
Date: Thu, 22 Jul 2021 16:16:29 +0800	[thread overview]
Message-ID: <20210722081629.7863-1-PengJu.Zhou@amd.com> (raw)

the object iova->head allocated statically when enable SRIOV but
freed dynamically when disable SRIOV which causing kmemleak.
changing the allocation from statically to dynamically.

Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>
---
 drivers/iommu/iova.c | 15 ++++++++-------
 include/linux/iova.h |  4 ++--
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 2371524796d3..505881d8d97f 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -26,6 +26,8 @@ static void free_iova_rcaches(struct iova_domain *iovad);
 static void fq_destroy_all_entries(struct iova_domain *iovad);
 static void fq_flush_timeout(struct timer_list *t);
 static void free_global_cached_iovas(struct iova_domain *iovad);
+static inline struct iova *alloc_and_init_iova(unsigned long pfn_lo,
+					       unsigned long pfn_hi);
 
 void
 init_iova_domain(struct iova_domain *iovad, unsigned long granule,
@@ -47,17 +49,16 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule,
 
 	INIT_LIST_HEAD(&iovad->holes);
 
-	iovad->head.pfn_lo = 0;
-	iovad->head.pfn_hi = start_pfn;
-	rb_link_node(&iovad->head.node, NULL, &iovad->rbroot.rb_node);
-	rb_insert_color(&iovad->head.node, &iovad->rbroot);
-	list_add(&iovad->head.hole, &iovad->holes);
+	iovad->head = alloc_and_init_iova(0, start_pfn);
+	rb_link_node(&iovad->head->node, NULL, &iovad->rbroot.rb_node);
+	rb_insert_color(&iovad->head->node, &iovad->rbroot);
+	list_add(&iovad->head->hole, &iovad->holes);
 
 	iovad->tail.pfn_lo = IOVA_ANCHOR;
 	iovad->tail.pfn_hi = IOVA_ANCHOR;
 	rb_link_node(&iovad->tail.node,
-		     &iovad->head.node,
-		     &iovad->head.node.rb_right);
+		     &iovad->head->node,
+		     &iovad->head->node.rb_right);
 	rb_insert_color(&iovad->tail.node, &iovad->rbroot);
 
 	init_iova_rcaches(iovad);
diff --git a/include/linux/iova.h b/include/linux/iova.h
index 076eb6cfc613..553905ef41fe 100644
--- a/include/linux/iova.h
+++ b/include/linux/iova.h
@@ -81,7 +81,7 @@ struct iova_domain {
 						   have been finished */
 
 	struct list_head holes;
-	struct iova	head, tail;		/* rbtree lookup anchors */
+	struct iova	*head, tail;		/* rbtree lookup anchors */
 	struct iova_rcache rcaches[IOVA_RANGE_CACHE_MAX_SIZE];	/* IOVA range caches */
 
 	iova_flush_cb	flush_cb;	/* Call-Back function to flush IOMMU
@@ -252,7 +252,7 @@ static inline void free_cpu_cached_iovas(unsigned int cpu,
 
 static inline unsigned long iovad_start_pfn(struct iova_domain *iovad)
 {
-	return iovad->head.pfn_hi;
+	return iovad->head->pfn_hi;
 }
 
 #endif
-- 
2.17.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

             reply	other threads:[~2021-07-22 10:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  8:16 Peng Ju Zhou via iommu [this message]
2021-07-22 14:58 ` [PATCH] iommu/iova: kmemleak when disable SRIOV Robin Murphy
2021-07-27  4:46   ` Zhou, Peng Ju via iommu
2021-07-27  8:51     ` Robin Murphy
2021-07-27 14:05       ` Zhou, Peng Ju via iommu
2021-07-27 14:23         ` Robin Murphy
2021-08-03  5:50           ` Zhou, Peng Ju via iommu
2021-08-03 13:29             ` Deucher, Alexander via iommu
2021-08-04  0:47               ` Zhou, Peng Ju via iommu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210722081629.7863-1-PengJu.Zhou@amd.com \
    --to=iommu@lists.linux-foundation.org \
    --cc=Alexander.Deucher@amd.com \
    --cc=PengJu.Zhou@amd.com \
    --cc=Yin.Wang@amd.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.