From patchwork Fri Sep 29 07:42:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 146674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp4170764vqu; Fri, 29 Sep 2023 09:47:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGw9EMkDyW8tBJig2DQlbPxFusmoO80LmSYe0ChT4IHXvuQh5QdR3h1oWtlv6frteQ1UGqf X-Received: by 2002:a17:903:228e:b0:1c6:2655:625d with SMTP id b14-20020a170903228e00b001c62655625dmr8564554plh.15.1696006041428; Fri, 29 Sep 2023 09:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696006041; cv=none; d=google.com; s=arc-20160816; b=IfPuDHwxmiJMFw0xWA5lPgo6WeLMwgsdjxZFFL8zUg6Lp8Hx77W3Z+MzRsYtwWbnwY auvZW4xUHjGzsrmhEUTWAk/DPvFAAPQz6K6tL0YHicJnPhA2YzXxddrZrFQlbO+bjlxY 5XbEBgdghgc07CffsKs/P++O+2GTpXrHYkMKI8luZ0GEADm62EzRTWVyeE79fwn2BZdS Qx0oEAx/yLhXlgQtqzLnjFhpzBDblHQJikYz+finZ7tBItlwqMffAWyuqmD3jCv5DwGY auUR4tHN+oZ+JmSsvFEnUP9LRKyf9JOtw95Jx5Z3RvZ1AQEBGgMsIme8wRBzmQY3x8qN 7HhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0rGGk5TlG7sve1jYkAhgjG+txIkMX8x3vOh+Kmoblfo=; fh=A6NNGgejDd0F81I6I/9zWdWOtBqD0woImsi6PTqxbkw=; b=yxbJVyc6aESWIJZruaWEwnWILX0BDaMutesGV5m7LaodG3ko7VwcjkPjcmTEZmjcjr Jqh/eMZxzwM0UOCg5rCQk5+j8wgVeoN7ifTv6kFyAmtivxZvlUc+H1IVyWmlTeuyziEv iiI8CZCSGKX2hgZ8AHWjlOILKKNT84GTUVVyBJA8hU/aorWy7ANNfkPa8I72d2cfxp+U lc63xRjMF1HOHdL6AGb3SKajCMtbTm0g6Esm20VlSMMNjvECnEg5cCnYMg2OcaAjSp6J SKiXbsiMCqj3Vbi8YFmiqHYUZym99Pw24a62oyT9MKgqvsdruFMt/BEczzzmVI8/xdhY IAVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=HKXOtQP4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id z16-20020a656650000000b00578aa7b0e03si20401877pgv.695.2023.09.29.09.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 09:47:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=HKXOtQP4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4F47682ABAB7; Fri, 29 Sep 2023 00:43:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232760AbjI2Hm7 (ORCPT + 20 others); Fri, 29 Sep 2023 03:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjI2Hm6 (ORCPT ); Fri, 29 Sep 2023 03:42:58 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C938B1A8; Fri, 29 Sep 2023 00:42:55 -0700 (PDT) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38T7gqhX029961; Fri, 29 Sep 2023 07:42:52 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=0rGGk5TlG7sve1jYkAhgjG+txIkMX8x3vOh+Kmoblfo=; b=HKXOtQP4Rk4qT7DGg6gqFbmWB59JyfgTvq15e6b+F3gFmJQuCL13Vbo09x9PmSBKcRjl CFC97MVHIkJ9IbG7caIGU2I5VNxkXuMYGaGAnDTp+frrs1oUzvSNmiPCoam3H3HUcs8D iAOZuNFGxwQtR+82hU5lDLgT7gCPty4hF1MVIkkgQhbOBTYk1vn97b7P7zP56TwuzqBN S+hkfZpR0h96Q6sxK2ouXen5nJJpDk5APSXQn1YPRM0gTFJonemiEMVDSQjTip7o8En1 ru5P0KRmGQ/7pjCxllhunt5ARUuxDPhIaO5M2/7bcpoIjGi8aiW5gMCEiEGhEvHU+BSq BA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tda4c1t0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 07:42:51 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38T7goiL018442 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 07:42:50 GMT Received: from ekangupt-linux.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.36; Fri, 29 Sep 2023 00:42:47 -0700 From: Ekansh Gupta To: , CC: Ekansh Gupta , , , , , stable Subject: [PATCH v1 1/3] misc: fastrpc: Reset metadata buffer to avoid incorrect free Date: Fri, 29 Sep 2023 13:12:38 +0530 Message-ID: <1695973360-14369-2-git-send-email-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1695973360-14369-1-git-send-email-quic_ekangupt@quicinc.com> References: <1695973360-14369-1-git-send-email-quic_ekangupt@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: v0axPEQ6M4hpPFkmv_5rN9qqgsl7ITmy X-Proofpoint-ORIG-GUID: v0axPEQ6M4hpPFkmv_5rN9qqgsl7ITmy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-29_05,2023-09-28_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 clxscore=1011 mlxscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309290064 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 29 Sep 2023 00:43:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778391230993827470 X-GMAIL-MSGID: 1778391230993827470 Metadata buffer is allocated during get_args for any remote call. This buffer carries buffers, fdlists and other payload information for the call. If the buffer is not reset, put_args might find some garbage FDs in the fdlist which might have an existing mapping in the list. This could result in improper freeing of FD map when DSP might still be using the buffer. Added change to reset the metadata buffer after allocation. Fixes: 8f6c1d8c4f0c ("misc: fastrpc: Add fdlist implementation") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index a66b7c1..fb92197 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -958,6 +958,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) if (err) return err; + memset(ctx->buf->virt, 0, pkt_size); rpra = ctx->buf->virt; list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages = fastrpc_phy_page_start(list, ctx->nscalars); From patchwork Fri Sep 29 07:42:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 146694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp4211376vqu; Fri, 29 Sep 2023 10:58:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLM6aNxk95NY7zk3aDG47/QLumgABI3PanwOaWYQNegwWrZ56xcyz0nlUHtGYp2he7AhiT X-Received: by 2002:a05:6a20:549c:b0:14c:d494:77d1 with SMTP id i28-20020a056a20549c00b0014cd49477d1mr5609322pzk.10.1696010302350; Fri, 29 Sep 2023 10:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696010302; cv=none; d=google.com; s=arc-20160816; b=zoCiVXoYqZ86MLJujHLxFNEh7zGKa7IuQ6xTZgCS45NDlILAUJNP/NvpEaP+aOD3gz AYALAdHirEJwvEbdWz8FhIH0t9jB9THWba560UA63hGE1+Bi7azqdlBMjeffQb/J7LJX IxfHtvynifqPaS2VnZozT6Itd3gL+DkZhVGKtZmzaV4j3sVnwBJou3srfRQLuE6IPu9n Apsb5QT71a9YcYJSmmbX3O+P2AZCY7rmhVep32WrdRPoROS7ef0gayIbvf1qzQauETZJ sh5mjKUeNQINhVBq6H56jfKQ67veu0zwXcbxxGK3dDL16HQptI2nVOkPMonlII7L59ux SwHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JnvGPfam0j++dYMYQFm6Fq6OnF+GhvPcHneOtNp3o/Q=; fh=A6NNGgejDd0F81I6I/9zWdWOtBqD0woImsi6PTqxbkw=; b=soPqxKnO2jTvSEZp/GFqk1ciGwFeTVwOqpTQfYo4WPguSe8MCsVGj/i8T0kHEVuPGg R5vID6inaIqkyHojYC+sI539deh7kJYN8rkBTyAFcrqjkp1uc62fF+8ckNItNVPQOYVm 2ACUgg5SPfPc0KVcAxGK6OVmDcx7MvzesxwW3glFnqem3SCE9aUJkYIAu3fAFK2yiJid NkcfdGSuNmyd62HQOJ60tkto5bD6Ge2OScZXHcC9o3Gah0g1UNAZf7lhAys4MLtQWsu3 P7OT0J3YBp7SxdgNoE/KDWQGkSZa3bE1IiJegK+tZf/90v53rydRgKNuwmPWQwne1Eu1 ma0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JlSyg4hX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n12-20020a170902d2cc00b001b829a32f2dsi23212444plc.457.2023.09.29.10.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 10:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=JlSyg4hX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BA66480FA869; Fri, 29 Sep 2023 00:43:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232779AbjI2HnF (ORCPT + 20 others); Fri, 29 Sep 2023 03:43:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbjI2HnB (ORCPT ); Fri, 29 Sep 2023 03:43:01 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32F351B3; Fri, 29 Sep 2023 00:42:59 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38T7FrGp025017; Fri, 29 Sep 2023 07:42:55 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=JnvGPfam0j++dYMYQFm6Fq6OnF+GhvPcHneOtNp3o/Q=; b=JlSyg4hXf7vy2PgbI0GhKucm6zvBiHeXWf1+ugmXkWEzDwqnaTV0ypxZoHfw7jtJLshi xgkCUBzgfyB/O8xZz0YI4mHulG7LfaJzfg0531BQnBRmICqjtXGThcv1TkTBzQy1llv7 R/qPtrG7cl6/SFSJQ0rlyKafKDxDU9cpLCxu7DNvQ0Kb+wAp4QrTwmfCsKFYQb6sm6/Y xMbZKUfyiVrT546shTtFIy5n6VZaGrB3YuLTS11v0txa9/9f682fEdQR76oN6liC+jJz K8M+oewHhlRGLnXLq8ks584KK8nrISac0UuB3X44wMOwQsT+fB8pQxcQWPtmoV/4IzEv lA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3td5se2bvw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 07:42:55 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38T7gsk2021131 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 07:42:54 GMT Received: from ekangupt-linux.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.36; Fri, 29 Sep 2023 00:42:50 -0700 From: Ekansh Gupta To: , CC: Ekansh Gupta , , , , , stable Subject: [PATCH v1 2/3] misc: fastrpc: Free DMA handles for RPC calls with no arguments Date: Fri, 29 Sep 2023 13:12:39 +0530 Message-ID: <1695973360-14369-3-git-send-email-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1695973360-14369-1-git-send-email-quic_ekangupt@quicinc.com> References: <1695973360-14369-1-git-send-email-quic_ekangupt@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: 5-oN3xOW69dh9HyhGz1AHXbsTnSK5KGY X-Proofpoint-GUID: 5-oN3xOW69dh9HyhGz1AHXbsTnSK5KGY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-29_05,2023-09-28_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 suspectscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309290064 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 29 Sep 2023 00:43:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778395698855674687 X-GMAIL-MSGID: 1778395698855674687 The FDs for DMA handles to be freed is updated in fdlist by DSP over a remote call. This holds true even for remote calls with no arguments. To handle this, get_args and put_args are needed to be called for remote calls with no arguments also as fdlist is allocated in get_args and FDs updated in fdlist is freed in put_args. Fixes: 8f6c1d8c4f0c ("misc: fastrpc: Add fdlist implementation") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index fb92197..a52701c 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1091,6 +1091,7 @@ 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]) break; @@ -1157,11 +1158,9 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (IS_ERR(ctx)) return PTR_ERR(ctx); - if (ctx->nscalars) { - err = fastrpc_get_args(kernel, ctx); - if (err) - goto bail; - } + err = fastrpc_get_args(kernel, ctx); + if (err) + goto bail; /* make sure that all CPU memory writes are seen by DSP */ dma_wmb(); @@ -1185,14 +1184,12 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (err) goto bail; - if (ctx->nscalars) { - /* make sure that all memory writes by DSP are seen by CPU */ - dma_rmb(); - /* populate all the output buffers with results */ - err = fastrpc_put_args(ctx, kernel); - if (err) - goto bail; - } + /* make sure that all memory writes by DSP are seen by CPU */ + dma_rmb(); + /* populate all the output buffers with results */ + err = fastrpc_put_args(ctx, kernel); + if (err) + goto bail; bail: if (err != -ERESTARTSYS && err != -ETIMEDOUT) { From patchwork Fri Sep 29 07:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 146498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3950304vqu; Fri, 29 Sep 2023 04:24:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM0VRgWomM3a02wOJzAB+YjVNZqkeSbWcKKgTUzEqV7h4NE23+wOuEmIAH6cPCrXQpFd9g X-Received: by 2002:a17:90b:250:b0:269:5b17:24b6 with SMTP id fz16-20020a17090b025000b002695b1724b6mr3582039pjb.9.1695986690555; Fri, 29 Sep 2023 04:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695986690; cv=none; d=google.com; s=arc-20160816; b=R+PBvATj7ohh6sN9AAYBcHUGXsK7W/R2rvqd2YvhVwZaakwh5c3JC8qxdimljYCGiE WILgjsGt2da1vbWxWfDV6Taxmm8CR4bjbe5weMqlJc9mb4cW/fjnrLcm4PYl/q4O3WfQ DLx25XGArUFQyZZM53/ppJyrv904DBIcx2WrzBbQoEqnbz9r2j0uxuQtWkEozLc+w4D4 dswucVfb17zGxistJLmNaufFTGJznEJyNl1eqGG4LFxpUd5/Y9MO33gdIfcplPKRk6x9 TlUo7injtZz5kYSuwSvruGHaCugsE33PbZeOm5hOZkRZ/MktD4WHD9QOoHNJvHuahO37 Jj8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5Bd9K5iycOja+CvdiqeJ6+Z3JpHqasc5jcyyWk1dwn4=; fh=A6NNGgejDd0F81I6I/9zWdWOtBqD0woImsi6PTqxbkw=; b=fG3O5eeZFhXpTQXSvAvMLmRiRj0gULZrZOcxjenq31uEKJgb9X+orceJE+56MFa8+Q wEr10k5XDo2dW9grPYEbKs80g+ctkWlOGUNKIBagQ6YwN+FT6HzOe1PsnzPHlJILAXy5 /AviKqmPOzgs/aBwlOBzP1NV4NAdTF+5HbwI1TdZrTjcpyydaIWI6ikyirB3QGuVmJ/c y5HVKhUxp/GEHwpsZeP15uohsRZeRsRFyKfNyemFe2pLQn9NLjc7jK7XOEQRyChdTl9t hX98bSt25NLJpNW7T+HCcVUiJDNuUpQ2lCmWgKkvkRvAsGuJLSeQIl3o+RIQnw9cOlPd D65w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gA68tXf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id kk8-20020a17090b4a0800b002791e9b60f9si1413956pjb.48.2023.09.29.04.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 04:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gA68tXf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E76CE801B42D; Fri, 29 Sep 2023 00:43:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232666AbjI2HnV (ORCPT + 20 others); Fri, 29 Sep 2023 03:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232824AbjI2HnN (ORCPT ); Fri, 29 Sep 2023 03:43:13 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A89991A8; Fri, 29 Sep 2023 00:43:10 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38T4gaA1032706; Fri, 29 Sep 2023 07:42:58 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=5Bd9K5iycOja+CvdiqeJ6+Z3JpHqasc5jcyyWk1dwn4=; b=gA68tXf57HXYj3LXeAyhVqaH8S6UrPQJfygZst2d9w3VvA6c+Sbyl65m+V3tc4gcFSxP CTYUxCOt1PbxQpB1/NaSIRO9xwi6VJc/o74Lh5TgBxKnUID3Q0ddmv+/cR4quEw6/B0K 0Z9GD6zlChQSMKuwCZoGNhOZtIlbUsT7/ggD2oGYR1VBB+WKLdNUQyzC+09EqguD3H27 5d3c4jz82B6Etv+AJ0Jn6gOoTI0dBzIMJum0MaCKmjLLM/JdmNjqxuNFNS2BFZB8wdGN +OM6iIe/4xMhsu45swXtCP8LrJgGtwgT6FDNerPlfZpyY40DrQPW5H2UcwQ/mfMUTc5J OQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tct5guypj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 07:42:58 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38T7gvMD021149 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 07:42:57 GMT Received: from ekangupt-linux.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.36; Fri, 29 Sep 2023 00:42:54 -0700 From: Ekansh Gupta To: , CC: Ekansh Gupta , , , , , stable Subject: [PATCH v1 3/3] misc: fastrpc: Clean buffers on remote invocation failures Date: Fri, 29 Sep 2023 13:12:40 +0530 Message-ID: <1695973360-14369-4-git-send-email-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1695973360-14369-1-git-send-email-quic_ekangupt@quicinc.com> References: <1695973360-14369-1-git-send-email-quic_ekangupt@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: 7n46u-urYstt8g6co3IFskxXydPO6Wmx X-Proofpoint-GUID: 7n46u-urYstt8g6co3IFskxXydPO6Wmx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-29_05,2023-09-28_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309290064 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 29 Sep 2023 00:43:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778370939789999576 X-GMAIL-MSGID: 1778370939789999576 With current design, buffers and dma handles are not freed in case of remote invocation failures returned from DSP. This could result in buffer leakings and dma handle pointing to wrong memory in the fastrpc kernel. Adding changes to clean buffers and dma handles even when remote invocation to DSP returns failures. Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index a52701c..3cdc584 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1179,11 +1179,6 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (err) goto bail; - /* Check the response from remote dsp */ - err = ctx->retval; - if (err) - goto bail; - /* make sure that all memory writes by DSP are seen by CPU */ dma_rmb(); /* populate all the output buffers with results */ @@ -1191,6 +1186,11 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (err) goto bail; + /* Check the response from remote dsp */ + err = ctx->retval; + if (err) + goto bail; + bail: if (err != -ERESTARTSYS && err != -ETIMEDOUT) { /* We are done with this compute context */