From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796260005; b=LZwTKr002qVbfjg+kJibm3ofY3gAfP3urlox51V2n+G9HVNnEU+BnYI2yesaahEySTnc udL3/M0LO62JZ8PleNRioeeFgY7LZ0B/vvFT+COG3ayWSd09OwjVsGJPlmztaPNASTTuh /YCLB+gqHUInINyOawXNhy1dIuBWAQv1e/wy1vMwriXfM2iGVINVNNVAktDox+jeZNA5Y vYTn6hUKamtUzMpn5azPzaJRptTCj/gNDWamS0oWHK+kGUTs7l1ZMr5j7TJPP6O2a1Moc suY9LJpePtXA3EPvfqyMDmdqr/mCFE+nOAsfMxhn74Fnswn1q51bEaDCZDUH47HCn5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796260005; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=7XtWoIxKRGudumMFWLlctB0LO8dhnEb/FUElp17EvwA=; b=K7kx9yGk6XF9ppSFrmtD+j376YFdyVD3Su0ODdjx9Q/88OFpOWm2wgk1a647colJXrPo eeTniJ3IJul98onYgCSNosKh7Ooqlu+NA2FgGEknF25s82CIr8LSZ+dYCKwp6QGhxZZhO WUi/STXC63+YKMkPH2HX5ZGL1Srn89FFE+njSj3xpmE0w1TA2HJ0xptzNLgjSS2kw/zHo ZnhCbrTqfTfn9KqmOtOISvmW+hUJWzTnEYCbmM9XXcAHsi/0ZIZjXXjfJomGIG7g50/Cc pcn2tiGk+aiTdvzVum3qmnEVeESssQfM0h+tkbu727KQ7K6DS4ekjVwN9sFfbT/9Puw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=e1ibTI++; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C274606A322; Thu, 3 Dec 2026 01:06:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=e1ibTI++ Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE8B41F000C1; Thu, 3 Dec 2026 01:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796260005; bh=7XtWoIxKRGudumMFWLlctB0LO8dhnEb/FUElp17EvwA=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=e1ibTI++QLIfDPFH/YjoTUCxH0BIbdbEU7giZMSPwzwuoR2LtnZb2BF7aFjJRGgQe mQ+F1jkNda3EP0q5ErY00F0SpR1eSMlOGyC2pPJxfYra4vUqUa5iSRzpGmI8RoMDW8 v23YmmUcmgdhO3+jC1YTw5MW8Lceu7x8FbviyVCs= Date: Wed, 2 Dec 2026 17:06:44 -0800 From: Andrew Morton To: Qian Xiao Cc: Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Krystian Kaniewski Subject: Re: [PATCH v3] xarray: fix index jumping backwards in xas_find_marked() Message-Id: <20261202170644.8b79f3de9e4e9c1df1b85e0f@linux-foundation.org> In-Reply-To: <20261129235255.848478-1-heyheyco@gmail.com> References: <20261124213424.2224554-1-heyheyco@gmail.com> <20261126190847.3064508-1-heyheyco@gmail.com> <20261127222110.3755894-1-heyheyco@gmail.com> <20261128191203.6d8a42b8a55809048367f903@linux-foundation.org> <20261129235255.848478-1-heyheyco@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 29 Nov 2026 15:52:55 -0800 Qian Xiao wrote: > On Sat, 28 Nov 2026 19:12:03 -0800 Andrew Morton wrote: > > What is the relationship between this and Krystian's identically-named > > patch? > > Thanks for taking a look. Krystian's patch is a4e667346a8d. It only > changes xas_find(). This is the same fix for xas_find_marked(), and it > doesn't touch xas_find(). > > > The kernel was not built. > > > > Well that isn't encouraging :( > > Fair point. I've since built an x86_64 defconfig vmlinux > successfully, without errors. The bug is legit and your patch (after fixing the Sashiko thing) fixes it. I'm struggling to figure out the userspace impact of the bug. It seems to be minor. afaict it's __folio_mark_dirty() -> set PAGECACHE_TAG_DIRTY WB_SYNC_ALL or tagged writeback -> transform PAGECACHE_TAG_DIRTY into PAGECACHE_TAG_TOWRITE writeback_iter() -> start IO on PAGECACHE_TAG_TOWRITE folios concurrent split -> uh oh, this makes the marked scan of mapping->i_pages move its xas.xa_index backwards. This can consume background writeback's page budget before it reaches later dirty folios. I could reproduce the backward jumping in test_xarray and in a kernel module scanning a real tmpfs page-cache XArray. The module set PAGECACHE_TAG_DIRTY itself - I couldn't reproduce the writeback-didn't-write-enough-stuff thing in actual testing. It turns out that there's more to the world than mm/, but Token Taxing Terrorist couldn't convincingly find any other xarray users which are impacted by this. DAX and memfd are "maybe, possibly". I've temporarily turned your patch into a series of three: 1: add the test 2: add your fix 3: add a (needed) -fix for the Sashiko thing I like to stage the test before the fix for simplifying the test-without/test-with testing. Shall scrunch everything together later. Sashiko -fix: --- a/lib/xarray.c~xarray-fix-index-jumping-backwards-in-xas_find_marked-fix +++ a/lib/xarray.c @@ -1544,8 +1544,10 @@ void *xas_find_marked(struct xa_state *x entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK)) continue; - if (xa_is_sibling(entry)) + if (xa_is_sibling(entry)) { + advance = true; continue; + } if (!xa_is_node(entry)) return entry; if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) _