Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1579220rwd; Tue, 16 May 2023 20:49:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Pkc01lZTGcgFebYUmv42FVLz4L2NsmQ9GX4iiNmcXGSzSjMHVDzQm1GF7ydDCMDaxiNrp X-Received: by 2002:a17:902:d509:b0:1a6:f93a:a136 with SMTP id b9-20020a170902d50900b001a6f93aa136mr1104949plg.22.1684295394810; Tue, 16 May 2023 20:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684295394; cv=none; d=google.com; s=arc-20160816; b=kD1gT5I+KlGxhIgQmFkKuE992QyuNY517Wh93FPrciJwugFsNGxOOquE3rg+6bw3PE DOUsGdyZAcfAKIlVqQ9JzwBmOyE2sm3pwdD3sO/cBw/ygFQVbjriFfdFNS4W1apG0cml DRarQXE0+qoaeCLZ42s7sjyruqU6twtuSQzWCchK55UJ4nyLHDmt5aI15lDyc89cna8x EHyL1tsx1xKhdBnmHQIXMiuhsdEVK7QBhOD5q0W3BMdb+3tP837qkBjPNCF9MBhkKAFi V2lrH6CovdOh9IyCwZAu/DuTbCZQSjUIV8VDuHw2PxPhXJlPspnNfWo2GwznXSHizc/U 2Jfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=bM0YNT+U36eWDYdIyW/GiESRO4pu/ZY5wFHIj9jl/Fk=; b=P4zjleYLQFEV2gCg28t7M5aWu+YE5KtkeEvhiiXyWJignR5kAW+rfecYrSiY5/y+04 mzp5eJGsYM3nSZfkzXvSAkair958B1AV3hy77Uve9X4jRD7M44CqunIf3Dq20v5Dw6O4 iFjO2I9EecWHIDjbMg7GtjA3COSEiiZbxYT4BgTBsI2kNgiMIadO80yGJlcJwhzQesab ZFFQH3HgTLotoGJSCXLUiOotQbStPknEzSEpPsgDiciOkl3Uq/Pt3d4UdlWEu2gi/rFx 0rX/vw/ben3Lt1OY5b7nwQikOd83PQYvG9OUzpQWJVvJetvl/MVHgi8ptcrXoaGzBggg ydZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hbz45D82; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw22-20020a170903045600b001a63b8e071esi18771580plb.28.2023.05.16.20.49.40; Tue, 16 May 2023 20:49:54 -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=@mediatek.com header.s=dk header.b=hbz45D82; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232168AbjEQDTJ (ORCPT + 99 others); Tue, 16 May 2023 23:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbjEQDTH (ORCPT ); Tue, 16 May 2023 23:19:07 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADA652114 for ; Tue, 16 May 2023 20:19:04 -0700 (PDT) X-UUID: 919b685cf46111ed9cb5633481061a41-20230517 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=bM0YNT+U36eWDYdIyW/GiESRO4pu/ZY5wFHIj9jl/Fk=; b=hbz45D82wcIIboPtdDa8xigSp7oNXmrpSTyL3u3UEJvTIcGycJ4oL4NIS0gT684vPCgFWHGR9IMxiu3X/W1kyuHIpBsr837zwxf+raUwJa5HSeTupZ0LeOKWxPatiXeLoMiZhBRRbOE+ZzJcK8dRHNAUTvBzEfZ+r7USypM55Sk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.25,REQID:2e7e0b34-cfa3-4e33-9886-90062db96ff5,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:d5b0ae3,CLOUDID:c2b50e6c-2f20-4998-991c-3b78627e4938,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-UUID: 919b685cf46111ed9cb5633481061a41-20230517 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 170742362; Wed, 17 May 2023 11:19:01 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 17 May 2023 11:18:59 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 17 May 2023 11:18:59 +0800 From: Xiaoming Ding To: Jens Wiklander , Sumit Garg , Matthias Brugger , AngeloGioacchino Del Regno , , , , CC: , , Xiaoming Ding Subject: [PATCH] tee: add FOLL_LONGTERM for CMA case when alloc shm Date: Wed, 17 May 2023 11:18:56 +0800 Message-ID: <20230517031856.19660-1-xiaoming.ding@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,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 FOLL_LONGTERM will avoid share memory alloc from CMA region, which may be used in secure playback case. if part of CMA region taken by share memory for long term usage, CMA will failed to get whole buffer back. Signed-off-by: Xiaoming Ding --- drivers/tee/tee_shm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 673cf0359494..ddd3947e2229 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -223,6 +223,7 @@ register_shm_helper(struct tee_context *ctx, unsigned long addr, size_t num_pages; void *ret; int rc; + u32 page_flag = FOLL_WRITE; if (!tee_device_get(teedev)) return ERR_PTR(-EINVAL); @@ -255,9 +256,11 @@ register_shm_helper(struct tee_context *ctx, unsigned long addr, ret = ERR_PTR(-ENOMEM); goto err_free_shm; } - +#if IS_ENABLED(CONFIG_CMA) + page_flag |= FOLL_LONGTERM; +#endif if (flags & TEE_SHM_USER_MAPPED) - rc = pin_user_pages_fast(start, num_pages, FOLL_WRITE, + rc = pin_user_pages_fast(start, num_pages, page_flag, shm->pages); else rc = shm_get_kernel_pages(start, num_pages, shm->pages); -- 2.18.0