From mboxrd@z Thu Jan 1 00:00:00 1970 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 1D7293C98A4 for ; Tue, 26 May 2026 07:25:18 +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=1779780319; cv=none; b=AFAEnod5h+E+j2ndLOqwwPfzCMnTBR1uPKp7+nxDcr1MV3VUcjZWoMdVT1hFIQ6BO8skb2wJWtOvR9uNHTrIa4RwfKIfz3ab+5+ohDcdlOFDWG+jG/cmbBHXpD64YuP5aJHstHR9InnmkqqdKWB9ieJ7Q9veNFQHHEsxpNYiOOk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779780319; c=relaxed/simple; bh=e98yY7FBU4ztLrfwflq3MKeC7JaeU89bB6UXwZ/KjpU=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=qkU5VFCmjINeMCnxkeL9w+/ZXytu+WKug3LRLUoFQyIjXaVAOjp5c4zrcIIdwhhj73FyQtIR9shpkqHuvwikO83EGM3TO37Pvs+aE7KbPgVmmOuLPlGkZcU2dy3CGhBBca4tUO/JlCO9TWhxPwuErMghiGAf0Aj0c9zTndS7wdI= 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=WyG4JJDR; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=AZPBQZN9; arc=none smtp.client-ip=205.220.168.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="WyG4JJDR"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="AZPBQZN9" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64PMCIFW1733979 for ; Tue, 26 May 2026 07:25:17 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= VHBSErm/baHSTdbtmVoVnrvbO2RjAxaPcuo57MHOiLk=; b=WyG4JJDRy+Bn8Nj9 SWdxHM4cP0KOoXe/i6V0Bx+lGDSCB+mVjvCy/y3U8eErNsLEXjgZFnG8KLLBA3f1 jveT8o3lLBMNCTIpt2YlhMiHTDe9Xozq2jHaAb0ob4sBgTS5WFD/4kzo8B1Zos+D r096IWn/6aqR5WJIeriLF5O/X1A8+NrabCd0kAJlDTxSTMb1inAUJJ+Qxu/uUrYg BmHGLdm973nuk3A4fkr3PWg6IZgvHRGUs16HT4OSGQU4X+K/CT/oX+tKdxnEm5Wo ynSZy33zfgtlHN7xbs+fa40YNd/7fLC/rGsYMi/0XqxqpQ1w394ctMubgNU7lqm3 DLfNag== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4eckmabg88-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 26 May 2026 07:25:17 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2b2ecc96a9aso114949255ad.1 for ; Tue, 26 May 2026 00:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1779780317; x=1780385117; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:cc:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=VHBSErm/baHSTdbtmVoVnrvbO2RjAxaPcuo57MHOiLk=; b=AZPBQZN9qg223vJZ3GxJwNak6xkMi1WLIUPSXqEW0Ni607/6vdSJIqEFXhBJMnt7V5 ShP8gcA+Q/9dgTYbC5TsO9jX7GaXl5DxuzFEyaAuGvO/81JjYRoxHYeTfX0JKRLPUk5y 75P5ME0hPSBwaI07g0eNvieB4cLh1nsTM8nWAcBplVjUF+4m60H2LhTzJvuFzKL2ax1b X9Mt365lTuFw3JIRDDgnWMZDZuGSycd0bZBTmZgCNGZBiKbSmTws0o9JA4WOMCUgaFQw eZZ+86GpdYRmOUr+3LazowvB0bgNtYX5K0HufYKCBlhJ83Tz+5X+hcVlywpa5tPbk6yK 1Tzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779780317; x=1780385117; h=content-transfer-encoding:in-reply-to:from:cc:content-language :references: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=VHBSErm/baHSTdbtmVoVnrvbO2RjAxaPcuo57MHOiLk=; b=ft79JCbSOsk0SfrSR+CT502x9PqDaMMoNvpS17X+Fy69IyWMx6x9lnWyPZf5Yi8vVp cCq2mRI3RqXyKgWSKJ/v2N2uWDC5D+D5Bk9ITYeb63fwBPRz/bzJk7/JhVdqAjtuwStO bH4Cif9sQ9M/sP6DL7XJSN/Ou1Aw+OxJo7r9fWhFXQGAjFj4vbqMLUjfAxYhX+4UauXJ g7Y2Y1RE8D+7z/nECw4RUzXRCj3MelilFFYzId6G//7T0L+ySOTTvsdYjROamdN8ylUl 5pY+hCdXiml9yeJKekFI3v+qc1Fq+gM7TenahSKHxSi70T/49zaOZd5AXcc2QvFGzjkk 5mpg== X-Forwarded-Encrypted: i=1; AFNElJ/Sy9//Rbocpu7g9F6Clo4YeGZiP+SYK7bS+bN9JQdOpUcjeGQG420LdV9WJr5zunWP51DchOVJcibi/Rg=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj3wlwJsL7/l2chn+1PENzHrHjXH4E6gEdAsqWofdQFmWxpKVZ lwg5fGJJvFmUO7UcTBl/WeuJ51tSmM6GLJecq+wQpAp507u4bObNMEJj4NLcraj9lIgm4J0MfDR D4IhY+E2k1axhCJmlDcMudQ9YCFfOtcJaewDBpZF+UA2P4Y7WAjbku6zh+o0NyCoK71fCTIyMLY JkKg== X-Gm-Gg: Acq92OF/N5RTg4qTXBVl5gB+IpodrEjRYomzP9ZOWwq52v82c3dvQlkvpesVaF1Esij H7JZB2vqHatO/ssjDq2GNiH+oJkZWaf5uR+ffBJWOpP5yJgQiy9+KS7IRFNlg4yEs8jjb4RiG+q NwQrCnUOQzXEYx6D4VvaoZ6e+F3ukmfrjwFz/lvxBanZjsaoUJ9V52EY8XzK1VP5zgGU2I1ZQVa J2OTHNltIS5byOTobOgnvOX5O33Ck8sGf5y/YufjjIZg62BVa/c48n/pdnEVM0yC9FJ3C9LOuFu Wbnv24spRqQYe5FVhiDuu7PyZHXcO/JO5U/vtDkqZTmM7lXwqXHaxtjr8nyZLVEUz2rL04gVrc+ NGyUX+/JVdZoMXM2zg8WKZMV2FUO57DDbTD7OfXe4AakSoINVBivNpspcll/5u1/FMxxGTyY4fZ zYBa91xaBdfbFj6dYW X-Received: by 2002:a17:903:32d1:b0:2b2:5597:bad4 with SMTP id d9443c01a7336-2beb0770f45mr198289195ad.30.1779780316799; Tue, 26 May 2026 00:25:16 -0700 (PDT) X-Received: by 2002:a17:903:32d1:b0:2b2:5597:bad4 with SMTP id d9443c01a7336-2beb0770f45mr198288965ad.30.1779780316320; Tue, 26 May 2026 00:25:16 -0700 (PDT) Received: from [10.133.33.225] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb58b3058sm117251945ad.39.2026.05.26.00.25.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 May 2026 00:25:15 -0700 (PDT) Message-ID: <5b838092-8372-4ffb-9367-a78f19ccdbd5@oss.qualcomm.com> Date: Tue, 26 May 2026 15:25:10 +0800 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 v5 2/5] misc: fastrpc: Remove buffer from list prior to unmap operation To: Dmitry Baryshkov References: <20260515124217.20723-1-jianping.li@oss.qualcomm.com> <20260515124217.20723-3-jianping.li@oss.qualcomm.com> <37146a3a-b18f-40f1-b95b-0ac19bf6c07a@oss.qualcomm.com> <85c2bfd1-8e69-47e4-a360-10a2655bd43f@oss.qualcomm.com> <4dc05557-ab95-468f-b972-84fe9fa3cc51@oss.qualcomm.com> Content-Language: en-US Cc: amahesh@qti.qualcomm.com, arnd@arndb.de, Greg KH , abelvesa@kernel.org, jorge.ramirez-ortiz@linaro.org, Ekansh Gupta , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, stable@kernel.org From: Jianping Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=cL3QdFeN c=1 sm=1 tr=0 ts=6a154add cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=3dfTGY2RfG25o-zzpn8A:9 a=QEXdDO2ut3YA:10 a=1OuFwYUASf3TG4hYMiVC:22 X-Proofpoint-ORIG-GUID: vLVGqq5Qu02MPgh6u1DiwQQ5bN7UBrwM X-Proofpoint-GUID: vLVGqq5Qu02MPgh6u1DiwQQ5bN7UBrwM X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTI2MDA2MyBTYWx0ZWRfXyu0yJ1jy4ujI NC6eWq874B0e0phwFeBd09L/OuWlwDS74cU1ktZhuC3eDTYFPRqgM91WmKvaEvuoSxKaj9Z48OF LjA97hJvA2i7Q8MyeQ5bmbLHYQbQPkFsl6UCkAM5cVnaIxCz/uTVJfKjnzBXobOFiKoyx9nrdnk tN9jBG+wpDY9LUb0rah0jNt3ppoHGgzsTIL4DvwccJ3ZDlsEBQWACm7J0WHaezXn6+WRFDGPXdL moZab1j39/j6Cb2dgMGIuzqsYsxNnFA5Vtg9hWldJXIE0BhTIVusDe9IIWgtiMeDzGbXz/w9gVR 7crdwgnD36AQandTKKKVzP3nWfkJzcehBllpungbpMKkuVk7iBREL8yR2iZk+1eWRby54T004SO iSgqeyH+On7xz3wlTu0iPX0ix73eI3nlSk/qUeBwaXjC54KmMhA46pdDJ873OCdVurZytfL7fbk SfMtdNeKWVQ/wBb7Ceg== 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_01,2026-05-18_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 priorityscore=1501 phishscore=0 adultscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 clxscore=1015 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605130000 definitions=main-2605260063 On 5/26/2026 3:06 PM, Dmitry Baryshkov wrote: > On Tue, May 26, 2026 at 02:59:31PM +0800, Jianping Li wrote: >> On 5/25/2026 5:35 PM, Dmitry Baryshkov wrote: >>> On Mon, 25 May 2026 at 11:34, Jianping Li wrote: >>>> On 5/25/2026 4:30 PM, Dmitry Baryshkov wrote: >>>>> On Fri, May 22, 2026 at 02:55:29PM +0800, Jianping Li wrote: >>>>>> On 5/15/2026 9:36 PM, Dmitry Baryshkov wrote: >>>>>>> On Fri, May 15, 2026 at 08:42:14PM +0800, Jianping Li wrote: >>>>>>>> From: Ekansh Gupta >>>>>>>> >>>>>>>> fastrpc_req_munmap_impl() is called to unmap any buffer. The buffer is >>>>>>>> getting removed from the list after it is unmapped from DSP. This can >>>>>>>> create potential race conditions if any other thread removes the entry >>>>>>>> from list while unmap operation is ongoing. Remove the entry before >>>>>>> How can it remove the entry from the list? >>>>>> Multiple threads sharing the same file descriptor may invoke unmap concurrently. >>>>> => commit message >>>>> >>>>>>>> @@ -1898,7 +1897,14 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) >>>>>>>> return -EINVAL; >>>>>>>> } >>>>>>>> - return fastrpc_req_munmap_impl(fl, buf); >>>>>>>> + err = fastrpc_req_munmap_impl(fl, buf); >>>>>>>> + if (err) { >>>>>>>> + spin_lock(&fl->lock); >>>>>>>> + list_add_tail(&buf->node, &fl->mmaps); >>>>>>>> + spin_unlock(&fl->lock); >>>>>>>> + } >>>>>>> Is it expected that userspace tries to unmap it again? Or why is it >>>>>>> being added to the list? >>>>>> User process can call unmap and fastrpc library won't call the unmap again. >>>>> In the other email you wrote that the driver can be used by random apps. >>>>> So... what happens if userspace unmaps it again? What if the userspace >>>>> _doesn't_ unmap it (although you've just readded it back)? >>>> If the same buf is unmapped again, because it has already been added back to the list, the unmap logic will be executed again. >>>> If userspace no longer performs unmap, the driver will not unmap it proactively. >>>> The Fastrpc driver will free up this list during fastrpc user-free. >>> It will free the list. But what happens with the memory mapping? >> When device release is called, DSP side PD is also cleaned up, which includes cleaning up of DSP side mappings >> >> Before kref_put of fl, we call DSP process release, where DSP PD is cleaned up. >> >> After calling this, we go ahead and do buf_free of the list > Okay, capture this discussion in the commit message. Got it, thanks. I'll update the commit message in the next version patch. > >> Thanks, >> Jianping. >> >>>>>> Fastrpc driver will free up this list during fastrpc user-free. >>>