tomoyo: Convert get_user_pages*() to pin_user_pages*()
Subsystems (2)
PATCH 1/2 tomoyo: Convert get_user_pages*() to pin_user_pages*()
In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1].
[1] Documentation/core-api/pin_user_pages.rst
[2] "Explicit pinning of user-space pages":
https://lwn.net/Articles/807108/
--- security/tomoyo/domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/tomoyo/domain.c +2 -2
@@ -914,7 +914,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,* (represented by bprm). 'current' is the process doing * the execve(). */ -if (get_user_pages_remote (bprm->mm, pos,1 , +if (pin_user_pages_remote (bprm->mm, pos,1 ,FOLL_FORCE , &page,NULL ,NULL ) <=0 )return false;#else
@@ -936,7 +936,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos, }/* Same with put_arg_page(page) in fs/exec.c */ #ifdef CONFIG_MMU -put_page (page); +unpin_user_page (page);#endif return true; }
Signature · 1 line
1.9.1
PATCH 2/2 tomoyo: Fixed typo in documentation
Fixed typo s/Poiner/Pointer
--- security/tomoyo/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/tomoyo/domain.c +1 -1
@@ -891,7 +891,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)* * @bprm: Pointer to "struct linux_binprm". * @pos: Location to dump. -* @dump: Poiner to "struct tomoyo_page_dump". +* @dump: Pointer to "struct tomoyo_page_dump". * * Returns true on success, false otherwise. */
Signature · 1 line
1.9.1
Re: [PATCH 2/2] tomoyo: Fixed typo in documentation
Quoted 14 lines · Souptick Joarder
Fixed typo s/Poiner/Pointer
Fixes 5b636857fee6 ("TOMOYO: Allow using argv[]/envp[] of execve() as conditions.")Signed-off-by Souptick Joarder <[email protected]>Cc John Hubbard <[email protected]>--- security/tomoyo/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/tomoyo/domain.c +0
-0
security/tomoyo/domain.c int tomoyo_find_next_domain(struct linux_binprm *bprm) · line 894
Quoted 5 lines
security/tomoyo/domain.c +1
-1@@ -891,7 +891,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)* * @bprm: Pointer to "struct linux_binprm". * @pos: Location to dump. -* @dump: Poiner to "struct tomoyo_page_dump". +* @dump: Pointer to "struct tomoyo_page_dump".
Not worth a separate patch, especially since the original comment is merely copying the C sources, and as such, does not add any value.
I'd either a) craft a new documentation line that adds some value, or b) just merge this patch into the previous one, and make a note in the commit description to the effect that you've included a trivial typo fix as long as you're there.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 4 lines
security/tomoyo/domain.c +0
-0* * Returns true on success, false otherwise. */
Re: [PATCH 2/2] tomoyo: Fixed typo in documentation
Quoted 25 lines · John Hubbard
Quoted 14 lines · Souptick Joarder
Fixed typo s/Poiner/Pointer
Fixes 5b636857fee6 ("TOMOYO: Allow using argv[]/envp[] of execve() as conditions.")Signed-off-by Souptick Joarder <[email protected]>Cc John Hubbard <[email protected]>--- security/tomoyo/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/tomoyo/domain.c +0
-0security/tomoyo/domain.c int tomoyo_find_next_domain(struct linux_binprm *bprm) · line 894
Quoted 5 lines
security/tomoyo/domain.c +1
-1@@ -891,7 +891,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)* * @bprm: Pointer to "struct linux_binprm". * @pos: Location to dump. -* @dump: Poiner to "struct tomoyo_page_dump". +* @dump: Pointer to "struct tomoyo_page_dump". Not worth a separate patch, especially since the original comment is merely copying the C sources, and as such, does not add any value.
Quoted 5 lines
I'd either a) craft a new documentation line that adds some value, or b) just merge this patch into the previous one, and make a note in the commit description to the effect that you've included a trivial typo fix as long as you're there.
John, as patch[1/2] is dropped, can we take this patch forward with some more updates in documentations ?
Re: [PATCH 2/2] tomoyo: Fixed typo in documentation
Quoted 26 lines · Souptick Joarder
Quoted 25 lines · John Hubbard
Quoted 14 lines · Souptick Joarder
Fixed typo s/Poiner/Pointer
Fixes 5b636857fee6 ("TOMOYO: Allow using argv[]/envp[] of execve() as conditions.")Signed-off-by Souptick Joarder <[email protected]>Cc John Hubbard <[email protected]>--- security/tomoyo/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/tomoyo/domain.c +0
-0security/tomoyo/domain.c int tomoyo_find_next_domain(struct linux_binprm *bprm) · line 894
Quoted 5 lines
security/tomoyo/domain.c +1
-1@@ -891,7 +891,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)* * @bprm: Pointer to "struct linux_binprm". * @pos: Location to dump. -* @dump: Poiner to "struct tomoyo_page_dump". +* @dump: Pointer to "struct tomoyo_page_dump". Not worth a separate patch, especially since the original comment is merely copying the C sources, and as such, does not add any value.
Quoted 9 lines
Quoted 5 lines
I'd either a) craft a new documentation line that adds some value, or b) just merge this patch into the previous one, and make a note in the commit description to the effect that you've included a trivial typo fix as long as you're there.
John, as patch[1/2] is dropped, can we take this patch forward with some more updates in documentations ?
That's really up to the folks who work on this code. Personally I would rarely post a patch *just* for this, but on the other hand it is a correction. Either way is fine with me of course.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Tetsuo Handa
maintainerRe: [PATCH 2/2] tomoyo: Fixed typo in documentation
Quoted 8 lines · John Hubbard
Quoted 3 lines · Souptick Joarder
John, as patch[1/2] is dropped, can we take this patch forward with some more updates in documentations ?
That's really up to the folks who work on this code. Personally I would rarely post a patch *just* for this, but on the other hand it is a correction. Either way is fine with me of course.
Xiaoming Ni has posted a patch for fixing spelling errors in security/ directory at https://lkml.kernel.org/r/[email protected] .
James, can we apply that patch? Or, should we split that patch into each subsystem?
James Morris
maintainerRe: [PATCH 2/2] tomoyo: Fixed typo in documentation
Quoted 6 lines · Tetsuo Handa
Quoted 5 lines · John Hubbard
Quoted 3 lines · Souptick Joarder
John, as patch[1/2] is dropped, can we take this patch forward with some more updates in documentations ?
Quoted 9 lines
Quoted 3 lines
That's really up to the folks who work on this code. Personally I would rarely post a patch *just* for this, but on the other hand it is a correction. Either way is fine with me of course.
Xiaoming Ni has posted a patch for fixing spelling errors in
security/directory at https://lkml.kernel.org/r/[email protected] .James, can we apply that patch? Or, should we split that patch into each subsystem?
Probably easiest to go via my tree, the author should resend and include me on the To: line.
Signature · 2 lines
James Morris <[email protected]>
Quoted 3 lines · Souptick Joarder
In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1].
It turns out that Case 5 can be implemented via a better pattern, as long as we're just dealing with a page at a time, briefly:
lock_page()
write to page's dataunlock_page()
...which neatly synchronizes with writeback and other fs activities.
I was going to track down the Case 5's and do that [1].
+CC Jan and Matthew, to keep us on the straight and narrow, just in case I'm misunderstanding something.
[1] https://lore.kernel.org/r/[email protected]
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 35 lines
[1]
Documentation/core-api/pin_user_pages.rst[2] "Explicit pinning of user-space pages":
https://lwn.net/Articles/807108/Signed-off-by Souptick Joarder <[email protected]>Cc John Hubbard <[email protected]>--- security/tomoyo/domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)security/tomoyo/domain.c +2
-2@@ -914,7 +914,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,* (represented by bprm). 'current' is the process doing * the execve(). */ -if (get_user_pages_remote (bprm->mm, pos,1 , +if (pin_user_pages_remote (bprm->mm, pos,1 ,FOLL_FORCE , &page,NULL ,NULL ) <=0 )return false;#else @@ -936,7 +936,7 @@ bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos, }/* Same with put_arg_page(page) in fs/exec.c */ #ifdef CONFIG_MMU -put_page (page); +unpin_user_page (page);#endif return true; }
Quoted 5 lines · John Hubbard
Quoted 3 lines · Souptick Joarder
In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1].
Quoted 8 lines
It turns out that Case 5 can be implemented via a better pattern, as long as we're just dealing with a page at a time, briefly:
lock_page()
write to page's dataunlock_page()...which neatly synchronizes with writeback and other fs activities.
Ahem, I left out a key step: set_page_dirty()!
lock_page()
write to page's dataset_page_dirty()unlock_page()
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Tetsuo Handa
maintainerQuoted 13 lines · John Hubbard
Quoted 12 lines · John Hubbard
Quoted 3 lines · Souptick Joarder
In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1].
It turns out that Case 5 can be implemented via a better pattern, as long as we're just dealing with a page at a time, briefly:
lock_page()
write to page's dataunlock_page()
Quoted 9 lines
Quoted 1 line
...which neatly synchronizes with writeback and other fs activities.
Ahem, I left out a key step:
set_page_dirty()!
lock_page()
write to page's dataset_page_dirty()unlock_page()
Excuse me, but Documentation/core-api/pin_user_pages.rst says "CASE 5: Pinning in order to _write_ to the data within the page" while tomoyo_dump_page() is for "_read_ the data within the page". Do we want to convert to pin_user_pages_remote() or lock_page() ?
Quoted 24 lines · Tetsuo Handa
Quoted 13 lines · John Hubbard
Quoted 12 lines · John Hubbard
Quoted 3 lines · Souptick Joarder
In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1].
It turns out that Case 5 can be implemented via a better pattern, as long as we're just dealing with a page at a time, briefly:
lock_page()
write to page's dataunlock_page()Quoted 9 lines
Quoted 1 line
...which neatly synchronizes with writeback and other fs activities.
Ahem, I left out a key step:
set_page_dirty()!
lock_page()
write to page's dataset_page_dirty()unlock_page()
Quoted 5 lines
Excuse me, but
Documentation/core-api/pin_user_pages.rstsays "CASE 5: Pinning in order to _write_ to the data within the page" whiletomoyo_dump_page()is for "_read_ the data within the page". Do we want to convert topin_user_pages_remote()orlock_page()?
Sorry, I missed the direction here, was too focused on the Case 5 aspect. Yes. Case 5 (which, again, I think we're about to re-document) is only about *writing* to data within the page.
So in this case, where it is just reading from the page, I think it's already from a gup vs pup point of view.
btw, it's not clear to me whether the current code is susceptible to any sort of problem involving something writing to the page while it is being dumped (I am curious). But changing from gup to pup wouldn't fix that, if it were a problem. It a separate question from this patch.
(Souptick, if you're interested, the Case 5 documentation change and callsite retrofit is all yours if you want it. Otherwise it's on my list.)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Tetsuo Handa
maintainerQuoted 10 lines · John Hubbard
Quoted 5 lines
Excuse me, but
Documentation/core-api/pin_user_pages.rstsays "CASE 5: Pinning in order to _write_ to the data within the page" whiletomoyo_dump_page()is for "_read_ the data within the page". Do we want to convert topin_user_pages_remote()orlock_page()?Sorry, I missed the direction here, was too focused on the Case 5 aspect. Yes. Case 5 (which, again, I think we're about to re-document) is only about *writing* to data within the page.
Quoted 7 lines
So in this case, where it is just reading from the page, I think it's already from a gup vs pup point of view.
btw, it's not clear to me whether the current code is susceptible to any sort of problem involving something writing to the page while it is being dumped (I am curious). But changing from gup to pup wouldn't fix that, if it were a problem. It a separate question from this patch.
The "struct page" tomoyo_dump_page() accesses is argv/envp arguments passed to execve() syscall. Therefore, these pages are not visible from threads except current thread, and thus there is no possibility that these pages are modified by other threads while current thread is reading.
Quoted 19 lines · Tetsuo Handa
Quoted 10 lines · John Hubbard
Quoted 5 lines
Excuse me, but
Documentation/core-api/pin_user_pages.rstsays "CASE 5: Pinning in order to _write_ to the data within the page" whiletomoyo_dump_page()is for "_read_ the data within the page". Do we want to convert topin_user_pages_remote()orlock_page()?Sorry, I missed the direction here, was too focused on the Case 5 aspect. Yes. Case 5 (which, again, I think we're about to re-document) is only about *writing* to data within the page.
Quoted 7 lines
So in this case, where it is just reading from the page, I think it's already from a gup vs pup point of view.
btw, it's not clear to me whether the current code is susceptible to any sort of problem involving something writing to the page while it is being dumped (I am curious). But changing from gup to pup wouldn't fix that, if it were a problem. It a separate question from this patch.
Quoted 5 lines
The "struct page"
tomoyo_dump_page()accesses is argv/envp arguments passed toexecve()syscall. Therefore, these pages are not visible from threads except current thread, and thus there is no possibility that these pages are modified by other threads while current thread is reading.
Perfect. So since I accidentally left out the word "correct" above (I meant to write, "it's already correct"), let me be extra clear: Souptick, we should just drop this patch.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 27 lines · John Hubbard
Quoted 19 lines · Tetsuo Handa
Quoted 10 lines · John Hubbard
Quoted 5 lines
Excuse me, but
Documentation/core-api/pin_user_pages.rstsays "CASE 5: Pinning in order to _write_ to the data within the page" whiletomoyo_dump_page()is for "_read_ the data within the page". Do we want to convert topin_user_pages_remote()orlock_page()?Sorry, I missed the direction here, was too focused on the Case 5 aspect. Yes. Case 5 (which, again, I think we're about to re-document) is only about *writing* to data within the page.
Quoted 7 lines
So in this case, where it is just reading from the page, I think it's already from a gup vs pup point of view.
btw, it's not clear to me whether the current code is susceptible to any sort of problem involving something writing to the page while it is being dumped (I am curious). But changing from gup to pup wouldn't fix that, if it were a problem. It a separate question from this patch.
Quoted 5 lines
The "struct page"
tomoyo_dump_page()accesses is argv/envp arguments passed toexecve()syscall. Therefore, these pages are not visible from threads except current thread, and thus there is no possibility that these pages are modified by other threads while current thread is reading.
Quoted 4 lines
Perfect. So since I accidentally left out the word "correct" above (I meant to write, "it's already correct"), let me be extra clear: Souptick, we should just drop this patch.
Agreed. I will drop this patch.
Quoted 39 lines · John Hubbard
Quoted 24 lines · Tetsuo Handa
Quoted 13 lines · John Hubbard
Quoted 12 lines · John Hubbard
Quoted 3 lines · Souptick Joarder
In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1].
It turns out that Case 5 can be implemented via a better pattern, as long as we're just dealing with a page at a time, briefly:
lock_page()
write to page's dataunlock_page()Quoted 9 lines
Quoted 1 line
...which neatly synchronizes with writeback and other fs activities.
Ahem, I left out a key step:
set_page_dirty()!
lock_page()
write to page's dataset_page_dirty()unlock_page()Quoted 5 lines
Excuse me, but
Documentation/core-api/pin_user_pages.rstsays "CASE 5: Pinning in order to _write_ to the data within the page" whiletomoyo_dump_page()is for "_read_ the data within the page". Do we want to convert topin_user_pages_remote()orlock_page()?Sorry, I missed the direction here, was too focused on the Case 5 aspect. Yes. Case 5 (which, again, I think we're about to re-document) is only about *writing* to data within the page.
So in this case, where it is just reading from the page, I think it's already from a gup vs pup point of view.
Quoted 8 lines
btw, it's not clear to me whether the current code is susceptible to any sort of problem involving something writing to the page while it is being dumped (I am curious). But changing from gup to pup wouldn't fix that, if it were a problem. It a separate question from this patch.
(Souptick, if you're interested, the Case 5 documentation change and callsite retrofit is all yours if you want it. Otherwise it's on my list.)
Sure John, I will take it.