Skip to contentSkip to conversation

mm/memory.c:1678:67: sparse: sparse: incorrect type in initializer (different base types)

PATCH kernel test robot 2 participants 2 messages Apr 13, 2022

Subsystems (3)
lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   c97e430ab5539993ab2afc6e80deea80aef9d799
commit: afbef99a0e4dfb0eda864ae9d3c78c9d9ed750ba [3841/3955] mm/hugetlb: only drop uffd-wp special pte if required
config: i386-randconfig-s002 (https://download.01.org/0day-ci/archive/20220414/[email protected]/config)
compiler: gcc-11 (Debian 11.2.0-19) 11.2.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=afbef99a0e4dfb0eda864ae9d3c78c9d9ed750ba
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout afbef99a0e4dfb0eda864ae9d3c78c9d9ed750ba
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash fs/hugetlbfs/ mm/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)
mm/memory.c:1238:1: sparse: sparse: symbol 'vma_needs_copy' was not declared. Should it be static?

>> mm/memory.c:1678:67: sparse: sparse: incorrect type in initializer (different base types) @@     expected unsigned long zap_flags @@     got restricted zap_flags_t @@

mm/memory.c:1678:67: sparse: expected unsigned long zap_flags
mm/memory.c:1678:67: sparse: got restricted zap_flags_t
mm/memory.c:1031:17: sparse: sparse: context imbalance in 'copy_pte_range' - different lock contexts for basic block mm/memory.c:1830:16: sparse: sparse: context imbalance in '__get_locked_pte' - different lock contexts for basic block mm/memory.c:1878:9: sparse: sparse: context imbalance in 'insert_page' - different lock contexts for basic block mm/memory.c:2380:17: sparse: sparse: context imbalance in 'remap_pte_range' - different lock contexts for basic block mm/memory.c:2636:17: sparse: sparse: context imbalance in 'apply_to_pte_range' - unexpected unlock mm/memory.c:2925:9: sparse: sparse: context imbalance in 'wp_page_copy' - different lock contexts for basic block mm/memory.c:3277:17: sparse: sparse: context imbalance in 'wp_pfn_shared' - unexpected unlock mm/memory.c:3344:19: sparse: sparse: context imbalance in 'do_wp_page' - different lock contexts for basic block mm/memory.c:5214:5: sparse: sparse: context imbalance in 'follow_invalidate_pte' - wrong count at exit mm/memory.c:5335:23: sparse: sparse: context imbalance in 'follow_pfn' - unexpected unlock mm/memory.c:5365:9: sparse: sparse: context imbalance in 'follow_phys' - unexpected unlock mm/memory.c:5399:9: sparse: sparse: context imbalance in 'generic_access_phys' - unexpected unlock
--

>> mm/hugetlb.c:5013:43: sparse: sparse: restricted zap_flags_t degrades to integer

mm/hugetlb.c:5047:35: sparse: sparse: restricted zap_flags_t degrades to integer
mm/hugetlb.c:460:12: sparse: sparse: context imbalance in 'allocate_file_region_entries' - wrong count at exit mm/hugetlb.c:533:13: sparse: sparse: context imbalance in 'region_add' - wrong count at exit mm/hugetlb.c:600:13: sparse: sparse: context imbalance in 'region_chg' - wrong count at exit mm/hugetlb.c: note: in included file:
include/linux/mm.h:1304:17: sparse: sparse: context imbalance in 'demote_free_huge_page' - unexpected unlock mm/hugetlb.c:4896:20: sparse: sparse: context imbalance in 'move_huge_pte' - different lock contexts for basic block include/linux/mm.h:1165:22: sparse: sparse: context imbalance in 'hugetlb_wp' - unexpected unlock mm/hugetlb.c:6127:25: sparse: sparse: context imbalance in 'follow_hugetlb_page' - different lock contexts for basic block
--

>> fs/hugetlbfs/inode.c:521:41: sparse: sparse: incorrect type in argument 4 (different base types) @@     expected unsigned long zap_flags @@     got restricted zap_flags_t [usertype] @@

fs/hugetlbfs/inode.c:521:41: sparse: expected unsigned long zap_flags
fs/hugetlbfs/inode.c:521:41: sparse: got restricted zap_flags_t [usertype]
fs/hugetlbfs/inode.c:588:39: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected unsigned long zap_flags @@ got restricted zap_flags_t [usertype] @@
fs/hugetlbfs/inode.c:588:39: sparse: expected unsigned long zap_flags
fs/hugetlbfs/inode.c:588:39: sparse: got restricted zap_flags_t [usertype]

vim +1678 mm/memory.c

1642
1643
1644 static void unmap_single_vma(struct mmu_gather *tlb,
1645 struct vm_area_struct *vma, unsigned long start_addr,
1646 unsigned long end_addr,
1647 struct zap_details *details)
1648 {
1649 unsigned long start = max(vma->vm_start, start_addr);
1650 unsigned long end;
1651
1652 if (start >= vma->vm_end)
1653 return;
1654 end = min(vma->vm_end, end_addr);
1655 if (end <= vma->vm_start)
1656 return;
1657
1658 if (vma->vm_file)
1659 uprobe_munmap(vma, start, end);
1660
1661 if (unlikely(vma->vm_flags & VM_PFNMAP))
1662 untrack_pfn(vma, 0, 0);
1663
1664 if (start != end) {
1665 if (unlikely(is_vm_hugetlb_page(vma))) {
1666 /*
1667 * It is undesirable to test vma->vm_file as it
1668 * should be non-null for valid hugetlb area.
1669 * However, vm_file will be NULL in the error
1670 * cleanup path of mmap_region. When
1671 * hugetlbfs ->mmap method fails,
1672 * mmap_region() nullifies vma->vm_file
1673 * before calling this function to clean up.
1674 * Since no pte has actually been setup, it is
1675 * safe to do nothing in this case.
1676 */
1677 if (vma->vm_file) {

> 1678					unsigned long zap_flags = details ?

1679 details->zap_flags : 0;
1680 i_mmap_lock_write(vma->vm_file->f_mapping);
1681 __unmap_hugepage_range_final(tlb, vma, start, end,
1682 NULL, zap_flags);
1683 i_mmap_unlock_write(vma->vm_file->f_mapping);
1684 }
1685 } else
1686 unmap_page_range(tlb, vma, start, end, details);
1687 }
1688 }
1689

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#1 lore raw
Quoted 14 lines · kernel test robot

1664 if (start != end) {
1665 if (unlikely(is_vm_hugetlb_page(vma))) {
1666 /*
1667 * It is undesirable to test vma->vm_file as it
1668 * should be non-null for valid hugetlb area.
1669 * However, vm_file will be NULL in the error
1670 * cleanup path of mmap_region. When
1671 * hugetlbfs ->mmap method fails,
1672 * mmap_region() nullifies vma->vm_file
1673 * before calling this function to clean up.
1674 * Since no pte has actually been setup, it is
1675 * safe to do nothing in this case.
1676 */
1677 if (vma->vm_file) {

Quoted 2 lines
Quoted 1 line

1678 unsigned long zap_flags = details ?

1679 details->zap_flags : 0;

The hugetlb side was overlooked after we re-typed zap_flags into bitmask..

One more patch (attached) needs to be squashed into patch "mm/hugetlb: Only drop uffd-wp special pte if required" to ease the sparse warning, sorry.

Signature · 1 line
Peter Xu

From ebb2908f24a7e2593c84406fe48afcc5923c68c7 Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Wed, 13 Apr 2022 14:50:04 -0400
Subject: [PATCH] fixup! mm/hugetlb: Only drop uffd-wp special pte if required

---
 fs/hugetlbfs/inode.c    | 2 +-
 include/linux/hugetlb.h | 6 +++---
 mm/hugetlb.c            | 6 +++---
 mm/memory.c             | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)
fs/hugetlbfs/inode.c +1 -1
index 8b5b9df2be7d..c0bf65c70ade 100644
@@ -405,7 +405,7 @@ static void remove_huge_page(struct page *page)
 
 static void
 hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end,
-		      unsigned long zap_flags)
+		      zap_flags_t zap_flags)
 {
 	struct vm_area_struct *vma;
 
include/linux/hugetlb.h +3 -3
index 6df51d23b7ee..3568dec16efb 100644
@@ -145,11 +145,11 @@ long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
 			 int *);
 void unmap_hugepage_range(struct vm_area_struct *,
 			  unsigned long, unsigned long, struct page *,
-			  unsigned long);
+			  zap_flags_t);
 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
 			  struct vm_area_struct *vma,
 			  unsigned long start, unsigned long end,
-			  struct page *ref_page, unsigned long zap_flags);
+			  struct page *ref_page, zap_flags_t zap_flags);
 void hugetlb_report_meminfo(struct seq_file *);
 int hugetlb_report_node_meminfo(char *buf, int len, int nid);
 void hugetlb_show_meminfo(void);
@@ -405,7 +405,7 @@ static inline unsigned long hugetlb_change_protection(
 static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb,
 			struct vm_area_struct *vma, unsigned long start,
 			unsigned long end, struct page *ref_page,
-			unsigned long zap_flags)
+			zap_flags_t zap_flags)
 {
 	BUG();
 }
mm/hugetlb.c +3 -3
index e1571179698a..b07a4c6f16f3 100644
@@ -4961,7 +4961,7 @@ int move_hugetlb_page_tables(struct vm_area_struct *vma,
 
 static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
 				   unsigned long start, unsigned long end,
-				   struct page *ref_page, unsigned long zap_flags)
+				   struct page *ref_page, zap_flags_t zap_flags)
 {
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long address;
@@ -5095,7 +5095,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct
 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
 			  struct vm_area_struct *vma, unsigned long start,
 			  unsigned long end, struct page *ref_page,
-			  unsigned long zap_flags)
+			  zap_flags_t zap_flags)
 {
 	__unmap_hugepage_range(tlb, vma, start, end, ref_page, zap_flags);
 
@@ -5114,7 +5114,7 @@ void __unmap_hugepage_range_final(struct mmu_gather *tlb,
 
 void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
 			  unsigned long end, struct page *ref_page,
-			  unsigned long zap_flags)
+			  zap_flags_t zap_flags)
 {
 	struct mmu_gather tlb;
 
mm/memory.c +1 -1
index 8e7f39c651c3..63644a7b5287 100644
@@ -1675,7 +1675,7 @@ static void unmap_single_vma(struct mmu_gather *tlb,
 			 * safe to do nothing in this case.
 			 */
 			if (vma->vm_file) {
-				unsigned long zap_flags = details ?
+				zap_flags_t zap_flags = details ?
 				    details->zap_flags : 0;
 				i_mmap_lock_write(vma->vm_file->f_mapping);
 				__unmap_hugepage_range_final(tlb, vma, start, end,
Signature · 1 line
2.32.0