Skip to content

Commit 8c56c5d

Browse files
davidhildenbrandakpm00
authored andcommitted
mm: (un)track_pfn_copy() fix + doc improvements
We got a late smatch warning and some additional review feedback. smatch warnings: mm/memory.c:1428 copy_page_range() error: uninitialized symbol 'pfn'. We actually use the pfn only when it is properly initialized; however, we may pass an uninitialized value to a function -- although it will not use it that likely still is UB in C. So let's just fix it by always initializing pfn in the caller of track_pfn_copy(), and improving the documentation of track_pfn_copy(). While at it, clarify the doc of untrack_pfn_copy(), that internal checks make sure if we actually have to untrack anything. Link: https://lkml.kernel.org/r/20250408085950.976103-1-david@redhat.com Fixes: dc84bc2 ("x86/mm/pat: Fix VM_PAT handling when fork() fails in copy_page_range()") Signed-off-by: David Hildenbrand <david@redhat.com> Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/r/202503270941.IFILyNCX-lkp@intel.com/ Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Acked-by: Ingo Molnar <mingo@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Borislav Petkov <bp@alien8.de> Cc: Rik van Riel <riel@surriel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8ab1b16 commit 8c56c5d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

include/linux/pgtable.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,9 @@ static inline void track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot,
15111511

15121512
/*
15131513
* track_pfn_copy is called when a VM_PFNMAP VMA is about to get the page
1514-
* tables copied during copy_page_range(). On success, stores the pfn to be
1515-
* passed to untrack_pfn_copy().
1514+
* tables copied during copy_page_range(). Will store the pfn to be
1515+
* passed to untrack_pfn_copy() only if there is something to be untracked.
1516+
* Callers should initialize the pfn to 0.
15161517
*/
15171518
static inline int track_pfn_copy(struct vm_area_struct *dst_vma,
15181519
struct vm_area_struct *src_vma, unsigned long *pfn)
@@ -1522,7 +1523,9 @@ static inline int track_pfn_copy(struct vm_area_struct *dst_vma,
15221523

15231524
/*
15241525
* untrack_pfn_copy is called when a VM_PFNMAP VMA failed to copy during
1525-
* copy_page_range(), but after track_pfn_copy() was already called.
1526+
* copy_page_range(), but after track_pfn_copy() was already called. Can
1527+
* be called even if track_pfn_copy() did not actually track anything:
1528+
* handled internally.
15261529
*/
15271530
static inline void untrack_pfn_copy(struct vm_area_struct *dst_vma,
15281531
unsigned long pfn)

mm/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma)
13611361
struct mm_struct *dst_mm = dst_vma->vm_mm;
13621362
struct mm_struct *src_mm = src_vma->vm_mm;
13631363
struct mmu_notifier_range range;
1364-
unsigned long next, pfn;
1364+
unsigned long next, pfn = 0;
13651365
bool is_cow;
13661366
int ret;
13671367

0 commit comments

Comments
 (0)