Netdev List
 help / color / mirror / Atom feed
* [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER
@ 2026-11-16 23:06 Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 1/7] mm: add GFP_HIGHUSER_KASAN Jeff Xu
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

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-kasan-v2-1-b7384458f076@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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v1 1/7] mm: add GFP_HIGHUSER_KASAN
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 2/7] pipe, fuse: use GFP_HIGHUSER_KASAN for pipe buffer pages Jeff Xu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

A later patch in this series adds __GFP_SKIP_KASAN to GFP_HIGHUSER, so
that with CONFIG_KASAN_HW_TAGS its pages are neither tagged on
allocation nor poisoned on free. That suits pages whose contents belong
to userspace and are mapped there.

Some GFP_HIGHUSER users allocate buffers that the kernel itself fills
and drains through kmap_local_page(), such as pipe buffers. While such
pages are tagged, KASAN can report a linear overflow out of the page
and an access to it while it is free.

Add GFP_HIGHUSER_KASAN for these users, so that they can be converted
before GFP_HIGHUSER changes. It has the value GFP_HIGHUSER has today
and will not gain __GFP_SKIP_KASAN. The two stay identical without
CONFIG_KASAN_HW_TAGS, where __GFP_SKIP_KASAN is 0.

GFP_HIGHUSER_KASAN must not be used for memory that userspace can map
with PROT_MTE (anonymous, shmem and hugetlb pages). Userspace sets the
memory tags of such a page, while the kernel keeps accessing it through
page_address() with the KASAN tag from page->flags. The two do not
match, and kernel accesses are reported as KASAN faults. arm64 does not
reset the tag in page->flags when the page is mapped; it relies on the
page having been allocated with __GFP_SKIP_KASAN. Nothing checks for
misuse at allocation or mapping time.

No functional change. The kernel-doc describes GFP_HIGHUSER as it will
be once it skips KASAN tagging.

Assisted-by: LLM
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 include/linux/gfp_types.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h
index c1331bf0b239..567c93fc1cfb 100644
--- a/include/linux/gfp_types.h
+++ b/include/linux/gfp_types.h
@@ -356,6 +356,16 @@ enum {
  * move once in use. An example may be a hardware allocation that maps
  * data directly into userspace but has no addressing limitations.
  *
+ * %GFP_HIGHUSER_KASAN is %GFP_HIGHUSER for pages that the kernel itself reads
+ * and writes, such as pipe buffers. Unlike %GFP_HIGHUSER it does not skip
+ * KASAN tagging: with CONFIG_KASAN_HW_TAGS the pages get a KASAN tag, which
+ * page_address() and kmap_local_page() return in the pointer. It must not be
+ * used for memory that userspace can map with PROT_MTE (anonymous, shmem and
+ * hugetlb pages). Userspace sets the memory tags of such a page, so the
+ * kernel's tagged pointer no longer matches them and kernel accesses to the
+ * page are reported as KASAN faults. Nothing checks for this at allocation
+ * or mapping time; those reports are the only sign of misuse.
+ *
  * %GFP_HIGHUSER_MOVABLE is for userspace allocations that the kernel does not
  * need direct access to but can use kmap() when access is required. They
  * are expected to be movable via page reclaim or page migration. Typically,
@@ -377,6 +387,7 @@ enum {
 #define GFP_DMA		__GFP_DMA
 #define GFP_DMA32	__GFP_DMA32
 #define GFP_HIGHUSER	(GFP_USER | __GFP_HIGHMEM)
+#define GFP_HIGHUSER_KASAN	(GFP_USER | __GFP_HIGHMEM)
 #define GFP_HIGHUSER_MOVABLE	(GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKIP_KASAN)
 #define GFP_TRANSHUGE_LIGHT	((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
 			 __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM)

base-commit: 4b028d0cedf95f66b8c5294fde2d7d698bf830da
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 2/7] pipe, fuse: use GFP_HIGHUSER_KASAN for pipe buffer pages
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 1/7] mm: add GFP_HIGHUSER_KASAN Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 3/7] kexec: use GFP_HIGHUSER_KASAN for segment pages Jeff Xu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

Pipe buffer pages hold data in transit. Pipe writes allocate them, and
the kernel fills and drains them through kmap_local_page(). The same
holds for the page fuse_copy_fill() allocates when a request is spliced
from /dev/fuse into a pipe.

Allocate them with GFP_HIGHUSER_KASAN, so that they keep their KASAN
tagging when GFP_HIGHUSER starts to skip it later in this series.

No functional change: GFP_HIGHUSER_KASAN has the same value as
GFP_HIGHUSER at this point.

Assisted-by: LLM
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org
Cc: fuse-devel@lists.linux.dev
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 fs/fuse/dev.c | 2 +-
 fs/pipe.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 3641abb90d6b..fdcb11679dbb 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1044,7 +1044,7 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
 			if (cs->nr_segs >= cs->pipe->max_usage)
 				return -EIO;
 
-			page = alloc_page(GFP_HIGHUSER);
+			page = alloc_page(GFP_HIGHUSER_KASAN);
 			if (!page)
 				return -ENOMEM;
 
diff --git a/fs/pipe.c b/fs/pipe.c
index 4fa69192e6fb..87792ef63564 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -155,7 +155,7 @@ static void anon_pipe_prefill_and_lock(struct pipe_inode_info *pipe, size_t tota
 	}
 
 	while (n < need) {
-		struct page *page = alloc_page(GFP_HIGHUSER | __GFP_ACCOUNT);
+		struct page *page = alloc_page(GFP_HIGHUSER_KASAN | __GFP_ACCOUNT);
 
 		if (!page)
 			break;
@@ -201,7 +201,7 @@ static struct page *anon_pipe_get_page(struct pipe_inode_info *pipe)
 		return page;
 
 	/* FWIW: This is called with pipe->mutex held */
-	return alloc_page(GFP_HIGHUSER | __GFP_ACCOUNT);
+	return alloc_page(GFP_HIGHUSER_KASAN | __GFP_ACCOUNT);
 }
 
 static void anon_pipe_put_page(struct pipe_inode_info *pipe,
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 3/7] kexec: use GFP_HIGHUSER_KASAN for segment pages
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 1/7] mm: add GFP_HIGHUSER_KASAN Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 2/7] pipe, fuse: use GFP_HIGHUSER_KASAN for pipe buffer pages Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 4/7] net/rds: use GFP_HIGHUSER_KASAN for message pages Jeff Xu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

kimage_load_normal_segment() allocates the pages that hold the segments
of the next kernel. The kernel clears and fills them through
kmap_local_page(), and they are never mapped into userspace.

Allocate them with GFP_HIGHUSER_KASAN, so that they keep their KASAN
tagging when GFP_HIGHUSER starts to skip it later in this series.

No functional change: GFP_HIGHUSER_KASAN has the same value as
GFP_HIGHUSER at this point. Build tested only.

Assisted-by: LLM
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: kexec@lists.infradead.org
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 kernel/kexec_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index f4a31565c447..a3abbb6a2d75 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -839,7 +839,7 @@ static int kimage_load_normal_segment(struct kimage *image, int idx)
 		char *ptr;
 		size_t uchunk, mchunk;
 
-		page = kimage_alloc_page(image, GFP_HIGHUSER, maddr);
+		page = kimage_alloc_page(image, GFP_HIGHUSER_KASAN, maddr);
 		if (!page) {
 			result  = -ENOMEM;
 			goto out;
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 4/7] net/rds: use GFP_HIGHUSER_KASAN for message pages
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
                   ` (2 preceding siblings ...)
  2026-11-16 23:06 ` [PATCH v1 3/7] kexec: use GFP_HIGHUSER_KASAN for segment pages Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

RDS allocates the pages that carry message payload with GFP_HIGHUSER:
the receive fragments in rds_ib_recv_refill_one() and the send payload
in rds_message_copy_from_user(). The kernel fills and drains them
through copy_page_from_iter(), copy_page_to_iter() and kmap_atomic(),
and they are not mapped into userspace.

Allocate them with GFP_HIGHUSER_KASAN, so that they keep their KASAN
tagging when GFP_HIGHUSER starts to skip it later in this series.

No functional change: GFP_HIGHUSER_KASAN has the same value as
GFP_HIGHUSER at this point. Build tested only.

Assisted-by: LLM
Cc: Allison Henderson <achender@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@kernel.org>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Cc: rds-devel@oss.oracle.com
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 net/rds/ib_recv.c | 2 +-
 net/rds/message.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index aa50b85b0f99..907bf2977583 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -316,7 +316,7 @@ static int rds_ib_recv_refill_one(struct rds_connection *conn,
 
 	if (gfp & __GFP_DIRECT_RECLAIM) {
 		slab_mask = GFP_KERNEL;
-		page_mask = GFP_HIGHUSER;
+		page_mask = GFP_HIGHUSER_KASAN;
 	}
 
 	if (!ic->i_cache_incs.ready)
diff --git a/net/rds/message.c b/net/rds/message.c
index 47d5e9ab9b10..80171ae2f40e 100644
--- a/net/rds/message.c
+++ b/net/rds/message.c
@@ -515,7 +515,7 @@ int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from,
 	while (iov_iter_count(from)) {
 		if (!sg_page(sg)) {
 			ret = rds_page_remainder_alloc(sg, iov_iter_count(from),
-						       GFP_HIGHUSER);
+						       GFP_HIGHUSER_KASAN);
 			if (ret)
 				return ret;
 			rm->data.op_nents++;
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
                   ` (3 preceding siblings ...)
  2026-11-16 23:06 ` [PATCH v1 4/7] net/rds: use GFP_HIGHUSER_KASAN for message pages Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-17 10:21   ` Lorenzo Stoakes (ARM)
  2026-11-16 23:06 ` [PATCH v1 6/7] mm/kasan/kunit: add page_alloc_skip_kasan test Jeff Xu
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

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.

Link: https://lore.kernel.org/r/20260519-panthor-kasan-v2-1-b7384458f076@gmail.com/ [1]
Link: https://lore.kernel.org/r/20260521105148.5497c281@fedora/ [2]
Assisted-by: LLM
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 include/linux/gfp_types.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h
index 567c93fc1cfb..bcc4827deb4c 100644
--- a/include/linux/gfp_types.h
+++ b/include/linux/gfp_types.h
@@ -386,9 +386,9 @@ enum {
 #define GFP_USER	(__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
 #define GFP_DMA		__GFP_DMA
 #define GFP_DMA32	__GFP_DMA32
-#define GFP_HIGHUSER	(GFP_USER | __GFP_HIGHMEM)
+#define GFP_HIGHUSER	(GFP_USER | __GFP_HIGHMEM | __GFP_SKIP_KASAN)
 #define GFP_HIGHUSER_KASAN	(GFP_USER | __GFP_HIGHMEM)
-#define GFP_HIGHUSER_MOVABLE	(GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKIP_KASAN)
+#define GFP_HIGHUSER_MOVABLE	(GFP_HIGHUSER | __GFP_MOVABLE)
 #define GFP_TRANSHUGE_LIGHT	((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
 			 __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM)
 #define GFP_TRANSHUGE	(GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM)
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 6/7] mm/kasan/kunit: add page_alloc_skip_kasan test
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
                   ` (4 preceding siblings ...)
  2026-11-16 23:06 ` [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-16 23:06 ` [PATCH v1 7/7] mm/kasan/kunit: add page_alloc_highuser_kasan test Jeff Xu
  2026-11-17 10:10 ` [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER David Hildenbrand (Arm)
  7 siblings, 0 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

Add a KUnit test (page_alloc_skip_kasan) to verify that page allocations
using __GFP_SKIP_KASAN (GFP_KERNEL | __GFP_SKIP_KASAN, GFP_HIGHUSER, and
GFP_HIGHUSER_MOVABLE) under CONFIG_KASAN_HW_TAGS:
1. Reset page_kasan_tag() to KASAN_TAG_KERNEL (0xff) across all sub-pages
   of a high-order allocation, and
2. Return a match-all (0xff) linear-map pointer from page_address() that
   does not trigger a KASAN fault even when the underlying physical
   granules carry a mismatched tag (such as KASAN_TAG_INVALID or
   restored userspace PROT_MTE tags).

Assisted-by: LLM
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 mm/kasan/kasan_test_c.c | 44 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index f34163e19bd6..72342137bb18 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -380,6 +380,49 @@ static void page_alloc_uaf(struct kunit *test)
 	KUNIT_EXPECT_KASAN_FAIL_READ(test, ((volatile char *)ptr)[0]);
 }
 
+static void page_alloc_skip_kasan_helper(struct kunit *test, gfp_t gfp)
+{
+	struct page *pages;
+	size_t order = 2;
+	char *ptr;
+	size_t i;
+
+	pages = alloc_pages(gfp, order);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages);
+
+	for (i = 0; i < (1UL << order); i++) {
+		/*
+		 * __GFP_SKIP_KASAN allocations must carry the match-all tag
+		 * in page->flags, and so in page_address(), not a random tag.
+		 */
+		KUNIT_EXPECT_EQ(test, page_kasan_tag(pages + i),
+				(u8)KASAN_TAG_KERNEL);
+
+		ptr = page_address(pages + i);
+		KUNIT_EXPECT_EQ(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL);
+
+		/*
+		 * The memory tags of such pages are arbitrary: stale poison,
+		 * or tags set by userspace through PROT_MTE. Accesses via
+		 * page_address() must not fault regardless.
+		 */
+		kasan_poison(ptr, PAGE_SIZE, KASAN_TAG_INVALID, false);
+		KUNIT_EXPECT_KASAN_RESULT(test, WRITE_ONCE(*ptr, 0),
+					  "WRITE_ONCE(*ptr, 0)", false);
+	}
+
+	__free_pages(pages, order);
+}
+
+static void page_alloc_skip_kasan(struct kunit *test)
+{
+	KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_HW_TAGS);
+
+	page_alloc_skip_kasan_helper(test, GFP_KERNEL | __GFP_SKIP_KASAN);
+	page_alloc_skip_kasan_helper(test, GFP_HIGHUSER);
+	page_alloc_skip_kasan_helper(test, GFP_HIGHUSER_MOVABLE);
+}
+
 static void krealloc_more_oob_helper(struct kunit *test,
 					size_t size1, size_t size2)
 {
@@ -2369,6 +2412,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {
 	KUNIT_CASE(kmalloc_large_invalid_free),
 	KUNIT_CASE(page_alloc_oob_right),
 	KUNIT_CASE(page_alloc_uaf),
+	KUNIT_CASE(page_alloc_skip_kasan),
 	KUNIT_CASE(krealloc_more_oob),
 	KUNIT_CASE(krealloc_less_oob),
 	KUNIT_CASE(krealloc_large_more_oob),
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 7/7] mm/kasan/kunit: add page_alloc_highuser_kasan test
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
                   ` (5 preceding siblings ...)
  2026-11-16 23:06 ` [PATCH v1 6/7] mm/kasan/kunit: add page_alloc_skip_kasan test Jeff Xu
@ 2026-11-16 23:06 ` Jeff Xu
  2026-11-17 10:10 ` [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER David Hildenbrand (Arm)
  7 siblings, 0 replies; 10+ messages in thread
From: Jeff Xu @ 2026-11-16 23:06 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

Add a KUnit test (page_alloc_highuser_kasan) to verify that, unlike
GFP_HIGHUSER, page allocations using GFP_HIGHUSER_KASAN under
CONFIG_KASAN_HW_TAGS:
1. Get a KASAN tag in page_kasan_tag() across all sub-pages of a
   high-order allocation, and the same tag in the pointer returned by
   page_address(), and
2. Are poisoned on free, so that a use-after-free through the stale
   pointer is reported.

The test fails if __GFP_SKIP_KASAN is added to GFP_HIGHUSER_KASAN.

Tested on arm64 with CONFIG_KASAN_HW_TAGS under QEMU (virt,mte=on) with
kasan.mode=sync, async and asymm.

Assisted-by: LLM
Signed-off-by: Jeff Xu <jeffxu@chromium.org>
---
 mm/kasan/kasan_test_c.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index 72342137bb18..285b82793bdd 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -423,6 +423,33 @@ static void page_alloc_skip_kasan(struct kunit *test)
 	page_alloc_skip_kasan_helper(test, GFP_HIGHUSER_MOVABLE);
 }
 
+static void page_alloc_highuser_kasan(struct kunit *test)
+{
+	struct page *pages;
+	size_t order = 2;
+	char *ptr;
+	size_t i;
+
+	KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_HW_TAGS);
+
+	pages = alloc_pages(GFP_HIGHUSER_KASAN, order);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages);
+	ptr = page_address(pages);
+
+	/* Unlike GFP_HIGHUSER, these pages must get a KASAN tag. */
+	for (i = 0; i < (1UL << order); i++) {
+		KUNIT_EXPECT_GE(test, page_kasan_tag(pages + i),
+				(u8)KASAN_TAG_MIN);
+		KUNIT_EXPECT_LT(test, page_kasan_tag(pages + i),
+				(u8)KASAN_TAG_KERNEL);
+	}
+	KUNIT_EXPECT_EQ(test, (u8)get_tag(ptr), page_kasan_tag(pages));
+
+	/* They are poisoned on free, so a use-after-free is reported. */
+	__free_pages(pages, order);
+	KUNIT_EXPECT_KASAN_FAIL_READ(test, READ_ONCE(*ptr));
+}
+
 static void krealloc_more_oob_helper(struct kunit *test,
 					size_t size1, size_t size2)
 {
@@ -2413,6 +2440,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {
 	KUNIT_CASE(page_alloc_oob_right),
 	KUNIT_CASE(page_alloc_uaf),
 	KUNIT_CASE(page_alloc_skip_kasan),
+	KUNIT_CASE(page_alloc_highuser_kasan),
 	KUNIT_CASE(krealloc_more_oob),
 	KUNIT_CASE(krealloc_less_oob),
 	KUNIT_CASE(krealloc_large_more_oob),
-- 
2.56.0.611.g1030f0b940-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER
  2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
                   ` (6 preceding siblings ...)
  2026-11-16 23:06 ` [PATCH v1 7/7] mm/kasan/kunit: add page_alloc_highuser_kasan test Jeff Xu
@ 2026-11-17 10:10 ` David Hildenbrand (Arm)
  7 siblings, 0 replies; 10+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-17 10:10 UTC (permalink / raw)
  To: Jeff Xu, Andrew Morton, Vlastimil Babka, Johannes Weiner,
	Andrey Ryabinin
  Cc: 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER
  2026-11-16 23:06 ` [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
@ 2026-11-17 10:21   ` Lorenzo Stoakes (ARM)
  0 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-17 10:21 UTC (permalink / raw)
  To: Jeff Xu
  Cc: Andrew Morton, David Hildenbrand, Vlastimil Babka,
	Johannes Weiner, Andrey Ryabinin, 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, linux-mm, kasan-dev,
	linux-arm-kernel, linux-fsdevel, fuse-devel, kexec, netdev,
	linux-rdma, rds-devel, linux-kernel

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.

You seem to have rewritten commit messages for the other patches, could you do
the same for this one? Thanks.

> Link: https://lore.kernel.org/r/20260519-panthor-kasan-v2-1-b7384458f076@gmail.com/ [1]
> Link: https://lore.kernel.org/r/20260521105148.5497c281@fedora/ [2]
> Assisted-by: LLM

This tag isn't used any longer! Thanks for acking LLM usage though, we prefer
you disclose it but in the commit message or the cover letter etc.

> Signed-off-by: Jeff Xu <jeffxu@chromium.org>
> ---
>  include/linux/gfp_types.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h
> index 567c93fc1cfb..bcc4827deb4c 100644
> --- a/include/linux/gfp_types.h
> +++ b/include/linux/gfp_types.h
> @@ -386,9 +386,9 @@ enum {
>  #define GFP_USER	(__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
>  #define GFP_DMA		__GFP_DMA
>  #define GFP_DMA32	__GFP_DMA32
> -#define GFP_HIGHUSER	(GFP_USER | __GFP_HIGHMEM)
> +#define GFP_HIGHUSER	(GFP_USER | __GFP_HIGHMEM | __GFP_SKIP_KASAN)
>  #define GFP_HIGHUSER_KASAN	(GFP_USER | __GFP_HIGHMEM)
> -#define GFP_HIGHUSER_MOVABLE	(GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKIP_KASAN)
> +#define GFP_HIGHUSER_MOVABLE	(GFP_HIGHUSER | __GFP_MOVABLE)
>  #define GFP_TRANSHUGE_LIGHT	((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
>  			 __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM)
>  #define GFP_TRANSHUGE	(GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM)
> --
> 2.56.0.611.g1030f0b940-goog
>

--
Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-17 10:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 23:06 [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
2026-11-16 23:06 ` [PATCH v1 1/7] mm: add GFP_HIGHUSER_KASAN Jeff Xu
2026-11-16 23:06 ` [PATCH v1 2/7] pipe, fuse: use GFP_HIGHUSER_KASAN for pipe buffer pages Jeff Xu
2026-11-16 23:06 ` [PATCH v1 3/7] kexec: use GFP_HIGHUSER_KASAN for segment pages Jeff Xu
2026-11-16 23:06 ` [PATCH v1 4/7] net/rds: use GFP_HIGHUSER_KASAN for message pages Jeff Xu
2026-11-16 23:06 ` [PATCH v1 5/7] mm: kasan: skip KASAN for GFP_HIGHUSER Jeff Xu
2026-11-17 10:21   ` Lorenzo Stoakes (ARM)
2026-11-16 23:06 ` [PATCH v1 6/7] mm/kasan/kunit: add page_alloc_skip_kasan test Jeff Xu
2026-11-16 23:06 ` [PATCH v1 7/7] mm/kasan/kunit: add page_alloc_highuser_kasan test Jeff Xu
2026-11-17 10:10 ` [PATCH v1 0/7] mm: kasan: skip KASAN for GFP_HIGHUSER David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox