Page MenuHomeFreeBSD

vm: Support swapping arm64 MTE tags
Needs ReviewPublic

Authored by andrew on Mar 19 2026, 4:06 PM.
Tags
None
Referenced Files
F160727379: D55957.diff
Sat, Jun 27, 6:11 AM
Unknown Object (File)
Thu, Jun 25, 11:44 AM
Unknown Object (File)
Thu, Jun 25, 5:57 AM
Unknown Object (File)
Wed, Jun 24, 10:22 PM
Unknown Object (File)
Tue, Jun 23, 1:00 AM
Unknown Object (File)
Mon, Jun 22, 6:41 AM
Unknown Object (File)
Sun, Jun 21, 9:46 PM
Unknown Object (File)
Sat, Jun 20, 5:19 AM
Subscribers

Details

Reviewers
manu
alc
kib
markj
Group Reviewers
arm64
cheri
Summary

When we swap out a page containing MTE tags we need to keep a copy of
them to be restored when the page is later restored. Add support to
allocate per-page tag storage that is used when a MTE tagged page is
moved to swap and populate this with the pages tags.

Sponsored by: Arm Ltd

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 73736
Build 70619: arc lint + arc unit

Event Timeline

Is this something cheri could use too?

In CheriBSD we have a somewhat different mechanism where we embed the tags in struct swblk due to a hesitance to add more allocation to the swap path. That's not great for memory usage since it's quite a lot of space and it should be fairly compressible in most cases. I'd expect MTE to be before more compressible given it's often going to be runs of the same value. I think we could adapt this code to add CHERI tags, likely in parallel, though maybe with a shared scan loop.

In CheriBSD we have a somewhat different mechanism where we embed the tags in struct swblk due to a hesitance to add more allocation to the swap path. That's not great for memory usage since it's quite a lot of space and it should be fairly compressible in most cases. I'd expect MTE to be before more compressible given it's often going to be runs of the same value. I think we could adapt this code to add CHERI tags, likely in parallel, though maybe with a shared scan loop.

struct swblk is a fixed size, so compressing tags there won't affect memory usage. I put the tags in a separate allocation as I expect the common case is no MTE in the immediate future, so the extra space will be wasted. In CheriBSD it's different as it's more likely there will be tags in a given page.

I didn't want to compress the tags yet as it's more likely the code would be incorrect as it will likely need to allocate a number of smaller fixed-sized regions to store them in. I don't have any numbers on the size of these regions as we still need userspace support, e.g. ASAN with MTE.

Rebase & use a pointer in mte_{load,save}_tags

sys/vm/swap_pager.c
782

Where does 32 come from? It should be defined in some arm64 header I suspect.

784

Yes, it should be n * SWAP_META_PAGES: in the worst case you allocate one tag buffer per page in each swap block.

785

Shouldn't we only reserve KVA if we know that MTE will be enabled? Or is this still too early during boot?

786
1576

The object lock isn't held here, nothing is synchronizing the lookup. I think you'll have to do something like, lock the object and look up the swap block, if there is no tag buffer then drop the lock and allocate one, then retry the lookup.

It might be profitable to first scan the page to see whether the page has any tags which need saving.

1578

How is this flag synchronized? The page busy lock?

1595