Re: (2) (2) [PATCH v2] xfs: check the disk address for hardware atomic writes
From: John Garry
Date: Mon Nov 16 2026 - 03:12:02 EST
On 11/16/26 07:39, Daejun Park wrote:
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.
uhhh... I thought about this a bit more, and I am really not sure on the best solution. On one hand, atomic writes whose length is above opt max should not use HW atomics. Or, more specifically, the user can't expect HW atomics to be used. However, if HW atomic is possible, then it would be silly not to use it.
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.
Yeah, I was really asking if HW atomic could span 2x extents before we catch it.
This is the same in v2 and v3. In v3, a write sent to theMaybe what you have in this patch is ok. I'll wait for v3 and consider it more. Sorry for the hesitancy.
hardware is also aligned and no larger than the group alignment, so it
cannot cross a group boundary.
Thanks,
John