Nicholas Piggin writes:
> This register controls supervisor SPR modifications, and as such is only
> relevant for KVM. KVM always sets AMOR to ~0 on guest entry, and never
> restores it coming back out to the host, so it can be kept constant and
> avoid the mtSPR in KVM guest entry.
>
> -21 cycles (9116) cycles POWER9 virt-mode NULL hcall
>
> Signed-off-by: Nicholas Piggin
Reviewed-by: Fabiano Rosas
> ---
> arch/powerpc/kernel/cpu_setup_power.c| 8
> arch/powerpc/kernel/dt_cpu_ftrs.c| 2 ++
> arch/powerpc/kvm/book3s_hv_p9_entry.c| 2 --
> arch/powerpc/kvm/book3s_hv_rmhandlers.S | 2 --
> arch/powerpc/mm/book3s64/radix_pgtable.c | 15 ---
> arch/powerpc/platforms/powernv/idle.c| 8 +++-
> 6 files changed, 13 insertions(+), 24 deletions(-)
>
> diff --git a/arch/powerpc/kernel/cpu_setup_power.c
> b/arch/powerpc/kernel/cpu_setup_power.c
> index 3cca88ee96d7..a29dc8326622 100644
> --- a/arch/powerpc/kernel/cpu_setup_power.c
> +++ b/arch/powerpc/kernel/cpu_setup_power.c
> @@ -137,6 +137,7 @@ void __setup_cpu_power7(unsigned long offset, struct
> cpu_spec *t)
> return;
>
> mtspr(SPRN_LPID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA206(mfspr(SPRN_LPCR), LPCR_LPES1 >> LPCR_LPES_SH);
> }
> @@ -150,6 +151,7 @@ void __restore_cpu_power7(void)
> return;
>
> mtspr(SPRN_LPID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA206(mfspr(SPRN_LPCR), LPCR_LPES1 >> LPCR_LPES_SH);
> }
> @@ -164,6 +166,7 @@ void __setup_cpu_power8(unsigned long offset, struct
> cpu_spec *t)
> return;
>
> mtspr(SPRN_LPID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA206(mfspr(SPRN_LPCR) | LPCR_PECEDH, 0); /* LPES = 0 */
> init_HFSCR();
> @@ -184,6 +187,7 @@ void __restore_cpu_power8(void)
> return;
>
> mtspr(SPRN_LPID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA206(mfspr(SPRN_LPCR) | LPCR_PECEDH, 0); /* LPES = 0 */
> init_HFSCR();
> @@ -202,6 +206,7 @@ void __setup_cpu_power9(unsigned long offset, struct
> cpu_spec *t)
> mtspr(SPRN_PSSCR, 0);
> mtspr(SPRN_LPID, 0);
> mtspr(SPRN_PID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
>LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
> @@ -223,6 +228,7 @@ void __restore_cpu_power9(void)
> mtspr(SPRN_PSSCR, 0);
> mtspr(SPRN_LPID, 0);
> mtspr(SPRN_PID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
>LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
> @@ -242,6 +248,7 @@ void __setup_cpu_power10(unsigned long offset, struct
> cpu_spec *t)
> mtspr(SPRN_PSSCR, 0);
> mtspr(SPRN_LPID, 0);
> mtspr(SPRN_PID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
>LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
> @@ -264,6 +271,7 @@ void __restore_cpu_power10(void)
> mtspr(SPRN_PSSCR, 0);
> mtspr(SPRN_LPID, 0);
> mtspr(SPRN_PID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_PCR, PCR_MASK);
> init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
>LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
> diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c
> b/arch/powerpc/kernel/dt_cpu_ftrs.c
> index 358aee7c2d79..0a6b36b4bda8 100644
> --- a/arch/powerpc/kernel/dt_cpu_ftrs.c
> +++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
> @@ -80,6 +80,7 @@ static void __restore_cpu_cpufeatures(void)
> mtspr(SPRN_LPCR, system_registers.lpcr);
> if (hv_mode) {
> mtspr(SPRN_LPID, 0);
> + mtspr(SPRN_AMOR, ~0);
> mtspr(SPRN_HFSCR, system_registers.hfscr);
> mtspr(SPRN_PCR, system_registers.pcr);
> }
> @@ -216,6 +217,7 @@ static int __init feat_enable_hv(struct dt_cpu_feature *f)
> }
>
> mtspr(SPRN_LPID, 0);
> + mtspr(SPRN_AMOR, ~0);
>
> lpcr = mfspr(SPRN_LPCR);
> lpcr &= ~LPCR_LPES0; /* HV external interrupts */
> diff --git a/arch/powerpc/kvm/book3s_hv_p9_entry.c
> b/arch/powerpc/kvm/book3s_hv_p9_entry.c
> index c4f3e066fcb4..a3281f0c9214 100644
> --- a/arch/powerpc/kvm/book3s_hv_p9_entry.c
> +++ b/arch/powerpc/kvm/book3s_hv_p9_entry.c
> @@ -286,8 +286,6 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64
> time_limit, unsigned long lpc
> mtspr(SPRN_SPRG2, vcpu->arch.shregs.sprg2);
> mtspr(SPRN_SPRG3, vcpu->arch.shregs.sprg3);
>
> - mtspr(SPRN_AMOR, ~0UL);
> -
> local_paca->kvm_hstate.in_guest =