RE:(2) (2) [PATCH v2] xfs: check the disk address for hardware atomic writes
From: Daejun Park
Date: Mon Nov 16 2026 - 02:39:12 EST
On Fri, Nov 13, 2026 at 09:45:22AM +0000, John Garry wrote:
> hmm.. I am still not confident that this the best fix. And if it is,
> then I think that we should still change the size pre-check in
> xfs_file_dio_write_atomic(). Here's a combined change which I am
> thinking of:
[...]
> bt_awu_max is the HW max, and you are saying that it is not aligned with
> the AG size (and so need a disk alignment check). However, opt max
> should be (aligned to AG size), so we could check that vs size instead.
Thanks, agreed. v3 will check the size instead of the disk address,
in both xfs_file_dio_write_atomic() and
xfs_bmap_hw_atomic_write_possible(). The limit is the one max_opt
applies: the smaller of bt_awu_max and the largest power-of-two factor
of the group size. Below that limit the existing br_startblock check is
enough, so v3 drops the disk address check.
v3 puts this limit in a helper that xfs_get_atomic_write_max_opt() also
uses, so max_opt and the checks use the same hardware limit. The checks
call the helper rather than max_opt, since max_opt is 0 on a filesystem
without reflink. When I tried max_opt there, the one-block atomic
writes went to COW and failed with -EINVAL. The helper returns
bt_awu_max when there are no groups, which is the rt device without
rtgroups.
> BTW, with your proposed change, since HW size is not aligned to AG size
> and we only check the size vs HW size for HW offload, it is in theory
> possible to have an atomic write which straddles the AG and is rejected,
> right?
Userspace does not see a rejection. Such a write maps to two extents,
so xfs_bmap_hw_atomic_write_possible() returns false and the write goes
through COW. This is the same in v2 and v3. In v3, a write sent to the
hardware is also aligned and no larger than the group alignment, so it
cannot cross a group boundary.
Best regards,
Daejun