From nobody Sun Sep 22 09:31:25 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6F42C433FE for ; Fri, 4 Feb 2022 09:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237754AbiBDJdH (ORCPT ); Fri, 4 Feb 2022 04:33:07 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:57650 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232946AbiBDJdG (ORCPT ); Fri, 4 Feb 2022 04:33:06 -0500 X-UUID: a50011e4aa3a4a8397125ce9a9d20236-20220204 X-UUID: a50011e4aa3a4a8397125ce9a9d20236-20220204 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1009347765; Fri, 04 Feb 2022 17:33:03 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 4 Feb 2022 17:33:02 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 4 Feb 2022 17:33:02 +0800 From: Phil Chang To: CC: , , , , , , Subject: [PATCH] optee: make tee_shm_register vmalloc supported Date: Fri, 4 Feb 2022 17:32:54 +0800 Message-ID: <20220204093254.2467-1-phil.chang@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch allowed the tee shm use vmalloc area buffer. Signed-off-by: Phil Chang --- Hi, In some low-memory devices, it's hard to aquire large-orders pages, this pathes is allowed user use scatter pages to register shm. Thanks. drivers/tee/optee/call.c | 2 +- drivers/tee/tee_shm.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index b25cc1fac945..937bcc7df8e4 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -362,7 +362,7 @@ int optee_check_mem_type(unsigned long start, size_t nu= m_pages) * Allow kernel address to register with OP-TEE as kernel * pages are configured as normal memory only. */ - if (virt_addr_valid(start)) + if (virt_addr_valid(start) || is_vmalloc_addr((void *)start)) return 0; mmap_read_lock(mm); diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 499fccba3d74..31d0c10485ff 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -195,6 +195,20 @@ struct tee_shm *tee_shm_register(struct tee_context *c= tx, unsigned long addr, if (flags & TEE_SHM_USER_MAPPED) { rc =3D pin_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages); + } else if (is_vmalloc_addr((void *)start)) { + struct page *page; + int i; + + for (i =3D 0; i < num_pages; i++) { + page =3D vmalloc_to_page((void *)(start + PAGE_SIZE * i)); + if (!page) { + ret =3D ERR_PTR(-ENOMEM); + goto err; + } + get_page(page); + shm->pages[i] =3D page; + } + rc =3D num_pages; } else { struct kvec *kiov; int i; -- 2.25.1