Executive summary:
mmap of /dev/mem gives different values than lseek/read of /dev/mem
Using lseek/read gives back bits of physical memory, but dereferencing
a pointer into the mmaped area mostly gives zeroes.
The file-system specific mmap routine, mmap_mem, calls
remap_page_range to do the work of remapping the physical pages
into user space. But eventually in remap_pte_range there's a check
if ((!VALID_PAGE(page)) || PageReserved(page))
set_pte(pte, mk_pte_phys(phys_addr, prot));
And the effect is that only the reserved pages and those outside
of the physical memory space get mapped. This isn't intuitive for
/dev/mem, but is it the intended behavior?
You could replicate those 80 odd lines of remap_page_range and helpers
to get a version without the PageReserved test. Yuk.
Quick hack:
SetPageReserved(virt_to_page(kva));
but you may want to undo that (Clear...) before kfree-ing the page,
as I'm not sure what will be confused by that.
Longer term solution: write your own mmap routine in the driver,
have the user code open /dev/my-driver, and mmap() on that instead
of going through /dev/mem with a hardcoded address.
-- Pete
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/