Re: chasing the four level page table

From: Andi Kleen
Date: Thu Jan 06 2005 - 13:20:24 EST


Jon Smirl <jonsmirl@xxxxxxxxx> writes:

> The DRM driver contains this routine:
>
> drivers/char/drm/drm_memory.h
>
> static inline unsigned long
> drm_follow_page (void *vaddr)
> {
> pgd_t *pgd = pgd_offset_k((unsigned long) vaddr);
> pud_t *pud = pud_offset(pgd, (unsigned long) vaddr);
> pmd_t *pmd = pmd_offset(pud, (unsigned long) vaddr);
> pte_t *ptep = pte_offset_kernel(pmd, (unsigned long) vaddr);
> return pte_pfn(*ptep) << PAGE_SHIFT;
> }
>
> No other driver needs to chase the page table like this so there is
> probably some other way to achieve this. Can someone who knows more
> about the VM system tell me if there is a way to eliminate this code?

Yes, you should use get_user_pages() instead if you access real memory.
If you try to find hardware mappings using that there is no ready
function for you right now, although I guess it could be added.

The function is also not quite correct, it should already least take
the page_table_lock (depending on where you call it from) and check
p*_none() on each level.

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/