-
Notifications
You must be signed in to change notification settings - Fork 361
ams and clk fixes #10881
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
Open
lgirdwood
wants to merge
3
commits into
thesofproject:main
Choose a base branch
from
lgirdwood:fix-lib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+12
−5
Open
ams and clk fixes #10881
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how AMS works, but this looks suspicious - the type of
msgis also called "...payload" which seems to suggest that the data is also attached to the header, which would then be dropped by this change?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
messagefield is a pointer (uint8_t *message), not inline data —ams_helper_prepare_payload()doespayload->message = message, pointing at a caller-owned buffer. So the payload bytes are referenced by the pointer, not appended after the struct.AMS_MESSAGE_SIZE()=sizeof(*msg) - 1 + message_lengththerefore readsmessage_length - 1bytes past the end of the struct (adjacent memory), not the actual payload. The slot only needs to carry the struct itself (which already includes themessagepointer andmessage_length);ams_process_slot()copies the slot back into astruct ams_message_payloadand uses those fields. So copyingsizeof(*msg)preserves exactly what the consumer reads back and just removes the over-read — no payload is dropped.(Whether that
messagepointer stays valid by the time another core consumes the slot is a separate, pre-existing concern this patch doesn't change.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgirdwood yes, I saw that comment, and I don't quite understand or follow it. "The message field is a pointer (uint8_t *message), not inline data" - of course it is a pointer - a local variable, containing a pointer. A pointer to a buffer that begins with a header which is followed by data. What's the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I traced the full path to be sure, and the by-pointer reading holds:
detect_test.c: ams_notify_kpb):ams_helper_prepare_payload()setsmessage = (uint8_t *)&cd->client_data(persistent component data) andmessage_length = sizeof(struct kpb_client).kpb.c: kpb_ams_kpd_notification):struct kpb_client *cli_data = (struct kpb_client *)payload->message;— it casts themessagepointer and dereferences it; nothing reads inline bytes.send_message_over_ixc()sends an IDC message carrying only the slot index (size = 0, payload = NULL); the target core reads the slot struct from the shared coherent context and dereferencesmessage(valid across SMP cores).So the payload is never stored inline — the slot only needs the struct (which holds the
messagepointer + length).AMS_MESSAGE_SIZE() = sizeof(*msg) - 1 + message_lengthwas readingmessage_length - 1bytes past the producer struct and copying bytes the consumer never looks at;sizeof(*msg)copies exactly what's read back. So the fix is correct and no payload is dropped.It was also the only user of
AMS_MESSAGE_SIZE(), andAMS_SLOT_SIZE()had none, so I've removed both as dead/misleading in a follow-up commit.(Orthogonal, pre-existing: the by-pointer design requires the producer's buffer to outlive async cross-core delivery — current clients point at persistent state, so that's fine; just noting the contract.)