Page MenuHomeFreeBSD

Ensure I/O buffers in fsck_ffs(8) are 64-byte aligned
AbandonedPublic

Authored by mckusick on Sep 5 2023, 9:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 27, 7:56 AM
Unknown Object (File)
Fri, Apr 26, 1:41 AM
Unknown Object (File)
Fri, Apr 19, 10:23 PM
Unknown Object (File)
Apr 9 2024, 2:36 AM
Unknown Object (File)
Apr 8 2024, 11:26 AM
Unknown Object (File)
Mar 12 2024, 7:40 PM
Unknown Object (File)
Dec 20 2023, 7:56 AM
Unknown Object (File)
Dec 19 2023, 11:56 AM
Subscribers

Details

Reviewers
kib
lwhsu
Summary

Various disk controllers require their buffers to be aligned to 64 bytes. For buffers allocated in structures, ensure that they are 64-byte aligned.

Create a new Balloc() function in fsck_ffs(8) that allocates 64-byte aligned memory to use when allocating memory that will be used for doing disk I/O. Go through and change all buffer allocations to call Balloc().

On 64-bit architectures, malloc always returns 64-bit aligned allocations, so this change should have no effect. But if a bigger alignment requirement (say 128) comes down in the future, it will be trivial to implement it.

Test Plan

The aligned I/O problems most recent showed up in Azure, so test that it is works on Azure.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

mckusick added reviewers: kib, lwhsu.

Same general comments s for the other review: don't hard code 64, document which controllers, and consider just doing this all page aligned.

sbin/fsck_ffs/suj.c
2277

And maybe make this allocated with mem_aligned() for a PAGE_SIZE alignment (or the sysconf returned value since arm64 is now both 4k and 64k page sized).

Updates reflecting comments from kib.

Please use git diff -U999999 ... or like to generate patches, so that the context is available.

sbin/fsck_ffs/fsck.h
433

static inline void *

439

It is simpler to just fail on aligned_alloc() failure without trying to free one buffer, IMO. Malloc() failures mean that UVA is exhausted and/or fragmented, and apps usually cannot get out of it.

Relevant parts of these changes were incorporated in commit 772430dd6795585 as discussed in PR 267654 and review https://reviews.freebsd.org/D41724.