From: kernel test robot <lkp@intel.com>
To: "Xu Xin (vivo)" <xu.xin@linux.dev>
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
chengming.zhou@linux.dev, david@kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org
Subject: Re: [PATCH v2 2/2] mm/ksm: add initialization helpers for scan_get_next_rmap_item()
Date: Sun, 15 Nov 2026 23:28:28 +0800 [thread overview]
Message-ID: <202611152302.OUfZlgfW-lkp@intel.com> (raw)
In-Reply-To: <20261115080049.132515-1-xu.xin@linux.dev>
Hi Xu,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Xu-Xin-vivo/mm-ksm-extract-helper-functions-for-scan-cycle-cleanup/20261115-160032
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20261115080049.132515-1-xu.xin%40linux.dev
patch subject: [PATCH v2 2/2] mm/ksm: add initialization helpers for scan_get_next_rmap_item()
config: loongarch-defconfig (https://download.01.org/0day-ci/archive/20261115/202611152302.OUfZlgfW-lkp@intel.com/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project ca14e3d05c4e63d6e8103945c86b958ed2f55d5f)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261115/202611152302.OUfZlgfW-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611152302.OUfZlgfW-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> mm/ksm.c:2693:6: warning: variable 'mm_slot' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
2693 | if (scan_should_start_new_cycle()) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/ksm.c:2720:10: note: uninitialized use occurs here
2720 | slot = &mm_slot->slot;
| ^~~~~~~
mm/ksm.c:2693:2: note: remove the 'if' if its condition is always true
2693 | if (scan_should_start_new_cycle()) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/ksm.c:2684:29: note: initialize the variable 'mm_slot' to silence this warning
2684 | struct ksm_mm_slot *mm_slot;
| ^
| = NULL
1 warning generated.
vim +2693 mm/ksm.c
2680
2681 static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
2682 {
2683 struct mm_struct *mm;
2684 struct ksm_mm_slot *mm_slot;
2685 struct mm_slot *slot;
2686 struct vm_area_struct *vma;
2687 struct ksm_rmap_item *rmap_item;
2688 struct vma_iterator vmi;
2689
2690 if (list_empty(&ksm_mm_head.slot.mm_node))
2691 return NULL;
2692
> 2693 if (scan_should_start_new_cycle()) {
2694 advisor_start_scan();
2695 trace_ksm_start_scan(ksm_scan.seqnr, ksm_rmap_items);
2696
2697 /*
2698 * A number of pages can hang around indefinitely in per-cpu
2699 * LRU cache, raised page count preventing write_protect_page
2700 * from merging them. Though it doesn't really matter much,
2701 * it is puzzling to see some stuck in pages_volatile until
2702 * other activity jostles them out, and they also prevented
2703 * LTP's KSM test from succeeding deterministically; so drain
2704 * them here (here rather than on entry to ksm_do_scan(),
2705 * so we don't IPI too often when pages_to_scan is set low).
2706 */
2707 lru_add_drain_all();
2708
2709 ksm_prune_migrate_nodes();
2710 ksm_reset_unstable_trees();
2711
2712 mm_slot = scan_get_first_mm();
2713 if (!mm_slot)
2714 return NULL;
2715 next_mm:
2716 ksm_scan.address = 0;
2717 ksm_scan.rmap_list = &mm_slot->rmap_list;
2718 }
2719
2720 slot = &mm_slot->slot;
2721 mm = slot->mm;
2722 vma_iter_init(&vmi, mm, ksm_scan.address);
2723
2724 mmap_read_lock(mm);
2725 if (ksm_test_exit(mm))
2726 goto no_vmas;
2727
2728 for_each_vma(vmi, vma) {
2729 if (!(vma->vm_flags & VM_MERGEABLE))
2730 continue;
2731 if (ksm_scan.address < vma->vm_start)
2732 ksm_scan.address = vma->vm_start;
2733 if (!vma_has_anon_rmap(vma))
2734 ksm_scan.address = vma->vm_end;
2735
2736 while (ksm_scan.address < vma->vm_end) {
2737 struct ksm_next_page_arg ksm_next_page_arg;
2738 struct page *tmp_page = NULL;
2739 struct folio *folio;
2740
2741 if (ksm_test_exit(mm))
2742 goto no_vmas;
2743
2744 int found;
2745
2746 found = walk_page_range_vma(vma, ksm_scan.address,
2747 vma->vm_end,
2748 &ksm_next_page_ops,
2749 &ksm_next_page_arg);
2750
2751 if (found > 0) {
2752 folio = ksm_next_page_arg.folio;
2753 tmp_page = ksm_next_page_arg.page;
2754 ksm_scan.address = ksm_next_page_arg.addr;
2755 } else {
2756 VM_WARN_ON_ONCE(found < 0);
2757 ksm_scan.address = vma->vm_end - PAGE_SIZE;
2758 }
2759
2760 if (tmp_page) {
2761 flush_anon_page(vma, tmp_page, ksm_scan.address);
2762 flush_dcache_page(tmp_page);
2763 rmap_item = get_next_rmap_item(mm_slot,
2764 ksm_scan.rmap_list, ksm_scan.address);
2765 if (rmap_item) {
2766 ksm_scan.rmap_list =
2767 &rmap_item->rmap_list;
2768
2769 if (should_skip_rmap_item(folio, rmap_item)) {
2770 folio_put(folio);
2771 goto next_page;
2772 }
2773
2774 ksm_scan.address += PAGE_SIZE;
2775 *page = tmp_page;
2776 } else {
2777 folio_put(folio);
2778 }
2779 mmap_read_unlock(mm);
2780 return rmap_item;
2781 }
2782 next_page:
2783 ksm_scan.address += PAGE_SIZE;
2784 cond_resched();
2785 }
2786 }
2787
2788 if (ksm_test_exit(mm)) {
2789 no_vmas:
2790 ksm_scan.address = 0;
2791 ksm_scan.rmap_list = &mm_slot->rmap_list;
2792 }
2793 /*
2794 * Nuke all the rmap_items that are above this current rmap:
2795 * because there were no VM_MERGEABLE vmas with such addresses.
2796 */
2797 remove_trailing_rmap_items(ksm_scan.rmap_list);
2798
2799 spin_lock(&ksm_mmlist_lock);
2800 slot = list_entry(mm_slot->slot.mm_node.next,
2801 struct mm_slot, mm_node);
2802 ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
2803 if (ksm_scan.address == 0) {
2804 /*
2805 * We've completed a full scan of all vmas, holding mmap_lock
2806 * throughout, and found no VM_MERGEABLE: so do the same as
2807 * __ksm_exit does to remove this mm from all our lists now.
2808 * This applies either when cleaning up after __ksm_exit
2809 * (but beware: we can reach here even before __ksm_exit),
2810 * or when all VM_MERGEABLE areas have been unmapped (and
2811 * mmap_lock then protects against race with MADV_MERGEABLE).
2812 */
2813 mm_slot_remove(&mm_slot->slot);
2814 spin_unlock(&ksm_mmlist_lock);
2815
2816 mm_slot_free(mm_slot_cache, mm_slot);
2817 /*
2818 * Only clear MMF_VM_MERGEABLE. We must not clear
2819 * MMF_VM_MERGE_ANY, because for those MMF_VM_MERGE_ANY process,
2820 * perhaps their mm_struct has just been added to ksm_mm_slot
2821 * list, and its process has not yet officially started running
2822 * or has not yet performed mmap/brk to allocate anonymous VMAS.
2823 */
2824 mm_flags_clear(MMF_VM_MERGEABLE, mm);
2825 mmap_read_unlock(mm);
2826 mmdrop(mm);
2827 } else {
2828 mmap_read_unlock(mm);
2829 /*
2830 * mmap_read_unlock(mm) first because after
2831 * spin_unlock(&ksm_mmlist_lock) run, the "mm" may
2832 * already have been freed under us by __ksm_exit()
2833 * because the "mm_slot" is still hashed and
2834 * ksm_scan.mm_slot doesn't point to it anymore.
2835 */
2836 spin_unlock(&ksm_mmlist_lock);
2837 }
2838
2839 /* Repeat until we've completed scanning the whole list */
2840 mm_slot = ksm_scan.mm_slot;
2841 if (mm_slot != &ksm_mm_head)
2842 goto next_mm;
2843
2844 advisor_stop_scan();
2845
2846 trace_ksm_stop_scan(ksm_scan.seqnr, ksm_rmap_items);
2847 ksm_scan.seqnr++;
2848 return NULL;
2849 }
2850
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
prev parent reply other threads:[~2026-11-15 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 7:58 [PATCH v2 0/2] mm/ksm: clean up scan_get_next_rmap_item() initialization Xu Xin (vivo)
2026-11-15 8:00 ` [PATCH v2 1/2] mm/ksm: extract helper functions for scan cycle cleanup Xu Xin (vivo)
2026-11-15 8:00 ` [PATCH v2 2/2] mm/ksm: add initialization helpers for scan_get_next_rmap_item() Xu Xin (vivo)
2026-11-15 15:28 ` kernel test robot [this message]
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=202611152302.OUfZlgfW-lkp@intel.com \
--to=lkp@intel.com \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=llvm@lists.linux.dev \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=xu.xin@linux.dev \
/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.