target/riscv: Fix incorrect PTE merge in walk_pte
PATCH 1/1 target/riscv: Fix incorrect PTE merge in walk_pte
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case, walk_pte will erroneously merge them.
Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:0x81200000 -> 0x89623000 (4K)0x8120f000 -> 0x89624000 (4K)
Before, walk_pte would have shown:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad 000000008120f000 0000000089624000 0000000000001000 rwxu-ad
--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/riscv/monitor.c +4 -1
@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;
@@ -116,13 +117,15 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr); *vbase = start; *pbase = paddr; *last_attr = attr; + last_start = start; } *last_paddr = paddr;
Signature · 1 line
2.35.1
Quoted 22 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-ad
Quoted 4 lines
Signed-off-by Ralf Ramsauer<[email protected]>--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
r~
Quoted 44 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/monitor.c +1
-1@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;@@ -116,13 +117,15 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) {
target/riscv/monitor.c static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, · line 129
Quoted 10 lines
target/riscv/monitor.c +3
-0+ (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr); *vbase = start; *pbase = paddr; *last_attr = attr; + last_start = start; }
Yikes, there's a small bug in my patch that I failed to see:last_addr = start should be outside the curly brackets, otherwise it will rip up too much regions.
I'll return with a V2.
Thanks
Ralf
Quoted 2 lines
target/riscv/monitor.c +0
-0*last_paddr = paddr;
PATCH v2 1/1 target/riscv: Fix incorrect PTE merge in walk_pte
In reply to Ralf RamsauerTwo non-subsequent PTEs can be mapped to subsequent paddrs. In this case, walk_pte will erroneously merge them.
Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:0x81200000 -> 0x89623000 (4K)0x8120f000 -> 0x89624000 (4K)
Before, walk_pte would have shown:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad 000000008120f000 0000000089624000 0000000000001000 rwxu-ad
--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/riscv/monitor.c +4 -1
@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;
@@ -116,7 +117,8 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);
@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else {
Signature · 1 line
2.35.1
Quoted 16 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
Quoted 8 lines
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>
Alistair
Quoted 38 lines
--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/monitor.c +4
-2@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;@@ -116,7 +117,8 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else { --2.35.1
Quoted 41 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/monitor.c +1
-0@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;
target/riscv/monitor.c static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, · line 118
Quoted 2 lines
target/riscv/monitor.c +0
-0@@ -116,7 +117,8 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */
Please also update the comments above to mention the new case you added here.
Quoted 8 lines
target/riscv/monitor.c +2
-1if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);
target/riscv/monitor.c static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,
Quoted 8 lines
target/riscv/monitor.c +1
-1@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else { --
Regards,
Bin
Bin Meng
Reviewed-byQuoted 40 lines · Bin Meng
Quoted 37 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/monitor.c +1
-0@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;
Quoted 9 lines
target/riscv/monitor.c static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, · line 118
Quoted 6 lines
target/riscv/monitor.c +0
-0target_ulong pgsize;target_ulong pte;int ptshift;@@ -116,7 +117,8 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ Please also update the comments above to mention the new case you added here.
Otherwise,
Quoted 41 lines · Bin Meng
Quoted 40 lines · Bin Meng
Quoted 37 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/monitor.c +1
-0@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;
Quoted 8 lines
Quoted 8 lines
target/riscv/monitor.c static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, · line 118
Quoted 6 lines
target/riscv/monitor.c +0
-0target_ulong pgsize;target_ulong pte;int ptshift;@@ -116,7 +117,8 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ Please also update the comments above to mention the new case you added here.
Shall I provide a v3? No problem, if that makes your life easier. Otherwise, you could also squash attached comment on integration.
Thanks
Ralf
target/riscv/monitor.c +0 -0
@@ -143,9 +143,9 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* A leaf PTE has been found * * If current PTE's permission bits differ from the
last one,
- * or current PTE's ppn does not make a contiguous physical
- * address block together with the last one, print out the last
- * contiguous mapped block details.
+ * or the current PTE breaks up a contiguous virtual or
+ * physical mapping, address block together with the last one,
+ * print out the last contiguous mapped block details.
*/
if ((*last_attr != attr) ||
(*last_paddr + *last_size != paddr) ||Quoted 54 lines · Ralf Ramsauer
Quoted 41 lines · Bin Meng
Quoted 40 lines · Bin Meng
Quoted 37 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>--- target/riscv/monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/monitor.c +1
-0@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;Quoted 8 lines
Quoted 8 lines
target/riscv/monitor.c static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, · line 118
Quoted 6 lines
target/riscv/monitor.c +0
-0target_ulong pgsize;target_ulong pte;int ptshift;@@ -116,7 +117,8 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* contiguous mapped block details. */ Please also update the comments above to mention the new case you added here.
Quoted 2 lines
Shall I provide a v3? No problem, if that makes your life easier. Otherwise, you could also squash attached comment on integration.
Yes, please submit a v3
Alistair
Quoted 26 lines
Thanks
Ralftarget/riscv/monitor.c +0
-2@@ -143,9 +143,9 @@ static void walk_pte(Monitor *mon, hwaddr base,target_ulong start, * A leaf PTE has been found * * If current PTE's permission bits differ from the last one, - * or current PTE's ppn does not make a contiguous physical - * address block together with the last one, print outthe last
target/riscv/monitor.c +2
-1-* contiguous mapped block details. +* or the current PTE breaks up a contiguous virtual or +* physical mapping, address block together with the last one,
+ * print out the last contiguous mapped block details.*/ if ((*last_attr != attr) || (*last_paddr + *last_size != paddr) ||
PATCH v3 1/1 target/riscv: Fix incorrect PTE merge in walk_pte
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case, walk_pte will erroneously merge them.
Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:0x81200000 -> 0x89623000 (4K)0x8120f000 -> 0x89624000 (4K)
Before, walk_pte would have shown:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad 000000008120f000 0000000089624000 0000000000001000 rwxu-ad
---
[since v2: Adjust comment, rebased to latest master]
target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target/riscv/monitor.c +7 -4
@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;
@@ -111,12 +112,13 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* A leaf PTE has been found * * If current PTE's permission bits differ from the last one, -* or current PTE's ppn does not make a contiguous physical -* address block together with the last one, print out the last -* contiguous mapped block details. +* or the current PTE breaks up a contiguous virtual or +* physical mapping, address block together with the last one, +* print out the last contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);
@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else {
Signature · 1 line
2.36.0
Quoted 23 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-adas it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-ad
Quoted 7 lines
Signed-off-by Ralf Ramsauer <[email protected]>---
[since v2: Adjust comment, rebased to latest master]target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 16 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
Quoted 8 lines
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>
Alistair
Quoted 47 lines
---
[since v2: Adjust comment, rebased to latest master]target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)target/riscv/monitor.c +7
-5@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;@@ -111,12 +112,13 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* A leaf PTE has been found * * If current PTE's permission bits differ from the last one, -* or current PTE's ppn does not make a contiguous physical -* address block together with the last one, print out the last -* contiguous mapped block details. +* or the current PTE breaks up a contiguous virtual or +* physical mapping, address block together with the last one, +* print out the last contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else { --2.36.0
Quoted 16 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
Quoted 8 lines
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>
Thanks for the patch. It doesn't seem to have made it to the QEMU mailing list though. Do you mind re-sending it and checking to make sure it is sent to the mailing list?
Alistair
Quoted 47 lines
---
[since v2: Adjust comment, rebased to latest master]target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)target/riscv/monitor.c +7
-5@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;@@ -111,12 +112,13 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* A leaf PTE has been found * * If current PTE's permission bits differ from the last one, -* or current PTE's ppn does not make a contiguous physical -* address block together with the last one, print out the last -* contiguous mapped block details. +* or the current PTE breaks up a contiguous virtual or +* physical mapping, address block together with the last one, +* print out the last contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else { --2.36.0
Alistair Francis
AppliedQuoted 16 lines · Ralf Ramsauer
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case,
walk_ptewill erroneously merge them.Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:
0x81200000->0x89623000(4K)0x8120f000->0x89624000(4K)Before,
walk_ptewould have shown:vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
Quoted 8 lines
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad000000008120f0000000000089624000 0000000000001000 rwxu-adSigned-off-by Ralf Ramsauer <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 47 lines
---
[since v2: Adjust comment, rebased to latest master]target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)target/riscv/monitor.c +7
-5@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;@@ -111,12 +112,13 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* A leaf PTE has been found * * If current PTE's permission bits differ from the last one, -* or current PTE's ppn does not make a contiguous physical -* address block together with the last one, print out the last -* contiguous mapped block details. +* or the current PTE breaks up a contiguous virtual or +* physical mapping, address block together with the last one, +* print out the last contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else { --2.36.0