* [PATCH] xfs: improve RT geometry validation
@ 2026-05-07 5:25 ` Christoph Hellwig
2026-05-07 12:17 ` Carlos Maiolino
2026-05-07 17:17 ` Darrick J. Wong
0 siblings, 2 replies; 5+ messages in thread
From: Christoph Hellwig @ 2026-05-07 5:25 UTC (permalink / raw)
To: cem; +Cc: djwong, linux-xfs
Make sure the rtgcount is plausible for the given RT group size.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 47322adb7690..c0354f43704f 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -302,17 +302,25 @@ xfs_validate_rt_geometry(
return false;
if (xfs_sb_is_v5(sbp) &&
- (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED)) {
+ (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR)) {
+ uint64_t nr_rgs;
uint32_t mod;
/*
- * Zoned RT devices must be aligned to the RT group size,
- * because garbage collection assumes that all zones have the
- * same size to avoid insane complexity if that weren't the
- * case.
+ * Check that the number of rgcounts is plausible for the RG
+ * size.
+ */
+ nr_rgs = div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
+ if (nr_rgs != sbp->sb_rgcount + !!mod)
+ return false;
+
+ /*
+ * Zoned RT devices must be aligned to the RT group size because
+ * garbage collection assumes that all zones have the same size
+ * to avoid insane complexity if that weren't the case.
*/
- div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
- if (mod)
+ if ((sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED) &&
+ mod > 0)
return false;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: improve RT geometry validation
2026-05-07 5:25 ` [PATCH] xfs: improve RT geometry validation Christoph Hellwig
@ 2026-05-07 12:17 ` Carlos Maiolino
2026-05-07 17:17 ` Darrick J. Wong
1 sibling, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2026-05-07 12:17 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: djwong, linux-xfs
On Thu, May 07, 2026 at 07:25:35AM +0200, Christoph Hellwig wrote:
> Make sure the rtgcount is plausible for the given RT group size.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++-------
> 1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> index 47322adb7690..c0354f43704f 100644
> --- a/fs/xfs/libxfs/xfs_sb.c
> +++ b/fs/xfs/libxfs/xfs_sb.c
> @@ -302,17 +302,25 @@ xfs_validate_rt_geometry(
> return false;
>
> if (xfs_sb_is_v5(sbp) &&
> - (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED)) {
> + (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR)) {
> + uint64_t nr_rgs;
> uint32_t mod;
>
> /*
> - * Zoned RT devices must be aligned to the RT group size,
> - * because garbage collection assumes that all zones have the
> - * same size to avoid insane complexity if that weren't the
> - * case.
> + * Check that the number of rgcounts is plausible for the RG
> + * size.
> + */
> + nr_rgs = div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
> + if (nr_rgs != sbp->sb_rgcount + !!mod)
> + return false;
> +
> + /*
> + * Zoned RT devices must be aligned to the RT group size because
> + * garbage collection assumes that all zones have the same size
> + * to avoid insane complexity if that weren't the case.
> */
> - div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
> - if (mod)
> + if ((sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED) &&
> + mod > 0)
> return false;
> }
Looks good
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
>
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: improve RT geometry validation
2026-05-07 5:25 ` [PATCH] xfs: improve RT geometry validation Christoph Hellwig
2026-05-07 12:17 ` Carlos Maiolino
@ 2026-05-07 17:17 ` Darrick J. Wong
2026-05-08 8:16 ` Christoph Hellwig
1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2026-05-07 17:17 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: cem, linux-xfs
On Thu, May 07, 2026 at 07:25:35AM +0200, Christoph Hellwig wrote:
> Make sure the rtgcount is plausible for the given RT group size.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/libxfs/xfs_sb.c | 22 +++++++++++++++-------
> 1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> index 47322adb7690..c0354f43704f 100644
> --- a/fs/xfs/libxfs/xfs_sb.c
> +++ b/fs/xfs/libxfs/xfs_sb.c
> @@ -302,17 +302,25 @@ xfs_validate_rt_geometry(
> return false;
>
> if (xfs_sb_is_v5(sbp) &&
> - (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED)) {
> + (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR)) {
> + uint64_t nr_rgs;
> uint32_t mod;
>
> /*
> - * Zoned RT devices must be aligned to the RT group size,
> - * because garbage collection assumes that all zones have the
> - * same size to avoid insane complexity if that weren't the
> - * case.
> + * Check that the number of rgcounts is plausible for the RG
> + * size.
> + */
> + nr_rgs = div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
> + if (nr_rgs != sbp->sb_rgcount + !!mod)
> + return false;
Isn't this already covered by xfs_validate_sb_rtgroups?
groups = howmany_64(sbp->sb_rextents, sbp->sb_rgextents);
if (groups != sbp->sb_rgcount) {
xfs_warn(mp,
"Realtime groups (%u) do not cover the entire rt section; need (%llu) groups.",
sbp->sb_rgcount, groups);
return -EINVAL;
}
> +
> + /*
> + * Zoned RT devices must be aligned to the RT group size because
> + * garbage collection assumes that all zones have the same size
> + * to avoid insane complexity if that weren't the case.
> */
> - div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
> - if (mod)
> + if ((sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED) &&
> + mod > 0)
> return false;
And shouldn't this be in xfs_validate_sb_zoned?
Or do you want this in xfs_validate_rt_geometry because that's what
xfs_repair calls to check the superblock?
--D
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: improve RT geometry validation
2026-05-07 17:17 ` Darrick J. Wong
@ 2026-05-08 8:16 ` Christoph Hellwig
2026-05-09 0:54 ` Darrick J. Wong
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2026-05-08 8:16 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Christoph Hellwig, cem, linux-xfs
On Thu, May 07, 2026 at 10:17:58AM -0700, Darrick J. Wong wrote:
> Isn't this already covered by xfs_validate_sb_rtgroups?
From a quick look it should...
> > - div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
> > - if (mod)
> > + if ((sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED) &&
> > + mod > 0)
> > return false;
>
> And shouldn't this be in xfs_validate_sb_zoned?
This just slightly moves code.
> Or do you want this in xfs_validate_rt_geometry because that's what
> xfs_repair calls to check the superblock?
I guess. At least it was repair that went off on my badly messed up
file system without this fix.
Maybe it's time to go back to the drawing board for the sb validation.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: improve RT geometry validation
2026-05-08 8:16 ` Christoph Hellwig
@ 2026-05-09 0:54 ` Darrick J. Wong
0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2026-05-09 0:54 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: cem, linux-xfs
On Fri, May 08, 2026 at 10:16:51AM +0200, Christoph Hellwig wrote:
> On Thu, May 07, 2026 at 10:17:58AM -0700, Darrick J. Wong wrote:
> > Isn't this already covered by xfs_validate_sb_rtgroups?
>
> From a quick look it should...
>
> > > - div_u64_rem(sbp->sb_rextents, sbp->sb_rgextents, &mod);
> > > - if (mod)
> > > + if ((sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED) &&
> > > + mod > 0)
> > > return false;
> >
> > And shouldn't this be in xfs_validate_sb_zoned?
>
> This just slightly moves code.
>
> > Or do you want this in xfs_validate_rt_geometry because that's what
> > xfs_repair calls to check the superblock?
>
> I guess. At least it was repair that went off on my badly messed up
> file system without this fix.
>
> Maybe it's time to go back to the drawing board for the sb validation.
Yeah, it's unfortunate that xfs_repair duplicates most of that sb
validation code just so it can return an enum instead of xfs_err()ing
all over the place. :/
--D
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-09 0:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <wV6uRtt8Mdv0dR-Ory4pMu4E-SDYDmUrTwaPRauY7S4lM07r4ogMmp38xxeF3FNG3X_E46ujDJHX94Lq_Oe-Vg==@protonmail.internalid>
2026-05-07 5:25 ` [PATCH] xfs: improve RT geometry validation Christoph Hellwig
2026-05-07 12:17 ` Carlos Maiolino
2026-05-07 17:17 ` Darrick J. Wong
2026-05-08 8:16 ` Christoph Hellwig
2026-05-09 0:54 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox