[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-head Branch: master Commit: 177f7213619a2bfd72363d73678f549adc45129c URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=177f7213619a2bfd72363d73678f549adc45129c Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/native/heap.h | 14 +++-- include/native/queue.h | 14 +++-- include/nucleus/heap.h | 19 +++-- include/vrtx/vrtx.h |8 ++--- ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 13 ++--- ksrc/skins/native/syscall.c |7 +++-- ksrc/skins/posix/syscall.c | 10 +-- ksrc/skins/psos+/syscall.c |2 + ksrc/skins/vrtx/syscall.c |4 +- src/skins/common/sem_heap.c | 41 + src/skins/native/heap.c |9 +- src/skins/native/queue.c| 10 ++- src/skins/psos+/rn.c|9 +- src/skins/rtai/shm.c|8 - src/skins/vrtx/heap.c |8 - src/skins/vrtx/pt.c |8 - 19 files changed, 152 insertions(+), 89 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/native/heap.h b/include/native/heap.h index 0c2a7a2..443fd82 100644 --- a/include/native/heap.h +++ b/include/native/heap.h @@ -58,15 +58,11 @@ typedef struct rt_heap_info { } RT_HEAP_INFO; typedef struct rt_heap_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_HEAP_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/native/queue.h b/include/native/queue.h index 2951c42..b266c1d 100644 --- a/include/native/queue.h +++ b/include/native/queue.h @@ -58,15 +58,11 @@ typedef struct rt_queue_info { } RT_QUEUE_INFO; typedef struct rt_queue_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_QUEUE_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..e837bf2 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -208,14 +208,17 @@ void xnheap_destroy_mapped(xnheap_t *heap, void (*release)(struct xnheap *heap), void __user *mapaddr); +#define xnheap_base_memory(heap) \ + ((caddr_t)(heap)->archdep.heapbase) + #define xnheap_mapped_offset(heap,ptr) \ -(((caddr_t)(ptr)) - ((caddr_t)(heap)->archdep.heapbase)) + (((caddr_t)(ptr)) - xnheap_base_memory(heap)) #define xnheap_mapped_address(heap,off) \ -(((caddr_t)(heap)->archdep.heapbase) + (off)) + (xnheap_base_memory(heap) + (off)) #define xnheap_mapped_p(heap) \ -((heap)->archdep.heapbase != N
[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-2.5 Branch: master Commit: 177f7213619a2bfd72363d73678f549adc45129c URL: http://git.xenomai.org/?p=xenomai-2.5.git;a=commit;h=177f7213619a2bfd72363d73678f549adc45129c Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/native/heap.h | 14 +++-- include/native/queue.h | 14 +++-- include/nucleus/heap.h | 19 +++-- include/vrtx/vrtx.h |8 ++--- ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 13 ++--- ksrc/skins/native/syscall.c |7 +++-- ksrc/skins/posix/syscall.c | 10 +-- ksrc/skins/psos+/syscall.c |2 + ksrc/skins/vrtx/syscall.c |4 +- src/skins/common/sem_heap.c | 41 + src/skins/native/heap.c |9 +- src/skins/native/queue.c| 10 ++- src/skins/psos+/rn.c|9 +- src/skins/rtai/shm.c|8 - src/skins/vrtx/heap.c |8 - src/skins/vrtx/pt.c |8 - 19 files changed, 152 insertions(+), 89 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/native/heap.h b/include/native/heap.h index 0c2a7a2..443fd82 100644 --- a/include/native/heap.h +++ b/include/native/heap.h @@ -58,15 +58,11 @@ typedef struct rt_heap_info { } RT_HEAP_INFO; typedef struct rt_heap_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_HEAP_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/native/queue.h b/include/native/queue.h index 2951c42..b266c1d 100644 --- a/include/native/queue.h +++ b/include/native/queue.h @@ -58,15 +58,11 @@ typedef struct rt_queue_info { } RT_QUEUE_INFO; typedef struct rt_queue_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_QUEUE_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..e837bf2 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -208,14 +208,17 @@ void xnheap_destroy_mapped(xnheap_t *heap, void (*release)(struct xnheap *heap), void __user *mapaddr); +#define xnheap_base_memory(heap) \ + ((caddr_t)(heap)->archdep.heapbase) + #define xnheap_mapped_offset(heap,ptr) \ -(((caddr_t)(ptr)) - ((caddr_t)(heap)->archdep.heapbase)) + (((caddr_t)(ptr)) - xnheap_base_memory(heap)) #define xnheap_mapped_address(heap,off) \ -(((caddr_t)(heap)->archdep.heapbase) + (off)) + (xnheap_base_memory(heap) + (off)) #define xnheap_mapped_p(heap) \ -((heap)->archdep.heapbase != NUL
[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-rpm Branch: queue/vfile Commit: d425929b313f9a54e856401f77ed964ea06cd312 URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=d425929b313f9a54e856401f77ed964ea06cd312 Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/native/heap.h | 14 +++-- include/native/queue.h | 14 +++-- include/nucleus/heap.h | 19 +++-- include/vrtx/vrtx.h |8 ++--- ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 13 ++--- ksrc/skins/native/syscall.c |7 +++-- ksrc/skins/posix/syscall.c | 10 +-- ksrc/skins/psos+/syscall.c |2 + ksrc/skins/vrtx/syscall.c |4 +- src/skins/common/sem_heap.c | 41 + src/skins/native/heap.c |9 +- src/skins/native/queue.c| 10 ++- src/skins/psos+/rn.c|9 +- src/skins/rtai/shm.c|8 - src/skins/vrtx/heap.c |8 - src/skins/vrtx/pt.c |8 - 19 files changed, 152 insertions(+), 89 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/native/heap.h b/include/native/heap.h index 0c2a7a2..443fd82 100644 --- a/include/native/heap.h +++ b/include/native/heap.h @@ -58,15 +58,11 @@ typedef struct rt_heap_info { } RT_HEAP_INFO; typedef struct rt_heap_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_HEAP_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/native/queue.h b/include/native/queue.h index 2951c42..b266c1d 100644 --- a/include/native/queue.h +++ b/include/native/queue.h @@ -58,15 +58,11 @@ typedef struct rt_queue_info { } RT_QUEUE_INFO; typedef struct rt_queue_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_QUEUE_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..e837bf2 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -208,14 +208,17 @@ void xnheap_destroy_mapped(xnheap_t *heap, void (*release)(struct xnheap *heap), void __user *mapaddr); +#define xnheap_base_memory(heap) \ + ((caddr_t)(heap)->archdep.heapbase) + #define xnheap_mapped_offset(heap,ptr) \ -(((caddr_t)(ptr)) - ((caddr_t)(heap)->archdep.heapbase)) + (((caddr_t)(ptr)) - xnheap_base_memory(heap)) #define xnheap_mapped_address(heap,off) \ -(((caddr_t)(heap)->archdep.heapbase) + (off)) + (xnheap_base_memory(heap) + (off)) #define xnheap_mapped_p(heap) \ -((heap)->archdep.heapbase !
[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-rpm Branch: for-upstream Commit: d425929b313f9a54e856401f77ed964ea06cd312 URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=d425929b313f9a54e856401f77ed964ea06cd312 Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/native/heap.h | 14 +++-- include/native/queue.h | 14 +++-- include/nucleus/heap.h | 19 +++-- include/vrtx/vrtx.h |8 ++--- ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 13 ++--- ksrc/skins/native/syscall.c |7 +++-- ksrc/skins/posix/syscall.c | 10 +-- ksrc/skins/psos+/syscall.c |2 + ksrc/skins/vrtx/syscall.c |4 +- src/skins/common/sem_heap.c | 41 + src/skins/native/heap.c |9 +- src/skins/native/queue.c| 10 ++- src/skins/psos+/rn.c|9 +- src/skins/rtai/shm.c|8 - src/skins/vrtx/heap.c |8 - src/skins/vrtx/pt.c |8 - 19 files changed, 152 insertions(+), 89 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/native/heap.h b/include/native/heap.h index 0c2a7a2..443fd82 100644 --- a/include/native/heap.h +++ b/include/native/heap.h @@ -58,15 +58,11 @@ typedef struct rt_heap_info { } RT_HEAP_INFO; typedef struct rt_heap_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_HEAP_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/native/queue.h b/include/native/queue.h index 2951c42..b266c1d 100644 --- a/include/native/queue.h +++ b/include/native/queue.h @@ -58,15 +58,11 @@ typedef struct rt_queue_info { } RT_QUEUE_INFO; typedef struct rt_queue_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_QUEUE_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..e837bf2 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -208,14 +208,17 @@ void xnheap_destroy_mapped(xnheap_t *heap, void (*release)(struct xnheap *heap), void __user *mapaddr); +#define xnheap_base_memory(heap) \ + ((caddr_t)(heap)->archdep.heapbase) + #define xnheap_mapped_offset(heap,ptr) \ -(((caddr_t)(ptr)) - ((caddr_t)(heap)->archdep.heapbase)) + (((caddr_t)(ptr)) - xnheap_base_memory(heap)) #define xnheap_mapped_address(heap,off) \ -(((caddr_t)(heap)->archdep.heapbase) + (off)) + (xnheap_base_memory(heap) + (off)) #define xnheap_mapped_p(heap) \ -((heap)->archdep.heapbase
[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-rpm Branch: for-upstream Commit: ada72009aa6a3734b65938b1c2abe00f5c278956 URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=ada72009aa6a3734b65938b1c2abe00f5c278956 Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/native/heap.h | 14 +++-- include/native/queue.h | 14 +++-- include/nucleus/heap.h | 19 +++-- include/vrtx/vrtx.h |8 ++--- ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 13 ++--- ksrc/skins/native/syscall.c |7 +++-- ksrc/skins/psos+/syscall.c |2 + ksrc/skins/vrtx/syscall.c |4 +- src/skins/common/sem_heap.c | 41 + src/skins/native/heap.c |9 +- src/skins/native/queue.c| 10 ++- src/skins/psos+/rn.c|9 +- src/skins/rtai/shm.c|8 - src/skins/vrtx/heap.c |8 - src/skins/vrtx/pt.c |8 - 18 files changed, 145 insertions(+), 86 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/native/heap.h b/include/native/heap.h index 0c2a7a2..443fd82 100644 --- a/include/native/heap.h +++ b/include/native/heap.h @@ -58,15 +58,11 @@ typedef struct rt_heap_info { } RT_HEAP_INFO; typedef struct rt_heap_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_HEAP_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/native/queue.h b/include/native/queue.h index 2951c42..b266c1d 100644 --- a/include/native/queue.h +++ b/include/native/queue.h @@ -58,15 +58,11 @@ typedef struct rt_queue_info { } RT_QUEUE_INFO; typedef struct rt_queue_placeholder { - -xnhandle_t opaque; - -void *opaque2; - -caddr_t mapbase; - -size_t mapsize; - + xnhandle_t opaque; + void *opaque2; + caddr_t mapbase; + size_t mapsize; + xnheap_area_decl(); } RT_QUEUE_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..e837bf2 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -208,14 +208,17 @@ void xnheap_destroy_mapped(xnheap_t *heap, void (*release)(struct xnheap *heap), void __user *mapaddr); +#define xnheap_base_memory(heap) \ + ((caddr_t)(heap)->archdep.heapbase) + #define xnheap_mapped_offset(heap,ptr) \ -(((caddr_t)(ptr)) - ((caddr_t)(heap)->archdep.heapbase)) + (((caddr_t)(ptr)) - xnheap_base_memory(heap)) #define xnheap_mapped_address(heap,off) \ -(((caddr_t)(heap)->archdep.heapbase) + (off)) + (xnheap_base_memory(heap) + (off)) #define xnheap_mapped_p(heap) \ -((heap)->archdep.heapbase != NULL) + (xnheap_base_memory(heap) != NU
[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-rpm Branch: queue/mayday Commit: 11221fefff6ceddca51d70a48d3fae67e0103d3c URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=11221fefff6ceddca51d70a48d3fae67e0103d3c Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/nucleus/heap.h |1 + ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 17 +--- src/skins/common/sem_heap.c | 45 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..da5732e 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -282,6 +282,7 @@ int xnheap_check_block(xnheap_t *heap, struct xnheap_desc { unsigned long handle; unsigned int size; + unsigned long area; }; #endif /* !_XENO_NUCLEUS_HEAP_H */ diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c index afcc4f8..a152567 100644 --- a/ksrc/nucleus/heap.c +++ b/ksrc/nucleus/heap.c @@ -1136,8 +1136,8 @@ static int xnheap_ioctl(struct inode *inode, static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) { unsigned long offset, size, vaddr; - xnheap_t *heap; - int err; + struct xnheap *heap; + int ret; if (vma->vm_ops != NULL || file->private_data == NULL) /* Caller should mmap() once for a given file instance, after @@ -1147,9 +1147,6 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) if ((vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_SHARED)) return -EINVAL; /* COW unsupported. */ - offset = vma->vm_pgoff << PAGE_SHIFT; - size = vma->vm_end - vma->vm_start; - spin_lock(&kheapq_lock); heap = __validate_heap_addr(file->private_data); @@ -1163,22 +1160,28 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) spin_unlock(&kheapq_lock); vma->vm_private_data = file->private_data; - - err = -ENXIO; - if (offset + size > xnheap_extentsize(heap)) - goto deref_out; + vma->vm_ops = &xnheap_vmops; + size = vma->vm_end - vma->vm_start; + ret = -ENXIO; if (countq(&heap->extents) > 1) /* Cannot map multi-extent heaps, we need the memory area we map from to be contiguous. */ goto deref_out; - vma->vm_ops = &xnheap_vmops; + offset = vma->vm_pgoff << PAGE_SHIFT; + vaddr = (unsigned long)heap->archdep.heapbase; #ifdef CONFIG_MMU - vaddr = (unsigned long)heap->archdep.heapbase + offset; + /* +* offset is actually an offset from the start of the heap +* memory. +*/ + if (offset + size > xnheap_extentsize(heap)) + goto deref_out; - err = -EAGAIN; + vaddr += offset; + ret = -EAGAIN; if ((heap->archdep.kmflags & ~XNHEAP_GFP_NONCACHED) == 0) { unsi
[Xenomai-git] Philippe Gerum : nucleus: fix heap mapping for nommu
Module: xenomai-rpm Branch: for-upstream Commit: 11221fefff6ceddca51d70a48d3fae67e0103d3c URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=11221fefff6ceddca51d70a48d3fae67e0103d3c Author: Philippe Gerum Date: Sun Jun 13 21:49:01 2010 +0200 nucleus: fix heap mapping for nommu Despite the kernel sees a single backing device with direct mapping capabilities on nommu targets (/dev/rtheap), we do map different heaps through it, so we want a brand new mapping region for each of them. Therefore, we must make sure to request mappings on non-overlapping areas. To this end, we request mappings from offsets representing the start RAM address of the heap memory instead of mapping from offset 0 like previously. Otherwise, the kernel could match the same region for different heaps, for all mmap() requests directed to /dev/rtheap which appear to be a subset of a previous one, i.e. [offset=0, length <= largest mapped size to date]. Which does happen most of the time. Basically, this also means that shared heap mapping on nommu systems has always been badly broken on all Xenomai releases prior to this commit. Yeepeee. For this reason, we do break the nommu ABI to introduce this fix (i.e. blackfin and nios2), simply because the previous implementation did not work at all. --- include/asm-blackfin/features.h |2 +- include/asm-nios2/features.h|2 +- include/nucleus/heap.h |1 + ksrc/nucleus/heap.c | 53 +-- ksrc/nucleus/shadow.c | 17 +--- src/skins/common/sem_heap.c | 45 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h index 9dbee9c..c365c38 100644 --- a/include/asm-blackfin/features.h +++ b/include/asm-blackfin/features.h @@ -22,7 +22,7 @@ #include /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-nios2/features.h b/include/asm-nios2/features.h index eb4589a..534c052 100644 --- a/include/asm-nios2/features.h +++ b/include/asm-nios2/features.h @@ -36,7 +36,7 @@ static inline void collect_arch_features(struct xnfeatinfo *finfo) #endif /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 1UL +#define XENOMAI_ABI_REV 2UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index f4ebe11..da5732e 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -282,6 +282,7 @@ int xnheap_check_block(xnheap_t *heap, struct xnheap_desc { unsigned long handle; unsigned int size; + unsigned long area; }; #endif /* !_XENO_NUCLEUS_HEAP_H */ diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c index afcc4f8..a152567 100644 --- a/ksrc/nucleus/heap.c +++ b/ksrc/nucleus/heap.c @@ -1136,8 +1136,8 @@ static int xnheap_ioctl(struct inode *inode, static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) { unsigned long offset, size, vaddr; - xnheap_t *heap; - int err; + struct xnheap *heap; + int ret; if (vma->vm_ops != NULL || file->private_data == NULL) /* Caller should mmap() once for a given file instance, after @@ -1147,9 +1147,6 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) if ((vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_SHARED)) return -EINVAL; /* COW unsupported. */ - offset = vma->vm_pgoff << PAGE_SHIFT; - size = vma->vm_end - vma->vm_start; - spin_lock(&kheapq_lock); heap = __validate_heap_addr(file->private_data); @@ -1163,22 +1160,28 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) spin_unlock(&kheapq_lock); vma->vm_private_data = file->private_data; - - err = -ENXIO; - if (offset + size > xnheap_extentsize(heap)) - goto deref_out; + vma->vm_ops = &xnheap_vmops; + size = vma->vm_end - vma->vm_start; + ret = -ENXIO; if (countq(&heap->extents) > 1) /* Cannot map multi-extent heaps, we need the memory area we map from to be contiguous. */ goto deref_out; - vma->vm_ops = &xnheap_vmops; + offset = vma->vm_pgoff << PAGE_SHIFT; + vaddr = (unsigned long)heap->archdep.heapbase; #ifdef CONFIG_MMU - vaddr = (unsigned long)heap->archdep.heapbase + offset; + /* +* offset is actually an offset from the start of the heap +* memory. +*/ + if (offset + size > xnheap_extentsize(heap)) + goto deref_out; - err = -EAGAIN; + vaddr += offset; + ret = -EAGAIN; if ((heap->archdep.kmflags & ~XNHEAP_GFP_NONCACHED) == 0) { unsi