Skip to content

Commit f8eb5bd

Browse files
committed
mm: fix build on 32-bit targets without MAX_PHYSMEM_BITS
The merge resolution to deal with the conflict between commits ea72ce5 ("x86/kaslr: Expose and use the end of the physical memory address space") and 99185c1 ("resource, kunit: add test case for region_intersects()") ended up being broken in configurations didn't define a MAX_PHYSMEM_BITS and that had a 32-bit 'phys_addr_t'. The fallback to using all bits set (ie "(-1ULL)") ended up causing a build error: kernel/resource.c: In function ‘gfr_start’: include/linux/minmax.h:93:30: error: conversion from ‘long long unsigned int’ to ‘resource_size_t’ {aka ‘unsigned int’} changes value from ‘18446744073709551615’ to ‘4294967295’ [-Werror=overflow] this was reported by Geert for m68k, but he points out that it happens on other 32-bit architectures too, eg mips, xtensa, parisc, and powerpc. Limiting 'PHYSMEM_END' to a 'phys_addr_t' (which is the same as 'resource_size_t') fixes the build, but Geert points out that it will then cause a silent overflow in mm/sparse.c: unsigned long max_sparsemem_pfn = (PHYSMEM_END + 1) >> PAGE_SHIFT; so we actually do want PHYSMEM_END to be defined a 64-bit type - just not all ones, and not larger than 'phys_addr_t'. The proper fix is probably to not have some kind of default fallback at all, but just make sure every architecture has a valid MAX_PHYSMEM_BITS. But in the meantime, this just applies the rule that PHYSMEM_END is the largest value that fits in a 'phys_addr_t', but does not have the high bit set in 64 bits. Ugly, ugly. Reported-by: Geert Uytterhoeven <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Huang Ying <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9631042 commit f8eb5bd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extern int mmap_rnd_compat_bits __read_mostly;
101101
# ifdef MAX_PHYSMEM_BITS
102102
# define PHYSMEM_END ((1ULL << MAX_PHYSMEM_BITS) - 1)
103103
# else
104-
# define PHYSMEM_END (-1ULL)
104+
# define PHYSMEM_END (((phys_addr_t)-1)&~(1ULL<<63))
105105
# endif
106106
#endif
107107

0 commit comments

Comments
 (0)