aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Neuling <mikey@neuling.org>2015-07-06 21:01:17 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2015-07-07 05:38:37 -0400
commit3f8dc44d88d3e86178eb9322c779c599f3745b21 (patch)
treec8b03ff06197cace0cf0457987083300b6d22c45
parentb32aadc1a8ed84afbe924cd2ced31cd6a2e67074 (diff)
cxl: Fix refcounting in kernel API
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> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--drivers/misc/cxl/api.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index 0c77240ae2fc..729e0851167d 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)
23 23
24 afu = cxl_pci_to_afu(dev); 24 afu = cxl_pci_to_afu(dev);
25 25
26 get_device(&afu->dev);
26 ctx = cxl_context_alloc(); 27 ctx = cxl_context_alloc();
27 if (IS_ERR(ctx)) 28 if (IS_ERR(ctx))
28 return ctx; 29 return ctx;
@@ -31,6 +32,7 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
31 rc = cxl_context_init(ctx, afu, false, NULL); 32 rc = cxl_context_init(ctx, afu, false, NULL);
32 if (rc) { 33 if (rc) {
33 kfree(ctx); 34 kfree(ctx);
35 put_device(&afu->dev);
34 return ERR_PTR(-ENOMEM); 36 return ERR_PTR(-ENOMEM);
35 } 37 }
36 cxl_assign_psn_space(ctx); 38 cxl_assign_psn_space(ctx);
@@ -60,6 +62,8 @@ int cxl_release_context(struct cxl_context *ctx)
60 if (ctx->status != CLOSED) 62 if (ctx->status != CLOSED)
61 return -EBUSY; 63 return -EBUSY;
62 64
65 put_device(&ctx->afu->dev);
66
63 cxl_context_free(ctx); 67 cxl_context_free(ctx);
64 68
65 return 0; 69 return 0;
@@ -159,7 +163,6 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
159 } 163 }
160 164
161 ctx->status = STARTED; 165 ctx->status = STARTED;
162 get_device(&ctx->afu->dev);
163out: 166out:
164 mutex_unlock(&ctx->status_mutex); 167 mutex_unlock(&ctx->status_mutex);
165 return rc; 168 return rc;
@@ -175,12 +178,7 @@ EXPORT_SYMBOL_GPL(cxl_process_element);
175/* Stop a context. Returns 0 on success, otherwise -Errno */ 178/* Stop a context. Returns 0 on success, otherwise -Errno */
176int cxl_stop_context(struct cxl_context *ctx) 179int cxl_stop_context(struct cxl_context *ctx)
177{ 180{
178 int rc; 181 return __detach_context(ctx);
179
180 rc = __detach_context(ctx);
181 if (!rc)
182 put_device(&ctx->afu->dev);
183 return rc;
184} 182}
185EXPORT_SYMBOL_GPL(cxl_stop_context); 183EXPORT_SYMBOL_GPL(cxl_stop_context);
186 184