Skip to contentSkip to conversation

x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()

PATCH kernel test robot 3 participants 4 messages Mar 27, 2025 – Apr 2, 2025 Memory management

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: David Hildenbrand <[email protected]>

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 38fec10eb60d687e30c8c6b5420d86e8149f7557]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Hildenbrand/x86-mm-pat-Fix-VM_PAT-handling-when-fork-fails-in-copy_page_range/20250326-032200
base:   38fec10eb60d687e30c8c6b5420d86e8149f7557
patch link:    https://lore.kernel.org/r/20250325191951.471185-1-david%40redhat.com
patch subject: [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()

:::::: branch date: 31 hours ago
:::::: commit date: 31 hours ago
config: hexagon-randconfig-r073-20250327 (https://download.01.org/0day-ci/archive/20250327/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project c2692afc0a92cd5da140dfcdfff7818a5b8ce997)

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
mm/memory.c:1428 copy_page_range() error: uninitialized symbol 'pfn'.

vim +/pfn +1428 mm/memory.c

c56d1b62cce836 Peter Xu                      2022-05-12  1360  
c78f463649d60f Peter Xu                      2020-10-13  1361  int
c78f463649d60f Peter Xu                      2020-10-13  1362  copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma)
^1da177e4c3f41 Linus Torvalds                2005-04-16  1363  {
^1da177e4c3f41 Linus Torvalds                2005-04-16  1364  	pgd_t *src_pgd, *dst_pgd;
c78f463649d60f Peter Xu                      2020-10-13  1365  	unsigned long addr = src_vma->vm_start;
c78f463649d60f Peter Xu                      2020-10-13  1366  	unsigned long end = src_vma->vm_end;
c78f463649d60f Peter Xu                      2020-10-13  1367  	struct mm_struct *dst_mm = dst_vma->vm_mm;
c78f463649d60f Peter Xu                      2020-10-13  1368  	struct mm_struct *src_mm = src_vma->vm_mm;
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1369  	struct mmu_notifier_range range;
ebd5c0670e88d9 David Hildenbrand             2025-03-25  1370  	unsigned long next, pfn;
2ec74c3ef2d8c5 Sagi Grimberg                 2012-10-08  1371  	bool is_cow;
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1372  	int ret;
^1da177e4c3f41 Linus Torvalds                2005-04-16  1373  
c56d1b62cce836 Peter Xu                      2022-05-12  1374  	if (!vma_needs_copy(dst_vma, src_vma))
d992895ba2b27c Nicholas Piggin               2005-08-28  1375  		return 0;
d992895ba2b27c Nicholas Piggin               2005-08-28  1376  
c78f463649d60f Peter Xu                      2020-10-13  1377  	if (is_vm_hugetlb_page(src_vma))
bc70fbf269fdff Peter Xu                      2022-05-12  1378  		return copy_hugetlb_page_range(dst_mm, src_mm, dst_vma, src_vma);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1379  
c78f463649d60f Peter Xu                      2020-10-13  1380  	if (unlikely(src_vma->vm_flags & VM_PFNMAP)) {
ebd5c0670e88d9 David Hildenbrand             2025-03-25  1381  		ret = track_pfn_copy(dst_vma, src_vma, &pfn);
2ab640379a0ab4 [email protected] 2008-12-18  1382  		if (ret)
2ab640379a0ab4 [email protected] 2008-12-18  1383  			return ret;
2ab640379a0ab4 [email protected] 2008-12-18  1384  	}
2ab640379a0ab4 [email protected] 2008-12-18  1385  
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1386  	/*
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1387  	 * We need to invalidate the secondary MMU mappings only when
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1388  	 * there could be a permission downgrade on the ptes of the
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1389  	 * parent mm. And a permission downgrade will only happen if
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1390  	 * is_cow_mapping() returns true.
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1391  	 */
c78f463649d60f Peter Xu                      2020-10-13  1392  	is_cow = is_cow_mapping(src_vma->vm_flags);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1393  
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1394  	if (is_cow) {
7269f999934b28 Jérôme Glisse                 2019-05-13  1395  		mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_PAGE,
7d4a8be0c4b2b7 Alistair Popple               2023-01-10  1396  					0, src_mm, addr, end);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1397  		mmu_notifier_invalidate_range_start(&range);
57efa1fe595769 Jason Gunthorpe               2020-12-14  1398  		/*
57efa1fe595769 Jason Gunthorpe               2020-12-14  1399  		 * Disabling preemption is not needed for the write side, as
57efa1fe595769 Jason Gunthorpe               2020-12-14  1400  		 * the read side doesn't spin, but goes to the mmap_lock.
57efa1fe595769 Jason Gunthorpe               2020-12-14  1401  		 *
57efa1fe595769 Jason Gunthorpe               2020-12-14  1402  		 * Use the raw variant of the seqcount_t write API to avoid
57efa1fe595769 Jason Gunthorpe               2020-12-14  1403  		 * lockdep complaining about preemptibility.
57efa1fe595769 Jason Gunthorpe               2020-12-14  1404  		 */
e727bfd5e73a35 Suren Baghdasaryan            2023-08-04  1405  		vma_assert_write_locked(src_vma);
57efa1fe595769 Jason Gunthorpe               2020-12-14  1406  		raw_write_seqcount_begin(&src_mm->write_protect_seq);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1407  	}
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1408  
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1409  	ret = 0;
^1da177e4c3f41 Linus Torvalds                2005-04-16  1410  	dst_pgd = pgd_offset(dst_mm, addr);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1411  	src_pgd = pgd_offset(src_mm, addr);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1412  	do {
^1da177e4c3f41 Linus Torvalds                2005-04-16  1413  		next = pgd_addr_end(addr, end);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1414  		if (pgd_none_or_clear_bad(src_pgd))
^1da177e4c3f41 Linus Torvalds                2005-04-16  1415  			continue;
c78f463649d60f Peter Xu                      2020-10-13  1416  		if (unlikely(copy_p4d_range(dst_vma, src_vma, dst_pgd, src_pgd,
c78f463649d60f Peter Xu                      2020-10-13  1417  					    addr, next))) {
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1418  			ret = -ENOMEM;
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1419  			break;
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1420  		}
^1da177e4c3f41 Linus Torvalds                2005-04-16  1421  	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1422  
57efa1fe595769 Jason Gunthorpe               2020-12-14  1423  	if (is_cow) {
57efa1fe595769 Jason Gunthorpe               2020-12-14  1424  		raw_write_seqcount_end(&src_mm->write_protect_seq);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1425  		mmu_notifier_invalidate_range_end(&range);
57efa1fe595769 Jason Gunthorpe               2020-12-14  1426  	}
ebd5c0670e88d9 David Hildenbrand             2025-03-25  1427  	if (ret && unlikely(src_vma->vm_flags & VM_PFNMAP))
ebd5c0670e88d9 David Hildenbrand             2025-03-25 @1428  		untrack_pfn_copy(dst_vma, pfn);
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1429  	return ret;
^1da177e4c3f41 Linus Torvalds                2005-04-16  1430  }
^1da177e4c3f41 Linus Torvalds                2005-04-16  1431  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw
Quoted 21 lines · kernel test robot

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: David Hildenbrand <[email protected]>

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 38fec10eb60d687e30c8c6b5420d86e8149f7557]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Hildenbrand/x86-mm-pat-Fix-VM_PAT-handling-when-fork-fails-in-copy_page_range/20250326-032200
base:   38fec10eb60d687e30c8c6b5420d86e8149f7557
patch link:    https://lore.kernel.org/r/20250325191951.471185-1-david%40redhat.com
patch subject: [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()

:::::: branch date: 31 hours ago
:::::: commit date: 31 hours ago
config: hexagon-randconfig-r073-20250327 (https://download.01.org/0day-ci/archive/20250327/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project c2692afc0a92cd5da140dfcdfff7818a5b8ce997)

Quoted 8 lines

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
mm/memory.c:1428 copy_page_range() error: uninitialized symbol 'pfn'.

I have a feeling this is because if ndef __HAVE_PFNMAP_TRACKING you just don't touch pfn at all, but also I see in the new track_pfn_copy() there are code paths where pfn doesn't get set, but you still pass the uninitialised pfn to untrack_pfn_copy()...

I mean it could also be in the case of !(src_vma->vm_flags & VM_PAT) (but & VM_PFNMAP), where we return 0 but still pass pfn to untrack_pfn_copy()...

This is all super icky, we probably want to actually have track_pfn_copy() indicate whether we want to later untrack, not only if there's an error.

Will comment accordingly on patch, but I mean I don't like the idea of us just initialising the pfn here, because... what to?... :)

Quoted 80 lines

vim +/pfn +1428 mm/memory.c

c56d1b62cce836 Peter Xu                      2022-05-12  1360
c78f463649d60f Peter Xu                      2020-10-13  1361  int
c78f463649d60f Peter Xu                      2020-10-13  1362  copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma)
^1da177e4c3f41 Linus Torvalds                2005-04-16  1363  {
^1da177e4c3f41 Linus Torvalds                2005-04-16  1364  	pgd_t *src_pgd, *dst_pgd;
c78f463649d60f Peter Xu                      2020-10-13  1365  	unsigned long addr = src_vma->vm_start;
c78f463649d60f Peter Xu                      2020-10-13  1366  	unsigned long end = src_vma->vm_end;
c78f463649d60f Peter Xu                      2020-10-13  1367  	struct mm_struct *dst_mm = dst_vma->vm_mm;
c78f463649d60f Peter Xu                      2020-10-13  1368  	struct mm_struct *src_mm = src_vma->vm_mm;
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1369  	struct mmu_notifier_range range;
ebd5c0670e88d9 David Hildenbrand             2025-03-25  1370  	unsigned long next, pfn;
2ec74c3ef2d8c5 Sagi Grimberg                 2012-10-08  1371  	bool is_cow;
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1372  	int ret;
^1da177e4c3f41 Linus Torvalds                2005-04-16  1373
c56d1b62cce836 Peter Xu                      2022-05-12  1374  	if (!vma_needs_copy(dst_vma, src_vma))
d992895ba2b27c Nicholas Piggin               2005-08-28  1375  		return 0;
d992895ba2b27c Nicholas Piggin               2005-08-28  1376
c78f463649d60f Peter Xu                      2020-10-13  1377  	if (is_vm_hugetlb_page(src_vma))
bc70fbf269fdff Peter Xu                      2022-05-12  1378  		return copy_hugetlb_page_range(dst_mm, src_mm, dst_vma, src_vma);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1379
c78f463649d60f Peter Xu                      2020-10-13  1380  	if (unlikely(src_vma->vm_flags & VM_PFNMAP)) {
ebd5c0670e88d9 David Hildenbrand             2025-03-25  1381  		ret = track_pfn_copy(dst_vma, src_vma, &pfn);
2ab640379a0ab4 [email protected] 2008-12-18  1382  		if (ret)
2ab640379a0ab4 [email protected] 2008-12-18  1383  			return ret;
2ab640379a0ab4 [email protected] 2008-12-18  1384  	}
2ab640379a0ab4 [email protected] 2008-12-18  1385
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1386  	/*
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1387  	 * We need to invalidate the secondary MMU mappings only when
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1388  	 * there could be a permission downgrade on the ptes of the
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1389  	 * parent mm. And a permission downgrade will only happen if
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1390  	 * is_cow_mapping() returns true.
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1391  	 */
c78f463649d60f Peter Xu                      2020-10-13  1392  	is_cow = is_cow_mapping(src_vma->vm_flags);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1393
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1394  	if (is_cow) {
7269f999934b28 Jérôme Glisse                 2019-05-13  1395  		mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_PAGE,
7d4a8be0c4b2b7 Alistair Popple               2023-01-10  1396  					0, src_mm, addr, end);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1397  		mmu_notifier_invalidate_range_start(&range);
57efa1fe595769 Jason Gunthorpe               2020-12-14  1398  		/*
57efa1fe595769 Jason Gunthorpe               2020-12-14  1399  		 * Disabling preemption is not needed for the write side, as
57efa1fe595769 Jason Gunthorpe               2020-12-14  1400  		 * the read side doesn't spin, but goes to the mmap_lock.
57efa1fe595769 Jason Gunthorpe               2020-12-14  1401  		 *
57efa1fe595769 Jason Gunthorpe               2020-12-14  1402  		 * Use the raw variant of the seqcount_t write API to avoid
57efa1fe595769 Jason Gunthorpe               2020-12-14  1403  		 * lockdep complaining about preemptibility.
57efa1fe595769 Jason Gunthorpe               2020-12-14  1404  		 */
e727bfd5e73a35 Suren Baghdasaryan            2023-08-04  1405  		vma_assert_write_locked(src_vma);
57efa1fe595769 Jason Gunthorpe               2020-12-14  1406  		raw_write_seqcount_begin(&src_mm->write_protect_seq);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1407  	}
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1408
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1409  	ret = 0;
^1da177e4c3f41 Linus Torvalds                2005-04-16  1410  	dst_pgd = pgd_offset(dst_mm, addr);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1411  	src_pgd = pgd_offset(src_mm, addr);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1412  	do {
^1da177e4c3f41 Linus Torvalds                2005-04-16  1413  		next = pgd_addr_end(addr, end);
^1da177e4c3f41 Linus Torvalds                2005-04-16  1414  		if (pgd_none_or_clear_bad(src_pgd))
^1da177e4c3f41 Linus Torvalds                2005-04-16  1415  			continue;
c78f463649d60f Peter Xu                      2020-10-13  1416  		if (unlikely(copy_p4d_range(dst_vma, src_vma, dst_pgd, src_pgd,
c78f463649d60f Peter Xu                      2020-10-13  1417  					    addr, next))) {
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1418  			ret = -ENOMEM;
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1419  			break;
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1420  		}
^1da177e4c3f41 Linus Torvalds                2005-04-16  1421  	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1422
57efa1fe595769 Jason Gunthorpe               2020-12-14  1423  	if (is_cow) {
57efa1fe595769 Jason Gunthorpe               2020-12-14  1424  		raw_write_seqcount_end(&src_mm->write_protect_seq);
ac46d4f3c43241 Jérôme Glisse                 2018-12-28  1425  		mmu_notifier_invalidate_range_end(&range);
57efa1fe595769 Jason Gunthorpe               2020-12-14  1426  	}
ebd5c0670e88d9 David Hildenbrand             2025-03-25  1427  	if (ret && unlikely(src_vma->vm_flags & VM_PFNMAP))
ebd5c0670e88d9 David Hildenbrand             2025-03-25 @1428  		untrack_pfn_copy(dst_vma, pfn);
cddb8a5c14aa89 Andrea Arcangeli              2008-07-28  1429  	return ret;
^1da177e4c3f41 Linus Torvalds                2005-04-16  1430  }
^1da177e4c3f41 Linus Torvalds                2005-04-16  1431

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#2 lore raw
Quoted 22 lines · Lorenzo Stoakes
Quoted 21 lines · kernel test robot

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: David Hildenbrand <[email protected]>

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 38fec10eb60d687e30c8c6b5420d86e8149f7557]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Hildenbrand/x86-mm-pat-Fix-VM_PAT-handling-when-fork-fails-in-copy_page_range/20250326-032200
base:   38fec10eb60d687e30c8c6b5420d86e8149f7557
patch link:    https://lore.kernel.org/r/20250325191951.471185-1-david%40redhat.com
patch subject: [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()

:::::: branch date: 31 hours ago
:::::: commit date: 31 hours ago
config: hexagon-randconfig-r073-20250327 (https://download.01.org/0day-ci/archive/20250327/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project c2692afc0a92cd5da140dfcdfff7818a5b8ce997)

Quoted 8 lines
Quoted 8 lines

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
mm/memory.c:1428 copy_page_range() error: uninitialized symbol 'pfn'.

Huh,

how did the original report not make it into my inbox ? :/

Thanks for replying Lorenzo!

Quoted 5 lines

I have a feeling this is because if ndef __HAVE_PFNMAP_TRACKING you just don't touch pfn at all, but also I see in the new track_pfn_copy() there are code paths where pfn doesn't get set, but you still pass the uninitialised pfn to untrack_pfn_copy()...

If track_pfn_copy() returns 0 and VM_PAT applies, the pfn is set. Otherwise (returns an error), we immediately return from copy_page_range().

So once we reach untrack_pfn_copy() ... the PFN was set.

In case of !__HAVE_PFNMAP_TRACKING the pfn is not set and not used.

Quoted 3 lines

I mean it could also be in the case of !(src_vma->vm_flags & VM_PAT) (but & VM_PFNMAP), where we return 0 but still pass pfn to untrack_pfn_copy()...

I assume that's what it is complaining about, and it doesn't figure out that the parameter is unused.

So likely it's best to just initialize pfn to 0.

Quoted 3 lines

This is all super icky, we probably want to actually have track_pfn_copy() indicate whether we want to later untrack, not only if there's an error.

Sounds overly-complicated. But having a pfn != 0 might work.

Quoted 2 lines
Quoted 1 line

Will comment accordingly on patch, but I mean I don't like the idea of us

just initialising the pfn here, because... what to?... :)

Stared at that code for too long (and I reached a point where the PAT stuff absolutely annoys me).

Thanks!

Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw

Let me try that again as my mail client went crazy...

Actually let me +cc a few more so this isn't lost further :P

Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Lorenzo Stoakes
Quoted 27 lines · kernel test robot

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: David Hildenbrand <[email protected]>

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 38fec10eb60d687e30c8c6b5420d86e8149f7557]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Hildenbrand/x86-mm-pat-Fix-VM_PAT-handling-when-fork-fails-in-copy_page_range/20250326-032200
base:   38fec10eb60d687e30c8c6b5420d86e8149f7557
patch link:    https://lore.kernel.org/r/20250325191951.471185-1-david%40redhat.com
patch subject: [PATCH v3] x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()

:::::: branch date: 31 hours ago
:::::: commit date: 31 hours ago
config: hexagon-randconfig-r073-20250327 (https://download.01.org/0day-ci/archive/20250327/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project c2692afc0a92cd5da140dfcdfff7818a5b8ce997)

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

smatch warnings:
mm/memory.c:1428 copy_page_range() error: uninitialized symbol 'pfn'.

Huh,

how did the original report not make it into my inbox ? :/

Yeah it's odd... maybe broken script?

Quoted 2 lines

Thanks for replying Lorenzo!

NP!

Quoted 24 lines
Quoted 6 lines

I have a feeling this is because if ndef __HAVE_PFNMAP_TRACKING you just don't touch pfn at all, but also I see in the new track_pfn_copy() there are code paths where pfn doesn't get set, but you still pass the uninitialised pfn to untrack_pfn_copy()...

If track_pfn_copy() returns 0 and VM_PAT applies, the pfn is set. Otherwise (returns an error), we immediately return from copy_page_range().

So once we reach untrack_pfn_copy() ... the PFN was set.

In case of !__HAVE_PFNMAP_TRACKING the pfn is not set and not used.

Quoted 3 lines

I mean it could also be in the case of !(src_vma->vm_flags & VM_PAT) (but & VM_PFNMAP), where we return 0 but still pass pfn to untrack_pfn_copy()...

I assume that's what it is complaining about, and it doesn't figure out that the parameter is unused.

So likely it's best to just initialize pfn to 0.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

This is all super icky, we probably want to actually have track_pfn_copy() indicate whether we want to later untrack, not only if there's an error.

Sounds overly-complicated. But having a pfn != 0 might work.

Quoted 1 line
Quoted 1 line

Will comment accordingly on patch, but I mean I don't like the idea of

us

Quoted 1 line

just initialising the pfn here, because... what to?... :)

Sure, I mean for all of above let's have the debate on the main patch I guess so it's in one place...

Quoted 2 lines

Stared at that code for too long (and I reached a point where the PAT stuff absolutely annoys me).

But, also lol. Can. Relate.

Quoted 8 lines

Thanks!

--
Cheers,

David / dhildenb

Cheers, Lorenzo