-
Notifications
You must be signed in to change notification settings - Fork 747
Alarm Syscall: fix computed dt
when both unshifted reference
and dt
from userspace have low-order bits.
#4201
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
Conversation
expired.reference.wrapping_add(expired.dt).into_usize(), | ||
expired | ||
.reference | ||
.wrapping_add(expired.dt) | ||
.into_u32_left_justified() as usize, |
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.
It's unfortunate that we don't yet have a reliable way to test this part of the code. 😞
Computing unshifted dt independently of unshifted reference can lead to too low of a final expiration if reference and dt from userspace both have low-order bits. Instead, compute unshifted dt by first computing the expected expirtion, and right-shifting it to make sure the final reference + dt expires at or after the expected expiration.
Co-authored-by: Leon Schuermann <leon@is.currently.online>
@lschuermann last one I promise, just fixes formatting |
Is there anything in terms of stability guarantees that we need to watch out for in this PR? My guess is no: the previous alarm changes (#3975) were almost entirely backwards compatible, except for the callback arguments that was left unscaled, which this PR fixes. Thus, after this PR, we should be back to being compliant to the alarm interface as it's specified and included in the previous release. |
Agree, I don't there are anything compatibility issues |
Pull Request Overview
This pull request fixes two issues in the alarm syscall driver, both necessary to correctly handle alarms that overflow in userspace. Each issue separated into its own commit:
dt
for a userspace alarm when userspace values are left-shifted to be u32 (e.g. on the 24-bit nRF52 RTC implementation) underestimateddt
in some cases where bothreference
anddt
had low-order bits that were rounded off. It is necessary to computedt
considering thereference
value when it is provided, so this PR computesdt
from the computed expiration in the shifted domain.Testing Strategy
The second commit adds test cases for 24-bit alarms with provided reference counters. Running
cargo test
without the changes in the second commit fail, and succeed with the changes. The first commit is tested via changes to libtock-c in a different PR to that repo.TODO or Help Wanted
It would be good to be able to test upcall values in unit tests, but I decided to avoid figuring out how to do that for this PR since the relevant change is pretty trivially correct, and was unnoticed simply because that value was never used.
Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.