mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-28 00:32:00 +00:00
9b20e24372
Dan Carpenter reported the following warning:
Commit e3aafd2d35
("mm: pgtable: reclaim empty PTE page in
madvise(MADV_DONTNEED)") from Dec 4, 2024 (linux-next), leads to the
following Smatch static checker warning:
mm/pt_reclaim.c:69 try_to_free_pte()
error: uninitialized symbol 'ptl'.
To fix it, assign an initial value of NULL to the ptl.
Link: https://lkml.kernel.org/r/20241206112348.51570-1-zhengqi.arch@bytedance.com
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-mm/224e6a4e-43b5-4080-bdd8-b0a6fb2f0853@stanley.mountain/
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
72 lines
1.5 KiB
C
72 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/hugetlb.h>
|
|
#include <asm-generic/tlb.h>
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include "internal.h"
|
|
|
|
bool reclaim_pt_is_enabled(unsigned long start, unsigned long end,
|
|
struct zap_details *details)
|
|
{
|
|
return details && details->reclaim_pt && (end - start >= PMD_SIZE);
|
|
}
|
|
|
|
bool try_get_and_clear_pmd(struct mm_struct *mm, pmd_t *pmd, pmd_t *pmdval)
|
|
{
|
|
spinlock_t *pml = pmd_lockptr(mm, pmd);
|
|
|
|
if (!spin_trylock(pml))
|
|
return false;
|
|
|
|
*pmdval = pmdp_get_lockless(pmd);
|
|
pmd_clear(pmd);
|
|
spin_unlock(pml);
|
|
|
|
return true;
|
|
}
|
|
|
|
void free_pte(struct mm_struct *mm, unsigned long addr, struct mmu_gather *tlb,
|
|
pmd_t pmdval)
|
|
{
|
|
pte_free_tlb(tlb, pmd_pgtable(pmdval), addr);
|
|
mm_dec_nr_ptes(mm);
|
|
}
|
|
|
|
void try_to_free_pte(struct mm_struct *mm, pmd_t *pmd, unsigned long addr,
|
|
struct mmu_gather *tlb)
|
|
{
|
|
pmd_t pmdval;
|
|
spinlock_t *pml, *ptl = NULL;
|
|
pte_t *start_pte, *pte;
|
|
int i;
|
|
|
|
pml = pmd_lock(mm, pmd);
|
|
start_pte = pte_offset_map_rw_nolock(mm, pmd, addr, &pmdval, &ptl);
|
|
if (!start_pte)
|
|
goto out_ptl;
|
|
if (ptl != pml)
|
|
spin_lock_nested(ptl, SINGLE_DEPTH_NESTING);
|
|
|
|
/* Check if it is empty PTE page */
|
|
for (i = 0, pte = start_pte; i < PTRS_PER_PTE; i++, pte++) {
|
|
if (!pte_none(ptep_get(pte)))
|
|
goto out_ptl;
|
|
}
|
|
pte_unmap(start_pte);
|
|
|
|
pmd_clear(pmd);
|
|
|
|
if (ptl != pml)
|
|
spin_unlock(ptl);
|
|
spin_unlock(pml);
|
|
|
|
free_pte(mm, addr, tlb, pmdval);
|
|
|
|
return;
|
|
out_ptl:
|
|
if (start_pte)
|
|
pte_unmap_unlock(start_pte, ptl);
|
|
if (ptl != pml)
|
|
spin_unlock(pml);
|
|
}
|