Align prefetch_policy_config struct#962
Conversation
7a9cdfe to
00cf7b9
Compare
| struct prefetch_policy_config { | ||
| uint8_t data[PREFETCH_POLICY_CONFIG_BYTES]; | ||
| }; | ||
| } __attribute__((aligned(4))); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
00cf7b9 to
2c37364
Compare
This properly alignes data and prevents UBSan from reporting misalignment errors.
Fixes #961