From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ECCB5285417; Wed, 23 Apr 2025 15:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745422328; cv=none; b=aGb6Me2jU822E1bJ9FORNRmQRfrKHxohC/ze3kccXp3KnH+0ycUswX2jA3HHrak6IMt7atIXthGiTOtm0IQxbBEk9Tpv/w/sigoz3aF8xWplltYQc4iUn8z4BcoDC9MPMuQ20ulgsIAfya6Hk0DQjmeKe8crDeOtkcZo8ng4z8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745422328; c=relaxed/simple; bh=Ur8UD0EqlUBP7uaIc0LRrNg2wGraHoaxXLBLiXnzsrI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AA3BQY8Ke07fgo9LlBpV9bceLyy3kgh4drGLJLUhOiqCA34+AIsJMxt5wQ4PRG9cKqY06RRujmTDc0hpSGYZyedHMjnjq3jVivILG25BdkVjV1QELjJei/OFTxaR2/ZWpfC89r+USLEYO4uVtRlIthXtBWl/t+nEiMKVkxWekqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0fJ6kALs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0fJ6kALs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FED1C4CEE2; Wed, 23 Apr 2025 15:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745422327; bh=Ur8UD0EqlUBP7uaIc0LRrNg2wGraHoaxXLBLiXnzsrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0fJ6kALspjO4VYPeSqZrbbJGtXQNtBM0E/yDvOojvksxoebfBN5mguAvzWwaBd2WR m+W9gwjRE3pAms1DIF75mw5FfGxBQ7b7Qb5GpudGYNWgcvbiY9iFBMGCSzrFr7HdnK bK2njemELf2NMCIIm7dASPR4ItBcTxB2Uxf1rTTw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Vishal Moola (Oracle)" , Qu Wenruo , "Matthew Wilcox (Oracle)" , Vivek Kasireddy , Andrew Morton Subject: [PATCH 6.6 321/393] mm: fix filemap_get_folios_contig returning batches of identical folios Date: Wed, 23 Apr 2025 16:43:37 +0200 Message-ID: <20250423142656.596106128@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250423142643.246005366@linuxfoundation.org> References: <20250423142643.246005366@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vishal Moola (Oracle) commit 8ab1b16023961dc640023b10436d282f905835ad upstream. filemap_get_folios_contig() is supposed to return distinct folios found within [start, end]. Large folios in the Xarray become multi-index entries. xas_next() can iterate through the sub-indexes before finding a sibling entry and breaking out of the loop. This can result in a returned folio_batch containing an indeterminate number of duplicate folios, which forces the callers to skeptically handle the returned batch. This is inefficient and incurs a large maintenance overhead. We can fix this by calling xas_advance() after we have successfully adding a folio to the batch to ensure our Xarray is positioned such that it will correctly find the next folio - similar to filemap_get_read_batch(). Link: https://lkml.kernel.org/r/Z-8s1-kiIDkzgRbc@fedora Fixes: 35b471467f88 ("filemap: add filemap_get_folios_contig()") Signed-off-by: Vishal Moola (Oracle) Reported-by: Qu Wenruo Closes: https://lkml.kernel.org/r/b714e4de-2583-4035-b829-72cfb5eb6fc6@gmx.com Tested-by: Qu Wenruo Cc: Matthew Wilcox (Oracle) Cc: Vivek Kasireddy Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/filemap.c | 1 + 1 file changed, 1 insertion(+) --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2256,6 +2256,7 @@ unsigned filemap_get_folios_contig(struc *start = folio->index + nr; goto out; } + xas_advance(&xas, folio_next_index(folio) - 1); continue; put_folio: folio_put(folio);