Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/744342/?format=api
{ "id": 744342, "url": "http://patchwork.ozlabs.org/api/patches/744342/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/1490714052-18902-4-git-send-email-clombard@linux.vnet.ibm.com/", "project": { "id": 2, "url": "http://patchwork.ozlabs.org/api/projects/2/?format=api", "name": "Linux PPC development", "link_name": "linuxppc-dev", "list_id": "linuxppc-dev.lists.ozlabs.org", "list_email": "linuxppc-dev@lists.ozlabs.org", "web_url": "https://github.com/linuxppc/wiki/wiki", "scm_url": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git", "webscm_url": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/", "list_archive_url_format": "https://lore.kernel.org/linuxppc-dev/{}/", "commit_url_format": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}" }, "msgid": "<1490714052-18902-4-git-send-email-clombard@linux.vnet.ibm.com>", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/1490714052-18902-4-git-send-email-clombard@linux.vnet.ibm.com/", "date": "2017-03-28T15:14:08", "name": "[V3,3/7] cxl: Keep track of mm struct associated with a context", "commit_ref": null, "pull_url": null, "state": "changes-requested", "archived": false, "hash": "97b25d6a00e4768b00b9533b4670214c8d51fbcf", "submitter": { "id": 67351, "url": "http://patchwork.ozlabs.org/api/people/67351/?format=api", "name": "Christophe Lombard", "email": "clombard@linux.vnet.ibm.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/1490714052-18902-4-git-send-email-clombard@linux.vnet.ibm.com/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/744342/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/744342/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>", "X-Original-To": [ "patchwork-incoming@ozlabs.org", "linuxppc-dev@lists.ozlabs.org" ], "Delivered-To": [ "patchwork-incoming@ozlabs.org", "linuxppc-dev@lists.ozlabs.org" ], "Received": [ "from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3vsvjB01wpz9s2P\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 29 Mar 2017 02:20:30 +1100 (AEDT)", "from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3vsvj96MGyzDqj1\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 29 Mar 2017 02:20:29 +1100 (AEDT)", "from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n\t[148.163.158.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3vsvbX4LFdzDqYB\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tWed, 29 Mar 2017 02:15:00 +1100 (AEDT)", "from pps.filterd (m0098416.ppops.net [127.0.0.1])\n\tby mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id\n\tv2SFE3R5046044\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 28 Mar 2017 11:14:49 -0400", "from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111])\n\tby mx0b-001b2d01.pphosted.com with ESMTP id 29ft6f8f7v-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 28 Mar 2017 11:14:49 -0400", "from localhost\n\tby e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from\n\t<clombard@linux.vnet.ibm.com>; Tue, 28 Mar 2017 16:14:47 +0100", "from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197)\n\tby e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted; \n\tTue, 28 Mar 2017 16:14:44 +0100", "from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com\n\t[9.149.105.232])\n\tby b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v2SFEIw338863068; Tue, 28 Mar 2017 15:14:18 GMT", "from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 9816852069;\n\tTue, 28 Mar 2017 15:12:33 +0100 (BST)", "from lombard-w520.ibm.com (unknown [9.167.235.7])\n\tby d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 1857752051; \n\tTue, 28 Mar 2017 15:12:33 +0100 (BST)" ], "From": "Christophe Lombard <clombard@linux.vnet.ibm.com>", "To": "linuxppc-dev@lists.ozlabs.org, fbarrat@linux.vnet.ibm.com,\n\timunsie@au1.ibm.com, andrew.donnellan@au1.ibm.com", "Subject": "[PATCH V3 3/7] cxl: Keep track of mm struct associated with a\n\tcontext", "Date": "Tue, 28 Mar 2017 17:14:08 +0200", "X-Mailer": "git-send-email 2.7.4", "In-Reply-To": "<1490714052-18902-1-git-send-email-clombard@linux.vnet.ibm.com>", "References": "<1490714052-18902-1-git-send-email-clombard@linux.vnet.ibm.com>", "X-TM-AS-GCONF": "00", "x-cbid": "17032815-0020-0000-0000-000003321881", "X-IBM-AV-DETECTION": "SAVI=unused REMOTE=unused XFE=unused", "x-cbparentid": "17032815-0021-0000-0000-000041011EF3", "Message-Id": "<1490714052-18902-4-git-send-email-clombard@linux.vnet.ibm.com>", "X-Proofpoint-Virus-Version": "vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-03-28_12:, , signatures=0", "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=2\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001\n\tdefinitions=main-1703280131", "X-BeenThere": "linuxppc-dev@lists.ozlabs.org", "X-Mailman-Version": "2.1.23", "Precedence": "list", "List-Id": "Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>", "List-Unsubscribe": "<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>", "List-Archive": "<http://lists.ozlabs.org/pipermail/linuxppc-dev/>", "List-Post": "<mailto:linuxppc-dev@lists.ozlabs.org>", "List-Help": "<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>", "List-Subscribe": "<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>", "Errors-To": "linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org", "Sender": "\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>" }, "content": "The mm_struct corresponding to the current task is acquired each time\nan interrupt is raised. So to simplify the code, we only get the\nmm_struct when attaching an AFU context to the process.\nThe mm_count reference is increased to ensure that the mm_struct can't\nbe freed. The mm_struct will be released when the context is detached.\nA reference on mm_users is not kept to avoid a circular dependency if\nthe process mmaps its cxl mmio and forget to unmap before exiting.\n\nSigned-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>\n---\n drivers/misc/cxl/api.c | 17 +++++++++--\n drivers/misc/cxl/context.c | 21 +++++++++++--\n drivers/misc/cxl/cxl.h | 13 ++++++--\n drivers/misc/cxl/fault.c | 76 ++++------------------------------------------\n drivers/misc/cxl/file.c | 15 +++++++--\n drivers/misc/cxl/main.c | 12 ++------\n 6 files changed, 64 insertions(+), 90 deletions(-)", "diff": "diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c\nindex bcc030e..1a138c8 100644\n--- a/drivers/misc/cxl/api.c\n+++ b/drivers/misc/cxl/api.c\n@@ -14,6 +14,7 @@\n #include <linux/msi.h>\n #include <linux/module.h>\n #include <linux/mount.h>\n+#include <linux/sched/mm.h>\n \n #include \"cxl.h\"\n \n@@ -321,19 +322,29 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,\n \n \tif (task) {\n \t\tctx->pid = get_task_pid(task, PIDTYPE_PID);\n-\t\tctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID);\n \t\tkernel = false;\n \t\tctx->real_mode = false;\n+\n+\t\t/* acquire a reference to the task's mm */\n+\t\tctx->mm = get_task_mm(current);\n+\n+\t\t/* ensure this mm_struct can't be freed */\n+\t\tcxl_context_mm_count_get(ctx);\n+\n+\t\t/* decrement the use count */\n+\t\tif (ctx->mm)\n+\t\t\tmmput(ctx->mm);\n \t}\n \n \tcxl_ctx_get();\n \n \tif ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {\n-\t\tput_pid(ctx->glpid);\n \t\tput_pid(ctx->pid);\n-\t\tctx->glpid = ctx->pid = NULL;\n+\t\tctx->pid = NULL;\n \t\tcxl_adapter_context_put(ctx->afu->adapter);\n \t\tcxl_ctx_put();\n+\t\tif (task)\n+\t\t\tcxl_context_mm_count_put(ctx);\n \t\tgoto out;\n \t}\n \ndiff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c\nindex 062bf6c..2e935ea 100644\n--- a/drivers/misc/cxl/context.c\n+++ b/drivers/misc/cxl/context.c\n@@ -17,6 +17,7 @@\n #include <linux/debugfs.h>\n #include <linux/slab.h>\n #include <linux/idr.h>\n+#include <linux/sched/mm.h>\n #include <asm/cputable.h>\n #include <asm/current.h>\n #include <asm/copro.h>\n@@ -41,7 +42,7 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master)\n \tspin_lock_init(&ctx->sste_lock);\n \tctx->afu = afu;\n \tctx->master = master;\n-\tctx->pid = ctx->glpid = NULL; /* Set in start work ioctl */\n+\tctx->pid = NULL; /* Set in start work ioctl */\n \tmutex_init(&ctx->mapping_lock);\n \tctx->mapping = NULL;\n \n@@ -242,12 +243,16 @@ int __detach_context(struct cxl_context *ctx)\n \n \t/* release the reference to the group leader and mm handling pid */\n \tput_pid(ctx->pid);\n-\tput_pid(ctx->glpid);\n \n \tcxl_ctx_put();\n \n \t/* Decrease the attached context count on the adapter */\n \tcxl_adapter_context_put(ctx->afu->adapter);\n+\n+\t/* Decrease the mm count on the context */\n+\tcxl_context_mm_count_put(ctx);\n+\tctx->mm = NULL;\n+\n \treturn 0;\n }\n \n@@ -325,3 +330,15 @@ void cxl_context_free(struct cxl_context *ctx)\n \tmutex_unlock(&ctx->afu->contexts_lock);\n \tcall_rcu(&ctx->rcu, reclaim_ctx);\n }\n+\n+void cxl_context_mm_count_get(struct cxl_context *ctx)\n+{\n+\tif (ctx->mm)\n+\t\tatomic_inc(&ctx->mm->mm_count);\n+}\n+\n+void cxl_context_mm_count_put(struct cxl_context *ctx)\n+{\n+\tif (ctx->mm)\n+\t\tmmdrop(ctx->mm);\n+}\ndiff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h\nindex 2bbe077..d8282e4 100644\n--- a/drivers/misc/cxl/cxl.h\n+++ b/drivers/misc/cxl/cxl.h\n@@ -482,8 +482,6 @@ struct cxl_context {\n \tunsigned int sst_size, sst_lru;\n \n \twait_queue_head_t wq;\n-\t/* pid of the group leader associated with the pid */\n-\tstruct pid *glpid;\n \t/* use mm context associated with this pid for ds faults */\n \tstruct pid *pid;\n \tspinlock_t lock; /* Protects pending_irq_mask, pending_fault and fault_addr */\n@@ -551,6 +549,8 @@ struct cxl_context {\n \t * CX4 only:\n \t */\n \tstruct list_head extra_irq_contexts;\n+\n+\tstruct mm_struct *mm;\n };\n \n struct cxl_service_layer_ops {\n@@ -1025,4 +1025,13 @@ int cxl_adapter_context_lock(struct cxl *adapter);\n /* Unlock the contexts-lock if taken. Warn and force unlock otherwise */\n void cxl_adapter_context_unlock(struct cxl *adapter);\n \n+/* Increases the reference count to \"struct mm_struct\" */\n+void cxl_context_mm_count_get(struct cxl_context *ctx);\n+\n+/* Decrements the reference count to \"struct mm_struct\" */\n+void cxl_context_mm_count_put(struct cxl_context *ctx);\n+\n+/* Increases the reference users to \"struct mm_struct\" */\n+void cxl_context_mm_users_get(struct cxl_context *ctx);\n+\n #endif\ndiff --git a/drivers/misc/cxl/fault.c b/drivers/misc/cxl/fault.c\nindex 2fa015c..cf8488b 100644\n--- a/drivers/misc/cxl/fault.c\n+++ b/drivers/misc/cxl/fault.c\n@@ -170,81 +170,18 @@ static void cxl_handle_page_fault(struct cxl_context *ctx,\n }\n \n /*\n- * Returns the mm_struct corresponding to the context ctx via ctx->pid\n- * In case the task has exited we use the task group leader accessible\n- * via ctx->glpid to find the next task in the thread group that has a\n- * valid mm_struct associated with it. If a task with valid mm_struct\n- * is found the ctx->pid is updated to use the task struct for subsequent\n- * translations. In case no valid mm_struct is found in the task group to\n- * service the fault a NULL is returned.\n+ * Returns the mm_struct corresponding to the context ctx.\n+ * mm_users == 0, the context may be in the process of being closed.\n */\n static struct mm_struct *get_mem_context(struct cxl_context *ctx)\n {\n-\tstruct task_struct *task = NULL;\n-\tstruct mm_struct *mm = NULL;\n-\tstruct pid *old_pid = ctx->pid;\n-\n-\tif (old_pid == NULL) {\n-\t\tpr_warn(\"%s: Invalid context for pe=%d\\n\",\n-\t\t\t __func__, ctx->pe);\n+\tif (ctx->mm == NULL)\n \t\treturn NULL;\n-\t}\n-\n-\ttask = get_pid_task(old_pid, PIDTYPE_PID);\n-\n-\t/*\n-\t * pid_alive may look racy but this saves us from costly\n-\t * get_task_mm when the task is a zombie. In worst case\n-\t * we may think a task is alive, which is about to die\n-\t * but get_task_mm will return NULL.\n-\t */\n-\tif (task != NULL && pid_alive(task))\n-\t\tmm = get_task_mm(task);\n \n-\t/* release the task struct that was taken earlier */\n-\tif (task)\n-\t\tput_task_struct(task);\n-\telse\n-\t\tpr_devel(\"%s: Context owning pid=%i for pe=%i dead\\n\",\n-\t\t\t__func__, pid_nr(old_pid), ctx->pe);\n-\n-\t/*\n-\t * If we couldn't find the mm context then use the group\n-\t * leader to iterate over the task group and find a task\n-\t * that gives us mm_struct.\n-\t */\n-\tif (unlikely(mm == NULL && ctx->glpid != NULL)) {\n-\n-\t\trcu_read_lock();\n-\t\ttask = pid_task(ctx->glpid, PIDTYPE_PID);\n-\t\tif (task)\n-\t\t\tdo {\n-\t\t\t\tmm = get_task_mm(task);\n-\t\t\t\tif (mm) {\n-\t\t\t\t\tctx->pid = get_task_pid(task,\n-\t\t\t\t\t\t\t\tPIDTYPE_PID);\n-\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t\ttask = next_thread(task);\n-\t\t\t} while (task && !thread_group_leader(task));\n-\t\trcu_read_unlock();\n-\n-\t\t/* check if we switched pid */\n-\t\tif (ctx->pid != old_pid) {\n-\t\t\tif (mm)\n-\t\t\t\tpr_devel(\"%s:pe=%i switch pid %i->%i\\n\",\n-\t\t\t\t\t __func__, ctx->pe, pid_nr(old_pid),\n-\t\t\t\t\t pid_nr(ctx->pid));\n-\t\t\telse\n-\t\t\t\tpr_devel(\"%s:Cannot find mm for pid=%i\\n\",\n-\t\t\t\t\t __func__, pid_nr(old_pid));\n-\n-\t\t\t/* drop the reference to older pid */\n-\t\t\tput_pid(old_pid);\n-\t\t}\n-\t}\n+\tif (!atomic_inc_not_zero(&ctx->mm->mm_users))\n+\t\treturn ctx->mm;\n \n-\treturn mm;\n+\treturn NULL;\n }\n \n \n@@ -282,7 +219,6 @@ void cxl_handle_fault(struct work_struct *fault_work)\n \tif (!ctx->kernel) {\n \n \t\tmm = get_mem_context(ctx);\n-\t\t/* indicates all the thread in task group have exited */\n \t\tif (mm == NULL) {\n \t\t\tpr_devel(\"%s: unable to get mm for pe=%d pid=%i\\n\",\n \t\t\t\t __func__, ctx->pe, pid_nr(ctx->pid));\ndiff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c\nindex e7139c7..17b433f 100644\n--- a/drivers/misc/cxl/file.c\n+++ b/drivers/misc/cxl/file.c\n@@ -18,6 +18,7 @@\n #include <linux/fs.h>\n #include <linux/mm.h>\n #include <linux/slab.h>\n+#include <linux/sched/mm.h>\n #include <asm/cputable.h>\n #include <asm/current.h>\n #include <asm/copro.h>\n@@ -216,8 +217,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,\n \t * process is still accessible.\n \t */\n \tctx->pid = get_task_pid(current, PIDTYPE_PID);\n-\tctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID);\n \n+\t/* acquire a reference to the task's mm */\n+\tctx->mm = get_task_mm(current);\n+\n+\t/* ensure this mm_struct can't be freed */\n+\tcxl_context_mm_count_get(ctx);\n+\n+\t/* decrement the use count */\n+\tif (ctx->mm)\n+\t\tmmput(ctx->mm);\n \n \ttrace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);\n \n@@ -225,9 +234,9 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,\n \t\t\t\t\t\t\tamr))) {\n \t\tafu_release_irqs(ctx, ctx);\n \t\tcxl_adapter_context_put(ctx->afu->adapter);\n-\t\tput_pid(ctx->glpid);\n \t\tput_pid(ctx->pid);\n-\t\tctx->glpid = ctx->pid = NULL;\n+\t\tctx->pid = NULL;\n+\t\tcxl_context_mm_count_put(ctx);\n \t\tgoto out;\n \t}\n \ndiff --git a/drivers/misc/cxl/main.c b/drivers/misc/cxl/main.c\nindex b0b6ed3..1703655 100644\n--- a/drivers/misc/cxl/main.c\n+++ b/drivers/misc/cxl/main.c\n@@ -59,16 +59,10 @@ int cxl_afu_slbia(struct cxl_afu *afu)\n \n static inline void _cxl_slbia(struct cxl_context *ctx, struct mm_struct *mm)\n {\n-\tstruct task_struct *task;\n \tunsigned long flags;\n-\tif (!(task = get_pid_task(ctx->pid, PIDTYPE_PID))) {\n-\t\tpr_devel(\"%s unable to get task %i\\n\",\n-\t\t\t __func__, pid_nr(ctx->pid));\n-\t\treturn;\n-\t}\n \n-\tif (task->mm != mm)\n-\t\tgoto out_put;\n+\tif (ctx->mm != mm)\n+\t\treturn;\n \n \tpr_devel(\"%s matched mm - card: %i afu: %i pe: %i\\n\", __func__,\n \t\t ctx->afu->adapter->adapter_num, ctx->afu->slice, ctx->pe);\n@@ -79,8 +73,6 @@ static inline void _cxl_slbia(struct cxl_context *ctx, struct mm_struct *mm)\n \tspin_unlock_irqrestore(&ctx->sste_lock, flags);\n \tmb();\n \tcxl_afu_slbia(ctx->afu);\n-out_put:\n-\tput_task_struct(task);\n }\n \n static inline void cxl_slbia_core(struct mm_struct *mm)\n", "prefixes": [ "V3", "3/7" ] }