Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH v3] linux-gen: fix unaligned access in checksum calculation #1946

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

JannePeltonen
Copy link
Collaborator

Architectures that support unaligned access do not necessarily support it for all instructions that a compiler might choose to use. Therefore we should not mispresent the alignment of an object to the compiler even when unaligned access is typically supported.

The current checksum code casts a potentially unaligned pointer to uint32_t when _ODP_UNALIGNED is set. This typically works but may, in some cases, result in generation of invalid code. In particular, when targeting AArch32 (which supports unaligned access for regular loads and stores) gcc-12.2 generated LDM instructions which always reguire 4-byte alignment.

Fix the problem by informing the compiler about the non-standard alignment by using a type attribute.

@odpbuild odpbuild changed the title linux-gen: fix unaligned access in checksum calculation [PATCH v1] linux-gen: fix unaligned access in checksum calculation Nov 9, 2023
@odpbuild odpbuild changed the title [PATCH v1] linux-gen: fix unaligned access in checksum calculation [PATCH v2] linux-gen: fix unaligned access in checksum calculation Nov 10, 2023
@JannePeltonen
Copy link
Collaborator Author

v2: there was still a possible unaligned uint16_t pointer that is now fixed. Also fixed the casts to use the unaligned types.

Architectures that support unaligned access do not necessarily support
it for all instructions that a compiler might choose to use. Therefore
we should not mispresent the alignment of an object to the compiler even
when unaligned access is typically supported.

The current checksum code casts a potentially unaligned address to a
pointer to uint32_t when _ODP_UNALIGNED is set. This typically works but
may, in some cases, result in generation of invalid code. In particular,
when targeting AArch32 (which supports unaligned access for regular loads
and stores) gcc-12.2 generated LDM instructions which always reguire
4-byte alignment.

Fix the problem by informing the compiler about the non-standard alignment
by using a type attribute.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Jere Leppänen <jere.leppanen@nokia.com>
@odpbuild odpbuild changed the title [PATCH v2] linux-gen: fix unaligned access in checksum calculation [PATCH v3] linux-gen: fix unaligned access in checksum calculation Nov 10, 2023
@MatiasElo MatiasElo merged commit bfa73fb into OpenDataPlane:master Nov 13, 2023
167 checks passed
@JannePeltonen JannePeltonen deleted the fix-unaligned branch November 13, 2023 13: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.

3 participants