From: syzbot <syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd
Date: Tue, 03 Feb 2026 12:06:22 -0800 [thread overview]
Message-ID: <6982553e.a00a0220.34fa92.0009.GAE@google.com> (raw)
In-Reply-To: <697d115a.050a0220.1d61ec.0004.GAE@google.com>
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
next prev parent reply other threads:[~2026-02-03 20:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
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
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 ` syzbot [this message]
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 ` [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)
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)
2026-02-09 18:24 ` Ackerley Tng
2026-02-09 19:38 ` David Hildenbrand (Arm)
2026-02-09 1:55 ` Forwarded: [PATCH] KVM: guest_memfd: Prevent THP collapse of guest_memfd pages syzbot
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6982553e.a00a0220.34fa92.0009.GAE@google.com \
--to=syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox