implement retry on SPIM failure

somehow, the retry still *fails* - to be looked into in the future
This commit is contained in:
bunnie 2024-11-19 22:17:19 +08:00
parent 265805ac94
commit d78899ca74
2 changed files with 32 additions and 17 deletions

View file

@ -42,4 +42,4 @@ oom-doom = []
debug-print = [] debug-print = []
debug-verbose = [] debug-verbose = []
default = [] default = ["debug-print"]

View file

@ -521,6 +521,11 @@ fn swap_handler(
// safety: this is only safe because the pointer we're passed from the kernel is guaranteed to be // safety: this is only safe because the pointer we're passed from the kernel is guaranteed to be
// a valid u8-page in memory // a valid u8-page in memory
let buf = unsafe { core::slice::from_raw_parts_mut(vaddr_in_swap as *mut u8, PAGE_SIZE) }; let buf = unsafe { core::slice::from_raw_parts_mut(vaddr_in_swap as *mut u8, PAGE_SIZE) };
// this is in a retry loop because the SPIM interface can timeout during high bus congestion
// periods.
const TIMEOUT_RETRIES: usize = 3;
let mut retries = 0;
while retries < TIMEOUT_RETRIES {
match ss.hal.decrypt_swap_from( match ss.hal.decrypt_swap_from(
buf, buf,
ss.sct.counts[paddr_in_swap / PAGE_SIZE], ss.sct.counts[paddr_in_swap / PAGE_SIZE],
@ -528,15 +533,25 @@ fn swap_handler(
vaddr_in_pid, vaddr_in_pid,
pid, pid,
) { ) {
Ok(_) => {} Ok(_) => {
break;
}
Err(e) => { Err(e) => {
retries += 1;
writeln!( writeln!(
DebugUart {}, DebugUart {},
"Decryption error: swap image corrupted, the tag does not match the data! {:?}", "Decryption error: swap image corrupted, the tag does not match the data! {:?} (try {}/{})",
e e,
retries,
TIMEOUT_RETRIES
) )
.ok(); .ok();
panic!("Decryption error: swap image corrupted, the tag does not match the data!"); if retries >= TIMEOUT_RETRIES {
panic!(
"Decryption error: swap image corrupted, the tag does not match the data; retry count exceeded!"
);
}
}
} }
} }
// at this point, the `buf` has our desired data, we're done, modulo updating the count. // at this point, the `buf` has our desired data, we're done, modulo updating the count.