问题
I am trying to implement tlb flush function. For flushing I use INVLPG
instruction, but unfortunately it always cause segmentation fault. Could you help me with this issue?
Here is the code:
#include "stdlib.h"
inline void tlb_flush_entry(int *m)
{
asm volatile ("invlpg %0"::"m"(*m):"memory");
}
int main(int argc, char **argv)
{
int *memory = (int *)malloc(100);
tlb_flush_entry(memory);
}
回答1:
The SIGSEGV happens because INVLPG is a privileged instruction and can only be called out of kernel code. This means you can't evict a userspace page out of the TLB that way. However I wrote a litte kernel module demonstrating the usage of invlpg: How to use INVLPG on x86-64 architecture?
来源:https://stackoverflow.com/questions/13253498/segfault-when-invlpg-instruction-is-called