From nobody Tue Dec 23 14:24:11 2025 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 10612182C5; Fri, 2 Feb 2024 06:41: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=1706856069; cv=none; b=Fdy3Mzl88MFiTKHSmrlsEYHAcL+fx2qQfCtuN1ucdy21E8H8LGFlTbAbOXX8pCj7UXh4ahlD4JKM6/P0Xhhf0cRAb4LYMkI3akJZeyy43gVSeUcjOdkqYwCiRZ/NeylHtJ8i5UDgewd3BPURlgnYN0o+FPZhpxBpIVHqF3FR274= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856069; c=relaxed/simple; bh=rWI9e2DBhsoZBuc6IiXSA/pVRd/KzaC9Fd3vD/Srqnk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vz5m01WXE3197tO+F8gPtMkNOVYNv5SUYtvMbmMH6zneF3F+sZSjrysRykcJ2alFZPv1iwVJhjj39eB8kY0DVb308fVluAFtpj8o8zQa+TrGWpRZKfkZBMBehp8w/vjPdSBKuTBDGdwO9rD0jBLahgOaLSPaIRVtRkjVne95ySY= 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=HwIbOlln; 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="HwIbOlln" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41256WXW024813; Fri, 2 Feb 2024 06:41:06 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=rtQEAGVD2KwsUx1lAIcO Ah9wMAKg3iWfDCz1mhH+fBE=; b=HwIbOlln5+5kfNlVSSjzwXkk0C4hjuVKvk64 LT+w/VhFIVZLsj57OFUTKlZP+CsyIBsE/VWMOGr3IgQmkLmVJHzBTD7t+9ou44Re jUsiJ7t6o+P5TmJ7A6l51N31K9hbxE5MLWaVCKELIeeHb6WqhFRA9wLLsWhnCl8V I0sw50VfZswBeYSvkE1f8O90axTOUToFHdY5uQ02MCoNYUkno6+eSD7KCyxfpAJZ vu5hSEu8lrMkczF9YjAGsQv/tosdgEzbbHdTJ7P2EiXIQPZIHdEFWbHVRrvY42XW DafDipnllKcajj9RPnTWUYzhnFxYAhEd6qAbjK2ZJKSZa8pggQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w0ptw8nd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Feb 2024 06:41:05 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 4126f4IY014264 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 2 Feb 2024 06:41:04 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; Thu, 1 Feb 2024 22:41:02 -0800 From: Ekansh Gupta To: , CC: , Subject: [PATCH v1 07/16] misc: fastrpc: Add support to save and restore interrupted Date: Fri, 2 Feb 2024 12:10:30 +0530 Message-ID: <20240202064039.15505-8-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20240202064039.15505-1-quic_ekangupt@quicinc.com> References: <20240202064039.15505-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@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-ORIG-GUID: yzZLk49h6HHm_O9by3JREjYyyYMSj_oX X-Proofpoint-GUID: yzZLk49h6HHm_O9by3JREjYyyYMSj_oX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-01_10,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402020047 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 --- drivers/misc/fastrpc.c | 83 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 11 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 33687d7f9a28..88f065e78bc2 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -359,6 +359,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; @@ -740,6 +741,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) @@ -1292,6 +1327,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); @@ -1313,6 +1356,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; @@ -1338,12 +1382,9 @@ static int fastrpc_internal_invoke(struct fastrpc_us= er *fl, u32 kernel, goto bail; =20 bail: - if (err !=3D -ERESTARTSYS && err !=3D -ETIMEDOUT) { - /* We are done with this compute context */ - spin_lock(&fl->lock); - list_del(&ctx->node); - spin_unlock(&fl->lock); - fastrpc_context_put(ctx); + if (err =3D=3D -ERESTARTSYS) { + if (ctx) + fastrpc_context_save_interrupted(ctx); } else if (ctx) { if (fl->profile && !err) fastrpc_update_invoke_count(handle, perf_counter, &invoket); @@ -1353,6 +1394,10 @@ static int fastrpc_internal_invoke(struct fastrpc_us= er *fl, u32 kernel, if (perferr) dev_info(fl->sctx->dev, "Warning: failed to copy perf data %d\n", perf= err); } + spin_lock(&fl->lock); + list_del(&ctx->node); + spin_unlock(&fl->lock); + fastrpc_context_put(ctx); } =20 if (err) @@ -1734,6 +1779,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]; @@ -1756,7 +1820,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; @@ -1770,10 +1833,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); @@ -1814,6 +1874,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); --=20 2.17.0