From patchwork Tue Nov 21 09:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 167598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp507521vqb; Tue, 21 Nov 2023 01:49:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9mv4+i8vVTqU7n79+i5vGebsS5SV8q70601CLcG8ukeKFYD9jvSzz3n24Zc1f/5YlDXdG X-Received: by 2002:a05:6a21:789d:b0:187:15e2:fdd9 with SMTP id bf29-20020a056a21789d00b0018715e2fdd9mr8806653pzc.39.1700560155860; Tue, 21 Nov 2023 01:49:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700560155; cv=none; d=google.com; s=arc-20160816; b=uWWViwp+pHy0UyVAg066MMqI/1FrHuMi1G0W4jyX81lJLj94PB09ABMUWake3BmaQQ Us3JWIQ+qi7reEHtzpQGsX9tpsYmo7R2LT7MRZkTVp/oMU4+DBTUyLdK2ajcLYICAIjA 0imQTor20I9ecKlwLZKlRsw38lOWsTeyxNB/5UETTN7kxOuyeYAxzb3UTj99ycq1DFOI qCOpNLWXSB5jduovNZzCUtamV5jeQfYF5kTCw6gdo9/uhE/z82n5EM0d74jCvBeIpWSj 0ovk8ei1ZVXzoJcqHnDiKJRiUk4UVT0tyOTQJvxnBP8jNPQuzQ/jFHYkm32nDZ9CDRE5 kHXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZDdbm6UJ22eg4twUHt99JbZdF45X29IpsgrcGASTZss=; fh=qZfm2gxVFKi5OFpGqqouvPKfcV9/1EOj1DTqrfs2EPk=; b=a0+xxEkptEOp/O16XiqANQzK2QXp5ut7s8vZMRl1gVO4Hy4UdmZQ+d8huqS7ji0pqv I+DEovHd9EaQPg53/FysxIEARTJsX1aub1xEntMycjWAnimac9qsOuWoTVd1nnCQ/In/ hQ5xjUBc+/PZqxhM5YsY/PJz8Qz6ikehKMtxzoOhuFRDCuXYzOW+uUCEgQJUg9jvskzo pf+na+oPp73QiHoK2u53yGWD3Yx2mCfXtCD+S3QuWfiHhwX1RVvO4jy56VSrEIM0BNHQ aV0az2kHsxRos0y5wyRye9lDRFbBrnSvWaFjB1pnWu9WUGBAyVUwRnxnFFDVQ0rR4RhQ oHjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=O7H0fa7d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ix3-20020a170902f80300b001c589ba4a04si9394000plb.24.2023.11.21.01.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:49:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=O7H0fa7d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9390880FA85F; Tue, 21 Nov 2023 01:49:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbjKUJtL (ORCPT + 99 others); Tue, 21 Nov 2023 04:49:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234095AbjKUJtE (ORCPT ); Tue, 21 Nov 2023 04:49:04 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F538D8; Tue, 21 Nov 2023 01:49:01 -0800 (PST) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AL9AhSM026417; Tue, 21 Nov 2023 09:48:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=ZDdbm6UJ22eg4twUHt99JbZdF45X29IpsgrcGASTZss=; b=O7H0fa7dOzbw53s35i1TSeKHZJM4XvuWngRVCh/JppICPq0h/JA64mMI6rrD8LBJvmvq 7G1C5vCVcEzeVZNU3Mqs5a+QftV8y+ckTQZRqmFMbj2i4AtUjbFNqRxjcSAQoopFAimv v+wNr2eqmS/wyzZULLWF/eaEZ162FIvoIg0CfgY80Ft/L0RvHbiyfOrA0VNQy8kdOCB+ OxR75YY5l6gydSsh5GonLgimLCQFVGODCV5+p20O1zn1QDYobvOFtUvzxusg5q5of3Ye T40Jgfbv6en1nSBUsD1bmfv1MjcZ8BLbSivF0237V9T9lbSFkMOtXhpgelpn118AYCXy pQ== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ugdxmhgt4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 09:48:59 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3AL9mwOL024339 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 09:48:58 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.1118.40; Tue, 21 Nov 2023 01:48:56 -0800 From: Ekansh Gupta To: , CC: , Subject: [PATCH v7 2/5] misc: fastrpc: Add CRC support for remote buffers Date: Tue, 21 Nov 2023 15:18:41 +0530 Message-ID: <20231121094844.5764-3-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231121094844.5764-1-quic_ekangupt@quicinc.com> References: <20231121094844.5764-1-quic_ekangupt@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] 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: mV2uo1tyaasM2FysDsKI-EyPZH79rLjp X-Proofpoint-ORIG-GUID: mV2uo1tyaasM2FysDsKI-EyPZH79rLjp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-21_03,2023-11-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 phishscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311210076 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 01:49:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783166566084499359 X-GMAIL-MSGID: 1783166566084499359 CRC check for input and output argument helps in ensuring data consistency over a remote call. If user intends to enable CRC check, first local user CRC is calculated at user end and a CRC buffer is passed to DSP to capture remote CRC values. DSP is expected to write to the remote CRC buffer which is then compared at user level with the local CRC values. Signed-off-by: Ekansh Gupta --- Changes in v7: - Rebase the patch to latest kernel version drivers/misc/fastrpc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 265e34f53c4e..55f126c779cb 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -611,6 +611,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( /* Released in fastrpc_context_put() */ fastrpc_channel_ctx_get(cctx); + ctx->crc = (u32 *)(uintptr_t)invoke->crc; ctx->sc = sc; ctx->retval = -1; ctx->pid = current->pid; @@ -1067,6 +1068,7 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, struct fastrpc_invoke_buf *list; struct fastrpc_phy_page *pages; u64 *fdlist; + u32 *crclist; int i, inbufs, outbufs, handles; inbufs = REMOTE_SCALARS_INBUFS(ctx->sc); @@ -1074,7 +1076,8 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, handles = REMOTE_SCALARS_INHANDLES(ctx->sc) + REMOTE_SCALARS_OUTHANDLES(ctx->sc); list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages = fastrpc_phy_page_start(list, ctx->nscalars); - fdlist = (uint64_t *)(pages + inbufs + outbufs + handles); + fdlist = (u64 *)(pages + inbufs + outbufs + handles); + crclist = (u32 *)(fdlist + FASTRPC_MAX_FDLIST); for (i = inbufs; i < ctx->nbufs; ++i) { if (!ctx->maps[i]) { @@ -1099,6 +1102,10 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, fastrpc_map_put(mmap); } + if (ctx->crc && crclist && rpra) { + if (copy_to_user((void __user *)ctx->crc, crclist, FASTRPC_MAX_CRCLIST * sizeof(u32))) + return -EFAULT; + } return 0; } @@ -1719,6 +1726,7 @@ static int fastrpc_multimode_invoke(struct fastrpc_user *fl, char __user *argp) switch (invoke.req) { case FASTRPC_INVOKE: + case FASTRPC_INVOKE_ENHANCED: /* nscalars is truncated here to max supported value */ if (copy_from_user(&einv, (void __user *)(uintptr_t)invoke.invparam, invoke.size))