Jeff Xu
unread,Nov 16, 2026, 6:06:47 PM (3 days ago) Nov 16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Andrew Morton, David Hildenbrand, Vlastimil Babka, Johannes Weiner, Andrey Ryabinin, Jeff Xu, Lorenzo Stoakes, Liam R . Howlett, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Marco Elver, Boris Brezillon, Catalin Marinas, Chia-I Wu, Dev Jain, Evgenii Stepanov, Ian Rickards, Jann Horn, Jeff Vander Stoep, Jeff Xu, Kees Cook, Mark Rutland, Peter Collingbourne, Pierre-Clément Tosi, Ryan Roberts, Tomasz Figa, Will Deacon, Alexander Viro, Christian Brauner, Jan Kara, Miklos Szeredi, Baoquan He, Pasha Tatashin, Pratyush Yadav, Allison Henderson, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, linu...@kvack.org, kasa...@googlegroups.com, linux-ar...@lists.infradead.org, linux-...@vger.kernel.org, fuse-...@lists.linux.dev, ke...@lists.infradead.org, net...@vger.kernel.org, linux...@vger.kernel.org, rds-...@oss.oracle.com, linux-...@vger.kernel.org
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, and Patches 2-4 use it for the pipe
buffer pages of pipe and FUSE, kexec segment pages and RDS message
pages, with no functional change. Patch 5 then moves __GFP_SKIP_KASAN
from GFP_HIGHUSER_MOVABLE to GFP_HIGHUSER. Patch 6 adds a KUnit test
(page_alloc_skip_kasan) verifying the __GFP_SKIP_KASAN page allocation
contract under CONFIG_KASAN_HW_TAGS, and Patch 7 adds one for
GFP_HIGHUSER_KASAN (page_alloc_highuser_kasan).
The conversions come first so that these buffers keep their KASAN
checking at every commit of the series.
Testing: on arm64 with CONFIG_KASAN_HW_TAGS under QEMU (virt,mte=on),
every commit builds and boots, and the KASAN KUnit suite was run with
kasan.mode=sync, async and asymm. The two new tests pass, and each
fails when the property it checks is broken on purpose. vmalloc_oob
and kasan_strings (async and asymm) fail there with or without this
series, and a few other tests fail intermittently under QEMU. The
changed files also build on arm64 with generic and software tag-based
KASAN and without KASAN, and on x86_64 with generic KASAN and without.
The FUSE, kexec and RDS changes are build tested only, and the KUnit
tests were not run on real hardware.
Tooling: an AI coding assistant was used under the author's direction
to audit GFP_HIGHUSER callers, draft GFP_HIGHUSER_KASAN (patch 1),
the subsystem conversions (patches 2-4), the page_alloc_highuser_kasan
test (patch 7), and the revised skip-test helper (patch 6), and revise
patch 5's changelog and this cover letter. It also scripted and ran the
builds and QEMU KUnit tests above.
Feedback and thoughts -- particularly on whether any other bare
GFP_HIGHUSER caller using kmap_local_page() would prefer opting back
into KASAN via GFP_HIGHUSER_KASAN -- are very welcome.
Link:
https://lore.kernel.org/r/20260519-panthor-kas...@gmail.com/ [1]
Link:
https://lore.kernel.org/r/20260521105148.5497c281@fedora/ [2]
Jeff Xu (7):
mm: add GFP_HIGHUSER_KASAN
pipe, fuse: use GFP_HIGHUSER_KASAN for pipe buffer pages
kexec: use GFP_HIGHUSER_KASAN for segment pages
net/rds: use GFP_HIGHUSER_KASAN for message pages
mm: kasan: skip KASAN for GFP_HIGHUSER
mm/kasan/kunit: add page_alloc_skip_kasan test
mm/kasan/kunit: add page_alloc_highuser_kasan test
fs/fuse/dev.c | 2 +-
fs/pipe.c | 4 +--
include/linux/gfp_types.h | 15 ++++++--
kernel/kexec_core.c | 2 +-
mm/kasan/kasan_test_c.c | 72 +++++++++++++++++++++++++++++++++++++++
net/rds/ib_recv.c | 2 +-
net/rds/message.c | 2 +-
7 files changed, 91 insertions(+), 8 deletions(-)
base-commit: 4b028d0cedf95f66b8c5294fde2d7d698bf830da
--
2.56.0.611.g1030f0b940-goog