KVM: PPC: support kvm selftests
Subsystems (3)
Nicholas Piggin
reviewercover KVM: PPC: support kvm selftests
Hi,
This series adds initial KVM selftests support for powerpc (64-bit, BookS). It spans 3 maintainers but it does not really affect arch/powerpc, and it is well contained in selftests code, just touches some makefiles and a tiny bit headers so conflicts should be unlikely and trivial.
I guess Paolo is the best point to merge these, if no comments or objections?
Thanks,
Nick
Nicholas Piggin (2):
KVM: PPC: Add kvm selftests support for powerpc
KVM: PPC: Add basic framework tests for kvm selftests
tools/testing/selftests/kvm/Makefile | 14 + .../selftests/kvm/include/kvm_util_base.h | 13 + .../selftests/kvm/include/powerpc/hcall.h | 22 ++ .../selftests/kvm/include/powerpc/processor.h | 13 + tools/testing/selftests/kvm/lib/kvm_util.c | 10 + .../testing/selftests/kvm/lib/powerpc/hcall.c | 45 +++ .../selftests/kvm/lib/powerpc/processor.c | 355 ++++++++++++++++++ .../testing/selftests/kvm/lib/powerpc/ucall.c | 30 ++ .../testing/selftests/kvm/powerpc/null_test.c | 186 +++++++++ .../selftests/kvm/powerpc/rtas_hcall.c | 146 +++++++ 10 files changed, 834 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/powerpc/hcall.h create mode 100644 tools/testing/selftests/kvm/include/powerpc/processor.h create mode 100644 tools/testing/selftests/kvm/lib/powerpc/hcall.c create mode 100644 tools/testing/selftests/kvm/lib/powerpc/processor.c create mode 100644 tools/testing/selftests/kvm/lib/powerpc/ucall.c create mode 100644 tools/testing/selftests/kvm/powerpc/null_test.c create mode 100644 tools/testing/selftests/kvm/powerpc/rtas_hcall.c
Signature · 1 line
2.37.2
Nicholas Piggin
reviewerPATCH 1/2 KVM: PPC: Add kvm selftests support for powerpc
Implement KVM selftests support for Book3S-64.
ucalls are implemented with an unsuppored PAPR hcall number which causes KVM to exit to userspace.
Virtual memory is only implemented for 64K page size and the radix MMU, and only the base page size is supported for now.
--- tools/testing/selftests/kvm/Makefile | 12 + .../selftests/kvm/include/kvm_util_base.h | 13 + .../selftests/kvm/include/powerpc/hcall.h | 20 + .../selftests/kvm/include/powerpc/processor.h | 13 + tools/testing/selftests/kvm/lib/kvm_util.c | 10 + .../testing/selftests/kvm/lib/powerpc/hcall.c | 45 +++ .../selftests/kvm/lib/powerpc/processor.c | 355 ++++++++++++++++++ .../testing/selftests/kvm/lib/powerpc/ucall.c | 30 ++ 8 files changed, 498 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/powerpc/hcall.h create mode 100644 tools/testing/selftests/kvm/include/powerpc/processor.h create mode 100644 tools/testing/selftests/kvm/lib/powerpc/hcall.c create mode 100644 tools/testing/selftests/kvm/lib/powerpc/processor.c create mode 100644 tools/testing/selftests/kvm/lib/powerpc/ucall.c
tools/testing/selftests/kvm/Makefile +12 -0
@@ -55,6 +55,10 @@ LIBKVM_s390x += lib/s390x/ucall.c LIBKVM_riscv += lib/riscv/processor.c LIBKVM_riscv += lib/riscv/ucall.c +LIBKVM_powerpc += lib/powerpc/processor.c +LIBKVM_powerpc += lib/powerpc/ucall.c +LIBKVM_powerpc += lib/powerpc/hcall.c + # Non-compiled test targets TEST_PROGS_x86_64 += x86_64/nx_huge_pages_test.sh
@@ -176,6 +180,14 @@ TEST_GEN_PROGS_riscv += kvm_page_table_test TEST_GEN_PROGS_riscv += set_memory_region_test TEST_GEN_PROGS_riscv += kvm_binary_stats_test +TEST_GEN_PROGS_powerpc += demand_paging_test +TEST_GEN_PROGS_powerpc += dirty_log_test +TEST_GEN_PROGS_powerpc += kvm_create_max_vcpus +TEST_GEN_PROGS_powerpc += kvm_page_table_test +TEST_GEN_PROGS_powerpc += rseq_test +TEST_GEN_PROGS_powerpc += set_memory_region_test +TEST_GEN_PROGS_powerpc += kvm_binary_stats_test + TEST_PROGS += $(TEST_PROGS_$(ARCH_DIR)) TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(ARCH_DIR)) TEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(ARCH_DIR))
tools/testing/selftests/kvm/include/kvm_util_base.h +13 -0
@@ -105,6 +105,7 @@ struct kvm_vm {bool pgd_created;vm_paddr_t ucall_mmio_addr;vm_paddr_t pgd; +vm_paddr_t prtb;// powerpc process table vm_vaddr_t gdt;vm_vaddr_t tss;vm_vaddr_t idt;
@@ -160,6 +161,7 @@ enum vm_guest_mode {VM_MODE_PXXV48_4K ,/* For 48bits VA but ANY bits PA */ VM_MODE_P47V64_4K ,VM_MODE_P44V64_4K , +VM_MODE_P52V52_64K ,VM_MODE_P36V48_4K ,VM_MODE_P36V48_16K , VM_MODE_P36V48_64K,
@@ -197,6 +199,17 @@ extern enum vm_guest_mode vm_mode_default;#define MIN_PAGE_SHIFT 12U#define ptes_per_page (page_size) ((page_size) / 8) +#elif defined(__powerpc64__) + +/* Radix guest EA and RA are 52-bit on POWER9 and POWER10 */ +#define VM_MODE_DEFAULT VM_MODE_P52V52_64K +#define MIN_PAGE_SHIFT 12U /// XXX: hack to allocate more page table memory because we aren't allocating page tables well on 64K base page size +#define ptes_per_page (page_size) ((page_size) / 8) + +#else + +#error "KVM selftests not implemented for architecture" +#endif #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT)
tools/testing/selftests/kvm/include/powerpc/hcall.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* powerpc hcall defines +*/ +#ifndef SELFTEST_KVM_HCALL_H +#define SELFTEST_KVM_HCALL_H + +#include <linux/compiler.h> + +/* Ucalls use unimplemented PAPR hcall 0 which exits KVM */ +#define H_UCALL 0 +#define UCALL_R4_UCALL 0x5715 // regular ucall, r5 contains ucall pointer +#define UCALL_R4_EXCPT 0x1b0f // other exception, r5 contains vector, r6,7 SRRs +// R4==0 is a simple asm exit + +int64_t hcall0 (uint64_t token); +int64_t hcall1 (uint64_t token,uint64_t arg1); +int64_t hcall2 (uint64_t token,uint64_t arg1,uint64_t arg2); + +#endif
tools/testing/selftests/kvm/include/powerpc/processor.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* powerpc processor specific defines +*/ +#ifndef SELFTEST_KVM_PROCESSOR_H +#define SELFTEST_KVM_PROCESSOR_H + +#include <linux/compiler.h> + +struct kvm_vcpu ; +extern bool (*interrupt_handler)(struct kvm_vcpu *vcpu,unsigned trap); + +#endif
tools/testing/selftests/kvm/lib/kvm_util.c +10 -0
@@ -153,6 +153,7 @@ const char *vm_guest_mode_string(uint32_t i) [VM_MODE_PXXV48_4K] = "PA-bits:ANY, VA-bits:48, 4K pages", [VM_MODE_P47V64_4K] = "PA-bits:47, VA-bits:64, 4K pages", [VM_MODE_P44V64_4K] = "PA-bits:44, VA-bits:64, 4K pages", + [VM_MODE_P52V52_64K] = "PA-bits:52, VA-bits:52, 64K pages", [VM_MODE_P36V48_4K] = "PA-bits:36, VA-bits:48, 4K pages", [VM_MODE_P36V48_16K] = "PA-bits:36, VA-bits:48, 16K pages", [VM_MODE_P36V48_64K] = "PA-bits:36, VA-bits:48, 64K pages",
@@ -178,6 +179,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = { [VM_MODE_PXXV48_4K] = { 0, 0, 0x1000, 12 }, [VM_MODE_P47V64_4K] = { 47, 64, 0x1000, 12 }, [VM_MODE_P44V64_4K] = { 44, 64, 0x1000, 12 }, + [VM_MODE_P52V52_64K] = { 52, 52, 0x10000, 16 }, [VM_MODE_P36V48_4K] = { 36, 48, 0x1000, 12 }, [VM_MODE_P36V48_16K] = { 36, 48, 0x4000, 14 }, [VM_MODE_P36V48_64K] = { 36, 48, 0x10000, 16 },
@@ -279,6 +281,14 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode)case VM_MODE_P44V64_4K : vm->pgtable_levels =5 ;break ; +case VM_MODE_P52V52_64K : +#ifdef __powerpc__ +TEST_ASSERT (getpagesize () ==64 *1024 , +"KVM selftests requires 64K host page size\n" ); + + vm->pgtable_levels =4 ; +#endif +break ;default :TEST_FAIL ("Unknown guest mode, mode: 0x%x" , mode); }
tools/testing/selftests/kvm/lib/powerpc/hcall.c new file +45 -0
45 lines not on this page · raw message
tools/testing/selftests/kvm/lib/powerpc/processor.c new file +355 -0
355 lines not on this page · raw message
tools/testing/selftests/kvm/lib/powerpc/ucall.c new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* ucall support. A ucall is a "hypercall to host userspace". +*/ +#include "kvm_util.h" +#include "hcall.h" + +void ucall_arch_init (struct kvm_vm *vm,vm_paddr_t mmio_gpa) +{ +} + +void ucall_arch_do_ucall (vm_vaddr_t uc) +{ +hcall2 (H_UCALL ,UCALL_R4_UCALL , (uintptr_t )(uc)); +} + +void *ucall_arch_get_ucall (struct kvm_vcpu *vcpu) +{ +struct kvm_run *run = vcpu->run; + +if (run->exit_reason ==KVM_EXIT_PAPR_HCALL && + run->papr_hcall.nr ==H_UCALL ) { +struct kvm_regs regs; + +vcpu_regs_get (vcpu, ®s); +if (regs.gpr[4 ] ==UCALL_R4_UCALL ) +return (void *)regs.gpr[5 ]; + } +return NULL ; +}
Signature · 1 line
2.37.2
Sean Christopherson
reviewerRe: [PATCH 1/2] KVM: PPC: Add kvm selftests support for powerpc
Quoted 21 lines · Nicholas Piggin
tools/testing/selftests/kvm/lib/kvm_util.c +2
-0@@ -153,6 +153,7 @@ const char *vm_guest_mode_string(uint32_t i) [VM_MODE_PXXV48_4K] = "PA-bits:ANY, VA-bits:48, 4K pages", [VM_MODE_P47V64_4K] = "PA-bits:47, VA-bits:64, 4K pages", [VM_MODE_P44V64_4K] = "PA-bits:44, VA-bits:64, 4K pages", + [VM_MODE_P52V52_64K] = "PA-bits:52, VA-bits:52, 64K pages", [VM_MODE_P36V48_4K] = "PA-bits:36, VA-bits:48, 4K pages", [VM_MODE_P36V48_16K] = "PA-bits:36, VA-bits:48, 16K pages", [VM_MODE_P36V48_64K] = "PA-bits:36, VA-bits:48, 64K pages",@@ -178,6 +179,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = { [VM_MODE_PXXV48_4K] = { 0, 0, 0x1000, 12 }, [VM_MODE_P47V64_4K] = { 47, 64, 0x1000, 12 }, [VM_MODE_P44V64_4K] = { 44, 64, 0x1000, 12 }, + [VM_MODE_P52V52_64K] = { 52, 52, 0x10000, 16 }, [VM_MODE_P36V48_4K] = { 36, 48, 0x1000, 12 }, [VM_MODE_P36V48_16K] = { 36, 48, 0x4000, 14 }, [VM_MODE_P36V48_64K] = { 36, 48, 0x10000, 16 },
tools/testing/selftests/kvm/lib/kvm_util.c struct kvm_vm *____vm_create(enum vm_guest_mode mode) · line 286
Quoted 6 lines
tools/testing/selftests/kvm/lib/kvm_util.c +3
-0@@ -279,6 +281,14 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode)case VM_MODE_P44V64_4K : vm->pgtable_levels =5 ;break ; +case VM_MODE_P52V52_64K : +#ifdef __powerpc__ + TEST_ASSERT(getpagesize() == 64*1024,
This can use SZ_64K (we really need to convert a bunch of open coded stuff...)
tools/testing/selftests/kvm/lib/kvm_util.c struct kvm_vm *____vm_create(enum vm_guest_mode mode) · line 287
Quoted 1 line
tools/testing/selftests/kvm/lib/kvm_util.c +1
-0+ "KVM selftests requires 64K host page size\n");
What is the actual requirement? E.g. is it that the host and guest page sizes must match, or is that the selftest setup itself only supports 64KiB pages? If it's the former, would it make sense to assert outside of the switch statement, e.g.
tools/testing/selftests/kvm/lib/kvm_util.c +4 -0
@@ -291,6 +291,10 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode)#ifdef __aarch64__if (vm->pa_bits !=40 ) vm->type =KVM_VM_TYPE_ARM_IPA_SIZE (vm->pa_bits); +#endif +#ifdef __powerpc__ +TEST_ASSERT (getpagesize () == vm->page_size,"blah blah blah" ); +#endif vm_open (vm);
If it's the latter (selftests limitation), can you add a comment explaining the limitation?
tools/testing/selftests/kvm/lib/kvm_util.c struct kvm_vm *____vm_create(enum vm_guest_mode mode)
Quoted 9 lines
tools/testing/selftests/kvm/lib/kvm_util.c +9
-0+void virt_arch_pgd_alloc (struct kvm_vm *vm) +{ +struct kvm_ppc_mmuv3_cfg mmu_cfg; +vm_paddr_t prtb, pgtb; +uint64_t *proc_table, *page_table; +size_t pgd_pages; + +TEST_ASSERT (vm->mode ==VM_MODE_P52V52_64K ,"Attempt to use " +"unknown or unsupported guest mode, mode: 0x%x" , vm->mode);
Please don't split quoted lines, especially when it's easily avoided, e.g.
TEST_ASSERT(vm->mode == VM_MODE_P52V52_64K, "PPC doesn't support guest mode '0x%x', vm->mode);
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 4 lines
tools/testing/selftests/kvm/lib/kvm_util.c +4
-0+ +/* If needed, create page table */ +if (vm->pgd_created) +return ;
Heh, every arch has this. Any objection to moving the check to virt_pgd_alloc() as a prep patch?
Quoted 131 lines
tools/testing/selftests/kvm/lib/kvm_util.c +131
-0+ + prtb =vm_phy_page_alloc (vm,KVM_GUEST_PAGE_TABLE_MIN_PADDR , + vm->memslots[MEM_REGION_PT ]); + proc_table =addr_gpa2hva (vm, prtb); +memset (proc_table,0 , vm->page_size); + vm->prtb = prtb; + + pgd_pages =1UL << ((RADIX_PGD_INDEX_SIZE +3 ) >> vm->page_shift); +TEST_ASSERT (pgd_pages ==1 ,"PGD allocation must be single page" ); + pgtb =vm_phy_page_alloc (vm,KVM_GUEST_PAGE_TABLE_MIN_PADDR , + vm->memslots[MEM_REGION_PT ]); + page_table =addr_gpa2hva (vm, pgtb); +memset (page_table,0 , vm->page_size * pgd_pages); + vm->pgd = pgtb; + +/* Set the base page directory in the proc table */ + proc_table[0 ] =cpu_to_be64 (pgtb |RTS |RADIX_PGD_INDEX_SIZE ); + + mmu_cfg.process_table = prtb |0x8000000000000000UL |0x4 ;// 64K size + mmu_cfg.flags =KVM_PPC_MMUV3_RADIX |KVM_PPC_MMUV3_GTSE ; + +vm_ioctl (vm,KVM_PPC_CONFIGURE_V3_MMU , &mmu_cfg); + + vm->pgd_created = true; +} + +static int pt_shift (struct kvm_vm *vm,int level) +{ +switch (level) { +case 1 : +return 13 ; +case 2 : +case 3 : +return 9 ; +case 4 : +return 5 ; +default : +TEST_ASSERT (false,"Invalid page table level %d\n" , level); +return 0 ; + } +} + +static uint64_t pt_entry_coverage (struct kvm_vm *vm,int level) +{ +uint64_t size = vm->page_size; + +if (level ==4 ) +return size; + size <<=pt_shift (vm,4 ); +if (level ==3 ) +return size; + size <<=pt_shift (vm,3 ); +if (level ==2 ) +return size; + size <<=pt_shift (vm,2 ); +return size; +} + +static int pt_idx (struct kvm_vm *vm,uint64_t vaddr,int level,uint64_t *nls) +{ +switch (level) { +case 1 : + *nls =0x9 ; +return (vaddr >>39 ) &0x1fff ; +case 2 : + *nls =0x9 ; +return (vaddr >>30 ) &0x1ff ; +case 3 : +// 4K *nls = 0x9; + *nls =0x5 ; +return (vaddr >>21 ) &0x1ff ; +case 4 : +// 4K return (vaddr >> 12) & 0x1ff; +return (vaddr >>16 ) &0x1f ; +default : +TEST_ASSERT (false,"Invalid page table level %d\n" , level); +return 0 ; + } +} + +static uint64_t *virt_get_pte (struct kvm_vm *vm,vm_paddr_t pt, +uint64_t vaddr,int level,uint64_t *nls) +{ +uint64_t *page_table =addr_gpa2hva (vm, pt); +int idx =pt_idx (vm, vaddr, level, nls); + +return &page_table[idx]; +} + +#define PTE_VALID 0x8000000000000000ull +#define PTE_LEAF 0x4000000000000000ull +#define PTE_REFERENCED 0x0000000000000100ull +#define PTE_CHANGED 0x0000000000000080ull +#define PTE_PRIV 0x0000000000000008ull +#define PTE_READ 0x0000000000000004ull +#define PTE_RW 0x0000000000000002ull +#define PTE_EXEC 0x0000000000000001ull +#define PTE_PAGE_MASK 0x01fffffffffff000ull + +#define PDE_VALID PTE_VALID +#define PDE_NLS 0x0000000000000011ull +#define PDE_PT_MASK 0x0fffffffffffff00ull + +void virt_arch_pg_map (struct kvm_vm *vm,uint64_t gva,uint64_t gpa) +{ +vm_paddr_t pt = vm->pgd; +uint64_t *ptep, pte; +int level; + +for (level =1 ; level <=3 ; level++) { +uint64_t nls; +uint64_t *pdep =virt_get_pte (vm, pt, gva, level, &nls); +uint64_t pde =be64_to_cpu (*pdep); +uint64_t *page_table; + +if (pde) { +TEST_ASSERT ((pde &PDE_VALID ) && !(pde &PTE_LEAF ), +"Invalid PDE at level: %u gva: 0x%lx pde:0x%lx\n" , + level, gva, pde); + pt = pde &PDE_PT_MASK ; +continue ; + } + +// XXX: 64K geometry does not require full pages! + pt =vm_phy_page_alloc (vm, +KVM_GUEST_PAGE_TABLE_MIN_PADDR , + vm->memslots[MEM_REGION_PT ]); + page_table =addr_gpa2hva (vm, pt); +memset (page_table,0 , vm->page_size); + pde =PDE_VALID | nls | pt; + *pdep =cpu_to_be64 (pde);
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 10 lines
tools/testing/selftests/kvm/lib/kvm_util.c +10
-0+ } + + ptep =virt_get_pte (vm, pt, gva, level,NULL ); + pte =be64_to_cpu (*ptep); + +TEST_ASSERT (!pte, +"PTE already present at level: %u gva: 0x%lx pte:0x%lx\n" , + level, gva, pte); + + pte =PTE_VALID |PTE_LEAF |PTE_REFERENCED |PTE_CHANGED |PTE_PRIV |PTE_READ |PTE_RW |PTE_EXEC | (gpa &PTE_PAGE_MASK );
Please wrap at 80 chars when it's convenient. The general/unofficial style in KVM is to honor the old 80 char limit unless there's a good reason not to. E.g. wrapping a line just because the terminating semicolon bumped past 80 is absurd.
Quoted 18 lines
tools/testing/selftests/kvm/lib/kvm_util.c +18
-0+ *ptep =cpu_to_be64 (pte); +} + +vm_paddr_t addr_arch_gva2gpa (struct kvm_vm *vm,vm_vaddr_t gva) +{ +vm_paddr_t pt = vm->pgd; +uint64_t *ptep, pte; +int level; + +for (level =1 ; level <=3 ; level++) { +uint64_t nls; +uint64_t *pdep =virt_get_pte (vm, pt, gva, level, &nls); +uint64_t pde =be64_to_cpu (*pdep); + +TEST_ASSERT ((pde &PDE_VALID ) && !(pde &PTE_LEAF ), +"PDE not present at level: %u gva: 0x%lx pde:0x%lx\n" , + level, gva, pde); + pt = pde &PDE_PT_MASK ;
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 10 lines
tools/testing/selftests/kvm/lib/kvm_util.c +10
-0+ } + + ptep =virt_get_pte (vm, pt, gva, level,NULL ); + pte =be64_to_cpu (*ptep); + +TEST_ASSERT (pte, +"PTE not present at level: %u gva: 0x%lx pte:0x%lx\n" , + level, gva, pte); + + TEST_ASSERT((pte & PTE_VALID) && (pte & PTE_LEAF) && (pte & PTE_READ) && (pte & PTE_RW) && (pte & PTE_EXEC),
Wrap here as well.
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 7 lines
tools/testing/selftests/kvm/lib/kvm_util.c +7
-0+"PTE not valid at level: %u gva: 0x%lx pte:0x%lx\n" , + level, gva, pte); + +return (pte &PTE_PAGE_MASK ) + (gva & (vm->page_size -1 )); +} + +static void virt_arch_dump_pt (FILE *stream,struct kvm_vm *vm,vm_paddr_t pt,vm_vaddr_t va,int level,uint8_t indent)
And here. Actually, why bother with the helper? There's one caller, and that callers checks pgd_created, i.e. is already assuming its dumping only page tables. Ooh, nevermind, it's recursive.
Can you drop "arch" from the name? Selftests uses "arch" to tag functions that are provided by arch code for use in generic code.
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 8 lines
tools/testing/selftests/kvm/lib/kvm_util.c +8
-0+{ +uint64_t *page_table; +int size, idx; + + page_table =addr_gpa2hva (vm, pt); + size =1U <<pt_shift (vm, level); +for (idx =0 ; idx < size; idx++) { +uint64_t pte =be64_to_cpu (page_table[idx]);
Newline after variable declaration.
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 2 lines
tools/testing/selftests/kvm/lib/kvm_util.c +2
-0+if (pte &PTE_VALID ) { +if (pte &PTE_LEAF ) {
Curly braces aren't necessary.
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 1 line
tools/testing/selftests/kvm/lib/kvm_util.c +1
-0+fprintf (stream,"%*sgVA:0x%016lx -> gRA:0x%016llx\n" , indent,"" , va, pte &PTE_PAGE_MASK );
Probably worth wrapping here too.
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 5 lines
tools/testing/selftests/kvm/lib/kvm_util.c +5
-0+ }else { +virt_arch_dump_pt (stream, vm, pte &PDE_PT_MASK , va, level +1 , indent); + } + } + va +=pt_entry_coverage (vm, level);
The shift is constant for vm+level, correct? In that case, can't this be written as
for (idx = 0; idx < size; idx++, va += va_coverage) {or even without a snapshot
for (idx = 0; idx < size; idx++, va += pt_entry_coverage(vm, level)) {That would allow
if (!(pte & PTE_VALID) continue
to reduce the indentation of the printing.
Quoted 8 lines
tools/testing/selftests/kvm/lib/kvm_util.c +8
-0+ } + +} + +void virt_arch_dump (FILE *stream,struct kvm_vm *vm,uint8_t indent) +{ +vm_paddr_t pt = vm->pgd; +
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 10 lines
tools/testing/selftests/kvm/lib/kvm_util.c +10
-0+if (!vm->pgd_created) +return ; + +virt_arch_dump_pt (stream, vm, pt,0 ,1 , indent); +} + +struct kvm_vcpu *vm_arch_vcpu_add (struct kvm_vm *vm,uint32_t vcpu_id, +void *guest_code) +{ +size_t stack_size =64 *1024 ;
SZ_64K
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 6 lines
tools/testing/selftests/kvm/lib/kvm_util.c +6
-0+uint64_t stack_vaddr; +struct kvm_regs regs; +struct kvm_vcpu *vcpu; +uint64_t lpcr; + + TEST_ASSERT(vm->page_size == 64*1024, "Unsupported page size: 0x%x",
SZ_64K
Quoted 12 lines
tools/testing/selftests/kvm/lib/kvm_util.c +12
-0+ vm->page_size); + + stack_vaddr =__vm_vaddr_alloc (vm, stack_size, +DEFAULT_GUEST_STACK_VADDR_MIN , +MEM_REGION_DATA ); + + vcpu =__vm_vcpu_add (vm, vcpu_id); + +vcpu_enable_cap (vcpu,KVM_CAP_PPC_PAPR ,1 ); + +/* Setup guest registers */ +vcpu_regs_get (vcpu, ®s);
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 10 lines
tools/testing/selftests/kvm/lib/kvm_util.c +10
-0+vcpu_get_reg (vcpu,KVM_REG_PPC_LPCR_64 , &lpcr); + + regs.pc = (uintptr_t )guest_code; + regs.gpr[12 ] = (uintptr_t )guest_code; + regs.msr =0x8000000002103032ull ; + regs.gpr[1 ] = stack_vaddr + stack_size -256 ; + +if (BYTE_ORDER ==LITTLE_ENDIAN ) { + regs.msr |=0x1 ;// LE + lpcr |=0x0000000002000000 ;// ILE
Would it be appropriate to add #defines to processor.h instead of open coding the magic numbers?
Quoted 7 lines
tools/testing/selftests/kvm/lib/kvm_util.c +7
-0+ }else { + lpcr &= ~0x0000000002000000 ;// !ILE + } + +vcpu_regs_set (vcpu, ®s); +vcpu_set_reg (vcpu,KVM_REG_PPC_LPCR_64 , lpcr); +
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 10 lines
tools/testing/selftests/kvm/lib/kvm_util.c +10
-0+return vcpu; +} + +void vcpu_args_set (struct kvm_vcpu *vcpu,unsigned int num, ...) +{ +va_list ap; +struct kvm_regs regs; +int i; + + TEST_ASSERT(num >= 1 && num <= 5, "Unsupported number of args,\n"
Newlines in TEST_ASSERT() usually lead to weird formatting.
tools/testing/selftests/kvm/lib/kvm_util.c
Quoted 1 line
tools/testing/selftests/kvm/lib/kvm_util.c +1
-0+ " num: %u\n",
No quoted line wrap please. And in this case, not wrapping is better IMO.
TEST_ASSERT(num >= 1 && num <= 5, "Unsupported number of args: %u", num);
Quoted 11 lines
tools/testing/selftests/kvm/lib/kvm_util.c +11
-0+ num); + +va_start (ap, num); +vcpu_regs_get (vcpu, ®s); + +for (i =0 ; i < num; i++) + regs.gpr[i +3 ] =va_arg (ap, uint64_t); + +vcpu_regs_set (vcpu, ®s); +va_end (ap); +}
Nicholas Piggin
reviewerRe: [PATCH 1/2] KVM: PPC: Add kvm selftests support for powerpc
Hey thanks for the review. Points about formatting and style all valid, I'll tidy those up. For the others,
Quoted 28 lines · Sean Christopherson
Review
Quoted 2 lines · Nicholas Piggin
(quoted diff) +2
-0+#ifdef __powerpc__ + TEST_ASSERT(getpagesize() == 64*1024,This can use
SZ_64K(we really need to convert a bunch of open coded stuff...)Review
Quoted 1 line
(quoted diff) +1
-0+ "KVM selftests requires 64K host page size\n");What is the actual requirement? E.g. is it that the host and guest page sizes must match, or is that the selftest setup itself only supports 64KiB pages? If it's the former, would it make sense to assert outside of the switch statement, e.g.
tools/testing/selftests/kvm/lib/kvm_util.c +4
-0@@ -291,6 +291,10 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode)#ifdef __aarch64__if (vm->pa_bits !=40 ) vm->type =KVM_VM_TYPE_ARM_IPA_SIZE (vm->pa_bits); +#endif +#ifdef __powerpc__ +TEST_ASSERT (getpagesize () == vm->page_size,"blah blah blah" ); +#endif vm_open (vm);
Quoted 2 lines
If it's the latter (selftests limitation), can you add a comment explaining the limitation?
It's the selftests setup, requires both host and guest to be 64k page size. I think it shouldn't be *too* hard to add any mix of 64k/4k, but there are a few quirks like requiring pgd to have 64k size allocation. 64/64 is the most important for us, but it would be nice to get other combos working soon if nothing else than because they don't get as much testing in other ways.
I can add a comment.
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ + /* If needed, create page table */ + if (vm->pgd_created) + return;Heh, every arch has this. Any objection to moving the check to
virt_pgd_alloc()as a prep patch?
I have no objection, I can do that for the next spin.
Quoted 12 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ "PTE not valid at level: %u gva: 0x%lx pte:0x%lx\n", + level, gva, pte); + + return (pte & PTE_PAGE_MASK) + (gva & (vm->page_size - 1)); +} + +static void virt_arch_dump_pt(FILE *stream, struct kvm_vm *vm, vm_paddr_t pt, vm_vaddr_t va, int level, uint8_t indent)And here. Actually, why bother with the helper? There's one caller, and that callers checks
pgd_created, i.e. is already assuming its dumping only page tables. Ooh, nevermind, it's recursive.
Quoted 2 lines
Can you drop "arch" from the name? Selftests uses "arch" to tag functions that are provided by arch code for use in generic code.
Yeah agree, I'll drop that.
Quoted 13 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ } else { + virt_arch_dump_pt(stream, vm, pte & PDE_PT_MASK, va, level + 1, indent); + } + } + va += pt_entry_coverage(vm, level);The shift is constant for vm+level, correct? In that case, can't this be written as
for (idx = 0; idx < size; idx++, va += va_coverage) {or even without a snapshot
Quoted 8 lines
for (idx = 0; idx < size; idx++, va += pt_entry_coverage(vm, level)) {That would allow
if (!(pte & PTE_VALID) continueto reduce the indentation of the printing.
It is constant for a given (vm, level). Good thinking, that should work.
Quoted 15 lines
Quoted 15 lines
(quoted diff) +15
-0+ stack_vaddr = __vm_vaddr_alloc(vm, stack_size, + DEFAULT_GUEST_STACK_VADDR_MIN, + MEM_REGION_DATA); + + vcpu = __vm_vcpu_add(vm, vcpu_id); + + vcpu_enable_cap(vcpu, KVM_CAP_PPC_PAPR, 1); + + /* Setup guest registers */ + vcpu_regs_get(vcpu, ®s); + vcpu_get_reg(vcpu, KVM_REG_PPC_LPCR_64, &lpcr); + + regs.pc = (uintptr_t)guest_code; + regs.gpr[12] = (uintptr_t)guest_code; + regs.msr = 0x8000000002103032ull;
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ regs.gpr[1] = stack_vaddr + stack_size - 256; + + if (BYTE_ORDER == LITTLE_ENDIAN) { + regs.msr |= 0x1; // LE + lpcr |= 0x0000000002000000; // ILEWould it be appropriate to add #defines to
processor.hinstead of open coding the magic numbers?
Yes it would. I should have not been lazy about it from the start, will fix.
(Other comments snipped but agreed for all)
Thanks,
Nick
Nicholas Piggin
reviewerPATCH 2/2 KVM: PPC: Add basic framework tests for kvm selftests
In reply to Nicholas PigginAdd some tests that exercise basic functions of the kvm selftests framework, guest creation, ucalls, hcalls, copying data between guest and host, interrupts and page faults.
These don't test KVM so much, but were useful when developing the selftests support for powerpc.
--- tools/testing/selftests/kvm/Makefile | 2 + .../selftests/kvm/include/powerpc/hcall.h | 4 +- .../testing/selftests/kvm/powerpc/null_test.c | 186 ++++++++++++++++++ .../selftests/kvm/powerpc/rtas_hcall.c | 146 ++++++++++++++ 4 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/powerpc/null_test.c create mode 100644 tools/testing/selftests/kvm/powerpc/rtas_hcall.c
tools/testing/selftests/kvm/Makefile +2 -0
@@ -180,6 +180,8 @@ TEST_GEN_PROGS_riscv += kvm_page_table_test TEST_GEN_PROGS_riscv += set_memory_region_test TEST_GEN_PROGS_riscv += kvm_binary_stats_test +TEST_GEN_PROGS_powerpc += powerpc/null_test +TEST_GEN_PROGS_powerpc += powerpc/rtas_hcall TEST_GEN_PROGS_powerpc += demand_paging_test TEST_GEN_PROGS_powerpc += dirty_log_test TEST_GEN_PROGS_powerpc += kvm_create_max_vcpus
tools/testing/selftests/kvm/include/powerpc/hcall.h +3 -1
@@ -11,7 +11,9 @@#define H_UCALL 0#define UCALL_R4_UCALL 0x5715 // regular ucall, r5 contains ucall pointer#define UCALL_R4_EXCPT 0x1b0f // other exception, r5 contains vector, r6,7 SRRs -// R4==0 is a simple asm exit +#define UCALL_R4_SIMPLE 0x0000 // simple exit usable by asm with no ucall data + +#define H_RTAS 0xf000int64_t hcall0 (uint64_t token);int64_t hcall1 (uint64_t token,uint64_t arg1);
tools/testing/selftests/kvm/powerpc/null_test.c new file +186 -0
186 lines not on this page · raw message
tools/testing/selftests/kvm/powerpc/rtas_hcall.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
2.37.2
Quoted 4 lines · Nicholas Piggin
Hi,
This series adds initial KVM selftests support for powerpc (64-bit, BookS).
Awesome.
Quoted 7 lines
It spans 3 maintainers but it does not really affect
arch/powerpc, and it is well contained in selftests code, just touches some makefiles and a tiny bit headers so conflicts should be unlikely and trivial.I guess Paolo is the best point to merge these, if no comments or objections?
Yeah. If it helps:
cheers
Sean Christopherson
reviewerQuoted 13 lines · Michael Ellerman
Quoted 4 lines · Nicholas Piggin
Hi,
This series adds initial KVM selftests support for powerpc (64-bit, BookS).
Awesome.
Quoted 5 lines
It spans 3 maintainers but it does not really affect
arch/powerpc, and it is well contained in selftests code, just touches some makefiles and a tiny bit headers so conflicts should be unlikely and trivial.
Quoted 6 lines
Quoted 2 lines
I guess Paolo is the best point to merge these, if no comments or objections?
Yeah. If it helps:
What is the long term plan for KVM PPC maintenance? I was under the impression that KVM PPC was trending toward "bug fixes only", but the addition of selftests support suggests otherwise.
I ask primarily because routing KVM PPC patches through the PPC tree is going to be problematic if KVM PPC sees signficiant development. The current situation is ok because the volume of patches is low and KVM PPC isn't trying to drive anything substantial into common KVM code, but if that changes...
My other concern is that for selftests specifically, us KVM folks are taking on more maintenance burden by supporting PPC. AFAIK, none of the people that focus on KVM selftests in any meaningful capacity have access to PPC hardware, let alone know enough about the architecture to make intelligent code changes.
Don't get me wrong, I'm very much in favor of more testing, I just don't want KVM to get left holding the bag.
Nicholas Piggin
reviewerQuoted 17 lines · Sean Christopherson
Quoted 16 lines · Michael Ellerman
Quoted 4 lines · Nicholas Piggin
Hi,
This series adds initial KVM selftests support for powerpc (64-bit, BookS).
Awesome.
Quoted 7 lines
It spans 3 maintainers but it does not really affect
arch/powerpc, and it is well contained in selftests code, just touches some makefiles and a tiny bit headers so conflicts should be unlikely and trivial.I guess Paolo is the best point to merge these, if no comments or objections?
Quoted 7 lines
Quoted 3 lines
Yeah. If it helps:
What is the long term plan for KVM PPC maintenance? I was under the impression that KVM PPC was trending toward "bug fixes only", but the addition of selftests support suggests otherwise.
We plan to continue maintaining it. New support and features has been a bit low in the past couple of years, hopefully that will pick up a bit though.
Quoted 4 lines
I ask primarily because routing KVM PPC patches through the PPC tree is going to be problematic if KVM PPC sees signficiant development. The current situation is ok because the volume of patches is low and KVM PPC isn't trying to drive anything substantial into common KVM code, but if that changes...
Michael has done KVM topic branches to pull from a few times when such conflicts came up (at smaller scale). If we end up with larger changes or regular conflicts we might start up a kvm-ppc tree again I guess.
Quoted 7 lines
My other concern is that for selftests specifically, us KVM folks are taking on more maintenance burden by supporting PPC. AFAIK, none of the people that focus on KVM selftests in any meaningful capacity have access to PPC hardware, let alone know enough about the architecture to make intelligent code changes.
Don't get me wrong, I'm very much in favor of more testing, I just don't want KVM to get left holding the bag.
Understood. I'll be happy to maintain powerpc part of kvm selftests and do any fixes that are needed for core code changes.If support fell away you could leave it broken (or rm -rf it if you prefer) -- I wouldn't ask anybody to work on archs they don't know or aren't paid to.
Not sure if anything more can be done to help your process or ease your mind. It (KVM and kvm-selftests) can run in QEMU at least.
Thanks,
Nick
Sean Christopherson
reviewerQuoted 22 lines · Nicholas Piggin
Quoted 21 lines · Sean Christopherson
Quoted 19 lines · Michael Ellerman
Quoted 4 lines · Nicholas Piggin
Hi,
This series adds initial KVM selftests support for powerpc (64-bit, BookS).
Awesome.
Quoted 7 lines
It spans 3 maintainers but it does not really affect
arch/powerpc, and it is well contained in selftests code, just touches some makefiles and a tiny bit headers so conflicts should be unlikely and trivial.I guess Paolo is the best point to merge these, if no comments or objections?
Yeah. If it helps:
Quoted 7 lines
Quoted 3 lines
What is the long term plan for KVM PPC maintenance? I was under the impression that KVM PPC was trending toward "bug fixes only", but the addition of selftests support suggests otherwise.
We plan to continue maintaining it. New support and features has been a bit low in the past couple of years, hopefully that will pick up a bit though.
Partly out of curiosity, but also to get a general feel for what types of changes we might see, what are the main use cases for KVM PPC these days? E.g. is it mainly a vehicle for developing and testing, hosting VMs in the cloud, something else?
Quoted 8 lines
Quoted 4 lines
I ask primarily because routing KVM PPC patches through the PPC tree is going to be problematic if KVM PPC sees signficiant development. The current situation is ok because the volume of patches is low and KVM PPC isn't trying to drive anything substantial into common KVM code, but if that changes...
Michael has done KVM topic branches to pull from a few times when such conflicts came up (at smaller scale). If we end up with larger changes or regular conflicts we might start up a kvm-ppc tree again I guess.
A wait-and-see approach works for me. I don't have any complaints with the current process, I was just caught off guard.
Quoted 8 lines
Quoted 7 lines
My other concern is that for selftests specifically, us KVM folks are taking on more maintenance burden by supporting PPC. AFAIK, none of the people that focus on KVM selftests in any meaningful capacity have access to PPC hardware, let alone know enough about the architecture to make intelligent code changes.
Don't get me wrong, I'm very much in favor of more testing, I just don't want KVM to get left holding the bag.
Quoted 7 lines
Understood. I'll be happy to maintain powerpc part of kvm selftests and do any fixes that are needed for core code changes.If support fell away you could leave it broken (or rm -rf it if you prefer) -- I wouldn't ask anybody to work on archs they don't know or aren't paid to.
Not sure if anything more can be done to help your process or ease your mind. It (KVM and kvm-selftests) can run in QEMU at least.
Updating the KVM/powerpc to include selftests would be very helpful, e.g
F: tools/testing/selftests/kvm/*/powerpc/
F: tools/testing/selftests/kvm/powerpc/
and ideally there would be one or more M: (and R:) entries as well. I'm not all that concerned about the selftests support being abandoned, but the lack of specific contacts makes it look like KVM PPC is in maintenance-only mode, and it sounds like that's not the case.
Thanks!
Nicholas Piggin
reviewerQuoted 27 lines · Sean Christopherson
Quoted 26 lines · Nicholas Piggin
Quoted 24 lines · Sean Christopherson
Quoted 13 lines · Michael Ellerman
Quoted 4 lines · Nicholas Piggin
Hi,
This series adds initial KVM selftests support for powerpc (64-bit, BookS).
Awesome.
Quoted 5 lines
It spans 3 maintainers but it does not really affect
arch/powerpc, and it is well contained in selftests code, just touches some makefiles and a tiny bit headers so conflicts should be unlikely and trivial.Quoted 6 lines
Quoted 2 lines
I guess Paolo is the best point to merge these, if no comments or objections?
Yeah. If it helps:
What is the long term plan for KVM PPC maintenance? I was under the impression that KVM PPC was trending toward "bug fixes only", but the addition of selftests support suggests otherwise.
Quoted 7 lines
Quoted 3 lines
We plan to continue maintaining it. New support and features has been a bit low in the past couple of years, hopefully that will pick up a bit though.
Partly out of curiosity, but also to get a general feel for what types of changes we might see, what are the main use cases for KVM PPC these days? E.g. is it mainly a vehicle for developing and testing, hosting VMs in the cloud, something else?
I didn't have too much specific in mind, just generally a bit more development activity.
As for use cases, I think broadly KVM is increasingly seen as a Linux feature and expected to be there, even in so-called enterprise world. For software and workflows designed around Linux virt, it can be difficult or impossible to substitue the proprietary partitioning layer in our firmware. So there is always someone who wants KVM for something. It could be all of the above, and even just as a traditional hypervisor hosting VMs in-house, there are people who would like to use KVM.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I ask primarily because routing KVM PPC patches through the PPC tree is going to be problematic if KVM PPC sees signficiant development. The current situation is ok because the volume of patches is low and KVM PPC isn't trying to drive anything substantial into common KVM code, but if that changes...
Quoted 6 lines
Quoted 3 lines
Michael has done KVM topic branches to pull from a few times when such conflicts came up (at smaller scale). If we end up with larger changes or regular conflicts we might start up a kvm-ppc tree again I guess.
A wait-and-see approach works for me. I don't have any complaints with the current process, I was just caught off guard.
Okay. Complaints and suggestions to improve the process are always welcome, so if something could be done better, feel free to ping the list or powerpc maintainers offline.
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
My other concern is that for selftests specifically, us KVM folks are taking on more maintenance burden by supporting PPC. AFAIK, none of the people that focus on KVM selftests in any meaningful capacity have access to PPC hardware, let alone know enough about the architecture to make intelligent code changes.
Don't get me wrong, I'm very much in favor of more testing, I just don't want KVM to get left holding the bag.
Understood. I'll be happy to maintain powerpc part of kvm selftests and do any fixes that are needed for core code changes.If support fell away you could leave it broken (or rm -rf it if you prefer) -- I wouldn't ask anybody to work on archs they don't know or aren't paid to.
Quoted 7 lines
Quoted 2 lines
Not sure if anything more can be done to help your process or ease your mind. It (KVM and kvm-selftests) can run in QEMU at least.
Updating the KVM/powerpc to include selftests would be very helpful, e.g
F:
tools/testing/selftests/kvm/*/powerpc/
F:tools/testing/selftests/kvm/powerpc/
Oh good point, I should have included that. I'll send a patch.
Quoted 4 lines
and ideally there would be one or more M: (and R:) entries as well. I'm not all that concerned about the selftests support being abandoned, but the lack of specific contacts makes it look like KVM PPC is in maintenance-only mode, and it sounds like that's not the case.
Yeah, I guess the intention was to bring it a bit more under general arch/powerpc maintainership but it does look a bit odd having a top level entry and no contacts. We'll reconsider what to do with that.
Thanks,
Nick
Quoted 3 lines · Nicholas Piggin
Quoted 2 lines · Sean Christopherson
Quoted 1 line · Nicholas Piggin
On Thu Mar 23, 2023 at 3:41 AM AEST, Sean Christopherson wrote:
...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
What is the long term plan for KVM PPC maintenance? I was under the impression that KVM PPC was trending toward "bug fixes only", but the addition of selftests support suggests otherwise.
...
Quoted 9 lines
Quoted 5 lines
and ideally there would be one or more M: (and R:) entries as well. I'm not all that concerned about the selftests support being abandoned, but the lack of specific contacts makes it look like KVM PPC is in maintenance-only mode, and it sounds like that's not the case.
Yeah, I guess the intention was to bring it a bit more under general
arch/powerpcmaintainership but it does look a bit odd having a top level entry and no contacts. We'll reconsider what to do with that.
Yeah I agree it ends up looking a bit weird.
The intention was just to make it clear that Paul's tree was no longer where patches were being handled, and that they'd be handled as regular powerpc patches.
At the time I hoped we'd relatively quickly be able to add someone as at least a KVM "R:"eviewer, but circumstances intervened.
Hopefully we can fix that soon.
cheers