Skip to content

Fix SRAT entry layout and SLIT distance lookup - #381

Merged
martin-hughes merged 2 commits into
rust-osdev:mainfrom
lexoliu:fix/srat-slit-accessors
Nov 13, 2026
Merged

martin-hughes merged 2 commits into
rust-osdev:mainfrom
lexoliu:fix/srat-slit-accessors

Conversation

@lexoliu

@lexoliu lexoliu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

SRAT and SLIT don't parse correctly at the moment. Four things, all small:

  • srat::EntryHeader::length is a u16, but an affinity structure's header is a one-byte type and a one-byte length. Every entry struct came out one byte too large, so each field after the header was read one byte late and the iterator stepped by length | next_byte << 8. This changes the field's type to u8, and adds size assertions for the six structures (16/40/24/18/12/32 bytes).
  • MemoryAffinity::length() took its high half from base_address_high.
  • Slit::matrix_raw() checked the table against N⁴ bytes rather than N², so any SLIT with more than one locality was reported as too short and came back empty (NumaInfo reads the matrix through it).
  • DistanceMatrix::distance(i, j) indexed i + j*N, the transpose of the documented i*N + j, and let i == N through.

The tests build a small SRAT and SLIT byte by byte from the spec's layouts; the SLIT uses different distances in each direction so a transposed lookup shows.

An SRAT affinity structure starts with a one-byte type and a one-byte
length; `EntryHeader::length` was a `u16`, which shifted every field
after it and broke iteration. `MemoryAffinity::length` read its high
half from the base address. `Slit::matrix_raw` required N^4 bytes for
an N x N matrix, so any multi-locality table came back empty, and
`DistanceMatrix::distance` indexed the transpose and accepted an
out-of-range locality.

@martin-hughes martin-hughes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this @lexoliu!

Good spot, and nice tests.

One minor change please as in the comments. (I do like that you check the structure sizes, it helps stop minor mistakes &/or errors in packing)

Comment thread src/sdt/srat.rs Resolved
@martin-hughes
martin-hughes merged commit c62c343 into rust-osdev:main Nov 13, 2026
6 checks passed
@martin-hughes

Copy link
Copy Markdown
Contributor

Thank you again @lexoliu

BTW, I've greatly enjoyed your personal website 😍

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