From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A95D32BEFE7 for ; Sat, 28 Feb 2026 03:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772248267; cv=none; b=ivZGLvHFiDAYmo85plz5e/YgOcKShj0OBDB3bZwmMAuEswuIaQgcyUQhKvEvXoFmJoRoe0n08Yu/JVLZJ0SformZumUBgJXnHRfYDG46QNGl2sJVNjbCqWlketGcReOnVbz3zVFj8vj2pOLBeKarsk4MACA/R+tqE9G0B2I9xcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772248267; c=relaxed/simple; bh=mNl1LbMGjYUbCzU4vQByzQJiBmXZeLfvhuiL59GXBDo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jwVKHQyjQpyWfIL6Bn8YFAgLHOmNgaH4EctGLmsFZYgk3B6UORgdclWqFIiX0Puk7Ri/+vk1GF/Ncf3QRDFMF/6vDdfLLZhYiAgMWJjArOuHCq87CBLBYFDiZdpbGjrOZ1ICZNM4WrYmIKCny7Iu66NhQ5piABsW3YnHpBo1vNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=i/IUwjHo; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="i/IUwjHo" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772248253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PYQQLk8wpmk+sABOYPuHFRoK/LYQ6t6e9PEJlhNNQ1c=; b=i/IUwjHoBmbin/bk4vmzAyNuXXnNsDly9+ntzJ+UD3h3i+ybef+o76so/8CXJDE5DIeaBh KBLEDNWenb4Ov8Mc/yi3lIUejaCsiv3OD4dv8VHcyYBNonnljwaj+M/qAoUibHlR1xEpTo K/3dqOsB2xj9dcW8neHDZYTamke2rrM= Date: Sat, 28 Feb 2026 11:10:30 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/huge_memory: fix a folio_split() race condition with folio_try_get() To: Zi Yan , Andrew Morton Cc: David Hildenbrand , Lorenzo Stoakes , Hugh Dickins , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Matthew Wilcox , Bas van Dijk , Eero Kelly , Andrew Battat , Adam Bratschi-Kaye , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org References: <20260228010614.2536430-1-ziy@nvidia.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260228010614.2536430-1-ziy@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/2/28 09:06, Zi Yan wrote: > During a pagecache folio split, the values in the related xarray should not > be changed from the original folio at xarray split time until all > after-split folios are well formed and stored in the xarray. Current use > of xas_try_split() in __split_unmapped_folio() lets some after-split folios > show up at wrong indices in the xarray. When these misplaced after-split > folios are unfrozen, before correct folios are stored via __xa_store(), and > grabbed by folio_try_get(), they are returned to userspace at wrong file > indices, causing data corruption. > > Fix it by using the original folio in xas_try_split() calls, so that > folio_try_get() can get the right after-split folios after the original > folio is unfrozen. > > Uniform split, split_huge_page*(), is not affected, since it uses > xas_split_alloc() and xas_split() only once and stores the original folio > in the xarray. > > Fixes below points to the commit introduces the code, but folio_split() is > used in a later commit 7460b470a131f ("mm/truncate: use folio_split() in > truncate operation"). > > Fixes: 00527733d0dc8 ("mm/huge_memory: add two new (not yet used) functions for folio_split()") > Reported-by: Bas van Dijk > Closes: https://lore.kernel.org/all/CAKNNEtw5_kZomhkugedKMPOG-sxs5Q5OLumWJdiWXv+C9Yct0w@mail.gmail.com/ > Signed-off-by: Zi Yan > Cc: > --- Thanks for the fix! I also made a C reproducer and tested this patch - the corruption disappeared. Without patch: corruption in < 10 iterations With patch: 1000 iterations, all clean Tested-by: Lance Yang