-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Bluetooth: controller: Fix ticker to avoid recursive ticker_job #32752
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
Bluetooth: controller: Fix ticker to avoid recursive ticker_job #32752
Conversation
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.
Consider also moving clearing of the job_guard to after ticker_job_compare_update
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.
Is this because ticks_slot_previous and ticks_current are updated in ticker_job_compare_update, and the vectoring (swap) to ticker_worker function would use stale values? or do you have other reasons?
(sorry for asking again, from the message here: #31026 (comment), I understand context-safety, but just making double sure :-) ).
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.
Is this because
ticks_slot_previousandticks_currentare updated inticker_job_compare_update, and the vectoring (swap) toticker_workerfunction would use stale values? or do you have other reasons?
Yes, that is exactly why. The suggestion is not based on an actual observation, just based on analysis and being cautious.
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.
Agreed. Your analysis is correct, as the resolution happens in ticker_worker, there are chances that after a current reserving ticker is stopped, it is necessary to have correct value of ticks_slot_previous and ticks_current be used in the ticker_worker.
Fix ticker job to defer itself to avoid recursive invocation to itself due to ticker interface calls from inside the ticker operation callbacks. The recursive use was exposed when using ticker stop operation callback of stopping an auxiliary PDU to stop the primary PDU scheduling as part of generation of Advertising Terminate event. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Move the ticker job_guard reset to after ticker_job_compare_update, so that the ticks_current and ticks_slot_previous are updated before ticker_worker gets to execute. Without this fix, there is a possibility that ticker_worker will use incorrect ticks_slot_previous and ticks_current value under race conditions. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
65a2158 to
ce32cc4
Compare
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.
Looks good!
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.
LGTM
Fix ticker job to defer itself to avoid recursive
invocation to itself due to ticker interface calls from
inside the ticker operation callbacks.
The recursive use was exposed when using ticker stop
operation callback of stopping an auxiliary PDU to stop
the primary PDU scheduling as part of generation of
Advertising Terminate event.
Signed-off-by: Vinayak Kariappa Chettimada [email protected]