From patchwork Mon Jan 27 04:42:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13950978 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 097D9157A48; Mon, 27 Jan 2025 04:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952980; cv=none; b=rwPZBNBJPrU82sNbdlaey1V2aA63ojp8WuTZVj6O5DePrlzJ/c43JnWqmbc/0UhWT1lHu9pObK0KUNgQmJhL/u1QPlk0wylc4QOXUKYgmmqfaXC3iPyJacvINlrAl/RtGCL+9ILl0w1QZ/j5iBLaeKlXi57UyzKfipvdGXdg/Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952980; c=relaxed/simple; bh=nb3gxqfjehK8j9+f936KyZBtrrxirkGeV3LQ5DNa2PU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iU18C3LOjbC2F61qLrvjjqbhj94SV7c0r4mAicya8XqM+l82eBsQKLXcwN41Y7m4Ov9rWvi4WSqc65OZRPtDqamiCqoMXr2zHZApq8BF23NojFkjH/3EhWvhLjECxZ4YE1kIsT3lIZMQQtGSXcgpmbPpu6CFTg8XlssaET3EM8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=AGdtN0n0; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="AGdtN0n0" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50R0xoQO031640; Mon, 27 Jan 2025 04:42:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 3OFm/qjrJDZTukJBcvS7s/C4ec+K6ntJXkwtdBSQAiA=; b=AGdtN0n0AYMEj59R lZS5AUBcAMAKgxJvQxOQdQs/Wd49ZfkfoGdCVzC2z/G8qjjdWeaET1gmmGGLzLFY pDw5XlX/ajJS6lRfCkwY6K5jQ9cy6Df12ZsIggiiiVpwKaQVYqSilKYcDsaTCA99 Qx66UrtsVT4DhSAOAha4t84U3Ywg9imO+Y1H5LKVvAJ1+kPkhy5bb1nmeCjkeccR zkKwjXXtS885OqmdyyF+gDg5dNlFl450m+MabCFp6F9TvDV+jpjHdqBnBAJ4Yu29 wVxscd7N3HGsOIgTlwjbVoV+mWmBtyNx46zvNuHah852n9onrPzG6zmXxHIzWCNe 4/XJCQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44dhu9h4f5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:42:53 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50R4grWl015812 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:42:53 GMT Received: from hu-ekangupt-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 26 Jan 2025 20:42:50 -0800 From: Ekansh Gupta To: , CC: , , , , , Subject: [PATCH v2 1/5] misc: fastrpc: Move fdlist to invoke context structure Date: Mon, 27 Jan 2025 10:12:35 +0530 Message-ID: <20250127044239.578540-2-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250127044239.578540-1-quic_ekangupt@quicinc.com> References: <20250127044239.578540-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: vD5wIzdKAvKD4XD-XzbIFbjTZ5Gfd2TD X-Proofpoint-ORIG-GUID: vD5wIzdKAvKD4XD-XzbIFbjTZ5Gfd2TD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_01,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 phishscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501270036 FD list is part of meta buffer which is calulated during put args. Move fdlist to invoke context structure for better maintenance and to avoid code duplicacy for calculation of critcal meta buffer contents that are used by fastrpc driver. Signed-off-by: Ekansh Gupta Reviewed-by: Dmitry Baryshkov --- drivers/misc/fastrpc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 42b4d60c224c..1a936d462519 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -236,6 +236,7 @@ struct fastrpc_invoke_ctx { int pid; int client_id; u32 sc; + u64 *fdlist; u32 *crc; u64 ctxid; u64 msg_sz; @@ -965,6 +966,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) rpra = ctx->buf->virt; list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages = fastrpc_phy_page_start(list, ctx->nscalars); + ctx->fdlist = (u64 *)(pages + ctx->nscalars); args = (uintptr_t)ctx->buf->virt + metalen; rlen = pkt_size - metalen; ctx->rpra = rpra; @@ -1067,17 +1069,9 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, union fastrpc_remote_arg *rpra = ctx->rpra; struct fastrpc_user *fl = ctx->fl; struct fastrpc_map *mmap = NULL; - struct fastrpc_invoke_buf *list; - struct fastrpc_phy_page *pages; - u64 *fdlist; - int i, inbufs, outbufs, handles; + int i, inbufs; inbufs = REMOTE_SCALARS_INBUFS(ctx->sc); - outbufs = REMOTE_SCALARS_OUTBUFS(ctx->sc); - handles = REMOTE_SCALARS_INHANDLES(ctx->sc) + REMOTE_SCALARS_OUTHANDLES(ctx->sc); - list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); - pages = fastrpc_phy_page_start(list, ctx->nscalars); - fdlist = (uint64_t *)(pages + inbufs + outbufs + handles); for (i = inbufs; i < ctx->nbufs; ++i) { if (!ctx->maps[i]) { @@ -1096,9 +1090,9 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, /* Clean up fdlist which is updated by DSP */ for (i = 0; i < FASTRPC_MAX_FDLIST; i++) { - if (!fdlist[i]) + if (!ctx->fdlist[i]) break; - if (!fastrpc_map_lookup(fl, (int)fdlist[i], &mmap, false)) + if (!fastrpc_map_lookup(fl, (int)ctx->fdlist[i], &mmap, false)) fastrpc_map_put(mmap); } From patchwork Mon Jan 27 04:42:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13950979 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6173B1FC7C6; Mon, 27 Jan 2025 04:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952983; cv=none; b=eVc91BeYCW4GWz7K0hnYiBbBhpjKxCUthwVrI/bxP05fMNVsTJuan/Dabuh30MAB+DkN34B0GOTy9awwANjdMAV64Uu3yp0eT5FGqA3VwofM+4BBH4ffDmnM1+J7oP9iFXkyY2Y3v8V4YXUvOpH5ECRVp+tPAqHB3U/vg5F8Q0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952983; c=relaxed/simple; bh=vuRgpROWghXtWenx5vHBr1eRxS/uv8LyJEn2NdMPlKw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BEDhjDSLks8B6KmpE3vJeL7WwjXRll2JS8xhUBn/2XZMdheq2u2xz8EKNNKVqFFhlEGWN1efno7Ak4AaZ9mJflVkhdhcsLjvCVaut5wsd3a/g+u5gjvbtjRGXy6bnHikUvwr1fawMR3lHLERVIPyDrPI1xvovE5KkPoBHnVtqzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=NAqdDcK+; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NAqdDcK+" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50R3TZ5P002702; Mon, 27 Jan 2025 04:42:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 7UwtQjBvoB+Dr3S9lh/xSyWx3AKsKVeEuZg0qEXzaSc=; b=NAqdDcK+AKp+zQ5Z LaHG5fFVHvgF8KeVaheJeAxZc0Eub73Zk4KUoQiYrKfFgjBEogUqHvzJFbv2ygxW Tfmpq0oI6YHcG9fmsvmyq+DIIiVXWDvTPwP0d0TMitiyaTRFHE7PwAwk4fOkyeyH d3iF0rESq8pQwjKDtPE2M4uuqiNXRVnGPtm6z1SKftxigFy7KzKFzWeKu4XWWZkX RHfWbfMOt9MRQBo1gQuIp53SAanrgzghtUwq+EFll+JDYoPIqlmfVlsi0bjXa93F FE1MT4sMzue5Y06PS8UDP76cMP4oIlFVK1HYXuioMBpGxYlxb384iY7PAlTqHkVU jBGWeg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44e29883en-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:42:56 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50R4gupw030078 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:42:56 GMT Received: from hu-ekangupt-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 26 Jan 2025 20:42:53 -0800 From: Ekansh Gupta To: , CC: , , , , , Subject: [PATCH v2 2/5] misc: fastrpc: Introduce context params structure Date: Mon, 27 Jan 2025 10:12:36 +0530 Message-ID: <20250127044239.578540-3-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250127044239.578540-1-quic_ekangupt@quicinc.com> References: <20250127044239.578540-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: dJFFFWpOo40LmHrOzFNGqNhGV9XsisfD X-Proofpoint-ORIG-GUID: dJFFFWpOo40LmHrOzFNGqNhGV9XsisfD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_01,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 adultscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501270036 Add structure to invoke context parameterms. This structure is meant to carry invoke context specific data. This structure is passed to internal invocation call to save the data in context. Examples of data intended to part of this structure are: CRC user memory address, poll timeout for invoke call, call priority etc. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 138 ++++++++++++++++++++++++++++++++++------- 1 file changed, 117 insertions(+), 21 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 1a936d462519..c29d5536195e 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -254,6 +254,11 @@ struct fastrpc_invoke_ctx { struct fastrpc_channel_ctx *cctx; }; +struct fastrpc_ctx_args { + struct fastrpc_invoke_args *args; + void __user *crc; +}; + struct fastrpc_session_ctx { struct device *dev; int sid; @@ -574,7 +579,7 @@ static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx) static struct fastrpc_invoke_ctx *fastrpc_context_alloc( struct fastrpc_user *user, u32 kernel, u32 sc, - struct fastrpc_invoke_args *args) + struct fastrpc_ctx_args *cargs) { struct fastrpc_channel_ctx *cctx = user->cctx; struct fastrpc_invoke_ctx *ctx = NULL; @@ -605,7 +610,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( kfree(ctx); return ERR_PTR(-ENOMEM); } - ctx->args = args; + ctx->args = cargs->args; fastrpc_get_buff_overlaps(ctx); } @@ -1133,7 +1138,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, u32 handle, u32 sc, - struct fastrpc_invoke_args *args) + struct fastrpc_ctx_args *cargs) { struct fastrpc_invoke_ctx *ctx = NULL; struct fastrpc_buf *buf, *b; @@ -1151,7 +1156,7 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, return -EPERM; } - ctx = fastrpc_context_alloc(fl, kernel, sc, args); + ctx = fastrpc_context_alloc(fl, kernel, sc, cargs); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1233,6 +1238,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, { struct fastrpc_init_create_static init; struct fastrpc_invoke_args *args; + struct fastrpc_ctx_args *cargs; struct fastrpc_phy_page pages[1]; char *name; int err; @@ -1307,15 +1313,25 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, args[2].length = sizeof(*pages); args[2].fd = -1; + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) { + err = -ENOMEM; + goto err_invoke; + } + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_STATIC, 3, 0); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, - sc, args); - if (err) + sc, cargs); + if (err) { + kfree(cargs); goto err_invoke; + } kfree(args); kfree(name); + kfree(cargs); return 0; err_invoke: @@ -1351,6 +1367,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, { struct fastrpc_init_create init; struct fastrpc_invoke_args *args; + struct fastrpc_ctx_args *cargs; struct fastrpc_phy_page pages[1]; struct fastrpc_map *map = NULL; struct fastrpc_buf *imem = NULL; @@ -1438,16 +1455,26 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, args[5].length = sizeof(inbuf.siglen); args[5].fd = -1; + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) { + err = -ENOMEM; + goto err_invoke; + } + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE, 4, 0); if (init.attrs) sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_ATTR, 4, 0); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, - sc, args); - if (err) + sc, cargs); + if (err) { + kfree(cargs); goto err_invoke; + } kfree(args); + kfree(cargs); return 0; @@ -1498,17 +1525,27 @@ static void fastrpc_session_free(struct fastrpc_channel_ctx *cctx, static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl) { struct fastrpc_invoke_args args[1]; - int client_id = 0; + struct fastrpc_ctx_args *cargs; + int client_id = 0, err; u32 sc; client_id = fl->client_id; args[0].ptr = (u64)(uintptr_t) &client_id; args[0].length = sizeof(client_id); args[0].fd = -1; + + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_RELEASE, 1, 0); - return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, - sc, &args[0]); + err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, cargs); + kfree(cargs); + + return err; } static int fastrpc_device_release(struct inode *inode, struct file *file) @@ -1643,22 +1680,33 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp) static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) { struct fastrpc_invoke_args args[1]; - int client_id = fl->client_id; + struct fastrpc_ctx_args *cargs; + int client_id = fl->client_id, err; u32 sc; args[0].ptr = (u64)(uintptr_t) &client_id; args[0].length = sizeof(client_id); args[0].fd = -1; + + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0); fl->pd = pd; - return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, - sc, &args[0]); + err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, cargs); + kfree(cargs); + + return err; } static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_invoke_args *args = NULL; + struct fastrpc_ctx_args *cargs; struct fastrpc_invoke inv; u32 nscalars; int err; @@ -1679,9 +1727,16 @@ static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) return -EFAULT; } } + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) { + kfree(args); + return -ENOMEM; + } - err = fastrpc_internal_invoke(fl, false, inv.handle, inv.sc, args); + cargs->args = args; + err = fastrpc_internal_invoke(fl, false, inv.handle, inv.sc, cargs); kfree(args); + kfree(cargs); return err; } @@ -1690,6 +1745,8 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_user *fl, uint32_t *dsp_attr uint32_t dsp_attr_buf_len) { struct fastrpc_invoke_args args[2] = { 0 }; + struct fastrpc_ctx_args *cargs; + int err; /* * Capability filled in userspace. This carries the information @@ -1706,8 +1763,15 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_user *fl, uint32_t *dsp_attr args[1].length = dsp_attr_buf_len * sizeof(u32); args[1].fd = -1; - return fastrpc_internal_invoke(fl, true, FASTRPC_DSP_UTILITIES_HANDLE, - FASTRPC_SCALARS(0, 1, 1), args); + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; + err = fastrpc_internal_invoke(fl, true, FASTRPC_DSP_UTILITIES_HANDLE, + FASTRPC_SCALARS(0, 1, 1), cargs); + kfree(cargs); + return err; } static int fastrpc_get_info_from_kernel(struct fastrpc_ioctl_capability *cap, @@ -1794,6 +1858,7 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp) static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; + struct fastrpc_ctx_args *cargs; struct fastrpc_munmap_req_msg req_msg; struct device *dev = fl->sctx->dev; int err; @@ -1806,9 +1871,14 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf * args[0].ptr = (u64) (uintptr_t) &req_msg; args[0].length = sizeof(req_msg); + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MUNMAP, 1, 0); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, - &args[0]); + cargs); if (!err) { dev_dbg(dev, "unmmap\tpt 0x%09lx OK\n", buf->raddr); spin_lock(&fl->lock); @@ -1818,6 +1888,7 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf * } else { dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr); } + kfree(cargs); return err; } @@ -1852,6 +1923,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_invoke_args args[3] = { [0 ... 2] = { 0 } }; + struct fastrpc_ctx_args *cargs; struct fastrpc_buf *buf = NULL; struct fastrpc_mmap_req_msg req_msg; struct fastrpc_mmap_rsp_msg rsp_msg; @@ -1902,12 +1974,18 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) args[2].ptr = (u64) (uintptr_t) &rsp_msg; args[2].length = sizeof(rsp_msg); + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MMAP, 2, 1); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, - &args[0]); + cargs); if (err) { dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size); fastrpc_buf_free(buf); + kfree(cargs); return err; } @@ -1942,17 +2020,20 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", buf->raddr, buf->size); + kfree(cargs); return 0; err_assign: fastrpc_req_munmap_impl(fl, buf); + kfree(cargs); return err; } static int fastrpc_req_mem_unmap_impl(struct fastrpc_user *fl, struct fastrpc_mem_unmap *req) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; + struct fastrpc_ctx_args *cargs; struct fastrpc_map *map = NULL, *iter, *m; struct fastrpc_mem_unmap_req_msg req_msg = { 0 }; int err = 0; @@ -1982,14 +2063,21 @@ static int fastrpc_req_mem_unmap_impl(struct fastrpc_user *fl, struct fastrpc_me args[0].ptr = (u64) (uintptr_t) &req_msg; args[0].length = sizeof(req_msg); + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_UNMAP, 1, 0); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, - &args[0]); + cargs); if (err) { dev_err(dev, "unmmap\tpt fd = %d, 0x%09llx error\n", map->fd, map->raddr); + kfree(cargs); return err; } fastrpc_map_put(map); + kfree(cargs); return 0; } @@ -2007,6 +2095,7 @@ static int fastrpc_req_mem_unmap(struct fastrpc_user *fl, char __user *argp) static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_invoke_args args[4] = { [0 ... 3] = { 0 } }; + struct fastrpc_ctx_args *cargs; struct fastrpc_mem_map_req_msg req_msg = { 0 }; struct fastrpc_mmap_rsp_msg rsp_msg = { 0 }; struct fastrpc_mem_unmap req_unmap = { 0 }; @@ -2051,8 +2140,13 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp) args[3].ptr = (u64) (uintptr_t) &rsp_msg; args[3].length = sizeof(rsp_msg); + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->args = args; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1); - err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]); + err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, cargs); if (err) { dev_err(dev, "mem mmap error, fd %d, vaddr %llx, size %lld\n", req.fd, req.vaddrin, map->size); @@ -2072,11 +2166,13 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp) fastrpc_req_mem_unmap_impl(fl, &req_unmap); return -EFAULT; } + kfree(cargs); return 0; err_invoke: fastrpc_map_put(map); + kfree(cargs); return err; } From patchwork Mon Jan 27 04:42:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13950980 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 518881FC7F4; Mon, 27 Jan 2025 04:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952985; cv=none; b=QTvO5J7LfM/djjlq0gFiOqndF+twZzNqRhzzX3Px2AN1l4si5BdpTf+nofhLqXHyDh1cU/O+29Efe/Muf8MzFlsurQFoCuiKbg/grFJilhGVHWU5IGBgaLjmJWVrHK+NQ7dHNzZy7SGY6WzVvwZKSxjZc4xoNSHVcxYSO3pSEd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952985; c=relaxed/simple; bh=YlNBtV+dfpY4zwt4Sk8VUvpyljafLN/0KNHePht557I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ka125OKjBNBDWjFG77j0W9XKW+QC0mgR6HRRVI5GvHQ5qQnLhjRQG+S0IzU5rS8T1TVVpoI28UxioQVDVGYySp8trfTEEwJNLrqgCr0JzDC/7Tdmqm59O2uUFi53sGc98n3/x+9iLKNcsyIIqftlP3CSnR8vfDKkPfYJ1gbaWx0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=VX1ovJ+C; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VX1ovJ+C" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50R2W54s016618; Mon, 27 Jan 2025 04:43:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= xsUVvHETE1rTl6Sv1OA46rXgILMWKsuzQBKnbzij/KM=; b=VX1ovJ+CIbPTtEFq 7EulEGf8PQyOP2WKlwrIQz+FNzWeIasl/e91nXFbizqGAn8o5/FBWkvSmui2n0C2 ySUfB8P/z/s5y2kzxVBgMrGPMUyk/PX73W3GKDEh2ExAVAcUmV9c8CIGEe5Wb1LA xyeSuXx5IrT/RII3/Z7YmlzePStTy378luy8B2atkQPCT6ceVUmEF1rSyavm9Ru/ azJ53ueGCDCOQmslIJpS0Bdt98cVtXapvgZ7H5l1POAbUimPeeZuoTBDwkkKXHH+ kkwhH5wA5xCNm7Cz/FfwIc7yOxPFPiTQt1Fg1fTGhxqAMqBrruHPOdKRDLjpWJ3F mQ55lQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44dgj1h7rv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:42:59 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50R4gxlx003009 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:42:59 GMT Received: from hu-ekangupt-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 26 Jan 2025 20:42:56 -0800 From: Ekansh Gupta To: , CC: , , , , , Subject: [PATCH v2 3/5] misc: fastrpc: Add CRC support using invokeV2 request Date: Mon, 27 Jan 2025 10:12:37 +0530 Message-ID: <20250127044239.578540-4-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250127044239.578540-1-quic_ekangupt@quicinc.com> References: <20250127044239.578540-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: RxBHmCAWq3vOLCCJa-GBxUFMjHk1csq1 X-Proofpoint-ORIG-GUID: RxBHmCAWq3vOLCCJa-GBxUFMjHk1csq1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_01,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501270035 InvokeV2 request is intended to support multiple enhanced invoke requests like CRC check, performance counter enablement and polling mode for RPC invocations. CRC check is getting enabled as part of this patch. CRC check for input and output argument helps in ensuring data consistency over a remote call. If user intends to enable CRC check, first local user CRC is calculated at user end and a CRC buffer is passed to DSP to capture remote CRC values. DSP is expected to write to the remote CRC buffer which is then compared at user level with the local CRC values. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 78 ++++++++++++++++++++++++++++++------- include/uapi/misc/fastrpc.h | 7 ++++ 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index c29d5536195e..cfacee0dded5 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -237,7 +237,8 @@ struct fastrpc_invoke_ctx { int client_id; u32 sc; u64 *fdlist; - u32 *crc; + u32 *crclist; + void __user *crc; u64 ctxid; u64 msg_sz; struct kref refcount; @@ -617,6 +618,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( /* Released in fastrpc_context_put() */ fastrpc_channel_ctx_get(cctx); + ctx->crc = cargs->crc; ctx->sc = sc; ctx->retval = -1; ctx->pid = current->pid; @@ -972,6 +974,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages = fastrpc_phy_page_start(list, ctx->nscalars); ctx->fdlist = (u64 *)(pages + ctx->nscalars); + ctx->crclist = (u32 *)(ctx->fdlist + FASTRPC_MAX_FDLIST); args = (uintptr_t)ctx->buf->virt + metalen; rlen = pkt_size - metalen; ctx->rpra = rpra; @@ -1101,6 +1104,12 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, fastrpc_map_put(mmap); } + if (ctx->crc && ctx->crclist && rpra) { + if (copy_to_user(ctx->crc, ctx->crclist, + FASTRPC_MAX_CRCLIST * sizeof(u32))) + return -EFAULT; + } + return 0; } @@ -1703,39 +1712,75 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) return err; } -static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) +static int fastrpc_remote_invoke(struct fastrpc_user *fl, struct fastrpc_invoke *inv, + struct fastrpc_ctx_args *cargs) { - struct fastrpc_invoke_args *args = NULL; - struct fastrpc_ctx_args *cargs; - struct fastrpc_invoke inv; + struct fastrpc_invoke_args *args; u32 nscalars; int err; - if (copy_from_user(&inv, argp, sizeof(inv))) - return -EFAULT; - /* nscalars is truncated here to max supported value */ - nscalars = REMOTE_SCALARS_LENGTH(inv.sc); + nscalars = REMOTE_SCALARS_LENGTH(inv->sc); if (nscalars) { args = kcalloc(nscalars, sizeof(*args), GFP_KERNEL); if (!args) return -ENOMEM; - if (copy_from_user(args, (void __user *)(uintptr_t)inv.args, + if (copy_from_user(args, (void __user *)(uintptr_t)inv->args, nscalars * sizeof(*args))) { kfree(args); return -EFAULT; } } + + cargs->args = args; + err = fastrpc_internal_invoke(fl, false, inv->handle, inv->sc, cargs); + kfree(args); + + return err; +} + +static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_ctx_args *cargs; + struct fastrpc_invoke inv; + int err; + + if (copy_from_user(&inv, argp, sizeof(inv))) + return -EFAULT; + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); - if (!cargs) { - kfree(args); + if (!cargs) return -ENOMEM; + + err = fastrpc_remote_invoke(fl, &inv, cargs); + kfree(cargs); + + return err; +} + +static int fastrpc_invokev2(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_ctx_args *cargs; + struct fastrpc_invoke_v2 inv2; + int i, err; + + if (copy_from_user(&inv2, argp, sizeof(inv2))) + return -EFAULT; + + /* Check if all reserved fields are zero */ + for (i = 0; i < 16; i++) { + if (inv2.reserved[i] != 0) + return -EINVAL; } - cargs->args = args; - err = fastrpc_internal_invoke(fl, false, inv.handle, inv.sc, cargs); - kfree(args); + cargs = kzalloc(sizeof(*cargs), GFP_KERNEL); + if (!cargs) + return -ENOMEM; + + cargs->crc = (void __user *)(uintptr_t)inv2.crc; + + err = fastrpc_remote_invoke(fl, &inv2.inv, cargs); kfree(cargs); return err; @@ -2188,6 +2233,9 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_INVOKE: err = fastrpc_invoke(fl, argp); break; + case FASTRPC_IOCTL_INVOKEV2: + err = fastrpc_invokev2(fl, argp); + break; case FASTRPC_IOCTL_INIT_ATTACH: err = fastrpc_init_attach(fl, ROOT_PD); break; diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index f33d914d8f46..406b80555d41 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -17,6 +17,7 @@ #define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map) #define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap) #define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability) +#define FASTRPC_IOCTL_INVOKEV2 _IOWR('R', 14, struct fastrpc_invoke_v2) /** * enum fastrpc_map_flags - control flags for mapping memory on DSP user process @@ -80,6 +81,12 @@ struct fastrpc_invoke { __u64 args; }; +struct fastrpc_invoke_v2 { + struct fastrpc_invoke inv; + __u64 crc; + __u32 reserved[16]; +}; + struct fastrpc_init_create { __u32 filelen; /* elf file length */ __s32 filefd; /* fd for the file */ From patchwork Mon Jan 27 04:42:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13950981 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ACA61FC7C6; Mon, 27 Jan 2025 04:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952990; cv=none; b=SJTh2KWhVaVhMgp5DOO1M+HegJZaOHwH2uokWJfwA142KtHRO92TrnBwmAnqt/kF1QQou8fEO8nMJS2NGJPMzNzVbpIshwAFgkS9LGnv+bZw1/I0D5ooFD8KZn6/wh6bntLN5UOpdIFf69mkmcpS8kUhsegqlCvhiFapb8spMug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952990; c=relaxed/simple; bh=YbCwJpDf/fyWg199r3u5kHp2qWjzEGMzdgJJzaYwmq8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pVukiELE0OVFSBqI83SQml+OFJk8lk5iMApO+zK2WAnqsEwEKKxTqH26YbXB+Yc4aGxxgcP6ApzO7Y8yySwY4xvbFFtDSTVUIhRHYegx4gEN9BhSNSysbKu0cpGlozSZWtEoFRkqllZLNCol+9tgehDkFa5rWGNB+hZ8G04sPDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=ZS5PFa/k; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ZS5PFa/k" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50R1ccp9008632; Mon, 27 Jan 2025 04:43:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= M01EAUmc0GjQN+utSYliCT+8oEL5CJS4CvJ8Ro1ooiI=; b=ZS5PFa/kpFEn1b5E 1LvjDRpG8tRvFEP5L5IdCH2fkKiNIqubSSHM3oMiAkr1zZn3GICSrU52xYVfzmMN je9EoSzTrv7/52jhT5c08PdNu4YXSV14ZOACdNPIC2zounKA3V2ow556Wmq1EOPm WN7AqM9w5wF5UNSaQ61c5kbfpCyPLkTFMqWLc6VuhvBPcqoth5QAmANC2FeaL6ye 0Hqp+QRYrCGwrs4mHwgn31nYEPkEi3z662D1kEzC7+kMsNM5t5nuqT7WOGXIibwY hSArkiSZTJogejfNKBmLAey9FcABNGR+t3yEziRpcOiVN0xblqH3Vugo/uoEYD8S XIaFQA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44dwg0rcun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:43:03 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50R4h2EU003085 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:43:02 GMT Received: from hu-ekangupt-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 26 Jan 2025 20:42:59 -0800 From: Ekansh Gupta To: , CC: , , , , , Subject: [PATCH v2 4/5] misc: fastrpc: Add polling mode support for fastRPC driver Date: Mon, 27 Jan 2025 10:12:38 +0530 Message-ID: <20250127044239.578540-5-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250127044239.578540-1-quic_ekangupt@quicinc.com> References: <20250127044239.578540-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: OifRupQm49DrCmBHe1Hn-I6aOOAycuMm X-Proofpoint-ORIG-GUID: OifRupQm49DrCmBHe1Hn-I6aOOAycuMm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_01,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 impostorscore=0 adultscore=0 bulkscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501270036 For any remote call to DSP, after sending an invocation message, fastRPC driver waits for glink response and during this time the CPU can go into low power modes. Adding a polling mode support with which fastRPC driver will poll continuously on a memory after sending a message to remote subsystem which will eliminate CPU wakeup and scheduling latencies and reduce fastRPC overhead. With this change, DSP always sends a glink response which will get ignored if polling mode didn't time out. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 122 +++++++++++++++++++++++++++++++++--- include/uapi/misc/fastrpc.h | 3 +- 2 files changed, 114 insertions(+), 11 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index cfacee0dded5..257a741af115 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ #define FASTRPC_CTX_MAX (256) #define FASTRPC_INIT_HANDLE 1 #define FASTRPC_DSP_UTILITIES_HANDLE 2 +#define FASTRPC_MAX_STATIC_HANDLE (20) #define FASTRPC_CTXID_MASK (0xFF0) #define INIT_FILELEN_MAX (2 * 1024 * 1024) #define INIT_FILE_NAMELEN_MAX (128) @@ -106,6 +108,19 @@ #define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscdev) +/* Poll response number from remote processor for call completion */ +#define FASTRPC_POLL_RESPONSE (0xdecaf) +/* timeout in us for polling until memory barrier */ +#define FASTRPC_POLL_TIME_MEM_UPDATE (500) + +/* Response types supported for RPC calls */ +enum fastrpc_response_flags { + /* normal job completion glink response */ + NORMAL_RESPONSE = 0, + /* process updates poll memory instead of glink response */ + POLL_MODE = 1, +}; + static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", "sdsp", "cdsp", "cdsp1" }; struct fastrpc_phy_page { @@ -238,9 +253,16 @@ struct fastrpc_invoke_ctx { u32 sc; u64 *fdlist; u32 *crclist; + u32 *poll; void __user *crc; u64 ctxid; u64 msg_sz; + /* Threads poll for specified timeout and fall back to glink wait */ + u64 poll_timeout; + /* work done status flag */ + bool is_work_done; + /* response flags from remote processor */ + enum fastrpc_response_flags rsp_flags; struct kref refcount; struct list_head node; /* list of ctxs */ struct completion work; @@ -258,6 +280,7 @@ struct fastrpc_invoke_ctx { struct fastrpc_ctx_args { struct fastrpc_invoke_args *args; void __user *crc; + u64 poll_timeout; }; struct fastrpc_session_ctx { @@ -619,11 +642,14 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( fastrpc_channel_ctx_get(cctx); ctx->crc = cargs->crc; + ctx->poll_timeout = cargs->poll_timeout; ctx->sc = sc; ctx->retval = -1; ctx->pid = current->pid; ctx->client_id = user->client_id; ctx->cctx = cctx; + ctx->rsp_flags = NORMAL_RESPONSE; + ctx->is_work_done = false; init_completion(&ctx->work); INIT_WORK(&ctx->put_work, fastrpc_context_put_wq); @@ -882,7 +908,8 @@ static int fastrpc_get_meta_size(struct fastrpc_invoke_ctx *ctx) sizeof(struct fastrpc_invoke_buf) + sizeof(struct fastrpc_phy_page)) * ctx->nscalars + sizeof(u64) * FASTRPC_MAX_FDLIST + - sizeof(u32) * FASTRPC_MAX_CRCLIST; + sizeof(u32) * FASTRPC_MAX_CRCLIST + + sizeof(u32); return size; } @@ -975,6 +1002,8 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) pages = fastrpc_phy_page_start(list, ctx->nscalars); ctx->fdlist = (u64 *)(pages + ctx->nscalars); ctx->crclist = (u32 *)(ctx->fdlist + FASTRPC_MAX_FDLIST); + ctx->poll = (u32 *)(ctx->crclist + FASTRPC_MAX_CRCLIST); + args = (uintptr_t)ctx->buf->virt + metalen; rlen = pkt_size - metalen; ctx->rpra = rpra; @@ -1145,6 +1174,72 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, } +static int poll_for_remote_response(struct fastrpc_invoke_ctx *ctx, u64 timeout) +{ + int err = -EIO, i, j; + + /* poll on memory for DSP response. Return failure on timeout */ + for (i = 0, j = 0; i < timeout; i++, j++) { + if (*ctx->poll == FASTRPC_POLL_RESPONSE) { + err = 0; + ctx->is_work_done = true; + ctx->retval = 0; + break; + } + if (j == FASTRPC_POLL_TIME_MEM_UPDATE) { + /* make sure that all poll memory writes by DSP are seen by CPU */ + dma_rmb(); + j = 0; + } + udelay(1); + } + return err; +} + +static inline int fastrpc_wait_for_response(struct fastrpc_invoke_ctx *ctx, + u32 kernel) +{ + int err = 0; + + if (kernel) { + if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) + err = -ETIMEDOUT; + } else { + err = wait_for_completion_interruptible(&ctx->work); + } + + return err; +} + +static int fastrpc_wait_for_completion(struct fastrpc_invoke_ctx *ctx, + u32 kernel) +{ + int err; + + do { + switch (ctx->rsp_flags) { + case NORMAL_RESPONSE: + err = fastrpc_wait_for_response(ctx, kernel); + if (err || ctx->is_work_done) + return err; + break; + case POLL_MODE: + err = poll_for_remote_response(ctx, ctx->poll_timeout); + /* If polling timed out, move to normal response mode */ + if (err) + ctx->rsp_flags = NORMAL_RESPONSE; + break; + default: + err = -EBADR; + dev_dbg(ctx->fl->sctx->dev, + "unsupported response type:0x%x\n", ctx->rsp_flags); + break; + } + } while (!ctx->is_work_done); + + return err; +} + static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, u32 handle, u32 sc, struct fastrpc_ctx_args *cargs) @@ -1180,16 +1275,20 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (err) goto bail; - if (kernel) { - if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) - err = -ETIMEDOUT; - } else { - err = wait_for_completion_interruptible(&ctx->work); - } + if (ctx->poll_timeout != 0 && handle > FASTRPC_MAX_STATIC_HANDLE + && fl->pd == USER_PD) + ctx->rsp_flags = POLL_MODE; + err = fastrpc_wait_for_completion(ctx, kernel); if (err) goto bail; + if (!ctx->is_work_done) { + err = -ETIMEDOUT; + dev_dbg(fl->sctx->dev, "Invalid workdone state for handle 0x%x, sc 0x%x\n", + handle, sc); + goto bail; + } /* make sure that all memory writes by DSP are seen by CPU */ dma_rmb(); /* populate all the output buffers with results */ @@ -1769,7 +1868,7 @@ static int fastrpc_invokev2(struct fastrpc_user *fl, char __user *argp) return -EFAULT; /* Check if all reserved fields are zero */ - for (i = 0; i < 16; i++) { + for (i = 0; i < 14; i++) { if (inv2.reserved[i] != 0) return -EINVAL; } @@ -1779,6 +1878,7 @@ static int fastrpc_invokev2(struct fastrpc_user *fl, char __user *argp) return -ENOMEM; cargs->crc = (void __user *)(uintptr_t)inv2.crc; + cargs->poll_timeout = inv2.poll_timeout; err = fastrpc_remote_invoke(fl, &inv2.inv, cargs); kfree(cargs); @@ -2581,12 +2681,14 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, ctx = idr_find(&cctx->ctx_idr, ctxid); spin_unlock_irqrestore(&cctx->lock, flags); + /* Ignore this failure as context returned will be NULL for polling mode */ if (!ctx) { - dev_err(&rpdev->dev, "No context ID matches response\n"); - return -ENOENT; + dev_dbg(&rpdev->dev, "No context ID matches response\n"); + return 0; } ctx->retval = rsp->retval; + ctx->is_work_done = true; complete(&ctx->work); /* diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index 406b80555d41..1920c537bbbf 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -84,7 +84,8 @@ struct fastrpc_invoke { struct fastrpc_invoke_v2 { struct fastrpc_invoke inv; __u64 crc; - __u32 reserved[16]; + __u64 poll_timeout; + __u32 reserved[14]; }; struct fastrpc_init_create { From patchwork Mon Jan 27 04:42:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13950982 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DD1F1FC10A; Mon, 27 Jan 2025 04:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952991; cv=none; b=d4VbrvYK5oXSiwdylcFzdi0Pf042RA9Uu9kV7JfDqVvE/RUMZr6u+sSizdAWxtV9XQKtM1oh5JHb17pOzBb/g1eASVJ+Mqg/UyNsv7mCbtFfoyQIf/MsADLFK67eWSjKFICsPEosKW66KHy7jxZn9AG39ig/62+7p6MiWSAdwT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737952991; c=relaxed/simple; bh=X6BhXYfMSRRt5zDCtR9PPK/6T/mc3moEdwnr2tW+7a8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WoHtFcSz1N7WGGniPf50Wfkw2MYtmzYc58oZKkw3yTS/tlR5Kj8UV90apM+RtO7cxepbP+qpZdDQHFdbUb4YURmuPII9MMa9h8oB32Ked1zChY8vTGxtTj/CJO3Yqc5kM2jKNTPx61KQ0Keyx13AhGaalcB96t+RG+igAD9Z4WM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=bz4qALS4; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="bz4qALS4" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50R1hUVG008471; Mon, 27 Jan 2025 04:43:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= PVBHZ51bNXLyMIA5posqUMWv/2n+p+py1aBTQ5EgWvY=; b=bz4qALS4RATZ85oF OKz7eQ8d8qWvLwTwluSeSLCCfdK91kobDJG2MLXQWPbV3hO7KtDPprHs6h+10Hx/ OYKV5RDd1KSHWh7bJxWLNS2aq0vr33ssACnIjG+yLhHqIjI/NUYu0CjGq/1Z3W56 5bG+Hp5gu8Be5elGXSL1TZF9gKv3jEM9ePvxVzKzPw//ANNLcKN9EL//+loq8Bzp ozqnCCXJZjvGpv0ZRw2fEunxEsnK6RX52Y64P7qdh7af1Z2S/14WS1C5/JrhUHFR n9CDbhd1xS1MHayT6Rt4xvidgnkH8E/66BfMAAmDWVrA+Jdaz4yuVi/9rgRdQIb6 24adJg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44dhu9h4fp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:43:05 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 50R4h5a6003164 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Jan 2025 04:43:05 GMT Received: from hu-ekangupt-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 26 Jan 2025 20:43:02 -0800 From: Ekansh Gupta To: , CC: , , , , , Subject: [PATCH v2 5/5] misc: fastrpc: Modify context id mask to support polling mode Date: Mon, 27 Jan 2025 10:12:39 +0530 Message-ID: <20250127044239.578540-6-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250127044239.578540-1-quic_ekangupt@quicinc.com> References: <20250127044239.578540-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: ymuqKnocGz3csGc394CVVg3fv5yH0Fms X-Proofpoint-ORIG-GUID: ymuqKnocGz3csGc394CVVg3fv5yH0Fms X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_01,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 phishscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501270036 DSP needs last 4 bits of context id to be 0 for polling mode to be supported as setting of last 8 is intended for async mode(not yet supported on upstream driver) and setting these bits restrics writing to poll memory from DSP. Modify context id mask to ensure polling mode is supported. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 257a741af115..ef56c793c564 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -40,7 +40,7 @@ #define FASTRPC_INIT_HANDLE 1 #define FASTRPC_DSP_UTILITIES_HANDLE 2 #define FASTRPC_MAX_STATIC_HANDLE (20) -#define FASTRPC_CTXID_MASK (0xFF0) +#define FASTRPC_CTXID_MASK (0xFF0000) #define INIT_FILELEN_MAX (2 * 1024 * 1024) #define INIT_FILE_NAMELEN_MAX (128) #define FASTRPC_DEVICE_NAME "fastrpc" @@ -524,7 +524,7 @@ static void fastrpc_context_free(struct kref *ref) fastrpc_buf_free(ctx->buf); spin_lock_irqsave(&cctx->lock, flags); - idr_remove(&cctx->ctx_idr, ctx->ctxid >> 4); + idr_remove(&cctx->ctx_idr, ctx->ctxid >> 16); spin_unlock_irqrestore(&cctx->lock, flags); kfree(ctx->maps); @@ -664,7 +664,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( spin_unlock_irqrestore(&cctx->lock, flags); goto err_idr; } - ctx->ctxid = ret << 4; + ctx->ctxid = ret << 16; spin_unlock_irqrestore(&cctx->lock, flags); kref_init(&ctx->refcount); @@ -2675,7 +2675,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, if (len < sizeof(*rsp)) return -EINVAL; - ctxid = ((rsp->ctx & FASTRPC_CTXID_MASK) >> 4); + ctxid = ((rsp->ctx & FASTRPC_CTXID_MASK) >> 16); spin_lock_irqsave(&cctx->lock, flags); ctx = idr_find(&cctx->ctx_idr, ctxid);