[rcu:willy-maple 175/202] mm/ksm.c:979 unmerge_and_remove_all_rmap_items() error: uninitialized symbol 'mm'.

From: Dan Carpenter
Date: Thu Feb 04 2021 - 02:18:36 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git willy-maple
head: 7e346d2845b4bd77663394f39fa70456e0084c86
commit: 3fd77bfa4f25fa2e3caec024c69168bf6a0ca8d7 [175/202] mm/ksm: Use maple tree iterators instead of vma linked list
config: x86_64-randconfig-m001-20210202 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

smatch warnings:
mm/ksm.c:979 unmerge_and_remove_all_rmap_items() error: uninitialized symbol 'mm'.

vim +/mm +979 mm/ksm.c

d952b79136a6c3 Hugh Dickins 2009-09-21 965 static int unmerge_and_remove_all_rmap_items(void)
31dbd01f314364 Izik Eidus 2009-09-21 966 {
31dbd01f314364 Izik Eidus 2009-09-21 967 struct mm_slot *mm_slot;
31dbd01f314364 Izik Eidus 2009-09-21 968 struct mm_struct *mm;
31dbd01f314364 Izik Eidus 2009-09-21 969 struct vm_area_struct *vma;
d952b79136a6c3 Hugh Dickins 2009-09-21 970 int err = 0;
31dbd01f314364 Izik Eidus 2009-09-21 971
d952b79136a6c3 Hugh Dickins 2009-09-21 972 spin_lock(&ksm_mmlist_lock);
9ba6929480088a Hugh Dickins 2009-09-21 973 ksm_scan.mm_slot = list_entry(ksm_mm_head.mm_list.next,
d952b79136a6c3 Hugh Dickins 2009-09-21 974 struct mm_slot, mm_list);
d952b79136a6c3 Hugh Dickins 2009-09-21 975 spin_unlock(&ksm_mmlist_lock);
d952b79136a6c3 Hugh Dickins 2009-09-21 976
9ba6929480088a Hugh Dickins 2009-09-21 977 for (mm_slot = ksm_scan.mm_slot;
3fd77bfa4f25fa Liam R. Howlett 2021-01-04 978 mm_slot != &ksm_mm_head; mm_slot = ksm_scan.mm_slot, mm = mm_slot->mm) {
3fd77bfa4f25fa Liam R. Howlett 2021-01-04 @979 MA_STATE(mas, &mm->mm_mt, 0, 0);
^^
Not initialized on the first iteration through the loop?

3fd77bfa4f25fa Liam R. Howlett 2021-01-04 980
d8ed45c5dcd455 Michel Lespinasse 2020-06-08 981 mmap_read_lock(mm);
3fd77bfa4f25fa Liam R. Howlett 2021-01-04 982 mas_set(&mas, 0);
3fd77bfa4f25fa Liam R. Howlett 2021-01-04 983 mas_for_each(&mas, vma, ULONG_MAX) {
9ba6929480088a Hugh Dickins 2009-09-21 984 if (ksm_test_exit(mm))
9ba6929480088a Hugh Dickins 2009-09-21 985 break;
31dbd01f314364 Izik Eidus 2009-09-21 986 if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
31dbd01f314364 Izik Eidus 2009-09-21 987 continue;
d952b79136a6c3 Hugh Dickins 2009-09-21 988 err = unmerge_ksm_pages(vma,
d952b79136a6c3 Hugh Dickins 2009-09-21 989 vma->vm_start, vma->vm_end);
9ba6929480088a Hugh Dickins 2009-09-21 990 if (err)
9ba6929480088a Hugh Dickins 2009-09-21 991 goto error;
31dbd01f314364 Izik Eidus 2009-09-21 992 }
9ba6929480088a Hugh Dickins 2009-09-21 993
6514d511dbe5a7 Hugh Dickins 2009-12-14 994 remove_trailing_rmap_items(mm_slot, &mm_slot->rmap_list);
d8ed45c5dcd455 Michel Lespinasse 2020-06-08 995 mmap_read_unlock(mm);
d952b79136a6c3 Hugh Dickins 2009-09-21 996
d952b79136a6c3 Hugh Dickins 2009-09-21 997 spin_lock(&ksm_mmlist_lock);
9ba6929480088a Hugh Dickins 2009-09-21 998 ksm_scan.mm_slot = list_entry(mm_slot->mm_list.next,
d952b79136a6c3 Hugh Dickins 2009-09-21 999 struct mm_slot, mm_list);
9ba6929480088a Hugh Dickins 2009-09-21 1000 if (ksm_test_exit(mm)) {
4ca3a69bcb6875 Sasha Levin 2013-02-22 1001 hash_del(&mm_slot->link);
9ba6929480088a Hugh Dickins 2009-09-21 1002 list_del(&mm_slot->mm_list);
9ba6929480088a Hugh Dickins 2009-09-21 1003 spin_unlock(&ksm_mmlist_lock);
9ba6929480088a Hugh Dickins 2009-09-21 1004
9ba6929480088a Hugh Dickins 2009-09-21 1005 free_mm_slot(mm_slot);
9ba6929480088a Hugh Dickins 2009-09-21 1006 clear_bit(MMF_VM_MERGEABLE, &mm->flags);
9ba6929480088a Hugh Dickins 2009-09-21 1007 mmdrop(mm);
7496fea9a6bf64 Zhou Chengming 2016-05-12 1008 } else
d952b79136a6c3 Hugh Dickins 2009-09-21 1009 spin_unlock(&ksm_mmlist_lock);
31dbd01f314364 Izik Eidus 2009-09-21 1010 }
31dbd01f314364 Izik Eidus 2009-09-21 1011
cbf86cfe04a664 Hugh Dickins 2013-02-22 1012 /* Clean up stable nodes, but don't worry if some are still busy */
cbf86cfe04a664 Hugh Dickins 2013-02-22 1013 remove_all_stable_nodes();
d952b79136a6c3 Hugh Dickins 2009-09-21 1014 ksm_scan.seqnr = 0;
9ba6929480088a Hugh Dickins 2009-09-21 1015 return 0;
9ba6929480088a Hugh Dickins 2009-09-21 1016
9ba6929480088a Hugh Dickins 2009-09-21 1017 error:
d8ed45c5dcd455 Michel Lespinasse 2020-06-08 1018 mmap_read_unlock(mm);
31dbd01f314364 Izik Eidus 2009-09-21 1019 spin_lock(&ksm_mmlist_lock);
31dbd01f314364 Izik Eidus 2009-09-21 1020 ksm_scan.mm_slot = &ksm_mm_head;
31dbd01f314364 Izik Eidus 2009-09-21 1021 spin_unlock(&ksm_mmlist_lock);
d952b79136a6c3 Hugh Dickins 2009-09-21 1022 return err;
31dbd01f314364 Izik Eidus 2009-09-21 1023 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip