how to context switch in a kernel module thread?

不打扰是莪最后的温柔 提交于 2019-12-08 04:09:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!