linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cxl: Fix refcounting in kernel API
@ 2015-07-07  1:01 Michael Neuling
  2015-07-07  1:12 ` Ian Munsie
  2015-07-08 10:54 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Neuling @ 2015-07-07  1:01 UTC (permalink / raw)
  To: mpe, benh; +Cc: imunsie, linuxppc-dev, Michael Neuling

Currently the kernel API AFU dev refcounting is done on context start and stop.
This patch moves this refcounting to context init and release, bringing it
inline with how the userspace API does it.

Without this we've seen the refcounting on the AFU get out of whack between the
user and kernel API usage.  This causes the AFU structures to be freed when
they are actually still in use.

This fixes some kref warnings we've been seeing and spurious ErrIVTE IRQs.

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
mpe: This is for 4.2 fixes

 drivers/misc/cxl/api.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index 0c77240..729e085 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -23,6 +23,7 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
 
 	afu = cxl_pci_to_afu(dev);
 
+	get_device(&afu->dev);
 	ctx = cxl_context_alloc();
 	if (IS_ERR(ctx))
 		return ctx;
@@ -31,6 +32,7 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
 	rc = cxl_context_init(ctx, afu, false, NULL);
 	if (rc) {
 		kfree(ctx);
+		put_device(&afu->dev);
 		return ERR_PTR(-ENOMEM);
 	}
 	cxl_assign_psn_space(ctx);
@@ -60,6 +62,8 @@ int cxl_release_context(struct cxl_context *ctx)
 	if (ctx->status != CLOSED)
 		return -EBUSY;
 
+	put_device(&ctx->afu->dev);
+
 	cxl_context_free(ctx);
 
 	return 0;
@@ -159,7 +163,6 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
 	}
 
 	ctx->status = STARTED;
-	get_device(&ctx->afu->dev);
 out:
 	mutex_unlock(&ctx->status_mutex);
 	return rc;
@@ -175,12 +178,7 @@ EXPORT_SYMBOL_GPL(cxl_process_element);
 /* Stop a context.  Returns 0 on success, otherwise -Errno */
 int cxl_stop_context(struct cxl_context *ctx)
 {
-	int rc;
-
-	rc = __detach_context(ctx);
-	if (!rc)
-		put_device(&ctx->afu->dev);
-	return rc;
+	return __detach_context(ctx);
 }
 EXPORT_SYMBOL_GPL(cxl_stop_context);
 
-- 
2.1.0

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

* Re: [PATCH] cxl: Fix refcounting in kernel API
  2015-07-07  1:01 [PATCH] cxl: Fix refcounting in kernel API Michael Neuling
@ 2015-07-07  1:12 ` Ian Munsie
  2015-07-08 10:54 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Munsie @ 2015-07-07  1:12 UTC (permalink / raw)
  To: Michael Neuling; +Cc: mpe, benh, linuxppc-dev

Acked-by: Ian Munsie <imunsie@au1.ibm.com>

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

* Re: cxl: Fix refcounting in kernel API
  2015-07-07  1:01 [PATCH] cxl: Fix refcounting in kernel API Michael Neuling
  2015-07-07  1:12 ` Ian Munsie
@ 2015-07-08 10:54 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2015-07-08 10:54 UTC (permalink / raw)
  To: Michael Neuling, benh; +Cc: linuxppc-dev, Michael Neuling, imunsie

On Tue, 2015-07-07 at 01:01:17 UTC, Michael Neuling wrote:
> Currently the kernel API AFU dev refcounting is done on context start and stop.
> This patch moves this refcounting to context init and release, bringing it
> inline with how the userspace API does it.
> 
> Without this we've seen the refcounting on the AFU get out of whack between the
> user and kernel API usage.  This causes the AFU structures to be freed when
> they are actually still in use.
> 
> This fixes some kref warnings we've been seeing and spurious ErrIVTE IRQs.
> 
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Acked-by: Ian Munsie <imunsie@au1.ibm.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/cgit/linux/kernel/git/powerpc/linux.git/commit/?h=fixes&id=3f8dc44d88d3e86178eb9322c779c599f3745b21

cheers

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

end of thread, other threads:[~2015-07-08 10:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07  1:01 [PATCH] cxl: Fix refcounting in kernel API Michael Neuling
2015-07-07  1:12 ` Ian Munsie
2015-07-08 10:54 ` Michael Ellerman

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