From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: mm/nommu.c:1010:12: warning: The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'int' [clang-analyzer-core.UndefinedBinaryOperatorResult]
Date: Sat, 13 Nov 2021 21:49:09 +0800 [thread overview]
Message-ID: <202111132149.EphgbyPT-lkp@intel.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 37040 bytes --]
CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Jakub Jelinek <jakub@redhat.com>
CC: "Peter Zijlstra (Intel)" <peterz@infradead.org>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 66f4beaa6c1d28161f534471484b2daa2de1dce0
commit: 2f78788b55baa3410b1ec91a576286abe1ad4d6a ilog2: improve ilog2 for constant arguments
date: 11 months ago
:::::: branch date: 17 hours ago
:::::: commit date: 11 months ago
config: riscv-randconfig-c006-20211003 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 962e503cc8bc411f7523cc393acae8aae425b1c4)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2f78788b55baa3410b1ec91a576286abe1ad4d6a
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 2f78788b55baa3410b1ec91a576286abe1ad4d6a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv clang-analyzer
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
clang-analyzer warnings: (new ones prefixed by >>)
#define ASSERTCMP(X, OP, Y) \
^
fs/fscache/operation.c:597:7: note: Assuming field 'n_ops' is not equal to 0
if (object->n_ops == 0)
^~~~~~~~~~~~~~~~~~
fs/fscache/operation.c:597:3: note: Taking false branch
if (object->n_ops == 0)
^
fs/fscache/operation.c:601:3: note: Memory is released
kfree(op);
^~~~~~~~~
fs/fscache/operation.c:571:2: note: Loop condition is true. Execution continues on line 572
do {
^
fs/fscache/operation.c:573:7: note: Assuming the condition is false
if (list_empty(&cache->op_gc_list)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/fscache/operation.c:573:3: note: Taking false branch
if (list_empty(&cache->op_gc_list)) {
^
fs/fscache/operation.c:578:8: note: Left side of '&&' is false
op = list_entry(cache->op_gc_list.next,
^
include/linux/list.h:511:2: note: expanded from macro 'list_entry'
container_of(ptr, type, member)
^
include/linux/kernel.h:694:61: note: expanded from macro 'container_of'
BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
^
fs/fscache/operation.c:578:8: note: Taking false branch
op = list_entry(cache->op_gc_list.next,
^
include/linux/list.h:511:2: note: expanded from macro 'list_entry'
container_of(ptr, type, member)
^
include/linux/kernel.h:694:2: note: expanded from macro 'container_of'
BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
^
include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/compiler_types.h:315:2: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
include/linux/compiler_types.h:303:2: note: expanded from macro '_compiletime_assert'
__compiletime_assert(condition, msg, prefix, suffix)
^
include/linux/compiler_types.h:295:3: note: expanded from macro '__compiletime_assert'
if (!(condition)) \
^
fs/fscache/operation.c:578:8: note: Loop condition is false. Exiting loop
op = list_entry(cache->op_gc_list.next,
^
include/linux/list.h:511:2: note: expanded from macro 'list_entry'
container_of(ptr, type, member)
^
include/linux/kernel.h:694:2: note: expanded from macro 'container_of'
BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
^
include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/compiler_types.h:315:2: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
include/linux/compiler_types.h:303:2: note: expanded from macro '_compiletime_assert'
__compiletime_assert(condition, msg, prefix, suffix)
^
include/linux/compiler_types.h:293:2: note: expanded from macro '__compiletime_assert'
do { \
^
fs/fscache/operation.c:580:3: note: Calling 'list_del'
list_del(&op->pend_link);
^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/list.h:146:2: note: Calling '__list_del_entry'
__list_del_entry(entry);
^~~~~~~~~~~~~~~~~~~~~~~
include/linux/list.h:132:2: note: Taking false branch
if (!__list_del_entry_valid(entry))
^
include/linux/list.h:135:13: note: Use of memory after it is freed
__list_del(entry->prev, entry->next);
^~~~~~~~~~~
Suppressed 10 warnings (2 in non-user code, 8 with check filters).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
47 warnings generated.
mm/nommu.c:423:2: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/nommu.c:423:2: note: Value stored to 'ret' is never read
ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/nommu.c:881:6: warning: Value stored to 'prot' is never read [clang-analyzer-deadcode.DeadStores]
prot |= PROT_EXEC;
^
mm/nommu.c:881:6: note: Value stored to 'prot' is never read
mm/nommu.c:899:4: warning: Value stored to 'prot' is never read [clang-analyzer-deadcode.DeadStores]
prot |= PROT_EXEC;
^
mm/nommu.c:899:4: note: Value stored to 'prot' is never read
>> mm/nommu.c:1010:12: warning: The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'int' [clang-analyzer-core.UndefinedBinaryOperatorResult]
total = 1 << order;
^
mm/nommu.c:1091:6: note: 'ret' is >= 0
if (ret < 0)
^~~
mm/nommu.c:1091:2: note: Taking false branch
if (ret < 0)
^
mm/nommu.c:1104:6: note: Assuming 'region' is non-null
if (!region)
^~~~~~~
mm/nommu.c:1104:2: note: Taking false branch
if (!region)
^
mm/nommu.c:1108:6: note: Assuming 'vma' is non-null
if (!vma)
^~~~
mm/nommu.c:1108:2: note: Taking false branch
if (!vma)
^
mm/nommu.c:1118:6: note: 'file' is null
if (file) {
^~~~
mm/nommu.c:1118:2: note: Taking false branch
if (file) {
^
mm/nommu.c:1133:6: note: Assuming the condition is false
if (vm_flags & VM_MAYSHARE) {
^~~~~~~~~~~~~~~~~~~~~~
mm/nommu.c:1133:2: note: Taking false branch
if (vm_flags & VM_MAYSHARE) {
^
mm/nommu.c:1230:6: note: 'file' is null
if (file && vma->vm_flags & VM_SHARED)
^~~~
mm/nommu.c:1230:11: note: Left side of '&&' is false
if (file && vma->vm_flags & VM_SHARED)
^
mm/nommu.c:1233:9: note: Calling 'do_mmap_private'
ret = do_mmap_private(vma, region, len, capabilities);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/nommu.c:988:2: note: Taking false branch
if (capabilities & NOMMU_MAP_DIRECT) {
^
mm/nommu.c:1009:10: note: Calling 'get_order'
order = get_order(len);
^~~~~~~~~~~~~~
include/asm-generic/getorder.h:31:2: note: Taking false branch
if (__builtin_constant_p(size)) {
^
include/asm-generic/getorder.h:46:9: note: Calling 'fls64'
return fls64(size);
^~~~~~~~~~~
include/asm-generic/bitops/fls64.h:29:6: note: Assuming 'x' is not equal to 0
if (x == 0)
^~~~~~
include/asm-generic/bitops/fls64.h:29:2: note: Taking false branch
if (x == 0)
^
include/asm-generic/bitops/fls64.h:31:2: note: Returning the value 32
return __fls(x) + 1;
^~~~~~~~~~~~~~~~~~~
include/asm-generic/getorder.h:46:9: note: Returning from 'fls64'
return fls64(size);
^~~~~~~~~~~
include/asm-generic/getorder.h:46:2: note: Returning the value 32
return fls64(size);
^~~~~~~~~~~~~~~~~~
mm/nommu.c:1009:10: note: Returning from 'get_order'
order = get_order(len);
^~~~~~~~~~~~~~
mm/nommu.c:1009:2: note: The value 32 is assigned to 'order'
order = get_order(len);
^~~~~~~~~~~~~~~~~~~~~~
mm/nommu.c:1010:12: note: The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'int'
total = 1 << order;
^ ~~~~~
mm/nommu.c:1010:12: warning: The result of the left shift is undefined due to shifting by '33', which is greater or equal to the width of type 'int' [clang-analyzer-core.UndefinedBinaryOperatorResult]
total = 1 << order;
^
mm/nommu.c:1091:6: note: 'ret' is >= 0
if (ret < 0)
^~~
mm/nommu.c:1091:2: note: Taking false branch
if (ret < 0)
^
mm/nommu.c:1104:6: note: Assuming 'region' is non-null
if (!region)
^~~~~~~
mm/nommu.c:1104:2: note: Taking false branch
if (!region)
^
mm/nommu.c:1108:6: note: Assuming 'vma' is non-null
if (!vma)
^~~~
mm/nommu.c:1108:2: note: Taking false branch
if (!vma)
^
mm/nommu.c:1118:6: note: 'file' is null
if (file) {
vim +1010 mm/nommu.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 750
^1da177e4c3f41 Linus Torvalds 2005-04-16 751 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 752 * determine whether a mapping should be permitted and, if so, what sort of
^1da177e4c3f41 Linus Torvalds 2005-04-16 753 * mapping we're capable of supporting
^1da177e4c3f41 Linus Torvalds 2005-04-16 754 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 755 static int validate_mmap_request(struct file *file,
^1da177e4c3f41 Linus Torvalds 2005-04-16 756 unsigned long addr,
^1da177e4c3f41 Linus Torvalds 2005-04-16 757 unsigned long len,
^1da177e4c3f41 Linus Torvalds 2005-04-16 758 unsigned long prot,
^1da177e4c3f41 Linus Torvalds 2005-04-16 759 unsigned long flags,
^1da177e4c3f41 Linus Torvalds 2005-04-16 760 unsigned long pgoff,
^1da177e4c3f41 Linus Torvalds 2005-04-16 761 unsigned long *_capabilities)
^1da177e4c3f41 Linus Torvalds 2005-04-16 762 {
8feae13110d60c David Howells 2009-01-08 763 unsigned long capabilities, rlen;
^1da177e4c3f41 Linus Torvalds 2005-04-16 764 int ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 765
^1da177e4c3f41 Linus Torvalds 2005-04-16 766 /* do the simple checks first */
22cc877b32202b Leon Romanovsky 2015-06-24 767 if (flags & MAP_FIXED)
^1da177e4c3f41 Linus Torvalds 2005-04-16 768 return -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 769
^1da177e4c3f41 Linus Torvalds 2005-04-16 770 if ((flags & MAP_TYPE) != MAP_PRIVATE &&
^1da177e4c3f41 Linus Torvalds 2005-04-16 771 (flags & MAP_TYPE) != MAP_SHARED)
^1da177e4c3f41 Linus Torvalds 2005-04-16 772 return -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 773
f81cff0d4067e4 Mike Frysinger 2006-12-06 774 if (!len)
^1da177e4c3f41 Linus Torvalds 2005-04-16 775 return -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 776
f81cff0d4067e4 Mike Frysinger 2006-12-06 777 /* Careful about overflows.. */
8feae13110d60c David Howells 2009-01-08 778 rlen = PAGE_ALIGN(len);
8feae13110d60c David Howells 2009-01-08 779 if (!rlen || rlen > TASK_SIZE)
f81cff0d4067e4 Mike Frysinger 2006-12-06 780 return -ENOMEM;
f81cff0d4067e4 Mike Frysinger 2006-12-06 781
^1da177e4c3f41 Linus Torvalds 2005-04-16 782 /* offset overflow? */
8feae13110d60c David Howells 2009-01-08 783 if ((pgoff + (rlen >> PAGE_SHIFT)) < pgoff)
f81cff0d4067e4 Mike Frysinger 2006-12-06 784 return -EOVERFLOW;
^1da177e4c3f41 Linus Torvalds 2005-04-16 785
^1da177e4c3f41 Linus Torvalds 2005-04-16 786 if (file) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 787 /* files must support mmap */
72c2d531920048 Al Viro 2013-09-22 788 if (!file->f_op->mmap)
^1da177e4c3f41 Linus Torvalds 2005-04-16 789 return -ENODEV;
^1da177e4c3f41 Linus Torvalds 2005-04-16 790
^1da177e4c3f41 Linus Torvalds 2005-04-16 791 /* work out if what we've got could possibly be shared
^1da177e4c3f41 Linus Torvalds 2005-04-16 792 * - we support chardevs that provide their own "memory"
^1da177e4c3f41 Linus Torvalds 2005-04-16 793 * - we support files/blockdevs that are memory backed
^1da177e4c3f41 Linus Torvalds 2005-04-16 794 */
b4caecd48005fb Christoph Hellwig 2015-01-14 795 if (file->f_op->mmap_capabilities) {
b4caecd48005fb Christoph Hellwig 2015-01-14 796 capabilities = file->f_op->mmap_capabilities(file);
b4caecd48005fb Christoph Hellwig 2015-01-14 797 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 798 /* no explicit capabilities set, so assume some
^1da177e4c3f41 Linus Torvalds 2005-04-16 799 * defaults */
496ad9aa8ef448 Al Viro 2013-01-23 800 switch (file_inode(file)->i_mode & S_IFMT) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 801 case S_IFREG:
^1da177e4c3f41 Linus Torvalds 2005-04-16 802 case S_IFBLK:
b4caecd48005fb Christoph Hellwig 2015-01-14 803 capabilities = NOMMU_MAP_COPY;
^1da177e4c3f41 Linus Torvalds 2005-04-16 804 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 805
^1da177e4c3f41 Linus Torvalds 2005-04-16 806 case S_IFCHR:
^1da177e4c3f41 Linus Torvalds 2005-04-16 807 capabilities =
b4caecd48005fb Christoph Hellwig 2015-01-14 808 NOMMU_MAP_DIRECT |
b4caecd48005fb Christoph Hellwig 2015-01-14 809 NOMMU_MAP_READ |
b4caecd48005fb Christoph Hellwig 2015-01-14 810 NOMMU_MAP_WRITE;
^1da177e4c3f41 Linus Torvalds 2005-04-16 811 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 812
^1da177e4c3f41 Linus Torvalds 2005-04-16 813 default:
^1da177e4c3f41 Linus Torvalds 2005-04-16 814 return -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 815 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 816 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 817
^1da177e4c3f41 Linus Torvalds 2005-04-16 818 /* eliminate any capabilities that we can't support on this
^1da177e4c3f41 Linus Torvalds 2005-04-16 819 * device */
^1da177e4c3f41 Linus Torvalds 2005-04-16 820 if (!file->f_op->get_unmapped_area)
b4caecd48005fb Christoph Hellwig 2015-01-14 821 capabilities &= ~NOMMU_MAP_DIRECT;
6e242a1ceeb1bc Al Viro 2015-03-31 822 if (!(file->f_mode & FMODE_CAN_READ))
b4caecd48005fb Christoph Hellwig 2015-01-14 823 capabilities &= ~NOMMU_MAP_COPY;
^1da177e4c3f41 Linus Torvalds 2005-04-16 824
28d7a6ae92c099 Graff Yang 2009-08-18 825 /* The file shall have been opened with read permission. */
28d7a6ae92c099 Graff Yang 2009-08-18 826 if (!(file->f_mode & FMODE_READ))
28d7a6ae92c099 Graff Yang 2009-08-18 827 return -EACCES;
28d7a6ae92c099 Graff Yang 2009-08-18 828
^1da177e4c3f41 Linus Torvalds 2005-04-16 829 if (flags & MAP_SHARED) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 830 /* do checks for writing, appending and locking */
^1da177e4c3f41 Linus Torvalds 2005-04-16 831 if ((prot & PROT_WRITE) &&
^1da177e4c3f41 Linus Torvalds 2005-04-16 832 !(file->f_mode & FMODE_WRITE))
^1da177e4c3f41 Linus Torvalds 2005-04-16 833 return -EACCES;
^1da177e4c3f41 Linus Torvalds 2005-04-16 834
496ad9aa8ef448 Al Viro 2013-01-23 835 if (IS_APPEND(file_inode(file)) &&
^1da177e4c3f41 Linus Torvalds 2005-04-16 836 (file->f_mode & FMODE_WRITE))
^1da177e4c3f41 Linus Torvalds 2005-04-16 837 return -EACCES;
^1da177e4c3f41 Linus Torvalds 2005-04-16 838
d7a06983a01a33 Jeff Layton 2014-03-10 839 if (locks_verify_locked(file))
^1da177e4c3f41 Linus Torvalds 2005-04-16 840 return -EAGAIN;
^1da177e4c3f41 Linus Torvalds 2005-04-16 841
b4caecd48005fb Christoph Hellwig 2015-01-14 842 if (!(capabilities & NOMMU_MAP_DIRECT))
^1da177e4c3f41 Linus Torvalds 2005-04-16 843 return -ENODEV;
^1da177e4c3f41 Linus Torvalds 2005-04-16 844
^1da177e4c3f41 Linus Torvalds 2005-04-16 845 /* we mustn't privatise shared mappings */
b4caecd48005fb Christoph Hellwig 2015-01-14 846 capabilities &= ~NOMMU_MAP_COPY;
ac7149045d9fcc Choi Gi-yong 2014-04-07 847 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 848 /* we're going to read the file into private memory we
^1da177e4c3f41 Linus Torvalds 2005-04-16 849 * allocate */
b4caecd48005fb Christoph Hellwig 2015-01-14 850 if (!(capabilities & NOMMU_MAP_COPY))
^1da177e4c3f41 Linus Torvalds 2005-04-16 851 return -ENODEV;
^1da177e4c3f41 Linus Torvalds 2005-04-16 852
^1da177e4c3f41 Linus Torvalds 2005-04-16 853 /* we don't permit a private writable mapping to be
^1da177e4c3f41 Linus Torvalds 2005-04-16 854 * shared with the backing device */
^1da177e4c3f41 Linus Torvalds 2005-04-16 855 if (prot & PROT_WRITE)
b4caecd48005fb Christoph Hellwig 2015-01-14 856 capabilities &= ~NOMMU_MAP_DIRECT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 857 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 858
b4caecd48005fb Christoph Hellwig 2015-01-14 859 if (capabilities & NOMMU_MAP_DIRECT) {
b4caecd48005fb Christoph Hellwig 2015-01-14 860 if (((prot & PROT_READ) && !(capabilities & NOMMU_MAP_READ)) ||
b4caecd48005fb Christoph Hellwig 2015-01-14 861 ((prot & PROT_WRITE) && !(capabilities & NOMMU_MAP_WRITE)) ||
b4caecd48005fb Christoph Hellwig 2015-01-14 862 ((prot & PROT_EXEC) && !(capabilities & NOMMU_MAP_EXEC))
3c7b204547bc3d Bernd Schmidt 2010-05-25 863 ) {
b4caecd48005fb Christoph Hellwig 2015-01-14 864 capabilities &= ~NOMMU_MAP_DIRECT;
3c7b204547bc3d Bernd Schmidt 2010-05-25 865 if (flags & MAP_SHARED) {
22cc877b32202b Leon Romanovsky 2015-06-24 866 pr_warn("MAP_SHARED not completely supported on !MMU\n");
3c7b204547bc3d Bernd Schmidt 2010-05-25 867 return -EINVAL;
3c7b204547bc3d Bernd Schmidt 2010-05-25 868 }
3c7b204547bc3d Bernd Schmidt 2010-05-25 869 }
3c7b204547bc3d Bernd Schmidt 2010-05-25 870 }
3c7b204547bc3d Bernd Schmidt 2010-05-25 871
^1da177e4c3f41 Linus Torvalds 2005-04-16 872 /* handle executable mappings and implied executable
^1da177e4c3f41 Linus Torvalds 2005-04-16 873 * mappings */
90f8572b0f021f Eric W. Biederman 2015-06-29 874 if (path_noexec(&file->f_path)) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 875 if (prot & PROT_EXEC)
^1da177e4c3f41 Linus Torvalds 2005-04-16 876 return -EPERM;
ac7149045d9fcc Choi Gi-yong 2014-04-07 877 } else if ((prot & PROT_READ) && !(prot & PROT_EXEC)) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 878 /* handle implication of PROT_EXEC by PROT_READ */
^1da177e4c3f41 Linus Torvalds 2005-04-16 879 if (current->personality & READ_IMPLIES_EXEC) {
b4caecd48005fb Christoph Hellwig 2015-01-14 880 if (capabilities & NOMMU_MAP_EXEC)
^1da177e4c3f41 Linus Torvalds 2005-04-16 @881 prot |= PROT_EXEC;
^1da177e4c3f41 Linus Torvalds 2005-04-16 882 }
ac7149045d9fcc Choi Gi-yong 2014-04-07 883 } else if ((prot & PROT_READ) &&
^1da177e4c3f41 Linus Torvalds 2005-04-16 884 (prot & PROT_EXEC) &&
b4caecd48005fb Christoph Hellwig 2015-01-14 885 !(capabilities & NOMMU_MAP_EXEC)
^1da177e4c3f41 Linus Torvalds 2005-04-16 886 ) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 887 /* backing file is not executable, try to copy */
b4caecd48005fb Christoph Hellwig 2015-01-14 888 capabilities &= ~NOMMU_MAP_DIRECT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 889 }
ac7149045d9fcc Choi Gi-yong 2014-04-07 890 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 891 /* anonymous mappings are always memory backed and can be
^1da177e4c3f41 Linus Torvalds 2005-04-16 892 * privately mapped
^1da177e4c3f41 Linus Torvalds 2005-04-16 893 */
b4caecd48005fb Christoph Hellwig 2015-01-14 894 capabilities = NOMMU_MAP_COPY;
^1da177e4c3f41 Linus Torvalds 2005-04-16 895
^1da177e4c3f41 Linus Torvalds 2005-04-16 896 /* handle PROT_EXEC implication by PROT_READ */
^1da177e4c3f41 Linus Torvalds 2005-04-16 897 if ((prot & PROT_READ) &&
^1da177e4c3f41 Linus Torvalds 2005-04-16 898 (current->personality & READ_IMPLIES_EXEC))
^1da177e4c3f41 Linus Torvalds 2005-04-16 899 prot |= PROT_EXEC;
^1da177e4c3f41 Linus Torvalds 2005-04-16 900 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 901
^1da177e4c3f41 Linus Torvalds 2005-04-16 902 /* allow the security API to have its say */
e5467859f7f79b Al Viro 2012-05-30 903 ret = security_mmap_addr(addr);
^1da177e4c3f41 Linus Torvalds 2005-04-16 904 if (ret < 0)
^1da177e4c3f41 Linus Torvalds 2005-04-16 905 return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 906
^1da177e4c3f41 Linus Torvalds 2005-04-16 907 /* looks okay */
^1da177e4c3f41 Linus Torvalds 2005-04-16 908 *_capabilities = capabilities;
^1da177e4c3f41 Linus Torvalds 2005-04-16 909 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 910 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 911
^1da177e4c3f41 Linus Torvalds 2005-04-16 912 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 913 * we've determined that we can make the mapping, now translate what we
^1da177e4c3f41 Linus Torvalds 2005-04-16 914 * now know into VMA flags
^1da177e4c3f41 Linus Torvalds 2005-04-16 915 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 916 static unsigned long determine_vm_flags(struct file *file,
^1da177e4c3f41 Linus Torvalds 2005-04-16 917 unsigned long prot,
^1da177e4c3f41 Linus Torvalds 2005-04-16 918 unsigned long flags,
^1da177e4c3f41 Linus Torvalds 2005-04-16 919 unsigned long capabilities)
^1da177e4c3f41 Linus Torvalds 2005-04-16 920 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 921 unsigned long vm_flags;
^1da177e4c3f41 Linus Torvalds 2005-04-16 922
e6bfb70959a0ca Dave Hansen 2016-02-12 923 vm_flags = calc_vm_prot_bits(prot, 0) | calc_vm_flag_bits(flags);
^1da177e4c3f41 Linus Torvalds 2005-04-16 924 /* vm_flags |= mm->def_flags; */
^1da177e4c3f41 Linus Torvalds 2005-04-16 925
b4caecd48005fb Christoph Hellwig 2015-01-14 926 if (!(capabilities & NOMMU_MAP_DIRECT)) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 927 /* attempt to share read-only copies of mapped file chunks */
3c7b204547bc3d Bernd Schmidt 2010-05-25 928 vm_flags |= VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
^1da177e4c3f41 Linus Torvalds 2005-04-16 929 if (file && !(prot & PROT_WRITE))
^1da177e4c3f41 Linus Torvalds 2005-04-16 930 vm_flags |= VM_MAYSHARE;
3c7b204547bc3d Bernd Schmidt 2010-05-25 931 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 932 /* overlay a shareable mapping on the backing device or inode
^1da177e4c3f41 Linus Torvalds 2005-04-16 933 * if possible - used for chardevs, ramfs/tmpfs/shmfs and
^1da177e4c3f41 Linus Torvalds 2005-04-16 934 * romfs/cramfs */
b4caecd48005fb Christoph Hellwig 2015-01-14 935 vm_flags |= VM_MAYSHARE | (capabilities & NOMMU_VMFLAGS);
^1da177e4c3f41 Linus Torvalds 2005-04-16 936 if (flags & MAP_SHARED)
3c7b204547bc3d Bernd Schmidt 2010-05-25 937 vm_flags |= VM_SHARED;
^1da177e4c3f41 Linus Torvalds 2005-04-16 938 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 939
^1da177e4c3f41 Linus Torvalds 2005-04-16 940 /* refuse to let anyone share private mappings with this process if
^1da177e4c3f41 Linus Torvalds 2005-04-16 941 * it's being traced - otherwise breakpoints set in it may interfere
^1da177e4c3f41 Linus Torvalds 2005-04-16 942 * with another untraced process
^1da177e4c3f41 Linus Torvalds 2005-04-16 943 */
a288eecce5253c Tejun Heo 2011-06-17 944 if ((flags & MAP_PRIVATE) && current->ptrace)
^1da177e4c3f41 Linus Torvalds 2005-04-16 945 vm_flags &= ~VM_MAYSHARE;
^1da177e4c3f41 Linus Torvalds 2005-04-16 946
^1da177e4c3f41 Linus Torvalds 2005-04-16 947 return vm_flags;
^1da177e4c3f41 Linus Torvalds 2005-04-16 948 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 949
^1da177e4c3f41 Linus Torvalds 2005-04-16 950 /*
8feae13110d60c David Howells 2009-01-08 951 * set up a shared mapping on a file (the driver or filesystem provides and
8feae13110d60c David Howells 2009-01-08 952 * pins the storage)
^1da177e4c3f41 Linus Torvalds 2005-04-16 953 */
8feae13110d60c David Howells 2009-01-08 954 static int do_mmap_shared_file(struct vm_area_struct *vma)
^1da177e4c3f41 Linus Torvalds 2005-04-16 955 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 956 int ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 957
f74ac01520c9f6 Miklos Szeredi 2017-02-20 958 ret = call_mmap(vma->vm_file, vma);
dd8632a12e500a Paul Mundt 2009-01-08 959 if (ret == 0) {
dd8632a12e500a Paul Mundt 2009-01-08 960 vma->vm_region->vm_top = vma->vm_region->vm_end;
645d83c5db970a David Howells 2009-09-24 961 return 0;
dd8632a12e500a Paul Mundt 2009-01-08 962 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 963 if (ret != -ENOSYS)
^1da177e4c3f41 Linus Torvalds 2005-04-16 964 return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 965
3fa30460ea5021 David Howells 2010-03-23 966 /* getting -ENOSYS indicates that direct mmap isn't possible (as
3fa30460ea5021 David Howells 2010-03-23 967 * opposed to tried but failed) so we can only give a suitable error as
3fa30460ea5021 David Howells 2010-03-23 968 * it's not possible to make a private copy if MAP_SHARED was given */
^1da177e4c3f41 Linus Torvalds 2005-04-16 969 return -ENODEV;
^1da177e4c3f41 Linus Torvalds 2005-04-16 970 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 971
^1da177e4c3f41 Linus Torvalds 2005-04-16 972 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 973 * set up a private mapping or an anonymous shared mapping
^1da177e4c3f41 Linus Torvalds 2005-04-16 974 */
8feae13110d60c David Howells 2009-01-08 975 static int do_mmap_private(struct vm_area_struct *vma,
8feae13110d60c David Howells 2009-01-08 976 struct vm_region *region,
645d83c5db970a David Howells 2009-09-24 977 unsigned long len,
645d83c5db970a David Howells 2009-09-24 978 unsigned long capabilities)
^1da177e4c3f41 Linus Torvalds 2005-04-16 979 {
dbc8358c72373d Joonsoo Kim 2014-12-12 980 unsigned long total, point;
^1da177e4c3f41 Linus Torvalds 2005-04-16 981 void *base;
8feae13110d60c David Howells 2009-01-08 982 int ret, order;
^1da177e4c3f41 Linus Torvalds 2005-04-16 983
^1da177e4c3f41 Linus Torvalds 2005-04-16 984 /* invoke the file's mapping function so that it can keep track of
^1da177e4c3f41 Linus Torvalds 2005-04-16 985 * shared mappings on devices or memory
^1da177e4c3f41 Linus Torvalds 2005-04-16 986 * - VM_MAYSHARE will be set if it may attempt to share
^1da177e4c3f41 Linus Torvalds 2005-04-16 987 */
b4caecd48005fb Christoph Hellwig 2015-01-14 988 if (capabilities & NOMMU_MAP_DIRECT) {
f74ac01520c9f6 Miklos Szeredi 2017-02-20 989 ret = call_mmap(vma->vm_file, vma);
dd8632a12e500a Paul Mundt 2009-01-08 990 if (ret == 0) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 991 /* shouldn't return success if we're not sharing */
dd8632a12e500a Paul Mundt 2009-01-08 992 BUG_ON(!(vma->vm_flags & VM_MAYSHARE));
dd8632a12e500a Paul Mundt 2009-01-08 993 vma->vm_region->vm_top = vma->vm_region->vm_end;
645d83c5db970a David Howells 2009-09-24 994 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 995 }
dd8632a12e500a Paul Mundt 2009-01-08 996 if (ret != -ENOSYS)
dd8632a12e500a Paul Mundt 2009-01-08 997 return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 998
^1da177e4c3f41 Linus Torvalds 2005-04-16 999 /* getting an ENOSYS error indicates that direct mmap isn't
^1da177e4c3f41 Linus Torvalds 2005-04-16 1000 * possible (as opposed to tried but failed) so we'll try to
^1da177e4c3f41 Linus Torvalds 2005-04-16 1001 * make a private copy of the data and map that instead */
^1da177e4c3f41 Linus Torvalds 2005-04-16 1002 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1003
8feae13110d60c David Howells 2009-01-08 1004
^1da177e4c3f41 Linus Torvalds 2005-04-16 1005 /* allocate some memory to hold the mapping
^1da177e4c3f41 Linus Torvalds 2005-04-16 1006 * - note that this may not return a page-aligned address if the object
^1da177e4c3f41 Linus Torvalds 2005-04-16 1007 * we're allocating is smaller than a page
^1da177e4c3f41 Linus Torvalds 2005-04-16 1008 */
f67d9b1576c1c6 Bob Liu 2011-05-24 1009 order = get_order(len);
8feae13110d60c David Howells 2009-01-08 @1010 total = 1 << order;
f67d9b1576c1c6 Bob Liu 2011-05-24 1011 point = len >> PAGE_SHIFT;
dd8632a12e500a Paul Mundt 2009-01-08 1012
dbc8358c72373d Joonsoo Kim 2014-12-12 1013 /* we don't want to allocate a power-of-2 sized page set */
22cc877b32202b Leon Romanovsky 2015-06-24 1014 if (sysctl_nr_trim_pages && total - point >= sysctl_nr_trim_pages)
dbc8358c72373d Joonsoo Kim 2014-12-12 1015 total = point;
8feae13110d60c David Howells 2009-01-08 1016
da616534ed7f6e Joonsoo Kim 2015-02-27 1017 base = alloc_pages_exact(total << PAGE_SHIFT, GFP_KERNEL);
dbc8358c72373d Joonsoo Kim 2014-12-12 1018 if (!base)
dbc8358c72373d Joonsoo Kim 2014-12-12 1019 goto enomem;
dbc8358c72373d Joonsoo Kim 2014-12-12 1020
dbc8358c72373d Joonsoo Kim 2014-12-12 1021 atomic_long_add(total, &mmap_pages_allocated);
8feae13110d60c David Howells 2009-01-08 1022
8feae13110d60c David Howells 2009-01-08 1023 region->vm_flags = vma->vm_flags |= VM_MAPPED_COPY;
8feae13110d60c David Howells 2009-01-08 1024 region->vm_start = (unsigned long) base;
f67d9b1576c1c6 Bob Liu 2011-05-24 1025 region->vm_end = region->vm_start + len;
dd8632a12e500a Paul Mundt 2009-01-08 1026 region->vm_top = region->vm_start + (total << PAGE_SHIFT);
8feae13110d60c David Howells 2009-01-08 1027
8feae13110d60c David Howells 2009-01-08 1028 vma->vm_start = region->vm_start;
8feae13110d60c David Howells 2009-01-08 1029 vma->vm_end = region->vm_start + len;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1030
^1da177e4c3f41 Linus Torvalds 2005-04-16 1031 if (vma->vm_file) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 1032 /* read the contents of a file into the copy */
^1da177e4c3f41 Linus Torvalds 2005-04-16 1033 loff_t fpos;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1034
^1da177e4c3f41 Linus Torvalds 2005-04-16 1035 fpos = vma->vm_pgoff;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1036 fpos <<= PAGE_SHIFT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1037
b4bf802a5a6563 Christoph Hellwig 2017-09-01 1038 ret = kernel_read(vma->vm_file, base, len, &fpos);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1039 if (ret < 0)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1040 goto error_free;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1041
^1da177e4c3f41 Linus Torvalds 2005-04-16 1042 /* clear the last little bit */
f67d9b1576c1c6 Bob Liu 2011-05-24 1043 if (ret < len)
f67d9b1576c1c6 Bob Liu 2011-05-24 1044 memset(base + ret, 0, len - ret);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1045
bfd40eaff5abb9 Kirill A. Shutemov 2018-07-26 1046 } else {
bfd40eaff5abb9 Kirill A. Shutemov 2018-07-26 1047 vma_set_anonymous(vma);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1048 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1049
^1da177e4c3f41 Linus Torvalds 2005-04-16 1050 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1051
^1da177e4c3f41 Linus Torvalds 2005-04-16 1052 error_free:
7223bb4a829628 Namhyung Kim 2011-05-24 1053 free_page_series(region->vm_start, region->vm_top);
8feae13110d60c David Howells 2009-01-08 1054 region->vm_start = vma->vm_start = 0;
8feae13110d60c David Howells 2009-01-08 1055 region->vm_end = vma->vm_end = 0;
dd8632a12e500a Paul Mundt 2009-01-08 1056 region->vm_top = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1057 return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1058
^1da177e4c3f41 Linus Torvalds 2005-04-16 1059 enomem:
b1de0d139c97a6 Mitchel Humpherys 2014-06-06 1060 pr_err("Allocation of length %lu from process %d (%s) failed\n",
05ae6fa31874ed Greg Ungerer 2009-01-13 1061 len, current->pid, current->comm);
9af744d743170b Michal Hocko 2017-02-22 1062 show_free_areas(0, NULL);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1063 return -ENOMEM;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1064 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1065
:::::: The code at line 1010 was first introduced by commit
:::::: 8feae13110d60cc6287afabc2887366b0eb226c2 NOMMU: Make VMAs per MM as for MMU-mode linux
:::::: TO: David Howells <dhowells@redhat.com>
:::::: CC: David Howells <dhowells@redhat.com>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37658 bytes --]
next reply other threads:[~2021-11-13 13:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-13 13:49 kernel test robot [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-11-08 14:00 mm/nommu.c:1010:12: warning: The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'int' [clang-analyzer-core.UndefinedBinaryOperatorResult] kernel test robot
2021-08-23 4:10 kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202111132149.EphgbyPT-lkp@intel.com \
--to=lkp@intel.com \
--cc=kbuild@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.