Skip to content

Commit

Permalink
cxl: Fix refcounting in kernel API
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ian Munsie <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
mikey authored and mpe committed Jul 7, 2015
1 parent b32aadc commit 3f8dc44
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions drivers/misc/cxl/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 3f8dc44

Please sign in to comment.