spa spa - 21 days ago 18
Linux Question

get_user_pages_fast() from kernel thread

I need to call

get_user_pages_fast()
from a kernel thread. But
get_user_pages_fast()
uses
current->mm
internally, which is set to
NULL
for kernel thread. Is there any way to get around this? The kernel thread in question is working on behalf of another process, say
x
, would it be be fine to just set
x->mm
to
current->mm
and invoke
get_user_pages_fast()
?

[EDIT 1]: I verified this and it seems to be working. I am still concerned if it could break in some cases. Any insight is welcome. Thanks.

Answer

I'm not convinced this is totally safe. The _fast part of get_user_pages_fast means that acquiring mm->mmap_sem is not required, and part of the reason that works is because it is assumed that we are running within the process itself (so eg the current->mm can't go away completely). Since you're running in another thread, you're susceptible to races if the real process ever does something that changes its mapping.

I guess the question is why can't you just use get_user_pages instead?

Comments