KVM: PPC: Book3S: C-ify the P9 entry/exit code
Subsystems (2)
Nicholas Piggin
reviewerv7 cover KVM: PPC: Book3S: C-ify the P9 entry/exit code
Git tree here
https://github.com/npiggin/linux/tree/kvm-in-c-5.14-1
This series applies to upstream plus a couple of KVM regression fixes not yet in powerpc tree, which are included in the above git tree.
I split out the series into a few parts including about a dozen which were merged in the last window, but this brings a bunch of them together again for proposed merge.
Since last posting, this is rebased with some patches merged. Some patches have also been deferred.
No major changes to code, changelogs have been improved including some numbers and better explanation for HPT guest performance regression.
This has been tested with radix host and hash / radix guest and hash host / hash guest on P9. Also hash guest and PR KVM hash guest, and a PR KVM nested hash guest, and radix guest and nested HV KVM radix nested guest. P8 with SMT guest. Also P10 with radix and hash guests. It has been tested with RHEL6,7,8,9 and AIX guests.
Thanks,
Nick
Nicholas Piggin (32):
KVM: PPC: Book3S 64: move KVM interrupt entry to a common entry point
KVM: PPC: Book3S 64: Move GUEST_MODE_SKIP test into KVM
KVM: PPC: Book3S 64: add hcall interrupt handler
KVM: PPC: Book3S 64: Move hcall early register setup to KVM
KVM: PPC: Book3S 64: Move interrupt early register setup to KVM
KVM: PPC: Book3S 64: move bad_host_intr check to HV handler
KVM: PPC: Book3S 64: Minimise hcall handler calling convention
differences
KVM: PPC: Book3S HV P9: implement kvmppc_xive_pull_vcpu in C
KVM: PPC: Book3S HV P9: Move setting HDEC after switching to guest
LPCR
KVM: PPC: Book3S HV P9: Reduce irq_work vs guest decrementer races
KVM: PPC: Book3S HV P9: Move xive vcpu context management into
kvmhv_p9_guest_entry
KVM: PPC: Book3S HV P9: Move radix MMU switching instructions together
KVM: PPC: Book3S HV P9: Stop handling hcalls in real-mode in the P9
path
KVM: PPC: Book3S HV P9: Implement the rest of the P9 path in C
KVM: PPC: Book3S HV P9: inline kvmhv_load_hv_regs_and_go into
__kvmhv_vcpu_entry_p9
KVM: PPC: Book3S HV P9: Read machine check registers while MSR[RI] is
0 KVM: PPC: Book3S HV P9: Improve exit timing accounting coverage
KVM: PPC: Book3S HV P9: Move SPR loading after expiry time check
KVM: PPC: Book3S HV P9: Add helpers for OS SPR handling
KVM: PPC: Book3S HV P9: Switch to guest MMU context as late as
possible
KVM: PPC: Book3S HV: Implement radix prefetch workaround by disabling
MMU
KVM: PPC: Book3S HV: Remove support for dependent threads mode on P9
KVM: PPC: Book3S HV: Remove radix guest support from P7/8 path
KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers
KVM: PPC: Book3S HV: Remove unused nested HV tests in XICS emulation
KVM: PPC: Book3S HV P9: Allow all P9 processors to enable nested HV
KVM: PPC: Book3S HV: small pseries_do_hcall cleanup
KVM: PPC: Book3S HV: add virtual mode handlers for HPT hcalls and page
faults
KVM: PPC: Book3S HV P9: Reflect userspace hcalls to hash guests to
support PR KVM
KVM: PPC: Book3S HV P9: implement hash guest support
KVM: PPC: Book3S HV P9: implement hash host / hash guest support
KVM: PPC: Book3S HV: remove ISA v3.0 and v3.1 support from P7/8 path
arch/powerpc/include/asm/asm-prototypes.h | 3 +- arch/powerpc/include/asm/exception-64s.h | 13 + arch/powerpc/include/asm/kvm_asm.h | 1 + arch/powerpc/include/asm/kvm_book3s_64.h | 8 + arch/powerpc/include/asm/kvm_host.h | 8 +- arch/powerpc/include/asm/kvm_ppc.h | 18 +- arch/powerpc/include/asm/mmu_context.h | 6 - arch/powerpc/include/asm/time.h | 12 + arch/powerpc/kernel/asm-offsets.c | 1 - arch/powerpc/kernel/exceptions-64s.S | 250 ++------ arch/powerpc/kernel/security.c | 5 +- arch/powerpc/kernel/time.c | 10 - arch/powerpc/kvm/Makefile | 4 + arch/powerpc/kvm/book3s.c | 17 +- arch/powerpc/kvm/book3s_64_entry.S | 416 +++++++++++++ arch/powerpc/kvm/book3s_64_vio_hv.c | 12 - arch/powerpc/kvm/book3s_hv.c | 696 ++++++++++++---------- arch/powerpc/kvm/book3s_hv_builtin.c | 135 +---- arch/powerpc/kvm/book3s_hv_interrupts.S | 9 +- arch/powerpc/kvm/book3s_hv_p9_entry.c | 508 ++++++++++++++++ arch/powerpc/kvm/book3s_hv_rm_mmu.c | 12 + arch/powerpc/kvm/book3s_hv_rm_xics.c | 15 - arch/powerpc/kvm/book3s_hv_rmhandlers.S | 684 +-------------------- arch/powerpc/kvm/book3s_segment.S | 3 + arch/powerpc/kvm/book3s_xive.c | 113 +++- arch/powerpc/kvm/book3s_xive.h | 7 - arch/powerpc/kvm/book3s_xive_native.c | 10 - arch/powerpc/mm/book3s64/radix_pgtable.c | 27 +- arch/powerpc/mm/book3s64/radix_tlb.c | 46 -- arch/powerpc/mm/mmu_context.c | 4 +- arch/powerpc/platforms/powernv/idle.c | 52 +- 31 files changed, 1588 insertions(+), 1517 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_entry.S create mode 100644 arch/powerpc/kvm/book3s_hv_p9_entry.c
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerv7 cover KVM: PPC: Book3S: C-ify the P9 entry/exit code
Git tree here
https://github.com/npiggin/linux/tree/kvm-in-c-5.14-1
This series applies to upstream plus a couple of KVM regression fixes not yet in powerpc tree, which are included in the above git tree.
I split out the series into a few parts including about a dozen which were merged in the last window, but this brings a bunch of them together again for proposed merge.
Since last posting, this is rebased with some patches merged. Some patches have also been deferred.
No major changes to code, changelogs have been improved including some numbers and better explanation for HPT guest performance regression.
This has been tested with radix host and hash / radix guest and hash host / hash guest on P9. Also hash guest and PR KVM hash guest, and a PR KVM nested hash guest, and radix guest and nested HV KVM radix nested guest. P8 with SMT guest. Also P10 with radix and hash guests. It has been tested with RHEL6,7,8,9 and AIX guests.
Thanks,
Nick
Nicholas Piggin (32):
KVM: PPC: Book3S 64: move KVM interrupt entry to a common entry point
KVM: PPC: Book3S 64: Move GUEST_MODE_SKIP test into KVM
KVM: PPC: Book3S 64: add hcall interrupt handler
KVM: PPC: Book3S 64: Move hcall early register setup to KVM
KVM: PPC: Book3S 64: Move interrupt early register setup to KVM
KVM: PPC: Book3S 64: move bad_host_intr check to HV handler
KVM: PPC: Book3S 64: Minimise hcall handler calling convention
differences
KVM: PPC: Book3S HV P9: implement kvmppc_xive_pull_vcpu in C
KVM: PPC: Book3S HV P9: Move setting HDEC after switching to guest
LPCR
KVM: PPC: Book3S HV P9: Reduce irq_work vs guest decrementer races
KVM: PPC: Book3S HV P9: Move xive vcpu context management into
kvmhv_p9_guest_entry
KVM: PPC: Book3S HV P9: Move radix MMU switching instructions together
KVM: PPC: Book3S HV P9: Stop handling hcalls in real-mode in the P9
path
KVM: PPC: Book3S HV P9: Implement the rest of the P9 path in C
KVM: PPC: Book3S HV P9: inline kvmhv_load_hv_regs_and_go into
__kvmhv_vcpu_entry_p9
KVM: PPC: Book3S HV P9: Read machine check registers while MSR[RI] is
0 KVM: PPC: Book3S HV P9: Improve exit timing accounting coverage
KVM: PPC: Book3S HV P9: Move SPR loading after expiry time check
KVM: PPC: Book3S HV P9: Add helpers for OS SPR handling
KVM: PPC: Book3S HV P9: Switch to guest MMU context as late as
possible
KVM: PPC: Book3S HV: Implement radix prefetch workaround by disabling
MMU
KVM: PPC: Book3S HV: Remove support for dependent threads mode on P9
KVM: PPC: Book3S HV: Remove radix guest support from P7/8 path
KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers
KVM: PPC: Book3S HV: Remove unused nested HV tests in XICS emulation
KVM: PPC: Book3S HV P9: Allow all P9 processors to enable nested HV
KVM: PPC: Book3S HV: small pseries_do_hcall cleanup
KVM: PPC: Book3S HV: add virtual mode handlers for HPT hcalls and page
faults
KVM: PPC: Book3S HV P9: Reflect userspace hcalls to hash guests to
support PR KVM
KVM: PPC: Book3S HV P9: implement hash guest support
KVM: PPC: Book3S HV P9: implement hash host / hash guest support
KVM: PPC: Book3S HV: remove ISA v3.0 and v3.1 support from P7/8 path
arch/powerpc/include/asm/asm-prototypes.h | 3 +- arch/powerpc/include/asm/exception-64s.h | 13 + arch/powerpc/include/asm/kvm_asm.h | 1 + arch/powerpc/include/asm/kvm_book3s_64.h | 8 + arch/powerpc/include/asm/kvm_host.h | 8 +- arch/powerpc/include/asm/kvm_ppc.h | 18 +- arch/powerpc/include/asm/mmu_context.h | 6 - arch/powerpc/include/asm/time.h | 12 + arch/powerpc/kernel/asm-offsets.c | 1 - arch/powerpc/kernel/exceptions-64s.S | 250 ++------ arch/powerpc/kernel/security.c | 5 +- arch/powerpc/kernel/time.c | 10 - arch/powerpc/kvm/Makefile | 4 + arch/powerpc/kvm/book3s.c | 17 +- arch/powerpc/kvm/book3s_64_entry.S | 416 +++++++++++++ arch/powerpc/kvm/book3s_64_vio_hv.c | 12 - arch/powerpc/kvm/book3s_hv.c | 696 ++++++++++++---------- arch/powerpc/kvm/book3s_hv_builtin.c | 135 +---- arch/powerpc/kvm/book3s_hv_interrupts.S | 9 +- arch/powerpc/kvm/book3s_hv_p9_entry.c | 508 ++++++++++++++++ arch/powerpc/kvm/book3s_hv_rm_mmu.c | 12 + arch/powerpc/kvm/book3s_hv_rm_xics.c | 15 - arch/powerpc/kvm/book3s_hv_rmhandlers.S | 684 +-------------------- arch/powerpc/kvm/book3s_segment.S | 3 + arch/powerpc/kvm/book3s_xive.c | 113 +++- arch/powerpc/kvm/book3s_xive.h | 7 - arch/powerpc/kvm/book3s_xive_native.c | 10 - arch/powerpc/mm/book3s64/radix_pgtable.c | 27 +- arch/powerpc/mm/book3s64/radix_tlb.c | 46 -- arch/powerpc/mm/mmu_context.c | 4 +- arch/powerpc/platforms/powernv/idle.c | 52 +- 31 files changed, 1588 insertions(+), 1517 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_entry.S create mode 100644 arch/powerpc/kvm/book3s_hv_p9_entry.c
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 1/32 KVM: PPC: Book3S 64: move KVM interrupt entry to a common entry point
Rather than bifurcate the call depending on whether or not HV is possible, and have the HV entry test for PR, just make a single common point which does the demultiplexing. This makes it simpler to add another type of exit handler.
--- arch/powerpc/kernel/exceptions-64s.S | 8 +----- arch/powerpc/kvm/Makefile | 3 +++ arch/powerpc/kvm/book3s_64_entry.S | 36 +++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 11 ++------ 4 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_entry.S
arch/powerpc/kernel/exceptions-64s.S +1 -7
@@ -208,7 +208,6 @@ do_define_int n .endm #ifdef CONFIG_KVM_BOOK3S_64_HANDLER -#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE /* * All interrupts which set HSRR registers, as well as SRESET and MCE and * syscall when invoked with "sc 1" switch to MSR[HV]=1 (HVMODE) to be taken,
@@ -238,13 +237,8 @@ do_define_int n /* * If an interrupt is taken while a guest is running, it is immediately routed - * to KVM to handle. If both HV and PR KVM arepossible, KVM interrupts go first - * to kvmppc_interrupt_hv, which handles the PR guest case. + * to KVM to handle. */ -#define kvmppc_interrupt kvmppc_interrupt_hv -#else -#define kvmppc_interrupt kvmppc_interrupt_pr -#endif .macro KVMTEST name lbz r10,HSTATE_IN_GUEST(r13)
arch/powerpc/kvm/Makefile +3 -0
@@ -59,6 +59,9 @@ kvm-pr-y := \ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ tm.o +kvm-book3s_64-builtin-objs-y += \ + book3s_64_entry.o + ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o
arch/powerpc/kvm/book3s_64_entry.S new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <asm/asm-offsets.h> +#include <asm/cache.h> +#include <asm/kvm_asm.h> +#include <asm/kvm_book3s_asm.h> +#include <asm/ppc_asm.h> +#include <asm/reg.h> + +/* + * This is branched to from interrupt handlers in exception-64s.S which set + * IKVM_REAL or IKVM_VIRT, if HSTATE_IN_GUEST was found to be non-zero. + */ +.global kvmppc_interrupt +.balign IFETCH_ALIGN_BYTES +kvmppc_interrupt: + /* + * Register contents: + * R12 = (guest CR << 32) | interrupt vector + * R13 = PACA + * guest R12 saved in shadow VCPU SCRATCH0 + * guest R13 saved in SPRN_SCRATCH0 + */ +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE + std r9,HSTATE_SCRATCH2(r13) + lbz r9,HSTATE_IN_GUEST(r13) + cmpwi r9,KVM_GUEST_MODE_HOST_HV + beq kvmppc_bad_host_intr +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE + cmpwi r9,KVM_GUEST_MODE_GUEST + ld r9,HSTATE_SCRATCH2(r13) + beq kvmppc_interrupt_pr +#endif + b kvmppc_interrupt_hv +#else + b kvmppc_interrupt_pr +#endif
arch/powerpc/kvm/book3s_hv_rmhandlers.S +2 -9
@@ -1272,16 +1272,8 @@ kvmppc_interrupt_hv: * R13 = PACA * guest R12 saved in shadow VCPU SCRATCH0 * guest R13 saved in SPRN_SCRATCH0 + * guest R9 saved in HSTATE_SCRATCH2 */ - std r9, HSTATE_SCRATCH2(r13) - lbz r9, HSTATE_IN_GUEST(r13) - cmpwi r9, KVM_GUEST_MODE_HOST_HV - beq kvmppc_bad_host_intr -#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE - cmpwi r9, KVM_GUEST_MODE_GUEST - ld r9, HSTATE_SCRATCH2(r13) - beq kvmppc_interrupt_pr -#endif /* We're now back in the host but in guest MMU context */ li r9, KVM_GUEST_MODE_HOST_HV stb r9, HSTATE_IN_GUEST(r13)
@@ -3287,6 +3279,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_P9_TM_HV_ASSIST) * cfar is saved in HSTATE_CFAR(r13) * ppr is saved in HSTATE_PPR(r13) */ +.global kvmppc_bad_host_intr kvmppc_bad_host_intr: /* * Switch to the emergency stack, but start half-way down in
Signature · 1 line
2.23.0
Michael Ellerman
reviewerRe: [PATCH v7 01/32] KVM: PPC: Book3S 64: move KVM interrupt entry to a common entry point
Quoted 49 lines · Nicholas Piggin
Rather than bifurcate the call depending on whether or not HV is possible, and have the HV entry test for PR, just make a single common point which does the demultiplexing. This makes it simpler to add another type of exit handler.
Acked-by Paul Mackerras <[email protected]>Reviewed-by Daniel Axtens <[email protected]>Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/kernel/exceptions-64s.S | 8 +----- arch/powerpc/kvm/Makefile | 3 +++ arch/powerpc/kvm/book3s_64_entry.S | 36 +++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 11 ++------ 4 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_entry.Sarch/powerpc/kernel/exceptions-64s.S +1
-7@@ -208,7 +208,6 @@ do_define_int n .endm #ifdef CONFIG_KVM_BOOK3S_64_HANDLER -#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE /* * All interrupts which set HSRR registers, as well as SRESET and MCE and * syscall when invoked with "sc 1" switch to MSR[HV]=1 (HVMODE) to be taken,@@ -238,13 +237,8 @@ do_define_int n /* * If an interrupt is taken while a guest is running, it is immediately routed - * to KVM to handle. If both HV and PR KVM arepossible, KVM interrupts go first - * to kvmppc_interrupt_hv, which handles the PR guest case. + * to KVM to handle. */ -#define kvmppc_interrupt kvmppc_interrupt_hv -#else -#define kvmppc_interrupt kvmppc_interrupt_pr -#endif .macro KVMTEST name lbz r10,HSTATE_IN_GUEST(r13)arch/powerpc/kvm/Makefile +0
-0
arch/powerpc/kvm/Makefile kvm-pr-y := \ · line 64
Quoted 6 lines
arch/powerpc/kvm/Makefile +3
-0@@ -59,6 +59,9 @@ kvm-pr-y := \ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ tm.o +kvm-book3s_64-builtin-objs-y += \ + book3s_64_entry.o +
Further we down we have:
obj-y += $(kvm-book3s_64-builtin-objs-y)
Which means book3s_64_entry.S ends up getting built for BOOKE, which breaks.
I think instead we want to add it to the preceding entry, eg:
arch/powerpc/kvm/Makefile +1 -3
@@ -57,11 +57,9 @@ kvm-pr-y := \ book3s_32_mmu.o kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ + book3s_64_entry.o \ tm.o -kvm-book3s_64-builtin-objs-y += \ - book3s_64_entry.o - ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o
cheers
Nicholas Piggin
reviewerPATCH v7 2/32 KVM: PPC: Book3S 64: Move GUEST_MODE_SKIP test into KVM
In reply to Nicholas PigginMove the GUEST_MODE_SKIP logic into KVM code. This is quite a KVM internal detail that has no real need to be in common handlers.
Add a comment explaining the what and why of KVM "skip" interrupts.
--- arch/powerpc/kernel/exceptions-64s.S | 60 ---------------------------- arch/powerpc/kvm/book3s_64_entry.S | 59 ++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 61 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +0 -60
@@ -133,7 +133,6 @@ name: #define IBRANCH_TO_COMMON .L_IBRANCH_TO_COMMON_\name\() /* ENTRY branch to common */ #define IREALMODE_COMMON .L_IREALMODE_COMMON_\name\() /* Common runs in realmode */ #define IMASK .L_IMASK_\name\() /* IRQ soft-mask bit */ -#define IKVM_SKIP .L_IKVM_SKIP_\name\() /* Generate KVM skip handler */ #define IKVM_REAL .L_IKVM_REAL_\name\() /* Real entry tests KVM */ #define __IKVM_REAL(name) .L_IKVM_REAL_ ## name #define IKVM_VIRT .L_IKVM_VIRT_\name\() /* Virt entry tests KVM */
@@ -190,9 +189,6 @@ do_define_int n .ifndef IMASK IMASK=0 .endif - .ifndef IKVM_SKIP - IKVM_SKIP=0 - .endif .ifndef IKVM_REAL IKVM_REAL=0 .endif
@@ -250,15 +246,10 @@ do_define_int n .balign IFETCH_ALIGN_BYTES \name\()_kvm: - .if IKVM_SKIP - cmpwi r10,KVM_GUEST_MODE_SKIP - beq 89f - .else BEGIN_FTR_SECTION ld r10,IAREA+EX_CFAR(r13) std r10,HSTATE_CFAR(r13) END_FTR_SECTION_IFSET(CPU_FTR_CFAR) - .endif ld r10,IAREA+EX_CTR(r13) mtctr r10
@@ -285,27 +276,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) ori r12,r12,(IVEC) .endif b kvmppc_interrupt - - .if IKVM_SKIP -89: mtocrf 0x80,r9 - ld r10,IAREA+EX_CTR(r13) - mtctr r10 - ld r9,IAREA+EX_R9(r13) - ld r10,IAREA+EX_R10(r13) - ld r11,IAREA+EX_R11(r13) - ld r12,IAREA+EX_R12(r13) - .if IHSRR_IF_HVMODE - BEGIN_FTR_SECTION - b kvmppc_skip_Hinterrupt - FTR_SECTION_ELSE - b kvmppc_skip_interrupt - ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) - .elseif IHSRR - b kvmppc_skip_Hinterrupt - .else - b kvmppc_skip_interrupt - .endif - .endif .endm #else
@@ -1064,7 +1034,6 @@ INT_DEFINE_BEGIN(machine_check) ISET_RI=0 IDAR=1 IDSISR=1 - IKVM_SKIP=1 IKVM_REAL=1 INT_DEFINE_END(machine_check)
@@ -1336,7 +1305,6 @@ INT_DEFINE_BEGIN(data_access) IVEC=0x300 IDAR=1 IDSISR=1 - IKVM_SKIP=1 IKVM_REAL=1 INT_DEFINE_END(data_access)
@@ -1390,7 +1358,6 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) INT_DEFINE_BEGIN(data_access_slb) IVEC=0x380 IDAR=1 - IKVM_SKIP=1 IKVM_REAL=1 INT_DEFINE_END(data_access_slb)
@@ -2057,7 +2024,6 @@ INT_DEFINE_BEGIN(h_data_storage) IHSRR=1 IDAR=1 IDSISR=1 - IKVM_SKIP=1 IKVM_REAL=1 IKVM_VIRT=1 INT_DEFINE_END(h_data_storage)
@@ -3003,32 +2969,6 @@ EXPORT_SYMBOL(do_uaccess_flush) MASKED_INTERRUPT MASKED_INTERRUPT hsrr=1 -#ifdef CONFIG_KVM_BOOK3S_64_HANDLER -kvmppc_skip_interrupt: - /* - * Here all GPRs are unchanged from when the interrupt happened - * except for r13, which is saved in SPRG_SCRATCH0. - */ - mfspr r13, SPRN_SRR0 - addi r13, r13, 4 - mtspr SPRN_SRR0, r13 - GET_SCRATCH0(r13) - RFI_TO_KERNEL - b . - -kvmppc_skip_Hinterrupt: - /* - * Here all GPRs are unchanged from when the interrupt happened - * except for r13, which is saved in SPRG_SCRATCH0. - */ - mfspr r13, SPRN_HSRR0 - addi r13, r13, 4 - mtspr SPRN_HSRR0, r13 - GET_SCRATCH0(r13) - HRFI_TO_KERNEL - b . -#endif - /* * Relocation-on interrupts: A subset of the interrupts can be delivered * with IR=1/DR=1, if AIL=2 and MSR.HV won't be changed by delivering
arch/powerpc/kvm/book3s_64_entry.S +58 -1
78 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 3/32 KVM: PPC: Book3S 64: add hcall interrupt handler
In reply to Nicholas PigginAdd a separate hcall entry point. This can be used to deal with the different calling convention.
--- arch/powerpc/kernel/exceptions-64s.S | 6 +++--- arch/powerpc/kvm/book3s_64_entry.S | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +3 -3
@@ -1966,16 +1966,16 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) ori r12,r12,0xc00 #ifdef CONFIG_RELOCATABLE /* - * Requires __LOAD_FAR_HANDLER beause kvmppc_interrupt lives + * Requires __LOAD_FAR_HANDLER beause kvmppc_hcall lives * outside the head section. */ - __LOAD_FAR_HANDLER(r10, kvmppc_interrupt) + __LOAD_FAR_HANDLER(r10, kvmppc_hcall) mtctr r10 ld r10,PACA_EXGEN+EX_R10(r13) bctr #else ld r10,PACA_EXGEN+EX_R10(r13) - b kvmppc_interrupt + b kvmppc_hcall #endif #endif
arch/powerpc/kvm/book3s_64_entry.S +5 -1
@@ -8,9 +8,13 @@ #include <asm/reg.h> /* - * This is branched to from interrupt handlers in exception-64s.S which set + * These are branched to from interrupt handlers in exception-64s.S which set * IKVM_REAL or IKVM_VIRT, if HSTATE_IN_GUEST was found to be non-zero. */ +.global kvmppc_hcall +.balign IFETCH_ALIGN_BYTES +kvmppc_hcall: + .global kvmppc_interrupt .balign IFETCH_ALIGN_BYTES kvmppc_interrupt:
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 4/32 KVM: PPC: Book3S 64: Move hcall early register setup to KVM
In reply to Nicholas PigginSystem calls / hcalls have a different calling convention than other interrupts, so there is code in the KVMTEST to massage these into the same form as other interrupt handlers.
Move this work into the KVM hcall handler. This means teaching KVM a little more about the low level interrupt handler setup, PACA save areas, etc., although that's not obviously worse than the current approach of coming up with an entirely different interrupt register / save convention.
--- arch/powerpc/include/asm/exception-64s.h | 13 ++++++++ arch/powerpc/kernel/exceptions-64s.S | 42 +----------------------- arch/powerpc/kvm/book3s_64_entry.S | 30 +++++++++++++++++ 3 files changed, 44 insertions(+), 41 deletions(-)
arch/powerpc/include/asm/exception-64s.h +13 -0
@@ -35,6 +35,19 @@/* PACA save area size in u64 units (exgen, exmc, etc) */ #define EX_SIZE 10 +/* PACA save area offsets */ +#define EX_R9 0 +#define EX_R10 8 +#define EX_R11 16 +#define EX_R12 24 +#define EX_R13 32 +#define EX_DAR 40 +#define EX_DSISR 48 +#define EX_CCR 52 +#define EX_CFAR 56 +#define EX_PPR 64 +#define EX_CTR 72 +/* * maximum recursive depth of MCE exceptions */
arch/powerpc/kernel/exceptions-64s.S +1 -41
67 lines not on this page · raw message
arch/powerpc/kvm/book3s_64_entry.S +30 -0
@@ -14,6 +14,36 @@ .global kvmppc_hcall .balign IFETCH_ALIGN_BYTES kvmppc_hcall: + /* + * This is a hcall, so register convention is as + * Documentation/powerpc/papr_hcalls.rst, with these additions: + * R13 = PACA + * guest R13 saved in SPRN_SCRATCH0 + * R10 = free + * guest r10 saved in PACA_EXGEN + * + * This may also be a syscall from PR-KVM userspace that is to be + * reflected to the PR guest kernel, so registers may be set up for + * a system call rather than hcall. We don't currently clobber + * anything here, but the 0xc00 handler has already clobbered CTR + * and CR0, so PR-KVM can not support a guest kernel that preserves + * those registers across its system calls. + */ + /* + * Save the PPR (on systems that support it) before changing to + * HMT_MEDIUM. That allows the KVM code to save that value into the + * guest state (it is the guest's PPR value). + */ +BEGIN_FTR_SECTION + mfspr r10,SPRN_PPR + std r10,HSTATE_PPR(r13) +END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) + HMT_MEDIUM + mfcr r10 + std r12,HSTATE_SCRATCH0(r13) + sldi r12,r10,32 + ori r12,r12,0xc00 + ld r10,PACA_EXGEN+EX_R10(r13) .global kvmppc_interrupt .balign IFETCH_ALIGN_BYTES
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 5/32 KVM: PPC: Book3S 64: Move interrupt early register setup to KVM
In reply to Nicholas PigginLike the earlier patch for hcalls, KVM interrupt entry requires a different calling convention than the Linux interrupt handlers set up. Move the code that converts from one to the other into KVM.
--- arch/powerpc/kernel/exceptions-64s.S | 131 +++++---------------------- arch/powerpc/kvm/book3s_64_entry.S | 50 +++++++++- 2 files changed, 71 insertions(+), 110 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +23 -108
@@ -187,7 +187,6 @@ do_define_int n .endif .endm -#ifdef CONFIG_KVM_BOOK3S_64_HANDLER /* * All interrupts which set HSRR registers, as well as SRESET and MCE and * syscall when invoked with "sc 1" switch to MSR[HV]=1 (HVMODE) to be taken,
@@ -220,54 +219,25 @@ do_define_int n * to KVM to handle. */ -.macro KVMTEST name +.macro KVMTEST name handler +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER lbz r10,HSTATE_IN_GUEST(r13) cmpwi r10,0 - bne \name\()_kvm -.endm - -.macro GEN_KVM name - .balign IFETCH_ALIGN_BYTES -\name\()_kvm: - -BEGIN_FTR_SECTION - ld r10,IAREA+EX_CFAR(r13) - std r10,HSTATE_CFAR(r13) -END_FTR_SECTION_IFSET(CPU_FTR_CFAR) - - ld r10,IAREA+EX_CTR(r13) - mtctr r10 -BEGIN_FTR_SECTION - ld r10,IAREA+EX_PPR(r13) - std r10,HSTATE_PPR(r13) -END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) - ld r11,IAREA+EX_R11(r13) - ld r12,IAREA+EX_R12(r13) - std r12,HSTATE_SCRATCH0(r13) - sldi r12,r9,32 - ld r9,IAREA+EX_R9(r13) - ld r10,IAREA+EX_R10(r13) /* HSRR variants have the 0x2 bit added to their trap number */ .if IHSRR_IF_HVMODE BEGIN_FTR_SECTION - ori r12,r12,(IVEC + 0x2) + li r10,(IVEC + 0x2) FTR_SECTION_ELSE - ori r12,r12,(IVEC) + li r10,(IVEC) ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) .elseif IHSRR - ori r12,r12,(IVEC+ 0x2) + li r10,(IVEC + 0x2) .else - ori r12,r12,(IVEC) + li r10,(IVEC) .endif - b kvmppc_interrupt -.endm - -#else -.macro KVMTEST name -.endm -.macro GEN_KVM name -.endm + bne \handler #endif +.endm /* * This is the BOOK3S interrupt entry code macro.
@@ -409,7 +379,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR) DEFINE_FIXED_SYMBOL(\name\()_common_real) \name\()_common_real: .if IKVM_REAL - KVMTEST \name + KVMTEST \name kvm_interrupt .endif ld r10,PACAKMSR(r13) /* get MSR value for kernel */
@@ -432,7 +402,7 @@ DEFINE_FIXED_SYMBOL(\name\()_common_real) DEFINE_FIXED_SYMBOL(\name\()_common_virt) \name\()_common_virt: .if IKVM_VIRT - KVMTEST \name + KVMTEST \name kvm_interrupt 1: .endif .endif /* IVIRT */
@@ -446,7 +416,7 @@ DEFINE_FIXED_SYMBOL(\name\()_common_virt) DEFINE_FIXED_SYMBOL(\name\()_common_real) \name\()_common_real: .if IKVM_REAL - KVMTEST \name + KVMTEST \name kvm_interrupt .endif .endm
@@ -948,8 +918,6 @@ EXC_COMMON_BEGIN(system_reset_common) EXCEPTION_RESTORE_REGS RFI_TO_USER_OR_KERNEL - GEN_KVM system_reset - /** * Interrupt 0x200 - Machine Check Interrupt (MCE).
@@ -1113,7 +1081,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) /* * Check if we are coming from guest. If yes, then run the normal * exception handler which will take the - * machine_check_kvm->kvmppc_interrupt branch to deliver the MC event + * machine_check_kvm->kvm_interrupt branch to deliver the MC event * to guest. */ lbz r11,HSTATE_IN_GUEST(r13)
@@ -1183,8 +1151,6 @@ EXC_COMMON_BEGIN(machine_check_common) bl machine_check_exception b interrupt_return - GEN_KVM machine_check - #ifdef CONFIG_PPC_P7_NAP /*
@@ -1319,8 +1285,6 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) REST_NVGPRS(r1) b interrupt_return - GEN_KVM data_access - /** * Interrupt 0x380 - Data Segment Interrupt (DSLB).
@@ -1370,8 +1334,6 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) bl do_bad_slb_fault b interrupt_return - GEN_KVM data_access_slb - /** * Interrupt 0x400 - Instruction Storage Interrupt (ISI).
@@ -1408,8 +1370,6 @@ MMU_FTR_SECTION_ELSE ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) b interrupt_return - GEN_KVM instruction_access - /** * Interrupt 0x480 - Instruction Segment Interrupt (ISLB).
@@ -1454,8 +1414,6 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) bl do_bad_slb_fault b interrupt_return - GEN_KVM instruction_access_slb - /** * Interrupt 0x500 - External Interrupt.
@@ -1500,8 +1458,6 @@ EXC_COMMON_BEGIN(hardware_interrupt_common) bl do_IRQ b interrupt_return - GEN_KVM hardware_interrupt - /** * Interrupt 0x600 - Alignment Interrupt
@@ -1529,8 +1485,6 @@ EXC_COMMON_BEGIN(alignment_common) REST_NVGPRS(r1) /* instruction emulation may change GPRs */ b interrupt_return - GEN_KVM alignment - /** * Interrupt 0x700 - Program Interrupt (program check).
@@ -1638,8 +1592,6 @@ EXC_COMMON_BEGIN(program_check_common) REST_NVGPRS(r1) /* instruction emulation may change GPRs */ b interrupt_return - GEN_KVM program_check - /* * Interrupt 0x800 - Floating-Point Unavailable Interrupt.
@@ -1689,8 +1641,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_TM) b interrupt_return #endif - GEN_KVM fp_unavailable - /** * Interrupt 0x900 - Decrementer Interrupt.
@@ -1729,8 +1679,6 @@ EXC_COMMON_BEGIN(decrementer_common) bl timer_interrupt b interrupt_return - GEN_KVM decrementer - /** * Interrupt 0x980 - Hypervisor Decrementer Interrupt.
@@ -1776,8 +1724,6 @@ EXC_COMMON_BEGIN(hdecrementer_common) ld r13,PACA_EXGEN+EX_R13(r13) HRFI_TO_KERNEL - GEN_KVM hdecrementer - /** * Interrupt 0xa00 - Directed Privileged Doorbell Interrupt.
@@ -1817,8 +1763,6 @@ EXC_COMMON_BEGIN(doorbell_super_common) #endif b interrupt_return - GEN_KVM doorbell_super - EXC_REAL_NONE(0xb00, 0x100) EXC_VIRT_NONE(0x4b00, 0x100)
@@ -1868,7 +1812,7 @@ INT_DEFINE_END(system_call) GET_PACA(r13) std r10,PACA_EXGEN+EX_R10(r13) INTERRUPT_TO_KERNEL - KVMTEST system_call /* uses r10, branch to system_call_kvm */ + KVMTEST system_call kvm_hcall /* uses r10, branch to kvm_hcall */ mfctr r9 #else mr r9,r13
@@ -1924,7 +1868,7 @@ EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100) EXC_VIRT_END(system_call, 0x4c00, 0x100) #ifdef CONFIG_KVM_BOOK3S_64_HANDLER -TRAMP_REAL_BEGIN(system_call_kvm) +TRAMP_REAL_BEGIN(kvm_hcall) mfctr r10 SET_SCRATCH0(r10) /* Save r13 in SCRATCH0 */ #ifdef CONFIG_RELOCATABLE
@@ -1964,8 +1908,6 @@ EXC_COMMON_BEGIN(single_step_common) bl single_step_exception b interrupt_return - GEN_KVM single_step - /** * Interrupt 0xe00 - Hypervisor Data Storage Interrupt (HDSI).
@@ -2004,8 +1946,6 @@ MMU_FTR_SECTION_ELSE ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX) b interrupt_return - GEN_KVM h_data_storage - /** * Interrupt 0xe20 - Hypervisor Instruction Storage Interrupt (HISI).
@@ -2031,8 +1971,6 @@ EXC_COMMON_BEGIN(h_instr_storage_common) bl unknown_exception b interrupt_return - GEN_KVM h_instr_storage - /** * Interrupt 0xe40 - Hypervisor Emulation Assistance Interrupt.
@@ -2057,8 +1995,6 @@ EXC_COMMON_BEGIN(emulation_assist_common) REST_NVGPRS(r1) /* instruction emulation may change GPRs */ b interrupt_return - GEN_KVM emulation_assist - /** * Interrupt 0xe60 - Hypervisor Maintenance Interrupt (HMI).
@@ -2130,16 +2066,12 @@ EXC_COMMON_BEGIN(hmi_exception_early_common) EXCEPTION_RESTORE_REGS hsrr=1 GEN_INT_ENTRY hmi_exception, virt=0 - GEN_KVM hmi_exception_early - EXC_COMMON_BEGIN(hmi_exception_common) GEN_COMMON hmi_exception addi r3,r1,STACK_FRAME_OVERHEAD bl handle_hmi_exception b interrupt_return - GEN_KVM hmi_exception - /** * Interrupt 0xe80 - Directed Hypervisor Doorbell Interrupt.
@@ -2170,8 +2102,6 @@ EXC_COMMON_BEGIN(h_doorbell_common) #endif b interrupt_return - GEN_KVM h_doorbell - /** * Interrupt 0xea0 - Hypervisor Virtualization Interrupt.
@@ -2198,8 +2128,6 @@ EXC_COMMON_BEGIN(h_virt_irq_common) bl do_IRQ b interrupt_return - GEN_KVM h_virt_irq - EXC_REAL_NONE(0xec0, 0x20) EXC_VIRT_NONE(0x4ec0, 0x20)
@@ -2243,8 +2171,6 @@ EXC_COMMON_BEGIN(performance_monitor_common) bl performance_monitor_exception b interrupt_return - GEN_KVM performance_monitor - /** * Interrupt 0xf20 - Vector Unavailable Interrupt.
@@ -2294,8 +2220,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) bl altivec_unavailable_exception b interrupt_return - GEN_KVM altivec_unavailable - /** * Interrupt 0xf40 - VSX Unavailable Interrupt.
@@ -2344,8 +2268,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) bl vsx_unavailable_exception b interrupt_return - GEN_KVM vsx_unavailable - /** * Interrupt 0xf60 - Facility Unavailable Interrupt.
@@ -2374,8 +2296,6 @@ EXC_COMMON_BEGIN(facility_unavailable_common) REST_NVGPRS(r1) /* instruction emulation may change GPRs */ b interrupt_return - GEN_KVM facility_unavailable - /** * Interrupt 0xf60 - Hypervisor Facility Unavailable Interrupt.
@@ -2404,8 +2324,6 @@ EXC_COMMON_BEGIN(h_facility_unavailable_common) REST_NVGPRS(r1) /* XXX Shouldn't be necessary in practice */ b interrupt_return - GEN_KVM h_facility_unavailable - EXC_REAL_NONE(0xfa0, 0x20) EXC_VIRT_NONE(0x4fa0, 0x20)
@@ -2435,8 +2353,6 @@ EXC_COMMON_BEGIN(cbe_system_error_common) bl cbe_system_error_exception b interrupt_return - GEN_KVM cbe_system_error - #else /* CONFIG_CBE_RAS */ EXC_REAL_NONE(0x1200, 0x100) EXC_VIRT_NONE(0x5200, 0x100)
@@ -2468,8 +2384,6 @@ EXC_COMMON_BEGIN(instruction_breakpoint_common) bl instruction_breakpoint_exception b interrupt_return - GEN_KVM instruction_breakpoint - EXC_REAL_NONE(0x1400, 0x100) EXC_VIRT_NONE(0x5400, 0x100)
@@ -2590,8 +2504,6 @@ EXC_COMMON_BEGIN(denorm_exception_common) bl unknown_exception b interrupt_return - GEN_KVM denorm_exception - #ifdef CONFIG_CBE_RAS INT_DEFINE_BEGIN(cbe_maintenance)
@@ -2609,8 +2521,6 @@ EXC_COMMON_BEGIN(cbe_maintenance_common) bl cbe_maintenance_exception b interrupt_return - GEN_KVM cbe_maintenance - #else /* CONFIG_CBE_RAS */ EXC_REAL_NONE(0x1600, 0x100) EXC_VIRT_NONE(0x5600, 0x100)
@@ -2641,8 +2551,6 @@ EXC_COMMON_BEGIN(altivec_assist_common) #endif b interrupt_return - GEN_KVM altivec_assist - #ifdef CONFIG_CBE_RAS INT_DEFINE_BEGIN(cbe_thermal)
@@ -2660,8 +2568,6 @@ EXC_COMMON_BEGIN(cbe_thermal_common) bl cbe_thermal_exception b interrupt_return - GEN_KVM cbe_thermal - #else /* CONFIG_CBE_RAS */ EXC_REAL_NONE(0x1800, 0x100) EXC_VIRT_NONE(0x5800, 0x100)
@@ -2914,6 +2820,15 @@ TRAMP_REAL_BEGIN(rfscv_flush_fallback) USE_TEXT_SECTION() +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER +kvm_interrupt: + /* + * The conditional branch in KVMTEST can't reach all the way, + * make a stub. + */ + b kvmppc_interrupt +#endif + _GLOBAL(do_uaccess_flush) UACCESS_FLUSH_FIXUP_SECTION nop
arch/powerpc/kvm/book3s_64_entry.S +48 -2
63 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 6/32 KVM: PPC: Book3S 64: move bad_host_intr check to HV handler
In reply to Nicholas PigginThe bad_host_intr check will never be true with PR KVM, move it to HV code.
--- arch/powerpc/kvm/book3s_64_entry.S | 4 ---- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 +++- arch/powerpc/kvm/book3s_segment.S | 3 +++ 3 files changed, 6 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_64_entry.S +0 -4
@@ -107,16 +107,12 @@ do_kvm_interrupt: beq- .Lmaybe_skip .Lno_skip: #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE - cmpwi r9,KVM_GUEST_MODE_HOST_HV - beq kvmppc_bad_host_intr #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE cmpwi r9,KVM_GUEST_MODE_GUEST - ld r9,HSTATE_SCRATCH2(r13) beq kvmppc_interrupt_pr #endif b kvmppc_interrupt_hv #else - ld r9,HSTATE_SCRATCH2(r13) b kvmppc_interrupt_pr #endif
arch/powerpc/kvm/book3s_hv_rmhandlers.S +3 -1
@@ -1268,6 +1268,7 @@ hdec_soon: kvmppc_interrupt_hv: /* * Register contents: + * R9 = HSTATE_IN_GUEST * R12 = (guest CR << 32) | interrupt vector * R13 = PACA * guest R12 saved in shadow VCPU SCRATCH0
@@ -1275,6 +1276,8 @@ kvmppc_interrupt_hv: * guest R9 saved in HSTATE_SCRATCH2 */ /* We're now back in the host but in guest MMU context */ + cmpwi r9,KVM_GUEST_MODE_HOST_HV + beq kvmppc_bad_host_intr li r9, KVM_GUEST_MODE_HOST_HV stb r9, HSTATE_IN_GUEST(r13)
@@ -3279,7 +3282,6 @@ END_FTR_SECTION_IFCLR(CPU_FTR_P9_TM_HV_ASSIST) * cfar is saved in HSTATE_CFAR(r13) * ppr is saved in HSTATE_PPR(r13) */ -.global kvmppc_bad_host_intr kvmppc_bad_host_intr: /* * Switch to the emergency stack, but start half-way down in
arch/powerpc/kvm/book3s_segment.S +3 -0
@@ -164,12 +164,15 @@ kvmppc_interrupt_pr: /* 64-bit entry. Register usage at this point: * * SPRG_SCRATCH0 = guest R13 + * R9 = HSTATE_IN_GUEST * R12 = (guest CR << 32) | exit handler id * R13 = PACA * HSTATE.SCRATCH0 = guest R12 + * HSTATE.SCRATCH2 = guest R9 */ #ifdef CONFIG_PPC64 /* Match 32-bit entry */ + ld r9,HSTATE_SCRATCH2(r13) rotldi r12, r12, 32 /* Flip R12 halves for stw */ stw r12, HSTATE_SCRATCH1(r13) /* CR is now in the low half */ srdi r12, r12, 32 /* shift trap into low half */
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 7/32 KVM: PPC: Book3S 64: Minimise hcall handler calling convention differences
In reply to Nicholas PigginThis sets up the same calling convention from interrupt entry to KVM interrupt handler for system calls as exists for other interrupt types.
This is a better API, it uses a save area rather than SPR, and it has more registers free to use. Using a single common API helps maintain it, and it becomes easier to use in C in a later patch.
--- arch/powerpc/kernel/exceptions-64s.S | 21 +++++++++- arch/powerpc/kvm/book3s_64_entry.S | 61 ++++++++++++---------------- 2 files changed, 45 insertions(+), 37 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +20 -1
@@ -1869,8 +1869,27 @@ EXC_VIRT_END(system_call, 0x4c00, 0x100) #ifdef CONFIG_KVM_BOOK3S_64_HANDLER TRAMP_REAL_BEGIN(kvm_hcall) + std r9,PACA_EXGEN+EX_R9(r13) + std r11,PACA_EXGEN+EX_R11(r13) + std r12,PACA_EXGEN+EX_R12(r13) + mfcr r9 mfctr r10 - SET_SCRATCH0(r10) /* Save r13 in SCRATCH0 */ + std r10,PACA_EXGEN+EX_R13(r13) + li r10,0 + std r10,PACA_EXGEN+EX_CFAR(r13) + std r10,PACA_EXGEN+EX_CTR(r13) + /* + * Save the PPR (on systems that support it) before changing to + * HMT_MEDIUM. That allows the KVM code to save that value into the + * guest state (it is the guest's PPR value). + */ +BEGIN_FTR_SECTION + mfspr r10,SPRN_PPR + std r10,PACA_EXGEN+EX_PPR(r13) +END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) + + HMT_MEDIUM + #ifdef CONFIG_RELOCATABLE /* * Requires __LOAD_FAR_HANDLER beause kvmppc_hcall lives
arch/powerpc/kvm/book3s_64_entry.S +25 -36
84 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 8/32 KVM: PPC: Book3S HV P9: implement kvmppc_xive_pull_vcpu in C
In reply to Nicholas PigginThis is more symmetric with kvmppc_xive_push_vcpu, and has the advantage that it runs with the MMU on.
The extra test added to the asm will go away with a future change.
--- arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kvm/book3s_hv.c | 2 ++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 5 ++++ arch/powerpc/kvm/book3s_xive.c | 31 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+)
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -671,6 +671,7 @@ extern int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval);extern int kvmppc_xive_set_irq (struct kvm *kvm,int irq_source_id,u32 irq,int level,bool line_status);extern void kvmppc_xive_push_vcpu (struct kvm_vcpu *vcpu); +extern void kvmppc_xive_pull_vcpu (struct kvm_vcpu *vcpu);static inline int kvmppc_xive_enabled (struct kvm_vcpu *vcpu) {
@@ -711,6 +712,7 @@ static inline int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval) { returstatic inline int kvmppc_xive_set_irq (struct kvm *kvm,int irq_source_id,u32 irq,int level,bool line_status) {return -ENODEV ; }static inline void kvmppc_xive_push_vcpu (struct kvm_vcpu *vcpu) { } +static inline void kvmppc_xive_pull_vcpu (struct kvm_vcpu *vcpu) { }static inline int kvmppc_xive_enabled (struct kvm_vcpu *vcpu) {return 0 ; }
arch/powerpc/kvm/book3s_hv.c +2 -0
@@ -3570,6 +3570,8 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit, trap =__kvmhv_vcpu_entry_p9 (vcpu); +kvmppc_xive_pull_vcpu (vcpu); +/* Advance host PURR/SPURR by the amount used by guest */ purr =mfspr (SPRN_PURR ); spurr =mfspr (SPRN_SPURR );
arch/powerpc/kvm/book3s_hv_rmhandlers.S +5 -0
@@ -1445,6 +1445,11 @@ guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */ bl kvmhv_accumulate_time #endif #ifdef CONFIG_KVM_XICS + /* If we came in through the P9 short path, xive pull is done in C */ + lwz r0, STACK_SLOT_SHORT_PATH(r1) + cmpwi r0, 0 + bne 1f + /* We are exiting, pull the VP from the XIVE */ lbz r0, VCPU_XIVE_PUSHED(r9) cmpwi cr0, r0, 0
arch/powerpc/kvm/book3s_xive.c +31 -0
@@ -127,6 +127,37 @@ void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu) }EXPORT_SYMBOL_GPL (kvmppc_xive_push_vcpu); +/* +* Pull a vcpu's context from the XIVE on guest exit. +* This assumes we are in virtual mode (MMU on) +*/ +void kvmppc_xive_pull_vcpu (struct kvm_vcpu *vcpu) +{ +void __iomem *tima = local_paca->kvm_hstate.xive_tima_virt; + +if (!vcpu->arch.xive_pushed) +return ; + +/* +* Should not have been pushed if there is no tima +*/ +if (WARN_ON (!tima)) +return ; + +eieio (); +/* First load to pull the context, we ignore the value */ +__raw_readl (tima +TM_SPC_PULL_OS_CTX ); +/* Second load to recover the context state (Words 0 and 1) */ + vcpu->arch.xive_saved_state.w01 =__raw_readq (tima +TM_QW1_OS ); + +/* Fixup some of the state for the next load */ + vcpu->arch.xive_saved_state.lsmfb =0 ; + vcpu->arch.xive_saved_state.ack =0xff ; + vcpu->arch.xive_pushed =0 ; +eieio (); +} +EXPORT_SYMBOL_GPL (kvmppc_xive_pull_vcpu); +/* * This is a simple trigger for a generic XIVE IRQ. This must * only be called for interrupts that support a trigger page
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 9/32 KVM: PPC: Book3S HV P9: Move setting HDEC after switching to guest LPCR
In reply to Nicholas PigginLPCR[HDICE]=0 suppresses hypervisor decrementer exceptions on some processors, so it must be enabled before HDEC is set.
Rather than set it in the host LPCR then setting HDEC, move the HDEC update to after the guest MMU context (including LPCR) is loaded. There shouldn't be much concern with delaying HDEC by some 10s or 100s of nanoseconds by setting it a bit later.
--- arch/powerpc/kvm/book3s_hv.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
arch/powerpc/kvm/book3s_hv.c +7 -12
@@ -3502,20 +3502,9 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit, host_dawrx1 =mfspr (SPRN_DAWRX1 ); } -/* -* P8 and P9 suppress the HDEC exception when LPCR[HDICE] = 0, -* so set HDICE before writing HDEC. -*/ -mtspr (SPRN_LPCR , vcpu->kvm->arch.host_lpcr |LPCR_HDICE ); -isync (); - hdec = time_limit -mftb (); -if (hdec <0 ) { -mtspr (SPRN_LPCR , vcpu->kvm->arch.host_lpcr); -isync (); +if (hdec <0 )return BOOK3S_INTERRUPT_HV_DECREMENTER ; - } -mtspr (SPRN_HDEC , hdec);if (vc->tb_offset) {u64 new_tb =mftb () + vc->tb_offset;
@@ -3563,6 +3552,12 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,mtspr (SPRN_LPCR , lpcr);isync (); +/* +* P9 suppresses the HDEC exception when LPCR[HDICE] = 0, +* so set guest LPCR (with HDICE) before writing HDEC. +*/ +mtspr (SPRN_HDEC , hdec); +kvmppc_xive_push_vcpu (vcpu);mtspr (SPRN_SRR0 , vcpu->arch.shregs.srr0);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 10/32 KVM: PPC: Book3S HV P9: Reduce irq_work vs guest decrementer races
In reply to Nicholas Pigginirq_work's use of the DEC SPR is racy with guest<->host switch and guest entry which flips the DEC interrupt to guest, which could lose a host work interrupt.
This patch closes one race, and attempts to comment another class of races.
--- arch/powerpc/include/asm/time.h | 12 ++++++++++++ arch/powerpc/kernel/time.c | 10 ---------- arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/time.h +12 -0
@@ -97,6 +97,18 @@ extern void div128_by_32(u64 dividend_high, u64 dividend_low,extern void secondary_cpu_time_init (void );extern void __init time_init (void ); +#ifdef CONFIG_PPC64 +static inline unsigned long test_irq_work_pending (void ) +{ +unsigned long x; + + asmvolatile ("lbz %0,%1(13)" + :"=r" (x) + :"i" (offsetof(struct paca_struct , irq_work_pending))); +return x; +} +#endif +DECLARE_PER_CPU (u64, decrementers_next_tb);/* Convert timebase ticks to nanoseconds */
arch/powerpc/kernel/time.c +0 -10
@@ -508,16 +508,6 @@ EXPORT_SYMBOL(profile_pc);* 64-bit uses a byte in the PACA, 32-bit uses a per-cpu variable... */ #ifdef CONFIG_PPC64 -static inline unsigned long test_irq_work_pending (void ) -{ -unsigned long x; - - asmvolatile ("lbz %0,%1(13)" - :"=r" (x) - :"i" (offsetof(struct paca_struct , irq_work_pending))); -return x; -} -static inline void set_irq_work_pending_flag (void ) { asm volatile("stb %0,%1(13)" : :
arch/powerpc/kvm/book3s_hv.c +15 -0
@@ -3708,6 +3708,18 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,if (!(vcpu->arch.ctrl &1 ))mtspr (SPRN_CTRLT ,mfspr (SPRN_CTRLF ) & ~1 ); +/* +* When setting DEC, we must always deal with irq_work_raise via NMI vs +* setting DEC. The problem occurs right as we switch into guest mode +* if a NMI hits and sets pending work and sets DEC, then that will +* apply to the guest and not bring us back to the host. +* +* irq_work_raise could check a flag (or possibly LPCR[HDICE] for +* example) and set HDEC to 1? That wouldn't solve the nested hv +* case which needs to abort the hcall or zero the time limit. +* +* XXX: Another day's problem. +*/ mtspr (SPRN_DEC , vcpu->arch.dec_expires -mftb ());if (kvmhv_on_pseries ()) {
@@ -3822,6 +3834,9 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, vc->in_guest =0 ;mtspr (SPRN_DEC , local_paca->kvm_hstate.dec_expires -mftb ()); +/* We may have raced with new irq work */ +if (test_irq_work_pending ()) +set_dec (1 );mtspr (SPRN_SPRG_VDSO_WRITE , local_paca->sprg_vdso);kvmhv_load_host_pmu ();
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 11/32 KVM: PPC: Book3S HV P9: Move xive vcpu context management into kvmhv_p9_guest_entry
In reply to Nicholas PigginMove the xive management up so the low level register switching can be pushed further down in a later patch. XIVE MMIO CI operations can run in higher level code with machine checks, tracing, etc., available.
--- arch/powerpc/kvm/book3s_hv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_hv.c +3 -4
@@ -3558,15 +3558,11 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,*/ mtspr (SPRN_HDEC , hdec); -kvmppc_xive_push_vcpu (vcpu); -mtspr (SPRN_SRR0 , vcpu->arch.shregs.srr0);mtspr (SPRN_SRR1 , vcpu->arch.shregs.srr1); trap =__kvmhv_vcpu_entry_p9 (vcpu); -kvmppc_xive_pull_vcpu (vcpu); -/* Advance host PURR/SPURR by the amount used by guest */ purr =mfspr (SPRN_PURR ); spurr =mfspr (SPRN_SPURR );
@@ -3764,7 +3760,10 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, trap =0 ; } }else { +kvmppc_xive_push_vcpu (vcpu); trap =kvmhv_load_hv_regs_and_go (vcpu, time_limit, lpcr); +kvmppc_xive_pull_vcpu (vcpu); + } vcpu->arch.slb_max =0 ;
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 12/32 KVM: PPC: Book3S HV P9: Move radix MMU switching instructions together
In reply to Nicholas PigginSwitching the MMU from radix<->radix mode is tricky particularly as the MMU can remain enabled and requires a certain sequence of SPR updates. Move these together into their own functions.
This also includes the radix TLB check / flush because it's tied in to MMU switching due to tlbiel getting LPID from LPIDR.
--- arch/powerpc/kvm/book3s_hv.c | 62 ++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 21 deletions(-)
arch/powerpc/kvm/book3s_hv.c +41 -21
@@ -3478,12 +3478,49 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)trace_kvmppc_run_core (vc,1 ); } +static void switch_mmu_to_guest_radix (struct kvm *kvm,struct kvm_vcpu *vcpu,u64 lpcr) +{ +struct kvmppc_vcore *vc = vcpu->arch.vcore; +struct kvm_nested_guest *nested = vcpu->arch.nested; +u32 lpid; + + lpid = nested ? nested->shadow_lpid : kvm->arch.lpid; + +/* +* All the isync()s are overkill but trivially follow the ISA +* requirements. Some can likely be replaced with justification +* comment for why they are not needed. +*/ +isync (); +mtspr (SPRN_LPID , lpid); +isync (); +mtspr (SPRN_LPCR , lpcr); +isync (); +mtspr (SPRN_PID , vcpu->arch.pid); +isync (); + +/* TLBIEL must have LPIDR set, so set guest LPID before flushing. */ +kvmppc_check_need_tlb_flush (kvm, vc->pcpu, nested); +} + +static void switch_mmu_to_host_radix (struct kvm *kvm,u32 pid) +{ +isync (); +mtspr (SPRN_PID , pid); +isync (); +mtspr (SPRN_LPID , kvm->arch.host_lpid); +isync (); +mtspr (SPRN_LPCR , kvm->arch.host_lpcr); +isync (); +} +/* * Load up hypervisor-mode registers on P9. */ static int kvmhv_load_hv_regs_and_go (struct kvm_vcpu *vcpu,u64 time_limit,unsigned long lpcr) { +struct kvm *kvm = vcpu->kvm;struct kvmppc_vcore *vc = vcpu->arch.vcore;s64 hdec;u64 tb, purr, spurr;
@@ -3535,7 +3572,6 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit, }mtspr (SPRN_CIABR , vcpu->arch.ciabr);mtspr (SPRN_IC , vcpu->arch.ic); -mtspr (SPRN_PID , vcpu->arch.pid);mtspr (SPRN_PSSCR , vcpu->arch.psscr |PSSCR_EC | (local_paca->kvm_hstate.fake_suspend <<PSSCR_FAKE_SUSPEND_LG ));
@@ -3549,8 +3585,7 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,mtspr (SPRN_AMOR , ~0UL ); -mtspr (SPRN_LPCR , lpcr); -isync (); +switch_mmu_to_guest_radix (kvm, vcpu, lpcr);/* * P9 suppresses the HDEC exception when LPCR[HDICE] = 0,
@@ -3593,7 +3628,6 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,mtspr (SPRN_DAWR1 , host_dawr1);mtspr (SPRN_DAWRX1 , host_dawrx1); } -mtspr (SPRN_PID , host_pidr);/* * Since this is radix, do a eieio; tlbsync; ptesync sequence in
@@ -3608,9 +3642,6 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,if (cpu_has_feature (CPU_FTR_ARCH_31 )) asm volatile(PPC_CP_ABORT); -mtspr (SPRN_LPID , vcpu->kvm->arch.host_lpid);/* restore host LPID */ -isync (); - vc->dpdes =mfspr (SPRN_DPDES ); vc->vtb =mfspr (SPRN_VTB );mtspr (SPRN_DPDES ,0 );
@@ -3627,7 +3658,8 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit, }mtspr (SPRN_HDEC ,0x7fffffff ); -mtspr (SPRN_LPCR , vcpu->kvm->arch.host_lpcr); + +switch_mmu_to_host_radix (kvm, host_pidr);return trap; }
@@ -4181,7 +4213,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, {struct kvm_run *run = vcpu->run;int trap, r, pcpu; -int srcu_idx, lpid; +int srcu_idx;struct kvmppc_vcore *vc;struct kvm *kvm = vcpu->kvm;struct kvm_nested_guest *nested = vcpu->arch.nested;
@@ -4255,13 +4287,6 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, vc->vcore_state =VCORE_RUNNING ;trace_kvmppc_run_core (vc,0 ); -if (cpu_has_feature (CPU_FTR_HVMODE )) { - lpid = nested ? nested->shadow_lpid : kvm->arch.lpid; -mtspr (SPRN_LPID , lpid); -isync (); -kvmppc_check_need_tlb_flush (kvm, pcpu, nested); - } -guest_enter_irqoff (); srcu_idx =srcu_read_lock (&kvm->srcu);
@@ -4280,11 +4305,6 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,srcu_read_unlock (&kvm->srcu, srcu_idx); -if (cpu_has_feature (CPU_FTR_HVMODE )) { -mtspr (SPRN_LPID , kvm->arch.host_lpid); -isync (); - } -set_irq_happened (trap);kvmppc_set_host_core (pcpu);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 13/32 KVM: PPC: Book3S HV P9: Stop handling hcalls in real-mode in the P9 path
In reply to Nicholas PigginIn the interest of minimising the amount of code that is run in "real-mode", don't handle hcalls in real mode in the P9 path. This requires some new handlers for H_CEDE and xics-on-xive to be added before xive is pulled or cede logic is checked.
This introduces a change in radix guest behaviour where radix guests that execute 'sc 1' in userspace now get a privilege fault whereas previously the 'sc 1' would be reflected as a syscall interrupt to the guest kernel. That reflection is only required for hash guests that run PR KVM.
Background:
In POWER8 and earlier processors, it is very expensive to exit from the HV real mode context of a guest hypervisor interrupt, and switch to host virtual mode. On those processors, guest->HV interrupts reach the hypervisor with the MMU off because the MMU is loaded with guest context (LPCR, SDR1, SLB), and the other threads in the sub-core need to be pulled out of the guest too. Then the primary must save off guest state, invalidate SLB and ERAT, and load up host state before the MMU can be enabled to run in host virtual mode (~= regular Linux mode).
Hash guests also require a lot of hcalls to run due to the nature of the MMU architecture and paravirtualisation design. The XICS interrupt controller requires hcalls to run.
So KVM traditionally tries hard to avoid the full exit, by handling hcalls and other interrupts in real mode as much as possible.
By contrast, POWER9 has independent MMU context per-thread, and in radix mode the hypervisor is in host virtual memory mode when the HV interrupt is taken. Radix guests do not require significant hcalls to manage their translations, and xive guests don't need hcalls to handle interrupts. So it's much less important for performance to handle hcalls in real mode on POWER9.
One caveat is that the TCE hcalls are performance critical, real-mode variants introduced for POWER8 in order to achieve 10GbE performance. Real mode TCE hcalls were found to be less important on POWER9, which was able to drive 40GBe networking without them (using the virt mode hcalls) but performance is still important. These hcalls will benefit from subsequent guest entry/exit optimisation including possibly a faster "partial exit" that does not entirely switch to host context to handle the hcall.
--- arch/powerpc/include/asm/kvm_ppc.h | 6 ++ arch/powerpc/kvm/book3s.c | 6 ++ arch/powerpc/kvm/book3s_hv.c | 79 +++++++++++++++++++++---- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 5 ++ arch/powerpc/kvm/book3s_xive.c | 64 ++++++++++++++++++++ 5 files changed, 149 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +6 -0
@@ -129,6 +129,7 @@ extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);extern int kvmppc_core_prepare_to_enter (struct kvm_vcpu *vcpu);extern int kvmppc_core_pending_dec (struct kvm_vcpu *vcpu);extern void kvmppc_core_queue_machine_check (struct kvm_vcpu *vcpu,ulong flags); +extern void kvmppc_core_queue_syscall (struct kvm_vcpu *vcpu);extern void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags);extern void kvmppc_core_queue_fpunavail (struct kvm_vcpu *vcpu);extern void kvmppc_core_queue_vec_unavail (struct kvm_vcpu *vcpu);
@@ -606,6 +607,7 @@ extern void kvmppc_free_pimap(struct kvm *kvm);extern int kvmppc_xics_rm_complete (struct kvm_vcpu *vcpu,u32 hcall);extern void kvmppc_xics_free_icp (struct kvm_vcpu *vcpu);extern int kvmppc_xics_hcall (struct kvm_vcpu *vcpu,u32 cmd); +extern int kvmppc_xive_xics_hcall (struct kvm_vcpu *vcpu,u32 req);extern u64 kvmppc_xics_get_icp (struct kvm_vcpu *vcpu);extern int kvmppc_xics_set_icp (struct kvm_vcpu *vcpu,u64 icpval); extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev,
@@ -638,6 +640,8 @@ static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)static inline void kvmppc_xics_free_icp (struct kvm_vcpu *vcpu) { }static inline int kvmppc_xics_hcall (struct kvm_vcpu *vcpu,u32 cmd) {return 0 ; } +static inline int kvmppc_xive_xics_hcall (struct kvm_vcpu *vcpu,u32 req) + {return 0 ; }#endif #ifdef CONFIG_KVM_XIVE
@@ -672,6 +676,7 @@ extern int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, bool line_status);extern void kvmppc_xive_push_vcpu (struct kvm_vcpu *vcpu);extern void kvmppc_xive_pull_vcpu (struct kvm_vcpu *vcpu); +extern void kvmppc_xive_rearm_escalation (struct kvm_vcpu *vcpu);static inline int kvmppc_xive_enabled (struct kvm_vcpu *vcpu) {
@@ -713,6 +718,7 @@ static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 ir int level, bool line_status) { return -ENODEV; }static inline void kvmppc_xive_push_vcpu (struct kvm_vcpu *vcpu) { }static inline void kvmppc_xive_pull_vcpu (struct kvm_vcpu *vcpu) { } +static inline void kvmppc_xive_rearm_escalation (struct kvm_vcpu *vcpu) { }static inline int kvmppc_xive_enabled (struct kvm_vcpu *vcpu) {return 0 ; }
arch/powerpc/kvm/book3s.c +6 -0
@@ -171,6 +171,12 @@ void kvmppc_core_queue_machine_check(struct kvm_vcpu *vcpu, ulong flags) }EXPORT_SYMBOL_GPL (kvmppc_core_queue_machine_check); +void kvmppc_core_queue_syscall (struct kvm_vcpu *vcpu) +{ +kvmppc_inject_interrupt (vcpu,BOOK3S_INTERRUPT_SYSCALL ,0 ); +} +EXPORT_SYMBOL (kvmppc_core_queue_syscall); +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) {/* might as well deliver this straight away */
arch/powerpc/kvm/book3s_hv.c +68 -11
128 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +5 -0
@@ -1400,9 +1400,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) mr r4,r9 bge fast_guest_return 2: + /* If we came in through the P9 short path, no real mode hcalls */ + lwz r0, STACK_SLOT_SHORT_PATH(r1) + cmpwi r0, 0 + bne no_try_real /* See if this is an hcall we can handle in real mode */ cmpwi r12,BOOK3S_INTERRUPT_SYSCALL beq hcall_try_real_mode +no_try_real: /* Hypervisor doorbell - exit only if host IPI flag set */ cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL
arch/powerpc/kvm/book3s_xive.c +64 -0
76 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 14/32 KVM: PPC: Book3S HV P9: Implement the rest of the P9 path in C
In reply to Nicholas PigginAlmost all logic is moved to C, by introducing a new in_guest mode for the P9 path that branches very early in the KVM interrupt handler to P9 exit code.
The main P9 entry and exit assembly is now only about 160 lines of low level stack setup and register save/restore, plus a bad-interrupt handler.
There are two motivations for this, the first is just make the code more maintainable being in C. The second is to reduce the amount of code running in a special KVM mode, "realmode". In quotes because with radix it is no longer necessarily real-mode in the MMU, but it still has to be treated specially because it may be in real-mode, and has various important registers like PID, DEC, TB, etc set to guest. This is hostile to the rest of Linux and can't use arbitrary kernel functionality or be instrumented well.
This initial patch is a reasonably faithful conversion of the asm code, but it does lack any loop to return quickly back into the guest without switching out of realmode in the case of unimportant or easily handled interrupts. As explained in previous changes, handling HV interrupts very quickly in this low level realmode is not so important for P9 performance, and are important to avoid for security, observability, debugability reasons.
--- arch/powerpc/include/asm/asm-prototypes.h | 3 +- arch/powerpc/include/asm/kvm_asm.h | 1 + arch/powerpc/include/asm/kvm_book3s_64.h | 8 + arch/powerpc/include/asm/kvm_host.h | 7 +- arch/powerpc/kernel/security.c | 5 +- arch/powerpc/kvm/Makefile | 1 + arch/powerpc/kvm/book3s_64_entry.S | 254 ++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv.c | 9 +- arch/powerpc/kvm/book3s_hv_p9_entry.c | 207 ++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 125 +---------- 10 files changed, 496 insertions(+), 124 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_hv_p9_entry.c
arch/powerpc/include/asm/asm-prototypes.h +2 -1
@@ -120,6 +120,7 @@ extern s32 patch__call_flush_branch_caches3;extern s32 patch__flush_count_cache_return;extern s32 patch__flush_link_stack_return;extern s32 patch__call_kvm_flush_link_stack; +extern s32 patch__call_kvm_flush_link_stack_p9;extern s32 patch__memset_nocache, patch__memcpy_nocache;extern long flush_branch_caches;
@@ -140,7 +141,7 @@ void kvmhv_load_host_pmu(void);void kvmhv_save_guest_pmu (struct kvm_vcpu *vcpu,bool pmu_in_use);void kvmhv_load_guest_pmu (struct kvm_vcpu *vcpu); -int __kvmhv_vcpu_entry_p9 (struct kvm_vcpu *vcpu); +void kvmppc_p9_enter_guest (struct kvm_vcpu *vcpu);long kvmppc_h_set_dabr (struct kvm_vcpu *vcpu,unsigned long dabr); long kvmppc_h_set_xdabr(struct kvm_vcpu *vcpu, unsigned long dabr,
arch/powerpc/include/asm/kvm_asm.h +1 -0
@@ -147,6 +147,7 @@#define KVM_GUEST_MODE_SKIP 2#define KVM_GUEST_MODE_GUEST_HV 3#define KVM_GUEST_MODE_HOST_HV 4 +#define KVM_GUEST_MODE_HV_FAST 5/* ISA >= v3.0 host+guest radix, indep thr */ #define KVM_INST_FETCH_FAILED -1
arch/powerpc/include/asm/kvm_book3s_64.h +8 -0
@@ -153,9 +153,17 @@ static inline bool kvmhv_vcpu_is_radix(struct kvm_vcpu *vcpu) return radix; } +int __kvmhv_vcpu_entry_p9 (struct kvm_vcpu *vcpu); +#define KVM_DEFAULT_HPT_ORDER 24/* 16MB HPT by default */ #endif +/* +* Invalid HDSISR value which is used to indicate when HW has not set the reg. +* Used to work around an errata. +*/ +#define HDSISR_CANARY 0x7fff +/* * We use a lock bit in HPTE dword 0 to synchronize updates and * accesses to each HPTE, and another bit to indicate non-present
arch/powerpc/include/asm/kvm_host.h +6 -1
@@ -683,7 +683,12 @@ struct kvm_vcpu_arch {ulong fault_dar;u32 fault_dsisr;unsigned long intr_msr; -ulong fault_gpa;/* guest real address of page fault (POWER9) */ +/* +* POWER9 and later: fault_gpa contains the guest real address of page +* fault for a radix guest, or segment descriptor (equivalent to result +* from slbmfev of SLB entry that translated the EA) for hash guests. +*/ +ulong fault_gpa;#endif #ifdef CONFIG_BOOKE
arch/powerpc/kernel/security.c +4 -1
@@ -432,16 +432,19 @@ device_initcall(stf_barrier_debugfs_init);static void update_branch_cache_flush (void ) { -u32 *site; +u32 *site,__maybe_unused *site2;#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE site = &patch__call_kvm_flush_link_stack; + site2 = &patch__call_kvm_flush_link_stack_p9;// This controls the branch from guest_exit_cont to kvm_flush_link_stack if (link_stack_flush_type =BRANCH_CACHE_FLUSH_NONE ) {patch_instruction_site (site,ppc_inst (PPC_INST_NOP )); +patch_instruction_site (site2,ppc_inst (PPC_INST_NOP )); }else {// Could use HW flush, but that could also flush count cache patch_branch_site (site, (u64)&kvm_flush_link_stack,BRANCH_SET_LINK ); +patch_branch_site (site2, (u64)&kvm_flush_link_stack,BRANCH_SET_LINK ); }#endif
arch/powerpc/kvm/Makefile +1 -0
@@ -89,6 +89,7 @@ kvm-book3s_64-builtin-tm-objs-$(CONFIG_PPC_TRANSACTIONAL_MEM) += \ ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_hv_hmi.o \ + book3s_hv_p9_entry.o \ book3s_hv_rmhandlers.o \ book3s_hv_rm_mmu.o \ book3s_hv_ras.o \
arch/powerpc/kvm/book3s_64_entry.S +254 -0
280 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c +6 -3
@@ -1445,6 +1445,8 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,*/ case BOOK3S_INTERRUPT_H_DATA_STORAGE : r =RESUME_PAGE_FAULT ; +if (vcpu->arch.fault_dsisr =HDSISR_CANARY ) + r =RESUME_GUEST ;/* Just retry if it's the canary */ break ;case BOOK3S_INTERRUPT_H_INST_STORAGE : vcpu->arch.fault_dar =kvmppc_get_pc (vcpu);
@@ -3708,6 +3710,8 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,u64 tb;int trap, save_pmu; +WARN_ON_ONCE (vcpu->arch.ceded); + dec =mfspr (SPRN_DEC ); tb =mftb ();if (dec <0 )
@@ -3716,8 +3720,6 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,if (local_paca->kvm_hstate.dec_expires < time_limit) time_limit = local_paca->kvm_hstate.dec_expires; - vcpu->arch.ceded =0 ; -kvmhv_save_host_pmu ();/* saves it to PACA kvm_hstate */ kvmppc_subcore_enter_guest ();
@@ -3844,9 +3846,10 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, } }kvmppc_xive_pull_vcpu (vcpu); + + vcpu->arch.slb_max =0 ; } - vcpu->arch.slb_max =0 ; dec =mfspr (SPRN_DEC );if (!(lpcr &LPCR_LD ))/* Sign extend if not using large decrementer */ dec = (s32 ) dec;
arch/powerpc/kvm/book3s_hv_p9_entry.c new file +207 -0
207 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +7 -118
193 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 15/32 KVM: PPC: Book3S HV P9: inline kvmhv_load_hv_regs_and_go into __kvmhv_vcpu_entry_p9
In reply to Nicholas PigginNow the initial C implementation is done, inline more HV code to make rearranging things easier.
And rename __kvmhv_vcpu_entry_p9 to drop the leading underscores as it's now C, and is now a more complete vcpu entry.
--- arch/powerpc/include/asm/kvm_book3s_64.h | 2 +- arch/powerpc/kvm/book3s_hv.c | 190 +---------------------- arch/powerpc/kvm/book3s_hv_p9_entry.c | 177 ++++++++++++++++++++- 3 files changed, 178 insertions(+), 191 deletions(-)
arch/powerpc/include/asm/kvm_book3s_64.h +1 -1
@@ -153,7 +153,7 @@ static inline bool kvmhv_vcpu_is_radix(struct kvm_vcpu *vcpu) return radix; } -int __kvmhv_vcpu_entry_p9 (struct kvm_vcpu *vcpu); +int kvmhv_vcpu_entry_p9 (struct kvm_vcpu *vcpu,u64 time_limit,unsigned long lpcr);#define KVM_DEFAULT_HPT_ORDER 24/* 16MB HPT by default */ #endif
arch/powerpc/kvm/book3s_hv.c +2 -188
208 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_p9_entry.c +175 -2
192 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 16/32 KVM: PPC: Book3S HV P9: Read machine check registers while MSR[RI] is 0
In reply to Nicholas PigginSRR0/1, DAR, DSISR must all be protected from machine check which can clobber them. Ensure MSR[RI] is clear while they are live.
--- arch/powerpc/kvm/book3s_hv.c | 11 +++++++-- arch/powerpc/kvm/book3s_hv_p9_entry.c | 33 ++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_hv.c +9 -2
@@ -3571,11 +3571,16 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,mtspr (SPRN_BESCR , vcpu->arch.bescr);mtspr (SPRN_WORT , vcpu->arch.wort);mtspr (SPRN_TIDR , vcpu->arch.tid); -mtspr (SPRN_DAR , vcpu->arch.shregs.dar); -mtspr (SPRN_DSISR , vcpu->arch.shregs.dsisr);mtspr (SPRN_AMR , vcpu->arch.amr);mtspr (SPRN_UAMOR , vcpu->arch.uamor); +/* +* DAR, DSISR, and for nested HV, SPRGs must be set with MSR[RI] +* clear (or hstate set appropriately to catch those registers +* being clobbered if we take a MCE or SRESET), so those are done +* later. +*/ +if (!(vcpu->arch.ctrl &1 ))mtspr (SPRN_CTRLT ,mfspr (SPRN_CTRLF ) & ~1 );
@@ -3618,6 +3623,8 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, hvregs.vcpu_token = vcpu->vcpu_id; } hvregs.hdec_expiry = time_limit; +mtspr (SPRN_DAR , vcpu->arch.shregs.dar); +mtspr (SPRN_DSISR , vcpu->arch.shregs.dsisr); trap =plpar_hcall_norets (H_ENTER_NESTED ,__pa (&hvregs),__pa (&vcpu->arch.regs));kvmhv_restore_hv_return_state (vcpu, &hvregs);
arch/powerpc/kvm/book3s_hv_p9_entry.c +30 -3
@@ -122,6 +122,7 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcs64 hdec;u64 tb, purr, spurr;u64 *exsave; +bool ri_set;unsigned long msr =mfmsr ();int trap;unsigned long host_hfscr =mfspr (SPRN_HFSCR );
@@ -192,9 +193,6 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc*/ mtspr (SPRN_HDEC , hdec); -mtspr (SPRN_SRR0 , vcpu->arch.shregs.srr0); -mtspr (SPRN_SRR1 , vcpu->arch.shregs.srr1); -start_timing (vcpu, &vcpu->arch.rm_entry); vcpu->arch.ceded =0 ;
@@ -220,6 +218,13 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc*/ mtspr (SPRN_HDSISR ,HDSISR_CANARY ); +__mtmsrd (0 ,1 );/* clear RI */ + +mtspr (SPRN_DAR , vcpu->arch.shregs.dar); +mtspr (SPRN_DSISR , vcpu->arch.shregs.dsisr); +mtspr (SPRN_SRR0 , vcpu->arch.shregs.srr0); +mtspr (SPRN_SRR1 , vcpu->arch.shregs.srr1); +accumulate_time (vcpu, &vcpu->arch.guest_time); local_paca->kvm_hstate.in_guest =KVM_GUEST_MODE_HV_FAST ;
@@ -237,7 +242,13 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc/* 0x2 bit for HSRR is only used by PR and P7/8 HV paths, clear it */ trap = local_paca->kvm_hstate.scratch0 & ~0x2 ; + +/* HSRR interrupts leave MSR[RI] unchanged, SRR interrupts clear it. */ + ri_set = false;if (likely (trap >BOOK3S_INTERRUPT_MACHINE_CHECK )) { +if (trap !=BOOK3S_INTERRUPT_SYSCALL && + (vcpu->arch.shregs.msr &MSR_RI )) + ri_set = true; exsave = local_paca->exgen; }else if (trap =BOOK3S_INTERRUPT_SYSTEM_RESET ) { exsave = local_paca->exnmi;
@@ -247,6 +258,22 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc vcpu->arch.regs.gpr[1 ] = local_paca->kvm_hstate.scratch1; vcpu->arch.regs.gpr[3 ] = local_paca->kvm_hstate.scratch2; + +/* +* Only set RI after reading machine check regs (DAR, DSISR, SRR0/1) +* and hstate scratch (which we need to move into exsave to make +* re-entrant vs SRESET/MCE) +*/ +if (ri_set) { +if (unlikely (!(mfmsr () &MSR_RI ))) { +__mtmsrd (MSR_RI ,1 ); +WARN_ON_ONCE (1 ); + } + }else { +WARN_ON_ONCE (mfmsr () &MSR_RI ); +__mtmsrd (MSR_RI ,1 ); + } + vcpu->arch.regs.gpr[9 ] = exsave[EX_R9 /sizeof (u64)]; vcpu->arch.regs.gpr[10 ] = exsave[EX_R10 /sizeof (u64)]; vcpu->arch.regs.gpr[11 ] = exsave[EX_R11 /sizeof (u64)];
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 17/32 KVM: PPC: Book3S HV P9: Improve exit timing accounting coverage
In reply to Nicholas PigginThe C conversion caused exit timing to become a bit cramped. Expand it to cover more of the entry and exit code.
--- arch/powerpc/kvm/book3s_hv_p9_entry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_hv_p9_entry.c +4 -4
@@ -143,6 +143,8 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcif (hdec <0 )return BOOK3S_INTERRUPT_HV_DECREMENTER ; +start_timing (vcpu, &vcpu->arch.rm_entry); +if (vc->tb_offset) {u64 new_tb =mftb () + vc->tb_offset;mtspr (SPRN_TBU40 , new_tb);
@@ -193,8 +195,6 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc*/ mtspr (SPRN_HDEC , hdec); -start_timing (vcpu, &vcpu->arch.rm_entry); - vcpu->arch.ceded =0 ;WARN_ON_ONCE (vcpu->arch.shregs.msr &MSR_HV );
@@ -337,8 +337,6 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcaccumulate_time (vcpu, &vcpu->arch.rm_exit); -end_timing (vcpu); -/* Advance host PURR/SPURR by the amount used by guest */ purr =mfspr (SPRN_PURR ); spurr =mfspr (SPRN_SPURR );
@@ -402,6 +400,8 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcswitch_mmu_to_host_radix (kvm, host_pidr); +end_timing (vcpu); +return trap; }EXPORT_SYMBOL_GPL (kvmhv_vcpu_entry_p9);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 18/32 KVM: PPC: Book3S HV P9: Move SPR loading after expiry time check
In reply to Nicholas PigginThis is wasted work if the time limit is exceeded.
--- arch/powerpc/kvm/book3s_hv_p9_entry.c | 36 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-)
arch/powerpc/kvm/book3s_hv_p9_entry.c +22 -14
@@ -123,21 +123,16 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcu64 tb, purr, spurr;u64 *exsave;bool ri_set; -unsigned long msr =mfmsr ();int trap; -unsigned long host_hfscr =mfspr (SPRN_HFSCR ); -unsigned long host_ciabr =mfspr (SPRN_CIABR ); -unsigned long host_dawr0 =mfspr (SPRN_DAWR0 ); -unsigned long host_dawrx0 =mfspr (SPRN_DAWRX0 ); -unsigned long host_psscr =mfspr (SPRN_PSSCR ); -unsigned long host_pidr =mfspr (SPRN_PID ); -unsigned long host_dawr1 =0 ; -unsigned long host_dawrx1 =0 ; - -if (cpu_has_feature (CPU_FTR_DAWR1 )) { - host_dawr1 =mfspr (SPRN_DAWR1 ); - host_dawrx1 =mfspr (SPRN_DAWRX1 ); - } +unsigned long msr; +unsigned long host_hfscr; +unsigned long host_ciabr; +unsigned long host_dawr0; +unsigned long host_dawrx0; +unsigned long host_psscr; +unsigned long host_pidr; +unsigned long host_dawr1; +unsigned long host_dawrx1; hdec = time_limit -mftb ();if (hdec <0 )
@@ -154,6 +149,19 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc vc->tb_offset_applied = vc->tb_offset; } + msr =mfmsr (); + + host_hfscr =mfspr (SPRN_HFSCR ); + host_ciabr =mfspr (SPRN_CIABR ); + host_dawr0 =mfspr (SPRN_DAWR0 ); + host_dawrx0 =mfspr (SPRN_DAWRX0 ); + host_psscr =mfspr (SPRN_PSSCR ); + host_pidr =mfspr (SPRN_PID ); +if (cpu_has_feature (CPU_FTR_DAWR1 )) { + host_dawr1 =mfspr (SPRN_DAWR1 ); + host_dawrx1 =mfspr (SPRN_DAWRX1 ); + } +if (vc->pcr)mtspr (SPRN_PCR , vc->pcr |PCR_MASK );mtspr (SPRN_DPDES , vc->dpdes);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 19/32 KVM: PPC: Book3S HV P9: Add helpers for OS SPR handling
In reply to Nicholas PigginThis is a first step to wrapping supervisor and user SPR saving and loading up into helpers, which will then be called independently in bare metal and nested HV cases in order to optimise SPR access.
--- arch/powerpc/kvm/book3s_hv.c | 148 ++++++++++++++++++++++------------- 1 file changed, 93 insertions(+), 55 deletions(-)
arch/powerpc/kvm/book3s_hv.c +93 -55
@@ -3501,6 +3501,93 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)trace_kvmppc_run_core (vc,1 ); } +static void load_spr_state (struct kvm_vcpu *vcpu) +{ +mtspr (SPRN_DSCR , vcpu->arch.dscr); +mtspr (SPRN_IAMR , vcpu->arch.iamr); +mtspr (SPRN_PSPB , vcpu->arch.pspb); +mtspr (SPRN_FSCR , vcpu->arch.fscr); +mtspr (SPRN_TAR , vcpu->arch.tar); +mtspr (SPRN_EBBHR , vcpu->arch.ebbhr); +mtspr (SPRN_EBBRR , vcpu->arch.ebbrr); +mtspr (SPRN_BESCR , vcpu->arch.bescr); +mtspr (SPRN_WORT , vcpu->arch.wort); +mtspr (SPRN_TIDR , vcpu->arch.tid); +mtspr (SPRN_AMR , vcpu->arch.amr); +mtspr (SPRN_UAMOR , vcpu->arch.uamor); + +/* +* DAR, DSISR, and for nested HV, SPRGs must be set with MSR[RI] +* clear (or hstate set appropriately to catch those registers +* being clobbered if we take a MCE or SRESET), so those are done +* later. +*/ + +if (!(vcpu->arch.ctrl &1 )) +mtspr (SPRN_CTRLT ,mfspr (SPRN_CTRLF ) & ~1 ); +} + +static void store_spr_state (struct kvm_vcpu *vcpu) +{ + vcpu->arch.ctrl =mfspr (SPRN_CTRLF ); + + vcpu->arch.iamr =mfspr (SPRN_IAMR ); + vcpu->arch.pspb =mfspr (SPRN_PSPB ); + vcpu->arch.fscr =mfspr (SPRN_FSCR ); + vcpu->arch.tar =mfspr (SPRN_TAR ); + vcpu->arch.ebbhr =mfspr (SPRN_EBBHR ); + vcpu->arch.ebbrr =mfspr (SPRN_EBBRR ); + vcpu->arch.bescr =mfspr (SPRN_BESCR ); + vcpu->arch.wort =mfspr (SPRN_WORT ); + vcpu->arch.tid =mfspr (SPRN_TIDR ); + vcpu->arch.amr =mfspr (SPRN_AMR ); + vcpu->arch.uamor =mfspr (SPRN_UAMOR ); + vcpu->arch.dscr =mfspr (SPRN_DSCR ); +} + +/* +* Privileged (non-hypervisor) host registers to save. +*/ +struct p9_host_os_sprs { +unsigned long dscr; +unsigned long tidr; +unsigned long iamr; +unsigned long amr; +unsigned long fscr; +}; + +static void save_p9_host_os_sprs (struct p9_host_os_sprs *host_os_sprs) +{ + host_os_sprs->dscr =mfspr (SPRN_DSCR ); + host_os_sprs->tidr =mfspr (SPRN_TIDR ); + host_os_sprs->iamr =mfspr (SPRN_IAMR ); + host_os_sprs->amr =mfspr (SPRN_AMR ); + host_os_sprs->fscr =mfspr (SPRN_FSCR ); +} + +/* vcpu guest regs must already be saved */ +static void restore_p9_host_os_sprs (struct kvm_vcpu *vcpu, +struct p9_host_os_sprs *host_os_sprs) +{ +mtspr (SPRN_PSPB ,0 ); +mtspr (SPRN_WORT ,0 ); +mtspr (SPRN_UAMOR ,0 ); + +mtspr (SPRN_DSCR , host_os_sprs->dscr); +mtspr (SPRN_TIDR , host_os_sprs->tidr); +mtspr (SPRN_IAMR , host_os_sprs->iamr); + +if (host_os_sprs->amr != vcpu->arch.amr) +mtspr (SPRN_AMR , host_os_sprs->amr); + +if (host_os_sprs->fscr != vcpu->arch.fscr) +mtspr (SPRN_FSCR , host_os_sprs->fscr); + +/* Save guest CTRL register, set runlatch to 1 */ +if (!(vcpu->arch.ctrl &1 )) +mtspr (SPRN_CTRLT ,1 ); +} +static inline bool hcall_is_xics (unsigned long req) { return req = H_EOI || req = H_CPPR || req = H_IPI ||
@@ -3515,11 +3602,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcr) {struct kvmppc_vcore *vc = vcpu->arch.vcore; -unsigned long host_dscr =mfspr (SPRN_DSCR ); -unsigned long host_tidr =mfspr (SPRN_TIDR ); -unsigned long host_iamr =mfspr (SPRN_IAMR ); -unsigned long host_amr =mfspr (SPRN_AMR ); -unsigned long host_fscr =mfspr (SPRN_FSCR ); +struct p9_host_os_sprs host_os_sprs;s64 dec;u64 tb;int trap, save_pmu;
@@ -3534,6 +3617,8 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,if (local_paca->kvm_hstate.dec_expires < time_limit) time_limit = local_paca->kvm_hstate.dec_expires; +save_p9_host_os_sprs (&host_os_sprs); +kvmhv_save_host_pmu ();/* saves it to PACA kvm_hstate */ kvmppc_subcore_enter_guest ();
@@ -3561,28 +3646,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,#endif mtspr (SPRN_VRSAVE , vcpu->arch.vrsave); -mtspr (SPRN_DSCR , vcpu->arch.dscr); -mtspr (SPRN_IAMR , vcpu->arch.iamr); -mtspr (SPRN_PSPB , vcpu->arch.pspb); -mtspr (SPRN_FSCR , vcpu->arch.fscr); -mtspr (SPRN_TAR , vcpu->arch.tar); -mtspr (SPRN_EBBHR , vcpu->arch.ebbhr); -mtspr (SPRN_EBBRR , vcpu->arch.ebbrr); -mtspr (SPRN_BESCR , vcpu->arch.bescr); -mtspr (SPRN_WORT , vcpu->arch.wort); -mtspr (SPRN_TIDR , vcpu->arch.tid); -mtspr (SPRN_AMR , vcpu->arch.amr); -mtspr (SPRN_UAMOR , vcpu->arch.uamor); - -/* -* DAR, DSISR, and for nested HV, SPRGs must be set with MSR[RI] -* clear (or hstate set appropriately to catch those registers -* being clobbered if we take a MCE or SRESET), so those are done -* later. -*/ - -if (!(vcpu->arch.ctrl &1 )) -mtspr (SPRN_CTRLT ,mfspr (SPRN_CTRLF ) & ~1 ); +load_spr_state (vcpu);/* * When setting DEC, we must always deal with irq_work_raise via NMI vs
@@ -3678,36 +3742,10 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, vcpu->arch.dec_expires = dec + tb; vcpu->cpu =-1 ; vcpu->arch.thread_cpu =-1 ; -/* Save guest CTRL register, set runlatch to 1 */ - vcpu->arch.ctrl =mfspr (SPRN_CTRLF ); -if (!(vcpu->arch.ctrl &1 )) -mtspr (SPRN_CTRLT , vcpu->arch.ctrl |1 ); - - vcpu->arch.iamr =mfspr (SPRN_IAMR ); - vcpu->arch.pspb =mfspr (SPRN_PSPB ); - vcpu->arch.fscr =mfspr (SPRN_FSCR ); - vcpu->arch.tar =mfspr (SPRN_TAR ); - vcpu->arch.ebbhr =mfspr (SPRN_EBBHR ); - vcpu->arch.ebbrr =mfspr (SPRN_EBBRR ); - vcpu->arch.bescr =mfspr (SPRN_BESCR ); - vcpu->arch.wort =mfspr (SPRN_WORT ); - vcpu->arch.tid =mfspr (SPRN_TIDR ); - vcpu->arch.amr =mfspr (SPRN_AMR ); - vcpu->arch.uamor =mfspr (SPRN_UAMOR ); - vcpu->arch.dscr =mfspr (SPRN_DSCR ); - -mtspr (SPRN_PSPB ,0 ); -mtspr (SPRN_WORT ,0 ); -mtspr (SPRN_UAMOR ,0 ); -mtspr (SPRN_DSCR , host_dscr); -mtspr (SPRN_TIDR , host_tidr); -mtspr (SPRN_IAMR , host_iamr); -if (host_amr != vcpu->arch.amr) -mtspr (SPRN_AMR , host_amr); +store_spr_state (vcpu); -if (host_fscr != vcpu->arch.fscr) -mtspr (SPRN_FSCR , host_fscr); +restore_p9_host_os_sprs (vcpu, &host_os_sprs);msr_check_and_set (MSR_FP |MSR_VEC |MSR_VSX );store_fp_state (&vcpu->arch.fp);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 20/32 KVM: PPC: Book3S HV P9: Switch to guest MMU context as late as possible
In reply to Nicholas PigginMove MMU context switch as late as reasonably possible to minimise code running with guest context switched in. This becomes more important when this code may run in real-mode, with later changes.
Move WARN_ON as early as possible so program check interrupts are less likely to tangle everything up.
--- arch/powerpc/kvm/book3s_hv_p9_entry.c | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-)
arch/powerpc/kvm/book3s_hv_p9_entry.c +20 -20
@@ -138,8 +138,13 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcif (hdec <0 )return BOOK3S_INTERRUPT_HV_DECREMENTER ; +WARN_ON_ONCE (vcpu->arch.shregs.msr &MSR_HV ); +WARN_ON_ONCE (!(vcpu->arch.shregs.msr &MSR_ME )); +start_timing (vcpu, &vcpu->arch.rm_entry); + vcpu->arch.ceded =0 ; +if (vc->tb_offset) {u64 new_tb =mftb () + vc->tb_offset;mtspr (SPRN_TBU40 , new_tb);
@@ -188,26 +193,6 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcmtspr (SPRN_HFSCR , vcpu->arch.hfscr); -mtspr (SPRN_SPRG0 , vcpu->arch.shregs.sprg0); -mtspr (SPRN_SPRG1 , vcpu->arch.shregs.sprg1); -mtspr (SPRN_SPRG2 , vcpu->arch.shregs.sprg2); -mtspr (SPRN_SPRG3 , vcpu->arch.shregs.sprg3); - -mtspr (SPRN_AMOR , ~0UL ); - -switch_mmu_to_guest_radix (kvm, vcpu, lpcr); - -/* -* P9 suppresses the HDEC exception when LPCR[HDICE] = 0, -* so set guest LPCR (with HDICE) before writing HDEC. -*/ -mtspr (SPRN_HDEC , hdec); - - vcpu->arch.ceded =0 ; - -WARN_ON_ONCE (vcpu->arch.shregs.msr &MSR_HV ); -WARN_ON_ONCE (!(vcpu->arch.shregs.msr &MSR_ME )); -mtspr (SPRN_HSRR0 , vcpu->arch.regs.nip);mtspr (SPRN_HSRR1 , (vcpu->arch.shregs.msr & ~MSR_HV ) |MSR_ME );
@@ -226,6 +211,21 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc*/ mtspr (SPRN_HDSISR ,HDSISR_CANARY ); +mtspr (SPRN_SPRG0 , vcpu->arch.shregs.sprg0); +mtspr (SPRN_SPRG1 , vcpu->arch.shregs.sprg1); +mtspr (SPRN_SPRG2 , vcpu->arch.shregs.sprg2); +mtspr (SPRN_SPRG3 , vcpu->arch.shregs.sprg3); + +mtspr (SPRN_AMOR , ~0UL ); + +switch_mmu_to_guest_radix (kvm, vcpu, lpcr); + +/* +* P9 suppresses the HDEC exception when LPCR[HDICE] = 0, +* so set guest LPCR (with HDICE) before writing HDEC. +*/ +mtspr (SPRN_HDEC , hdec); +__mtmsrd (0 ,1 );/* clear RI */ mtspr (SPRN_DAR , vcpu->arch.shregs.dar);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 21/32 KVM: PPC: Book3S HV: Implement radix prefetch workaround by disabling MMU
In reply to Nicholas PigginRather than partition the guest PID space + flush a rogue guest PID to work around this problem, instead fix it by always disabling the MMU when switching in or out of guest MMU context in HV mode.
This may be a bit less efficient, but it is a lot less complicated and allows the P9 path to trivally implement the workaround too. Newer CPUs are not subject to this issue.
--- arch/powerpc/include/asm/mmu_context.h | 6 ---- arch/powerpc/kvm/book3s_hv.c | 21 +++++++---- arch/powerpc/kvm/book3s_hv_p9_entry.c | 14 ++++++-- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 34 ------------------ arch/powerpc/mm/book3s64/radix_pgtable.c | 27 +++++--------- arch/powerpc/mm/book3s64/radix_tlb.c | 46 ------------------------ arch/powerpc/mm/mmu_context.c | 4 +-- 7 files changed, 34 insertions(+), 118 deletions(-)
arch/powerpc/include/asm/mmu_context.h +0 -6
@@ -122,12 +122,6 @@ static inline bool need_extra_context(struct mm_struct *mm, unsigned long ea) }#endif -#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE ) && defined(CONFIG_PPC_RADIX_MMU ) -extern void radix_kvm_prefetch_workaround (struct mm_struct *mm); -#else -static inline void radix_kvm_prefetch_workaround (struct mm_struct *mm) { } -#endif -extern void switch_cop (struct mm_struct *next);extern int use_cop (unsigned long acop,struct mm_struct *mm);extern void drop_cop (unsigned long acop,struct mm_struct *mm);
arch/powerpc/kvm/book3s_hv.c +14 -7
@@ -807,7 +807,8 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags,* KVM does not support mflags=2 (AIL=2) and AIL=1 is reserved. * Keep this in synch with kvmppc_filter_guest_lpcr_hv. */ -if (mflags !=0 && mflags !=3 ) +if (cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG ) && +kvmhv_vcpu_is_radix (vcpu) && mflags =3 )return H_UNSUPPORTED_FLAG_START ;return H_TOO_HARD ;default :
@@ -1677,6 +1678,14 @@ unsigned long kvmppc_filter_lpcr_hv(struct kvm *kvm, unsigned long lpcr) lpcr &= ~LPCR_AIL ;if ((lpcr &LPCR_AIL ) !=LPCR_AIL_3 ) lpcr &= ~LPCR_AIL ;/* LPCR[AIL]=1/2 is disallowed */ +/* +* On some POWER9s we force AIL off for radix guests to prevent +* executing in MSR[HV]=1 mode with the MMU enabled and PIDR set to +* guest, which can result in Q0 translations with LPID=0 PID=PIDR to +* be cached, which the host TLB management does not expect. +*/ +if (kvm_is_radix (kvm) &&cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) + lpcr &= ~LPCR_AIL ;/* * On POWER9, allow userspace to enable large decrementer for the
@@ -4360,12 +4369,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu) vcpu->arch.state =KVMPPC_VCPU_BUSY_IN_HOST ; do { - /* - * The TLB prefetch bug fixup is only in the kvmppc_run_vcpu - * path, which also handles hash and dependent threads mode. - */ - if (kvm->arch.threads_indep && kvm_is_radix(kvm) && - !cpu_has_feature(CPU_FTR_P9_RADIX_PREFETCH_BUG)) + if (kvm->arch.threads_indep && kvm_is_radix(kvm)) r = kvmhv_run_single_vcpu(vcpu, ~(u64)0, vcpu->arch.vcore->lpcr); else
@@ -4995,6 +4999,9 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)if (!indep_threads_mode && !cpu_has_feature (CPU_FTR_HVMODE )) {pr_warn ("KVM: Ignoring indep_threads_mode=N in nested hypervisor\n" ); kvm->arch.threads_indep = true; + }else if (!indep_threads_mode &&cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) { +pr_warn ("KVM: Ignoring indep_threads_mode=N on pre-DD2.2 POWER9\n" ); + kvm->arch.threads_indep = true; }else { kvm->arch.threads_indep = indep_threads_mode; }
arch/powerpc/kvm/book3s_hv_p9_entry.c +11 -3
@@ -218,6 +218,9 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcmtspr (SPRN_AMOR , ~0UL ); +if (cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) +__mtmsrd (msr & ~(MSR_IR |MSR_DR |MSR_RI ),0 ); +switch_mmu_to_guest_radix (kvm, vcpu, lpcr);/*
@@ -226,7 +229,8 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc*/ mtspr (SPRN_HDEC , hdec); -__mtmsrd (0 ,1 );/* clear RI */ +if (!cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) +__mtmsrd (0 ,1 );/* clear RI */ mtspr (SPRN_DAR , vcpu->arch.shregs.dar);mtspr (SPRN_DSISR , vcpu->arch.shregs.dsisr);
@@ -341,8 +345,6 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcradix_clear_slb (); -__mtmsrd (msr,0 ); -accumulate_time (vcpu, &vcpu->arch.rm_exit);/* Advance host PURR/SPURR by the amount used by guest */
@@ -408,6 +410,12 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcswitch_mmu_to_host_radix (kvm, host_pidr); +/* +* If we are in real mode, only switch MMU on after the MMU is +* switched to host, to avoid the P9_RADIX_PREFETCH_BUG. +*/ +__mtmsrd (msr,0 ); +end_timing (vcpu);return trap;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +0 -34
@@ -1717,40 +1717,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) eieio tlbsync ptesync - -BEGIN_FTR_SECTION - /* Radix: Handle the case where the guest used an illegal PID */ - LOAD_REG_ADDR(r4, mmu_base_pid) - lwz r3, VCPU_GUEST_PID(r9) - lwz r5, 0(r4) - cmpw cr0,r3,r5 - blt 2f - - /* - * Illegal PID, the HW might have prefetched and cached in the TLB - * some translations for the LPID 0 / guest PID combination which - * Linux doesn't know about, so we need to flush that PID out of - * the TLB. First we need to set LPIDR to 0 so tlbiel applies to - * the right context. - */ - li r0,0 - mtspr SPRN_LPID,r0 - isync - - /* Then do a congruence class local flush */ - ld r6,VCPU_KVM(r9) - lwz r0,KVM_TLB_SETS(r6) - mtctr r0 - li r7,0x400 /* IS field = 0b01 */ - ptesync - sldi r0,r3,32 /* RS has PID */ -1: PPC_TLBIEL(7,0,2,1,1) /* RIC=2, PRS=1, R=1 */ - addi r7,r7,0x1000 - bdnz 1b - ptesync -END_FTR_SECTION_IFSET(CPU_FTR_P9_RADIX_PREFETCH_BUG) - -2: #endif /* CONFIG_PPC_RADIX_MMU */ /*
arch/powerpc/mm/book3s64/radix_pgtable.c +8 -19
@@ -357,30 +357,19 @@ static void __init radix_init_pgtable(void) }/* Find out how many PID bits are supported */ -if (!cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) { -if (!mmu_pid_bits) - mmu_pid_bits =20 ; - mmu_base_pid =1 ; - }else if (cpu_has_feature (CPU_FTR_HVMODE )) { -if (!mmu_pid_bits) - mmu_pid_bits =20 ; -#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +if (!cpu_has_feature (CPU_FTR_HVMODE ) && +cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) {/* -* When KVM is possible, we only use the top half of the -* PID space to avoid collisions between host and guest PIDs -* which can cause problems due to prefetch when exiting the -* guest with AIL=3 +* Older versions of KVM on these machines perfer if the +* guest only uses the low 19 PID bits. */ - mmu_base_pid =1 << (mmu_pid_bits -1 ); -#else - mmu_base_pid =1 ; -#endif - }else { -/* The guest uses the bottom half of the PID space */ if (!mmu_pid_bits) mmu_pid_bits =19 ; - mmu_base_pid =1 ; + }else { +if (!mmu_pid_bits) + mmu_pid_bits =20 ; } + mmu_base_pid =1 ;/* * Allocate Partition table and process table for the
arch/powerpc/mm/book3s64/radix_tlb.c +0 -46
49 lines not on this page · raw message
arch/powerpc/mm/mmu_context.c +1 -3
@@ -83,9 +83,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,if (cpu_has_feature (CPU_FTR_ALTIVEC )) asmvolatile ("dssall" ); -if (new_on_cpu) -radix_kvm_prefetch_workaround (next); -else +if (!new_on_cpu)membarrier_arch_switch_mm (prev, next, tsk);/*
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 22/32 KVM: PPC: Book3S HV: Remove support for dependent threads mode on P9
In reply to Nicholas PigginDependent-threads mode is the normal KVM mode for pre-POWER9 SMT processors, where all threads in a core (or subcore) would run the same partition at the same time, or they would run the host.
This design was mandated by MMU state that is shared between threads in a processor, so the synchronisation point is in hypervisor real-mode that has essentially no shared state, so it's safe for multiple threads to gather and switch to the correct mode.
It is implemented by having the host unplug all secondary threads and always run in SMT1 mode, and host QEMU threads essentially represent virtual cores that wake these secondary threads out of unplug when the ioctl is called to run the guest. This happens via a side-path that is mostly invisible to the rest of the Linux host and the secondary threads still appear to be unplugged.
POWER9 / ISA v3.0 has a more flexible MMU design that is independent per-thread and allows a much simpler KVM implementation. Before the new "P9 fast path" was added that began to take advantage of this, POWER9 support was implemented in the existing path which has support to run in the dependent threads mode. So it was not much work to add support to run POWER9 in this dependent threads mode.
The mode is not required by the POWER9 MMU (although "mixed-mode" hash / radix MMU limitations of early processors were worked around using this mode). But it is one way to run SMT guests without running different guests or guest and host on different threads of the same core, so it could avoid or reduce some SMT attack surfaces without turning off SMT entirely.
This security feature has some real, if indeterminate, value. However the old path is lagging in features (nested HV), and with this series the new P9 path adds remaining missing features (radix prefetch bug and hash support, in later patches), so POWER9 dependent threads mode support would be the only remaining reason to keep that code in and keep supporting POWER9/POWER10 in the old path. So here we make the call to drop this feature.
Remove dependent threads mode support for POWER9 and above processors. Systems can still achieve this security by disabling SMT entirely, but that would generally come at a larger performance cost for guests.
--- arch/powerpc/include/asm/kvm_asm.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 1 - arch/powerpc/kvm/book3s_64_entry.S | 3 +-- arch/powerpc/kvm/book3s_hv.c | 27 +++++---------------------- 4 files changed, 7 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +1 -1
@@ -147,7 +147,7 @@#define KVM_GUEST_MODE_SKIP 2#define KVM_GUEST_MODE_GUEST_HV 3#define KVM_GUEST_MODE_HOST_HV 4 -#define KVM_GUEST_MODE_HV_FAST 5/* ISA >= v3.0 host+guest radix, indep thr */ +#define KVM_GUEST_MODE_HV_FAST 5/* ISA >= v3.0 host+guest radix */ #define KVM_INST_FETCH_FAILED -1
arch/powerpc/include/asm/kvm_host.h +0 -1
@@ -297,7 +297,6 @@ struct kvm_arch {u8 fwnmi_enabled;u8 secure_guest;u8 svm_enabled; -bool threads_indep;bool nested_enable;bool dawr1_enabled;pgd_t *pgtable;
arch/powerpc/kvm/book3s_64_entry.S +1 -2
@@ -184,8 +184,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) * void kvmppc_p9_enter_guest(struct vcpu *vcpu); * * Enter the guest on a ISAv3.0 or later system where we have exactly - * one vcpu per vcore, and both the host and guest are radix, and threads - * are set to "indepdent mode". + * one vcpu per vcore, and both the host and guest are radix. */ .balign IFETCH_ALIGN_BYTES _GLOBAL(kvmppc_p9_enter_guest)
arch/powerpc/kvm/book3s_hv.c +5 -22
@@ -103,13 +103,9 @@ static int target_smt_mode;module_param (target_smt_mode, int,0644 );MODULE_PARM_DESC (target_smt_mode,"Target threads per core (0 = max)" ); -static bool indep_threads_mode = true; -module_param (indep_threads_mode, bool,S_IRUGO |S_IWUSR ); -MODULE_PARM_DESC (indep_threads_mode,"Independent-threads mode (only on POWER9)" ); -static bool one_vm_per_core;module_param (one_vm_per_core, bool,S_IRUGO |S_IWUSR ); -MODULE_PARM_DESC (one_vm_per_core,"Only run vCPUs from the same VM on a core (requires indep_threads_mode=N)" ); +MODULE_PARM_DESC (one_vm_per_core,"Only run vCPUs from the same VM on a core (requires POWER8 or older)" );#ifdef CONFIG_KVM_XICS static const struct kernel_param_ops module_param_ops = {
@@ -2265,7 +2261,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,*/ static int threads_per_vcore (struct kvm *kvm) { -if (kvm->arch.threads_indep) +if (cpu_has_feature (CPU_FTR_ARCH_300 ))return 1 ;return threads_per_subcore; }
@@ -4369,7 +4365,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu) vcpu->arch.state =KVMPPC_VCPU_BUSY_IN_HOST ; do { - if (kvm->arch.threads_indep && kvm_is_radix(kvm)) + if (kvm_is_radix(kvm)) r = kvmhv_run_single_vcpu(vcpu, ~(u64)0, vcpu->arch.vcore->lpcr); else
@@ -4992,21 +4988,8 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)/* * Track that we now have a HV mode VM active. This blocks secondary * CPU threads from coming online. -* On POWER9, we only need to do this if the "indep_threads_mode" -* module parameter has been set to N. */ -if (cpu_has_feature (CPU_FTR_ARCH_300 )) { -if (!indep_threads_mode && !cpu_has_feature (CPU_FTR_HVMODE )) { -pr_warn ("KVM: Ignoring indep_threads_mode=N in nested hypervisor\n" ); - kvm->arch.threads_indep = true; - }else if (!indep_threads_mode &&cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) { -pr_warn ("KVM: Ignoring indep_threads_mode=N on pre-DD2.2 POWER9\n" ); - kvm->arch.threads_indep = true; - }else { - kvm->arch.threads_indep = indep_threads_mode; - } - } -if (!kvm->arch.threads_indep) +if (!cpu_has_feature (CPU_FTR_ARCH_300 ))kvm_hv_vm_activated ();/*
@@ -5047,7 +5030,7 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) {debugfs_remove_recursive (kvm->arch.debugfs_dir); -if (!kvm->arch.threads_indep) +if (!cpu_has_feature (CPU_FTR_ARCH_300 ))kvm_hv_vm_deactivated ();kvmppc_free_vcores (kvm);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 23/32 KVM: PPC: Book3S HV: Remove radix guest support from P7/8 path
In reply to Nicholas PigginThe P9 path now runs all supported radix guest combinations, so remove radix guest support from the P7/8 path.
--- arch/powerpc/kernel/asm-offsets.c | 1 - arch/powerpc/kvm/book3s_hv_rmhandlers.S | 103 +----------------------- 2 files changed, 3 insertions(+), 101 deletions(-)
arch/powerpc/kernel/asm-offsets.c +0 -1
@@ -534,7 +534,6 @@ int main(void)OFFSET (VCPU_SLB_NR , kvm_vcpu, arch.slb_nr);OFFSET (VCPU_FAULT_DSISR , kvm_vcpu, arch.fault_dsisr);OFFSET (VCPU_FAULT_DAR , kvm_vcpu, arch.fault_dar); -OFFSET (VCPU_FAULT_GPA , kvm_vcpu, arch.fault_gpa);OFFSET (VCPU_INTR_MSR , kvm_vcpu, arch.intr_msr);OFFSET (VCPU_LAST_INST , kvm_vcpu, arch.last_inst);OFFSET (VCPU_TRAP , kvm_vcpu, arch.trap);
arch/powerpc/kvm/book3s_hv_rmhandlers.S +3 -100
190 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 24/32 KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers
In reply to Nicholas PigginNow that the P7/8 path no longer supports radix, real-mode handlers do not need to deal with being called in virt mode.
This change effectively reverts commit acde25726bc6 ("KVM: PPC: Book3S
HV: Add radix checks in real-mode hypercall handlers").
It removes a few more real-mode tests in rm hcall handlers, which allows the indirect ops for the xive module to be removed from the built-in xics rm handlers.
kvmppc_h_random is renamed to kvmppc_rm_h_random to be a bit more descriptive and consistent with other rm handlers.
--- arch/powerpc/include/asm/kvm_ppc.h | 10 +-- arch/powerpc/kvm/book3s.c | 11 +-- arch/powerpc/kvm/book3s_64_vio_hv.c | 12 ---- arch/powerpc/kvm/book3s_hv_builtin.c | 91 ++++++------------------- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 2 +- arch/powerpc/kvm/book3s_xive.c | 18 ----- arch/powerpc/kvm/book3s_xive.h | 7 -- arch/powerpc/kvm/book3s_xive_native.c | 10 --- 8 files changed, 23 insertions(+), 138 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +1 -9
@@ -659,8 +659,6 @@ extern int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, u32 *priority);extern int kvmppc_xive_int_on (struct kvm *kvm,u32 irq);extern int kvmppc_xive_int_off (struct kvm *kvm,u32 irq); -extern void kvmppc_xive_init_module (void ); -extern void kvmppc_xive_exit_module (void );extern int kvmppc_xive_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu);
@@ -686,8 +684,6 @@ static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)extern int kvmppc_xive_native_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu);extern void kvmppc_xive_native_cleanup_vcpu (struct kvm_vcpu *vcpu); -extern void kvmppc_xive_native_init_module (void ); -extern void kvmppc_xive_native_exit_module (void );extern int kvmppc_xive_native_get_vp (struct kvm_vcpu *vcpu,union kvmppc_one_reg *val); extern int kvmppc_xive_native_set_vp(struct kvm_vcpu *vcpu,
@@ -701,8 +697,6 @@ static inline int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, u32 *priority) { return -1; }static inline int kvmppc_xive_int_on (struct kvm *kvm,u32 irq) {return -1 ; }static inline int kvmppc_xive_int_off (struct kvm *kvm,u32 irq) {return -1 ; } -static inline void kvmppc_xive_init_module (void ) { } -static inline void kvmppc_xive_exit_module (void ) { }static inline int kvmppc_xive_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu) {return -EBUSY ; }
@@ -725,8 +719,6 @@ static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)static inline int kvmppc_xive_native_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu) {return -EBUSY ; }static inline void kvmppc_xive_native_cleanup_vcpu (struct kvm_vcpu *vcpu) { } -static inline void kvmppc_xive_native_init_module (void ) { } -static inline void kvmppc_xive_native_exit_module (void ) { }static inline int kvmppc_xive_native_get_vp (struct kvm_vcpu *vcpu,union kvmppc_one_reg *val) {return 0 ; }
@@ -762,7 +754,7 @@ long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu, unsigned long tce_value, unsigned long npages);long int kvmppc_rm_h_confer (struct kvm_vcpu *vcpu,int target,unsigned int yield_count); -long kvmppc_h_random (struct kvm_vcpu *vcpu); +long kvmppc_rm_h_random (struct kvm_vcpu *vcpu);void kvmhv_commence_exit (int trap);void kvmppc_realmode_machine_check (struct kvm_vcpu *vcpu);void kvmppc_subcore_enter_guest (void );
arch/powerpc/kvm/book3s.c +1 -10
@@ -1050,13 +1050,10 @@ static int kvmppc_book3s_init(void)#ifdef CONFIG_KVM_XICS #ifdef CONFIG_KVM_XIVE if (xics_on_xive ()) { -kvmppc_xive_init_module ();kvm_register_device_ops (&kvm_xive_ops,KVM_DEV_TYPE_XICS ); -if (kvmppc_xive_native_supported ()) { -kvmppc_xive_native_init_module (); +if (kvmppc_xive_native_supported ())kvm_register_device_ops (&kvm_xive_native_ops,KVM_DEV_TYPE_XIVE ); - } } else#endif kvm_register_device_ops (&kvm_xics_ops,KVM_DEV_TYPE_XICS );
@@ -1066,12 +1063,6 @@ static int kvmppc_book3s_init(void)static void kvmppc_book3s_exit (void ) { -#ifdef CONFIG_KVM_XICS -if (xics_on_xive ()) { -kvmppc_xive_exit_module (); -kvmppc_xive_native_exit_module (); - } -#endif #ifdef CONFIG_KVM_BOOK3S_32_HANDLER kvmppc_book3s_exit_pr ();#endif
arch/powerpc/kvm/book3s_64_vio_hv.c +0 -12
@@ -391,10 +391,6 @@ long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,/* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */ /* liobn, ioba, tce); */ -/* For radix, we might be in virtual mode, so punt */ -if (kvm_is_radix (vcpu->kvm)) -return H_TOO_HARD ; - stt =kvmppc_find_table (vcpu->kvm, liobn);if (!stt)return H_TOO_HARD ;
@@ -489,10 +485,6 @@ long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,bool prereg = false;struct kvmppc_spapr_tce_iommu_table *stit; -/* For radix, we might be in virtual mode, so punt */ -if (kvm_is_radix (vcpu->kvm)) -return H_TOO_HARD ; -/* * used to check for invalidations in progress */
@@ -602,10 +594,6 @@ long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu,long i, ret;struct kvmppc_spapr_tce_iommu_table *stit; -/* For radix, we might be in virtual mode, so punt */ -if (kvm_is_radix (vcpu->kvm)) -return H_TOO_HARD ; - stt =kvmppc_find_table (vcpu->kvm, liobn);if (!stt)return H_TOO_HARD ;
arch/powerpc/kvm/book3s_hv_builtin.c +20 -71
144 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +1 -1
@@ -2306,7 +2306,7 @@ hcall_real_table: #else .long 0 /* 0x2fc - H_XIRR_X*/ #endif - .long DOTSYM(kvmppc_h_random) - hcall_real_table + .long DOTSYM(kvmppc_rm_h_random) - hcall_real_table .globl hcall_real_table_end hcall_real_table_end:
arch/powerpc/kvm/book3s_xive.c +0 -18
@@ -2352,21 +2352,3 @@ struct kvm_device_ops kvm_xive_ops = { .get_attr = xive_get_attr, .has_attr = xive_has_attr, }; - -void kvmppc_xive_init_module (void ) -{ - __xive_vm_h_xirr = xive_vm_h_xirr; - __xive_vm_h_ipoll = xive_vm_h_ipoll; - __xive_vm_h_ipi = xive_vm_h_ipi; - __xive_vm_h_cppr = xive_vm_h_cppr; - __xive_vm_h_eoi = xive_vm_h_eoi; -} - -void kvmppc_xive_exit_module (void ) -{ - __xive_vm_h_xirr =NULL ; - __xive_vm_h_ipoll =NULL ; - __xive_vm_h_ipi =NULL ; - __xive_vm_h_cppr =NULL ; - __xive_vm_h_eoi =NULL ; -}
arch/powerpc/kvm/book3s_xive.h +0 -7
@@ -289,13 +289,6 @@ extern int xive_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,extern int xive_rm_h_cppr (struct kvm_vcpu *vcpu,unsigned long cppr);extern int xive_rm_h_eoi (struct kvm_vcpu *vcpu,unsigned long xirr); -extern unsigned long (*__xive_vm_h_xirr)(struct kvm_vcpu *vcpu); -extern unsigned long (*__xive_vm_h_ipoll)(struct kvm_vcpu *vcpu,unsigned long server); -extern int (*__xive_vm_h_ipi)(struct kvm_vcpu *vcpu,unsigned long server, -unsigned long mfrr); -extern int (*__xive_vm_h_cppr)(struct kvm_vcpu *vcpu,unsigned long cppr); -extern int (*__xive_vm_h_eoi)(struct kvm_vcpu *vcpu,unsigned long xirr); -/* * Common Xive routines for XICS-over-XIVE and XIVE native */
arch/powerpc/kvm/book3s_xive_native.c +0 -10
@@ -1281,13 +1281,3 @@ struct kvm_device_ops kvm_xive_native_ops = { .has_attr = kvmppc_xive_native_has_attr, .mmap = kvmppc_xive_native_mmap, }; - -void kvmppc_xive_native_init_module (void ) -{ - ; -} - -void kvmppc_xive_native_exit_module (void ) -{ - ; -}
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 25/32 KVM: PPC: Book3S HV: Remove unused nested HV tests in XICS emulation
In reply to Nicholas PigginCommit f3c18e9342a44 ("KVM: PPC: Book3S HV: Use XICS hypercalls when running as a nested hypervisor") added nested HV tests in XICS hypercalls, but not all are required.
* icp_eoi is only called by kvmppc_deliver_irq_passthru which is only called by kvmppc_check_passthru which is only caled by kvmppc_read_one_intr.
* kvmppc_read_one_intr is only called by kvmppc_read_intr which is only called by the L0 HV rmhandlers code.
* kvmhv_rm_send_ipi is called by:
- kvmhv_interrupt_vcore which is only called by kvmhv_commence_exit which is only called by the L0 HV rmhandlers code.
- icp_send_hcore_msg which is only called by icp_rm_set_vcpu_irq.
- icp_rm_set_vcpu_irq which is only called by icp_rm_try_update
- icp_rm_set_vcpu_irq is not nested HV safe because it writes to LPCR directly without a kvmhv_on_pseries test. Nested handlers should not in general be using the rm handlers.
The important test seems to be in kvmppc_ipi_thread, which sends the virt-mode H_IPI handler kick to use smp_call_function rather than msgsnd.
--- arch/powerpc/kvm/book3s_hv_builtin.c | 44 +++++----------------------- arch/powerpc/kvm/book3s_hv_rm_xics.c | 15 ---------- 2 files changed, 8 insertions(+), 51 deletions(-)
arch/powerpc/kvm/book3s_hv_builtin.c +8 -36
@@ -199,15 +199,6 @@ void kvmhv_rm_send_ipi(int cpu)void __iomem *xics_phys;unsigned long msg =PPC_DBELL_TYPE (PPC_DBELL_SERVER ); -/* For a nested hypervisor, use the XICS via hcall */ -if (kvmhv_on_pseries ()) { -unsigned long retbuf[PLPAR_HCALL_BUFSIZE ]; - -plpar_hcall_raw (H_IPI , retbuf,get_hard_smp_processor_id (cpu), -IPI_PRIORITY ); -return ; - } -/* On POWER9 we can use msgsnd for any destination cpu. */ if (cpu_has_feature (CPU_FTR_ARCH_300 )) { msg |=get_hard_smp_processor_id (cpu);
@@ -420,19 +411,12 @@ static long kvmppc_read_one_intr(bool *again)return 1 ;/* Now read the interrupt from the ICP */ -if (kvmhv_on_pseries ()) { -unsigned long retbuf[PLPAR_HCALL_BUFSIZE ]; - - rc =plpar_hcall_raw (H_XIRR , retbuf,0xFF ); - xirr =cpu_to_be32 (retbuf[0 ]); - }else { - xics_phys = local_paca->kvm_hstate.xics_phys; - rc =0 ; -if (!xics_phys) - rc =opal_int_get_xirr (&xirr, false); -else - xirr =__raw_rm_readl (xics_phys +XICS_XIRR ); - } + xics_phys = local_paca->kvm_hstate.xics_phys; + rc =0 ; +if (!xics_phys) + rc =opal_int_get_xirr (&xirr, false); +else + xirr =__raw_rm_readl (xics_phys +XICS_XIRR );if (rc <0 )return 1 ;
@@ -461,13 +445,7 @@ static long kvmppc_read_one_intr(bool *again)*/ if (xisr =XICS_IPI ) { rc =0 ; -if (kvmhv_on_pseries ()) { -unsigned long retbuf[PLPAR_HCALL_BUFSIZE ]; - -plpar_hcall_raw (H_IPI , retbuf, -hard_smp_processor_id (),0xff ); -plpar_hcall_raw (H_EOI , retbuf, h_xirr); - }else if (xics_phys) { +if (xics_phys) {__raw_rm_writeb (0xff , xics_phys +XICS_MFRR );__raw_rm_writel (xirr, xics_phys +XICS_XIRR ); }else {
@@ -493,13 +471,7 @@ static long kvmppc_read_one_intr(bool *again)/* We raced with the host, * we need to resend that IPI, bummer */ -if (kvmhv_on_pseries ()) { -unsigned long retbuf[PLPAR_HCALL_BUFSIZE ]; - -plpar_hcall_raw (H_IPI , retbuf, -hard_smp_processor_id (), -IPI_PRIORITY ); - }else if (xics_phys) +if (xics_phys)__raw_rm_writeb (IPI_PRIORITY , xics_phys +XICS_MFRR );else
arch/powerpc/kvm/book3s_hv_rm_xics.c +0 -15
@@ -141,13 +141,6 @@ static void icp_rm_set_vcpu_irq(struct kvm_vcpu *vcpu,return ; } -if (xive_enabled () &&kvmhv_on_pseries ()) { -/* No XICS access or hypercalls available, too hard */ - this_icp->rm_action |=XICS_RM_KICK_VCPU ; - this_icp->rm_kick_target = vcpu; -return ; - } -/* * Check if the core is loaded, * if not, find an available host core to post to wake the VCPU,
@@ -771,14 +764,6 @@ static void icp_eoi(struct irq_chip *c, u32 hwirq, __be32 xirr, bool *again)void __iomem *xics_phys;int64_t rc; -if (kvmhv_on_pseries ()) { -unsigned long retbuf[PLPAR_HCALL_BUFSIZE ]; - -iosync (); -plpar_hcall_raw (H_EOI , retbuf, hwirq); -return ; - } - rc =pnv_opal_pci_msi_eoi (c, hwirq);if (rc)
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 26/32 KVM: PPC: Book3S HV P9: Allow all P9 processors to enable nested HV
In reply to Nicholas PigginAll radix guests go via the P9 path now, so there is no need to limit nested HV to processors that support "mixed mode" MMU. Remove the restriction.
--- arch/powerpc/kvm/book3s_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -5451,7 +5451,7 @@ static int kvmhv_enable_nested(struct kvm *kvm) {if (!nested)return -EPERM ; -if (!cpu_has_feature (CPU_FTR_ARCH_300 ) || no_mixing_hpt_and_radix) +if (!cpu_has_feature (CPU_FTR_ARCH_300 ))return -ENODEV ;/* kvm = NULL means the caller is testing if the capability exists */
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 27/32 KVM: PPC: Book3S HV: small pseries_do_hcall cleanup
In reply to Nicholas PigginFunctionality should not be changed.
--- arch/powerpc/kvm/book3s_hv.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
arch/powerpc/kvm/book3s_hv.c +15 -14
@@ -927,6 +927,7 @@ static int kvmppc_get_yield_count(struct kvm_vcpu *vcpu)int kvmppc_pseries_do_hcall (struct kvm_vcpu *vcpu) { +struct kvm *kvm = vcpu->kvm;unsigned long req =kvmppc_get_gpr (vcpu,3 );unsigned long target, ret =H_SUCCESS ;int yield_count;
@@ -942,7 +943,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)break ;case H_PROD : target =kvmppc_get_gpr (vcpu,4 ); - tvcpu =kvmppc_find_vcpu (vcpu->kvm, target); + tvcpu =kvmppc_find_vcpu (kvm, target);if (!tvcpu) { ret =H_PARAMETER ;break ;
@@ -956,7 +957,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) target =kvmppc_get_gpr (vcpu,4 );if (target =-1 )break ; - tvcpu =kvmppc_find_vcpu (vcpu->kvm, target); + tvcpu =kvmppc_find_vcpu (kvm, target);if (!tvcpu) { ret =H_PARAMETER ;break ;
@@ -972,12 +973,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) kvmppc_get_gpr(vcpu, 6));break ;case H_RTAS : -if (list_empty (&vcpu->kvm->arch.rtas_tokens)) +if (list_empty (&kvm->arch.rtas_tokens))return RESUME_HOST ; - idx =srcu_read_lock (&vcpu->kvm->srcu); + idx =srcu_read_lock (&kvm->srcu); rc =kvmppc_rtas_hcall (vcpu); -srcu_read_unlock (&vcpu->kvm->srcu, idx); +srcu_read_unlock (&kvm->srcu, idx);if (rc = -ENOENT )return RESUME_HOST ;
@@ -1064,12 +1065,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)case H_SET_PARTITION_TABLE : ret =H_FUNCTION ; -if (nesting_enabled (vcpu->kvm)) +if (nesting_enabled (kvm)) ret =kvmhv_set_partition_table (vcpu);break ;case H_ENTER_NESTED : ret =H_FUNCTION ; -if (!nesting_enabled (vcpu->kvm)) +if (!nesting_enabled (kvm))break ; ret =kvmhv_enter_nested_guest (vcpu);if (ret =H_INTERRUPT ) {
@@ -1084,12 +1085,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)break ;case H_TLB_INVALIDATE : ret =H_FUNCTION ; -if (nesting_enabled (vcpu->kvm)) +if (nesting_enabled (kvm)) ret =kvmhv_do_nested_tlbie (vcpu);break ;case H_COPY_TOFROM_GUEST : ret =H_FUNCTION ; -if (nesting_enabled (vcpu->kvm)) +if (nesting_enabled (kvm)) ret =kvmhv_copy_tofrom_guest_nested (vcpu);break ;case H_PAGE_INIT :
@@ -1100,7 +1101,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)case H_SVM_PAGE_IN : ret =H_UNSUPPORTED ;if (kvmppc_get_srr1 (vcpu) &MSR_S ) - ret =kvmppc_h_svm_page_in (vcpu->kvm, + ret =kvmppc_h_svm_page_in (kvm,kvmppc_get_gpr (vcpu,4 ),kvmppc_get_gpr (vcpu,5 ),kvmppc_get_gpr (vcpu,6 ));
@@ -1108,7 +1109,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)case H_SVM_PAGE_OUT : ret =H_UNSUPPORTED ;if (kvmppc_get_srr1 (vcpu) &MSR_S ) - ret =kvmppc_h_svm_page_out (vcpu->kvm, + ret =kvmppc_h_svm_page_out (kvm,kvmppc_get_gpr (vcpu,4 ),kvmppc_get_gpr (vcpu,5 ),kvmppc_get_gpr (vcpu,6 ));
@@ -1116,12 +1117,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)case H_SVM_INIT_START : ret =H_UNSUPPORTED ;if (kvmppc_get_srr1 (vcpu) &MSR_S ) - ret =kvmppc_h_svm_init_start (vcpu->kvm); + ret =kvmppc_h_svm_init_start (kvm);break ;case H_SVM_INIT_DONE : ret =H_UNSUPPORTED ;if (kvmppc_get_srr1 (vcpu) &MSR_S ) - ret =kvmppc_h_svm_init_done (vcpu->kvm); + ret =kvmppc_h_svm_init_done (kvm);break ;case H_SVM_INIT_ABORT :/*
@@ -1131,7 +1132,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)* Instead the kvm->arch.secure_guest flag is checked inside * kvmppc_h_svm_init_abort(). */ - ret =kvmppc_h_svm_init_abort (vcpu->kvm); + ret =kvmppc_h_svm_init_abort (kvm);break ;default :
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 28/32 KVM: PPC: Book3S HV: add virtual mode handlers for HPT hcalls and page faults
In reply to Nicholas PigginIn order to support hash guests in the P9 path (which does not do real mode hcalls or page fault handling), these real-mode hash specific interrupts need to be implemented in virt mode.
--- arch/powerpc/kvm/book3s_hv.c | 145 ++++++++++++++++++++++++++-- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 ++ 2 files changed, 144 insertions(+), 9 deletions(-)
arch/powerpc/kvm/book3s_hv.c +136 -9
@@ -939,6 +939,52 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)return RESUME_HOST ;switch (req) { +case H_REMOVE : + ret =kvmppc_h_remove (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_ENTER : + ret =kvmppc_h_enter (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 ), +kvmppc_get_gpr (vcpu,7 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_READ : + ret =kvmppc_h_read (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_CLEAR_MOD : + ret =kvmppc_h_clear_mod (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_CLEAR_REF : + ret =kvmppc_h_clear_ref (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_PROTECT : + ret =kvmppc_h_protect (vcpu,kvmppc_get_gpr (vcpu,4 ), +kvmppc_get_gpr (vcpu,5 ), +kvmppc_get_gpr (vcpu,6 )); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_BULK_REMOVE : + ret =kvmppc_h_bulk_remove (vcpu); +if (ret =H_TOO_HARD ) +return RESUME_HOST ; +break ; +case H_CEDE :break ;case H_PROD :
@@ -1138,6 +1184,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)default :return RESUME_HOST ; } +WARN_ON_ONCE (ret =H_TOO_HARD );kvmppc_set_gpr (vcpu,3 , ret); vcpu->arch.hcall_needed =0 ;return RESUME_GUEST ;
@@ -1438,22 +1485,102 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* We get these next two if the guest accesses a page which it thinks * it has mapped but which is not actually present, either because * it is for an emulated I/O device or because the corresonding -* host page has been paged out. Any other HDSI/HISI interrupts -* have been handled already. +* host page has been paged out. +* +* Any other HDSI/HISI interrupts have been handled already for P7/8 +* guests. For POWER9 hash guests not using rmhandlers, basic hash +* fault handling is done here. */ -case BOOK3S_INTERRUPT_H_DATA_STORAGE : - r =RESUME_PAGE_FAULT ; -if (vcpu->arch.fault_dsisr =HDSISR_CANARY ) +case BOOK3S_INTERRUPT_H_DATA_STORAGE : { +unsigned long vsid; +long err; + +if (vcpu->arch.fault_dsisr =HDSISR_CANARY ) { r =RESUME_GUEST ;/* Just retry if it's the canary */ +break ; + } + +if (kvm_is_radix (vcpu->kvm) || !cpu_has_feature (CPU_FTR_ARCH_300 )) { +/* +* Radix doesn't require anything, and pre-ISAv3.0 hash +* already attempted to handle this in rmhandlers. The +* hash fault handling below is v3 only (it uses ASDR +* via fault_gpa). +*/ + r =RESUME_PAGE_FAULT ; +break ; + } + +if (!(vcpu->arch.fault_dsisr & (DSISR_NOHPTE |DSISR_PROTFAULT ))) { +kvmppc_core_queue_data_storage (vcpu, + vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); + r =RESUME_GUEST ; +break ; + } + +if (!(vcpu->arch.shregs.msr &MSR_DR )) + vsid = vcpu->kvm->arch.vrma_slb_v; +else + vsid = vcpu->arch.fault_gpa; + + err =kvmppc_hpte_hv_fault (vcpu, vcpu->arch.fault_dar, + vsid, vcpu->arch.fault_dsisr, true); +if (err =0 ) { + r =RESUME_GUEST ; + }else if (err =-1 || err =-2 ) { + r =RESUME_PAGE_FAULT ; + }else { +kvmppc_core_queue_data_storage (vcpu, + vcpu->arch.fault_dar, err); + r =RESUME_GUEST ; + }break ; -case BOOK3S_INTERRUPT_H_INST_STORAGE : + } +case BOOK3S_INTERRUPT_H_INST_STORAGE : { +unsigned long vsid; +long err; + vcpu->arch.fault_dar =kvmppc_get_pc (vcpu); vcpu->arch.fault_dsisr = vcpu->arch.shregs.msr &DSISR_SRR1_MATCH_64S ; -if (vcpu->arch.shregs.msr &HSRR1_HISI_WRITE ) - vcpu->arch.fault_dsisr |=DSISR_ISSTORE ; - r =RESUME_PAGE_FAULT ; +if (kvm_is_radix (vcpu->kvm) || !cpu_has_feature (CPU_FTR_ARCH_300 )) { +/* +* Radix doesn't require anything, and pre-ISAv3.0 hash +* already attempted to handle this in rmhandlers. The +* hash fault handling below is v3 only (it uses ASDR +* via fault_gpa). +*/ +if (vcpu->arch.shregs.msr &HSRR1_HISI_WRITE ) + vcpu->arch.fault_dsisr |=DSISR_ISSTORE ; + r =RESUME_PAGE_FAULT ; +break ; + } + +if (!(vcpu->arch.fault_dsisr &SRR1_ISI_NOPT )) { +kvmppc_core_queue_inst_storage (vcpu, + vcpu->arch.fault_dsisr); + r =RESUME_GUEST ; +break ; + } + +if (!(vcpu->arch.shregs.msr &MSR_IR )) + vsid = vcpu->kvm->arch.vrma_slb_v; +else + vsid = vcpu->arch.fault_gpa; + + err =kvmppc_hpte_hv_fault (vcpu, vcpu->arch.fault_dar, + vsid, vcpu->arch.fault_dsisr, false); +if (err =0 ) { + r =RESUME_GUEST ; + }else if (err =-1 ) { + r =RESUME_PAGE_FAULT ; + }else { +kvmppc_core_queue_inst_storage (vcpu, err); + r =RESUME_GUEST ; + }break ; + } +/* * This occurs if the guest executes an illegal instruction. * If the guest debug is disabled, generate a program interrupt
arch/powerpc/kvm/book3s_hv_rm_mmu.c +8 -0
@@ -398,6 +398,7 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, vcpu->arch.pgdir, true, &vcpu->arch.regs.gpr[4]); } +EXPORT_SYMBOL_GPL (kvmppc_h_enter);#ifdef __BIG_ENDIAN__#define LOCK_TOKEN (*(u32 *)(&get_paca()->lock_token))
@@ -542,6 +543,7 @@ long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,return kvmppc_do_h_remove (vcpu->kvm, flags, pte_index, avpn, &vcpu->arch.regs.gpr[4 ]); } +EXPORT_SYMBOL_GPL (kvmppc_h_remove);long kvmppc_h_bulk_remove (struct kvm_vcpu *vcpu) {
@@ -660,6 +662,7 @@ long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu)return ret; } +EXPORT_SYMBOL_GPL (kvmppc_h_bulk_remove);long kvmppc_h_protect (struct kvm_vcpu *vcpu,unsigned long flags,unsigned long pte_index,unsigned long avpn)
@@ -730,6 +733,7 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,return H_SUCCESS ; } +EXPORT_SYMBOL_GPL (kvmppc_h_protect);long kvmppc_h_read (struct kvm_vcpu *vcpu,unsigned long flags,unsigned long pte_index)
@@ -770,6 +774,7 @@ long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags, }return H_SUCCESS ; } +EXPORT_SYMBOL_GPL (kvmppc_h_read);long kvmppc_h_clear_ref (struct kvm_vcpu *vcpu,unsigned long flags,unsigned long pte_index)
@@ -818,6 +823,7 @@ long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags,unlock_hpte (hpte, v & ~HPTE_V_HVLOCK );return ret; } +EXPORT_SYMBOL_GPL (kvmppc_h_clear_ref);long kvmppc_h_clear_mod (struct kvm_vcpu *vcpu,unsigned long flags,unsigned long pte_index)
@@ -865,6 +871,7 @@ long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,unlock_hpte (hpte, v & ~HPTE_V_HVLOCK );return ret; } +EXPORT_SYMBOL_GPL (kvmppc_h_clear_mod); static int kvmppc_get_hpa(struct kvm_vcpu *vcpu, unsigned long mmu_seq, unsigned long gpa, int writing, unsigned long *hpa,
@@ -1283,3 +1290,4 @@ long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr,return -1 ;/* send fault up to host kernel mode */ } +EXPORT_SYMBOL_GPL (kvmppc_hpte_hv_fault);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 29/32 KVM: PPC: Book3S HV P9: Reflect userspace hcalls to hash guests to support PR KVM
In reply to Nicholas PigginThe reflection of sc 1 interrupts from guest PR=1 to the guest kernel is required to support a hash guest running PR KVM where its guest is making hcalls with sc 1.
In preparation for hash guest support, add this hcall reflection to the P9 path. The P7/8 path does this in its realmode hcall handler (sc_1_fast_return).
--- arch/powerpc/kvm/book3s_hv.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_hv.c +16 -6
@@ -1457,13 +1457,23 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* Guest userspace executed sc 1. This can only be * reached by the P9 path because the old path * handles this case in realmode hcall handlers. -* -* Radix guests can not run PR KVM or nested HV hash -* guests which might run PR KVM, so this is always -* a privilege fault. Send a program check to guest -* kernel. */ -kvmppc_core_queue_program (vcpu,SRR1_PROGPRIV ); +if (!kvmhv_vcpu_is_radix (vcpu)) { +/* +* A guest could be running PR KVM, so this +* may be a PR KVM hcall. It must be reflected +* to the guest kernel as a sc interrupt. +*/ +kvmppc_core_queue_syscall (vcpu); + }else { +/* +* Radix guests can not run PR KVM or nested HV +* hash guests which might run PR KVM, so this +* is always a privilege fault. Send a program +* check to guest kernel. +*/ +kvmppc_core_queue_program (vcpu,SRR1_PROGPRIV ); + } r =RESUME_GUEST ;break ; }
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 30/32 KVM: PPC: Book3S HV P9: implement hash guest support
In reply to Nicholas PigginImplement hash guest support. Guest entry/exit has to restore and save/clear the SLB, plus several other bits to accommodate hash guests in the P9 path. Radix host, hash guest support is removed from the P7/8 path.
The HPT hcalls and faults are not handled in real mode, which is a performance regression. A worst-case fork/exit microbenchmark takes 3x longer after this patch. kbuild benchmark performance is in the noise, but the slowdown is likely to be noticed somewhere.
For now, accept this penalty for the benefit of simplifying the P7/8 paths and unifying P9 hash with the new code, because hash is a less important configuration than radix on processors that support it. Hash will benefit from future optimisations to this path, including possibly a faster path to handle such hcalls and interrupts without doing a full exit.
--- arch/powerpc/include/asm/kvm_asm.h | 2 +- arch/powerpc/kvm/book3s_64_entry.S | 2 +- arch/powerpc/kvm/book3s_hv.c | 20 +++-- arch/powerpc/kvm/book3s_hv_p9_entry.c | 97 ++++++++++++++++++++----- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 4 + arch/powerpc/kvm/book3s_hv_rmhandlers.S | 14 +--- 6 files changed, 101 insertions(+), 38 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +1 -1
@@ -147,7 +147,7 @@#define KVM_GUEST_MODE_SKIP 2#define KVM_GUEST_MODE_GUEST_HV 3#define KVM_GUEST_MODE_HOST_HV 4 -#define KVM_GUEST_MODE_HV_FAST 5/* ISA >= v3.0 host+guest radix */ +#define KVM_GUEST_MODE_HV_FAST 5/* ISA >= v3.0 host radix */ #define KVM_INST_FETCH_FAILED -1
arch/powerpc/kvm/book3s_64_entry.S +1 -1
@@ -184,7 +184,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) * void kvmppc_p9_enter_guest(struct vcpu *vcpu); * * Enter the guest on a ISAv3.0 or later system where we have exactly - * one vcpu per vcore, and both the host and guest are radix. + * one vcpu per vcore, and the host is radix. */ .balign IFETCH_ALIGN_BYTES _GLOBAL(kvmppc_p9_enter_guest)
arch/powerpc/kvm/book3s_hv.c +14 -6
@@ -3875,7 +3875,8 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, }kvmppc_xive_pull_vcpu (vcpu); - vcpu->arch.slb_max =0 ; +if (kvm_is_radix (vcpu->kvm)) + vcpu->arch.slb_max =0 ; } dec =mfspr (SPRN_DEC );
@@ -4110,7 +4111,6 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)/* * This never fails for a radix guest, as none of the operations it does * for a radix guest can fail or have a way to report failure. -* kvmhv_run_single_vcpu() relies on this fact. */ static int kvmhv_setup_mmu (struct kvm_vcpu *vcpu) {
@@ -4289,8 +4289,15 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, vc->runner = vcpu;/* See if the MMU is ready to go */ -if (!kvm->arch.mmu_ready) -kvmhv_setup_mmu (vcpu); +if (!kvm->arch.mmu_ready) { + r =kvmhv_setup_mmu (vcpu); +if (r) { + run->exit_reason =KVM_EXIT_FAIL_ENTRY ; + run->fail_entry.hardware_entry_failure_reason =0 ; + vcpu->arch.ret = r; +return r; + } + }if (need_resched ())cond_resched ();
@@ -4303,7 +4310,8 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,preempt_disable (); pcpu =smp_processor_id (); vc->pcpu = pcpu; -kvmppc_prepare_radix_vcpu (vcpu, pcpu); +if (kvm_is_radix (kvm)) +kvmppc_prepare_radix_vcpu (vcpu, pcpu);local_irq_disable ();hard_irq_disable ();
@@ -4503,7 +4511,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu) vcpu->arch.state =KVMPPC_VCPU_BUSY_IN_HOST ; do { - if (kvm_is_radix(kvm)) + if (radix_enabled()) r = kvmhv_run_single_vcpu(vcpu, ~(u64)0, vcpu->arch.vcore->lpcr); else
arch/powerpc/kvm/book3s_hv_p9_entry.c +79 -18
177 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rm_mmu.c +4 -0
@@ -46,6 +46,10 @@ static int global_invalidates(struct kvm *kvm)else global =1 ; +/* LPID has been switched to host if in virt mode so can't do local */ +if (!global && (mfmsr () & (MSR_IR |MSR_DR ))) + global =1 ; +if (!global) {/* any other core might now have stale TLB entries... */ smp_wmb ();
arch/powerpc/kvm/book3s_hv_rmhandlers.S +2 -12
@@ -888,14 +888,11 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) cmpdi r3, 512 /* 1 microsecond */ blt hdec_soon - /* For hash guest, clear out and reload the SLB */ -BEGIN_MMU_FTR_SECTION - /* Radix host won't have populated the SLB, so no need to clear */ + /* Clear out and reload the SLB */ li r6, 0 slbmte r6, r6 PPC_SLBIA(6) ptesync -END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) /* Load up guest SLB entries (N.B. slb_max will be 0 for radix) */ lwz r5,VCPU_SLB_MAX(r4)
@@ -1373,9 +1370,6 @@ guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */ stw r5,VCPU_SLB_MAX(r9) /* load host SLB entries */ -BEGIN_MMU_FTR_SECTION - b guest_bypass -END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) ld r8,PACA_SLBSHADOWPTR(r13) .rept SLB_NUM_BOLTED
@@ -3131,10 +3125,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_DAWR1) PPC_SLBIA(6) ptesync -BEGIN_MMU_FTR_SECTION - b 4f -END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) - /* load host SLB entries */ ld r8, PACA_SLBSHADOWPTR(r13) .rept SLB_NUM_BOLTED
@@ -3148,7 +3138,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) 3: addi r8, r8, 16 .endr -4: lwz r7, KVM_HOST_LPID(r10) + lwz r7, KVM_HOST_LPID(r10) mtspr SPRN_LPID, r7 mtspr SPRN_PID, r0 ld r8, KVM_HOST_LPCR(r10)
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 31/32 KVM: PPC: Book3S HV P9: implement hash host / hash guest support
In reply to Nicholas PigginImplement support for hash guests under hash host. This has to save and restore the host SLB, and ensure that the MMU is off while switching into the guest SLB.
POWER9 and later CPUs now always go via the P9 path. The "fast" guest mode is now renamed to the P9 mode, which is consistent with its functionality and the rest of the naming.
--- arch/powerpc/include/asm/kvm_asm.h | 2 +- arch/powerpc/kvm/book3s_64_entry.S | 15 +++++++---- arch/powerpc/kvm/book3s_hv.c | 4 ++- arch/powerpc/kvm/book3s_hv_p9_entry.c | 36 ++++++++++++++++++++++----- 4 files changed, 44 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +1 -1
@@ -147,7 +147,7 @@#define KVM_GUEST_MODE_SKIP 2#define KVM_GUEST_MODE_GUEST_HV 3#define KVM_GUEST_MODE_HOST_HV 4 -#define KVM_GUEST_MODE_HV_FAST 5/* ISA >= v3.0 host radix */ +#define KVM_GUEST_MODE_HV_P9 5/* ISA >= v3.0 path */ #define KVM_INST_FETCH_FAILED -1
arch/powerpc/kvm/book3s_64_entry.S +10 -5
@@ -36,7 +36,7 @@ kvmppc_hcall: #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE lbz r10,HSTATE_IN_GUEST(r13) - cmpwi r10,KVM_GUEST_MODE_HV_FAST + cmpwi r10,KVM_GUEST_MODE_HV_P9 beq kvmppc_p9_exit_hcall #endif ld r10,PACA_EXGEN+EX_R13(r13)
@@ -68,7 +68,7 @@ kvmppc_interrupt: #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE std r10,HSTATE_SCRATCH0(r13) lbz r10,HSTATE_IN_GUEST(r13) - cmpwi r10,KVM_GUEST_MODE_HV_FAST + cmpwi r10,KVM_GUEST_MODE_HV_P9 beq kvmppc_p9_exit_interrupt ld r10,HSTATE_SCRATCH0(r13) #endif
@@ -183,8 +183,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) /* * void kvmppc_p9_enter_guest(struct vcpu *vcpu); * - * Enter the guest on a ISAv3.0 or later system where we have exactly - * one vcpu per vcore, and the host is radix. + * Enter the guest on a ISAv3.0 or later system. */ .balign IFETCH_ALIGN_BYTES _GLOBAL(kvmppc_p9_enter_guest)
@@ -284,7 +283,7 @@ kvmppc_p9_exit_hcall: .balign IFETCH_ALIGN_BYTES kvmppc_p9_exit_interrupt: /* - * If set to KVM_GUEST_MODE_HV_FAST but we're still in the + * If set to KVM_GUEST_MODE_HV_P9 but we're still in the * hypervisor, that means we can't return from the entry stack. */ rldicl. r10,r12,64-MSR_HV_LG,63
@@ -358,6 +357,12 @@ kvmppc_p9_exit_interrupt: * effort for a small bit of code. Lots of other things to do first. */ kvmppc_p9_bad_interrupt: +BEGIN_MMU_FTR_SECTION + /* + * Hash host doesn't try to recover MMU (requires host SLB reload) + */ + b . +END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) /* * Clean up guest registers to give host a chance to run. */
arch/powerpc/kvm/book3s_hv.c +3 -1
@@ -4511,7 +4511,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu) vcpu->arch.state =KVMPPC_VCPU_BUSY_IN_HOST ; do { - if (radix_enabled()) + if (cpu_has_feature(CPU_FTR_ARCH_300)) r = kvmhv_run_single_vcpu(vcpu, ~(u64)0, vcpu->arch.vcore->lpcr); else
@@ -5599,6 +5599,8 @@ static int kvmhv_enable_nested(struct kvm *kvm)return -EPERM ;if (!cpu_has_feature (CPU_FTR_ARCH_300 ))return -ENODEV ; +if (!radix_enabled ()) +return -ENODEV ;/* kvm = NULL means the caller is testing if the capability exists */ if (kvm)
arch/powerpc/kvm/book3s_hv_p9_entry.c +30 -6
@@ -130,7 +130,7 @@ static void switch_mmu_to_guest_hpt(struct kvm *kvm, struct kvm_vcpu *vcpu, u64isync (); } -static void switch_mmu_to_host_radix (struct kvm *kvm,u32 pid) +static void switch_mmu_to_host (struct kvm *kvm,u32 pid) {isync ();mtspr (SPRN_PID , pid);
@@ -139,6 +139,22 @@ static void switch_mmu_to_host_radix(struct kvm *kvm, u32 pid)isync ();mtspr (SPRN_LPCR , kvm->arch.host_lpcr);isync (); + +if (!radix_enabled ()) +slb_restore_bolted_realmode (); +} + +static void save_clear_host_mmu (struct kvm *kvm) +{ +if (!radix_enabled ()) { +/* +* Hash host could save and restore host SLB entries to +* reduce SLB fault overheads of VM exits, but for now the +* existing code clears all entries and restores just the +* bolted ones when switching back to host. +*/ +slb_clear_invalidate_partition (); + } }static void save_clear_guest_mmu (struct kvm *kvm,struct kvm_vcpu *vcpu)
@@ -271,16 +287,24 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcmtspr (SPRN_AMOR , ~0UL ); - local_paca->kvm_hstate.in_guest =KVM_GUEST_MODE_HV_FAST ; + local_paca->kvm_hstate.in_guest =KVM_GUEST_MODE_HV_P9 ; + +/* +* Hash host, hash guest, or radix guest with prefetch bug, all have +* to disable the MMU before switching to guest MMU state. +*/ +if (!radix_enabled () || !kvm_is_radix (kvm) || +cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) +__mtmsrd (msr & ~(MSR_IR |MSR_DR |MSR_RI ),0 ); + +save_clear_host_mmu (kvm); +if (kvm_is_radix (kvm)) { -if (cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG )) -__mtmsrd (msr & ~(MSR_IR |MSR_DR |MSR_RI ),0 );switch_mmu_to_guest_radix (kvm, vcpu, lpcr);if (!cpu_has_feature (CPU_FTR_P9_RADIX_PREFETCH_BUG ))__mtmsrd (0 ,1 );/* clear RI */ }else { -__mtmsrd (msr & ~(MSR_IR |MSR_DR |MSR_RI ),0 );switch_mmu_to_guest_hpt (kvm, vcpu, lpcr); }
@@ -468,7 +492,7 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpcmtspr (SPRN_HDEC ,0x7fffffff );save_clear_guest_mmu (kvm, vcpu); -switch_mmu_to_host_radix (kvm, host_pidr); +switch_mmu_to_host (kvm, host_pidr); local_paca->kvm_hstate.in_guest =KVM_GUEST_MODE_NONE ;/*
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v7 32/32 KVM: PPC: Book3S HV: remove ISA v3.0 and v3.1 support from P7/8 path
In reply to Nicholas PigginPOWER9 and later processors always go via the P9 guest entry path now. Remove the remaining support from the P7/8 path.
--- arch/powerpc/kvm/book3s_hv.c | 62 ++-- arch/powerpc/kvm/book3s_hv_interrupts.S | 9 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 421 +----------------------- arch/powerpc/platforms/powernv/idle.c | 52 +-- 4 files changed, 43 insertions(+), 501 deletions(-)
arch/powerpc/kvm/book3s_hv.c +22 -40
@@ -130,9 +130,6 @@ static inline bool nesting_enabled(struct kvm *kvm)return kvm->arch.nested_enable &&kvm_is_radix (kvm); } -/* If set, the threads on each CPU core have to be in the same MMU mode */ -static bool no_mixing_hpt_and_radix__read_mostly ; -static int kvmppc_hv_setup_htab_rma (struct kvm_vcpu *vcpu);/*
@@ -3133,9 +3130,6 @@ static void prepare_threads(struct kvmppc_vcore *vc)for_each_runnable_thread (i, vcpu, vc) {if (signal_pending (vcpu->arch.run_task)) vcpu->arch.ret = -EINTR ; -else if (no_mixing_hpt_and_radix && -kvm_is_radix (vc->kvm) !=radix_enabled ()) - vcpu->arch.ret = -EINVAL ;else if (vcpu->arch.vpa.update_pending || vcpu->arch.slb_shadow.update_pending || vcpu->arch.dtl.update_pending)
@@ -3342,6 +3336,9 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)int trap;bool is_power8; +if (WARN_ON_ONCE (cpu_has_feature (CPU_FTR_ARCH_300 ))) +return ; +/* * Remove from the list any threads that have a signal pending * or need a VPA update done
@@ -3369,9 +3366,6 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)* Make sure we are running on primary threads, and that secondary * threads are offline. Also check if the number of threads in this * guest are greater than the current system threads per guest. -* On POWER9, we need to be not in independent-threads mode if -* this is a HPT guest on a radix host machine where the -* CPU threads may not be in different MMU modes. */ if ((controlled_threads >1 ) && ((vc->num_threads > threads_per_subcore) || !on_primary_thread ())) {
@@ -3395,18 +3389,6 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)if (vc->num_threads < target_threads)collect_piggybacks (&core_info, target_threads); -/* -* On radix, arrange for TLB flushing if necessary. -* This has to be done before disabling interrupts since -* it uses smp_call_function(). -*/ - pcpu =smp_processor_id (); -if (kvm_is_radix (vc->kvm)) { -for (sub =0 ; sub < core_info.n_subcores; ++sub) -for_each_runnable_thread (i, vcpu, core_info.vc[sub]) -kvmppc_prepare_radix_vcpu (vcpu, pcpu); - } -/* * Hard-disable interrupts, and check resched flag and signals. * If we need to reschedule or deliver a signal, clean up
@@ -3439,8 +3421,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc) cmd_bit = stat_bit =0 ; split = core_info.n_subcores; sip =NULL ; - is_power8 =cpu_has_feature (CPU_FTR_ARCH_207S ) - && !cpu_has_feature (CPU_FTR_ARCH_300 ); + is_power8 =cpu_has_feature (CPU_FTR_ARCH_207S );if (split >1 ) { sip = &split_info;
@@ -3738,8 +3719,7 @@ static inline bool hcall_is_xics(unsigned long req) }/* -* Virtual-mode guest entry for POWER9 and later when the host and -* guest are both using the radix MMU. The LPIDR has already been set. +* Guest entry for POWER9 and later CPUs. */ static int kvmhv_p9_guest_entry (struct kvm_vcpu *vcpu,u64 time_limit,unsigned long lpcr)
@@ -5762,11 +5742,25 @@ static int kvmhv_enable_dawr1(struct kvm *kvm)static bool kvmppc_hash_v3_possible (void ) { -if (radix_enabled () && no_mixing_hpt_and_radix) +if (!cpu_has_feature (CPU_FTR_ARCH_300 ))return false; -return cpu_has_feature (CPU_FTR_ARCH_300 ) && -cpu_has_feature (CPU_FTR_HVMODE ); +if (!cpu_has_feature (CPU_FTR_HVMODE )) +return false; + +/* +* POWER9 chips before version 2.02 can't have some threads in +* HPT mode and some in radix mode on the same core. +*/ +if (radix_enabled ()) { +unsigned int pvr =mfspr (SPRN_PVR ); +if ((pvr >>16 ) =PVR_POWER9 && + (((pvr &0xe000 ) =0 && (pvr &0xfff ) <0x202 ) || + ((pvr &0xe000 ) =0x2000 && (pvr &0xfff ) <0x101 ))) +return false; + } + +return true; }static struct kvmppc_ops kvm_ops_hv = {
@@ -5910,18 +5904,6 @@ static int kvmppc_book3s_init_hv(void)if (kvmppc_radix_possible ()) r =kvmppc_radix_init (); -/* -* POWER9 chips before version 2.02 can't have some threads in -* HPT mode and some in radix mode on the same core. -*/ -if (cpu_has_feature (CPU_FTR_ARCH_300 )) { -unsigned int pvr =mfspr (SPRN_PVR ); -if ((pvr >>16 ) =PVR_POWER9 && - (((pvr &0xe000 ) =0 && (pvr &0xfff ) <0x202 ) || - ((pvr &0xe000 ) =0x2000 && (pvr &0xfff ) <0x101 ))) - no_mixing_hpt_and_radix = true; - } - r =kvmppc_uvmem_init ();if (r <0 )pr_err ("KVM-HV: kvmppc_uvmem_init failed %d\n" , r);
arch/powerpc/kvm/book3s_hv_interrupts.S +2 -7
@@ -58,7 +58,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) /* * Put whatever is in the decrementer into the * hypervisor decrementer. - * Because of a hardware deviation in P8 and P9, + * Because of a hardware deviation in P8, * we need to set LPCR[HDICE] before writing HDEC. */ ld r5, HSTATE_KVM_VCORE(r13)
@@ -67,15 +67,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) ori r8, r9, LPCR_HDICE mtspr SPRN_LPCR, r8 isync - andis. r0, r9, LPCR_LD@h mfspr r8,SPRN_DEC mftb r7 -BEGIN_FTR_SECTION - /* On POWER9, don't sign-extend if host LPCR[LD] bit is set */ - bne 32f -END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) extsw r8,r8 -32: mtspr SPRN_HDEC,r8 + mtspr SPRN_HDEC,r8 add r8,r8,r7 std r8,HSTATE_DECEXP(r13)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +11 -410
699 lines not on this page · raw message
arch/powerpc/platforms/powernv/idle.c +8 -44
103 lines not on this page · raw message
Signature · 1 line
2.23.0
Michael Ellerman
AppliedQuoted 8 lines · Nicholas Piggin
Git tree here
https://github.com/npiggin/linux/tree/kvm-in-c-5.14-1
This series applies to upstream plus a couple of KVM regression fixes not yet in powerpc tree, which are included in the above git tree.
[...]
Applied to powerpc/topic/ppc-kvm.
[01/32] KVM: PPC: Book3S 64: move KVM interrupt entry to a common entry point
https://git.kernel.org/powerpc/c/f36011569b90b3973f07cea00c5872c4dc0c707f [02/32] KVM: PPC: Book3S 64: Move GUEST_MODE_SKIP test into KVM https://git.kernel.org/powerpc/c/f33e0702d98cc5ff21f44833525b07581862eb57 [03/32] KVM: PPC: Book3S 64: add hcall interrupt handler https://git.kernel.org/powerpc/c/31c67cfe2a6a5a7364dc1552b877c6b7820dd556 [04/32] KVM: PPC: Book3S 64: Move hcall early register setup to KVM https://git.kernel.org/powerpc/c/04ece7b60b689e1de38b9b0f597f8f94951e4367 [05/32] KVM: PPC: Book3S 64: Move interrupt early register setup to KVM https://git.kernel.org/powerpc/c/69fdd67499716efca861f7cecabdfeee5e5d7b51 [06/32] KVM: PPC: Book3S 64: move bad_host_intr check to HV handler https://git.kernel.org/powerpc/c/1b5821c630c219e3c6f643ebbefcf08c9fa714d8 [07/32] KVM: PPC: Book3S 64: Minimise hcall handler calling convention differences https://git.kernel.org/powerpc/c/e2762743c6328dde14290cd58ddf2175b068ad80 [08/32] KVM: PPC: Book3S HV P9: implement kvmppc_xive_pull_vcpu in C https://git.kernel.org/powerpc/c/023c3c96ca4d196c09d554d5a98900406e4d7ecb [09/32] KVM: PPC: Book3S HV P9: Move setting HDEC after switching to guest LPCR https://git.kernel.org/powerpc/c/413679e73bdfc2720dc2fa2172b65b7411185fa7 [10/32] KVM: PPC: Book3S HV P9: Reduce irq_work vs guest decrementer races https://git.kernel.org/powerpc/c/6ffe2c6e6dcefb971e4046f02086c4adadd0b310 [11/32] KVM: PPC: Book3S HV P9: Move xive vcpu context management into kvmhv_p9_guest_entry https://git.kernel.org/powerpc/c/09512c29167bd3792820caf83bcca4d4e5ac2266 [12/32] KVM: PPC: Book3S HV P9: Move radix MMU switching instructions together https://git.kernel.org/powerpc/c/48013cbc504e064d2318f24482cfbe3c53e0a812 [13/32] KVM: PPC: Book3S HV P9: Stop handling hcalls in real-mode in the P9 path https://git.kernel.org/powerpc/c/9dc2babc185e0a24fbb48098daafd552cac157fa [14/32] KVM: PPC: Book3S HV P9: Implement the rest of the P9 path in C https://git.kernel.org/powerpc/c/89d35b23910158a9add33a206e973f4227906d3c [15/32] KVM: PPC: Book3S HV P9: inline kvmhv_load_hv_regs_and_go into __kvmhv_vcpu_entry_p9 https://git.kernel.org/powerpc/c/c00366e2375408e43370cd7981af3354f7c83ed3 [16/32] KVM: PPC: Book3S HV P9: Read machine check registers while MSR[RI] is 0 https://git.kernel.org/powerpc/c/6d770e3fe9a120560cda66331ce5faa363400e97 [17/32] KVM: PPC: Book3S HV P9: Improve exit timing accounting coverage https://git.kernel.org/powerpc/c/a32ed1bb70723ec7a6c888b6c7071d516cca0e8f [18/32] KVM: PPC: Book3S HV P9: Move SPR loading after expiry time check https://git.kernel.org/powerpc/c/68e3baaca8c56bbb336d2215f201f4047ce736e5 [19/32] KVM: PPC: Book3S HV P9: Add helpers for OS SPR handling https://git.kernel.org/powerpc/c/edba6aff4f2c3893e168df6a2e9a20f3c39b0b30 [20/32] KVM: PPC: Book3S HV P9: Switch to guest MMU context as late as possible https://git.kernel.org/powerpc/c/41f779917669fcc28a7f5646d1f7a85043c9d152 [21/32] KVM: PPC: Book3S HV: Implement radix prefetch workaround by disabling MMU https://git.kernel.org/powerpc/c/2e1ae9cd56f8616a707185f3c6cb7ee2a20809e1 [22/32] KVM: PPC: Book3S HV: Remove support for dependent threads mode on P9 https://git.kernel.org/powerpc/c/aaae8c79005846eeafc7a0e5d3eda4e34ea8ca2e [23/32] KVM: PPC: Book3S HV: Remove radix guest support from P7/8 path https://git.kernel.org/powerpc/c/9769a7fd79b65a6a6f8362154ab59c36d0defbf3 [24/32] KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers https://git.kernel.org/powerpc/c/dcbac73a5b374873bd6dfd8a0ee5d0b7fc844420 [25/32] KVM: PPC: Book3S HV: Remove unused nested HV tests in XICS emulation https://git.kernel.org/powerpc/c/2ce008c8b25467ceacf45bcf0e183d660edb82f2 [26/32] KVM: PPC: Book3S HV P9: Allow all P9 processors to enable nested HV https://git.kernel.org/powerpc/c/cbcff8b1c53e458ed4e23877048d7268fd13ab8a [27/32] KVM: PPC: Book3S HV: small pseries_do_hcall cleanup https://git.kernel.org/powerpc/c/a9aa86e08b3a0b2c273cdb772283c872e55f14bf [28/32] KVM: PPC: Book3S HV: add virtual mode handlers for HPT hcalls and page faults https://git.kernel.org/powerpc/c/6165d5dd99dbaec7a309491c3951bd81fc89978d [29/32] KVM: PPC: Book3S HV P9: Reflect userspace hcalls to hash guests to support PR KVM https://git.kernel.org/powerpc/c/ac3c8b41c27ea112daed031f852a4b361c11a03e [30/32] KVM: PPC: Book3S HV P9: implement hash guest support https://git.kernel.org/powerpc/c/079a09a500c399f804effcf9bb49214cdfa698e5 [31/32] KVM: PPC: Book3S HV P9: implement hash host / hash guest support https://git.kernel.org/powerpc/c/0bf7e1b2e9a496e1ebca9e3e1f53c7e98add4417 [32/32] KVM: PPC: Book3S HV: remove ISA v3.0 and v3.1 support from P7/8 path https://git.kernel.org/powerpc/c/fae5c9f3664ba278137e54a2083b39b90c64093a
cheers