linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
To: linuxppc-dev@ozlabs.org
Cc: imunsie@au1.ibm.com, mikey@neuling.org,
	vaibhav@linux.vnet.ibm.com, mrochs@linux.vnet.ibm.com
Subject: [PATCH 3/3] cxl: fix leak of ctx->mapping when releasing kernel API contexts
Date: Wed, 30 Sep 2015 11:58:07 +1000	[thread overview]
Message-ID: <1443578287-7847-3-git-send-email-andrew.donnellan@au1.ibm.com> (raw)
In-Reply-To: <1443578287-7847-1-git-send-email-andrew.donnellan@au1.ibm.com>

When a context is created via the kernel API, ctx->mapping is allocated
within the kernel and thus needs to be freed when the context is freed.
reclaim_ctx() attempts to do this for contexts with the ctx->kernelapi flag
set, but afu_release() (which can be called from the kernel API through
cxl_fd_release()) sets ctx->mapping to NULL before calling
cxl_context_free() to free the context.

Add a check to afu_release() so that the mappings in contexts created via
the kernel API are left alone so reclaim_ctx() can free them.

Reported-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Fixes: 6f7f0b3df6d4 ("cxl: Add AFU virtual PHB and kernel API")
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 drivers/misc/cxl/file.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index a30bf28..fcda6b0 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -120,9 +120,16 @@ int afu_release(struct inode *inode, struct file *file)
 		 __func__, ctx->pe);
 	cxl_context_detach(ctx);
 
-	mutex_lock(&ctx->mapping_lock);
-	ctx->mapping = NULL;
-	mutex_unlock(&ctx->mapping_lock);
+
+	/* 
+	 * Delete the context's mapping pointer, unless it's created by the
+	 * kernel API, in which case leave it so it can be freed by reclaim_ctx()
+	 */
+	if (!ctx->kernelapi) {
+		mutex_lock(&ctx->mapping_lock);
+		ctx->mapping = NULL;
+		mutex_unlock(&ctx->mapping_lock);
+	}
 
 	put_device(&ctx->afu->dev);
 
-- 
Andrew Donnellan              Software Engineer, OzLabs
andrew.donnellan@au1.ibm.com  Australia Development Lab, Canberra
+61 2 6201 8874 (work)        IBM Australia Limited

  parent reply	other threads:[~2015-09-30  1:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30  1:58 [PATCH 1/3] cxl: fix leak of IRQ names in cxl_free_afu_irqs() Andrew Donnellan
2015-09-30  1:58 ` [PATCH 2/3] cxl: fix leak of ctx->irq_bitmap when releasing context via kernel API Andrew Donnellan
2015-09-30  6:01   ` Ian Munsie
2015-09-30 14:04   ` Matthew R. Ochs
2015-10-01  6:51   ` [2/3] " Michael Ellerman
2015-09-30  1:58 ` Andrew Donnellan [this message]
2015-09-30  6:02   ` [PATCH 3/3] cxl: fix leak of ctx->mapping when releasing kernel API contexts Ian Munsie
2015-09-30 14:04   ` Matthew R. Ochs
2015-10-01  6:51   ` [3/3] " Michael Ellerman
2015-10-07 10:10   ` Michael Ellerman
2015-09-30 14:03 ` [PATCH 1/3] cxl: fix leak of IRQ names in cxl_free_afu_irqs() Matthew R. Ochs
2015-10-01  6:49 ` [1/3] " Michael Ellerman
2015-10-01  6:51 ` Michael Ellerman

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=1443578287-7847-3-git-send-email-andrew.donnellan@au1.ibm.com \
    --to=andrew.donnellan@au1.ibm.com \
    --cc=imunsie@au1.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=mrochs@linux.vnet.ibm.com \
    --cc=vaibhav@linux.vnet.ibm.com \
    /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 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).