* kernel - userspace shared memory
@ 2011-06-06 17:17 Zoltan Devai
2011-06-10 4:16 ` viresh kumar
2011-06-10 7:33 ` Barry Song
0 siblings, 2 replies; 4+ messages in thread
From: Zoltan Devai @ 2011-06-06 17:17 UTC (permalink / raw)
To: linux-arm-kernel
Hi all,
We are having a kernel driver and a userspace application that
communicates via shared memory. The problem is, that when the userspace
application modifies some data in the shared memory, this modification
is not "visible" when the kernel driver takes a look at that memory
location (specifically this code is in a kernel timer function).
Actually, the modification is sometimes seen, sometimes not,
which suggests that we are having some kind of cache coherency issue.
The strange thing is, that AFAIK we have disabled caching on the pages
where the shared memory resides.
Below is the code that we use to create the shared memory area.
1. Do you see any problems with it?
2. As it can be seen, we are disabling caching for the user space
mapping, maybe we need to explicitly disable it for the kernel
mapping too? If yes, how to access the PTEs that are doing the kernel
logical mappings and disable caching?
3. Any hints on how to debug the source of such an error?
Any help is appreciated.
Best regards,
Istvan Devai
(actually sent by Zoltan Devai, on his behalf)
----------------------------------------
Kernel initialization code (error handling is omitted for clarity, also
the code that rounds the memory to the nearest page boundary):
kmalloc_ptr = kmalloc((SHAREDMEM_PAGE_NUM) * PAGE_SIZE, GFP_KERNEL);
for (i = 0; i < SHAREDMEM_PAGE_NUM * PAGE_SIZE; i+= PAGE_SIZE) {
SetPageReserved(virt_to_page(((unsigned long)kmalloc_ptr) + i));
}
Kernel mmap code:
vma->vm_flags |= VM_RESERVED;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
/* map the whole physically contiguous area in one piece */
remap_pfn_range(vma,
vma->vm_start,
virt_to_phys((void *)kmalloc_ptr) >> PAGE_SHIFT,
length,
vma->vm_page_prot)) < 0)
Userspace mmap code:
mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED| MAP_LOCKED, fd,
MMAP_OFFSET_SHAREDMEM)
^ permalink raw reply [flat|nested] 4+ messages in thread* kernel - userspace shared memory
2011-06-06 17:17 kernel - userspace shared memory Zoltan Devai
@ 2011-06-10 4:16 ` viresh kumar
2011-06-10 6:45 ` Arnd Bergmann
2011-06-10 7:33 ` Barry Song
1 sibling, 1 reply; 4+ messages in thread
From: viresh kumar @ 2011-06-10 4:16 UTC (permalink / raw)
To: linux-arm-kernel
On 06/06/2011 10:47 PM, Zoltan Devai wrote:
> Hi all,
>
> We are having a kernel driver and a userspace application that
> communicates via shared memory. The problem is, that when the userspace
> application modifies some data in the shared memory, this modification
> is not "visible" when the kernel driver takes a look at that memory
> location (specifically this code is in a kernel timer function).
> Actually, the modification is sometimes seen, sometimes not,
> which suggests that we are having some kind of cache coherency issue.
> The strange thing is, that AFAIK we have disabled caching on the pages
> where the shared memory resides.
Which core are you using? One problem that i am aware of is, on ARMv7
"Multiple mappings of memory with different attributes is not supported".
And the result of such is unspecified.
And for that we need to allocate memory with dma_mmap_writecombine() and remap it
for virtual space with dma_mmap_writecombine().
HTH.
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
* kernel - userspace shared memory
2011-06-10 4:16 ` viresh kumar
@ 2011-06-10 6:45 ` Arnd Bergmann
0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2011-06-10 6:45 UTC (permalink / raw)
To: linux-arm-kernel
On Friday 10 June 2011 06:16:42 viresh kumar wrote:
> On 06/06/2011 10:47 PM, Zoltan Devai wrote:
> > Hi all,
> >
> > We are having a kernel driver and a userspace application that
> > communicates via shared memory. The problem is, that when the userspace
> > application modifies some data in the shared memory, this modification
> > is not "visible" when the kernel driver takes a look at that memory
> > location (specifically this code is in a kernel timer function).
> > Actually, the modification is sometimes seen, sometimes not,
> > which suggests that we are having some kind of cache coherency issue.
> > The strange thing is, that AFAIK we have disabled caching on the pages
> > where the shared memory resides.
>
> Which core are you using? One problem that i am aware of is, on ARMv7
> "Multiple mappings of memory with different attributes is not supported".
> And the result of such is unspecified.
There are also possible problems with cache aliases. Zoltan, if this is
an out-of-tree driver, please post it here in patch form if you want
anyone to give you a more specific answer.
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* kernel - userspace shared memory
2011-06-06 17:17 kernel - userspace shared memory Zoltan Devai
2011-06-10 4:16 ` viresh kumar
@ 2011-06-10 7:33 ` Barry Song
1 sibling, 0 replies; 4+ messages in thread
From: Barry Song @ 2011-06-10 7:33 UTC (permalink / raw)
To: linux-arm-kernel
2011/6/7 Zoltan Devai <zdevai@gmail.com>:
> Hi all,
>
> We are having a kernel driver and a userspace application that
> communicates via shared memory. The problem is, that when the userspace
> application modifies some data in the shared memory, this modification
> is not "visible" when the kernel driver takes a look at that memory
> location (specifically this code is in a kernel timer function).
> Actually, the modification is sometimes seen, sometimes not,
> which suggests that we are having some kind of cache coherency issue.
> The strange thing is, that AFAIK we have disabled caching on the pages
> where the shared memory resides.
>
> Below is the code that we use to create the shared memory area.
>
> 1. Do you see any problems with it?
> 2. As it can be seen, we are disabling caching for the user space
> ? mapping, maybe we need to explicitly disable it for the kernel
> ? mapping too? If yes, how to access the PTEs that are doing the kernel
> ? logical mappings and disable caching?
> 3. Any hints on how to debug the source of such an error?
what's your ARM core? is it VIPT or VIVT? and do you have DMA
operation? All those result in difference answers. If VIVT, it will be
easy to have cache aliasing issue.
>
> Any help is appreciated.
>
> Best regards,
> Istvan Devai
> (actually sent by Zoltan Devai, on his behalf)
> ----------------------------------------
>
> Kernel initialization code (error handling is omitted for clarity, also
> the code that rounds the memory to the nearest page boundary):
>
> kmalloc_ptr = kmalloc((SHAREDMEM_PAGE_NUM) * PAGE_SIZE, GFP_KERNEL);
> for (i = 0; i < SHAREDMEM_PAGE_NUM * PAGE_SIZE; i+= PAGE_SIZE) {
> ? ? ? ? ? ?SetPageReserved(virt_to_page(((unsigned long)kmalloc_ptr) + i));
> ? ?}
>
> Kernel mmap code:
>
> vma->vm_flags |= VM_RESERVED;
> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>
> /* map the whole physically contiguous area in one piece */
> remap_pfn_range(vma,
> ? ? ? ? ? ? ? ? ? ? ? ? ? vma->vm_start,
> ? ? ? ? ? ? ? ? ? ? ? ? ? virt_to_phys((void *)kmalloc_ptr) >> PAGE_SHIFT,
> ? ? ? ? ? ? ? ? ? ? ? ? ? length,
> ? ? ? ? ? ? ? ? ? ? ? ? ? vma->vm_page_prot)) < 0)
>
> Userspace mmap code:
>
> mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED| MAP_LOCKED, fd,
> MMAP_OFFSET_SHAREDMEM)
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-06-10 7:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 17:17 kernel - userspace shared memory Zoltan Devai
2011-06-10 4:16 ` viresh kumar
2011-06-10 6:45 ` Arnd Bergmann
2011-06-10 7:33 ` Barry Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox