Re: Few queries



It looks reasonalbe, have you verify it with __pa?

kushneeraj@xxxxxxxxx wrote:
can we follow the page table to get the physical address for kernel
virtual address like this

unsigned long get_pte(unsigned long va)
{
pgd_t *pgd;
pmd_t *pmd;
pte_t *ptep, pte;
unsigned long page_base, pa ;

pgd = pgd_offset(current->mm, va);
if(pgd_none(*pgd) || pgd_bad(*pgd))
goto out;

pmd = pmd_offset(pgd, va);
if(pmd_none(*pmd) || pmd_bad(*pmd))
goto out;

ptep = pte_offset_map(pmd, va);
if(!ptep)
goto out;

pte = *ptep;
pte_unmap(ptep);

if(!pte_present(pte))
goto out;

page_base = pte_val(pte);
pa = (va & ~PAGE_MASK) | (page_base & PAGE_MASK);
return pa;

out:
return -1;
}

Kaz Kylheku wrote:
Josef Moellers wrote:
I still don't see a difference between a "logical" and a "virtual" address.
Apparently the distinction is that "logical addresses" have a simple,
fixed mapping to physical addresses (e.g. a constant offset) while
virtual addresses have an arbitrary mapping
(http://linux.derkeiler.com/Newsgroups/comp.os.linux.development.system/2006-01/msg00245.html)
IMHO, this is just trying to name things differently.

On some better-designed architectures, there can be sections of memory
which are not subject to paging, but instead to a simple translation.
E.g. the kernel segments or "ksegs" on MIPS.

It would not be quite accurate to call these addresses virtual, since
they don't go through virtual address translation.

It's an advantage to have this feature, because accesses to these
segments do not map through the TLB, which is precious cache space.
It's stupid to use virtual address translation to implement a simple
displacement over a large memory range, and the more physical RAM you
make visible that way, the stupider it gets due to the greater demand
on the TLB.

So, ideally, every platform would have a way to do kernel segments, and
so the MMU hardware would never be used for these logical pages at all.
Only for highmem pages, and for truly virtual allocations (user space
mmap, vmalloc).

So it does make sense to distinguish logical and virtual addresses. On
platforms like i386 can think of logical addresses as being a kernel
segment inefficiently emulated using the paging hardware.

.



Relevant Pages

  • Re: Few queries
    ... pmd_t *pmd; ... goto out; ... E.g. the kernel segments or "ksegs" on MIPS. ...
    (comp.os.linux.development.system)
  • [RFC/PATH 2/2] MM: Make Page Tables Relocatable -- relocation code.
    ... goto backout; ... pmd_populate(mm, pmd, new); ... * it's important to distinguish between what the cpu is doing internally ... To avoid unnecessary TLB cache tharshing, ...
    (Linux-Kernel)
  • Re: [Xen-devel] [RFC] VMI for Xen?
    ... I think with help from Linus' sparse checker, it might be more easily maintained by using noderef on the PTE types. ... goto no_context; ... pud = pud_offset; ... the kernel pmd. ...
    (Linux-Kernel)
  • Re: Few queries
    ... goto out; ... which are not subject to paging, but instead to a simple translation. ... E.g. the kernel segments or "ksegs" on MIPS. ... so the MMU hardware would never be used for these logical pages at all. ...
    (comp.os.linux.development.system)
  • Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad
    ... Don't spend any time on bisection: ... we have an strace/ptrace fix pending in x86.git - but that should not ... int pmd_huge(pmd_t pmd) ... goto no_page_table; ...
    (Linux-Kernel)