Skip to content

soc: apple: sep: open the host-state store only for each operation - #583

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
koxu1996:sep-store-open-per-operation
Nov 9, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
koxu1996:sep-store-open-per-operation

Conversation

@koxu1996

Copy link
Copy Markdown
Contributor

On a NixOS install with an impermanent root (ZFS, rolled back at every boot), every poweroff logs Failed to unmount /persist: Device or resource busy. The cause is the SEP driver: it keeps /var/lib/aurora-sep-host-state.bin open read-write from the kernel until power-off. This opens it only while it is being used.

What happened

store::Store::open() opens the host-state file once at probe, and Store holds that file in host_store for the driver's lifetime. The open comes from the kernel, so no process owns it, and killing every process at shutdown does not close it.

On this machine /var/lib/aurora-sep-host-state.bin is a symlink into /persist, where all persistent state lives. A final-shutdown hook captured the following:

  • After systemd-shutdown's SIGKILL, only kernel threads were left.
  • Remounting /persist read-only failed with EBUSY, which happens while a file is open for writing.
  • The unmount failed with EBUSY too, and still failed 1 s and 3 s later.
  • /persist stayed mounted read-write until power-off.
  • Every other mount from the same file system unmounted normally.

The keybag, ref-key and catacomb files are already opened per use, and the xART store is a block device under /dev. So the host-state store is the only file that stays open.

Anything that keeps /var/lib off the root file system is affected the same way: a separate /var or /var/lib, or impermanence setups like this one.

The change (store.rs only)

  • Store keeps the slot table and generation in memory as before, but no longer holds the file.
  • It opens the file to load it at probe, to read a record, and once for each write, and closes it when the operation returns.
  • The write sequence (intent, sync, data, sync, table, sync) and the on-disk format are unchanged, so store_shipped.rs and the compatibility tests are unaffected.
  • Store is generic over a small StoreSource that opens the backing file. Production uses HostFile (STORE_PATH via open_host). An open StoreIo that is Copy is its own source, so the KUnit tests keep using &MemoryFile without changes.
  • from_file is now only used by the tests, so it is #[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)]. Production loads through Store::open(), which reuses the file open_host just opened.

Tested

  • J413 (MacBook Air M2), NixOS, root on ZFS rolled back at boot, store on /persist. Running feat/sep at 120e030 (7.1.9) with the same change made to the older store.rs:
    • Touch ID verification works across reboots with the existing enrolments, and the store file is read in place.
    • /persist now unmounts at poweroff; the EBUSY from before is gone.
  • This branch (integration/aurora, 7.3.0): apple-sep.ko builds with CONFIG_APPLE_SEP_KUNIT_TEST=y and no warnings (rustc 1.99).
  • Still to do: I have not run the KUnit suite. A run would be welcome.

Store::open() opens /var/lib/aurora-sep-host-state.bin read-write, and
the store keeps the file open until the driver goes away, in practice
until power-off. The driver opens it from the kernel, so no task holds
it, and killing every process at shutdown does not close it. The file
system it lives on can then be neither unmounted nor remounted
read-only: every poweroff logs

  Failed to unmount /persist: Device or resource busy

and the file system stays mounted read-write until the machine powers
off. This hits any setup where the store is not on the root file
system, such as an impermanent root that keeps /var/lib state on a
/persist file system through a symlink.

Keep the slot table in memory as before, and open the file only to load
it, to read a record and for each write, closing it when the operation
returns. The write sequence and the on-disk format do not change. The
keybag, ref-key and catacomb files are already opened per use, and the
xART store is a block device under /dev.

Store is now generic over a StoreSource that opens the backing file. An
open StoreIo that is Copy is its own source, so the KUnit tests keep
using their in-memory files unchanged.

Fixes: 24d20c9 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)")
Assisted-by: LLM
Signed-off-by: Andrzej Broński <[email protected]>
RyanTheTide added a commit that referenced this pull request Nov 9, 2026
jgoyvaerts added a commit to jgoyvaerts/linux that referenced this pull request Nov 9, 2026
The xART guard opens /var/lib/aurora-sep-xart-owned.bin read-write when
the xART store is set up and keeps it in the guard, which lives as long
as the store: until the device is unbound. Nothing unbinds it before a
reboot, so the kernel holds a writer on the file system that holds
/var/lib until power-off. systemd-shutdown's read-only remount of that
file system then fails with EBUSY and it stays read-write.

The host-state store has the same problem, and aurora-silicon#583 fixes that one.
Both files have to be closed before the file system unmounts cleanly:
on a J616s with the host-state store fixed, the root still was not
remounted read-only at shutdown, and every boot still replayed the
ext4 journal.

Open the list for each access instead: read-only for size, reads and
syncs, existing-only for writes. Only Guard::open() creates it. The
create-and-adopt rule in with_file() is unchanged: the directory is
still flushed before a list is adopted. The list format and the KUnit
tests, which use an in-memory file, are unchanged.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
@RyanTheTide
RyanTheTide merged commit 9505fe7 into aurora-silicon:integration/aurora Nov 9, 2026
@koxu1996
koxu1996 deleted the sep-store-open-per-operation branch November 13, 2026 16:16
koxu1996 added a commit to koxu1996/nixos-config that referenced this pull request Nov 16, 2026
aurora-silicon/linux#583 was merged into integration/aurora (Linux 7.3), not
feat/sep, which this kernel is pinned to; the patch stays until the pin moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants