From d014ef60644d61b84c7eaf94e3ba4ff16ac36dcc Mon Sep 17 00:00:00 2001 From: Jordan Crouse Date: Thu, 24 Sep 2020 09:24:12 -0600 Subject: [PATCH] msm: kgsl: Make sure that pool pages don't have any extra references Before putting a page back in the pool be sure that it doesn't have any additional references that would be a signal that somebody else is looking at the page and that it would be a bad idea to keep it around and run the risk of accidentally handing it to a different process. Change-Id: Ic0dedbad0cf2ffb34b76ad23e393c5a911114b82 Signed-off-by: Jordan Crouse --- drivers/gpu/msm/kgsl_pool.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/msm/kgsl_pool.c b/drivers/gpu/msm/kgsl_pool.c index 9f7e41660c1c..a6c726fbd990 100644 --- a/drivers/gpu/msm/kgsl_pool.c +++ b/drivers/gpu/msm/kgsl_pool.c @@ -96,6 +96,15 @@ _kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p) if (!p) return; + /* + * Sanity check to make sure we don't re-pool a page that + * somebody else has a reference to. + */ + if (WARN_ON(unlikely(page_count(p) > 1))) { + __free_pages(p, pool->pool_order); + return; + } + spin_lock(&pool->list_lock); list_add_tail(&p->lru, &pool->page_list); pool->page_count++;