* [Qemu-devel] [PATCH v2 0/1] target-ppc: Fix booke206 tlbwe TLB instruction @ 2018-01-15 9:32 Luc MICHEL 2018-01-15 9:32 ` [Qemu-devel] [PATCH v2 1/1] " Luc MICHEL 0 siblings, 1 reply; 3+ messages in thread From: Luc MICHEL @ 2018-01-15 9:32 UTC (permalink / raw) To: qemu-devel; +Cc: Luc MICHEL, qemu-ppc, David Gibson, Alexander Graf v1 is here: https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg00140.html v2: - Add a comment with a cite from the "PowerPC e500 Core Family Reference Manual, Rev. 1", as advised by David. Thanks. Luc MICHEL (1): target-ppc: Fix booke206 tlbwe TLB instruction target/ppc/mmu_helper.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) -- 2.15.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH v2 1/1] target-ppc: Fix booke206 tlbwe TLB instruction 2018-01-15 9:32 [Qemu-devel] [PATCH v2 0/1] target-ppc: Fix booke206 tlbwe TLB instruction Luc MICHEL @ 2018-01-15 9:32 ` Luc MICHEL 2018-01-16 4:58 ` David Gibson 0 siblings, 1 reply; 3+ messages in thread From: Luc MICHEL @ 2018-01-15 9:32 UTC (permalink / raw) To: qemu-devel; +Cc: Luc MICHEL, qemu-ppc, David Gibson, Alexander Graf When overwritting a valid TLB entry with a new one, the previous page were not flushed in QEMU TLB, leading to incoherent mapping. This commit fixes this. Signed-off-by: Luc MICHEL <luc.michel@git.antfield.fr> --- target/ppc/mmu_helper.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/target/ppc/mmu_helper.c b/target/ppc/mmu_helper.c index 2a1f9902c9..298c15e961 100644 --- a/target/ppc/mmu_helper.c +++ b/target/ppc/mmu_helper.c @@ -2570,6 +2570,17 @@ void helper_booke_setpid(CPUPPCState *env, uint32_t pidn, target_ulong pid) tlb_flush(CPU(cpu)); } +static inline void flush_page(CPUPPCState *env, ppcmas_tlb_t *tlb) +{ + PowerPCCPU *cpu = ppc_env_get_cpu(env); + + if (booke206_tlb_to_page_size(env, tlb) == TARGET_PAGE_SIZE) { + tlb_flush_page(CPU(cpu), tlb->mas2 & MAS2_EPN_MASK); + } else { + tlb_flush(CPU(cpu)); + } +} + void helper_booke206_tlbwe(CPUPPCState *env) { PowerPCCPU *cpu = ppc_env_get_cpu(env); @@ -2628,6 +2639,21 @@ void helper_booke206_tlbwe(CPUPPCState *env) if (msr_gs) { cpu_abort(CPU(cpu), "missing HV implementation\n"); } + + if (tlb->mas1 & MAS1_VALID) { + /* Invalidate the page in QEMU TLB if it was a valid entry. + * + * In "PowerPC e500 Core Family Reference Manual, Rev. 1", + * Section "12.4.2 TLB Write Entry (tlbwe) Instruction": + * (https://www.nxp.com/docs/en/reference-manual/E500CORERM.pdf) + * + * "Note that when an L2 TLB entry is written, it may be displacing an + * already valid entry in the same L2 TLB location (a victim). If a + * valid L1 TLB entry corresponds to the L2 MMU victim entry, that L1 + * TLB entry is automatically invalidated." */ + flush_page(env, tlb); + } + tlb->mas7_3 = ((uint64_t)env->spr[SPR_BOOKE_MAS7] << 32) | env->spr[SPR_BOOKE_MAS3]; tlb->mas1 = env->spr[SPR_BOOKE_MAS1]; @@ -2663,11 +2689,7 @@ void helper_booke206_tlbwe(CPUPPCState *env) tlb->mas1 &= ~MAS1_IPROT; } - if (booke206_tlb_to_page_size(env, tlb) == TARGET_PAGE_SIZE) { - tlb_flush_page(CPU(cpu), tlb->mas2 & MAS2_EPN_MASK); - } else { - tlb_flush(CPU(cpu)); - } + flush_page(env, tlb); } static inline void booke206_tlb_to_mas(CPUPPCState *env, ppcmas_tlb_t *tlb) -- 2.15.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/1] target-ppc: Fix booke206 tlbwe TLB instruction 2018-01-15 9:32 ` [Qemu-devel] [PATCH v2 1/1] " Luc MICHEL @ 2018-01-16 4:58 ` David Gibson 0 siblings, 0 replies; 3+ messages in thread From: David Gibson @ 2018-01-16 4:58 UTC (permalink / raw) To: Luc MICHEL; +Cc: qemu-devel, qemu-ppc, Alexander Graf [-- Attachment #1: Type: text/plain, Size: 2870 bytes --] On Mon, Jan 15, 2018 at 10:32:20AM +0100, Luc MICHEL wrote: > When overwritting a valid TLB entry with a new one, the previous page > were not flushed in QEMU TLB, leading to incoherent mapping. This commit > fixes this. > > Signed-off-by: Luc MICHEL <luc.michel@git.antfield.fr> Applied to ppc-for-2.12. > --- > target/ppc/mmu_helper.c | 32 +++++++++++++++++++++++++++----- > 1 file changed, 27 insertions(+), 5 deletions(-) > > diff --git a/target/ppc/mmu_helper.c b/target/ppc/mmu_helper.c > index 2a1f9902c9..298c15e961 100644 > --- a/target/ppc/mmu_helper.c > +++ b/target/ppc/mmu_helper.c > @@ -2570,6 +2570,17 @@ void helper_booke_setpid(CPUPPCState *env, uint32_t pidn, target_ulong pid) > tlb_flush(CPU(cpu)); > } > > +static inline void flush_page(CPUPPCState *env, ppcmas_tlb_t *tlb) > +{ > + PowerPCCPU *cpu = ppc_env_get_cpu(env); > + > + if (booke206_tlb_to_page_size(env, tlb) == TARGET_PAGE_SIZE) { > + tlb_flush_page(CPU(cpu), tlb->mas2 & MAS2_EPN_MASK); > + } else { > + tlb_flush(CPU(cpu)); > + } > +} > + > void helper_booke206_tlbwe(CPUPPCState *env) > { > PowerPCCPU *cpu = ppc_env_get_cpu(env); > @@ -2628,6 +2639,21 @@ void helper_booke206_tlbwe(CPUPPCState *env) > if (msr_gs) { > cpu_abort(CPU(cpu), "missing HV implementation\n"); > } > + > + if (tlb->mas1 & MAS1_VALID) { > + /* Invalidate the page in QEMU TLB if it was a valid entry. > + * > + * In "PowerPC e500 Core Family Reference Manual, Rev. 1", > + * Section "12.4.2 TLB Write Entry (tlbwe) Instruction": > + * (https://www.nxp.com/docs/en/reference-manual/E500CORERM.pdf) > + * > + * "Note that when an L2 TLB entry is written, it may be displacing an > + * already valid entry in the same L2 TLB location (a victim). If a > + * valid L1 TLB entry corresponds to the L2 MMU victim entry, that L1 > + * TLB entry is automatically invalidated." */ > + flush_page(env, tlb); > + } > + > tlb->mas7_3 = ((uint64_t)env->spr[SPR_BOOKE_MAS7] << 32) | > env->spr[SPR_BOOKE_MAS3]; > tlb->mas1 = env->spr[SPR_BOOKE_MAS1]; > @@ -2663,11 +2689,7 @@ void helper_booke206_tlbwe(CPUPPCState *env) > tlb->mas1 &= ~MAS1_IPROT; > } > > - if (booke206_tlb_to_page_size(env, tlb) == TARGET_PAGE_SIZE) { > - tlb_flush_page(CPU(cpu), tlb->mas2 & MAS2_EPN_MASK); > - } else { > - tlb_flush(CPU(cpu)); > - } > + flush_page(env, tlb); > } > > static inline void booke206_tlb_to_mas(CPUPPCState *env, ppcmas_tlb_t *tlb) -- 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 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-16 5:16 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-01-15 9:32 [Qemu-devel] [PATCH v2 0/1] target-ppc: Fix booke206 tlbwe TLB instruction Luc MICHEL 2018-01-15 9:32 ` [Qemu-devel] [PATCH v2 1/1] " Luc MICHEL 2018-01-16 4:58 ` David Gibson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).