From: Junjie Mao Date: Thu, 21 Nov 2024 16:58:05 +0000 (+0000) Subject: rust/pl011: Fix range checks for device ID accesses X-Git-Tag: v9.2.0-rc2~5^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f7ceab1e307128c2e07bee1f92fd57d4a948b1f8;p=thirdparty%2Fqemu.git rust/pl011: Fix range checks for device ID accesses The peripheral and PrimeCell identification registers of pl011 are located at offset 0xFE0 - 0xFFC. To check if a read falls to such registers, the C implementation checks if the offset-shifted-by-2 (not the offset itself) is in the range 0x3F8 - 0x3FF. Use the same check in the Rust implementation. This fixes the timeout of the following avocado tests: * tests/avocado/boot_linux_console.py:BootLinuxConsole.test_arm_virt * tests/avocado/replay_kernel.py:ReplayKernelNormal.test_arm_virt * tests/avocado/replay_kernel.py:ReplayKernelNormal.test_arm_vexpressa9 Reported-by: Peter Maydell Signed-off-by: Junjie Mao Tested-by: Alex Bennée Reviewed-by: Alex Bennée Message-Id: Signed-off-by: Alex Bennée Message-Id: <20241121165806.476008-39-alex.bennee@linaro.org> --- diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 2a85960b81f..476cacc8449 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -182,7 +182,7 @@ impl PL011State { use RegisterOffset::*; std::ops::ControlFlow::Break(match RegisterOffset::try_from(offset) { - Err(v) if (0x3f8..0x400).contains(&v) => { + Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { u64::from(self.device_id[(offset - 0xfe0) >> 2]) } Err(_) => {