Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/kasan: use pXd_leaf() in shadow_mapped()

There is an old trick in shadow_mapped() to use pXd_bad() to detect huge
pages. After commit 93fab1b22ef7 ("mm: add generic p?d_leaf() macros") we
have a global API for huge mappings. Use that to replace the trick.

Link: https://lkml.kernel.org/r/20240305043750.93762-7-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yang Shi <shy828301@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Peter Xu and committed by
Andrew Morton
b6c9d5a9 924bd6a8

+2 -9
+2 -9
mm/kasan/shadow.c
··· 199 199 pud = pud_offset(p4d, addr); 200 200 if (pud_none(*pud)) 201 201 return false; 202 - 203 - /* 204 - * We can't use pud_large() or pud_huge(), the first one is 205 - * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse 206 - * pud_bad(), if pud is bad then it's bad because it's huge. 207 - */ 208 - if (pud_bad(*pud)) 202 + if (pud_leaf(*pud)) 209 203 return true; 210 204 pmd = pmd_offset(pud, addr); 211 205 if (pmd_none(*pmd)) 212 206 return false; 213 - 214 - if (pmd_bad(*pmd)) 207 + if (pmd_leaf(*pmd)) 215 208 return true; 216 209 pte = pte_offset_kernel(pmd, addr); 217 210 return !pte_none(ptep_get(pte));