Skip to contentSkip to conversation

mm: Handle 0 flags in _calc_vm_trans() macro

PATCH In review Jan Kara 2 participants 2 messages Nov 3, 2017 Memory management

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 mm: Handle 0 flags in _calc_vm_trans() macro

_calc_vm_trans() does not handle the situation when some of the passed flags are 0 (which can happen if these VM flags do not make sense for the architecture). Improve the _calc_vm_trans() macro to return 0 in such situation. Since all passed flags are constant, this does not add any runtime overhead.

---
 include/linux/mman.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Dan, can you please prepend this patch before my series so that we don't break bisectability? This fixes the reported problem for me when arch does not define MAP_SYNC. Thanks!

include/linux/mman.h +2 -1
index 8f7cc87828e6..3427bf3daef5 100644
@@ -105,8 +105,9 @@ static inline bool arch_validate_prot(unsigned long prot)
  * ("bit1" and "bit2" must be single bits)
  */
 #define _calc_vm_trans(x, bit1, bit2) \
+  ((!(bit1) || !(bit2)) ? 0 : \
   ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
-   : ((x) & (bit1)) / ((bit1) / (bit2)))
+   : ((x) & (bit1)) / ((bit1) / (bit2))))
 
 /*
  * Combine the mmap "prot" argument into "vm_flags" used internally.
Signature · 7 lines
2.12.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 20 lines · Jan Kara

_calc_vm_trans() does not handle the situation when some of the passed flags are 0 (which can happen if these VM flags do not make sense for the architecture). Improve the _calc_vm_trans() macro to return 0 in such situation. Since all passed flags are constant, this does not add any runtime overhead.

---
 include/linux/mman.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Dan, can you please prepend this patch before my series so that we don't break bisectability? This fixes the reported problem for me when arch does not define MAP_SYNC. Thanks!

include/linux/mman.h +0 -0
index 8f7cc87828e6..3427bf3daef5 100644

include/linux/mman.h static inline bool arch_validate_prot(unsigned long prot) · line 111

Quoted 8 lines
include/linux/mman.h +2 -1
@@ -105,8 +105,9 @@ static inline bool arch_validate_prot(unsigned long prot)
  * ("bit1" and "bit2" must be single bits)
  */
 #define _calc_vm_trans(x, bit1, bit2) \
+  ((!(bit1) || !(bit2)) ? 0 : \
   ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
-   : ((x) & (bit1)) / ((bit1) / (bit2)))
+   : ((x) & (bit1)) / ((bit1) / (bit2))))
 

Looks good to me, thanks Jan.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>