0

If my understanding is not wrong, TLB stores not only virtual to physical address mappings, but also each page's flag such as writable flag(W), execute disable(XD) flag.

My question is what faults will be generated, if it tries to execute non-executable pages such as heap or stack? Is it a page fault?

halfer
  • 19,824
  • 17
  • 99
  • 186
ruach
  • 1,369
  • 11
  • 21
  • 2
    TLB contents "win" (nothing else is checked, that's why the TLB exists), which is why you must flush the entry if you modify the flags. – harold May 10 '16 at 14:24
  • Oh really? I've heard that TLB also maintains the flags in the table. – ruach May 10 '16 at 14:26
  • Yes, that's the problem. If the TLB didn't have a copy of them, it wouldn't accelerate anything because those flags would have to be looked up. So it does. But then it doesn't know what the "real flags" are, it only knows what they were on the moment the TLB miss happened and it made the copy. – harold May 10 '16 at 14:35
  • Do you mean that even though TLB has a copy of the flags, but it never been checked?? Then why it contains the flag in the TLB it would waste the cache though... – ruach May 10 '16 at 14:41
  • No, the real flag, in the page table, isn't checked. That's why this problem even exists. It does not notice the mismatch. – harold May 10 '16 at 14:45
  • Oh, I see. You want to say that even though TLB has flags field in its table, and checked everytime memory access is occurred, but it doesn't automatically synchronized with the real flags stored in the page table. right? – ruach May 10 '16 at 14:48
  • Oh, it's not the page fault but general protection fault.. – ruach May 10 '16 at 14:55
  • 2
    No nvm I looked at the wrong table. #PF for both of those. – harold May 10 '16 at 14:58
  • Okay #PF! And is the system fault handler(exeception handler) automatically flush that entry and fill up the new flags? or just crush? I mean if the case that TLB and page talbe flags are not match – ruach May 10 '16 at 14:58
  • 1
    You can sort of that "lazy TLB invalidation" that way if you changed a flag from "will generate #PF" to "would not generate #PF", then if you get the #PF do the relevant invlpg, but it wouldn't work the other way around (eg if you make a page read-only, it won't take effect until you flush the TLB entry, and in this case you don't get a chance to do it lazily) – harold May 10 '16 at 15:08

1 Answers1

-1

Page-Fault Exception

...

  • Code running in user mode attempts to write to a read-only page. In the Intel486 and later processors, if the WP flag is set in CR0, the page fault will also be triggered by code running in supervisor mode that tries to write to a read-only page.
  • An instruction fetch to a linear address that translates to a physical address in a memory page with the execute-disable bit set.

...

From Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3A: System Programming Guide, Part 1 page 6-54.

Görkem Mülayim
  • 1,139
  • 1
  • 12
  • 22