Memory inconsistency when mmap()ping

Russell King - ARM Linux linux at arm.linux.org.uk
Wed Jan 2 05:21:50 EST 2013


On Wed, Jan 02, 2013 at 10:59:55AM +0100, Christoph M. wrote:
> I'm experiencing a strange problem when mmap()ping memory
> to userspace on ARM-based Linux System.

You're running into the standard problems with virtually tagged caches.
What you ask for can't be done without adding cache flushes on both the
user space and kernel space sides, which depending on your application
may not be acceptable.

> Now to the technical details:
>  * The memory is allocated using kzalloc(PAGE_SIZE, GFP_KERNEL);
>  * The event counter is a u32 value which is stored at offset 0 of
>    the buffer.
>  * When accessing (read/write) the buffer from kernelspace a call
>    to mb() is done afterwards.
>  * My mmap() code does this:
>      vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

And doing that will violate the requirements of the ARMv7 architecture
that all mappings of the same physical memory space will be of the same
type (let alone, have the same attributes.)

The kernel mapping will still be 'memory like' and 'cacheable', maybe
even with write-allocation.

As you've mapped this into userspace as 'strongly ordered' its highly
likely that the caches are being bypassed for all accesses.



More information about the linux-arm mailing list