Commit ad3ff105 authored by Huacai Chen's avatar Huacai Chen

LoongArch: Remove shm_align_mask and use SHMLBA instead

Both shm_align_mask and SHMLBA want to avoid cache alias. But they are
inconsistent: shm_align_mask is (PAGE_SIZE - 1) while SHMLBA is SZ_64K,
but PAGE_SIZE is not always equal to SZ_64K.

This may cause problems when shmat() twice. Fix this problem by removing
shm_align_mask and using SHMLBA (strictly SHMLBA - 1) instead.
Reported-by: default avatarJiantao Shan <shanjiantao@loongson.cn>
Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
parent 303be4b3
...@@ -156,7 +156,6 @@ void cpu_cache_init(void) ...@@ -156,7 +156,6 @@ void cpu_cache_init(void)
current_cpu_data.cache_leaves_present = leaf; current_cpu_data.cache_leaves_present = leaf;
current_cpu_data.options |= LOONGARCH_CPU_PREFETCH; current_cpu_data.options |= LOONGARCH_CPU_PREFETCH;
shm_align_mask = PAGE_SIZE - 1;
} }
static const pgprot_t protection_map[16] = { static const pgprot_t protection_map[16] = {
......
...@@ -8,12 +8,11 @@ ...@@ -8,12 +8,11 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/mman.h> #include <linux/mman.h>
unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ #define SHM_ALIGN_MASK (SHMLBA - 1)
EXPORT_SYMBOL(shm_align_mask);
#define COLOUR_ALIGN(addr, pgoff) \ #define COLOUR_ALIGN(addr, pgoff) \
((((addr) + shm_align_mask) & ~shm_align_mask) + \ ((((addr) + SHM_ALIGN_MASK) & ~SHM_ALIGN_MASK) \
(((pgoff) << PAGE_SHIFT) & shm_align_mask)) + (((pgoff) << PAGE_SHIFT) & SHM_ALIGN_MASK))
enum mmap_allocation_direction {UP, DOWN}; enum mmap_allocation_direction {UP, DOWN};
...@@ -40,7 +39,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, ...@@ -40,7 +39,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
* cache aliasing constraints. * cache aliasing constraints.
*/ */
if ((flags & MAP_SHARED) && if ((flags & MAP_SHARED) &&
((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask)) ((addr - (pgoff << PAGE_SHIFT)) & SHM_ALIGN_MASK))
return -EINVAL; return -EINVAL;
return addr; return addr;
} }
...@@ -63,7 +62,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp, ...@@ -63,7 +62,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
} }
info.length = len; info.length = len;
info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0; info.align_mask = do_color_align ? (PAGE_MASK & SHM_ALIGN_MASK) : 0;
info.align_offset = pgoff << PAGE_SHIFT; info.align_offset = pgoff << PAGE_SHIFT;
if (dir == DOWN) { if (dir == DOWN) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment