INVLPG

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
DarylD

INVLPG

Post by DarylD »

I have been furiously searching on google for the correct use of INVLPG, but its still not clear.

From the intel manual, its used as

invlpg mem

But is the memory address, an address of a page table or is it just a normal memory address??

I have found articles on when to use invlpg, but not actual real-life usage.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:INVLPG

Post by Pype.Clicker »

the "mem" argument you will put is a memory location which will be resolved (just as when you perform some "mov mem,eax" instruction) into an effective address and further into a virtual address using the selector in DS (except if you specify a segment override with i.e. invlpg [cs:some_label]).

Instead of issuing a 'read cycle" for this address, the CPU will remove any entry in its page cache related to virtual address AND 0xFFFFF000.
Note that there might be a separate page cache for data and instructions ... so i don't know if the CS: override is needed or not ... better check back intel 's doc to know.
DarylD

Re:INVLPG

Post by DarylD »

I understand all that, but one thing the intel docs don't seem to make clear (well to me anyhow!) is whether this is indirect or not.

I.e. the following instruction:

INVLPG (100000)

Will this read in the address to use in the page invalidation from 100000 and then invalidate that or will it try to invalidate address ds:100000 itself?

Just so I am clear on this.

Thanks Pype,

Daryl.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:INVLPG

Post by Pype.Clicker »

invlpg [0x10000] will invalidate ds:0x10000
invlpg 0x10000 is invalid (this is a constant, not a memory location)
invlpg [eax+ecx*4] will invalidate ds:(result of effective address computation)

invlpg [es:0x0000] should be allowed as well.
DarylD

Re:INVLPG

Post by DarylD »

Thanks Pype.

All is clear now, I just don't want to get weird paging errors later on because I am not doing things correct!

Daryl.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:INVLPG

Post by Pype.Clicker »

Code: Select all

#ifdef __PARANOIA__
#define invlpg(mem) asm("movl %%cr3,%%eax ; movl %%eax,%%cr3":::"memory")
#else
#define invlpg(mem) asm("invlpg %0"::"m"(mem):"memory")
#endif
and just #define __PARANOIA__ if you suspect something is going wr0ng :)
Post Reply