From mboxrd@z Thu Jan 1 00:00:00 1970 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 F294934EF04 for ; Tue, 26 May 2026 08:35:36 +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=1779784538; cv=none; b=XpgMleXqWSuQk005S1YLbKL/WFVvgGGa/R5KtLKEHpFR40d5N11ynBWPHAoheZOHg8qs+NvWIfnpq3QSqh4YFsBBrvLf4e+/0ykZzwIrAHoH+fYBLDR9H/nYkPWx1bVi1RV3xzdzJPlUPmuAEQE0Z23XcIWnpO8I4h12A1zKXg0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779784538; c=relaxed/simple; bh=W0hMroCYS5fbz9f0gfltAG8CqfsGAO0JiMRl9c/r31c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jNhlIu6xEZMMBirnSpV5T4Plx+eh4lN+Z/Elk0fSDjnThGFFtbzj6UCN3R8RW571jECmmDmhSO69yL6pvs7S0xrgJIASu3hUhIaTX3O9FqG3uy2CX2zw5itRnV3GDJ+1uZNR97RY1V0OLLQ7EXGbgTTVI82thD6IUwfSbU0ZXd0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=HfvsJ4JG; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=AN/d2/ea; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="HfvsJ4JG"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="AN/d2/ea" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64Q5xjvU1604524 for ; Tue, 26 May 2026 08:35:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= DxN7uZ0WxSxkaNekTFdgi3oj+0DA7+48Vw++MklSwVQ=; b=HfvsJ4JGWoXw1fuD Krxf92uXqUokgbUoD/JC4DyGvFSiA39CXGRsv1WmMpYfPazMuL2rjuiY5eRfd0O5 M62T2BzXqzeN8byKZABnSjRSU7sPVZSGgN51iGT8+9Kl+pa+0YUOUkDf+RSp+FaZ IsZUbTvPzPiMLbpmvjSvCaVVDRiI9quaaOxjwpOdkiiJkXeCOfSHOS+aZ1Mdz5q5 GrfIFLY8I3dz1wyVXtXwKBisORSNB8vG+EJC69CBGzGBr2GaDwG9hPxOCd9QgAl+ NvsnJJIOq/w4eqp9thjx5ooh85MoC1RgycqRCLWQvnbachSEa4M7lO747CwC5s8y /Ff+lA== Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ed5v3rkyy-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 26 May 2026 08:35:35 +0000 (GMT) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-82f6e6a3a76so12466872b3a.0 for ; Tue, 26 May 2026 01:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1779784535; x=1780389335; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DxN7uZ0WxSxkaNekTFdgi3oj+0DA7+48Vw++MklSwVQ=; b=AN/d2/eaT6DsFo5ubfRGCPgUMMz4IOlW1l+YeQO9t5wEktAwn8xbGIUSNYiFANSGzu Hr51hOtUX8mNEUvcWKFJjTk3VfczZNm//dB6/xw4nyFrFoy9XHJd0NrPZQIEyVh2wU8S 9294BKKlrAAXcwuFbf0M9EI8HxoMzzbCc6g5hoCHfSkD/VtY8XmWuelyxTxlAEBC6jZ9 ggzrrWC7hjWEYFB6wG2+KDxbmSehnKn33jhdm4r1mAtIEErhs5egNOzkb+vJAdkDdWc+ CqIdDRsErsCZ3oHftg16SMYi5GJ2oOHW7EzlK8M/NUweyPFl0riGkazwOq1IoSLIvwwr coOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779784535; x=1780389335; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DxN7uZ0WxSxkaNekTFdgi3oj+0DA7+48Vw++MklSwVQ=; b=Rhu/+9v015jCLoornG3XZK5dwNxLk92HGYjzfUlBOk6JK2vpkp0xoVwway3fKVZTB3 hHL2xWFNopmaGX2D0yK2B9+siDxfF3g/EwTVEuHp2eZQArDFuBDJBZJ+XOxxvMgRgU3v 7eJWOmqTp8gX0lnNPw+/AW5BKkYW7JL05Z0xXMw5zqArXy3x8qzDHqI/th+e+FBtG5vv y0cpRIAJeD8//rwvL6JzplbLW4/U132EAvNb2Jx+0xkdTNXsYEkx2KdeSdGXoRi8dSSa yQP5YjzUC3olHaRQflGRXGWkp3D3sbN5/gtcLyT1LkmFlPjWpz5Rf86Cy7WNRX/P/9yM s4bA== X-Forwarded-Encrypted: i=1; AFNElJ+8Mn313ju1wSq5Q7kX8p0iALno5g9gSCRAmhb4ZAJlRYBNcZWi9++wtBTy6dFCy/StvxuFjW+9QcChLoc=@vger.kernel.org X-Gm-Message-State: AOJu0YyMyoxS2sge/l+G2lZVQbUn6K4GVJvVxvgXXHUWM/vVwxe1zehZ rgDCb2McqOQDH8+vZ7GA663+hIqJI7YkBY69bLFo0yTha6v1IXQcoEWgd0FmyOgwpUy+fOzLCDn ORfkRFACcUdAjLx/oOew57iMAx3zSG/gnmOSj0dI+O60WmY3svcTEQucHswOYPFga4fs= X-Gm-Gg: Acq92OHAiSIfU5Dp+d1gV1hROodxvL65ZSAXde+2pfOPNYeFHBdj8sByn7+MKEyAHIT bzCfYrEuS8j3cXoBv+fWtsCsMQqQpbhcKdofxVydWEcQvi6BbjHlp3j4/GfsrOepQNkHX9Gcd54 UzVbEErUrUw5huKpeIvcLLMh/ifqJf3z1QdTVDhLxIqLK7/n63AYspxqRXs6Xdue30Sr6FwiQti PoUfIQz+x2C8DItB3uM885XOoSAzRPMXBW620csRAblNulLbyyHo4/gpR7CtZJvnlcHrMPRPQul WaYkzd8k5F0n3NABNx0OqEQV1ARUbJ3fWc/2OWAec5BPONdu5jD3l2+UncSiBjTzMdm/RxFvnPx ZJPD6+7bCk6CUVHG3cgsfGK/YlJxSalm2K4GOLKeFJH9zcg== X-Received: by 2002:a05:6a00:3a0d:b0:82f:3828:a009 with SMTP id d2e1a72fcca58-8415f3b0771mr16934556b3a.3.1779784534870; Tue, 26 May 2026 01:35:34 -0700 (PDT) X-Received: by 2002:a05:6a00:3a0d:b0:82f:3828:a009 with SMTP id d2e1a72fcca58-8415f3b0771mr16934512b3a.3.1779784534257; Tue, 26 May 2026 01:35:34 -0700 (PDT) Received: from [10.206.98.126] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84165009852sm11859079b3a.59.2026.05.26.01.35.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 May 2026 01:35:33 -0700 (PDT) Message-ID: <02630778-a16d-405e-9ce4-7076d14c06b2@oss.qualcomm.com> Date: Tue, 26 May 2026 14:05:28 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] misc: fastrpc: fix context leak and hang on signal-interrupted invoke To: Dmitry Baryshkov Cc: srini@kernel.org, linux-arm-msm@vger.kernel.org, gregkh@linuxfoundation.org, quic_bkumar@quicinc.com, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, dri-devel@lists.freedesktop.org, arnd@arndb.de, ekansh.gupta@oss.qualcomm.com, stable@kernel.org References: <20260525124222.3082420-1-anandu.e@oss.qualcomm.com> <37zqhqm3ryyigcalimems2xvy2ccq3eyssls2pqx4qjufx57z6@w5kbehynw4h6> Content-Language: en-US From: Anandu Krishnan E In-Reply-To: <37zqhqm3ryyigcalimems2xvy2ccq3eyssls2pqx4qjufx57z6@w5kbehynw4h6> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTI2MDA3MyBTYWx0ZWRfX/R4kOZlOMuCu ephbEOM4utDYYEytYYXt3lF4XjzGEWINHAbtSrQea31oU3HUu0VDLJJtb0FJGZ5oNfNfBRXfb8I qnNqSm9H+516tOtXUpE+393KL6+MyriHPizWdCzEJrhJ0y4+nkxbC+yTVV+Oji8nupoOSvu8lKG AHcMEPMJN+5ozmAEiva9sdxUuzT+UWQCNDvo2+CHXWXUvOC/a9IfrfzfavKk8hSg/VE5mQEZ2QC fVMIemGGJhQzKyCDi2rNWC5+8jn8rNN59s3mBc4EFLb9qFr+plXqPsm04M6Mf+6RGe5Vtuiw9Jr rylZTVqdA2uJQ/o1u3+ZL2+/HgaewG5x0wAWDd50WjzwteeNm2ZhN2dqRHR/bcxccDOC3a+aw3M 7/dufURORZp0pdNa/H8vjv+nT5zOo/DE1JirjGKT0BANlqsbKnnp/PbbQ6ZFO3wehiz/6qCQp6c PPW2jc3aoe0l++QHeFw== X-Authority-Analysis: v=2.4 cv=Zc4t8MVA c=1 sm=1 tr=0 ts=6a155b57 cx=c_pps a=WW5sKcV1LcKqjgzy2JUPuA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=Kv5pTRVh4xdshmm17rYA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=OpyuDcXvxspvyRM73sMx:22 X-Proofpoint-ORIG-GUID: dp9ASwPm_oZAfuzsPFoXOUILAeEx58K0 X-Proofpoint-GUID: dp9ASwPm_oZAfuzsPFoXOUILAeEx58K0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-26_02,2026-05-18_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 phishscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605260073 On 25-05-2026 06:58 pm, Dmitry Baryshkov wrote: > On Mon, May 25, 2026 at 06:12:22PM +0530, Anandu Krishnan E wrote: >> fastrpc invokes work by sending an RPC message to the DSP and blocking >> in wait_for_completion_interruptible() until the DSP responds. If a >> signal arrives during this wait, the syscall returns -ERESTARTSYS and >> the invoke context which holds the in-flight DMA buffers and >> completion state is left stranded in fl->pending. >> >> On the next syscall attempt (either auto-restarted by the kernel via >> SA_RESTART or manually retried by user-space after EINTR), a fresh >> context is allocated and the RPC message is re-sent to the DSP. This >> has two consequences: >> >> - The original context leaks in fl->pending until the file is closed. >> - The DSP receives a duplicate invocation. If the DSP was mid-way >> through processing the first request and had issued a reverse RPC >> call back to the host, the retry sends a new forward request >> instead of the expected reverse-RPC response. The DSP thread >> waiting for that response is never woken, causing a hang. >> >> Fix this by saving the interrupted context to a new fl->interrupted >> list on -ERESTARTSYS. When the same thread retries the invoke with a >> matching sc, restore the context and jump directly to the wait, >> skipping context allocation and message re-send. > What if the userspace doesn't honour -ERESTARTSYS and submits a new > workload? If the same thread submits a new workload with a different sc while an interrupted context is pending,  fastrpc_context_restore_interrupted() detects the mismatch (ictx->sc != sc) and returns -EINVAL . This blocks the new submission and forces the thread to resolve its in-flight interrupted context first. This is intentional. The original DSP request is still in-flight and the DSP may issue a reverse RPC back to  the host as part of completing it. If we allowed a new forward request from the same thread in parallel,  the DSP would receive an unexpected message instead of the reverse-RPC response it is waiting for,  causing a hang/ unexpected behavior. i am open to new suggestions as well , can you please help suggest what is the correct way to handle  interrupted scenarios ?.  > >> Also drain fl->interrupted on process exit and complete any sleeping >> contexts with -EPIPE when the rpmsg channel is removed. >> >> Fixes: 387f625585d1 ("misc: fastrpc: handle interrupted contexts") >> Cc: stable@kernel.org >> Signed-off-by: Anandu Krishnan E >> --- >> drivers/misc/fastrpc.c | 69 ++++++++++++++++++++++++++++++++---------- >> 1 file changed, 53 insertions(+), 16 deletions(-) >>