/* * Start a context * Code here similar to afu_ioctl_start_work(). */ int cxl_start_context(struct cxl_context *ctx, u64 wed, struct task_struct *task) { int rc = 0; bool kernel = true; pr_devel("%s: pe: %i\n", __func__, ctx->pe); mutex_lock(&ctx->status_mutex); if (ctx->status == STARTED) goto out; /* already started */ if (task) { ctx->pid = get_task_pid(task, PIDTYPE_PID); get_pid(ctx->pid); kernel = false; } cxl_ctx_get(); if ((rc = cxl_attach_process(ctx, kernel, wed , 0))) { put_pid(ctx->pid); cxl_ctx_put(); goto out; } ctx->status = STARTED; out: mutex_unlock(&ctx->status_mutex); return rc; }
static int __afu_open(struct inode *inode, struct file *file, bool master) { struct cxl *adapter; struct cxl_afu *afu; struct cxl_context *ctx; int adapter_num = CXL_DEVT_ADAPTER(inode->i_rdev); int slice = CXL_DEVT_AFU(inode->i_rdev); int rc = -ENODEV; pr_devel("afu_open afu%i.%i\n", slice, adapter_num); if (!(adapter = get_cxl_adapter(adapter_num))) return -ENODEV; if (slice > adapter->slices) goto err_put_adapter; spin_lock(&adapter->afu_list_lock); if (!(afu = adapter->afu[slice])) { spin_unlock(&adapter->afu_list_lock); goto err_put_adapter; } get_device(&afu->dev); spin_unlock(&adapter->afu_list_lock); if (!afu->current_mode) goto err_put_afu; if (!(ctx = cxl_context_alloc())) { rc = -ENOMEM; goto err_put_afu; } if ((rc = cxl_context_init(ctx, afu, master, inode->i_mapping))) goto err_put_afu; pr_devel("afu_open pe: %i\n", ctx->pe); file->private_data = ctx; cxl_ctx_get(); /* Our ref on the AFU will now hold the adapter */ put_device(&adapter->dev); return 0; err_put_afu: put_device(&afu->dev); err_put_adapter: put_device(&adapter->dev); return rc; }
static int __afu_open(struct inode *inode, struct file *file, bool master) { struct cxl *adapter; struct cxl_afu *afu; struct cxl_context *ctx; int adapter_num = CXL_DEVT_ADAPTER(inode->i_rdev); int slice = CXL_DEVT_AFU(inode->i_rdev); int rc = -ENODEV; pr_devel("afu_open afu%i.%i\n", slice, adapter_num); if (!(adapter = get_cxl_adapter(adapter_num))) return -ENODEV; if (slice > adapter->slices) goto err_put_adapter; spin_lock(&adapter->afu_list_lock); if (!(afu = adapter->afu[slice])) { spin_unlock(&adapter->afu_list_lock); goto err_put_adapter; } /* * taking a ref to the afu so that it doesn't go away * for rest of the function. This ref is released before * we return. */ cxl_afu_get(afu); spin_unlock(&adapter->afu_list_lock); if (!afu->current_mode) goto err_put_afu; if (!cxl_ops->link_ok(adapter, afu)) { rc = -EIO; goto err_put_afu; } if (!(ctx = cxl_context_alloc())) { rc = -ENOMEM; goto err_put_afu; } rc = cxl_context_init(ctx, afu, master); if (rc) goto err_put_afu; cxl_context_set_mapping(ctx, inode->i_mapping); pr_devel("afu_open pe: %i\n", ctx->pe); file->private_data = ctx; cxl_ctx_get(); /* indicate success */ rc = 0; err_put_afu: /* release the ref taken earlier */ cxl_afu_put(afu); err_put_adapter: put_device(&adapter->dev); return rc; }
/* * Start a context * Code here similar to afu_ioctl_start_work(). */ int cxl_start_context(struct cxl_context *ctx, u64 wed, struct task_struct *task) { int rc = 0; bool kernel = true; pr_devel("%s: pe: %i\n", __func__, ctx->pe); mutex_lock(&ctx->status_mutex); if (ctx->status == STARTED) goto out; /* already started */ /* * Increment the mapped context count for adapter. This also checks * if adapter_context_lock is taken. */ rc = cxl_adapter_context_get(ctx->afu->adapter); if (rc) goto out; if (task) { ctx->pid = get_task_pid(task, PIDTYPE_PID); kernel = false; /* acquire a reference to the task's mm */ ctx->mm = get_task_mm(current); /* ensure this mm_struct can't be freed */ cxl_context_mm_count_get(ctx); if (ctx->mm) { /* decrement the use count from above */ mmput(ctx->mm); /* make TLBIs for this context global */ mm_context_add_copro(ctx->mm); } } /* * Increment driver use count. Enables global TLBIs for hash * and callbacks to handle the segment table */ cxl_ctx_get(); /* See the comment in afu_ioctl_start_work() */ smp_mb(); if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) { put_pid(ctx->pid); ctx->pid = NULL; cxl_adapter_context_put(ctx->afu->adapter); cxl_ctx_put(); if (task) { cxl_context_mm_count_put(ctx); if (ctx->mm) mm_context_remove_copro(ctx->mm); } goto out; } ctx->status = STARTED; out: mutex_unlock(&ctx->status_mutex); return rc; }