Skip to content

Commit ad3ff10

Browse files
committed
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: Jiantao Shan <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 303be4b commit ad3ff10

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

arch/loongarch/mm/cache.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ void cpu_cache_init(void)
156156

157157
current_cpu_data.cache_leaves_present = leaf;
158158
current_cpu_data.options |= LOONGARCH_CPU_PREFETCH;
159-
shm_align_mask = PAGE_SIZE - 1;
160159
}
161160

162161
static const pgprot_t protection_map[16] = {

arch/loongarch/mm/mmap.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
#include <linux/mm.h>
99
#include <linux/mman.h>
1010

11-
unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
12-
EXPORT_SYMBOL(shm_align_mask);
11+
#define SHM_ALIGN_MASK (SHMLBA - 1)
1312

14-
#define COLOUR_ALIGN(addr, pgoff) \
15-
((((addr) + shm_align_mask) & ~shm_align_mask) + \
16-
(((pgoff) << PAGE_SHIFT) & shm_align_mask))
13+
#define COLOUR_ALIGN(addr, pgoff) \
14+
((((addr) + SHM_ALIGN_MASK) & ~SHM_ALIGN_MASK) \
15+
+ (((pgoff) << PAGE_SHIFT) & SHM_ALIGN_MASK))
1716

1817
enum mmap_allocation_direction {UP, DOWN};
1918

@@ -40,7 +39,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4039
* cache aliasing constraints.
4140
*/
4241
if ((flags & MAP_SHARED) &&
43-
((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
42+
((addr - (pgoff << PAGE_SHIFT)) & SHM_ALIGN_MASK))
4443
return -EINVAL;
4544
return addr;
4645
}
@@ -63,7 +62,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6362
}
6463

6564
info.length = len;
66-
info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
65+
info.align_mask = do_color_align ? (PAGE_MASK & SHM_ALIGN_MASK) : 0;
6766
info.align_offset = pgoff << PAGE_SHIFT;
6867

6968
if (dir == DOWN) {

0 commit comments

Comments
 (0)