Use kasan_unpoison_pages() on the leading whole page(s) of ranges that are page-aligned, which is very common with vmalloc() allocations. Signed-off-by: Pierre-Clément Tosi --- mm/kasan/hw_tags.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 8efe6b1f88a7..c25268b76569 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -331,6 +331,7 @@ void *__kasan_unpoison_vmalloc(const void *start, unsigned long size, kasan_vmalloc_flags_t flags) { bool init = flags & KASAN_VMALLOC_INIT; + const void *pos; u8 tag; if (!kasan_vmalloc_enabled()) { @@ -374,16 +375,26 @@ void *__kasan_unpoison_vmalloc(const void *start, unsigned long size, tag = (flags & KASAN_VMALLOC_KEEP_TAG) ? get_tag(start) : kasan_random_tag(); start = set_tag(start, tag); + pos = start; /* Unpoison and initialize memory up to size. */ - kasan_unpoison(start, size, init); + if (PAGE_ALIGNED(pos)) { + unsigned long nr_pages; + + size = round_up(size, KASAN_GRANULE_SIZE); + nr_pages = size >> PAGE_SHIFT; + kasan_unpoison_pages(pos, nr_pages, init); + pos += nr_pages << PAGE_SHIFT; + size &= ~PAGE_MASK; + } + kasan_unpoison(pos, size, init); /* * Explicitly poison and initialize the in-page vmalloc() redzone. * Unlike software KASAN modes, hardware tag-based KASAN doesn't * unpoison memory when populating shadow for vmalloc() space. */ - poison_redzone(start + size, init); + poison_redzone(pos + size, init); /* * Set per-page tag flags to allow accessing physical memory for the -- 2.56.1.839.g22a8290db9-goog