[PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER
David Hildenbrand (Arm)
david at kernel.org
Tue Nov 17 02:10:37 PST 2026
On 11/17/26 00:06, Jeff Xu wrote:
> Hi all,
>
> Currently, GFP_HIGHUSER_MOVABLE includes __GFP_SKIP_KASAN (commits
> c275c5c6d50a, 70c248aca9e7, and 0a54864f8dfb), allowing movable
> userspace page allocations to skip KASAN page unpoisoning on allocation
> and poisoning on free under CONFIG_KASAN_HW_TAGS (ARM64 MTE). However,
> GFP_HIGHUSER does not include __GFP_SKIP_KASAN, even though it shares
> the same kernel-accessibility contract in include/linux/gfp_types.h
> ("for userspace allocations that may be mapped to userspace, do not need
> to be directly accessible by the kernel but that cannot move once in
> use") and differs only by !__GFP_MOVABLE.
>
> Moving __GFP_SKIP_KASAN to GFP_HIGHUSER addresses the performance issue
> below (following up on the earlier drm/panthor discussion [1, 2]). The
> swap issue from that discussion is not addressed by this series:
>
> 1. Performance: For every 4 KB page without __GFP_SKIP_KASAN,
> mte_set_mem_tag_range() tags all 256 16-byte MTE granules (via
> STG/STZG and DC GVA/GZVA) on allocation and again on free. In
> graphics and UI workloads, DMA-BUF (system_heap) and DRM/GPU
> (shmem/TTM) buffers use GFP_HIGHUSER; while steady-state rendering
> reuses buffers, window resizes, surface transitions, and app launches
> synchronously allocate and free tens to hundreds of megabytes (~32 MB
> per 4K RGBA frame) on UI/compositor/render threads. That takes a
> significant share of the 8.3 ms (120 Hz) / 16.7 ms (60 Hz) frame
> budget and thrashes CPU data/MTE tag caches (especially on
> cold-cache free). On Armv9.2-A, skipping KASAN cuts ~32 MB DMA-BUF
> alloc+free latency by ~80% (~98% faster close()) and improves the
> OpenGL score of an app-loading benchmark by 15-23%.
>
> 2. False-positive KASAN report after shmem swap-in readahead [1] (not
> addressed here): when a shmem page is swapped in,
> swap_cluster_readahead() also reads the neighboring swap slots and
> allocates their swap-cache folios with the gfp mask of that shmem
> mapping. A neighboring slot can hold an unrelated page that
> userspace maps with PROT_MTE. If the mask lacks __GFP_SKIP_KASAN,
> that page's folio gets a KASAN tag in page->flags. When its owner
> faults it in, arch_swap_restore() writes the saved userspace tags to
> the memory, but page->flags keeps the KASAN tag. Later kernel
> accesses through page_address() then use a tag that does not match
> the memory and are reported by KASAN.
>
> This series does not fix the readahead path. It only removes one
> way to hit it: shmem mappings that use GFP_HIGHUSER (e.g.
> drm_gem_shmem_helper / panthor) now pass __GFP_SKIP_KASAN to
> readahead, so the neighboring folios no longer get a KASAN tag.
> Shmem mappings with other gfp masks that lack __GFP_SKIP_KASAN
> (e.g. GFP_KERNEL) can still trigger the report. That issue should
> be followed up separately, for example in [1].
>
> What changes for users of GFP_HIGHUSER pages under CONFIG_KASAN_HW_TAGS
> (other KASAN modes are not affected):
>
> - Access through vmap(): nothing changes. Those pointers already carry
> the match-all tag and are not checked today.
> - Access through kmap_local_page() or page_address() (for example
> ramfs): accesses are no longer checked by KASAN, as is already the
> case for GFP_HIGHUSER_MOVABLE pages.
> - Buffers that the kernel itself fills (pipe, FUSE, kexec, RDS) keep
> KASAN checking by using the new GFP_HIGHUSER_KASAN (patches 1-4).
>
> GFP_KERNEL, GFP_USER, slab and vmalloc() allocations are not affected.
>
> Patch 1 adds GFP_HIGHUSER_KASAN
I really don't want us to spread KASAN-related GFP flags in the kernel.
There must be a proper way to abstract this.
Why is GFP_HIGHUSER not sufficient? We were already told that this is memory to
be mapped into user space. Placing data structure on it and handing out pointers
to that would already be a bit questionable.
So what are the ways to avoid GFP_HIGHUSER_KASAN?
--
Cheers,
David
More information about the kexec
mailing list