diff --git a/src/util/metadata/side_metadata/global.rs b/src/util/metadata/side_metadata/global.rs index 250a79420c..2a64b33848 100644 --- a/src/util/metadata/side_metadata/global.rs +++ b/src/util/metadata/side_metadata/global.rs @@ -1066,6 +1066,8 @@ impl SideMetadataSpec { let end_addr = data_addr; // Then figure out the start and end metadata address and bits. + // The start bit may not be accurate, as we map any address in the region to the same bit. + // We will filter the result at the end to make sure the found address is in the search range. let start_meta_addr = address_to_contiguous_meta_address(self, start_addr); let start_meta_shift = meta_byte_lshift(self, start_addr); let end_meta_addr = address_to_contiguous_meta_address(self, end_addr); @@ -1120,7 +1122,12 @@ impl SideMetadataSpec { &mut visitor, ); + // We have to filter the result. We search between [start_addr, end_addr). But we actually + // search with metadata bits. It is possible the metadata bit for start_addr is the same bit + // as an address that is before start_addr. E.g. 0x2010f026360 and 0x2010f026361 are mapped + // to the same bit, 0x2010f026361 is the start address and 0x2010f026360 is outside the search range. res.map(|addr| addr.align_down(1 << self.log_bytes_in_region)) + .filter(|addr| *addr >= start_addr && *addr < end_addr) } /// Search for data addresses that have non zero values in the side metadata. This method is