From d78899ca74876aee185f85c9ac85f75cf9a9def8 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 19 Nov 2024 22:17:19 +0800 Subject: [PATCH] implement retry on SPIM failure somehow, the retry still *fails* - to be looked into in the future --- services/xous-swapper/Cargo.toml | 2 +- services/xous-swapper/src/main.rs | 47 ++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/services/xous-swapper/Cargo.toml b/services/xous-swapper/Cargo.toml index 3357ed91b..569f2bfac 100644 --- a/services/xous-swapper/Cargo.toml +++ b/services/xous-swapper/Cargo.toml @@ -42,4 +42,4 @@ oom-doom = [] debug-print = [] debug-verbose = [] -default = [] +default = ["debug-print"] diff --git a/services/xous-swapper/src/main.rs b/services/xous-swapper/src/main.rs index 6408628c3..9f56c2858 100644 --- a/services/xous-swapper/src/main.rs +++ b/services/xous-swapper/src/main.rs @@ -521,22 +521,37 @@ fn swap_handler( // safety: this is only safe because the pointer we're passed from the kernel is guaranteed to be // a valid u8-page in memory let buf = unsafe { core::slice::from_raw_parts_mut(vaddr_in_swap as *mut u8, PAGE_SIZE) }; - match ss.hal.decrypt_swap_from( - buf, - ss.sct.counts[paddr_in_swap / PAGE_SIZE], - paddr_in_swap, - vaddr_in_pid, - pid, - ) { - Ok(_) => {} - Err(e) => { - writeln!( - DebugUart {}, - "Decryption error: swap image corrupted, the tag does not match the data! {:?}", - e - ) - .ok(); - panic!("Decryption error: swap image corrupted, the tag does not match the data!"); + // 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( + buf, + ss.sct.counts[paddr_in_swap / PAGE_SIZE], + paddr_in_swap, + vaddr_in_pid, + pid, + ) { + Ok(_) => { + break; + } + Err(e) => { + retries += 1; + writeln!( + DebugUart {}, + "Decryption error: swap image corrupted, the tag does not match the data! {:?} (try {}/{})", + e, + retries, + TIMEOUT_RETRIES + ) + .ok(); + 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.