On 02/02/17 04:30, Christophe Lombard wrote:
The mm_struct corresponding to the current task is acquired each time
an interrupt is raised. So to simplify the code, we only get the
mm_struct when attaching an AFU context to the process.
The mm_count reference is increased to ensure that the mm_struct can't
be freed. The mm_struct will be released when the context is detached.
The reference (use count) on the struct mm is not kept to avoid a
circular dependency if the process mmaps its cxl mmio and forget to
unmap before exiting.

Signed-off-by: Christophe Lombard <clomb...@linux.vnet.ibm.com>

One question below, otherwise this all looks good to me.

Reviewed-by: Andrew Donnellan <andrew.donnel...@au1.ibm.com>

@@ -281,7 +212,6 @@ void cxl_handle_fault(struct work_struct *fault_work)
        if (!ctx->kernel) {

                mm = get_mem_context(ctx);
-               /* indicates all the thread in task group have exited */
                if (mm == NULL) {
                        pr_devel("%s: unable to get mm for pe=%d pid=%i\n",
                                 __func__, ctx->pe, pid_nr(ctx->pid));

Is there still a case where mm can equal NULL?

diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 859959f..af6bd0e 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -216,8 +216,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
         * process is still accessible.
         */
        ctx->pid = get_task_pid(current, PIDTYPE_PID);
-       ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID);

+       /* 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);
+
+       /* decrement the use count */
+       if (ctx->mm)
+               mmput(ctx->mm);

It took me a while to work out the difference between mm_users and mm_count... this looks fine.

--
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnel...@au1.ibm.com  IBM Australia Limited

Reply via email to