From nobody Sun Sep 22 07:44:15 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 1665FC433EF for ; Fri, 25 Feb 2022 15:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241928AbiBYPVc (ORCPT ); Fri, 25 Feb 2022 10:21:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241109AbiBYPVb (ORCPT ); Fri, 25 Feb 2022 10:21:31 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 256411DD0E4 for ; Fri, 25 Feb 2022 07:20:54 -0800 (PST) X-UUID: 8b348bcd090e4e0eaed7592f18f08dc6-20220225 X-UUID: 8b348bcd090e4e0eaed7592f18f08dc6-20220225 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1326226168; Fri, 25 Feb 2022 23:20:50 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Fri, 25 Feb 2022 23:20:49 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 25 Feb 2022 23:20:49 +0800 From: Phil Chang To: CC: , , , , , , Subject: [PATCH v4] tee: make tee_shm_register_kernel_buf vmalloc supported Date: Fri, 25 Feb 2022 23:20:40 +0800 Message-ID: <20220225152040.31896-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" In some low-memory devices, it's hard to aquire large-orders pages, this patch allowed user using scatter pages to register shm. Signed-off-by: Phil Chang Reviewed-by: Sumit Garg --- drivers/tee/optee/call.c | 2 +- drivers/tee/tee_shm.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index bd49ec934060..2082e632adff 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; =20 mmap_read_lock(mm); diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index f31e29e8f1ca..836872467dc6 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -23,21 +23,36 @@ static void shm_put_kernel_pages(struct page **pages, s= ize_t page_count) static int shm_get_kernel_pages(unsigned long start, size_t page_count, struct page **pages) { - struct kvec *kiov; size_t n; int rc; =20 - kiov =3D kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); - if (!kiov) - return -ENOMEM; + if (is_vmalloc_addr((void *)start)) { + struct page *page; =20 - for (n =3D 0; n < page_count; n++) { - kiov[n].iov_base =3D (void *)(start + n * PAGE_SIZE); - kiov[n].iov_len =3D PAGE_SIZE; - } + for (n =3D 0; n < page_count; n++) { + page =3D vmalloc_to_page((void *)(start + PAGE_SIZE * n)); + if (!page) + return -ENOMEM; + + get_page(page); + pages[n] =3D page; + } + rc =3D page_count; + } else { + struct kvec *kiov; + + kiov =3D kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); + if (!kiov) + return -ENOMEM; =20 - rc =3D get_kernel_pages(kiov, page_count, 0, pages); - kfree(kiov); + for (n =3D 0; n < page_count; n++) { + kiov[n].iov_base =3D (void *)(start + n * PAGE_SIZE); + kiov[n].iov_len =3D PAGE_SIZE; + } + + rc =3D get_kernel_pages(kiov, page_count, 0, pages); + kfree(kiov); + } =20 return rc; } --=20 2.25.1