Re: [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER

From: David Hildenbrand (Arm)

Date: Tue Nov 17 2026 - 07:07:36 EST


On 11/17/26 11:21, Lorenzo Stoakes (ARM) wrote:
> On Mon, Nov 16, 2026 at 03:06:25PM -0800, Jeff Xu wrote:
>> Move __GFP_SKIP_KASAN from GFP_HIGHUSER_MOVABLE to GFP_HIGHUSER so that
>> both GFP_HIGHUSER and GFP_HIGHUSER_MOVABLE allocations skip KASAN
>> unpoisoning on allocation and poisoning on free in HW_TAGS mode.
>>
>> Previously, commit c275c5c6d50a ("kasan: disable freed user page
>> poisoning with HW tags"), commit 70c248aca9e7 ("mm: kasan: Skip
>> unpoisoning of user pages"), and commit 0a54864f8dfb ("kasan: remove
>> PG_skip_kasan_poison flag") added __GFP_SKIP_KASAN to
>> GFP_HIGHUSER_MOVABLE because user pages are not intended to be used as
>> directly addressable kernel data structures, and the lower likelihood of
>> catching a kernel linear-map bug on user payload pages does not justify
>> tagging all 256 16-byte MTE granules per 4 KB page on every allocation
>> and free.
>>
>> GFP_HIGHUSER 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"). The only semantic difference between
>> GFP_HIGHUSER and GFP_HIGHUSER_MOVABLE is __GFP_MOVABLE.
>>
>> For every 4 KB page without __GFP_SKIP_KASAN under CONFIG_KASAN_HW_TAGS,
>> mte_set_mem_tag_range() tags all 256 16-byte MTE granules (via STG/STZG
>> and DC GVA/GZVA) on allocation (__kasan_unpoison_pages) and again on
>> free (__kasan_poison_pages). For users of GFP_HIGHUSER, this can
>> significantly impact performance when allocating and freeing large
>> buffers. For example, in graphics and interactive UI workloads, large
>> DMA-BUF and DRM/GPU buffers are allocated with GFP_HIGHUSER: while
>> steady-state rendering reuses swapchain buffers, UI window resizes,
>> surface creation/teardown, and app or scene launches synchronously
>> allocate and release tens to hundreds of megabytes of DMA-BUF
>> framebuffers (~32 MB per 4K RGBA frame, or ~96 MB for a triple-buffered
>> surface) and GPU shmem pools directly on UI, compositor, and render
>> threads. Touching millions of 16-byte granules stalls these critical
>> threads for milliseconds per buffer, a significant share of the 8.3 ms
>> (120 Hz) / 16.7 ms (60 Hz) frame budget, while polluting CPU L1/L2 data
>> and MTE tag caches, evicting hot working-set cachelines, and saturating
>> DRAM bandwidth (especially on free when DMA pages are cold in the CPU
>> cache).
>>
>> GFP_HIGHUSER is used by subsystems such as the DMA-BUF system heap, DRM
>> GEM shmem/TTM and non-movable HugeTLB. They use it instead of
>> GFP_HIGHUSER_MOVABLE only because their pages are pinned for DMA or
>> cannot migrate.
>>
>> What skipping KASAN means for the kernel's own accesses to these pages:
>>
>> - Through vmap(): nothing changes. With CONFIG_KASAN_HW_TAGS those
>> pointers already carry the match-all tag, so the page tags never
>> protected these accesses.
>> - Through kmap_local_page() or page_address() (for example ramfs):
>> post_alloc_hook() now gives the pages the match-all tag, so these
>> accesses are no longer checked. GFP_HIGHUSER_MOVABLE pages already
>> behave this way. Callers that want to keep the checks use
>> GFP_HIGHUSER_KASAN: the previous patches in this series converted
>> pipe, FUSE, kexec and RDS, and backports of this patch should
>> include them.
>>
>> Slab allocations cannot use GFP_HIGHUSER, because they do not accept
>> __GFP_HIGHMEM. GFP_KERNEL, GFP_USER and vmalloc() allocations are not
>> affected.
>>
>> This patch does not address the false-positive KASAN report after shmem
>> swap-in readahead with MTE that was reported on drm/panthor [1, 2].
>> There, swap_cluster_readahead() allocates swap-cache folios for
>> neighboring swap slots with the gfp mask of the shmem mapping being
>> swapped in. If such a slot holds a page that userspace maps with
>> PROT_MTE, the folio keeps a KASAN tag in page->flags that does not
>> match the userspace tags restored by arch_swap_restore().
>>
>> This patch only removes one way to hit it: shmem mappings that use
>> GFP_HIGHUSER (such as drm_gem_shmem_helper or panthor) now pass
>> __GFP_SKIP_KASAN to readahead, so the neighboring folios no longer get
>> a KASAN tag. The readahead path itself is unchanged, and shmem mappings
>> with other gfp masks that lack __GFP_SKIP_KASAN can still trigger the
>> report. That issue should be followed up separately, for example in
>> [1].
>>
>> On an Armv9.2-A device running a 6.12-based kernel with kasan.mode=sync,
>> this reduces the allocation + release time of a ~32 MB buffer from
>> /dev/dma_heap/system by ~80%: allocation is ~59% faster and release ~98%
>> faster. Poisoning on free accounted for ~55% of the total before. In an
>> application loading benchmark, the OpenGL score improves by 15-23%,
>> recovering 60-80% of the regression that enabling MTE causes.
>>
>
> This commit message is just inscrutable. It's like reading Finnegan's Wake :)
> LLMs are obscenely terrible at this stuff unfortunately.

I truly wonder how some can decide to submit something like that with their name
under it :)

--
Cheers,

David