ITchimp wrote:
so my question: what is the criteria for resetting the paging circuit for reassigning the CR3 register?
The criterion is: Do you merely add access, or do you remove/change access? If you add access to a previously unavailable address, you don't need to invalidate the TLB (which is what reloading CR3 does), because at least AMD CPUs are documented to reread the page table in that case, and Intel CPUs might just generate a spurious page fault (that is fixed simply by returning from that interrupt). But if you remove access to an address, or you change where an address is mapped to, or you remove access for user space, or you set a previously writable page to read-only, then you have to invalidate the TLB, because then it is wrong. And one way to do that is to reload CR3. Note that this won't invalidate TLB for pages marked as global, but then, invalidating those is rarely required.
Since invalidating all TLBs is a bit of a performance hit, you usually want to avoid that if possible. So a less scattershot approach is to just use "invlpg" anyway. But if you are replacing large parts of the address space (e.g. when switching processes), then reloading CR3 is still faster than invalidating every single userspace mapping.