Remove get_kernel_pages()
Subsystems (3)
cover Remove get_kernel_pages()
From: Ira Weiny <[email protected]>
get_kernel_pages() only had one caller [shm_get_kernel_pages()] which did not need the functionality it provided. Furthermore, it called kmap_to_page() which we are looking to removed.
Alter shm_get_kernel_pages() to no longer call get_kernel_pages() and remove get_kernel_pages(). Along the way it was noted that shm_get_kernel_pages() does not have any need to support vmalloc'ed addresses either. Remove that functionality to clean up the logic.
This series also fixes and uses is_kmap_addr().
Ira Weiny (4):
highmem: Enhance is_kmap_addr() to check kmap_local_page() mappings
tee: Remove vmalloc page support
tee: Remove call to get_kernel_pages()
mm: Remove get_kernel_pages()
drivers/tee/tee_shm.c | 41 ++++++++++++-------------------- include/linux/highmem-internal.h | 5 +++- include/linux/mm.h | 2 -- mm/swap.c | 30 ----------------------- 4 files changed, 19 insertions(+), 59 deletions(-)
base-commit: 274d7803837da78dfc911bcda0d593412676fc20
Signature · 1 line
2.37.2
PATCH 1/4 highmem: Enhance is_kmap_addr() to check kmap_local_page() mappings
From: Ira Weiny <[email protected]>
is_kmap_addr() is only looking at the kmap() address range which may cause check_heap_object() to miss checking an overflow on a kmap_local_page() page.
Add a check for the kmap_local_page() address range to is_kmap_addr().
--- include/linux/highmem-internal.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/highmem-internal.h +4 -1
@@ -152,7 +152,10 @@ static inline void totalhigh_pages_add(long count)static inline bool is_kmap_addr (const void *x) {unsigned long addr = (unsigned long )x; -return addr >=PKMAP_ADDR (0 ) && addr <PKMAP_ADDR (LAST_PKMAP ); + +return (addr >=PKMAP_ADDR (0 ) && addr <PKMAP_ADDR (LAST_PKMAP )) || + (addr >=__fix_to_virt (FIX_KMAP_END ) && + addr <__fix_to_virt (FIX_KMAP_BEGIN )); }#else /* CONFIG_HIGHMEM */
Signature · 1 line
2.37.2
PATCH 2/4 tee: Remove vmalloc page support
In reply to [email protected]From: Ira Weiny <[email protected]>
The kernel pages used by shm_get_kernel_pages() are allocated using GFP_KERNEL through the following call stack:
trusted_instantiate()
trusted_payload_alloc() -> GFP_KERNEL <trusted key op> tee_shm_register_kernel_buf() register_shm_helper() shm_get_kernel_pages()
Where <trusted key op> is one of:
trusted_key_unseal()
trusted_key_get_random()
trusted_key_seal()
Remove the vmalloc page support from shm_get_kernel_pages(). Replace with a warn on once.
---
Jens I went with the suggestion from Linus and Christoph and rejected vmalloc addresses. I did not hear back from you regarding Linus' question if the vmalloc page support was required by an up coming patch set or not. So I assumed it was something out of tree.
--- drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
drivers/tee/tee_shm.c +12 -24
@@ -24,37 +24,25 @@ static void shm_put_kernel_pages(struct page **pages, size_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; -if (is_vmalloc_addr ((void *)start)) { -struct page *page; - -for (n =0 ; n < page_count; n++) { - page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); -if (!page) -return -ENOMEM ; - -get_page (page); - pages[n] = page; - } - rc = page_count; - }else { -struct kvec *kiov; - - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start))) +return -EINVAL ; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; } + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); +return rc; }
Signature · 1 line
2.37.2
Re: [PATCH 2/4] tee: Remove vmalloc page support
Hi Ira,
Quoted 29 lines · On Sun, Oct 2, 2022 at 2:23 AM <[email protected]> wrote:
From: Ira Weiny <[email protected]>
The kernel pages used by
shm_get_kernel_pages()are allocated usingGFP_KERNELthrough the following call stack:
trusted_instantiate()
trusted_payload_alloc()->GFP_KERNEL<trusted key op>
tee_shm_register_kernel_buf()
register_shm_helper()
shm_get_kernel_pages()Where <trusted key op> is one of:
trusted_key_unseal()
trusted_key_get_random()
trusted_key_seal()Remove the vmalloc page support from
shm_get_kernel_pages(). Replace with a warn on once.Cc Jens Wiklander <[email protected]>Cc Al Viro <[email protected]>Cc "Fabio M. De Francesco" <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Linus Torvalds <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Quoted 5 lines
---
Jens I went with the suggestion from Linus and Christoph and rejected vmalloc addresses. I did not hear back from you regarding Linus' question if the vmalloc page support was required by an up coming patch set or not. So I assumed it was something out of tree.
Yes, that's correctly assumed, sorry for not confirming that earlier.
Thanks,
Jens
Quoted 61 lines
--- drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)drivers/tee/tee_shm.c +12
-25@@ -24,37 +24,25 @@ static void shm_put_kernel_pages(struct page **pages, size_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; -if (is_vmalloc_addr ((void *)start)) { -struct page *page; - -for (n =0 ; n < page_count; n++) { - page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); -if (!page) -return -ENOMEM ; - -get_page (page); - pages[n] = page; - } - rc = page_count; - }else { -struct kvec *kiov; - - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start))) +return -EINVAL ; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; } + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); +return rc; } --2.37.2
Re: [PATCH 2/4] tee: Remove vmalloc page support
In reply to [email protected]+ Phil
Hi Ira,
Quoted 29 lines · On Sun, 2 Oct 2022 at 05:53, <[email protected]> wrote:
From: Ira Weiny <[email protected]>
The kernel pages used by
shm_get_kernel_pages()are allocated usingGFP_KERNELthrough the following call stack:
trusted_instantiate()
trusted_payload_alloc()->GFP_KERNEL<trusted key op>
tee_shm_register_kernel_buf()
register_shm_helper()
shm_get_kernel_pages()Where <trusted key op> is one of:
trusted_key_unseal()
trusted_key_get_random()
trusted_key_seal()Remove the vmalloc page support from
shm_get_kernel_pages(). Replace with a warn on once.Cc Jens Wiklander <[email protected]>Cc Al Viro <[email protected]>Cc "Fabio M. De Francesco" <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Linus Torvalds <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Quoted 5 lines
---
Jens I went with the suggestion from Linus and Christoph and rejected vmalloc addresses. I did not hear back from you regarding Linus' question if the vmalloc page support was required by an up coming patch set or not. So I assumed it was something out of tree.
It looks like I wasn't CC'd to that conversation. IIRC, support for vmalloc addresses was added recently by Phil here [1]. So I would like to give him a chance if he is planning to post a corresponding kernel driver upstream.
-Sumit
Quoted 61 lines
--- drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)drivers/tee/tee_shm.c +12
-25@@ -24,37 +24,25 @@ static void shm_put_kernel_pages(struct page **pages, size_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; -if (is_vmalloc_addr ((void *)start)) { -struct page *page; - -for (n =0 ; n < page_count; n++) { - page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); -if (!page) -return -ENOMEM ; - -get_page (page); - pages[n] = page; - } - rc = page_count; - }else { -struct kvec *kiov; - - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start))) +return -EINVAL ; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; } + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); +return rc; } --2.37.2
RE: [PATCH 2/4] tee: Remove vmalloc page support
Hi Sumit
Thanks for mentioning that, in fact, our product is low memory devices, and continuous pages are extremely valuable. Although our driver is not upstream yet but highly dependent on tee shm vmalloc support,
some scenarios are driver alloc high order pages but system memory is fragmentation so that alloc failed. In this situation, vmalloc support is important and gives flexible usage to user.
-----Original Message-----
From: Sumit Garg <[email protected]>
Sent: Monday, October 3, 2022 2:57 PM
To: [email protected]
Cc: Jens Wiklander <[email protected]>; Andrew Morton <[email protected]>; Al Viro <[email protected]>; Fabio M. De Francesco <[email protected]>; Christoph Hellwig <[email protected]>; Linus Torvalds <[email protected]>; [email protected]; [email protected]; [email protected]; Phil Chang (張世勳) <[email protected]>
Subject: Re: [PATCH 2/4] tee: Remove vmalloc page support
+ Phil
Hi Ira,
Quoted 29 lines · On Sun, 2 Oct 2022 at 05:53, <[email protected]> wrote:
From: Ira Weiny <[email protected]>
The kernel pages used by
shm_get_kernel_pages()are allocated usingGFP_KERNELthrough the following call stack:
trusted_instantiate()
trusted_payload_alloc()->GFP_KERNEL<trusted key op>
tee_shm_register_kernel_buf()
register_shm_helper()
shm_get_kernel_pages()Where <trusted key op> is one of:
trusted_key_unseal()
trusted_key_get_random()
trusted_key_seal()Remove the vmalloc page support from
shm_get_kernel_pages(). Replace with a warn on once.Cc Jens Wiklander <[email protected]>Cc Al Viro <[email protected]>Cc "Fabio M. De Francesco" <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Linus Torvalds <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Quoted 5 lines
---
Jens I went with the suggestion from Linus and Christoph and rejected vmalloc addresses. I did not hear back from you regarding Linus' question if the vmalloc page support was required by an up coming patch set or not. So I assumed it was something out of tree.
It looks like I wasn't CC'd to that conversation. IIRC, support for vmalloc addresses was added recently by Phil here [1]. So I would like to give him a chance if he is planning to post a corresponding kernel driver upstream.
-Sumit
Quoted 60 lines
--- drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)drivers/tee/tee_shm.c index renamed from drivers/tee/tee_shm.c +0
-0
27295bda3e0b..527a6eabc03e100644drivers/tee/tee_shm.c +12
-25@@ -24,37 +24,25 @@ static void shm_put_kernel_pages(struct page **pages, size_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; -if (is_vmalloc_addr ((void *)start)) { -struct page *page; - -for (n =0 ; n < page_count; n++) { - page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); -if (!page) -return -ENOMEM ; - -get_page (page); - pages[n] = page; - } - rc = page_count; - }else { -struct kvec *kiov; - - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start))) +return -EINVAL ; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; } + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); +return rc; } --2.37.2
Re: [PATCH 2/4] tee: Remove vmalloc page support
Hi Phil,
Please don't top-post in the OSS mailing list.
Quoted 5 lines · Phil Chang (張世勳)
Hi Sumit
Thanks for mentioning that, in fact, our product is low memory devices, and continuous pages are extremely valuable. Although our driver is not upstream yet but highly dependent on tee shm vmalloc support,
Sorry but you need to get your driver mainline in order to support vmalloc interface. As otherwise it's a maintenance nightmare to support interfaces in the mainline for out-of-tree drivers.
-Sumit
Quoted 117 lines
some scenarios are driver alloc high order pages but system memory is fragmentation so that alloc failed. In this situation, vmalloc support is important and gives flexible usage to user.
-----Original Message-----
From: Sumit Garg <[email protected]>
Sent: Monday, October 3, 2022 2:57 PM
To: ira.weiny(a)intel.com
Cc: Jens Wiklander <[email protected]>; Andrew Morton <[email protected]>; Al Viro <[email protected]>; Fabio M. De Francesco <[email protected]>; Christoph Hellwig <[email protected]>; Linus Torvalds <[email protected]>; op-tee(a)lists.trustedfirmware.org; linux-kernel(a)vger.kernel.org; linux-mm(a)kvack.org; Phil Chang (張世勳) <[email protected]>
Subject: Re: [PATCH 2/4] tee: Remove vmalloc page support+ Phil
Hi Ira,
Quoted 29 lines · On Sun, 2 Oct 2022 at 05:53, <[email protected]> wrote:
From: Ira Weiny <[email protected]>
The kernel pages used by
shm_get_kernel_pages()are allocated usingGFP_KERNELthrough the following call stack:
trusted_instantiate()
trusted_payload_alloc()->GFP_KERNEL<trusted key op>
tee_shm_register_kernel_buf()
register_shm_helper()
shm_get_kernel_pages()Where <trusted key op> is one of:
trusted_key_unseal()
trusted_key_get_random()
trusted_key_seal()Remove the vmalloc page support from
shm_get_kernel_pages(). Replace with a warn on once.Cc Jens Wiklander <[email protected]>Cc Al Viro <[email protected]>Cc "Fabio M. De Francesco" <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Linus Torvalds <[email protected]>Signed-off-by Ira Weiny <[email protected]>Quoted 5 lines
---
Jens I went with the suggestion from Linus and Christoph and rejected vmalloc addresses. I did not hear back from you regarding Linus' question if the vmalloc page support was required by an up coming patch set or not. So I assumed it was something out of tree.It looks like I wasn't CC'd to that conversation. IIRC, support for vmalloc addresses was added recently by Phil here [1]. So I would like to give him a chance if he is planning to post a corresponding kernel driver upstream.
-Sumit
Quoted 60 lines
--- drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)drivers/tee/tee_shm.c index renamed from drivers/tee/tee_shm.c +0
-0
27295bda3e0b..527a6eabc03e100644drivers/tee/tee_shm.c +12
-25@@ -24,37 +24,25 @@ static void shm_put_kernel_pages(struct page **pages, size_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; -if (is_vmalloc_addr ((void *)start)) { -struct page *page; - -for (n =0 ; n < page_count; n++) { - page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); -if (!page) -return -ENOMEM ; - -get_page (page); - pages[n] = page; - } - rc = page_count; - }else { -struct kvec *kiov; - - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start))) +return -EINVAL ; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; } + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); +return rc; } --2.37.2
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 6 lines · Sumit Garg
Hi Phil,
Please don't top-post in the OSS mailing list.
Quoted 1 line · Phil Chang (張世勳)
Quoted 8 lines
Quoted 4 lines
Hi Sumit
Thanks for mentioning that, in fact, our product is low memory devices, and continuous pages are extremely valuable. Although our driver is not upstream yet but highly dependent on tee shm vmalloc support,
Sorry but you need to get your driver mainline in order to support vmalloc interface. As otherwise it's a maintenance nightmare to support interfaces in the mainline for out-of-tree drivers.
I agree. It sounds like this driver is not going to be submitted any time soon. So I'll respin this series as is. But I do have a couple of other things to deal with first. So if I'm wrong let me know soon.
Thanks,
Ira
Re: [PATCH 2/4] tee: Remove vmalloc page support
In reply to Sumit GargQuoted 3 lines · Sumit Garg
Sorry but you need to get your driver mainline in order to support vmalloc interface.
Actually, I think even then we shouldn't support vmalloc - and register_shm_helper() just needs to be changed to pass in an array of actual page pointers instead.
At that point TEE_SHM_USER_MAPPED should also go away, because then it's the caller that should just do either the user space page pinning, or pass in the kernel page pointer.
JensW, is there some reason that wouldn't work?
Linus
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Sumit Garg
Sorry but you need to get your driver mainline in order to support vmalloc interface.
Actually, I think even then we shouldn't support vmalloc - and
register_shm_helper()just needs to be changed to pass in an array of actual page pointers instead.
register_shm_helper() is an internal function, I suppose it's what's passed to tee_shm_register_user_buf() and especially tee_shm_register_kernel_buf() in this case.
So the gain is that in the kernel it becomes the caller's responsibility to provide the array of page pointers and the TEE subsystem doesn't need to care about what kind of kernel memory it is any longer. Yes, that should avoid eventual complexities with vmalloc() etc.
Quoted 6 lines
At that point
TEE_SHM_USER_MAPPEDshould also go away, because then it's the caller that should just do either the user space page pinning, or pass in the kernel page pointer.JensW, is there some reason that wouldn't work?
We still need to know if it's kernel or user pages in release_registered_pages().
The struct tee_shm:s acquired with syscalls from user space are reference counted. As are the kernel tee_shm:s, but I believe we could separate them to avoid reference counting tee_shm:s used by kernel clients if needed. I'll need to look closer at this if we're going to use that approach.
Without reference counting the caller of tee_shm_free() can be certain that the secure world is done with the memory so we could delegate the kernel pages part of release_registered_pages() to the caller instead.
Cheers,
Jens
Quoted 2 lines
Linus
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 16 lines · Jens Wiklander
Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Sumit Garg
Sorry but you need to get your driver mainline in order to support vmalloc interface.
Actually, I think even then we shouldn't support vmalloc - and
register_shm_helper()just needs to be changed to pass in an array of actual page pointers instead.
register_shm_helper()is an internal function, I suppose it's what's passed totee_shm_register_user_buf()and especiallytee_shm_register_kernel_buf()in this case.
Quoted 5 lines
So the gain is that in the kernel it becomes the caller's responsibility to provide the array of page pointers and the TEE subsystem doesn't need to care about what kind of kernel memory it is any longer. Yes, that should avoid eventual complexities with
vmalloc()etc.
I finally spent some time digging into this again.
Overall I'm not opposed to trying to clean up the code more but I feel like the removal of TEE_SHM_USER_MAPPED is too complex for the main goal; to remove a caller of kmap_to_page().
Not only is that flag used in release_registered_pages() but it is also used in tee_shm_fop_mmap(). I'm not following exactly why. I think this is to allow mmap of the tee_shm's allocated by kernel users? Which I _think_ is orthogonal to the callers of tee_shm_register_kernel_buf()?
Quoted 10 lines
Quoted 7 lines
At that point
TEE_SHM_USER_MAPPEDshould also go away, because then it's the caller that should just do either the user space page pinning, or pass in the kernel page pointer.JensW, is there some reason that wouldn't work?
We still need to know if it's kernel or user pages in
release_registered_pages().
Yes.
As I dug into this it seemed ok to define a tee_shm_kernel_free(). Pull out the allocation of the page array from register_shm_helper() such that it could be handled by tee_shm_register_kernel_buf() and this new tee_shm_kernel_free().
This seems reasonable because the only callers of tee_shm_register_kernel_buf() are in trusted_tee.c and they all call tee_shm_free() on the registered memory prior to returning.
Other callers[*] of tee_shm_free() obtained tee_shm from tee_shm_alloc_kernel_buf() which AFAICT avoids all this nonsense.
[*] such as .../drivers/firmware/broadcom/tee_bnxt_fw.c.
Quoted 11 lines
The struct tee_shm:s acquired with syscalls from user space are reference counted. As are the kernel tee_shm:s, but I believe we could separate them to avoid reference counting tee_shm:s used by kernel clients if needed. I'll need to look closer at this if we're going to use that approach.
Without reference counting the caller of
tee_shm_free()can be certain that the secure world is done with the memory so we could delegate the kernel pages part ofrelease_registered_pages()to the caller instead.
I'm not sure I follow you here. Would this be along the lines of creating a tee_shm_free_kernel() to be used in trusted_tee.c for those specific kernel data?
Overall I feel like submitting this series again with Christoph and Al's comments addressed is the best way forward to get rid of kmap_to_page(). I would really like to get moving on that to avoid any further issues with the kmap conversions.
But if folks feel strongly enough about removing that flag I can certainly try to do so.
Ira
Quoted 5 lines
Cheers,
JensQuoted 2 lines
Linus
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 26 lines · Ira Weiny
Quoted 16 lines · Jens Wiklander
Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Sumit Garg
Sorry but you need to get your driver mainline in order to support vmalloc interface.
Actually, I think even then we shouldn't support vmalloc - and
register_shm_helper()just needs to be changed to pass in an array of actual page pointers instead.
register_shm_helper()is an internal function, I suppose it's what's passed totee_shm_register_user_buf()and especiallytee_shm_register_kernel_buf()in this case.Quoted 5 lines
So the gain is that in the kernel it becomes the caller's responsibility to provide the array of page pointers and the TEE subsystem doesn't need to care about what kind of kernel memory it is any longer. Yes, that should avoid eventual complexities with
vmalloc()etc.I finally spent some time digging into this again.
Quoted 7 lines
Overall I'm not opposed to trying to clean up the code more but I feel like the removal of
TEE_SHM_USER_MAPPEDis too complex for the main goal; to remove a caller ofkmap_to_page().Not only is that flag used in
release_registered_pages()but it is also used intee_shm_fop_mmap(). I'm not following exactly why. I think this is to allow mmap of the tee_shm's allocated by kernel users?
No, its rather to allow mmap of tee_shm allocated via tee_shm_alloc_user_buf(). Have a look at its user-space usage here [1]. So overall I agree here that we can't get rid of TEE_SHM_USER_MAPPED completely as it has a valid mmap use-case.
[1] https://github.com/OP-TEE/optee_client/blob/master/libteec/src/tee_client_api.c#L907
Quoted 11 lines
Which I _think_ is
orthogonal to the callers oftee_shm_register_kernel_buf()?Quoted 8 lines
Quoted 7 lines
At that point
TEE_SHM_USER_MAPPEDshould also go away, because then it's the caller that should just do either the user space page pinning, or pass in the kernel page pointer.JensW, is there some reason that wouldn't work?
Quoted 9 lines
Quoted 2 lines
We still need to know if it's kernel or user pages in
release_registered_pages().Yes.
As I dug into this it seemed ok to define a
tee_shm_kernel_free(). Pull out the allocation of the page array fromregister_shm_helper()such that it could be handled bytee_shm_register_kernel_buf()and this newtee_shm_kernel_free().
+1
Quoted 16 lines
This seems reasonable because the only callers of
tee_shm_register_kernel_buf()are intrusted_tee.cand they all calltee_shm_free()on the registered memory prior to returning.Other callers[*] of
tee_shm_free()obtainedtee_shmfromtee_shm_alloc_kernel_buf()which AFAICT avoids all this nonsense.[*] such as
.../drivers/firmware/broadcom/tee_bnxt_fw.c.Quoted 7 lines
The struct tee_shm:s acquired with syscalls from user space are reference counted. As are the kernel tee_shm:s, but I believe we could separate them to avoid reference counting tee_shm:s used by kernel clients if needed. I'll need to look closer at this if we're going to use that approach.
Quoted 8 lines
Quoted 4 lines
Without reference counting the caller of
tee_shm_free()can be certain that the secure world is done with the memory so we could delegate the kernel pages part ofrelease_registered_pages()to the caller instead.I'm not sure I follow you here. Would this be along the lines of creating a
tee_shm_free_kernel()to be used intrusted_tee.cfor those specific kernel data?
I can't find a reason/use-case for the TEE subsystem to keep a refcount of memory registered by other kernel drivers like trusted_tee.c. So yes I think it should be safe to directly free that shm via tee_shm_free_kernel(). Also with that we can simplify shm registration by kernel clients via directly passing page pointers to tee_shm_register_kernel_buf() (I would rather rename this API as tee_shm_register_kernel_pages()).
-Sumit
Quoted 16 lines
Overall I feel like submitting this series again with Christoph and Al's comments addressed is the best way forward to get rid of
kmap_to_page(). I would really like to get moving on that to avoid any further issues with the kmap conversions.But if folks feel strongly enough about removing that flag I can certainly try to do so.
Ira
Quoted 5 lines
Cheers,
JensQuoted 2 lines
Linus
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 91 lines · Sumit Garg
Quoted 26 lines · Ira Weiny
Quoted 16 lines · Jens Wiklander
Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Sumit Garg
Sorry but you need to get your driver mainline in order to support vmalloc interface.
Actually, I think even then we shouldn't support vmalloc - and
register_shm_helper()just needs to be changed to pass in an array of actual page pointers instead.
register_shm_helper()is an internal function, I suppose it's what's passed totee_shm_register_user_buf()and especiallytee_shm_register_kernel_buf()in this case.Quoted 5 lines
So the gain is that in the kernel it becomes the caller's responsibility to provide the array of page pointers and the TEE subsystem doesn't need to care about what kind of kernel memory it is any longer. Yes, that should avoid eventual complexities with
vmalloc()etc.I finally spent some time digging into this again.
Quoted 7 lines
Overall I'm not opposed to trying to clean up the code more but I feel like the removal of
TEE_SHM_USER_MAPPEDis too complex for the main goal; to remove a caller ofkmap_to_page().Not only is that flag used in
release_registered_pages()but it is also used intee_shm_fop_mmap(). I'm not following exactly why. I think this is to allow mmap of the tee_shm's allocated by kernel users?No, its rather to allow mmap of
tee_shmallocated viatee_shm_alloc_user_buf(). Have a look at its user-space usage here [1]. So overall I agree here that we can't get rid ofTEE_SHM_USER_MAPPEDcompletely as it has a valid mmap use-case.[1] https://github.com/OP-TEE/optee_client/blob/master/libteec/src/tee_client_api.c#L907
Quoted 11 lines
Which I _think_ is
orthogonal to the callers oftee_shm_register_kernel_buf()?Quoted 8 lines
Quoted 7 lines
At that point
TEE_SHM_USER_MAPPEDshould also go away, because then it's the caller that should just do either the user space page pinning, or pass in the kernel page pointer.JensW, is there some reason that wouldn't work?
Quoted 9 lines
Quoted 2 lines
We still need to know if it's kernel or user pages in
release_registered_pages().Yes.
As I dug into this it seemed ok to define a
tee_shm_kernel_free(). Pull out the allocation of the page array fromregister_shm_helper()such that it could be handled bytee_shm_register_kernel_buf()and this newtee_shm_kernel_free().+1
Quoted 16 lines
This seems reasonable because the only callers of
tee_shm_register_kernel_buf()are intrusted_tee.cand they all calltee_shm_free()on the registered memory prior to returning.Other callers[*] of
tee_shm_free()obtainedtee_shmfromtee_shm_alloc_kernel_buf()which AFAICT avoids all this nonsense.[*] such as
.../drivers/firmware/broadcom/tee_bnxt_fw.c.Quoted 7 lines
The struct tee_shm:s acquired with syscalls from user space are reference counted. As are the kernel tee_shm:s, but I believe we could separate them to avoid reference counting tee_shm:s used by kernel clients if needed. I'll need to look closer at this if we're going to use that approach.
Quoted 8 lines
Quoted 4 lines
Without reference counting the caller of
tee_shm_free()can be certain that the secure world is done with the memory so we could delegate the kernel pages part ofrelease_registered_pages()to the caller instead.I'm not sure I follow you here. Would this be along the lines of creating a
tee_shm_free_kernel()to be used intrusted_tee.cfor those specific kernel data?
Quoted 7 lines
I can't find a reason/use-case for the TEE subsystem to keep a refcount of memory registered by other kernel drivers like
trusted_tee.c. So yes I think it should be safe to directly free that shm viatee_shm_free_kernel(). Also with that we can simplify shm registration by kernel clients via directly passing page pointers totee_shm_register_kernel_buf()(I would rather rename this API astee_shm_register_kernel_pages()).
Okay, so I will take up this work and get rid of kmap_to_page invocation from the TEE subsystem.
Ira,
You can then rebase your patchset over my work.
-Sumit
Quoted 17 lines
Quoted 17 lines
Overall I feel like submitting this series again with Christoph and Al's comments addressed is the best way forward to get rid of
kmap_to_page(). I would really like to get moving on that to avoid any further issues with the kmap conversions.But if folks feel strongly enough about removing that flag I can certainly try to do so.
Ira
Quoted 5 lines
Cheers,
JensQuoted 2 lines
Linus
Re: [PATCH 2/4] tee: Remove vmalloc page support
In reply to Ira WeinyQuoted 4 lines · Ira Weiny
Overall I feel like submitting this series again with Christoph and Al's comments addressed is the best way forward to get rid of
kmap_to_page(). I would really like to get moving on that to avoid any further issues with the kmap conversions.
Yes. While the flag is really odd, killing kmap_to_page should be the priority.
Re: [PATCH 2/4] tee: Remove vmalloc page support
In reply to Linus TorvaldsQuoted 9 lines · Linus Torvalds
Actually, I think even then we shouldn't support vmalloc - and
register_shm_helper()just needs to be changed to pass in an array of actual page pointers instead.At that point
TEE_SHM_USER_MAPPEDshould also go away, because then it's the caller that should just do either the user space page pinning, or pass in the kernel page pointer.JensW, is there some reason that wouldn't work?
I suspect the best long term option would be to just pass an iov_iter..
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 2 lines · Christoph Hellwig
I suspect the best long term option would be to just pass an
iov_iter..
Hmm. Yeah, that sounds like a workable model, and solves the problem JensW pointed out with my simplistic "just pass a page array" approach where you also need to keep track of how to release things.
Linus
Re: [PATCH 2/4] tee: Remove vmalloc page support
Quoted 7 lines · Linus Torvalds
Quoted 2 lines · Christoph Hellwig
I suspect the best long term option would be to just pass an
iov_iter..Hmm. Yeah, that sounds like a workable model, and solves the problem JensW pointed out with my simplistic "just pass a page array" approach where you also need to keep track of how to release things.
Except that then you need to get iov_iter_get_pages analogue that would work for ITER_KVEC, which is exact same problem right back.
PATCH 3/4 tee: Remove call to get_kernel_pages()
In reply to [email protected]From: Ira Weiny <[email protected]>
The kernel pages used by shm_get_kernel_pages() are allocated using GFP_KERNEL through the following call stack:
trusted_instantiate()
trusted_payload_alloc() -> GFP_KERNEL <trusted key op> tee_shm_register_kernel_buf() register_shm_helper() shm_get_kernel_pages()
Where <trusted key op> is one of:
trusted_key_unseal()
trusted_key_get_random()
trusted_key_seal()
Because the pages can't be from highmem get_kernel_pages() boils down to a get_page() call.
Remove the get_kernel_pages() call and open code the get_page().
In case a kmap page does slip through warn on once for a kmap address.
--- drivers/tee/tee_shm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/tee/tee_shm.c +6 -5
@@ -11,6 +11,7 @@#include <linux/tee_drv.h> #include <linux/uaccess.h> #include <linux/uio.h> +#include <linux/highmem.h> #include "tee_private.h" static void shm_put_kernel_pages (struct page **pages,size_t page_count)
@@ -26,9 +27,9 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count, {struct kvec *kiov;size_t n; -int rc; -if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start))) +if (WARN_ON_ONCE (is_vmalloc_addr ((void *)start) || +is_kmap_addr ((void *)start)))return -EINVAL ; kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL );
@@ -38,12 +39,12 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count,for (n =0 ; n < page_count; n++) { kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); kiov[n].iov_len =PAGE_SIZE ; + pages[n] =virt_to_page (kiov[n].iov_base); +get_page (pages[n]); } - - rc =get_kernel_pages (kiov, page_count,0 , pages);kfree (kiov); -return rc; +return page_count; }static void release_registered_pages (struct tee_shm *shm)
Signature · 1 line
2.37.2
Re: [PATCH 3/4] tee: Remove call to get_kernel_pages()
drivers/tee/tee_shm.c static int shm_get_kernel_pages(unsigned long start, size_t page_count, · line 45
Quoted 11 lines · ira.weiny(a)intel.com
drivers/tee/tee_shm.c +2
-2kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL );@@ -38,12 +39,12 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count,for (n =0 ; n < page_count; n++) { kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); kiov[n].iov_len =PAGE_SIZE ; + pages[n] =virt_to_page (kiov[n].iov_base); +get_page (pages[n]); } - - rc =get_kernel_pages (kiov, page_count,0 , pages);kfree (kiov);
IDGI. The only thing in kiov[...] you are every reading is ->iov_base. And you fetch it once, right after the assignment.
Why bother with allocating the array at all?
pages[n] = virt_to_page((void *)start + n * PAGE_SIZE);
would do just as well, not to mention the fact that since you reject vmalloc and kmap, you might simply do
page = virt_to_page(start); for (int n = 0; n < page_count; n++) get_page(pages[n] = page + n);
instead...
Re: [PATCH 3/4] tee: Remove call to get_kernel_pages()
Quoted 16 lines · Al Viro
drivers/tee/tee_shm.c static int shm_get_kernel_pages(unsigned long start, size_t page_count, · line 45
Quoted 11 lines · ira.weiny(a)intel.com
drivers/tee/tee_shm.c +2
-2kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL );@@ -38,12 +39,12 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count,for (n =0 ; n < page_count; n++) { kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); kiov[n].iov_len =PAGE_SIZE ; + pages[n] =virt_to_page (kiov[n].iov_base); +get_page (pages[n]); } - - rc =get_kernel_pages (kiov, page_count,0 , pages);kfree (kiov);IDGI. The only thing in kiov[...] you are every reading is ->iov_base. And you fetch it once, right after the assignment.
:-( Good point. Thanks for catching that. I was too focused on just replacing get_kernel_pages() with get_page() and I should have refactored more.
Quoted 9 lines
Why bother with allocating the array at all?
pages[n] = virt_to_page((void *)start + n * PAGE_SIZE);would do just as well, not to mention the fact that since you reject vmalloc and kmap, you might simply do
page = virt_to_page(start); for (int n = 0; n < page_count; n++) get_page(pages[n] = page + n);
I think I'd avoid the assignment in the parameter as I would miss that if I came back and looked at this code later.
I'll get rid of the kiov in v2.
Sorry for not cleaning it up more and thanks for the review!
Ira
Re: [PATCH 3/4] tee: Remove call to get_kernel_pages()
In reply to Al ViroQuoted 2 lines · Al Viro
IDGI. The only thing in kiov[...] you are every reading is ->iov_base. And you fetch it once, right after the assignment.
... and that's exactly what I pointed out on the last version of the patch ...
Re: [PATCH 3/4] tee: Remove call to get_kernel_pages()
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Al Viro
IDGI. The only thing in kiov[...] you are every reading is ->iov_base. And you fetch it once, right after the assignment.
... and that's exactly what I pointed out on the last version of the patch ...
Apologies I guess I missed it.
Ira
PATCH 4/4 mm: Remove get_kernel_pages()
In reply to [email protected]From: Ira Weiny <[email protected]>
The only caller to get_kernel_pages() [shm_get_kernel_pages()] has been updated to not need it.
Remove get_kernel_pages().
--- include/linux/mm.h | 2 -- mm/swap.c | 30 ------------------------------ 2 files changed, 32 deletions(-)
include/linux/mm.h +0 -2
@@ -1969,8 +1969,6 @@ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, struct task_struct *task, bool bypass_rlim);struct kvec ; -int get_kernel_pages (const struct kvec *iov,int nr_pages,int write, -struct page **pages);struct page *get_dump_page (unsigned long addr);bool folio_mark_dirty (struct folio *folio);
mm/swap.c +0 -30
@@ -157,36 +157,6 @@ void put_pages_list(struct list_head *pages) }EXPORT_SYMBOL (put_pages_list); -/* -* get_kernel_pages() - pin kernel pages in memory -* @kiov: An array of struct kvec structures -* @nr_segs: number of segments to pin -* @write: pinning for read/write, currently ignored -* @pages: array that receives pointers to the pages pinned. -* Should be at least nr_segs long. -* -* Returns number of pages pinned. This may be fewer than the number requested. -* If nr_segs is 0 or negative, returns 0. If no pages were pinned, returns 0. -* Each page returned must be released with a put_page() call when it is -* finished with. -*/ -int get_kernel_pages (const struct kvec *kiov,int nr_segs,int write, -struct page **pages) -{ -int seg; - -for (seg =0 ; seg < nr_segs; seg++) { -if (WARN_ON (kiov[seg].iov_len !=PAGE_SIZE )) -return seg; - - pages[seg] =kmap_to_page (kiov[seg].iov_base); -get_page (pages[seg]); - } - -return seg; -} -EXPORT_SYMBOL_GPL (get_kernel_pages); -typedef void (*move_fn_t )(struct lruvec *lruvec,struct folio *folio);static void lru_add_fn (struct lruvec *lruvec,struct folio *folio)
Signature · 1 line
2.37.2
Re: [PATCH 4/4] mm: Remove get_kernel_pages()
Quoted 13 lines · ira.weiny(a)intel.com
From: Ira Weiny <[email protected]>
The only caller to
get_kernel_pages()[shm_get_kernel_pages()] has been updated to not need it.Remove
get_kernel_pages().Cc Mel Gorman <[email protected]>Cc Al Viro <[email protected]>Cc "Fabio M. De Francesco" <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Andrew Morton <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Quoted 5 lines
--- include/linux/mm.h | 2 -- mm/swap.c | 30 ------------------------------ 2 files changed, 32 deletions(-)
Good to see this removed (including the EXPORT), even if the functionality still remains in a less obvious form, over in shm.
The fewer "all your page are pinned" calls we need, the simpler things get. :)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 54 lines
include/linux/mm.h +0
-2@@ -1969,8 +1969,6 @@ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, struct task_struct *task, bool bypass_rlim);struct kvec ; -int get_kernel_pages (const struct kvec *iov,int nr_pages,int write, -struct page **pages);struct page *get_dump_page (unsigned long addr);bool folio_mark_dirty (struct folio *folio);mm/swap.c +0
-30@@ -157,36 +157,6 @@ void put_pages_list(struct list_head *pages) }EXPORT_SYMBOL (put_pages_list); -/* -* get_kernel_pages() - pin kernel pages in memory -* @kiov: An array of struct kvec structures -* @nr_segs: number of segments to pin -* @write: pinning for read/write, currently ignored -* @pages: array that receives pointers to the pages pinned. -* Should be at least nr_segs long. -* -* Returns number of pages pinned. This may be fewer than the number requested. -* If nr_segs is 0 or negative, returns 0. If no pages were pinned, returns 0. -* Each page returned must be released with a put_page() call when it is -* finished with. -*/ -int get_kernel_pages (const struct kvec *kiov,int nr_segs,int write, -struct page **pages) -{ -int seg; - -for (seg =0 ; seg < nr_segs; seg++) { -if (WARN_ON (kiov[seg].iov_len !=PAGE_SIZE )) -return seg; - - pages[seg] =kmap_to_page (kiov[seg].iov_base); -get_page (pages[seg]); - } - -return seg; -} -EXPORT_SYMBOL_GPL (get_kernel_pages); -typedef void (*move_fn_t )(struct lruvec *lruvec,struct folio *folio);static void lru_add_fn (struct lruvec *lruvec,struct folio *folio)
Hi Ira,
Quoted 7 lines · On Sun, 2 Oct 2022 at 05:53, <[email protected]> wrote:
From: Ira Weiny <[email protected]>
get_kernel_pages()only had one caller [shm_get_kernel_pages()] which did not need the functionality it provided. Furthermore, it calledkmap_to_page()which we are looking to removed.
Quoted 6 lines
Alter
shm_get_kernel_pages()to no longer callget_kernel_pages()and removeget_kernel_pages(). Along the way it was noted thatshm_get_kernel_pages()does not have any need to support vmalloc'ed addresses either. Remove that functionality to clean up the logic.This series also fixes and uses
is_kmap_addr().
From the above description, I am failing to see the motivation behind this change. Can you elaborate here?
Also, since you are targeting to remove kmap_to_page(), is there any alternative way to support highmem for future TEE bus drivers? As I can see higmem being enabled for multiple Arm defconfigs [1] which can also support TEE (an example which already does it:arch/arm/configs/imx_v6_v7_defconfig).
[1] git grep CONFIG_HIGHMEM arch/arm/
-Sumit
Quoted 18 lines
Ira Weiny (4):
highmem: Enhanceis_kmap_addr()to checkkmap_local_page()mappings
tee: Remove vmalloc page support
tee: Remove call toget_kernel_pages()
mm: Removeget_kernel_pages()drivers/tee/tee_shm.c | 41 ++++++++++++-------------------- include/linux/highmem-internal.h | 5 +++- include/linux/mm.h | 2 -- mm/swap.c | 30 ----------------------- 4 files changed, 19 insertions(+), 59 deletions(-)base-commit:
274d7803837da78dfc911bcda0d593412676fc20--
2.37.2
Quoted 15 lines · Sumit Garg
Hi Ira,
Quoted 12 lines · On Sun, 2 Oct 2022 at 05:53, <[email protected]> wrote:
From: Ira Weiny <[email protected]>
get_kernel_pages()only had one caller [shm_get_kernel_pages()] which did not need the functionality it provided. Furthermore, it calledkmap_to_page()which we are looking to removed.Alter
shm_get_kernel_pages()to no longer callget_kernel_pages()and removeget_kernel_pages(). Along the way it was noted thatshm_get_kernel_pages()does not have any need to support vmalloc'ed addresses either. Remove that functionality to clean up the logic.
Quoted 4 lines
Quoted 1 line
This series also fixes and uses
is_kmap_addr().From the above description, I am failing to see the motivation behind this change. Can you elaborate here?
Al Viro found[1] that kmap_to_page() is broken. But not only was it broken but it presents confusion over how highmem should be used because kmap() and friends should not be used for 'long term' mappings.
[1] https://lore.kernel.org/lkml/YzSSl1ItVlARDvG3(a)ZenIV
Quoted 6 lines
Also, since you are targeting to remove
kmap_to_page(), is there any alternative way to support highmem for future TEE bus drivers? As I can see higmem being enabled for multiple Arm defconfigs [1] which can also support TEE (an example which already does it:arch/arm/configs/imx_v6_v7_defconfig).
With TEE how are the highmem pages used? Right now the code does not seem to use any user pages. So I can't really say how this should work. Why does the kernel need a mapping of those pages?
Ira
Quoted 23 lines
[1] git grep
CONFIG_HIGHMEMarch/arm/-Sumit
Quoted 18 lines
Ira Weiny (4):
highmem: Enhanceis_kmap_addr()to checkkmap_local_page()mappings
tee: Remove vmalloc page support
tee: Remove call toget_kernel_pages()
mm: Removeget_kernel_pages()drivers/tee/tee_shm.c | 41 ++++++++++++-------------------- include/linux/highmem-internal.h | 5 +++- include/linux/mm.h | 2 -- mm/swap.c | 30 ----------------------- 4 files changed, 19 insertions(+), 59 deletions(-)base-commit:
274d7803837da78dfc911bcda0d593412676fc20--
2.37.2
Quoted 19 lines · Ira Weiny
Quoted 17 lines · Sumit Garg
Hi Ira,
Quoted 13 lines · On Sun, 2 Oct 2022 at 05:53, <[email protected]> wrote:
From: Ira Weiny <[email protected]>
get_kernel_pages()only had one caller [shm_get_kernel_pages()] which did not need the functionality it provided. Furthermore, it calledkmap_to_page()which we are looking to removed.Alter
shm_get_kernel_pages()to no longer callget_kernel_pages()and removeget_kernel_pages(). Along the way it was noted thatshm_get_kernel_pages()does not have any need to support vmalloc'ed addresses either. Remove that functionality to clean up the logic.This series also fixes and uses
is_kmap_addr().
Quoted 9 lines
Quoted 2 lines
From the above description, I am failing to see the motivation behind this change. Can you elaborate here?
Al Viro found[1] that
kmap_to_page()is broken. But not only was it broken but it presents confusion over how highmem should be used becausekmap()and friends should not be used for 'long term' mappings.
Thanks for the background info. This should be part of the cover letter.
Quoted 10 lines
Quoted 6 lines
Also, since you are targeting to remove
kmap_to_page(), is there any alternative way to support highmem for future TEE bus drivers? As I can see higmem being enabled for multiple Arm defconfigs [1] which can also support TEE (an example which already does it:arch/arm/configs/imx_v6_v7_defconfig).With TEE how are the highmem pages used? Right now the code does not seem to use any user pages. So I can't really say how this should work. Why does the kernel need a mapping of those pages?
Fair enough, I don't have a real kernel driver use-case for highmem which is required to be registered with TEE.
-Sumit
Quoted 26 lines
Ira
Quoted 23 lines
[1] git grep
CONFIG_HIGHMEMarch/arm/-Sumit
Quoted 18 lines
Ira Weiny (4):
highmem: Enhanceis_kmap_addr()to checkkmap_local_page()mappings
tee: Remove vmalloc page support
tee: Remove call toget_kernel_pages()
mm: Removeget_kernel_pages()drivers/tee/tee_shm.c | 41 ++++++++++++-------------------- include/linux/highmem-internal.h | 5 +++- include/linux/mm.h | 2 -- mm/swap.c | 30 ----------------------- 4 files changed, 19 insertions(+), 59 deletions(-)base-commit:
274d7803837da78dfc911bcda0d593412676fc20--
2.37.2