* Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
@ 2026-02-01 4:57 ` syzbot
2026-02-01 5:48 ` syzbot
` (10 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-01 4:57 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The kvm_gmem_fault_user_mapping() function currently triggers a warning
when it receives large folios, as indicated by the WARN_ON_ONCE() at
line 416. The code comment in kvm_gmem_get_folio() clearly states
"TODO: Support huge pages", indicating that large folio support is not
yet implemented.
Without explicitly restricting the folio order, filemap_grab_folio() may
opportunistically allocate large folios when memory is available, causing
the warning to trigger and the page fault to fail with VM_FAULT_SIGBUS.
Fix this by explicitly setting the mapping's folio order range to (0, 0)
during inode initialization, ensuring only order-0 (single-page) folios
are allocated until proper large folio support is added.
Reproducer: mlock() on memory backed by guest_memfd with
GUEST_MEMFD_FLAG_INIT_SHARED triggers the warning when large folios
are allocated.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..4dc154b4b370 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -596,6 +596,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_mode |= S_IFREG;
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
mapping_set_inaccessible(inode->i_mapping);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
2026-02-01 4:57 ` Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented syzbot
@ 2026-02-01 5:48 ` syzbot
2026-02-01 7:48 ` syzbot
` (9 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-01 5:48 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The kvm_gmem_fault_user_mapping() function currently triggers a warning
when it receives large folios, as indicated by the WARN_ON_ONCE() at
line 416. The code comment in kvm_gmem_get_folio() clearly states
"TODO: Support huge pages", indicating that large folio support is not
yet implemented.
Without explicitly restricting the folio order, filemap_grab_folio() may
opportunistically allocate large folios when memory is available, causing
the warning to trigger and the page fault to fail with VM_FAULT_SIGBUS.
Fix this by explicitly setting the mapping's folio order range to (0, 0)
during inode initialization in __kvm_gmem_create(), ensuring only order-0
(single-page) folios are allocated until proper large folio support is
added.
Reproducer: mlock() on memory backed by guest_memfd with
GUEST_MEMFD_FLAG_INIT_SHARED triggers the warning when large folios
are allocated.
Add debug logging to track folio order configuration and allocation
for further investigation.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..e513e0f735d0 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -412,7 +412,8 @@ static vm_fault_t kvm_gmem_fault_user_mapping(struct vm_fault *vmf)
return vmf_error(PTR_ERR(folio));
}
-
+ pr_info("KVM: fault got folio, large=%d order=%u\n",
+ folio_test_large(folio), folio_order(folio));
if (WARN_ON_ONCE(folio_test_large(folio))) {
ret = VM_FAULT_SIGBUS;
goto out_folio;
@@ -596,6 +597,10 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_mode |= S_IFREG;
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
+ pr_info("KVM: guest_memfd created, folio_order min=%u max=%u\n",
+ mapping_min_folio_order(inode->i_mapping),
+ mapping_max_folio_order(inode->i_mapping));
mapping_set_inaccessible(inode->i_mapping);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
2026-02-01 4:57 ` Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented syzbot
2026-02-01 5:48 ` syzbot
@ 2026-02-01 7:48 ` syzbot
2026-02-01 11:08 ` syzbot
` (8 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-01 7:48 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The kvm_gmem_fault_user_mapping() function currently triggers a warning
when it receives large folios, as indicated by the WARN_ON_ONCE() at
line 416. The code comment in kvm_gmem_get_folio() clearly states
"TODO: Support huge pages", indicating that large folio support is not
yet implemented.
Without explicitly restricting the folio order, filemap_grab_folio() may
opportunistically allocate large folios when memory is available, causing
the warning to trigger and the page fault to fail with VM_FAULT_SIGBUS.
Fix this by explicitly setting the mapping's folio order range to (0, 0)
during inode initialization in __kvm_gmem_create(), ensuring only order-0
(single-page) folios are allocated until proper large folio support is
added.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..679814ec1874 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -596,7 +596,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_mode |= S_IFREG;
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
- mapping_set_inaccessible(inode->i_mapping);
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (2 preceding siblings ...)
2026-02-01 7:48 ` syzbot
@ 2026-02-01 11:08 ` syzbot
2026-02-02 8:34 ` Forwarded: [PATCH] KVM: guest_memfd: Reject large folios until " syzbot
` (7 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-01 11:08 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The kvm_gmem_fault_user_mapping() function currently triggers a warning
when it receives large folios, as indicated by the WARN_ON_ONCE() at
line 416. The code comment in kvm_gmem_get_folio() clearly states
"TODO: Support huge pages", indicating that large folio support is not
yet implemented.
Without explicitly restricting the folio order, filemap_grab_folio() may
opportunistically allocate large folios when memory is available, causing
the warning to trigger and the page fault to fail with VM_FAULT_SIGBUS.
Fix this by explicitly setting the mapping's folio order range to (0, 0)
during inode initialization in __kvm_gmem_create(), ensuring only order-0
(single-page) folios are allocated until proper large folio support is
added.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..4dc154b4b370 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -596,6 +596,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_mode |= S_IFREG;
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
mapping_set_inaccessible(inode->i_mapping);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] KVM: guest_memfd: Reject large folios until support is implemented
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (3 preceding siblings ...)
2026-02-01 11:08 ` syzbot
@ 2026-02-02 8:34 ` syzbot
2026-02-02 15:11 ` syzbot
` (6 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-02 8:34 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Reject large folios until support is implemented
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Large folios are not yet supported in guest_memfd (see TODO comment
in kvm_gmem_get_folio()), but can still be allocated if userspace
uses madvise(MADV_HUGEPAGE), which overrides the folio order
restrictions set by mapping_set_folio_order_range().
When a large folio is allocated, it triggers WARN_ON_ONCE() at line
416 in kvm_gmem_fault_user_mapping(), causing a kernel panic if
panic_on_warn is enabled.
Add mapping_set_folio_order_range(0, 0) as defense in depth, and
actively check for large folios in kvm_gmem_get_folio(). If found,
remove the large folio from the page cache and return -E2BIG to
force reallocation as an order-0 page.
This prevents the WARNING from triggering and avoids kernel panics.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..60181efdc00a 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -143,13 +143,30 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index)
folio = __filemap_get_folio(inode->i_mapping, index,
FGP_LOCK | FGP_ACCESSED, 0);
if (!IS_ERR(folio))
- return folio;
+ goto check_folio;
policy = mpol_shared_policy_lookup(&GMEM_I(inode)->policy, index);
folio = __filemap_get_folio_mpol(inode->i_mapping, index,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
mapping_gfp_mask(inode->i_mapping), policy);
mpol_cond_put(policy);
+ if (IS_ERR(folio))
+ return folio;
+check_folio:
+ /*
+ * Large folios are not supported yet. This can still happen
+ * despite mapping_set_folio_order_range() if userspace uses
+ * madvise(MADV_HUGEPAGE) which can override the folio order
+ * restrictions. Reject the large folio and remove it from
+ * the page cache so the next fault can allocate a order-0
+ * page instead.
+ */
+ if (folio_test_large(folio)) {
+ folio_unlock(folio);
+ filemap_remove_folio(folio);
+ folio_put(folio);
+ return ERR_PTR(-E2BIG);
+ }
return folio;
}
@@ -596,6 +613,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_mode |= S_IFREG;
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
mapping_set_inaccessible(inode->i_mapping);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] KVM: guest_memfd: Reject large folios until support is implemented
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (4 preceding siblings ...)
2026-02-02 8:34 ` Forwarded: [PATCH] KVM: guest_memfd: Reject large folios until " syzbot
@ 2026-02-02 15:11 ` syzbot
2026-02-03 20:06 ` Forwarded: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd syzbot
` (5 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-02 15:11 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Reject large folios until support is implemented
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Large folios are not yet supported in guest_memfd (see TODO comment
in kvm_gmem_get_folio()), but can still be allocated if userspace
uses madvise(MADV_HUGEPAGE), which overrides the folio order
restrictions set by mapping_set_folio_order_range().
When a large folio is allocated, it triggers WARN_ON_ONCE() at line
416 in kvm_gmem_fault_user_mapping(), causing a kernel panic if
panic_on_warn is enabled.
Add mapping_set_folio_order_range(0, 0) as defense in depth, and
actively check for large folios in kvm_gmem_get_folio() on both
the fast-path (existing folio) and slow-path (newly created folio).
If a large folio is found, unlock it, drop the reference, and return
-E2BIG to prevent the WARNING from triggering.
This avoids kernel panics when panic_on_warn is enabled.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..ee5bcf238f98 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -143,13 +143,29 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index)
folio = __filemap_get_folio(inode->i_mapping, index,
FGP_LOCK | FGP_ACCESSED, 0);
if (!IS_ERR(folio))
- return folio;
+ goto check_folio;
policy = mpol_shared_policy_lookup(&GMEM_I(inode)->policy, index);
folio = __filemap_get_folio_mpol(inode->i_mapping, index,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
mapping_gfp_mask(inode->i_mapping), policy);
mpol_cond_put(policy);
+ if (IS_ERR(folio))
+ return folio;
+check_folio:
+ /*
+ * Large folios are not supported yet. This can still happen
+ * despite mapping_set_folio_order_range() if userspace uses
+ * madvise(MADV_HUGEPAGE) which can override the folio order
+ * restrictions. Reject the large folio and remove it from
+ * the page cache so the next fault can allocate a order-0
+ * page instead.
+ */
+ if (folio_test_large(folio)) {
+ folio_unlock(folio);
+ folio_put(folio);
+ return ERR_PTR(-E2BIG);
+ }
return folio;
}
@@ -596,6 +612,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_mode |= S_IFREG;
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
mapping_set_inaccessible(inode->i_mapping);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (5 preceding siblings ...)
2026-02-02 15:11 ` syzbot
@ 2026-02-03 20:06 ` syzbot
2026-02-04 17:01 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
` (4 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-03 20:06 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd
Author: ackerleytng@google.com
#syz test: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
filemap_{grab,get}_folio() and related functions, used since the early
stages of guest_memfd have determined the order of the folio to be
allocated by looking up mapping_min_folio_order(mapping). As identified by
syzbot, MADV_HUGEPAGE can be used to set the result of
mapping_min_folio_order() to a value greater than 0, leading to the
allocation of a huge page and subsequent WARNing.
Refactor the allocation code of guest_memfd to directly use
filemap_add_folio(), specifying an order of 0.
This refactoring replaces the original functionality where FGP_LOCK and
FGP_CREAT are requested. Opportunistically drop functionality provided by
FGP_ACCESSED. guest_memfd folios don't care about accessed flags because
guest_memfd memory is unevictable and there is no storage to write back to.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Tested-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
virt/kvm/guest_memfd.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..0c58f6aa5609 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -135,23 +135,35 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index)
/* TODO: Support huge pages. */
struct mempolicy *policy;
struct folio *folio;
+ gfp_t gfp;
+ int ret;
/*
* Fast-path: See if folio is already present in mapping to avoid
* policy_lookup.
*/
+repeat:
folio = __filemap_get_folio(inode->i_mapping, index,
FGP_LOCK | FGP_ACCESSED, 0);
if (!IS_ERR(folio))
return folio;
+ gfp = mapping_gfp_mask(inode->i_mapping);
+
policy = mpol_shared_policy_lookup(&GMEM_I(inode)->policy, index);
- folio = __filemap_get_folio_mpol(inode->i_mapping, index,
- FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
- mapping_gfp_mask(inode->i_mapping), policy);
+ folio = filemap_alloc_folio(gfp, 0, policy);
mpol_cond_put(policy);
+ if (!folio)
+ return ERR_PTR(-ENOMEM);
- return folio;
+ ret = filemap_add_folio(inode->i_mapping, folio, index, gfp);
+ if (ret)
+ folio_put(folio);
+
+ if (ret == -EEXIST)
+ goto repeat;
+
+ return ret ? ERR_PTR(ret) : folio;
}
static enum kvm_gfn_range_filter kvm_gmem_get_invalidate_filter(struct inode *inode)
--
2.53.0.rc2.204.g2597b5adb4-goog
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (6 preceding siblings ...)
2026-02-03 20:06 ` Forwarded: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd syzbot
@ 2026-02-04 17:01 ` Ackerley Tng
2026-02-04 18:21 ` [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
2026-02-04 19:10 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
2026-02-09 1:55 ` Forwarded: [PATCH] KVM: guest_memfd: Prevent THP collapse of guest_memfd pages syzbot
` (3 subsequent siblings)
11 siblings, 2 replies; 34+ messages in thread
From: Ackerley Tng @ 2026-02-04 17:01 UTC (permalink / raw)
To: syzbot+33a04338019ac7e43a44
Cc: kvm, linux-kernel, pbonzini, syzkaller-bugs, Ackerley Tng
#syz test: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
guest_memfd VMAs don't need to be merged, especially now, since guest_memfd
only supports PAGE_SIZE folios.
Set VM_DONTEXPAND on guest_memfd VMAs.
In addition, this disables khugepaged from operating on guest_memfd folios,
which may result in unintended merging of guest_memfd folios.
Change-Id: I5867edcb66b075b54b25260afd22a198aee76df1
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
virt/kvm/guest_memfd.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..3d4ac461c28b 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -480,6 +480,12 @@ static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma)
return -EINVAL;
}
+ /*
+ * Disable VMA merging - guest_memfd VMAs should be
+ * static. This also stops khugepaged from operating on
+ * guest_memfd VMAs and folios.
+ */
+ vm_flags_set(vma, VM_DONTEXPAND);
vma->vm_ops = &kvm_gmem_vm_ops;
return 0;
--
2.53.0.rc2.204.g2597b5adb4-goog
^ permalink raw reply related [flat|nested] 34+ messages in thread* Re: [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping
2026-02-04 17:01 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
@ 2026-02-04 18:21 ` syzbot
2026-02-04 19:10 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
1 sibling, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-04 18:21 UTC (permalink / raw)
To: ackerleytng, kvm, linux-kernel, pbonzini, syzkaller-bugs
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Tested-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Tested on:
commit: 0499add8 Merge tag 'kvm-x86-fixes-6.19-rc1' of https:/..
git tree: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
console output: https://syzkaller.appspot.com/x/log.txt?x=1778a402580000
kernel config: https://syzkaller.appspot.com/x/.config?x=3aec2f7e1730a8eb
dashboard link: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
patch: https://syzkaller.appspot.com/x/patch.diff?x=13b847fa580000
Note: testing is done by a robot and is best-effort only.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-04 17:01 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
2026-02-04 18:21 ` [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
@ 2026-02-04 19:10 ` Ackerley Tng
2026-02-04 21:37 ` Sean Christopherson
1 sibling, 1 reply; 34+ messages in thread
From: Ackerley Tng @ 2026-02-04 19:10 UTC (permalink / raw)
To: syzbot+33a04338019ac7e43a44
Cc: kvm, linux-kernel, pbonzini, syzkaller-bugs, david, michael.roth,
vannapurve, kartikey406
Ackerley Tng <ackerleytng@google.com> writes:
> #syz test: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
>
> guest_memfd VMAs don't need to be merged, especially now, since guest_memfd
> only supports PAGE_SIZE folios.
>
> Set VM_DONTEXPAND on guest_memfd VMAs.
>
Local tests and syzbot agree that this fixes the issue identified. :)
I would like to look into madvise(MADV_COLLAPSE) and uprobes triggering
mapping/folio collapsing before submitting a full patch series.
David, Michael, Vishal, what do you think of the choice of setting
VM_DONTEXPAND to disable khugepaged?
+ For 4K guest_memfd, there's really nothing to expand
+ For THP and HugeTLB guest_memfd (future), we actually don't want
expansion of the VMAs.
IIUC setting VM_DONTEXPAND doesn't affect mremap() as long as the
remapping does not involve expansion.
> In addition, this disables khugepaged from operating on guest_memfd folios,
> which may result in unintended merging of guest_memfd folios.
>
> Change-Id: I5867edcb66b075b54b25260afd22a198aee76df1
> Signed-off-by: Ackerley Tng <ackerleytng@google.com>
> ---
> virt/kvm/guest_memfd.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index fdaea3422c30..3d4ac461c28b 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -480,6 +480,12 @@ static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma)
> return -EINVAL;
> }
>
> + /*
> + * Disable VMA merging - guest_memfd VMAs should be
> + * static. This also stops khugepaged from operating on
> + * guest_memfd VMAs and folios.
> + */
> + vm_flags_set(vma, VM_DONTEXPAND);
> vma->vm_ops = &kvm_gmem_vm_ops;
>
> return 0;
> --
> 2.53.0.rc2.204.g2597b5adb4-goog
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-04 19:10 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
@ 2026-02-04 21:37 ` Sean Christopherson
2026-02-04 21:45 ` David Hildenbrand (arm)
0 siblings, 1 reply; 34+ messages in thread
From: Sean Christopherson @ 2026-02-04 21:37 UTC (permalink / raw)
To: Ackerley Tng
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, david, michael.roth, vannapurve, kartikey406
On Wed, Feb 04, 2026, Ackerley Tng wrote:
> Ackerley Tng <ackerleytng@google.com> writes:
>
> > #syz test: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
> >
> > guest_memfd VMAs don't need to be merged,
Why not? There are benefits to merging VMAs that have nothing to do with folios.
E.g. map 1GiB of guest_memfd with 512*512 4KiB VMAs, and then it becomes quite
desirable to merge all of those VMAs into one.
Creating _hugepages_ doesn't add value, but that's not the same things as merging
VMAs.
> > especially now, since guest_memfd only supports PAGE_SIZE folios.
> >
> > Set VM_DONTEXPAND on guest_memfd VMAs.
>
> Local tests and syzbot agree that this fixes the issue identified. :)
>
> I would like to look into madvise(MADV_COLLAPSE) and uprobes triggering
> mapping/folio collapsing before submitting a full patch series.
>
> David, Michael, Vishal, what do you think of the choice of setting
> VM_DONTEXPAND to disable khugepaged?
I'm not one of the above, but for me it feels very much like treating a symptom
and not fixing the underlying cause.
It seems like what KVM should do is not block one path that triggers hugepage
processing, but instead flat out disallow creating hugepages. Unfortunately,
AFAICT, there's no existing way to prevent madvise() from clearing VM_NOHUGEPAGE,
so we can't simply force that flag.
I'd prefer not to special case guest_memfd, a la devdax, but I also want to address
this head-on, not by removing a tangentially related trigger.
> + For 4K guest_memfd, there's really nothing to expand
> + For THP and HugeTLB guest_memfd (future), we actually don't want
> expansion of the VMAs.
>
> IIUC setting VM_DONTEXPAND doesn't affect mremap() as long as the
> remapping does not involve expansion.
>
> > In addition, this disables khugepaged from operating on guest_memfd folios,
> > which may result in unintended merging of guest_memfd folios.
> >
> > Change-Id: I5867edcb66b075b54b25260afd22a198aee76df1
> > Signed-off-by: Ackerley Tng <ackerleytng@google.com>
> > ---
> > virt/kvm/guest_memfd.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> > index fdaea3422c30..3d4ac461c28b 100644
> > --- a/virt/kvm/guest_memfd.c
> > +++ b/virt/kvm/guest_memfd.c
> > @@ -480,6 +480,12 @@ static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma)
> > return -EINVAL;
> > }
> >
> > + /*
> > + * Disable VMA merging - guest_memfd VMAs should be
> > + * static. This also stops khugepaged from operating on
> > + * guest_memfd VMAs and folios.
> > + */
> > + vm_flags_set(vma, VM_DONTEXPAND);
> > vma->vm_ops = &kvm_gmem_vm_ops;
> >
> > return 0;
> > --
> > 2.53.0.rc2.204.g2597b5adb4-goog
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-04 21:37 ` Sean Christopherson
@ 2026-02-04 21:45 ` David Hildenbrand (arm)
2026-02-04 23:17 ` Ackerley Tng
0 siblings, 1 reply; 34+ messages in thread
From: David Hildenbrand (arm) @ 2026-02-04 21:45 UTC (permalink / raw)
To: Sean Christopherson, Ackerley Tng
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve, kartikey406
On 2/4/26 22:37, Sean Christopherson wrote:
> On Wed, Feb 04, 2026, Ackerley Tng wrote:
>> Ackerley Tng <ackerleytng@google.com> writes:
>>
>>> #syz test: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
>>>
>>> guest_memfd VMAs don't need to be merged,
>
> Why not? There are benefits to merging VMAs that have nothing to do with folios.
> E.g. map 1GiB of guest_memfd with 512*512 4KiB VMAs, and then it becomes quite
> desirable to merge all of those VMAs into one.
>
> Creating _hugepages_ doesn't add value, but that's not the same things as merging
> VMAs.
>
>>> especially now, since guest_memfd only supports PAGE_SIZE folios.
>>>
>>> Set VM_DONTEXPAND on guest_memfd VMAs.
>>
>> Local tests and syzbot agree that this fixes the issue identified. :)
>>
>> I would like to look into madvise(MADV_COLLAPSE) and uprobes triggering
>> mapping/folio collapsing before submitting a full patch series.
>>
>> David, Michael, Vishal, what do you think of the choice of setting
>> VM_DONTEXPAND to disable khugepaged?
>
> I'm not one of the above, but for me it feels very much like treating a symptom
> and not fixing the underlying cause.
And you are spot-on :)
>
> It seems like what KVM should do is not block one path that triggers hugepage
> processing, but instead flat out disallow creating hugepages. Unfortunately,
> AFAICT, there's no existing way to prevent madvise() from clearing VM_NOHUGEPAGE,
> so we can't simply force that flag.
>
> I'd prefer not to special case guest_memfd, a la devdax, but I also want to address
> this head-on, not by removing a tangentially related trigger.
VM_NOHUGEPAGE also smells like the wrong thing. This is a file limitation.
!thp_vma_allowable_order() must take care of that somehow down in
__thp_vma_allowable_orders(), by checking the file).
Likely the file_thp_enabled() check is the culprit with
CONFIG_READ_ONLY_THP_FOR_FS?
Maybe we need a flag to say "even not CONFIG_READ_ONLY_THP_FOR_FS".
I wonder how we handle that for secretmem. Too late for me, going to bed :)
--
Cheers,
David
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-04 21:45 ` David Hildenbrand (arm)
@ 2026-02-04 23:17 ` Ackerley Tng
2026-02-08 17:34 ` Ackerley Tng
0 siblings, 1 reply; 34+ messages in thread
From: Ackerley Tng @ 2026-02-04 23:17 UTC (permalink / raw)
To: David Hildenbrand (arm), Sean Christopherson
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve, kartikey406
"David Hildenbrand (arm)" <david@kernel.org> writes:
> On 2/4/26 22:37, Sean Christopherson wrote:
>> On Wed, Feb 04, 2026, Ackerley Tng wrote:
>>> Ackerley Tng <ackerleytng@google.com> writes:
>>>
>>>> #syz test: git://git.kernel.org/pub/scm/virt/kvm/kvm.git next
>>>>
>>>> guest_memfd VMAs don't need to be merged,
>>
>> Why not? There are benefits to merging VMAs that have nothing to do with folios.
>> E.g. map 1GiB of guest_memfd with 512*512 4KiB VMAs, and then it becomes quite
>> desirable to merge all of those VMAs into one.
>>
I didn't realise VM_DONTEXPAND's no expansion policy extends to the case
where adjacent VMAs with the same flags, etc automatically merge. Since
VM_DONTEXPAND blocks this kind of expansion, I agree VM_DONTEXPAND is
not great.
>> Creating _hugepages_ doesn't add value, but that's not the same things as merging
>> VMAs.
>>
>>>> especially now, since guest_memfd only supports PAGE_SIZE folios.
>>>>
>>>> Set VM_DONTEXPAND on guest_memfd VMAs.
>>>
>>> Local tests and syzbot agree that this fixes the issue identified. :)
>>>
>>> I would like to look into madvise(MADV_COLLAPSE) and uprobes triggering
>>> mapping/folio collapsing before submitting a full patch series.
>>>
>>> David, Michael, Vishal, what do you think of the choice of setting
>>> VM_DONTEXPAND to disable khugepaged?
>>
>> I'm not one of the above, but for me it feels very much like treating a symptom
Was going to find some solution before getting to you to save you some
time :)
>> and not fixing the underlying cause.
>
> And you are spot-on :)
>
>>
>> It seems like what KVM should do is not block one path that triggers hugepage
>> processing, but instead flat out disallow creating hugepages. Unfortunately,
__filemap_get_folio_mpol(), which we use in kvm_gmem_get_folio(), looks
up mapping_min_folio_order() to determine what order to allocate. I
think we could lock that down to always use order 0. I tried that here
[1] but in this case khugepaged allocates new folios for guest_memfd
(and others) directly in collapse_file(), explicitly specifying
PMD_ORDER.
I took a look and wasn't able to find a central callback/ops to catch
all fs allocations.
[1] https://lore.kernel.org/all/6982553e.a00a0220.34fa92.0009.GAE@google.com/
>> AFAICT, there's no existing way to prevent madvise() from clearing VM_NOHUGEPAGE,
>> so we can't simply force that flag.
>>
>> I'd prefer not to special case guest_memfd, a la devdax, but I also want to address
>> this head-on, not by removing a tangentially related trigger.
>
> VM_NOHUGEPAGE also smells like the wrong thing. This is a file limitation.
>
> !thp_vma_allowable_order() must take care of that somehow down in
> __thp_vma_allowable_orders(), by checking the file).
>
> Likely the file_thp_enabled() check is the culprit with
> CONFIG_READ_ONLY_THP_FOR_FS?
>
> Maybe we need a flag to say "even not CONFIG_READ_ONLY_THP_FOR_FS".
>
> I wonder how we handle that for secretmem. Too late for me, going to bed :)
>
Let me look deeper into this. Thanks!
> --
> Cheers,
>
> David
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-04 23:17 ` Ackerley Tng
@ 2026-02-08 17:34 ` Ackerley Tng
2026-02-09 3:40 ` Deepanshu Kartikey
2026-02-09 10:38 ` David Hildenbrand (Arm)
0 siblings, 2 replies; 34+ messages in thread
From: Ackerley Tng @ 2026-02-08 17:34 UTC (permalink / raw)
To: David Hildenbrand (arm), Sean Christopherson
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve, kartikey406
Ackerley Tng <ackerleytng@google.com> writes:
>
> [...snip...]
>
>> !thp_vma_allowable_order() must take care of that somehow down in
>> __thp_vma_allowable_orders(), by checking the file).
>>
>> Likely the file_thp_enabled() check is the culprit with
>> CONFIG_READ_ONLY_THP_FOR_FS?
>>
>> Maybe we need a flag to say "even not CONFIG_READ_ONLY_THP_FOR_FS".
>>
>> I wonder how we handle that for secretmem. Too late for me, going to bed :)
>>
>
> Let me look deeper into this. Thanks!
>
I trimmed the repro to this:
static void test_guest_memfd_repro(void)
{
struct kvm_vcpu *vcpu;
uint8_t *unaligned_mem;
struct kvm_vm *vm;
uint8_t *mem;
int fd;
vm = __vm_create_shape_with_one_vcpu(VM_SHAPE_DEFAULT, &vcpu, 1, guest_code);
fd = vm_create_guest_memfd(vm, SZ_2M * 2, GUEST_MEMFD_FLAG_MMAP |
GUEST_MEMFD_FLAG_INIT_SHARED);
unaligned_mem = mmap(NULL, SZ_2M + SZ_2M, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_SHARED, fd, 0);
mem = align_ptr_up(unaligned_mem, SZ_2M);
TEST_ASSERT(((unsigned long)mem & (SZ_2M - 1)) == 0, "returned
address must be aligned to SZ_2M");
TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_HUGEPAGE), 0);
for (int i = 0; i < SZ_2M; i += SZ_4K)
READ_ONCE(mem[i]);
TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_COLLAPSE), 0);
TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_DONTNEED), 0);
/* This triggers the WARNing. */
READ_ONCE(mem[0]);
munmap(unaligned_mem, SZ_2M * 2);
close(fd);
kvm_vm_free(vm);
}
And tried to replace the fd creation the secretmem equivalent
fd = syscall(__NR_memfd_secret, 0);
TEST_ASSERT(fd >= 0, "Couldn't create secretmem fd.");
TEST_ASSERT_EQ(ftruncate(fd, SZ_2M * 2), 0);
Should a guest_memfd selftest be added to cover this?
MADV_COLLAPSE fails with EINVAL, but it does go through to
hpage_collapse_scan_file() -> collapse_file(), before failing because
when collapsing the page, copy_mc_highpage() returns > 0.
Not super familiar with copy_mc_highpage() - I haven't looked into why
copy_mc_highpage() failed, but looks like it would have caused
memory_failure_queue() which would be inappropriate.
Since this also affects secretmem, I think thp_vma_allowable_order() is
the best place to intercept the collapsing flow for both secretmem and
guest_memfd.
Let me know if you have any ideas!
>> --
>> Cheers,
>>
>> David
^ permalink raw reply [flat|nested] 34+ messages in thread* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-08 17:34 ` Ackerley Tng
@ 2026-02-09 3:40 ` Deepanshu Kartikey
2026-02-09 10:38 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 34+ messages in thread
From: Deepanshu Kartikey @ 2026-02-09 3:40 UTC (permalink / raw)
To: Ackerley Tng
Cc: David Hildenbrand (arm), Sean Christopherson,
syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve
On Sun, Feb 8, 2026 at 11:04 PM Ackerley Tng <ackerleytng@google.com> wrote:
>
> Since this also affects secretmem, I think thp_vma_allowable_order() is
> the best place to intercept the collapsing flow for both secretmem and
> guest_memfd.
>
> Let me know if you have any ideas!
>
Hi David, Ackerley,
I have been looking into this bug and I think the root cause is in
file_thp_enabled(). When CONFIG_READ_ONLY_THP_FOR_FS is enabled,
guest_memfd and secretmem inodes pass the S_ISREG() and
!inode_is_open_for_write() checks, so file_thp_enabled() incorrectly
returns true. This allows khugepaged and MADV_COLLAPSE to create large
folios in the page cache.
I sent a patch that fixes this at the source by explicitly rejecting
GUEST_MEMFD_MAGIC and SECRETMEM_MAGIC in file_thp_enabled():
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 40cf59301c21..4f57c78b57dd 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -93,6 +93,9 @@ static inline bool file_thp_enabled(struct
vm_area_struct *vma)
return false;
inode = file_inode(vma->vm_file);
+ if (inode->i_sb->s_magic == GUEST_MEMFD_MAGIC ||
+ inode->i_sb->s_magic == SECRETMEM_MAGIC)
+ return false;
return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
}
I have tested this and confirmed the warning no longer triggers. This
approach covers both guest_memfd and secretmem in one place without
needing separate VMA flag changes in each subsystem. I have sent the
patch.
Please have a look and let me know your thoughts.
Thanks,
Deepanshu
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-08 17:34 ` Ackerley Tng
2026-02-09 3:40 ` Deepanshu Kartikey
@ 2026-02-09 10:38 ` David Hildenbrand (Arm)
2026-02-09 18:24 ` Ackerley Tng
1 sibling, 1 reply; 34+ messages in thread
From: David Hildenbrand (Arm) @ 2026-02-09 10:38 UTC (permalink / raw)
To: Ackerley Tng, Sean Christopherson
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve, kartikey406
On 2/8/26 18:34, Ackerley Tng wrote:
> Ackerley Tng <ackerleytng@google.com> writes:
>
>>
>> [...snip...]
>>
>>> !thp_vma_allowable_order() must take care of that somehow down in
>>> __thp_vma_allowable_orders(), by checking the file).
>>>
>>> Likely the file_thp_enabled() check is the culprit with
>>> CONFIG_READ_ONLY_THP_FOR_FS?
>>>
>>> Maybe we need a flag to say "even not CONFIG_READ_ONLY_THP_FOR_FS".
>>>
>>> I wonder how we handle that for secretmem. Too late for me, going to bed :)
>>>
>>
>> Let me look deeper into this. Thanks!
>>
>
> I trimmed the repro to this:
>
> static void test_guest_memfd_repro(void)
> {
> struct kvm_vcpu *vcpu;
> uint8_t *unaligned_mem;
> struct kvm_vm *vm;
> uint8_t *mem;
> int fd;
>
> vm = __vm_create_shape_with_one_vcpu(VM_SHAPE_DEFAULT, &vcpu, 1, guest_code);
>
> fd = vm_create_guest_memfd(vm, SZ_2M * 2, GUEST_MEMFD_FLAG_MMAP |
> GUEST_MEMFD_FLAG_INIT_SHARED);
>
> unaligned_mem = mmap(NULL, SZ_2M + SZ_2M, PROT_READ | PROT_WRITE,
> MAP_FIXED | MAP_SHARED, fd, 0);
> mem = align_ptr_up(unaligned_mem, SZ_2M);
> TEST_ASSERT(((unsigned long)mem & (SZ_2M - 1)) == 0, "returned
> address must be aligned to SZ_2M");
>
> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_HUGEPAGE), 0);
>
> for (int i = 0; i < SZ_2M; i += SZ_4K)
> READ_ONCE(mem[i]);
>
> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_COLLAPSE), 0);
>
> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_DONTNEED), 0);
>
> /* This triggers the WARNing. */
> READ_ONCE(mem[0]);
>
> munmap(unaligned_mem, SZ_2M * 2);
>
> close(fd);
> kvm_vm_free(vm);
> }
>
> And tried to replace the fd creation the secretmem equivalent
>
> fd = syscall(__NR_memfd_secret, 0);
> TEST_ASSERT(fd >= 0, "Couldn't create secretmem fd.");
> TEST_ASSERT_EQ(ftruncate(fd, SZ_2M * 2), 0);
>
> Should a guest_memfd selftest be added to cover this?
>
> MADV_COLLAPSE fails with EINVAL, but it does go through to
> hpage_collapse_scan_file() -> collapse_file(), before failing because
> when collapsing the page, copy_mc_highpage() returns > 0.
Just what I suspected. :)
Thanks for digging into the details!
--
Cheers,
David
^ permalink raw reply [flat|nested] 34+ messages in thread* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-09 10:38 ` David Hildenbrand (Arm)
@ 2026-02-09 18:24 ` Ackerley Tng
2026-02-09 19:38 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 34+ messages in thread
From: Ackerley Tng @ 2026-02-09 18:24 UTC (permalink / raw)
To: David Hildenbrand (Arm), Sean Christopherson
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve, kartikey406
"David Hildenbrand (Arm)" <david@kernel.org> writes:
> On 2/8/26 18:34, Ackerley Tng wrote:
>> Ackerley Tng <ackerleytng@google.com> writes:
>>
>>>
>>> [...snip...]
>>>
>>>> !thp_vma_allowable_order() must take care of that somehow down in
>>>> __thp_vma_allowable_orders(), by checking the file).
>>>>
>>>> Likely the file_thp_enabled() check is the culprit with
>>>> CONFIG_READ_ONLY_THP_FOR_FS?
>>>>
>>>> Maybe we need a flag to say "even not CONFIG_READ_ONLY_THP_FOR_FS".
>>>>
>>>> I wonder how we handle that for secretmem. Too late for me, going to bed :)
>>>>
>>>
>>> Let me look deeper into this. Thanks!
>>>
>>
>> I trimmed the repro to this:
>>
>> static void test_guest_memfd_repro(void)
>> {
>> struct kvm_vcpu *vcpu;
>> uint8_t *unaligned_mem;
>> struct kvm_vm *vm;
>> uint8_t *mem;
>> int fd;
>>
>> vm = __vm_create_shape_with_one_vcpu(VM_SHAPE_DEFAULT, &vcpu, 1, guest_code);
>>
>> fd = vm_create_guest_memfd(vm, SZ_2M * 2, GUEST_MEMFD_FLAG_MMAP |
>> GUEST_MEMFD_FLAG_INIT_SHARED);
>>
>> unaligned_mem = mmap(NULL, SZ_2M + SZ_2M, PROT_READ | PROT_WRITE,
>> MAP_FIXED | MAP_SHARED, fd, 0);
>> mem = align_ptr_up(unaligned_mem, SZ_2M);
>> TEST_ASSERT(((unsigned long)mem & (SZ_2M - 1)) == 0, "returned
>> address must be aligned to SZ_2M");
>>
>> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_HUGEPAGE), 0);
>>
>> for (int i = 0; i < SZ_2M; i += SZ_4K)
>> READ_ONCE(mem[i]);
>>
>> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_COLLAPSE), 0);
>>
>> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_DONTNEED), 0);
>>
>> /* This triggers the WARNing. */
>> READ_ONCE(mem[0]);
>>
>> munmap(unaligned_mem, SZ_2M * 2);
>>
>> close(fd);
>> kvm_vm_free(vm);
>> }
>>
>> And tried to replace the fd creation the secretmem equivalent
>>
>> fd = syscall(__NR_memfd_secret, 0);
>> TEST_ASSERT(fd >= 0, "Couldn't create secretmem fd.");
>> TEST_ASSERT_EQ(ftruncate(fd, SZ_2M * 2), 0);
>>
>> Should a guest_memfd selftest be added to cover this?
>>
>> MADV_COLLAPSE fails with EINVAL, but it does go through to
>> hpage_collapse_scan_file() -> collapse_file(), before failing because
>> when collapsing the page, copy_mc_highpage() returns > 0.
>
> Just what I suspected. :)
>
> Thanks for digging into the details!
>
Happy to help :)
In general, do we want the reproducers added as selftests? Should this
be added as part of tools/testing/selftests/kvm/guest_memfd_test.c or a
separate file?
> --
> Cheers,
>
> David
^ permalink raw reply [flat|nested] 34+ messages in thread* Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
2026-02-09 18:24 ` Ackerley Tng
@ 2026-02-09 19:38 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 34+ messages in thread
From: David Hildenbrand (Arm) @ 2026-02-09 19:38 UTC (permalink / raw)
To: Ackerley Tng, Sean Christopherson
Cc: syzbot+33a04338019ac7e43a44, kvm, linux-kernel, pbonzini,
syzkaller-bugs, michael.roth, vannapurve, kartikey406
On 2/9/26 19:24, Ackerley Tng wrote:
> "David Hildenbrand (Arm)" <david@kernel.org> writes:
>
>> On 2/8/26 18:34, Ackerley Tng wrote:
>>> Ackerley Tng <ackerleytng@google.com> writes:
>>>
>>>
>>> I trimmed the repro to this:
>>>
>>> static void test_guest_memfd_repro(void)
>>> {
>>> struct kvm_vcpu *vcpu;
>>> uint8_t *unaligned_mem;
>>> struct kvm_vm *vm;
>>> uint8_t *mem;
>>> int fd;
>>>
>>> vm = __vm_create_shape_with_one_vcpu(VM_SHAPE_DEFAULT, &vcpu, 1, guest_code);
>>>
>>> fd = vm_create_guest_memfd(vm, SZ_2M * 2, GUEST_MEMFD_FLAG_MMAP |
>>> GUEST_MEMFD_FLAG_INIT_SHARED);
>>>
>>> unaligned_mem = mmap(NULL, SZ_2M + SZ_2M, PROT_READ | PROT_WRITE,
>>> MAP_FIXED | MAP_SHARED, fd, 0);
>>> mem = align_ptr_up(unaligned_mem, SZ_2M);
>>> TEST_ASSERT(((unsigned long)mem & (SZ_2M - 1)) == 0, "returned
>>> address must be aligned to SZ_2M");
>>>
>>> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_HUGEPAGE), 0);
>>>
>>> for (int i = 0; i < SZ_2M; i += SZ_4K)
>>> READ_ONCE(mem[i]);
>>>
>>> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_COLLAPSE), 0);
>>>
>>> TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_DONTNEED), 0);
>>>
>>> /* This triggers the WARNing. */
>>> READ_ONCE(mem[0]);
>>>
>>> munmap(unaligned_mem, SZ_2M * 2);
>>>
>>> close(fd);
>>> kvm_vm_free(vm);
>>> }
>>>
>>> And tried to replace the fd creation the secretmem equivalent
>>>
>>> fd = syscall(__NR_memfd_secret, 0);
>>> TEST_ASSERT(fd >= 0, "Couldn't create secretmem fd.");
>>> TEST_ASSERT_EQ(ftruncate(fd, SZ_2M * 2), 0);
>>>
>>> Should a guest_memfd selftest be added to cover this?
>>>
>>> MADV_COLLAPSE fails with EINVAL, but it does go through to
>>> hpage_collapse_scan_file() -> collapse_file(), before failing because
>>> when collapsing the page, copy_mc_highpage() returns > 0.
>>
>> Just what I suspected. :)
>>
>> Thanks for digging into the details!
>>
>
> Happy to help :)
>
> In general, do we want the reproducers added as selftests? Should this
> be added as part of tools/testing/selftests/kvm/guest_memfd_test.c
I guess adding it to guest_memfd_test.c and asserting that MADV_COLLAPSE
fails as expected could be a reasonable test case. It's not a lot of
code and easy to verify.
--
Cheers,
David
^ permalink raw reply [flat|nested] 34+ messages in thread
* Forwarded: [PATCH] KVM: guest_memfd: Prevent THP collapse of guest_memfd pages
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (7 preceding siblings ...)
2026-02-04 17:01 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
@ 2026-02-09 1:55 ` syzbot
2026-02-09 2:02 ` Forwarded: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled() syzbot
` (2 subsequent siblings)
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-09 1:55 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] KVM: guest_memfd: Prevent THP collapse of guest_memfd pages
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
guest_memfd fault handler kvm_gmem_fault_user_mapping() does not support
large folios and warns via WARN_ON_ONCE(folio_test_large(folio)).
When a guest_memfd mapping has VM_HUGEPAGE set via madvise(MADV_HUGEPAGE),
khugepaged or MADV_COLLAPSE can collapse small pages into a large folio
in the page cache. This happens because file_thp_enabled() incorrectly
returns true for guest_memfd inodes when CONFIG_READ_ONLY_THP_FOR_FS is
enabled. A subsequent page fault finds the large folio and triggers the
warning.
Fix this by setting VM_NO_KHUGEPAGED on the VMA in kvm_gmem_mmap().
This causes __thp_vma_allowable_orders() to reject THP early for both
MADV_COLLAPSE and khugepaged. The page fault path is unaffected since
guest_memfd does not define a huge_fault handler.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
virt/kvm/guest_memfd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..94ac360afe79 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -474,12 +474,13 @@ static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma)
{
if (!kvm_gmem_supports_mmap(file_inode(file)))
return -ENODEV;
-
+
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) !=
(VM_SHARED | VM_MAYSHARE)) {
return -EINVAL;
}
+ vm_flags_set(vma, VM_NO_KHUGEPAGED);
vma->vm_ops = &kvm_gmem_vm_ops;
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled()
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (8 preceding siblings ...)
2026-02-09 1:55 ` Forwarded: [PATCH] KVM: guest_memfd: Prevent THP collapse of guest_memfd pages syzbot
@ 2026-02-09 2:02 ` syzbot
2026-02-09 13:11 ` syzbot
2026-02-13 15:43 ` Forwarded: [PATCH] mm: thp: deny THP for files on anonymous inodes syzbot
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-09 2:02 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled()
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
file_thp_enabled() incorrectly returns true for guest_memfd and secretmem
inodes because they appear as regular read-only files when
CONFIG_READ_ONLY_THP_FOR_FS is enabled. This allows khugepaged and
MADV_COLLAPSE to create large folios in the page cache, but their fault
handlers do not support large folios.
Add explicit checks for GUEST_MEMFD_MAGIC and SECRETMEM_MAGIC to reject
these filesystems early in file_thp_enabled().
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
mm/huge_memory.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 40cf59301c21..4f57c78b57dd 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -93,6 +93,9 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)
return false;
inode = file_inode(vma->vm_file);
+ if (inode->i_sb->s_magic == GUEST_MEMFD_MAGIC ||
+ inode->i_sb->s_magic == SECRETMEM_MAGIC)
+ return false;
return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled()
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (9 preceding siblings ...)
2026-02-09 2:02 ` Forwarded: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled() syzbot
@ 2026-02-09 13:11 ` syzbot
2026-02-13 15:43 ` Forwarded: [PATCH] mm: thp: deny THP for files on anonymous inodes syzbot
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-09 13:11 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled()
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
file_thp_enabled() incorrectly returns true for guest_memfd and secretmem
inodes because they use alloc_file_pseudo() which does not call
get_write_access(), leaving i_writecount at 0. Combined with S_ISREG being
true, these pseudo-filesystem inodes appear as read-only regular files when
CONFIG_READ_ONLY_THP_FOR_FS is enabled.
This allows khugepaged and MADV_COLLAPSE to create large folios in the
page cache via the TVA_COLLAPSE path, but their fault handlers do not
support large folios. For guest_memfd this triggers
WARN_ON_ONCE(folio_test_large(folio)) in kvm_gmem_fault_user_mapping().
Introduce AS_NO_READ_ONLY_THP_FOR_FS address_space flag to allow
filesystems to opt out of CONFIG_READ_ONLY_THP_FOR_FS. Set this flag
in both guest_memfd and secretmem inode setup. This flag can be easily
removed along with CONFIG_READ_ONLY_THP_FOR_FS when it goes away.
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
include/linux/pagemap.h | 1 +
mm/huge_memory.c | 3 +++
mm/secretmem.c | 3 ++-
virt/kvm/guest_memfd.c | 1 +
4 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index ec442af3f886..23f559fc1a4c 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -211,6 +211,7 @@ enum mapping_flags {
AS_KERNEL_FILE = 10, /* mapping for a fake kernel file that shouldn't
account usage to user cgroups */
AS_NO_DATA_INTEGRITY = 11, /* no data integrity guarantees */
+ AS_NO_READ_ONLY_THP_FOR_FS = 12,
/* Bits 16-25 are used for FOLIO_ORDER */
AS_FOLIO_ORDER_BITS = 5,
AS_FOLIO_ORDER_MIN = 16,
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 40cf59301c21..4bdda92ce01e 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -94,6 +94,9 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)
inode = file_inode(vma->vm_file);
+ if (test_bit(AS_NO_READ_ONLY_THP_FOR_FS, &inode->i_mapping->flags))
+ return false;
+
return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
}
diff --git a/mm/secretmem.c b/mm/secretmem.c
index edf111e0a1bb..56d93a74f5fc 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -205,7 +205,8 @@ static struct file *secretmem_file_create(unsigned long flags)
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
mapping_set_unevictable(inode->i_mapping);
-
+ set_bit(AS_NO_READ_ONLY_THP_FOR_FS, &inode->i_mapping->flags);
+
inode->i_op = &secretmem_iops;
inode->i_mapping->a_ops = &secretmem_aops;
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index fdaea3422c30..b93a324c81bd 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -597,6 +597,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
inode->i_size = size;
mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
mapping_set_inaccessible(inode->i_mapping);
+ set_bit(AS_NO_READ_ONLY_THP_FOR_FS, &inode->i_mapping->flags);
/* Unmovable mappings are supposed to be marked unevictable as well. */
WARN_ON_ONCE(!mapping_unevictable(inode->i_mapping));
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread* Forwarded: [PATCH] mm: thp: deny THP for files on anonymous inodes
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
` (10 preceding siblings ...)
2026-02-09 13:11 ` syzbot
@ 2026-02-13 15:43 ` syzbot
11 siblings, 0 replies; 34+ messages in thread
From: syzbot @ 2026-02-13 15:43 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] mm: thp: deny THP for files on anonymous inodes
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
file_thp_enabled() incorrectly allows THP for files on anonymous inodes
(e.g. guest_memfd and secretmem). These files are created via
alloc_file_pseudo(), which does not call get_write_access() and leaves
inode->i_writecount at 0. Combined with S_ISREG(inode->i_mode) being
true, they appear as read-only regular files when
CONFIG_READ_ONLY_THP_FOR_FS is enabled, making them eligible for THP
collapse.
Anonymous inodes can never pass the inode_is_open_for_write() check
since their i_writecount is never incremented through the normal VFS
open path. The right thing to do is to exclude them from THP eligibility
altogether, since CONFIG_READ_ONLY_THP_FOR_FS was designed for real
filesystem files (e.g. shared libraries), not for pseudo-filesystem
inodes.
For guest_memfd, this allows khugepaged and MADV_COLLAPSE to create
large folios in the page cache via the collapse path, but the
guest_memfd fault handler does not support large folios. This triggers
WARN_ON_ONCE(folio_test_large(folio)) in kvm_gmem_fault_user_mapping().
For secretmem, collapse_file() tries to copy page contents through the
direct map, but secretmem pages are removed from the direct map. This
can result in a kernel crash:
BUG: unable to handle page fault for address: ffff88810284d000
RIP: 0010:memcpy_orig+0x16/0x130
Call Trace:
collapse_file
hpage_collapse_scan_file
madvise_collapse
Secretmem is not affected by the crash on upstream as the memory failure
recovery handles the failed copy gracefully, but it still triggers
confusing false memory failure reports:
Memory failure: 0x106d96f: recovery action for clean unevictable
LRU page: Recovered
Check IS_ANON_FILE(inode) in file_thp_enabled() to deny THP for all
anonymous inode files.
Link: https://syzkaller.appspot.com/bug?extid=33a04338019ac7e43a44
Link: https://lore.kernel.org/linux-mm/CAEvNRgHegcz3ro35ixkDw39ES8=U6rs6S7iP0gkR9enr7HoGtA@mail.gmail.com
Reported-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com
Fixes: 7fbb5e188248 ("mm: remove VM_EXEC requirement for THP eligibility")
Cc: stable@vger.kernel.org
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
v2:
- Use IS_ANON_FILE(inode) to deny THP for all anonymous inode files
instead of checking for specific subsystems (David Hildenbrand)
- Updated Fixes tag to 7fbb5e188248 which removed the VM_EXEC
requirement that accidentally protected secretmem
- Expanded commit message with implications for both guest_memfd
and secretmem
---
mm/huge_memory.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 40cf59301c21..d3beddd8cc30 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -94,6 +94,9 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)
inode = file_inode(vma->vm_file);
+ if (IS_ANON_FILE(inode))
+ return false;
+
return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 34+ messages in thread