From nobody Wed Dec 17 13:24:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49686C61D88 for ; Tue, 21 Nov 2023 09:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbjKUJtO (ORCPT ); Tue, 21 Nov 2023 04:49:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234132AbjKUJtL (ORCPT ); Tue, 21 Nov 2023 04:49:11 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86875123; Tue, 21 Nov 2023 01:49:05 -0800 (PST) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AL9AVBe007988; Tue, 21 Nov 2023 09:49:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=gOkkbezRGKZBHXP1iggS2/Jl27fwQSQsSEE7refs9T4=; b=YHffwRl0iuaH89Klh2QjWkrK4tpQD8tR6IDc62kYo9LFwHl3qe3YIxwmnJn+/33eMGkV vqMKX8hXLmKZIpQQuvPDBkG5EA+DjffJueIFB7FGiofckzZgaXALBBKjSruo20ukq3iJ ouMJei1zkRZuAMsv0fxVzjXV8dgShaiTXVxox9+9MDPGY+YEUMYY/QXp6Y5ZPiRidWlC olvlvJS+qMqLM8Bz8MzQP4nKVkYGD/0cvbxVbXSYhcKZqYvX7VUJ48/dFzthwVl1lBd5 4hroXC1q1fMpwPWO1D16s+AOq+LysRfLZyBCr9XGEK3grj6ZO8rknixJuRdTqIkjKGEv BQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ug37mk8b1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 09:49:03 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AL9n2co004289 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 09:49: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.1118.40; Tue, 21 Nov 2023 01:49:00 -0800 From: Ekansh Gupta To: , CC: , Subject: [PATCH v7 4/5] misc: fastrpc: Add support to save and restore interrupted Date: Tue, 21 Nov 2023 15:18:43 +0530 Message-ID: <20231121094844.5764-5-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231121094844.5764-1-quic_ekangupt@quicinc.com> References: <20231121094844.5764-1-quic_ekangupt@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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: CU44ccJPyMjFXkwNTr5Uz1PM51HgKuCW X-Proofpoint-ORIG-GUID: CU44ccJPyMjFXkwNTr5Uz1PM51HgKuCW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-21_03,2023-11-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311210076 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For any remote call, driver sends a message to DSP using RPMSG framework. After message is sent, there is a wait on a completion object at driver which is completed when DSP response is received. There is a possibility that a signal is received while waiting causing the wait function to return -ERESTARTSYS. In this case the context should be saved and it should get restored for the next invocation for the thread. Adding changes to support saving and restoring of interrupted fastrpc contexts. Signed-off-by: Ekansh Gupta --- Changes in v2: - Fixed missing definition - Fixes compile time issue Changes in v5: - Removed Change-Id tag Changes in v7: - Rebase the patch to latest kernel version drivers/misc/fastrpc.c | 97 +++++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 15 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index cbcac0b3d09b..aa0695f9576e 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -333,6 +333,7 @@ struct fastrpc_user { struct list_head user; struct list_head maps; struct list_head pending; + struct list_head interrupted; struct list_head mmaps; =20 struct fastrpc_channel_ctx *cctx; @@ -712,6 +713,40 @@ static struct fastrpc_invoke_ctx *fastrpc_context_allo= c( return ERR_PTR(ret); } =20 +static struct fastrpc_invoke_ctx *fastrpc_context_restore_interrupted( + struct fastrpc_user *fl, struct fastrpc_invoke *inv) +{ + struct fastrpc_invoke_ctx *ctx =3D NULL, *ictx =3D NULL, *n; + + spin_lock(&fl->lock); + list_for_each_entry_safe(ictx, n, &fl->interrupted, node) { + if (ictx->pid =3D=3D current->pid) { + if (inv->sc !=3D ictx->sc || ictx->fl !=3D fl) { + dev_err(ictx->fl->sctx->dev, + "interrupted sc (0x%x) or fl (%pK) does not match with invoke sc (0x%= x) or fl (%pK)\n", + ictx->sc, ictx->fl, inv->sc, fl); + spin_unlock(&fl->lock); + return ERR_PTR(-EINVAL); + } + ctx =3D ictx; + list_del(&ctx->node); + list_add_tail(&ctx->node, &fl->pending); + break; + } + } + spin_unlock(&fl->lock); + return ctx; +} + +static void fastrpc_context_save_interrupted( + struct fastrpc_invoke_ctx *ctx) +{ + spin_lock(&ctx->fl->lock); + list_del(&ctx->node); + list_add_tail(&ctx->node, &ctx->fl->interrupted); + spin_unlock(&ctx->fl->lock); +} + static struct sg_table * fastrpc_map_dma_buf(struct dma_buf_attachment *attachment, enum dma_data_direction dir) @@ -1267,6 +1302,14 @@ static int fastrpc_internal_invoke(struct fastrpc_us= er *fl, u32 kernel, return -EPERM; } =20 + if (!kernel) { + ctx =3D fastrpc_context_restore_interrupted(fl, inv); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); + if (ctx) + goto wait; + } + ctx =3D fastrpc_context_alloc(fl, kernel, sc, invoke); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1288,6 +1331,7 @@ static int fastrpc_internal_invoke(struct fastrpc_use= r *fl, u32 kernel, goto bail; PERF_END); =20 +wait: if (kernel) { if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) err =3D -ETIMEDOUT; @@ -1322,6 +1366,9 @@ static int fastrpc_internal_invoke(struct fastrpc_use= r *fl, u32 kernel, } =20 if (err =3D=3D -ERESTARTSYS) { + if (ctx) + fastrpc_context_save_interrupted(ctx); + list_for_each_entry_safe(buf, b, &fl->mmaps, node) { list_del(&buf->node); list_add_tail(&buf->node, &fl->cctx->invoke_interrupted_mmaps); @@ -1443,7 +1490,7 @@ static int fastrpc_init_create_static_process(struct = fastrpc_user *fl, =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_STATIC, 3, 0); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, true, &ioctl); if (err) @@ -1576,7 +1623,7 @@ static int fastrpc_init_create_process(struct fastrpc= _user *fl, ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE, 4, 0); if (init.attrs) ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_ATTR, 4, 0); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, true, &ioctl); if (err) @@ -1627,6 +1674,25 @@ static void fastrpc_session_free(struct fastrpc_chan= nel_ctx *cctx, spin_unlock_irqrestore(&cctx->lock, flags); } =20 +static void fastrpc_context_list_free(struct fastrpc_user *fl) +{ + struct fastrpc_invoke_ctx *ctx, *n; + + list_for_each_entry_safe(ctx, n, &fl->interrupted, node) { + spin_lock(&fl->lock); + list_del(&ctx->node); + spin_unlock(&fl->lock); + fastrpc_context_put(ctx); + } + + list_for_each_entry_safe(ctx, n, &fl->pending, node) { + spin_lock(&fl->lock); + list_del(&ctx->node); + spin_unlock(&fl->lock); + fastrpc_context_put(ctx); + } +} + static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl) { struct fastrpc_invoke_args args[1]; @@ -1640,7 +1706,7 @@ static int fastrpc_release_current_dsp_process(struct= fastrpc_user *fl) =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_RELEASE, 1, 0); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 return fastrpc_internal_invoke(fl, true, &ioctl); } @@ -1649,7 +1715,6 @@ static int fastrpc_device_release(struct inode *inode= , struct file *file) { struct fastrpc_user *fl =3D (struct fastrpc_user *)file->private_data; struct fastrpc_channel_ctx *cctx =3D fl->cctx; - struct fastrpc_invoke_ctx *ctx, *n; struct fastrpc_map *map, *m; struct fastrpc_buf *buf, *b; unsigned long flags; @@ -1663,10 +1728,7 @@ static int fastrpc_device_release(struct inode *inod= e, struct file *file) if (fl->init_mem) fastrpc_buf_free(fl->init_mem); =20 - list_for_each_entry_safe(ctx, n, &fl->pending, node) { - list_del(&ctx->node); - fastrpc_context_put(ctx); - } + fastrpc_context_list_free(fl); =20 list_for_each_entry_safe(map, m, &fl->maps, node) fastrpc_map_put(map); @@ -1707,6 +1769,7 @@ static int fastrpc_device_open(struct inode *inode, s= truct file *filp) spin_lock_init(&fl->lock); mutex_init(&fl->mutex); INIT_LIST_HEAD(&fl->pending); + INIT_LIST_HEAD(&fl->interrupted); INIT_LIST_HEAD(&fl->maps); INIT_LIST_HEAD(&fl->mmaps); INIT_LIST_HEAD(&fl->user); @@ -1788,7 +1851,7 @@ static int fastrpc_init_attach(struct fastrpc_user *f= l, int pd) =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 return fastrpc_internal_invoke(fl, true, &ioctl); } @@ -1819,7 +1882,7 @@ static int fastrpc_invoke(struct fastrpc_user *fl, ch= ar __user *argp) } =20 ioctl.inv =3D inv; - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, false, &ioctl); kfree(args); @@ -1901,7 +1964,7 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_u= ser *fl, uint32_t *dsp_attr =20 ioctl.inv.handle =3D FASTRPC_DSP_UTILITIES_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(0, 1, 1); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 return fastrpc_internal_invoke(fl, true, &ioctl); } @@ -2004,7 +2067,7 @@ static int fastrpc_req_munmap_impl(struct fastrpc_use= r *fl, struct fastrpc_buf * =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_MUNMAP, 1, 0); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, true, &ioctl); if (!err) { @@ -2102,7 +2165,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, = char __user *argp) =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_MMAP, 2, 1); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, true, &ioctl); if (err) { @@ -2183,7 +2246,7 @@ static int fastrpc_req_mem_unmap_impl(struct fastrpc_= user *fl, struct fastrpc_me =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_UNMAP, 1, 0); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, true, &ioctl); if (err) { @@ -2254,7 +2317,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *f= l, char __user *argp) =20 ioctl.inv.handle =3D FASTRPC_INIT_HANDLE; ioctl.inv.sc =3D FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1); - ioctl.inv.args =3D (__u64)args; + ioctl.inv.args =3D (u64)args; =20 err =3D fastrpc_internal_invoke(fl, true, &ioctl); if (err) { @@ -2575,6 +2638,10 @@ static void fastrpc_notify_users(struct fastrpc_user= *user) ctx->retval =3D -EPIPE; complete(&ctx->work); } + list_for_each_entry(ctx, &user->interrupted, node) { + ctx->retval =3D -EPIPE; + complete(&ctx->work); + } spin_unlock(&user->lock); } =20 --=20 2.17.1