From patchwork Tue Mar 21 10:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekansh Gupta X-Patchwork-Id: 72799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1699967wrt; Tue, 21 Mar 2023 03:41:52 -0700 (PDT) X-Google-Smtp-Source: AK7set/xNItVPAzqEw5pLJa2IWLr1pgGmNwlAVK5ooTe/mKxl4fMiVgV9Yo6Pl4etHi+UrDokAJs X-Received: by 2002:a17:90b:4ac9:b0:23d:1aae:29e5 with SMTP id mh9-20020a17090b4ac900b0023d1aae29e5mr2265335pjb.20.1679395312392; Tue, 21 Mar 2023 03:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679395312; cv=none; d=google.com; s=arc-20160816; b=V1uP4a7raD7c5gwySA1g/DsnvYPausuBYjgcAdNUlIRWS2R8r8NuUxdNg8yMixtu9F kack9jpwRCeGw5ySaOuYY5uXavkBecF8EITZEpdvUh0fb8OSdoKEv5EPvp+zX8Y6wsJE L1IKsu0MZEaRXjD82SjPs+AavbgK4B912YEp+ymdkNi/aOPLemn/c8IP224CDSDWI2HW reSUThUssQfTQapfS44awJOjlZDTK2hSRDNsM8TYH92UK8d8gduejDCFUXDUgpZsilZ1 vg9BNv6jx3OmqzbPhWV5wXiRVvNlYQTF/UIDDXOrN6GOYYhKUutw8ingrp1DS4ZrGWOF GQAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=9YNn0GvTOWUriUJfRXqCWTiMNG5e3zQlxzQtEIl/lzc=; b=KANs0+67zf5Cqi0QqCXL+MJVvQYG3e2plTd3se8Y6GPwdold3hJ3RBM+VXeP2HZKvS adYlkRabomMGt/zIuDRMMaPBA3lqJNY8yRXrv/Ea/XXkzUfo6C4CAd1lbp8pgs80grvf FSLWmfbq8NrlyNys+ehXNamVw9muuu4HOb8US+/UIMYDwFm1qASGIDvUjqS2gVQ+XS1f s6ynHk/CXh52YFW9uz7OklHoNw9j2SQgX/QYbAu25zG4CsszVKD5u7fK8byNPQNXvJQv mU2r/+JiOmGS8cUsKmimSmFtjjwjgZnrmSh9pNkpP1muGM2UCSb2W9kHZ7z0lab2xpVW FR2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VADFsHCI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 23-20020a630617000000b004fc29a7445asi13275577pgg.89.2023.03.21.03.41.37; Tue, 21 Mar 2023 03:41:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VADFsHCI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbjCUKe0 (ORCPT + 99 others); Tue, 21 Mar 2023 06:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbjCUKeY (ORCPT ); Tue, 21 Mar 2023 06:34:24 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96F6F30B28; Tue, 21 Mar 2023 03:33:49 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32L7cKno029817; Tue, 21 Mar 2023 10:33:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=9YNn0GvTOWUriUJfRXqCWTiMNG5e3zQlxzQtEIl/lzc=; b=VADFsHCIGZIzTIHFBSC1bjAHduy9xgKmJraiwlLWhbuYIRm3znw0NYiQ92lG9Yw9exkX 9b/I9GJKGODud2OeCKsAMEkySLuvwc3M3PIFbDGkWVV3HXq4VISlk3pIy/ryP/zk+iZO bCeDPyjHlMrMq9XYMerA19d+Q9LuWNz/x4XI53ruKvSiCR7lVqOcGJHpx813dE8f1bzY oqvxaYOlVEHpN1eKunL/JPFNHWDCz5N+0FfZgKjeGc+vQ/FdDkr21kpNZqSvFzFlNutX 7zeWuyTFlwBCwqnKkLt00jAAR83umdo+CA48n/0wduOuDk0qcIotCcj2hCRdZ82zeffs dg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3peg57v1gh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Mar 2023 10:33:12 +0000 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 32LAXBG4006394 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Mar 2023 10:33:11 GMT Received: from ekangupt-linux.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 21 Mar 2023 03:33:07 -0700 From: Ekansh Gupta To: , CC: Ekansh Gupta , , , , , , stable Subject: [PATCH v1] misc: fastrpc: Pass proper scm arguments for secure map request Date: Tue, 21 Mar 2023 16:02:59 +0530 Message-ID: <1679394779-2658-1-git-send-email-quic_ekangupt@quicinc.com> X-Mailer: git-send-email 2.7.4 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-ORIG-GUID: qcc0-ZtQNdKBqq2-NFwM6kaEJ22Nef38 X-Proofpoint-GUID: qcc0-ZtQNdKBqq2-NFwM6kaEJ22Nef38 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-21_07,2023-03-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 spamscore=0 clxscore=1015 phishscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303210081 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760973619311257906?= X-GMAIL-MSGID: =?utf-8?q?1760973619311257906?= If a map request is made with securemap attribute, the memory ownership needs to be reassigned to new VMID to allow access from protection domain. Currently only DSP VMID is passed to the reassign call which is incorrect as only a combination of HLOS and DSP VMID is allowed for memory ownership reassignment and passing only DSP VMID will cause assign call failure. Also pass proper restoring permissions to HLOS as the source permission will now carry both HLOS and DSP VMID permission. Change is also made to get valid physical address from scatter/gather for this allocation request. Fixes: e90d91190619 ("misc: fastrpc: Add support to secure memory map") Cc: stable Tested-by: Ekansh Gupta Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index a701132..77a5930 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -316,12 +316,14 @@ static void fastrpc_free_map(struct kref *ref) if (map->table) { if (map->attr & FASTRPC_ATTR_SECUREMAP) { struct qcom_scm_vmperm perm; + int vmid = map->fl->cctx->vmperms[0].vmid; + unsigned int src_perms = BIT(QCOM_SCM_VMID_HLOS) | BIT(vmid); int err = 0; perm.vmid = QCOM_SCM_VMID_HLOS; perm.perm = QCOM_SCM_PERM_RWX; err = qcom_scm_assign_mem(map->phys, map->size, - &map->fl->cctx->perms, &perm, 1); + &src_perms, &perm, 1); if (err) { dev_err(map->fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d", map->phys, map->size, err); @@ -787,8 +789,12 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd, goto map_err; } - map->phys = sg_dma_address(map->table->sgl); - map->phys += ((u64)fl->sctx->sid << 32); + if (attr & FASTRPC_ATTR_SECUREMAP) { + map->phys = sg_phys(map->table->sgl); + } else { + map->phys = sg_dma_address(map->table->sgl); + map->phys += ((u64)fl->sctx->sid << 32); + } map->size = len; map->va = sg_virt(map->table->sgl); map->len = len; @@ -798,9 +804,15 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd, * If subsystem VMIDs are defined in DTSI, then do * hyp_assign from HLOS to those VM(s) */ + unsigned int src_perms = BIT(QCOM_SCM_VMID_HLOS); + struct qcom_scm_vmperm dst_perms[2] = {0}; + + dst_perms[0].vmid = QCOM_SCM_VMID_HLOS; + dst_perms[0].perm = QCOM_SCM_PERM_RW; + dst_perms[1].vmid = fl->cctx->vmperms[0].vmid; + dst_perms[1].perm = QCOM_SCM_PERM_RWX; map->attr = attr; - err = qcom_scm_assign_mem(map->phys, (u64)map->size, &fl->cctx->perms, - fl->cctx->vmperms, fl->cctx->vmcount); + 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", map->phys, map->size, err);