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 D4E0928312D for ; Wed, 21 Jan 2026 02:13:31 +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=1768961611; cv=none; b=pqlCPltUHfg5PGrbwPm77n+wDncp2xjeqBLsu5Sm1VFxGwNlscm+Aab0fgCELo1goVYgfSUp98sl3wyrmPI1VoWuQjGmLMUWzTKlHUOCcFoLB80QLXZQeFuzsJR8VLb5Hmvx64FiBMuIsjgns1a4+7pKDsMbds/bpiS3zjHel0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768961611; c=relaxed/simple; bh=B5A+cSVVIBrLRtxhgw5ITmlGcyNs90iDicXjPoi+yWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ScQ2WK1YWVSAycxhmKfjpEw1DzXlDbe0oZZzHgtPD5t4MIp56ftpxkcoB7xRPPlI+K5OhxaIkS9bk3MDubcg9DLRbvBB0FzAvvD8Y20Lm5ErhaBuH153DE2p5g8hagbHuBfgVED78WLC27CGxV3j3n6JeeX1ODO5ji3WzL8urPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i0siBT/b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i0siBT/b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9CFEC16AAE; Wed, 21 Jan 2026 02:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768961611; bh=B5A+cSVVIBrLRtxhgw5ITmlGcyNs90iDicXjPoi+yWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i0siBT/b2VmthTPuWZweSvw/RHfioSPFlRriDdy+/Ij7IcTOBuLxsODM9K7MaNarl DwN6TRFSdojd23XGw1EIbS6yjmRMovC2qDnxf/qO2z277lU4tR8BTBPlOeB1Bi8W2M yDuNyqOxI8SWVOeUNjQDypPkA3ae5lVu3/eeArT374tolp89qIheSVEl7tte+H5SbW JAoItYzVWUM+RLi4j4inaPRX4DrxEfKh8wveVJzfE75usQh/l58t1IlU1BiM51KKlB qTgeDH9l20TcqQOXVGQ+GCzkb2638WG/n0MG590+YIUa53gM3ndT9MlPTrg50hnoYp bl9rBhdX6akvw== From: Sasha Levin To: stable@vger.kernel.org Cc: Brian Foster , "Darrick J. Wong" , Carlos Maiolino , Sasha Levin Subject: [PATCH 6.6.y] xfs: set max_agbno to allow sparse alloc of last full inode chunk Date: Tue, 20 Jan 2026 21:13:29 -0500 Message-ID: <20260121021329.1126671-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026012007-legal-directly-ad82@gregkh> References: <2026012007-legal-directly-ad82@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Brian Foster [ Upstream commit c360004c0160dbe345870f59f24595519008926f ] Sparse inode cluster allocation sets min/max agbno values to avoid allocating an inode cluster that might map to an invalid inode chunk. For example, we can't have an inode record mapped to agbno 0 or that extends past the end of a runt AG of misaligned size. The initial calculation of max_agbno is unnecessarily conservative, however. This has triggered a corner case allocation failure where a small runt AG (i.e. 2063 blocks) is mostly full save for an extent to the EOFS boundary: [2050,13]. max_agbno is set to 2048 in this case, which happens to be the offset of the last possible valid inode chunk in the AG. In practice, we should be able to allocate the 4-block cluster at agbno 2052 to map to the parent inode record at agbno 2048, but the max_agbno value precludes it. Note that this can result in filesystem shutdown via dirty trans cancel on stable kernels prior to commit 9eb775968b68 ("xfs: walk all AGs if TRYLOCK passed to xfs_alloc_vextent_iterate_ags") because the tail AG selection by the allocator sets t_highest_agno on the transaction. If the inode allocator spins around and finds an inode chunk with free inodes in an earlier AG, the subsequent dir name creation path may still fail to allocate due to the AG restriction and cancel. To avoid this problem, update the max_agbno calculation to the agbno prior to the last chunk aligned agbno in the AG. This is not necessarily the last valid allocation target for a sparse chunk, but since inode chunks (i.e. records) are chunk aligned and sparse allocs are cluster sized/aligned, this allows the sb_spino_align alignment restriction to take over and round down the max effective agbno to within the last valid inode chunk in the AG. Note that even though the allocator improvements in the aforementioned commit seem to avoid this particular dirty trans cancel situation, the max_agbno logic improvement still applies as we should be able to allocate from an AG that has been appropriately selected. The more important target for this patch however are older/stable kernels prior to this allocator rework/improvement. Cc: stable@vger.kernel.org # v4.2 Fixes: 56d1115c9bc7 ("xfs: allocate sparse inode chunks on full chunk allocation failure") Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino [ xfs_ag_block_count(args.mp, pag_agno(pag)) => args.mp->m_sb.sb_agblocks ] Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_ialloc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index b83e54c709069..fc6cf445123ea 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -791,14 +791,15 @@ xfs_ialloc_ag_alloc( * invalid inode records, such as records that start at agbno 0 * or extend beyond the AG. * - * Set min agbno to the first aligned, non-zero agbno and max to - * the last aligned agbno that is at least one full chunk from - * the end of the AG. + * Set min agbno to the first chunk aligned, non-zero agbno and + * max to one less than the last chunk aligned agbno from the + * end of the AG. We subtract 1 from max so that the cluster + * allocation alignment takes over and allows allocation within + * the last full inode chunk in the AG. */ args.min_agbno = args.mp->m_sb.sb_inoalignmt; args.max_agbno = round_down(args.mp->m_sb.sb_agblocks, - args.mp->m_sb.sb_inoalignmt) - - igeo->ialloc_blks; + args.mp->m_sb.sb_inoalignmt) - 1; error = xfs_alloc_vextent_near_bno(&args, XFS_AGB_TO_FSB(args.mp, pag->pag_agno, -- 2.51.0