-
Notifications
You must be signed in to change notification settings - Fork 361
Fix bug in scratch_reserve #1295
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
base: riscv
Are you sure you want to change the base?
Conversation
This commit fixes comparison in scratch_reserve function Change-Id: If994b333282bf706736b953227a9739e52f08139 Signed-off-by: Farid Khaydari <[email protected]>
…or alignment and bit operations This commit refactors the scratch_reserve() - Replacing hardcoded bit manipulation with BIT() macro - Using GENMASK_ULL() instead of hardcoded masks for sign extension - Applying ALIGN_UP() macro for address alignment calculations - Using DIV_ROUND_UP() instead of manual division with addition Change-Id: Ic40923ef7d9ac5ca0ffb313c9d4fc6d1457d6bbb Signed-off-by: Farid Khaydari <[email protected]>
@JanMatCodasip, @MarekVCodasip, could you take a look? This change is required to make this Spike MR pass the testing |
Failure example: |
There's a logic error in the comparisons in If riscv_xlen == 32 then fpr_read_progbuf calls internal_register_read64_progbuf_scratch function that calls scratch_reserve. And here we have our comparisons: Current code (wrong): // Option 1: data registers
if ((size_bytes + scratch->hart_address - info->dataaddr + 3) / 4 >=
info->datasize) {
// use data registers
}
// Option 2: progbuf
if ((info->progbuf_writable == YNM_YES) &&
((size_bytes + scratch->hart_address - info->progbuf_address + 3) / 4 >=
info->progbufsize)) {
// use progbuf
} What happens:
The conditions should use // Option 1: data registers
if ((size_bytes + scratch->hart_address - info->dataaddr + 3) / 4 <=
info->datasize) {
// fine for datasize > 2
}
// Option 2: progbuf
if ((info->progbuf_writable == YNM_YES) &&
((size_bytes + scratch->hart_address - info->progbuf_address + 3) / 4 <=
info->progbufsize)) {
// fine for larger progbuf
} |
Was this issue (or at least part of it?) introduced in this PR? which includes this change:
|
@TommyMurphyTM1234, the bug was already there; #424 didn’t introduce it, it preserved the same |
No description provided.