target/ppc: Do not set HPTE R/C bits on !guest_visible xlate
RFC PATCH 1/1 target/ppc: Do not set HPTE R/C bits on !guest_visible xlate
Perform !guest_visible memory accesses without modifying R/C bits.
It's arguable whether !guest_visible memory accesses should modify R/C bits. i386 seems to set accessed/dirty bit updates for "probe" accesses, but ppc with radix MMU does not. Follow the ppc/radix lead and perform the accesses without updating R/C bits.
--- target/ppc/mmu-hash32.c | 27 ++++++++++++++------------- target/ppc/mmu-hash64.c | 27 ++++++++++++++------------- 2 files changed, 28 insertions(+), 26 deletions(-)
target/ppc/mmu-hash32.c +14 -13
@@ -410,19 +410,20 @@ bool ppc_hash32_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,qemu_log_mask (CPU_LOG_MMU ,"PTE access granted !\n" );/* 8. Update PTE referenced and changed bits if necessary */ - -if (!(pte.pte1 &HPTE32_R_R )) { -ppc_hash32_set_r (cpu, pte_offset, pte.pte1); - } -if (!(pte.pte1 &HPTE32_R_C )) { -if (access_type ==MMU_DATA_STORE ) { -ppc_hash32_set_c (cpu, pte_offset, pte.pte1); - }else { -/* -* Treat the page as read-only for now, so that a later write -* will pass through this function again to set the C bit -*/ - prot &= ~PAGE_WRITE ; +if (guest_visible) { +if (!(pte.pte1 &HPTE32_R_R )) { +ppc_hash32_set_r (cpu, pte_offset, pte.pte1); + } +if (!(pte.pte1 &HPTE32_R_C )) { +if (access_type ==MMU_DATA_STORE ) { +ppc_hash32_set_c (cpu, pte_offset, pte.pte1); + }else { +/* +* Treat the page as read-only for now, so that a later write +* will pass through this function again to set the C bit +*/ + prot &= ~PAGE_WRITE ; + } } } *protp = prot;
target/ppc/mmu-hash64.c +14 -13
@@ -1183,19 +1183,20 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,qemu_log_mask (CPU_LOG_MMU ,"PTE access granted !\n" );/* 6. Update PTE referenced and changed bits if necessary */ - -if (!(pte.pte1 &HPTE64_R_R )) { -ppc_hash64_set_r (cpu, ptex, pte.pte1); - } -if (!(pte.pte1 &HPTE64_R_C )) { -if (access_type ==MMU_DATA_STORE ) { -ppc_hash64_set_c (cpu, ptex, pte.pte1); - }else { -/* -* Treat the page as read-only for now, so that a later write -* will pass through this function again to set the C bit -*/ - prot &= ~PAGE_WRITE ; +if (guest_visible) { +if (!(pte.pte1 &HPTE64_R_R )) { +ppc_hash64_set_r (cpu, ptex, pte.pte1); + } +if (!(pte.pte1 &HPTE64_R_C )) { +if (access_type ==MMU_DATA_STORE ) { +ppc_hash64_set_c (cpu, ptex, pte.pte1); + }else { +/* +* Treat the page as read-only for now, so that a later write +* will pass through this function again to set the C bit +*/ + prot &= ~PAGE_WRITE ; + } } }
Signature · 1 line
2.47.1
Quoted 25 lines · Nicholas Piggin
Perform !guest_visible memory accesses without modifying R/C bits.
It's arguable whether !guest_visible memory accesses should modify R/C bits. i386 seems to set accessed/dirty bit updates for "probe" accesses, but ppc with radix MMU does not. Follow the ppc/radix lead and perform the accesses without updating R/C bits.
Signed-off-by Nicholas Piggin <[email protected]>---
target/ppc/mmu-hash32.c| 27 ++++++++++++++-------------target/ppc/mmu-hash64.c| 27 ++++++++++++++-------------2 files changed, 28 insertions(+), 26 deletions(-)target/ppc/mmu-hash32.c +0
-4@@ -410,19 +410,20 @@ bool ppc_hash32_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,qemu_log_mask (CPU_LOG_MMU ,"PTE access granted !\n" );/* 8. Update PTE referenced and changed bits if necessary */ - -if (!(pte.pte1 &HPTE32_R_R )) { -ppc_hash32_set_r (cpu, pte_offset, pte.pte1); - }
target/ppc/mmu-hash32.c bool ppc_hash32_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, · line 413
Quoted 10 lines
target/ppc/mmu-hash32.c +1
-9-if (!(pte.pte1 &HPTE32_R_C )) { -if (access_type ==MMU_DATA_STORE ) { -ppc_hash32_set_c (cpu, pte_offset, pte.pte1); - }else { -/* -* Treat the page as read-only for now, so that a later write -* will pass through this function again to set the C bit -*/ - prot &= ~PAGE_WRITE ; +if (guest_visible) {
Are these unlikely() ? Not sure if that makes a difference but if we know it may help some compilers.
Regards,
BALATON Zoltan
Quoted 55 lines
target/ppc/mmu-hash32.c +13
-0+if (!(pte.pte1 &HPTE32_R_R )) { +ppc_hash32_set_r (cpu, pte_offset, pte.pte1); + } +if (!(pte.pte1 &HPTE32_R_C )) { +if (access_type ==MMU_DATA_STORE ) { +ppc_hash32_set_c (cpu, pte_offset, pte.pte1); + }else { +/* +* Treat the page as read-only for now, so that a later write +* will pass through this function again to set the C bit +*/ + prot &= ~PAGE_WRITE ; + } } } *protp = prot;target/ppc/mmu-hash64.c +14
-13@@ -1183,19 +1183,20 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,qemu_log_mask (CPU_LOG_MMU ,"PTE access granted !\n" );/* 6. Update PTE referenced and changed bits if necessary */ - -if (!(pte.pte1 &HPTE64_R_R )) { -ppc_hash64_set_r (cpu, ptex, pte.pte1); - } -if (!(pte.pte1 &HPTE64_R_C )) { -if (access_type ==MMU_DATA_STORE ) { -ppc_hash64_set_c (cpu, ptex, pte.pte1); - }else { -/* -* Treat the page as read-only for now, so that a later write -* will pass through this function again to set the C bit -*/ - prot &= ~PAGE_WRITE ; +if (guest_visible) { +if (!(pte.pte1 &HPTE64_R_R )) { +ppc_hash64_set_r (cpu, ptex, pte.pte1); + } +if (!(pte.pte1 &HPTE64_R_C )) { +if (access_type ==MMU_DATA_STORE ) { +ppc_hash64_set_c (cpu, ptex, pte.pte1); + }else { +/* +* Treat the page as read-only for now, so that a later write +* will pass through this function again to set the C bit +*/ + prot &= ~PAGE_WRITE ; + } } }
Quoted 31 lines · BALATON Zoltan
Quoted 30 lines · Nicholas Piggin
Perform !guest_visible memory accesses without modifying R/C bits.
It's arguable whether !guest_visible memory accesses should modify R/C bits. i386 seems to set accessed/dirty bit updates for "probe" accesses, but ppc with radix MMU does not. Follow the ppc/radix lead and perform the accesses without updating R/C bits.
Signed-off-by Nicholas Piggin <[email protected]>---
target/ppc/mmu-hash32.c| 27 ++++++++++++++-------------target/ppc/mmu-hash64.c| 27 ++++++++++++++-------------2 files changed, 28 insertions(+), 26 deletions(-)target/ppc/mmu-hash32.c +0
-9@@ -410,19 +410,20 @@ bool ppc_hash32_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,qemu_log_mask (CPU_LOG_MMU ,"PTE access granted !\n" );/* 8. Update PTE referenced and changed bits if necessary */ - -if (!(pte.pte1 &HPTE32_R_R )) { -ppc_hash32_set_r (cpu, pte_offset, pte.pte1); - } -if (!(pte.pte1 &HPTE32_R_C )) { -if (access_type ==MMU_DATA_STORE ) { -ppc_hash32_set_c (cpu, pte_offset, pte.pte1); - }else { -/*
Quoted 8 lines
target/ppc/mmu-hash32.c bool ppc_hash32_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type, · line 413
Quoted 5 lines
target/ppc/mmu-hash32.c +1
-4-* Treat the page as read-only for now, so that a later write -* will pass through this function again to set the C bit -*/ - prot &= ~PAGE_WRITE ; +if (guest_visible) {Are these
unlikely()? Not sure if that makes a difference but if we know it may help some compilers.
Yes it probably is. Although we don't tend to use unlikely very much. I guess we have to start somewhere.
Thanks,
Nick