* [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill()
@ 2024-08-11 16:54 Philippe Mathieu-Daudé
2024-08-12 0:48 ` Richard Henderson
2024-08-12 9:40 ` Jiaxun Yang
0 siblings, 2 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-11 16:54 UTC (permalink / raw)
To: qemu-devel
Cc: Philippe Mathieu-Daudé, Richard Henderson, Aurelien Jarno,
Jiaxun Yang, Aleksandar Rikalo, Thomas Petazzoni,
Waldemar Brodkorb
When refactoring page_table_walk_refill() in commit 4e999bf419
we replaced the execution mode and forced it to kernel mode.
Restore the previous behavior to also get supervisor / user modes.
Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Reported-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470
Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from mips_cpu_tlb_fill")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/mips/tcg/sysemu/tlb_helper.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/tlb_helper.c
index 3ba6d369a6..e7ae4f0bef 100644
--- a/target/mips/tcg/sysemu/tlb_helper.c
+++ b/target/mips/tcg/sysemu/tlb_helper.c
@@ -940,8 +940,9 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
* Memory reads during hardware page table walking are performed
* as if they were kernel-mode load instructions.
*/
- int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL ?
- MMU_ERL_IDX : MMU_KERNEL_IDX);
+ int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL)
+ ? MMU_ERL_IDX
+ : (env->hflags & MIPS_HFLAG_KSU);
if (page_table_walk_refill(env, address, ptw_mmu_idx)) {
ret = get_physical_address(env, &physical, &prot, address,
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill()
2024-08-11 16:54 [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill() Philippe Mathieu-Daudé
@ 2024-08-12 0:48 ` Richard Henderson
2024-08-12 5:35 ` Philippe Mathieu-Daudé
2024-08-12 9:40 ` Jiaxun Yang
1 sibling, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2024-08-12 0:48 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Aurelien Jarno, Jiaxun Yang, Aleksandar Rikalo, Thomas Petazzoni,
Waldemar Brodkorb
On 8/12/24 02:54, Philippe Mathieu-Daudé wrote:
> When refactoring page_table_walk_refill() in commit 4e999bf419
> we replaced the execution mode and forced it to kernel mode.
> Restore the previous behavior to also get supervisor / user modes.
>
> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Reported-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470
> Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from mips_cpu_tlb_fill")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/mips/tcg/sysemu/tlb_helper.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/tlb_helper.c
> index 3ba6d369a6..e7ae4f0bef 100644
> --- a/target/mips/tcg/sysemu/tlb_helper.c
> +++ b/target/mips/tcg/sysemu/tlb_helper.c
> @@ -940,8 +940,9 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
> * Memory reads during hardware page table walking are performed
> * as if they were kernel-mode load instructions.
> */
> - int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL ?
> - MMU_ERL_IDX : MMU_KERNEL_IDX);
> + int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL)
> + ? MMU_ERL_IDX
> + : (env->hflags & MIPS_HFLAG_KSU);
This contradicts the comment above.
If this code change is correct, then the comment isn't.
But the comment certainly makes sense -- page tables are never accessible to user mode.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill()
2024-08-12 0:48 ` Richard Henderson
@ 2024-08-12 5:35 ` Philippe Mathieu-Daudé
2024-08-12 7:02 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-12 5:35 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Aurelien Jarno, Jiaxun Yang, Aleksandar Rikalo, Thomas Petazzoni,
Waldemar Brodkorb
On 12/8/24 02:48, Richard Henderson wrote:
> On 8/12/24 02:54, Philippe Mathieu-Daudé wrote:
>> When refactoring page_table_walk_refill() in commit 4e999bf419
>> we replaced the execution mode and forced it to kernel mode.
>> Restore the previous behavior to also get supervisor / user modes.
>>
>> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
>> Reported-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470
>> Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from
>> mips_cpu_tlb_fill")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> target/mips/tcg/sysemu/tlb_helper.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/target/mips/tcg/sysemu/tlb_helper.c
>> b/target/mips/tcg/sysemu/tlb_helper.c
>> index 3ba6d369a6..e7ae4f0bef 100644
>> --- a/target/mips/tcg/sysemu/tlb_helper.c
>> +++ b/target/mips/tcg/sysemu/tlb_helper.c
>> @@ -940,8 +940,9 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr
>> address, int size,
>> * Memory reads during hardware page table walking are
>> performed
>> * as if they were kernel-mode load instructions.
>> */
>> - int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL ?
>> - MMU_ERL_IDX : MMU_KERNEL_IDX);
>> + int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL)
>> + ? MMU_ERL_IDX
>> + : (env->hflags & MIPS_HFLAG_KSU);
>
> This contradicts the comment above.
> If this code change is correct, then the comment isn't.
OK.
> But the comment certainly makes sense -- page tables are never
> accessible to user mode.
But we are still dropping the supervisor mode, so OK if I
reword as:
"Restore the previous behavior to also get supervisor modes."
?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill()
2024-08-12 5:35 ` Philippe Mathieu-Daudé
@ 2024-08-12 7:02 ` Richard Henderson
2024-08-13 10:18 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2024-08-12 7:02 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Aurelien Jarno, Jiaxun Yang, Aleksandar Rikalo, Thomas Petazzoni,
Waldemar Brodkorb
On 8/12/24 15:35, Philippe Mathieu-Daudé wrote:
> On 12/8/24 02:48, Richard Henderson wrote:
>> On 8/12/24 02:54, Philippe Mathieu-Daudé wrote:
>>> When refactoring page_table_walk_refill() in commit 4e999bf419
>>> we replaced the execution mode and forced it to kernel mode.
>>> Restore the previous behavior to also get supervisor / user modes.
>>>
>>> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
>>> Reported-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
>>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470
>>> Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from mips_cpu_tlb_fill")
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> ---
>>> target/mips/tcg/sysemu/tlb_helper.c | 5 +++--
>>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/tlb_helper.c
>>> index 3ba6d369a6..e7ae4f0bef 100644
>>> --- a/target/mips/tcg/sysemu/tlb_helper.c
>>> +++ b/target/mips/tcg/sysemu/tlb_helper.c
>>> @@ -940,8 +940,9 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
>>> * Memory reads during hardware page table walking are performed
>>> * as if they were kernel-mode load instructions.
>>> */
>>> - int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL ?
>>> - MMU_ERL_IDX : MMU_KERNEL_IDX);
>>> + int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL)
>>> + ? MMU_ERL_IDX
>>> + : (env->hflags & MIPS_HFLAG_KSU);
>>
>> This contradicts the comment above.
>> If this code change is correct, then the comment isn't.
>
> OK.
>
>> But the comment certainly makes sense -- page tables are never accessible to user mode.
>
> But we are still dropping the supervisor mode, so OK if I
> reword as:
>
> "Restore the previous behavior to also get supervisor modes."
The old code
- env->hflags &= ~MIPS_HFLAG_KSU;
drops both supervisor and user bits, so my comment still stands.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill()
2024-08-11 16:54 [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill() Philippe Mathieu-Daudé
2024-08-12 0:48 ` Richard Henderson
@ 2024-08-12 9:40 ` Jiaxun Yang
1 sibling, 0 replies; 6+ messages in thread
From: Jiaxun Yang @ 2024-08-12 9:40 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, QEMU devel
Cc: Richard Henderson, Aurelien Jarno, Aleksandar Rikalo,
Thomas Petazzoni, Waldemar Brodkorb
在2024年8月11日八月 下午5:54,Philippe Mathieu-Daudé写道:
> When refactoring page_table_walk_refill() in commit 4e999bf419
> we replaced the execution mode and forced it to kernel mode.
> Restore the previous behavior to also get supervisor / user modes.
>
> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Reported-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470
> Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from mips_cpu_tlb_fill")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Thanks!
> ---
> target/mips/tcg/sysemu/tlb_helper.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/target/mips/tcg/sysemu/tlb_helper.c
> b/target/mips/tcg/sysemu/tlb_helper.c
> index 3ba6d369a6..e7ae4f0bef 100644
> --- a/target/mips/tcg/sysemu/tlb_helper.c
> +++ b/target/mips/tcg/sysemu/tlb_helper.c
> @@ -940,8 +940,9 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address,
> int size,
> * Memory reads during hardware page table walking are
> performed
> * as if they were kernel-mode load instructions.
> */
> - int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL ?
> - MMU_ERL_IDX : MMU_KERNEL_IDX);
> + int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL)
> + ? MMU_ERL_IDX
> + : (env->hflags & MIPS_HFLAG_KSU);
>
> if (page_table_walk_refill(env, address, ptw_mmu_idx)) {
> ret = get_physical_address(env, &physical, &prot, address,
> --
> 2.45.2
--
- Jiaxun
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill()
2024-08-12 7:02 ` Richard Henderson
@ 2024-08-13 10:18 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-13 10:18 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Aurelien Jarno, Jiaxun Yang, Aleksandar Rikalo, Thomas Petazzoni,
Waldemar Brodkorb
On 12/8/24 09:02, Richard Henderson wrote:
> On 8/12/24 15:35, Philippe Mathieu-Daudé wrote:
>> On 12/8/24 02:48, Richard Henderson wrote:
>>> On 8/12/24 02:54, Philippe Mathieu-Daudé wrote:
>>>> When refactoring page_table_walk_refill() in commit 4e999bf419
>>>> we replaced the execution mode and forced it to kernel mode.
>>>> Restore the previous behavior to also get supervisor / user modes.
>>>>
>>>> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
>>>> Reported-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
>>>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470
>>>> Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from
>>>> mips_cpu_tlb_fill")
>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>> ---
>>>> target/mips/tcg/sysemu/tlb_helper.c | 5 +++--
>>>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/target/mips/tcg/sysemu/tlb_helper.c
>>>> b/target/mips/tcg/sysemu/tlb_helper.c
>>>> index 3ba6d369a6..e7ae4f0bef 100644
>>>> --- a/target/mips/tcg/sysemu/tlb_helper.c
>>>> +++ b/target/mips/tcg/sysemu/tlb_helper.c
>>>> @@ -940,8 +940,9 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr
>>>> address, int size,
>>>> * Memory reads during hardware page table walking are
>>>> performed
>>>> * as if they were kernel-mode load instructions.
>>>> */
>>>> - int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL ?
>>>> - MMU_ERL_IDX : MMU_KERNEL_IDX);
>>>> + int ptw_mmu_idx = (env->hflags & MIPS_HFLAG_ERL)
>>>> + ? MMU_ERL_IDX
>>>> + : (env->hflags & MIPS_HFLAG_KSU);
>>>
>>> This contradicts the comment above.
>>> If this code change is correct, then the comment isn't.
>>
>> OK.
>>
>>> But the comment certainly makes sense -- page tables are never
>>> accessible to user mode.
>>
>> But we are still dropping the supervisor mode, so OK if I
>> reword as:
>>
>> "Restore the previous behavior to also get supervisor modes."
>
> The old code
>
> - env->hflags &= ~MIPS_HFLAG_KSU;
>
> drops both supervisor and user bits, so my comment still stands.
Right, I missed that.
The issue is in get_pte(), we have:
page_table_walk_refill()
-> get_pte()
-> cpu_ld[lq]_code()
-> cpu_mmu_index()
Since we don't mask anymore the modes in hflags, cpu_mmu_index() can
return UM or SM.
I'll respin the fix.
Phil.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-13 10:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-11 16:54 [PATCH-for-9.1] target/mips: Fix execution mode in page_table_walk_refill() Philippe Mathieu-Daudé
2024-08-12 0:48 ` Richard Henderson
2024-08-12 5:35 ` Philippe Mathieu-Daudé
2024-08-12 7:02 ` Richard Henderson
2024-08-13 10:18 ` Philippe Mathieu-Daudé
2024-08-12 9:40 ` Jiaxun Yang
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).