target/ppc: Add support for Radix partition-scoped translation
cover target/ppc: Add support for Radix partition-scoped translation
Hello,
The Radix tree translation model currently supports process-scoped translation for the PowerNV machine (Hypervisor mode) and for the pSeries machine (Guest mode). Guests running under an emulated Hypervisor (PowerNV machine) require a new type of Radix translation, called partition-scoped, which is missing today.
The Radix tree translation is a 2 steps process. The first step, process-scoped translation, converts an effective Address to a guest real address, and the second step, partition-scoped translation, converts a guest real address to a host real address.
There are difference cases to covers :
* Hypervisor real mode access: no Radix translation.
* Hypervisor or host application access (quadrant 0 and 3) with relocation on: process-scoped translation.
* Guest OS real mode access: only partition-scoped translation.
* Guest OS real or guest application access (quadrant 0 and 3) with relocation on: both process-scoped translation and partition-scoped translations.
* Hypervisor access in quadrant 1 and 2 with relocation on: both process-scoped translation and partition-scoped translations.
The radix tree partition-scoped translation is performed using tables pointed to by the first double-word of the Partition Table Entries and process-scoped translation uses tables pointed to by the Process Table Entries (second double-word of the Partition Table Entries).
Both partition-scoped and process-scoped translations process are identical and thus the radix tree traversing code is largely reused. However, errors in partition-scoped translations generate hypervisor exceptions.
Based on work from Suraj Jitindar Singh <[email protected]>
Thanks,
C.
Cédric Le Goater (6):
target/ppc: Introduce a relocation bool in ppc_radix64_handle_mmu_fault() target/ppc: Assert if HV mode is set when running under a pseries machine target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation target/ppc: Extend ppc_radix64_check_prot() with a 'partition_scoped' bool target/ppc: Add support for Radix partition-scoped translation
Suraj Jitindar Singh (1):
target/ppc: Enforce that the root page directory size must be at least
5
target/ppc/cpu.h | 3 + target/ppc/excp_helper.c | 3 +- target/ppc/mmu-radix64.c | 411 +++++++++++++++++++++++++++++---------- 3 files changed, 308 insertions(+), 109 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/7 target/ppc: Enforce that the root page directory size must be at least 5
From: Suraj Jitindar Singh <[email protected]>
According to the ISA the root page directory size of a radix tree for either process- or partition-scoped translation must be >= 5.
Thus add this to the list of conditions checked when validating the partition table entry in validate_pate();
--- target/ppc/mmu-radix64.c | 3 +++ 1 file changed, 3 insertions(+)
target/ppc/mmu-radix64.c +3 -0
@@ -212,6 +212,9 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)if (lpid ==0 && !msr_hv) {return false; } +if ((pate->dw0 &PATE1_R_PRTS ) <5 ) { +return false; + }/* More checks ... */ return true; }
Signature · 1 line
2.21.1
Re: [PATCH 1/7] target/ppc: Enforce that the root page directory size must be at least 5
Quoted 5 lines · On Mon, 30 Mar 2020 11:49:40 +0200 Cédric Le Goater <[email protected]> wrote:
From: Suraj Jitindar Singh <[email protected]>
According to the ISA the root page directory size of a radix tree for either process- or partition-scoped translation must be >= 5.
Quoted 7 lines
Thus add this to the list of conditions checked when validating the partition table entry in
validate_pate();Signed-off-by Suraj Jitindar Singh <[email protected]>Reviewed-by David Gibson <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 17 lines
target/ppc/mmu-radix64.c | 3 +++ 1 file changed, 3 insertions(+)target/ppc/mmu-radix64.c +3
-0@@ -212,6 +212,9 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)if (lpid ==0 && !msr_hv) {return false; } +if ((pate->dw0 &PATE1_R_PRTS ) <5 ) { +return false; + }/* More checks ... */ return true; }
David Gibson
AppliedRe: [PATCH 1/7] target/ppc: Enforce that the root page directory size must be at least 5
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
From: Suraj Jitindar Singh <[email protected]>
According to the ISA the root page directory size of a radix tree for either process- or partition-scoped translation must be >= 5.
Thus add this to the list of conditions checked when validating the partition table entry in
validate_pate();Signed-off-by Suraj Jitindar Singh <[email protected]>Reviewed-by David Gibson <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Applied to ppc-for-5.1.
Quoted 18 lines
--- target/ppc/mmu-radix64.c | 3 +++ 1 file changed, 3 insertions(+)target/ppc/mmu-radix64.c +3
-0@@ -212,6 +212,9 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)if (lpid ==0 && !msr_hv) {return false; } +if ((pate->dw0 &PATE1_R_PRTS ) <5 ) { +return false; + }/* More checks ... */ return true; }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 2/7 target/ppc: Introduce a relocation bool in ppc_radix64_handle_mmu_fault()
In reply to Cédric Le GoaterIt will ease the introduction of new routines for partition-scoped Radix translation.
--- target/ppc/mmu-radix64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/mmu-radix64.c +3 -2
@@ -229,12 +229,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte;int page_size, prot, fault_cause =0 ;ppc_v3_pate_t pate; +bool relocation;assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 )); + relocation = ((rwx ==2 ) && (msr_ir ==1 )) || ((rwx !=2 ) && (msr_dr ==1 ));/* HV or virtual hypervisor Real Mode Access */ -if ((msr_hv || cpu->vhyp) && - (((rwx ==2 ) && (msr_ir ==0 )) || ((rwx !=2 ) && (msr_dr ==0 )))) { +if (!relocation && (msr_hv || cpu->vhyp)) {/* In real mode top 4 effective addr bits (mostly) ignored */ raddr = eaddr &0x0FFFFFFFFFFFFFFFULL ;
Signature · 1 line
2.21.1
Re: [PATCH 2/7] target/ppc: Introduce a relocation bool in ppc_radix64_handle_mmu_fault()
Quoted 6 lines · On Mon, 30 Mar 2020 11:49:41 +0200 Cédric Le Goater <[email protected]> wrote:
It will ease the introduction of new routines for partition-scoped Radix translation.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 23 lines
target/ppc/mmu-radix64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/ppc/mmu-radix64.c +3
-2@@ -229,12 +229,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte;int page_size, prot, fault_cause =0 ;ppc_v3_pate_t pate; +bool relocation;assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 )); + relocation = ((rwx ==2 ) && (msr_ir ==1 )) || ((rwx !=2 ) && (msr_dr ==1 ));/* HV or virtual hypervisor Real Mode Access */ -if ((msr_hv || cpu->vhyp) && - (((rwx ==2 ) && (msr_ir ==0 )) || ((rwx !=2 ) && (msr_dr ==0 )))) { +if (!relocation && (msr_hv || cpu->vhyp)) {/* In real mode top 4 effective addr bits (mostly) ignored */ raddr = eaddr &0x0FFFFFFFFFFFFFFFULL ;
David Gibson
AppliedRe: [PATCH 2/7] target/ppc: Introduce a relocation bool in ppc_radix64_handle_mmu_fault()
In reply to Cédric Le GoaterQuoted 5 lines · Cédric Le Goater
It will ease the introduction of new routines for partition-scoped Radix translation.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Applied to ppc-for-5.1.
Quoted 24 lines
--- target/ppc/mmu-radix64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/ppc/mmu-radix64.c +3
-2@@ -229,12 +229,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte;int page_size, prot, fault_cause =0 ;ppc_v3_pate_t pate; +bool relocation;assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 )); + relocation = ((rwx ==2 ) && (msr_ir ==1 )) || ((rwx !=2 ) && (msr_dr ==1 ));/* HV or virtual hypervisor Real Mode Access */ -if ((msr_hv || cpu->vhyp) && - (((rwx ==2 ) && (msr_ir ==0 )) || ((rwx !=2 ) && (msr_dr ==0 )))) { +if (!relocation && (msr_hv || cpu->vhyp)) {/* In real mode top 4 effective addr bits (mostly) ignored */ raddr = eaddr &0x0FFFFFFFFFFFFFFFULL ;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 3/7 target/ppc: Assert if HV mode is set when running under a pseries machine
In reply to Cédric Le Goater--- target/ppc/mmu-radix64.c | 1 + 1 file changed, 1 insertion(+)
target/ppc/mmu-radix64.c +1 -0
@@ -231,6 +231,7 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,ppc_v3_pate_t pate;bool relocation; +assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 )); relocation = ((rwx ==2 ) && (msr_ir ==1 )) || ((rwx !=2 ) && (msr_dr ==1 ));
Signature · 1 line
2.21.1
Re: [PATCH 3/7] target/ppc: Assert if HV mode is set when running under a pseries machine
Quoted 3 lines · On Mon, 30 Mar 2020 11:49:42 +0200 Cédric Le Goater <[email protected]> wrote:
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 15 lines
target/ppc/mmu-radix64.c | 1 + 1 file changed, 1 insertion(+)target/ppc/mmu-radix64.c +1
-0@@ -231,6 +231,7 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,ppc_v3_pate_t pate;bool relocation; +assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 )); relocation = ((rwx ==2 ) && (msr_ir ==1 )) || ((rwx !=2 ) && (msr_dr ==1 ));
David Gibson
AppliedRe: [PATCH 3/7] target/ppc: Assert if HV mode is set when running under a pseries machine
In reply to Cédric Le GoaterQuoted 2 lines · Cédric Le Goater
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Applied to ppc-for-5.1.
Quoted 16 lines
--- target/ppc/mmu-radix64.c | 1 + 1 file changed, 1 insertion(+)target/ppc/mmu-radix64.c +1
-0@@ -231,6 +231,7 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,ppc_v3_pate_t pate;bool relocation; +assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 )); relocation = ((rwx ==2 ) && (msr_ir ==1 )) || ((rwx !=2 ) && (msr_dr ==1 ));
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 4/7 target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
In reply to Cédric Le GoaterThis is moving code under a new ppc_radix64_xlate() routine shared by the MMU Radix page fault handler and the get_phys_page_debug PPC callback. The difference being that get_phys_page_debug does not generate exceptions.
The specific part of process-scoped Radix translation is moved under ppc_radix64_process_scoped_xlate() in preparation of the future support for partition-scoped Radix translation.
It should be functionally equivalent.
--- target/ppc/mmu-radix64.c | 201 ++++++++++++++++++++++----------------- 1 file changed, 116 insertions(+), 85 deletions(-)
target/ppc/mmu-radix64.c +116 -85
@@ -219,17 +219,119 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)return true; } +static int ppc_radix64_process_scoped_xlate (PowerPCCPU *cpu,int rwx, +vaddr eaddr,uint64_t lpid,uint64_t pid, +ppc_v3_pate_t pate,hwaddr *g_raddr, +int *g_prot,int *g_page_size, +bool cause_excp) +{ +CPUState *cs =CPU (cpu); +uint64_t offset, size, prtbe_addr, prtbe0, pte; +int fault_cause =0 ; +hwaddr pte_addr; + +/* Index Process Table by PID to Find Corresponding Process Table Entry */ + offset = pid *sizeof (struct prtb_entry ); + size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); +if (offset >= size) { +/* offset exceeds size of the process table */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } + prtbe_addr = (pate.dw1 &PATE1_R_PRTB ) + offset; + prtbe0 =ldq_phys (cs->as, prtbe_addr); + +/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ + *g_page_size =PRTBE_R_GET_RTS (prtbe0); + pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , + prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , + g_raddr, g_page_size, &fault_cause, &pte_addr); + +if (!(pte &R_PTE_VALID ) || +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) { +/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp) +{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr; + + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) { +PPCVirtualHypervisorClass *vhc; + vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + vhc->get_pate (cpu->vhyp, &pate); + }else { +if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } +if (!validate_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* We don't support guest mode yet */ +if (lpid !=0 ) { +error_report ("PowerNV guest support Unimplemented" ); +exit (1 ); + } + } + +/* +* Perform process-scoped translation if relocation enabled. +* +* - Translates an effective address to a host real address in +* quadrants 0 and 3 when HV=1. +*/ +if (relocation) { +int ret =ppc_radix64_process_scoped_xlate (cpu, rwx, eaddr, lpid, pid, + pate, &g_raddr, &prot, + &psize, cause_excp); +if (ret) { +return ret; + } + *psizep =MIN (*psizep, psize); + *protp &= prot; + }else { + g_raddr = eaddr &R_EADDR_MASK ; + } + + *raddr = g_raddr; +return 0 ; +} +int ppc_radix64_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, prot, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int page_size, prot;bool relocation; +hwaddr raddr;assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 ));
@@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,return 1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); -return 1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); +/* Translate eaddr to raddr (where raddr is addr qemu needs for access) */ +if (ppc_radix64_xlate (cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot,1 )) {return 1 ; } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte ||ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, &prot)) { -/* Couldn't get pte or access denied due to protection */ -ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); -return 1 ; - } - -/* Update Reference and Change Bits */ -ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, &prot);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,1UL << page_size);
@@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,hwaddr ppc_radix64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong eaddr) { -CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int psize, prot; +hwaddr raddr;/* Handle Real Mode */ -if (msr_dr ==0 ) { +if ((msr_dr ==0 ) && (msr_hv || (cpu->vhyp && lpid ==0 ))) {/* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr &0x0FFFFFFFFFFFFFFFULL ; }
@@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr)return -1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -return -1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -return -1 ; - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -return -1 ; - } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte) { +if (ppc_radix64_xlate (cpu, eaddr,0 , lpid, pid, msr_dr, &raddr, &psize, + &prot,0 )) {return -1 ; }
Signature · 1 line
2.21.1
Re: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
Quoted 47 lines · On Mon, 30 Mar 2020 11:49:43 +0200 Cédric Le Goater <[email protected]> wrote:
This is moving code under a new
ppc_radix64_xlate()routine shared by the MMU Radix page fault handler and theget_phys_page_debugPPC callback. The difference being thatget_phys_page_debugdoes not generate exceptions.The specific part of process-scoped Radix translation is moved under
ppc_radix64_process_scoped_xlate()in preparation of the future support for partition-scoped Radix translation.It should be functionally equivalent.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 201 ++++++++++++++++++++++----------------- 1 file changed, 116 insertions(+), 85 deletions(-)target/ppc/mmu-radix64.c +22
-0@@ -219,17 +219,119 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)return true; } +static int ppc_radix64_process_scoped_xlate (PowerPCCPU *cpu,int rwx, +vaddr eaddr,uint64_t lpid,uint64_t pid, +ppc_v3_pate_t pate,hwaddr *g_raddr, +int *g_prot,int *g_page_size, +bool cause_excp) +{ +CPUState *cs =CPU (cpu); +uint64_t offset, size, prtbe_addr, prtbe0, pte; +int fault_cause =0 ; +hwaddr pte_addr; + +/* Index Process Table by PID to Find Corresponding Process Table Entry */ + offset = pid *sizeof (struct prtb_entry ); + size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); +if (offset >= size) { +/* offset exceeds size of the process table */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } + prtbe_addr = (pate.dw1 &PATE1_R_PRTB ) + offset;
target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 253
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+ prtbe0 =ldq_phys (cs->as, prtbe_addr); + +/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ + *g_page_size =PRTBE_R_GET_RTS (prtbe0); + pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , + prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , + g_raddr, g_page_size, &fault_cause, &pte_addr); + +if (!(pte &R_PTE_VALID ) || +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) {
Current code checks !pte instead of !(pte & R_PTE_VALID)... and I it seems that ppc_radix64_walk_tree() already handles that:
if (!(pde & R_PTE_VALID)) { /* Invalid Entry */
*fault_cause |= DSISR_NOPTE;
return 0;
}Quoted 16 lines
target/ppc/mmu-radix64.c +16
-0+/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp)
target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 279
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr; + + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) {
Current code doesn't check lpid == 0. Not sure to see what it's for... especially env->spr[SPR_LPIDR] is always 0 with pseries machine types AFAICT... is it even possible to have lpid != 0 here ?
Rest LGTM.
Quoted 178 lines
target/ppc/mmu-radix64.c +58
-85+PPCVirtualHypervisorClass *vhc; + vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + vhc->get_pate (cpu->vhyp, &pate); + }else { +if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } +if (!validate_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* We don't support guest mode yet */ +if (lpid !=0 ) { +error_report ("PowerNV guest support Unimplemented" ); +exit (1 ); + } + } + +/* +* Perform process-scoped translation if relocation enabled. +* +* - Translates an effective address to a host real address in +* quadrants 0 and 3 when HV=1. +*/ +if (relocation) { +int ret =ppc_radix64_process_scoped_xlate (cpu, rwx, eaddr, lpid, pid, + pate, &g_raddr, &prot, + &psize, cause_excp); +if (ret) { +return ret; + } + *psizep =MIN (*psizep, psize); + *protp &= prot; + }else { + g_raddr = eaddr &R_EADDR_MASK ; + } + + *raddr = g_raddr; +return 0 ; +} +int ppc_radix64_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, prot, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int page_size, prot;bool relocation; +hwaddr raddr;assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 ));@@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,return 1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); -return 1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); +/* Translate eaddr to raddr (where raddr is addr qemu needs for access) */ +if (ppc_radix64_xlate (cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot,1 )) {return 1 ; } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte ||ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, &prot)) { -/* Couldn't get pte or access denied due to protection */ -ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); -return 1 ; - } - -/* Update Reference and Change Bits */ -ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, &prot);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,1UL << page_size);@@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,hwaddr ppc_radix64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong eaddr) { -CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int psize, prot; +hwaddr raddr;/* Handle Real Mode */ -if (msr_dr ==0 ) { +if ((msr_dr ==0 ) && (msr_hv || (cpu->vhyp && lpid ==0 ))) {/* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr &0x0FFFFFFFFFFFFFFFULL ; }@@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr)return -1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -return -1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -return -1 ; - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -return -1 ; - } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte) { +if (ppc_radix64_xlate (cpu, eaddr,0 , lpid, pid, msr_dr, &raddr, &psize, + &prot,0 )) {return -1 ; }
Re: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
Quoted 64 lines · Greg Kurz
Quoted 47 lines · On Mon, 30 Mar 2020 11:49:43 +0200 Cédric Le Goater <[email protected]> wrote:
This is moving code under a new
ppc_radix64_xlate()routine shared by the MMU Radix page fault handler and theget_phys_page_debugPPC callback. The difference being thatget_phys_page_debugdoes not generate exceptions.The specific part of process-scoped Radix translation is moved under
ppc_radix64_process_scoped_xlate()in preparation of the future support for partition-scoped Radix translation.It should be functionally equivalent.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 201 ++++++++++++++++++++++----------------- 1 file changed, 116 insertions(+), 85 deletions(-)target/ppc/mmu-radix64.c +22
-0@@ -219,17 +219,119 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)return true; } +static int ppc_radix64_process_scoped_xlate (PowerPCCPU *cpu,int rwx, +vaddr eaddr,uint64_t lpid,uint64_t pid, +ppc_v3_pate_t pate,hwaddr *g_raddr, +int *g_prot,int *g_page_size, +bool cause_excp) +{ +CPUState *cs =CPU (cpu); +uint64_t offset, size, prtbe_addr, prtbe0, pte; +int fault_cause =0 ; +hwaddr pte_addr; + +/* Index Process Table by PID to Find Corresponding Process Table Entry */ + offset = pid *sizeof (struct prtb_entry ); + size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); +if (offset >= size) { +/* offset exceeds size of the process table */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } + prtbe_addr = (pate.dw1 &PATE1_R_PRTB ) + offset;target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 253
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+ prtbe0 =ldq_phys (cs->as, prtbe_addr); + +/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ + *g_page_size =PRTBE_R_GET_RTS (prtbe0); + pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , + prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , + g_raddr, g_page_size, &fault_cause, &pte_addr); + +if (!(pte &R_PTE_VALID ) || +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) {Current code checks !pte instead of !(pte &
R_PTE_VALID)... and I it seems thatppc_radix64_walk_tree()already handles that:
Quoted 4 lines
if (!(pde & R_PTE_VALID)) { /* Invalid Entry */
*fault_cause |= DSISR_NOPTE;
return 0;
}There are more changes in the following patches when partition-scoped is introduced.
Quoted 21 lines
Quoted 21 lines
target/ppc/mmu-radix64.c +20
-0+/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp) +{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr;
Quoted 8 lines
target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 279
Quoted 6 lines
target/ppc/mmu-radix64.c +6
-0+ + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) {Current code doesn't check lpid == 0. Not sure to see what it's for...
cpu->vhyp means a pseries machine, lpid == 0 means accessing quadrant3, so it's the kernel.
Quoted 2 lines
especially env->spr[SPR_LPIDR] is always 0 with pseries machine types AFAICT... is it even possible to have lpid != 0 here ?
When under PowerNV, SPR_LPIDR can be set, but not under pseries.
C.
Quoted 183 lines
Rest LGTM.
Quoted 178 lines
target/ppc/mmu-radix64.c +58
-85+PPCVirtualHypervisorClass *vhc; + vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + vhc->get_pate (cpu->vhyp, &pate); + }else { +if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } +if (!validate_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* We don't support guest mode yet */ +if (lpid !=0 ) { +error_report ("PowerNV guest support Unimplemented" ); +exit (1 ); + } + } + +/* +* Perform process-scoped translation if relocation enabled. +* +* - Translates an effective address to a host real address in +* quadrants 0 and 3 when HV=1. +*/ +if (relocation) { +int ret =ppc_radix64_process_scoped_xlate (cpu, rwx, eaddr, lpid, pid, + pate, &g_raddr, &prot, + &psize, cause_excp); +if (ret) { +return ret; + } + *psizep =MIN (*psizep, psize); + *protp &= prot; + }else { + g_raddr = eaddr &R_EADDR_MASK ; + } + + *raddr = g_raddr; +return 0 ; +} +int ppc_radix64_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, prot, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int page_size, prot;bool relocation; +hwaddr raddr;assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 ));@@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,return 1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); -return 1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); +/* Translate eaddr to raddr (where raddr is addr qemu needs for access) */ +if (ppc_radix64_xlate (cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot,1 )) {return 1 ; } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte ||ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, &prot)) { -/* Couldn't get pte or access denied due to protection */ -ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); -return 1 ; - } - -/* Update Reference and Change Bits */ -ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, &prot);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,1UL << page_size);@@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,hwaddr ppc_radix64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong eaddr) { -CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int psize, prot; +hwaddr raddr;/* Handle Real Mode */ -if (msr_dr ==0 ) { +if ((msr_dr ==0 ) && (msr_hv || (cpu->vhyp && lpid ==0 ))) {/* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr &0x0FFFFFFFFFFFFFFFULL ; }@@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr)return -1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -return -1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -return -1 ; - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -return -1 ; - } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte) { +if (ppc_radix64_xlate (cpu, eaddr,0 , lpid, pid, msr_dr, &raddr, &psize, + &prot,0 )) {return -1 ; }
Re: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
target/ppc/mmu-radix64.c +20
-0+/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp) +{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr;Quoted 8 lines
target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 279
Quoted 6 lines
target/ppc/mmu-radix64.c +6
-0+ + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) {Current code doesn't check lpid == 0. Not sure to see what it's for...
Quoted 2 lines
cpu->vhypmeans a pseries machine, lpid == 0 means accessing quadrant3, so it's the kernel.
Sorry. I misread that. It would pid == 0 for the kernel.
So yes, the test cpu->vhyp && lpid == 0 might be a bit overkill, given that lpid is always 0 when running under a QEMU pseries machine.
C.
Quoted 192 lines
Quoted 3 lines
especially env->spr[SPR_LPIDR] is always 0 with pseries machine types AFAICT... is it even possible to have lpid != 0 here ?
When under PowerNV,
SPR_LPIDRcan be set, but not under pseries.C.
Quoted 183 lines
Rest LGTM.
Quoted 178 lines
target/ppc/mmu-radix64.c +58
-85+PPCVirtualHypervisorClass *vhc; + vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + vhc->get_pate (cpu->vhyp, &pate); + }else { +if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } +if (!validate_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* We don't support guest mode yet */ +if (lpid !=0 ) { +error_report ("PowerNV guest support Unimplemented" ); +exit (1 ); + } + } + +/* +* Perform process-scoped translation if relocation enabled. +* +* - Translates an effective address to a host real address in +* quadrants 0 and 3 when HV=1. +*/ +if (relocation) { +int ret =ppc_radix64_process_scoped_xlate (cpu, rwx, eaddr, lpid, pid, + pate, &g_raddr, &prot, + &psize, cause_excp); +if (ret) { +return ret; + } + *psizep =MIN (*psizep, psize); + *protp &= prot; + }else { + g_raddr = eaddr &R_EADDR_MASK ; + } + + *raddr = g_raddr; +return 0 ; +} +int ppc_radix64_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, prot, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int page_size, prot;bool relocation; +hwaddr raddr;assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 ));@@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,return 1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); -return 1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); +/* Translate eaddr to raddr (where raddr is addr qemu needs for access) */ +if (ppc_radix64_xlate (cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot,1 )) {return 1 ; } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte ||ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, &prot)) { -/* Couldn't get pte or access denied due to protection */ -ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); -return 1 ; - } - -/* Update Reference and Change Bits */ -ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, &prot);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,1UL << page_size);@@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,hwaddr ppc_radix64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong eaddr) { -CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int psize, prot; +hwaddr raddr;/* Handle Real Mode */ -if (msr_dr ==0 ) { +if ((msr_dr ==0 ) && (msr_hv || (cpu->vhyp && lpid ==0 ))) {/* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr &0x0FFFFFFFFFFFFFFFULL ; }@@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr)return -1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -return -1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -return -1 ; - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -return -1 ; - } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte) { +if (ppc_radix64_xlate (cpu, eaddr,0 , lpid, pid, msr_dr, &raddr, &psize, + &prot,0 )) {return -1 ; }
Re: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
Quoted 29 lines · On Mon, 30 Mar 2020 17:34:40 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 29 lines
Quoted 28 lines
Quoted 16 lines
target/ppc/mmu-radix64.c +16
-0+/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp)target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 279
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr; + + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) {Current code doesn't check lpid == 0. Not sure to see what it's for...
Quoted 5 lines
Quoted 2 lines
cpu->vhypmeans a pseries machine, lpid == 0 means accessing quadrant3, so it's the kernel.Sorry. I misread that. It would pid == 0 for the kernel.
Yes.
Quoted 3 lines
So yes, the test
cpu->vhyp&& lpid == 0 might be a bit overkill, given that lpid is always 0 when running under a QEMU pseries machine.
That's my thinking as well.
Quoted 15 lines
C.
Quoted 12 lines
Quoted 3 lines
especially env->spr[SPR_LPIDR] is always 0 with pseries machine types AFAICT... is it even possible to have lpid != 0 here ?
When under PowerNV,
SPR_LPIDRcan be set, but not under pseries.C.
Quoted 4 lines
Rest LGTM.
Just a few nits below...
Quoted 87 lines
Quoted 87 lines
Quoted 87 lines
Quoted 87 lines
target/ppc/mmu-radix64.c +49
-25+PPCVirtualHypervisorClass *vhc; + vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + vhc->get_pate (cpu->vhyp, &pate); + }else { +if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } +if (!validate_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* We don't support guest mode yet */ +if (lpid !=0 ) { +error_report ("PowerNV guest support Unimplemented" ); +exit (1 ); + } + } + +/* +* Perform process-scoped translation if relocation enabled. +* +* - Translates an effective address to a host real address in +* quadrants 0 and 3 when HV=1. +*/ +if (relocation) { +int ret =ppc_radix64_process_scoped_xlate (cpu, rwx, eaddr, lpid, pid, + pate, &g_raddr, &prot, + &psize, cause_excp); +if (ret) { +return ret; + } + *psizep =MIN (*psizep, psize); + *protp &= prot; + }else { + g_raddr = eaddr &R_EADDR_MASK ; + } + + *raddr = g_raddr; +return 0 ; +} +int ppc_radix64_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, prot, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int page_size, prot;bool relocation; +hwaddr raddr;assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 ));@@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,return 1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); -return 1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
target/ppc/mmu-radix64.c int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx, · line 375
Quoted 8 lines
target/ppc/mmu-radix64.c +3
-5- offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); +/* Translate eaddr to raddr (where raddr is addr qemu needs for access) */ +if (ppc_radix64_xlate (cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot,1 )) {
... passe true instead of 1 and...
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
target/ppc/mmu-radix64.c +4
-49return 1 ; } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte ||ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, &prot)) { -/* Couldn't get pte or access denied due to protection */ -ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); -return 1 ; - } - -/* Update Reference and Change Bits */ -ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, &prot);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,1UL << page_size);@@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,hwaddr ppc_radix64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong eaddr) { -CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int psize, prot; +hwaddr raddr;/* Handle Real Mode */ -if (msr_dr ==0 ) { +if ((msr_dr ==0 ) && (msr_hv || (cpu->vhyp && lpid ==0 ))) {/* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr &0x0FFFFFFFFFFFFFFFULL ; }@@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr)return -1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -return -1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -return -1 ; - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -return -1 ; - } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); -
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
target/ppc/mmu-radix64.c hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr) · line 403
Quoted 8 lines
target/ppc/mmu-radix64.c +2
-6-/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte) { +if (ppc_radix64_xlate (cpu, eaddr,0 , lpid, pid, msr_dr, &raddr, &psize, + &prot,0 )) {
... false here since ppc_radix64_xlate() takes a bool argument.
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
target/ppc/mmu-radix64.c +0
-0return -1 ; }
Re: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
In reply to Cédric Le GoaterQuoted 29 lines · Cédric Le Goater
Quoted 29 lines
Quoted 28 lines
Quoted 16 lines
target/ppc/mmu-radix64.c +16
-0+/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp)target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 279
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr; + + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) {Current code doesn't check lpid == 0. Not sure to see what it's for...
Quoted 7 lines
Quoted 2 lines
cpu->vhypmeans a pseries machine, lpid == 0 means accessing quadrant3, so it's the kernel.Sorry. I misread that. It would pid == 0 for the kernel.
So yes, the test
cpu->vhyp&& lpid == 0 might be a bit overkill, given that lpid is always 0 when running under a QEMU pseries machine.
Overkill and conceptually incorrect. When in vhyp mode we're not modelling the hypervisor part of the CPU, which means that really the LPID doesn't exist, so we shouldn't be looking at it (though it will always be 0 in practice).
Quoted 197 lines
C.
Quoted 192 lines
Quoted 3 lines
especially env->spr[SPR_LPIDR] is always 0 with pseries machine types AFAICT... is it even possible to have lpid != 0 here ?
When under PowerNV,
SPR_LPIDRcan be set, but not under pseries.C.
Quoted 183 lines
Rest LGTM.
Quoted 178 lines
target/ppc/mmu-radix64.c +58
-85+PPCVirtualHypervisorClass *vhc; + vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + vhc->get_pate (cpu->vhyp, &pate); + }else { +if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); + } +return 1 ; + } +if (!validate_pate (cpu, lpid, &pate)) { +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* We don't support guest mode yet */ +if (lpid !=0 ) { +error_report ("PowerNV guest support Unimplemented" ); +exit (1 ); + } + } + +/* +* Perform process-scoped translation if relocation enabled. +* +* - Translates an effective address to a host real address in +* quadrants 0 and 3 when HV=1. +*/ +if (relocation) { +int ret =ppc_radix64_process_scoped_xlate (cpu, rwx, eaddr, lpid, pid, + pate, &g_raddr, &prot, + &psize, cause_excp); +if (ret) { +return ret; + } + *psizep =MIN (*psizep, psize); + *protp &= prot; + }else { + g_raddr = eaddr &R_EADDR_MASK ; + } + + *raddr = g_raddr; +return 0 ; +} +int ppc_radix64_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, prot, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int page_size, prot;bool relocation; +hwaddr raddr;assert (!(msr_hv && cpu->vhyp));assert ((rwx ==0 ) || (rwx ==1 ) || (rwx ==2 ));@@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,return 1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); -return 1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_R_BADCONFIG ); - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -ppc_radix64_raise_si (cpu, rwx, eaddr,DSISR_NOPTE ); +/* Translate eaddr to raddr (where raddr is addr qemu needs for access) */ +if (ppc_radix64_xlate (cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot,1 )) {return 1 ; } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte ||ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, &prot)) { -/* Couldn't get pte or access denied due to protection */ -ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); -return 1 ; - } - -/* Update Reference and Change Bits */ -ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, &prot);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,1UL << page_size);@@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,hwaddr ppc_radix64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong eaddr) { -CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PPCVirtualHypervisorClass *vhc; -hwaddr raddr, pte_addr; -uint64_t lpid =0 , pid =0 , offset, size, prtbe0, pte; -int page_size, fault_cause =0 ; -ppc_v3_pate_t pate; +uint64_t lpid =0 , pid =0 ; +int psize, prot; +hwaddr raddr;/* Handle Real Mode */ -if (msr_dr ==0 ) { +if ((msr_dr ==0 ) && (msr_hv || (cpu->vhyp && lpid ==0 ))) {/* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr &0x0FFFFFFFFFFFFFFFULL ; }@@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr)return -1 ; } -/* Get Process Table */ -if (cpu->vhyp) { - vhc =PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - vhc->get_pate (cpu->vhyp, &pate); - }else { -if (!ppc64_v3_get_pate (cpu, lpid, &pate)) { -return -1 ; - } -if (!validate_pate (cpu, lpid, &pate)) { -return -1 ; - } -/* We don't support guest mode yet */ -if (lpid !=0 ) { -error_report ("PowerNV guest support Unimplemented" ); -exit (1 ); - } - } - -/* Index Process Table by PID to Find Corresponding Process Table Entry */ - offset = pid *sizeof (struct prtb_entry ); - size =1ULL << ((pate.dw1 &PATE1_R_PRTS ) +12 ); -if (offset >= size) { -/* offset exceeds size of the process table */ -return -1 ; - } - prtbe0 =ldq_phys (cs->as, (pate.dw1 &PATE1_R_PRTB ) + offset); - -/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =PRTBE_R_GET_RTS (prtbe0); - pte =ppc_radix64_walk_tree (cpu, eaddr &R_EADDR_MASK , - prtbe0 &PRTBE_R_RPDB , prtbe0 &PRTBE_R_RPDS , - &raddr, &page_size, &fault_cause, &pte_addr); -if (!pte) { +if (ppc_radix64_xlate (cpu, eaddr,0 , lpid, pid, msr_dr, &raddr, &psize, + &prot,0 )) {return -1 ; }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation
Quoted 35 lines · David Gibson
Quoted 34 lines · Cédric Le Goater
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
target/ppc/mmu-radix64.c +20
-0+/* No valid pte or access denied due to protection */ +if (cause_excp) { +ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause); + } +return 1 ; + } + +ppc_radix64_set_rc (cpu, rwx, pte, pte_addr, g_prot); + +return 0 ; +} + +static int ppc_radix64_xlate (PowerPCCPU *cpu,vaddr eaddr,int rwx, +uint64_t lpid,uint64_t pid,bool relocation, +hwaddr *raddr,int *psizep,int *protp, +bool cause_excp) +{ +ppc_v3_pate_t pate; +int psize, prot; +hwaddr g_raddr;Quoted 8 lines
target/ppc/mmu-radix64.c static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate) · line 279
Quoted 6 lines
target/ppc/mmu-radix64.c +6
-0+ + *psizep =INT_MAX ; + *protp =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +/* Get Process Table */ +if (cpu->vhyp && lpid ==0 ) {Current code doesn't check lpid == 0. Not sure to see what it's for...
Quoted 2 lines
cpu->vhypmeans a pseries machine, lpid == 0 means accessing quadrant3, so it's the kernel.Sorry. I misread that. It would pid == 0 for the kernel.
Quoted 7 lines
Quoted 2 lines
So yes, the test
cpu->vhyp&& lpid == 0 might be a bit overkill, given that lpid is always 0 when running under a QEMU pseries machine.Overkill and conceptually incorrect. When in vhyp mode we're not modelling the hypervisor part of the CPU, which means that really the LPID doesn't exist, so we shouldn't be looking at it (though it will always be 0 in practice).
I will remove the extra check. This has the nice effect of cleaning up a couple of weird changes in patch 7.
Thanks,
C.
PATCH 5/7 target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation
In reply to Cédric Le GoaterThe ppc_radix64_walk_tree() routine walks through the nested radix tables to look for a PTE.
Split it two and introduce a new routine ppc_radix64_next_level() which we will use for partition-scoped Radix translation when translating the process tree addresses.
--- target/ppc/mmu-radix64.c | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-)
target/ppc/mmu-radix64.c +33 -17
@@ -162,44 +162,60 @@ static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, } } -static uint64_t ppc_radix64_walk_tree (PowerPCCPU *cpu,vaddr eaddr, -uint64_t base_addr,uint64_t nls, -hwaddr *raddr,int *psize, -int *fault_cause,hwaddr *pte_addr) +static uint64_t ppc_radix64_next_level (PowerPCCPU *cpu,vaddr eaddr, +uint64_t *pte_addr,uint64_t *nls, +int *psize,int *fault_cause) {CPUState *cs =CPU (cpu);uint64_t index, pde; -if (nls <5 ) {/* Directory maps less than 2**5 entries */ +if (*nls <5 ) {/* Directory maps less than 2**5 entries */ *fault_cause |=DSISR_R_BADCONFIG ;return 0 ; }/* Read page <directory/table> entry from guest address space */ - index = eaddr >> (*psize - nls);/* Shift */ - index &= ((1UL << nls) -1 );/* Mask */ - pde =ldq_phys (cs->as, base_addr + (index *sizeof (pde))); -if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ + pde =ldq_phys (cs->as, *pte_addr); +if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ *fault_cause |=DSISR_NOPTE ;return 0 ; } - *psize -= nls; + *psize -= *nls; +if (!(pde &R_PTE_LEAF )) {/* Prepare for next iteration */ + *nls = pde &R_PDE_NLS ; + index = eaddr >> (*psize - *nls);/* Shift */ + index &= ((1UL << *nls) -1 );/* Mask */ + *pte_addr = (pde &R_PDE_NLB ) + (index *sizeof (pde)); + } +return pde; +} + +static uint64_t ppc_radix64_walk_tree (PowerPCCPU *cpu,vaddr eaddr, +uint64_t base_addr,uint64_t nls, +hwaddr *raddr,int *psize, +int *fault_cause,hwaddr *pte_addr) +{ +uint64_t index, pde; + + index = eaddr >> (*psize - nls);/* Shift */ + index &= ((1UL << nls) -1 );/* Mask */ + *pte_addr = base_addr + (index *sizeof (pde)); +do { + pde =ppc_radix64_next_level (cpu, eaddr, pte_addr, &nls, psize, + fault_cause); + }while ((pde &R_PTE_VALID ) && !(pde &R_PTE_LEAF )); -/* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ -if (pde &R_PTE_LEAF ) { +/* Did we find a valid leaf? */ +if ((pde &R_PTE_VALID ) && (pde &R_PTE_LEAF )) {uint64_t rpn = pde &R_PTE_RPN ;uint64_t mask = (1UL << *psize) -1 ;/* Or high bits of rpn and low bits to ea to form whole real addr */ *raddr = (rpn & ~mask) | (eaddr & mask); - *pte_addr = base_addr + (index *sizeof (pde)); -return pde; } -/* Next Level of Radix Tree */ -return ppc_radix64_walk_tree (cpu, eaddr, pde &R_PDE_NLB , pde &R_PDE_NLS , - raddr, psize, fault_cause, pte_addr); +return pde; }static bool validate_pate (PowerPCCPU *cpu,uint64_t lpid,ppc_v3_pate_t *pate)
Signature · 1 line
2.21.1
Re: [PATCH 5/7] target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation
Quoted 4 lines · On Mon, 30 Mar 2020 11:49:44 +0200 Cédric Le Goater <[email protected]> wrote:
The
ppc_radix64_walk_tree()routine walks through the nested radix tables to look for a PTE.Split it two and introduce a new routine
ppc_radix64_next_level()
Split it in two...
Quoted 24 lines
which we will use for partition-scoped Radix translation when translating the process tree addresses.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-)target/ppc/mmu-radix64.c +3
-4@@ -162,44 +162,60 @@ static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, } } -static uint64_t ppc_radix64_walk_tree (PowerPCCPU *cpu,vaddr eaddr, -uint64_t base_addr,uint64_t nls, -hwaddr *raddr,int *psize, -int *fault_cause,hwaddr *pte_addr) +static uint64_t ppc_radix64_next_level (PowerPCCPU *cpu,vaddr eaddr, +uint64_t *pte_addr,uint64_t *nls, +int *psize,int *fault_cause)
target/ppc/mmu-radix64.c static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, · line 176
Quoted 10 lines
target/ppc/mmu-radix64.c +1
-1{CPUState *cs =CPU (cpu);uint64_t index, pde; -if (nls <5 ) {/* Directory maps less than 2**5 entries */ +if (*nls <5 ) {/* Directory maps less than 2**5 entries */ *fault_cause |=DSISR_R_BADCONFIG ;return 0 ; }
I think this should stay in the caller...
Quoted 23 lines
target/ppc/mmu-radix64.c +13
-5/* Read page <directory/table> entry from guest address space */ - index = eaddr >> (*psize - nls);/* Shift */ - index &= ((1UL << nls) -1 );/* Mask */ - pde =ldq_phys (cs->as, base_addr + (index *sizeof (pde))); -if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ + pde =ldq_phys (cs->as, *pte_addr); +if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ *fault_cause |=DSISR_NOPTE ;return 0 ; } - *psize -= nls; + *psize -= *nls; +if (!(pde &R_PTE_LEAF )) {/* Prepare for next iteration */ + *nls = pde &R_PDE_NLS ; + index = eaddr >> (*psize - *nls);/* Shift */ + index &= ((1UL << *nls) -1 );/* Mask */ + *pte_addr = (pde &R_PDE_NLB ) + (index *sizeof (pde)); + } +return pde; +} + +static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr,
target/ppc/mmu-radix64.c static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, · line 204
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+ uint64_t base_addr, uint64_t nls, + hwaddr *raddr, int *psize, + int *fault_cause, hwaddr *pte_addr) +{ + uint64_t index, pde; + + index = eaddr >> (*psize - nls);/* Shift */ + index &= ((1UL << nls) -1 );/* Mask */ + *pte_addr = base_addr + (index *sizeof (pde)); + do {
... here. So that we have a well established "bad config" path at the root level, just like the current code has.
Since the ppc_radix64_walk_tree() now calls ppc_radix64_next_level() in a loop instead of recursing, and since ppc_radix64_next_level() returns the nls value for the next level, it really makes sense to have this check in ppc_radix64_walk_tree() and maybe put an assert in ppc_radix64_next_level().
Quoted 24 lines
target/ppc/mmu-radix64.c +6
-7+ pde =ppc_radix64_next_level (cpu, eaddr, pte_addr, &nls, psize, + fault_cause); + }while ((pde &R_PTE_VALID ) && !(pde &R_PTE_LEAF )); -/* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ -if (pde &R_PTE_LEAF ) { +/* Did we find a valid leaf? */ +if ((pde &R_PTE_VALID ) && (pde &R_PTE_LEAF )) {uint64_t rpn = pde &R_PTE_RPN ;uint64_t mask = (1UL << *psize) -1 ;/* Or high bits of rpn and low bits to ea to form whole real addr */ *raddr = (rpn & ~mask) | (eaddr & mask); - *pte_addr = base_addr + (index *sizeof (pde)); -return pde; } -/* Next Level of Radix Tree */ -return ppc_radix64_walk_tree (cpu, eaddr, pde &R_PDE_NLB , pde &R_PDE_NLS , - raddr, psize, fault_cause, pte_addr); +return pde; }static bool validate_pate (PowerPCCPU *cpu,uint64_t lpid,ppc_v3_pate_t *pate)
Re: [PATCH 5/7] target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation
Quoted 84 lines · Greg Kurz
Quoted 4 lines · On Mon, 30 Mar 2020 11:49:44 +0200 Cédric Le Goater <[email protected]> wrote:
The
ppc_radix64_walk_tree()routine walks through the nested radix tables to look for a PTE.Split it two and introduce a new routine
ppc_radix64_next_level()Split it in two...
Quoted 24 lines
which we will use for partition-scoped Radix translation when translating the process tree addresses.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-)target/ppc/mmu-radix64.c +3
-4@@ -162,44 +162,60 @@ static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, } } -static uint64_t ppc_radix64_walk_tree (PowerPCCPU *cpu,vaddr eaddr, -uint64_t base_addr,uint64_t nls, -hwaddr *raddr,int *psize, -int *fault_cause,hwaddr *pte_addr) +static uint64_t ppc_radix64_next_level (PowerPCCPU *cpu,vaddr eaddr, +uint64_t *pte_addr,uint64_t *nls, +int *psize,int *fault_cause)target/ppc/mmu-radix64.c static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, · line 176
Quoted 10 lines
target/ppc/mmu-radix64.c +1
-1{CPUState *cs =CPU (cpu);uint64_t index, pde; -if (nls <5 ) {/* Directory maps less than 2**5 entries */ +if (*nls <5 ) {/* Directory maps less than 2**5 entries */ *fault_cause |=DSISR_R_BADCONFIG ;return 0 ; }I think this should stay in the caller...
Quoted 23 lines
target/ppc/mmu-radix64.c +13
-5/* Read page <directory/table> entry from guest address space */ - index = eaddr >> (*psize - nls);/* Shift */ - index &= ((1UL << nls) -1 );/* Mask */ - pde =ldq_phys (cs->as, base_addr + (index *sizeof (pde))); -if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ + pde =ldq_phys (cs->as, *pte_addr); +if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ *fault_cause |=DSISR_NOPTE ;return 0 ; } - *psize -= nls; + *psize -= *nls; +if (!(pde &R_PTE_LEAF )) {/* Prepare for next iteration */ + *nls = pde &R_PDE_NLS ; + index = eaddr >> (*psize - *nls);/* Shift */ + index &= ((1UL << *nls) -1 );/* Mask */ + *pte_addr = (pde &R_PDE_NLB ) + (index *sizeof (pde)); + } +return pde; +} + +static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr,target/ppc/mmu-radix64.c static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, · line 204
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+ uint64_t base_addr, uint64_t nls, + hwaddr *raddr, int *psize, + int *fault_cause, hwaddr *pte_addr) +{ + uint64_t index, pde; + + index = eaddr >> (*psize - nls);/* Shift */ + index &= ((1UL << nls) -1 );/* Mask */ + *pte_addr = base_addr + (index *sizeof (pde)); + do {... here. So that we have a well established "bad config" path at the root level, just like the current code has.
Quoted 5 lines
Since the
ppc_radix64_walk_tree()now callsppc_radix64_next_level()in a loop instead of recursing, and sinceppc_radix64_next_level()returns the nls value for the next level, it really makes sense to have this check inppc_radix64_walk_tree()and maybe put an assert inppc_radix64_next_level().
ppc_radix64_next_level() also covers the needs of partition-scoped translation which translates each process table address. See PATCH 7.
I rather not duplicate more code and leave it as it is.
Thanks,
C.
Quoted 26 lines
Quoted 25 lines
target/ppc/mmu-radix64.c +6
-7+ pde =ppc_radix64_next_level (cpu, eaddr, pte_addr, &nls, psize, + fault_cause); + }while ((pde &R_PTE_VALID ) && !(pde &R_PTE_LEAF )); -/* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ -if (pde &R_PTE_LEAF ) { +/* Did we find a valid leaf? */ +if ((pde &R_PTE_VALID ) && (pde &R_PTE_LEAF )) {uint64_t rpn = pde &R_PTE_RPN ;uint64_t mask = (1UL << *psize) -1 ;/* Or high bits of rpn and low bits to ea to form whole real addr */ *raddr = (rpn & ~mask) | (eaddr & mask); - *pte_addr = base_addr + (index *sizeof (pde)); -return pde; } -/* Next Level of Radix Tree */ -return ppc_radix64_walk_tree (cpu, eaddr, pde &R_PDE_NLB , pde &R_PDE_NLS , - raddr, psize, fault_cause, pte_addr); +return pde; }static bool validate_pate (PowerPCCPU *cpu,uint64_t lpid,ppc_v3_pate_t *pate)
Re: [PATCH 5/7] target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation
Quoted 91 lines · On Tue, 31 Mar 2020 11:10:20 +0200 Cédric Le Goater <[email protected]> wrote:
Quoted 84 lines · Greg Kurz
Quoted 4 lines · On Mon, 30 Mar 2020 11:49:44 +0200 Cédric Le Goater <[email protected]> wrote:
The
ppc_radix64_walk_tree()routine walks through the nested radix tables to look for a PTE.Split it two and introduce a new routine
ppc_radix64_next_level()Split it in two...
Quoted 24 lines
which we will use for partition-scoped Radix translation when translating the process tree addresses.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-)target/ppc/mmu-radix64.c +3
-4@@ -162,44 +162,60 @@ static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, } } -static uint64_t ppc_radix64_walk_tree (PowerPCCPU *cpu,vaddr eaddr, -uint64_t base_addr,uint64_t nls, -hwaddr *raddr,int *psize, -int *fault_cause,hwaddr *pte_addr) +static uint64_t ppc_radix64_next_level (PowerPCCPU *cpu,vaddr eaddr, +uint64_t *pte_addr,uint64_t *nls, +int *psize,int *fault_cause)target/ppc/mmu-radix64.c static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, · line 176
Quoted 10 lines
target/ppc/mmu-radix64.c +1
-1{CPUState *cs =CPU (cpu);uint64_t index, pde; -if (nls <5 ) {/* Directory maps less than 2**5 entries */ +if (*nls <5 ) {/* Directory maps less than 2**5 entries */ *fault_cause |=DSISR_R_BADCONFIG ;return 0 ; }I think this should stay in the caller...
Quoted 23 lines
target/ppc/mmu-radix64.c +13
-5/* Read page <directory/table> entry from guest address space */ - index = eaddr >> (*psize - nls);/* Shift */ - index &= ((1UL << nls) -1 );/* Mask */ - pde =ldq_phys (cs->as, base_addr + (index *sizeof (pde))); -if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ + pde =ldq_phys (cs->as, *pte_addr); +if (!(pde &R_PTE_VALID )) {/* Invalid Entry */ *fault_cause |=DSISR_NOPTE ;return 0 ; } - *psize -= nls; + *psize -= *nls; +if (!(pde &R_PTE_LEAF )) {/* Prepare for next iteration */ + *nls = pde &R_PDE_NLS ; + index = eaddr >> (*psize - *nls);/* Shift */ + index &= ((1UL << *nls) -1 );/* Mask */ + *pte_addr = (pde &R_PDE_NLB ) + (index *sizeof (pde)); + } +return pde; +} + +static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr,target/ppc/mmu-radix64.c static void ppc_radix64_set_rc(PowerPCCPU *cpu, int rwx, uint64_t pte, · line 204
Quoted 10 lines
target/ppc/mmu-radix64.c +10
-0+ uint64_t base_addr, uint64_t nls, + hwaddr *raddr, int *psize, + int *fault_cause, hwaddr *pte_addr) +{ + uint64_t index, pde; + + index = eaddr >> (*psize - nls);/* Shift */ + index &= ((1UL << nls) -1 );/* Mask */ + *pte_addr = base_addr + (index *sizeof (pde)); + do {... here. So that we have a well established "bad config" path at the root level, just like the current code has.
Quoted 5 lines
Since the
ppc_radix64_walk_tree()now callsppc_radix64_next_level()in a loop instead of recursing, and sinceppc_radix64_next_level()returns the nls value for the next level, it really makes sense to have this check inppc_radix64_walk_tree()and maybe put an assert inppc_radix64_next_level().
Quoted 5 lines
ppc_radix64_next_level()also covers the needs of partition-scoped translation which translates each process table address. See PATCH 7.I rather not duplicate more code and leave it as it is.
These patches change the behaviour of some existing paths in a non-trivial way. I'll wait for the respin and try to review again.
Quoted 31 lines
Thanks,
C.
Quoted 26 lines
Quoted 25 lines
target/ppc/mmu-radix64.c +6
-7+ pde =ppc_radix64_next_level (cpu, eaddr, pte_addr, &nls, psize, + fault_cause); + }while ((pde &R_PTE_VALID ) && !(pde &R_PTE_LEAF )); -/* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ -if (pde &R_PTE_LEAF ) { +/* Did we find a valid leaf? */ +if ((pde &R_PTE_VALID ) && (pde &R_PTE_LEAF )) {uint64_t rpn = pde &R_PTE_RPN ;uint64_t mask = (1UL << *psize) -1 ;/* Or high bits of rpn and low bits to ea to form whole real addr */ *raddr = (rpn & ~mask) | (eaddr & mask); - *pte_addr = base_addr + (index *sizeof (pde)); -return pde; } -/* Next Level of Radix Tree */ -return ppc_radix64_walk_tree (cpu, eaddr, pde &R_PDE_NLB , pde &R_PDE_NLS , - raddr, psize, fault_cause, pte_addr); +return pde; }static bool validate_pate (PowerPCCPU *cpu,uint64_t lpid,ppc_v3_pate_t *pate)
PATCH 6/7 target/ppc: Extend ppc_radix64_check_prot() with a 'partition_scoped' bool
In reply to Cédric Le GoaterThis prepares ground for partition-scoped Radix translation.
--- target/ppc/mmu-radix64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
target/ppc/mmu-radix64.c +6 -5
@@ -105,7 +105,8 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int rwx, vaddr eaddr,static bool ppc_radix64_check_prot (PowerPCCPU *cpu,int rwx,uint64_t pte, -int *fault_cause,int *prot) +int *fault_cause,int *prot, +bool partition_scoped) {CPUPPCState *env = &cpu->env;const int need_prot[] = {PAGE_READ ,PAGE_WRITE ,PAGE_EXEC };
@@ -121,11 +122,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, }/* Determine permissions allowed by Encoded Access Authority */ -if ((pte &R_PTE_EAA_PRIV ) && msr_pr) {/* Insufficient Privilege */ +if (!partition_scoped && (pte &R_PTE_EAA_PRIV ) && msr_pr) { *prot =0 ; - }else if (msr_pr || (pte &R_PTE_EAA_PRIV )) { + }else if (msr_pr || (pte &R_PTE_EAA_PRIV ) || partition_scoped) { *prot =ppc_radix64_get_prot_eaa (pte); - }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) */ + }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */ *prot =ppc_radix64_get_prot_eaa (pte); *prot &=ppc_radix64_get_prot_amr (cpu);/* Least combined permissions */ }
@@ -266,7 +267,7 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, g_raddr, g_page_size, &fault_cause, &pte_addr);if (!(pte &R_PTE_VALID ) || -ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) { +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot,0 )) {/* No valid pte or access denied due to protection */ if (cause_excp) {ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause);
Signature · 1 line
2.21.1
Re: [PATCH 6/7] target/ppc: Extend ppc_radix64_check_prot() with a 'partition_scoped' bool
Quoted 38 lines · On Mon, 30 Mar 2020 11:49:45 +0200 Cédric Le Goater <[email protected]> wrote:
This prepares ground for partition-scoped Radix translation.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)target/ppc/mmu-radix64.c +5
-4@@ -105,7 +105,8 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int rwx, vaddr eaddr,static bool ppc_radix64_check_prot (PowerPCCPU *cpu,int rwx,uint64_t pte, -int *fault_cause,int *prot) +int *fault_cause,int *prot, +bool partition_scoped) {CPUPPCState *env = &cpu->env;const int need_prot[] = {PAGE_READ ,PAGE_WRITE ,PAGE_EXEC };@@ -121,11 +122,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, }/* Determine permissions allowed by Encoded Access Authority */ -if ((pte &R_PTE_EAA_PRIV ) && msr_pr) {/* Insufficient Privilege */ +if (!partition_scoped && (pte &R_PTE_EAA_PRIV ) && msr_pr) { *prot =0 ; - }else if (msr_pr || (pte &R_PTE_EAA_PRIV )) { + }else if (msr_pr || (pte &R_PTE_EAA_PRIV ) || partition_scoped) { *prot =ppc_radix64_get_prot_eaa (pte); - }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) */ + }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */ *prot =ppc_radix64_get_prot_eaa (pte); *prot &=ppc_radix64_get_prot_amr (cpu);/* Least combined permissions */ }
target/ppc/mmu-radix64.c static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, · line 270
Quoted 5 lines
target/ppc/mmu-radix64.c +1
-1@@ -266,7 +267,7 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, g_raddr, g_page_size, &fault_cause, &pte_addr);if (!(pte &R_PTE_VALID ) || -ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) { +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot,0 )) {
Maybe pass false since ppc_radix64_check_prot() expects a bool ?
Apart from that,
Quoted 3 lines
target/ppc/mmu-radix64.c +0
-0/* No valid pte or access denied due to protection */ if (cause_excp) {ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause);
Re: [PATCH 6/7] target/ppc: Extend ppc_radix64_check_prot() with a 'partition_scoped' bool
Quoted 43 lines · Greg Kurz
Quoted 40 lines · On Mon, 30 Mar 2020 11:49:45 +0200 Cédric Le Goater <[email protected]> wrote:
This prepares ground for partition-scoped Radix translation.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)target/ppc/mmu-radix64.c +5
-4@@ -105,7 +105,8 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int rwx, vaddr eaddr,static bool ppc_radix64_check_prot (PowerPCCPU *cpu,int rwx,uint64_t pte, -int *fault_cause,int *prot) +int *fault_cause,int *prot, +bool partition_scoped) {CPUPPCState *env = &cpu->env;const int need_prot[] = {PAGE_READ ,PAGE_WRITE ,PAGE_EXEC };@@ -121,11 +122,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, }/* Determine permissions allowed by Encoded Access Authority */ -if ((pte &R_PTE_EAA_PRIV ) && msr_pr) {/* Insufficient Privilege */ +if (!partition_scoped && (pte &R_PTE_EAA_PRIV ) && msr_pr) { *prot =0 ; - }else if (msr_pr || (pte &R_PTE_EAA_PRIV )) { + }else if (msr_pr || (pte &R_PTE_EAA_PRIV ) || partition_scoped) { *prot =ppc_radix64_get_prot_eaa (pte); - }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) */ + }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */ *prot =ppc_radix64_get_prot_eaa (pte); *prot &=ppc_radix64_get_prot_amr (cpu);/* Least combined permissions */ }@@ -266,7 +267,7 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, g_raddr, g_page_size, &fault_cause, &pte_addr);
Quoted 5 lines
target/ppc/mmu-radix64.c static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, · line 270
Quoted 3 lines
target/ppc/mmu-radix64.c +1
-1if (!(pte &R_PTE_VALID ) || -ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) { +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot,0 )) {Maybe pass false since
ppc_radix64_check_prot()expects a bool ?
Sure,
Quoted 3 lines
Apart from that,
Reviewed-by Greg Kurz <[email protected]>
Thanks,
C.
Re: [PATCH 6/7] target/ppc: Extend ppc_radix64_check_prot() with a 'partition_scoped' bool
In reply to Cédric Le GoaterQuoted 38 lines · On Mon, 30 Mar 2020 11:49:45 +0200 Cédric Le Goater <[email protected]> wrote:
This prepares ground for partition-scoped Radix translation.
Signed-off-by Suraj Jitindar Singh <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-radix64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)target/ppc/mmu-radix64.c +5
-4@@ -105,7 +105,8 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int rwx, vaddr eaddr,static bool ppc_radix64_check_prot (PowerPCCPU *cpu,int rwx,uint64_t pte, -int *fault_cause,int *prot) +int *fault_cause,int *prot, +bool partition_scoped) {CPUPPCState *env = &cpu->env;const int need_prot[] = {PAGE_READ ,PAGE_WRITE ,PAGE_EXEC };@@ -121,11 +122,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, }/* Determine permissions allowed by Encoded Access Authority */ -if ((pte &R_PTE_EAA_PRIV ) && msr_pr) {/* Insufficient Privilege */ +if (!partition_scoped && (pte &R_PTE_EAA_PRIV ) && msr_pr) { *prot =0 ; - }else if (msr_pr || (pte &R_PTE_EAA_PRIV )) { + }else if (msr_pr || (pte &R_PTE_EAA_PRIV ) || partition_scoped) { *prot =ppc_radix64_get_prot_eaa (pte); - }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) */ + }else {/* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */ *prot =ppc_radix64_get_prot_eaa (pte); *prot &=ppc_radix64_get_prot_amr (cpu);/* Least combined permissions */ }
target/ppc/mmu-radix64.c static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, · line 270
Quoted 5 lines
target/ppc/mmu-radix64.c +1
-1@@ -266,7 +267,7 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, g_raddr, g_page_size, &fault_cause, &pte_addr);if (!(pte &R_PTE_VALID ) || -ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot)) { +ppc_radix64_check_prot (cpu, rwx, pte, &fault_cause, g_prot,0 )) {
Maybe pass false instead of 0 ?
Anyway,
Quoted 3 lines
target/ppc/mmu-radix64.c +0
-0/* No valid pte or access denied due to protection */ if (cause_excp) {ppc_radix64_raise_si (cpu, rwx, eaddr, fault_cause);
PATCH 7/7 target/ppc: Add support for Radix partition-scoped translation
In reply to Cédric Le GoaterThe Radix tree translation model currently supports process-scoped translation for the PowerNV machine (Hypervisor mode) and for the pSeries machine (Guest mode). Guests running under an emulated Hypervisor (PowerNV machine) require a new type of Radix translation, called partition-scoped, which is missing today.
The Radix tree translation is a 2 steps process. The first step, process-scoped translation, converts an effective Address to a guest real address, and the second step, partition-scoped translation, converts a guest real address to a host real address.
There are difference cases to covers :
* Hypervisor real mode access: no Radix translation.
* Hypervisor or host application access (quadrant 0 and 3) with relocation on: process-scoped translation.
* Guest OS real mode access: only partition-scoped translation.
* Guest OS real or guest application access (quadrant 0 and 3) with relocation on: both process-scoped translation and partition-scoped translations.
* Hypervisor access in quadrant 1 and 2 with relocation on: both process-scoped translation and partition-scoped translations.
The radix tree partition-scoped translation is performed using tables pointed to by the first double-word of the Partition Table Entries and process-scoped translation uses tables pointed to by the Process Table Entries (second double-word of the Partition Table Entries).
Both partition-scoped and process-scoped translations process are identical and thus the radix tree traversing code is largely reused. However, errors in partition-scoped translations generate hypervisor exceptions.
--- target/ppc/cpu.h | 3 + target/ppc/excp_helper.c | 3 +- target/ppc/mmu-radix64.c | 172 +++++++++++++++++++++++++++++++++++---- 3 files changed, 162 insertions(+), 16 deletions(-)
target/ppc/cpu.h +3 -0
@@ -464,6 +464,9 @@ typedef struct ppc_v3_pate_t {#define DSISR_AMR 0x00200000/* Unsupported Radix Tree Configuration */ #define DSISR_R_BADCONFIG 0x00080000 +#define DSISR_ATOMIC_RC 0x00040000 +/* Unable to translate address of (guest) pde or process/page table entry */ +#define DSISR_PRTABLE_FAULT 0x00020000/* SRR1 error code fields */
target/ppc/excp_helper.c +2 -1
@@ -525,9 +525,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)case POWERPC_EXCP_ISEG :/* Instruction segment exception */ case POWERPC_EXCP_TRACE :/* Trace exception */ break ; +case POWERPC_EXCP_HISI :/* Hypervisor instruction storage exception */ + msr |= env->error_code;case POWERPC_EXCP_HDECR :/* Hypervisor decrementer exception */ case POWERPC_EXCP_HDSI :/* Hypervisor data storage exception */ -case POWERPC_EXCP_HISI :/* Hypervisor instruction storage exception */ case POWERPC_EXCP_HDSEG :/* Hypervisor data segment exception */ case POWERPC_EXCP_HISEG :/* Hypervisor instruction segment exception */ case POWERPC_EXCP_SDOOR_HV :/* Hypervisor Doorbell interrupt */
target/ppc/mmu-radix64.c +157 -15
240 lines not on this page · raw message
Signature · 1 line
2.21.1