Paging unmap pages

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
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Paging unmap pages

Post by Jeko »

When I unmap a page, which of them must I flush:
- Virtual addr of the page
- Virtual addr of the PTE that contains the page
- Virtual addr of the PDE that contains the page

I think only first two. The second only if it is possible to deallocate the frame of the page table used to map the page, so, if in the page table there isn't any other page.
jgraef
Member
Member
Posts: 47
Joined: Wed Jan 16, 2008 7:37 am
Location: Wonsheim, Germany

Post by jgraef »

Hi,

It would be enough by setting the enable bit in the page table entry to 0. The simplest way is to set the whole dword to zero, because playing with bitmask would be just pointless.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

jgraef wrote:Hi,

It would be enough by setting the enable bit in the page table entry to 0. The simplest way is to set the whole dword to zero, because playing with bitmask would be just pointless.
Mustn't I flush any page?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Yes, you should flush the entry. Try invlpg or reloading CR3. The processor doesn't maintain coherency between page tables in memory, and the TLB cache.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

I do something like this when I unmap a page:

Code: Select all

	// Unmap the page.

	*ADDR_TO_PTE(vir_addr) = 0;


	// Invalidate the page in the TLB cache.

	flush_tlb_single(vir_addr);



	// Check if it is possible to deallocate the frame

	// of the page table used to map the address

	// So let's examine all entries in the page table

	// where the address is mapped.

	for (temp = PAGE_DIR_ALIGN(vir_addr);

		temp < PAGE_DIR_ALIGN_UP(vir_addr);

		temp += PAGE_SIZE) {

		if ((*ADDR_TO_PTE(temp) & P_PRESENT) == P_PRESENT) {


			return;

		}

	}


	flush_tlb_single(ADDR_TO_PTE(vir_addr));


	// No PTEs found... deallocate the page table!

	push_frame(*ADDR_TO_PDE(vir_addr));

	*ADDR_TO_PDE(vir_addr) = 0;
Post Reply