From patchwork Tue May 28 11:29:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676480 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 8EDE6182B3; Tue, 28 May 2024 11:30:14 +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=1716895816; cv=none; b=TmkyPWoDvCgLUkl427rkVJPyLfYrT0HpRr2ZuRYcSTCbBd0JX3niRapHV21GcVwubFVc682YiLZ65BTNXTpNgvRhInfB3pN/dBQLUrjnpGsw58hzNXKHbUwKL06Ugeb9PUD5hWGXw/hXb/OLiKd7t1XqDBZIdgNb3VSBebC8BWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895816; c=relaxed/simple; bh=RWIsEqPeVlOmF7FXwHF2Q/qHk0T/3X6I1ml83lchXR8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sKFlnFYqK+p4T2vd4OTJoZKs4Sd9fIDQFOMonDU52M/7ElA4sRTo+VQrZPtgFFijMoBLfuP0TAaUPfMmMrj+ZoAd+USZdktd0cYv6oPgtTdEzZuuf+lHRQE19QkAaq0BXg7M4C160t01+TRGYFGdGTPs6+J9HiVfQiCzoK9a1aE= 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=mcKOA1mh; arc=none smtp.client-ip=205.220.168.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="mcKOA1mh" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SAwQdj022257; Tue, 28 May 2024 11:30:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= zar8uZesiyIz13yi/Q7CM/fVi8HkaqVyoZ/iInraejo=; b=mcKOA1mhX8YVQbjh dw8DHzJ7wotGuOgxvfiEQjoEHvuMAQO3v3S1w1U/kA/sKbEevbjVDvtZq2B8SyT/ 5tJOZQ2lp1mn4/apbQr198JIXeOgnTuafYtFULAJzS2fAaP/FRr8MrPQEHZnkXda bWfyhcYZnthNuHfnNmEr/huzNW3OWpD5woGZaxhWSST5ZX0lk7BEkB1utT29eaiU R+B7buUFQ64KBWFE4dBRuwMZ9ILprrW5lWDFsemLLoqE4X0KoIesCV85o1aPVti4 o0GQL5naejyeq1nnDanQkIkj/EqVSTPvjz509/22QGsgTLXHbxI7gWZedLcfqdBY De26ig== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba1k5wcj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:11 +0000 (GMT) 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 44SBUAR3007523 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:10 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.1544.9; Tue, 28 May 2024 04:30:07 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 1/8] misc: fastrpc: Add missing dev_err newlines Date: Tue, 28 May 2024 16:59:47 +0530 Message-ID: <20240528112956.5979-2-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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: zG7c15ugTVzNi9gst-AIW11dVKKW-D9W X-Proofpoint-GUID: zG7c15ugTVzNi9gst-AIW11dVKKW-D9W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1011 priorityscore=1501 lowpriorityscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Few dev_err calls are missing newlines. This can result in unrelated lines getting appended which might make logs difficult to understand. Add trailing newlines to avoid this. Signed-off-by: Ekansh Gupta Reviewed-by: Dmitry Baryshkov --- 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 4c67e2c5a82e..4028cb96bcf2 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -325,7 +325,7 @@ static void fastrpc_free_map(struct kref *ref) err = qcom_scm_assign_mem(map->phys, map->size, &src_perms, &perm, 1); if (err) { - dev_err(map->fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d", + dev_err(map->fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", map->phys, map->size, err); return; } @@ -816,7 +816,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd, map->attr = attr; err = qcom_scm_assign_mem(map->phys, (u64)map->size, &src_perms, dst_perms, 2); if (err) { - dev_err(sess->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d", + dev_err(sess->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d\n", map->phys, map->size, err); goto map_err; } @@ -1222,7 +1222,7 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques * that does not support unsigned PD offload */ if (!fl->cctx->unsigned_support || !unsigned_pd_request) { - dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD"); + dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD\n"); return true; } } @@ -1285,7 +1285,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); if (err) { - dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d", + dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d\n", fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); goto err_map; } @@ -1337,7 +1337,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, (u64)fl->cctx->remote_heap->size, &src_perms, &dst_perms, 1); if (err) - dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d", + dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); } err_map: From patchwork Tue May 28 11:29:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676484 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 9F75116C849; Tue, 28 May 2024 11:30:28 +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=1716895830; cv=none; b=Iae+uCvFsy87rzvSV3RfpfWOZT8waYpDsrxxZ2QGe0G6ntDEeen5dGZXnf2j0xr7HTUMYc9CqZofEccQnAsbG8Ra0NKMOXBq2cPkFRkMJ3zcwYba9/mLQj7LbNvpn6BdfOQDyhoxvLtzGuUIzbWYjbSvkq8yM0WwjGazTNxt08E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895830; c=relaxed/simple; bh=AcuyhtQ6bvBzy8YUVGc8awBJZuAK8x1nA1LM2fUqigQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p+Iws9D8siHdyq+vXdZpxBKB59jBJ9DeByZ63BlMyWYyUtQ8MbPZZ/w5cVtxJkr7oYDh8JBvT5p8HrHokvTajqseanEe1Vm8LEQaKvUy5m6tvcvVHIQMZMVVSXem0dBCrjnLUsVQd5OPyVszWAeYG+gWUknGGdc089k9/SvGaGA= 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=oUWiSxqG; 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="oUWiSxqG" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44RN68dH021695; Tue, 28 May 2024 11:30:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= UQ3IpkA+E/iRPZ2pDpvk41LjQvlXFdoRtybvckLcti0=; b=oUWiSxqGdd/hmKde laU2AqFo6uMbVcA9jMcg8amAaz2dnvr/4569vb3LUtrrSSVIG4VkjdfVVhP3Eshr 0kj/RrwUY/cgt/6sRlAF6qSlwVqp+F6R750nxzZszXoJ0b1u31VqG45waMH1Ctf3 X2K5A3GQIGwwRTRw4STKeVfF36rFUXWgmzZzKxv4tcbMKLwTFYrK42hpsNulYgx9 zQZHKGyNXDG8H2/UTY/XA1uW4tdl0zuuqrfqma5QSxZuWZaf/ziQYtgYvVRHZpq1 IevsEl1NyYvXzeMT+DYJL8avbZ8L9P8k78ekKgvlyYAIgVK9DE5i3ZrxNmtJ+lyv VtCaCg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2mwtwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:22 +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 44SBUD9L027814 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:13 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.1544.9; Tue, 28 May 2024 04:30:10 -0700 From: Ekansh Gupta To: , CC: , , , , stable Subject: [PATCH v2 2/8] misc: fastrpc: Fix DSP capabilities request Date: Tue, 28 May 2024 16:59:48 +0530 Message-ID: <20240528112956.5979-3-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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-GUID: FFS_PTCBU34lvcp-2CaavSJPazbqNmsK X-Proofpoint-ORIG-GUID: FFS_PTCBU34lvcp-2CaavSJPazbqNmsK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Incorrect remote arguments are getting passed when requesting for capabilities from DSP. Also there is no requirement to update the PD type as it might cause problems for any PD other than user PD. In addition to this, the collected capability information is not getting copied properly to user. Add changes to address these problems and get correct DSP capabilities. Also, DSP capabilities request is sending bad size to utilities skel call which is resulting in memory corruption. Pass proper size to avoid the corruption. Fixes: 6c16fd8bdd40 ("misc: fastrpc: Add support to get DSP capabilities") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 4028cb96bcf2..3e1ab58038ed 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1695,14 +1695,14 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_user *fl, uint32_t *dsp_attr /* Capability filled in userspace */ dsp_attr_buf[0] = 0; + dsp_attr_buf_len -= 1; args[0].ptr = (u64)(uintptr_t)&dsp_attr_buf_len; args[0].length = sizeof(dsp_attr_buf_len); args[0].fd = -1; args[1].ptr = (u64)(uintptr_t)&dsp_attr_buf[1]; - args[1].length = dsp_attr_buf_len; + args[1].length = dsp_attr_buf_len * sizeof(uint32_t); args[1].fd = -1; - fl->pd = USER_PD; return fastrpc_internal_invoke(fl, true, FASTRPC_DSP_UTILITIES_HANDLE, FASTRPC_SCALARS(0, 1, 1), args); @@ -1730,7 +1730,7 @@ static int fastrpc_get_info_from_kernel(struct fastrpc_ioctl_capability *cap, if (!dsp_attributes) return -ENOMEM; - err = fastrpc_get_info_from_dsp(fl, dsp_attributes, FASTRPC_MAX_DSP_ATTRIBUTES_LEN); + err = fastrpc_get_info_from_dsp(fl, dsp_attributes, FASTRPC_MAX_DSP_ATTRIBUTES); if (err == DSP_UNSUPPORTED_API) { dev_info(&cctx->rpdev->dev, "Warning: DSP capabilities not supported on domain: %d\n", domain); @@ -1783,7 +1783,7 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp) if (err) return err; - if (copy_to_user(argp, &cap.capability, sizeof(cap.capability))) + if (copy_to_user(argp, &cap, sizeof(cap))) return -EFAULT; return 0; From patchwork Tue May 28 11:29:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676488 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 BBBD416D9A4; Tue, 28 May 2024 11:30:34 +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=1716895836; cv=none; b=ZXEg2z2RTmIKj3heuDqzEUXr+dpYwgK2HyKijKTTiS6lparwl18LuyjxH0ojqQmGCJ5i1xfIHdJNLqMqPyG1vrl75/8HQyZSNfWuoDuTruzlXV3IDpA6hpPc5Q+J54r35Imjzoenc0789KtnLAHC5eWTabpc/+CIJvGOJkVW9qc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895836; c=relaxed/simple; bh=+L7kuUmr9FyAZbCUcKYYeYkJAEw/ysT9W6xjTStfBkE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DTTc6Pz3G1fQ7V8x0HtAGVh+X5MZ+Yvv4CHFl9onpQIrFLFFOcXY27FOauSdZoIVTNPx1xoUWkGqdT2lCi0Qh+ATMq6FP2FCYAOF6zQlWV+yBg8wVuIyBU4rnrL0HbFATwrz9LjpughPYcX9iqD4jyb1DAzBP27aHeo8ya+lsFw= 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=E1P2H9BL; 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="E1P2H9BL" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SB8JAv001099; Tue, 28 May 2024 11:30:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= DCKxu3wI0UPd81xSXuFLpW1mBarClzhlEbq/D2G8tBA=; b=E1P2H9BLZmmmMJFX uP39wTlWwWFbH2OR8X4BKORwZhRsxXhXafNRMY6poKmMreFNhxvHozCHwoi86cQr EaaugXUFs4eFvj988I+lDVu+mctht9dJgvZQWJRcUJvuYOnTwIjx0RT0mm9MNDzT H2ckK94USSDrb4pZPMTNhIntYZBeeRr2zz/Nk6GgBiLr3JizwgFzyC4PN1MZF0GZ 45POH+dxyJ1kDzfmoJ+LCHgiPmsIhCoV+8cJ+LAQwwiHmqnqMC3dEJnnK6eRAlKY 1Mv2xSlGHGyzxUdWkKiFVptz37Z9uvIS3ub4VBZuXz8UfKIPlw1ZwKMIUy0NsV2F s1hinw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yb9yj5wy4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:31 +0000 (GMT) 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 44SBUFOv001609 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:15 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.1544.9; Tue, 28 May 2024 04:30:13 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 3/8] misc: fastrpc: Add support to save and restore Date: Tue, 28 May 2024 16:59:49 +0530 Message-ID: <20240528112956.5979-4-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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-GUID: wY9vmNjWoEu53iSKUTl04-BczrhQSD6J X-Proofpoint-ORIG-GUID: wY9vmNjWoEu53iSKUTl04-BczrhQSD6J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 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 | 105 +++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 3e1ab58038ed..6556c63c4ad7 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -241,7 +241,6 @@ struct fastrpc_invoke_ctx { struct kref refcount; struct list_head node; /* list of ctxs */ struct completion work; - struct work_struct put_work; struct fastrpc_msg msg; struct fastrpc_user *fl; union fastrpc_remote_arg *rpra; @@ -276,7 +275,6 @@ struct fastrpc_channel_ctx { struct fastrpc_device *secure_fdevice; struct fastrpc_device *fdevice; struct fastrpc_buf *remote_heap; - struct list_head invoke_interrupted_mmaps; bool secure; bool unsigned_support; u64 dma_mask; @@ -292,6 +290,7 @@ struct fastrpc_user { struct list_head user; struct list_head maps; struct list_head pending; + struct list_head interrupted; struct list_head mmaps; struct fastrpc_channel_ctx *cctx; @@ -513,14 +512,6 @@ static void fastrpc_context_put(struct fastrpc_invoke_ctx *ctx) kref_put(&ctx->refcount, fastrpc_context_free); } -static void fastrpc_context_put_wq(struct work_struct *work) -{ - struct fastrpc_invoke_ctx *ctx = - container_of(work, struct fastrpc_invoke_ctx, put_work); - - fastrpc_context_put(ctx); -} - #define CMP(aa, bb) ((aa) == (bb) ? 0 : (aa) < (bb) ? -1 : 1) static int olaps_cmp(const void *a, const void *b) { @@ -616,7 +607,6 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( ctx->tgid = user->tgid; ctx->cctx = cctx; init_completion(&ctx->work); - INIT_WORK(&ctx->put_work, fastrpc_context_put_wq); spin_lock(&user->lock); list_add_tail(&ctx->node, &user->pending); @@ -647,6 +637,40 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( return ERR_PTR(ret); } +static struct fastrpc_invoke_ctx *fastrpc_context_restore_interrupted( + struct fastrpc_user *fl, u32 sc) +{ + struct fastrpc_invoke_ctx *ctx = NULL, *ictx = NULL, *n; + + spin_lock(&fl->lock); + list_for_each_entry_safe(ictx, n, &fl->interrupted, node) { + if (ictx->pid == current->pid) { + if (sc != ictx->sc || ictx->fl != 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, sc, fl); + spin_unlock(&fl->lock); + return ERR_PTR(-EINVAL); + } + ctx = 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) @@ -1138,7 +1162,6 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, struct fastrpc_invoke_args *args) { struct fastrpc_invoke_ctx *ctx = NULL; - struct fastrpc_buf *buf, *b; int err = 0; @@ -1153,6 +1176,14 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, return -EPERM; } + if (!kernel) { + ctx = fastrpc_context_restore_interrupted(fl, sc); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); + if (ctx) + goto wait; + } + ctx = fastrpc_context_alloc(fl, kernel, sc, args); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1168,6 +1199,7 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (err) goto bail; +wait: if (kernel) { if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) err = -ETIMEDOUT; @@ -1191,7 +1223,9 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, goto bail; bail: - if (err != -ERESTARTSYS && err != -ETIMEDOUT) { + if (ctx && err == -ERESTARTSYS) { + fastrpc_context_save_interrupted(ctx); + } else if (ctx) { /* We are done with this compute context */ spin_lock(&fl->lock); list_del(&ctx->node); @@ -1199,13 +1233,6 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, fastrpc_context_put(ctx); } - if (err == -ERESTARTSYS) { - list_for_each_entry_safe(buf, b, &fl->mmaps, node) { - list_del(&buf->node); - list_add_tail(&buf->node, &fl->cctx->invoke_interrupted_mmaps); - } - } - if (err) dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err); @@ -1496,6 +1523,25 @@ static void fastrpc_session_free(struct fastrpc_channel_ctx *cctx, spin_unlock_irqrestore(&cctx->lock, flags); } +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]; @@ -1516,7 +1562,6 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) { struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data; struct fastrpc_channel_ctx *cctx = fl->cctx; - struct fastrpc_invoke_ctx *ctx, *n; struct fastrpc_map *map, *m; struct fastrpc_buf *buf, *b; unsigned long flags; @@ -1530,10 +1575,7 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) if (fl->init_mem) fastrpc_buf_free(fl->init_mem); - list_for_each_entry_safe(ctx, n, &fl->pending, node) { - list_del(&ctx->node); - fastrpc_context_put(ctx); - } + fastrpc_context_list_free(fl); list_for_each_entry_safe(map, m, &fl->maps, node) fastrpc_map_put(map); @@ -1574,6 +1616,7 @@ static int fastrpc_device_open(struct inode *inode, struct 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); @@ -2332,7 +2375,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) rdev->dma_mask = &data->dma_mask; dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32)); INIT_LIST_HEAD(&data->users); - INIT_LIST_HEAD(&data->invoke_interrupted_mmaps); spin_lock_init(&data->lock); idr_init(&data->ctx_idr); data->domain_id = domain_id; @@ -2370,7 +2412,6 @@ static void fastrpc_notify_users(struct fastrpc_user *user) static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) { struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev); - struct fastrpc_buf *buf, *b; struct fastrpc_user *user; unsigned long flags; @@ -2387,9 +2428,6 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) if (cctx->secure_fdevice) misc_deregister(&cctx->secure_fdevice->miscdev); - list_for_each_entry_safe(buf, b, &cctx->invoke_interrupted_mmaps, node) - list_del(&buf->node); - if (cctx->remote_heap) fastrpc_buf_free(cctx->remote_heap); @@ -2424,12 +2462,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, ctx->retval = rsp->retval; complete(&ctx->work); - /* - * The DMA buffer associated with the context cannot be freed in - * interrupt context so schedule it through a worker thread to - * avoid a kernel BUG. - */ - schedule_work(&ctx->put_work); + fastrpc_context_put(ctx); return 0; } From patchwork Tue May 28 11:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676481 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 BE59D7D07D; Tue, 28 May 2024 11:30:23 +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=1716895825; cv=none; b=IVjsT/PwWZ33jmWpZL/sWzsu95O3Q8oZvJIIkxwgPWWmSyojBc3qg9kwxeBFWW1QOXWMhbmas7+ue96X042js33QXfEtMYQXVj5Iq2vdmCJOjQVTkyoagOfX3YeR5T5HK9Hdmb/VzGqNj0uRYdIv/EM1U8F8TJF7e4hfI97WtQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895825; c=relaxed/simple; bh=stEOMRE5qaaxUEKxC9KKoTrg2An3XsDVIS1rT20bowY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZofWZPaW5qvsa1orHkGvC4fkmXb6vvXAIi8ZOUyFGkvJne3gnXGeWuey+Pga+95PJzr5MR7o/EdP8tEe3gDrwUb/DXBwc3BU4O/HH4PM97ER45Bj1DYW5IiavlaOt9SMax4MSKuvnf+v8cJrMbcrnq/mrHnoU5BRLmevpGAR8yE= 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=mk1TvVJs; 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="mk1TvVJs" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SA5AsD001837; Tue, 28 May 2024 11:30:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= cC1hDyz2CCa8jeJyKNelkqAicu2gVEEwkU7DAVmLdpM=; b=mk1TvVJsi2L4NtxN rBhmarM22HKlq50ft+40zOr/foErBrcoQpJEd1dfPi5NYJ4irMA6DGeewBCnQBxK 0PtJYWrltcVUxj7yY+0286rC5Y79QnkPVQ97cbTRNy/P4ti1Gw70J86sOHO9TSTg DpaZkGiIX0vw9ZjU1jWzwZNTnpcwYlhBKCiCn3b8aQw+eeftvdaNuMURTqs0bINB 5d0XHrcX3U5lfamBfWiRKIdi2eV9UBl0AGG6PVt7JHPrHQTkl5f6n8VSrhtu+YK7 IdwyfkOPufSCNLkg3SNavn77vk7doQKDzS6NPfkpktEmdBykwyyvjJkIHd7azEaF TcmPWw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0g5yfe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:20 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44SBUIcr021829 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:18 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.1544.9; Tue, 28 May 2024 04:30:15 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 4/8] misc: fastrpc: Add static PD restart support Date: Tue, 28 May 2024 16:59:50 +0530 Message-ID: <20240528112956.5979-5-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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-GUID: KCmnxBIlYrWYjPXuyGLUoLRR9YCxCHIS X-Proofpoint-ORIG-GUID: KCmnxBIlYrWYjPXuyGLUoLRR9YCxCHIS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Static PDs on the audio and sensor domains are expected to support PD restart. The kernel resource handling for the PDs are expected to be handled by fastrpc driver. For this, there is a requirement of PD service locator to get the event notifications for static PD services. Also when events are received, the driver needs to handle based on PD states. Added changes to add service locator for audio and sensor domain static PDs and handle the PD restart sequence. Signed-off-by: Ekansh Gupta --- drivers/misc/Kconfig | 2 + drivers/misc/fastrpc.c | 205 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 195 insertions(+), 12 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index faf983680040..e2d83cd085b5 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -280,8 +280,10 @@ config QCOM_FASTRPC tristate "Qualcomm FastRPC" depends on ARCH_QCOM || COMPILE_TEST depends on RPMSG + depends on NET select DMA_SHARED_BUFFER select QCOM_SCM + select QCOM_PDR_HELPERS help Provides a communication mechanism that allows for clients to make remote method invocations across processor boundary to diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 6556c63c4ad7..7796b743cc45 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -22,6 +22,7 @@ #include #include #include +#include #define ADSP_DOMAIN_ID (0) #define MDSP_DOMAIN_ID (1) @@ -29,6 +30,7 @@ #define CDSP_DOMAIN_ID (3) #define FASTRPC_DEV_MAX 4 /* adsp, mdsp, slpi, cdsp*/ #define FASTRPC_MAX_SESSIONS 14 +#define FASTRPC_MAX_SPD 4 #define FASTRPC_MAX_VMIDS 16 #define FASTRPC_ALIGN 128 #define FASTRPC_MAX_FDLIST 16 @@ -105,6 +107,18 @@ #define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscdev) +#define AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME "audio_pdr_adsp" +#define AUDIO_PDR_ADSP_SERVICE_NAME "avs/audio" +#define ADSP_AUDIOPD_NAME "msm/adsp/audio_pd" + +#define SENSORS_PDR_ADSP_SERVICE_LOCATION_CLIENT_NAME "sensors_pdr_adsp" +#define SENSORS_PDR_ADSP_SERVICE_NAME "tms/servreg" +#define ADSP_SENSORPD_NAME "msm/adsp/sensor_pd" + +#define SENSORS_PDR_SLPI_SERVICE_LOCATION_CLIENT_NAME "sensors_pdr_slpi" +#define SENSORS_PDR_SLPI_SERVICE_NAME SENSORS_PDR_ADSP_SERVICE_NAME +#define SLPI_SENSORPD_NAME "msm/slpi/sensor_pd" + static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", "sdsp", "cdsp"}; struct fastrpc_phy_page { @@ -258,6 +272,15 @@ struct fastrpc_session_ctx { bool valid; }; +struct fastrpc_static_pd { + char *servloc_name; + char *spdname; + void *pdrhandle; + struct fastrpc_channel_ctx *cctx; + struct fastrpc_user *fl; + bool ispdup; +}; + struct fastrpc_channel_ctx { int domain_id; int sesscount; @@ -265,6 +288,7 @@ struct fastrpc_channel_ctx { struct qcom_scm_vmperm vmperms[FASTRPC_MAX_VMIDS]; struct rpmsg_device *rpdev; struct fastrpc_session_ctx session[FASTRPC_MAX_SESSIONS]; + struct fastrpc_static_pd spd[FASTRPC_MAX_SPD]; spinlock_t lock; struct idr ctx_idr; struct list_head users; @@ -296,10 +320,12 @@ struct fastrpc_user { struct fastrpc_channel_ctx *cctx; struct fastrpc_session_ctx *sctx; struct fastrpc_buf *init_mem; + struct fastrpc_static_pd *spd; int tgid; int pd; bool is_secure_dev; + char *servloc_name; /* Lock for lists */ spinlock_t lock; /* lock for allocations */ @@ -1257,12 +1283,33 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques return false; } +static struct fastrpc_static_pd *fastrpc_get_spd_session( + struct fastrpc_user *fl) +{ + int i; + struct fastrpc_static_pd *spd = NULL; + struct fastrpc_channel_ctx *cctx = fl->cctx; + + for (i = 0; i < FASTRPC_MAX_SPD ; i++) { + if (!cctx->spd[i].servloc_name) + continue; + if (!strcmp(fl->servloc_name, cctx->spd[i].servloc_name)) { + spd = &cctx->spd[i]; + spd->fl = fl; + break; + } + } + + return spd; +} + static int fastrpc_init_create_static_process(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_init_create_static init; struct fastrpc_invoke_args *args; struct fastrpc_phy_page pages[1]; + struct fastrpc_static_pd *spd = NULL; char *name; int err; struct { @@ -1297,6 +1344,19 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, goto err_name; } + fl->servloc_name = AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME; + + spd = fastrpc_get_spd_session(fl); + if (!spd) { + err = -EUSERS; + goto err_name; + } + + if (!spd->ispdup) { + err = -ENOTCONN; + goto err_name; + } + fl->spd = spd; if (!fl->cctx->remote_heap) { err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, &fl->cctx->remote_heap); @@ -1688,6 +1748,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp) static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) { struct fastrpc_invoke_args args[1]; + struct fastrpc_static_pd *spd = NULL; int tgid = fl->tgid; u32 sc; @@ -1697,6 +1758,22 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0); fl->pd = pd; + if (pd == SENSORS_PD) { + if (fl->cctx->domain_id == ADSP_DOMAIN_ID) + fl->servloc_name = SENSORS_PDR_ADSP_SERVICE_LOCATION_CLIENT_NAME; + else if (fl->cctx->domain_id == SDSP_DOMAIN_ID) + fl->servloc_name = SENSORS_PDR_SLPI_SERVICE_LOCATION_CLIENT_NAME; + + spd = fastrpc_get_spd_session(fl); + if (!spd) + return -EUSERS; + + if (!spd->ispdup) + return -ENOTCONN; + + fl->spd = spd; + } + return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]); } @@ -2172,6 +2249,64 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, return err; } +static void fastrpc_notify_users(struct fastrpc_user *user) +{ + struct fastrpc_invoke_ctx *ctx; + + spin_lock(&user->lock); + list_for_each_entry(ctx, &user->pending, node) { + ctx->retval = -EPIPE; + complete(&ctx->work); + } + spin_unlock(&user->lock); +} + +static void fastrpc_notify_pdr_drivers(struct fastrpc_channel_ctx *cctx, + char *servloc_name) +{ + struct fastrpc_user *fl; + unsigned long flags; + + spin_lock_irqsave(&cctx->lock, flags); + list_for_each_entry(fl, &cctx->users, user) { + if (fl->servloc_name && !strcmp(servloc_name, fl->servloc_name)) + fastrpc_notify_users(fl); + } + spin_unlock_irqrestore(&cctx->lock, flags); +} + +static void fastrpc_pdr_cb(int state, char *service_path, void *priv) +{ + struct fastrpc_static_pd *spd = (struct fastrpc_static_pd *)priv; + struct fastrpc_channel_ctx *cctx; + + if (!spd) + return; + + cctx = spd->cctx; + switch (state) { + case SERVREG_SERVICE_STATE_DOWN: + dev_info(&cctx->rpdev->dev, + "%s: %s (%s) is down for PDR on %s\n", + __func__, spd->spdname, + spd->servloc_name, + domains[cctx->domain_id]); + spd->ispdup = false; + fastrpc_notify_pdr_drivers(cctx, spd->servloc_name); + break; + case SERVREG_SERVICE_STATE_UP: + dev_info(&cctx->rpdev->dev, + "%s: %s (%s) is up for PDR on %s\n", + __func__, spd->spdname, + spd->servloc_name, + domains[cctx->domain_id]); + spd->ispdup = true; + break; + default: + break; + } +} + static const struct file_operations fastrpc_fops = { .open = fastrpc_device_open, .release = fastrpc_device_release, @@ -2291,6 +2426,39 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ct return err; } +static int fastrpc_setup_service_locator(struct fastrpc_channel_ctx *cctx, char *client_name, + char *service_name, char *service_path, int domain, int spd_session) +{ + int err = 0; + struct pdr_handle *handle = NULL; + struct pdr_service *service = NULL; + + /* Register the service locator's callback function */ + handle = pdr_handle_alloc(fastrpc_pdr_cb, &cctx->spd[spd_session]); + if (IS_ERR(handle)) { + err = PTR_ERR(handle); + goto bail; + } + cctx->spd[spd_session].pdrhandle = handle; + cctx->spd[spd_session].servloc_name = client_name; + cctx->spd[spd_session].spdname = service_path; + cctx->spd[spd_session].cctx = cctx; + service = pdr_add_lookup(handle, service_name, service_path); + if (IS_ERR(service)) { + err = PTR_ERR(service); + goto bail; + } + pr_info("fastrpc: %s: pdr_add_lookup enabled for %s (%s, %s)\n", + __func__, service_name, client_name, service_path); + +bail: + if (err) { + pr_warn("fastrpc: %s: failed for %s (%s, %s)with err %d\n", + __func__, service_name, client_name, service_path, err); + } + return err; +} + static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) { struct device *rdev = &rpdev->dev; @@ -2369,6 +2537,25 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) goto fdev_error; } + if (domain_id == ADSP_DOMAIN_ID) { + err = fastrpc_setup_service_locator(data, AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME, + AUDIO_PDR_ADSP_SERVICE_NAME, ADSP_AUDIOPD_NAME, domain_id, 0); + if (err) + goto populate_error; + + err = fastrpc_setup_service_locator(data, + SENSORS_PDR_ADSP_SERVICE_LOCATION_CLIENT_NAME, + SENSORS_PDR_ADSP_SERVICE_NAME, ADSP_SENSORPD_NAME, domain_id, 1); + if (err) + goto populate_error; + } else if (domain_id == SDSP_DOMAIN_ID) { + err = fastrpc_setup_service_locator(data, + SENSORS_PDR_SLPI_SERVICE_LOCATION_CLIENT_NAME, + SENSORS_PDR_SLPI_SERVICE_NAME, SLPI_SENSORPD_NAME, domain_id, 0); + if (err) + goto populate_error; + } + kref_init(&data->refcount); dev_set_drvdata(&rpdev->dev, data); @@ -2397,23 +2584,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) return err; } -static void fastrpc_notify_users(struct fastrpc_user *user) -{ - struct fastrpc_invoke_ctx *ctx; - - spin_lock(&user->lock); - list_for_each_entry(ctx, &user->pending, node) { - ctx->retval = -EPIPE; - complete(&ctx->work); - } - spin_unlock(&user->lock); -} - static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) { struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev); struct fastrpc_user *user; unsigned long flags; + int i; /* No invocations past this point */ spin_lock_irqsave(&cctx->lock, flags); @@ -2431,6 +2607,11 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) if (cctx->remote_heap) fastrpc_buf_free(cctx->remote_heap); + for (i = 0; i < FASTRPC_MAX_SPD; i++) { + if (cctx->spd[i].pdrhandle) + pdr_handle_release(cctx->spd[i].pdrhandle); + } + of_platform_depopulate(&rpdev->dev); fastrpc_channel_ctx_put(cctx); From patchwork Tue May 28 11:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676482 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 E0D86182B3; Tue, 28 May 2024 11:30:24 +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=1716895826; cv=none; b=oEZrfpZ+JWQqRCZzQFhCb8ad5i+ST+veKTDCSGGN9J+8MQeynmL40nftRtPblZxBo1ZnVyOm3tCfB+Gv33BUFSO3nOmciuaehg567zSiWlN89N5LCERhX5t3lm13oObjRzq518R2Cjr9OflWuQO2oxVqPmYqPF1UiCb6YsQHRbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895826; c=relaxed/simple; bh=BRFwAoyJ/b7Y/ZsGoH+pLi+5j/4fPFWAifpLCTnJxEw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HjC+D+hsYvqfeedHuNYnWhfy4pWNf0NOS4Qn3IeUaXrIN2Q3BHntg6Jnbzm+VVjElFEqLhgsJszBLpSy6kndO8lIxsmnUWd4gyRNG7aBfmunm7WxqGsj4iKOKygoc5NrsJ8qkRjlsVFRwKdlX5iO+RGjPfMfwOjmLsF/tJo5LrM= 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=V8bh8MXG; 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="V8bh8MXG" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44RNP6KD013116; Tue, 28 May 2024 11:30:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /25Lv+m2pI0JLuJAbcXNEupUkVgeoF+6ky2d5EQN7Gg=; b=V8bh8MXGa+1M3gos 1MCp9vVXIiLCVKHaTWolcuW++dxH/EJSXa9SvpAZs/GH/dMZaVIHjZrUvCDgCDBV 9pJ8J54kFidOK/gcO1o1UeTQZR6GvUNAYYvxZd7M2qjjhDK2dGqhQ5soyeFjiYc9 M8D4isK4JQSdchfdF8ggfhqTM7If4QR0oG1gHt47lNwrWYAbJ9ZOKGXjSXeIk3Sk ovfejNNpeeGX72rrF/xvRLWol1edYxxmjwyNLw5KGdBKCWm5MOihO5w3v6dy9GUz fEzo4BnRMuXFmcsPbTaUJ32l+obSIcGtPfBsaSpiNmO4RzHJz+5Pb3xZs2DcwH3G rf+Ycg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ybadx5uwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:22 +0000 (GMT) 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 44SBUKFr007677 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:20 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.1544.9; Tue, 28 May 2024 04:30:18 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 5/8] misc: fastrpc: Redesign remote heap management Date: Tue, 28 May 2024 16:59:51 +0530 Message-ID: <20240528112956.5979-6-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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: 5d8TeNF-ofUcDV_KOGkXGFj-pQq3bGDk X-Proofpoint-GUID: 5d8TeNF-ofUcDV_KOGkXGFj-pQq3bGDk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 mlxscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Current remote heap design comes with problems where all types of buffers are getting added to interrupted list and also user unmap request is not handled properly. Add changes to maintain list in a way that it can be properly managed and used at different audio PD specific scenarios. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 221 ++++++++++++++++++++++++++++++++--------- 1 file changed, 175 insertions(+), 46 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 7796b743cc45..1c0e5d050fd4 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -210,6 +210,7 @@ struct fastrpc_buf { struct dma_buf *dmabuf; struct device *dev; void *virt; + u32 flag; u64 phys; u64 size; /* Lock for dma buf attachments */ @@ -273,6 +274,7 @@ struct fastrpc_session_ctx { }; struct fastrpc_static_pd { + struct list_head rmaps; char *servloc_name; char *spdname; void *pdrhandle; @@ -298,7 +300,6 @@ struct fastrpc_channel_ctx { u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES]; struct fastrpc_device *secure_fdevice; struct fastrpc_device *fdevice; - struct fastrpc_buf *remote_heap; bool secure; bool unsigned_support; u64 dma_mask; @@ -1283,6 +1284,53 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques return false; } +static void fastrpc_mmap_remove_pdr(struct fastrpc_static_pd *spd) +{ + struct fastrpc_buf *buf, *b; + struct fastrpc_channel_ctx *cctx; + int err; + + if (!spd || !spd->fl) + return; + + cctx = spd->cctx; + + spin_lock(&spd->fl->lock); + list_for_each_entry_safe(buf, b, &spd->rmaps, node) { + list_del(&buf->node); + spin_unlock(&spd->fl->lock); + if (cctx->vmcount) { + u64 src_perms = 0; + struct qcom_scm_vmperm dst_perms; + u32 i; + + for (i = 0; i < cctx->vmcount; i++) + src_perms |= BIT(cctx->vmperms[i].vmid); + + dst_perms.vmid = QCOM_SCM_VMID_HLOS; + dst_perms.perm = QCOM_SCM_PERM_RWX; + err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, + &src_perms, &dst_perms, 1); + if (err) { + pr_err("%s: Failed to assign memory phys 0x%llx size 0x%llx err %d\n", + __func__, buf->phys, buf->size, err); + return; + } + } + fastrpc_buf_free(buf); + spin_lock(&spd->fl->lock); + } + spin_unlock(&spd->fl->lock); +} + +static void fastrpc_mmap_remove_ssr(struct fastrpc_channel_ctx *cctx) +{ + int i; + + for (i = 0; i < FASTRPC_MAX_SPD; i++) + fastrpc_mmap_remove_pdr(&cctx->spd[i]); +} + static struct fastrpc_static_pd *fastrpc_get_spd_session( struct fastrpc_user *fl) { @@ -1309,9 +1357,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, struct fastrpc_init_create_static init; struct fastrpc_invoke_args *args; struct fastrpc_phy_page pages[1]; + struct fastrpc_buf *buf = NULL; struct fastrpc_static_pd *spd = NULL; + u64 phys = 0, size = 0; char *name; int err; + bool scm_done = false; struct { int pgid; u32 namelen; @@ -1357,25 +1408,26 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, goto err_name; } fl->spd = spd; - if (!fl->cctx->remote_heap) { - err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, - &fl->cctx->remote_heap); + if (list_empty(&spd->rmaps)) { + err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, &buf); if (err) goto err_name; + phys = buf->phys; + size = buf->size; /* Map if we have any heap VMIDs associated with this ADSP Static Process. */ if (fl->cctx->vmcount) { u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); - err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys, - (u64)fl->cctx->remote_heap->size, + err = qcom_scm_assign_mem(phys, (u64)size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); if (err) { dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d\n", - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); + phys, size, err); goto err_map; } + scm_done = true; } } @@ -1392,8 +1444,8 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, args[1].length = inbuf.namelen; args[1].fd = -1; - pages[0].addr = fl->cctx->remote_heap->phys; - pages[0].size = fl->cctx->remote_heap->size; + pages[0].addr = phys; + pages[0].size = size; args[2].ptr = (u64)(uintptr_t) pages; args[2].length = sizeof(*pages); @@ -1407,10 +1459,17 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, goto err_invoke; kfree(args); + kfree(name); + + if (buf) { + spin_lock(&fl->lock); + list_add_tail(&buf->node, &spd->rmaps); + spin_unlock(&fl->lock); + } return 0; err_invoke: - if (fl->cctx->vmcount) { + if (fl->cctx->vmcount && scm_done) { u64 src_perms = 0; struct qcom_scm_vmperm dst_perms; u32 i; @@ -1420,15 +1479,15 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, dst_perms.vmid = QCOM_SCM_VMID_HLOS; dst_perms.perm = QCOM_SCM_PERM_RWX; - err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys, - (u64)fl->cctx->remote_heap->size, + err = qcom_scm_assign_mem(phys, (u64)size, &src_perms, &dst_perms, 1); if (err) dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); + phys, size, err); } err_map: - fastrpc_buf_free(fl->cctx->remote_heap); + if (buf) + fastrpc_buf_free(buf); err_name: kfree(name); err: @@ -1909,17 +1968,16 @@ static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp) return 0; } -static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf) +static int fastrpc_req_munmap_dsp(struct fastrpc_user *fl, uintptr_t raddr, u64 size) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; struct fastrpc_munmap_req_msg req_msg; - struct device *dev = fl->sctx->dev; int err; u32 sc; req_msg.pgid = fl->tgid; - req_msg.size = buf->size; - req_msg.vaddr = buf->raddr; + req_msg.size = size; + req_msg.vaddr = raddr; args[0].ptr = (u64) (uintptr_t) &req_msg; args[0].length = sizeof(req_msg); @@ -1927,11 +1985,38 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf * sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MUNMAP, 1, 0); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]); + + return err; +} + +static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *buf) +{ + struct device *dev = fl->sctx->dev; + int err; + + err = fastrpc_req_munmap_dsp(fl, buf->raddr, buf->size); if (!err) { + if (buf->flag == ADSP_MMAP_REMOTE_HEAP_ADDR) { + if (fl->cctx->vmcount) { + u64 src_perms = 0; + struct qcom_scm_vmperm dst_perms; + u32 i; + + for (i = 0; i < fl->cctx->vmcount; i++) + src_perms |= BIT(fl->cctx->vmperms[i].vmid); + + dst_perms.vmid = QCOM_SCM_VMID_HLOS; + dst_perms.perm = QCOM_SCM_PERM_RWX; + err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, + &src_perms, &dst_perms, 1); + if (err) { + dev_err(dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", + buf->phys, buf->size, err); + return err; + } + } + } dev_dbg(dev, "unmmap\tpt 0x%09lx OK\n", buf->raddr); - spin_lock(&fl->lock); - list_del(&buf->node); - spin_unlock(&fl->lock); fastrpc_buf_free(buf); } else { dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr); @@ -1945,6 +2030,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) struct fastrpc_buf *buf = NULL, *iter, *b; struct fastrpc_req_munmap req; struct device *dev = fl->sctx->dev; + int err = 0; if (copy_from_user(&req, argp, sizeof(req))) return -EFAULT; @@ -1953,20 +2039,48 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) list_for_each_entry_safe(iter, b, &fl->mmaps, node) { if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) { buf = iter; + list_del(&buf->node); break; } } spin_unlock(&fl->lock); - if (!buf) { - dev_err(dev, "mmap\t\tpt 0x%09llx [len 0x%08llx] not in list\n", - req.vaddrout, req.size); - return -EINVAL; + if (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); + } + return err; } - return fastrpc_req_munmap_impl(fl, buf); + spin_lock(&fl->lock); + if (fl->spd) { + list_for_each_entry_safe(iter, b, &fl->spd->rmaps, node) { + if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) { + buf = iter; + list_del(&buf->node); + break; + } + } + } + spin_unlock(&fl->lock); + if (buf) { + err = fastrpc_req_munmap_impl(fl, buf); + if (err) { + spin_lock(&fl->lock); + list_add_tail(&buf->node, &fl->spd->rmaps); + spin_unlock(&fl->lock); + } + return err; + } + dev_err(dev, "buffer not found addr 0x%09lx, len 0x%08llx\n", + req.vaddrout, req.size); + return -EINVAL; } + static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_invoke_args args[3] = { [0 ... 2] = { 0 } }; @@ -1993,16 +2107,34 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) return -EINVAL; } - if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) + if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { + if (!fl->spd || !fl->spd->ispdup) { + dev_err(dev, "remote heap request supported only for active static PD\n"); + return -EINVAL; + } err = fastrpc_remote_heap_alloc(fl, dev, req.size, &buf); - else + } else { err = fastrpc_buf_alloc(fl, dev, req.size, &buf); + } if (err) { dev_err(dev, "failed to allocate buffer\n"); return err; } + buf->flag = req.flags; + /* Add memory to static PD pool, protection through hypervisor */ + if ((req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) && fl->cctx->vmcount) { + u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); + + err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, + &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); + if (err) { + dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", + buf->phys, buf->size, err); + goto err_invoke; + } + } req_msg.pgid = fl->tgid; req_msg.flags = req.flags; req_msg.vaddr = req.vaddrin; @@ -2034,26 +2166,17 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) /* let the client know the address to use */ req.vaddrout = rsp_msg.vaddr; - /* Add memory to static PD pool, protection thru hypervisor */ - if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR && fl->cctx->vmcount) { - u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); - - err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, - &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); - if (err) { - dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d", - buf->phys, buf->size, err); - goto err_assign; - } - } spin_lock(&fl->lock); - list_add_tail(&buf->node, &fl->mmaps); + if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) + list_add_tail(&buf->node, &fl->spd->rmaps); + else + list_add_tail(&buf->node, &fl->mmaps); spin_unlock(&fl->lock); if (copy_to_user((void __user *)argp, &req, sizeof(req))) { err = -EFAULT; - goto err_assign; + goto err_copy; } dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", @@ -2061,14 +2184,19 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) return 0; -err_assign: +err_copy: + spin_lock(&fl->lock); + list_del(&buf->node); + spin_unlock(&fl->lock); fastrpc_req_munmap_impl(fl, buf); + buf = NULL; err_invoke: fastrpc_buf_free(buf); return err; } + static int fastrpc_req_mem_unmap_impl(struct fastrpc_user *fl, struct fastrpc_mem_unmap *req) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; @@ -2292,6 +2420,7 @@ static void fastrpc_pdr_cb(int state, char *service_path, void *priv) spd->servloc_name, domains[cctx->domain_id]); spd->ispdup = false; + fastrpc_mmap_remove_pdr(spd); fastrpc_notify_pdr_drivers(cctx, spd->servloc_name); break; case SERVREG_SERVICE_STATE_UP: @@ -2443,6 +2572,7 @@ static int fastrpc_setup_service_locator(struct fastrpc_channel_ctx *cctx, char cctx->spd[spd_session].servloc_name = client_name; cctx->spd[spd_session].spdname = service_path; cctx->spd[spd_session].cctx = cctx; + INIT_LIST_HEAD(&cctx->spd[spd_session].rmaps); service = pdr_add_lookup(handle, service_name, service_path); if (IS_ERR(service)) { err = PTR_ERR(service); @@ -2604,9 +2734,6 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) if (cctx->secure_fdevice) misc_deregister(&cctx->secure_fdevice->miscdev); - if (cctx->remote_heap) - fastrpc_buf_free(cctx->remote_heap); - for (i = 0; i < FASTRPC_MAX_SPD; i++) { if (cctx->spd[i].pdrhandle) pdr_handle_release(cctx->spd[i].pdrhandle); @@ -2614,6 +2741,8 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) of_platform_depopulate(&rpdev->dev); + fastrpc_mmap_remove_ssr(cctx); + fastrpc_channel_ctx_put(cctx); } From patchwork Tue May 28 11:29:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676483 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 07D8016C862; Tue, 28 May 2024 11:30:27 +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=1716895830; cv=none; b=uT7IvDdDcksZyB3cLXXf9ay0EK5kyddCEQqPYFcZT8tHCYrnCXBEtrSKGEFErKebwb2Ca50dKPdwJ3KoqQv92Gbl11VN9iBghyRwMSL83jxdSgD3iVFyBKHO8Rkx+O5zCqWLT8vBVL03/ISSpAJUJX4RhN13MVwnDIto43eoN0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895830; c=relaxed/simple; bh=GGPEFyzdkqFePe+1NEUDwoSleY9w+XMpe5aRBUHvTVE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r7mXoIRbODuJWppJHryoypiGoaHUKxOAnw4rdN52ETofob9FImGC0CmwedQDREMCkIo40iDfttLPwfFbkInuSaCZvhB7yqGBGueToxPMatA0Ef1d2eiuOXvN2g5vKLZ7aKJsXN9iTbkUeSaPne7n5kEFs+e4gbxM/MtQOY9VaG8= 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=No8CWxVt; 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="No8CWxVt" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44RNjQXf014007; Tue, 28 May 2024 11:30:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= r5UxKo/khzjb9DNkjj5+rQwoA5eCGOuDH8oBnKUEod4=; b=No8CWxVtESIfU5dJ TEDWNMpAmomf3WI5AozdzEk80d/Wa9K/ZSUFuLNNRYfa4g1ld+juxWZzhEtHnX64 w6AARBTEkPBPR3xnUzPwEhMoXOmjpcAwv747w+xmq3fKuIzvgDIOwNhdhalLPK8S nVhiI1tDxLeHUehdShnfhvriqcmidXtfKJmFPV8YaiFU1/SjL7bd0Cyl1fcC8gJS wzmj5GvBIOgATa5TIurxr1O621kTLT7hNEnGikHWXz5iqMuSidxE1HaZlkiMnwsH Kd3mu5lfazPrwWU02TxcGyJwN5ycW+nsN+tWwqWrmoRYvUrvcRfmilXHarulLnqy yG6vZw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ybadx5uwr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:24 +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 44SBUNNw028014 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:23 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.1544.9; Tue, 28 May 2024 04:30:20 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 6/8] misc: fastrpc: Add support for unsigned PD Date: Tue, 28 May 2024 16:59:52 +0530 Message-ID: <20240528112956.5979-7-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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: egUKivdPp3s5xxVvagvfrkxKIketbJRI X-Proofpoint-GUID: egUKivdPp3s5xxVvagvfrkxKIketbJRI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 mlxscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Unsigned PDs are sandboxed DSP processes used to offload computation workloads to the DSP. Unsigned PD have less privileges in terms of DSP resource access as compared to Signed PD. Unsigned PD requires more initial memory to spawn. Also most of the memory request are allocated from userspace. Add support for unsigned PD by increasing init memory size and handling mapping request for cases other than DSP heap grow requests. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 227 ++++++++++++++++++++++++++--------------- 1 file changed, 147 insertions(+), 80 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 1c0e5d050fd4..23dd20c22f6d 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -40,7 +40,7 @@ #define FASTRPC_INIT_HANDLE 1 #define FASTRPC_DSP_UTILITIES_HANDLE 2 #define FASTRPC_CTXID_MASK (0xFF0) -#define INIT_FILELEN_MAX (2 * 1024 * 1024) +#define INIT_FILELEN_MAX (5 * 1024 * 1024) #define INIT_FILE_NAMELEN_MAX (128) #define FASTRPC_DEVICE_NAME "fastrpc" @@ -119,6 +119,11 @@ #define SENSORS_PDR_SLPI_SERVICE_NAME SENSORS_PDR_ADSP_SERVICE_NAME #define SLPI_SENSORPD_NAME "msm/slpi/sensor_pd" +enum fastrpc_userpd_type { + SIGNED_PD = 1, + UNSIGNED_PD = 2, +}; + static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", "sdsp", "cdsp"}; struct fastrpc_phy_page { @@ -326,6 +331,7 @@ struct fastrpc_user { int tgid; int pd; bool is_secure_dev; + enum fastrpc_userpd_type userpd_type; char *servloc_name; /* Lock for lists */ spinlock_t lock; @@ -1515,7 +1521,6 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, u32 siglen; } inbuf; u32 sc; - bool unsigned_module = false; args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); if (!args) @@ -1527,9 +1532,10 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, } if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE) - unsigned_module = true; + fl->userpd_type = UNSIGNED_PD; - if (is_session_rejected(fl, unsigned_module)) { + + if (is_session_rejected(fl, !(fl->userpd_type == SIGNED_PD))) { err = -ECONNREFUSED; goto err; } @@ -1742,6 +1748,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) fl->tgid = current->tgid; fl->cctx = cctx; fl->is_secure_dev = fdevice->secure; + fl->userpd_type = SIGNED_PD; fl->sctx = fastrpc_session_alloc(cctx); if (!fl->sctx) { @@ -2029,6 +2036,7 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_buf *buf = NULL, *iter, *b; struct fastrpc_req_munmap req; + struct fastrpc_map *map = NULL, *iterm, *m; struct device *dev = fl->sctx->dev; int err = 0; @@ -2075,76 +2083,49 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp) } return err; } - dev_err(dev, "buffer not found addr 0x%09lx, len 0x%08llx\n", + spin_lock(&fl->lock); + list_for_each_entry_safe(iterm, m, &fl->maps, node) { + if (iterm->raddr == req.vaddrout) { + map = iterm; + break; + } + } + spin_unlock(&fl->lock); + if (!map) { + dev_err(dev, "buffer not found addr 0x%09llx, len 0x%08llx\n", req.vaddrout, req.size); - return -EINVAL; -} + return -EINVAL; + } + err = fastrpc_req_munmap_dsp(fl, map->raddr, map->size); + if (err) + dev_err(dev, "unmmap\tpt fd = %d, 0x%09llx error\n", map->fd, map->raddr); + else + fastrpc_map_put(map); -static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) + return err; +} + +static int fastrpc_req_map_dsp(struct fastrpc_user *fl, u64 phys, + u64 size, u32 flag, uintptr_t vaddrin, u64 *raddr) { struct fastrpc_invoke_args args[3] = { [0 ... 2] = { 0 } }; - struct fastrpc_buf *buf = NULL; struct fastrpc_mmap_req_msg req_msg; struct fastrpc_mmap_rsp_msg rsp_msg; struct fastrpc_phy_page pages; - struct fastrpc_req_mmap req; - struct device *dev = fl->sctx->dev; int err; u32 sc; - if (copy_from_user(&req, argp, sizeof(req))) - return -EFAULT; - - if (req.flags != ADSP_MMAP_ADD_PAGES && req.flags != ADSP_MMAP_REMOTE_HEAP_ADDR) { - dev_err(dev, "flag not supported 0x%x\n", req.flags); - - return -EINVAL; - } - - if (req.vaddrin) { - dev_err(dev, "adding user allocated pages is not supported\n"); - return -EINVAL; - } - - if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { - if (!fl->spd || !fl->spd->ispdup) { - dev_err(dev, "remote heap request supported only for active static PD\n"); - return -EINVAL; - } - err = fastrpc_remote_heap_alloc(fl, dev, req.size, &buf); - } else { - err = fastrpc_buf_alloc(fl, dev, req.size, &buf); - } - - if (err) { - dev_err(dev, "failed to allocate buffer\n"); - return err; - } - buf->flag = req.flags; - - /* Add memory to static PD pool, protection through hypervisor */ - if ((req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) && fl->cctx->vmcount) { - u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); - - err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, - &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); - if (err) { - dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", - buf->phys, buf->size, err); - goto err_invoke; - } - } req_msg.pgid = fl->tgid; - req_msg.flags = req.flags; - req_msg.vaddr = req.vaddrin; + req_msg.flags = flag; + req_msg.vaddr = vaddrin; req_msg.num = sizeof(pages); args[0].ptr = (u64) (uintptr_t) &req_msg; args[0].length = sizeof(req_msg); - pages.addr = buf->phys; - pages.size = buf->size; + pages.addr = phys; + pages.size = size; args[1].ptr = (u64) (uintptr_t) &pages; args[1].length = sizeof(pages); @@ -2154,49 +2135,135 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MMAP, 2, 1); err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, - &args[0]); + &args[0]); + if (err) { - dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size); - goto err_invoke; + dev_err(fl->sctx->dev, "mmap error (len 0x%08llx)\n", size); + return err; } + *raddr = rsp_msg.vaddr; - /* update the buffer to be able to deallocate the memory on the DSP */ - buf->raddr = (uintptr_t) rsp_msg.vaddr; + return err; +} - /* let the client know the address to use */ - req.vaddrout = rsp_msg.vaddr; +static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_buf *buf = NULL; + struct fastrpc_req_mmap req; + struct fastrpc_map *map = NULL; + struct device *dev = fl->sctx->dev; + u64 raddr = 0; + int err; + if (copy_from_user(&req, argp, sizeof(req))) + return -EFAULT; - spin_lock(&fl->lock); - if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) - list_add_tail(&buf->node, &fl->spd->rmaps); - else - list_add_tail(&buf->node, &fl->mmaps); - spin_unlock(&fl->lock); + if ((req.flags == ADSP_MMAP_ADD_PAGES || + req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) && (fl->userpd_type == SIGNED_PD)) { + if (req.vaddrin) { + dev_err(dev, "adding user allocated pages is not supported for signed PD\n"); + return -EINVAL; + } + + if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { + if (!fl->spd || !fl->spd->ispdup) { + dev_err(dev, "remote heap request supported only for active static PD\n"); + return -EINVAL; + } + err = fastrpc_remote_heap_alloc(fl, dev, req.size, &buf); + } else { + err = fastrpc_buf_alloc(fl, dev, req.size, &buf); + } + + if (err) { + dev_err(dev, "failed to allocate buffer\n"); + return err; + } + buf->flag = req.flags; + + /* Add memory to static PD pool, protection through hypervisor */ + if ((req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) && fl->cctx->vmcount) { + u64 src_perms = BIT(QCOM_SCM_VMID_HLOS); + + err = qcom_scm_assign_mem(buf->phys, (u64)buf->size, + &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); + if (err) { + dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d\n", + buf->phys, buf->size, err); + goto err_invoke; + } + } + + err = fastrpc_req_map_dsp(fl, buf->phys, buf->size, buf->flag, + req.vaddrin, &raddr); + if (err) + goto err_invoke; + + /* update the buffer to be able to deallocate the memory on the DSP */ + buf->raddr = (uintptr_t) raddr; + /* let the client know the address to use */ + req.vaddrout = raddr; + + spin_lock(&fl->lock); + if (req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) + list_add_tail(&buf->node, &fl->spd->rmaps); + else + list_add_tail(&buf->node, &fl->mmaps); + spin_unlock(&fl->lock); + dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", + buf->raddr, buf->size); + } else { + if ((req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) && (fl->userpd_type != SIGNED_PD)) { + dev_err(dev, "secure memory allocation is not supported in unsigned PD\n"); + return -EINVAL; + } + err = fastrpc_map_create(fl, req.fd, req.size, 0, &map); + if (err) { + dev_err(dev, "failed to map buffer, fd = %d\n", req.fd); + return err; + } + + err = fastrpc_req_map_dsp(fl, map->phys, map->size, req.flags, + req.vaddrin, &raddr); + if (err) + goto err_invoke; + + /* update the buffer to be able to deallocate the memory on the DSP */ + map->raddr = (uintptr_t) raddr; + + /* let the client know the address to use */ + req.vaddrout = raddr; + dev_dbg(dev, "mmap\t\tpt 0x%09llx OK [len 0x%08llx]\n", + map->raddr, map->size); + } if (copy_to_user((void __user *)argp, &req, sizeof(req))) { err = -EFAULT; goto err_copy; } - dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n", - buf->raddr, buf->size); - return 0; err_copy: - spin_lock(&fl->lock); - list_del(&buf->node); - spin_unlock(&fl->lock); - fastrpc_req_munmap_impl(fl, buf); - buf = NULL; + if ((req.flags != ADSP_MMAP_ADD_PAGES && + req.flags != ADSP_MMAP_REMOTE_HEAP_ADDR) || fl->userpd_type != SIGNED_PD) { + fastrpc_req_munmap_dsp(fl, map->raddr, map->size); + } else { + spin_lock(&fl->lock); + list_del(&buf->node); + spin_unlock(&fl->lock); + fastrpc_req_munmap_impl(fl, buf); + buf = NULL; + } err_invoke: - fastrpc_buf_free(buf); + if (map) + fastrpc_map_put(map); + if (buf) + fastrpc_buf_free(buf); return err; } - static int fastrpc_req_mem_unmap_impl(struct fastrpc_user *fl, struct fastrpc_mem_unmap *req) { struct fastrpc_invoke_args args[1] = { [0] = { 0 } }; From patchwork Tue May 28 11:29:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676485 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 ACBBA16C872; Tue, 28 May 2024 11:30:29 +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=1716895831; cv=none; b=p0hzwI0ahLp0jimyAkXCTrjcw6Yy6mWl7ICRZnrnz5vFxX4s3GtfTdAPgpIpQdHie7wn9nSPn/yeX7iVtALzCSfjUfPwNApd33qcz9i2ldf8dx5ywQKM/+AHwp6cxQDR0qpK0PALP7MyRv2svo702aK+BseC/dzBF0Y3B4aPyD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895831; c=relaxed/simple; bh=NPlw+UgRXFCYW39MQ5raA1QAH3Z8ZdFUTg6r3oIjN3A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vt1AnVWxem4qBj6bc/MUOqyEqXprZ1nauALZn+3kpSsvxr/y3QKlHeCvY1UIe49l7Gz2WVr/wBinhzgaZ37emLtecfZ0q+sh6dwMCLuilT8/u1UYJHAltDLoxLY+zjo+kxPR98FJ/BFxhkF+3hGf3/RPKlbA0KtO0q5Fz5EusO0= 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=UaYpx5bp; 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="UaYpx5bp" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SBAa46016293; Tue, 28 May 2024 11:30:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 90rs+1NhWIyzHw7JC+KSKG0OGHUhEX+N4aq6NhYEOqI=; b=UaYpx5bpE2r3qwdp O4dHFbIG5XlNxRxLjotiMOGDzDIXtCP2vebQ17LjDo+JxhGjaEUFeTEUBdCj7yk2 5w1Hm61pRMfl9/2wHKZVe98FykUOczTncafBaSG5a+24n0Sr1ImFE4xN/XaVzsHW jzjnZmYHY53RT3Oyq8/6xBaFJfTF9gzIX6aszNVfaLmA+pYWWo/f+YQ5+RWsfKCV tUAj6qSAzAB+CR5pzNk+bWAQQ3nYt0ycdGpPDa8vnJCMozyxR+Q89xxBiYMaEj0Q bzw48oxMY/S72PvG+GQOKqgUi5664AKjVSLKIm3qiAFyZexZEpRIwsK7HHLnsPFN R3ZlRA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2mwtx9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:26 +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 44SBUP7d028042 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:25 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.1544.9; Tue, 28 May 2024 04:30:23 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 7/8] misc: fastrpc: Restrict untrusted apk to spawn Date: Tue, 28 May 2024 16:59:53 +0530 Message-ID: <20240528112956.5979-8-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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-GUID: mfm0Nlufys3XcnQoCa3N8ZvEWrHhcLU4 X-Proofpoint-ORIG-GUID: mfm0Nlufys3XcnQoCa3N8ZvEWrHhcLU4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=790 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Untrusted application can attach to guestOS and staticPD if it can make root PD, sensors PD or audio PD attach request. This is a potential security issue as the untrusted application can crash rootPD or staticPD. Restrict attach to guestOS or staticPD request if request is being made using non-secure device node. Also for untrusted dynamic processes, DSP HAL process opens the device node on behalf of the application. Add a check to restrict such untrusted applications from offloading to signed PD. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 23dd20c22f6d..7f81a18b8aea 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -332,6 +332,7 @@ struct fastrpc_user { int pd; bool is_secure_dev; enum fastrpc_userpd_type userpd_type; + bool untrusted_process; char *servloc_name; /* Lock for lists */ spinlock_t lock; @@ -1274,20 +1275,24 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_request) { - /* Check if the device node is non-secure and channel is secure*/ + /* Check if the device node is non-secure and channel is secure */ if (!fl->is_secure_dev && fl->cctx->secure) { /* * Allow untrusted applications to offload only to Unsigned PD when * channel is configured as secure and block untrusted apps on channel * that does not support unsigned PD offload */ - if (!fl->cctx->unsigned_support || !unsigned_pd_request) { - dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD\n"); - return true; - } + if (!fl->cctx->unsigned_support || !unsigned_pd_request) + goto reject_session; } + /* Check if untrusted process is trying to offload to signed PD */ + if (fl->untrusted_process && !unsigned_pd_request) + goto reject_session; return false; +reject_session: + dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD\n"); + return true; } static void fastrpc_mmap_remove_pdr(struct fastrpc_static_pd *spd) @@ -1376,6 +1381,11 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, } inbuf; u32 sc; + if (!fl->is_secure_dev) { + dev_err(&fl->cctx->rpdev->dev, "untrusted app trying to attach to privileged DSP PD\n"); + return -EACCES; + } + args = kcalloc(FASTRPC_CREATE_STATIC_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); if (!args) return -ENOMEM; @@ -1531,12 +1541,20 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, goto err; } + /* + * Third-party apps don't have permission to open the fastrpc device, so + * it is opened on their behalf by DSP HAL. This is detected by + * comparing current PID with the one stored during device open. + */ + if (current->tgid != fl->tgid) + fl->untrusted_process = true; + if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE) fl->userpd_type = UNSIGNED_PD; if (is_session_rejected(fl, !(fl->userpd_type == SIGNED_PD))) { - err = -ECONNREFUSED; + err = -EACCES; goto err; } @@ -1818,6 +1836,11 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) int tgid = fl->tgid; u32 sc; + if (!fl->is_secure_dev) { + dev_err(&fl->cctx->rpdev->dev, "untrusted app trying to attach to privileged DSP PD\n"); + return -EACCES; + } + args[0].ptr = (u64)(uintptr_t) &tgid; args[0].length = sizeof(tgid); args[0].fd = -1; From patchwork Tue May 28 11:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13676487 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 3426A16D4D8; Tue, 28 May 2024 11:30:32 +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=1716895834; cv=none; b=ojc6R0DEHnmYTCj+PB8gnxWNSFjDnVLAUrg+d6e68JtXfyk5KLdcYxtROh5MexL5ta+5VwV87SQK/mInQZwTMyAZVWIX8OPtsfM1Jci1S9jhLIzNb/klUxzIbbDfWOP6Dnf/NeHZnpKuLMSgGlG/bTIJdBkS+SNFLcbtAAgaLB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716895834; c=relaxed/simple; bh=ItLh038yTXkpBO2JVPmLDXhnSPBcMqCuu4HfftVx0pc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q+MJdJ7JLYwacsfIF/bnbcomizeBk+eiMOsefIa6VAipvkR72r+8Y4HRhZxgH4pUQmHuHggAqmqtzbef812NEsLmNCAS+8M9BaBuU2uAN+MXhEKGwV+NYJzJ+8NPFqMV8mLRAFq5KTnwNo/3mdeEtvXQBEg29RE/0GaGmzz+748= 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=FcQ8iV/l; arc=none smtp.client-ip=205.220.168.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="FcQ8iV/l" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SAXhWa021501; Tue, 28 May 2024 11:30:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 7FQ8GTcx+lE1HArNnPtx3PNwM1Jn9g53NbtM9+mUJoE=; b=FcQ8iV/lgjHnyoZk nWAbQ8itxT7dYo/95TpjM4PV7/acyycN34ObVBweQeI17ivrh1Pj6MbSu7hZvU5+ mIGr0HbH5KLgsJXLnVyDV87wHWKQJogAqNYSPmPMW1nOTfmE8T2G8TIp2BrbhEgr ncA30G1X9sBiqzWQ999BHB/32mUp/rgIQfu9+GaF5WRTm5EpvqFK6Veo0CNsohvk OkbLckTdXCtwEYHhfbiO/3UCaDSxe7x8G6WA9fzYWJo2z2TAh5ZMeT1mkULe1J6H hIlU6/W7BXiorQy5jxBw2QltqP3iLhR6VEfmgvLPpjdElKd/zemsNYH6w/nn9RYT 8eiJqQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0pnud1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:30 +0000 (GMT) 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 44SBUSf8002254 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 11:30:28 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.1544.9; Tue, 28 May 2024 04:30:25 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v2 8/8] misc: fastrpc: Add system unsigned PD support Date: Tue, 28 May 2024 16:59:54 +0530 Message-ID: <20240528112956.5979-9-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240528112956.5979-1-quic_ekangupt@quicinc.com> References: <20240528112956.5979-1-quic_ekangupt@quicinc.com> Precedence: bulk X-Mailing-List: linux-arm-msm@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: pGNstejnuWe-R7xw3aKQgXzHi7T7UM3u X-Proofpoint-GUID: pGNstejnuWe-R7xw3aKQgXzHi7T7UM3u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 bulkscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280087 Trusted CPU applications currently offload to signed PDs on CDSP to gain some additional services provided by root PD. Unsigned PDs have access to limited root PD services that may not be sufficient for all use-cases. Signed PDs have a higher dynamic loading latency which impacts the performance of applications. Limited root PD services could be opened up for unsigned PDs but that should be restricted for untrusted processes. For this requirement, System unsigned PD is introduced which will be same as Unsigned PD for most part but will have access to more root PD services. Add changes to offload trusted applications to System unsigned PD when unsigned offload is requested. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 9 +++++++++ include/uapi/misc/fastrpc.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 7f81a18b8aea..ebe20915392f 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -122,6 +122,7 @@ enum fastrpc_userpd_type { SIGNED_PD = 1, UNSIGNED_PD = 2, + SYSTEM_UNSIGNED_PD = 3, }; static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", @@ -1552,12 +1553,20 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE) fl->userpd_type = UNSIGNED_PD; + /* Disregard any system unsigned PD attribute from userspace */ + init.attrs &= (~FASTRPC_MODE_SYSTEM_UNSIGNED_PD); if (is_session_rejected(fl, !(fl->userpd_type == SIGNED_PD))) { err = -EACCES; goto err; } + /* Trusted apps will be launched as system unsigned PDs */ + if (!fl->untrusted_process && (fl->userpd_type != SIGNED_PD)) { + fl->userpd_type = SYSTEM_UNSIGNED_PD; + init.attrs |= FASTRPC_MODE_SYSTEM_UNSIGNED_PD; + } + if (init.filelen > INIT_FILELEN_MAX) { err = -EINVAL; goto err; diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index f33d914d8f46..3b3279bb2cf9 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -62,6 +62,8 @@ enum fastrpc_proc_attr { FASTRPC_MODE_SYSTEM_PROCESS = (1 << 5), /* Macro for Prvileged Process */ FASTRPC_MODE_PRIVILEGED = (1 << 6), + /* Macro for system unsigned PD */ + FASTRPC_MODE_SYSTEM_UNSIGNED_PD = (1 << 17), }; /* Fastrpc attribute for memory protection of buffers */