From nobody Wed Apr 1 22:20:18 2026 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 D28D8369997 for ; Wed, 1 Apr 2026 08:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775032896; cv=none; b=n4rACg9JHrXVD3j/w0zwOucW0D4hdLcS++wmxqrDvfU5Kl+hv/X2BPaGQt7Nw8dws/v7htFrik0KpCwF4b6a2Y4sGmy2Ug+3YHkTFNfYWHUn9+UtIPzgLeAP7ZdfLIF3puLRFqZjTlaXHzaheN2nYdX9VowggThcU45ysAQjKLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775032896; c=relaxed/simple; bh=SPrbCK1xUcO2DTRWunu1BsCNQxI3G9PCacukAmgTyME=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hj5fqozMvzLcK9Mbmj9ZwZSK6WOJ0FfsZLUKOdtq+2uk6DLwxlcfpTx36cM2DZLrG0VpEnfHvOyEx5Y6YW1dAA9ilguq0m1mXDMFSH4fuTRz/ZTotyAua/5Jm500Zv6gYzjIFwgzmQIom8as8r+ZvrQ1e3MkTO9VTO2JA49rKqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WPrrlEWt; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WPrrlEWt" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2b2503753efso26110335ad.0 for ; Wed, 01 Apr 2026 01:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775032893; x=1775637693; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=g1aqQ8mbDFeeQ3nynqxs5YAP/IEVa98qSTF28X6wFGM=; b=WPrrlEWtaWUR0TC8hty5A/hD6odQTXTkuoySE2FQglbl29KZ2TGbuv/vTQFW+m9BYc cxNr9PKn5LD2Ia67PUD36OpcUL/2poo1xxFq8vsZ68cLJKqEy8b1rnOebfwD6xx9MO6t LiOhZyWRU95R2bIpbewzgB5t5c2gC2P04mlGvH2VsMXnKASAanISHM3VegIYcpnGIJSs muH2LK8ZyCCNfZQiPwWqe4dXI0edSxklbztudfOvEHRDLyZp/4knQckD7h+ATWiO2vNI 0+O4gnVrr+aNKNe4EtSQBzSgnggicLMC5Bn/JbBdd/+DnD3Yk53jV2oSavc49d8t+ibw TtwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775032893; x=1775637693; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=g1aqQ8mbDFeeQ3nynqxs5YAP/IEVa98qSTF28X6wFGM=; b=PHuKg8cA7A4QE/SLIdzpDK7kcXfiQ3ZTWkVRHPC9pjTM8hsiY+oRqytqXbQHoxGu/0 QLtPyw0pQzPzQxMsq4VI+/33ne+G2kJjaRf5f4P2R6+68mZcH2P9CFbtYlSQYYwsPYF+ 4K2h42xZ6ZZVG7qNMReQW4U3PPyw3CJaoumKZOdYYBRslt5LoGkgPDVm9VKEzwf1j4zA qusecSUXhp4xoRdI6P15P0fDceVH/g4mzm8u+K9AXcmJNS1cTnHdh7XbOgYgtdCeZAgE qoz0yKcM5d0FxgTJGt2D1I1AfFejhwAFrXOD3VrtzggDup3l62WV/C9cNHu1K71riZAF k8Jg== X-Forwarded-Encrypted: i=1; AJvYcCWnRXZO1sqwutpGuvMxd/HaA5YiRTfu870rhP3aodYdMlevJDHqMDBqWpQ+vNWlqOo5A5vH10IBPN33AH0=@vger.kernel.org X-Gm-Message-State: AOJu0YyiQqBpMw1LKqva5OFZ9awo21Blje3eGqnScAbkFLxm7L4K9Fao AZQruHVI4B9LiT5MoRfQprwV+KFFTnfiie1jAYYr8E++Tsr9OHOxHec+ X-Gm-Gg: ATEYQzza/dQz+4LvcSudZPy8mFlCHL93xofpBvYqtP8LsRy1u3brUUTrKZMqX4lfxtY Qt4DN/sZ8CfYFZcYqNUOp+C4y2PD9fVU4KJJjMCrJBwyDhZzT1ECepXDCUQMLwLKHhciTKNZ7RO hYve1unY2qAoiSTp+BB4D34YsKFxFZC0z2zjDGdo797vUCRQM8ZKeDChZNcuTqGB3Xv+rhkHeka T0L3joYj1WjWA3PN2whlqSFYrp1uUcynVHTNx4OWsYjx2/5dyqDlWNQN97JXzcw+BakvxdWuvbn qEwX30zOrnDchqXGSjU++YeSwluKpAfoDScMjieXkHt5NmWPiwi/RFLmZVaFy8s/uMipJwopt2Z 5HVpH8n9gLtMyIdc8f2ra5DHkQoONps8/hn+e1fsRacvAqXzDOtESqZR4xBujDo/gxohMqK60RE Nhi8tJKf50ShH8iJoYVGyZcKszAokeGG7HZCcoISq8cLLHVj6SVFlHTvFvJBhVpgDquLyvKlKb2 F8HV/4= X-Received: by 2002:a17:902:ef06:b0:2b2:481b:de6c with SMTP id d9443c01a7336-2b269ade14dmr27741615ad.10.1775032893449; Wed, 01 Apr 2026 01:41:33 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:27b3:c33d:3338:bc86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b24264287csm134794435ad.3.2026.04.01.01.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 01:41:33 -0700 (PDT) From: Deepanshu Kartikey To: akpm@linux-foundation.org, david@kernel.org, ziy@nvidia.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com Cc: usama.arif@linux.dev, richard.weiyang@gmail.com, sj@kernel.org, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+a7067a757858ac8eb085@syzkaller.appspotmail.com Subject: [PATCH] mm/migrate: fix stale partially_mapped arg to deferred_split_folio() Date: Wed, 1 Apr 2026 14:11:16 +0530 Message-ID: <20260401084116.22219-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In migrate_folio_move(), src_partially_mapped is sampled from the source folio before move_to_new_folio() is called: if (folio_order(src) > 1 && !data_race(list_empty(&src->_deferred_list))) { src_deferred_split =3D true; src_partially_mapped =3D folio_test_partially_mapped(src); } A concurrent thread can unmap pages from the source folio between this read and the actual migration, making the sampled value stale. After move_to_new_folio() succeeds, __folio_migrate_mapping() has already copied all folio flags including PG_partially_mapped from src to dst. Passing the stale src_partially_mapped=3Dfalse to deferred_split_folio(dst) while dst already has PG_partially_mapped=3Dtrue triggers the invariant check in deferred_split_folio(): VM_WARN_ON_FOLIO(folio_test_partially_mapped(folio), folio) at mm/huge_memory.c:4371, because the argument contradicts the flag already set on the folio. Fix this by removing the src_partially_mapped variable entirely and reading PG_partially_mapped directly from dst after move_to_new_folio() completes, where it is authoritative and race-free. Fixes: 8a8ca142a488 ("mm: migrate: requeue destination folio on deferred sp= lit queue") Reported-by: syzbot+a7067a757858ac8eb085@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Da7067a757858ac8eb085 Tested-by: syzbot+a7067a757858ac8eb085@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- mm/migrate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 05cb408846f2..11236779e910 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1361,7 +1361,6 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, int old_page_state =3D 0; struct anon_vma *anon_vma =3D NULL; bool src_deferred_split =3D false; - bool src_partially_mapped =3D false; struct list_head *prev; =20 __migrate_folio_extract(dst, &old_page_state, &anon_vma); @@ -1378,7 +1377,6 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, if (folio_order(src) > 1 && !data_race(list_empty(&src->_deferred_list))) { src_deferred_split =3D true; - src_partially_mapped =3D folio_test_partially_mapped(src); } =20 rc =3D move_to_new_folio(dst, src, mode); @@ -1404,11 +1402,13 @@ static int migrate_folio_move(free_folio_t put_new_= folio, unsigned long private, /* * Requeue the destination folio on the deferred split queue if * the source was on the queue. The source is unqueued in - * __folio_migrate_mapping(), so we recorded the state from - * before move_to_new_folio(). + * __folio_migrate_mapping(). Read PG_partially_mapped directly from + * dst: move_to_new_folio() copies all flags from src to dst, so dst + * now holds the correct authoritative state. The pre-migration value + * sampled from src is racy and must not be used. */ if (src_deferred_split) - deferred_split_folio(dst, src_partially_mapped); + deferred_split_folio(dst, folio_test_partially_mapped(dst)); =20 out_unlock_both: folio_unlock(dst); --=20 2.43.0