* [PATCH v2] mm: report all-zero cachestat for DAX mappings
@ 2026-11-25 3:04 Henry Martin
2026-11-25 9:14 ` Jan Kara
2026-11-25 20:48 ` + mm-report-all-zero-cachestat-for-dax-mappings.patch added to mm-hotfixes-unstable branch Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Henry Martin @ 2026-11-25 3:04 UTC (permalink / raw)
To: Matthew Wilcox, Jan Kara, Andrew Morton, Nhat Pham,
Johannes Weiner
Cc: linux-fsdevel, linux-mm, Henry Martin, stable
filemap_cachestat() treats every xarray value entry as a workingset
shadow. On DAX mappings, value entries are DAX exceptional entries:
same value bit, different bit layout (flags in the low bits, pfn
above). Decoded as a shadow, a DAX entry yields a bogus node id;
NODE_DATA() for it can be NULL, and lru_gen_test_recent() then
dereferences it:
Oops: general protection fault
RIP: 0010:lru_gen_test_recent+0xde/0x300
Call Trace:
workingset_test_recent
filemap_cachestat
__x64_sys_cachestat
Any writable file on a DAX mount triggers this once an mmap write
fault has populated entries.
DAX mappings have no page cache, so none of the cachestat fields
make sense for them. Skip the xarray walk for them and report all
zeros, and document the behaviour in the syscall's kernel-doc.
This issue was discovered by Tencent CodeBuddy Security.
Cc: stable@vger.kernel.org
Fixes: cf264e1329fb ("cachestat: implement cachestat syscall")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
Changes in v2:
- Return all zeros for DAX mappings instead of counting DAX entries as
cached, per Jan Kara's suggestion (Nhat Pham agreed). This also drops
the dirty-accounting gap and the inaccurate PMD-order claim from v1.
- Document the DAX behaviour in the syscall's kernel-doc.
Link: https://lore.kernel.org/linux-mm/lh4cnpy2kw3tdtmhubwhhvim25kxpqxo6xttt7sihyx7x5hqdf@3tvivew2qh7m/ [Jan Kara]
Link: https://lore.kernel.org/linux-mm/CAKEwX=Py7W0vOwxKdWMCZu3d=BbF2OkgDt6Tu_AHhEJZ06w0ew@mail.gmail.com/ [Nhat Pham]
Link: https://sashiko.dev/#/patchset/20261123030014.3116755-1-bsdhenrymartin@gmail.com?part=1
mm/filemap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index a1b2ca5b933cb..4f6fd1f4caedb 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -4779,7 +4779,8 @@ static inline bool can_do_cachestat(struct file *f)
* The `flags` argument is unused for now, but is included for future
* extensibility. User should pass 0 (i.e no flag specified).
*
- * Currently, hugetlbfs is not supported.
+ * Currently, hugetlbfs is not supported. DAX mappings have no page
+ * cache, so cachestat() always reports all zeros for them.
*
* Because the status of a page can change after cachestat() checks it
* but before it returns to the application, the returned values may
@@ -4824,7 +4825,10 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
memset(&cs, 0, sizeof(struct cachestat));
mapping = fd_file(f)->f_mapping;
- filemap_cachestat(mapping, first_index, last_index, &cs);
+
+ /* DAX mappings have no page cache; report all zeros. */
+ if (!dax_mapping(mapping))
+ filemap_cachestat(mapping, first_index, last_index, &cs);
if (copy_to_user(cstat, &cs, sizeof(struct cachestat)))
return -EFAULT;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mm: report all-zero cachestat for DAX mappings
2026-11-25 3:04 [PATCH v2] mm: report all-zero cachestat for DAX mappings Henry Martin
@ 2026-11-25 9:14 ` Jan Kara
2026-11-25 20:48 ` + mm-report-all-zero-cachestat-for-dax-mappings.patch added to mm-hotfixes-unstable branch Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2026-11-25 9:14 UTC (permalink / raw)
To: Henry Martin
Cc: Matthew Wilcox, Jan Kara, Andrew Morton, Nhat Pham,
Johannes Weiner, linux-fsdevel, linux-mm, stable
On Wed 25-11-26 11:04:32, Henry Martin wrote:
> filemap_cachestat() treats every xarray value entry as a workingset
> shadow. On DAX mappings, value entries are DAX exceptional entries:
> same value bit, different bit layout (flags in the low bits, pfn
> above). Decoded as a shadow, a DAX entry yields a bogus node id;
> NODE_DATA() for it can be NULL, and lru_gen_test_recent() then
> dereferences it:
>
> Oops: general protection fault
> RIP: 0010:lru_gen_test_recent+0xde/0x300
> Call Trace:
> workingset_test_recent
> filemap_cachestat
> __x64_sys_cachestat
>
> Any writable file on a DAX mount triggers this once an mmap write
> fault has populated entries.
>
> DAX mappings have no page cache, so none of the cachestat fields
> make sense for them. Skip the xarray walk for them and report all
> zeros, and document the behaviour in the syscall's kernel-doc.
>
> This issue was discovered by Tencent CodeBuddy Security.
> Cc: stable@vger.kernel.org
> Fixes: cf264e1329fb ("cachestat: implement cachestat syscall")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> Changes in v2:
> - Return all zeros for DAX mappings instead of counting DAX entries as
> cached, per Jan Kara's suggestion (Nhat Pham agreed). This also drops
> the dirty-accounting gap and the inaccurate PMD-order claim from v1.
> - Document the DAX behaviour in the syscall's kernel-doc.
>
> Link: https://lore.kernel.org/linux-mm/lh4cnpy2kw3tdtmhubwhhvim25kxpqxo6xttt7sihyx7x5hqdf@3tvivew2qh7m/ [Jan Kara]
> Link: https://lore.kernel.org/linux-mm/CAKEwX=Py7W0vOwxKdWMCZu3d=BbF2OkgDt6Tu_AHhEJZ06w0ew@mail.gmail.com/ [Nhat Pham]
> Link: https://sashiko.dev/#/patchset/20261123030014.3116755-1-bsdhenrymartin@gmail.com?part=1
>
> mm/filemap.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index a1b2ca5b933cb..4f6fd1f4caedb 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -4779,7 +4779,8 @@ static inline bool can_do_cachestat(struct file *f)
> * The `flags` argument is unused for now, but is included for future
> * extensibility. User should pass 0 (i.e no flag specified).
> *
> - * Currently, hugetlbfs is not supported.
> + * Currently, hugetlbfs is not supported. DAX mappings have no page
> + * cache, so cachestat() always reports all zeros for them.
> *
> * Because the status of a page can change after cachestat() checks it
> * but before it returns to the application, the returned values may
> @@ -4824,7 +4825,10 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
> csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
> memset(&cs, 0, sizeof(struct cachestat));
> mapping = fd_file(f)->f_mapping;
> - filemap_cachestat(mapping, first_index, last_index, &cs);
> +
> + /* DAX mappings have no page cache; report all zeros. */
> + if (!dax_mapping(mapping))
> + filemap_cachestat(mapping, first_index, last_index, &cs);
>
> if (copy_to_user(cstat, &cs, sizeof(struct cachestat)))
> return -EFAULT;
> --
> 2.53.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* + mm-report-all-zero-cachestat-for-dax-mappings.patch added to mm-hotfixes-unstable branch
2026-11-25 3:04 [PATCH v2] mm: report all-zero cachestat for DAX mappings Henry Martin
2026-11-25 9:14 ` Jan Kara
@ 2026-11-25 20:48 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-25 20:48 UTC (permalink / raw)
To: mm-commits, willy, stable, nphamcs, jack, hannes, bsdhenrymartin,
akpm
The patch titled
Subject: mm: report all-zero cachestat for DAX mappings
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
mm-report-all-zero-cachestat-for-dax-mappings.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-report-all-zero-cachestat-for-dax-mappings.patch
This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Henry Martin <bsdhenrymartin@gmail.com>
Subject: mm: report all-zero cachestat for DAX mappings
Date: Wed, 25 Nov 2026 11:04:32 +0800
filemap_cachestat() treats every xarray value entry as a workingset
shadow. On DAX mappings, value entries are DAX exceptional entries: same
value bit, different bit layout (flags in the low bits, pfn above).
Decoded as a shadow, a DAX entry yields a bogus node id; NODE_DATA() for
it can be NULL, and lru_gen_test_recent() then dereferences it:
Oops: general protection fault
RIP: 0010:lru_gen_test_recent+0xde/0x300
Call Trace:
workingset_test_recent
filemap_cachestat
__x64_sys_cachestat
Any writable file on a DAX mount triggers this once an mmap write fault
has populated entries.
DAX mappings have no page cache, so none of the cachestat fields make
sense for them. Skip the xarray walk for them and report all zeros, and
document the behaviour in the syscall's kernel-doc.
This issue was discovered by Tencent CodeBuddy Security.
Link: https://patch.msgid.link/20261125030432.274396-1-bsdhenrymartin@gmail.com
Fixes: cf264e1329fb ("cachestat: implement cachestat syscall")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: <stable@vger.kernel.org>
mm/filemap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--- a/mm/filemap.c~mm-report-all-zero-cachestat-for-dax-mappings
+++ a/mm/filemap.c
@@ -4789,7 +4789,8 @@ static inline bool can_do_cachestat(stru
* The `flags` argument is unused for now, but is included for future
* extensibility. User should pass 0 (i.e no flag specified).
*
- * Currently, hugetlbfs is not supported.
+ * Currently, hugetlbfs is not supported. DAX mappings have no page
+ * cache, so cachestat() always reports all zeros for them.
*
* Because the status of a page can change after cachestat() checks it
* but before it returns to the application, the returned values may
@@ -4834,7 +4835,10 @@ SYSCALL_DEFINE4(cachestat, unsigned int,
csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
memset(&cs, 0, sizeof(struct cachestat));
mapping = fd_file(f)->f_mapping;
- filemap_cachestat(mapping, first_index, last_index, &cs);
+
+ /* DAX mappings have no page cache; report all zeros. */
+ if (!dax_mapping(mapping))
+ filemap_cachestat(mapping, first_index, last_index, &cs);
if (copy_to_user(cstat, &cs, sizeof(struct cachestat)))
return -EFAULT;
_
Patches currently in -mm which might be from bsdhenrymartin@gmail.com are
mm-report-all-zero-cachestat-for-dax-mappings.patch
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 20:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 3:04 [PATCH v2] mm: report all-zero cachestat for DAX mappings Henry Martin
2026-11-25 9:14 ` Jan Kara
2026-11-25 20:48 ` + mm-report-all-zero-cachestat-for-dax-mappings.patch added to mm-hotfixes-unstable branch Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox