* [PATCH] rust/pl011: Fix range checks for device ID accesses
@ 2024-11-07 6:13 Junjie Mao
2024-11-18 9:43 ` Alex Bennée
2024-11-21 16:47 ` Alex Bennée
0 siblings, 2 replies; 5+ messages in thread
From: Junjie Mao @ 2024-11-07 6:13 UTC (permalink / raw)
To: Manos Pitsidianakis, Paolo Bonzini; +Cc: qemu-devel, Junjie Mao, Peter Maydell
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 <peter.maydell@linaro.org>
Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
---
rust/hw/char/pl011/src/device.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 2a85960b81..476cacc844 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -182,7 +182,7 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow<u
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(_) => {
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] rust/pl011: Fix range checks for device ID accesses
2024-11-07 6:13 [PATCH] rust/pl011: Fix range checks for device ID accesses Junjie Mao
@ 2024-11-18 9:43 ` Alex Bennée
2024-11-18 9:54 ` Junjie Mao
2024-11-21 16:47 ` Alex Bennée
1 sibling, 1 reply; 5+ messages in thread
From: Alex Bennée @ 2024-11-18 9:43 UTC (permalink / raw)
To: Junjie Mao; +Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-devel, Peter Maydell
Junjie Mao <junjie.mao@hotmail.com> writes:
> 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 <peter.maydell@linaro.org>
> Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
This certainly fixes the avocado failures.
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> rust/hw/char/pl011/src/device.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
> index 2a85960b81..476cacc844 100644
> --- a/rust/hw/char/pl011/src/device.rs
> +++ b/rust/hw/char/pl011/src/device.rs
> @@ -182,7 +182,7 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow<u
> 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(_) => {
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust/pl011: Fix range checks for device ID accesses
2024-11-18 9:43 ` Alex Bennée
@ 2024-11-18 9:54 ` Junjie Mao
2024-11-18 10:38 ` Alex Bennée
0 siblings, 1 reply; 5+ messages in thread
From: Junjie Mao @ 2024-11-18 9:54 UTC (permalink / raw)
To: Alex Bennée
Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-devel, Peter Maydell
Alex Bennée <alex.bennee@linaro.org> writes:
> Junjie Mao <junjie.mao@hotmail.com> writes:
>
>> 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 <peter.maydell@linaro.org>
>> Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
>
> This certainly fixes the avocado failures.
>
> Tested-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>
Thanks for reviewing and testing, Alex!
Meanwhile, Manos has submitted another fix [1] which also replaces
arrays of constant register values with more explicit register
getters. His change may supercedes mine.
[1] https://lore.kernel.org/qemu-devel/20241117161039.3758840-1-manos.pitsidianakis@linaro.org
--
Best Regards
Junjie Mao
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust/pl011: Fix range checks for device ID accesses
2024-11-18 9:54 ` Junjie Mao
@ 2024-11-18 10:38 ` Alex Bennée
0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2024-11-18 10:38 UTC (permalink / raw)
To: Junjie Mao; +Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-devel, Peter Maydell
Junjie Mao <junjie.mao@hotmail.com> writes:
> Alex Bennée <alex.bennee@linaro.org> writes:
>
>> Junjie Mao <junjie.mao@hotmail.com> writes:
>>
>>> 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 <peter.maydell@linaro.org>
>>> Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
>>
>> This certainly fixes the avocado failures.
>>
>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>
>
> Thanks for reviewing and testing, Alex!
>
> Meanwhile, Manos has submitted another fix [1] which also replaces
> arrays of constant register values with more explicit register
> getters. His change may supercedes mine.
>
> [1]
> https://lore.kernel.org/qemu-devel/20241117161039.3758840-1-manos.pitsidianakis@linaro.org
Yes I'm looking at that series now. I just wanted to note this simple
fix might be more relevant to 9.2 as its concise and easy to see what
its doing.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust/pl011: Fix range checks for device ID accesses
2024-11-07 6:13 [PATCH] rust/pl011: Fix range checks for device ID accesses Junjie Mao
2024-11-18 9:43 ` Alex Bennée
@ 2024-11-21 16:47 ` Alex Bennée
1 sibling, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2024-11-21 16:47 UTC (permalink / raw)
To: Junjie Mao; +Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-devel, Peter Maydell
Junjie Mao <junjie.mao@hotmail.com> writes:
> 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 <peter.maydell@linaro.org>
> Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
As this is the simple fix I'm grabbing this for rc2. We can revisit more
Rusty solutions after the release.
Queued to maintainer/for-9.2-rc2, thanks.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-21 16:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-07 6:13 [PATCH] rust/pl011: Fix range checks for device ID accesses Junjie Mao
2024-11-18 9:43 ` Alex Bennée
2024-11-18 9:54 ` Junjie Mao
2024-11-18 10:38 ` Alex Bennée
2024-11-21 16:47 ` Alex Bennée
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).