From nobody Mon Feb 9 01:44:12 2026 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B26A92F5311 for ; Tue, 3 Feb 2026 20:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770149185; cv=none; b=UaCYoujMv3zlDQ/tUWSJQbwHqdFrlyTmk0gn7k471CODiom+gL2Cz8x7KVCuZ/+OzWA9kPz+yCjP03yGipYhkJIQCkDE3ar277otYVLSQ3rdDPXqAtoubpDKtRvY9MraioKvFhZdFu3v+PE4vLilBJZzsfnviqlT++3X+xn4eWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770149185; c=relaxed/simple; bh=NurzY3v6FIjUKK6vs0RNr3CDKUBXvVerMTnNYBbFDlk=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=nWVpBgs0UubsAU1M81XmTwLMXbVd/dZIiB1Sf1yxEgi1mBOCd+xsTPMyt+6btvgf5zR3c2qGq5yCrKZajDr9ig8YC2WqwbnQoFlMWWiE6lIMaxYXjx5j6XVnhzsp0dX0jfrbU+7HN5c+GaojD/HYlNBFyGKQL2/UOrugPj/RdfE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-663134c706eso650715eaf.0 for ; Tue, 03 Feb 2026 12:06:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770149182; x=1770753982; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zaSQ/trPz49O0qv/c4suedseoDB86Tom9a4Q3CwQf3Q=; b=Ya64t2D+w6GOASwc5LZKZS50H437dH8olhitmNDlwBRyLQEvsiyHNyiIp4gIOM8r7+ J2F0b+8WL+I07R11FUQFr19L8aDw5ZtgsDmlaMLoPJAhnrb21aOstrjol6VcoCLfV4hs EtsX9aj69p6wcizR3csUIYJhE2qSXzb9x9kiMFfRJo6zaR4OMLXcy3q1zB3E2kwRqgw5 vcsm5CGkknt80rzR3StPFobIz2N+19Z2ZfRR/62rOT7e0r8G9Jdep2YAWgJe3H52c8uh EMhT3r5ICN02tI/wTk987r4TlslJA3umugppi9P/3xgd5Iw24T+n0+zEcxDGL+rK7wcY OhSg== X-Gm-Message-State: AOJu0YzYAYXuib6xjIriqxNY1ApAUHAAptCqe5Y51sGhRl4u5kfWesAJ t8PMRlEscZQQ/Nop3JqA7s6oX+FKA9KWipbkaZTfQmlhMoVlqcc58Z1icQ53OZFv2hknqunPwDd TCXFTAfmPAwZyd1peDgZTTc3n7SqnuhCbghoXfjcIET6hN8vfr6dEILCJLdM= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:16aa:b0:662:fb51:48d with SMTP id 006d021491bc7-668c5eac004mr1881728eaf.4.1770149182605; Tue, 03 Feb 2026 12:06:22 -0800 (PST) Date: Tue, 03 Feb 2026 12:06:22 -0800 In-Reply-To: <697d115a.050a0220.1d61ec.0004.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6982553e.a00a0220.34fa92.0009.GAE@google.com> Subject: Forwarded: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 f= or 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=3D33a04338019ac7e43a44 Tested-by: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com Signed-off-by: Ackerley Tng --- 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 =3D __filemap_get_folio(inode->i_mapping, index, FGP_LOCK | FGP_ACCESSED, 0); if (!IS_ERR(folio)) return folio; + gfp =3D mapping_gfp_mask(inode->i_mapping); + policy =3D mpol_shared_policy_lookup(&GMEM_I(inode)->policy, index); - folio =3D __filemap_get_folio_mpol(inode->i_mapping, index, - FGP_LOCK | FGP_ACCESSED | FGP_CREAT, - mapping_gfp_mask(inode->i_mapping), policy); + folio =3D filemap_alloc_folio(gfp, 0, policy); mpol_cond_put(policy); + if (!folio) + return ERR_PTR(-ENOMEM); - return folio; + ret =3D filemap_add_folio(inode->i_mapping, folio, index, gfp); + if (ret) + folio_put(folio); + + if (ret =3D=3D -EEXIST) + goto repeat; + + return ret ? ERR_PTR(ret) : folio; } static enum kvm_gfn_range_filter kvm_gmem_get_invalidate_filter(struct ino= de *inode) -- 2.53.0.rc2.204.g2597b5adb4-goog