Skip to content

Align prefetch_policy_config struct#962

Open
rafalste wants to merge 1 commit into
Open-CAS:masterfrom
rafalste:fix_prefetch_align
Open

Align prefetch_policy_config struct#962
rafalste wants to merge 1 commit into
Open-CAS:masterfrom
rafalste:fix_prefetch_align

Conversation

@rafalste

@rafalste rafalste commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This properly alignes data and prevents UBSan from reporting misalignment errors.

Fixes #961

struct prefetch_policy_config {
uint8_t data[PREFETCH_POLICY_CONFIG_BYTES];
};
} __attribute__((aligned(4)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't it complain about other config structures (cleaning/promotion)? They are constructed and embedded into superblock exactly the same way, so their potential alignment is at best coincidental.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem of misalignment stems from the size of prefetch_mask which prepends prefetch field in the struct ocf_superblock_config.
Before the config structures for cleaning and promotion, there are cleaning/promotion_policy_type fields, which are enums and thus have a size of 4 bytes, so the next config struct is properly aligned to 4 bytes as well.
But before the prefetch config structure, there is a prefetch_mask field, which is uint8_t and 1 byte in size and the next struct is placed right after it.
That matches with the UBSan output, which shows exactly one byte shift.

Nevertheless, I've added proper alignment to cleaning and promotion config structs as well to make it more robust in case of any future changes to the field placements.

This properly alignes data and prevents UBSan from reporting
misalignment errors.

Signed-off-by: Rafal Stefanowski <r.stefanowski@pm.me>
@rafalste rafalste force-pushed the fix_prefetch_align branch from 00cf7b9 to 2c37364 Compare July 4, 2026 17:05
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.

Misaligned prefetch struct

2 participants