ppc: booke206: KVM MMU API and info tlb
v2 cover ppc: booke206: KVM MMU API and info tlb
For this functionality to work with KVM, this kernel patch is required:
http://www.spinics.net/lists/kvm-ppc/msg03053.html
Scott Wood (4):
kvm: update linux-headers
kvm: ppc: booke206: use MMU API
ppc: booke206: use MAV=2.0 TSIZE definition, fix 4G pages
ppc: booke206: add "info tlb" support
hmp-commands.hx | 2 +- hw/ppce500_mpc8544ds.c | 4 +- linux-headers/asm-powerpc/kvm.h | 54 +++++++++++++++++++++- linux-headers/asm-x86/kvm_para.h | 14 ++++++ linux-headers/linux/kvm.h | 41 +++++++++++++--- linux-headers/linux/kvm_para.h | 1 + monitor.c | 5 +- target-ppc/cpu.h | 8 +++- target-ppc/helper.c | 93 +++++++++++++++++++++++++++++++++++++- target-ppc/kvm.c | 87 +++++++++++++++++++++++++++++++++++ 10 files changed, 291 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.6
PATCH v2 1/4 kvm: update linux-headers
Needed for PPC MMU API support.
---
v2: new to v2
linux-headers/asm-powerpc/kvm.h | 54 ++++++++++++++++++++++++++++++++++++- linux-headers/asm-x86/kvm_para.h | 14 ++++++++++ linux-headers/linux/kvm.h | 41 +++++++++++++++++++++++----- linux-headers/linux/kvm_para.h | 1 + 4 files changed, 100 insertions(+), 10 deletions(-)
linux-headers/asm-powerpc/kvm.h +52 -2
@@ -22,6 +22,10 @@#include <linux/types.h> +/* Select powerpc specific features in <linux/kvm.h> */ +#define __KVM_HAVE_SPAPR_TCE +#define __KVM_HAVE_PPC_SMT +struct kvm_regs {__u64 pc;__u64 cr;
@@ -166,8 +170,8 @@ struct kvm_sregs { } ppc64;struct {__u32 sr[16 ]; -__u64 ibat[8 ]; -__u64 dbat[8 ]; +__u64 ibat[8 ]; +__u64 dbat[8 ]; } ppc32; } s;struct {
@@ -272,4 +276,50 @@ struct kvm_guest_debug_arch {#define KVM_INTERRUPT_UNSET -2U#define KVM_INTERRUPT_SET_LEVEL -3U +/* for KVM_CAP_SPAPR_TCE */ +struct kvm_create_spapr_tce { +__u64 liobn; +__u32 window_size; +}; + +/* for KVM_ALLOCATE_RMA */ +struct kvm_allocate_rma { +__u64 rma_size; +}; + +struct kvm_book3e_206_tlb_entry { +__u32 mas8; +__u32 mas1; +__u64 mas2; +__u64 mas7_3; +}; + +struct kvm_book3e_206_tlb_params { +/* +* For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV: +* +* - The number of ways of TLB0 must be a power of two between 2 and +* 16. +* - TLB1 must be fully associative. +* - The size of TLB0 must be a multiple of the number of ways, and +* the number of sets must be a power of two. +* - The size of TLB1 may not exceed 64 entries. +* - TLB0 supports 4 KiB pages. +* - The page sizes supported by TLB1 are as indicated by +* TLB1CFG (if MMUCFG[MAVN] = 0) or TLB1PS (if MMUCFG[MAVN] = 1) +* as returned by KVM_GET_SREGS. +* - TLB2 and TLB3 are reserved, and their entries in tlb_sizes[] +* and tlb_ways[] must be zero. +* +* tlb_ways[n] = tlb_sizes[n] means the array is fully associative. +* +* KVM will adjust TLBnCFG based on the sizes configured here, +* though arrays greater than 2048 entries will have TLBnCFG[NENTRY] +* set to zero. +*/ +__u32 tlb_sizes[4 ]; +__u32 tlb_ways[4 ]; +__u32 reserved[8 ]; +}; +#endif /* __LINUX_KVM_POWERPC_H */
linux-headers/asm-x86/kvm_para.h +14 -0
@@ -21,6 +21,7 @@*/ #define KVM_FEATURE_CLOCKSOURCE2 3#define KVM_FEATURE_ASYNC_PF 4 +#define KVM_FEATURE_STEAL_TIME 5/* The last 8 bits are used to indicate how to interpret the flags field * in pvclock structure. If no bits are set, all flags are ignored.
@@ -30,10 +31,23 @@#define MSR_KVM_WALL_CLOCK 0x11#define MSR_KVM_SYSTEM_TIME 0x12 +#define KVM_MSR_ENABLED 1/* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */ #define MSR_KVM_WALL_CLOCK_NEW 0x4b564d00#define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01#define MSR_KVM_ASYNC_PF_EN 0x4b564d02 +#define MSR_KVM_STEAL_TIME 0x4b564d03 + +struct kvm_steal_time { +__u64 steal; +__u32 version; +__u32 flags; +__u32 pad[12 ]; +}; + +#define KVM_STEAL_ALIGNMENT_BITS 5 +#define KVM_STEAL_VALID_BITS ((-1ULL << (KVM_STEAL_ALIGNMENT_BITS + 1))) +#define KVM_STEAL_RESERVED_MASK (((1 << KVM_STEAL_ALIGNMENT_BITS) - 1 ) << 1)#define KVM_MAX_MMU_OP_BATCH 32
linux-headers/linux/kvm.h +33 -8
90 lines not on this page · raw message
linux-headers/linux/kvm_para.h +1 -0
@@ -26,3 +26,4 @@#include <asm/kvm_para.h> #endif /* __LINUX_KVM_PARA_H */ +
Signature · 1 line
1.7.6
PATCH v2 2/4 kvm: ppc: booke206: use MMU API
In reply to Scott WoodShare the TLB array with KVM. This allows us to set the initial TLB both on initial boot and reset, is useful for debugging, and could eventually be used to support migration.
---
v2 (was 1/3 in v1):
updated for kernel API change, removed kernel header ifdefs, minor changes as requested
hw/ppce500_mpc8544ds.c | 2 + target-ppc/cpu.h | 2 + target-ppc/kvm.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 0 deletions(-)
hw/ppce500_mpc8544ds.c +2 -0
@@ -202,6 +202,8 @@ static void mmubooke_create_initial_mapping(CPUState *env, tlb->mas2 = va &TARGET_PAGE_MASK ; tlb->mas7_3 = pa &TARGET_PAGE_MASK ; tlb->mas7_3 |=MAS3_UR |MAS3_UW |MAS3_UX |MAS3_SR |MAS3_SW |MAS3_SX ; + + env->tlb_dirty = true; }static void mpc8544ds_cpu_reset (void *opaque)
target-ppc/cpu.h +2 -0
@@ -919,6 +919,8 @@ struct CPUPPCState {ppc_tlb_t tlb;/* TLB is optional. Allocate them only if needed */ /* 403 dedicated access protection registers */ target_ulong pb[4 ]; +bool tlb_dirty;/* Set to non-zero when modifying TLB */ +bool kvm_sw_tlb;/* non-zero if KVM SW TLB API is active */ #endif /* Other registers */
target-ppc/kvm.c +87 -0
111 lines not on this page · raw message
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 2/4] kvm: ppc: booke206: use MMU API
Quoted 66 lines · Scott Wood
Share the TLB array with KVM. This allows us to set the initial TLB both on initial boot and reset, is useful for debugging, and could eventually be used to support migration.
Signed-off-by Scott Wood <[email protected]>---
v2 (was 1/3 in v1):
updated for kernel API change, removed kernel header ifdefs, minor changes as requestedhw/ppce500_mpc8544ds.c | 2 + target-ppc/cpu.h | 2 + target-ppc/kvm.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 0 deletions(-)hw/ppce500_mpc8544ds.c +2
-0@@ -202,6 +202,8 @@ static void mmubooke_create_initial_mapping(CPUState *env, tlb->mas2 = va &TARGET_PAGE_MASK ; tlb->mas7_3 = pa &TARGET_PAGE_MASK ; tlb->mas7_3 |=MAS3_UR |MAS3_UW |MAS3_UX |MAS3_SR |MAS3_SW |MAS3_SX ; + + env->tlb_dirty = true; }static void mpc8544ds_cpu_reset (void *opaque)target-ppc/cpu.h +2
-0@@ -919,6 +919,8 @@ struct CPUPPCState {ppc_tlb_t tlb;/* TLB is optional. Allocate them only if needed */ /* 403 dedicated access protection registers */ target_ulong pb[4 ]; +bool tlb_dirty;/* Set to non-zero when modifying TLB */ +bool kvm_sw_tlb;/* non-zero if KVM SW TLB API is active */ #endif /* Other registers */ target-ppc/kvm.c +17
-0@@ -105,6 +105,54 @@ static int kvm_arch_sync_sregs(CPUState *cenv)return kvm_vcpu_ioctl (cenv,KVM_SET_SREGS , &sregs); } +/* Set up a shared TLB array with KVM */ +static int kvm_booke206_tlb_init (CPUState *env) +{ +struct kvm_book3e_206_tlb_params params = {}; +struct kvm_config_tlb cfg = {}; +struct kvm_enable_cap encap = {}; +size_t array_len; +unsigned int entries =0 ; +int ret, i; + +if (!kvm_enabled () || + !kvm_check_extension (env->kvm_state,KVM_CAP_SW_TLB )) { +return 0 ; + } + +assert (ARRAY_SIZE (params.tlb_sizes) ==BOOKE206_MAX_TLBN ); +
target-ppc/kvm.c static int kvm_arch_sync_sregs(CPUState *cenv) · line 134
Quoted 10 lines
target-ppc/kvm.c +10
-0+for (i =0 ; i <BOOKE206_MAX_TLBN ; i++) { + params.tlb_sizes[i] =booke206_tlb_size (env, i); + params.tlb_ways[i] =booke206_tlb_ways (env, i); + entries += params.tlb_sizes[i]; + } + +assert (entries == env->nb_tlb); +assert (sizeof (struct kvm_book3e_206_tlb_entry ) ==sizeof (ppcmas_tlb_t)); + + array_len =sizeof (ppcmas_tlb_t) * entries;
/dev/shm/qemu/target-ppc/kvm.c: In function 'kvm_booke206_tlb_init':/dev/shm/qemu/target-ppc/kvm.c:121:12: warning: variable 'array_len' set but not used [-Wunused-but-set-variable]
Alex
PATCH v2 3/4 ppc: booke206: use MAV=2.0 TSIZE definition, fix 4G pages
In reply to Scott WoodThis definition is backward compatible with MAV=1.0 as long as the guest does not set reserved bits in MAS1/MAS4.
Also, fix the shift in booke206_tlb_to_page_size -- it's the base that should be able to hold a 4G page size, not the shift count.
---
v2 (was 2/3 in v1): no change
hw/ppce500_mpc8544ds.c | 2 +- target-ppc/cpu.h | 4 ++-- target-ppc/helper.c | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-)
hw/ppce500_mpc8544ds.c +1 -1
@@ -187,7 +187,7 @@ out:/* Create -kernel TLB entries for BookE, linearly spanning 256MB. */ static inline target_phys_addr_t booke206_page_size_to_tlb (uint64_t size) { -return (ffs (size >>10 ) -1 ) >>1 ; +return ffs (size >>10 ) -1 ; } static void mmubooke_create_initial_mapping(CPUState *env,
target-ppc/cpu.h +2 -2
@@ -652,8 +652,8 @@ enum {#define MAS0_ATSEL_TLB 0#define MAS0_ATSEL_LRAT MAS0_ATSEL -#define MAS1_TSIZE_SHIFT 8 -#define MAS1_TSIZE_MASK (0xf << MAS1_TSIZE_SHIFT) +#define MAS1_TSIZE_SHIFT 7 +#define MAS1_TSIZE_MASK (0x1f << MAS1_TSIZE_SHIFT)#define MAS1_TS_SHIFT 12#define MAS1_TS (1 << MAS1_TS_SHIFT)
target-ppc/helper.c +3 -2
@@ -1293,7 +1293,7 @@ target_phys_addr_t booke206_tlb_to_page_size(CPUState *env, ppcmas_tlb_t *tlb) {uint32_t tlbncfg;int tlbn =booke206_tlbm_to_tlbn (env, tlb); -target_phys_addr_t tlbm_size; +int tlbm_size; tlbncfg = env->spr[SPR_BOOKE_TLB0CFG + tlbn];
@@ -1301,9 +1301,10 @@ target_phys_addr_t booke206_tlb_to_page_size(CPUState *env, ppcmas_tlb_t *tlb) tlbm_size = (tlb->mas1 &MAS1_TSIZE_MASK ) >>MAS1_TSIZE_SHIFT ; }else { tlbm_size = (tlbncfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT; + tlbm_size <<=1 ; } -return (1 << (tlbm_size <<1 )) <<10 ; +return 1024ULL << tlbm_size; }/* TLB check function for MAS based SoftTLBs */
Signature · 1 line
1.7.6
PATCH v2 4/4 ppc: booke206: add "info tlb" support
In reply to Scott Wood---
v2 (was 3/3 in v1): no change
hmp-commands.hx | 2 +- monitor.c | 5 ++- target-ppc/cpu.h | 2 + target-ppc/helper.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-)
hmp-commands.hx +1 -1
@@ -1306,7 +1306,7 @@ show i8259 (PIC) state @item info pci show emulated PCI device info @item info tlb -show virtual to physical memory mappings (i386, SH4 and SPARC only) +show virtual to physical memory mappings (i386, SH4, SPARC, and PPC only) @item info mem show the active virtual memory mappings (i386 only) @item info jit
monitor.c +3 -2
@@ -2442,7 +2442,7 @@ static void tlb_info(Monitor *mon)#endif -#if defined(TARGET_SPARC ) +#if defined(TARGET_SPARC ) || defined(TARGET_PPC )static void tlb_info (Monitor *mon) {CPUState *env1 =mon_get_cpu ();
@@ -2935,7 +2935,8 @@ static const mon_cmd_t info_cmds[] = { .user_print = do_pci_info_print, .mhandler.info_new = do_pci_info, }, -#if defined(TARGET_I386 ) || defined(TARGET_SH4 ) || defined(TARGET_SPARC ) +#if defined(TARGET_I386 ) || defined(TARGET_SH4 ) || defined(TARGET_SPARC ) || \ + defined(TARGET_PPC ) { .name = "tlb", .args_type = "",
target-ppc/cpu.h +2 -0
@@ -2030,4 +2030,6 @@ static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb) env->nip = tb->pc; } +void dump_mmu (FILE *f,fprintf_function cpu_fprintf,CPUState *env); +#endif /* !defined (__CPU_PPC_H__) */
target-ppc/helper.c +88 -0
94 lines not on this page · raw message
Signature · 1 line
1.7.6