From patchwork Thu May 30 10:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680121 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 BF84617C7A1; Thu, 30 May 2024 10:20:49 +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=1717064451; cv=none; b=F3JH40He9xlCnfKgf/3y42TnfCil8GUy2owaT2u/Cc9xQQI1NxfhPz4IlUAldaqKTJlqiUz37CyXR35pbtnFz8mhdwKWBYGAPdBjmz2CYMKGEAGsgQFHxTGoqRYhqCb/di/w/l7y1spAIe+SSVCDuhNeYKXchTZxvd8TK99lZWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064451; c=relaxed/simple; bh=H2jWcvpKqbzAnp9/j0WSN87+yx8nAalCoyjprgqfvk4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Pfd1iEU0zkJbyM7Muj2SAoHvdl/noUN/a7lWJ0EI8VvTv/PzrQfGDkM1QhEQpDMfvKDCSbfyuLRXarYS5YGY96vVSQvdxQdHDaPN/Sw/1+E1fLpTsIaiDtczWe8IEnk0EM4hXw3vzE3jz9MKbakR3u3M6u1OfeFn7xYYEogc+XI= 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=BaYv9gNW; 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="BaYv9gNW" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44U5aOMA015776; Thu, 30 May 2024 10:20:47 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= ZgcGq+gGLMZzRgJ3mrjkWIPtheOdd4pHy1h0aokwgUM=; b=BaYv9gNWdfda6yIY Kd1oV8pAA7imQkBcswUXiyl943Hae/iKtFbMnv5P2vgnhA+/iNlezyMlvZDaZlY/ aPRlGAt9Nni9yRn87gqmNhlEpRJcU4RBvk2cavzFLqY+mJbKRn9LE9tAsNMEv1k6 N2fwf6Hak8J5iZ3C9zyxTsoWxA6uB1EGuY8AR+GuYem9QAfIxSruLgiaXZ/bAo0B sMS7MaJNtfeqKxln2T1RZ6jgEBOKg9xCf+jJgIc5eSnpzWZnzAq57/ggygx2Q4S7 3PBIXeu0dxgiHHjIaEmoA2Zt78Ak4F9/ZHkez0mn9nOpZLMlTAi/Bw21rKqfpSmG +tLdqg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ydyws3ach-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:46 +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 44UAKk9x008411 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:46 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; Thu, 30 May 2024 03:20:43 -0700 From: Ekansh Gupta To: , CC: , , , , Dmitry Baryshkov Subject: [PATCH v3 1/9] misc: fastrpc: Add missing dev_err newlines Date: Thu, 30 May 2024 15:50:19 +0530 Message-ID: <20240530102032.27179-2-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: piKBNdm0SwQXFy2Bk2vYyG3ahpMWNdPg X-Proofpoint-GUID: piKBNdm0SwQXFy2Bk2vYyG3ahpMWNdPg 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-30_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405300078 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. Reviewed-by: Dmitry Baryshkov 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 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 Thu May 30 10:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680122 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 1A17817D375; Thu, 30 May 2024 10:20:53 +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=1717064455; cv=none; b=YPCXzLzFy+wpr2D0CHFhrquOllRDacF6ze8o67zceEaGsZsG3k5YPwCFsn26pBWp1JcI72CS3DQLIhqrouuLqmgn04y8H8LDT3dtWaugYAZEfNeG9GwSMoPFsUxCaZcip4WYTu8lgepHBUtTODOJKMB+IX8Huy2ZTQm5J4Z4stc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064455; c=relaxed/simple; bh=Dyhr7keEUVVzyyNY+TREEUaFWBf8yRwzboMKiSGpBA4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WlyG2GredEM6B3aL4QOgvQ771GhoXcb7CIMPONn8HUFeJXp2nYjFKSLcekpUaWB84eFA0KMne8uVBl0vvRu41KHYJrO3Kbk/iKTequGlM/nHu0PDdgGY6bx0Iyria4DcbShO3zzT0Ol9gAg60ajYMsM5uHMw44WwFoTgEGeUWEw= 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=j3BHo8W1; 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="j3BHo8W1" 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 44UA9Q9r005808; Thu, 30 May 2024 10:20:49 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= l9AMveJ+dSan5ebZIRz9hxO5CEtlvoPrrlO06yvWKGY=; b=j3BHo8W1umWUOCEU +898ELvpyOrz07gaNZeIp6ACsfj2C+bh/dRVih5e62DnQoxagjylYAKzT7PuuJjL 1VGaR8fDgKOx97ARiRcALszi+wRwVbDGxXOXk4TeJTtRE1bGVrvCDZGfNEuXhvXI 9tu6Mztu9Le4Wt5a0V3Vp9WHbOhYCg0vbxQHFvMe6yALrl6mCXhPXkADEk2vHGPA krXMKT5MsNsQEBZ+BJGX/2UPYV4vjQbZkZZWCJ4E6jIPsYuMAvKKhkhLkBXj2YZm lx3WRtxFHJo6dNmUsTjG+1zGou4wR9At/ve1+x46t7nn6xzfTjR7XvEarPRPyFmn Oo3osQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0pufpu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:49 +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 44UAKmo6012736 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:48 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; Thu, 30 May 2024 03:20:46 -0700 From: Ekansh Gupta To: , CC: , , , , stable Subject: [PATCH v3 2/9] misc: fastrpc: Fix DSP capabilities request Date: Thu, 30 May 2024 15:50:20 +0530 Message-ID: <20240530102032.27179-3-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: rIsDX0Jz9gijY2q3q5JZJAXgr5MCoL7o X-Proofpoint-GUID: rIsDX0Jz9gijY2q3q5JZJAXgr5MCoL7o 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-30_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-2405300078 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. Fixes: 6c16fd8bdd40 ("misc: fastrpc: Add support to get DSP capabilities") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 4028cb96bcf2..61389795f498 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1700,9 +1700,8 @@ static int fastrpc_get_info_from_dsp(struct fastrpc_user *fl, uint32_t *dsp_attr 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 +1729,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 +1782,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 Thu May 30 10:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680123 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 56E0217E464; Thu, 30 May 2024 10:20:56 +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=1717064457; cv=none; b=tq0cxEk09gbh0fmTnVr3pJm5WJ1pFMyXa3eAAKzvnG8krCGZt7n2JzlSp1CnyHdAzfccRex8Cjw2PI8veLSVae32wJuar0zNvT7w6WzZVEEnssifxuhuDgpPbXILC6smzG36/eskOU3KXRPAha6JEbAah06aZ4KVlzBgoqqbBxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064457; c=relaxed/simple; bh=+zf3wOWL9nEPaWe0XMjwhv+ZASVMdKnvh2ZQOcAedzw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bXzbUS9h2j4UMdbi3AKuJIrgPFaX3lwrh67HYB4G/Wh1AM4o3RCPiqAvnrOOyyiv5POYYIQ8Pq8aceWWJSqFny7U83k2cezAKA/m9m0RgC8q9p5+bOYxQe4mIWlPsR1HCAT5/N0l0Zp+HfsOpbRy0wQ57Lqls/rtBjNbtW/O82E= 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=UaVcV0s2; 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="UaVcV0s2" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44U9ZSlh025134; Thu, 30 May 2024 10:20:52 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= VZjjUE0o7FO4788n4bimmulmOT7RWu5dKDpXWyVexEU=; b=UaVcV0s2gOTaqNgo yRXbXAzXSXxy7V1/kBsQ9zRsUxrhMZeZY118AcyNC9hfNnwrBcyx2vmRqc1XQb6j UvVIuSQoQFGSq1h0cAKavyW1zLwb9qkt4F6XIiTqyKzR9pWd4GCkzPlibQkvfghy gZNLPhJ/IAzjvfonqgOyKLYw8Z1QSWGF3tKEyZJo2s4LnhEH4WUHen4W+YvnMuMn TkkxKJmrmeB31Fot77QlSBQXtLq/d6bTsRxh42Qr0R2sBTkqvMc0n1qV4iwdbhdT RACIbcc6XjCMkgoAqXLAIpBcMRvvUks1eKJCxe/8q4AyE6KioB4+Yy8SllIjF13r C/cU6w== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2hbhmq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:52 +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 44UAKpdr012756 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:51 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; Thu, 30 May 2024 03:20:48 -0700 From: Ekansh Gupta To: , CC: , , , , stable Subject: [PATCH v3 3/9] misc: fastrpc: Fix memory corruption in DSP capabilities Date: Thu, 30 May 2024 15:50:21 +0530 Message-ID: <20240530102032.27179-4-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: r5j9ITlkJJQju3JtRrZFP3fLq1EtWBNJ X-Proofpoint-ORIG-GUID: r5j9ITlkJJQju3JtRrZFP3fLq1EtWBNJ 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-30_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 suspectscore=0 phishscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=997 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405300078 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 61389795f498..3e1ab58038ed 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1695,6 +1695,7 @@ 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); From patchwork Thu May 30 10:20:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680124 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 2FC0F176AC8; Thu, 30 May 2024 10:20:57 +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=1717064458; cv=none; b=YucvzcryhgPtvesabcxrfFvK+zJCUKrw9hbkmplcOqbDtHnwdWwY0y3P3PvIRgCOBVvMLWxhCl3nc6fSb0zM5A2JPkBGclkojOyVgUJpBgv1dHzfGGVM1ntB1D00xpesGQeydgi9QJhdMt0kkQw0/LAjdyAACM9dQnek7Ak0lFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064458; c=relaxed/simple; bh=FpWp9nUBhtJBPIh2kt6Ks3Jcrkn9GAMRbcGo9j/UPQg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pvnPuQxifKEvgsC4CM0xNYpLq/9GQCvm5ndA5ztgfWOST96kEppq8HviUdbs2VtF/2k4upA3iYUTK8Mj0+3I4FGYLNsixAgmdi3Ajy1agxL9/jK3S7fjefUzjQkSfjQyFdVLjDD5wmooNM+Vi1mFYM9IJChSXYTYjdrfJGTzb18= 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=iBGP25My; 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="iBGP25My" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44U8N5J4025517; Thu, 30 May 2024 10:20:55 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= GfSZa+lg/fZ6NX14CneYh+onrT/jxAOMGtkIMCVYkPI=; b=iBGP25MyAxKZeDnf LBhMwPBFDC+LLg6HrGd+S/AVUDab2lMGductuWXmApOLoRSvoXiXJxlxLuR3huZA jRXMOaqkGHx4f66Pgq+FhpYNEmAVf3zlk00w59tvZihQZyP5Nw5uWkkRBar0kPtd PQ0KIqmo3djyWunp8AF9q00MbRhgQmT5MDffTzWHcenvuTjfdieS5ThSldTMUli+ yx+xTjh6lzt2KQUN7Ilv+CTpgGiOwBiXR2G3VjCYklz0ChAmP4PW+nTV0CtUfg+z d7/bow4R2ubqlX6lbZXkxK+60r8CJTojSJ7mOlhkwaMrNlprgtstdIIBwCYJRVIh 7Zzkiw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2puqyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:54 +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 44UAKsEW008540 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:54 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; Thu, 30 May 2024 03:20:51 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v3 4/9] misc: fastrpc: Add static PD restart support Date: Thu, 30 May 2024 15:50:22 +0530 Message-ID: <20240530102032.27179-5-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: fNmA0LsDwR4qdeI9LEWUMdws0B1a1jJG X-Proofpoint-ORIG-GUID: fNmA0LsDwR4qdeI9LEWUMdws0B1a1jJG 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-30_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 clxscore=1015 bulkscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405300078 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 3e1ab58038ed..d115860fc356 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 { @@ -259,6 +273,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; @@ -266,6 +289,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; @@ -297,10 +321,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 */ @@ -1230,12 +1256,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 { @@ -1270,6 +1317,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); @@ -1645,6 +1705,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; @@ -1654,6 +1715,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]); } @@ -2129,6 +2206,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, @@ -2248,6 +2383,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; @@ -2326,6 +2494,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); @@ -2355,24 +2542,13 @@ 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_buf *buf, *b; struct fastrpc_user *user; unsigned long flags; + int i; /* No invocations past this point */ spin_lock_irqsave(&cctx->lock, flags); @@ -2393,6 +2569,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 Thu May 30 10:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680125 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 C01FF17FADB; Thu, 30 May 2024 10:21:01 +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=1717064463; cv=none; b=OsikK/8e0Q1AqdATCyaShYvbkdZOuZm+mp7bgxSSsjhBvTdv4nHjMEW3gxtUB3ADGCdtgj6N5W1vJ7BLu9iuK3P3swFmBJ9mfNstTNIH/JN2kpBXDjN5Uul08ihE98htBP7FJqETh9pMTg066BXm5IW40O/3WyJM1JDCr4Xyhec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064463; c=relaxed/simple; bh=pURWiVdQiIRvSEYAhn6eVcAh1jv+SW/m+hNJ1ghp4uM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uBAh4cjr581fOaaBMge8XGfWUFsvIIAofRiW+4ciJijbqnnbxphiMX0FHN4pqSVPIxDEW4hHDCvlO7SqysM5O8ng8d1H4dVw1thASa7Y/jj/btmsB91NoSdjiMU+1OxrODeO1xOa2qVKdpvkqhZciu1TvbYii3nc9TLceWQOCtw= 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=DCvKmxTG; 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="DCvKmxTG" 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 44U83lEG013484; Thu, 30 May 2024 10:20:58 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= XviRhjn8Nh0zHkNpoG6LcuMMZOwS7cMOfzDTeDj+sIg=; b=DCvKmxTGWESZgQ7j buiCvTMMLvgFHNrGPSg6kH4m2hJaC8cJ3Jr6Q4Xm3sF5G129mGS+ugGDdPZBR6Us Wu1GA5DqDz/AIPaATDTIMDfymEgdSjnDEexy2izGPcQidB7dI75xmvlGoF82iMw9 dpbEmDa//GJFxFzyz9yqmkSzMx1UioJKsGqBBnVJMG+TDv5HKFPQkKsVwQzpdhiB qbx5trnJheAoeaYBk3jEzr6AkwF2FjREHmgXN/4G5J01/zSNR8R264i0+XQ0SPp3 OUmAO6A1J0cMc7xkc1aq0Clt9Iw39bmFa053lpeV/h4fawRhE7j/DJcDHstSJ5N7 jmBPQA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2n3m51-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:57 +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 44UAKu6N008562 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:56 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; Thu, 30 May 2024 03:20:54 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v3 5/9] misc: fastrpc: Redesign remote heap management Date: Thu, 30 May 2024 15:50:23 +0530 Message-ID: <20240530102032.27179-6-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: q5UVzqYmnDM0GKmSOvKT1Iul9C5a7A9F X-Proofpoint-ORIG-GUID: q5UVzqYmnDM0GKmSOvKT1Iul9C5a7A9F 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-30_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-2405300078 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 handling the request to unmap remote heap buffer type. Add changes to maintain list in a way that it can be used to to support remote heap grow/shrink request and the remote heap buffers cleanup during static PD restart. 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 d115860fc356..ef9bbd8c3dd1 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 */ @@ -274,6 +275,7 @@ struct fastrpc_session_ctx { }; struct fastrpc_static_pd { + struct list_head rmaps; char *servloc_name; char *spdname; void *pdrhandle; @@ -299,7 +301,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; struct list_head invoke_interrupted_mmaps; bool secure; bool unsigned_support; @@ -1256,6 +1257,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) { @@ -1282,9 +1330,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; @@ -1330,25 +1381,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; } } @@ -1365,8 +1417,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); @@ -1380,10 +1432,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; @@ -1393,15 +1452,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: @@ -1866,17 +1925,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); @@ -1884,11 +1942,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); @@ -1902,6 +1987,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; @@ -1910,20 +1996,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 } }; @@ -1950,16 +2064,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; @@ -1991,26 +2123,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", @@ -2018,14 +2141,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 } }; @@ -2249,6 +2377,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: @@ -2400,6 +2529,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); @@ -2566,9 +2696,6 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) 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); - for (i = 0; i < FASTRPC_MAX_SPD; i++) { if (cctx->spd[i].pdrhandle) pdr_handle_release(cctx->spd[i].pdrhandle); @@ -2576,6 +2703,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 Thu May 30 10:20:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680126 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 196FF17E467; Thu, 30 May 2024 10:21:05 +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=1717064467; cv=none; b=oXS7QLAMiRa0Z9ygFiI8ZROU64Y3d1Hkq58RQvIS74cbx4fj2XlAYQB0uNWSlwAsaMozs3c2Fm6kyBtJ0Ni1cXz933qHmsFKFb/UKCb9wKnpvVn9PZzwdk6vPjJ7v/HRmQ3vYGmTslHtMQ1C1yJIoGbKtCgQaXJwbLTHm0Tyh1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064467; c=relaxed/simple; bh=6KdX+5njdymJKO0qcdW+dnYulR6DY/GbtrLYVUntsvU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lYsdaR+dT61f+TySmarIvchpgjwTY0OB5jgDESdLH0U9SAiBJmr/MZynpeFwBJWxBpju2sGViYpTN/Vi4N0zH4ZIo01aSzFV5p/RwanCUUeezE2bObv1Vj6/fsHMDHcuSgy+UONPN6n4GekEKh1WuSVaXgxwMdqpGfF3DLWG28o= 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=QYj8rcaM; 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="QYj8rcaM" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44U8xLxe012513; Thu, 30 May 2024 10:21:01 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= US63t+Yz1Uf22K3LrCU7j64FxBUX2lmKIMBiTQrgHFk=; b=QYj8rcaMwzzb2vII vHG+cZ9G4s66uU8D5i5g/Jg/VQpD13d7TCuwe2uAOlSbr9qWWfq4SZS1CqtqMy9z IU0hKV55sygpfiBpU9UpbFTwxutBoIscOfnm2+gAb+GJdr6Jhl8HDM1nWbomr6ib Jpw/BZk8SWG3Hv39rjbsdeBYcCsXDEdAVyY6T4mOIcQ9/80xd8lVuWr9bVdKn0zB kTMVDzYCJ5+EELm0FXGFHvTLnBpr7OR83xVR6ar/UALFbBmua4bI7O6/nLQwumC3 v0FyVnRliNXjLJOJwQJb6yg9OKftRZtYutNJi1nM1DMD07kQlCVzb6RhHDRFzwPq MwJxeg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0qknv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:00 +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 44UAKxsK020577 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:20:59 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; Thu, 30 May 2024 03:20:56 -0700 From: Ekansh Gupta To: , CC: , , , , stable Subject: [PATCH v3 6/9] misc: fastrpc: Fix unsigned PD support Date: Thu, 30 May 2024 15:50:24 +0530 Message-ID: <20240530102032.27179-7-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: 0mXgfIR3c7xyP_V_YoXeKYHx3MAMXyX2 X-Proofpoint-ORIG-GUID: 0mXgfIR3c7xyP_V_YoXeKYHx3MAMXyX2 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-30_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405300078 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 user space. Current initial memory size is not sufficient and mapping request for user space allocated buffer is not supported. This results in failure of unsigned PD offload request. Add changes to fix initial memory size and user space allocated buffer mapping support. Fixes: 7f1f481263c3 ("misc: fastrpc: check before loading process to the DSP") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 221 ++++++++++++++++++++++++++--------------- 1 file changed, 141 insertions(+), 80 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index ef9bbd8c3dd1..d9d9f889e39e 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" @@ -327,6 +327,7 @@ struct fastrpc_user { int tgid; int pd; bool is_secure_dev; + bool is_unsigned_pd; char *servloc_name; /* Lock for lists */ spinlock_t lock; @@ -1488,7 +1489,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) @@ -1500,9 +1500,10 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, } if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE) - unsigned_module = true; + fl->is_unsigned_pd = true; - if (is_session_rejected(fl, unsigned_module)) { + + if (is_session_rejected(fl, fl->is_unsigned_pd)) { err = -ECONNREFUSED; goto err; } @@ -1986,6 +1987,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; @@ -2032,76 +2034,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_dbg(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_dbg(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); @@ -2111,49 +2086,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->is_unsigned_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->is_unsigned_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->is_unsigned_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 Thu May 30 10:20:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680127 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 DD3B81822DD; Thu, 30 May 2024 10:21:06 +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=1717064468; cv=none; b=m92CxhUH6MjGR+mq+4AsdurVSXAr8PB9dWLSTklG1NT6CiNUnRuVdK5qGlANZM1yRKOpPGOayyb1Brc4f0T9GkdowBvdHhWmrF8W+11pTFtx0RtqTqEFSS0aBrB8DGMOkuZnLrAl/HMUPNs7HOI8dbWoQEdTa5mPsTNxv2e6Kfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064468; c=relaxed/simple; bh=LERIl4p8XTRTxdG0Sa8lN3ZU7TRE7DybjDBqK5sjvJM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=peiXR5Sw4Kg1lGqiwvFbFPODZo10MeZr7cNkd54uCTR0qGiwMo/8R+o9X9FSRdoAEk0Z5VhXrsaiCnahrsMWe41kYwdIHu+xofjnG1RvGA89GU8StroYaf4I4A0gQoxKernf58ShPbrrmPie43wGwScRO50mCpOJ7gwBg43KDXA= 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=Fa7F+lr8; 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="Fa7F+lr8" 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 44U91fFg001343; Thu, 30 May 2024 10:21:03 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= AtkcS7gVxkgsG+XqnCl6qkIkQGTz6Qc14699SEWkJfs=; b=Fa7F+lr82jBnQ61A 3iIBH6i764R/zsu7AVPXJG0GLM3t8t7Jks8Z7Ll/jy5fcwH7SXWH0sBZuKhm1/Af MdGcerZHZ0aS9UsptPwWRDnCJvNC2/jGeEU71pISLs0Uvk9b/uGzfgV3cQuy/M0B 1zTNFYMyO4s3IHywEk3zYoZX30nzTVv8nQlttjfZARqYVU+61fLzCfudcvKLIETj ++sYGsfgFofNkNleiKURYWKX8NJuv3qGP+wKNmNjXw5WOepsIlXGAfm/uZkwNajz tY2xo9L5VHlFI1GhgbzbJLw7FNl8ixLg+4Yx3QObqGRGNDXtHSDLUf9lLiYHtTHj ih1iDg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0pufqj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:03 +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 44UAL21L013121 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:02 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; Thu, 30 May 2024 03:20:59 -0700 From: Ekansh Gupta To: , CC: , , , , stable Subject: [PATCH v3 7/9] misc: fastrpc: Restrict untrusted app to attach to privileged PD Date: Thu, 30 May 2024 15:50:25 +0530 Message-ID: <20240530102032.27179-8-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: wLO8n3owdA8n2e67guPKwrPTZ2XpJU8E X-Proofpoint-GUID: wLO8n3owdA8n2e67guPKwrPTZ2XpJU8E 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-30_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=883 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-2405300078 Untrusted application with access to only non-secure fastrpc device node can attach to root_pd or static PDs if it can make the respective init request. This can cause problems as the untrusted application can send bad requests to root_pd or static PDs. Add changes to reject attach to privileged PDs if the request is being made using non-secure fastrpc device node. Fixes: 0871561055e6 ("misc: fastrpc: Add support for audiopd") Cc: stable Signed-off-by: Ekansh Gupta Reviewed-by: Dmitry Baryshkov --- drivers/misc/fastrpc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index d9d9f889e39e..73fa0e536cf9 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1344,6 +1344,11 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, } inbuf; u32 sc; + if (!fl->is_secure_dev) { + dev_dbg(&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; @@ -1769,6 +1774,11 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) int tgid = fl->tgid; u32 sc; + if (!fl->is_secure_dev) { + dev_dbg(&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 Thu May 30 10:20:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680129 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 B582C183A77; Thu, 30 May 2024 10:21:11 +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=1717064473; cv=none; b=e5NdA92MKjQ9aUDKPtVIiSIuDcMgpLbCnQILcDHtdISy7dbTYV7hJLpeXfoW65VxEf3KAjCWvmzeUgNJ1XW1V54Hzs7Ryejk+SaDuPwxnj+EtGDY1JFbBbTBF/Qt7/7ne7JIMJipUHd837qlcf6AMV75K+NNn4grOEa0gkZvfbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064473; c=relaxed/simple; bh=NDxJxCiSKxhOVyshX2EdcNFHWjKyLjm6Jh3sadTuF3U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vAJIrwnccJqvj516Ydmr2pWAKdOK9HLvCL6DaTZmpI41rdkLF9iXRSPBTzMVba5to5FnCIKgSCsMIDoib1rX3Ed1iyFf8qETMaecMev+5mSCH94l8Oj8DbRgFzeQuOmPkKEcB8ect4iVaH0Vkr3JiqeEqGJp7mysgEzdX6dPZic= 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=HXmvwukS; 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="HXmvwukS" 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 44U0gDwO004882; Thu, 30 May 2024 10:21:06 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= oSJXg147aTxzjU2gH4ri1vgUqOjpDR0kc/VcrJ30saE=; b=HXmvwukSYAUwT+L+ 2vs74o08L3GbnxdvJ9P1GNMV3weGHA7VoOPf4PtCh+ETUzzul9o7LXyMKfslwVqz kKCgqr97PrCP+otGjEHbuC8494kdKMhaKQPOo0/JSZCQdA0K/NMzlZmOM8xjsrAV xV2GfRXcS1s5rKx+nG+LsnjsMq07i9eHn0C+HAGJE5XiWLhyGuEGkze/txnoROvG TJTM5ycPHvNYj0uyYXtRbXxvPhHBMNOYytb3YzYg5UnKYRwqz7Yxm0DypGWSF9bA e+091nlDmXuPrW65/XLdyTPVStgII4mv3SQcAU9r3yH+u+PrPRTYWqCM4O/FpKKG jOgaTg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba0gbu9y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:06 +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 44UAL5Va013240 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:05 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; Thu, 30 May 2024 03:21:02 -0700 From: Ekansh Gupta To: , CC: , , , , stable Subject: [PATCH v3 8/9] misc: fastrpc: Restrict untrusted app to spawn signed PD Date: Thu, 30 May 2024 15:50:26 +0530 Message-ID: <20240530102032.27179-9-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: bvj00v421i9rjMI2IRD6LNuWF0BQ76Pe X-Proofpoint-ORIG-GUID: bvj00v421i9rjMI2IRD6LNuWF0BQ76Pe 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-30_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-2405300078 Some untrusted applications will not have access to open fastrpc device nodes and a privileged process can open the device node on behalf of the application. Add a check to restrict such untrusted applications from offloading to signed PD. Fixes: 7f1f481263c3 ("misc: fastrpc: check before loading process to the DSP") Cc: stable Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 73fa0e536cf9..32615ccde7ac 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -328,6 +328,7 @@ struct fastrpc_user { int pd; bool is_secure_dev; bool is_unsigned_pd; + bool untrusted_process; char *servloc_name; /* Lock for lists */ spinlock_t lock; @@ -1249,13 +1250,17 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques * 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_dbg(&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) @@ -1504,12 +1509,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 a priveleged process. 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->is_unsigned_pd = true; if (is_session_rejected(fl, fl->is_unsigned_pd)) { - err = -ECONNREFUSED; + err = -EACCES; goto err; } From patchwork Thu May 30 10:20:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 13680128 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 57D9D183A76; Thu, 30 May 2024 10:21:11 +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=1717064472; cv=none; b=IVo8r1IOamSfCgOtRWp9HH4tVViejhZCBWs18+EuieuXq8fMcP6NMV9fcvafcJRNPN5ScKiaEOtYx90IFaQbrtvEKioqZFJxTrd9WHCYxBmbyuhmkLOSoEnp5H0OzYHDLT9tClUXeXxm4ImjZ2AUcKPY6iiJew9DWYACw0dR94k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064472; c=relaxed/simple; bh=lWUVovV8diMODE6RkshdgaufNsjzuhV3F8PtdYrCg1w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rpYl54G+7S2hsFEkfeAaqH+tEqk55Bl0VRQ1yv4SiwTfLZtCpubB/mB/vc+fAdvmmhkLkZl24OZQG7PkUQLCEHGA4JjG8YnoYNi8gZcWXbgm2vhs5v1kzPNqupUQchjMqM2dYqM7gVUsbIoDXFSPWqp5OSkl+MsOLjApyBoZjr4= 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=ByCTx+vd; 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="ByCTx+vd" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44U8N5J6025517; Thu, 30 May 2024 10:21:09 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= luZTosupL6TDya/Gh2MiaCHdLtt1tzOx79R4jtJkzrM=; b=ByCTx+vdiYAjIDDK I3kF5CbK+Ow9Ko3cpbR+YLq5I77cCPzwdiLuF6q/sJzcE3kwbYGKUOCbN0UHXKA+ xO2sRi408+u5VeOMq1bqLMgClx71t9zgjJMPXCz55WiA7sqK1YPperXC86ZSD4/3 M/yOXfL7m6ArcTxih4mBm0Pif8ZH7HxQGOI2qXU6YWfepNyHnEU5aL3IrPuHZ11g m1oEjGyfePZwj+2KRCxaaO+jUpOZGcKpuUdHr4aTaBFxEiG8K4QGK8A+oobOXsl3 +aLl8VEarvrS41TmrHU6DwPNTr67iwNXhkBppSP3e6fZbxvBEhbKw5ZN6NpKMI5u ALwq+A== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2pur0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:08 +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 44UAL8fQ001393 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 10:21:08 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; Thu, 30 May 2024 03:21:05 -0700 From: Ekansh Gupta To: , CC: , , , Subject: [PATCH v3 9/9] misc: fastrpc: Add system unsigned PD support Date: Thu, 30 May 2024 15:50:27 +0530 Message-ID: <20240530102032.27179-10-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240530102032.27179-1-quic_ekangupt@quicinc.com> References: <20240530102032.27179-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: nasanex01b.na.qualcomm.com (10.46.141.250) 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: Qq4so4NFU9_Q5kNRF-_zFc2Bj3Oc3EzU X-Proofpoint-ORIG-GUID: Qq4so4NFU9_Q5kNRF-_zFc2Bj3Oc3EzU 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-30_07,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 clxscore=1015 bulkscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405300078 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 Reviewed-by: Dmitry Baryshkov --- drivers/misc/fastrpc.c | 27 +++++++++++++++++++++------ include/uapi/misc/fastrpc.h | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 32615ccde7ac..fc24653d7b7e 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -119,6 +119,12 @@ #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, + SYSTEM_UNSIGNED_PD = 3, +}; + static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", "sdsp", "cdsp"}; struct fastrpc_phy_page { @@ -327,7 +333,7 @@ struct fastrpc_user { int tgid; int pd; bool is_secure_dev; - bool is_unsigned_pd; + enum fastrpc_userpd_type userpd_type; bool untrusted_process; char *servloc_name; /* Lock for lists */ @@ -1518,14 +1524,22 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, fl->untrusted_process = true; if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE) - fl->is_unsigned_pd = true; + 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->is_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; @@ -1718,6 +1732,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) { @@ -2133,7 +2148,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) return -EFAULT; if ((req.flags == ADSP_MMAP_ADD_PAGES || - req.flags == ADSP_MMAP_REMOTE_HEAP_ADDR) && !fl->is_unsigned_pd) { + 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; @@ -2188,7 +2203,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) 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->is_unsigned_pd) { + 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; } @@ -2220,7 +2235,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) err_copy: if ((req.flags != ADSP_MMAP_ADD_PAGES && - req.flags != ADSP_MMAP_REMOTE_HEAP_ADDR) || fl->is_unsigned_pd) { + 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); 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 */