{"id":806361,"url":"http://patchwork.ozlabs.org/api/1.0/patches/806361/?format=json","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/1.0/projects/2/?format=json","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/"},"msgid":"<20170828041555.3342-1-vaibhav@linux.vnet.ibm.com>","date":"2017-08-28T04:15:55","name":"[RFC] cxl: Enable use of custom PE-id for contexts","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"1ed05b23c80d0ce4fb74768e632407b87390b32d","submitter":{"id":66174,"url":"http://patchwork.ozlabs.org/api/1.0/people/66174/?format=json","name":"Vaibhav Jain","email":"vaibhav@linux.vnet.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20170828041555.3342-1-vaibhav@linux.vnet.ibm.com/mbox/","series":[{"id":67,"url":"http://patchwork.ozlabs.org/api/1.0/series/67/?format=json","date":"2017-08-28T04:15:55","name":"[RFC] cxl: Enable use of custom PE-id for contexts","version":1,"mbox":"http://patchwork.ozlabs.org/series/67/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/806361/checks/","tags":{},"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 3xgdlh6YqQz9sNc\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon, 28 Aug 2017 14:17:36 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xgdlh5hbjzDqYw\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon, 28 Aug 2017 14:17:36 +1000 (AEST)","from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com\n\t[148.163.156.1])\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 3xgdkH4g86zDqNc\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tMon, 28 Aug 2017 14:16:23 +1000 (AEST)","from pps.filterd (m0098410.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv7S4Daxf043650\n\tfor <linuxppc-dev@lists.ozlabs.org>; Mon, 28 Aug 2017 00:16:21 -0400","from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2cm2rphdu4-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Mon, 28 Aug 2017 00:16:20 -0400","from localhost\n\tby e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from <vaibhav@linux.vnet.ibm.com>;\n\tMon, 28 Aug 2017 14:16:18 +1000","from d23relay09.au.ibm.com (202.81.31.228)\n\tby e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tMon, 28 Aug 2017 14:16:16 +1000","from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\n\tby d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id\n\tv7S4GFIL42336418\n\tfor <linuxppc-dev@lists.ozlabs.org>; Mon, 28 Aug 2017 14:16:15 +1000","from d23av04.au.ibm.com (localhost [127.0.0.1])\n\tby d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id\n\tv7S4GFEc020554\n\tfor <linuxppc-dev@lists.ozlabs.org>; Mon, 28 Aug 2017 14:16:16 +1000","from vajain21.in.ibm.com ([9.77.80.146])\n\tby d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id\n\tv7S4GDDi020514; Mon, 28 Aug 2017 14:16:14 +1000"],"From":"Vaibhav Jain <vaibhav@linux.vnet.ibm.com>","To":"linuxppc-dev@lists.ozlabs.org,\n\tFrederic Barrat <fbarrat@linux.vnet.ibm.com>","Subject":"[RFC] cxl: Enable use of custom PE-id for contexts","Date":"Mon, 28 Aug 2017 09:45:55 +0530","X-Mailer":"git-send-email 2.13.5","X-TM-AS-MML":"disable","x-cbid":"17082804-0008-0000-0000-0000015492AD","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17082804-0009-0000-0000-0000098791B6","Message-Id":"<20170828041555.3342-1-vaibhav@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-08-28_01:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=0\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1708280067","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>","Cc":"Philippe Bergheaud <philippe.bergheaud@fr.ibm.com>,\n\tAlastair D'Silva <alastair@au1.ibm.com>,\n\tVaibhav Jain <vaibhav@linux.vnet.ibm.com>,\n\tAndrew Donnellan <andrew.donnellan@au1.ibm.com>,\n\tChristophe Lombard <christophe_lombard@fr.ibm.com>","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":"Some AFUs differentiate between multiple PE's based on their\nPE-ids. Unfortunately presently cxl provides no way for external\nusers (libcxl/kernel-api) to control the id assigned to a specific\nPE. The ids are currently assigned serially to PE's and are dolled out\nusing an idr table.\n\nWith this patch external users of the cxl api can request a specific\n__u16 peid to be used when issuing CXL_IOCTL_START_WORK or calling\ncxl_start_context(). Struct cxl_ioctl_start_work has a new member named\nuse_pe that can be used to provide the PE-id to be used. Also a new\nCXL_START_WORK flag named CXL_START_WORK_CUSTOM_PE has been introduced\nto indicated to cxl to try to switch the PE-id of the context to the\nvalue provided in use_pe before attaching the context to the AFU.\n\nThe switching of context PE-id is done by inserting the\nsame context with the requested PE-id from struct cxl_ioctl_start_work\nand removing the previously allocated PE-id from the afu->contexts_idr\ntable. In case an existing context with the requested PE-id already\nexists the first step above will fail causing the context attach to\nabort and an error is returned back to caller.\n\nSigned-off-by: Vaibhav Jain <vaibhav@linux.vnet.ibm.com>\n---\n drivers/misc/cxl/api.c     |  7 ++++++\n drivers/misc/cxl/context.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++\n drivers/misc/cxl/cxl.h     |  3 +++\n drivers/misc/cxl/file.c    | 12 ++++++++--\n include/uapi/misc/cxl.h    |  9 ++++----\n 5 files changed, 80 insertions(+), 6 deletions(-)","diff":"diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c\nindex 1a138c83f877..3c34f486a0ce 100644\n--- a/drivers/misc/cxl/api.c\n+++ b/drivers/misc/cxl/api.c\n@@ -505,6 +505,13 @@ int cxl_start_work(struct cxl_context *ctx,\n {\n \tint rc;\n \n+\t/* If requesting a custom PE id ? */\n+\tif (work->flags & CXL_START_WORK_CUSTOM_PE) {\n+\t\trc = cxl_context_switch_pe(ctx, work->use_pe);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t}\n+\n \t/* code taken from afu_ioctl_start_work */\n \tif (!(work->flags & CXL_START_WORK_NUM_IRQS))\n \t\twork->num_interrupts = ctx->afu->pp_irqs;\ndiff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c\nindex 8c32040b9c09..3699891a84be 100644\n--- a/drivers/misc/cxl/context.c\n+++ b/drivers/misc/cxl/context.c\n@@ -117,6 +117,61 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master)\n \treturn 0;\n }\n \n+/*\n+ * Switch the PE# if context ctx to newpe\n+ */\n+int cxl_context_switch_pe(struct cxl_context *ctx, __u16 newpe)\n+{\n+\tint rc, oldpe = 0;\n+\n+\tpr_debug(\"Switching PE#%u to PE#%u\\n\", ctx->pe, newpe);\n+\t/* Assigning custom PE only supported on bare-metal right now */\n+\tif (!cpu_has_feature(CPU_FTR_HVMODE)) {\n+\t\tpr_err(\"Assigning custom PE# only supported on bare metal\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Silently ignore if newpe == ctx->pe */\n+\tif (newpe ==  ctx->pe)\n+\t\treturn 0;\n+\n+\t/* Bunch of sanity validations */\n+\tif (newpe < ctx->afu->adapter->min_pe ||\n+\t    newpe >= (ctx->afu->adapter->min_pe + ctx->afu->num_procs)) {\n+\t\tpr_debug(\"Cant assign out of range PE#%u\\n\", newpe);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (ctx->pe_inserted) {\n+\t\tpr_debug(\"Cant switch PE for attached PE#%u\\n\", ctx->pe);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* serialize access to the idr table */\n+\tmutex_lock(&ctx->afu->contexts_lock);\n+\tidr_preload(GFP_KERNEL);\n+\trc = idr_alloc(&ctx->afu->contexts_idr, ctx, newpe, newpe + 1,\n+\t\t       GFP_NOWAIT);\n+\t/* if successful allocation then remove the existing idr entry */\n+\tif (rc >= 0) {\n+\t\tidr_remove(&ctx->afu->contexts_idr, ctx->pe);\n+\t\toldpe = ctx->pe;\n+\t\tctx->pe = newpe;\n+\t\tctx->external_pe = ctx->pe;\n+\t\tctx->elem = &ctx->afu->native->spa[newpe];\n+\t}\n+\tidr_preload_end();\n+\tmutex_unlock(&ctx->afu->contexts_lock);\n+\n+\tif (rc >= 0)\n+\t\tpr_debug(\"Switched PE#%u -> PE%u\\n\", oldpe, ctx->pe);\n+\telse\n+\t\tpr_debug(\"Unable to switch PE#%u->PE%u. Error=%d\\n\",\n+\t\t\t oldpe, ctx->pe, rc);\n+\n+\treturn rc >= 0 ? 0 : rc;\n+}\n+\n void cxl_context_set_mapping(struct cxl_context *ctx,\n \t\t\tstruct address_space *mapping)\n {\ndiff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h\nindex b1afeccbb97f..6d7c0accb30e 100644\n--- a/drivers/misc/cxl/cxl.h\n+++ b/drivers/misc/cxl/cxl.h\n@@ -1171,4 +1171,7 @@ void cxl_context_mm_count_get(struct cxl_context *ctx);\n /* Decrements the reference count to \"struct mm_struct\" */\n void cxl_context_mm_count_put(struct cxl_context *ctx);\n \n+/* Switch the PE# of given context ctx to newpe */\n+int cxl_context_switch_pe(struct cxl_context *ctx, __u16 newpe);\n+\n #endif\ndiff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c\nindex 0761271d68c5..7ae7020aa062 100644\n--- a/drivers/misc/cxl/file.c\n+++ b/drivers/misc/cxl/file.c\n@@ -173,12 +173,20 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,\n \t * flags are set it's invalid\n \t */\n \tif (work.reserved1 || work.reserved2 || work.reserved3 ||\n-\t    work.reserved4 || work.reserved5 || work.reserved6 ||\n-\t    (work.flags & ~CXL_START_WORK_ALL)) {\n+\t    work.reserved4 || work.reserved5 ||\n+\t    ((work.flags & ~CXL_START_WORK_ALL) &&\n+\t     !(work.flags & CXL_START_WORK_CUSTOM_PE))) {\n \t\trc = -EINVAL;\n \t\tgoto out;\n \t}\n \n+\t/* If requesting a custom PE id ? */\n+\tif (work.flags & CXL_START_WORK_CUSTOM_PE) {\n+\t\trc = cxl_context_switch_pe(ctx, work.use_pe);\n+\t\tif (rc)\n+\t\t\tgoto out;\n+\t}\n+\n \tif (!(work.flags & CXL_START_WORK_NUM_IRQS))\n \t\twork.num_interrupts = ctx->afu->pp_irqs;\n \telse if ((work.num_interrupts < ctx->afu->pp_irqs) ||\ndiff --git a/include/uapi/misc/cxl.h b/include/uapi/misc/cxl.h\nindex 180d526a55c3..0d585dc46369 100644\n--- a/include/uapi/misc/cxl.h\n+++ b/include/uapi/misc/cxl.h\n@@ -19,18 +19,19 @@ struct cxl_ioctl_start_work {\n \t__u64 work_element_descriptor;\n \t__u64 amr;\n \t__s16 num_interrupts;\n-\t__s16 reserved1;\n-\t__s32 reserved2;\n+\t__u16 use_pe;\n+\t__s32 reserved1;\n+\t__u64 reserved2;\n \t__u64 reserved3;\n \t__u64 reserved4;\n \t__u64 reserved5;\n-\t__u64 reserved6;\n };\n \n #define CXL_START_WORK_AMR\t\t0x0000000000000001ULL\n #define CXL_START_WORK_NUM_IRQS\t\t0x0000000000000002ULL\n #define CXL_START_WORK_ERR_FF\t\t0x0000000000000004ULL\n-#define CXL_START_WORK_ALL\t\t(CXL_START_WORK_AMR |\\\n+#define CXL_START_WORK_CUSTOM_PE\t0x0000000000000008ULL\n+#define CXL_START_WORK_ALL\t\t(CXL_START_WORK_AMR |\t\t\\\n \t\t\t\t\t CXL_START_WORK_NUM_IRQS |\\\n \t\t\t\t\t CXL_START_WORK_ERR_FF)\n \n","prefixes":["RFC"]}