From 809dbbdbc2cece6f58972233ca04a6f6ade89fcf Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 26 Dec 2021 16:29:35 +0800 Subject: [PATCH] fix a bug in the reserved amount of data in large keys --- services/pddb/src/backend/basis.rs | 14 +++++++++----- services/pddb/src/backend/dictionary.rs | 8 +++++--- services/pddb/src/main.rs | 8 +++++--- xous-rs/src/definitions.rs | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/services/pddb/src/backend/basis.rs b/services/pddb/src/backend/basis.rs index 45a5b38fd..743d5e15d 100644 --- a/services/pddb/src/backend/basis.rs +++ b/services/pddb/src/backend/basis.rs @@ -1116,17 +1116,21 @@ impl BasisCacheEntry { pub(crate) fn dict_delete(&mut self, hw: &mut PddbOs, name: &str, paranoid: bool) -> Result<()> { if self.ensure_dict_in_cache(hw, name) { let dcache = self.dicts.get_mut(name).expect("entry was ensured, but somehow missing"); - //log::info!("dcache {} index {}, key_count {}", name, dcache.index, dcache.key_count); + log::trace!("dcache {} index {}, key_count {}", name, dcache.index, dcache.key_count); // ensure all the keys are in RAM dcache.fill(hw, &self.v2p_map, &self.cipher); - //log::info!("dcache filled"); + // allocate a copy of the key list, to avoid interior mutability problems with the next remove step let mut key_list = Vec::::new(); - for key in dcache.keys.keys() { - key_list.push(key.to_string()); + let mut key_sanity_check = 0; + for (key, entry) in dcache.keys.iter() { + if entry.flags.valid() { + key_list.push(key.to_string()); + key_sanity_check += 1; + } } for key in key_list { - //log::info!("removing {}:{}", name, key); + log::debug!("removing {}:{}", name, key); // this will wipe any large pools if paranoid is set dcache.key_remove(hw, &mut self.v2p_map, &self.cipher, &key, paranoid); } diff --git a/services/pddb/src/backend/dictionary.rs b/services/pddb/src/backend/dictionary.rs index 69daa99af..8bd3c5066 100644 --- a/services/pddb/src/backend/dictionary.rs +++ b/services/pddb/src/backend/dictionary.rs @@ -384,9 +384,9 @@ impl DictCacheEntry { panic!("Updated file size is greater than the large file size limit."); } assert!((kcache.start + kcache.reserved) % VPAGE_SIZE as u64 == 0, "large space allocation rules were violated"); - let new_reservation = PageAlignedVa::from(kcache.start + offset as u64 + data.len() as u64).as_u64(); + let new_reservation_abs_addr = PageAlignedVa::from(kcache.start + offset as u64 + data.len() as u64).as_u64(); for vpage_addr in ( - (kcache.start + kcache.reserved)..new_reservation + (kcache.start + kcache.reserved)..new_reservation_abs_addr ).step_by(VPAGE_SIZE) { // ensures that a physical page entry exists for every new virtual address required by the extended key v2p_map.entry(VirtAddr::new(vpage_addr).unwrap()).or_insert_with(|| { @@ -395,7 +395,7 @@ impl DictCacheEntry { ap }); } - kcache.reserved = new_reservation; + kcache.reserved = new_reservation_abs_addr - kcache.start; // convert absolute address to an actual length kcache.clean = false; // now retry the call, with the new physical page reservations in place return self.key_update(hw, v2p_map, cipher, name, data, offset, alloc_hint, truncate, large_alloc_ptr); @@ -727,6 +727,8 @@ impl DictCacheEntry { // - in-memory representation will return an entry, but with its valid flag set to false. // - disk still contains a key entry that claims we have a valid key // a call to sync is necessary to completely flush things, but, we don't sync every time we remove because it's inefficient. + } else { + log::debug!("key_remove() key does not exist: {}", name_str); } // if there's no key....we're done! } diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index f5b6e90ae..53f03b86b 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -437,10 +437,11 @@ fn xmain() -> ! { const EXTRA_BASIS_PW: &'static str = "some password blah blah"; log::set_max_level(log::LevelFilter::Info); + log::info!("Seed for this run: {}", xous::TESTING_RNG_SEED); pddb_os.test_reset(); log::info!("Creating `basecase1e`"); - log::set_max_level(log::LevelFilter::Debug); + log::set_max_level(log::LevelFilter::Info); let mut basis_cache = BasisCache::new(); create_basis_testcase(&mut pddb_os, &mut basis_cache, None, None, None, Some(32)); @@ -469,11 +470,9 @@ fn xmain() -> ! { patch_test(&mut pddb_os, &mut basis_cache, None, None, true); pddb_os.dbg_dump(Some("patche".to_string()), None); - log::set_max_level(log::LevelFilter::Debug); log::info!("Doing delete pattern test"); delete_pattern(&mut pddb_os, &mut basis_cache, None, None, None, None); pddb_os.dbg_dump(Some("patterne".to_string()), None); - log::set_max_level(log::LevelFilter::Info); // extended tests. // allocation space curtailed to force resource exhaustion faster. @@ -486,11 +485,14 @@ fn xmain() -> ! { delete_pattern(&mut pddb_os, &mut basis_cache, None, None, None, None); pddb_os.dbg_dump(Some("patterne2".to_string()), None); + log::set_max_level(log::LevelFilter::Debug); + // dict2|key6|len794 log::info!("Doing delete/add consistency with data extension 2"); delete_add_dict_consistency(&mut pddb_os, &mut basis_cache, Some(3), Some(50), None, None, None); log::info!("Saving `dachecke2` to local host"); pddb_os.dbg_dump(Some("dachecke2".to_string()), None); + log::set_max_level(log::LevelFilter::Info); log::info!("Doing delete/add consistency with data extension 3"); delete_add_dict_consistency(&mut pddb_os, &mut basis_cache, Some(3), diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index 6db721827..314572ad3 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -40,7 +40,7 @@ pub const PDDB_LOC: u32 = 0x0100_0000; // PDDB start pub const PDDB_LEN: u32 = EC_REGION_LOC - PDDB_LOC; #[cfg(all(any(windows, unix), not(feature = "processes-as-threads")))] -pub const TESTING_RNG_SEED: u64 = 0; // 2 "works" +pub const TESTING_RNG_SEED: u64 = 8; // 0, 1, 2, 3, 4, 7, 8 "works"; 5 "oom"; 6 "key space oom" pub mod exceptions; pub use exceptions::*;