Re: question about amd64 pagetable page allocation.

2012-04-04 Thread vasanth rao naik sabavat
Hello Mark,

>From what I understand, the virtual address of a given page table should
not change when accessing from vtopte() and pmap_pte().

However, with small code change in pmap_remove_pages(), I was able to print
the values returned by these two functions.

vtopte() and pmap_pte(),

pte1 0x806432e0 pa1 346941425 m1 0xff04291cf600, pte2
0xff03463032e0 pa2 346941425 m2 0xff04291cf600
pte1 0x806432e8 pa1 346842425 m1 0xff04291c7e78, pte2
0xff03463032e8 pa2 346842425 m2 0xff04291c7e78
pte1 0x806432f0 pa1 346863425 m1 0xff04291c8df0, pte2
0xff03463032f0 pa2 346863425 m2 0xff04291c8df0

In the above result, the pte1 is the result of vtopte() and pte2 is the
result of pmap_pte().

Interestingly, the value of these two virtual addresses pte1 and pte2,
result in the same physical address pa1 == pa2.

If I am not wrong, the page tables are now mapped in two different virtual
addresses?

Could you please clarify this?

Thanks,
Vasanth

On Tue, Apr 3, 2012 at 3:18 PM, Mark Tinguely wrote:

> On Tue, Apr 3, 2012 at 1:52 PM, vasanth rao naik sabavat
>  wrote:
> > Hello Mark,
> >
> > I think pmap_remove_pages() is executed only for the current process.
> >
> >2549 #ifdef PMAP_REMOVE_PAGES_CURPROC_ONLY
> >2550 if (pmap != vmspace_pmap(curthread->td_proc->p_vmspace)) {
> >2551 printf("warning: pmap_remove_pages called with
> non-current
> > pmap\n");
> >2552 return;
> >2553 }
> >2554 #endif
> >
> > I dont still get it why this was removed?
> >
> > Thanks,
> > Vasanth
>
>
> That is pretty old code. Newer code does not make that assumption.
>
> Without the assumption that the pages are from the current map, then you
> have to use the direct physical -> virtual mapping:
>
> 2547#ifdef PMAP_REMOVE_PAGES_CURPROC_ONLY
> 2548pte = vtopte(pv->pv_va);
> 2549#else
> 2550pte = pmap_pte(pmap, pv->pv_va);
> 2551#endif
>
> --Mark Tinguely.
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: question about amd64 pagetable page allocation.

2012-04-03 Thread Mark Tinguely
On Tue, Apr 3, 2012 at 1:52 PM, vasanth rao naik sabavat
 wrote:
> Hello Mark,
>
> I think pmap_remove_pages() is executed only for the current process.
>
>    2549 #ifdef PMAP_REMOVE_PAGES_CURPROC_ONLY
>    2550     if (pmap != vmspace_pmap(curthread->td_proc->p_vmspace)) {
>    2551         printf("warning: pmap_remove_pages called with non-current
> pmap\n");
>    2552         return;
>    2553     }
>    2554 #endif
>
> I dont still get it why this was removed?
>
> Thanks,
> Vasanth


That is pretty old code. Newer code does not make that assumption.

Without the assumption that the pages are from the current map, then you
have to use the direct physical -> virtual mapping:

2547#ifdef PMAP_REMOVE_PAGES_CURPROC_ONLY
2548pte = vtopte(pv->pv_va);
2549#else
2550pte = pmap_pte(pmap, pv->pv_va);
2551#endif

--Mark Tinguely.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: question about amd64 pagetable page allocation.

2012-04-03 Thread vasanth rao naik sabavat
Hello Mark,

I think pmap_remove_pages() is executed only for the current process.

   2549 #ifdef PMAP_REMOVE_PAGES_CURPROC_ONLY
   2550 if (pmap != vmspace_pmap(curthread->td_proc->p_vmspace)) {
   2551 printf("warning: pmap_remove_pages called with non-current
pmap\n");
   2552 return;
   2553 }
   2554 #endif

I dont still get it why this was removed?

Thanks,
Vasanth

On Tue, Apr 3, 2012 at 12:42 PM, Mark Tinguely wrote:

> On Tue, Apr 3, 2012 at 10:18 AM, vasanth rao naik sabavat
>  wrote:
> > Hello Mark,
> >
> > Thank you for replying,
> >
> > Could you please point me to any document which illustrates the
> > implementation of recursive page tables in FreeBSD for amd64.
> >
> > Also, I just found that with the following patch from Alon, the usage of
> > vtopte() is removed in pmap_remove_pages(). Why was this removed?
> >
> > http://lists.freebsd.org/pipermail/svn-src-all/2009-March/006006.html
> >
> > Thanks,
> > Vasanth
> >
> > On Tue, Apr 3, 2012 at 10:56 AM, Mark Tinguely 
> > wrote:
> >>
> >> On Tue, Apr 3, 2012 at 8:33 AM, vasanth rao naik sabavat
> >>  wrote:
> >> > Hi,
> >> >
> >> > I am trying to understand the page table page allocation for a process
> >> > in
> >> > FBSD6.1. I see that the page table pages are allocated by
> >> > vm_page_alloc().
> >> > I believe the virtual address for this allocated page can be derived
> by
> >> > PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)), however when I compare this address
> >> > with
> >> > the virtual address accessed in pmap_remove_pages() they are not the
> >> > same.
> >> >
> >> > The virtual address of a *PTE in pmap_remove_pages() is something like
> >> > *0x80643200
> >> > *
> >> > However, the virtual address of the page allocated by vm_page_alloc()
> is
> >> >  *
> >> > 0xff033c6a
> >> >
> >> > *I would also like to understand the importance of loc_PTmap, I
> believe
> >> > the
> >> > pmap_remove_pages() is derving the page table page addresses from
> >> > loc_PTmap?
> >> > (kgdb) p loc_PTmap
> >> > Cannot access memory at address 0x8000
> >> >
> >> > How do we relate the loc_PTmap to the page table pages allocated by
> >> > vm_page_alloc() in _pmap_allocpte().
> >> >
> >> > Thanks,
> >> > Vasanth
> >>
> >>
> >>
> >> The answer to your questions will be more obvious when you get an
> >> understanding of the Recursive Page Tables.
> >>
> >> --Mark Tinguely.
> >
> >
>
> Search for "recursive page tables" start with 32 bits first. I did not
> read it, but the below page looks promising:
>
>
> http://www.rohitab.com/discuss/topic/31139-tutorial-paging-memory-mapping-with-a-recursive-page-directory/
>
> The nice thing about recursive page table is the MMU does the work. But:
>
> 1) User recursive page tables work only for the current map.
> 2) Kernel mappings are placed at the top of every map - so the kernel
>recursive addresses will always be valid.
>
> As the comment in the link states, that change converted from using
> user recursive page table virtual address (which is only valid when
> the map is current) to using the physical to virtual direct map (which
> is always valid).
>
> --Mark Tinguely.
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: question about amd64 pagetable page allocation.

2012-04-03 Thread Mark Tinguely
On Tue, Apr 3, 2012 at 10:18 AM, vasanth rao naik sabavat
 wrote:
> Hello Mark,
>
> Thank you for replying,
>
> Could you please point me to any document which illustrates the
> implementation of recursive page tables in FreeBSD for amd64.
>
> Also, I just found that with the following patch from Alon, the usage of
> vtopte() is removed in pmap_remove_pages(). Why was this removed?
>
> http://lists.freebsd.org/pipermail/svn-src-all/2009-March/006006.html
>
> Thanks,
> Vasanth
>
> On Tue, Apr 3, 2012 at 10:56 AM, Mark Tinguely 
> wrote:
>>
>> On Tue, Apr 3, 2012 at 8:33 AM, vasanth rao naik sabavat
>>  wrote:
>> > Hi,
>> >
>> > I am trying to understand the page table page allocation for a process
>> > in
>> > FBSD6.1. I see that the page table pages are allocated by
>> > vm_page_alloc().
>> > I believe the virtual address for this allocated page can be derived by
>> > PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)), however when I compare this address
>> > with
>> > the virtual address accessed in pmap_remove_pages() they are not the
>> > same.
>> >
>> > The virtual address of a *PTE in pmap_remove_pages() is something like
>> > *0x80643200
>> > *
>> > However, the virtual address of the page allocated by vm_page_alloc() is
>> >  *
>> > 0xff033c6a
>> >
>> > *I would also like to understand the importance of loc_PTmap, I believe
>> > the
>> > pmap_remove_pages() is derving the page table page addresses from
>> > loc_PTmap?
>> > (kgdb) p loc_PTmap
>> > Cannot access memory at address 0x8000
>> >
>> > How do we relate the loc_PTmap to the page table pages allocated by
>> > vm_page_alloc() in _pmap_allocpte().
>> >
>> > Thanks,
>> > Vasanth
>>
>>
>>
>> The answer to your questions will be more obvious when you get an
>> understanding of the Recursive Page Tables.
>>
>> --Mark Tinguely.
>
>

Search for "recursive page tables" start with 32 bits first. I did not
read it, but the below page looks promising:

http://www.rohitab.com/discuss/topic/31139-tutorial-paging-memory-mapping-with-a-recursive-page-directory/

The nice thing about recursive page table is the MMU does the work. But:

1) User recursive page tables work only for the current map.
2) Kernel mappings are placed at the top of every map - so the kernel
recursive addresses will always be valid.

As the comment in the link states, that change converted from using
user recursive page table virtual address (which is only valid when
the map is current) to using the physical to virtual direct map (which
is always valid).

--Mark Tinguely.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: question about amd64 pagetable page allocation.

2012-04-03 Thread vasanth rao naik sabavat
Hello Mark,

Thank you for replying,

Could you please point me to any document which illustrates the
implementation of recursive page tables in FreeBSD for amd64.

Also, I just found that with the following patch from Alon, the usage of
vtopte() is removed in pmap_remove_pages(). Why was this removed?

http://lists.freebsd.org/pipermail/svn-src-all/2009-March/006006.html

Thanks,
Vasanth

On Tue, Apr 3, 2012 at 10:56 AM, Mark Tinguely wrote:

> On Tue, Apr 3, 2012 at 8:33 AM, vasanth rao naik sabavat
>  wrote:
> > Hi,
> >
> > I am trying to understand the page table page allocation for a process in
> > FBSD6.1. I see that the page table pages are allocated by
> vm_page_alloc().
> > I believe the virtual address for this allocated page can be derived by
> > PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)), however when I compare this address
> with
> > the virtual address accessed in pmap_remove_pages() they are not the
> same.
> >
> > The virtual address of a *PTE in pmap_remove_pages() is something like
> > *0x80643200
> > *
> > However, the virtual address of the page allocated by vm_page_alloc() is
>  *
> > 0xff033c6a
> >
> > *I would also like to understand the importance of loc_PTmap, I believe
> the
> > pmap_remove_pages() is derving the page table page addresses from
> loc_PTmap?
> > (kgdb) p loc_PTmap
> > Cannot access memory at address 0x8000
> >
> > How do we relate the loc_PTmap to the page table pages allocated by
> > vm_page_alloc() in _pmap_allocpte().
> >
> > Thanks,
> > Vasanth
>
>
>
> The answer to your questions will be more obvious when you get an
> understanding of the Recursive Page Tables.
>
> --Mark Tinguely.
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: question about amd64 pagetable page allocation.

2012-04-03 Thread Mark Tinguely
On Tue, Apr 3, 2012 at 8:33 AM, vasanth rao naik sabavat
 wrote:
> Hi,
>
> I am trying to understand the page table page allocation for a process in
> FBSD6.1. I see that the page table pages are allocated by vm_page_alloc().
> I believe the virtual address for this allocated page can be derived by
> PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)), however when I compare this address with
> the virtual address accessed in pmap_remove_pages() they are not the same.
>
> The virtual address of a *PTE in pmap_remove_pages() is something like
> *0x80643200
> *
> However, the virtual address of the page allocated by vm_page_alloc() is  *
> 0xff033c6a
>
> *I would also like to understand the importance of loc_PTmap, I believe the
> pmap_remove_pages() is derving the page table page addresses from loc_PTmap?
> (kgdb) p loc_PTmap
> Cannot access memory at address 0x8000
>
> How do we relate the loc_PTmap to the page table pages allocated by
> vm_page_alloc() in _pmap_allocpte().
>
> Thanks,
> Vasanth



The answer to your questions will be more obvious when you get an
understanding of the Recursive Page Tables.

--Mark Tinguely.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


question about amd64 pagetable page allocation.

2012-04-03 Thread vasanth rao naik sabavat
Hi,

I am trying to understand the page table page allocation for a process in
FBSD6.1. I see that the page table pages are allocated by vm_page_alloc().
I believe the virtual address for this allocated page can be derived by
PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)), however when I compare this address with
the virtual address accessed in pmap_remove_pages() they are not the same.

The virtual address of a *PTE in pmap_remove_pages() is something like
*0x80643200
*
However, the virtual address of the page allocated by vm_page_alloc() is  *
0xff033c6a

*I would also like to understand the importance of loc_PTmap, I believe the
pmap_remove_pages() is derving the page table page addresses from loc_PTmap?
(kgdb) p loc_PTmap
Cannot access memory at address 0x8000

How do we relate the loc_PTmap to the page table pages allocated by
vm_page_alloc() in _pmap_allocpte().

Thanks,
Vasanth
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"