ARM64: KVM: Nuke EL2 mode tlbs before enabling MMU for EL2
PATCH 1/1 ARM64: KVM: Nuke EL2 mode tlbs before enabling MMU for EL2
X-Gene u-boot runs in EL2 mode with MMU enabled hence we might have stale EL2 tlb enteris when we enable EL2 MMU on each host CPU.
This can happen on any ARM64 board running bootloader in EL2 with MMU enabled.
This patch ensures that we flush all EL2 TLBs on each host CPU before enabling EL2 MMU. This is very similar to what we do for EL1 TLBs before enabling EL1 MMU.
(Refer __cpu_setup() of arch/arm64/mm/proc.S)
--- arch/arm64/kvm/hyp-init.S | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/kvm/hyp-init.S +4 -0
@@ -80,6 +80,10 @@ __do_hyp_init: msr mair_el2, x4 isb + /* Invalidate the stale TLBs from Bootloader */ + tlbi alle2 + dsb sy + mrs x4, sctlr_el2 and x4, x4, #SCTLR_EL2_EE // preserve endianness of EL2 ldr x5, =SCTLR_EL2_FLAGS
Signature · 1 line
1.7.9.5
PATCH 1/1 ARM64: KVM: Nuke EL2 mode tlbs before enabling MMU for EL2
Hi Pranav,
Quoted 22 lines · Pranavkumar Sawargaonkar
X-Gene u-boot runs in EL2 mode with MMU enabled hence we might have stale EL2 tlb enteris when we enable EL2 MMU on each host CPU.
This can happen on any ARM64 board running bootloader in EL2 with MMU enabled.
This patch ensures that we flush all EL2 TLBs on each host CPU before enabling EL2 MMU. This is very similar to what we do for EL1 TLBs before enabling EL1 MMU.
(Refer__cpu_setup()ofarch/arm64/mm/proc.S)Signed-off-by Pranavkumar Sawargaonkar <[email protected]>Signed-off-by Anup Patel <[email protected]>--- arch/arm64/kvm/hyp-init.S | 4 ++++ 1 file changed, 4 insertions(+)arch/arm64/kvm/hyp-init.S +0
-0
arch/arm64/kvm/hyp-init.S __do_hyp_init: · line 89
Quoted 10 lines
arch/arm64/kvm/hyp-init.S +4
-0@@ -80,6 +80,10 @@ __do_hyp_init: msr mair_el2, x4 isb + /* Invalidate the stale TLBs from Bootloader */ + tlbi alle2 + dsb sy + mrs x4, sctlr_el2 and x4, x4, #SCTLR_EL2_EE // preserve endianness of EL2 ldr x5, =SCTLR_EL2_FLAGS
This looks like a valid fix. But I wonder if it wouldn't be better located in kernel/head.S::el2_setup?
Also, the 32bit code seems to suffer from the same issue. Care to fix it as well?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
A message that is not in the archive (sent off-list or not yet received): CAAHg+Hjo12X3_X+NXNb9+-+Xj2hetkEx+RihdRap9szLWvUd_w@mail.gmail.com
PATCH 1/1 ARM64: KVM: Nuke EL2 mode tlbs before enabling MMU for EL2
Quoted 44 lines · Pranavkumar Sawargaonkar
Hi Marc,
On 30 July 2014 16:30, Marc Zyngier <[email protected]> wrote:
Hi Pranav, On Wed, Jul 30 2014 at 10:46:47 am BST, Pranavkumar Sawargaonkar < pranavkumar at linaro.org> wrote: > X-Gene u-boot runs in EL2 mode with MMU enabled hence we might > have stale EL2 tlb enteris when we enable EL2 MMU on each host CPU. > > This can happen on any ARM64 board running bootloader in EL2 > with MMU enabled. > > This patch ensures that we flush all EL2 TLBs on each host CPU > before enabling EL2 MMU. This is very similar to what we do > for EL1 TLBs before enabling EL1 MMU. > (Refer __cpu_setup() of arch/arm64/mm/proc.S) > > Signed-off-by: Pranavkumar Sawargaonkar <[email protected]> > Signed-off-by: Anup Patel <[email protected]> > --- > ?arch/arm64/kvm/hyp-init.S | ? ?4 ++++ > ?1 file changed, 4 insertions(+) > > diff --git a/arch/arm64/kvm/hyp-init.S b/arch/arm64/kvm/hyp-init.S > index d968796..c319116 100644 > --- a/arch/arm64/kvm/hyp-init.S > +++ b/arch/arm64/kvm/hyp-init.S > @@ -80,6 +80,10 @@ __do_hyp_init: > ? ? ? msr ? ? mair_el2, x4 > ? ? ? isb > > + ? ? /* Invalidate the stale TLBs from Bootloader */ > + ? ? tlbi ? ?alle2 > + ? ? dsb ? ? sy > + > ? ? ? mrs ? ? x4, sctlr_el2 > ? ? ? and ? ? x4, x4, #SCTLR_EL2_EE ? // preserve endianness of EL2 > ? ? ? ldr ? ? x5, =SCTLR_EL2_FLAGS This looks like a valid fix. But I wonder if it wouldn't be better located in kernel/head.S::el2_setup?
Quoted 3 lines
Sure, I can try this on one of my flaky setup where I see this issue :) One question is , if someone tries to do load/unload KVM module frequently then do "
__do_hyp_init" will require the flushing again ?
Well, we can't really "unload" KVM, it is not a module. But CPU hotplug could trigger something similar (though I'd expect it to come back through el2_setup anyway).
Anyway, we can probably keep it in KVM, and revisit that later if that makes sense.
Quoted 7 lines
?
Also, the 32bit code seems to suffer from the same issue. Care to fix it as well?
I am fine with this but as I do not have arm32 board to test it somebody will need to add tested-by.
Sure. Fire away!
M.
Signature · 1 line
Jazz is not dead. It just smells funny.