Skip to contentSkip to conversation

ARM: use cache type functions for arch_get_unmapped_area

PATCH New Rob Herring 4 participants 7 messages Nov 17, 2011 – Oct 24, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 ARM: use cache type functions for arch_get_unmapped_area

From: Rob Herring <[email protected]>

There are already cache type decoding functions, so use those instead of custom decode code which only works for ARMv6.

This change also correctly enables cache colour alignment on Cortex-A9 whose I-cache is aliasing VIPT.

---
v2:
- remove icache_is_vipt_aliasing check

Nico, can you pick up these 2 patches into the Linaro kernel to get some testing?

Rob

 arch/arm/mm/mmap.c |   23 ++++++-----------------
 1 files changed, 6 insertions(+), 17 deletions(-)
arch/arm/mm/mmap.c +6 -17
index 74be05f..44b628e 100644
@@ -9,8 +9,7 @@
 #include <linux/io.h>
 #include <linux/personality.h>
 #include <linux/random.h>
-#include <asm/cputype.h>
-#include <asm/system.h>
+#include <asm/cachetype.h>
 
 #define COLOUR_ALIGN(addr,pgoff)		\
 	((((addr)+SHMLBA-1)&~(SHMLBA-1)) +	\
@@ -32,25 +31,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
 	unsigned long start_addr;
-#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K)
-	unsigned int cache_type;
-	int do_align = 0, aliasing = 0;
+	int do_align = 0;
+	int aliasing = cache_is_vipt_aliasing();
 
 	/*
 	 * We only need to do colour alignment if either the I or D
-	 * caches alias.  This is indicated by bits 9 and 21 of the
-	 * cache type register.
+	 * caches alias.
 	 */
-	cache_type = read_cpuid_cachetype();
-	if (cache_type != read_cpuid_id()) {
-		aliasing = (cache_type | cache_type >> 12) & (1 << 11);
-		if (aliasing)
-			do_align = filp || flags & MAP_SHARED;
-	}
-#else
-#define do_align 0
-#define aliasing 0
-#endif
+	if (aliasing)
+		do_align = filp || (flags & MAP_SHARED);
 
 	/*
 	 * We enforce the MAP_FIXED case.
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH v2 2/2 ARM: topdown mmap support

From: Rob Herring <[email protected]>

Similar to other architectures, this adds topdown mmap support in user process address space allocation policy. This allows mmap sizes greater than 2GB. This support is largely copied from MIPS and the generic implementations.

The address space randomization is moved into arch_pick_mmap_layout.

Tested on V-Express with ubuntu and a mmap test from here:
https://bugs.launchpad.net/bugs/861296

---
v2:
- remove icache_is_vipt_aliasing check

 arch/arm/include/asm/pgtable.h   |    1 +
 arch/arm/include/asm/processor.h |    2 +
 arch/arm/mm/mmap.c               |  173 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 171 insertions(+), 5 deletions(-)
arch/arm/include/asm/pgtable.h +1 -0
index 9451dce..2f659e2 100644
@@ -336,6 +336,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  * We provide our own arch_get_unmapped_area to cope with VIPT caches.
  */
 #define HAVE_ARCH_UNMAPPED_AREA
+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
 
 /*
  * remap a physical page `pfn' of size `size' with page protection `prot'
arch/arm/include/asm/processor.h +2 -0
index b2d9df5..ce280b8 100644
@@ -123,6 +123,8 @@ static inline void prefetch(const void *ptr)
 
 #endif
 
+#define HAVE_ARCH_PICK_MMAP_LAYOUT
+
 #endif
 
 #endif /* __ASM_ARM_PROCESSOR_H */
arch/arm/mm/mmap.c +168 -5

197 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#6 lore raw

PATCH v2 1/2 ARM: use cache type functions for arch_get_unmapped_area

In reply to Rob Herring

Hi Rob,

Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

There are already cache type decoding functions, so use those instead of custom decode code which only works for ARMv6.

This change also correctly enables cache colour alignment on Cortex-A9 whose I-cache is aliasing VIPT.

You can probably drop this paragraph.

With that,

but yes, it would be nice to see this in -next for a bit.

Cheers,

Will

#2 lore raw

PATCH v2 2/2 ARM: topdown mmap support

In reply to Rob Herring
Quoted 14 lines · Rob Herring

From: Rob Herring <[email protected]>

Similar to other architectures, this adds topdown mmap support in user process address space allocation policy. This allows mmap sizes greater than 2GB. This support is largely copied from MIPS and the generic implementations.

The address space randomization is moved into arch_pick_mmap_layout.

Tested on V-Express with ubuntu and a mmap test from here:
https://bugs.launchpad.net/bugs/861296

Quoted 9 lines

---
v2:
- remove icache_is_vipt_aliasing check

 arch/arm/include/asm/pgtable.h   |    1 +
 arch/arm/include/asm/processor.h |    2 +
 arch/arm/mm/mmap.c               |  173 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 171 insertions(+), 5 deletions(-)

Russell,

I submitted these 2 patches to the patch system. Can you please pull into your next branch so they can get some more testing.

Cheers,
Rob

#3 lore raw

PATCH v2 2/2 ARM: topdown mmap support

Quoted 25 lines · Rob Herring
Quoted 14 lines · Rob Herring

From: Rob Herring <[email protected]>

Similar to other architectures, this adds topdown mmap support in user process address space allocation policy. This allows mmap sizes greater than 2GB. This support is largely copied from MIPS and the generic implementations.

The address space randomization is moved into arch_pick_mmap_layout.

Tested on V-Express with ubuntu and a mmap test from here:
https://bugs.launchpad.net/bugs/861296

Quoted 9 lines

---
v2:
- remove icache_is_vipt_aliasing check

 arch/arm/include/asm/pgtable.h   |    1 +
 arch/arm/include/asm/processor.h |    2 +
 arch/arm/mm/mmap.c               |  173 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 171 insertions(+), 5 deletions(-)
Quoted 4 lines

Russell,

I submitted these 2 patches to the patch system. Can you please pull into your next branch so they can get some more testing.

For the record, I included an earlier version of those patches in the Linaro kernel a week ago, and no breakage were reported so far.

Nicolas

#4 lore raw

PATCH v2 2/2 ARM: topdown mmap support

In reply to Rob Herring
Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

Similar to other architectures, this adds topdown mmap support in user process address space allocation policy. This allows mmap sizes greater than 2GB. This support is largely copied from MIPS and the generic implementations.

Quoted 7 lines

The address space randomization is moved into arch_pick_mmap_layout.

Tested on V-Express with ubuntu and a mmap test from here:
https://bugs.launchpad.net/bugs/861296

Unfortunately, we met "no vspace available" during loading libmono.so, when using default arch_get_unmapped_area_topdown method, tested on Jelly Bean with 3.4 kernel.
While no problem using arch_get_unmapped_area in the patch, or just revert this patch.
The result is some application can not run.

Just google, find same issue reported on Jelly Bean with 3.4 kernel.

Any suggestion?

Thanks

#5 lore raw

PATCH v2 2/2 ARM: topdown mmap support

Quoted 23 lines · zhangfei gao
Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

Similar to other architectures, this adds topdown mmap support in user process address space allocation policy. This allows mmap sizes greater than 2GB. This support is largely copied from MIPS and the generic implementations.

Quoted 7 lines

The address space randomization is moved into arch_pick_mmap_layout.

Tested on V-Express with ubuntu and a mmap test from here:
https://bugs.launchpad.net/bugs/861296

Unfortunately, we met "no vspace available" during loading libmono.so, when using default arch_get_unmapped_area_topdown method, tested on Jelly Bean with 3.4 kernel.
While no problem using arch_get_unmapped_area in the patch, or just revert this patch.
The result is some application can not run.

Quoted 3 lines

Just google, find same issue reported on Jelly Bean with 3.4 kernel.

Any suggestion?

Perhaps Android has hardcoded expectations about the virtual memory layout? I was worried about that at the time and asked the Linaro Android folks to test it.

I believe either layout can be selected at runtime per process. I don't recall the exact /proc file to control this.

Rob