target-ppc: htab fixes
cover target-ppc: htab fixes
Hi,
This is a new tentative for the patches 2/5 to 5/5 from the "target-ppc: Add support for dumping guest memory using qemu gdb server" patchset:
https://lists.nongnu.org/archive/html/qemu-ppc/2014-01/msg00380.html
All patches have been rebased on the current ppc-next head (72c798d7dccc).
To ensure proper bisectability, the following was verified for each individual patch:
•- 32 and 64 bit build of ppc-softmmu and ppc64-softmmu (fedora 19 ppc64) •- 64 bit pseries guest with KVM on a POWER7 host (fedora 19 ppc64) •- 64 bit pseries guest with 64 bit TCG on a x86_64 host (fedora 19 ppc64) •- 64 bit pseries guest with 32 bit TCG on a x86_64 host (fedora 19 ppc64) •- 32 bit mac99 guest with 64 bit TCG on a x86_64 host (wheezy ppc) •- 32 bit mac99 guest with 32 bit TCG on a x86_64 host (wheezy ppc)
Alex,
This should address all the requirements you expressed in your last mail. Please tell me if something is missing.
Best regards.
---
Aneesh Kumar K.V (4):
target-ppc: Fix htab_mask calculation
target-ppc: Fix page table lookup with kvm enabled
target-ppc: Change the hpte store API
target-ppc: Update ppc_hash64_store_hpte to support updating in-kernel htab
hw/ppc/spapr.c | 9 ++++ hw/ppc/spapr_hcall.c | 81 ++++++++++++++++++++++--------------- target-ppc/cpu.h | 1 target-ppc/kvm.c | 93 ++++++++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 29 +++++++++++++ target-ppc/machine.c | 11 +++-- target-ppc/misc_helper.c | 4 +- target-ppc/mmu-hash64.c | 101 +++++++++++++++++++++++++++++++++++++++------- target-ppc/mmu-hash64.h | 47 ++++++++------------- target-ppc/mmu_helper.c | 3 + 10 files changed, 293 insertions(+), 86 deletions(-)
Signature · 1 line
Greg
PATCH 1/4 target-ppc: Fix htab_mask calculation
From: Aneesh Kumar K.V <[email protected]>
Correctly update the htab_mask using the return value of KVM_PPC_ALLOCATE_HTAB ioctl. Also we don't update sdr1 on GET_SREGS for HV. We check for external htab and if found true, we don't need to update sdr1
[ fixed pte group offset computation in ppc_hash64_htab_lookup() that
caused TCG to fail, Greg Kurz <[email protected]> ]
--- hw/ppc/spapr.c | 8 +++++++- hw/ppc/spapr_hcall.c | 19 +++++++++++++++---- target-ppc/cpu.h | 1 + target-ppc/kvm.c | 4 +++- target-ppc/machine.c | 11 +++++++---- target-ppc/misc_helper.c | 4 +++- target-ppc/mmu-hash64.c | 4 ++-- target-ppc/mmu_helper.c | 3 ++- 8 files changed, 40 insertions(+), 14 deletions(-)
hw/ppc/spapr.c +7 -1
@@ -749,7 +749,13 @@ static void spapr_cpu_reset(void *opaque) env->external_htab = (void *)1 ; } env->htab_base =-1 ; - env->htab_mask =HTAB_SIZE (spapr) -1 ; +/* +* htab_mask is the mask used to normalize hash value to PTEG index. +* htab_shift is log2 of hash table size. +* We have 8 hpte per group, and each hpte is 16 bytes. +* ie have 128 bytes per hpte entry. +*/ + env->htab_mask = (1ULL << ((spapr)->htab_shift -7 )) -1 ; env->spr[SPR_SDR1 ] = (target_ulong )(uintptr_t )spapr->htab | (spapr->htab_shift -18 ); }
hw/ppc/spapr_hcall.c +15 -4
@@ -40,6 +40,17 @@ static target_ulong compute_tlbie_rb(target_ulong v, target_ulong r,return rb; } +static inline bool valid_pte_index (CPUPPCState *env,target_ulong pte_index) +{ +/* +* hash value/pteg group index is normalized by htab_mask +*/ +if (((pte_index & ~7ULL ) /HPTES_PER_GROUP ) & ~env->htab_mask) { +return false; + } +return true; +} +static target_ulong h_enter (PowerPCCPU *cpu,sPAPREnvironment *spapr,target_ulong opcode,target_ulong *args) {
@@ -91,7 +102,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, pteh &= ~0x60ULL ; -if ((pte_index *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ; }if (likely ((flags &H_EXACT ) ==0 )) {
@@ -136,7 +147,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,hwaddr hpte;target_ulong v, r, rb; -if ((ptex *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, ptex)) {return REMOVE_PARM ; }
@@ -262,7 +273,7 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,hwaddr hpte;target_ulong v, r, rb; -if ((pte_index *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ; }
@@ -299,7 +310,7 @@ static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,uint8_t *hpte;int i, ridx, n_entries =1 ; -if ((pte_index *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ; }
target-ppc/cpu.h +1 -0
@@ -961,6 +961,7 @@ struct CPUPPCState {#endif /* segment registers */ hwaddr htab_base; +/* mask used to normalize hash value to PTEG index */ hwaddr htab_mask;target_ulong sr[32 ];/* externally stored hash table */
target-ppc/kvm.c +3 -1
@@ -1031,7 +1031,9 @@ int kvm_arch_get_registers(CPUState *cs)return ret; } -ppc_store_sdr1 (env, sregs.u.s.sdr1); +if (!env->external_htab) { +ppc_store_sdr1 (env, sregs.u.s.sdr1); + }/* Sync SLB */ #ifdef TARGET_PPC64
target-ppc/machine.c +7 -4
@@ -70,7 +70,9 @@ static int cpu_load_old(QEMUFile *f, void *opaque, int version_id)qemu_get_betls (f, &env->pb[i]);for (i =0 ; i <1024 ; i++)qemu_get_betls (f, &env->spr[i]); -ppc_store_sdr1 (env, sdr1); +if (!env->external_htab) { +ppc_store_sdr1 (env, sdr1); + }qemu_get_be32s (f, &env->vscr);qemu_get_be64s (f, &env->spe_acc);qemu_get_be32s (f, &env->spe_fscr);
@@ -179,9 +181,10 @@ static int cpu_post_load(void *opaque, int version_id) env->IBAT[1 ][i+4 ] = env->spr[SPR_IBAT4U +2 *i +1 ]; } -/* Restore htab_base and htab_mask variables */ -ppc_store_sdr1 (env, env->spr[SPR_SDR1 ]); - +if (!env->external_htab) { +/* Restore htab_base and htab_mask variables */ +ppc_store_sdr1 (env, env->spr[SPR_SDR1 ]); + }hreg_compute_hflags (env);hreg_compute_mem_idx (env);
target-ppc/misc_helper.c +3 -1
@@ -38,7 +38,9 @@ void helper_store_dump_spr(CPUPPCState *env, uint32_t sprn)void helper_store_sdr1 (CPUPPCState *env,target_ulong val) { -ppc_store_sdr1 (env, val); +if (!env->external_htab) { +ppc_store_sdr1 (env, val); + } }void helper_store_hid0_601 (CPUPPCState *env,target_ulong val)
target-ppc/mmu-hash64.c +2 -2
@@ -375,7 +375,7 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env," vsid=" TARGET_FMT_lx" ptem=" TARGET_FMT_lx" hash=" TARGET_FMT_plx"\n" , env->htab_base, env->htab_mask, vsid, ptem, hash); - pteg_off = (hash *HASH_PTEG_SIZE_64 ) & env->htab_mask; + pteg_off = (hash & env->htab_mask) *HASH_PTEG_SIZE_64 ; pte_offset =ppc_hash64_pteg_search (env, pteg_off,0 , ptem, pte);if (pte_offset ==-1 ) {
@@ -385,7 +385,7 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env," hash=" TARGET_FMT_plx"\n" , env->htab_base, env->htab_mask, vsid, ptem, ~hash); - pteg_off = (~hash *HASH_PTEG_SIZE_64 ) & env->htab_mask; + pteg_off = (~hash & env->htab_mask) *HASH_PTEG_SIZE_64 ; pte_offset =ppc_hash64_pteg_search (env, pteg_off,1 , ptem, pte); }
target-ppc/mmu_helper.c +2 -1
@@ -2014,6 +2014,7 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)void ppc_store_sdr1 (CPUPPCState *env,target_ulong value) {LOG_MMU ("%s: " TARGET_FMT_lx"\n" , __func__, value); +assert (!env->external_htab);if (env->spr[SPR_SDR1 ] != value) { env->spr[SPR_SDR1 ] = value;#if defined(TARGET_PPC64 )
@@ -2025,7 +2026,7 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value) " stored in SDR1\n", htabsize); htabsize = 28; } - env->htab_mask = (1ULL << (htabsize +18 )) -1 ; + env->htab_mask = (1ULL << (htabsize +18 -7 )) -1 ; env->htab_base = value &SDR_64_HTABORG ; } else#endif /* defined(TARGET_PPC64) */
PATCH 2/4 target-ppc: Fix page table lookup with kvm enabled
In reply to Greg KurzFrom: Aneesh Kumar K.V <[email protected]>
With kvm enabled, we store the hash page table information in the hypervisor. Use ioctl to read the htab contents. Without this we get the below error when trying to read the guest address
(gdb) x/10 do_fork
0xc000000000098660 <do_fork>: Cannot access memory at address 0xc000000000098660
(gdb)
[ folded fixes for 32 bit build (casts!), ldq_phys() API change,
Greg Kurz <[email protected] ]
--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_hcall.c | 50 +++++++++++++++++++----------- target-ppc/kvm.c | 53 ++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 19 +++++++++++ target-ppc/mmu-hash64.c | 78 +++++++++++++++++++++++++++++++++++++++-------- target-ppc/mmu-hash64.h | 22 +++++++++---- 6 files changed, 183 insertions(+), 40 deletions(-)
hw/ppc/spapr.c +1 -0
@@ -686,6 +686,7 @@ static void spapr_reset_htab(sPAPREnvironment *spapr)if (shift >0 ) {/* Kernel handles htab, we don't need to allocate one */ spapr->htab_shift = shift; + kvmppc_kern_htab = true; }else {if (!spapr->htab) {/* Allocate an htab if we don't yet have one */
hw/ppc/spapr_hcall.c +31 -19
113 lines not on this page · raw message
target-ppc/kvm.c +53 -0
62 lines not on this page · raw message
target-ppc/kvm_ppc.h +19 -0
@@ -39,10 +39,13 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);int kvmppc_fixup_cpu (PowerPCCPU *cpu);bool kvmppc_has_cap_epr (void );int kvmppc_define_rtas_kernel_token (uint32_t token,const char *function); +bool kvmppc_has_cap_htab_fd (void );int kvmppc_get_htab_fd (bool write);int kvmppc_save_htab (QEMUFile *f,int fd,size_t bufsize,int64_t max_ns);int kvmppc_load_htab_chunk (QEMUFile *f,int fd,uint32_t index,uint16_t n_valid,uint16_t n_invalid); +uint64_t kvmppc_hash64_read_pteg (PowerPCCPU *cpu,target_ulong pte_index); +void kvmppc_hash64_free_pteg (uint64_t token);#else
@@ -171,6 +174,11 @@ static inline int kvmppc_define_rtas_kernel_token(uint32_t token,return -1 ; } +static inline bool kvmppc_has_cap_htab_fd (void ) +{ +return false; +} +static inline int kvmppc_get_htab_fd (bool write) {return -1 ;
@@ -188,6 +196,17 @@ static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, abort(); } +static inline uint64_t kvmppc_hash64_read_pteg (PowerPCCPU *cpu, +target_ulong pte_index) +{ +abort (); +} + +static inline void kvmppc_hash64_free_pteg (uint64_t token) +{ +abort (); +} +#endif #ifndef CONFIG_KVM
target-ppc/mmu-hash64.c +64 -14
122 lines not on this page · raw message
target-ppc/mmu-hash64.h +15 -7
@@ -75,26 +75,34 @@ int ppc_hash64_handle_mmu_fault(CPUPPCState *env, target_ulong address, int rw,#define HPTE64_V_1TB_SEG 0x4000000000000000ULL#define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL + +extern bool kvmppc_kern_htab; +uint64_t ppc_hash64_start_access (PowerPCCPU *cpu,target_ulong pte_index); +void ppc_hash64_stop_access (uint64_t token); +static inline target_ulong ppc_hash64_load_hpte0 (CPUPPCState *env, -hwaddr pte_offset) +uint64_t token,int index) {CPUState *cs =ENV_GET_CPU (env); +uint64_t addr; + addr = token + (index *HASH_PTE_SIZE_64 );if (env->external_htab) { -return ldq_p (env->external_htab + pte_offset); +return ldq_p ((const void *)(uintptr_t )addr); }else { -return ldq_phys (cs->as, env->htab_base + pte_offset); +return ldq_phys (cs->as, addr); } }static inline target_ulong ppc_hash64_load_hpte1 (CPUPPCState *env, -hwaddr pte_offset) +uint64_t token,int index) {CPUState *cs =ENV_GET_CPU (env); +uint64_t addr; + addr = token + (index *HASH_PTE_SIZE_64 ) +HASH_PTE_SIZE_64 /2 ;if (env->external_htab) { -return ldq_p (env->external_htab + pte_offset +HASH_PTE_SIZE_64 /2 ); +return ldq_p ((const void *)(uintptr_t )addr); }else { -return ldq_phys (cs->as, - env->htab_base + pte_offset +HASH_PTE_SIZE_64 /2 ); +return ldq_phys (cs->as, addr); } }
PATCH 3/4 target-ppc: Change the hpte store API
In reply to Greg KurzFrom: Aneesh Kumar K.V <[email protected]>
For updating in kernel htab we need to provide both pte0 and pte1, hence update the interface to take pte0 and pte1 together
--- hw/ppc/spapr_hcall.c | 20 ++++++-------------- target-ppc/mmu-hash64.c | 3 ++- target-ppc/mmu-hash64.h | 24 ++++++++---------------- 3 files changed, 16 insertions(+), 31 deletions(-)
hw/ppc/spapr_hcall.c +6 -14
@@ -62,7 +62,6 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,target_ulong page_shift =12 ;target_ulong raddr;target_ulong index; -hwaddr hpte;uint64_t token;/* only handle 4k and 16M pages for now */
@@ -108,7 +107,6 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, } index =0 ; - hpte = pte_index *HASH_PTE_SIZE_64 ;if (likely ((flags &H_EXACT ) ==0 )) { pte_index &= ~7ULL ; token =ppc_hash64_start_access (cpu, pte_index);
@@ -130,11 +128,9 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, }ppc_hash64_stop_access (token); } - hpte += index *HASH_PTE_SIZE_64 ; -ppc_hash64_store_hpte1 (env, hpte, ptel); -/* eieio(); FIXME: need some sort of barrier for smp? */ -ppc_hash64_store_hpte0 (env, hpte, pteh |HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, pte_index + index, + pteh |HPTE64_V_HPTE_DIRTY , ptel); args[0 ] = pte_index + index;return H_SUCCESS ;
@@ -152,7 +148,6 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,target_ulong flags, target_ulong *vp, target_ulong *rp) { - hwaddr hpte; uint64_t token;target_ulong v, r, rb;
@@ -172,8 +167,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex, } *vp = v; *rp = r; - hpte = ptex *HASH_PTE_SIZE_64 ; -ppc_hash64_store_hpte0 (env, hpte,HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, ptex,HPTE64_V_HPTE_DIRTY ,0 ); rb =compute_tlbie_rb (v, r, ptex);ppc_tlb_invalidate_one (env, rb);return REMOVE_SUCCESS ;
@@ -280,7 +274,6 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,target_ulong flags = args[0 ];target_ulong pte_index = args[1 ];target_ulong avpn = args[2 ]; -hwaddr hpte;uint64_t token;target_ulong v, r, rb;
@@ -304,12 +297,11 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr, r |= (flags <<48 ) &HPTE64_R_KEY_HI ; r |= flags & (HPTE64_R_PP |HPTE64_R_N |HPTE64_R_KEY_LO ); rb =compute_tlbie_rb (v, r, pte_index); - hpte = pte_index *HASH_PTE_SIZE_64 ; -ppc_hash64_store_hpte0 (env, hpte, (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, pte_index, + (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY ,0 );ppc_tlb_invalidate_one (env, rb); -ppc_hash64_store_hpte1 (env, hpte, r);/* Don't need a memory barrier, due to qemu's global lock */ -ppc_hash64_store_hpte0 (env, hpte, v |HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, pte_index, v |HPTE64_V_HPTE_DIRTY , r);return H_SUCCESS ; }
target-ppc/mmu-hash64.c +2 -1
@@ -566,7 +566,8 @@ int ppc_hash64_handle_mmu_fault(CPUPPCState *env, target_ulong eaddr, }if (new_pte1 != pte.pte1) { -ppc_hash64_store_hpte1 (env, pte_offset, new_pte1); +ppc_hash64_store_hpte (env, pte_offset /HASH_PTE_SIZE_64 , + pte.pte0, new_pte1); }/* 7. Determine the real address from the PTE */
target-ppc/mmu-hash64.h +8 -16
@@ -106,26 +106,18 @@ static inline target_ulong ppc_hash64_load_hpte1(CPUPPCState *env, } } -static inline void ppc_hash64_store_hpte0 (CPUPPCState *env, -hwaddr pte_offset,target_ulong pte0) +static inline void ppc_hash64_store_hpte (CPUPPCState *env, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) {CPUState *cs =ENV_GET_CPU (env); + pte_index *=HASH_PTE_SIZE_64 ;if (env->external_htab) { -stq_p (env->external_htab + pte_offset, pte0); +stq_p (env->external_htab + pte_index, pte0); +stq_p (env->external_htab + pte_index +HASH_PTE_SIZE_64 /2 , pte1); }else { -stq_phys (cs->as, env->htab_base + pte_offset, pte0); - } -} - -static inline void ppc_hash64_store_hpte1 (CPUPPCState *env, -hwaddr pte_offset,target_ulong pte1) -{ -CPUState *cs =ENV_GET_CPU (env); -if (env->external_htab) { -stq_p (env->external_htab + pte_offset +HASH_PTE_SIZE_64 /2 , pte1); - }else { -stq_phys (cs->as, - env->htab_base + pte_offset +HASH_PTE_SIZE_64 /2 , pte1); +stq_phys (cs->as, env->htab_base + pte_index, pte0); +stq_phys (cs->as, env->htab_base + pte_index +HASH_PTE_SIZE_64 /2 , pte1); } }
PATCH 4/4 target-ppc: Update ppc_hash64_store_hpte to support updating in-kernel htab
In reply to Greg KurzFrom: Aneesh Kumar K.V <[email protected]>
This support updating htab managed by the hypervisor. Currently we don't have any user for this feature. This actually bring the store_hpte interface in-line with the load_hpte one. We may want to use this when we want to emulate henter hcall in qemu for HV kvm.
[ folded fix for the "warn_unused_result" build break in
kvmppc_hash64_write_pte(), Greg Kurz <[email protected]> ]
--- target-ppc/kvm.c | 36 ++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 10 ++++++++++ target-ppc/mmu-hash64.c | 20 ++++++++++++++++++++ target-ppc/mmu-hash64.h | 17 ++--------------- 4 files changed, 68 insertions(+), 15 deletions(-)
target-ppc/kvm.c +36 -0
@@ -1991,3 +1991,39 @@ void kvmppc_hash64_free_pteg(uint64_t token)g_free (htab_buf);return ; } + +void kvmppc_hash64_write_pte (CPUPPCState *env,target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +int htab_fd; +struct kvm_get_htab_fd ghf; +struct kvm_get_htab_buf hpte_buf; + + ghf.flags =0 ; + ghf.start_index =0 ;/* Ignored */ + htab_fd =kvm_vm_ioctl (kvm_state,KVM_PPC_GET_HTAB_FD , &ghf); +if (htab_fd <0 ) { + goto error_out; + } + + hpte_buf.header.n_valid =1 ; + hpte_buf.header.n_invalid =0 ; + hpte_buf.header.index = pte_index; + hpte_buf.hpte[0 ] = pte0; + hpte_buf.hpte[1 ] = pte1; +/* +* Write the hpte entry. +* CAUTION: write() has the warn_unused_result attribute. Hence we +* need to check the return value, even though we do nothing. +*/ +if (write (htab_fd, &hpte_buf,sizeof (hpte_buf)) <0 ) { + goto out_close; + } + +out_close: +close (htab_fd); +return ; + +error_out: +return ; +}
target-ppc/kvm_ppc.h +10 -0
@@ -47,6 +47,9 @@ int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,uint64_t kvmppc_hash64_read_pteg (PowerPCCPU *cpu,target_ulong pte_index);void kvmppc_hash64_free_pteg (uint64_t token); +void kvmppc_hash64_write_pte (CPUPPCState *env,target_ulong pte_index, +target_ulong pte0,target_ulong pte1); +#else static inline uint32_t kvmppc_get_tbfreq (void )
@@ -207,6 +210,13 @@ static inline void kvmppc_hash64_free_pteg(uint64_t token) abort(); } +static inline void kvmppc_hash64_write_pte (CPUPPCState *env, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +abort (); +} +#endif #ifndef CONFIG_KVM
target-ppc/mmu-hash64.c +20 -0
@@ -603,3 +603,23 @@ hwaddr ppc_hash64_get_phys_page_debug(CPUPPCState *env, target_ulong addr)return ppc_hash64_pte_raddr (slb, pte, addr) &TARGET_PAGE_MASK ; } + +void ppc_hash64_store_hpte (CPUPPCState *env, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +CPUState *cs =ENV_GET_CPU (env); + +if (kvmppc_kern_htab) { +return kvmppc_hash64_write_pte (env, pte_index, pte0, pte1); + } + + pte_index *=HASH_PTE_SIZE_64 ; +if (env->external_htab) { +stq_p (env->external_htab + pte_index, pte0); +stq_p (env->external_htab + pte_index +HASH_PTE_SIZE_64 /2 , pte1); + }else { +stq_phys (cs->as, env->htab_base + pte_index, pte0); +stq_phys (cs->as, env->htab_base + pte_index +HASH_PTE_SIZE_64 /2 , pte1); + } +}
target-ppc/mmu-hash64.h +2 -15
@@ -9,6 +9,8 @@ int ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs);hwaddr ppc_hash64_get_phys_page_debug (CPUPPCState *env,target_ulong addr);int ppc_hash64_handle_mmu_fault (CPUPPCState *env,target_ulong address,int rw,int mmu_idx); +void ppc_hash64_store_hpte (CPUPPCState *env,target_ulong index, +target_ulong pte0,target_ulong pte1);#endif /*
@@ -106,21 +108,6 @@ static inline target_ulong ppc_hash64_load_hpte1(CPUPPCState *env, } } -static inline void ppc_hash64_store_hpte (CPUPPCState *env, -target_ulong pte_index, -target_ulong pte0,target_ulong pte1) -{ -CPUState *cs =ENV_GET_CPU (env); - pte_index *=HASH_PTE_SIZE_64 ; -if (env->external_htab) { -stq_p (env->external_htab + pte_index, pte0); -stq_p (env->external_htab + pte_index +HASH_PTE_SIZE_64 /2 , pte1); - }else { -stq_phys (cs->as, env->htab_base + pte_index, pte0); -stq_phys (cs->as, env->htab_base + pte_index +HASH_PTE_SIZE_64 /2 , pte1); - } -} -typedef struct {uint64_t pte0, pte1; }ppc_hash_pte64_t ;
cover target-ppc: htab fixes (V2)
In reply to Greg KurzQuoted 18 lines · On Mon, 17 Feb 2014 14:22:14 +0100 Greg Kurz <[email protected]> wrote:
Hi,
This is a new tentative for the patches 2/5 to 5/5 from the "target-ppc:
Add support for dumping guest memory using qemu gdb server" patchset:https://lists.nongnu.org/archive/html/qemu-ppc/2014-01/msg00380.html
All patches have been rebased on the current ppc-next head (
72c798d7dccc).To ensure proper bisectability, the following was verified for each individual patch:
•- 32 and 64 bit build of ppc-softmmu and ppc64-softmmu (fedora 19 ppc64) •- 64 bit pseries guest with KVM on a POWER7 host (fedora 19 ppc64) •- 64 bit pseries guest with 64 bit TCG on ax86_64host (fedora 19 ppc64) •- 64 bit pseries guest with 32 bit TCG on ax86_64host (fedora 19 ppc64) •- 32 bit mac99 guest with 64 bit TCG on ax86_64host (wheezy ppc) •- 32 bit mac99 guest with 32 bit TCG on ax86_64host (wheezy ppc)
Quoted 4 lines
Alex,
This should address all the requirements you expressed in your last mail. Please tell me if something is missing.
Alex,
I have added the 32 bit build with KVM enabled to catch the remaining build breaks:
target-ppc/kvm.c: In function 'kvmppc_hash64_read_pteg':target-ppc/kvm.c:1977:12: error: cast from pointer to integer of different size
[-Werror=pointer-to-int-cast]target-ppc/kvm.c: In function 'kvmppc_hash64_free_pteg':target-ppc/kvm.c:1990:82: error: cast to pointer from integer of different size
[-Werror=int-to-pointer-cast]
I have folded the fix into patch 2/4.
I have also fixed the SoB mess, and rebased on the current ppc-next.
Hope this time, it is okay ! :)
Best Regards.
---
Aneesh Kumar K.V (4):
target-ppc: Fix htab_mask calculation
target-ppc: Fix page table lookup with kvm enabled
target-ppc: Change the hpte store API
target-ppc: Update ppc_hash64_store_hpte to support updating in-kernel htab
hw/ppc/spapr.c | 9 ++++ hw/ppc/spapr_hcall.c | 81 ++++++++++++++++++++++--------------- target-ppc/cpu.h | 1 target-ppc/kvm.c | 94 ++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 29 +++++++++++++ target-ppc/machine.c | 11 +++-- target-ppc/misc_helper.c | 4 +- target-ppc/mmu-hash64.c | 101 +++++++++++++++++++++++++++++++++++++++------- target-ppc/mmu-hash64.h | 47 ++++++++------------- target-ppc/mmu_helper.c | 3 + 10 files changed, 294 insertions(+), 86 deletions(-)
Signature · 1 line
Greg
PATCH 1/4 target-ppc: Fix htab_mask calculation
From: Aneesh Kumar K.V <[email protected]>
Correctly update the htab_mask using the return value of KVM_PPC_ALLOCATE_HTAB ioctl. Also we don't update sdr1 on GET_SREGS for HV. We check for external htab and if found true, we don't need to update sdr1
[ fixed pte group offset computation in ppc_hash64_htab_lookup() that
caused TCG to fail, Greg Kurz <[email protected]> ]
--- hw/ppc/spapr.c | 8 +++++++- hw/ppc/spapr_hcall.c | 19 +++++++++++++++---- target-ppc/cpu.h | 1 + target-ppc/kvm.c | 4 +++- target-ppc/machine.c | 11 +++++++---- target-ppc/misc_helper.c | 4 +++- target-ppc/mmu-hash64.c | 4 ++-- target-ppc/mmu_helper.c | 3 ++- 8 files changed, 40 insertions(+), 14 deletions(-)
hw/ppc/spapr.c +7 -1
@@ -749,7 +749,13 @@ static void spapr_cpu_reset(void *opaque) env->external_htab = (void *)1 ; } env->htab_base =-1 ; - env->htab_mask =HTAB_SIZE (spapr) -1 ; +/* +* htab_mask is the mask used to normalize hash value to PTEG index. +* htab_shift is log2 of hash table size. +* We have 8 hpte per group, and each hpte is 16 bytes. +* ie have 128 bytes per hpte entry. +*/ + env->htab_mask = (1ULL << ((spapr)->htab_shift -7 )) -1 ; env->spr[SPR_SDR1 ] = (target_ulong )(uintptr_t )spapr->htab | (spapr->htab_shift -18 ); }
hw/ppc/spapr_hcall.c +15 -4
@@ -40,6 +40,17 @@ static target_ulong compute_tlbie_rb(target_ulong v, target_ulong r,return rb; } +static inline bool valid_pte_index (CPUPPCState *env,target_ulong pte_index) +{ +/* +* hash value/pteg group index is normalized by htab_mask +*/ +if (((pte_index & ~7ULL ) /HPTES_PER_GROUP ) & ~env->htab_mask) { +return false; + } +return true; +} +static target_ulong h_enter (PowerPCCPU *cpu,sPAPREnvironment *spapr,target_ulong opcode,target_ulong *args) {
@@ -91,7 +102,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, pteh &= ~0x60ULL ; -if ((pte_index *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ; }if (likely ((flags &H_EXACT ) ==0 )) {
@@ -136,7 +147,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,hwaddr hpte;target_ulong v, r, rb; -if ((ptex *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, ptex)) {return REMOVE_PARM ; }
@@ -262,7 +273,7 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,hwaddr hpte;target_ulong v, r, rb; -if ((pte_index *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ; }
@@ -299,7 +310,7 @@ static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,uint8_t *hpte;int i, ridx, n_entries =1 ; -if ((pte_index *HASH_PTE_SIZE_64 ) & ~env->htab_mask) { +if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ; }
target-ppc/cpu.h +1 -0
@@ -966,6 +966,7 @@ struct CPUPPCState {#endif /* segment registers */ hwaddr htab_base; +/* mask used to normalize hash value to PTEG index */ hwaddr htab_mask;target_ulong sr[32 ];/* externally stored hash table */
target-ppc/kvm.c +3 -1
@@ -1031,7 +1031,9 @@ int kvm_arch_get_registers(CPUState *cs)return ret; } -ppc_store_sdr1 (env, sregs.u.s.sdr1); +if (!env->external_htab) { +ppc_store_sdr1 (env, sregs.u.s.sdr1); + }/* Sync SLB */ #ifdef TARGET_PPC64
target-ppc/machine.c +7 -4
@@ -70,7 +70,9 @@ static int cpu_load_old(QEMUFile *f, void *opaque, int version_id)qemu_get_betls (f, &env->pb[i]);for (i =0 ; i <1024 ; i++)qemu_get_betls (f, &env->spr[i]); -ppc_store_sdr1 (env, sdr1); +if (!env->external_htab) { +ppc_store_sdr1 (env, sdr1); + }qemu_get_be32s (f, &env->vscr);qemu_get_be64s (f, &env->spe_acc);qemu_get_be32s (f, &env->spe_fscr);
@@ -179,9 +181,10 @@ static int cpu_post_load(void *opaque, int version_id) env->IBAT[1 ][i+4 ] = env->spr[SPR_IBAT4U +2 *i +1 ]; } -/* Restore htab_base and htab_mask variables */ -ppc_store_sdr1 (env, env->spr[SPR_SDR1 ]); - +if (!env->external_htab) { +/* Restore htab_base and htab_mask variables */ +ppc_store_sdr1 (env, env->spr[SPR_SDR1 ]); + }hreg_compute_hflags (env);hreg_compute_mem_idx (env);
target-ppc/misc_helper.c +3 -1
@@ -38,7 +38,9 @@ void helper_store_dump_spr(CPUPPCState *env, uint32_t sprn)void helper_store_sdr1 (CPUPPCState *env,target_ulong val) { -ppc_store_sdr1 (env, val); +if (!env->external_htab) { +ppc_store_sdr1 (env, val); + } }void helper_store_hid0_601 (CPUPPCState *env,target_ulong val)
target-ppc/mmu-hash64.c +2 -2
@@ -375,7 +375,7 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env," vsid=" TARGET_FMT_lx" ptem=" TARGET_FMT_lx" hash=" TARGET_FMT_plx"\n" , env->htab_base, env->htab_mask, vsid, ptem, hash); - pteg_off = (hash *HASH_PTEG_SIZE_64 ) & env->htab_mask; + pteg_off = (hash & env->htab_mask) *HASH_PTEG_SIZE_64 ; pte_offset =ppc_hash64_pteg_search (env, pteg_off,0 , ptem, pte);if (pte_offset ==-1 ) {
@@ -385,7 +385,7 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env," hash=" TARGET_FMT_plx"\n" , env->htab_base, env->htab_mask, vsid, ptem, ~hash); - pteg_off = (~hash *HASH_PTEG_SIZE_64 ) & env->htab_mask; + pteg_off = (~hash & env->htab_mask) *HASH_PTEG_SIZE_64 ; pte_offset =ppc_hash64_pteg_search (env, pteg_off,1 , ptem, pte); }
target-ppc/mmu_helper.c +2 -1
@@ -2014,6 +2014,7 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)void ppc_store_sdr1 (CPUPPCState *env,target_ulong value) {LOG_MMU ("%s: " TARGET_FMT_lx"\n" , __func__, value); +assert (!env->external_htab);if (env->spr[SPR_SDR1 ] != value) { env->spr[SPR_SDR1 ] = value;#if defined(TARGET_PPC64 )
@@ -2025,7 +2026,7 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value) " stored in SDR1\n", htabsize); htabsize = 28; } - env->htab_mask = (1ULL << (htabsize +18 )) -1 ; + env->htab_mask = (1ULL << (htabsize +18 -7 )) -1 ; env->htab_base = value &SDR_64_HTABORG ; } else#endif /* defined(TARGET_PPC64) */
PATCH 2/4 target-ppc: Fix page table lookup with kvm enabled
In reply to Greg KurzFrom: Aneesh Kumar K.V <[email protected]>
With kvm enabled, we store the hash page table information in the hypervisor. Use ioctl to read the htab contents. Without this we get the below error when trying to read the guest address
(gdb) x/10 do_fork
0xc000000000098660 <do_fork>: Cannot access memory at address 0xc000000000098660
(gdb)
[ fixes for 32 bit build (casts!), ldq_phys() API change,
Greg Kurz <[email protected] ]
--- hw/ppc/spapr.c | 1 + hw/ppc/spapr_hcall.c | 50 +++++++++++++++++++----------- target-ppc/kvm.c | 54 +++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 19 +++++++++++ target-ppc/mmu-hash64.c | 78 +++++++++++++++++++++++++++++++++++++++-------- target-ppc/mmu-hash64.h | 22 +++++++++---- 6 files changed, 184 insertions(+), 40 deletions(-)
hw/ppc/spapr.c +1 -0
@@ -686,6 +686,7 @@ static void spapr_reset_htab(sPAPREnvironment *spapr)if (shift >0 ) {/* Kernel handles htab, we don't need to allocate one */ spapr->htab_shift = shift; + kvmppc_kern_htab = true; }else {if (!spapr->htab) {/* Allocate an htab if we don't yet have one */
hw/ppc/spapr_hcall.c +31 -19
113 lines not on this page · raw message
target-ppc/kvm.c +54 -0
63 lines not on this page · raw message
target-ppc/kvm_ppc.h +19 -0
@@ -39,10 +39,13 @@ uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);int kvmppc_fixup_cpu (PowerPCCPU *cpu);bool kvmppc_has_cap_epr (void );int kvmppc_define_rtas_kernel_token (uint32_t token,const char *function); +bool kvmppc_has_cap_htab_fd (void );int kvmppc_get_htab_fd (bool write);int kvmppc_save_htab (QEMUFile *f,int fd,size_t bufsize,int64_t max_ns);int kvmppc_load_htab_chunk (QEMUFile *f,int fd,uint32_t index,uint16_t n_valid,uint16_t n_invalid); +uint64_t kvmppc_hash64_read_pteg (PowerPCCPU *cpu,target_ulong pte_index); +void kvmppc_hash64_free_pteg (uint64_t token);#else
@@ -171,6 +174,11 @@ static inline int kvmppc_define_rtas_kernel_token(uint32_t token,return -1 ; } +static inline bool kvmppc_has_cap_htab_fd (void ) +{ +return false; +} +static inline int kvmppc_get_htab_fd (bool write) {return -1 ;
@@ -188,6 +196,17 @@ static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, abort(); } +static inline uint64_t kvmppc_hash64_read_pteg (PowerPCCPU *cpu, +target_ulong pte_index) +{ +abort (); +} + +static inline void kvmppc_hash64_free_pteg (uint64_t token) +{ +abort (); +} +#endif #ifndef CONFIG_KVM
target-ppc/mmu-hash64.c +64 -14
122 lines not on this page · raw message
target-ppc/mmu-hash64.h +15 -7
@@ -75,26 +75,34 @@ int ppc_hash64_handle_mmu_fault(CPUPPCState *env, target_ulong address, int rw,#define HPTE64_V_1TB_SEG 0x4000000000000000ULL#define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL + +extern bool kvmppc_kern_htab; +uint64_t ppc_hash64_start_access (PowerPCCPU *cpu,target_ulong pte_index); +void ppc_hash64_stop_access (uint64_t token); +static inline target_ulong ppc_hash64_load_hpte0 (CPUPPCState *env, -hwaddr pte_offset) +uint64_t token,int index) {CPUState *cs =ENV_GET_CPU (env); +uint64_t addr; + addr = token + (index *HASH_PTE_SIZE_64 );if (env->external_htab) { -return ldq_p (env->external_htab + pte_offset); +return ldq_p ((const void *)(uintptr_t )addr); }else { -return ldq_phys (cs->as, env->htab_base + pte_offset); +return ldq_phys (cs->as, addr); } }static inline target_ulong ppc_hash64_load_hpte1 (CPUPPCState *env, -hwaddr pte_offset) +uint64_t token,int index) {CPUState *cs =ENV_GET_CPU (env); +uint64_t addr; + addr = token + (index *HASH_PTE_SIZE_64 ) +HASH_PTE_SIZE_64 /2 ;if (env->external_htab) { -return ldq_p (env->external_htab + pte_offset +HASH_PTE_SIZE_64 /2 ); +return ldq_p ((const void *)(uintptr_t )addr); }else { -return ldq_phys (cs->as, - env->htab_base + pte_offset +HASH_PTE_SIZE_64 /2 ); +return ldq_phys (cs->as, addr); } }
PATCH 3/4 target-ppc: Change the hpte store API
In reply to Greg KurzFrom: Aneesh Kumar K.V <[email protected]>
For updating in kernel htab we need to provide both pte0 and pte1, hence update the interface to take pte0 and pte1 together
--- hw/ppc/spapr_hcall.c | 20 ++++++-------------- target-ppc/mmu-hash64.c | 3 ++- target-ppc/mmu-hash64.h | 24 ++++++++---------------- 3 files changed, 16 insertions(+), 31 deletions(-)
hw/ppc/spapr_hcall.c +6 -14
@@ -62,7 +62,6 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,target_ulong page_shift =12 ;target_ulong raddr;target_ulong index; -hwaddr hpte;uint64_t token;/* only handle 4k and 16M pages for now */
@@ -108,7 +107,6 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, } index =0 ; - hpte = pte_index *HASH_PTE_SIZE_64 ;if (likely ((flags &H_EXACT ) ==0 )) { pte_index &= ~7ULL ; token =ppc_hash64_start_access (cpu, pte_index);
@@ -130,11 +128,9 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr, }ppc_hash64_stop_access (token); } - hpte += index *HASH_PTE_SIZE_64 ; -ppc_hash64_store_hpte1 (env, hpte, ptel); -/* eieio(); FIXME: need some sort of barrier for smp? */ -ppc_hash64_store_hpte0 (env, hpte, pteh |HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, pte_index + index, + pteh |HPTE64_V_HPTE_DIRTY , ptel); args[0 ] = pte_index + index;return H_SUCCESS ;
@@ -152,7 +148,6 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,target_ulong flags, target_ulong *vp, target_ulong *rp) { - hwaddr hpte; uint64_t token;target_ulong v, r, rb;
@@ -172,8 +167,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex, } *vp = v; *rp = r; - hpte = ptex *HASH_PTE_SIZE_64 ; -ppc_hash64_store_hpte0 (env, hpte,HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, ptex,HPTE64_V_HPTE_DIRTY ,0 ); rb =compute_tlbie_rb (v, r, ptex);ppc_tlb_invalidate_one (env, rb);return REMOVE_SUCCESS ;
@@ -280,7 +274,6 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,target_ulong flags = args[0 ];target_ulong pte_index = args[1 ];target_ulong avpn = args[2 ]; -hwaddr hpte;uint64_t token;target_ulong v, r, rb;
@@ -304,12 +297,11 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr, r |= (flags <<48 ) &HPTE64_R_KEY_HI ; r |= flags & (HPTE64_R_PP |HPTE64_R_N |HPTE64_R_KEY_LO ); rb =compute_tlbie_rb (v, r, pte_index); - hpte = pte_index *HASH_PTE_SIZE_64 ; -ppc_hash64_store_hpte0 (env, hpte, (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, pte_index, + (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY ,0 );ppc_tlb_invalidate_one (env, rb); -ppc_hash64_store_hpte1 (env, hpte, r);/* Don't need a memory barrier, due to qemu's global lock */ -ppc_hash64_store_hpte0 (env, hpte, v |HPTE64_V_HPTE_DIRTY ); +ppc_hash64_store_hpte (env, pte_index, v |HPTE64_V_HPTE_DIRTY , r);return H_SUCCESS ; }
target-ppc/mmu-hash64.c +2 -1
@@ -566,7 +566,8 @@ int ppc_hash64_handle_mmu_fault(CPUPPCState *env, target_ulong eaddr, }if (new_pte1 != pte.pte1) { -ppc_hash64_store_hpte1 (env, pte_offset, new_pte1); +ppc_hash64_store_hpte (env, pte_offset /HASH_PTE_SIZE_64 , + pte.pte0, new_pte1); }/* 7. Determine the real address from the PTE */
target-ppc/mmu-hash64.h +8 -16
@@ -106,26 +106,18 @@ static inline target_ulong ppc_hash64_load_hpte1(CPUPPCState *env, } } -static inline void ppc_hash64_store_hpte0 (CPUPPCState *env, -hwaddr pte_offset,target_ulong pte0) +static inline void ppc_hash64_store_hpte (CPUPPCState *env, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) {CPUState *cs =ENV_GET_CPU (env); + pte_index *=HASH_PTE_SIZE_64 ;if (env->external_htab) { -stq_p (env->external_htab + pte_offset, pte0); +stq_p (env->external_htab + pte_index, pte0); +stq_p (env->external_htab + pte_index +HASH_PTE_SIZE_64 /2 , pte1); }else { -stq_phys (cs->as, env->htab_base + pte_offset, pte0); - } -} - -static inline void ppc_hash64_store_hpte1 (CPUPPCState *env, -hwaddr pte_offset,target_ulong pte1) -{ -CPUState *cs =ENV_GET_CPU (env); -if (env->external_htab) { -stq_p (env->external_htab + pte_offset +HASH_PTE_SIZE_64 /2 , pte1); - }else { -stq_phys (cs->as, - env->htab_base + pte_offset +HASH_PTE_SIZE_64 /2 , pte1); +stq_phys (cs->as, env->htab_base + pte_index, pte0); +stq_phys (cs->as, env->htab_base + pte_index +HASH_PTE_SIZE_64 /2 , pte1); } }
PATCH 4/4 target-ppc: Update ppc_hash64_store_hpte to support updating in-kernel htab
In reply to Greg KurzFrom: Aneesh Kumar K.V <[email protected]>
This support updating htab managed by the hypervisor. Currently we don't have any user for this feature. This actually bring the store_hpte interface in-line with the load_hpte one. We may want to use this when we want to emulate henter hcall in qemu for HV kvm.
[ folded fix for the "warn_unused_result" build break in
kvmppc_hash64_write_pte(), Greg Kurz <[email protected]> ]
--- target-ppc/kvm.c | 36 ++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 10 ++++++++++ target-ppc/mmu-hash64.c | 20 ++++++++++++++++++++ target-ppc/mmu-hash64.h | 17 ++--------------- 4 files changed, 68 insertions(+), 15 deletions(-)
target-ppc/kvm.c +36 -0
@@ -1992,3 +1992,39 @@ void kvmppc_hash64_free_pteg(uint64_t token)g_free (htab_buf);return ; } + +void kvmppc_hash64_write_pte (CPUPPCState *env,target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +int htab_fd; +struct kvm_get_htab_fd ghf; +struct kvm_get_htab_buf hpte_buf; + + ghf.flags =0 ; + ghf.start_index =0 ;/* Ignored */ + htab_fd =kvm_vm_ioctl (kvm_state,KVM_PPC_GET_HTAB_FD , &ghf); +if (htab_fd <0 ) { + goto error_out; + } + + hpte_buf.header.n_valid =1 ; + hpte_buf.header.n_invalid =0 ; + hpte_buf.header.index = pte_index; + hpte_buf.hpte[0 ] = pte0; + hpte_buf.hpte[1 ] = pte1; +/* +* Write the hpte entry. +* CAUTION: write() has the warn_unused_result attribute. Hence we +* need to check the return value, even though we do nothing. +*/ +if (write (htab_fd, &hpte_buf,sizeof (hpte_buf)) <0 ) { + goto out_close; + } + +out_close: +close (htab_fd); +return ; + +error_out: +return ; +}
target-ppc/kvm_ppc.h +10 -0
@@ -47,6 +47,9 @@ int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,uint64_t kvmppc_hash64_read_pteg (PowerPCCPU *cpu,target_ulong pte_index);void kvmppc_hash64_free_pteg (uint64_t token); +void kvmppc_hash64_write_pte (CPUPPCState *env,target_ulong pte_index, +target_ulong pte0,target_ulong pte1); +#else static inline uint32_t kvmppc_get_tbfreq (void )
@@ -207,6 +210,13 @@ static inline void kvmppc_hash64_free_pteg(uint64_t token) abort(); } +static inline void kvmppc_hash64_write_pte (CPUPPCState *env, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +abort (); +} +#endif #ifndef CONFIG_KVM
target-ppc/mmu-hash64.c +20 -0
@@ -603,3 +603,23 @@ hwaddr ppc_hash64_get_phys_page_debug(CPUPPCState *env, target_ulong addr)return ppc_hash64_pte_raddr (slb, pte, addr) &TARGET_PAGE_MASK ; } + +void ppc_hash64_store_hpte (CPUPPCState *env, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +CPUState *cs =ENV_GET_CPU (env); + +if (kvmppc_kern_htab) { +return kvmppc_hash64_write_pte (env, pte_index, pte0, pte1); + } + + pte_index *=HASH_PTE_SIZE_64 ; +if (env->external_htab) { +stq_p (env->external_htab + pte_index, pte0); +stq_p (env->external_htab + pte_index +HASH_PTE_SIZE_64 /2 , pte1); + }else { +stq_phys (cs->as, env->htab_base + pte_index, pte0); +stq_phys (cs->as, env->htab_base + pte_index +HASH_PTE_SIZE_64 /2 , pte1); + } +}
target-ppc/mmu-hash64.h +2 -15
@@ -9,6 +9,8 @@ int ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs);hwaddr ppc_hash64_get_phys_page_debug (CPUPPCState *env,target_ulong addr);int ppc_hash64_handle_mmu_fault (CPUPPCState *env,target_ulong address,int rw,int mmu_idx); +void ppc_hash64_store_hpte (CPUPPCState *env,target_ulong index, +target_ulong pte0,target_ulong pte1);#endif /*
@@ -106,21 +108,6 @@ static inline target_ulong ppc_hash64_load_hpte1(CPUPPCState *env, } } -static inline void ppc_hash64_store_hpte (CPUPPCState *env, -target_ulong pte_index, -target_ulong pte0,target_ulong pte1) -{ -CPUState *cs =ENV_GET_CPU (env); - pte_index *=HASH_PTE_SIZE_64 ; -if (env->external_htab) { -stq_p (env->external_htab + pte_index, pte0); -stq_p (env->external_htab + pte_index +HASH_PTE_SIZE_64 /2 , pte1); - }else { -stq_phys (cs->as, env->htab_base + pte_index, pte0); -stq_phys (cs->as, env->htab_base + pte_index +HASH_PTE_SIZE_64 /2 , pte1); - } -} -typedef struct {uint64_t pte0, pte1; }ppc_hash_pte64_t ;
Alexander Graf
AppliedRe: [Qemu-devel] [PATCH 0/4] target-ppc: htab fixes (V2)
In reply to Greg KurzQuoted 39 lines · Greg Kurz
Quoted 18 lines · On Mon, 17 Feb 2014 14:22:14 +0100 Greg Kurz <[email protected]> wrote:
Hi,
This is a new tentative for the patches 2/5 to 5/5 from the "target-ppc:
Add support for dumping guest memory using qemu gdb server" patchset:https://lists.nongnu.org/archive/html/qemu-ppc/2014-01/msg00380.html
All patches have been rebased on the current ppc-next head (
72c798d7dccc).To ensure proper bisectability, the following was verified for each individual patch:
•- 32 and 64 bit build of ppc-softmmu and ppc64-softmmu (fedora 19 ppc64) •- 64 bit pseries guest with KVM on a POWER7 host (fedora 19 ppc64) •- 64 bit pseries guest with 64 bit TCG on ax86_64host (fedora 19 ppc64) •- 64 bit pseries guest with 32 bit TCG on ax86_64host (fedora 19 ppc64) •- 32 bit mac99 guest with 64 bit TCG on ax86_64host (wheezy ppc) •- 32 bit mac99 guest with 32 bit TCG on ax86_64host (wheezy ppc)Quoted 5 lines
Alex,
This should address all the requirements you expressed in your last mail. Please tell me if something is missing.
Alex,
I have added the 32 bit build with KVM enabled to catch the remaining build breaks:
target-ppc/kvm.c: In function 'kvmppc_hash64_read_pteg':target-ppc/kvm.c:1977:12: error: cast from pointer to integer of different size
[-Werror=pointer-to-int-cast]target-ppc/kvm.c: In function 'kvmppc_hash64_free_pteg':target-ppc/kvm.c:1990:82: error: cast to pointer from integer of different size
[-Werror=int-to-pointer-cast]
Quoted 6 lines
I have folded the fix into patch 2/4.
I have also fixed the SoB mess, and rebased on the current ppc-next.
Hope this time, it is okay ! :)
Thanks, applied to ppc-next.
Alex