Skip to contentSkip to conversation

rtdm_iomap_to_user: fix caching and page fault issues

Xenomai Wolfgang Grandegger 3 participants 5 messages Jan 15, 2013 – Sep 27, 2013 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

From: Wolfgang Grandegger <[email protected]>

Pages mapped by rtdm_iomap_to_user() might be cached and may page fault on the first write. At least that's the behaviour we observed on an ARM mx6q system. This patch fixes these issues.

---
 include/asm-generic/wrappers.h | 2 +-
 ksrc/skins/rtdm/drvlib.c       | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/wrappers.h +1 -1
index de1f0d7..e71bcc3 100644
@@ -394,7 +394,7 @@ static inline void *kzalloc(size_t size, int flags)
 #define wrap_remap_io_page_range(vma,from,to,size,prot)  ({		\
     (vma)->vm_page_prot = pgprot_noncached((vma)->vm_page_prot);	\
     /* Sets VM_RESERVED | VM_IO | VM_PFNMAP on the vma. */		\
-    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,prot);		\
+    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,pgprot_noncached(prot));		\
     })
 #define wrap_remap_kmem_page_range(vma,from,to,size,prot)  ({		\
     /* Sets VM_RESERVED | VM_IO | VM_PFNMAP on the vma. */		\
ksrc/skins/rtdm/drvlib.c +5 -3
index e5c470c..391d45f 100644
@@ -1858,10 +1858,12 @@ static int rtdm_mmap_buffer(struct file *filp, struct vm_area_struct *vma)
 #else
 	vma->vm_pgoff = paddr >> PAGE_SHIFT;
 #endif /* CONFIG_MMU */
-	if (mmap_data->src_paddr)
-	  	ret = xnarch_remap_io_page_range(filp, vma, maddr, paddr,
+	if (mmap_data->src_paddr) {
+		ret = xnarch_remap_io_page_range(filp, vma, maddr, paddr,
 						 size, PAGE_SHARED);
-	else {
+		if (!ret)
+			xnarch_fault_range(vma);
+	} else {
 		ret = xnarch_remap_kmem_page_range(vma, maddr, paddr,
 						   size, PAGE_SHARED);
 		if (!ret)
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 18 lines · Wolfgang Grandegger

From: Wolfgang Grandegger <[email protected]>

Pages mapped by rtdm_iomap_to_user() might be cached and may page fault on the first write. At least that's the behaviour we observed on an ARM mx6q system. This patch fixes these issues.

---
 include/asm-generic/wrappers.h | 2 +-
 ksrc/skins/rtdm/drvlib.c       | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/wrappers.h +0 -0
index de1f0d7..e71bcc3 100644

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 397

Quoted 5 lines
include/asm-generic/wrappers.h +1 -1
@@ -394,7 +394,7 @@ static inline void *kzalloc(size_t size, int flags)
 #define wrap_remap_io_page_range(vma,from,to,size,prot)  ({		\
     (vma)->vm_page_prot = pgprot_noncached((vma)->vm_page_prot);	\
     /* Sets VM_RESERVED | VM_IO | VM_PFNMAP on the vma. */		\
-    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,prot);		\
+    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,pgprot_noncached(prot));		\

Should not this be decided in the upper layers?

Signature · 1 line
                                                                Gilles.
#2 lore raw
Quoted 15 lines · Gilles Chanteperdrix
Quoted 13 lines · Wolfgang Grandegger

From: Wolfgang Grandegger <[email protected]>

Pages mapped by rtdm_iomap_to_user() might be cached and may page fault on the first write. At least that's the behaviour we observed on an ARM mx6q system. This patch fixes these issues.

---
 include/asm-generic/wrappers.h | 2 +-
 ksrc/skins/rtdm/drvlib.c       | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
Quoted 7 lines

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 395

Quoted 7 lines
include/asm-generic/wrappers.h +0 -0
index de1f0d7..e71bcc3 100644
@@ -394,7 +394,7 @@ static inline void *kzalloc(size_t size, int flags)
 #define wrap_remap_io_page_range(vma,from,to,size,prot)  ({		\
     (vma)->vm_page_prot = pgprot_noncached((vma)->vm_page_prot);	\

Hm, here pgprot_noncached() is already used.

Quoted 6 lines

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 397

Quoted 3 lines
include/asm-generic/wrappers.h +1 -1
     /* Sets VM_RESERVED | VM_IO | VM_PFNMAP on the vma. */		\
-    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,prot);		\
+    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,pgprot_noncached(prot));		\

Should not this be decided in the upper layers?

Upper layers? You mean calling xnarch_remap_io_page_range() with the protection argument "pgprot_noncached(PAGE_SHARED)" in rtdm_mmap_buffer()?

Wolfgang.

Quoted 1 line
#3 lore raw
Quoted 31 lines · Wolfgang Grandegger
Quoted 15 lines · Gilles Chanteperdrix
Quoted 13 lines · Wolfgang Grandegger

From: Wolfgang Grandegger <[email protected]>

Pages mapped by rtdm_iomap_to_user() might be cached and may page fault on the first write. At least that's the behaviour we observed on an ARM mx6q system. This patch fixes these issues.

---
 include/asm-generic/wrappers.h | 2 +-
 ksrc/skins/rtdm/drvlib.c       | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
Quoted 7 lines

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 395

Quoted 7 lines
include/asm-generic/wrappers.h +0 -0
index de1f0d7..e71bcc3 100644
@@ -394,7 +394,7 @@ static inline void *kzalloc(size_t size, int flags)
 #define wrap_remap_io_page_range(vma,from,to,size,prot)  ({		\
     (vma)->vm_page_prot = pgprot_noncached((vma)->vm_page_prot);	\

Hm, here pgprot_noncached() is already used.

Quoted 5 lines
Quoted 3 lines
include/asm-generic/wrappers.h +1 -1
     /* Sets VM_RESERVED | VM_IO | VM_PFNMAP on the vma. */		\
-    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,prot);		\
+    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,pgprot_noncached(prot));		\
Quoted 4 lines
Quoted 1 line

Should not this be decided in the upper layers?

Upper layers? You mean calling xnarch_remap_io_page_range() with the protection argument "pgprot_noncached(PAGE_SHARED)" in rtdm_mmap_buffer()?

I mean users could want to map i/o regions cacheable, but as you say, the pgprot_noncached is already hardcoded in the vma, so, I will merge your patch.

Signature · 1 line
                                                                Gilles.
#4 lore raw
Quoted 39 lines · Gilles Chanteperdrix
Quoted 10 lines · Wolfgang Grandegger
Quoted 9 lines · Gilles Chanteperdrix
Quoted 7 lines · Wolfgang Grandegger

From: Wolfgang Grandegger <[email protected]>

Pages mapped by rtdm_iomap_to_user() might be cached and may page fault on the first write. At least that's the behaviour we observed on an ARM mx6q system. This patch fixes these issues.

Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
---
 include/asm-generic/wrappers.h | 2 +-
 ksrc/skins/rtdm/drvlib.c       | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/include/asm-generic/wrappers.h

Quoted 5 lines
Quoted 5 lines

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 394

Quoted 5 lines

index de1f0d7..e71bcc3 100644

include/asm-generic/wrappers.h +0 -0
@@ -394,7 +394,7 @@ static inline void *kzalloc(size_t size, int flags)
 #define wrap_remap_io_page_range(vma,from,to,size,prot)  ({
     \
Quoted 6 lines
Quoted 1 line

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 395

Quoted 1 line
include/asm-generic/wrappers.h +0 -0
     (vma)->vm_page_prot = pgprot_noncached((vma)->vm_page_prot);   \

Hm, here pgprot_noncached() is already used.

Quoted 2 lines
Quoted 2 lines
include/asm-generic/wrappers.h +0 -1
     /* Sets VM_RESERVED | VM_IO | VM_PFNMAP on the vma. */         \
-    remap_pfn_range(vma,from,(to) >> PAGE_SHIFT,size,prot);
     \
Quoted 1 line
Quoted 1 line

include/asm-generic/wrappers.h static inline void *kzalloc(size_t size, int flags) · line 397

Quoted 1 line
include/asm-generic/wrappers.h +1 -0
+    remap_pfn_range(vma,from,(to) >>

PAGE_SHIFT,size,pgprot_noncached(prot)); \

Quoted 4 lines
Quoted 3 lines

Should not this be decided in the upper layers?

Quoted 9 lines
Quoted 2 lines

Upper layers? You mean calling xnarch_remap_io_page_range() with the protection argument "pgprot_noncached(PAGE_SHARED)" in

rtdm_mmap_buffer()?

I mean users could want to map i/o regions cacheable, but as you say, the pgprot_noncached is already hardcoded in the vma, so, I will merge your patch.

I used rtdm_iomap_to_user() to map the iMX6 EIM device into user space and still see caching behavior.

Wolfgang, your patch didn't apply the pgprot_noncached(prot) to the #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) && defined(CONFIG_MMU) case. Was that intended? Were you using a non-mmu configuration or an old kernel?

Anyway, when I apply that change to the >v2.6.15&mmu case, then the caching behavior is gone. I think that is correct, because my assumption is the

Quoted 1 line

v2.6.15&mmu check should only switch the use of vm_insert_page(). Please

comment on this assumption.

If the assumption is correct, then select one of the attached patches. The first one just adds the pgprot_noncached(prot) to the >v2.6.15&mmu case, while version 2 removes removes the duplicate code
for wrap_remap_io_page_range() and wrap_remap_kmem_page_range(). So NOTE to only select one of the patches.

Thanks,
Henri

Quoted 9 lines

--
Gilles.

_______________________________________________
Xenomai mailing list
[email protected]
http://www.xenomai.org/mailman/listinfo/xenomai

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_wrap_remap_io_page_range_cached_mapping_v1.patch
Type: application/octet-stream
Size: 729 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130927/03f29aad/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_wrap_remap_io_page_range_cached_mapping_v2.patch
Type: application/octet-stream
Size: 2085 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130927/03f29aad/attachment-0001.obj>