问题
I'm wondering if there is a way for a kernel module thread to switch its current mm. Kernel threads usually use the last mm that was active before it was scheduled. Is it possible to switch to a particular mm in a kernel thread?
I'm looking for a linux equivalent to KeStackAttachProcess
in windows.
Context_switch()
and switch_mm()
are not exported so I'm wondering what I can use to switch context in my kernel module thread.
回答1:
There is no such function available currently to switch context. However, the same thing can be achieved in a different way. The best way i have found to do anything in the context of a particular process in the kernel, is to sleep in process context(wait_* family of functions) and wake up that thread and do whatever needs to be done in that context. This would ofcourse mean you would have to have the application call into the kernel via IOCTL or something and sleep on that thread and wake it up whenever you need to do something. This seems to be a very widely used and popular mechanism.
来源:https://stackoverflow.com/questions/24888548/how-to-context-switch-in-a-kernel-module-thread