开发者

nested page-faulting of user-space address in Linux

开发者 https://www.devze.com 2022-12-24 13:17 出处:网络
Iwould like to know if it is functionally wrong to page-fault auser-space address when kernel is running fault-handler to bring in a user-page.

I would like to know if it is functionally wrong to page-fault a user-space address when kernel is running fault-handler to bring in a user-page.

OS is Linux 2.6.30

Assume t开发者_如何学Gohat both user-addresses are valid ( falling within vma , rw permission ) for the task.

When I check the kernel code, i find that the kernel does not mind the nested fault if the faulted-addresses are valid and the fault did not occur in atomic-context or in irq handler.

(I dont think the answer is cpu-specific, but I would add that i am interested in arm and mips ).

eg : The scenario can happen if I print stack-data from page-fault handler.


Looking through kernel sources for the last hour suggests that it is fine: Neither the definition of struct vm_operations_struct nor the code between handle_mm_fault() and the call to vma->vm_ops->fault in __do_fault() has any cautionary statements about this, and the few ->fault handlers I looked at didn't seem worried about it either...

... I think the main thing is that you need to avoid going into an infinite recursion by faulting on the same address again, but that would presumably only happen if the kernel stack was in your vma, which is most likely not going to be happen?


It is absolutely correct. As a matter of fact, you can even sleep.

But you can do it only once this line is passed, since you will be in non-atomic context.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号