Re: How to read Page Table Entry in the linux kernel module?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 28, 2008 at 10:14 PM, Cédric Augonnet
<cedric.augonnet@xxxxxxxxx> wrote:
> 2008/5/28 sahlot arvind <asahlot@xxxxxxxxx>:
>> I am trying to understand how can I read the pte using pte_page. Please
>> could you explain?
>>
>> On 5/28/08, Cédric Augonnet <cedric.augonnet@xxxxxxxxx> wrote:
>>>
>>> 2008/5/28 sahlot arvind <asahlot@xxxxxxxxx>:
>>> > I am working on Linux 2.6 and inside the init function of my module I am
>>> > doing this -
>>> >
>>> > -------------
>>> > init_module ()
>>> > {
>>> >      va = kmalloc (4096, GFP_KERNEL);
>>> > }
>>> > --------------
>>> >
>>> > Now I want to read the page table entry for this va?
>>> > What is the right way to do that?
>>> > Thanks in advance
>>> > - A
>>> >
>>>
>>> Hi,
>>>
>>> Is it not the pte_page macro that you are looking for ?
>>>
>>> Cheers,
>>> Cédric
>>
>>
>>
>> --
>> http://linuxexplained.blogspot.com
>
> Perhaps this would to the trick
>
> struct mm_struct *mm = current->mm;
> pgd = pgd_offset(mm, address);
> pmd = pmd_offset(pgd, address);
> pte = *pte_offset_map(pmd, address);

take note:  the pmd u derive here is meant for A PROCESS ie, u are
deriving the userspace's address of that process.

But if u are looking for PAGES that represented kernel memory it
should be pte_offset_kernel().   Examples are in arch/x86 directories:

./mm/init_32.c:
                BUG_ON(page_table != pte_offset_kernel(pmd, 0));
        return pte_offset_kernel(pmd, 0);
        return pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr),
        pte = pte_offset_kernel(pmd, vaddr);
                pte = pte_offset_kernel(pmd, va);

./mm/pageattr.c:
        return pte_offset_kernel(pmd, address);

./mm/pgtable_32.c:
        pte = pte_offset_kernel(pmd, vaddr);

./mm/init_64.c:
                if (pte != pte_offset_kernel(pmd, 0)) {
        pte = pte_offset_kernel(pmd, vaddr);
        pte = pte_offset_kernel(pmd, addr);

./mm/fault.c:
        pte = pte_offset_kernel(pmd, address);
        pte = pte_offset_kernel(pmd, address);
        pte_k = pte_offset_kernel(pmd_k, address);
        pte_ref = pte_offset_kernel(pmd_ref, address);
        pte = pte_offset_kernel(pmd, address);

etc......correct me if wrong..... :-).

> page = pte_page(pte);
>
> Actually, you don't need the last line if i read your initial question
> more carefuly... sorry
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Regards,
Peter Teoh

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux