Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull second round of KVM changes from Paolo Bonzini:
"Here are the PPC and ARM changes for KVM, which I separated because
they had small conflicts (respectively within KVM documentation, and
with 3.16-rc changes). Since they were all within the subsystem, I
took care of them.

Stephen Rothwell reported some snags in PPC builds, but they are all
fixed now; the latest linux-next report was clean.

New features for ARM include:
- KVM VGIC v2 emulation on GICv3 hardware
- Big-Endian support for arm/arm64 (guest and host)
- Debug Architecture support for arm64 (arm32 is on Christoffer's todo list)

And for PPC:
- Book3S: Good number of LE host fixes, enable HV on LE
- Book3S HV: Add in-guest debug support

This release drops support for KVM on the PPC440. As a result, the
PPC merge removes more lines than it adds. :)

I also included an x86 change, since Davidlohr tied it to an
independent bug report and the reporter quickly provided a Tested-by;
there was no reason to wait for -rc2"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (122 commits)
KVM: Move more code under CONFIG_HAVE_KVM_IRQFD
KVM: nVMX: fix "acknowledge interrupt on exit" when APICv is in use
KVM: nVMX: Fix nested vmexit ack intr before load vmcs01
KVM: PPC: Enable IRQFD support for the XICS interrupt controller
KVM: Give IRQFD its own separate enabling Kconfig option
KVM: Move irq notifier implementation into eventfd.c
KVM: Move all accesses to kvm::irq_routing into irqchip.c
KVM: irqchip: Provide and use accessors for irq routing table
KVM: Don't keep reference to irq routing table in irqfd struct
KVM: PPC: drop duplicate tracepoint
arm64: KVM: fix 64bit CP15 VM access for 32bit guests
KVM: arm64: GICv3: mandate page-aligned GICV region
arm64: KVM: GICv3: move system register access to msr_s/mrs_s
KVM: PPC: PR: Handle FSCR feature deselects
KVM: PPC: HV: Remove generic instruction emulation
KVM: PPC: BOOKEHV: rename e500hv_spr to bookehv_spr
KVM: PPC: Remove DCR handling
KVM: PPC: Expose helper functions for data/inst faults
KVM: PPC: Separate loadstore emulation from priv emulation
KVM: PPC: Handle magic page in kvmppc_ld/st
...

+5019 -2834
+8
Documentation/arm64/booting.txt
··· 168 168 the kernel image will be entered must be initialised by software at a 169 169 higher exception level to prevent execution in an UNKNOWN state. 170 170 171 + For systems with a GICv3 interrupt controller: 172 + - If EL3 is present: 173 + ICC_SRE_EL3.Enable (bit 3) must be initialiased to 0b1. 174 + ICC_SRE_EL3.SRE (bit 0) must be initialised to 0b1. 175 + - If the kernel is entered at EL1: 176 + ICC.SRE_EL2.Enable (bit 3) must be initialised to 0b1 177 + ICC_SRE_EL2.SRE (bit 0) must be initialised to 0b1. 178 + 171 179 The requirements described above for CPU mode, caches, MMUs, architected 172 180 timers, coherency and system registers apply to all CPUs. All CPUs must 173 181 enter the kernel in the same exception level.
+79
Documentation/devicetree/bindings/arm/gic-v3.txt
··· 1 + * ARM Generic Interrupt Controller, version 3 2 + 3 + AArch64 SMP cores are often associated with a GICv3, providing Private 4 + Peripheral Interrupts (PPI), Shared Peripheral Interrupts (SPI), 5 + Software Generated Interrupts (SGI), and Locality-specific Peripheral 6 + Interrupts (LPI). 7 + 8 + Main node required properties: 9 + 10 + - compatible : should at least contain "arm,gic-v3". 11 + - interrupt-controller : Identifies the node as an interrupt controller 12 + - #interrupt-cells : Specifies the number of cells needed to encode an 13 + interrupt source. Must be a single cell with a value of at least 3. 14 + 15 + The 1st cell is the interrupt type; 0 for SPI interrupts, 1 for PPI 16 + interrupts. Other values are reserved for future use. 17 + 18 + The 2nd cell contains the interrupt number for the interrupt type. 19 + SPI interrupts are in the range [0-987]. PPI interrupts are in the 20 + range [0-15]. 21 + 22 + The 3rd cell is the flags, encoded as follows: 23 + bits[3:0] trigger type and level flags. 24 + 1 = edge triggered 25 + 4 = level triggered 26 + 27 + Cells 4 and beyond are reserved for future use. When the 1st cell 28 + has a value of 0 or 1, cells 4 and beyond act as padding, and may be 29 + ignored. It is recommended that padding cells have a value of 0. 30 + 31 + - reg : Specifies base physical address(s) and size of the GIC 32 + registers, in the following order: 33 + - GIC Distributor interface (GICD) 34 + - GIC Redistributors (GICR), one range per redistributor region 35 + - GIC CPU interface (GICC) 36 + - GIC Hypervisor interface (GICH) 37 + - GIC Virtual CPU interface (GICV) 38 + 39 + GICC, GICH and GICV are optional. 40 + 41 + - interrupts : Interrupt source of the VGIC maintenance interrupt. 42 + 43 + Optional 44 + 45 + - redistributor-stride : If using padding pages, specifies the stride 46 + of consecutive redistributors. Must be a multiple of 64kB. 47 + 48 + - #redistributor-regions: The number of independent contiguous regions 49 + occupied by the redistributors. Required if more than one such 50 + region is present. 51 + 52 + Examples: 53 + 54 + gic: interrupt-controller@2cf00000 { 55 + compatible = "arm,gic-v3"; 56 + #interrupt-cells = <3>; 57 + interrupt-controller; 58 + reg = <0x0 0x2f000000 0 0x10000>, // GICD 59 + <0x0 0x2f100000 0 0x200000>, // GICR 60 + <0x0 0x2c000000 0 0x2000>, // GICC 61 + <0x0 0x2c010000 0 0x2000>, // GICH 62 + <0x0 0x2c020000 0 0x2000>; // GICV 63 + interrupts = <1 9 4>; 64 + }; 65 + 66 + gic: interrupt-controller@2c010000 { 67 + compatible = "arm,gic-v3"; 68 + #interrupt-cells = <3>; 69 + interrupt-controller; 70 + redistributor-stride = <0x0 0x40000>; // 256kB stride 71 + #redistributor-regions = <2>; 72 + reg = <0x0 0x2c010000 0 0x10000>, // GICD 73 + <0x0 0x2d000000 0 0x800000>, // GICR 1: CPUs 0-31 74 + <0x0 0x2e000000 0 0x800000>; // GICR 2: CPUs 32-63 75 + <0x0 0x2c040000 0 0x2000>, // GICC 76 + <0x0 0x2c060000 0 0x2000>, // GICH 77 + <0x0 0x2c080000 0 0x2000>; // GICV 78 + interrupts = <1 9 4>; 79 + };
-2
Documentation/powerpc/00-INDEX
··· 17 17 - Documentation on the firmware assisted dump mechanism "fadump". 18 18 hvcs.txt 19 19 - IBM "Hypervisor Virtual Console Server" Installation Guide 20 - kvm_440.txt 21 - - Various notes on the implementation of KVM for PowerPC 440. 22 20 mpc52xx.txt 23 21 - Linux 2.6.x on MPC52xx family 24 22 pmu-ebb.txt
-41
Documentation/powerpc/kvm_440.txt
··· 1 - Hollis Blanchard <hollisb@us.ibm.com> 2 - 15 Apr 2008 3 - 4 - Various notes on the implementation of KVM for PowerPC 440: 5 - 6 - To enforce isolation, host userspace, guest kernel, and guest userspace all 7 - run at user privilege level. Only the host kernel runs in supervisor mode. 8 - Executing privileged instructions in the guest traps into KVM (in the host 9 - kernel), where we decode and emulate them. Through this technique, unmodified 10 - 440 Linux kernels can be run (slowly) as guests. Future performance work will 11 - focus on reducing the overhead and frequency of these traps. 12 - 13 - The usual code flow is started from userspace invoking an "run" ioctl, which 14 - causes KVM to switch into guest context. We use IVPR to hijack the host 15 - interrupt vectors while running the guest, which allows us to direct all 16 - interrupts to kvmppc_handle_interrupt(). At this point, we could either 17 - - handle the interrupt completely (e.g. emulate "mtspr SPRG0"), or 18 - - let the host interrupt handler run (e.g. when the decrementer fires), or 19 - - return to host userspace (e.g. when the guest performs device MMIO) 20 - 21 - Address spaces: We take advantage of the fact that Linux doesn't use the AS=1 22 - address space (in host or guest), which gives us virtual address space to use 23 - for guest mappings. While the guest is running, the host kernel remains mapped 24 - in AS=0, but the guest can only use AS=1 mappings. 25 - 26 - TLB entries: The TLB entries covering the host linear mapping remain 27 - present while running the guest. This reduces the overhead of lightweight 28 - exits, which are handled by KVM running in the host kernel. We keep three 29 - copies of the TLB: 30 - - guest TLB: contents of the TLB as the guest sees it 31 - - shadow TLB: the TLB that is actually in hardware while guest is running 32 - - host TLB: to restore TLB state when context switching guest -> host 33 - When a TLB miss occurs because a mapping was not present in the shadow TLB, 34 - but was present in the guest TLB, KVM handles the fault without invoking the 35 - guest. Large guest pages are backed by multiple 4KB shadow pages through this 36 - mechanism. 37 - 38 - IO: MMIO and DCR accesses are emulated by userspace. We use virtio for network 39 - and block IO, so those drivers must be enabled in the guest. It's possible 40 - that some qemu device emulation (e.g. e1000 or rtl8139) may also work with 41 - little effort.
+52 -8
Documentation/virtual/kvm/api.txt
··· 148 148 149 149 4.4 KVM_CHECK_EXTENSION 150 150 151 - Capability: basic 151 + Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl 152 152 Architectures: all 153 - Type: system ioctl 153 + Type: system ioctl, vm ioctl 154 154 Parameters: extension identifier (KVM_CAP_*) 155 155 Returns: 0 if unsupported; 1 (or some other positive integer) if supported 156 156 ··· 160 160 Generally 0 means no and 1 means yes, but some extensions may report 161 161 additional information in the integer return value. 162 162 163 + Based on their initialization different VMs may have different capabilities. 164 + It is thus encouraged to use the vm ioctl to query for capabilities (available 165 + with KVM_CAP_CHECK_EXTENSION_VM on the vm fd) 163 166 164 167 4.5 KVM_GET_VCPU_MMAP_SIZE 165 168 ··· 1895 1892 PPC | KVM_REG_PPC_PID | 64 1896 1893 PPC | KVM_REG_PPC_ACOP | 64 1897 1894 PPC | KVM_REG_PPC_VRSAVE | 32 1898 - PPC | KVM_REG_PPC_LPCR | 64 1895 + PPC | KVM_REG_PPC_LPCR | 32 1896 + PPC | KVM_REG_PPC_LPCR_64 | 64 1899 1897 PPC | KVM_REG_PPC_PPR | 64 1900 1898 PPC | KVM_REG_PPC_ARCH_COMPAT | 32 1901 1899 PPC | KVM_REG_PPC_DABRX | 32 ··· 2681 2677 appear if the VCPU performed a load or store of the appropriate width directly 2682 2678 to the byte array. 2683 2679 2684 - NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_DCR, 2685 - KVM_EXIT_PAPR and KVM_EXIT_EPR the corresponding 2680 + NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR and 2681 + KVM_EXIT_EPR the corresponding 2686 2682 operations are complete (and guest state is consistent) only after userspace 2687 2683 has re-entered the kernel with KVM_RUN. The kernel side will first finish 2688 2684 incomplete operations and then check for pending signals. Userspace ··· 2753 2749 __u8 is_write; 2754 2750 } dcr; 2755 2751 2756 - powerpc specific. 2752 + Deprecated - was used for 440 KVM. 2757 2753 2758 2754 /* KVM_EXIT_OSI */ 2759 2755 struct { ··· 2935 2931 this function/index combination 2936 2932 2937 2933 2938 - 6. Capabilities that can be enabled 2939 - ----------------------------------- 2934 + 6. Capabilities that can be enabled on vCPUs 2935 + -------------------------------------------- 2940 2936 2941 2937 There are certain capabilities that change the behavior of the virtual CPU or 2942 2938 the virtual machine when enabled. To enable them, please see section 4.37. ··· 3095 3091 3096 3092 This capability enables the in-kernel irqchip for s390. Please refer to 3097 3093 "4.24 KVM_CREATE_IRQCHIP" for details. 3094 + 3095 + 7. Capabilities that can be enabled on VMs 3096 + ------------------------------------------ 3097 + 3098 + There are certain capabilities that change the behavior of the virtual 3099 + machine when enabled. To enable them, please see section 4.37. Below 3100 + you can find a list of capabilities and what their effect on the VM 3101 + is when enabling them. 3102 + 3103 + The following information is provided along with the description: 3104 + 3105 + Architectures: which instruction set architectures provide this ioctl. 3106 + x86 includes both i386 and x86_64. 3107 + 3108 + Parameters: what parameters are accepted by the capability. 3109 + 3110 + Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL) 3111 + are not detailed, but errors with specific meanings are. 3112 + 3113 + 3114 + 7.1 KVM_CAP_PPC_ENABLE_HCALL 3115 + 3116 + Architectures: ppc 3117 + Parameters: args[0] is the sPAPR hcall number 3118 + args[1] is 0 to disable, 1 to enable in-kernel handling 3119 + 3120 + This capability controls whether individual sPAPR hypercalls (hcalls) 3121 + get handled by the kernel or not. Enabling or disabling in-kernel 3122 + handling of an hcall is effective across the VM. On creation, an 3123 + initial set of hcalls are enabled for in-kernel handling, which 3124 + consists of those hcalls for which in-kernel handlers were implemented 3125 + before this capability was implemented. If disabled, the kernel will 3126 + not to attempt to handle the hcall, but will always exit to userspace 3127 + to handle it. Note that it may not make sense to enable some and 3128 + disable others of a group of related hcalls, but KVM does not prevent 3129 + userspace from doing that. 3130 + 3131 + If the hcall number specified is not one that has an in-kernel 3132 + implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL 3133 + error.
+18
arch/arm/include/asm/kvm_asm.h
··· 61 61 #define ARM_EXCEPTION_FIQ 6 62 62 #define ARM_EXCEPTION_HVC 7 63 63 64 + /* 65 + * The rr_lo_hi macro swaps a pair of registers depending on 66 + * current endianness. It is used in conjunction with ldrd and strd 67 + * instructions that load/store a 64-bit value from/to memory to/from 68 + * a pair of registers which are used with the mrrc and mcrr instructions. 69 + * If used with the ldrd/strd instructions, the a1 parameter is the first 70 + * source/destination register and the a2 parameter is the second 71 + * source/destination register. Note that the ldrd/strd instructions 72 + * already swap the bytes within the words correctly according to the 73 + * endianness setting, but the order of the registers need to be effectively 74 + * swapped when used with the mrrc/mcrr instructions. 75 + */ 76 + #ifdef CONFIG_CPU_ENDIAN_BE8 77 + #define rr_lo_hi(a1, a2) a2, a1 78 + #else 79 + #define rr_lo_hi(a1, a2) a1, a2 80 + #endif 81 + 64 82 #ifndef __ASSEMBLY__ 65 83 struct kvm; 66 84 struct kvm_vcpu;
+18 -4
arch/arm/include/asm/kvm_emulate.h
··· 185 185 default: 186 186 return be32_to_cpu(data); 187 187 } 188 + } else { 189 + switch (len) { 190 + case 1: 191 + return data & 0xff; 192 + case 2: 193 + return le16_to_cpu(data & 0xffff); 194 + default: 195 + return le32_to_cpu(data); 196 + } 188 197 } 189 - 190 - return data; /* Leave LE untouched */ 191 198 } 192 199 193 200 static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu, ··· 210 203 default: 211 204 return cpu_to_be32(data); 212 205 } 206 + } else { 207 + switch (len) { 208 + case 1: 209 + return data & 0xff; 210 + case 2: 211 + return cpu_to_le16(data & 0xffff); 212 + default: 213 + return cpu_to_le32(data); 214 + } 213 215 } 214 - 215 - return data; /* Leave LE untouched */ 216 216 } 217 217 218 218 #endif /* __ARM_KVM_EMULATE_H__ */
+5 -3
arch/arm/include/asm/kvm_host.h
··· 225 225 return 0; 226 226 } 227 227 228 + static inline void vgic_arch_setup(const struct vgic_params *vgic) 229 + { 230 + BUG_ON(vgic->type != VGIC_V2); 231 + } 232 + 228 233 int kvm_perf_init(void); 229 234 int kvm_perf_teardown(void); 230 - 231 - u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid); 232 - int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value); 233 235 234 236 #endif /* __ARM_KVM_HOST_H__ */
+12
arch/arm/include/asm/kvm_mmu.h
··· 127 127 (__boundary - 1 < (end) - 1)? __boundary: (end); \ 128 128 }) 129 129 130 + static inline bool kvm_page_empty(void *ptr) 131 + { 132 + struct page *ptr_page = virt_to_page(ptr); 133 + return page_count(ptr_page) == 1; 134 + } 135 + 136 + 137 + #define kvm_pte_table_empty(ptep) kvm_page_empty(ptep) 138 + #define kvm_pmd_table_empty(pmdp) kvm_page_empty(pmdp) 139 + #define kvm_pud_table_empty(pudp) (0) 140 + 141 + 130 142 struct kvm; 131 143 132 144 #define kvm_flush_dcache_to_poc(a,l) __cpuc_flush_dcache_area((a), (l))
+7 -7
arch/arm/kernel/asm-offsets.c
··· 182 182 DEFINE(VCPU_HYP_PC, offsetof(struct kvm_vcpu, arch.fault.hyp_pc)); 183 183 #ifdef CONFIG_KVM_ARM_VGIC 184 184 DEFINE(VCPU_VGIC_CPU, offsetof(struct kvm_vcpu, arch.vgic_cpu)); 185 - DEFINE(VGIC_CPU_HCR, offsetof(struct vgic_cpu, vgic_hcr)); 186 - DEFINE(VGIC_CPU_VMCR, offsetof(struct vgic_cpu, vgic_vmcr)); 187 - DEFINE(VGIC_CPU_MISR, offsetof(struct vgic_cpu, vgic_misr)); 188 - DEFINE(VGIC_CPU_EISR, offsetof(struct vgic_cpu, vgic_eisr)); 189 - DEFINE(VGIC_CPU_ELRSR, offsetof(struct vgic_cpu, vgic_elrsr)); 190 - DEFINE(VGIC_CPU_APR, offsetof(struct vgic_cpu, vgic_apr)); 191 - DEFINE(VGIC_CPU_LR, offsetof(struct vgic_cpu, vgic_lr)); 185 + DEFINE(VGIC_V2_CPU_HCR, offsetof(struct vgic_cpu, vgic_v2.vgic_hcr)); 186 + DEFINE(VGIC_V2_CPU_VMCR, offsetof(struct vgic_cpu, vgic_v2.vgic_vmcr)); 187 + DEFINE(VGIC_V2_CPU_MISR, offsetof(struct vgic_cpu, vgic_v2.vgic_misr)); 188 + DEFINE(VGIC_V2_CPU_EISR, offsetof(struct vgic_cpu, vgic_v2.vgic_eisr)); 189 + DEFINE(VGIC_V2_CPU_ELRSR, offsetof(struct vgic_cpu, vgic_v2.vgic_elrsr)); 190 + DEFINE(VGIC_V2_CPU_APR, offsetof(struct vgic_cpu, vgic_v2.vgic_apr)); 191 + DEFINE(VGIC_V2_CPU_LR, offsetof(struct vgic_cpu, vgic_v2.vgic_lr)); 192 192 DEFINE(VGIC_CPU_NR_LR, offsetof(struct vgic_cpu, nr_lr)); 193 193 #ifdef CONFIG_KVM_ARM_TIMER 194 194 DEFINE(VCPU_TIMER_CNTV_CTL, offsetof(struct kvm_vcpu, arch.timer_cpu.cntv_ctl));
+1 -3
arch/arm/kernel/hyp-stub.S
··· 134 134 mcr p15, 4, r7, c1, c1, 3 @ HSTR 135 135 136 136 THUMB( orr r7, #(1 << 30) ) @ HSCTLR.TE 137 - #ifdef CONFIG_CPU_BIG_ENDIAN 138 - orr r7, #(1 << 9) @ HSCTLR.EE 139 - #endif 137 + ARM_BE8(orr r7, r7, #(1 << 25)) @ HSCTLR.EE 140 138 mcr p15, 4, r7, c1, c0, 0 @ HSCTLR 141 139 142 140 mrc p15, 4, r7, c1, c1, 1 @ HDCR
+1 -1
arch/arm/kvm/Kconfig
··· 23 23 select HAVE_KVM_CPU_RELAX_INTERCEPT 24 24 select KVM_MMIO 25 25 select KVM_ARM_HOST 26 - depends on ARM_VIRT_EXT && ARM_LPAE && !CPU_BIG_ENDIAN 26 + depends on ARM_VIRT_EXT && ARM_LPAE 27 27 ---help--- 28 28 Support hosting virtualized guest machines. You will also 29 29 need to select one or more of the processor modules below.
+1
arch/arm/kvm/Makefile
··· 21 21 obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o 22 22 obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o 23 23 obj-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic.o 24 + obj-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic-v2.o 24 25 obj-$(CONFIG_KVM_ARM_TIMER) += $(KVM)/arm/arch_timer.o
+1 -38
arch/arm/kvm/arm.c
··· 155 155 return VM_FAULT_SIGBUS; 156 156 } 157 157 158 - void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, 159 - struct kvm_memory_slot *dont) 160 - { 161 - } 162 - 163 - int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, 164 - unsigned long npages) 165 - { 166 - return 0; 167 - } 168 158 169 159 /** 170 160 * kvm_arch_destroy_vm - destroy the VM data structure ··· 174 184 } 175 185 } 176 186 177 - int kvm_dev_ioctl_check_extension(long ext) 187 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) 178 188 { 179 189 int r; 180 190 switch (ext) { ··· 215 225 return -EINVAL; 216 226 } 217 227 218 - void kvm_arch_memslots_updated(struct kvm *kvm) 219 - { 220 - } 221 - 222 - int kvm_arch_prepare_memory_region(struct kvm *kvm, 223 - struct kvm_memory_slot *memslot, 224 - struct kvm_userspace_memory_region *mem, 225 - enum kvm_mr_change change) 226 - { 227 - return 0; 228 - } 229 - 230 - void kvm_arch_commit_memory_region(struct kvm *kvm, 231 - struct kvm_userspace_memory_region *mem, 232 - const struct kvm_memory_slot *old, 233 - enum kvm_mr_change change) 234 - { 235 - } 236 - 237 - void kvm_arch_flush_shadow_all(struct kvm *kvm) 238 - { 239 - } 240 - 241 - void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 242 - struct kvm_memory_slot *slot) 243 - { 244 - } 245 228 246 229 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) 247 230 {
+79 -9
arch/arm/kvm/coproc.c
··· 44 44 /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ 45 45 #define CSSELR_MAX 12 46 46 47 + /* 48 + * kvm_vcpu_arch.cp15 holds cp15 registers as an array of u32, but some 49 + * of cp15 registers can be viewed either as couple of two u32 registers 50 + * or one u64 register. Current u64 register encoding is that least 51 + * significant u32 word is followed by most significant u32 word. 52 + */ 53 + static inline void vcpu_cp15_reg64_set(struct kvm_vcpu *vcpu, 54 + const struct coproc_reg *r, 55 + u64 val) 56 + { 57 + vcpu->arch.cp15[r->reg] = val & 0xffffffff; 58 + vcpu->arch.cp15[r->reg + 1] = val >> 32; 59 + } 60 + 61 + static inline u64 vcpu_cp15_reg64_get(struct kvm_vcpu *vcpu, 62 + const struct coproc_reg *r) 63 + { 64 + u64 val; 65 + 66 + val = vcpu->arch.cp15[r->reg + 1]; 67 + val = val << 32; 68 + val = val | vcpu->arch.cp15[r->reg]; 69 + return val; 70 + } 71 + 47 72 int kvm_handle_cp10_id(struct kvm_vcpu *vcpu, struct kvm_run *run) 48 73 { 49 74 kvm_inject_undefined(vcpu); ··· 707 682 { CRn( 0), CRm( 0), Op1( 1), Op2( 7), is32, NULL, get_AIDR }, 708 683 }; 709 684 685 + /* 686 + * Reads a register value from a userspace address to a kernel 687 + * variable. Make sure that register size matches sizeof(*__val). 688 + */ 710 689 static int reg_from_user(void *val, const void __user *uaddr, u64 id) 711 690 { 712 - /* This Just Works because we are little endian. */ 713 691 if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0) 714 692 return -EFAULT; 715 693 return 0; 716 694 } 717 695 696 + /* 697 + * Writes a register value to a userspace address from a kernel variable. 698 + * Make sure that register size matches sizeof(*__val). 699 + */ 718 700 static int reg_to_user(void __user *uaddr, const void *val, u64 id) 719 701 { 720 - /* This Just Works because we are little endian. */ 721 702 if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0) 722 703 return -EFAULT; 723 704 return 0; ··· 733 702 { 734 703 struct coproc_params params; 735 704 const struct coproc_reg *r; 705 + int ret; 736 706 737 707 if (!index_to_params(id, &params)) 738 708 return -ENOENT; ··· 742 710 if (!r) 743 711 return -ENOENT; 744 712 745 - return reg_to_user(uaddr, &r->val, id); 713 + ret = -ENOENT; 714 + if (KVM_REG_SIZE(id) == 4) { 715 + u32 val = r->val; 716 + 717 + ret = reg_to_user(uaddr, &val, id); 718 + } else if (KVM_REG_SIZE(id) == 8) { 719 + ret = reg_to_user(uaddr, &r->val, id); 720 + } 721 + return ret; 746 722 } 747 723 748 724 static int set_invariant_cp15(u64 id, void __user *uaddr) ··· 758 718 struct coproc_params params; 759 719 const struct coproc_reg *r; 760 720 int err; 761 - u64 val = 0; /* Make sure high bits are 0 for 32-bit regs */ 721 + u64 val; 762 722 763 723 if (!index_to_params(id, &params)) 764 724 return -ENOENT; ··· 766 726 if (!r) 767 727 return -ENOENT; 768 728 769 - err = reg_from_user(&val, uaddr, id); 729 + err = -ENOENT; 730 + if (KVM_REG_SIZE(id) == 4) { 731 + u32 val32; 732 + 733 + err = reg_from_user(&val32, uaddr, id); 734 + if (!err) 735 + val = val32; 736 + } else if (KVM_REG_SIZE(id) == 8) { 737 + err = reg_from_user(&val, uaddr, id); 738 + } 770 739 if (err) 771 740 return err; 772 741 ··· 1053 1004 { 1054 1005 const struct coproc_reg *r; 1055 1006 void __user *uaddr = (void __user *)(long)reg->addr; 1007 + int ret; 1056 1008 1057 1009 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX) 1058 1010 return demux_c15_get(reg->id, uaddr); ··· 1065 1015 if (!r) 1066 1016 return get_invariant_cp15(reg->id, uaddr); 1067 1017 1068 - /* Note: copies two regs if size is 64 bit. */ 1069 - return reg_to_user(uaddr, &vcpu->arch.cp15[r->reg], reg->id); 1018 + ret = -ENOENT; 1019 + if (KVM_REG_SIZE(reg->id) == 8) { 1020 + u64 val; 1021 + 1022 + val = vcpu_cp15_reg64_get(vcpu, r); 1023 + ret = reg_to_user(uaddr, &val, reg->id); 1024 + } else if (KVM_REG_SIZE(reg->id) == 4) { 1025 + ret = reg_to_user(uaddr, &vcpu->arch.cp15[r->reg], reg->id); 1026 + } 1027 + 1028 + return ret; 1070 1029 } 1071 1030 1072 1031 int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 1073 1032 { 1074 1033 const struct coproc_reg *r; 1075 1034 void __user *uaddr = (void __user *)(long)reg->addr; 1035 + int ret; 1076 1036 1077 1037 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX) 1078 1038 return demux_c15_set(reg->id, uaddr); ··· 1094 1034 if (!r) 1095 1035 return set_invariant_cp15(reg->id, uaddr); 1096 1036 1097 - /* Note: copies two regs if size is 64 bit */ 1098 - return reg_from_user(&vcpu->arch.cp15[r->reg], uaddr, reg->id); 1037 + ret = -ENOENT; 1038 + if (KVM_REG_SIZE(reg->id) == 8) { 1039 + u64 val; 1040 + 1041 + ret = reg_from_user(&val, uaddr, reg->id); 1042 + if (!ret) 1043 + vcpu_cp15_reg64_set(vcpu, r, val); 1044 + } else if (KVM_REG_SIZE(reg->id) == 4) { 1045 + ret = reg_from_user(&vcpu->arch.cp15[r->reg], uaddr, reg->id); 1046 + } 1047 + 1048 + return ret; 1099 1049 } 1100 1050 1101 1051 static unsigned int num_demux_regs(void)
-10
arch/arm/kvm/guest.c
··· 124 124 return false; 125 125 } 126 126 127 - int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) 128 - { 129 - return 0; 130 - } 131 - 132 - u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid) 133 - { 134 - return 0; 135 - } 136 - 137 127 #else 138 128 139 129 #define NUM_TIMER_REGS 3
+2 -2
arch/arm/kvm/init.S
··· 72 72 bne phase2 @ Yes, second stage init 73 73 74 74 @ Set the HTTBR to point to the hypervisor PGD pointer passed 75 - mcrr p15, 4, r2, r3, c2 75 + mcrr p15, 4, rr_lo_hi(r2, r3), c2 76 76 77 77 @ Set the HTCR and VTCR to the same shareability and cacheability 78 78 @ settings as the non-secure TTBCR and with T0SZ == 0. ··· 138 138 ret r0 139 139 140 140 target: @ We're now in the trampoline code, switch page tables 141 - mcrr p15, 4, r2, r3, c2 141 + mcrr p15, 4, rr_lo_hi(r2, r3), c2 142 142 isb 143 143 144 144 @ Invalidate the old TLBs
+7 -2
arch/arm/kvm/interrupts.S
··· 52 52 dsb ishst 53 53 add r0, r0, #KVM_VTTBR 54 54 ldrd r2, r3, [r0] 55 - mcrr p15, 6, r2, r3, c2 @ Write VTTBR 55 + mcrr p15, 6, rr_lo_hi(r2, r3), c2 @ Write VTTBR 56 56 isb 57 57 mcr p15, 0, r0, c8, c3, 0 @ TLBIALLIS (rt ignored) 58 58 dsb ish ··· 135 135 ldr r1, [vcpu, #VCPU_KVM] 136 136 add r1, r1, #KVM_VTTBR 137 137 ldrd r2, r3, [r1] 138 - mcrr p15, 6, r2, r3, c2 @ Write VTTBR 138 + mcrr p15, 6, rr_lo_hi(r2, r3), c2 @ Write VTTBR 139 139 140 140 @ We're all done, just restore the GPRs and go to the guest 141 141 restore_guest_regs ··· 199 199 200 200 restore_host_regs 201 201 clrex @ Clear exclusive monitor 202 + #ifndef CONFIG_CPU_ENDIAN_BE8 202 203 mov r0, r1 @ Return the return code 203 204 mov r1, #0 @ Clear upper bits in return value 205 + #else 206 + @ r1 already has return code 207 + mov r0, #0 @ Clear upper bits in return value 208 + #endif /* CONFIG_CPU_ENDIAN_BE8 */ 204 209 bx lr @ return to IOCTL 205 210 206 211 /********************************************************************
+30 -16
arch/arm/kvm/interrupts_head.S
··· 1 1 #include <linux/irqchip/arm-gic.h> 2 + #include <asm/assembler.h> 2 3 3 4 #define VCPU_USR_REG(_reg_nr) (VCPU_USR_REGS + (_reg_nr * 4)) 4 5 #define VCPU_USR_SP (VCPU_USR_REG(13)) ··· 421 420 ldr r8, [r2, #GICH_ELRSR0] 422 421 ldr r9, [r2, #GICH_ELRSR1] 423 422 ldr r10, [r2, #GICH_APR] 423 + ARM_BE8(rev r3, r3 ) 424 + ARM_BE8(rev r4, r4 ) 425 + ARM_BE8(rev r5, r5 ) 426 + ARM_BE8(rev r6, r6 ) 427 + ARM_BE8(rev r7, r7 ) 428 + ARM_BE8(rev r8, r8 ) 429 + ARM_BE8(rev r9, r9 ) 430 + ARM_BE8(rev r10, r10 ) 424 431 425 - str r3, [r11, #VGIC_CPU_HCR] 426 - str r4, [r11, #VGIC_CPU_VMCR] 427 - str r5, [r11, #VGIC_CPU_MISR] 428 - str r6, [r11, #VGIC_CPU_EISR] 429 - str r7, [r11, #(VGIC_CPU_EISR + 4)] 430 - str r8, [r11, #VGIC_CPU_ELRSR] 431 - str r9, [r11, #(VGIC_CPU_ELRSR + 4)] 432 - str r10, [r11, #VGIC_CPU_APR] 432 + str r3, [r11, #VGIC_V2_CPU_HCR] 433 + str r4, [r11, #VGIC_V2_CPU_VMCR] 434 + str r5, [r11, #VGIC_V2_CPU_MISR] 435 + str r6, [r11, #VGIC_V2_CPU_EISR] 436 + str r7, [r11, #(VGIC_V2_CPU_EISR + 4)] 437 + str r8, [r11, #VGIC_V2_CPU_ELRSR] 438 + str r9, [r11, #(VGIC_V2_CPU_ELRSR + 4)] 439 + str r10, [r11, #VGIC_V2_CPU_APR] 433 440 434 441 /* Clear GICH_HCR */ 435 442 mov r5, #0 ··· 445 436 446 437 /* Save list registers */ 447 438 add r2, r2, #GICH_LR0 448 - add r3, r11, #VGIC_CPU_LR 439 + add r3, r11, #VGIC_V2_CPU_LR 449 440 ldr r4, [r11, #VGIC_CPU_NR_LR] 450 441 1: ldr r6, [r2], #4 442 + ARM_BE8(rev r6, r6 ) 451 443 str r6, [r3], #4 452 444 subs r4, r4, #1 453 445 bne 1b ··· 473 463 add r11, vcpu, #VCPU_VGIC_CPU 474 464 475 465 /* We only restore a minimal set of registers */ 476 - ldr r3, [r11, #VGIC_CPU_HCR] 477 - ldr r4, [r11, #VGIC_CPU_VMCR] 478 - ldr r8, [r11, #VGIC_CPU_APR] 466 + ldr r3, [r11, #VGIC_V2_CPU_HCR] 467 + ldr r4, [r11, #VGIC_V2_CPU_VMCR] 468 + ldr r8, [r11, #VGIC_V2_CPU_APR] 469 + ARM_BE8(rev r3, r3 ) 470 + ARM_BE8(rev r4, r4 ) 471 + ARM_BE8(rev r8, r8 ) 479 472 480 473 str r3, [r2, #GICH_HCR] 481 474 str r4, [r2, #GICH_VMCR] ··· 486 473 487 474 /* Restore list registers */ 488 475 add r2, r2, #GICH_LR0 489 - add r3, r11, #VGIC_CPU_LR 476 + add r3, r11, #VGIC_V2_CPU_LR 490 477 ldr r4, [r11, #VGIC_CPU_NR_LR] 491 478 1: ldr r6, [r3], #4 479 + ARM_BE8(rev r6, r6 ) 492 480 str r6, [r2], #4 493 481 subs r4, r4, #1 494 482 bne 1b ··· 520 506 mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL 521 507 isb 522 508 523 - mrrc p15, 3, r2, r3, c14 @ CNTV_CVAL 509 + mrrc p15, 3, rr_lo_hi(r2, r3), c14 @ CNTV_CVAL 524 510 ldr r4, =VCPU_TIMER_CNTV_CVAL 525 511 add r5, vcpu, r4 526 512 strd r2, r3, [r5] ··· 560 546 561 547 ldr r2, [r4, #KVM_TIMER_CNTVOFF] 562 548 ldr r3, [r4, #(KVM_TIMER_CNTVOFF + 4)] 563 - mcrr p15, 4, r2, r3, c14 @ CNTVOFF 549 + mcrr p15, 4, rr_lo_hi(r2, r3), c14 @ CNTVOFF 564 550 565 551 ldr r4, =VCPU_TIMER_CNTV_CVAL 566 552 add r5, vcpu, r4 567 553 ldrd r2, r3, [r5] 568 - mcrr p15, 3, r2, r3, c14 @ CNTV_CVAL 554 + mcrr p15, 3, rr_lo_hi(r2, r3), c14 @ CNTV_CVAL 569 555 isb 570 556 571 557 ldr r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
+142 -80
arch/arm/kvm/mmu.c
··· 90 90 return p; 91 91 } 92 92 93 - static bool page_empty(void *ptr) 93 + static void clear_pgd_entry(struct kvm *kvm, pgd_t *pgd, phys_addr_t addr) 94 94 { 95 - struct page *ptr_page = virt_to_page(ptr); 96 - return page_count(ptr_page) == 1; 95 + pud_t *pud_table __maybe_unused = pud_offset(pgd, 0); 96 + pgd_clear(pgd); 97 + kvm_tlb_flush_vmid_ipa(kvm, addr); 98 + pud_free(NULL, pud_table); 99 + put_page(virt_to_page(pgd)); 97 100 } 98 101 99 102 static void clear_pud_entry(struct kvm *kvm, pud_t *pud, phys_addr_t addr) 100 103 { 101 - if (pud_huge(*pud)) { 102 - pud_clear(pud); 103 - kvm_tlb_flush_vmid_ipa(kvm, addr); 104 - } else { 105 - pmd_t *pmd_table = pmd_offset(pud, 0); 106 - pud_clear(pud); 107 - kvm_tlb_flush_vmid_ipa(kvm, addr); 108 - pmd_free(NULL, pmd_table); 109 - } 104 + pmd_t *pmd_table = pmd_offset(pud, 0); 105 + VM_BUG_ON(pud_huge(*pud)); 106 + pud_clear(pud); 107 + kvm_tlb_flush_vmid_ipa(kvm, addr); 108 + pmd_free(NULL, pmd_table); 110 109 put_page(virt_to_page(pud)); 111 110 } 112 111 113 112 static void clear_pmd_entry(struct kvm *kvm, pmd_t *pmd, phys_addr_t addr) 114 113 { 115 - if (kvm_pmd_huge(*pmd)) { 116 - pmd_clear(pmd); 117 - kvm_tlb_flush_vmid_ipa(kvm, addr); 118 - } else { 119 - pte_t *pte_table = pte_offset_kernel(pmd, 0); 120 - pmd_clear(pmd); 121 - kvm_tlb_flush_vmid_ipa(kvm, addr); 122 - pte_free_kernel(NULL, pte_table); 123 - } 114 + pte_t *pte_table = pte_offset_kernel(pmd, 0); 115 + VM_BUG_ON(kvm_pmd_huge(*pmd)); 116 + pmd_clear(pmd); 117 + kvm_tlb_flush_vmid_ipa(kvm, addr); 118 + pte_free_kernel(NULL, pte_table); 124 119 put_page(virt_to_page(pmd)); 125 120 } 126 121 127 - static void clear_pte_entry(struct kvm *kvm, pte_t *pte, phys_addr_t addr) 122 + static void unmap_ptes(struct kvm *kvm, pmd_t *pmd, 123 + phys_addr_t addr, phys_addr_t end) 128 124 { 129 - if (pte_present(*pte)) { 130 - kvm_set_pte(pte, __pte(0)); 131 - put_page(virt_to_page(pte)); 132 - kvm_tlb_flush_vmid_ipa(kvm, addr); 133 - } 125 + phys_addr_t start_addr = addr; 126 + pte_t *pte, *start_pte; 127 + 128 + start_pte = pte = pte_offset_kernel(pmd, addr); 129 + do { 130 + if (!pte_none(*pte)) { 131 + kvm_set_pte(pte, __pte(0)); 132 + put_page(virt_to_page(pte)); 133 + kvm_tlb_flush_vmid_ipa(kvm, addr); 134 + } 135 + } while (pte++, addr += PAGE_SIZE, addr != end); 136 + 137 + if (kvm_pte_table_empty(start_pte)) 138 + clear_pmd_entry(kvm, pmd, start_addr); 134 139 } 135 140 136 - static void unmap_range(struct kvm *kvm, pgd_t *pgdp, 137 - unsigned long long start, u64 size) 141 + static void unmap_pmds(struct kvm *kvm, pud_t *pud, 142 + phys_addr_t addr, phys_addr_t end) 138 143 { 139 - pgd_t *pgd; 140 - pud_t *pud; 141 - pmd_t *pmd; 142 - pte_t *pte; 143 - unsigned long long addr = start, end = start + size; 144 - u64 next; 144 + phys_addr_t next, start_addr = addr; 145 + pmd_t *pmd, *start_pmd; 145 146 146 - while (addr < end) { 147 - pgd = pgdp + pgd_index(addr); 148 - pud = pud_offset(pgd, addr); 149 - pte = NULL; 150 - if (pud_none(*pud)) { 151 - addr = kvm_pud_addr_end(addr, end); 152 - continue; 153 - } 154 - 155 - if (pud_huge(*pud)) { 156 - /* 157 - * If we are dealing with a huge pud, just clear it and 158 - * move on. 159 - */ 160 - clear_pud_entry(kvm, pud, addr); 161 - addr = kvm_pud_addr_end(addr, end); 162 - continue; 163 - } 164 - 165 - pmd = pmd_offset(pud, addr); 166 - if (pmd_none(*pmd)) { 167 - addr = kvm_pmd_addr_end(addr, end); 168 - continue; 169 - } 170 - 171 - if (!kvm_pmd_huge(*pmd)) { 172 - pte = pte_offset_kernel(pmd, addr); 173 - clear_pte_entry(kvm, pte, addr); 174 - next = addr + PAGE_SIZE; 175 - } 176 - 177 - /* 178 - * If the pmd entry is to be cleared, walk back up the ladder 179 - */ 180 - if (kvm_pmd_huge(*pmd) || (pte && page_empty(pte))) { 181 - clear_pmd_entry(kvm, pmd, addr); 182 - next = kvm_pmd_addr_end(addr, end); 183 - if (page_empty(pmd) && !page_empty(pud)) { 184 - clear_pud_entry(kvm, pud, addr); 185 - next = kvm_pud_addr_end(addr, end); 147 + start_pmd = pmd = pmd_offset(pud, addr); 148 + do { 149 + next = kvm_pmd_addr_end(addr, end); 150 + if (!pmd_none(*pmd)) { 151 + if (kvm_pmd_huge(*pmd)) { 152 + pmd_clear(pmd); 153 + kvm_tlb_flush_vmid_ipa(kvm, addr); 154 + put_page(virt_to_page(pmd)); 155 + } else { 156 + unmap_ptes(kvm, pmd, addr, next); 186 157 } 187 158 } 159 + } while (pmd++, addr = next, addr != end); 188 160 189 - addr = next; 190 - } 161 + if (kvm_pmd_table_empty(start_pmd)) 162 + clear_pud_entry(kvm, pud, start_addr); 163 + } 164 + 165 + static void unmap_puds(struct kvm *kvm, pgd_t *pgd, 166 + phys_addr_t addr, phys_addr_t end) 167 + { 168 + phys_addr_t next, start_addr = addr; 169 + pud_t *pud, *start_pud; 170 + 171 + start_pud = pud = pud_offset(pgd, addr); 172 + do { 173 + next = kvm_pud_addr_end(addr, end); 174 + if (!pud_none(*pud)) { 175 + if (pud_huge(*pud)) { 176 + pud_clear(pud); 177 + kvm_tlb_flush_vmid_ipa(kvm, addr); 178 + put_page(virt_to_page(pud)); 179 + } else { 180 + unmap_pmds(kvm, pud, addr, next); 181 + } 182 + } 183 + } while (pud++, addr = next, addr != end); 184 + 185 + if (kvm_pud_table_empty(start_pud)) 186 + clear_pgd_entry(kvm, pgd, start_addr); 187 + } 188 + 189 + 190 + static void unmap_range(struct kvm *kvm, pgd_t *pgdp, 191 + phys_addr_t start, u64 size) 192 + { 193 + pgd_t *pgd; 194 + phys_addr_t addr = start, end = start + size; 195 + phys_addr_t next; 196 + 197 + pgd = pgdp + pgd_index(addr); 198 + do { 199 + next = kvm_pgd_addr_end(addr, end); 200 + unmap_puds(kvm, pgd, addr, next); 201 + } while (pgd++, addr = next, addr != end); 191 202 } 192 203 193 204 static void stage2_flush_ptes(struct kvm *kvm, pmd_t *pmd, ··· 759 748 struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; 760 749 struct vm_area_struct *vma; 761 750 pfn_t pfn; 751 + pgprot_t mem_type = PAGE_S2; 762 752 763 753 write_fault = kvm_is_write_fault(kvm_vcpu_get_hsr(vcpu)); 764 754 if (fault_status == FSC_PERM && !write_fault) { ··· 810 798 if (is_error_pfn(pfn)) 811 799 return -EFAULT; 812 800 801 + if (kvm_is_mmio_pfn(pfn)) 802 + mem_type = PAGE_S2_DEVICE; 803 + 813 804 spin_lock(&kvm->mmu_lock); 814 805 if (mmu_notifier_retry(kvm, mmu_seq)) 815 806 goto out_unlock; ··· 820 805 hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa); 821 806 822 807 if (hugetlb) { 823 - pmd_t new_pmd = pfn_pmd(pfn, PAGE_S2); 808 + pmd_t new_pmd = pfn_pmd(pfn, mem_type); 824 809 new_pmd = pmd_mkhuge(new_pmd); 825 810 if (writable) { 826 811 kvm_set_s2pmd_writable(&new_pmd); ··· 829 814 coherent_cache_guest_page(vcpu, hva & PMD_MASK, PMD_SIZE); 830 815 ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd); 831 816 } else { 832 - pte_t new_pte = pfn_pte(pfn, PAGE_S2); 817 + pte_t new_pte = pfn_pte(pfn, mem_type); 833 818 if (writable) { 834 819 kvm_set_s2pte_writable(&new_pte); 835 820 kvm_set_pfn_dirty(pfn); 836 821 } 837 822 coherent_cache_guest_page(vcpu, hva, PAGE_SIZE); 838 - ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, false); 823 + ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, 824 + mem_type == PAGE_S2_DEVICE); 839 825 } 840 826 841 827 ··· 1115 1099 out: 1116 1100 free_hyp_pgds(); 1117 1101 return err; 1102 + } 1103 + 1104 + void kvm_arch_commit_memory_region(struct kvm *kvm, 1105 + struct kvm_userspace_memory_region *mem, 1106 + const struct kvm_memory_slot *old, 1107 + enum kvm_mr_change change) 1108 + { 1109 + gpa_t gpa = old->base_gfn << PAGE_SHIFT; 1110 + phys_addr_t size = old->npages << PAGE_SHIFT; 1111 + if (change == KVM_MR_DELETE || change == KVM_MR_MOVE) { 1112 + spin_lock(&kvm->mmu_lock); 1113 + unmap_stage2_range(kvm, gpa, size); 1114 + spin_unlock(&kvm->mmu_lock); 1115 + } 1116 + } 1117 + 1118 + int kvm_arch_prepare_memory_region(struct kvm *kvm, 1119 + struct kvm_memory_slot *memslot, 1120 + struct kvm_userspace_memory_region *mem, 1121 + enum kvm_mr_change change) 1122 + { 1123 + return 0; 1124 + } 1125 + 1126 + void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, 1127 + struct kvm_memory_slot *dont) 1128 + { 1129 + } 1130 + 1131 + int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, 1132 + unsigned long npages) 1133 + { 1134 + return 0; 1135 + } 1136 + 1137 + void kvm_arch_memslots_updated(struct kvm *kvm) 1138 + { 1139 + } 1140 + 1141 + void kvm_arch_flush_shadow_all(struct kvm *kvm) 1142 + { 1143 + } 1144 + 1145 + void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 1146 + struct kvm_memory_slot *slot) 1147 + { 1118 1148 }
+14 -5
arch/arm64/include/asm/debug-monitors.h
··· 18 18 19 19 #ifdef __KERNEL__ 20 20 21 + /* Low-level stepping controls. */ 22 + #define DBG_MDSCR_SS (1 << 0) 23 + #define DBG_SPSR_SS (1 << 21) 24 + 25 + /* MDSCR_EL1 enabling bits */ 26 + #define DBG_MDSCR_KDE (1 << 13) 27 + #define DBG_MDSCR_MDE (1 << 15) 28 + #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE) 29 + 21 30 #define DBG_ESR_EVT(x) (((x) >> 27) & 0x7) 22 31 23 32 /* AArch64 */ ··· 82 73 83 74 #define CACHE_FLUSH_IS_SAFE 1 84 75 85 - enum debug_el { 86 - DBG_ACTIVE_EL0 = 0, 87 - DBG_ACTIVE_EL1, 88 - }; 89 - 90 76 /* AArch32 */ 91 77 #define DBG_ESR_EVT_BKPT 0x4 92 78 #define DBG_ESR_EVT_VECC 0x5 ··· 118 114 void unregister_break_hook(struct break_hook *hook); 119 115 120 116 u8 debug_monitors_arch(void); 117 + 118 + enum debug_el { 119 + DBG_ACTIVE_EL0 = 0, 120 + DBG_ACTIVE_EL1, 121 + }; 121 122 122 123 void enable_debug_monitors(enum debug_el el); 123 124 void disable_debug_monitors(enum debug_el el);
+3 -2
arch/arm64/include/asm/kvm_arm.h
··· 76 76 */ 77 77 #define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \ 78 78 HCR_TVM | HCR_BSU_IS | HCR_FB | HCR_TAC | \ 79 - HCR_AMO | HCR_IMO | HCR_FMO | \ 80 - HCR_SWIO | HCR_TIDCP | HCR_RW) 79 + HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW) 81 80 #define HCR_VIRT_EXCP_MASK (HCR_VA | HCR_VI | HCR_VF) 81 + #define HCR_INT_OVERRIDE (HCR_FMO | HCR_IMO) 82 + 82 83 83 84 /* Hyp System Control Register (SCTLR_EL2) bits */ 84 85 #define SCTLR_EL2_EE (1 << 25)
+43 -10
arch/arm64/include/asm/kvm_asm.h
··· 18 18 #ifndef __ARM_KVM_ASM_H__ 19 19 #define __ARM_KVM_ASM_H__ 20 20 21 + #include <asm/virt.h> 22 + 21 23 /* 22 24 * 0 is reserved as an invalid value. 23 25 * Order *must* be kept in sync with the hyp switch code. ··· 45 43 #define AMAIR_EL1 19 /* Aux Memory Attribute Indirection Register */ 46 44 #define CNTKCTL_EL1 20 /* Timer Control Register (EL1) */ 47 45 #define PAR_EL1 21 /* Physical Address Register */ 46 + #define MDSCR_EL1 22 /* Monitor Debug System Control Register */ 47 + #define DBGBCR0_EL1 23 /* Debug Breakpoint Control Registers (0-15) */ 48 + #define DBGBCR15_EL1 38 49 + #define DBGBVR0_EL1 39 /* Debug Breakpoint Value Registers (0-15) */ 50 + #define DBGBVR15_EL1 54 51 + #define DBGWCR0_EL1 55 /* Debug Watchpoint Control Registers (0-15) */ 52 + #define DBGWCR15_EL1 70 53 + #define DBGWVR0_EL1 71 /* Debug Watchpoint Value Registers (0-15) */ 54 + #define DBGWVR15_EL1 86 55 + #define MDCCINT_EL1 87 /* Monitor Debug Comms Channel Interrupt Enable Reg */ 56 + 48 57 /* 32bit specific registers. Keep them at the end of the range */ 49 - #define DACR32_EL2 22 /* Domain Access Control Register */ 50 - #define IFSR32_EL2 23 /* Instruction Fault Status Register */ 51 - #define FPEXC32_EL2 24 /* Floating-Point Exception Control Register */ 52 - #define DBGVCR32_EL2 25 /* Debug Vector Catch Register */ 53 - #define TEECR32_EL1 26 /* ThumbEE Configuration Register */ 54 - #define TEEHBR32_EL1 27 /* ThumbEE Handler Base Register */ 55 - #define NR_SYS_REGS 28 58 + #define DACR32_EL2 88 /* Domain Access Control Register */ 59 + #define IFSR32_EL2 89 /* Instruction Fault Status Register */ 60 + #define FPEXC32_EL2 90 /* Floating-Point Exception Control Register */ 61 + #define DBGVCR32_EL2 91 /* Debug Vector Catch Register */ 62 + #define TEECR32_EL1 92 /* ThumbEE Configuration Register */ 63 + #define TEEHBR32_EL1 93 /* ThumbEE Handler Base Register */ 64 + #define NR_SYS_REGS 94 56 65 57 66 /* 32bit mapping */ 58 67 #define c0_MPIDR (MPIDR_EL1 * 2) /* MultiProcessor ID Register */ ··· 95 82 #define c10_AMAIR0 (AMAIR_EL1 * 2) /* Aux Memory Attr Indirection Reg */ 96 83 #define c10_AMAIR1 (c10_AMAIR0 + 1)/* Aux Memory Attr Indirection Reg */ 97 84 #define c14_CNTKCTL (CNTKCTL_EL1 * 2) /* Timer Control Register (PL1) */ 98 - #define NR_CP15_REGS (NR_SYS_REGS * 2) 85 + 86 + #define cp14_DBGDSCRext (MDSCR_EL1 * 2) 87 + #define cp14_DBGBCR0 (DBGBCR0_EL1 * 2) 88 + #define cp14_DBGBVR0 (DBGBVR0_EL1 * 2) 89 + #define cp14_DBGBXVR0 (cp14_DBGBVR0 + 1) 90 + #define cp14_DBGWCR0 (DBGWCR0_EL1 * 2) 91 + #define cp14_DBGWVR0 (DBGWVR0_EL1 * 2) 92 + #define cp14_DBGDCCINT (MDCCINT_EL1 * 2) 93 + 94 + #define NR_COPRO_REGS (NR_SYS_REGS * 2) 99 95 100 96 #define ARM_EXCEPTION_IRQ 0 101 97 #define ARM_EXCEPTION_TRAP 1 98 + 99 + #define KVM_ARM64_DEBUG_DIRTY_SHIFT 0 100 + #define KVM_ARM64_DEBUG_DIRTY (1 << KVM_ARM64_DEBUG_DIRTY_SHIFT) 102 101 103 102 #ifndef __ASSEMBLY__ 104 103 struct kvm; ··· 121 96 122 97 extern char __kvm_hyp_vector[]; 123 98 124 - extern char __kvm_hyp_code_start[]; 125 - extern char __kvm_hyp_code_end[]; 99 + #define __kvm_hyp_code_start __hyp_text_start 100 + #define __kvm_hyp_code_end __hyp_text_end 126 101 127 102 extern void __kvm_flush_vm_context(void); 128 103 extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa); 129 104 130 105 extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu); 106 + 107 + extern u64 __vgic_v3_get_ich_vtr_el2(void); 108 + 109 + extern char __save_vgic_v2_state[]; 110 + extern char __restore_vgic_v2_state[]; 111 + extern char __save_vgic_v3_state[]; 112 + extern char __restore_vgic_v3_state[]; 113 + 131 114 #endif 132 115 133 116 #endif /* __ARM_KVM_ASM_H__ */
+2 -1
arch/arm64/include/asm/kvm_coproc.h
··· 39 39 struct kvm_sys_reg_target_table *table); 40 40 41 41 int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu, struct kvm_run *run); 42 - int kvm_handle_cp14_access(struct kvm_vcpu *vcpu, struct kvm_run *run); 42 + int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run); 43 + int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run); 43 44 int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run); 44 45 int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run); 45 46 int kvm_handle_sys_reg(struct kvm_vcpu *vcpu, struct kvm_run *run);
+22
arch/arm64/include/asm/kvm_emulate.h
··· 213 213 default: 214 214 return be64_to_cpu(data); 215 215 } 216 + } else { 217 + switch (len) { 218 + case 1: 219 + return data & 0xff; 220 + case 2: 221 + return le16_to_cpu(data & 0xffff); 222 + case 4: 223 + return le32_to_cpu(data & 0xffffffff); 224 + default: 225 + return le64_to_cpu(data); 226 + } 216 227 } 217 228 218 229 return data; /* Leave LE untouched */ ··· 243 232 return cpu_to_be32(data & 0xffffffff); 244 233 default: 245 234 return cpu_to_be64(data); 235 + } 236 + } else { 237 + switch (len) { 238 + case 1: 239 + return data & 0xff; 240 + case 2: 241 + return cpu_to_le16(data & 0xffff); 242 + case 4: 243 + return cpu_to_le32(data & 0xffffffff); 244 + default: 245 + return cpu_to_le64(data); 246 246 } 247 247 } 248 248
+46 -2
arch/arm64/include/asm/kvm_host.h
··· 86 86 struct kvm_regs gp_regs; 87 87 union { 88 88 u64 sys_regs[NR_SYS_REGS]; 89 - u32 cp15[NR_CP15_REGS]; 89 + u32 copro[NR_COPRO_REGS]; 90 90 }; 91 91 }; 92 92 ··· 100 100 101 101 /* Exception Information */ 102 102 struct kvm_vcpu_fault_info fault; 103 + 104 + /* Debug state */ 105 + u64 debug_flags; 103 106 104 107 /* Pointer to host CPU context */ 105 108 kvm_cpu_context_t *host_cpu_context; ··· 141 138 142 139 #define vcpu_gp_regs(v) (&(v)->arch.ctxt.gp_regs) 143 140 #define vcpu_sys_reg(v,r) ((v)->arch.ctxt.sys_regs[(r)]) 144 - #define vcpu_cp15(v,r) ((v)->arch.ctxt.cp15[(r)]) 141 + /* 142 + * CP14 and CP15 live in the same array, as they are backed by the 143 + * same system registers. 144 + */ 145 + #define vcpu_cp14(v,r) ((v)->arch.ctxt.copro[(r)]) 146 + #define vcpu_cp15(v,r) ((v)->arch.ctxt.copro[(r)]) 147 + 148 + #ifdef CONFIG_CPU_BIG_ENDIAN 149 + #define vcpu_cp15_64_high(v,r) vcpu_cp15((v),(r)) 150 + #define vcpu_cp15_64_low(v,r) vcpu_cp15((v),(r) + 1) 151 + #else 152 + #define vcpu_cp15_64_high(v,r) vcpu_cp15((v),(r) + 1) 153 + #define vcpu_cp15_64_low(v,r) vcpu_cp15((v),(r)) 154 + #endif 145 155 146 156 struct kvm_vm_stat { 147 157 u32 remote_tlb_flush; ··· 214 198 */ 215 199 kvm_call_hyp((void *)boot_pgd_ptr, pgd_ptr, 216 200 hyp_stack_ptr, vector_ptr); 201 + } 202 + 203 + struct vgic_sr_vectors { 204 + void *save_vgic; 205 + void *restore_vgic; 206 + }; 207 + 208 + static inline void vgic_arch_setup(const struct vgic_params *vgic) 209 + { 210 + extern struct vgic_sr_vectors __vgic_sr_vectors; 211 + 212 + switch(vgic->type) 213 + { 214 + case VGIC_V2: 215 + __vgic_sr_vectors.save_vgic = __save_vgic_v2_state; 216 + __vgic_sr_vectors.restore_vgic = __restore_vgic_v2_state; 217 + break; 218 + 219 + #ifdef CONFIG_ARM_GIC_V3 220 + case VGIC_V3: 221 + __vgic_sr_vectors.save_vgic = __save_vgic_v3_state; 222 + __vgic_sr_vectors.restore_vgic = __restore_vgic_v3_state; 223 + break; 224 + #endif 225 + 226 + default: 227 + BUG(); 228 + } 217 229 } 218 230 219 231 #endif /* __ARM64_KVM_HOST_H__ */
+15
arch/arm64/include/asm/kvm_mmu.h
··· 125 125 #define kvm_pud_addr_end(addr, end) pud_addr_end(addr, end) 126 126 #define kvm_pmd_addr_end(addr, end) pmd_addr_end(addr, end) 127 127 128 + static inline bool kvm_page_empty(void *ptr) 129 + { 130 + struct page *ptr_page = virt_to_page(ptr); 131 + return page_count(ptr_page) == 1; 132 + } 133 + 134 + #define kvm_pte_table_empty(ptep) kvm_page_empty(ptep) 135 + #ifndef CONFIG_ARM64_64K_PAGES 136 + #define kvm_pmd_table_empty(pmdp) kvm_page_empty(pmdp) 137 + #else 138 + #define kvm_pmd_table_empty(pmdp) (0) 139 + #endif 140 + #define kvm_pud_table_empty(pudp) (0) 141 + 142 + 128 143 struct kvm; 129 144 130 145 #define kvm_flush_dcache_to_poc(a,l) __flush_dcache_area((a), (l))
+4
arch/arm64/include/asm/virt.h
··· 50 50 return __boot_cpu_mode[0] != __boot_cpu_mode[1]; 51 51 } 52 52 53 + /* The section containing the hypervisor text */ 54 + extern char __hyp_text_start[]; 55 + extern char __hyp_text_end[]; 56 + 53 57 #endif /* __ASSEMBLY__ */ 54 58 55 59 #endif /* ! __ASM__VIRT_H */
+19 -7
arch/arm64/kernel/asm-offsets.c
··· 120 120 DEFINE(VCPU_ESR_EL2, offsetof(struct kvm_vcpu, arch.fault.esr_el2)); 121 121 DEFINE(VCPU_FAR_EL2, offsetof(struct kvm_vcpu, arch.fault.far_el2)); 122 122 DEFINE(VCPU_HPFAR_EL2, offsetof(struct kvm_vcpu, arch.fault.hpfar_el2)); 123 + DEFINE(VCPU_DEBUG_FLAGS, offsetof(struct kvm_vcpu, arch.debug_flags)); 123 124 DEFINE(VCPU_HCR_EL2, offsetof(struct kvm_vcpu, arch.hcr_el2)); 124 125 DEFINE(VCPU_IRQ_LINES, offsetof(struct kvm_vcpu, arch.irq_lines)); 125 126 DEFINE(VCPU_HOST_CONTEXT, offsetof(struct kvm_vcpu, arch.host_cpu_context)); ··· 130 129 DEFINE(KVM_TIMER_ENABLED, offsetof(struct kvm, arch.timer.enabled)); 131 130 DEFINE(VCPU_KVM, offsetof(struct kvm_vcpu, kvm)); 132 131 DEFINE(VCPU_VGIC_CPU, offsetof(struct kvm_vcpu, arch.vgic_cpu)); 133 - DEFINE(VGIC_CPU_HCR, offsetof(struct vgic_cpu, vgic_hcr)); 134 - DEFINE(VGIC_CPU_VMCR, offsetof(struct vgic_cpu, vgic_vmcr)); 135 - DEFINE(VGIC_CPU_MISR, offsetof(struct vgic_cpu, vgic_misr)); 136 - DEFINE(VGIC_CPU_EISR, offsetof(struct vgic_cpu, vgic_eisr)); 137 - DEFINE(VGIC_CPU_ELRSR, offsetof(struct vgic_cpu, vgic_elrsr)); 138 - DEFINE(VGIC_CPU_APR, offsetof(struct vgic_cpu, vgic_apr)); 139 - DEFINE(VGIC_CPU_LR, offsetof(struct vgic_cpu, vgic_lr)); 132 + DEFINE(VGIC_SAVE_FN, offsetof(struct vgic_sr_vectors, save_vgic)); 133 + DEFINE(VGIC_RESTORE_FN, offsetof(struct vgic_sr_vectors, restore_vgic)); 134 + DEFINE(VGIC_SR_VECTOR_SZ, sizeof(struct vgic_sr_vectors)); 135 + DEFINE(VGIC_V2_CPU_HCR, offsetof(struct vgic_cpu, vgic_v2.vgic_hcr)); 136 + DEFINE(VGIC_V2_CPU_VMCR, offsetof(struct vgic_cpu, vgic_v2.vgic_vmcr)); 137 + DEFINE(VGIC_V2_CPU_MISR, offsetof(struct vgic_cpu, vgic_v2.vgic_misr)); 138 + DEFINE(VGIC_V2_CPU_EISR, offsetof(struct vgic_cpu, vgic_v2.vgic_eisr)); 139 + DEFINE(VGIC_V2_CPU_ELRSR, offsetof(struct vgic_cpu, vgic_v2.vgic_elrsr)); 140 + DEFINE(VGIC_V2_CPU_APR, offsetof(struct vgic_cpu, vgic_v2.vgic_apr)); 141 + DEFINE(VGIC_V2_CPU_LR, offsetof(struct vgic_cpu, vgic_v2.vgic_lr)); 142 + DEFINE(VGIC_V3_CPU_HCR, offsetof(struct vgic_cpu, vgic_v3.vgic_hcr)); 143 + DEFINE(VGIC_V3_CPU_VMCR, offsetof(struct vgic_cpu, vgic_v3.vgic_vmcr)); 144 + DEFINE(VGIC_V3_CPU_MISR, offsetof(struct vgic_cpu, vgic_v3.vgic_misr)); 145 + DEFINE(VGIC_V3_CPU_EISR, offsetof(struct vgic_cpu, vgic_v3.vgic_eisr)); 146 + DEFINE(VGIC_V3_CPU_ELRSR, offsetof(struct vgic_cpu, vgic_v3.vgic_elrsr)); 147 + DEFINE(VGIC_V3_CPU_AP0R, offsetof(struct vgic_cpu, vgic_v3.vgic_ap0r)); 148 + DEFINE(VGIC_V3_CPU_AP1R, offsetof(struct vgic_cpu, vgic_v3.vgic_ap1r)); 149 + DEFINE(VGIC_V3_CPU_LR, offsetof(struct vgic_cpu, vgic_v3.vgic_lr)); 140 150 DEFINE(VGIC_CPU_NR_LR, offsetof(struct vgic_cpu, nr_lr)); 141 151 DEFINE(KVM_VTTBR, offsetof(struct kvm, arch.vttbr)); 142 152 DEFINE(KVM_VGIC_VCTRL, offsetof(struct kvm, arch.vgic.vctrl_base));
-9
arch/arm64/kernel/debug-monitors.c
··· 30 30 #include <asm/cputype.h> 31 31 #include <asm/system_misc.h> 32 32 33 - /* Low-level stepping controls. */ 34 - #define DBG_MDSCR_SS (1 << 0) 35 - #define DBG_SPSR_SS (1 << 21) 36 - 37 - /* MDSCR_EL1 enabling bits */ 38 - #define DBG_MDSCR_KDE (1 << 13) 39 - #define DBG_MDSCR_MDE (1 << 15) 40 - #define DBG_MDSCR_MASK ~(DBG_MDSCR_KDE | DBG_MDSCR_MDE) 41 - 42 33 /* Determine debug architecture. */ 43 34 u8 debug_monitors_arch(void) 44 35 {
+4
arch/arm64/kvm/Makefile
··· 20 20 kvm-$(CONFIG_KVM_ARM_HOST) += guest.o reset.o sys_regs.o sys_regs_generic_v8.o 21 21 22 22 kvm-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic.o 23 + kvm-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic-v2.o 24 + kvm-$(CONFIG_KVM_ARM_VGIC) += vgic-v2-switch.o 25 + kvm-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic-v3.o 26 + kvm-$(CONFIG_KVM_ARM_VGIC) += vgic-v3-switch.o 23 27 kvm-$(CONFIG_KVM_ARM_TIMER) += $(KVM)/arm/arch_timer.o
+67 -1
arch/arm64/kvm/guest.c
··· 136 136 } 137 137 138 138 /** 139 + * ARM64 versions of the TIMER registers, always available on arm64 140 + */ 141 + 142 + #define NUM_TIMER_REGS 3 143 + 144 + static bool is_timer_reg(u64 index) 145 + { 146 + switch (index) { 147 + case KVM_REG_ARM_TIMER_CTL: 148 + case KVM_REG_ARM_TIMER_CNT: 149 + case KVM_REG_ARM_TIMER_CVAL: 150 + return true; 151 + } 152 + return false; 153 + } 154 + 155 + static int copy_timer_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) 156 + { 157 + if (put_user(KVM_REG_ARM_TIMER_CTL, uindices)) 158 + return -EFAULT; 159 + uindices++; 160 + if (put_user(KVM_REG_ARM_TIMER_CNT, uindices)) 161 + return -EFAULT; 162 + uindices++; 163 + if (put_user(KVM_REG_ARM_TIMER_CVAL, uindices)) 164 + return -EFAULT; 165 + 166 + return 0; 167 + } 168 + 169 + static int set_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 170 + { 171 + void __user *uaddr = (void __user *)(long)reg->addr; 172 + u64 val; 173 + int ret; 174 + 175 + ret = copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id)); 176 + if (ret != 0) 177 + return ret; 178 + 179 + return kvm_arm_timer_set_reg(vcpu, reg->id, val); 180 + } 181 + 182 + static int get_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) 183 + { 184 + void __user *uaddr = (void __user *)(long)reg->addr; 185 + u64 val; 186 + 187 + val = kvm_arm_timer_get_reg(vcpu, reg->id); 188 + return copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id)); 189 + } 190 + 191 + /** 139 192 * kvm_arm_num_regs - how many registers do we present via KVM_GET_ONE_REG 140 193 * 141 194 * This is for all registers. 142 195 */ 143 196 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu) 144 197 { 145 - return num_core_regs() + kvm_arm_num_sys_reg_descs(vcpu); 198 + return num_core_regs() + kvm_arm_num_sys_reg_descs(vcpu) 199 + + NUM_TIMER_REGS; 146 200 } 147 201 148 202 /** ··· 208 154 { 209 155 unsigned int i; 210 156 const u64 core_reg = KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE; 157 + int ret; 211 158 212 159 for (i = 0; i < sizeof(struct kvm_regs) / sizeof(__u32); i++) { 213 160 if (put_user(core_reg | i, uindices)) 214 161 return -EFAULT; 215 162 uindices++; 216 163 } 164 + 165 + ret = copy_timer_indices(vcpu, uindices); 166 + if (ret) 167 + return ret; 168 + uindices += NUM_TIMER_REGS; 217 169 218 170 return kvm_arm_copy_sys_reg_indices(vcpu, uindices); 219 171 } ··· 234 174 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE) 235 175 return get_core_reg(vcpu, reg); 236 176 177 + if (is_timer_reg(reg->id)) 178 + return get_timer_reg(vcpu, reg); 179 + 237 180 return kvm_arm_sys_reg_get_reg(vcpu, reg); 238 181 } 239 182 ··· 249 186 /* Register group 16 means we set a core register. */ 250 187 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE) 251 188 return set_core_reg(vcpu, reg); 189 + 190 + if (is_timer_reg(reg->id)) 191 + return set_timer_reg(vcpu, reg); 252 192 253 193 return kvm_arm_sys_reg_set_reg(vcpu, reg); 254 194 }
+2 -2
arch/arm64/kvm/handle_exit.c
··· 73 73 [ESR_EL2_EC_WFI] = kvm_handle_wfx, 74 74 [ESR_EL2_EC_CP15_32] = kvm_handle_cp15_32, 75 75 [ESR_EL2_EC_CP15_64] = kvm_handle_cp15_64, 76 - [ESR_EL2_EC_CP14_MR] = kvm_handle_cp14_access, 76 + [ESR_EL2_EC_CP14_MR] = kvm_handle_cp14_32, 77 77 [ESR_EL2_EC_CP14_LS] = kvm_handle_cp14_load_store, 78 - [ESR_EL2_EC_CP14_64] = kvm_handle_cp14_access, 78 + [ESR_EL2_EC_CP14_64] = kvm_handle_cp14_64, 79 79 [ESR_EL2_EC_HVC32] = handle_hvc, 80 80 [ESR_EL2_EC_SMC32] = handle_smc, 81 81 [ESR_EL2_EC_HVC64] = handle_hvc,
+494 -106
arch/arm64/kvm/hyp.S
··· 16 16 */ 17 17 18 18 #include <linux/linkage.h> 19 - #include <linux/irqchip/arm-gic.h> 20 19 21 20 #include <asm/assembler.h> 22 21 #include <asm/memory.h> 23 22 #include <asm/asm-offsets.h> 23 + #include <asm/debug-monitors.h> 24 24 #include <asm/fpsimdmacros.h> 25 25 #include <asm/kvm.h> 26 26 #include <asm/kvm_asm.h> ··· 35 35 .text 36 36 .pushsection .hyp.text, "ax" 37 37 .align PAGE_SHIFT 38 - 39 - __kvm_hyp_code_start: 40 - .globl __kvm_hyp_code_start 41 38 42 39 .macro save_common_regs 43 40 // x2: base address for cpu context ··· 212 215 mrs x22, amair_el1 213 216 mrs x23, cntkctl_el1 214 217 mrs x24, par_el1 218 + mrs x25, mdscr_el1 215 219 216 220 stp x4, x5, [x3] 217 221 stp x6, x7, [x3, #16] ··· 224 226 stp x18, x19, [x3, #112] 225 227 stp x20, x21, [x3, #128] 226 228 stp x22, x23, [x3, #144] 227 - str x24, [x3, #160] 229 + stp x24, x25, [x3, #160] 230 + .endm 231 + 232 + .macro save_debug 233 + // x2: base address for cpu context 234 + // x3: tmp register 235 + 236 + mrs x26, id_aa64dfr0_el1 237 + ubfx x24, x26, #12, #4 // Extract BRPs 238 + ubfx x25, x26, #20, #4 // Extract WRPs 239 + mov w26, #15 240 + sub w24, w26, w24 // How many BPs to skip 241 + sub w25, w26, w25 // How many WPs to skip 242 + 243 + add x3, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1) 244 + 245 + adr x26, 1f 246 + add x26, x26, x24, lsl #2 247 + br x26 248 + 1: 249 + mrs x20, dbgbcr15_el1 250 + mrs x19, dbgbcr14_el1 251 + mrs x18, dbgbcr13_el1 252 + mrs x17, dbgbcr12_el1 253 + mrs x16, dbgbcr11_el1 254 + mrs x15, dbgbcr10_el1 255 + mrs x14, dbgbcr9_el1 256 + mrs x13, dbgbcr8_el1 257 + mrs x12, dbgbcr7_el1 258 + mrs x11, dbgbcr6_el1 259 + mrs x10, dbgbcr5_el1 260 + mrs x9, dbgbcr4_el1 261 + mrs x8, dbgbcr3_el1 262 + mrs x7, dbgbcr2_el1 263 + mrs x6, dbgbcr1_el1 264 + mrs x5, dbgbcr0_el1 265 + 266 + adr x26, 1f 267 + add x26, x26, x24, lsl #2 268 + br x26 269 + 270 + 1: 271 + str x20, [x3, #(15 * 8)] 272 + str x19, [x3, #(14 * 8)] 273 + str x18, [x3, #(13 * 8)] 274 + str x17, [x3, #(12 * 8)] 275 + str x16, [x3, #(11 * 8)] 276 + str x15, [x3, #(10 * 8)] 277 + str x14, [x3, #(9 * 8)] 278 + str x13, [x3, #(8 * 8)] 279 + str x12, [x3, #(7 * 8)] 280 + str x11, [x3, #(6 * 8)] 281 + str x10, [x3, #(5 * 8)] 282 + str x9, [x3, #(4 * 8)] 283 + str x8, [x3, #(3 * 8)] 284 + str x7, [x3, #(2 * 8)] 285 + str x6, [x3, #(1 * 8)] 286 + str x5, [x3, #(0 * 8)] 287 + 288 + add x3, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1) 289 + 290 + adr x26, 1f 291 + add x26, x26, x24, lsl #2 292 + br x26 293 + 1: 294 + mrs x20, dbgbvr15_el1 295 + mrs x19, dbgbvr14_el1 296 + mrs x18, dbgbvr13_el1 297 + mrs x17, dbgbvr12_el1 298 + mrs x16, dbgbvr11_el1 299 + mrs x15, dbgbvr10_el1 300 + mrs x14, dbgbvr9_el1 301 + mrs x13, dbgbvr8_el1 302 + mrs x12, dbgbvr7_el1 303 + mrs x11, dbgbvr6_el1 304 + mrs x10, dbgbvr5_el1 305 + mrs x9, dbgbvr4_el1 306 + mrs x8, dbgbvr3_el1 307 + mrs x7, dbgbvr2_el1 308 + mrs x6, dbgbvr1_el1 309 + mrs x5, dbgbvr0_el1 310 + 311 + adr x26, 1f 312 + add x26, x26, x24, lsl #2 313 + br x26 314 + 315 + 1: 316 + str x20, [x3, #(15 * 8)] 317 + str x19, [x3, #(14 * 8)] 318 + str x18, [x3, #(13 * 8)] 319 + str x17, [x3, #(12 * 8)] 320 + str x16, [x3, #(11 * 8)] 321 + str x15, [x3, #(10 * 8)] 322 + str x14, [x3, #(9 * 8)] 323 + str x13, [x3, #(8 * 8)] 324 + str x12, [x3, #(7 * 8)] 325 + str x11, [x3, #(6 * 8)] 326 + str x10, [x3, #(5 * 8)] 327 + str x9, [x3, #(4 * 8)] 328 + str x8, [x3, #(3 * 8)] 329 + str x7, [x3, #(2 * 8)] 330 + str x6, [x3, #(1 * 8)] 331 + str x5, [x3, #(0 * 8)] 332 + 333 + add x3, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1) 334 + 335 + adr x26, 1f 336 + add x26, x26, x25, lsl #2 337 + br x26 338 + 1: 339 + mrs x20, dbgwcr15_el1 340 + mrs x19, dbgwcr14_el1 341 + mrs x18, dbgwcr13_el1 342 + mrs x17, dbgwcr12_el1 343 + mrs x16, dbgwcr11_el1 344 + mrs x15, dbgwcr10_el1 345 + mrs x14, dbgwcr9_el1 346 + mrs x13, dbgwcr8_el1 347 + mrs x12, dbgwcr7_el1 348 + mrs x11, dbgwcr6_el1 349 + mrs x10, dbgwcr5_el1 350 + mrs x9, dbgwcr4_el1 351 + mrs x8, dbgwcr3_el1 352 + mrs x7, dbgwcr2_el1 353 + mrs x6, dbgwcr1_el1 354 + mrs x5, dbgwcr0_el1 355 + 356 + adr x26, 1f 357 + add x26, x26, x25, lsl #2 358 + br x26 359 + 360 + 1: 361 + str x20, [x3, #(15 * 8)] 362 + str x19, [x3, #(14 * 8)] 363 + str x18, [x3, #(13 * 8)] 364 + str x17, [x3, #(12 * 8)] 365 + str x16, [x3, #(11 * 8)] 366 + str x15, [x3, #(10 * 8)] 367 + str x14, [x3, #(9 * 8)] 368 + str x13, [x3, #(8 * 8)] 369 + str x12, [x3, #(7 * 8)] 370 + str x11, [x3, #(6 * 8)] 371 + str x10, [x3, #(5 * 8)] 372 + str x9, [x3, #(4 * 8)] 373 + str x8, [x3, #(3 * 8)] 374 + str x7, [x3, #(2 * 8)] 375 + str x6, [x3, #(1 * 8)] 376 + str x5, [x3, #(0 * 8)] 377 + 378 + add x3, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1) 379 + 380 + adr x26, 1f 381 + add x26, x26, x25, lsl #2 382 + br x26 383 + 1: 384 + mrs x20, dbgwvr15_el1 385 + mrs x19, dbgwvr14_el1 386 + mrs x18, dbgwvr13_el1 387 + mrs x17, dbgwvr12_el1 388 + mrs x16, dbgwvr11_el1 389 + mrs x15, dbgwvr10_el1 390 + mrs x14, dbgwvr9_el1 391 + mrs x13, dbgwvr8_el1 392 + mrs x12, dbgwvr7_el1 393 + mrs x11, dbgwvr6_el1 394 + mrs x10, dbgwvr5_el1 395 + mrs x9, dbgwvr4_el1 396 + mrs x8, dbgwvr3_el1 397 + mrs x7, dbgwvr2_el1 398 + mrs x6, dbgwvr1_el1 399 + mrs x5, dbgwvr0_el1 400 + 401 + adr x26, 1f 402 + add x26, x26, x25, lsl #2 403 + br x26 404 + 405 + 1: 406 + str x20, [x3, #(15 * 8)] 407 + str x19, [x3, #(14 * 8)] 408 + str x18, [x3, #(13 * 8)] 409 + str x17, [x3, #(12 * 8)] 410 + str x16, [x3, #(11 * 8)] 411 + str x15, [x3, #(10 * 8)] 412 + str x14, [x3, #(9 * 8)] 413 + str x13, [x3, #(8 * 8)] 414 + str x12, [x3, #(7 * 8)] 415 + str x11, [x3, #(6 * 8)] 416 + str x10, [x3, #(5 * 8)] 417 + str x9, [x3, #(4 * 8)] 418 + str x8, [x3, #(3 * 8)] 419 + str x7, [x3, #(2 * 8)] 420 + str x6, [x3, #(1 * 8)] 421 + str x5, [x3, #(0 * 8)] 422 + 423 + mrs x21, mdccint_el1 424 + str x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)] 228 425 .endm 229 426 230 427 .macro restore_sysregs ··· 438 245 ldp x18, x19, [x3, #112] 439 246 ldp x20, x21, [x3, #128] 440 247 ldp x22, x23, [x3, #144] 441 - ldr x24, [x3, #160] 248 + ldp x24, x25, [x3, #160] 442 249 443 250 msr vmpidr_el2, x4 444 251 msr csselr_el1, x5 ··· 461 268 msr amair_el1, x22 462 269 msr cntkctl_el1, x23 463 270 msr par_el1, x24 271 + msr mdscr_el1, x25 272 + .endm 273 + 274 + .macro restore_debug 275 + // x2: base address for cpu context 276 + // x3: tmp register 277 + 278 + mrs x26, id_aa64dfr0_el1 279 + ubfx x24, x26, #12, #4 // Extract BRPs 280 + ubfx x25, x26, #20, #4 // Extract WRPs 281 + mov w26, #15 282 + sub w24, w26, w24 // How many BPs to skip 283 + sub w25, w26, w25 // How many WPs to skip 284 + 285 + add x3, x2, #CPU_SYSREG_OFFSET(DBGBCR0_EL1) 286 + 287 + adr x26, 1f 288 + add x26, x26, x24, lsl #2 289 + br x26 290 + 1: 291 + ldr x20, [x3, #(15 * 8)] 292 + ldr x19, [x3, #(14 * 8)] 293 + ldr x18, [x3, #(13 * 8)] 294 + ldr x17, [x3, #(12 * 8)] 295 + ldr x16, [x3, #(11 * 8)] 296 + ldr x15, [x3, #(10 * 8)] 297 + ldr x14, [x3, #(9 * 8)] 298 + ldr x13, [x3, #(8 * 8)] 299 + ldr x12, [x3, #(7 * 8)] 300 + ldr x11, [x3, #(6 * 8)] 301 + ldr x10, [x3, #(5 * 8)] 302 + ldr x9, [x3, #(4 * 8)] 303 + ldr x8, [x3, #(3 * 8)] 304 + ldr x7, [x3, #(2 * 8)] 305 + ldr x6, [x3, #(1 * 8)] 306 + ldr x5, [x3, #(0 * 8)] 307 + 308 + adr x26, 1f 309 + add x26, x26, x24, lsl #2 310 + br x26 311 + 1: 312 + msr dbgbcr15_el1, x20 313 + msr dbgbcr14_el1, x19 314 + msr dbgbcr13_el1, x18 315 + msr dbgbcr12_el1, x17 316 + msr dbgbcr11_el1, x16 317 + msr dbgbcr10_el1, x15 318 + msr dbgbcr9_el1, x14 319 + msr dbgbcr8_el1, x13 320 + msr dbgbcr7_el1, x12 321 + msr dbgbcr6_el1, x11 322 + msr dbgbcr5_el1, x10 323 + msr dbgbcr4_el1, x9 324 + msr dbgbcr3_el1, x8 325 + msr dbgbcr2_el1, x7 326 + msr dbgbcr1_el1, x6 327 + msr dbgbcr0_el1, x5 328 + 329 + add x3, x2, #CPU_SYSREG_OFFSET(DBGBVR0_EL1) 330 + 331 + adr x26, 1f 332 + add x26, x26, x24, lsl #2 333 + br x26 334 + 1: 335 + ldr x20, [x3, #(15 * 8)] 336 + ldr x19, [x3, #(14 * 8)] 337 + ldr x18, [x3, #(13 * 8)] 338 + ldr x17, [x3, #(12 * 8)] 339 + ldr x16, [x3, #(11 * 8)] 340 + ldr x15, [x3, #(10 * 8)] 341 + ldr x14, [x3, #(9 * 8)] 342 + ldr x13, [x3, #(8 * 8)] 343 + ldr x12, [x3, #(7 * 8)] 344 + ldr x11, [x3, #(6 * 8)] 345 + ldr x10, [x3, #(5 * 8)] 346 + ldr x9, [x3, #(4 * 8)] 347 + ldr x8, [x3, #(3 * 8)] 348 + ldr x7, [x3, #(2 * 8)] 349 + ldr x6, [x3, #(1 * 8)] 350 + ldr x5, [x3, #(0 * 8)] 351 + 352 + adr x26, 1f 353 + add x26, x26, x24, lsl #2 354 + br x26 355 + 1: 356 + msr dbgbvr15_el1, x20 357 + msr dbgbvr14_el1, x19 358 + msr dbgbvr13_el1, x18 359 + msr dbgbvr12_el1, x17 360 + msr dbgbvr11_el1, x16 361 + msr dbgbvr10_el1, x15 362 + msr dbgbvr9_el1, x14 363 + msr dbgbvr8_el1, x13 364 + msr dbgbvr7_el1, x12 365 + msr dbgbvr6_el1, x11 366 + msr dbgbvr5_el1, x10 367 + msr dbgbvr4_el1, x9 368 + msr dbgbvr3_el1, x8 369 + msr dbgbvr2_el1, x7 370 + msr dbgbvr1_el1, x6 371 + msr dbgbvr0_el1, x5 372 + 373 + add x3, x2, #CPU_SYSREG_OFFSET(DBGWCR0_EL1) 374 + 375 + adr x26, 1f 376 + add x26, x26, x25, lsl #2 377 + br x26 378 + 1: 379 + ldr x20, [x3, #(15 * 8)] 380 + ldr x19, [x3, #(14 * 8)] 381 + ldr x18, [x3, #(13 * 8)] 382 + ldr x17, [x3, #(12 * 8)] 383 + ldr x16, [x3, #(11 * 8)] 384 + ldr x15, [x3, #(10 * 8)] 385 + ldr x14, [x3, #(9 * 8)] 386 + ldr x13, [x3, #(8 * 8)] 387 + ldr x12, [x3, #(7 * 8)] 388 + ldr x11, [x3, #(6 * 8)] 389 + ldr x10, [x3, #(5 * 8)] 390 + ldr x9, [x3, #(4 * 8)] 391 + ldr x8, [x3, #(3 * 8)] 392 + ldr x7, [x3, #(2 * 8)] 393 + ldr x6, [x3, #(1 * 8)] 394 + ldr x5, [x3, #(0 * 8)] 395 + 396 + adr x26, 1f 397 + add x26, x26, x25, lsl #2 398 + br x26 399 + 1: 400 + msr dbgwcr15_el1, x20 401 + msr dbgwcr14_el1, x19 402 + msr dbgwcr13_el1, x18 403 + msr dbgwcr12_el1, x17 404 + msr dbgwcr11_el1, x16 405 + msr dbgwcr10_el1, x15 406 + msr dbgwcr9_el1, x14 407 + msr dbgwcr8_el1, x13 408 + msr dbgwcr7_el1, x12 409 + msr dbgwcr6_el1, x11 410 + msr dbgwcr5_el1, x10 411 + msr dbgwcr4_el1, x9 412 + msr dbgwcr3_el1, x8 413 + msr dbgwcr2_el1, x7 414 + msr dbgwcr1_el1, x6 415 + msr dbgwcr0_el1, x5 416 + 417 + add x3, x2, #CPU_SYSREG_OFFSET(DBGWVR0_EL1) 418 + 419 + adr x26, 1f 420 + add x26, x26, x25, lsl #2 421 + br x26 422 + 1: 423 + ldr x20, [x3, #(15 * 8)] 424 + ldr x19, [x3, #(14 * 8)] 425 + ldr x18, [x3, #(13 * 8)] 426 + ldr x17, [x3, #(12 * 8)] 427 + ldr x16, [x3, #(11 * 8)] 428 + ldr x15, [x3, #(10 * 8)] 429 + ldr x14, [x3, #(9 * 8)] 430 + ldr x13, [x3, #(8 * 8)] 431 + ldr x12, [x3, #(7 * 8)] 432 + ldr x11, [x3, #(6 * 8)] 433 + ldr x10, [x3, #(5 * 8)] 434 + ldr x9, [x3, #(4 * 8)] 435 + ldr x8, [x3, #(3 * 8)] 436 + ldr x7, [x3, #(2 * 8)] 437 + ldr x6, [x3, #(1 * 8)] 438 + ldr x5, [x3, #(0 * 8)] 439 + 440 + adr x26, 1f 441 + add x26, x26, x25, lsl #2 442 + br x26 443 + 1: 444 + msr dbgwvr15_el1, x20 445 + msr dbgwvr14_el1, x19 446 + msr dbgwvr13_el1, x18 447 + msr dbgwvr12_el1, x17 448 + msr dbgwvr11_el1, x16 449 + msr dbgwvr10_el1, x15 450 + msr dbgwvr9_el1, x14 451 + msr dbgwvr8_el1, x13 452 + msr dbgwvr7_el1, x12 453 + msr dbgwvr6_el1, x11 454 + msr dbgwvr5_el1, x10 455 + msr dbgwvr4_el1, x9 456 + msr dbgwvr3_el1, x8 457 + msr dbgwvr2_el1, x7 458 + msr dbgwvr1_el1, x6 459 + msr dbgwvr0_el1, x5 460 + 461 + ldr x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)] 462 + msr mdccint_el1, x21 464 463 .endm 465 464 466 465 .macro skip_32bit_state tmp, target ··· 665 280 // Skip ThumbEE state if not needed 666 281 mrs \tmp, id_pfr0_el1 667 282 tbz \tmp, #12, \target 283 + .endm 284 + 285 + .macro skip_debug_state tmp, target 286 + ldr \tmp, [x0, #VCPU_DEBUG_FLAGS] 287 + tbz \tmp, #KVM_ARM64_DEBUG_DIRTY_SHIFT, \target 288 + .endm 289 + 290 + .macro compute_debug_state target 291 + // Compute debug state: If any of KDE, MDE or KVM_ARM64_DEBUG_DIRTY 292 + // is set, we do a full save/restore cycle and disable trapping. 293 + add x25, x0, #VCPU_CONTEXT 294 + 295 + // Check the state of MDSCR_EL1 296 + ldr x25, [x25, #CPU_SYSREG_OFFSET(MDSCR_EL1)] 297 + and x26, x25, #DBG_MDSCR_KDE 298 + and x25, x25, #DBG_MDSCR_MDE 299 + adds xzr, x25, x26 300 + b.eq 9998f // Nothing to see there 301 + 302 + // If any interesting bits was set, we must set the flag 303 + mov x26, #KVM_ARM64_DEBUG_DIRTY 304 + str x26, [x0, #VCPU_DEBUG_FLAGS] 305 + b 9999f // Don't skip restore 306 + 307 + 9998: 308 + // Otherwise load the flags from memory in case we recently 309 + // trapped 310 + skip_debug_state x25, \target 311 + 9999: 668 312 .endm 669 313 670 314 .macro save_guest_32bit_state ··· 711 297 mrs x4, dacr32_el2 712 298 mrs x5, ifsr32_el2 713 299 mrs x6, fpexc32_el2 714 - mrs x7, dbgvcr32_el2 715 300 stp x4, x5, [x3] 716 - stp x6, x7, [x3, #16] 301 + str x6, [x3, #16] 717 302 303 + skip_debug_state x8, 2f 304 + mrs x7, dbgvcr32_el2 305 + str x7, [x3, #24] 306 + 2: 718 307 skip_tee_state x8, 1f 719 308 720 309 add x3, x2, #CPU_SYSREG_OFFSET(TEECR32_EL1) ··· 740 323 741 324 add x3, x2, #CPU_SYSREG_OFFSET(DACR32_EL2) 742 325 ldp x4, x5, [x3] 743 - ldp x6, x7, [x3, #16] 326 + ldr x6, [x3, #16] 744 327 msr dacr32_el2, x4 745 328 msr ifsr32_el2, x5 746 329 msr fpexc32_el2, x6 747 - msr dbgvcr32_el2, x7 748 330 331 + skip_debug_state x8, 2f 332 + ldr x7, [x3, #24] 333 + msr dbgvcr32_el2, x7 334 + 2: 749 335 skip_tee_state x8, 1f 750 336 751 337 add x3, x2, #CPU_SYSREG_OFFSET(TEECR32_EL1) ··· 759 339 .endm 760 340 761 341 .macro activate_traps 762 - ldr x2, [x0, #VCPU_IRQ_LINES] 763 - ldr x1, [x0, #VCPU_HCR_EL2] 764 - orr x2, x2, x1 765 - msr hcr_el2, x2 766 - 342 + ldr x2, [x0, #VCPU_HCR_EL2] 343 + msr hcr_el2, x2 767 344 ldr x2, =(CPTR_EL2_TTA) 768 345 msr cptr_el2, x2 769 346 ··· 770 353 mrs x2, mdcr_el2 771 354 and x2, x2, #MDCR_EL2_HPMN_MASK 772 355 orr x2, x2, #(MDCR_EL2_TPM | MDCR_EL2_TPMCR) 356 + orr x2, x2, #(MDCR_EL2_TDRA | MDCR_EL2_TDOSA) 357 + 358 + // Check for KVM_ARM64_DEBUG_DIRTY, and set debug to trap 359 + // if not dirty. 360 + ldr x3, [x0, #VCPU_DEBUG_FLAGS] 361 + tbnz x3, #KVM_ARM64_DEBUG_DIRTY_SHIFT, 1f 362 + orr x2, x2, #MDCR_EL2_TDA 363 + 1: 773 364 msr mdcr_el2, x2 774 365 .endm 775 366 ··· 804 379 .endm 805 380 806 381 /* 807 - * Save the VGIC CPU state into memory 808 - * x0: Register pointing to VCPU struct 809 - * Do not corrupt x1!!! 382 + * Call into the vgic backend for state saving 810 383 */ 811 384 .macro save_vgic_state 812 - /* Get VGIC VCTRL base into x2 */ 813 - ldr x2, [x0, #VCPU_KVM] 814 - kern_hyp_va x2 815 - ldr x2, [x2, #KVM_VGIC_VCTRL] 816 - kern_hyp_va x2 817 - cbz x2, 2f // disabled 818 - 819 - /* Compute the address of struct vgic_cpu */ 820 - add x3, x0, #VCPU_VGIC_CPU 821 - 822 - /* Save all interesting registers */ 823 - ldr w4, [x2, #GICH_HCR] 824 - ldr w5, [x2, #GICH_VMCR] 825 - ldr w6, [x2, #GICH_MISR] 826 - ldr w7, [x2, #GICH_EISR0] 827 - ldr w8, [x2, #GICH_EISR1] 828 - ldr w9, [x2, #GICH_ELRSR0] 829 - ldr w10, [x2, #GICH_ELRSR1] 830 - ldr w11, [x2, #GICH_APR] 831 - CPU_BE( rev w4, w4 ) 832 - CPU_BE( rev w5, w5 ) 833 - CPU_BE( rev w6, w6 ) 834 - CPU_BE( rev w7, w7 ) 835 - CPU_BE( rev w8, w8 ) 836 - CPU_BE( rev w9, w9 ) 837 - CPU_BE( rev w10, w10 ) 838 - CPU_BE( rev w11, w11 ) 839 - 840 - str w4, [x3, #VGIC_CPU_HCR] 841 - str w5, [x3, #VGIC_CPU_VMCR] 842 - str w6, [x3, #VGIC_CPU_MISR] 843 - str w7, [x3, #VGIC_CPU_EISR] 844 - str w8, [x3, #(VGIC_CPU_EISR + 4)] 845 - str w9, [x3, #VGIC_CPU_ELRSR] 846 - str w10, [x3, #(VGIC_CPU_ELRSR + 4)] 847 - str w11, [x3, #VGIC_CPU_APR] 848 - 849 - /* Clear GICH_HCR */ 850 - str wzr, [x2, #GICH_HCR] 851 - 852 - /* Save list registers */ 853 - add x2, x2, #GICH_LR0 854 - ldr w4, [x3, #VGIC_CPU_NR_LR] 855 - add x3, x3, #VGIC_CPU_LR 856 - 1: ldr w5, [x2], #4 857 - CPU_BE( rev w5, w5 ) 858 - str w5, [x3], #4 859 - sub w4, w4, #1 860 - cbnz w4, 1b 861 - 2: 385 + adr x24, __vgic_sr_vectors 386 + ldr x24, [x24, VGIC_SAVE_FN] 387 + kern_hyp_va x24 388 + blr x24 389 + mrs x24, hcr_el2 390 + mov x25, #HCR_INT_OVERRIDE 391 + neg x25, x25 392 + and x24, x24, x25 393 + msr hcr_el2, x24 862 394 .endm 863 395 864 396 /* 865 - * Restore the VGIC CPU state from memory 866 - * x0: Register pointing to VCPU struct 397 + * Call into the vgic backend for state restoring 867 398 */ 868 399 .macro restore_vgic_state 869 - /* Get VGIC VCTRL base into x2 */ 870 - ldr x2, [x0, #VCPU_KVM] 871 - kern_hyp_va x2 872 - ldr x2, [x2, #KVM_VGIC_VCTRL] 873 - kern_hyp_va x2 874 - cbz x2, 2f // disabled 875 - 876 - /* Compute the address of struct vgic_cpu */ 877 - add x3, x0, #VCPU_VGIC_CPU 878 - 879 - /* We only restore a minimal set of registers */ 880 - ldr w4, [x3, #VGIC_CPU_HCR] 881 - ldr w5, [x3, #VGIC_CPU_VMCR] 882 - ldr w6, [x3, #VGIC_CPU_APR] 883 - CPU_BE( rev w4, w4 ) 884 - CPU_BE( rev w5, w5 ) 885 - CPU_BE( rev w6, w6 ) 886 - 887 - str w4, [x2, #GICH_HCR] 888 - str w5, [x2, #GICH_VMCR] 889 - str w6, [x2, #GICH_APR] 890 - 891 - /* Restore list registers */ 892 - add x2, x2, #GICH_LR0 893 - ldr w4, [x3, #VGIC_CPU_NR_LR] 894 - add x3, x3, #VGIC_CPU_LR 895 - 1: ldr w5, [x3], #4 896 - CPU_BE( rev w5, w5 ) 897 - str w5, [x2], #4 898 - sub w4, w4, #1 899 - cbnz w4, 1b 900 - 2: 400 + mrs x24, hcr_el2 401 + ldr x25, [x0, #VCPU_IRQ_LINES] 402 + orr x24, x24, #HCR_INT_OVERRIDE 403 + orr x24, x24, x25 404 + msr hcr_el2, x24 405 + adr x24, __vgic_sr_vectors 406 + ldr x24, [x24, #VGIC_RESTORE_FN] 407 + kern_hyp_va x24 408 + blr x24 901 409 .endm 902 410 903 411 .macro save_timer_state ··· 895 537 restore_sysregs 896 538 ret 897 539 540 + __save_debug: 541 + save_debug 542 + ret 543 + 544 + __restore_debug: 545 + restore_debug 546 + ret 547 + 898 548 __save_fpsimd: 899 549 save_fpsimd 900 550 ret ··· 934 568 bl __save_fpsimd 935 569 bl __save_sysregs 936 570 571 + compute_debug_state 1f 572 + bl __save_debug 573 + 1: 937 574 activate_traps 938 575 activate_vm 939 576 ··· 948 579 949 580 bl __restore_sysregs 950 581 bl __restore_fpsimd 582 + 583 + skip_debug_state x3, 1f 584 + bl __restore_debug 585 + 1: 951 586 restore_guest_32bit_state 952 587 restore_guest_regs 953 588 ··· 968 595 save_guest_regs 969 596 bl __save_fpsimd 970 597 bl __save_sysregs 598 + 599 + skip_debug_state x3, 1f 600 + bl __save_debug 601 + 1: 971 602 save_guest_32bit_state 972 603 973 604 save_timer_state ··· 986 609 987 610 bl __restore_sysregs 988 611 bl __restore_fpsimd 612 + 613 + skip_debug_state x3, 1f 614 + // Clear the dirty flag for the next run, as all the state has 615 + // already been saved. Note that we nuke the whole 64bit word. 616 + // If we ever add more flags, we'll have to be more careful... 617 + str xzr, [x0, #VCPU_DEBUG_FLAGS] 618 + bl __restore_debug 619 + 1: 989 620 restore_host_regs 990 621 991 622 mov x0, x1 ··· 1037 652 dsb ish 1038 653 ret 1039 654 ENDPROC(__kvm_flush_vm_context) 655 + 656 + // struct vgic_sr_vectors __vgi_sr_vectors; 657 + .align 3 658 + ENTRY(__vgic_sr_vectors) 659 + .skip VGIC_SR_VECTOR_SZ 660 + ENDPROC(__vgic_sr_vectors) 1040 661 1041 662 __kvm_hyp_panic: 1042 663 // Guess the context by looking at VTTBR: ··· 1221 830 mrs x2, far_el2 1222 831 1223 832 2: mrs x0, tpidr_el2 1224 - str x1, [x0, #VCPU_ESR_EL2] 833 + str w1, [x0, #VCPU_ESR_EL2] 1225 834 str x2, [x0, #VCPU_FAR_EL2] 1226 835 str x3, [x0, #VCPU_HPFAR_EL2] 1227 836 ··· 1270 879 ventry el1_fiq_invalid // FIQ 32-bit EL1 1271 880 ventry el1_error_invalid // Error 32-bit EL1 1272 881 ENDPROC(__kvm_hyp_vector) 1273 - 1274 - __kvm_hyp_code_end: 1275 - .globl __kvm_hyp_code_end 1276 882 1277 883 .popsection
+473 -73
arch/arm64/kvm/sys_regs.c
··· 30 30 #include <asm/kvm_mmu.h> 31 31 #include <asm/cacheflush.h> 32 32 #include <asm/cputype.h> 33 + #include <asm/debug-monitors.h> 33 34 #include <trace/events/kvm.h> 34 35 35 36 #include "sys_regs.h" ··· 138 137 if (!p->is_aarch32) { 139 138 vcpu_sys_reg(vcpu, r->reg) = val; 140 139 } else { 141 - vcpu_cp15(vcpu, r->reg) = val & 0xffffffffUL; 142 140 if (!p->is_32bit) 143 - vcpu_cp15(vcpu, r->reg + 1) = val >> 32; 141 + vcpu_cp15_64_high(vcpu, r->reg) = val >> 32; 142 + vcpu_cp15_64_low(vcpu, r->reg) = val & 0xffffffffUL; 144 143 } 144 + 145 145 return true; 146 146 } 147 147 ··· 165 163 return true; 166 164 } 167 165 168 - /* 169 - * We could trap ID_DFR0 and tell the guest we don't support performance 170 - * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was 171 - * NAKed, so it will read the PMCR anyway. 172 - * 173 - * Therefore we tell the guest we have 0 counters. Unfortunately, we 174 - * must always support PMCCNTR (the cycle counter): we just RAZ/WI for 175 - * all PM registers, which doesn't crash the guest kernel at least. 176 - */ 177 - static bool pm_fake(struct kvm_vcpu *vcpu, 178 - const struct sys_reg_params *p, 179 - const struct sys_reg_desc *r) 166 + static bool trap_raz_wi(struct kvm_vcpu *vcpu, 167 + const struct sys_reg_params *p, 168 + const struct sys_reg_desc *r) 180 169 { 181 170 if (p->is_write) 182 171 return ignore_write(vcpu, p); 183 172 else 184 173 return read_zero(vcpu, p); 174 + } 175 + 176 + static bool trap_oslsr_el1(struct kvm_vcpu *vcpu, 177 + const struct sys_reg_params *p, 178 + const struct sys_reg_desc *r) 179 + { 180 + if (p->is_write) { 181 + return ignore_write(vcpu, p); 182 + } else { 183 + *vcpu_reg(vcpu, p->Rt) = (1 << 3); 184 + return true; 185 + } 186 + } 187 + 188 + static bool trap_dbgauthstatus_el1(struct kvm_vcpu *vcpu, 189 + const struct sys_reg_params *p, 190 + const struct sys_reg_desc *r) 191 + { 192 + if (p->is_write) { 193 + return ignore_write(vcpu, p); 194 + } else { 195 + u32 val; 196 + asm volatile("mrs %0, dbgauthstatus_el1" : "=r" (val)); 197 + *vcpu_reg(vcpu, p->Rt) = val; 198 + return true; 199 + } 200 + } 201 + 202 + /* 203 + * We want to avoid world-switching all the DBG registers all the 204 + * time: 205 + * 206 + * - If we've touched any debug register, it is likely that we're 207 + * going to touch more of them. It then makes sense to disable the 208 + * traps and start doing the save/restore dance 209 + * - If debug is active (DBG_MDSCR_KDE or DBG_MDSCR_MDE set), it is 210 + * then mandatory to save/restore the registers, as the guest 211 + * depends on them. 212 + * 213 + * For this, we use a DIRTY bit, indicating the guest has modified the 214 + * debug registers, used as follow: 215 + * 216 + * On guest entry: 217 + * - If the dirty bit is set (because we're coming back from trapping), 218 + * disable the traps, save host registers, restore guest registers. 219 + * - If debug is actively in use (DBG_MDSCR_KDE or DBG_MDSCR_MDE set), 220 + * set the dirty bit, disable the traps, save host registers, 221 + * restore guest registers. 222 + * - Otherwise, enable the traps 223 + * 224 + * On guest exit: 225 + * - If the dirty bit is set, save guest registers, restore host 226 + * registers and clear the dirty bit. This ensure that the host can 227 + * now use the debug registers. 228 + */ 229 + static bool trap_debug_regs(struct kvm_vcpu *vcpu, 230 + const struct sys_reg_params *p, 231 + const struct sys_reg_desc *r) 232 + { 233 + if (p->is_write) { 234 + vcpu_sys_reg(vcpu, r->reg) = *vcpu_reg(vcpu, p->Rt); 235 + vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY; 236 + } else { 237 + *vcpu_reg(vcpu, p->Rt) = vcpu_sys_reg(vcpu, r->reg); 238 + } 239 + 240 + return true; 185 241 } 186 242 187 243 static void reset_amair_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) ··· 258 198 vcpu_sys_reg(vcpu, MPIDR_EL1) = (1UL << 31) | (vcpu->vcpu_id & 0xff); 259 199 } 260 200 201 + /* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */ 202 + #define DBG_BCR_BVR_WCR_WVR_EL1(n) \ 203 + /* DBGBVRn_EL1 */ \ 204 + { Op0(0b10), Op1(0b000), CRn(0b0000), CRm((n)), Op2(0b100), \ 205 + trap_debug_regs, reset_val, (DBGBVR0_EL1 + (n)), 0 }, \ 206 + /* DBGBCRn_EL1 */ \ 207 + { Op0(0b10), Op1(0b000), CRn(0b0000), CRm((n)), Op2(0b101), \ 208 + trap_debug_regs, reset_val, (DBGBCR0_EL1 + (n)), 0 }, \ 209 + /* DBGWVRn_EL1 */ \ 210 + { Op0(0b10), Op1(0b000), CRn(0b0000), CRm((n)), Op2(0b110), \ 211 + trap_debug_regs, reset_val, (DBGWVR0_EL1 + (n)), 0 }, \ 212 + /* DBGWCRn_EL1 */ \ 213 + { Op0(0b10), Op1(0b000), CRn(0b0000), CRm((n)), Op2(0b111), \ 214 + trap_debug_regs, reset_val, (DBGWCR0_EL1 + (n)), 0 } 215 + 261 216 /* 262 217 * Architected system registers. 263 218 * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 219 + * 220 + * We could trap ID_DFR0 and tell the guest we don't support performance 221 + * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was 222 + * NAKed, so it will read the PMCR anyway. 223 + * 224 + * Therefore we tell the guest we have 0 counters. Unfortunately, we 225 + * must always support PMCCNTR (the cycle counter): we just RAZ/WI for 226 + * all PM registers, which doesn't crash the guest kernel at least. 227 + * 228 + * Debug handling: We do trap most, if not all debug related system 229 + * registers. The implementation is good enough to ensure that a guest 230 + * can use these with minimal performance degradation. The drawback is 231 + * that we don't implement any of the external debug, none of the 232 + * OSlock protocol. This should be revisited if we ever encounter a 233 + * more demanding guest... 264 234 */ 265 235 static const struct sys_reg_desc sys_reg_descs[] = { 266 236 /* DC ISW */ ··· 303 213 { Op0(0b01), Op1(0b000), CRn(0b0111), CRm(0b1110), Op2(0b010), 304 214 access_dcsw }, 305 215 216 + DBG_BCR_BVR_WCR_WVR_EL1(0), 217 + DBG_BCR_BVR_WCR_WVR_EL1(1), 218 + /* MDCCINT_EL1 */ 219 + { Op0(0b10), Op1(0b000), CRn(0b0000), CRm(0b0010), Op2(0b000), 220 + trap_debug_regs, reset_val, MDCCINT_EL1, 0 }, 221 + /* MDSCR_EL1 */ 222 + { Op0(0b10), Op1(0b000), CRn(0b0000), CRm(0b0010), Op2(0b010), 223 + trap_debug_regs, reset_val, MDSCR_EL1, 0 }, 224 + DBG_BCR_BVR_WCR_WVR_EL1(2), 225 + DBG_BCR_BVR_WCR_WVR_EL1(3), 226 + DBG_BCR_BVR_WCR_WVR_EL1(4), 227 + DBG_BCR_BVR_WCR_WVR_EL1(5), 228 + DBG_BCR_BVR_WCR_WVR_EL1(6), 229 + DBG_BCR_BVR_WCR_WVR_EL1(7), 230 + DBG_BCR_BVR_WCR_WVR_EL1(8), 231 + DBG_BCR_BVR_WCR_WVR_EL1(9), 232 + DBG_BCR_BVR_WCR_WVR_EL1(10), 233 + DBG_BCR_BVR_WCR_WVR_EL1(11), 234 + DBG_BCR_BVR_WCR_WVR_EL1(12), 235 + DBG_BCR_BVR_WCR_WVR_EL1(13), 236 + DBG_BCR_BVR_WCR_WVR_EL1(14), 237 + DBG_BCR_BVR_WCR_WVR_EL1(15), 238 + 239 + /* MDRAR_EL1 */ 240 + { Op0(0b10), Op1(0b000), CRn(0b0001), CRm(0b0000), Op2(0b000), 241 + trap_raz_wi }, 242 + /* OSLAR_EL1 */ 243 + { Op0(0b10), Op1(0b000), CRn(0b0001), CRm(0b0000), Op2(0b100), 244 + trap_raz_wi }, 245 + /* OSLSR_EL1 */ 246 + { Op0(0b10), Op1(0b000), CRn(0b0001), CRm(0b0001), Op2(0b100), 247 + trap_oslsr_el1 }, 248 + /* OSDLR_EL1 */ 249 + { Op0(0b10), Op1(0b000), CRn(0b0001), CRm(0b0011), Op2(0b100), 250 + trap_raz_wi }, 251 + /* DBGPRCR_EL1 */ 252 + { Op0(0b10), Op1(0b000), CRn(0b0001), CRm(0b0100), Op2(0b100), 253 + trap_raz_wi }, 254 + /* DBGCLAIMSET_EL1 */ 255 + { Op0(0b10), Op1(0b000), CRn(0b0111), CRm(0b1000), Op2(0b110), 256 + trap_raz_wi }, 257 + /* DBGCLAIMCLR_EL1 */ 258 + { Op0(0b10), Op1(0b000), CRn(0b0111), CRm(0b1001), Op2(0b110), 259 + trap_raz_wi }, 260 + /* DBGAUTHSTATUS_EL1 */ 261 + { Op0(0b10), Op1(0b000), CRn(0b0111), CRm(0b1110), Op2(0b110), 262 + trap_dbgauthstatus_el1 }, 263 + 306 264 /* TEECR32_EL1 */ 307 265 { Op0(0b10), Op1(0b010), CRn(0b0000), CRm(0b0000), Op2(0b000), 308 266 NULL, reset_val, TEECR32_EL1, 0 }, 309 267 /* TEEHBR32_EL1 */ 310 268 { Op0(0b10), Op1(0b010), CRn(0b0001), CRm(0b0000), Op2(0b000), 311 269 NULL, reset_val, TEEHBR32_EL1, 0 }, 270 + 271 + /* MDCCSR_EL1 */ 272 + { Op0(0b10), Op1(0b011), CRn(0b0000), CRm(0b0001), Op2(0b000), 273 + trap_raz_wi }, 274 + /* DBGDTR_EL0 */ 275 + { Op0(0b10), Op1(0b011), CRn(0b0000), CRm(0b0100), Op2(0b000), 276 + trap_raz_wi }, 277 + /* DBGDTR[TR]X_EL0 */ 278 + { Op0(0b10), Op1(0b011), CRn(0b0000), CRm(0b0101), Op2(0b000), 279 + trap_raz_wi }, 280 + 312 281 /* DBGVCR32_EL2 */ 313 282 { Op0(0b10), Op1(0b100), CRn(0b0000), CRm(0b0111), Op2(0b000), 314 283 NULL, reset_val, DBGVCR32_EL2, 0 }, ··· 409 260 410 261 /* PMINTENSET_EL1 */ 411 262 { Op0(0b11), Op1(0b000), CRn(0b1001), CRm(0b1110), Op2(0b001), 412 - pm_fake }, 263 + trap_raz_wi }, 413 264 /* PMINTENCLR_EL1 */ 414 265 { Op0(0b11), Op1(0b000), CRn(0b1001), CRm(0b1110), Op2(0b010), 415 - pm_fake }, 266 + trap_raz_wi }, 416 267 417 268 /* MAIR_EL1 */ 418 269 { Op0(0b11), Op1(0b000), CRn(0b1010), CRm(0b0010), Op2(0b000), ··· 441 292 442 293 /* PMCR_EL0 */ 443 294 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b000), 444 - pm_fake }, 295 + trap_raz_wi }, 445 296 /* PMCNTENSET_EL0 */ 446 297 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b001), 447 - pm_fake }, 298 + trap_raz_wi }, 448 299 /* PMCNTENCLR_EL0 */ 449 300 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b010), 450 - pm_fake }, 301 + trap_raz_wi }, 451 302 /* PMOVSCLR_EL0 */ 452 303 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b011), 453 - pm_fake }, 304 + trap_raz_wi }, 454 305 /* PMSWINC_EL0 */ 455 306 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b100), 456 - pm_fake }, 307 + trap_raz_wi }, 457 308 /* PMSELR_EL0 */ 458 309 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b101), 459 - pm_fake }, 310 + trap_raz_wi }, 460 311 /* PMCEID0_EL0 */ 461 312 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b110), 462 - pm_fake }, 313 + trap_raz_wi }, 463 314 /* PMCEID1_EL0 */ 464 315 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b111), 465 - pm_fake }, 316 + trap_raz_wi }, 466 317 /* PMCCNTR_EL0 */ 467 318 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1101), Op2(0b000), 468 - pm_fake }, 319 + trap_raz_wi }, 469 320 /* PMXEVTYPER_EL0 */ 470 321 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1101), Op2(0b001), 471 - pm_fake }, 322 + trap_raz_wi }, 472 323 /* PMXEVCNTR_EL0 */ 473 324 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1101), Op2(0b010), 474 - pm_fake }, 325 + trap_raz_wi }, 475 326 /* PMUSERENR_EL0 */ 476 327 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1110), Op2(0b000), 477 - pm_fake }, 328 + trap_raz_wi }, 478 329 /* PMOVSSET_EL0 */ 479 330 { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1110), Op2(0b011), 480 - pm_fake }, 331 + trap_raz_wi }, 481 332 482 333 /* TPIDR_EL0 */ 483 334 { Op0(0b11), Op1(0b011), CRn(0b1101), CRm(0b0000), Op2(0b010), ··· 497 348 NULL, reset_val, FPEXC32_EL2, 0x70 }, 498 349 }; 499 350 351 + static bool trap_dbgidr(struct kvm_vcpu *vcpu, 352 + const struct sys_reg_params *p, 353 + const struct sys_reg_desc *r) 354 + { 355 + if (p->is_write) { 356 + return ignore_write(vcpu, p); 357 + } else { 358 + u64 dfr = read_cpuid(ID_AA64DFR0_EL1); 359 + u64 pfr = read_cpuid(ID_AA64PFR0_EL1); 360 + u32 el3 = !!((pfr >> 12) & 0xf); 361 + 362 + *vcpu_reg(vcpu, p->Rt) = ((((dfr >> 20) & 0xf) << 28) | 363 + (((dfr >> 12) & 0xf) << 24) | 364 + (((dfr >> 28) & 0xf) << 20) | 365 + (6 << 16) | (el3 << 14) | (el3 << 12)); 366 + return true; 367 + } 368 + } 369 + 370 + static bool trap_debug32(struct kvm_vcpu *vcpu, 371 + const struct sys_reg_params *p, 372 + const struct sys_reg_desc *r) 373 + { 374 + if (p->is_write) { 375 + vcpu_cp14(vcpu, r->reg) = *vcpu_reg(vcpu, p->Rt); 376 + vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY; 377 + } else { 378 + *vcpu_reg(vcpu, p->Rt) = vcpu_cp14(vcpu, r->reg); 379 + } 380 + 381 + return true; 382 + } 383 + 384 + #define DBG_BCR_BVR_WCR_WVR(n) \ 385 + /* DBGBVRn */ \ 386 + { Op1( 0), CRn( 0), CRm((n)), Op2( 4), trap_debug32, \ 387 + NULL, (cp14_DBGBVR0 + (n) * 2) }, \ 388 + /* DBGBCRn */ \ 389 + { Op1( 0), CRn( 0), CRm((n)), Op2( 5), trap_debug32, \ 390 + NULL, (cp14_DBGBCR0 + (n) * 2) }, \ 391 + /* DBGWVRn */ \ 392 + { Op1( 0), CRn( 0), CRm((n)), Op2( 6), trap_debug32, \ 393 + NULL, (cp14_DBGWVR0 + (n) * 2) }, \ 394 + /* DBGWCRn */ \ 395 + { Op1( 0), CRn( 0), CRm((n)), Op2( 7), trap_debug32, \ 396 + NULL, (cp14_DBGWCR0 + (n) * 2) } 397 + 398 + #define DBGBXVR(n) \ 399 + { Op1( 0), CRn( 1), CRm((n)), Op2( 1), trap_debug32, \ 400 + NULL, cp14_DBGBXVR0 + n * 2 } 401 + 402 + /* 403 + * Trapped cp14 registers. We generally ignore most of the external 404 + * debug, on the principle that they don't really make sense to a 405 + * guest. Revisit this one day, whould this principle change. 406 + */ 407 + static const struct sys_reg_desc cp14_regs[] = { 408 + /* DBGIDR */ 409 + { Op1( 0), CRn( 0), CRm( 0), Op2( 0), trap_dbgidr }, 410 + /* DBGDTRRXext */ 411 + { Op1( 0), CRn( 0), CRm( 0), Op2( 2), trap_raz_wi }, 412 + 413 + DBG_BCR_BVR_WCR_WVR(0), 414 + /* DBGDSCRint */ 415 + { Op1( 0), CRn( 0), CRm( 1), Op2( 0), trap_raz_wi }, 416 + DBG_BCR_BVR_WCR_WVR(1), 417 + /* DBGDCCINT */ 418 + { Op1( 0), CRn( 0), CRm( 2), Op2( 0), trap_debug32 }, 419 + /* DBGDSCRext */ 420 + { Op1( 0), CRn( 0), CRm( 2), Op2( 2), trap_debug32 }, 421 + DBG_BCR_BVR_WCR_WVR(2), 422 + /* DBGDTR[RT]Xint */ 423 + { Op1( 0), CRn( 0), CRm( 3), Op2( 0), trap_raz_wi }, 424 + /* DBGDTR[RT]Xext */ 425 + { Op1( 0), CRn( 0), CRm( 3), Op2( 2), trap_raz_wi }, 426 + DBG_BCR_BVR_WCR_WVR(3), 427 + DBG_BCR_BVR_WCR_WVR(4), 428 + DBG_BCR_BVR_WCR_WVR(5), 429 + /* DBGWFAR */ 430 + { Op1( 0), CRn( 0), CRm( 6), Op2( 0), trap_raz_wi }, 431 + /* DBGOSECCR */ 432 + { Op1( 0), CRn( 0), CRm( 6), Op2( 2), trap_raz_wi }, 433 + DBG_BCR_BVR_WCR_WVR(6), 434 + /* DBGVCR */ 435 + { Op1( 0), CRn( 0), CRm( 7), Op2( 0), trap_debug32 }, 436 + DBG_BCR_BVR_WCR_WVR(7), 437 + DBG_BCR_BVR_WCR_WVR(8), 438 + DBG_BCR_BVR_WCR_WVR(9), 439 + DBG_BCR_BVR_WCR_WVR(10), 440 + DBG_BCR_BVR_WCR_WVR(11), 441 + DBG_BCR_BVR_WCR_WVR(12), 442 + DBG_BCR_BVR_WCR_WVR(13), 443 + DBG_BCR_BVR_WCR_WVR(14), 444 + DBG_BCR_BVR_WCR_WVR(15), 445 + 446 + /* DBGDRAR (32bit) */ 447 + { Op1( 0), CRn( 1), CRm( 0), Op2( 0), trap_raz_wi }, 448 + 449 + DBGBXVR(0), 450 + /* DBGOSLAR */ 451 + { Op1( 0), CRn( 1), CRm( 0), Op2( 4), trap_raz_wi }, 452 + DBGBXVR(1), 453 + /* DBGOSLSR */ 454 + { Op1( 0), CRn( 1), CRm( 1), Op2( 4), trap_oslsr_el1 }, 455 + DBGBXVR(2), 456 + DBGBXVR(3), 457 + /* DBGOSDLR */ 458 + { Op1( 0), CRn( 1), CRm( 3), Op2( 4), trap_raz_wi }, 459 + DBGBXVR(4), 460 + /* DBGPRCR */ 461 + { Op1( 0), CRn( 1), CRm( 4), Op2( 4), trap_raz_wi }, 462 + DBGBXVR(5), 463 + DBGBXVR(6), 464 + DBGBXVR(7), 465 + DBGBXVR(8), 466 + DBGBXVR(9), 467 + DBGBXVR(10), 468 + DBGBXVR(11), 469 + DBGBXVR(12), 470 + DBGBXVR(13), 471 + DBGBXVR(14), 472 + DBGBXVR(15), 473 + 474 + /* DBGDSAR (32bit) */ 475 + { Op1( 0), CRn( 2), CRm( 0), Op2( 0), trap_raz_wi }, 476 + 477 + /* DBGDEVID2 */ 478 + { Op1( 0), CRn( 7), CRm( 0), Op2( 7), trap_raz_wi }, 479 + /* DBGDEVID1 */ 480 + { Op1( 0), CRn( 7), CRm( 1), Op2( 7), trap_raz_wi }, 481 + /* DBGDEVID */ 482 + { Op1( 0), CRn( 7), CRm( 2), Op2( 7), trap_raz_wi }, 483 + /* DBGCLAIMSET */ 484 + { Op1( 0), CRn( 7), CRm( 8), Op2( 6), trap_raz_wi }, 485 + /* DBGCLAIMCLR */ 486 + { Op1( 0), CRn( 7), CRm( 9), Op2( 6), trap_raz_wi }, 487 + /* DBGAUTHSTATUS */ 488 + { Op1( 0), CRn( 7), CRm(14), Op2( 6), trap_dbgauthstatus_el1 }, 489 + }; 490 + 491 + /* Trapped cp14 64bit registers */ 492 + static const struct sys_reg_desc cp14_64_regs[] = { 493 + /* DBGDRAR (64bit) */ 494 + { Op1( 0), CRm( 1), .access = trap_raz_wi }, 495 + 496 + /* DBGDSAR (64bit) */ 497 + { Op1( 0), CRm( 2), .access = trap_raz_wi }, 498 + }; 499 + 500 500 /* 501 501 * Trapped cp15 registers. TTBR0/TTBR1 get a double encoding, 502 502 * depending on the way they are accessed (as a 32bit or a 64bit 503 503 * register). 504 504 */ 505 505 static const struct sys_reg_desc cp15_regs[] = { 506 - { Op1( 0), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR0 }, 507 506 { Op1( 0), CRn( 1), CRm( 0), Op2( 0), access_sctlr, NULL, c1_SCTLR }, 508 507 { Op1( 0), CRn( 2), CRm( 0), Op2( 0), access_vm_reg, NULL, c2_TTBR0 }, 509 508 { Op1( 0), CRn( 2), CRm( 0), Op2( 1), access_vm_reg, NULL, c2_TTBR1 }, ··· 671 374 { Op1( 0), CRn( 7), CRm(10), Op2( 2), access_dcsw }, 672 375 { Op1( 0), CRn( 7), CRm(14), Op2( 2), access_dcsw }, 673 376 674 - { Op1( 0), CRn( 9), CRm(12), Op2( 0), pm_fake }, 675 - { Op1( 0), CRn( 9), CRm(12), Op2( 1), pm_fake }, 676 - { Op1( 0), CRn( 9), CRm(12), Op2( 2), pm_fake }, 677 - { Op1( 0), CRn( 9), CRm(12), Op2( 3), pm_fake }, 678 - { Op1( 0), CRn( 9), CRm(12), Op2( 5), pm_fake }, 679 - { Op1( 0), CRn( 9), CRm(12), Op2( 6), pm_fake }, 680 - { Op1( 0), CRn( 9), CRm(12), Op2( 7), pm_fake }, 681 - { Op1( 0), CRn( 9), CRm(13), Op2( 0), pm_fake }, 682 - { Op1( 0), CRn( 9), CRm(13), Op2( 1), pm_fake }, 683 - { Op1( 0), CRn( 9), CRm(13), Op2( 2), pm_fake }, 684 - { Op1( 0), CRn( 9), CRm(14), Op2( 0), pm_fake }, 685 - { Op1( 0), CRn( 9), CRm(14), Op2( 1), pm_fake }, 686 - { Op1( 0), CRn( 9), CRm(14), Op2( 2), pm_fake }, 377 + /* PMU */ 378 + { Op1( 0), CRn( 9), CRm(12), Op2( 0), trap_raz_wi }, 379 + { Op1( 0), CRn( 9), CRm(12), Op2( 1), trap_raz_wi }, 380 + { Op1( 0), CRn( 9), CRm(12), Op2( 2), trap_raz_wi }, 381 + { Op1( 0), CRn( 9), CRm(12), Op2( 3), trap_raz_wi }, 382 + { Op1( 0), CRn( 9), CRm(12), Op2( 5), trap_raz_wi }, 383 + { Op1( 0), CRn( 9), CRm(12), Op2( 6), trap_raz_wi }, 384 + { Op1( 0), CRn( 9), CRm(12), Op2( 7), trap_raz_wi }, 385 + { Op1( 0), CRn( 9), CRm(13), Op2( 0), trap_raz_wi }, 386 + { Op1( 0), CRn( 9), CRm(13), Op2( 1), trap_raz_wi }, 387 + { Op1( 0), CRn( 9), CRm(13), Op2( 2), trap_raz_wi }, 388 + { Op1( 0), CRn( 9), CRm(14), Op2( 0), trap_raz_wi }, 389 + { Op1( 0), CRn( 9), CRm(14), Op2( 1), trap_raz_wi }, 390 + { Op1( 0), CRn( 9), CRm(14), Op2( 2), trap_raz_wi }, 687 391 688 392 { Op1( 0), CRn(10), CRm( 2), Op2( 0), access_vm_reg, NULL, c10_PRRR }, 689 393 { Op1( 0), CRn(10), CRm( 2), Op2( 1), access_vm_reg, NULL, c10_NMRR }, 690 394 { Op1( 0), CRn(10), CRm( 3), Op2( 0), access_vm_reg, NULL, c10_AMAIR0 }, 691 395 { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 }, 692 396 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, 397 + }; 693 398 399 + static const struct sys_reg_desc cp15_64_regs[] = { 400 + { Op1( 0), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR0 }, 694 401 { Op1( 1), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR1 }, 695 402 }; 696 403 ··· 755 454 return 1; 756 455 } 757 456 758 - int kvm_handle_cp14_access(struct kvm_vcpu *vcpu, struct kvm_run *run) 457 + /* 458 + * emulate_cp -- tries to match a sys_reg access in a handling table, and 459 + * call the corresponding trap handler. 460 + * 461 + * @params: pointer to the descriptor of the access 462 + * @table: array of trap descriptors 463 + * @num: size of the trap descriptor array 464 + * 465 + * Return 0 if the access has been handled, and -1 if not. 466 + */ 467 + static int emulate_cp(struct kvm_vcpu *vcpu, 468 + const struct sys_reg_params *params, 469 + const struct sys_reg_desc *table, 470 + size_t num) 759 471 { 760 - kvm_inject_undefined(vcpu); 761 - return 1; 762 - } 472 + const struct sys_reg_desc *r; 763 473 764 - static void emulate_cp15(struct kvm_vcpu *vcpu, 765 - const struct sys_reg_params *params) 766 - { 767 - size_t num; 768 - const struct sys_reg_desc *table, *r; 474 + if (!table) 475 + return -1; /* Not handled */ 769 476 770 - table = get_target_table(vcpu->arch.target, false, &num); 771 - 772 - /* Search target-specific then generic table. */ 773 477 r = find_reg(params, table, num); 774 - if (!r) 775 - r = find_reg(params, cp15_regs, ARRAY_SIZE(cp15_regs)); 776 478 777 - if (likely(r)) { 479 + if (r) { 778 480 /* 779 481 * Not having an accessor means that we have 780 482 * configured a trap that we don't know how to ··· 789 485 if (likely(r->access(vcpu, params, r))) { 790 486 /* Skip instruction, since it was emulated */ 791 487 kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 792 - return; 793 488 } 794 - /* If access function fails, it should complain. */ 489 + 490 + /* Handled */ 491 + return 0; 795 492 } 796 493 797 - kvm_err("Unsupported guest CP15 access at: %08lx\n", *vcpu_pc(vcpu)); 494 + /* Not handled */ 495 + return -1; 496 + } 497 + 498 + static void unhandled_cp_access(struct kvm_vcpu *vcpu, 499 + struct sys_reg_params *params) 500 + { 501 + u8 hsr_ec = kvm_vcpu_trap_get_class(vcpu); 502 + int cp; 503 + 504 + switch(hsr_ec) { 505 + case ESR_EL2_EC_CP15_32: 506 + case ESR_EL2_EC_CP15_64: 507 + cp = 15; 508 + break; 509 + case ESR_EL2_EC_CP14_MR: 510 + case ESR_EL2_EC_CP14_64: 511 + cp = 14; 512 + break; 513 + default: 514 + WARN_ON((cp = -1)); 515 + } 516 + 517 + kvm_err("Unsupported guest CP%d access at: %08lx\n", 518 + cp, *vcpu_pc(vcpu)); 798 519 print_sys_reg_instr(params); 799 520 kvm_inject_undefined(vcpu); 800 521 } 801 522 802 523 /** 803 - * kvm_handle_cp15_64 -- handles a mrrc/mcrr trap on a guest CP15 access 524 + * kvm_handle_cp_64 -- handles a mrrc/mcrr trap on a guest CP15 access 804 525 * @vcpu: The VCPU pointer 805 526 * @run: The kvm_run struct 806 527 */ 807 - int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) 528 + static int kvm_handle_cp_64(struct kvm_vcpu *vcpu, 529 + const struct sys_reg_desc *global, 530 + size_t nr_global, 531 + const struct sys_reg_desc *target_specific, 532 + size_t nr_specific) 808 533 { 809 534 struct sys_reg_params params; 810 535 u32 hsr = kvm_vcpu_get_hsr(vcpu); ··· 862 529 *vcpu_reg(vcpu, params.Rt) = val; 863 530 } 864 531 865 - emulate_cp15(vcpu, &params); 532 + if (!emulate_cp(vcpu, &params, target_specific, nr_specific)) 533 + goto out; 534 + if (!emulate_cp(vcpu, &params, global, nr_global)) 535 + goto out; 866 536 537 + unhandled_cp_access(vcpu, &params); 538 + 539 + out: 867 540 /* Do the opposite hack for the read side */ 868 541 if (!params.is_write) { 869 542 u64 val = *vcpu_reg(vcpu, params.Rt); ··· 885 546 * @vcpu: The VCPU pointer 886 547 * @run: The kvm_run struct 887 548 */ 888 - int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run) 549 + static int kvm_handle_cp_32(struct kvm_vcpu *vcpu, 550 + const struct sys_reg_desc *global, 551 + size_t nr_global, 552 + const struct sys_reg_desc *target_specific, 553 + size_t nr_specific) 889 554 { 890 555 struct sys_reg_params params; 891 556 u32 hsr = kvm_vcpu_get_hsr(vcpu); ··· 904 561 params.Op1 = (hsr >> 14) & 0x7; 905 562 params.Op2 = (hsr >> 17) & 0x7; 906 563 907 - emulate_cp15(vcpu, &params); 564 + if (!emulate_cp(vcpu, &params, target_specific, nr_specific)) 565 + return 1; 566 + if (!emulate_cp(vcpu, &params, global, nr_global)) 567 + return 1; 568 + 569 + unhandled_cp_access(vcpu, &params); 908 570 return 1; 571 + } 572 + 573 + int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) 574 + { 575 + const struct sys_reg_desc *target_specific; 576 + size_t num; 577 + 578 + target_specific = get_target_table(vcpu->arch.target, false, &num); 579 + return kvm_handle_cp_64(vcpu, 580 + cp15_64_regs, ARRAY_SIZE(cp15_64_regs), 581 + target_specific, num); 582 + } 583 + 584 + int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run) 585 + { 586 + const struct sys_reg_desc *target_specific; 587 + size_t num; 588 + 589 + target_specific = get_target_table(vcpu->arch.target, false, &num); 590 + return kvm_handle_cp_32(vcpu, 591 + cp15_regs, ARRAY_SIZE(cp15_regs), 592 + target_specific, num); 593 + } 594 + 595 + int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run) 596 + { 597 + return kvm_handle_cp_64(vcpu, 598 + cp14_64_regs, ARRAY_SIZE(cp14_64_regs), 599 + NULL, 0); 600 + } 601 + 602 + int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run) 603 + { 604 + return kvm_handle_cp_32(vcpu, 605 + cp14_regs, ARRAY_SIZE(cp14_regs), 606 + NULL, 0); 909 607 } 910 608 911 609 static int emulate_sys_reg(struct kvm_vcpu *vcpu, ··· 1160 776 NULL, get_ctr_el0 }, 1161 777 }; 1162 778 1163 - static int reg_from_user(void *val, const void __user *uaddr, u64 id) 779 + static int reg_from_user(u64 *val, const void __user *uaddr, u64 id) 1164 780 { 1165 - /* This Just Works because we are little endian. */ 1166 781 if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0) 1167 782 return -EFAULT; 1168 783 return 0; 1169 784 } 1170 785 1171 - static int reg_to_user(void __user *uaddr, const void *val, u64 id) 786 + static int reg_to_user(void __user *uaddr, const u64 *val, u64 id) 1172 787 { 1173 - /* This Just Works because we are little endian. */ 1174 788 if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0) 1175 789 return -EFAULT; 1176 790 return 0; ··· 1344 962 1345 963 static int write_demux_regids(u64 __user *uindices) 1346 964 { 1347 - u64 val = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX; 965 + u64 val = KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX; 1348 966 unsigned int i; 1349 967 1350 968 val |= KVM_REG_ARM_DEMUX_ID_CCSIDR; ··· 1451 1069 return write_demux_regids(uindices); 1452 1070 } 1453 1071 1072 + static int check_sysreg_table(const struct sys_reg_desc *table, unsigned int n) 1073 + { 1074 + unsigned int i; 1075 + 1076 + for (i = 1; i < n; i++) { 1077 + if (cmp_sys_reg(&table[i-1], &table[i]) >= 0) { 1078 + kvm_err("sys_reg table %p out of order (%d)\n", table, i - 1); 1079 + return 1; 1080 + } 1081 + } 1082 + 1083 + return 0; 1084 + } 1085 + 1454 1086 void kvm_sys_reg_table_init(void) 1455 1087 { 1456 1088 unsigned int i; 1457 1089 struct sys_reg_desc clidr; 1458 1090 1459 1091 /* Make sure tables are unique and in order. */ 1460 - for (i = 1; i < ARRAY_SIZE(sys_reg_descs); i++) 1461 - BUG_ON(cmp_sys_reg(&sys_reg_descs[i-1], &sys_reg_descs[i]) >= 0); 1092 + BUG_ON(check_sysreg_table(sys_reg_descs, ARRAY_SIZE(sys_reg_descs))); 1093 + BUG_ON(check_sysreg_table(cp14_regs, ARRAY_SIZE(cp14_regs))); 1094 + BUG_ON(check_sysreg_table(cp14_64_regs, ARRAY_SIZE(cp14_64_regs))); 1095 + BUG_ON(check_sysreg_table(cp15_regs, ARRAY_SIZE(cp15_regs))); 1096 + BUG_ON(check_sysreg_table(cp15_64_regs, ARRAY_SIZE(cp15_64_regs))); 1097 + BUG_ON(check_sysreg_table(invariant_sys_regs, ARRAY_SIZE(invariant_sys_regs))); 1462 1098 1463 1099 /* We abuse the reset function to overwrite the table itself. */ 1464 1100 for (i = 0; i < ARRAY_SIZE(invariant_sys_regs); i++)
+133
arch/arm64/kvm/vgic-v2-switch.S
··· 1 + /* 2 + * Copyright (C) 2012,2013 - ARM Ltd 3 + * Author: Marc Zyngier <marc.zyngier@arm.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 + */ 17 + 18 + #include <linux/linkage.h> 19 + #include <linux/irqchip/arm-gic.h> 20 + 21 + #include <asm/assembler.h> 22 + #include <asm/memory.h> 23 + #include <asm/asm-offsets.h> 24 + #include <asm/kvm.h> 25 + #include <asm/kvm_asm.h> 26 + #include <asm/kvm_arm.h> 27 + #include <asm/kvm_mmu.h> 28 + 29 + .text 30 + .pushsection .hyp.text, "ax" 31 + 32 + /* 33 + * Save the VGIC CPU state into memory 34 + * x0: Register pointing to VCPU struct 35 + * Do not corrupt x1!!! 36 + */ 37 + ENTRY(__save_vgic_v2_state) 38 + __save_vgic_v2_state: 39 + /* Get VGIC VCTRL base into x2 */ 40 + ldr x2, [x0, #VCPU_KVM] 41 + kern_hyp_va x2 42 + ldr x2, [x2, #KVM_VGIC_VCTRL] 43 + kern_hyp_va x2 44 + cbz x2, 2f // disabled 45 + 46 + /* Compute the address of struct vgic_cpu */ 47 + add x3, x0, #VCPU_VGIC_CPU 48 + 49 + /* Save all interesting registers */ 50 + ldr w4, [x2, #GICH_HCR] 51 + ldr w5, [x2, #GICH_VMCR] 52 + ldr w6, [x2, #GICH_MISR] 53 + ldr w7, [x2, #GICH_EISR0] 54 + ldr w8, [x2, #GICH_EISR1] 55 + ldr w9, [x2, #GICH_ELRSR0] 56 + ldr w10, [x2, #GICH_ELRSR1] 57 + ldr w11, [x2, #GICH_APR] 58 + CPU_BE( rev w4, w4 ) 59 + CPU_BE( rev w5, w5 ) 60 + CPU_BE( rev w6, w6 ) 61 + CPU_BE( rev w7, w7 ) 62 + CPU_BE( rev w8, w8 ) 63 + CPU_BE( rev w9, w9 ) 64 + CPU_BE( rev w10, w10 ) 65 + CPU_BE( rev w11, w11 ) 66 + 67 + str w4, [x3, #VGIC_V2_CPU_HCR] 68 + str w5, [x3, #VGIC_V2_CPU_VMCR] 69 + str w6, [x3, #VGIC_V2_CPU_MISR] 70 + str w7, [x3, #VGIC_V2_CPU_EISR] 71 + str w8, [x3, #(VGIC_V2_CPU_EISR + 4)] 72 + str w9, [x3, #VGIC_V2_CPU_ELRSR] 73 + str w10, [x3, #(VGIC_V2_CPU_ELRSR + 4)] 74 + str w11, [x3, #VGIC_V2_CPU_APR] 75 + 76 + /* Clear GICH_HCR */ 77 + str wzr, [x2, #GICH_HCR] 78 + 79 + /* Save list registers */ 80 + add x2, x2, #GICH_LR0 81 + ldr w4, [x3, #VGIC_CPU_NR_LR] 82 + add x3, x3, #VGIC_V2_CPU_LR 83 + 1: ldr w5, [x2], #4 84 + CPU_BE( rev w5, w5 ) 85 + str w5, [x3], #4 86 + sub w4, w4, #1 87 + cbnz w4, 1b 88 + 2: 89 + ret 90 + ENDPROC(__save_vgic_v2_state) 91 + 92 + /* 93 + * Restore the VGIC CPU state from memory 94 + * x0: Register pointing to VCPU struct 95 + */ 96 + ENTRY(__restore_vgic_v2_state) 97 + __restore_vgic_v2_state: 98 + /* Get VGIC VCTRL base into x2 */ 99 + ldr x2, [x0, #VCPU_KVM] 100 + kern_hyp_va x2 101 + ldr x2, [x2, #KVM_VGIC_VCTRL] 102 + kern_hyp_va x2 103 + cbz x2, 2f // disabled 104 + 105 + /* Compute the address of struct vgic_cpu */ 106 + add x3, x0, #VCPU_VGIC_CPU 107 + 108 + /* We only restore a minimal set of registers */ 109 + ldr w4, [x3, #VGIC_V2_CPU_HCR] 110 + ldr w5, [x3, #VGIC_V2_CPU_VMCR] 111 + ldr w6, [x3, #VGIC_V2_CPU_APR] 112 + CPU_BE( rev w4, w4 ) 113 + CPU_BE( rev w5, w5 ) 114 + CPU_BE( rev w6, w6 ) 115 + 116 + str w4, [x2, #GICH_HCR] 117 + str w5, [x2, #GICH_VMCR] 118 + str w6, [x2, #GICH_APR] 119 + 120 + /* Restore list registers */ 121 + add x2, x2, #GICH_LR0 122 + ldr w4, [x3, #VGIC_CPU_NR_LR] 123 + add x3, x3, #VGIC_V2_CPU_LR 124 + 1: ldr w5, [x3], #4 125 + CPU_BE( rev w5, w5 ) 126 + str w5, [x2], #4 127 + sub w4, w4, #1 128 + cbnz w4, 1b 129 + 2: 130 + ret 131 + ENDPROC(__restore_vgic_v2_state) 132 + 133 + .popsection
+267
arch/arm64/kvm/vgic-v3-switch.S
··· 1 + /* 2 + * Copyright (C) 2012,2013 - ARM Ltd 3 + * Author: Marc Zyngier <marc.zyngier@arm.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 + */ 17 + 18 + #include <linux/linkage.h> 19 + #include <linux/irqchip/arm-gic-v3.h> 20 + 21 + #include <asm/assembler.h> 22 + #include <asm/memory.h> 23 + #include <asm/asm-offsets.h> 24 + #include <asm/kvm.h> 25 + #include <asm/kvm_asm.h> 26 + #include <asm/kvm_arm.h> 27 + 28 + .text 29 + .pushsection .hyp.text, "ax" 30 + 31 + /* 32 + * We store LRs in reverse order to let the CPU deal with streaming 33 + * access. Use this macro to make it look saner... 34 + */ 35 + #define LR_OFFSET(n) (VGIC_V3_CPU_LR + (15 - n) * 8) 36 + 37 + /* 38 + * Save the VGIC CPU state into memory 39 + * x0: Register pointing to VCPU struct 40 + * Do not corrupt x1!!! 41 + */ 42 + .macro save_vgic_v3_state 43 + // Compute the address of struct vgic_cpu 44 + add x3, x0, #VCPU_VGIC_CPU 45 + 46 + // Make sure stores to the GIC via the memory mapped interface 47 + // are now visible to the system register interface 48 + dsb st 49 + 50 + // Save all interesting registers 51 + mrs_s x4, ICH_HCR_EL2 52 + mrs_s x5, ICH_VMCR_EL2 53 + mrs_s x6, ICH_MISR_EL2 54 + mrs_s x7, ICH_EISR_EL2 55 + mrs_s x8, ICH_ELSR_EL2 56 + 57 + str w4, [x3, #VGIC_V3_CPU_HCR] 58 + str w5, [x3, #VGIC_V3_CPU_VMCR] 59 + str w6, [x3, #VGIC_V3_CPU_MISR] 60 + str w7, [x3, #VGIC_V3_CPU_EISR] 61 + str w8, [x3, #VGIC_V3_CPU_ELRSR] 62 + 63 + msr_s ICH_HCR_EL2, xzr 64 + 65 + mrs_s x21, ICH_VTR_EL2 66 + mvn w22, w21 67 + ubfiz w23, w22, 2, 4 // w23 = (15 - ListRegs) * 4 68 + 69 + adr x24, 1f 70 + add x24, x24, x23 71 + br x24 72 + 73 + 1: 74 + mrs_s x20, ICH_LR15_EL2 75 + mrs_s x19, ICH_LR14_EL2 76 + mrs_s x18, ICH_LR13_EL2 77 + mrs_s x17, ICH_LR12_EL2 78 + mrs_s x16, ICH_LR11_EL2 79 + mrs_s x15, ICH_LR10_EL2 80 + mrs_s x14, ICH_LR9_EL2 81 + mrs_s x13, ICH_LR8_EL2 82 + mrs_s x12, ICH_LR7_EL2 83 + mrs_s x11, ICH_LR6_EL2 84 + mrs_s x10, ICH_LR5_EL2 85 + mrs_s x9, ICH_LR4_EL2 86 + mrs_s x8, ICH_LR3_EL2 87 + mrs_s x7, ICH_LR2_EL2 88 + mrs_s x6, ICH_LR1_EL2 89 + mrs_s x5, ICH_LR0_EL2 90 + 91 + adr x24, 1f 92 + add x24, x24, x23 93 + br x24 94 + 95 + 1: 96 + str x20, [x3, #LR_OFFSET(15)] 97 + str x19, [x3, #LR_OFFSET(14)] 98 + str x18, [x3, #LR_OFFSET(13)] 99 + str x17, [x3, #LR_OFFSET(12)] 100 + str x16, [x3, #LR_OFFSET(11)] 101 + str x15, [x3, #LR_OFFSET(10)] 102 + str x14, [x3, #LR_OFFSET(9)] 103 + str x13, [x3, #LR_OFFSET(8)] 104 + str x12, [x3, #LR_OFFSET(7)] 105 + str x11, [x3, #LR_OFFSET(6)] 106 + str x10, [x3, #LR_OFFSET(5)] 107 + str x9, [x3, #LR_OFFSET(4)] 108 + str x8, [x3, #LR_OFFSET(3)] 109 + str x7, [x3, #LR_OFFSET(2)] 110 + str x6, [x3, #LR_OFFSET(1)] 111 + str x5, [x3, #LR_OFFSET(0)] 112 + 113 + tbnz w21, #29, 6f // 6 bits 114 + tbz w21, #30, 5f // 5 bits 115 + // 7 bits 116 + mrs_s x20, ICH_AP0R3_EL2 117 + str w20, [x3, #(VGIC_V3_CPU_AP0R + 3*4)] 118 + mrs_s x19, ICH_AP0R2_EL2 119 + str w19, [x3, #(VGIC_V3_CPU_AP0R + 2*4)] 120 + 6: mrs_s x18, ICH_AP0R1_EL2 121 + str w18, [x3, #(VGIC_V3_CPU_AP0R + 1*4)] 122 + 5: mrs_s x17, ICH_AP0R0_EL2 123 + str w17, [x3, #VGIC_V3_CPU_AP0R] 124 + 125 + tbnz w21, #29, 6f // 6 bits 126 + tbz w21, #30, 5f // 5 bits 127 + // 7 bits 128 + mrs_s x20, ICH_AP1R3_EL2 129 + str w20, [x3, #(VGIC_V3_CPU_AP1R + 3*4)] 130 + mrs_s x19, ICH_AP1R2_EL2 131 + str w19, [x3, #(VGIC_V3_CPU_AP1R + 2*4)] 132 + 6: mrs_s x18, ICH_AP1R1_EL2 133 + str w18, [x3, #(VGIC_V3_CPU_AP1R + 1*4)] 134 + 5: mrs_s x17, ICH_AP1R0_EL2 135 + str w17, [x3, #VGIC_V3_CPU_AP1R] 136 + 137 + // Restore SRE_EL1 access and re-enable SRE at EL1. 138 + mrs_s x5, ICC_SRE_EL2 139 + orr x5, x5, #ICC_SRE_EL2_ENABLE 140 + msr_s ICC_SRE_EL2, x5 141 + isb 142 + mov x5, #1 143 + msr_s ICC_SRE_EL1, x5 144 + .endm 145 + 146 + /* 147 + * Restore the VGIC CPU state from memory 148 + * x0: Register pointing to VCPU struct 149 + */ 150 + .macro restore_vgic_v3_state 151 + // Disable SRE_EL1 access. Necessary, otherwise 152 + // ICH_VMCR_EL2.VFIQEn becomes one, and FIQ happens... 153 + msr_s ICC_SRE_EL1, xzr 154 + isb 155 + 156 + // Compute the address of struct vgic_cpu 157 + add x3, x0, #VCPU_VGIC_CPU 158 + 159 + // Restore all interesting registers 160 + ldr w4, [x3, #VGIC_V3_CPU_HCR] 161 + ldr w5, [x3, #VGIC_V3_CPU_VMCR] 162 + 163 + msr_s ICH_HCR_EL2, x4 164 + msr_s ICH_VMCR_EL2, x5 165 + 166 + mrs_s x21, ICH_VTR_EL2 167 + 168 + tbnz w21, #29, 6f // 6 bits 169 + tbz w21, #30, 5f // 5 bits 170 + // 7 bits 171 + ldr w20, [x3, #(VGIC_V3_CPU_AP1R + 3*4)] 172 + msr_s ICH_AP1R3_EL2, x20 173 + ldr w19, [x3, #(VGIC_V3_CPU_AP1R + 2*4)] 174 + msr_s ICH_AP1R2_EL2, x19 175 + 6: ldr w18, [x3, #(VGIC_V3_CPU_AP1R + 1*4)] 176 + msr_s ICH_AP1R1_EL2, x18 177 + 5: ldr w17, [x3, #VGIC_V3_CPU_AP1R] 178 + msr_s ICH_AP1R0_EL2, x17 179 + 180 + tbnz w21, #29, 6f // 6 bits 181 + tbz w21, #30, 5f // 5 bits 182 + // 7 bits 183 + ldr w20, [x3, #(VGIC_V3_CPU_AP0R + 3*4)] 184 + msr_s ICH_AP0R3_EL2, x20 185 + ldr w19, [x3, #(VGIC_V3_CPU_AP0R + 2*4)] 186 + msr_s ICH_AP0R2_EL2, x19 187 + 6: ldr w18, [x3, #(VGIC_V3_CPU_AP0R + 1*4)] 188 + msr_s ICH_AP0R1_EL2, x18 189 + 5: ldr w17, [x3, #VGIC_V3_CPU_AP0R] 190 + msr_s ICH_AP0R0_EL2, x17 191 + 192 + and w22, w21, #0xf 193 + mvn w22, w21 194 + ubfiz w23, w22, 2, 4 // w23 = (15 - ListRegs) * 4 195 + 196 + adr x24, 1f 197 + add x24, x24, x23 198 + br x24 199 + 200 + 1: 201 + ldr x20, [x3, #LR_OFFSET(15)] 202 + ldr x19, [x3, #LR_OFFSET(14)] 203 + ldr x18, [x3, #LR_OFFSET(13)] 204 + ldr x17, [x3, #LR_OFFSET(12)] 205 + ldr x16, [x3, #LR_OFFSET(11)] 206 + ldr x15, [x3, #LR_OFFSET(10)] 207 + ldr x14, [x3, #LR_OFFSET(9)] 208 + ldr x13, [x3, #LR_OFFSET(8)] 209 + ldr x12, [x3, #LR_OFFSET(7)] 210 + ldr x11, [x3, #LR_OFFSET(6)] 211 + ldr x10, [x3, #LR_OFFSET(5)] 212 + ldr x9, [x3, #LR_OFFSET(4)] 213 + ldr x8, [x3, #LR_OFFSET(3)] 214 + ldr x7, [x3, #LR_OFFSET(2)] 215 + ldr x6, [x3, #LR_OFFSET(1)] 216 + ldr x5, [x3, #LR_OFFSET(0)] 217 + 218 + adr x24, 1f 219 + add x24, x24, x23 220 + br x24 221 + 222 + 1: 223 + msr_s ICH_LR15_EL2, x20 224 + msr_s ICH_LR14_EL2, x19 225 + msr_s ICH_LR13_EL2, x18 226 + msr_s ICH_LR12_EL2, x17 227 + msr_s ICH_LR11_EL2, x16 228 + msr_s ICH_LR10_EL2, x15 229 + msr_s ICH_LR9_EL2, x14 230 + msr_s ICH_LR8_EL2, x13 231 + msr_s ICH_LR7_EL2, x12 232 + msr_s ICH_LR6_EL2, x11 233 + msr_s ICH_LR5_EL2, x10 234 + msr_s ICH_LR4_EL2, x9 235 + msr_s ICH_LR3_EL2, x8 236 + msr_s ICH_LR2_EL2, x7 237 + msr_s ICH_LR1_EL2, x6 238 + msr_s ICH_LR0_EL2, x5 239 + 240 + // Ensure that the above will have reached the 241 + // (re)distributors. This ensure the guest will read 242 + // the correct values from the memory-mapped interface. 243 + isb 244 + dsb sy 245 + 246 + // Prevent the guest from touching the GIC system registers 247 + mrs_s x5, ICC_SRE_EL2 248 + and x5, x5, #~ICC_SRE_EL2_ENABLE 249 + msr_s ICC_SRE_EL2, x5 250 + .endm 251 + 252 + ENTRY(__save_vgic_v3_state) 253 + save_vgic_v3_state 254 + ret 255 + ENDPROC(__save_vgic_v3_state) 256 + 257 + ENTRY(__restore_vgic_v3_state) 258 + restore_vgic_v3_state 259 + ret 260 + ENDPROC(__restore_vgic_v3_state) 261 + 262 + ENTRY(__vgic_v3_get_ich_vtr_el2) 263 + mrs_s x0, ICH_VTR_EL2 264 + ret 265 + ENDPROC(__vgic_v3_get_ich_vtr_el2) 266 + 267 + .popsection
+1
arch/ia64/kvm/Kconfig
··· 25 25 select PREEMPT_NOTIFIERS 26 26 select ANON_INODES 27 27 select HAVE_KVM_IRQCHIP 28 + select HAVE_KVM_IRQFD 28 29 select HAVE_KVM_IRQ_ROUTING 29 30 select KVM_APIC_ARCHITECTURE 30 31 select KVM_MMIO
+1 -1
arch/ia64/kvm/kvm-ia64.c
··· 190 190 *(int *)rtn = 0; 191 191 } 192 192 193 - int kvm_dev_ioctl_check_extension(long ext) 193 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) 194 194 { 195 195 196 196 int r;
+1 -1
arch/mips/kvm/mips.c
··· 886 886 return VM_FAULT_SIGBUS; 887 887 } 888 888 889 - int kvm_dev_ioctl_check_extension(long ext) 889 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) 890 890 { 891 891 int r; 892 892
+1 -3
arch/powerpc/Kconfig.debug
··· 202 202 203 203 config PPC_EARLY_DEBUG_44x 204 204 bool "Early serial debugging for IBM/AMCC 44x CPUs" 205 - # PPC_EARLY_DEBUG on 440 leaves AS=1 mappings above the TLB high water 206 - # mark, which doesn't work with current 440 KVM. 207 - depends on 44x && !KVM 205 + depends on 44x 208 206 help 209 207 Select this to enable early debugging for IBM 44x chips via the 210 208 inbuilt serial port. If you enable this, ensure you set
-1
arch/powerpc/configs/ppc44x_defconfig
··· 127 127 # CONFIG_CRYPTO_ANSI_CPRNG is not set 128 128 # CONFIG_CRYPTO_HW is not set 129 129 CONFIG_VIRTUALIZATION=y 130 - CONFIG_KVM_440=y
+4
arch/powerpc/include/asm/asm-compat.h
··· 34 34 #define PPC_MIN_STKFRM 112 35 35 36 36 #ifdef __BIG_ENDIAN__ 37 + #define LWZX_BE stringify_in_c(lwzx) 37 38 #define LDX_BE stringify_in_c(ldx) 39 + #define STWX_BE stringify_in_c(stwx) 38 40 #define STDX_BE stringify_in_c(stdx) 39 41 #else 42 + #define LWZX_BE stringify_in_c(lwbrx) 40 43 #define LDX_BE stringify_in_c(ldbrx) 44 + #define STWX_BE stringify_in_c(stwbrx) 41 45 #define STDX_BE stringify_in_c(stdbrx) 42 46 #endif 43 47
+7
arch/powerpc/include/asm/cache.h
··· 3 3 4 4 #ifdef __KERNEL__ 5 5 6 + #include <asm/reg.h> 6 7 7 8 /* bytes per L1 cache line */ 8 9 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX) ··· 40 39 }; 41 40 42 41 extern struct ppc64_caches ppc64_caches; 42 + 43 + static inline void logmpp(u64 x) 44 + { 45 + asm volatile(PPC_LOGMPP(R1) : : "r" (x)); 46 + } 47 + 43 48 #endif /* __powerpc64__ && ! __ASSEMBLY__ */ 44 49 45 50 #if defined(__ASSEMBLY__)
+6
arch/powerpc/include/asm/hvcall.h
··· 279 279 #define H_GET_24X7_DATA 0xF07C 280 280 #define H_GET_PERF_COUNTER_INFO 0xF080 281 281 282 + /* Values for 2nd argument to H_SET_MODE */ 283 + #define H_SET_MODE_RESOURCE_SET_CIABR 1 284 + #define H_SET_MODE_RESOURCE_SET_DAWR 2 285 + #define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE 3 286 + #define H_SET_MODE_RESOURCE_LE 4 287 + 282 288 #ifndef __ASSEMBLY__ 283 289 284 290 /**
-67
arch/powerpc/include/asm/kvm_44x.h
··· 1 - /* 2 - * This program is free software; you can redistribute it and/or modify 3 - * it under the terms of the GNU General Public License, version 2, as 4 - * published by the Free Software Foundation. 5 - * 6 - * This program is distributed in the hope that it will be useful, 7 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 - * GNU General Public License for more details. 10 - * 11 - * You should have received a copy of the GNU General Public License 12 - * along with this program; if not, write to the Free Software 13 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 - * 15 - * Copyright IBM Corp. 2008 16 - * 17 - * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18 - */ 19 - 20 - #ifndef __ASM_44X_H__ 21 - #define __ASM_44X_H__ 22 - 23 - #include <linux/kvm_host.h> 24 - 25 - #define PPC44x_TLB_SIZE 64 26 - 27 - /* If the guest is expecting it, this can be as large as we like; we'd just 28 - * need to find some way of advertising it. */ 29 - #define KVM44x_GUEST_TLB_SIZE 64 30 - 31 - struct kvmppc_44x_tlbe { 32 - u32 tid; /* Only the low 8 bits are used. */ 33 - u32 word0; 34 - u32 word1; 35 - u32 word2; 36 - }; 37 - 38 - struct kvmppc_44x_shadow_ref { 39 - struct page *page; 40 - u16 gtlb_index; 41 - u8 writeable; 42 - u8 tid; 43 - }; 44 - 45 - struct kvmppc_vcpu_44x { 46 - /* Unmodified copy of the guest's TLB. */ 47 - struct kvmppc_44x_tlbe guest_tlb[KVM44x_GUEST_TLB_SIZE]; 48 - 49 - /* References to guest pages in the hardware TLB. */ 50 - struct kvmppc_44x_shadow_ref shadow_refs[PPC44x_TLB_SIZE]; 51 - 52 - /* State of the shadow TLB at guest context switch time. */ 53 - struct kvmppc_44x_tlbe shadow_tlb[PPC44x_TLB_SIZE]; 54 - u8 shadow_tlb_mod[PPC44x_TLB_SIZE]; 55 - 56 - struct kvm_vcpu vcpu; 57 - }; 58 - 59 - static inline struct kvmppc_vcpu_44x *to_44x(struct kvm_vcpu *vcpu) 60 - { 61 - return container_of(vcpu, struct kvmppc_vcpu_44x, vcpu); 62 - } 63 - 64 - void kvmppc_44x_tlb_put(struct kvm_vcpu *vcpu); 65 - void kvmppc_44x_tlb_load(struct kvm_vcpu *vcpu); 66 - 67 - #endif /* __ASM_44X_H__ */
+1 -1
arch/powerpc/include/asm/kvm_asm.h
··· 33 33 /* IVPR must be 64KiB-aligned. */ 34 34 #define VCPU_SIZE_ORDER 4 35 35 #define VCPU_SIZE_LOG (VCPU_SIZE_ORDER + 12) 36 - #define VCPU_TLB_PGSZ PPC44x_TLB_64K 37 36 #define VCPU_SIZE_BYTES (1<<VCPU_SIZE_LOG) 38 37 39 38 #define BOOKE_INTERRUPT_CRITICAL 0 ··· 131 132 #define BOOK3S_HFLAG_NATIVE_PS 0x8 132 133 #define BOOK3S_HFLAG_MULTI_PGSIZE 0x10 133 134 #define BOOK3S_HFLAG_NEW_TLBIE 0x20 135 + #define BOOK3S_HFLAG_SPLIT_HACK 0x40 134 136 135 137 #define RESUME_FLAG_NV (1<<0) /* Reload guest nonvolatile state? */ 136 138 #define RESUME_FLAG_HOST (1<<1) /* Resume host? */
+19 -32
arch/powerpc/include/asm/kvm_book3s.h
··· 83 83 u64 sdr1; 84 84 u64 hior; 85 85 u64 msr_mask; 86 - u64 purr_offset; 87 - u64 spurr_offset; 88 86 #ifdef CONFIG_PPC_BOOK3S_32 89 87 u32 vsid_pool[VSID_POOL_SIZE]; 90 88 u32 vsid_next; ··· 146 148 extern int kvmppc_mmu_hpte_sysinit(void); 147 149 extern void kvmppc_mmu_hpte_sysexit(void); 148 150 extern int kvmppc_mmu_hv_init(void); 151 + extern int kvmppc_book3s_hcall_implemented(struct kvm *kvm, unsigned long hc); 149 152 153 + /* XXX remove this export when load_last_inst() is generic */ 150 154 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); 151 - extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); 152 155 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec); 153 156 extern void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu, 154 157 unsigned int vec); ··· 158 159 bool upper, u32 val); 159 160 extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); 160 161 extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu); 161 - extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing, 162 + extern pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing, 162 163 bool *writable); 163 164 extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev, 164 165 unsigned long *rmap, long pte_index, int realmode); 165 - extern void kvmppc_invalidate_hpte(struct kvm *kvm, unsigned long *hptep, 166 + extern void kvmppc_invalidate_hpte(struct kvm *kvm, __be64 *hptep, 166 167 unsigned long pte_index); 167 - void kvmppc_clear_ref_hpte(struct kvm *kvm, unsigned long *hptep, 168 + void kvmppc_clear_ref_hpte(struct kvm *kvm, __be64 *hptep, 168 169 unsigned long pte_index); 169 170 extern void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long addr, 170 171 unsigned long *nb_ret); ··· 182 183 struct kvm_memory_slot *memslot, unsigned long *map); 183 184 extern void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr, 184 185 unsigned long mask); 186 + extern void kvmppc_set_fscr(struct kvm_vcpu *vcpu, u64 fscr); 185 187 186 188 extern void kvmppc_entry_trampoline(void); 187 189 extern void kvmppc_hv_entry_trampoline(void); 188 190 extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst); 189 191 extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst); 190 192 extern int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd); 193 + extern void kvmppc_pr_init_default_hcalls(struct kvm *kvm); 194 + extern int kvmppc_hcall_impl_pr(unsigned long cmd); 195 + extern int kvmppc_hcall_impl_hv_realmode(unsigned long cmd); 191 196 extern void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, 192 197 struct kvm_vcpu *vcpu); 193 198 extern void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu, ··· 277 274 return (kvmppc_get_msr(vcpu) & MSR_LE) != (MSR_KERNEL & MSR_LE); 278 275 } 279 276 280 - static inline u32 kvmppc_get_last_inst_internal(struct kvm_vcpu *vcpu, ulong pc) 281 - { 282 - /* Load the instruction manually if it failed to do so in the 283 - * exit path */ 284 - if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) 285 - kvmppc_ld(vcpu, &pc, sizeof(u32), &vcpu->arch.last_inst, false); 286 - 287 - return kvmppc_need_byteswap(vcpu) ? swab32(vcpu->arch.last_inst) : 288 - vcpu->arch.last_inst; 289 - } 290 - 291 - static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu) 292 - { 293 - return kvmppc_get_last_inst_internal(vcpu, kvmppc_get_pc(vcpu)); 294 - } 295 - 296 - /* 297 - * Like kvmppc_get_last_inst(), but for fetching a sc instruction. 298 - * Because the sc instruction sets SRR0 to point to the following 299 - * instruction, we have to fetch from pc - 4. 300 - */ 301 - static inline u32 kvmppc_get_last_sc(struct kvm_vcpu *vcpu) 302 - { 303 - return kvmppc_get_last_inst_internal(vcpu, kvmppc_get_pc(vcpu) - 4); 304 - } 305 - 306 277 static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) 307 278 { 308 279 return vcpu->arch.fault_dar; ··· 285 308 static inline bool is_kvmppc_resume_guest(int r) 286 309 { 287 310 return (r == RESUME_GUEST || r == RESUME_GUEST_NV); 311 + } 312 + 313 + static inline bool is_kvmppc_hv_enabled(struct kvm *kvm); 314 + static inline bool kvmppc_supports_magic_page(struct kvm_vcpu *vcpu) 315 + { 316 + /* Only PR KVM supports the magic page */ 317 + return !is_kvmppc_hv_enabled(vcpu->kvm); 288 318 } 289 319 290 320 /* Magic register values loaded into r3 and r4 before the 'sc' assembly ··· 305 321 306 322 /* LPIDs we support with this build -- runtime limit may be lower */ 307 323 #define KVMPPC_NR_LPIDS (LPID_RSVD + 1) 324 + 325 + #define SPLIT_HACK_MASK 0xff000000 326 + #define SPLIT_HACK_OFFS 0xfb000000 308 327 309 328 #endif /* __ASM_KVM_BOOK3S_H__ */
+18 -11
arch/powerpc/include/asm/kvm_book3s_64.h
··· 59 59 /* These bits are reserved in the guest view of the HPTE */ 60 60 #define HPTE_GR_RESERVED HPTE_GR_MODIFIED 61 61 62 - static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits) 62 + static inline long try_lock_hpte(__be64 *hpte, unsigned long bits) 63 63 { 64 64 unsigned long tmp, old; 65 + __be64 be_lockbit, be_bits; 66 + 67 + /* 68 + * We load/store in native endian, but the HTAB is in big endian. If 69 + * we byte swap all data we apply on the PTE we're implicitly correct 70 + * again. 71 + */ 72 + be_lockbit = cpu_to_be64(HPTE_V_HVLOCK); 73 + be_bits = cpu_to_be64(bits); 65 74 66 75 asm volatile(" ldarx %0,0,%2\n" 67 76 " and. %1,%0,%3\n" 68 77 " bne 2f\n" 69 - " ori %0,%0,%4\n" 78 + " or %0,%0,%4\n" 70 79 " stdcx. %0,0,%2\n" 71 80 " beq+ 2f\n" 72 81 " mr %1,%3\n" 73 82 "2: isync" 74 83 : "=&r" (tmp), "=&r" (old) 75 - : "r" (hpte), "r" (bits), "i" (HPTE_V_HVLOCK) 84 + : "r" (hpte), "r" (be_bits), "r" (be_lockbit) 76 85 : "cc", "memory"); 77 86 return old == 0; 78 87 } ··· 119 110 static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r, 120 111 unsigned long pte_index) 121 112 { 122 - int b_psize, a_psize; 113 + int b_psize = MMU_PAGE_4K, a_psize = MMU_PAGE_4K; 123 114 unsigned int penc; 124 115 unsigned long rb = 0, va_low, sllp; 125 116 unsigned int lp = (r >> LP_SHIFT) & ((1 << LP_BITS) - 1); 126 117 127 - if (!(v & HPTE_V_LARGE)) { 128 - /* both base and actual psize is 4k */ 129 - b_psize = MMU_PAGE_4K; 130 - a_psize = MMU_PAGE_4K; 131 - } else { 118 + if (v & HPTE_V_LARGE) { 132 119 for (b_psize = 0; b_psize < MMU_PAGE_COUNT; b_psize++) { 133 120 134 121 /* valid entries have a shift value */ ··· 147 142 */ 148 143 /* This covers 14..54 bits of va*/ 149 144 rb = (v & ~0x7fUL) << 16; /* AVA field */ 145 + 146 + rb |= v >> (62 - 8); /* B field */ 150 147 /* 151 148 * AVA in v had cleared lower 23 bits. We need to derive 152 149 * that from pteg index ··· 179 172 { 180 173 int aval_shift; 181 174 /* 182 - * remaining 7bits of AVA/LP fields 175 + * remaining bits of AVA/LP fields 183 176 * Also contain the rr bits of LP 184 177 */ 185 - rb |= (va_low & 0x7f) << 16; 178 + rb |= (va_low << mmu_psize_defs[b_psize].shift) & 0x7ff000; 186 179 /* 187 180 * Now clear not needed LP bits based on actual psize 188 181 */
+10 -5
arch/powerpc/include/asm/kvm_booke.h
··· 69 69 return false; 70 70 } 71 71 72 - static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu) 73 - { 74 - return vcpu->arch.last_inst; 75 - } 76 - 77 72 static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val) 78 73 { 79 74 vcpu->arch.ctr = val; ··· 102 107 static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) 103 108 { 104 109 return vcpu->arch.fault_dear; 110 + } 111 + 112 + static inline bool kvmppc_supports_magic_page(struct kvm_vcpu *vcpu) 113 + { 114 + /* Magic page is only supported on e500v2 */ 115 + #ifdef CONFIG_KVM_E500V2 116 + return true; 117 + #else 118 + return false; 119 + #endif 105 120 } 106 121 #endif /* __ASM_KVM_BOOKE_H__ */
+16 -12
arch/powerpc/include/asm/kvm_host.h
··· 34 34 #include <asm/processor.h> 35 35 #include <asm/page.h> 36 36 #include <asm/cacheflush.h> 37 + #include <asm/hvcall.h> 37 38 38 39 #define KVM_MAX_VCPUS NR_CPUS 39 40 #define KVM_MAX_VCORES NR_CPUS ··· 49 48 #define KVM_NR_IRQCHIPS 1 50 49 #define KVM_IRQCHIP_NUM_PINS 256 51 50 52 - #if !defined(CONFIG_KVM_440) 53 51 #include <linux/mmu_notifier.h> 54 52 55 53 #define KVM_ARCH_WANT_MMU_NOTIFIER ··· 60 60 extern int kvm_age_hva(struct kvm *kvm, unsigned long hva); 61 61 extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); 62 62 extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 63 - 64 - #endif 65 63 66 64 #define HPTEG_CACHE_NUM (1 << 15) 67 65 #define HPTEG_HASH_BITS_PTE 13 ··· 94 96 struct kvm_vcpu_stat { 95 97 u32 sum_exits; 96 98 u32 mmio_exits; 97 - u32 dcr_exits; 98 99 u32 signal_exits; 99 100 u32 light_exits; 100 101 /* Account for special types of light exits: */ ··· 110 113 u32 halt_wakeup; 111 114 u32 dbell_exits; 112 115 u32 gdbell_exits; 116 + u32 ld; 117 + u32 st; 113 118 #ifdef CONFIG_PPC_BOOK3S 114 119 u32 pf_storage; 115 120 u32 pf_instruc; 116 121 u32 sp_storage; 117 122 u32 sp_instruc; 118 123 u32 queue_intr; 119 - u32 ld; 120 124 u32 ld_slow; 121 - u32 st; 122 125 u32 st_slow; 123 126 #endif 124 127 }; 125 128 126 129 enum kvm_exit_types { 127 130 MMIO_EXITS, 128 - DCR_EXITS, 129 131 SIGNAL_EXITS, 130 132 ITLB_REAL_MISS_EXITS, 131 133 ITLB_VIRT_MISS_EXITS, ··· 250 254 atomic_t hpte_mod_interest; 251 255 spinlock_t slot_phys_lock; 252 256 cpumask_t need_tlb_flush; 253 - struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; 254 257 int hpt_cma_alloc; 255 258 #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ 256 259 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE ··· 258 263 #ifdef CONFIG_PPC_BOOK3S_64 259 264 struct list_head spapr_tce_tables; 260 265 struct list_head rtas_tokens; 266 + DECLARE_BITMAP(enabled_hcalls, MAX_HCALL_OPCODE/4 + 1); 261 267 #endif 262 268 #ifdef CONFIG_KVM_MPIC 263 269 struct openpic *mpic; ··· 267 271 struct kvmppc_xics *xics; 268 272 #endif 269 273 struct kvmppc_ops *kvm_ops; 274 + #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 275 + /* This array can grow quite large, keep it at the end */ 276 + struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; 277 + #endif 270 278 }; 271 279 272 280 /* ··· 305 305 u32 arch_compat; 306 306 ulong pcr; 307 307 ulong dpdes; /* doorbell state (POWER8) */ 308 + void *mpp_buffer; /* Micro Partition Prefetch buffer */ 309 + bool mpp_buffer_is_valid; 308 310 }; 309 311 310 312 #define VCORE_ENTRY_COUNT(vc) ((vc)->entry_exit_count & 0xff) ··· 505 503 #ifdef CONFIG_BOOKE 506 504 u32 decar; 507 505 #endif 508 - u32 tbl; 509 - u32 tbu; 506 + /* Time base value when we entered the guest */ 507 + u64 entry_tb; 508 + u64 entry_vtb; 509 + u64 entry_ic; 510 510 u32 tcr; 511 511 ulong tsr; /* we need to perform set/clr_bits() which requires ulong */ 512 512 u32 ivor[64]; ··· 584 580 u32 mmucfg; 585 581 u32 eptcfg; 586 582 u32 epr; 583 + u64 sprg9; 584 + u32 pwrmgtcr0; 587 585 u32 crit_save; 588 586 /* guest debug registers*/ 589 587 struct debug_reg dbg_reg; ··· 599 593 u8 io_gpr; /* GPR used as IO source/target */ 600 594 u8 mmio_is_bigendian; 601 595 u8 mmio_sign_extend; 602 - u8 dcr_needed; 603 - u8 dcr_is_write; 604 596 u8 osi_needed; 605 597 u8 osi_enabled; 606 598 u8 papr_enabled;
+106 -10
arch/powerpc/include/asm/kvm_ppc.h
··· 41 41 enum emulation_result { 42 42 EMULATE_DONE, /* no further processing */ 43 43 EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */ 44 - EMULATE_DO_DCR, /* kvm_run filled with DCR request */ 45 44 EMULATE_FAIL, /* can't emulate this instruction */ 46 45 EMULATE_AGAIN, /* something went wrong. go again */ 47 46 EMULATE_EXIT_USER, /* emulation requires exit to user-space */ 47 + }; 48 + 49 + enum instruction_type { 50 + INST_GENERIC, 51 + INST_SC, /* system call */ 52 + }; 53 + 54 + enum xlate_instdata { 55 + XLATE_INST, /* translate instruction address */ 56 + XLATE_DATA /* translate data address */ 57 + }; 58 + 59 + enum xlate_readwrite { 60 + XLATE_READ, /* check for read permissions */ 61 + XLATE_WRITE /* check for write permissions */ 48 62 }; 49 63 50 64 extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); ··· 76 62 u64 val, unsigned int bytes, 77 63 int is_default_endian); 78 64 65 + extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, 66 + enum instruction_type type, u32 *inst); 67 + 68 + extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 69 + bool data); 70 + extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 71 + bool data); 79 72 extern int kvmppc_emulate_instruction(struct kvm_run *run, 80 73 struct kvm_vcpu *vcpu); 74 + extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu); 81 75 extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu); 82 76 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu); 83 77 extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); ··· 108 86 gva_t eaddr); 109 87 extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu); 110 88 extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu); 89 + extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, 90 + enum xlate_instdata xlid, enum xlate_readwrite xlrw, 91 + struct kvmppc_pte *pte); 111 92 112 93 extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, 113 94 unsigned int id); ··· 131 106 extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, 132 107 struct kvm_interrupt *irq); 133 108 extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu); 109 + extern void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, ulong dear_flags, 110 + ulong esr_flags); 111 + extern void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, 112 + ulong dear_flags, 113 + ulong esr_flags); 114 + extern void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu); 115 + extern void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, 116 + ulong esr_flags); 134 117 extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu); 135 118 extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu); 136 119 ··· 261 228 void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu); 262 229 long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl, 263 230 unsigned long arg); 264 - 231 + int (*hcall_implemented)(unsigned long hcall); 265 232 }; 266 233 267 234 extern struct kvmppc_ops *kvmppc_hv_ops; 268 235 extern struct kvmppc_ops *kvmppc_pr_ops; 236 + 237 + static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu, 238 + enum instruction_type type, u32 *inst) 239 + { 240 + int ret = EMULATE_DONE; 241 + u32 fetched_inst; 242 + 243 + /* Load the instruction manually if it failed to do so in the 244 + * exit path */ 245 + if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) 246 + ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst); 247 + 248 + /* Write fetch_failed unswapped if the fetch failed */ 249 + if (ret == EMULATE_DONE) 250 + fetched_inst = kvmppc_need_byteswap(vcpu) ? 251 + swab32(vcpu->arch.last_inst) : 252 + vcpu->arch.last_inst; 253 + else 254 + fetched_inst = vcpu->arch.last_inst; 255 + 256 + *inst = fetched_inst; 257 + return ret; 258 + } 269 259 270 260 static inline bool is_kvmppc_hv_enabled(struct kvm *kvm) 271 261 { ··· 448 392 { return 0; } 449 393 #endif 450 394 395 + static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu) 396 + { 397 + #ifdef CONFIG_KVM_BOOKE_HV 398 + return mfspr(SPRN_GEPR); 399 + #elif defined(CONFIG_BOOKE) 400 + return vcpu->arch.epr; 401 + #else 402 + return 0; 403 + #endif 404 + } 405 + 451 406 static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr) 452 407 { 453 408 #ifdef CONFIG_KVM_BOOKE_HV ··· 539 472 #endif 540 473 } 541 474 475 + #define SPRNG_WRAPPER_GET(reg, bookehv_spr) \ 476 + static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ 477 + { \ 478 + return mfspr(bookehv_spr); \ 479 + } \ 480 + 481 + #define SPRNG_WRAPPER_SET(reg, bookehv_spr) \ 482 + static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \ 483 + { \ 484 + mtspr(bookehv_spr, val); \ 485 + } \ 486 + 542 487 #define SHARED_WRAPPER_GET(reg, size) \ 543 - static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ 488 + static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ 544 489 { \ 545 490 if (kvmppc_shared_big_endian(vcpu)) \ 546 491 return be##size##_to_cpu(vcpu->arch.shared->reg); \ ··· 573 494 SHARED_WRAPPER_GET(reg, size) \ 574 495 SHARED_WRAPPER_SET(reg, size) \ 575 496 497 + #define SPRNG_WRAPPER(reg, bookehv_spr) \ 498 + SPRNG_WRAPPER_GET(reg, bookehv_spr) \ 499 + SPRNG_WRAPPER_SET(reg, bookehv_spr) \ 500 + 501 + #ifdef CONFIG_KVM_BOOKE_HV 502 + 503 + #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ 504 + SPRNG_WRAPPER(reg, bookehv_spr) \ 505 + 506 + #else 507 + 508 + #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ 509 + SHARED_WRAPPER(reg, size) \ 510 + 511 + #endif 512 + 576 513 SHARED_WRAPPER(critical, 64) 577 - SHARED_WRAPPER(sprg0, 64) 578 - SHARED_WRAPPER(sprg1, 64) 579 - SHARED_WRAPPER(sprg2, 64) 580 - SHARED_WRAPPER(sprg3, 64) 581 - SHARED_WRAPPER(srr0, 64) 582 - SHARED_WRAPPER(srr1, 64) 583 - SHARED_WRAPPER(dar, 64) 514 + SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0) 515 + SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1) 516 + SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2) 517 + SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3) 518 + SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0) 519 + SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1) 520 + SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR) 521 + SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR) 584 522 SHARED_WRAPPER_GET(msr, 64) 585 523 static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val) 586 524 {
+7 -1
arch/powerpc/include/asm/mmu-book3e.h
··· 40 40 41 41 /* MAS registers bit definitions */ 42 42 43 - #define MAS0_TLBSEL(x) (((x) << 28) & 0x30000000) 43 + #define MAS0_TLBSEL_MASK 0x30000000 44 + #define MAS0_TLBSEL_SHIFT 28 45 + #define MAS0_TLBSEL(x) (((x) << MAS0_TLBSEL_SHIFT) & MAS0_TLBSEL_MASK) 46 + #define MAS0_GET_TLBSEL(mas0) (((mas0) & MAS0_TLBSEL_MASK) >> \ 47 + MAS0_TLBSEL_SHIFT) 44 48 #define MAS0_ESEL_MASK 0x0FFF0000 45 49 #define MAS0_ESEL_SHIFT 16 46 50 #define MAS0_ESEL(x) (((x) << MAS0_ESEL_SHIFT) & MAS0_ESEL_MASK) ··· 62 58 #define MAS1_TSIZE_MASK 0x00000f80 63 59 #define MAS1_TSIZE_SHIFT 7 64 60 #define MAS1_TSIZE(x) (((x) << MAS1_TSIZE_SHIFT) & MAS1_TSIZE_MASK) 61 + #define MAS1_GET_TSIZE(mas1) (((mas1) & MAS1_TSIZE_MASK) >> MAS1_TSIZE_SHIFT) 65 62 66 63 #define MAS2_EPN (~0xFFFUL) 67 64 #define MAS2_X0 0x00000040 ··· 91 86 #define MAS3_SPSIZE 0x0000003e 92 87 #define MAS3_SPSIZE_SHIFT 1 93 88 89 + #define MAS4_TLBSEL_MASK MAS0_TLBSEL_MASK 94 90 #define MAS4_TLBSELD(x) MAS0_TLBSEL(x) 95 91 #define MAS4_INDD 0x00008000 /* Default IND */ 96 92 #define MAS4_TSIZED(x) MAS1_TSIZE(x)
+17
arch/powerpc/include/asm/ppc-opcode.h
··· 139 139 #define PPC_INST_ISEL 0x7c00001e 140 140 #define PPC_INST_ISEL_MASK 0xfc00003e 141 141 #define PPC_INST_LDARX 0x7c0000a8 142 + #define PPC_INST_LOGMPP 0x7c0007e4 142 143 #define PPC_INST_LSWI 0x7c0004aa 143 144 #define PPC_INST_LSWX 0x7c00042a 144 145 #define PPC_INST_LWARX 0x7c000028 ··· 278 277 #define __PPC_EH(eh) 0 279 278 #endif 280 279 280 + /* POWER8 Micro Partition Prefetch (MPP) parameters */ 281 + /* Address mask is common for LOGMPP instruction and MPPR SPR */ 282 + #define PPC_MPPE_ADDRESS_MASK 0xffffffffc000 283 + 284 + /* Bits 60 and 61 of MPP SPR should be set to one of the following */ 285 + /* Aborting the fetch is indeed setting 00 in the table size bits */ 286 + #define PPC_MPPR_FETCH_ABORT (0x0ULL << 60) 287 + #define PPC_MPPR_FETCH_WHOLE_TABLE (0x2ULL << 60) 288 + 289 + /* Bits 54 and 55 of register for LOGMPP instruction should be set to: */ 290 + #define PPC_LOGMPP_LOG_L2 (0x02ULL << 54) 291 + #define PPC_LOGMPP_LOG_L2L3 (0x01ULL << 54) 292 + #define PPC_LOGMPP_LOG_ABORT (0x03ULL << 54) 293 + 281 294 /* Deal with instructions that older assemblers aren't aware of */ 282 295 #define PPC_DCBAL(a, b) stringify_in_c(.long PPC_INST_DCBAL | \ 283 296 __PPC_RA(a) | __PPC_RB(b)) ··· 300 285 #define PPC_LDARX(t, a, b, eh) stringify_in_c(.long PPC_INST_LDARX | \ 301 286 ___PPC_RT(t) | ___PPC_RA(a) | \ 302 287 ___PPC_RB(b) | __PPC_EH(eh)) 288 + #define PPC_LOGMPP(b) stringify_in_c(.long PPC_INST_LOGMPP | \ 289 + __PPC_RB(b)) 303 290 #define PPC_LWARX(t, a, b, eh) stringify_in_c(.long PPC_INST_LWARX | \ 304 291 ___PPC_RT(t) | ___PPC_RA(a) | \ 305 292 ___PPC_RB(b) | __PPC_EH(eh))
+10 -3
arch/powerpc/include/asm/reg.h
··· 225 225 #define CTRL_TE 0x00c00000 /* thread enable */ 226 226 #define CTRL_RUNLATCH 0x1 227 227 #define SPRN_DAWR 0xB4 228 + #define SPRN_MPPR 0xB8 /* Micro Partition Prefetch Register */ 228 229 #define SPRN_RPR 0xBA /* Relative Priority Register */ 229 230 #define SPRN_CIABR 0xBB 230 231 #define CIABR_PRIV 0x3 ··· 945 944 * readable variant for reads, which can avoid a fault 946 945 * with KVM type virtualization. 947 946 * 948 - * (*) Under KVM, the host SPRG1 is used to point to 949 - * the current VCPU data structure 950 - * 951 947 * 32-bit 8xx: 952 948 * - SPRG0 scratch for exception vectors 953 949 * - SPRG1 scratch for exception vectors ··· 1200 1202 #define mtspr(rn, v) asm volatile("mtspr " __stringify(rn) ",%0" : \ 1201 1203 : "r" ((unsigned long)(v)) \ 1202 1204 : "memory") 1205 + 1206 + static inline unsigned long mfvtb (void) 1207 + { 1208 + #ifdef CONFIG_PPC_BOOK3S_64 1209 + if (cpu_has_feature(CPU_FTR_ARCH_207S)) 1210 + return mfspr(SPRN_VTB); 1211 + #endif 1212 + return 0; 1213 + } 1203 1214 1204 1215 #ifdef __powerpc64__ 1205 1216 #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
+9
arch/powerpc/include/asm/time.h
··· 102 102 return (u64)hi * 1000000000 + lo; 103 103 } 104 104 105 + static inline u64 get_vtb(void) 106 + { 107 + #ifdef CONFIG_PPC_BOOK3S_64 108 + if (cpu_has_feature(CPU_FTR_ARCH_207S)) 109 + return mfvtb(); 110 + #endif 111 + return 0; 112 + } 113 + 105 114 #ifdef CONFIG_PPC64 106 115 static inline u64 get_tb(void) 107 116 {
+2
arch/powerpc/include/uapi/asm/kvm.h
··· 548 548 549 549 #define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4) 550 550 #define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5) 551 + #define KVM_REG_PPC_LPCR_64 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb5) 551 552 #define KVM_REG_PPC_PPR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb6) 552 553 553 554 /* Architecture compatibility level */ ··· 556 555 557 556 #define KVM_REG_PPC_DABRX (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb8) 558 557 #define KVM_REG_PPC_WORT (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb9) 558 + #define KVM_REG_PPC_SPRG9 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xba) 559 559 560 560 /* Transactional Memory checkpointed state: 561 561 * This is all GPRs, all VSX regs and a subset of SPRs
+2
arch/powerpc/kernel/asm-offsets.c
··· 491 491 DEFINE(KVM_HOST_SDR1, offsetof(struct kvm, arch.host_sdr1)); 492 492 DEFINE(KVM_TLBIE_LOCK, offsetof(struct kvm, arch.tlbie_lock)); 493 493 DEFINE(KVM_NEED_FLUSH, offsetof(struct kvm, arch.need_tlb_flush.bits)); 494 + DEFINE(KVM_ENABLED_HCALLS, offsetof(struct kvm, arch.enabled_hcalls)); 494 495 DEFINE(KVM_LPCR, offsetof(struct kvm, arch.lpcr)); 495 496 DEFINE(KVM_RMOR, offsetof(struct kvm, arch.rmor)); 496 497 DEFINE(KVM_VRMA_SLB_V, offsetof(struct kvm, arch.vrma_slb_v)); ··· 666 665 DEFINE(VCPU_LR, offsetof(struct kvm_vcpu, arch.lr)); 667 666 DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr)); 668 667 DEFINE(VCPU_PC, offsetof(struct kvm_vcpu, arch.pc)); 668 + DEFINE(VCPU_SPRG9, offsetof(struct kvm_vcpu, arch.sprg9)); 669 669 DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); 670 670 DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear)); 671 671 DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
-237
arch/powerpc/kvm/44x.c
··· 1 - /* 2 - * This program is free software; you can redistribute it and/or modify 3 - * it under the terms of the GNU General Public License, version 2, as 4 - * published by the Free Software Foundation. 5 - * 6 - * This program is distributed in the hope that it will be useful, 7 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 - * GNU General Public License for more details. 10 - * 11 - * You should have received a copy of the GNU General Public License 12 - * along with this program; if not, write to the Free Software 13 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 - * 15 - * Copyright IBM Corp. 2008 16 - * 17 - * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18 - */ 19 - 20 - #include <linux/kvm_host.h> 21 - #include <linux/slab.h> 22 - #include <linux/err.h> 23 - #include <linux/export.h> 24 - #include <linux/module.h> 25 - #include <linux/miscdevice.h> 26 - 27 - #include <asm/reg.h> 28 - #include <asm/cputable.h> 29 - #include <asm/tlbflush.h> 30 - #include <asm/kvm_44x.h> 31 - #include <asm/kvm_ppc.h> 32 - 33 - #include "44x_tlb.h" 34 - #include "booke.h" 35 - 36 - static void kvmppc_core_vcpu_load_44x(struct kvm_vcpu *vcpu, int cpu) 37 - { 38 - kvmppc_booke_vcpu_load(vcpu, cpu); 39 - kvmppc_44x_tlb_load(vcpu); 40 - } 41 - 42 - static void kvmppc_core_vcpu_put_44x(struct kvm_vcpu *vcpu) 43 - { 44 - kvmppc_44x_tlb_put(vcpu); 45 - kvmppc_booke_vcpu_put(vcpu); 46 - } 47 - 48 - int kvmppc_core_check_processor_compat(void) 49 - { 50 - int r; 51 - 52 - if (strncmp(cur_cpu_spec->platform, "ppc440", 6) == 0) 53 - r = 0; 54 - else 55 - r = -ENOTSUPP; 56 - 57 - return r; 58 - } 59 - 60 - int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu) 61 - { 62 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 63 - struct kvmppc_44x_tlbe *tlbe = &vcpu_44x->guest_tlb[0]; 64 - int i; 65 - 66 - tlbe->tid = 0; 67 - tlbe->word0 = PPC44x_TLB_16M | PPC44x_TLB_VALID; 68 - tlbe->word1 = 0; 69 - tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR; 70 - 71 - tlbe++; 72 - tlbe->tid = 0; 73 - tlbe->word0 = 0xef600000 | PPC44x_TLB_4K | PPC44x_TLB_VALID; 74 - tlbe->word1 = 0xef600000; 75 - tlbe->word2 = PPC44x_TLB_SX | PPC44x_TLB_SW | PPC44x_TLB_SR 76 - | PPC44x_TLB_I | PPC44x_TLB_G; 77 - 78 - /* Since the guest can directly access the timebase, it must know the 79 - * real timebase frequency. Accordingly, it must see the state of 80 - * CCR1[TCS]. */ 81 - /* XXX CCR1 doesn't exist on all 440 SoCs. */ 82 - vcpu->arch.ccr1 = mfspr(SPRN_CCR1); 83 - 84 - for (i = 0; i < ARRAY_SIZE(vcpu_44x->shadow_refs); i++) 85 - vcpu_44x->shadow_refs[i].gtlb_index = -1; 86 - 87 - vcpu->arch.cpu_type = KVM_CPU_440; 88 - vcpu->arch.pvr = mfspr(SPRN_PVR); 89 - 90 - return 0; 91 - } 92 - 93 - /* 'linear_address' is actually an encoding of AS|PID|EADDR . */ 94 - int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, 95 - struct kvm_translation *tr) 96 - { 97 - int index; 98 - gva_t eaddr; 99 - u8 pid; 100 - u8 as; 101 - 102 - eaddr = tr->linear_address; 103 - pid = (tr->linear_address >> 32) & 0xff; 104 - as = (tr->linear_address >> 40) & 0x1; 105 - 106 - index = kvmppc_44x_tlb_index(vcpu, eaddr, pid, as); 107 - if (index == -1) { 108 - tr->valid = 0; 109 - return 0; 110 - } 111 - 112 - tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr); 113 - /* XXX what does "writeable" and "usermode" even mean? */ 114 - tr->valid = 1; 115 - 116 - return 0; 117 - } 118 - 119 - static int kvmppc_core_get_sregs_44x(struct kvm_vcpu *vcpu, 120 - struct kvm_sregs *sregs) 121 - { 122 - return kvmppc_get_sregs_ivor(vcpu, sregs); 123 - } 124 - 125 - static int kvmppc_core_set_sregs_44x(struct kvm_vcpu *vcpu, 126 - struct kvm_sregs *sregs) 127 - { 128 - return kvmppc_set_sregs_ivor(vcpu, sregs); 129 - } 130 - 131 - static int kvmppc_get_one_reg_44x(struct kvm_vcpu *vcpu, u64 id, 132 - union kvmppc_one_reg *val) 133 - { 134 - return -EINVAL; 135 - } 136 - 137 - static int kvmppc_set_one_reg_44x(struct kvm_vcpu *vcpu, u64 id, 138 - union kvmppc_one_reg *val) 139 - { 140 - return -EINVAL; 141 - } 142 - 143 - static struct kvm_vcpu *kvmppc_core_vcpu_create_44x(struct kvm *kvm, 144 - unsigned int id) 145 - { 146 - struct kvmppc_vcpu_44x *vcpu_44x; 147 - struct kvm_vcpu *vcpu; 148 - int err; 149 - 150 - vcpu_44x = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); 151 - if (!vcpu_44x) { 152 - err = -ENOMEM; 153 - goto out; 154 - } 155 - 156 - vcpu = &vcpu_44x->vcpu; 157 - err = kvm_vcpu_init(vcpu, kvm, id); 158 - if (err) 159 - goto free_vcpu; 160 - 161 - vcpu->arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO); 162 - if (!vcpu->arch.shared) 163 - goto uninit_vcpu; 164 - 165 - return vcpu; 166 - 167 - uninit_vcpu: 168 - kvm_vcpu_uninit(vcpu); 169 - free_vcpu: 170 - kmem_cache_free(kvm_vcpu_cache, vcpu_44x); 171 - out: 172 - return ERR_PTR(err); 173 - } 174 - 175 - static void kvmppc_core_vcpu_free_44x(struct kvm_vcpu *vcpu) 176 - { 177 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 178 - 179 - free_page((unsigned long)vcpu->arch.shared); 180 - kvm_vcpu_uninit(vcpu); 181 - kmem_cache_free(kvm_vcpu_cache, vcpu_44x); 182 - } 183 - 184 - static int kvmppc_core_init_vm_44x(struct kvm *kvm) 185 - { 186 - return 0; 187 - } 188 - 189 - static void kvmppc_core_destroy_vm_44x(struct kvm *kvm) 190 - { 191 - } 192 - 193 - static struct kvmppc_ops kvm_ops_44x = { 194 - .get_sregs = kvmppc_core_get_sregs_44x, 195 - .set_sregs = kvmppc_core_set_sregs_44x, 196 - .get_one_reg = kvmppc_get_one_reg_44x, 197 - .set_one_reg = kvmppc_set_one_reg_44x, 198 - .vcpu_load = kvmppc_core_vcpu_load_44x, 199 - .vcpu_put = kvmppc_core_vcpu_put_44x, 200 - .vcpu_create = kvmppc_core_vcpu_create_44x, 201 - .vcpu_free = kvmppc_core_vcpu_free_44x, 202 - .mmu_destroy = kvmppc_mmu_destroy_44x, 203 - .init_vm = kvmppc_core_init_vm_44x, 204 - .destroy_vm = kvmppc_core_destroy_vm_44x, 205 - .emulate_op = kvmppc_core_emulate_op_44x, 206 - .emulate_mtspr = kvmppc_core_emulate_mtspr_44x, 207 - .emulate_mfspr = kvmppc_core_emulate_mfspr_44x, 208 - }; 209 - 210 - static int __init kvmppc_44x_init(void) 211 - { 212 - int r; 213 - 214 - r = kvmppc_booke_init(); 215 - if (r) 216 - goto err_out; 217 - 218 - r = kvm_init(NULL, sizeof(struct kvmppc_vcpu_44x), 0, THIS_MODULE); 219 - if (r) 220 - goto err_out; 221 - kvm_ops_44x.owner = THIS_MODULE; 222 - kvmppc_pr_ops = &kvm_ops_44x; 223 - 224 - err_out: 225 - return r; 226 - } 227 - 228 - static void __exit kvmppc_44x_exit(void) 229 - { 230 - kvmppc_pr_ops = NULL; 231 - kvmppc_booke_exit(); 232 - } 233 - 234 - module_init(kvmppc_44x_init); 235 - module_exit(kvmppc_44x_exit); 236 - MODULE_ALIAS_MISCDEV(KVM_MINOR); 237 - MODULE_ALIAS("devname:kvm");
-194
arch/powerpc/kvm/44x_emulate.c
··· 1 - /* 2 - * This program is free software; you can redistribute it and/or modify 3 - * it under the terms of the GNU General Public License, version 2, as 4 - * published by the Free Software Foundation. 5 - * 6 - * This program is distributed in the hope that it will be useful, 7 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 - * GNU General Public License for more details. 10 - * 11 - * You should have received a copy of the GNU General Public License 12 - * along with this program; if not, write to the Free Software 13 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 - * 15 - * Copyright IBM Corp. 2008 16 - * 17 - * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18 - */ 19 - 20 - #include <asm/kvm_ppc.h> 21 - #include <asm/dcr.h> 22 - #include <asm/dcr-regs.h> 23 - #include <asm/disassemble.h> 24 - #include <asm/kvm_44x.h> 25 - #include "timing.h" 26 - 27 - #include "booke.h" 28 - #include "44x_tlb.h" 29 - 30 - #define XOP_MFDCRX 259 31 - #define XOP_MFDCR 323 32 - #define XOP_MTDCRX 387 33 - #define XOP_MTDCR 451 34 - #define XOP_TLBSX 914 35 - #define XOP_ICCCI 966 36 - #define XOP_TLBWE 978 37 - 38 - static int emulate_mtdcr(struct kvm_vcpu *vcpu, int rs, int dcrn) 39 - { 40 - /* emulate some access in kernel */ 41 - switch (dcrn) { 42 - case DCRN_CPR0_CONFIG_ADDR: 43 - vcpu->arch.cpr0_cfgaddr = kvmppc_get_gpr(vcpu, rs); 44 - return EMULATE_DONE; 45 - default: 46 - vcpu->run->dcr.dcrn = dcrn; 47 - vcpu->run->dcr.data = kvmppc_get_gpr(vcpu, rs); 48 - vcpu->run->dcr.is_write = 1; 49 - vcpu->arch.dcr_is_write = 1; 50 - vcpu->arch.dcr_needed = 1; 51 - kvmppc_account_exit(vcpu, DCR_EXITS); 52 - return EMULATE_DO_DCR; 53 - } 54 - } 55 - 56 - static int emulate_mfdcr(struct kvm_vcpu *vcpu, int rt, int dcrn) 57 - { 58 - /* The guest may access CPR0 registers to determine the timebase 59 - * frequency, and it must know the real host frequency because it 60 - * can directly access the timebase registers. 61 - * 62 - * It would be possible to emulate those accesses in userspace, 63 - * but userspace can really only figure out the end frequency. 64 - * We could decompose that into the factors that compute it, but 65 - * that's tricky math, and it's easier to just report the real 66 - * CPR0 values. 67 - */ 68 - switch (dcrn) { 69 - case DCRN_CPR0_CONFIG_ADDR: 70 - kvmppc_set_gpr(vcpu, rt, vcpu->arch.cpr0_cfgaddr); 71 - break; 72 - case DCRN_CPR0_CONFIG_DATA: 73 - local_irq_disable(); 74 - mtdcr(DCRN_CPR0_CONFIG_ADDR, 75 - vcpu->arch.cpr0_cfgaddr); 76 - kvmppc_set_gpr(vcpu, rt, 77 - mfdcr(DCRN_CPR0_CONFIG_DATA)); 78 - local_irq_enable(); 79 - break; 80 - default: 81 - vcpu->run->dcr.dcrn = dcrn; 82 - vcpu->run->dcr.data = 0; 83 - vcpu->run->dcr.is_write = 0; 84 - vcpu->arch.dcr_is_write = 0; 85 - vcpu->arch.io_gpr = rt; 86 - vcpu->arch.dcr_needed = 1; 87 - kvmppc_account_exit(vcpu, DCR_EXITS); 88 - return EMULATE_DO_DCR; 89 - } 90 - 91 - return EMULATE_DONE; 92 - } 93 - 94 - int kvmppc_core_emulate_op_44x(struct kvm_run *run, struct kvm_vcpu *vcpu, 95 - unsigned int inst, int *advance) 96 - { 97 - int emulated = EMULATE_DONE; 98 - int dcrn = get_dcrn(inst); 99 - int ra = get_ra(inst); 100 - int rb = get_rb(inst); 101 - int rc = get_rc(inst); 102 - int rs = get_rs(inst); 103 - int rt = get_rt(inst); 104 - int ws = get_ws(inst); 105 - 106 - switch (get_op(inst)) { 107 - case 31: 108 - switch (get_xop(inst)) { 109 - 110 - case XOP_MFDCR: 111 - emulated = emulate_mfdcr(vcpu, rt, dcrn); 112 - break; 113 - 114 - case XOP_MFDCRX: 115 - emulated = emulate_mfdcr(vcpu, rt, 116 - kvmppc_get_gpr(vcpu, ra)); 117 - break; 118 - 119 - case XOP_MTDCR: 120 - emulated = emulate_mtdcr(vcpu, rs, dcrn); 121 - break; 122 - 123 - case XOP_MTDCRX: 124 - emulated = emulate_mtdcr(vcpu, rs, 125 - kvmppc_get_gpr(vcpu, ra)); 126 - break; 127 - 128 - case XOP_TLBWE: 129 - emulated = kvmppc_44x_emul_tlbwe(vcpu, ra, rs, ws); 130 - break; 131 - 132 - case XOP_TLBSX: 133 - emulated = kvmppc_44x_emul_tlbsx(vcpu, rt, ra, rb, rc); 134 - break; 135 - 136 - case XOP_ICCCI: 137 - break; 138 - 139 - default: 140 - emulated = EMULATE_FAIL; 141 - } 142 - 143 - break; 144 - 145 - default: 146 - emulated = EMULATE_FAIL; 147 - } 148 - 149 - if (emulated == EMULATE_FAIL) 150 - emulated = kvmppc_booke_emulate_op(run, vcpu, inst, advance); 151 - 152 - return emulated; 153 - } 154 - 155 - int kvmppc_core_emulate_mtspr_44x(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) 156 - { 157 - int emulated = EMULATE_DONE; 158 - 159 - switch (sprn) { 160 - case SPRN_PID: 161 - kvmppc_set_pid(vcpu, spr_val); break; 162 - case SPRN_MMUCR: 163 - vcpu->arch.mmucr = spr_val; break; 164 - case SPRN_CCR0: 165 - vcpu->arch.ccr0 = spr_val; break; 166 - case SPRN_CCR1: 167 - vcpu->arch.ccr1 = spr_val; break; 168 - default: 169 - emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, spr_val); 170 - } 171 - 172 - return emulated; 173 - } 174 - 175 - int kvmppc_core_emulate_mfspr_44x(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) 176 - { 177 - int emulated = EMULATE_DONE; 178 - 179 - switch (sprn) { 180 - case SPRN_PID: 181 - *spr_val = vcpu->arch.pid; break; 182 - case SPRN_MMUCR: 183 - *spr_val = vcpu->arch.mmucr; break; 184 - case SPRN_CCR0: 185 - *spr_val = vcpu->arch.ccr0; break; 186 - case SPRN_CCR1: 187 - *spr_val = vcpu->arch.ccr1; break; 188 - default: 189 - emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, spr_val); 190 - } 191 - 192 - return emulated; 193 - } 194 -
-528
arch/powerpc/kvm/44x_tlb.c
··· 1 - /* 2 - * This program is free software; you can redistribute it and/or modify 3 - * it under the terms of the GNU General Public License, version 2, as 4 - * published by the Free Software Foundation. 5 - * 6 - * This program is distributed in the hope that it will be useful, 7 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 - * GNU General Public License for more details. 10 - * 11 - * You should have received a copy of the GNU General Public License 12 - * along with this program; if not, write to the Free Software 13 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 - * 15 - * Copyright IBM Corp. 2007 16 - * 17 - * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18 - */ 19 - 20 - #include <linux/types.h> 21 - #include <linux/string.h> 22 - #include <linux/kvm.h> 23 - #include <linux/kvm_host.h> 24 - #include <linux/highmem.h> 25 - 26 - #include <asm/tlbflush.h> 27 - #include <asm/mmu-44x.h> 28 - #include <asm/kvm_ppc.h> 29 - #include <asm/kvm_44x.h> 30 - #include "timing.h" 31 - 32 - #include "44x_tlb.h" 33 - #include "trace.h" 34 - 35 - #ifndef PPC44x_TLBE_SIZE 36 - #define PPC44x_TLBE_SIZE PPC44x_TLB_4K 37 - #endif 38 - 39 - #define PAGE_SIZE_4K (1<<12) 40 - #define PAGE_MASK_4K (~(PAGE_SIZE_4K - 1)) 41 - 42 - #define PPC44x_TLB_UATTR_MASK \ 43 - (PPC44x_TLB_U0|PPC44x_TLB_U1|PPC44x_TLB_U2|PPC44x_TLB_U3) 44 - #define PPC44x_TLB_USER_PERM_MASK (PPC44x_TLB_UX|PPC44x_TLB_UR|PPC44x_TLB_UW) 45 - #define PPC44x_TLB_SUPER_PERM_MASK (PPC44x_TLB_SX|PPC44x_TLB_SR|PPC44x_TLB_SW) 46 - 47 - #ifdef DEBUG 48 - void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu) 49 - { 50 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 51 - struct kvmppc_44x_tlbe *tlbe; 52 - int i; 53 - 54 - printk("vcpu %d TLB dump:\n", vcpu->vcpu_id); 55 - printk("| %2s | %3s | %8s | %8s | %8s |\n", 56 - "nr", "tid", "word0", "word1", "word2"); 57 - 58 - for (i = 0; i < ARRAY_SIZE(vcpu_44x->guest_tlb); i++) { 59 - tlbe = &vcpu_44x->guest_tlb[i]; 60 - if (tlbe->word0 & PPC44x_TLB_VALID) 61 - printk(" G%2d | %02X | %08X | %08X | %08X |\n", 62 - i, tlbe->tid, tlbe->word0, tlbe->word1, 63 - tlbe->word2); 64 - } 65 - } 66 - #endif 67 - 68 - static inline void kvmppc_44x_tlbie(unsigned int index) 69 - { 70 - /* 0 <= index < 64, so the V bit is clear and we can use the index as 71 - * word0. */ 72 - asm volatile( 73 - "tlbwe %[index], %[index], 0\n" 74 - : 75 - : [index] "r"(index) 76 - ); 77 - } 78 - 79 - static inline void kvmppc_44x_tlbre(unsigned int index, 80 - struct kvmppc_44x_tlbe *tlbe) 81 - { 82 - asm volatile( 83 - "tlbre %[word0], %[index], 0\n" 84 - "mfspr %[tid], %[sprn_mmucr]\n" 85 - "andi. %[tid], %[tid], 0xff\n" 86 - "tlbre %[word1], %[index], 1\n" 87 - "tlbre %[word2], %[index], 2\n" 88 - : [word0] "=r"(tlbe->word0), 89 - [word1] "=r"(tlbe->word1), 90 - [word2] "=r"(tlbe->word2), 91 - [tid] "=r"(tlbe->tid) 92 - : [index] "r"(index), 93 - [sprn_mmucr] "i"(SPRN_MMUCR) 94 - : "cc" 95 - ); 96 - } 97 - 98 - static inline void kvmppc_44x_tlbwe(unsigned int index, 99 - struct kvmppc_44x_tlbe *stlbe) 100 - { 101 - unsigned long tmp; 102 - 103 - asm volatile( 104 - "mfspr %[tmp], %[sprn_mmucr]\n" 105 - "rlwimi %[tmp], %[tid], 0, 0xff\n" 106 - "mtspr %[sprn_mmucr], %[tmp]\n" 107 - "tlbwe %[word0], %[index], 0\n" 108 - "tlbwe %[word1], %[index], 1\n" 109 - "tlbwe %[word2], %[index], 2\n" 110 - : [tmp] "=&r"(tmp) 111 - : [word0] "r"(stlbe->word0), 112 - [word1] "r"(stlbe->word1), 113 - [word2] "r"(stlbe->word2), 114 - [tid] "r"(stlbe->tid), 115 - [index] "r"(index), 116 - [sprn_mmucr] "i"(SPRN_MMUCR) 117 - ); 118 - } 119 - 120 - static u32 kvmppc_44x_tlb_shadow_attrib(u32 attrib, int usermode) 121 - { 122 - /* We only care about the guest's permission and user bits. */ 123 - attrib &= PPC44x_TLB_PERM_MASK|PPC44x_TLB_UATTR_MASK; 124 - 125 - if (!usermode) { 126 - /* Guest is in supervisor mode, so we need to translate guest 127 - * supervisor permissions into user permissions. */ 128 - attrib &= ~PPC44x_TLB_USER_PERM_MASK; 129 - attrib |= (attrib & PPC44x_TLB_SUPER_PERM_MASK) << 3; 130 - } 131 - 132 - /* Make sure host can always access this memory. */ 133 - attrib |= PPC44x_TLB_SX|PPC44x_TLB_SR|PPC44x_TLB_SW; 134 - 135 - /* WIMGE = 0b00100 */ 136 - attrib |= PPC44x_TLB_M; 137 - 138 - return attrib; 139 - } 140 - 141 - /* Load shadow TLB back into hardware. */ 142 - void kvmppc_44x_tlb_load(struct kvm_vcpu *vcpu) 143 - { 144 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 145 - int i; 146 - 147 - for (i = 0; i <= tlb_44x_hwater; i++) { 148 - struct kvmppc_44x_tlbe *stlbe = &vcpu_44x->shadow_tlb[i]; 149 - 150 - if (get_tlb_v(stlbe) && get_tlb_ts(stlbe)) 151 - kvmppc_44x_tlbwe(i, stlbe); 152 - } 153 - } 154 - 155 - static void kvmppc_44x_tlbe_set_modified(struct kvmppc_vcpu_44x *vcpu_44x, 156 - unsigned int i) 157 - { 158 - vcpu_44x->shadow_tlb_mod[i] = 1; 159 - } 160 - 161 - /* Save hardware TLB to the vcpu, and invalidate all guest mappings. */ 162 - void kvmppc_44x_tlb_put(struct kvm_vcpu *vcpu) 163 - { 164 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 165 - int i; 166 - 167 - for (i = 0; i <= tlb_44x_hwater; i++) { 168 - struct kvmppc_44x_tlbe *stlbe = &vcpu_44x->shadow_tlb[i]; 169 - 170 - if (vcpu_44x->shadow_tlb_mod[i]) 171 - kvmppc_44x_tlbre(i, stlbe); 172 - 173 - if (get_tlb_v(stlbe) && get_tlb_ts(stlbe)) 174 - kvmppc_44x_tlbie(i); 175 - } 176 - } 177 - 178 - 179 - /* Search the guest TLB for a matching entry. */ 180 - int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, unsigned int pid, 181 - unsigned int as) 182 - { 183 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 184 - int i; 185 - 186 - /* XXX Replace loop with fancy data structures. */ 187 - for (i = 0; i < ARRAY_SIZE(vcpu_44x->guest_tlb); i++) { 188 - struct kvmppc_44x_tlbe *tlbe = &vcpu_44x->guest_tlb[i]; 189 - unsigned int tid; 190 - 191 - if (eaddr < get_tlb_eaddr(tlbe)) 192 - continue; 193 - 194 - if (eaddr > get_tlb_end(tlbe)) 195 - continue; 196 - 197 - tid = get_tlb_tid(tlbe); 198 - if (tid && (tid != pid)) 199 - continue; 200 - 201 - if (!get_tlb_v(tlbe)) 202 - continue; 203 - 204 - if (get_tlb_ts(tlbe) != as) 205 - continue; 206 - 207 - return i; 208 - } 209 - 210 - return -1; 211 - } 212 - 213 - gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index, 214 - gva_t eaddr) 215 - { 216 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 217 - struct kvmppc_44x_tlbe *gtlbe = &vcpu_44x->guest_tlb[gtlb_index]; 218 - unsigned int pgmask = get_tlb_bytes(gtlbe) - 1; 219 - 220 - return get_tlb_raddr(gtlbe) | (eaddr & pgmask); 221 - } 222 - 223 - int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr) 224 - { 225 - unsigned int as = !!(vcpu->arch.shared->msr & MSR_IS); 226 - 227 - return kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as); 228 - } 229 - 230 - int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr) 231 - { 232 - unsigned int as = !!(vcpu->arch.shared->msr & MSR_DS); 233 - 234 - return kvmppc_44x_tlb_index(vcpu, eaddr, vcpu->arch.pid, as); 235 - } 236 - 237 - void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu) 238 - { 239 - } 240 - 241 - void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu) 242 - { 243 - } 244 - 245 - static void kvmppc_44x_shadow_release(struct kvmppc_vcpu_44x *vcpu_44x, 246 - unsigned int stlb_index) 247 - { 248 - struct kvmppc_44x_shadow_ref *ref = &vcpu_44x->shadow_refs[stlb_index]; 249 - 250 - if (!ref->page) 251 - return; 252 - 253 - /* Discard from the TLB. */ 254 - /* Note: we could actually invalidate a host mapping, if the host overwrote 255 - * this TLB entry since we inserted a guest mapping. */ 256 - kvmppc_44x_tlbie(stlb_index); 257 - 258 - /* Now release the page. */ 259 - if (ref->writeable) 260 - kvm_release_page_dirty(ref->page); 261 - else 262 - kvm_release_page_clean(ref->page); 263 - 264 - ref->page = NULL; 265 - 266 - /* XXX set tlb_44x_index to stlb_index? */ 267 - 268 - trace_kvm_stlb_inval(stlb_index); 269 - } 270 - 271 - void kvmppc_mmu_destroy_44x(struct kvm_vcpu *vcpu) 272 - { 273 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 274 - int i; 275 - 276 - for (i = 0; i <= tlb_44x_hwater; i++) 277 - kvmppc_44x_shadow_release(vcpu_44x, i); 278 - } 279 - 280 - /** 281 - * kvmppc_mmu_map -- create a host mapping for guest memory 282 - * 283 - * If the guest wanted a larger page than the host supports, only the first 284 - * host page is mapped here and the rest are demand faulted. 285 - * 286 - * If the guest wanted a smaller page than the host page size, we map only the 287 - * guest-size page (i.e. not a full host page mapping). 288 - * 289 - * Caller must ensure that the specified guest TLB entry is safe to insert into 290 - * the shadow TLB. 291 - */ 292 - void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr, 293 - unsigned int gtlb_index) 294 - { 295 - struct kvmppc_44x_tlbe stlbe; 296 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 297 - struct kvmppc_44x_tlbe *gtlbe = &vcpu_44x->guest_tlb[gtlb_index]; 298 - struct kvmppc_44x_shadow_ref *ref; 299 - struct page *new_page; 300 - hpa_t hpaddr; 301 - gfn_t gfn; 302 - u32 asid = gtlbe->tid; 303 - u32 flags = gtlbe->word2; 304 - u32 max_bytes = get_tlb_bytes(gtlbe); 305 - unsigned int victim; 306 - 307 - /* Select TLB entry to clobber. Indirectly guard against races with the TLB 308 - * miss handler by disabling interrupts. */ 309 - local_irq_disable(); 310 - victim = ++tlb_44x_index; 311 - if (victim > tlb_44x_hwater) 312 - victim = 0; 313 - tlb_44x_index = victim; 314 - local_irq_enable(); 315 - 316 - /* Get reference to new page. */ 317 - gfn = gpaddr >> PAGE_SHIFT; 318 - new_page = gfn_to_page(vcpu->kvm, gfn); 319 - if (is_error_page(new_page)) { 320 - printk(KERN_ERR "Couldn't get guest page for gfn %llx!\n", 321 - (unsigned long long)gfn); 322 - return; 323 - } 324 - hpaddr = page_to_phys(new_page); 325 - 326 - /* Invalidate any previous shadow mappings. */ 327 - kvmppc_44x_shadow_release(vcpu_44x, victim); 328 - 329 - /* XXX Make sure (va, size) doesn't overlap any other 330 - * entries. 440x6 user manual says the result would be 331 - * "undefined." */ 332 - 333 - /* XXX what about AS? */ 334 - 335 - /* Force TS=1 for all guest mappings. */ 336 - stlbe.word0 = PPC44x_TLB_VALID | PPC44x_TLB_TS; 337 - 338 - if (max_bytes >= PAGE_SIZE) { 339 - /* Guest mapping is larger than or equal to host page size. We can use 340 - * a "native" host mapping. */ 341 - stlbe.word0 |= (gvaddr & PAGE_MASK) | PPC44x_TLBE_SIZE; 342 - } else { 343 - /* Guest mapping is smaller than host page size. We must restrict the 344 - * size of the mapping to be at most the smaller of the two, but for 345 - * simplicity we fall back to a 4K mapping (this is probably what the 346 - * guest is using anyways). */ 347 - stlbe.word0 |= (gvaddr & PAGE_MASK_4K) | PPC44x_TLB_4K; 348 - 349 - /* 'hpaddr' is a host page, which is larger than the mapping we're 350 - * inserting here. To compensate, we must add the in-page offset to the 351 - * sub-page. */ 352 - hpaddr |= gpaddr & (PAGE_MASK ^ PAGE_MASK_4K); 353 - } 354 - 355 - stlbe.word1 = (hpaddr & 0xfffffc00) | ((hpaddr >> 32) & 0xf); 356 - stlbe.word2 = kvmppc_44x_tlb_shadow_attrib(flags, 357 - vcpu->arch.shared->msr & MSR_PR); 358 - stlbe.tid = !(asid & 0xff); 359 - 360 - /* Keep track of the reference so we can properly release it later. */ 361 - ref = &vcpu_44x->shadow_refs[victim]; 362 - ref->page = new_page; 363 - ref->gtlb_index = gtlb_index; 364 - ref->writeable = !!(stlbe.word2 & PPC44x_TLB_UW); 365 - ref->tid = stlbe.tid; 366 - 367 - /* Insert shadow mapping into hardware TLB. */ 368 - kvmppc_44x_tlbe_set_modified(vcpu_44x, victim); 369 - kvmppc_44x_tlbwe(victim, &stlbe); 370 - trace_kvm_stlb_write(victim, stlbe.tid, stlbe.word0, stlbe.word1, 371 - stlbe.word2); 372 - } 373 - 374 - /* For a particular guest TLB entry, invalidate the corresponding host TLB 375 - * mappings and release the host pages. */ 376 - static void kvmppc_44x_invalidate(struct kvm_vcpu *vcpu, 377 - unsigned int gtlb_index) 378 - { 379 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 380 - int i; 381 - 382 - for (i = 0; i < ARRAY_SIZE(vcpu_44x->shadow_refs); i++) { 383 - struct kvmppc_44x_shadow_ref *ref = &vcpu_44x->shadow_refs[i]; 384 - if (ref->gtlb_index == gtlb_index) 385 - kvmppc_44x_shadow_release(vcpu_44x, i); 386 - } 387 - } 388 - 389 - void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr) 390 - { 391 - int usermode = vcpu->arch.shared->msr & MSR_PR; 392 - 393 - vcpu->arch.shadow_pid = !usermode; 394 - } 395 - 396 - void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 new_pid) 397 - { 398 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 399 - int i; 400 - 401 - if (unlikely(vcpu->arch.pid == new_pid)) 402 - return; 403 - 404 - vcpu->arch.pid = new_pid; 405 - 406 - /* Guest userspace runs with TID=0 mappings and PID=0, to make sure it 407 - * can't access guest kernel mappings (TID=1). When we switch to a new 408 - * guest PID, which will also use host PID=0, we must discard the old guest 409 - * userspace mappings. */ 410 - for (i = 0; i < ARRAY_SIZE(vcpu_44x->shadow_refs); i++) { 411 - struct kvmppc_44x_shadow_ref *ref = &vcpu_44x->shadow_refs[i]; 412 - 413 - if (ref->tid == 0) 414 - kvmppc_44x_shadow_release(vcpu_44x, i); 415 - } 416 - } 417 - 418 - static int tlbe_is_host_safe(const struct kvm_vcpu *vcpu, 419 - const struct kvmppc_44x_tlbe *tlbe) 420 - { 421 - gpa_t gpa; 422 - 423 - if (!get_tlb_v(tlbe)) 424 - return 0; 425 - 426 - /* Does it match current guest AS? */ 427 - /* XXX what about IS != DS? */ 428 - if (get_tlb_ts(tlbe) != !!(vcpu->arch.shared->msr & MSR_IS)) 429 - return 0; 430 - 431 - gpa = get_tlb_raddr(tlbe); 432 - if (!gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT)) 433 - /* Mapping is not for RAM. */ 434 - return 0; 435 - 436 - return 1; 437 - } 438 - 439 - int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws) 440 - { 441 - struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu); 442 - struct kvmppc_44x_tlbe *tlbe; 443 - unsigned int gtlb_index; 444 - int idx; 445 - 446 - gtlb_index = kvmppc_get_gpr(vcpu, ra); 447 - if (gtlb_index >= KVM44x_GUEST_TLB_SIZE) { 448 - printk("%s: index %d\n", __func__, gtlb_index); 449 - kvmppc_dump_vcpu(vcpu); 450 - return EMULATE_FAIL; 451 - } 452 - 453 - tlbe = &vcpu_44x->guest_tlb[gtlb_index]; 454 - 455 - /* Invalidate shadow mappings for the about-to-be-clobbered TLB entry. */ 456 - if (tlbe->word0 & PPC44x_TLB_VALID) 457 - kvmppc_44x_invalidate(vcpu, gtlb_index); 458 - 459 - switch (ws) { 460 - case PPC44x_TLB_PAGEID: 461 - tlbe->tid = get_mmucr_stid(vcpu); 462 - tlbe->word0 = kvmppc_get_gpr(vcpu, rs); 463 - break; 464 - 465 - case PPC44x_TLB_XLAT: 466 - tlbe->word1 = kvmppc_get_gpr(vcpu, rs); 467 - break; 468 - 469 - case PPC44x_TLB_ATTRIB: 470 - tlbe->word2 = kvmppc_get_gpr(vcpu, rs); 471 - break; 472 - 473 - default: 474 - return EMULATE_FAIL; 475 - } 476 - 477 - idx = srcu_read_lock(&vcpu->kvm->srcu); 478 - 479 - if (tlbe_is_host_safe(vcpu, tlbe)) { 480 - gva_t eaddr; 481 - gpa_t gpaddr; 482 - u32 bytes; 483 - 484 - eaddr = get_tlb_eaddr(tlbe); 485 - gpaddr = get_tlb_raddr(tlbe); 486 - 487 - /* Use the advertised page size to mask effective and real addrs. */ 488 - bytes = get_tlb_bytes(tlbe); 489 - eaddr &= ~(bytes - 1); 490 - gpaddr &= ~(bytes - 1); 491 - 492 - kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); 493 - } 494 - 495 - srcu_read_unlock(&vcpu->kvm->srcu, idx); 496 - 497 - trace_kvm_gtlb_write(gtlb_index, tlbe->tid, tlbe->word0, tlbe->word1, 498 - tlbe->word2); 499 - 500 - kvmppc_set_exit_type(vcpu, EMULATED_TLBWE_EXITS); 501 - return EMULATE_DONE; 502 - } 503 - 504 - int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, u8 rc) 505 - { 506 - u32 ea; 507 - int gtlb_index; 508 - unsigned int as = get_mmucr_sts(vcpu); 509 - unsigned int pid = get_mmucr_stid(vcpu); 510 - 511 - ea = kvmppc_get_gpr(vcpu, rb); 512 - if (ra) 513 - ea += kvmppc_get_gpr(vcpu, ra); 514 - 515 - gtlb_index = kvmppc_44x_tlb_index(vcpu, ea, pid, as); 516 - if (rc) { 517 - u32 cr = kvmppc_get_cr(vcpu); 518 - 519 - if (gtlb_index < 0) 520 - kvmppc_set_cr(vcpu, cr & ~0x20000000); 521 - else 522 - kvmppc_set_cr(vcpu, cr | 0x20000000); 523 - } 524 - kvmppc_set_gpr(vcpu, rt, gtlb_index); 525 - 526 - kvmppc_set_exit_type(vcpu, EMULATED_TLBSX_EXITS); 527 - return EMULATE_DONE; 528 - }
-86
arch/powerpc/kvm/44x_tlb.h
··· 1 - /* 2 - * This program is free software; you can redistribute it and/or modify 3 - * it under the terms of the GNU General Public License, version 2, as 4 - * published by the Free Software Foundation. 5 - * 6 - * This program is distributed in the hope that it will be useful, 7 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 - * GNU General Public License for more details. 10 - * 11 - * You should have received a copy of the GNU General Public License 12 - * along with this program; if not, write to the Free Software 13 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 - * 15 - * Copyright IBM Corp. 2007 16 - * 17 - * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18 - */ 19 - 20 - #ifndef __KVM_POWERPC_TLB_H__ 21 - #define __KVM_POWERPC_TLB_H__ 22 - 23 - #include <linux/kvm_host.h> 24 - #include <asm/mmu-44x.h> 25 - 26 - extern int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr, 27 - unsigned int pid, unsigned int as); 28 - 29 - extern int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, 30 - u8 rc); 31 - extern int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws); 32 - 33 - /* TLB helper functions */ 34 - static inline unsigned int get_tlb_size(const struct kvmppc_44x_tlbe *tlbe) 35 - { 36 - return (tlbe->word0 >> 4) & 0xf; 37 - } 38 - 39 - static inline gva_t get_tlb_eaddr(const struct kvmppc_44x_tlbe *tlbe) 40 - { 41 - return tlbe->word0 & 0xfffffc00; 42 - } 43 - 44 - static inline gva_t get_tlb_bytes(const struct kvmppc_44x_tlbe *tlbe) 45 - { 46 - unsigned int pgsize = get_tlb_size(tlbe); 47 - return 1 << 10 << (pgsize << 1); 48 - } 49 - 50 - static inline gva_t get_tlb_end(const struct kvmppc_44x_tlbe *tlbe) 51 - { 52 - return get_tlb_eaddr(tlbe) + get_tlb_bytes(tlbe) - 1; 53 - } 54 - 55 - static inline u64 get_tlb_raddr(const struct kvmppc_44x_tlbe *tlbe) 56 - { 57 - u64 word1 = tlbe->word1; 58 - return ((word1 & 0xf) << 32) | (word1 & 0xfffffc00); 59 - } 60 - 61 - static inline unsigned int get_tlb_tid(const struct kvmppc_44x_tlbe *tlbe) 62 - { 63 - return tlbe->tid & 0xff; 64 - } 65 - 66 - static inline unsigned int get_tlb_ts(const struct kvmppc_44x_tlbe *tlbe) 67 - { 68 - return (tlbe->word0 >> 8) & 0x1; 69 - } 70 - 71 - static inline unsigned int get_tlb_v(const struct kvmppc_44x_tlbe *tlbe) 72 - { 73 - return (tlbe->word0 >> 9) & 0x1; 74 - } 75 - 76 - static inline unsigned int get_mmucr_stid(const struct kvm_vcpu *vcpu) 77 - { 78 - return vcpu->arch.mmucr & 0xff; 79 - } 80 - 81 - static inline unsigned int get_mmucr_sts(const struct kvm_vcpu *vcpu) 82 - { 83 - return (vcpu->arch.mmucr >> 16) & 0x1; 84 - } 85 - 86 - #endif /* __KVM_POWERPC_TLB_H__ */
+4 -16
arch/powerpc/kvm/Kconfig
··· 75 75 config KVM_BOOK3S_64_HV 76 76 tristate "KVM support for POWER7 and PPC970 using hypervisor mode in host" 77 77 depends on KVM_BOOK3S_64 78 - depends on !CPU_LITTLE_ENDIAN 79 78 select KVM_BOOK3S_HV_POSSIBLE 80 79 select MMU_NOTIFIER 81 80 select CMA ··· 112 113 config KVM_BOOKE_HV 113 114 bool 114 115 115 - config KVM_440 116 - bool "KVM support for PowerPC 440 processors" 117 - depends on 44x 118 - select KVM 119 - select KVM_MMIO 120 - ---help--- 121 - Support running unmodified 440 guest kernels in virtual machines on 122 - 440 host processors. 123 - 124 - This module provides access to the hardware capabilities through 125 - a character device node named /dev/kvm. 126 - 127 - If unsure, say N. 128 - 129 116 config KVM_EXIT_TIMING 130 117 bool "Detailed exit timing" 131 - depends on KVM_440 || KVM_E500V2 || KVM_E500MC 118 + depends on KVM_E500V2 || KVM_E500MC 132 119 ---help--- 133 120 Calculate elapsed time for every exit/enter cycle. A per-vcpu 134 121 report is available in debugfs kvm/vm#_vcpu#_timing. ··· 158 173 bool "KVM in-kernel MPIC emulation" 159 174 depends on KVM && E500 160 175 select HAVE_KVM_IRQCHIP 176 + select HAVE_KVM_IRQFD 161 177 select HAVE_KVM_IRQ_ROUTING 162 178 select HAVE_KVM_MSI 163 179 help ··· 170 184 config KVM_XICS 171 185 bool "KVM in-kernel XICS emulation" 172 186 depends on KVM_BOOK3S_64 && !KVM_MPIC 187 + select HAVE_KVM_IRQCHIP 188 + select HAVE_KVM_IRQFD 173 189 ---help--- 174 190 Include support for the XICS (eXternal Interrupt Controller 175 191 Specification) interrupt controller architecture used on
+4 -14
arch/powerpc/kvm/Makefile
··· 10 10 common-objs-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o \ 11 11 $(KVM)/eventfd.o 12 12 13 - CFLAGS_44x_tlb.o := -I. 14 13 CFLAGS_e500_mmu.o := -I. 15 14 CFLAGS_e500_mmu_host.o := -I. 16 15 CFLAGS_emulate.o := -I. 16 + CFLAGS_emulate_loadstore.o := -I. 17 17 18 - common-objs-y += powerpc.o emulate.o 18 + common-objs-y += powerpc.o emulate.o emulate_loadstore.o 19 19 obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o 20 20 obj-$(CONFIG_KVM_BOOK3S_HANDLER) += book3s_exports.o 21 21 22 22 AFLAGS_booke_interrupts.o := -I$(obj) 23 - 24 - kvm-440-objs := \ 25 - $(common-objs-y) \ 26 - booke.o \ 27 - booke_emulate.o \ 28 - booke_interrupts.o \ 29 - 44x.o \ 30 - 44x_tlb.o \ 31 - 44x_emulate.o 32 - kvm-objs-$(CONFIG_KVM_440) := $(kvm-440-objs) 33 23 34 24 kvm-e500-objs := \ 35 25 $(common-objs-y) \ ··· 48 58 49 59 kvm-pr-y := \ 50 60 fpu.o \ 61 + emulate.o \ 51 62 book3s_paired_singles.o \ 52 63 book3s_pr.o \ 53 64 book3s_pr_papr.o \ ··· 91 100 $(KVM)/kvm_main.o \ 92 101 $(KVM)/eventfd.o \ 93 102 powerpc.o \ 94 - emulate.o \ 103 + emulate_loadstore.o \ 95 104 book3s.o \ 96 105 book3s_64_vio.o \ 97 106 book3s_rtas.o \ ··· 117 126 118 127 kvm-objs := $(kvm-objs-m) $(kvm-objs-y) 119 128 120 - obj-$(CONFIG_KVM_440) += kvm.o 121 129 obj-$(CONFIG_KVM_E500V2) += kvm.o 122 130 obj-$(CONFIG_KVM_E500MC) += kvm.o 123 131 obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o
+77 -83
arch/powerpc/kvm/book3s.c
··· 72 72 { 73 73 } 74 74 75 + void kvmppc_unfixup_split_real(struct kvm_vcpu *vcpu) 76 + { 77 + if (vcpu->arch.hflags & BOOK3S_HFLAG_SPLIT_HACK) { 78 + ulong pc = kvmppc_get_pc(vcpu); 79 + if ((pc & SPLIT_HACK_MASK) == SPLIT_HACK_OFFS) 80 + kvmppc_set_pc(vcpu, pc & ~SPLIT_HACK_MASK); 81 + vcpu->arch.hflags &= ~BOOK3S_HFLAG_SPLIT_HACK; 82 + } 83 + } 84 + EXPORT_SYMBOL_GPL(kvmppc_unfixup_split_real); 85 + 75 86 static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu) 76 87 { 77 88 if (!is_kvmppc_hv_enabled(vcpu->kvm)) ··· 129 118 130 119 void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags) 131 120 { 121 + kvmppc_unfixup_split_real(vcpu); 132 122 kvmppc_set_srr0(vcpu, kvmppc_get_pc(vcpu)); 133 123 kvmppc_set_srr1(vcpu, kvmppc_get_msr(vcpu) | flags); 134 124 kvmppc_set_pc(vcpu, kvmppc_interrupt_offset(vcpu) + vec); ··· 228 216 { 229 217 kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL); 230 218 kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_EXTERNAL_LEVEL); 219 + } 220 + 221 + void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, ulong dar, 222 + ulong flags) 223 + { 224 + kvmppc_set_dar(vcpu, dar); 225 + kvmppc_set_dsisr(vcpu, flags); 226 + kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_DATA_STORAGE); 227 + } 228 + 229 + void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, ulong flags) 230 + { 231 + u64 msr = kvmppc_get_msr(vcpu); 232 + msr &= ~(SRR1_ISI_NOPT | SRR1_ISI_N_OR_G | SRR1_ISI_PROT); 233 + msr |= flags & (SRR1_ISI_NOPT | SRR1_ISI_N_OR_G | SRR1_ISI_PROT); 234 + kvmppc_set_msr_fast(vcpu, msr); 235 + kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_INST_STORAGE); 231 236 } 232 237 233 238 int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority) ··· 371 342 } 372 343 EXPORT_SYMBOL_GPL(kvmppc_core_prepare_to_enter); 373 344 374 - pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing, 345 + pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing, 375 346 bool *writable) 376 347 { 377 - ulong mp_pa = vcpu->arch.magic_page_pa; 348 + ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM; 349 + gfn_t gfn = gpa >> PAGE_SHIFT; 378 350 379 351 if (!(kvmppc_get_msr(vcpu) & MSR_SF)) 380 352 mp_pa = (uint32_t)mp_pa; 381 353 382 354 /* Magic page override */ 383 - if (unlikely(mp_pa) && 384 - unlikely(((gfn << PAGE_SHIFT) & KVM_PAM) == 385 - ((mp_pa & PAGE_MASK) & KVM_PAM))) { 355 + gpa &= ~0xFFFULL; 356 + if (unlikely(mp_pa) && unlikely((gpa & KVM_PAM) == mp_pa)) { 386 357 ulong shared_page = ((ulong)vcpu->arch.shared) & PAGE_MASK; 387 358 pfn_t pfn; 388 359 ··· 395 366 396 367 return gfn_to_pfn_prot(vcpu->kvm, gfn, writing, writable); 397 368 } 398 - EXPORT_SYMBOL_GPL(kvmppc_gfn_to_pfn); 369 + EXPORT_SYMBOL_GPL(kvmppc_gpa_to_pfn); 399 370 400 - static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data, 401 - bool iswrite, struct kvmppc_pte *pte) 371 + int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid, 372 + enum xlate_readwrite xlrw, struct kvmppc_pte *pte) 402 373 { 374 + bool data = (xlid == XLATE_DATA); 375 + bool iswrite = (xlrw == XLATE_WRITE); 403 376 int relocated = (kvmppc_get_msr(vcpu) & (data ? MSR_DR : MSR_IR)); 404 377 int r; 405 378 ··· 415 384 pte->may_write = true; 416 385 pte->may_execute = true; 417 386 r = 0; 387 + 388 + if ((kvmppc_get_msr(vcpu) & (MSR_IR | MSR_DR)) == MSR_DR && 389 + !data) { 390 + if ((vcpu->arch.hflags & BOOK3S_HFLAG_SPLIT_HACK) && 391 + ((eaddr & SPLIT_HACK_MASK) == SPLIT_HACK_OFFS)) 392 + pte->raddr &= ~SPLIT_HACK_MASK; 393 + } 418 394 } 419 395 420 396 return r; 421 397 } 422 398 423 - static hva_t kvmppc_bad_hva(void) 399 + int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, enum instruction_type type, 400 + u32 *inst) 424 401 { 425 - return PAGE_OFFSET; 402 + ulong pc = kvmppc_get_pc(vcpu); 403 + int r; 404 + 405 + if (type == INST_SC) 406 + pc -= 4; 407 + 408 + r = kvmppc_ld(vcpu, &pc, sizeof(u32), inst, false); 409 + if (r == EMULATE_DONE) 410 + return r; 411 + else 412 + return EMULATE_AGAIN; 426 413 } 427 - 428 - static hva_t kvmppc_pte_to_hva(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte, 429 - bool read) 430 - { 431 - hva_t hpage; 432 - 433 - if (read && !pte->may_read) 434 - goto err; 435 - 436 - if (!read && !pte->may_write) 437 - goto err; 438 - 439 - hpage = gfn_to_hva(vcpu->kvm, pte->raddr >> PAGE_SHIFT); 440 - if (kvm_is_error_hva(hpage)) 441 - goto err; 442 - 443 - return hpage | (pte->raddr & ~PAGE_MASK); 444 - err: 445 - return kvmppc_bad_hva(); 446 - } 447 - 448 - int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 449 - bool data) 450 - { 451 - struct kvmppc_pte pte; 452 - 453 - vcpu->stat.st++; 454 - 455 - if (kvmppc_xlate(vcpu, *eaddr, data, true, &pte)) 456 - return -ENOENT; 457 - 458 - *eaddr = pte.raddr; 459 - 460 - if (!pte.may_write) 461 - return -EPERM; 462 - 463 - if (kvm_write_guest(vcpu->kvm, pte.raddr, ptr, size)) 464 - return EMULATE_DO_MMIO; 465 - 466 - return EMULATE_DONE; 467 - } 468 - EXPORT_SYMBOL_GPL(kvmppc_st); 469 - 470 - int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 471 - bool data) 472 - { 473 - struct kvmppc_pte pte; 474 - hva_t hva = *eaddr; 475 - 476 - vcpu->stat.ld++; 477 - 478 - if (kvmppc_xlate(vcpu, *eaddr, data, false, &pte)) 479 - goto nopte; 480 - 481 - *eaddr = pte.raddr; 482 - 483 - hva = kvmppc_pte_to_hva(vcpu, &pte, true); 484 - if (kvm_is_error_hva(hva)) 485 - goto mmio; 486 - 487 - if (copy_from_user(ptr, (void __user *)hva, size)) { 488 - printk(KERN_INFO "kvmppc_ld at 0x%lx failed\n", hva); 489 - goto mmio; 490 - } 491 - 492 - return EMULATE_DONE; 493 - 494 - nopte: 495 - return -ENOENT; 496 - mmio: 497 - return EMULATE_DO_MMIO; 498 - } 499 - EXPORT_SYMBOL_GPL(kvmppc_ld); 414 + EXPORT_SYMBOL_GPL(kvmppc_load_last_inst); 500 415 501 416 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 502 417 { ··· 623 646 case KVM_REG_PPC_BESCR: 624 647 val = get_reg_val(reg->id, vcpu->arch.bescr); 625 648 break; 649 + case KVM_REG_PPC_VTB: 650 + val = get_reg_val(reg->id, vcpu->arch.vtb); 651 + break; 652 + case KVM_REG_PPC_IC: 653 + val = get_reg_val(reg->id, vcpu->arch.ic); 654 + break; 626 655 default: 627 656 r = -EINVAL; 628 657 break; ··· 732 749 break; 733 750 case KVM_REG_PPC_BESCR: 734 751 vcpu->arch.bescr = set_reg_val(reg->id, val); 752 + break; 753 + case KVM_REG_PPC_VTB: 754 + vcpu->arch.vtb = set_reg_val(reg->id, val); 755 + break; 756 + case KVM_REG_PPC_IC: 757 + vcpu->arch.ic = set_reg_val(reg->id, val); 735 758 break; 736 759 default: 737 760 r = -EINVAL; ··· 900 911 * or PR module 901 912 */ 902 913 return 0; 914 + } 915 + 916 + int kvmppc_book3s_hcall_implemented(struct kvm *kvm, unsigned long hcall) 917 + { 918 + return kvm->arch.kvm_ops->hcall_implemented(hcall); 903 919 } 904 920 905 921 static int kvmppc_book3s_init(void)
+1 -1
arch/powerpc/kvm/book3s_32_mmu.c
··· 335 335 if (r < 0) 336 336 r = kvmppc_mmu_book3s_32_xlate_pte(vcpu, eaddr, pte, 337 337 data, iswrite, true); 338 - if (r < 0) 338 + if (r == -ENOENT) 339 339 r = kvmppc_mmu_book3s_32_xlate_pte(vcpu, eaddr, pte, 340 340 data, iswrite, false); 341 341
+3 -4
arch/powerpc/kvm/book3s_32_mmu_host.c
··· 156 156 bool writable; 157 157 158 158 /* Get host physical address for gpa */ 159 - hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT, 160 - iswrite, &writable); 159 + hpaddr = kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable); 161 160 if (is_error_noslot_pfn(hpaddr)) { 162 - printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n", 163 - orig_pte->eaddr); 161 + printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n", 162 + orig_pte->raddr); 164 163 r = -EINVAL; 165 164 goto out; 166 165 }
+3 -2
arch/powerpc/kvm/book3s_64_mmu_host.c
··· 104 104 smp_rmb(); 105 105 106 106 /* Get host physical address for gpa */ 107 - pfn = kvmppc_gfn_to_pfn(vcpu, gfn, iswrite, &writable); 107 + pfn = kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable); 108 108 if (is_error_noslot_pfn(pfn)) { 109 - printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n", gfn); 109 + printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n", 110 + orig_pte->raddr); 110 111 r = -EINVAL; 111 112 goto out; 112 113 }
+72 -73
arch/powerpc/kvm/book3s_64_mmu_hv.c
··· 448 448 unsigned long slb_v; 449 449 unsigned long pp, key; 450 450 unsigned long v, gr; 451 - unsigned long *hptep; 451 + __be64 *hptep; 452 452 int index; 453 453 int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR); 454 454 ··· 471 471 preempt_enable(); 472 472 return -ENOENT; 473 473 } 474 - hptep = (unsigned long *)(kvm->arch.hpt_virt + (index << 4)); 475 - v = hptep[0] & ~HPTE_V_HVLOCK; 474 + hptep = (__be64 *)(kvm->arch.hpt_virt + (index << 4)); 475 + v = be64_to_cpu(hptep[0]) & ~HPTE_V_HVLOCK; 476 476 gr = kvm->arch.revmap[index].guest_rpte; 477 477 478 478 /* Unlock the HPTE */ 479 479 asm volatile("lwsync" : : : "memory"); 480 - hptep[0] = v; 480 + hptep[0] = cpu_to_be64(v); 481 481 preempt_enable(); 482 482 483 483 gpte->eaddr = eaddr; ··· 528 528 static int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu, 529 529 unsigned long gpa, gva_t ea, int is_store) 530 530 { 531 - int ret; 532 531 u32 last_inst; 533 - unsigned long srr0 = kvmppc_get_pc(vcpu); 534 532 535 - /* We try to load the last instruction. We don't let 536 - * emulate_instruction do it as it doesn't check what 537 - * kvmppc_ld returns. 533 + /* 538 534 * If we fail, we just return to the guest and try executing it again. 539 535 */ 540 - if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) { 541 - ret = kvmppc_ld(vcpu, &srr0, sizeof(u32), &last_inst, false); 542 - if (ret != EMULATE_DONE || last_inst == KVM_INST_FETCH_FAILED) 543 - return RESUME_GUEST; 544 - vcpu->arch.last_inst = last_inst; 545 - } 536 + if (kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) != 537 + EMULATE_DONE) 538 + return RESUME_GUEST; 546 539 547 540 /* 548 541 * WARNING: We do not know for sure whether the instruction we just ··· 549 556 * we just return and retry the instruction. 550 557 */ 551 558 552 - if (instruction_is_store(kvmppc_get_last_inst(vcpu)) != !!is_store) 559 + if (instruction_is_store(last_inst) != !!is_store) 553 560 return RESUME_GUEST; 554 561 555 562 /* ··· 574 581 unsigned long ea, unsigned long dsisr) 575 582 { 576 583 struct kvm *kvm = vcpu->kvm; 577 - unsigned long *hptep, hpte[3], r; 584 + unsigned long hpte[3], r; 585 + __be64 *hptep; 578 586 unsigned long mmu_seq, psize, pte_size; 579 587 unsigned long gpa_base, gfn_base; 580 588 unsigned long gpa, gfn, hva, pfn; ··· 598 604 if (ea != vcpu->arch.pgfault_addr) 599 605 return RESUME_GUEST; 600 606 index = vcpu->arch.pgfault_index; 601 - hptep = (unsigned long *)(kvm->arch.hpt_virt + (index << 4)); 607 + hptep = (__be64 *)(kvm->arch.hpt_virt + (index << 4)); 602 608 rev = &kvm->arch.revmap[index]; 603 609 preempt_disable(); 604 610 while (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) 605 611 cpu_relax(); 606 - hpte[0] = hptep[0] & ~HPTE_V_HVLOCK; 607 - hpte[1] = hptep[1]; 612 + hpte[0] = be64_to_cpu(hptep[0]) & ~HPTE_V_HVLOCK; 613 + hpte[1] = be64_to_cpu(hptep[1]); 608 614 hpte[2] = r = rev->guest_rpte; 609 615 asm volatile("lwsync" : : : "memory"); 610 - hptep[0] = hpte[0]; 616 + hptep[0] = cpu_to_be64(hpte[0]); 611 617 preempt_enable(); 612 618 613 619 if (hpte[0] != vcpu->arch.pgfault_hpte[0] || ··· 723 729 preempt_disable(); 724 730 while (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) 725 731 cpu_relax(); 726 - if ((hptep[0] & ~HPTE_V_HVLOCK) != hpte[0] || hptep[1] != hpte[1] || 727 - rev->guest_rpte != hpte[2]) 732 + if ((be64_to_cpu(hptep[0]) & ~HPTE_V_HVLOCK) != hpte[0] || 733 + be64_to_cpu(hptep[1]) != hpte[1] || 734 + rev->guest_rpte != hpte[2]) 728 735 /* HPTE has been changed under us; let the guest retry */ 729 736 goto out_unlock; 730 737 hpte[0] = (hpte[0] & ~HPTE_V_ABSENT) | HPTE_V_VALID; ··· 745 750 rcbits = *rmap >> KVMPPC_RMAP_RC_SHIFT; 746 751 r &= rcbits | ~(HPTE_R_R | HPTE_R_C); 747 752 748 - if (hptep[0] & HPTE_V_VALID) { 753 + if (be64_to_cpu(hptep[0]) & HPTE_V_VALID) { 749 754 /* HPTE was previously valid, so we need to invalidate it */ 750 755 unlock_rmap(rmap); 751 - hptep[0] |= HPTE_V_ABSENT; 756 + hptep[0] |= cpu_to_be64(HPTE_V_ABSENT); 752 757 kvmppc_invalidate_hpte(kvm, hptep, index); 753 758 /* don't lose previous R and C bits */ 754 - r |= hptep[1] & (HPTE_R_R | HPTE_R_C); 759 + r |= be64_to_cpu(hptep[1]) & (HPTE_R_R | HPTE_R_C); 755 760 } else { 756 761 kvmppc_add_revmap_chain(kvm, rev, rmap, index, 0); 757 762 } 758 763 759 - hptep[1] = r; 764 + hptep[1] = cpu_to_be64(r); 760 765 eieio(); 761 - hptep[0] = hpte[0]; 766 + hptep[0] = cpu_to_be64(hpte[0]); 762 767 asm volatile("ptesync" : : : "memory"); 763 768 preempt_enable(); 764 769 if (page && hpte_is_writable(r)) ··· 777 782 return ret; 778 783 779 784 out_unlock: 780 - hptep[0] &= ~HPTE_V_HVLOCK; 785 + hptep[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 781 786 preempt_enable(); 782 787 goto out_put; 783 788 } ··· 853 858 { 854 859 struct revmap_entry *rev = kvm->arch.revmap; 855 860 unsigned long h, i, j; 856 - unsigned long *hptep; 861 + __be64 *hptep; 857 862 unsigned long ptel, psize, rcbits; 858 863 859 864 for (;;) { ··· 869 874 * rmap chain lock. 870 875 */ 871 876 i = *rmapp & KVMPPC_RMAP_INDEX; 872 - hptep = (unsigned long *) (kvm->arch.hpt_virt + (i << 4)); 877 + hptep = (__be64 *) (kvm->arch.hpt_virt + (i << 4)); 873 878 if (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) { 874 879 /* unlock rmap before spinning on the HPTE lock */ 875 880 unlock_rmap(rmapp); 876 - while (hptep[0] & HPTE_V_HVLOCK) 881 + while (be64_to_cpu(hptep[0]) & HPTE_V_HVLOCK) 877 882 cpu_relax(); 878 883 continue; 879 884 } ··· 892 897 893 898 /* Now check and modify the HPTE */ 894 899 ptel = rev[i].guest_rpte; 895 - psize = hpte_page_size(hptep[0], ptel); 896 - if ((hptep[0] & HPTE_V_VALID) && 900 + psize = hpte_page_size(be64_to_cpu(hptep[0]), ptel); 901 + if ((be64_to_cpu(hptep[0]) & HPTE_V_VALID) && 897 902 hpte_rpn(ptel, psize) == gfn) { 898 903 if (kvm->arch.using_mmu_notifiers) 899 - hptep[0] |= HPTE_V_ABSENT; 904 + hptep[0] |= cpu_to_be64(HPTE_V_ABSENT); 900 905 kvmppc_invalidate_hpte(kvm, hptep, i); 901 906 /* Harvest R and C */ 902 - rcbits = hptep[1] & (HPTE_R_R | HPTE_R_C); 907 + rcbits = be64_to_cpu(hptep[1]) & (HPTE_R_R | HPTE_R_C); 903 908 *rmapp |= rcbits << KVMPPC_RMAP_RC_SHIFT; 904 909 if (rcbits & ~rev[i].guest_rpte) { 905 910 rev[i].guest_rpte = ptel | rcbits; ··· 907 912 } 908 913 } 909 914 unlock_rmap(rmapp); 910 - hptep[0] &= ~HPTE_V_HVLOCK; 915 + hptep[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 911 916 } 912 917 return 0; 913 918 } ··· 954 959 { 955 960 struct revmap_entry *rev = kvm->arch.revmap; 956 961 unsigned long head, i, j; 957 - unsigned long *hptep; 962 + __be64 *hptep; 958 963 int ret = 0; 959 964 960 965 retry: ··· 970 975 971 976 i = head = *rmapp & KVMPPC_RMAP_INDEX; 972 977 do { 973 - hptep = (unsigned long *) (kvm->arch.hpt_virt + (i << 4)); 978 + hptep = (__be64 *) (kvm->arch.hpt_virt + (i << 4)); 974 979 j = rev[i].forw; 975 980 976 981 /* If this HPTE isn't referenced, ignore it */ 977 - if (!(hptep[1] & HPTE_R_R)) 982 + if (!(be64_to_cpu(hptep[1]) & HPTE_R_R)) 978 983 continue; 979 984 980 985 if (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) { 981 986 /* unlock rmap before spinning on the HPTE lock */ 982 987 unlock_rmap(rmapp); 983 - while (hptep[0] & HPTE_V_HVLOCK) 988 + while (be64_to_cpu(hptep[0]) & HPTE_V_HVLOCK) 984 989 cpu_relax(); 985 990 goto retry; 986 991 } 987 992 988 993 /* Now check and modify the HPTE */ 989 - if ((hptep[0] & HPTE_V_VALID) && (hptep[1] & HPTE_R_R)) { 994 + if ((be64_to_cpu(hptep[0]) & HPTE_V_VALID) && 995 + (be64_to_cpu(hptep[1]) & HPTE_R_R)) { 990 996 kvmppc_clear_ref_hpte(kvm, hptep, i); 991 997 if (!(rev[i].guest_rpte & HPTE_R_R)) { 992 998 rev[i].guest_rpte |= HPTE_R_R; ··· 995 999 } 996 1000 ret = 1; 997 1001 } 998 - hptep[0] &= ~HPTE_V_HVLOCK; 1002 + hptep[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 999 1003 } while ((i = j) != head); 1000 1004 1001 1005 unlock_rmap(rmapp); ··· 1029 1033 do { 1030 1034 hp = (unsigned long *)(kvm->arch.hpt_virt + (i << 4)); 1031 1035 j = rev[i].forw; 1032 - if (hp[1] & HPTE_R_R) 1036 + if (be64_to_cpu(hp[1]) & HPTE_R_R) 1033 1037 goto out; 1034 1038 } while ((i = j) != head); 1035 1039 } ··· 1069 1073 unsigned long head, i, j; 1070 1074 unsigned long n; 1071 1075 unsigned long v, r; 1072 - unsigned long *hptep; 1076 + __be64 *hptep; 1073 1077 int npages_dirty = 0; 1074 1078 1075 1079 retry: ··· 1085 1089 1086 1090 i = head = *rmapp & KVMPPC_RMAP_INDEX; 1087 1091 do { 1088 - hptep = (unsigned long *) (kvm->arch.hpt_virt + (i << 4)); 1092 + unsigned long hptep1; 1093 + hptep = (__be64 *) (kvm->arch.hpt_virt + (i << 4)); 1089 1094 j = rev[i].forw; 1090 1095 1091 1096 /* ··· 1103 1106 * Otherwise we need to do the tlbie even if C==0 in 1104 1107 * order to pick up any delayed writeback of C. 1105 1108 */ 1106 - if (!(hptep[1] & HPTE_R_C) && 1107 - (!hpte_is_writable(hptep[1]) || vcpus_running(kvm))) 1109 + hptep1 = be64_to_cpu(hptep[1]); 1110 + if (!(hptep1 & HPTE_R_C) && 1111 + (!hpte_is_writable(hptep1) || vcpus_running(kvm))) 1108 1112 continue; 1109 1113 1110 1114 if (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) { 1111 1115 /* unlock rmap before spinning on the HPTE lock */ 1112 1116 unlock_rmap(rmapp); 1113 - while (hptep[0] & HPTE_V_HVLOCK) 1117 + while (hptep[0] & cpu_to_be64(HPTE_V_HVLOCK)) 1114 1118 cpu_relax(); 1115 1119 goto retry; 1116 1120 } 1117 1121 1118 1122 /* Now check and modify the HPTE */ 1119 - if (!(hptep[0] & HPTE_V_VALID)) 1123 + if (!(hptep[0] & cpu_to_be64(HPTE_V_VALID))) 1120 1124 continue; 1121 1125 1122 1126 /* need to make it temporarily absent so C is stable */ 1123 - hptep[0] |= HPTE_V_ABSENT; 1127 + hptep[0] |= cpu_to_be64(HPTE_V_ABSENT); 1124 1128 kvmppc_invalidate_hpte(kvm, hptep, i); 1125 - v = hptep[0]; 1126 - r = hptep[1]; 1129 + v = be64_to_cpu(hptep[0]); 1130 + r = be64_to_cpu(hptep[1]); 1127 1131 if (r & HPTE_R_C) { 1128 - hptep[1] = r & ~HPTE_R_C; 1132 + hptep[1] = cpu_to_be64(r & ~HPTE_R_C); 1129 1133 if (!(rev[i].guest_rpte & HPTE_R_C)) { 1130 1134 rev[i].guest_rpte |= HPTE_R_C; 1131 1135 note_hpte_modification(kvm, &rev[i]); ··· 1139 1141 } 1140 1142 v &= ~(HPTE_V_ABSENT | HPTE_V_HVLOCK); 1141 1143 v |= HPTE_V_VALID; 1142 - hptep[0] = v; 1144 + hptep[0] = cpu_to_be64(v); 1143 1145 } while ((i = j) != head); 1144 1146 1145 1147 unlock_rmap(rmapp); ··· 1303 1305 * Returns 1 if this HPT entry has been modified or has pending 1304 1306 * R/C bit changes. 1305 1307 */ 1306 - static int hpte_dirty(struct revmap_entry *revp, unsigned long *hptp) 1308 + static int hpte_dirty(struct revmap_entry *revp, __be64 *hptp) 1307 1309 { 1308 1310 unsigned long rcbits_unset; 1309 1311 ··· 1312 1314 1313 1315 /* Also need to consider changes in reference and changed bits */ 1314 1316 rcbits_unset = ~revp->guest_rpte & (HPTE_R_R | HPTE_R_C); 1315 - if ((hptp[0] & HPTE_V_VALID) && (hptp[1] & rcbits_unset)) 1317 + if ((be64_to_cpu(hptp[0]) & HPTE_V_VALID) && 1318 + (be64_to_cpu(hptp[1]) & rcbits_unset)) 1316 1319 return 1; 1317 1320 1318 1321 return 0; 1319 1322 } 1320 1323 1321 - static long record_hpte(unsigned long flags, unsigned long *hptp, 1324 + static long record_hpte(unsigned long flags, __be64 *hptp, 1322 1325 unsigned long *hpte, struct revmap_entry *revp, 1323 1326 int want_valid, int first_pass) 1324 1327 { ··· 1334 1335 return 0; 1335 1336 1336 1337 valid = 0; 1337 - if (hptp[0] & (HPTE_V_VALID | HPTE_V_ABSENT)) { 1338 + if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT)) { 1338 1339 valid = 1; 1339 1340 if ((flags & KVM_GET_HTAB_BOLTED_ONLY) && 1340 - !(hptp[0] & HPTE_V_BOLTED)) 1341 + !(be64_to_cpu(hptp[0]) & HPTE_V_BOLTED)) 1341 1342 valid = 0; 1342 1343 } 1343 1344 if (valid != want_valid) ··· 1349 1350 preempt_disable(); 1350 1351 while (!try_lock_hpte(hptp, HPTE_V_HVLOCK)) 1351 1352 cpu_relax(); 1352 - v = hptp[0]; 1353 + v = be64_to_cpu(hptp[0]); 1353 1354 1354 1355 /* re-evaluate valid and dirty from synchronized HPTE value */ 1355 1356 valid = !!(v & HPTE_V_VALID); ··· 1357 1358 1358 1359 /* Harvest R and C into guest view if necessary */ 1359 1360 rcbits_unset = ~revp->guest_rpte & (HPTE_R_R | HPTE_R_C); 1360 - if (valid && (rcbits_unset & hptp[1])) { 1361 - revp->guest_rpte |= (hptp[1] & (HPTE_R_R | HPTE_R_C)) | 1362 - HPTE_GR_MODIFIED; 1361 + if (valid && (rcbits_unset & be64_to_cpu(hptp[1]))) { 1362 + revp->guest_rpte |= (be64_to_cpu(hptp[1]) & 1363 + (HPTE_R_R | HPTE_R_C)) | HPTE_GR_MODIFIED; 1363 1364 dirty = 1; 1364 1365 } 1365 1366 ··· 1378 1379 revp->guest_rpte = r; 1379 1380 } 1380 1381 asm volatile(PPC_RELEASE_BARRIER "" : : : "memory"); 1381 - hptp[0] &= ~HPTE_V_HVLOCK; 1382 + hptp[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 1382 1383 preempt_enable(); 1383 1384 if (!(valid == want_valid && (first_pass || dirty))) 1384 1385 ok = 0; 1385 1386 } 1386 - hpte[0] = v; 1387 - hpte[1] = r; 1387 + hpte[0] = cpu_to_be64(v); 1388 + hpte[1] = cpu_to_be64(r); 1388 1389 return ok; 1389 1390 } 1390 1391 ··· 1394 1395 struct kvm_htab_ctx *ctx = file->private_data; 1395 1396 struct kvm *kvm = ctx->kvm; 1396 1397 struct kvm_get_htab_header hdr; 1397 - unsigned long *hptp; 1398 + __be64 *hptp; 1398 1399 struct revmap_entry *revp; 1399 1400 unsigned long i, nb, nw; 1400 1401 unsigned long __user *lbuf; ··· 1410 1411 flags = ctx->flags; 1411 1412 1412 1413 i = ctx->index; 1413 - hptp = (unsigned long *)(kvm->arch.hpt_virt + (i * HPTE_SIZE)); 1414 + hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE)); 1414 1415 revp = kvm->arch.revmap + i; 1415 1416 lbuf = (unsigned long __user *)buf; 1416 1417 ··· 1494 1495 unsigned long i, j; 1495 1496 unsigned long v, r; 1496 1497 unsigned long __user *lbuf; 1497 - unsigned long *hptp; 1498 + __be64 *hptp; 1498 1499 unsigned long tmp[2]; 1499 1500 ssize_t nb; 1500 1501 long int err, ret; ··· 1536 1537 i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) 1537 1538 break; 1538 1539 1539 - hptp = (unsigned long *)(kvm->arch.hpt_virt + (i * HPTE_SIZE)); 1540 + hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE)); 1540 1541 lbuf = (unsigned long __user *)buf; 1541 1542 for (j = 0; j < hdr.n_valid; ++j) { 1542 1543 err = -EFAULT; ··· 1548 1549 lbuf += 2; 1549 1550 nb += HPTE_SIZE; 1550 1551 1551 - if (hptp[0] & (HPTE_V_VALID | HPTE_V_ABSENT)) 1552 + if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT)) 1552 1553 kvmppc_do_h_remove(kvm, 0, i, 0, tmp); 1553 1554 err = -EIO; 1554 1555 ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r, ··· 1574 1575 } 1575 1576 1576 1577 for (j = 0; j < hdr.n_invalid; ++j) { 1577 - if (hptp[0] & (HPTE_V_VALID | HPTE_V_ABSENT)) 1578 + if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT)) 1578 1579 kvmppc_do_h_remove(kvm, 0, i, 0, tmp); 1579 1580 ++i; 1580 1581 hptp += 2;
+18 -12
arch/powerpc/kvm/book3s_emulate.c
··· 439 439 (mfmsr() & MSR_HV)) 440 440 vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; 441 441 break; 442 - case SPRN_PURR: 443 - to_book3s(vcpu)->purr_offset = spr_val - get_tb(); 444 - break; 445 - case SPRN_SPURR: 446 - to_book3s(vcpu)->spurr_offset = spr_val - get_tb(); 447 - break; 448 442 case SPRN_GQR0: 449 443 case SPRN_GQR1: 450 444 case SPRN_GQR2: ··· 449 455 case SPRN_GQR7: 450 456 to_book3s(vcpu)->gqr[sprn - SPRN_GQR0] = spr_val; 451 457 break; 452 - case SPRN_FSCR: 453 - vcpu->arch.fscr = spr_val; 454 - break; 455 458 #ifdef CONFIG_PPC_BOOK3S_64 459 + case SPRN_FSCR: 460 + kvmppc_set_fscr(vcpu, spr_val); 461 + break; 456 462 case SPRN_BESCR: 457 463 vcpu->arch.bescr = spr_val; 458 464 break; ··· 566 572 *spr_val = 0; 567 573 break; 568 574 case SPRN_PURR: 569 - *spr_val = get_tb() + to_book3s(vcpu)->purr_offset; 575 + /* 576 + * On exit we would have updated purr 577 + */ 578 + *spr_val = vcpu->arch.purr; 570 579 break; 571 580 case SPRN_SPURR: 572 - *spr_val = get_tb() + to_book3s(vcpu)->purr_offset; 581 + /* 582 + * On exit we would have updated spurr 583 + */ 584 + *spr_val = vcpu->arch.spurr; 585 + break; 586 + case SPRN_VTB: 587 + *spr_val = vcpu->arch.vtb; 588 + break; 589 + case SPRN_IC: 590 + *spr_val = vcpu->arch.ic; 573 591 break; 574 592 case SPRN_GQR0: 575 593 case SPRN_GQR1: ··· 593 587 case SPRN_GQR7: 594 588 *spr_val = to_book3s(vcpu)->gqr[sprn - SPRN_GQR0]; 595 589 break; 590 + #ifdef CONFIG_PPC_BOOK3S_64 596 591 case SPRN_FSCR: 597 592 *spr_val = vcpu->arch.fscr; 598 593 break; 599 - #ifdef CONFIG_PPC_BOOK3S_64 600 594 case SPRN_BESCR: 601 595 *spr_val = vcpu->arch.bescr; 602 596 break;
+228 -43
arch/powerpc/kvm/book3s_hv.c
··· 35 35 36 36 #include <asm/reg.h> 37 37 #include <asm/cputable.h> 38 + #include <asm/cache.h> 38 39 #include <asm/cacheflush.h> 39 40 #include <asm/tlbflush.h> 40 41 #include <asm/uaccess.h> ··· 67 66 68 67 /* Used as a "null" value for timebase values */ 69 68 #define TB_NIL (~(u64)0) 69 + 70 + static DECLARE_BITMAP(default_enabled_hcalls, MAX_HCALL_OPCODE/4 + 1); 71 + 72 + #if defined(CONFIG_PPC_64K_PAGES) 73 + #define MPP_BUFFER_ORDER 0 74 + #elif defined(CONFIG_PPC_4K_PAGES) 75 + #define MPP_BUFFER_ORDER 3 76 + #endif 77 + 70 78 71 79 static void kvmppc_end_cede(struct kvm_vcpu *vcpu); 72 80 static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); ··· 280 270 static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa) 281 271 { 282 272 vpa->__old_status |= LPPACA_OLD_SHARED_PROC; 283 - vpa->yield_count = 1; 273 + vpa->yield_count = cpu_to_be32(1); 284 274 } 285 275 286 276 static int set_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *v, ··· 303 293 struct reg_vpa { 304 294 u32 dummy; 305 295 union { 306 - u16 hword; 307 - u32 word; 296 + __be16 hword; 297 + __be32 word; 308 298 } length; 309 299 }; 310 300 ··· 343 333 if (va == NULL) 344 334 return H_PARAMETER; 345 335 if (subfunc == H_VPA_REG_VPA) 346 - len = ((struct reg_vpa *)va)->length.hword; 336 + len = be16_to_cpu(((struct reg_vpa *)va)->length.hword); 347 337 else 348 - len = ((struct reg_vpa *)va)->length.word; 338 + len = be32_to_cpu(((struct reg_vpa *)va)->length.word); 349 339 kvmppc_unpin_guest_page(kvm, va, vpa, false); 350 340 351 341 /* Check length */ ··· 550 540 return; 551 541 memset(dt, 0, sizeof(struct dtl_entry)); 552 542 dt->dispatch_reason = 7; 553 - dt->processor_id = vc->pcpu + vcpu->arch.ptid; 554 - dt->timebase = now + vc->tb_offset; 555 - dt->enqueue_to_dispatch_time = stolen; 556 - dt->srr0 = kvmppc_get_pc(vcpu); 557 - dt->srr1 = vcpu->arch.shregs.msr; 543 + dt->processor_id = cpu_to_be16(vc->pcpu + vcpu->arch.ptid); 544 + dt->timebase = cpu_to_be64(now + vc->tb_offset); 545 + dt->enqueue_to_dispatch_time = cpu_to_be32(stolen); 546 + dt->srr0 = cpu_to_be64(kvmppc_get_pc(vcpu)); 547 + dt->srr1 = cpu_to_be64(vcpu->arch.shregs.msr); 558 548 ++dt; 559 549 if (dt == vcpu->arch.dtl.pinned_end) 560 550 dt = vcpu->arch.dtl.pinned_addr; 561 551 vcpu->arch.dtl_ptr = dt; 562 552 /* order writing *dt vs. writing vpa->dtl_idx */ 563 553 smp_wmb(); 564 - vpa->dtl_idx = ++vcpu->arch.dtl_index; 554 + vpa->dtl_idx = cpu_to_be64(++vcpu->arch.dtl_index); 565 555 vcpu->arch.dtl.dirty = true; 556 + } 557 + 558 + static bool kvmppc_power8_compatible(struct kvm_vcpu *vcpu) 559 + { 560 + if (vcpu->arch.vcore->arch_compat >= PVR_ARCH_207) 561 + return true; 562 + if ((!vcpu->arch.vcore->arch_compat) && 563 + cpu_has_feature(CPU_FTR_ARCH_207S)) 564 + return true; 565 + return false; 566 + } 567 + 568 + static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags, 569 + unsigned long resource, unsigned long value1, 570 + unsigned long value2) 571 + { 572 + switch (resource) { 573 + case H_SET_MODE_RESOURCE_SET_CIABR: 574 + if (!kvmppc_power8_compatible(vcpu)) 575 + return H_P2; 576 + if (value2) 577 + return H_P4; 578 + if (mflags) 579 + return H_UNSUPPORTED_FLAG_START; 580 + /* Guests can't breakpoint the hypervisor */ 581 + if ((value1 & CIABR_PRIV) == CIABR_PRIV_HYPER) 582 + return H_P3; 583 + vcpu->arch.ciabr = value1; 584 + return H_SUCCESS; 585 + case H_SET_MODE_RESOURCE_SET_DAWR: 586 + if (!kvmppc_power8_compatible(vcpu)) 587 + return H_P2; 588 + if (mflags) 589 + return H_UNSUPPORTED_FLAG_START; 590 + if (value2 & DABRX_HYP) 591 + return H_P4; 592 + vcpu->arch.dawr = value1; 593 + vcpu->arch.dawrx = value2; 594 + return H_SUCCESS; 595 + default: 596 + return H_TOO_HARD; 597 + } 566 598 } 567 599 568 600 int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) ··· 613 561 unsigned long target, ret = H_SUCCESS; 614 562 struct kvm_vcpu *tvcpu; 615 563 int idx, rc; 564 + 565 + if (req <= MAX_HCALL_OPCODE && 566 + !test_bit(req/4, vcpu->kvm->arch.enabled_hcalls)) 567 + return RESUME_HOST; 616 568 617 569 switch (req) { 618 570 case H_ENTER: ··· 676 620 677 621 /* Send the error out to userspace via KVM_RUN */ 678 622 return rc; 679 - 623 + case H_SET_MODE: 624 + ret = kvmppc_h_set_mode(vcpu, kvmppc_get_gpr(vcpu, 4), 625 + kvmppc_get_gpr(vcpu, 5), 626 + kvmppc_get_gpr(vcpu, 6), 627 + kvmppc_get_gpr(vcpu, 7)); 628 + if (ret == H_TOO_HARD) 629 + return RESUME_HOST; 630 + break; 680 631 case H_XIRR: 681 632 case H_CPPR: 682 633 case H_EOI: ··· 700 637 kvmppc_set_gpr(vcpu, 3, ret); 701 638 vcpu->arch.hcall_needed = 0; 702 639 return RESUME_GUEST; 640 + } 641 + 642 + static int kvmppc_hcall_impl_hv(unsigned long cmd) 643 + { 644 + switch (cmd) { 645 + case H_CEDE: 646 + case H_PROD: 647 + case H_CONFER: 648 + case H_REGISTER_VPA: 649 + case H_SET_MODE: 650 + #ifdef CONFIG_KVM_XICS 651 + case H_XIRR: 652 + case H_CPPR: 653 + case H_EOI: 654 + case H_IPI: 655 + case H_IPOLL: 656 + case H_XIRR_X: 657 + #endif 658 + return 1; 659 + } 660 + 661 + /* See if it's in the real-mode table */ 662 + return kvmppc_hcall_impl_hv_realmode(cmd); 703 663 } 704 664 705 665 static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, ··· 871 785 return 0; 872 786 } 873 787 874 - static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr) 788 + static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr, 789 + bool preserve_top32) 875 790 { 876 791 struct kvmppc_vcore *vc = vcpu->arch.vcore; 877 792 u64 mask; ··· 907 820 mask = LPCR_DPFD | LPCR_ILE | LPCR_TC; 908 821 if (cpu_has_feature(CPU_FTR_ARCH_207S)) 909 822 mask |= LPCR_AIL; 823 + 824 + /* Broken 32-bit version of LPCR must not clear top bits */ 825 + if (preserve_top32) 826 + mask &= 0xFFFFFFFF; 910 827 vc->lpcr = (vc->lpcr & ~mask) | (new_lpcr & mask); 911 828 spin_unlock(&vc->lock); 912 829 } ··· 985 894 case KVM_REG_PPC_CIABR: 986 895 *val = get_reg_val(id, vcpu->arch.ciabr); 987 896 break; 988 - case KVM_REG_PPC_IC: 989 - *val = get_reg_val(id, vcpu->arch.ic); 990 - break; 991 - case KVM_REG_PPC_VTB: 992 - *val = get_reg_val(id, vcpu->arch.vtb); 993 - break; 994 897 case KVM_REG_PPC_CSIGR: 995 898 *val = get_reg_val(id, vcpu->arch.csigr); 996 899 break; ··· 1024 939 *val = get_reg_val(id, vcpu->arch.vcore->tb_offset); 1025 940 break; 1026 941 case KVM_REG_PPC_LPCR: 942 + case KVM_REG_PPC_LPCR_64: 1027 943 *val = get_reg_val(id, vcpu->arch.vcore->lpcr); 1028 944 break; 1029 945 case KVM_REG_PPC_PPR: ··· 1180 1094 if ((vcpu->arch.ciabr & CIABR_PRIV) == CIABR_PRIV_HYPER) 1181 1095 vcpu->arch.ciabr &= ~CIABR_PRIV; /* disable */ 1182 1096 break; 1183 - case KVM_REG_PPC_IC: 1184 - vcpu->arch.ic = set_reg_val(id, *val); 1185 - break; 1186 - case KVM_REG_PPC_VTB: 1187 - vcpu->arch.vtb = set_reg_val(id, *val); 1188 - break; 1189 1097 case KVM_REG_PPC_CSIGR: 1190 1098 vcpu->arch.csigr = set_reg_val(id, *val); 1191 1099 break; ··· 1230 1150 ALIGN(set_reg_val(id, *val), 1UL << 24); 1231 1151 break; 1232 1152 case KVM_REG_PPC_LPCR: 1233 - kvmppc_set_lpcr(vcpu, set_reg_val(id, *val)); 1153 + kvmppc_set_lpcr(vcpu, set_reg_val(id, *val), true); 1154 + break; 1155 + case KVM_REG_PPC_LPCR_64: 1156 + kvmppc_set_lpcr(vcpu, set_reg_val(id, *val), false); 1234 1157 break; 1235 1158 case KVM_REG_PPC_PPR: 1236 1159 vcpu->arch.ppr = set_reg_val(id, *val); ··· 1311 1228 return r; 1312 1229 } 1313 1230 1231 + static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core) 1232 + { 1233 + struct kvmppc_vcore *vcore; 1234 + 1235 + vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL); 1236 + 1237 + if (vcore == NULL) 1238 + return NULL; 1239 + 1240 + INIT_LIST_HEAD(&vcore->runnable_threads); 1241 + spin_lock_init(&vcore->lock); 1242 + init_waitqueue_head(&vcore->wq); 1243 + vcore->preempt_tb = TB_NIL; 1244 + vcore->lpcr = kvm->arch.lpcr; 1245 + vcore->first_vcpuid = core * threads_per_subcore; 1246 + vcore->kvm = kvm; 1247 + 1248 + vcore->mpp_buffer_is_valid = false; 1249 + 1250 + if (cpu_has_feature(CPU_FTR_ARCH_207S)) 1251 + vcore->mpp_buffer = (void *)__get_free_pages( 1252 + GFP_KERNEL|__GFP_ZERO, 1253 + MPP_BUFFER_ORDER); 1254 + 1255 + return vcore; 1256 + } 1257 + 1314 1258 static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm, 1315 1259 unsigned int id) 1316 1260 { ··· 1389 1279 mutex_lock(&kvm->lock); 1390 1280 vcore = kvm->arch.vcores[core]; 1391 1281 if (!vcore) { 1392 - vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL); 1393 - if (vcore) { 1394 - INIT_LIST_HEAD(&vcore->runnable_threads); 1395 - spin_lock_init(&vcore->lock); 1396 - init_waitqueue_head(&vcore->wq); 1397 - vcore->preempt_tb = TB_NIL; 1398 - vcore->lpcr = kvm->arch.lpcr; 1399 - vcore->first_vcpuid = core * threads_per_subcore; 1400 - vcore->kvm = kvm; 1401 - } 1282 + vcore = kvmppc_vcore_create(kvm, core); 1402 1283 kvm->arch.vcores[core] = vcore; 1403 1284 kvm->arch.online_vcores++; 1404 1285 } ··· 1601 1500 return 1; 1602 1501 } 1603 1502 1503 + static void kvmppc_start_saving_l2_cache(struct kvmppc_vcore *vc) 1504 + { 1505 + phys_addr_t phy_addr, mpp_addr; 1506 + 1507 + phy_addr = (phys_addr_t)virt_to_phys(vc->mpp_buffer); 1508 + mpp_addr = phy_addr & PPC_MPPE_ADDRESS_MASK; 1509 + 1510 + mtspr(SPRN_MPPR, mpp_addr | PPC_MPPR_FETCH_ABORT); 1511 + logmpp(mpp_addr | PPC_LOGMPP_LOG_L2); 1512 + 1513 + vc->mpp_buffer_is_valid = true; 1514 + } 1515 + 1516 + static void kvmppc_start_restoring_l2_cache(const struct kvmppc_vcore *vc) 1517 + { 1518 + phys_addr_t phy_addr, mpp_addr; 1519 + 1520 + phy_addr = virt_to_phys(vc->mpp_buffer); 1521 + mpp_addr = phy_addr & PPC_MPPE_ADDRESS_MASK; 1522 + 1523 + /* We must abort any in-progress save operations to ensure 1524 + * the table is valid so that prefetch engine knows when to 1525 + * stop prefetching. */ 1526 + logmpp(mpp_addr | PPC_LOGMPP_LOG_ABORT); 1527 + mtspr(SPRN_MPPR, mpp_addr | PPC_MPPR_FETCH_WHOLE_TABLE); 1528 + } 1529 + 1604 1530 /* 1605 1531 * Run a set of guest threads on a physical core. 1606 1532 * Called with vc->lock held. ··· 1705 1577 1706 1578 srcu_idx = srcu_read_lock(&vc->kvm->srcu); 1707 1579 1580 + if (vc->mpp_buffer_is_valid) 1581 + kvmppc_start_restoring_l2_cache(vc); 1582 + 1708 1583 __kvmppc_vcore_entry(); 1709 1584 1710 1585 spin_lock(&vc->lock); 1586 + 1587 + if (vc->mpp_buffer) 1588 + kvmppc_start_saving_l2_cache(vc); 1589 + 1711 1590 /* disable sending of IPIs on virtual external irqs */ 1712 1591 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) 1713 1592 vcpu->cpu = -1; ··· 2064 1929 (*sps)->page_shift = def->shift; 2065 1930 (*sps)->slb_enc = def->sllp; 2066 1931 (*sps)->enc[0].page_shift = def->shift; 2067 - /* 2068 - * Only return base page encoding. We don't want to return 2069 - * all the supporting pte_enc, because our H_ENTER doesn't 2070 - * support MPSS yet. Once they do, we can start passing all 2071 - * support pte_enc here 2072 - */ 2073 1932 (*sps)->enc[0].pte_enc = def->penc[linux_psize]; 2074 1933 /* 2075 1934 * Add 16MB MPSS support if host supports it ··· 2410 2281 */ 2411 2282 cpumask_setall(&kvm->arch.need_tlb_flush); 2412 2283 2284 + /* Start out with the default set of hcalls enabled */ 2285 + memcpy(kvm->arch.enabled_hcalls, default_enabled_hcalls, 2286 + sizeof(kvm->arch.enabled_hcalls)); 2287 + 2413 2288 kvm->arch.rma = NULL; 2414 2289 2415 2290 kvm->arch.host_sdr1 = mfspr(SPRN_SDR1); ··· 2456 2323 { 2457 2324 long int i; 2458 2325 2459 - for (i = 0; i < KVM_MAX_VCORES; ++i) 2326 + for (i = 0; i < KVM_MAX_VCORES; ++i) { 2327 + if (kvm->arch.vcores[i] && kvm->arch.vcores[i]->mpp_buffer) { 2328 + struct kvmppc_vcore *vc = kvm->arch.vcores[i]; 2329 + free_pages((unsigned long)vc->mpp_buffer, 2330 + MPP_BUFFER_ORDER); 2331 + } 2460 2332 kfree(kvm->arch.vcores[i]); 2333 + } 2461 2334 kvm->arch.online_vcores = 0; 2462 2335 } 2463 2336 ··· 2558 2419 return r; 2559 2420 } 2560 2421 2422 + /* 2423 + * List of hcall numbers to enable by default. 2424 + * For compatibility with old userspace, we enable by default 2425 + * all hcalls that were implemented before the hcall-enabling 2426 + * facility was added. Note this list should not include H_RTAS. 2427 + */ 2428 + static unsigned int default_hcall_list[] = { 2429 + H_REMOVE, 2430 + H_ENTER, 2431 + H_READ, 2432 + H_PROTECT, 2433 + H_BULK_REMOVE, 2434 + H_GET_TCE, 2435 + H_PUT_TCE, 2436 + H_SET_DABR, 2437 + H_SET_XDABR, 2438 + H_CEDE, 2439 + H_PROD, 2440 + H_CONFER, 2441 + H_REGISTER_VPA, 2442 + #ifdef CONFIG_KVM_XICS 2443 + H_EOI, 2444 + H_CPPR, 2445 + H_IPI, 2446 + H_IPOLL, 2447 + H_XIRR, 2448 + H_XIRR_X, 2449 + #endif 2450 + 0 2451 + }; 2452 + 2453 + static void init_default_hcalls(void) 2454 + { 2455 + int i; 2456 + unsigned int hcall; 2457 + 2458 + for (i = 0; default_hcall_list[i]; ++i) { 2459 + hcall = default_hcall_list[i]; 2460 + WARN_ON(!kvmppc_hcall_impl_hv(hcall)); 2461 + __set_bit(hcall / 4, default_enabled_hcalls); 2462 + } 2463 + } 2464 + 2561 2465 static struct kvmppc_ops kvm_ops_hv = { 2562 2466 .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, 2563 2467 .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, ··· 2633 2451 .emulate_mfspr = kvmppc_core_emulate_mfspr_hv, 2634 2452 .fast_vcpu_kick = kvmppc_fast_vcpu_kick_hv, 2635 2453 .arch_vm_ioctl = kvm_arch_vm_ioctl_hv, 2454 + .hcall_implemented = kvmppc_hcall_impl_hv, 2636 2455 }; 2637 2456 2638 2457 static int kvmppc_book3s_init_hv(void) ··· 2648 2465 2649 2466 kvm_ops_hv.owner = THIS_MODULE; 2650 2467 kvmppc_hv_ops = &kvm_ops_hv; 2468 + 2469 + init_default_hcalls(); 2651 2470 2652 2471 r = kvmppc_mmu_hv_init(); 2653 2472 return r;
+13
arch/powerpc/kvm/book3s_hv_builtin.c
··· 219 219 { 220 220 return atomic_read(&hv_vm_count) != 0; 221 221 } 222 + 223 + extern int hcall_real_table[], hcall_real_table_end[]; 224 + 225 + int kvmppc_hcall_impl_hv_realmode(unsigned long cmd) 226 + { 227 + cmd /= 4; 228 + if (cmd < hcall_real_table_end - hcall_real_table && 229 + hcall_real_table[cmd]) 230 + return 1; 231 + 232 + return 0; 233 + } 234 + EXPORT_SYMBOL_GPL(kvmppc_hcall_impl_hv_realmode);
+3 -3
arch/powerpc/kvm/book3s_hv_ras.c
··· 45 45 return; 46 46 47 47 /* Sanity check */ 48 - n = min_t(u32, slb->persistent, SLB_MIN_SIZE); 48 + n = min_t(u32, be32_to_cpu(slb->persistent), SLB_MIN_SIZE); 49 49 if ((void *) &slb->save_area[n] > vcpu->arch.slb_shadow.pinned_end) 50 50 return; 51 51 52 52 /* Load up the SLB from that */ 53 53 for (i = 0; i < n; ++i) { 54 - unsigned long rb = slb->save_area[i].esid; 55 - unsigned long rs = slb->save_area[i].vsid; 54 + unsigned long rb = be64_to_cpu(slb->save_area[i].esid); 55 + unsigned long rs = be64_to_cpu(slb->save_area[i].vsid); 56 56 57 57 rb = (rb & ~0xFFFul) | i; /* insert entry number */ 58 58 asm volatile("slbmte %0,%1" : : "r" (rs), "r" (rb));
+83 -63
arch/powerpc/kvm/book3s_hv_rm_mmu.c
··· 154 154 return kvmppc_read_update_linux_pte(ptep, writing, hugepage_shift); 155 155 } 156 156 157 - static inline void unlock_hpte(unsigned long *hpte, unsigned long hpte_v) 157 + static inline void unlock_hpte(__be64 *hpte, unsigned long hpte_v) 158 158 { 159 159 asm volatile(PPC_RELEASE_BARRIER "" : : : "memory"); 160 - hpte[0] = hpte_v; 160 + hpte[0] = cpu_to_be64(hpte_v); 161 161 } 162 162 163 163 long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags, ··· 166 166 { 167 167 unsigned long i, pa, gpa, gfn, psize; 168 168 unsigned long slot_fn, hva; 169 - unsigned long *hpte; 169 + __be64 *hpte; 170 170 struct revmap_entry *rev; 171 171 unsigned long g_ptel; 172 172 struct kvm_memory_slot *memslot; ··· 275 275 return H_PARAMETER; 276 276 if (likely((flags & H_EXACT) == 0)) { 277 277 pte_index &= ~7UL; 278 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (pte_index << 4)); 278 + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index << 4)); 279 279 for (i = 0; i < 8; ++i) { 280 - if ((*hpte & HPTE_V_VALID) == 0 && 280 + if ((be64_to_cpu(*hpte) & HPTE_V_VALID) == 0 && 281 281 try_lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID | 282 282 HPTE_V_ABSENT)) 283 283 break; ··· 292 292 */ 293 293 hpte -= 16; 294 294 for (i = 0; i < 8; ++i) { 295 + u64 pte; 295 296 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK)) 296 297 cpu_relax(); 297 - if (!(*hpte & (HPTE_V_VALID | HPTE_V_ABSENT))) 298 + pte = be64_to_cpu(*hpte); 299 + if (!(pte & (HPTE_V_VALID | HPTE_V_ABSENT))) 298 300 break; 299 - *hpte &= ~HPTE_V_HVLOCK; 301 + *hpte &= ~cpu_to_be64(HPTE_V_HVLOCK); 300 302 hpte += 2; 301 303 } 302 304 if (i == 8) ··· 306 304 } 307 305 pte_index += i; 308 306 } else { 309 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (pte_index << 4)); 307 + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index << 4)); 310 308 if (!try_lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID | 311 309 HPTE_V_ABSENT)) { 312 310 /* Lock the slot and check again */ 311 + u64 pte; 312 + 313 313 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK)) 314 314 cpu_relax(); 315 - if (*hpte & (HPTE_V_VALID | HPTE_V_ABSENT)) { 316 - *hpte &= ~HPTE_V_HVLOCK; 315 + pte = be64_to_cpu(*hpte); 316 + if (pte & (HPTE_V_VALID | HPTE_V_ABSENT)) { 317 + *hpte &= ~cpu_to_be64(HPTE_V_HVLOCK); 317 318 return H_PTEG_FULL; 318 319 } 319 320 } ··· 352 347 } 353 348 } 354 349 355 - hpte[1] = ptel; 350 + hpte[1] = cpu_to_be64(ptel); 356 351 357 352 /* Write the first HPTE dword, unlocking the HPTE and making it valid */ 358 353 eieio(); 359 - hpte[0] = pteh; 354 + hpte[0] = cpu_to_be64(pteh); 360 355 asm volatile("ptesync" : : : "memory"); 361 356 362 357 *pte_idx_ret = pte_index; ··· 473 468 unsigned long pte_index, unsigned long avpn, 474 469 unsigned long *hpret) 475 470 { 476 - unsigned long *hpte; 471 + __be64 *hpte; 477 472 unsigned long v, r, rb; 478 473 struct revmap_entry *rev; 474 + u64 pte; 479 475 480 476 if (pte_index >= kvm->arch.hpt_npte) 481 477 return H_PARAMETER; 482 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (pte_index << 4)); 478 + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index << 4)); 483 479 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK)) 484 480 cpu_relax(); 485 - if ((hpte[0] & (HPTE_V_ABSENT | HPTE_V_VALID)) == 0 || 486 - ((flags & H_AVPN) && (hpte[0] & ~0x7fUL) != avpn) || 487 - ((flags & H_ANDCOND) && (hpte[0] & avpn) != 0)) { 488 - hpte[0] &= ~HPTE_V_HVLOCK; 481 + pte = be64_to_cpu(hpte[0]); 482 + if ((pte & (HPTE_V_ABSENT | HPTE_V_VALID)) == 0 || 483 + ((flags & H_AVPN) && (pte & ~0x7fUL) != avpn) || 484 + ((flags & H_ANDCOND) && (pte & avpn) != 0)) { 485 + hpte[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 489 486 return H_NOT_FOUND; 490 487 } 491 488 492 489 rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]); 493 - v = hpte[0] & ~HPTE_V_HVLOCK; 490 + v = pte & ~HPTE_V_HVLOCK; 494 491 if (v & HPTE_V_VALID) { 495 - hpte[0] &= ~HPTE_V_VALID; 496 - rb = compute_tlbie_rb(v, hpte[1], pte_index); 492 + u64 pte1; 493 + 494 + pte1 = be64_to_cpu(hpte[1]); 495 + hpte[0] &= ~cpu_to_be64(HPTE_V_VALID); 496 + rb = compute_tlbie_rb(v, pte1, pte_index); 497 497 do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags), true); 498 498 /* Read PTE low word after tlbie to get final R/C values */ 499 - remove_revmap_chain(kvm, pte_index, rev, v, hpte[1]); 499 + remove_revmap_chain(kvm, pte_index, rev, v, pte1); 500 500 } 501 501 r = rev->guest_rpte & ~HPTE_GR_RESERVED; 502 502 note_hpte_modification(kvm, rev); ··· 524 514 { 525 515 struct kvm *kvm = vcpu->kvm; 526 516 unsigned long *args = &vcpu->arch.gpr[4]; 527 - unsigned long *hp, *hptes[4], tlbrb[4]; 517 + __be64 *hp, *hptes[4]; 518 + unsigned long tlbrb[4]; 528 519 long int i, j, k, n, found, indexes[4]; 529 520 unsigned long flags, req, pte_index, rcbits; 530 521 int global; 531 522 long int ret = H_SUCCESS; 532 523 struct revmap_entry *rev, *revs[4]; 524 + u64 hp0; 533 525 534 526 global = global_invalidates(kvm, 0); 535 527 for (i = 0; i < 4 && ret == H_SUCCESS; ) { ··· 554 542 ret = H_PARAMETER; 555 543 break; 556 544 } 557 - hp = (unsigned long *) 558 - (kvm->arch.hpt_virt + (pte_index << 4)); 545 + hp = (__be64 *) (kvm->arch.hpt_virt + (pte_index << 4)); 559 546 /* to avoid deadlock, don't spin except for first */ 560 547 if (!try_lock_hpte(hp, HPTE_V_HVLOCK)) { 561 548 if (n) ··· 563 552 cpu_relax(); 564 553 } 565 554 found = 0; 566 - if (hp[0] & (HPTE_V_ABSENT | HPTE_V_VALID)) { 555 + hp0 = be64_to_cpu(hp[0]); 556 + if (hp0 & (HPTE_V_ABSENT | HPTE_V_VALID)) { 567 557 switch (flags & 3) { 568 558 case 0: /* absolute */ 569 559 found = 1; 570 560 break; 571 561 case 1: /* andcond */ 572 - if (!(hp[0] & args[j + 1])) 562 + if (!(hp0 & args[j + 1])) 573 563 found = 1; 574 564 break; 575 565 case 2: /* AVPN */ 576 - if ((hp[0] & ~0x7fUL) == args[j + 1]) 566 + if ((hp0 & ~0x7fUL) == args[j + 1]) 577 567 found = 1; 578 568 break; 579 569 } 580 570 } 581 571 if (!found) { 582 - hp[0] &= ~HPTE_V_HVLOCK; 572 + hp[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 583 573 args[j] = ((0x90 | flags) << 56) + pte_index; 584 574 continue; 585 575 } ··· 589 577 rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]); 590 578 note_hpte_modification(kvm, rev); 591 579 592 - if (!(hp[0] & HPTE_V_VALID)) { 580 + if (!(hp0 & HPTE_V_VALID)) { 593 581 /* insert R and C bits from PTE */ 594 582 rcbits = rev->guest_rpte & (HPTE_R_R|HPTE_R_C); 595 583 args[j] |= rcbits << (56 - 5); ··· 597 585 continue; 598 586 } 599 587 600 - hp[0] &= ~HPTE_V_VALID; /* leave it locked */ 601 - tlbrb[n] = compute_tlbie_rb(hp[0], hp[1], pte_index); 588 + /* leave it locked */ 589 + hp[0] &= ~cpu_to_be64(HPTE_V_VALID); 590 + tlbrb[n] = compute_tlbie_rb(be64_to_cpu(hp[0]), 591 + be64_to_cpu(hp[1]), pte_index); 602 592 indexes[n] = j; 603 593 hptes[n] = hp; 604 594 revs[n] = rev; ··· 619 605 pte_index = args[j] & ((1ul << 56) - 1); 620 606 hp = hptes[k]; 621 607 rev = revs[k]; 622 - remove_revmap_chain(kvm, pte_index, rev, hp[0], hp[1]); 608 + remove_revmap_chain(kvm, pte_index, rev, 609 + be64_to_cpu(hp[0]), be64_to_cpu(hp[1])); 623 610 rcbits = rev->guest_rpte & (HPTE_R_R|HPTE_R_C); 624 611 args[j] |= rcbits << (56 - 5); 625 612 hp[0] = 0; ··· 635 620 unsigned long va) 636 621 { 637 622 struct kvm *kvm = vcpu->kvm; 638 - unsigned long *hpte; 623 + __be64 *hpte; 639 624 struct revmap_entry *rev; 640 625 unsigned long v, r, rb, mask, bits; 626 + u64 pte; 641 627 642 628 if (pte_index >= kvm->arch.hpt_npte) 643 629 return H_PARAMETER; 644 630 645 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (pte_index << 4)); 631 + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index << 4)); 646 632 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK)) 647 633 cpu_relax(); 648 - if ((hpte[0] & (HPTE_V_ABSENT | HPTE_V_VALID)) == 0 || 649 - ((flags & H_AVPN) && (hpte[0] & ~0x7fUL) != avpn)) { 650 - hpte[0] &= ~HPTE_V_HVLOCK; 634 + pte = be64_to_cpu(hpte[0]); 635 + if ((pte & (HPTE_V_ABSENT | HPTE_V_VALID)) == 0 || 636 + ((flags & H_AVPN) && (pte & ~0x7fUL) != avpn)) { 637 + hpte[0] &= ~cpu_to_be64(HPTE_V_HVLOCK); 651 638 return H_NOT_FOUND; 652 639 } 653 640 654 - v = hpte[0]; 641 + v = pte; 655 642 bits = (flags << 55) & HPTE_R_PP0; 656 643 bits |= (flags << 48) & HPTE_R_KEY_HI; 657 644 bits |= flags & (HPTE_R_PP | HPTE_R_N | HPTE_R_KEY_LO); ··· 667 650 rev->guest_rpte = r; 668 651 note_hpte_modification(kvm, rev); 669 652 } 670 - r = (hpte[1] & ~mask) | bits; 653 + r = (be64_to_cpu(hpte[1]) & ~mask) | bits; 671 654 672 655 /* Update HPTE */ 673 656 if (v & HPTE_V_VALID) { 674 657 rb = compute_tlbie_rb(v, r, pte_index); 675 - hpte[0] = v & ~HPTE_V_VALID; 658 + hpte[0] = cpu_to_be64(v & ~HPTE_V_VALID); 676 659 do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags), true); 677 660 /* 678 661 * If the host has this page as readonly but the guest ··· 698 681 } 699 682 } 700 683 } 701 - hpte[1] = r; 684 + hpte[1] = cpu_to_be64(r); 702 685 eieio(); 703 - hpte[0] = v & ~HPTE_V_HVLOCK; 686 + hpte[0] = cpu_to_be64(v & ~HPTE_V_HVLOCK); 704 687 asm volatile("ptesync" : : : "memory"); 705 688 return H_SUCCESS; 706 689 } ··· 709 692 unsigned long pte_index) 710 693 { 711 694 struct kvm *kvm = vcpu->kvm; 712 - unsigned long *hpte, v, r; 695 + __be64 *hpte; 696 + unsigned long v, r; 713 697 int i, n = 1; 714 698 struct revmap_entry *rev = NULL; 715 699 ··· 722 704 } 723 705 rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]); 724 706 for (i = 0; i < n; ++i, ++pte_index) { 725 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (pte_index << 4)); 726 - v = hpte[0] & ~HPTE_V_HVLOCK; 727 - r = hpte[1]; 707 + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index << 4)); 708 + v = be64_to_cpu(hpte[0]) & ~HPTE_V_HVLOCK; 709 + r = be64_to_cpu(hpte[1]); 728 710 if (v & HPTE_V_ABSENT) { 729 711 v &= ~HPTE_V_ABSENT; 730 712 v |= HPTE_V_VALID; ··· 739 721 return H_SUCCESS; 740 722 } 741 723 742 - void kvmppc_invalidate_hpte(struct kvm *kvm, unsigned long *hptep, 724 + void kvmppc_invalidate_hpte(struct kvm *kvm, __be64 *hptep, 743 725 unsigned long pte_index) 744 726 { 745 727 unsigned long rb; 746 728 747 - hptep[0] &= ~HPTE_V_VALID; 748 - rb = compute_tlbie_rb(hptep[0], hptep[1], pte_index); 729 + hptep[0] &= ~cpu_to_be64(HPTE_V_VALID); 730 + rb = compute_tlbie_rb(be64_to_cpu(hptep[0]), be64_to_cpu(hptep[1]), 731 + pte_index); 749 732 do_tlbies(kvm, &rb, 1, 1, true); 750 733 } 751 734 EXPORT_SYMBOL_GPL(kvmppc_invalidate_hpte); 752 735 753 - void kvmppc_clear_ref_hpte(struct kvm *kvm, unsigned long *hptep, 736 + void kvmppc_clear_ref_hpte(struct kvm *kvm, __be64 *hptep, 754 737 unsigned long pte_index) 755 738 { 756 739 unsigned long rb; 757 740 unsigned char rbyte; 758 741 759 - rb = compute_tlbie_rb(hptep[0], hptep[1], pte_index); 760 - rbyte = (hptep[1] & ~HPTE_R_R) >> 8; 742 + rb = compute_tlbie_rb(be64_to_cpu(hptep[0]), be64_to_cpu(hptep[1]), 743 + pte_index); 744 + rbyte = (be64_to_cpu(hptep[1]) & ~HPTE_R_R) >> 8; 761 745 /* modify only the second-last byte, which contains the ref bit */ 762 746 *((char *)hptep + 14) = rbyte; 763 747 do_tlbies(kvm, &rb, 1, 1, false); ··· 785 765 unsigned long somask; 786 766 unsigned long vsid, hash; 787 767 unsigned long avpn; 788 - unsigned long *hpte; 768 + __be64 *hpte; 789 769 unsigned long mask, val; 790 770 unsigned long v, r; 791 771 ··· 817 797 val |= avpn; 818 798 819 799 for (;;) { 820 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (hash << 7)); 800 + hpte = (__be64 *)(kvm->arch.hpt_virt + (hash << 7)); 821 801 822 802 for (i = 0; i < 16; i += 2) { 823 803 /* Read the PTE racily */ 824 - v = hpte[i] & ~HPTE_V_HVLOCK; 804 + v = be64_to_cpu(hpte[i]) & ~HPTE_V_HVLOCK; 825 805 826 806 /* Check valid/absent, hash, segment size and AVPN */ 827 807 if (!(v & valid) || (v & mask) != val) ··· 830 810 /* Lock the PTE and read it under the lock */ 831 811 while (!try_lock_hpte(&hpte[i], HPTE_V_HVLOCK)) 832 812 cpu_relax(); 833 - v = hpte[i] & ~HPTE_V_HVLOCK; 834 - r = hpte[i+1]; 813 + v = be64_to_cpu(hpte[i]) & ~HPTE_V_HVLOCK; 814 + r = be64_to_cpu(hpte[i+1]); 835 815 836 816 /* 837 817 * Check the HPTE again, including base page size ··· 842 822 return (hash << 3) + (i >> 1); 843 823 844 824 /* Unlock and move on */ 845 - hpte[i] = v; 825 + hpte[i] = cpu_to_be64(v); 846 826 } 847 827 848 828 if (val & HPTE_V_SECONDARY) ··· 871 851 struct kvm *kvm = vcpu->kvm; 872 852 long int index; 873 853 unsigned long v, r, gr; 874 - unsigned long *hpte; 854 + __be64 *hpte; 875 855 unsigned long valid; 876 856 struct revmap_entry *rev; 877 857 unsigned long pp, key; ··· 887 867 return status; /* there really was no HPTE */ 888 868 return 0; /* for prot fault, HPTE disappeared */ 889 869 } 890 - hpte = (unsigned long *)(kvm->arch.hpt_virt + (index << 4)); 891 - v = hpte[0] & ~HPTE_V_HVLOCK; 892 - r = hpte[1]; 870 + hpte = (__be64 *)(kvm->arch.hpt_virt + (index << 4)); 871 + v = be64_to_cpu(hpte[0]) & ~HPTE_V_HVLOCK; 872 + r = be64_to_cpu(hpte[1]); 893 873 rev = real_vmalloc_addr(&kvm->arch.revmap[index]); 894 874 gr = rev->guest_rpte; 895 875
+5
arch/powerpc/kvm/book3s_hv_rm_xics.c
··· 401 401 icp->rm_action |= XICS_RM_REJECT; 402 402 icp->rm_reject = irq; 403 403 } 404 + 405 + if (!hlist_empty(&vcpu->kvm->irq_ack_notifier_list)) { 406 + icp->rm_action |= XICS_RM_NOTIFY_EOI; 407 + icp->rm_eoied_irq = irq; 408 + } 404 409 bail: 405 410 return check_too_hard(xics, icp); 406 411 }
+46 -24
arch/powerpc/kvm/book3s_hv_rmhandlers.S
··· 32 32 33 33 #define VCPU_GPRS_TM(reg) (((reg) * ULONG_SIZE) + VCPU_GPR_TM) 34 34 35 - #ifdef __LITTLE_ENDIAN__ 36 - #error Need to fix lppaca and SLB shadow accesses in little endian mode 37 - #endif 38 - 39 35 /* Values in HSTATE_NAPPING(r13) */ 40 36 #define NAPPING_CEDE 1 41 37 #define NAPPING_NOVCPU 2 ··· 597 601 ld r3, VCPU_VPA(r4) 598 602 cmpdi r3, 0 599 603 beq 25f 600 - lwz r5, LPPACA_YIELDCOUNT(r3) 604 + li r6, LPPACA_YIELDCOUNT 605 + LWZX_BE r5, r3, r6 601 606 addi r5, r5, 1 602 - stw r5, LPPACA_YIELDCOUNT(r3) 607 + STWX_BE r5, r3, r6 603 608 li r6, 1 604 609 stb r6, VCPU_VPA_DIRTY(r4) 605 610 25: ··· 674 677 675 678 mr r31, r4 676 679 addi r3, r31, VCPU_FPRS_TM 677 - bl .load_fp_state 680 + bl load_fp_state 678 681 addi r3, r31, VCPU_VRS_TM 679 - bl .load_vr_state 682 + bl load_vr_state 680 683 mr r4, r31 681 684 lwz r7, VCPU_VRSAVE_TM(r4) 682 685 mtspr SPRN_VRSAVE, r7 ··· 1420 1423 1421 1424 /* Save FP/VSX. */ 1422 1425 addi r3, r9, VCPU_FPRS_TM 1423 - bl .store_fp_state 1426 + bl store_fp_state 1424 1427 addi r3, r9, VCPU_VRS_TM 1425 - bl .store_vr_state 1428 + bl store_vr_state 1426 1429 mfspr r6, SPRN_VRSAVE 1427 1430 stw r6, VCPU_VRSAVE_TM(r9) 1428 1431 1: ··· 1445 1448 ld r8, VCPU_VPA(r9) /* do they have a VPA? */ 1446 1449 cmpdi r8, 0 1447 1450 beq 25f 1448 - lwz r3, LPPACA_YIELDCOUNT(r8) 1451 + li r4, LPPACA_YIELDCOUNT 1452 + LWZX_BE r3, r8, r4 1449 1453 addi r3, r3, 1 1450 - stw r3, LPPACA_YIELDCOUNT(r8) 1454 + STWX_BE r3, r8, r4 1451 1455 li r3, 1 1452 1456 stb r3, VCPU_VPA_DIRTY(r9) 1453 1457 25: ··· 1761 1763 33: ld r8,PACA_SLBSHADOWPTR(r13) 1762 1764 1763 1765 .rept SLB_NUM_BOLTED 1764 - ld r5,SLBSHADOW_SAVEAREA(r8) 1765 - ld r6,SLBSHADOW_SAVEAREA+8(r8) 1766 + li r3, SLBSHADOW_SAVEAREA 1767 + LDX_BE r5, r8, r3 1768 + addi r3, r3, 8 1769 + LDX_BE r6, r8, r3 1766 1770 andis. r7,r5,SLB_ESID_V@h 1767 1771 beq 1f 1768 1772 slbmte r6,r5 ··· 1915 1915 clrrdi r3,r3,2 1916 1916 cmpldi r3,hcall_real_table_end - hcall_real_table 1917 1917 bge guest_exit_cont 1918 + /* See if this hcall is enabled for in-kernel handling */ 1919 + ld r4, VCPU_KVM(r9) 1920 + srdi r0, r3, 8 /* r0 = (r3 / 4) >> 6 */ 1921 + sldi r0, r0, 3 /* index into kvm->arch.enabled_hcalls[] */ 1922 + add r4, r4, r0 1923 + ld r0, KVM_ENABLED_HCALLS(r4) 1924 + rlwinm r4, r3, 32-2, 0x3f /* r4 = (r3 / 4) & 0x3f */ 1925 + srd r0, r0, r4 1926 + andi. r0, r0, 1 1927 + beq guest_exit_cont 1928 + /* Get pointer to handler, if any, and call it */ 1918 1929 LOAD_REG_ADDR(r4, hcall_real_table) 1919 1930 lwax r3,r3,r4 1920 1931 cmpwi r3,0 1921 1932 beq guest_exit_cont 1922 - add r3,r3,r4 1923 - mtctr r3 1933 + add r12,r3,r4 1934 + mtctr r12 1924 1935 mr r3,r9 /* get vcpu pointer */ 1925 1936 ld r4,VCPU_GPR(R4)(r9) 1926 1937 bctrl ··· 2048 2037 .long 0 /* 0x12c */ 2049 2038 .long 0 /* 0x130 */ 2050 2039 .long DOTSYM(kvmppc_h_set_xdabr) - hcall_real_table 2040 + .globl hcall_real_table_end 2051 2041 hcall_real_table_end: 2052 2042 2053 2043 ignore_hdec: ··· 2356 2344 cmpdi r6, 0 2357 2345 beq- 1f 2358 2346 lwzcix r0, r6, r7 2359 - rlwinm. r3, r0, 0, 0xffffff 2347 + /* 2348 + * Save XIRR for later. Since we get in in reverse endian on LE 2349 + * systems, save it byte reversed and fetch it back in host endian. 2350 + */ 2351 + li r3, HSTATE_SAVED_XIRR 2352 + STWX_BE r0, r3, r13 2353 + #ifdef __LITTLE_ENDIAN__ 2354 + lwz r3, HSTATE_SAVED_XIRR(r13) 2355 + #else 2356 + mr r3, r0 2357 + #endif 2358 + rlwinm. r3, r3, 0, 0xffffff 2360 2359 sync 2361 2360 beq 1f /* if nothing pending in the ICP */ 2362 2361 ··· 2399 2376 li r3, -1 2400 2377 1: blr 2401 2378 2402 - 42: /* It's not an IPI and it's for the host, stash it in the PACA 2403 - * before exit, it will be picked up by the host ICP driver 2379 + 42: /* It's not an IPI and it's for the host. We saved a copy of XIRR in 2380 + * the PACA earlier, it will be picked up by the host ICP driver 2404 2381 */ 2405 - stw r0, HSTATE_SAVED_XIRR(r13) 2406 2382 li r3, 1 2407 2383 b 1b 2408 2384 ··· 2436 2414 mtmsrd r8 2437 2415 isync 2438 2416 addi r3,r3,VCPU_FPRS 2439 - bl .store_fp_state 2417 + bl store_fp_state 2440 2418 #ifdef CONFIG_ALTIVEC 2441 2419 BEGIN_FTR_SECTION 2442 2420 addi r3,r31,VCPU_VRS 2443 - bl .store_vr_state 2421 + bl store_vr_state 2444 2422 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 2445 2423 #endif 2446 2424 mfspr r6,SPRN_VRSAVE ··· 2472 2450 mtmsrd r8 2473 2451 isync 2474 2452 addi r3,r4,VCPU_FPRS 2475 - bl .load_fp_state 2453 + bl load_fp_state 2476 2454 #ifdef CONFIG_ALTIVEC 2477 2455 BEGIN_FTR_SECTION 2478 2456 addi r3,r31,VCPU_VRS 2479 - bl .load_vr_state 2457 + bl load_vr_state 2480 2458 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 2481 2459 #endif 2482 2460 lwz r7,VCPU_VRSAVE(r31)
+24 -14
arch/powerpc/kvm/book3s_paired_singles.c
··· 639 639 640 640 int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu) 641 641 { 642 - u32 inst = kvmppc_get_last_inst(vcpu); 642 + u32 inst; 643 643 enum emulation_result emulated = EMULATE_DONE; 644 + int ax_rd, ax_ra, ax_rb, ax_rc; 645 + short full_d; 646 + u64 *fpr_d, *fpr_a, *fpr_b, *fpr_c; 644 647 645 - int ax_rd = inst_get_field(inst, 6, 10); 646 - int ax_ra = inst_get_field(inst, 11, 15); 647 - int ax_rb = inst_get_field(inst, 16, 20); 648 - int ax_rc = inst_get_field(inst, 21, 25); 649 - short full_d = inst_get_field(inst, 16, 31); 650 - 651 - u64 *fpr_d = &VCPU_FPR(vcpu, ax_rd); 652 - u64 *fpr_a = &VCPU_FPR(vcpu, ax_ra); 653 - u64 *fpr_b = &VCPU_FPR(vcpu, ax_rb); 654 - u64 *fpr_c = &VCPU_FPR(vcpu, ax_rc); 655 - 656 - bool rcomp = (inst & 1) ? true : false; 657 - u32 cr = kvmppc_get_cr(vcpu); 648 + bool rcomp; 649 + u32 cr; 658 650 #ifdef DEBUG 659 651 int i; 660 652 #endif 653 + 654 + emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, &inst); 655 + if (emulated != EMULATE_DONE) 656 + return emulated; 657 + 658 + ax_rd = inst_get_field(inst, 6, 10); 659 + ax_ra = inst_get_field(inst, 11, 15); 660 + ax_rb = inst_get_field(inst, 16, 20); 661 + ax_rc = inst_get_field(inst, 21, 25); 662 + full_d = inst_get_field(inst, 16, 31); 663 + 664 + fpr_d = &VCPU_FPR(vcpu, ax_rd); 665 + fpr_a = &VCPU_FPR(vcpu, ax_ra); 666 + fpr_b = &VCPU_FPR(vcpu, ax_rb); 667 + fpr_c = &VCPU_FPR(vcpu, ax_rc); 668 + 669 + rcomp = (inst & 1) ? true : false; 670 + cr = kvmppc_get_cr(vcpu); 661 671 662 672 if (!kvmppc_inst_is_paired_single(vcpu, inst)) 663 673 return EMULATE_FAIL;
+164 -65
arch/powerpc/kvm/book3s_pr.c
··· 62 62 #define HW_PAGE_SIZE PAGE_SIZE 63 63 #endif 64 64 65 + static bool kvmppc_is_split_real(struct kvm_vcpu *vcpu) 66 + { 67 + ulong msr = kvmppc_get_msr(vcpu); 68 + return (msr & (MSR_IR|MSR_DR)) == MSR_DR; 69 + } 70 + 71 + static void kvmppc_fixup_split_real(struct kvm_vcpu *vcpu) 72 + { 73 + ulong msr = kvmppc_get_msr(vcpu); 74 + ulong pc = kvmppc_get_pc(vcpu); 75 + 76 + /* We are in DR only split real mode */ 77 + if ((msr & (MSR_IR|MSR_DR)) != MSR_DR) 78 + return; 79 + 80 + /* We have not fixed up the guest already */ 81 + if (vcpu->arch.hflags & BOOK3S_HFLAG_SPLIT_HACK) 82 + return; 83 + 84 + /* The code is in fixupable address space */ 85 + if (pc & SPLIT_HACK_MASK) 86 + return; 87 + 88 + vcpu->arch.hflags |= BOOK3S_HFLAG_SPLIT_HACK; 89 + kvmppc_set_pc(vcpu, pc | SPLIT_HACK_OFFS); 90 + } 91 + 92 + void kvmppc_unfixup_split_real(struct kvm_vcpu *vcpu); 93 + 65 94 static void kvmppc_core_vcpu_load_pr(struct kvm_vcpu *vcpu, int cpu) 66 95 { 67 96 #ifdef CONFIG_PPC_BOOK3S_64 ··· 100 71 svcpu->in_use = 0; 101 72 svcpu_put(svcpu); 102 73 #endif 74 + 75 + /* Disable AIL if supported */ 76 + if (cpu_has_feature(CPU_FTR_HVMODE) && 77 + cpu_has_feature(CPU_FTR_ARCH_207S)) 78 + mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) & ~LPCR_AIL); 79 + 103 80 vcpu->cpu = smp_processor_id(); 104 81 #ifdef CONFIG_PPC_BOOK3S_32 105 82 current->thread.kvm_shadow_vcpu = vcpu->arch.shadow_vcpu; 106 83 #endif 84 + 85 + if (kvmppc_is_split_real(vcpu)) 86 + kvmppc_fixup_split_real(vcpu); 107 87 } 108 88 109 89 static void kvmppc_core_vcpu_put_pr(struct kvm_vcpu *vcpu) ··· 127 89 svcpu_put(svcpu); 128 90 #endif 129 91 92 + if (kvmppc_is_split_real(vcpu)) 93 + kvmppc_unfixup_split_real(vcpu); 94 + 130 95 kvmppc_giveup_ext(vcpu, MSR_FP | MSR_VEC | MSR_VSX); 131 96 kvmppc_giveup_fac(vcpu, FSCR_TAR_LG); 97 + 98 + /* Enable AIL if supported */ 99 + if (cpu_has_feature(CPU_FTR_HVMODE) && 100 + cpu_has_feature(CPU_FTR_ARCH_207S)) 101 + mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) | LPCR_AIL_3); 102 + 132 103 vcpu->cpu = -1; 133 104 } 134 105 ··· 167 120 #ifdef CONFIG_PPC_BOOK3S_64 168 121 svcpu->shadow_fscr = vcpu->arch.shadow_fscr; 169 122 #endif 123 + /* 124 + * Now also save the current time base value. We use this 125 + * to find the guest purr and spurr value. 126 + */ 127 + vcpu->arch.entry_tb = get_tb(); 128 + vcpu->arch.entry_vtb = get_vtb(); 129 + if (cpu_has_feature(CPU_FTR_ARCH_207S)) 130 + vcpu->arch.entry_ic = mfspr(SPRN_IC); 170 131 svcpu->in_use = true; 171 132 } 172 133 ··· 221 166 #ifdef CONFIG_PPC_BOOK3S_64 222 167 vcpu->arch.shadow_fscr = svcpu->shadow_fscr; 223 168 #endif 169 + /* 170 + * Update purr and spurr using time base on exit. 171 + */ 172 + vcpu->arch.purr += get_tb() - vcpu->arch.entry_tb; 173 + vcpu->arch.spurr += get_tb() - vcpu->arch.entry_tb; 174 + vcpu->arch.vtb += get_vtb() - vcpu->arch.entry_vtb; 175 + if (cpu_has_feature(CPU_FTR_ARCH_207S)) 176 + vcpu->arch.ic += mfspr(SPRN_IC) - vcpu->arch.entry_ic; 224 177 svcpu->in_use = false; 225 178 226 179 out: ··· 356 293 kvmppc_set_msr_fast(vcpu, msr); 357 294 } 358 295 } 296 + 297 + if (kvmppc_is_split_real(vcpu)) 298 + kvmppc_fixup_split_real(vcpu); 299 + else 300 + kvmppc_unfixup_split_real(vcpu); 359 301 360 302 if ((kvmppc_get_msr(vcpu) & (MSR_PR|MSR_IR|MSR_DR)) != 361 303 (old_msr & (MSR_PR|MSR_IR|MSR_DR))) { ··· 511 443 put_page(hpage); 512 444 } 513 445 514 - static int kvmppc_visible_gfn(struct kvm_vcpu *vcpu, gfn_t gfn) 446 + static int kvmppc_visible_gpa(struct kvm_vcpu *vcpu, gpa_t gpa) 515 447 { 516 448 ulong mp_pa = vcpu->arch.magic_page_pa; 517 449 518 450 if (!(kvmppc_get_msr(vcpu) & MSR_SF)) 519 451 mp_pa = (uint32_t)mp_pa; 520 452 521 - if (unlikely(mp_pa) && 522 - unlikely((mp_pa & KVM_PAM) >> PAGE_SHIFT == gfn)) { 453 + gpa &= ~0xFFFULL; 454 + if (unlikely(mp_pa) && unlikely((mp_pa & KVM_PAM) == (gpa & KVM_PAM))) { 523 455 return 1; 524 456 } 525 457 526 - return kvm_is_visible_gfn(vcpu->kvm, gfn); 458 + return kvm_is_visible_gfn(vcpu->kvm, gpa >> PAGE_SHIFT); 527 459 } 528 460 529 461 int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu, ··· 562 494 pte.vpage |= ((u64)VSID_REAL << (SID_SHIFT - 12)); 563 495 break; 564 496 case MSR_DR: 497 + if (!data && 498 + (vcpu->arch.hflags & BOOK3S_HFLAG_SPLIT_HACK) && 499 + ((pte.raddr & SPLIT_HACK_MASK) == SPLIT_HACK_OFFS)) 500 + pte.raddr &= ~SPLIT_HACK_MASK; 501 + /* fall through */ 565 502 case MSR_IR: 566 503 vcpu->arch.mmu.esid_to_vsid(vcpu, eaddr >> SID_SHIFT, &vsid); 567 504 ··· 614 541 kvmppc_set_dar(vcpu, kvmppc_get_fault_dar(vcpu)); 615 542 kvmppc_book3s_queue_irqprio(vcpu, vec + 0x80); 616 543 } else if (!is_mmio && 617 - kvmppc_visible_gfn(vcpu, pte.raddr >> PAGE_SHIFT)) { 544 + kvmppc_visible_gpa(vcpu, pte.raddr)) { 618 545 if (data && !(vcpu->arch.fault_dsisr & DSISR_NOHPTE)) { 619 546 /* 620 547 * There is already a host HPTE there, presumably ··· 708 635 break; 709 636 } 710 637 #endif 711 - } 712 - 713 - static int kvmppc_read_inst(struct kvm_vcpu *vcpu) 714 - { 715 - ulong srr0 = kvmppc_get_pc(vcpu); 716 - u32 last_inst = kvmppc_get_last_inst(vcpu); 717 - int ret; 718 - 719 - ret = kvmppc_ld(vcpu, &srr0, sizeof(u32), &last_inst, false); 720 - if (ret == -ENOENT) { 721 - ulong msr = kvmppc_get_msr(vcpu); 722 - 723 - msr = kvmppc_set_field(msr, 33, 33, 1); 724 - msr = kvmppc_set_field(msr, 34, 36, 0); 725 - msr = kvmppc_set_field(msr, 42, 47, 0); 726 - kvmppc_set_msr_fast(vcpu, msr); 727 - kvmppc_book3s_queue_irqprio(vcpu, BOOK3S_INTERRUPT_INST_STORAGE); 728 - return EMULATE_AGAIN; 729 - } 730 - 731 - return EMULATE_DONE; 732 - } 733 - 734 - static int kvmppc_check_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr) 735 - { 736 - 737 - /* Need to do paired single emulation? */ 738 - if (!(vcpu->arch.hflags & BOOK3S_HFLAG_PAIRED_SINGLE)) 739 - return EMULATE_DONE; 740 - 741 - /* Read out the instruction */ 742 - if (kvmppc_read_inst(vcpu) == EMULATE_DONE) 743 - /* Need to emulate */ 744 - return EMULATE_FAIL; 745 - 746 - return EMULATE_AGAIN; 747 638 } 748 639 749 640 /* Handle external providers (FPU, Altivec, VSX) */ ··· 871 834 872 835 return RESUME_GUEST; 873 836 } 837 + 838 + void kvmppc_set_fscr(struct kvm_vcpu *vcpu, u64 fscr) 839 + { 840 + if ((vcpu->arch.fscr & FSCR_TAR) && !(fscr & FSCR_TAR)) { 841 + /* TAR got dropped, drop it in shadow too */ 842 + kvmppc_giveup_fac(vcpu, FSCR_TAR_LG); 843 + } 844 + vcpu->arch.fscr = fscr; 845 + } 874 846 #endif 875 847 876 848 int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, ··· 903 857 { 904 858 ulong shadow_srr1 = vcpu->arch.shadow_srr1; 905 859 vcpu->stat.pf_instruc++; 860 + 861 + if (kvmppc_is_split_real(vcpu)) 862 + kvmppc_fixup_split_real(vcpu); 906 863 907 864 #ifdef CONFIG_PPC_BOOK3S_32 908 865 /* We set segments as unused segments when invalidating them. So ··· 1009 960 case BOOK3S_INTERRUPT_DECREMENTER: 1010 961 case BOOK3S_INTERRUPT_HV_DECREMENTER: 1011 962 case BOOK3S_INTERRUPT_DOORBELL: 963 + case BOOK3S_INTERRUPT_H_DOORBELL: 1012 964 vcpu->stat.dec_exits++; 1013 965 r = RESUME_GUEST; 1014 966 break; ··· 1027 977 { 1028 978 enum emulation_result er; 1029 979 ulong flags; 980 + u32 last_inst; 981 + int emul; 1030 982 1031 983 program_interrupt: 1032 984 flags = vcpu->arch.shadow_srr1 & 0x1f0000ull; 1033 985 986 + emul = kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst); 987 + if (emul != EMULATE_DONE) { 988 + r = RESUME_GUEST; 989 + break; 990 + } 991 + 1034 992 if (kvmppc_get_msr(vcpu) & MSR_PR) { 1035 993 #ifdef EXIT_DEBUG 1036 - printk(KERN_INFO "Userspace triggered 0x700 exception at 0x%lx (0x%x)\n", kvmppc_get_pc(vcpu), kvmppc_get_last_inst(vcpu)); 994 + pr_info("Userspace triggered 0x700 exception at\n 0x%lx (0x%x)\n", 995 + kvmppc_get_pc(vcpu), last_inst); 1037 996 #endif 1038 - if ((kvmppc_get_last_inst(vcpu) & 0xff0007ff) != 997 + if ((last_inst & 0xff0007ff) != 1039 998 (INS_DCBZ & 0xfffffff7)) { 1040 999 kvmppc_core_queue_program(vcpu, flags); 1041 1000 r = RESUME_GUEST; ··· 1063 1004 break; 1064 1005 case EMULATE_FAIL: 1065 1006 printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", 1066 - __func__, kvmppc_get_pc(vcpu), kvmppc_get_last_inst(vcpu)); 1007 + __func__, kvmppc_get_pc(vcpu), last_inst); 1067 1008 kvmppc_core_queue_program(vcpu, flags); 1068 1009 r = RESUME_GUEST; 1069 1010 break; ··· 1080 1021 break; 1081 1022 } 1082 1023 case BOOK3S_INTERRUPT_SYSCALL: 1024 + { 1025 + u32 last_sc; 1026 + int emul; 1027 + 1028 + /* Get last sc for papr */ 1029 + if (vcpu->arch.papr_enabled) { 1030 + /* The sc instuction points SRR0 to the next inst */ 1031 + emul = kvmppc_get_last_inst(vcpu, INST_SC, &last_sc); 1032 + if (emul != EMULATE_DONE) { 1033 + kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) - 4); 1034 + r = RESUME_GUEST; 1035 + break; 1036 + } 1037 + } 1038 + 1083 1039 if (vcpu->arch.papr_enabled && 1084 - (kvmppc_get_last_sc(vcpu) == 0x44000022) && 1040 + (last_sc == 0x44000022) && 1085 1041 !(kvmppc_get_msr(vcpu) & MSR_PR)) { 1086 1042 /* SC 1 papr hypercalls */ 1087 1043 ulong cmd = kvmppc_get_gpr(vcpu, 3); ··· 1141 1067 r = RESUME_GUEST; 1142 1068 } 1143 1069 break; 1070 + } 1144 1071 case BOOK3S_INTERRUPT_FP_UNAVAIL: 1145 1072 case BOOK3S_INTERRUPT_ALTIVEC: 1146 1073 case BOOK3S_INTERRUPT_VSX: 1147 1074 { 1148 1075 int ext_msr = 0; 1076 + int emul; 1077 + u32 last_inst; 1149 1078 1079 + if (vcpu->arch.hflags & BOOK3S_HFLAG_PAIRED_SINGLE) { 1080 + /* Do paired single instruction emulation */ 1081 + emul = kvmppc_get_last_inst(vcpu, INST_GENERIC, 1082 + &last_inst); 1083 + if (emul == EMULATE_DONE) 1084 + goto program_interrupt; 1085 + else 1086 + r = RESUME_GUEST; 1087 + 1088 + break; 1089 + } 1090 + 1091 + /* Enable external provider */ 1150 1092 switch (exit_nr) { 1151 - case BOOK3S_INTERRUPT_FP_UNAVAIL: ext_msr = MSR_FP; break; 1152 - case BOOK3S_INTERRUPT_ALTIVEC: ext_msr = MSR_VEC; break; 1153 - case BOOK3S_INTERRUPT_VSX: ext_msr = MSR_VSX; break; 1093 + case BOOK3S_INTERRUPT_FP_UNAVAIL: 1094 + ext_msr = MSR_FP; 1095 + break; 1096 + 1097 + case BOOK3S_INTERRUPT_ALTIVEC: 1098 + ext_msr = MSR_VEC; 1099 + break; 1100 + 1101 + case BOOK3S_INTERRUPT_VSX: 1102 + ext_msr = MSR_VSX; 1103 + break; 1154 1104 } 1155 1105 1156 - switch (kvmppc_check_ext(vcpu, exit_nr)) { 1157 - case EMULATE_DONE: 1158 - /* everything ok - let's enable the ext */ 1159 - r = kvmppc_handle_ext(vcpu, exit_nr, ext_msr); 1160 - break; 1161 - case EMULATE_FAIL: 1162 - /* we need to emulate this instruction */ 1163 - goto program_interrupt; 1164 - break; 1165 - default: 1166 - /* nothing to worry about - go again */ 1167 - break; 1168 - } 1106 + r = kvmppc_handle_ext(vcpu, exit_nr, ext_msr); 1169 1107 break; 1170 1108 } 1171 1109 case BOOK3S_INTERRUPT_ALIGNMENT: 1172 - if (kvmppc_read_inst(vcpu) == EMULATE_DONE) { 1173 - u32 last_inst = kvmppc_get_last_inst(vcpu); 1110 + { 1111 + u32 last_inst; 1112 + int emul = kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst); 1113 + 1114 + if (emul == EMULATE_DONE) { 1174 1115 u32 dsisr; 1175 1116 u64 dar; 1176 1117 ··· 1199 1110 } 1200 1111 r = RESUME_GUEST; 1201 1112 break; 1113 + } 1202 1114 #ifdef CONFIG_PPC_BOOK3S_64 1203 1115 case BOOK3S_INTERRUPT_FAC_UNAVAIL: 1204 1116 kvmppc_handle_fac(vcpu, vcpu->arch.shadow_fscr >> 56); ··· 1323 1233 *val = get_reg_val(id, to_book3s(vcpu)->hior); 1324 1234 break; 1325 1235 case KVM_REG_PPC_LPCR: 1236 + case KVM_REG_PPC_LPCR_64: 1326 1237 /* 1327 1238 * We are only interested in the LPCR_ILE bit 1328 1239 */ ··· 1359 1268 to_book3s(vcpu)->hior_explicit = true; 1360 1269 break; 1361 1270 case KVM_REG_PPC_LPCR: 1271 + case KVM_REG_PPC_LPCR_64: 1362 1272 kvmppc_set_lpcr_pr(vcpu, set_reg_val(id, *val)); 1363 1273 break; 1364 1274 default: ··· 1402 1310 p = __get_free_page(GFP_KERNEL|__GFP_ZERO); 1403 1311 if (!p) 1404 1312 goto uninit_vcpu; 1405 - /* the real shared page fills the last 4k of our page */ 1406 - vcpu->arch.shared = (void *)(p + PAGE_SIZE - 4096); 1313 + vcpu->arch.shared = (void *)p; 1407 1314 #ifdef CONFIG_PPC_BOOK3S_64 1408 1315 /* Always start the shared struct in native endian mode */ 1409 1316 #ifdef __BIG_ENDIAN__ ··· 1659 1568 { 1660 1569 mutex_init(&kvm->arch.hpt_mutex); 1661 1570 1571 + #ifdef CONFIG_PPC_BOOK3S_64 1572 + /* Start out with the default set of hcalls enabled */ 1573 + kvmppc_pr_init_default_hcalls(kvm); 1574 + #endif 1575 + 1662 1576 if (firmware_has_feature(FW_FEATURE_SET_MODE)) { 1663 1577 spin_lock(&kvm_global_user_count_lock); 1664 1578 if (++kvm_global_user_count == 1) ··· 1732 1636 .emulate_mfspr = kvmppc_core_emulate_mfspr_pr, 1733 1637 .fast_vcpu_kick = kvm_vcpu_kick, 1734 1638 .arch_vm_ioctl = kvm_arch_vm_ioctl_pr, 1639 + #ifdef CONFIG_PPC_BOOK3S_64 1640 + .hcall_implemented = kvmppc_hcall_impl_pr, 1641 + #endif 1735 1642 }; 1736 1643 1737 1644
+80 -12
arch/powerpc/kvm/book3s_pr_papr.c
··· 40 40 { 41 41 long flags = kvmppc_get_gpr(vcpu, 4); 42 42 long pte_index = kvmppc_get_gpr(vcpu, 5); 43 - unsigned long pteg[2 * 8]; 44 - unsigned long pteg_addr, i, *hpte; 43 + __be64 pteg[2 * 8]; 44 + __be64 *hpte; 45 + unsigned long pteg_addr, i; 45 46 long int ret; 46 47 47 48 i = pte_index & 7; ··· 94 93 pteg = get_pteg_addr(vcpu, pte_index); 95 94 mutex_lock(&vcpu->kvm->arch.hpt_mutex); 96 95 copy_from_user(pte, (void __user *)pteg, sizeof(pte)); 97 - pte[0] = be64_to_cpu(pte[0]); 98 - pte[1] = be64_to_cpu(pte[1]); 96 + pte[0] = be64_to_cpu((__force __be64)pte[0]); 97 + pte[1] = be64_to_cpu((__force __be64)pte[1]); 99 98 100 99 ret = H_NOT_FOUND; 101 100 if ((pte[0] & HPTE_V_VALID) == 0 || ··· 172 171 173 172 pteg = get_pteg_addr(vcpu, tsh & H_BULK_REMOVE_PTEX); 174 173 copy_from_user(pte, (void __user *)pteg, sizeof(pte)); 175 - pte[0] = be64_to_cpu(pte[0]); 176 - pte[1] = be64_to_cpu(pte[1]); 174 + pte[0] = be64_to_cpu((__force __be64)pte[0]); 175 + pte[1] = be64_to_cpu((__force __be64)pte[1]); 177 176 178 177 /* tsl = AVPN */ 179 178 flags = (tsh & H_BULK_REMOVE_FLAGS) >> 26; ··· 212 211 pteg = get_pteg_addr(vcpu, pte_index); 213 212 mutex_lock(&vcpu->kvm->arch.hpt_mutex); 214 213 copy_from_user(pte, (void __user *)pteg, sizeof(pte)); 215 - pte[0] = be64_to_cpu(pte[0]); 216 - pte[1] = be64_to_cpu(pte[1]); 214 + pte[0] = be64_to_cpu((__force __be64)pte[0]); 215 + pte[1] = be64_to_cpu((__force __be64)pte[1]); 217 216 218 217 ret = H_NOT_FOUND; 219 218 if ((pte[0] & HPTE_V_VALID) == 0 || ··· 232 231 233 232 rb = compute_tlbie_rb(v, r, pte_index); 234 233 vcpu->arch.mmu.tlbie(vcpu, rb, rb & 1 ? true : false); 235 - pte[0] = cpu_to_be64(pte[0]); 236 - pte[1] = cpu_to_be64(pte[1]); 234 + pte[0] = (__force u64)cpu_to_be64(pte[0]); 235 + pte[1] = (__force u64)cpu_to_be64(pte[1]); 237 236 copy_to_user((void __user *)pteg, pte, sizeof(pte)); 238 237 ret = H_SUCCESS; 239 238 ··· 267 266 268 267 int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd) 269 268 { 269 + int rc, idx; 270 + 271 + if (cmd <= MAX_HCALL_OPCODE && 272 + !test_bit(cmd/4, vcpu->kvm->arch.enabled_hcalls)) 273 + return EMULATE_FAIL; 274 + 270 275 switch (cmd) { 271 276 case H_ENTER: 272 277 return kvmppc_h_pr_enter(vcpu); ··· 301 294 break; 302 295 case H_RTAS: 303 296 if (list_empty(&vcpu->kvm->arch.rtas_tokens)) 304 - return RESUME_HOST; 305 - if (kvmppc_rtas_hcall(vcpu)) 297 + break; 298 + idx = srcu_read_lock(&vcpu->kvm->srcu); 299 + rc = kvmppc_rtas_hcall(vcpu); 300 + srcu_read_unlock(&vcpu->kvm->srcu, idx); 301 + if (rc) 306 302 break; 307 303 kvmppc_set_gpr(vcpu, 3, 0); 308 304 return EMULATE_DONE; 309 305 } 310 306 311 307 return EMULATE_FAIL; 308 + } 309 + 310 + int kvmppc_hcall_impl_pr(unsigned long cmd) 311 + { 312 + switch (cmd) { 313 + case H_ENTER: 314 + case H_REMOVE: 315 + case H_PROTECT: 316 + case H_BULK_REMOVE: 317 + case H_PUT_TCE: 318 + case H_CEDE: 319 + #ifdef CONFIG_KVM_XICS 320 + case H_XIRR: 321 + case H_CPPR: 322 + case H_EOI: 323 + case H_IPI: 324 + case H_IPOLL: 325 + case H_XIRR_X: 326 + #endif 327 + return 1; 328 + } 329 + return 0; 330 + } 331 + 332 + /* 333 + * List of hcall numbers to enable by default. 334 + * For compatibility with old userspace, we enable by default 335 + * all hcalls that were implemented before the hcall-enabling 336 + * facility was added. Note this list should not include H_RTAS. 337 + */ 338 + static unsigned int default_hcall_list[] = { 339 + H_ENTER, 340 + H_REMOVE, 341 + H_PROTECT, 342 + H_BULK_REMOVE, 343 + H_PUT_TCE, 344 + H_CEDE, 345 + #ifdef CONFIG_KVM_XICS 346 + H_XIRR, 347 + H_CPPR, 348 + H_EOI, 349 + H_IPI, 350 + H_IPOLL, 351 + H_XIRR_X, 352 + #endif 353 + 0 354 + }; 355 + 356 + void kvmppc_pr_init_default_hcalls(struct kvm *kvm) 357 + { 358 + int i; 359 + unsigned int hcall; 360 + 361 + for (i = 0; default_hcall_list[i]; ++i) { 362 + hcall = default_hcall_list[i]; 363 + WARN_ON(!kvmppc_hcall_impl_pr(hcall)); 364 + __set_bit(hcall / 4, kvm->arch.enabled_hcalls); 365 + } 312 366 }
+46 -9
arch/powerpc/kvm/book3s_xics.c
··· 64 64 static void icp_deliver_irq(struct kvmppc_xics *xics, struct kvmppc_icp *icp, 65 65 u32 new_irq); 66 66 67 - static int ics_deliver_irq(struct kvmppc_xics *xics, u32 irq, u32 level, 68 - bool report_status) 67 + /* 68 + * Return value ideally indicates how the interrupt was handled, but no 69 + * callers look at it (given that we don't implement KVM_IRQ_LINE_STATUS), 70 + * so just return 0. 71 + */ 72 + static int ics_deliver_irq(struct kvmppc_xics *xics, u32 irq, u32 level) 69 73 { 70 74 struct ics_irq_state *state; 71 75 struct kvmppc_ics *ics; ··· 86 82 if (!state->exists) 87 83 return -EINVAL; 88 84 89 - if (report_status) 90 - return state->asserted; 91 - 92 85 /* 93 86 * We set state->asserted locklessly. This should be fine as 94 87 * we are the only setter, thus concurrent access is undefined 95 88 * to begin with. 96 89 */ 97 - if (level == KVM_INTERRUPT_SET_LEVEL) 90 + if (level == 1 || level == KVM_INTERRUPT_SET_LEVEL) 98 91 state->asserted = 1; 99 - else if (level == KVM_INTERRUPT_UNSET) { 92 + else if (level == 0 || level == KVM_INTERRUPT_UNSET) { 100 93 state->asserted = 0; 101 94 return 0; 102 95 } ··· 101 100 /* Attempt delivery */ 102 101 icp_deliver_irq(xics, NULL, irq); 103 102 104 - return state->asserted; 103 + return 0; 105 104 } 106 105 107 106 static void ics_check_resend(struct kvmppc_xics *xics, struct kvmppc_ics *ics, ··· 773 772 if (state->asserted) 774 773 icp_deliver_irq(xics, icp, irq); 775 774 775 + kvm_notify_acked_irq(vcpu->kvm, 0, irq); 776 + 776 777 return H_SUCCESS; 777 778 } 778 779 ··· 792 789 icp_check_resend(xics, icp); 793 790 if (icp->rm_action & XICS_RM_REJECT) 794 791 icp_deliver_irq(xics, icp, icp->rm_reject); 792 + if (icp->rm_action & XICS_RM_NOTIFY_EOI) 793 + kvm_notify_acked_irq(vcpu->kvm, 0, icp->rm_eoied_irq); 795 794 796 795 icp->rm_action = 0; 797 796 ··· 1175 1170 { 1176 1171 struct kvmppc_xics *xics = kvm->arch.xics; 1177 1172 1178 - return ics_deliver_irq(xics, irq, level, line_status); 1173 + return ics_deliver_irq(xics, irq, level); 1174 + } 1175 + 1176 + int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm, 1177 + int irq_source_id, int level, bool line_status) 1178 + { 1179 + if (!level) 1180 + return -1; 1181 + return kvm_set_irq(kvm, irq_source_id, irq_entry->gsi, 1182 + level, line_status); 1179 1183 } 1180 1184 1181 1185 static int xics_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) ··· 1314 1300 kfree(vcpu->arch.icp); 1315 1301 vcpu->arch.icp = NULL; 1316 1302 vcpu->arch.irq_type = KVMPPC_IRQ_DEFAULT; 1303 + } 1304 + 1305 + static int xics_set_irq(struct kvm_kernel_irq_routing_entry *e, 1306 + struct kvm *kvm, int irq_source_id, int level, 1307 + bool line_status) 1308 + { 1309 + return kvm_set_irq(kvm, irq_source_id, e->gsi, level, line_status); 1310 + } 1311 + 1312 + int kvm_irq_map_gsi(struct kvm *kvm, 1313 + struct kvm_kernel_irq_routing_entry *entries, int gsi) 1314 + { 1315 + entries->gsi = gsi; 1316 + entries->type = KVM_IRQ_ROUTING_IRQCHIP; 1317 + entries->set = xics_set_irq; 1318 + entries->irqchip.irqchip = 0; 1319 + entries->irqchip.pin = gsi; 1320 + return 1; 1321 + } 1322 + 1323 + int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin) 1324 + { 1325 + return pin; 1317 1326 }
+2
arch/powerpc/kvm/book3s_xics.h
··· 71 71 #define XICS_RM_KICK_VCPU 0x1 72 72 #define XICS_RM_CHECK_RESEND 0x2 73 73 #define XICS_RM_REJECT 0x4 74 + #define XICS_RM_NOTIFY_EOI 0x8 74 75 u32 rm_action; 75 76 struct kvm_vcpu *rm_kick_target; 76 77 u32 rm_reject; 78 + u32 rm_eoied_irq; 77 79 78 80 /* Debug stuff for real mode */ 79 81 union kvmppc_icp_state rm_dbgstate;
+136 -89
arch/powerpc/kvm/booke.c
··· 51 51 52 52 struct kvm_stats_debugfs_item debugfs_entries[] = { 53 53 { "mmio", VCPU_STAT(mmio_exits) }, 54 - { "dcr", VCPU_STAT(dcr_exits) }, 55 54 { "sig", VCPU_STAT(signal_exits) }, 56 55 { "itlb_r", VCPU_STAT(itlb_real_miss_exits) }, 57 56 { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) }, ··· 184 185 set_bit(priority, &vcpu->arch.pending_exceptions); 185 186 } 186 187 187 - static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, 188 - ulong dear_flags, ulong esr_flags) 188 + void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, 189 + ulong dear_flags, ulong esr_flags) 189 190 { 190 191 vcpu->arch.queued_dear = dear_flags; 191 192 vcpu->arch.queued_esr = esr_flags; 192 193 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS); 193 194 } 194 195 195 - static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, 196 - ulong dear_flags, ulong esr_flags) 196 + void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, 197 + ulong dear_flags, ulong esr_flags) 197 198 { 198 199 vcpu->arch.queued_dear = dear_flags; 199 200 vcpu->arch.queued_esr = esr_flags; 200 201 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE); 201 202 } 202 203 203 - static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, 204 - ulong esr_flags) 204 + void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu) 205 + { 206 + kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); 207 + } 208 + 209 + void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, ulong esr_flags) 205 210 { 206 211 vcpu->arch.queued_esr = esr_flags; 207 212 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE); ··· 269 266 270 267 static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) 271 268 { 272 - #ifdef CONFIG_KVM_BOOKE_HV 273 - mtspr(SPRN_GSRR0, srr0); 274 - mtspr(SPRN_GSRR1, srr1); 275 - #else 276 - vcpu->arch.shared->srr0 = srr0; 277 - vcpu->arch.shared->srr1 = srr1; 278 - #endif 269 + kvmppc_set_srr0(vcpu, srr0); 270 + kvmppc_set_srr1(vcpu, srr1); 279 271 } 280 272 281 273 static void set_guest_csrr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) ··· 293 295 { 294 296 vcpu->arch.mcsrr0 = srr0; 295 297 vcpu->arch.mcsrr1 = srr1; 296 - } 297 - 298 - static unsigned long get_guest_dear(struct kvm_vcpu *vcpu) 299 - { 300 - #ifdef CONFIG_KVM_BOOKE_HV 301 - return mfspr(SPRN_GDEAR); 302 - #else 303 - return vcpu->arch.shared->dar; 304 - #endif 305 - } 306 - 307 - static void set_guest_dear(struct kvm_vcpu *vcpu, unsigned long dear) 308 - { 309 - #ifdef CONFIG_KVM_BOOKE_HV 310 - mtspr(SPRN_GDEAR, dear); 311 - #else 312 - vcpu->arch.shared->dar = dear; 313 - #endif 314 - } 315 - 316 - static unsigned long get_guest_esr(struct kvm_vcpu *vcpu) 317 - { 318 - #ifdef CONFIG_KVM_BOOKE_HV 319 - return mfspr(SPRN_GESR); 320 - #else 321 - return vcpu->arch.shared->esr; 322 - #endif 323 - } 324 - 325 - static void set_guest_esr(struct kvm_vcpu *vcpu, u32 esr) 326 - { 327 - #ifdef CONFIG_KVM_BOOKE_HV 328 - mtspr(SPRN_GESR, esr); 329 - #else 330 - vcpu->arch.shared->esr = esr; 331 - #endif 332 - } 333 - 334 - static unsigned long get_guest_epr(struct kvm_vcpu *vcpu) 335 - { 336 - #ifdef CONFIG_KVM_BOOKE_HV 337 - return mfspr(SPRN_GEPR); 338 - #else 339 - return vcpu->arch.epr; 340 - #endif 341 298 } 342 299 343 300 /* Deliver the interrupt of the corresponding priority, if possible. */ ··· 403 450 404 451 vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; 405 452 if (update_esr == true) 406 - set_guest_esr(vcpu, vcpu->arch.queued_esr); 453 + kvmppc_set_esr(vcpu, vcpu->arch.queued_esr); 407 454 if (update_dear == true) 408 - set_guest_dear(vcpu, vcpu->arch.queued_dear); 455 + kvmppc_set_dar(vcpu, vcpu->arch.queued_dear); 409 456 if (update_epr == true) { 410 457 if (vcpu->arch.epr_flags & KVMPPC_EPR_USER) 411 458 kvm_make_request(KVM_REQ_EPR_EXIT, vcpu); ··· 705 752 * they were actually modified by emulation. */ 706 753 return RESUME_GUEST_NV; 707 754 708 - case EMULATE_DO_DCR: 709 - run->exit_reason = KVM_EXIT_DCR; 710 - return RESUME_HOST; 755 + case EMULATE_AGAIN: 756 + return RESUME_GUEST; 711 757 712 758 case EMULATE_FAIL: 713 759 printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", ··· 818 866 } 819 867 } 820 868 869 + static int kvmppc_resume_inst_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 870 + enum emulation_result emulated, u32 last_inst) 871 + { 872 + switch (emulated) { 873 + case EMULATE_AGAIN: 874 + return RESUME_GUEST; 875 + 876 + case EMULATE_FAIL: 877 + pr_debug("%s: load instruction from guest address %lx failed\n", 878 + __func__, vcpu->arch.pc); 879 + /* For debugging, encode the failing instruction and 880 + * report it to userspace. */ 881 + run->hw.hardware_exit_reason = ~0ULL << 32; 882 + run->hw.hardware_exit_reason |= last_inst; 883 + kvmppc_core_queue_program(vcpu, ESR_PIL); 884 + return RESUME_HOST; 885 + 886 + default: 887 + BUG(); 888 + } 889 + } 890 + 821 891 /** 822 892 * kvmppc_handle_exit 823 893 * ··· 851 877 int r = RESUME_HOST; 852 878 int s; 853 879 int idx; 880 + u32 last_inst = KVM_INST_FETCH_FAILED; 881 + enum emulation_result emulated = EMULATE_DONE; 854 882 855 883 /* update before a new last_exit_type is rewritten */ 856 884 kvmppc_update_timing_stats(vcpu); 857 885 858 886 /* restart interrupts if they were meant for the host */ 859 887 kvmppc_restart_interrupt(vcpu, exit_nr); 888 + 889 + /* 890 + * get last instruction before beeing preempted 891 + * TODO: for e6500 check also BOOKE_INTERRUPT_LRAT_ERROR & ESR_DATA 892 + */ 893 + switch (exit_nr) { 894 + case BOOKE_INTERRUPT_DATA_STORAGE: 895 + case BOOKE_INTERRUPT_DTLB_MISS: 896 + case BOOKE_INTERRUPT_HV_PRIV: 897 + emulated = kvmppc_get_last_inst(vcpu, false, &last_inst); 898 + break; 899 + default: 900 + break; 901 + } 860 902 861 903 local_irq_enable(); 862 904 ··· 881 891 882 892 run->exit_reason = KVM_EXIT_UNKNOWN; 883 893 run->ready_for_interrupt_injection = 1; 894 + 895 + if (emulated != EMULATE_DONE) { 896 + r = kvmppc_resume_inst_load(run, vcpu, emulated, last_inst); 897 + goto out; 898 + } 884 899 885 900 switch (exit_nr) { 886 901 case BOOKE_INTERRUPT_MACHINE_CHECK: ··· 1176 1181 BUG(); 1177 1182 } 1178 1183 1184 + out: 1179 1185 /* 1180 1186 * To avoid clobbering exit_reason, only check for signals if we 1181 1187 * aren't already exiting to userspace for some other reason. ··· 1261 1265 regs->lr = vcpu->arch.lr; 1262 1266 regs->xer = kvmppc_get_xer(vcpu); 1263 1267 regs->msr = vcpu->arch.shared->msr; 1264 - regs->srr0 = vcpu->arch.shared->srr0; 1265 - regs->srr1 = vcpu->arch.shared->srr1; 1268 + regs->srr0 = kvmppc_get_srr0(vcpu); 1269 + regs->srr1 = kvmppc_get_srr1(vcpu); 1266 1270 regs->pid = vcpu->arch.pid; 1267 - regs->sprg0 = vcpu->arch.shared->sprg0; 1268 - regs->sprg1 = vcpu->arch.shared->sprg1; 1269 - regs->sprg2 = vcpu->arch.shared->sprg2; 1270 - regs->sprg3 = vcpu->arch.shared->sprg3; 1271 - regs->sprg4 = vcpu->arch.shared->sprg4; 1272 - regs->sprg5 = vcpu->arch.shared->sprg5; 1273 - regs->sprg6 = vcpu->arch.shared->sprg6; 1274 - regs->sprg7 = vcpu->arch.shared->sprg7; 1271 + regs->sprg0 = kvmppc_get_sprg0(vcpu); 1272 + regs->sprg1 = kvmppc_get_sprg1(vcpu); 1273 + regs->sprg2 = kvmppc_get_sprg2(vcpu); 1274 + regs->sprg3 = kvmppc_get_sprg3(vcpu); 1275 + regs->sprg4 = kvmppc_get_sprg4(vcpu); 1276 + regs->sprg5 = kvmppc_get_sprg5(vcpu); 1277 + regs->sprg6 = kvmppc_get_sprg6(vcpu); 1278 + regs->sprg7 = kvmppc_get_sprg7(vcpu); 1275 1279 1276 1280 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) 1277 1281 regs->gpr[i] = kvmppc_get_gpr(vcpu, i); ··· 1289 1293 vcpu->arch.lr = regs->lr; 1290 1294 kvmppc_set_xer(vcpu, regs->xer); 1291 1295 kvmppc_set_msr(vcpu, regs->msr); 1292 - vcpu->arch.shared->srr0 = regs->srr0; 1293 - vcpu->arch.shared->srr1 = regs->srr1; 1296 + kvmppc_set_srr0(vcpu, regs->srr0); 1297 + kvmppc_set_srr1(vcpu, regs->srr1); 1294 1298 kvmppc_set_pid(vcpu, regs->pid); 1295 - vcpu->arch.shared->sprg0 = regs->sprg0; 1296 - vcpu->arch.shared->sprg1 = regs->sprg1; 1297 - vcpu->arch.shared->sprg2 = regs->sprg2; 1298 - vcpu->arch.shared->sprg3 = regs->sprg3; 1299 - vcpu->arch.shared->sprg4 = regs->sprg4; 1300 - vcpu->arch.shared->sprg5 = regs->sprg5; 1301 - vcpu->arch.shared->sprg6 = regs->sprg6; 1302 - vcpu->arch.shared->sprg7 = regs->sprg7; 1299 + kvmppc_set_sprg0(vcpu, regs->sprg0); 1300 + kvmppc_set_sprg1(vcpu, regs->sprg1); 1301 + kvmppc_set_sprg2(vcpu, regs->sprg2); 1302 + kvmppc_set_sprg3(vcpu, regs->sprg3); 1303 + kvmppc_set_sprg4(vcpu, regs->sprg4); 1304 + kvmppc_set_sprg5(vcpu, regs->sprg5); 1305 + kvmppc_set_sprg6(vcpu, regs->sprg6); 1306 + kvmppc_set_sprg7(vcpu, regs->sprg7); 1303 1307 1304 1308 for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) 1305 1309 kvmppc_set_gpr(vcpu, i, regs->gpr[i]); ··· 1317 1321 sregs->u.e.csrr0 = vcpu->arch.csrr0; 1318 1322 sregs->u.e.csrr1 = vcpu->arch.csrr1; 1319 1323 sregs->u.e.mcsr = vcpu->arch.mcsr; 1320 - sregs->u.e.esr = get_guest_esr(vcpu); 1321 - sregs->u.e.dear = get_guest_dear(vcpu); 1324 + sregs->u.e.esr = kvmppc_get_esr(vcpu); 1325 + sregs->u.e.dear = kvmppc_get_dar(vcpu); 1322 1326 sregs->u.e.tsr = vcpu->arch.tsr; 1323 1327 sregs->u.e.tcr = vcpu->arch.tcr; 1324 1328 sregs->u.e.dec = kvmppc_get_dec(vcpu, tb); ··· 1335 1339 vcpu->arch.csrr0 = sregs->u.e.csrr0; 1336 1340 vcpu->arch.csrr1 = sregs->u.e.csrr1; 1337 1341 vcpu->arch.mcsr = sregs->u.e.mcsr; 1338 - set_guest_esr(vcpu, sregs->u.e.esr); 1339 - set_guest_dear(vcpu, sregs->u.e.dear); 1342 + kvmppc_set_esr(vcpu, sregs->u.e.esr); 1343 + kvmppc_set_dar(vcpu, sregs->u.e.dear); 1340 1344 vcpu->arch.vrsave = sregs->u.e.vrsave; 1341 1345 kvmppc_set_tcr(vcpu, sregs->u.e.tcr); 1342 1346 ··· 1489 1493 val = get_reg_val(reg->id, vcpu->arch.dbg_reg.dac2); 1490 1494 break; 1491 1495 case KVM_REG_PPC_EPR: { 1492 - u32 epr = get_guest_epr(vcpu); 1496 + u32 epr = kvmppc_get_epr(vcpu); 1493 1497 val = get_reg_val(reg->id, epr); 1494 1498 break; 1495 1499 } ··· 1782 1786 vcpu->arch.shadow_msrp &= ~MSRP_PMMP; 1783 1787 } 1784 1788 #endif 1789 + } 1790 + 1791 + int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid, 1792 + enum xlate_readwrite xlrw, struct kvmppc_pte *pte) 1793 + { 1794 + int gtlb_index; 1795 + gpa_t gpaddr; 1796 + 1797 + #ifdef CONFIG_KVM_E500V2 1798 + if (!(vcpu->arch.shared->msr & MSR_PR) && 1799 + (eaddr & PAGE_MASK) == vcpu->arch.magic_page_ea) { 1800 + pte->eaddr = eaddr; 1801 + pte->raddr = (vcpu->arch.magic_page_pa & PAGE_MASK) | 1802 + (eaddr & ~PAGE_MASK); 1803 + pte->vpage = eaddr >> PAGE_SHIFT; 1804 + pte->may_read = true; 1805 + pte->may_write = true; 1806 + pte->may_execute = true; 1807 + 1808 + return 0; 1809 + } 1810 + #endif 1811 + 1812 + /* Check the guest TLB. */ 1813 + switch (xlid) { 1814 + case XLATE_INST: 1815 + gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); 1816 + break; 1817 + case XLATE_DATA: 1818 + gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); 1819 + break; 1820 + default: 1821 + BUG(); 1822 + } 1823 + 1824 + /* Do we have a TLB entry at all? */ 1825 + if (gtlb_index < 0) 1826 + return -ENOENT; 1827 + 1828 + gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); 1829 + 1830 + pte->eaddr = eaddr; 1831 + pte->raddr = (gpaddr & PAGE_MASK) | (eaddr & ~PAGE_MASK); 1832 + pte->vpage = eaddr >> PAGE_SHIFT; 1833 + 1834 + /* XXX read permissions from the guest TLB */ 1835 + pte->may_read = true; 1836 + pte->may_write = true; 1837 + pte->may_execute = true; 1838 + 1839 + return 0; 1785 1840 } 1786 1841 1787 1842 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
-7
arch/powerpc/kvm/booke.h
··· 99 99 100 100 void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type); 101 101 102 - extern void kvmppc_mmu_destroy_44x(struct kvm_vcpu *vcpu); 103 - extern int kvmppc_core_emulate_op_44x(struct kvm_run *run, struct kvm_vcpu *vcpu, 104 - unsigned int inst, int *advance); 105 - extern int kvmppc_core_emulate_mtspr_44x(struct kvm_vcpu *vcpu, int sprn, 106 - ulong spr_val); 107 - extern int kvmppc_core_emulate_mfspr_44x(struct kvm_vcpu *vcpu, int sprn, 108 - ulong *spr_val); 109 102 extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu); 110 103 extern int kvmppc_core_emulate_op_e500(struct kvm_run *run, 111 104 struct kvm_vcpu *vcpu,
+4 -4
arch/powerpc/kvm/booke_emulate.c
··· 165 165 * guest (PR-mode only). 166 166 */ 167 167 case SPRN_SPRG4: 168 - vcpu->arch.shared->sprg4 = spr_val; 168 + kvmppc_set_sprg4(vcpu, spr_val); 169 169 break; 170 170 case SPRN_SPRG5: 171 - vcpu->arch.shared->sprg5 = spr_val; 171 + kvmppc_set_sprg5(vcpu, spr_val); 172 172 break; 173 173 case SPRN_SPRG6: 174 - vcpu->arch.shared->sprg6 = spr_val; 174 + kvmppc_set_sprg6(vcpu, spr_val); 175 175 break; 176 176 case SPRN_SPRG7: 177 - vcpu->arch.shared->sprg7 = spr_val; 177 + kvmppc_set_sprg7(vcpu, spr_val); 178 178 break; 179 179 180 180 case SPRN_IVPR:
-5
arch/powerpc/kvm/booke_interrupts.S
··· 21 21 #include <asm/ppc_asm.h> 22 22 #include <asm/kvm_asm.h> 23 23 #include <asm/reg.h> 24 - #include <asm/mmu-44x.h> 25 24 #include <asm/page.h> 26 25 #include <asm/asm-offsets.h> 27 26 ··· 421 422 #ifdef CONFIG_FSL_BOOKE 422 423 lwz r3, VCPU_SHADOW_PID1(r4) 423 424 mtspr SPRN_PID1, r3 424 - #endif 425 - 426 - #ifdef CONFIG_44x 427 - iccci 0, 0 /* XXX hack */ 428 425 #endif 429 426 430 427 /* Load some guest volatiles. */
+10 -50
arch/powerpc/kvm/bookehv_interrupts.S
··· 24 24 #include <asm/ppc_asm.h> 25 25 #include <asm/kvm_asm.h> 26 26 #include <asm/reg.h> 27 - #include <asm/mmu-44x.h> 28 27 #include <asm/page.h> 29 28 #include <asm/asm-compat.h> 30 29 #include <asm/asm-offsets.h> 31 30 #include <asm/bitsperlong.h> 32 - #include <asm/thread_info.h> 33 31 34 32 #ifdef CONFIG_64BIT 35 33 #include <asm/exception-64e.h> ··· 120 122 1: 121 123 122 124 .if \flags & NEED_EMU 123 - /* 124 - * This assumes you have external PID support. 125 - * To support a bookehv CPU without external PID, you'll 126 - * need to look up the TLB entry and create a temporary mapping. 127 - * 128 - * FIXME: we don't currently handle if the lwepx faults. PR-mode 129 - * booke doesn't handle it either. Since Linux doesn't use 130 - * broadcast tlbivax anymore, the only way this should happen is 131 - * if the guest maps its memory execute-but-not-read, or if we 132 - * somehow take a TLB miss in the middle of this entry code and 133 - * evict the relevant entry. On e500mc, all kernel lowmem is 134 - * bolted into TLB1 large page mappings, and we don't use 135 - * broadcast invalidates, so we should not take a TLB miss here. 136 - * 137 - * Later we'll need to deal with faults here. Disallowing guest 138 - * mappings that are execute-but-not-read could be an option on 139 - * e500mc, but not on chips with an LRAT if it is used. 140 - */ 141 - 142 - mfspr r3, SPRN_EPLC /* will already have correct ELPID and EGS */ 143 125 PPC_STL r15, VCPU_GPR(R15)(r4) 144 126 PPC_STL r16, VCPU_GPR(R16)(r4) 145 127 PPC_STL r17, VCPU_GPR(R17)(r4) 146 128 PPC_STL r18, VCPU_GPR(R18)(r4) 147 129 PPC_STL r19, VCPU_GPR(R19)(r4) 148 - mr r8, r3 149 130 PPC_STL r20, VCPU_GPR(R20)(r4) 150 - rlwimi r8, r6, EPC_EAS_SHIFT - MSR_IR_LG, EPC_EAS 151 131 PPC_STL r21, VCPU_GPR(R21)(r4) 152 - rlwimi r8, r6, EPC_EPR_SHIFT - MSR_PR_LG, EPC_EPR 153 132 PPC_STL r22, VCPU_GPR(R22)(r4) 154 - rlwimi r8, r10, EPC_EPID_SHIFT, EPC_EPID 155 133 PPC_STL r23, VCPU_GPR(R23)(r4) 156 134 PPC_STL r24, VCPU_GPR(R24)(r4) 157 135 PPC_STL r25, VCPU_GPR(R25)(r4) ··· 137 163 PPC_STL r29, VCPU_GPR(R29)(r4) 138 164 PPC_STL r30, VCPU_GPR(R30)(r4) 139 165 PPC_STL r31, VCPU_GPR(R31)(r4) 140 - mtspr SPRN_EPLC, r8 141 - 142 - /* disable preemption, so we are sure we hit the fixup handler */ 143 - CURRENT_THREAD_INFO(r8, r1) 144 - li r7, 1 145 - stw r7, TI_PREEMPT(r8) 146 - 147 - isync 148 166 149 167 /* 150 - * In case the read goes wrong, we catch it and write an invalid value 151 - * in LAST_INST instead. 168 + * We don't use external PID support. lwepx faults would need to be 169 + * handled by KVM and this implies aditional code in DO_KVM (for 170 + * DTB_MISS, DSI and LRAT) to check ESR[EPID] and EPLC[EGS] which 171 + * is too intrusive for the host. Get last instuction in 172 + * kvmppc_get_last_inst(). 152 173 */ 153 - 1: lwepx r9, 0, r5 154 - 2: 155 - .section .fixup, "ax" 156 - 3: li r9, KVM_INST_FETCH_FAILED 157 - b 2b 158 - .previous 159 - .section __ex_table,"a" 160 - PPC_LONG_ALIGN 161 - PPC_LONG 1b,3b 162 - .previous 163 - 164 - mtspr SPRN_EPLC, r3 165 - li r7, 0 166 - stw r7, TI_PREEMPT(r8) 174 + li r9, KVM_INST_FETCH_FAILED 167 175 stw r9, VCPU_LAST_INST(r4) 168 176 .endif 169 177 ··· 397 441 #ifdef CONFIG_64BIT 398 442 PPC_LL r3, PACA_SPRG_VDSO(r13) 399 443 #endif 444 + mfspr r5, SPRN_SPRG9 400 445 PPC_STD(r6, VCPU_SHARED_SPRG4, r11) 401 446 mfspr r8, SPRN_SPRG6 402 447 PPC_STD(r7, VCPU_SHARED_SPRG5, r11) ··· 405 448 #ifdef CONFIG_64BIT 406 449 mtspr SPRN_SPRG_VDSO_WRITE, r3 407 450 #endif 451 + PPC_STD(r5, VCPU_SPRG9, r4) 408 452 PPC_STD(r8, VCPU_SHARED_SPRG6, r11) 409 453 mfxer r3 410 454 PPC_STD(r9, VCPU_SHARED_SPRG7, r11) ··· 640 682 mtspr SPRN_SPRG5W, r6 641 683 PPC_LD(r8, VCPU_SHARED_SPRG7, r11) 642 684 mtspr SPRN_SPRG6W, r7 685 + PPC_LD(r5, VCPU_SPRG9, r4) 643 686 mtspr SPRN_SPRG7W, r8 687 + mtspr SPRN_SPRG9, r5 644 688 645 689 /* Load some guest volatiles. */ 646 690 PPC_LL r3, VCPU_LR(r4)
+12
arch/powerpc/kvm/e500_emulate.c
··· 250 250 spr_val); 251 251 break; 252 252 253 + case SPRN_PWRMGTCR0: 254 + /* 255 + * Guest relies on host power management configurations 256 + * Treat the request as a general store 257 + */ 258 + vcpu->arch.pwrmgtcr0 = spr_val; 259 + break; 260 + 253 261 /* extra exceptions */ 254 262 case SPRN_IVOR32: 255 263 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL] = spr_val; ··· 374 366 * category is disabled in the VM. Give them a chance to live. 375 367 */ 376 368 *spr_val = vcpu->arch.eptcfg; 369 + break; 370 + 371 + case SPRN_PWRMGTCR0: 372 + *spr_val = vcpu->arch.pwrmgtcr0; 377 373 break; 378 374 379 375 /* extra exceptions */
+102
arch/powerpc/kvm/e500_mmu_host.c
··· 107 107 { 108 108 unsigned long flags; 109 109 u32 mas0; 110 + u32 mas4; 110 111 111 112 local_irq_save(flags); 112 113 mtspr(SPRN_MAS6, 0); 114 + mas4 = mfspr(SPRN_MAS4); 115 + mtspr(SPRN_MAS4, mas4 & ~MAS4_TLBSEL_MASK); 113 116 asm volatile("tlbsx 0, %0" : : "b" (eaddr & ~CONFIG_PAGE_OFFSET)); 114 117 mas0 = mfspr(SPRN_MAS0); 118 + mtspr(SPRN_MAS4, mas4); 115 119 local_irq_restore(flags); 116 120 117 121 return mas0; ··· 610 606 break; 611 607 } 612 608 } 609 + 610 + #ifdef CONFIG_KVM_BOOKE_HV 611 + int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, enum instruction_type type, 612 + u32 *instr) 613 + { 614 + gva_t geaddr; 615 + hpa_t addr; 616 + hfn_t pfn; 617 + hva_t eaddr; 618 + u32 mas1, mas2, mas3; 619 + u64 mas7_mas3; 620 + struct page *page; 621 + unsigned int addr_space, psize_shift; 622 + bool pr; 623 + unsigned long flags; 624 + 625 + /* Search TLB for guest pc to get the real address */ 626 + geaddr = kvmppc_get_pc(vcpu); 627 + 628 + addr_space = (vcpu->arch.shared->msr & MSR_IS) >> MSR_IR_LG; 629 + 630 + local_irq_save(flags); 631 + mtspr(SPRN_MAS6, (vcpu->arch.pid << MAS6_SPID_SHIFT) | addr_space); 632 + mtspr(SPRN_MAS5, MAS5_SGS | vcpu->kvm->arch.lpid); 633 + asm volatile("tlbsx 0, %[geaddr]\n" : : 634 + [geaddr] "r" (geaddr)); 635 + mtspr(SPRN_MAS5, 0); 636 + mtspr(SPRN_MAS8, 0); 637 + mas1 = mfspr(SPRN_MAS1); 638 + mas2 = mfspr(SPRN_MAS2); 639 + mas3 = mfspr(SPRN_MAS3); 640 + #ifdef CONFIG_64BIT 641 + mas7_mas3 = mfspr(SPRN_MAS7_MAS3); 642 + #else 643 + mas7_mas3 = ((u64)mfspr(SPRN_MAS7) << 32) | mas3; 644 + #endif 645 + local_irq_restore(flags); 646 + 647 + /* 648 + * If the TLB entry for guest pc was evicted, return to the guest. 649 + * There are high chances to find a valid TLB entry next time. 650 + */ 651 + if (!(mas1 & MAS1_VALID)) 652 + return EMULATE_AGAIN; 653 + 654 + /* 655 + * Another thread may rewrite the TLB entry in parallel, don't 656 + * execute from the address if the execute permission is not set 657 + */ 658 + pr = vcpu->arch.shared->msr & MSR_PR; 659 + if (unlikely((pr && !(mas3 & MAS3_UX)) || 660 + (!pr && !(mas3 & MAS3_SX)))) { 661 + pr_err_ratelimited( 662 + "%s: Instuction emulation from guest addres %08lx without execute permission\n", 663 + __func__, geaddr); 664 + return EMULATE_AGAIN; 665 + } 666 + 667 + /* 668 + * The real address will be mapped by a cacheable, memory coherent, 669 + * write-back page. Check for mismatches when LRAT is used. 670 + */ 671 + if (has_feature(vcpu, VCPU_FTR_MMU_V2) && 672 + unlikely((mas2 & MAS2_I) || (mas2 & MAS2_W) || !(mas2 & MAS2_M))) { 673 + pr_err_ratelimited( 674 + "%s: Instuction emulation from guest addres %08lx mismatches storage attributes\n", 675 + __func__, geaddr); 676 + return EMULATE_AGAIN; 677 + } 678 + 679 + /* Get pfn */ 680 + psize_shift = MAS1_GET_TSIZE(mas1) + 10; 681 + addr = (mas7_mas3 & (~0ULL << psize_shift)) | 682 + (geaddr & ((1ULL << psize_shift) - 1ULL)); 683 + pfn = addr >> PAGE_SHIFT; 684 + 685 + /* Guard against emulation from devices area */ 686 + if (unlikely(!page_is_ram(pfn))) { 687 + pr_err_ratelimited("%s: Instruction emulation from non-RAM host addres %08llx is not supported\n", 688 + __func__, addr); 689 + return EMULATE_AGAIN; 690 + } 691 + 692 + /* Map a page and get guest's instruction */ 693 + page = pfn_to_page(pfn); 694 + eaddr = (unsigned long)kmap_atomic(page); 695 + *instr = *(u32 *)(eaddr | (unsigned long)(addr & ~PAGE_MASK)); 696 + kunmap_atomic((u32 *)eaddr); 697 + 698 + return EMULATE_DONE; 699 + } 700 + #else 701 + int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, enum instruction_type type, 702 + u32 *instr) 703 + { 704 + return EMULATE_AGAIN; 705 + } 706 + #endif 613 707 614 708 /************* MMU Notifiers *************/ 615 709
+23 -5
arch/powerpc/kvm/e500mc.c
··· 110 110 { 111 111 } 112 112 113 - static DEFINE_PER_CPU(struct kvm_vcpu *, last_vcpu_on_cpu); 113 + static DEFINE_PER_CPU(struct kvm_vcpu *[KVMPPC_NR_LPIDS], last_vcpu_of_lpid); 114 114 115 115 static void kvmppc_core_vcpu_load_e500mc(struct kvm_vcpu *vcpu, int cpu) 116 116 { ··· 141 141 mtspr(SPRN_GESR, vcpu->arch.shared->esr); 142 142 143 143 if (vcpu->arch.oldpir != mfspr(SPRN_PIR) || 144 - __get_cpu_var(last_vcpu_on_cpu) != vcpu) { 144 + __get_cpu_var(last_vcpu_of_lpid)[vcpu->kvm->arch.lpid] != vcpu) { 145 145 kvmppc_e500_tlbil_all(vcpu_e500); 146 - __get_cpu_var(last_vcpu_on_cpu) = vcpu; 146 + __get_cpu_var(last_vcpu_of_lpid)[vcpu->kvm->arch.lpid] = vcpu; 147 147 } 148 148 149 149 kvmppc_load_guest_fp(vcpu); ··· 267 267 static int kvmppc_get_one_reg_e500mc(struct kvm_vcpu *vcpu, u64 id, 268 268 union kvmppc_one_reg *val) 269 269 { 270 - int r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val); 270 + int r = 0; 271 + 272 + switch (id) { 273 + case KVM_REG_PPC_SPRG9: 274 + *val = get_reg_val(id, vcpu->arch.sprg9); 275 + break; 276 + default: 277 + r = kvmppc_get_one_reg_e500_tlb(vcpu, id, val); 278 + } 279 + 271 280 return r; 272 281 } 273 282 274 283 static int kvmppc_set_one_reg_e500mc(struct kvm_vcpu *vcpu, u64 id, 275 284 union kvmppc_one_reg *val) 276 285 { 277 - int r = kvmppc_set_one_reg_e500_tlb(vcpu, id, val); 286 + int r = 0; 287 + 288 + switch (id) { 289 + case KVM_REG_PPC_SPRG9: 290 + vcpu->arch.sprg9 = set_reg_val(id, *val); 291 + break; 292 + default: 293 + r = kvmppc_set_one_reg_e500_tlb(vcpu, id, val); 294 + } 295 + 278 296 return r; 279 297 } 280 298
+11 -195
arch/powerpc/kvm/emulate.c
··· 207 207 return emulated; 208 208 } 209 209 210 - /* XXX to do: 211 - * lhax 212 - * lhaux 213 - * lswx 214 - * lswi 215 - * stswx 216 - * stswi 217 - * lha 218 - * lhau 219 - * lmw 220 - * stmw 221 - * 222 - */ 223 210 /* XXX Should probably auto-generate instruction decoding for a particular core 224 211 * from opcode tables in the future. */ 225 212 int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) 226 213 { 227 - u32 inst = kvmppc_get_last_inst(vcpu); 228 - int ra = get_ra(inst); 229 - int rs = get_rs(inst); 230 - int rt = get_rt(inst); 231 - int sprn = get_sprn(inst); 232 - enum emulation_result emulated = EMULATE_DONE; 214 + u32 inst; 215 + int rs, rt, sprn; 216 + enum emulation_result emulated; 233 217 int advance = 1; 234 218 235 219 /* this default type might be overwritten by subcategories */ 236 220 kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS); 237 221 222 + emulated = kvmppc_get_last_inst(vcpu, false, &inst); 223 + if (emulated != EMULATE_DONE) 224 + return emulated; 225 + 238 226 pr_debug("Emulating opcode %d / %d\n", get_op(inst), get_xop(inst)); 227 + 228 + rs = get_rs(inst); 229 + rt = get_rt(inst); 230 + sprn = get_sprn(inst); 239 231 240 232 switch (get_op(inst)) { 241 233 case OP_TRAP: ··· 256 264 #endif 257 265 advance = 0; 258 266 break; 259 - case OP_31_XOP_LWZX: 260 - emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); 261 - break; 262 - 263 - case OP_31_XOP_LBZX: 264 - emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 265 - break; 266 - 267 - case OP_31_XOP_LBZUX: 268 - emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 269 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 270 - break; 271 - 272 - case OP_31_XOP_STWX: 273 - emulated = kvmppc_handle_store(run, vcpu, 274 - kvmppc_get_gpr(vcpu, rs), 275 - 4, 1); 276 - break; 277 - 278 - case OP_31_XOP_STBX: 279 - emulated = kvmppc_handle_store(run, vcpu, 280 - kvmppc_get_gpr(vcpu, rs), 281 - 1, 1); 282 - break; 283 - 284 - case OP_31_XOP_STBUX: 285 - emulated = kvmppc_handle_store(run, vcpu, 286 - kvmppc_get_gpr(vcpu, rs), 287 - 1, 1); 288 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 289 - break; 290 - 291 - case OP_31_XOP_LHAX: 292 - emulated = kvmppc_handle_loads(run, vcpu, rt, 2, 1); 293 - break; 294 - 295 - case OP_31_XOP_LHZX: 296 - emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 297 - break; 298 - 299 - case OP_31_XOP_LHZUX: 300 - emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 301 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 302 - break; 303 267 304 268 case OP_31_XOP_MFSPR: 305 269 emulated = kvmppc_emulate_mfspr(vcpu, sprn, rt); 306 - break; 307 - 308 - case OP_31_XOP_STHX: 309 - emulated = kvmppc_handle_store(run, vcpu, 310 - kvmppc_get_gpr(vcpu, rs), 311 - 2, 1); 312 - break; 313 - 314 - case OP_31_XOP_STHUX: 315 - emulated = kvmppc_handle_store(run, vcpu, 316 - kvmppc_get_gpr(vcpu, rs), 317 - 2, 1); 318 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 319 270 break; 320 271 321 272 case OP_31_XOP_MTSPR: 322 273 emulated = kvmppc_emulate_mtspr(vcpu, sprn, rs); 323 274 break; 324 275 325 - case OP_31_XOP_DCBST: 326 - case OP_31_XOP_DCBF: 327 - case OP_31_XOP_DCBI: 328 - /* Do nothing. The guest is performing dcbi because 329 - * hardware DMA is not snooped by the dcache, but 330 - * emulated DMA either goes through the dcache as 331 - * normal writes, or the host kernel has handled dcache 332 - * coherence. */ 333 - break; 334 - 335 - case OP_31_XOP_LWBRX: 336 - emulated = kvmppc_handle_load(run, vcpu, rt, 4, 0); 337 - break; 338 - 339 276 case OP_31_XOP_TLBSYNC: 340 - break; 341 - 342 - case OP_31_XOP_STWBRX: 343 - emulated = kvmppc_handle_store(run, vcpu, 344 - kvmppc_get_gpr(vcpu, rs), 345 - 4, 0); 346 - break; 347 - 348 - case OP_31_XOP_LHBRX: 349 - emulated = kvmppc_handle_load(run, vcpu, rt, 2, 0); 350 - break; 351 - 352 - case OP_31_XOP_STHBRX: 353 - emulated = kvmppc_handle_store(run, vcpu, 354 - kvmppc_get_gpr(vcpu, rs), 355 - 2, 0); 356 277 break; 357 278 358 279 default: 359 280 /* Attempt core-specific emulation below. */ 360 281 emulated = EMULATE_FAIL; 361 282 } 362 - break; 363 - 364 - case OP_LWZ: 365 - emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); 366 - break; 367 - 368 - /* TBD: Add support for other 64 bit load variants like ldu, ldux, ldx etc. */ 369 - case OP_LD: 370 - rt = get_rt(inst); 371 - emulated = kvmppc_handle_load(run, vcpu, rt, 8, 1); 372 - break; 373 - 374 - case OP_LWZU: 375 - emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); 376 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 377 - break; 378 - 379 - case OP_LBZ: 380 - emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 381 - break; 382 - 383 - case OP_LBZU: 384 - emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 385 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 386 - break; 387 - 388 - case OP_STW: 389 - emulated = kvmppc_handle_store(run, vcpu, 390 - kvmppc_get_gpr(vcpu, rs), 391 - 4, 1); 392 - break; 393 - 394 - /* TBD: Add support for other 64 bit store variants like stdu, stdux, stdx etc. */ 395 - case OP_STD: 396 - rs = get_rs(inst); 397 - emulated = kvmppc_handle_store(run, vcpu, 398 - kvmppc_get_gpr(vcpu, rs), 399 - 8, 1); 400 - break; 401 - 402 - case OP_STWU: 403 - emulated = kvmppc_handle_store(run, vcpu, 404 - kvmppc_get_gpr(vcpu, rs), 405 - 4, 1); 406 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 407 - break; 408 - 409 - case OP_STB: 410 - emulated = kvmppc_handle_store(run, vcpu, 411 - kvmppc_get_gpr(vcpu, rs), 412 - 1, 1); 413 - break; 414 - 415 - case OP_STBU: 416 - emulated = kvmppc_handle_store(run, vcpu, 417 - kvmppc_get_gpr(vcpu, rs), 418 - 1, 1); 419 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 420 - break; 421 - 422 - case OP_LHZ: 423 - emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 424 - break; 425 - 426 - case OP_LHZU: 427 - emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 428 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 429 - break; 430 - 431 - case OP_LHA: 432 - emulated = kvmppc_handle_loads(run, vcpu, rt, 2, 1); 433 - break; 434 - 435 - case OP_LHAU: 436 - emulated = kvmppc_handle_loads(run, vcpu, rt, 2, 1); 437 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 438 - break; 439 - 440 - case OP_STH: 441 - emulated = kvmppc_handle_store(run, vcpu, 442 - kvmppc_get_gpr(vcpu, rs), 443 - 2, 1); 444 - break; 445 - 446 - case OP_STHU: 447 - emulated = kvmppc_handle_store(run, vcpu, 448 - kvmppc_get_gpr(vcpu, rs), 449 - 2, 1); 450 - kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 451 283 break; 452 284 453 285 default:
+272
arch/powerpc/kvm/emulate_loadstore.c
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify 3 + * it under the terms of the GNU General Public License, version 2, as 4 + * published by the Free Software Foundation. 5 + * 6 + * This program is distributed in the hope that it will be useful, 7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 + * GNU General Public License for more details. 10 + * 11 + * You should have received a copy of the GNU General Public License 12 + * along with this program; if not, write to the Free Software 13 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 + * 15 + * Copyright IBM Corp. 2007 16 + * Copyright 2011 Freescale Semiconductor, Inc. 17 + * 18 + * Authors: Hollis Blanchard <hollisb@us.ibm.com> 19 + */ 20 + 21 + #include <linux/jiffies.h> 22 + #include <linux/hrtimer.h> 23 + #include <linux/types.h> 24 + #include <linux/string.h> 25 + #include <linux/kvm_host.h> 26 + #include <linux/clockchips.h> 27 + 28 + #include <asm/reg.h> 29 + #include <asm/time.h> 30 + #include <asm/byteorder.h> 31 + #include <asm/kvm_ppc.h> 32 + #include <asm/disassemble.h> 33 + #include <asm/ppc-opcode.h> 34 + #include "timing.h" 35 + #include "trace.h" 36 + 37 + /* XXX to do: 38 + * lhax 39 + * lhaux 40 + * lswx 41 + * lswi 42 + * stswx 43 + * stswi 44 + * lha 45 + * lhau 46 + * lmw 47 + * stmw 48 + * 49 + */ 50 + int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) 51 + { 52 + struct kvm_run *run = vcpu->run; 53 + u32 inst; 54 + int ra, rs, rt; 55 + enum emulation_result emulated; 56 + int advance = 1; 57 + 58 + /* this default type might be overwritten by subcategories */ 59 + kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS); 60 + 61 + emulated = kvmppc_get_last_inst(vcpu, false, &inst); 62 + if (emulated != EMULATE_DONE) 63 + return emulated; 64 + 65 + ra = get_ra(inst); 66 + rs = get_rs(inst); 67 + rt = get_rt(inst); 68 + 69 + switch (get_op(inst)) { 70 + case 31: 71 + switch (get_xop(inst)) { 72 + case OP_31_XOP_LWZX: 73 + emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); 74 + break; 75 + 76 + case OP_31_XOP_LBZX: 77 + emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 78 + break; 79 + 80 + case OP_31_XOP_LBZUX: 81 + emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 82 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 83 + break; 84 + 85 + case OP_31_XOP_STWX: 86 + emulated = kvmppc_handle_store(run, vcpu, 87 + kvmppc_get_gpr(vcpu, rs), 88 + 4, 1); 89 + break; 90 + 91 + case OP_31_XOP_STBX: 92 + emulated = kvmppc_handle_store(run, vcpu, 93 + kvmppc_get_gpr(vcpu, rs), 94 + 1, 1); 95 + break; 96 + 97 + case OP_31_XOP_STBUX: 98 + emulated = kvmppc_handle_store(run, vcpu, 99 + kvmppc_get_gpr(vcpu, rs), 100 + 1, 1); 101 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 102 + break; 103 + 104 + case OP_31_XOP_LHAX: 105 + emulated = kvmppc_handle_loads(run, vcpu, rt, 2, 1); 106 + break; 107 + 108 + case OP_31_XOP_LHZX: 109 + emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 110 + break; 111 + 112 + case OP_31_XOP_LHZUX: 113 + emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 114 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 115 + break; 116 + 117 + case OP_31_XOP_STHX: 118 + emulated = kvmppc_handle_store(run, vcpu, 119 + kvmppc_get_gpr(vcpu, rs), 120 + 2, 1); 121 + break; 122 + 123 + case OP_31_XOP_STHUX: 124 + emulated = kvmppc_handle_store(run, vcpu, 125 + kvmppc_get_gpr(vcpu, rs), 126 + 2, 1); 127 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 128 + break; 129 + 130 + case OP_31_XOP_DCBST: 131 + case OP_31_XOP_DCBF: 132 + case OP_31_XOP_DCBI: 133 + /* Do nothing. The guest is performing dcbi because 134 + * hardware DMA is not snooped by the dcache, but 135 + * emulated DMA either goes through the dcache as 136 + * normal writes, or the host kernel has handled dcache 137 + * coherence. */ 138 + break; 139 + 140 + case OP_31_XOP_LWBRX: 141 + emulated = kvmppc_handle_load(run, vcpu, rt, 4, 0); 142 + break; 143 + 144 + case OP_31_XOP_STWBRX: 145 + emulated = kvmppc_handle_store(run, vcpu, 146 + kvmppc_get_gpr(vcpu, rs), 147 + 4, 0); 148 + break; 149 + 150 + case OP_31_XOP_LHBRX: 151 + emulated = kvmppc_handle_load(run, vcpu, rt, 2, 0); 152 + break; 153 + 154 + case OP_31_XOP_STHBRX: 155 + emulated = kvmppc_handle_store(run, vcpu, 156 + kvmppc_get_gpr(vcpu, rs), 157 + 2, 0); 158 + break; 159 + 160 + default: 161 + emulated = EMULATE_FAIL; 162 + break; 163 + } 164 + break; 165 + 166 + case OP_LWZ: 167 + emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); 168 + break; 169 + 170 + /* TBD: Add support for other 64 bit load variants like ldu, ldux, ldx etc. */ 171 + case OP_LD: 172 + rt = get_rt(inst); 173 + emulated = kvmppc_handle_load(run, vcpu, rt, 8, 1); 174 + break; 175 + 176 + case OP_LWZU: 177 + emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1); 178 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 179 + break; 180 + 181 + case OP_LBZ: 182 + emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 183 + break; 184 + 185 + case OP_LBZU: 186 + emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1); 187 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 188 + break; 189 + 190 + case OP_STW: 191 + emulated = kvmppc_handle_store(run, vcpu, 192 + kvmppc_get_gpr(vcpu, rs), 193 + 4, 1); 194 + break; 195 + 196 + /* TBD: Add support for other 64 bit store variants like stdu, stdux, stdx etc. */ 197 + case OP_STD: 198 + rs = get_rs(inst); 199 + emulated = kvmppc_handle_store(run, vcpu, 200 + kvmppc_get_gpr(vcpu, rs), 201 + 8, 1); 202 + break; 203 + 204 + case OP_STWU: 205 + emulated = kvmppc_handle_store(run, vcpu, 206 + kvmppc_get_gpr(vcpu, rs), 207 + 4, 1); 208 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 209 + break; 210 + 211 + case OP_STB: 212 + emulated = kvmppc_handle_store(run, vcpu, 213 + kvmppc_get_gpr(vcpu, rs), 214 + 1, 1); 215 + break; 216 + 217 + case OP_STBU: 218 + emulated = kvmppc_handle_store(run, vcpu, 219 + kvmppc_get_gpr(vcpu, rs), 220 + 1, 1); 221 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 222 + break; 223 + 224 + case OP_LHZ: 225 + emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 226 + break; 227 + 228 + case OP_LHZU: 229 + emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1); 230 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 231 + break; 232 + 233 + case OP_LHA: 234 + emulated = kvmppc_handle_loads(run, vcpu, rt, 2, 1); 235 + break; 236 + 237 + case OP_LHAU: 238 + emulated = kvmppc_handle_loads(run, vcpu, rt, 2, 1); 239 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 240 + break; 241 + 242 + case OP_STH: 243 + emulated = kvmppc_handle_store(run, vcpu, 244 + kvmppc_get_gpr(vcpu, rs), 245 + 2, 1); 246 + break; 247 + 248 + case OP_STHU: 249 + emulated = kvmppc_handle_store(run, vcpu, 250 + kvmppc_get_gpr(vcpu, rs), 251 + 2, 1); 252 + kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed); 253 + break; 254 + 255 + default: 256 + emulated = EMULATE_FAIL; 257 + break; 258 + } 259 + 260 + if (emulated == EMULATE_FAIL) { 261 + advance = 0; 262 + kvmppc_core_queue_program(vcpu, 0); 263 + } 264 + 265 + trace_kvm_ppc_instr(inst, kvmppc_get_pc(vcpu), emulated); 266 + 267 + /* Advance past emulated instruction. */ 268 + if (advance) 269 + kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4); 270 + 271 + return emulated; 272 + }
+1 -3
arch/powerpc/kvm/mpic.c
··· 1826 1826 return 0; 1827 1827 } 1828 1828 1829 - int kvm_set_routing_entry(struct kvm_irq_routing_table *rt, 1830 - struct kvm_kernel_irq_routing_entry *e, 1829 + int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, 1831 1830 const struct kvm_irq_routing_entry *ue) 1832 1831 { 1833 1832 int r = -EINVAL; ··· 1838 1839 e->irqchip.pin = ue->u.irqchip.pin; 1839 1840 if (e->irqchip.pin >= KVM_IRQCHIP_NUM_PINS) 1840 1841 goto out; 1841 - rt->chip[ue->u.irqchip.irqchip][e->irqchip.pin] = ue->gsi; 1842 1842 break; 1843 1843 case KVM_IRQ_ROUTING_MSI: 1844 1844 e->set = kvm_set_msi;
+163 -18
arch/powerpc/kvm/powerpc.c
··· 190 190 vcpu->arch.magic_page_pa = param1 & ~0xfffULL; 191 191 vcpu->arch.magic_page_ea = param2 & ~0xfffULL; 192 192 193 + #ifdef CONFIG_PPC_64K_PAGES 194 + /* 195 + * Make sure our 4k magic page is in the same window of a 64k 196 + * page within the guest and within the host's page. 197 + */ 198 + if ((vcpu->arch.magic_page_pa & 0xf000) != 199 + ((ulong)vcpu->arch.shared & 0xf000)) { 200 + void *old_shared = vcpu->arch.shared; 201 + ulong shared = (ulong)vcpu->arch.shared; 202 + void *new_shared; 203 + 204 + shared &= PAGE_MASK; 205 + shared |= vcpu->arch.magic_page_pa & 0xf000; 206 + new_shared = (void*)shared; 207 + memcpy(new_shared, old_shared, 0x1000); 208 + vcpu->arch.shared = new_shared; 209 + } 210 + #endif 211 + 193 212 r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7; 194 213 195 214 r = EV_SUCCESS; ··· 217 198 case KVM_HCALL_TOKEN(KVM_HC_FEATURES): 218 199 r = EV_SUCCESS; 219 200 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2) 220 - /* XXX Missing magic page on 44x */ 221 201 r2 |= (1 << KVM_FEATURE_MAGIC_PAGE); 222 202 #endif 223 203 ··· 272 254 enum emulation_result er; 273 255 int r; 274 256 275 - er = kvmppc_emulate_instruction(run, vcpu); 257 + er = kvmppc_emulate_loadstore(vcpu); 276 258 switch (er) { 277 259 case EMULATE_DONE: 278 260 /* Future optimization: only reload non-volatiles if they were 279 261 * actually modified. */ 280 262 r = RESUME_GUEST_NV; 263 + break; 264 + case EMULATE_AGAIN: 265 + r = RESUME_GUEST; 281 266 break; 282 267 case EMULATE_DO_MMIO: 283 268 run->exit_reason = KVM_EXIT_MMIO; ··· 291 270 r = RESUME_HOST_NV; 292 271 break; 293 272 case EMULATE_FAIL: 273 + { 274 + u32 last_inst; 275 + 276 + kvmppc_get_last_inst(vcpu, false, &last_inst); 294 277 /* XXX Deliver Program interrupt to guest. */ 295 - printk(KERN_EMERG "%s: emulation failed (%08x)\n", __func__, 296 - kvmppc_get_last_inst(vcpu)); 278 + pr_emerg("%s: emulation failed (%08x)\n", __func__, last_inst); 297 279 r = RESUME_HOST; 298 280 break; 281 + } 299 282 default: 300 283 WARN_ON(1); 301 284 r = RESUME_GUEST; ··· 308 283 return r; 309 284 } 310 285 EXPORT_SYMBOL_GPL(kvmppc_emulate_mmio); 286 + 287 + int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 288 + bool data) 289 + { 290 + ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM & PAGE_MASK; 291 + struct kvmppc_pte pte; 292 + int r; 293 + 294 + vcpu->stat.st++; 295 + 296 + r = kvmppc_xlate(vcpu, *eaddr, data ? XLATE_DATA : XLATE_INST, 297 + XLATE_WRITE, &pte); 298 + if (r < 0) 299 + return r; 300 + 301 + *eaddr = pte.raddr; 302 + 303 + if (!pte.may_write) 304 + return -EPERM; 305 + 306 + /* Magic page override */ 307 + if (kvmppc_supports_magic_page(vcpu) && mp_pa && 308 + ((pte.raddr & KVM_PAM & PAGE_MASK) == mp_pa) && 309 + !(kvmppc_get_msr(vcpu) & MSR_PR)) { 310 + void *magic = vcpu->arch.shared; 311 + magic += pte.eaddr & 0xfff; 312 + memcpy(magic, ptr, size); 313 + return EMULATE_DONE; 314 + } 315 + 316 + if (kvm_write_guest(vcpu->kvm, pte.raddr, ptr, size)) 317 + return EMULATE_DO_MMIO; 318 + 319 + return EMULATE_DONE; 320 + } 321 + EXPORT_SYMBOL_GPL(kvmppc_st); 322 + 323 + int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, 324 + bool data) 325 + { 326 + ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM & PAGE_MASK; 327 + struct kvmppc_pte pte; 328 + int rc; 329 + 330 + vcpu->stat.ld++; 331 + 332 + rc = kvmppc_xlate(vcpu, *eaddr, data ? XLATE_DATA : XLATE_INST, 333 + XLATE_READ, &pte); 334 + if (rc) 335 + return rc; 336 + 337 + *eaddr = pte.raddr; 338 + 339 + if (!pte.may_read) 340 + return -EPERM; 341 + 342 + if (!data && !pte.may_execute) 343 + return -ENOEXEC; 344 + 345 + /* Magic page override */ 346 + if (kvmppc_supports_magic_page(vcpu) && mp_pa && 347 + ((pte.raddr & KVM_PAM & PAGE_MASK) == mp_pa) && 348 + !(kvmppc_get_msr(vcpu) & MSR_PR)) { 349 + void *magic = vcpu->arch.shared; 350 + magic += pte.eaddr & 0xfff; 351 + memcpy(ptr, magic, size); 352 + return EMULATE_DONE; 353 + } 354 + 355 + if (kvm_read_guest(vcpu->kvm, pte.raddr, ptr, size)) 356 + return EMULATE_DO_MMIO; 357 + 358 + return EMULATE_DONE; 359 + } 360 + EXPORT_SYMBOL_GPL(kvmppc_ld); 311 361 312 362 int kvm_arch_hardware_enable(void *garbage) 313 363 { ··· 466 366 { 467 367 } 468 368 469 - int kvm_dev_ioctl_check_extension(long ext) 369 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) 470 370 { 471 371 int r; 472 - /* FIXME!! 473 - * Should some of this be vm ioctl ? is it possible now ? 474 - */ 372 + /* Assume we're using HV mode when the HV module is loaded */ 475 373 int hv_enabled = kvmppc_hv_ops ? 1 : 0; 374 + 375 + if (kvm) { 376 + /* 377 + * Hooray - we know which VM type we're running on. Depend on 378 + * that rather than the guess above. 379 + */ 380 + hv_enabled = is_kvmppc_hv_enabled(kvm); 381 + } 476 382 477 383 switch (ext) { 478 384 #ifdef CONFIG_BOOKE ··· 493 387 case KVM_CAP_PPC_UNSET_IRQ: 494 388 case KVM_CAP_PPC_IRQ_LEVEL: 495 389 case KVM_CAP_ENABLE_CAP: 390 + case KVM_CAP_ENABLE_CAP_VM: 496 391 case KVM_CAP_ONE_REG: 497 392 case KVM_CAP_IOEVENTFD: 498 393 case KVM_CAP_DEVICE_CTRL: ··· 524 417 case KVM_CAP_PPC_ALLOC_HTAB: 525 418 case KVM_CAP_PPC_RTAS: 526 419 case KVM_CAP_PPC_FIXUP_HCALL: 420 + case KVM_CAP_PPC_ENABLE_HCALL: 527 421 #ifdef CONFIG_KVM_XICS 528 422 case KVM_CAP_IRQ_XICS: 529 423 #endif ··· 743 635 #endif 744 636 } 745 637 746 - static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu, 747 - struct kvm_run *run) 748 - { 749 - kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, run->dcr.data); 750 - } 751 - 752 638 static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu, 753 639 struct kvm_run *run) 754 640 { ··· 939 837 if (!vcpu->mmio_is_write) 940 838 kvmppc_complete_mmio_load(vcpu, run); 941 839 vcpu->mmio_needed = 0; 942 - } else if (vcpu->arch.dcr_needed) { 943 - if (!vcpu->arch.dcr_is_write) 944 - kvmppc_complete_dcr_load(vcpu, run); 945 - vcpu->arch.dcr_needed = 0; 946 840 } else if (vcpu->arch.osi_needed) { 947 841 u64 *gprs = run->osi.gprs; 948 842 int i; ··· 1197 1099 return 0; 1198 1100 } 1199 1101 1102 + 1103 + static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, 1104 + struct kvm_enable_cap *cap) 1105 + { 1106 + int r; 1107 + 1108 + if (cap->flags) 1109 + return -EINVAL; 1110 + 1111 + switch (cap->cap) { 1112 + #ifdef CONFIG_KVM_BOOK3S_64_HANDLER 1113 + case KVM_CAP_PPC_ENABLE_HCALL: { 1114 + unsigned long hcall = cap->args[0]; 1115 + 1116 + r = -EINVAL; 1117 + if (hcall > MAX_HCALL_OPCODE || (hcall & 3) || 1118 + cap->args[1] > 1) 1119 + break; 1120 + if (!kvmppc_book3s_hcall_implemented(kvm, hcall)) 1121 + break; 1122 + if (cap->args[1]) 1123 + set_bit(hcall / 4, kvm->arch.enabled_hcalls); 1124 + else 1125 + clear_bit(hcall / 4, kvm->arch.enabled_hcalls); 1126 + r = 0; 1127 + break; 1128 + } 1129 + #endif 1130 + default: 1131 + r = -EINVAL; 1132 + break; 1133 + } 1134 + 1135 + return r; 1136 + } 1137 + 1200 1138 long kvm_arch_vm_ioctl(struct file *filp, 1201 1139 unsigned int ioctl, unsigned long arg) 1202 1140 { ··· 1250 1116 goto out; 1251 1117 } 1252 1118 1119 + break; 1120 + } 1121 + case KVM_ENABLE_CAP: 1122 + { 1123 + struct kvm_enable_cap cap; 1124 + r = -EFAULT; 1125 + if (copy_from_user(&cap, argp, sizeof(cap))) 1126 + goto out; 1127 + r = kvm_vm_ioctl_enable_cap(kvm, &cap); 1253 1128 break; 1254 1129 } 1255 1130 #ifdef CONFIG_PPC_BOOK3S_64 ··· 1347 1204 { 1348 1205 1349 1206 } 1207 + 1208 + EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_ppc_instr);
-1
arch/powerpc/kvm/timing.c
··· 110 110 111 111 static const char *kvm_exit_names[__NUMBER_OF_KVM_EXIT_TYPES] = { 112 112 [MMIO_EXITS] = "MMIO", 113 - [DCR_EXITS] = "DCR", 114 113 [SIGNAL_EXITS] = "SIGNAL", 115 114 [ITLB_REAL_MISS_EXITS] = "ITLBREAL", 116 115 [ITLB_VIRT_MISS_EXITS] = "ITLBVIRT",
-3
arch/powerpc/kvm/timing.h
··· 63 63 case EMULATED_INST_EXITS: 64 64 vcpu->stat.emulated_inst_exits++; 65 65 break; 66 - case DCR_EXITS: 67 - vcpu->stat.dcr_exits++; 68 - break; 69 66 case DSI_EXITS: 70 67 vcpu->stat.dsi_exits++; 71 68 break;
+1
arch/s390/kvm/Kconfig
··· 26 26 select KVM_ASYNC_PF 27 27 select KVM_ASYNC_PF_SYNC 28 28 select HAVE_KVM_IRQCHIP 29 + select HAVE_KVM_IRQFD 29 30 select HAVE_KVM_IRQ_ROUTING 30 31 ---help--- 31 32 Support hosting paravirtualized guest machines using the SIE
+1 -2
arch/s390/kvm/interrupt.c
··· 1556 1556 return ret; 1557 1557 } 1558 1558 1559 - int kvm_set_routing_entry(struct kvm_irq_routing_table *rt, 1560 - struct kvm_kernel_irq_routing_entry *e, 1559 + int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, 1561 1560 const struct kvm_irq_routing_entry *ue) 1562 1561 { 1563 1562 int ret;
+1 -1
arch/s390/kvm/kvm-s390.c
··· 146 146 return -EINVAL; 147 147 } 148 148 149 - int kvm_dev_ioctl_check_extension(long ext) 149 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) 150 150 { 151 151 int r; 152 152
+1
arch/x86/kvm/Kconfig
··· 27 27 select MMU_NOTIFIER 28 28 select ANON_INODES 29 29 select HAVE_KVM_IRQCHIP 30 + select HAVE_KVM_IRQFD 30 31 select HAVE_KVM_IRQ_ROUTING 31 32 select HAVE_KVM_EVENTFD 32 33 select KVM_APIC_ARCHITECTURE
+1 -1
arch/x86/kvm/irq.c
··· 108 108 109 109 vector = kvm_cpu_get_extint(v); 110 110 111 - if (kvm_apic_vid_enabled(v->kvm) || vector != -1) 111 + if (vector != -1) 112 112 return vector; /* PIC */ 113 113 114 114 return kvm_get_apic_interrupt(v); /* APIC */
+39 -13
arch/x86/kvm/lapic.c
··· 352 352 353 353 static inline void apic_clear_irr(int vec, struct kvm_lapic *apic) 354 354 { 355 - apic->irr_pending = false; 355 + struct kvm_vcpu *vcpu; 356 + 357 + vcpu = apic->vcpu; 358 + 356 359 apic_clear_vector(vec, apic->regs + APIC_IRR); 357 - if (apic_search_irr(apic) != -1) 358 - apic->irr_pending = true; 360 + if (unlikely(kvm_apic_vid_enabled(vcpu->kvm))) 361 + /* try to update RVI */ 362 + kvm_make_request(KVM_REQ_EVENT, vcpu); 363 + else { 364 + vec = apic_search_irr(apic); 365 + apic->irr_pending = (vec != -1); 366 + } 359 367 } 360 368 361 369 static inline void apic_set_isr(int vec, struct kvm_lapic *apic) 362 370 { 363 - /* Note that we never get here with APIC virtualization enabled. */ 371 + struct kvm_vcpu *vcpu; 364 372 365 - if (!__apic_test_and_set_vector(vec, apic->regs + APIC_ISR)) 366 - ++apic->isr_count; 367 - BUG_ON(apic->isr_count > MAX_APIC_VECTOR); 373 + if (__apic_test_and_set_vector(vec, apic->regs + APIC_ISR)) 374 + return; 375 + 376 + vcpu = apic->vcpu; 377 + 368 378 /* 369 - * ISR (in service register) bit is set when injecting an interrupt. 370 - * The highest vector is injected. Thus the latest bit set matches 371 - * the highest bit in ISR. 379 + * With APIC virtualization enabled, all caching is disabled 380 + * because the processor can modify ISR under the hood. Instead 381 + * just set SVI. 372 382 */ 373 - apic->highest_isr_cache = vec; 383 + if (unlikely(kvm_apic_vid_enabled(vcpu->kvm))) 384 + kvm_x86_ops->hwapic_isr_update(vcpu->kvm, vec); 385 + else { 386 + ++apic->isr_count; 387 + BUG_ON(apic->isr_count > MAX_APIC_VECTOR); 388 + /* 389 + * ISR (in service register) bit is set when injecting an interrupt. 390 + * The highest vector is injected. Thus the latest bit set matches 391 + * the highest bit in ISR. 392 + */ 393 + apic->highest_isr_cache = vec; 394 + } 374 395 } 375 396 376 397 static inline int apic_find_highest_isr(struct kvm_lapic *apic) ··· 1648 1627 int vector = kvm_apic_has_interrupt(vcpu); 1649 1628 struct kvm_lapic *apic = vcpu->arch.apic; 1650 1629 1651 - /* Note that we never get here with APIC virtualization enabled. */ 1652 - 1653 1630 if (vector == -1) 1654 1631 return -1; 1632 + 1633 + /* 1634 + * We get here even with APIC virtualization enabled, if doing 1635 + * nested virtualization and L1 runs with the "acknowledge interrupt 1636 + * on exit" mode. Then we cannot inject the interrupt via RVI, 1637 + * because the process would deliver it through the IDT. 1638 + */ 1655 1639 1656 1640 apic_set_isr(vector, apic); 1657 1641 apic_update_ppr(apic);
+2 -2
arch/x86/kvm/vmx.c
··· 8754 8754 prepare_vmcs12(vcpu, vmcs12, exit_reason, exit_intr_info, 8755 8755 exit_qualification); 8756 8756 8757 + vmx_load_vmcs01(vcpu); 8758 + 8757 8759 if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT) 8758 8760 && nested_exit_intr_ack_set(vcpu)) { 8759 8761 int irq = kvm_cpu_get_interrupt(vcpu); ··· 8770 8768 vmcs12->vm_exit_intr_info, 8771 8769 vmcs12->vm_exit_intr_error_code, 8772 8770 KVM_ISA_VMX); 8773 - 8774 - vmx_load_vmcs01(vcpu); 8775 8771 8776 8772 vm_entry_controls_init(vmx, vmcs_read32(VM_ENTRY_CONTROLS)); 8777 8773 vm_exit_controls_init(vmx, vmcs_read32(VM_EXIT_CONTROLS));
+1 -1
arch/x86/kvm/x86.c
··· 2636 2636 return r; 2637 2637 } 2638 2638 2639 - int kvm_dev_ioctl_check_extension(long ext) 2639 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) 2640 2640 { 2641 2641 int r; 2642 2642
+14
include/kvm/arm_arch_timer.h
··· 67 67 void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu); 68 68 void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu); 69 69 void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu); 70 + 71 + u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid); 72 + int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value); 73 + 70 74 #else 71 75 static inline int kvm_timer_hyp_init(void) 72 76 { ··· 88 84 static inline void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) {} 89 85 static inline void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) {} 90 86 static inline void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) {} 87 + 88 + static inline int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) 89 + { 90 + return 0; 91 + } 92 + 93 + static inline u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid) 94 + { 95 + return 0; 96 + } 91 97 #endif 92 98 93 99 #endif
+104 -11
include/kvm/arm_vgic.h
··· 24 24 #include <linux/irqreturn.h> 25 25 #include <linux/spinlock.h> 26 26 #include <linux/types.h> 27 - #include <linux/irqchip/arm-gic.h> 28 27 29 28 #define VGIC_NR_IRQS 256 30 29 #define VGIC_NR_SGIS 16 ··· 31 32 #define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) 32 33 #define VGIC_NR_SHARED_IRQS (VGIC_NR_IRQS - VGIC_NR_PRIVATE_IRQS) 33 34 #define VGIC_MAX_CPUS KVM_MAX_VCPUS 34 - #define VGIC_MAX_LRS (1 << 6) 35 + 36 + #define VGIC_V2_MAX_LRS (1 << 6) 37 + #define VGIC_V3_MAX_LRS 16 35 38 36 39 /* Sanity checks... */ 37 40 #if (VGIC_MAX_CPUS > 8) ··· 69 68 u32 shared[VGIC_NR_SHARED_IRQS / 4]; 70 69 }; 71 70 71 + struct kvm_vcpu; 72 + 73 + enum vgic_type { 74 + VGIC_V2, /* Good ol' GICv2 */ 75 + VGIC_V3, /* New fancy GICv3 */ 76 + }; 77 + 78 + #define LR_STATE_PENDING (1 << 0) 79 + #define LR_STATE_ACTIVE (1 << 1) 80 + #define LR_STATE_MASK (3 << 0) 81 + #define LR_EOI_INT (1 << 2) 82 + 83 + struct vgic_lr { 84 + u16 irq; 85 + u8 source; 86 + u8 state; 87 + }; 88 + 89 + struct vgic_vmcr { 90 + u32 ctlr; 91 + u32 abpr; 92 + u32 bpr; 93 + u32 pmr; 94 + }; 95 + 96 + struct vgic_ops { 97 + struct vgic_lr (*get_lr)(const struct kvm_vcpu *, int); 98 + void (*set_lr)(struct kvm_vcpu *, int, struct vgic_lr); 99 + void (*sync_lr_elrsr)(struct kvm_vcpu *, int, struct vgic_lr); 100 + u64 (*get_elrsr)(const struct kvm_vcpu *vcpu); 101 + u64 (*get_eisr)(const struct kvm_vcpu *vcpu); 102 + u32 (*get_interrupt_status)(const struct kvm_vcpu *vcpu); 103 + void (*enable_underflow)(struct kvm_vcpu *vcpu); 104 + void (*disable_underflow)(struct kvm_vcpu *vcpu); 105 + void (*get_vmcr)(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 106 + void (*set_vmcr)(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 107 + void (*enable)(struct kvm_vcpu *vcpu); 108 + }; 109 + 110 + struct vgic_params { 111 + /* vgic type */ 112 + enum vgic_type type; 113 + /* Physical address of vgic virtual cpu interface */ 114 + phys_addr_t vcpu_base; 115 + /* Number of list registers */ 116 + u32 nr_lr; 117 + /* Interrupt number */ 118 + unsigned int maint_irq; 119 + /* Virtual control interface base address */ 120 + void __iomem *vctrl_base; 121 + }; 122 + 72 123 struct vgic_dist { 73 124 #ifdef CONFIG_KVM_ARM_VGIC 74 125 spinlock_t lock; 126 + bool in_kernel; 75 127 bool ready; 76 128 77 129 /* Virtual control interface mapping */ ··· 164 110 #endif 165 111 }; 166 112 113 + struct vgic_v2_cpu_if { 114 + u32 vgic_hcr; 115 + u32 vgic_vmcr; 116 + u32 vgic_misr; /* Saved only */ 117 + u32 vgic_eisr[2]; /* Saved only */ 118 + u32 vgic_elrsr[2]; /* Saved only */ 119 + u32 vgic_apr; 120 + u32 vgic_lr[VGIC_V2_MAX_LRS]; 121 + }; 122 + 123 + struct vgic_v3_cpu_if { 124 + #ifdef CONFIG_ARM_GIC_V3 125 + u32 vgic_hcr; 126 + u32 vgic_vmcr; 127 + u32 vgic_misr; /* Saved only */ 128 + u32 vgic_eisr; /* Saved only */ 129 + u32 vgic_elrsr; /* Saved only */ 130 + u32 vgic_ap0r[4]; 131 + u32 vgic_ap1r[4]; 132 + u64 vgic_lr[VGIC_V3_MAX_LRS]; 133 + #endif 134 + }; 135 + 167 136 struct vgic_cpu { 168 137 #ifdef CONFIG_KVM_ARM_VGIC 169 138 /* per IRQ to LR mapping */ ··· 197 120 DECLARE_BITMAP( pending_shared, VGIC_NR_SHARED_IRQS); 198 121 199 122 /* Bitmap of used/free list registers */ 200 - DECLARE_BITMAP( lr_used, VGIC_MAX_LRS); 123 + DECLARE_BITMAP( lr_used, VGIC_V2_MAX_LRS); 201 124 202 125 /* Number of list registers on this CPU */ 203 126 int nr_lr; 204 127 205 128 /* CPU vif control registers for world switch */ 206 - u32 vgic_hcr; 207 - u32 vgic_vmcr; 208 - u32 vgic_misr; /* Saved only */ 209 - u32 vgic_eisr[2]; /* Saved only */ 210 - u32 vgic_elrsr[2]; /* Saved only */ 211 - u32 vgic_apr; 212 - u32 vgic_lr[VGIC_MAX_LRS]; 129 + union { 130 + struct vgic_v2_cpu_if vgic_v2; 131 + struct vgic_v3_cpu_if vgic_v3; 132 + }; 213 133 #endif 214 134 }; 215 135 216 136 #define LR_EMPTY 0xff 137 + 138 + #define INT_STATUS_EOI (1 << 0) 139 + #define INT_STATUS_UNDERFLOW (1 << 1) 217 140 218 141 struct kvm; 219 142 struct kvm_vcpu; ··· 234 157 bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, 235 158 struct kvm_exit_mmio *mmio); 236 159 237 - #define irqchip_in_kernel(k) (!!((k)->arch.vgic.vctrl_base)) 160 + #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) 238 161 #define vgic_initialized(k) ((k)->arch.vgic.ready) 162 + 163 + int vgic_v2_probe(struct device_node *vgic_node, 164 + const struct vgic_ops **ops, 165 + const struct vgic_params **params); 166 + #ifdef CONFIG_ARM_GIC_V3 167 + int vgic_v3_probe(struct device_node *vgic_node, 168 + const struct vgic_ops **ops, 169 + const struct vgic_params **params); 170 + #else 171 + static inline int vgic_v3_probe(struct device_node *vgic_node, 172 + const struct vgic_ops **ops, 173 + const struct vgic_params **params) 174 + { 175 + return -ENODEV; 176 + } 177 + #endif 239 178 240 179 #else 241 180 static inline int kvm_vgic_hyp_init(void)
+16 -31
include/linux/kvm_host.h
··· 325 325 struct hlist_node link; 326 326 }; 327 327 328 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 329 - 330 - struct kvm_irq_routing_table { 331 - int chip[KVM_NR_IRQCHIPS][KVM_IRQCHIP_NUM_PINS]; 332 - struct kvm_kernel_irq_routing_entry *rt_entries; 333 - u32 nr_rt_entries; 334 - /* 335 - * Array indexed by gsi. Each entry contains list of irq chips 336 - * the gsi is connected to. 337 - */ 338 - struct hlist_head map[0]; 339 - }; 340 - 341 - #else 342 - 343 - struct kvm_irq_routing_table {}; 344 - 345 - #endif 328 + struct kvm_irq_routing_table; 346 329 347 330 #ifndef KVM_PRIVATE_MEM_SLOTS 348 331 #define KVM_PRIVATE_MEM_SLOTS 0 ··· 384 401 struct mutex irq_lock; 385 402 #ifdef CONFIG_HAVE_KVM_IRQCHIP 386 403 /* 387 - * Update side is protected by irq_lock and, 388 - * if configured, irqfds.lock. 404 + * Update side is protected by irq_lock. 389 405 */ 390 406 struct kvm_irq_routing_table __rcu *irq_routing; 391 407 struct hlist_head mask_notifier_list; 408 + #endif 409 + #ifdef CONFIG_HAVE_KVM_IRQFD 392 410 struct hlist_head irq_ack_notifier_list; 393 411 #endif 394 412 ··· 439 455 int __must_check vcpu_load(struct kvm_vcpu *vcpu); 440 456 void vcpu_put(struct kvm_vcpu *vcpu); 441 457 442 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 458 + #ifdef CONFIG_HAVE_KVM_IRQFD 443 459 int kvm_irqfd_init(void); 444 460 void kvm_irqfd_exit(void); 445 461 #else ··· 586 602 unsigned int ioctl, unsigned long arg); 587 603 int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf); 588 604 589 - int kvm_dev_ioctl_check_extension(long ext); 605 + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext); 590 606 591 607 int kvm_get_dirty_log(struct kvm *kvm, 592 608 struct kvm_dirty_log *log, int *is_dirty); ··· 735 751 struct kvm_irq_mask_notifier *kimn); 736 752 void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin, 737 753 bool mask); 754 + 755 + int kvm_irq_map_gsi(struct kvm *kvm, 756 + struct kvm_kernel_irq_routing_entry *entries, int gsi); 757 + int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin); 738 758 739 759 int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, 740 760 bool line_status); ··· 930 942 const struct kvm_irq_routing_entry *entries, 931 943 unsigned nr, 932 944 unsigned flags); 933 - int kvm_set_routing_entry(struct kvm_irq_routing_table *rt, 934 - struct kvm_kernel_irq_routing_entry *e, 945 + int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, 935 946 const struct kvm_irq_routing_entry *ue); 936 947 void kvm_free_irq_routing(struct kvm *kvm); 937 - 938 - int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi); 939 948 940 949 #else 941 950 ··· 940 955 941 956 #endif 942 957 958 + int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi); 959 + 943 960 #ifdef CONFIG_HAVE_KVM_EVENTFD 944 961 945 962 void kvm_eventfd_init(struct kvm *kvm); 946 963 int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args); 947 964 948 - #ifdef CONFIG_HAVE_KVM_IRQCHIP 965 + #ifdef CONFIG_HAVE_KVM_IRQFD 949 966 int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args); 950 967 void kvm_irqfd_release(struct kvm *kvm); 951 - void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *); 968 + void kvm_irq_routing_update(struct kvm *); 952 969 #else 953 970 static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args) 954 971 { ··· 972 985 static inline void kvm_irqfd_release(struct kvm *kvm) {} 973 986 974 987 #ifdef CONFIG_HAVE_KVM_IRQCHIP 975 - static inline void kvm_irq_routing_update(struct kvm *kvm, 976 - struct kvm_irq_routing_table *irq_rt) 988 + static inline void kvm_irq_routing_update(struct kvm *kvm) 977 989 { 978 - rcu_assign_pointer(kvm->irq_routing, irq_rt); 979 990 } 980 991 #endif 981 992
+4 -4
include/trace/events/kvm.h
··· 37 37 __entry->errno < 0 ? -__entry->errno : __entry->reason) 38 38 ); 39 39 40 - #if defined(CONFIG_HAVE_KVM_IRQCHIP) 40 + #if defined(CONFIG_HAVE_KVM_IRQFD) 41 41 TRACE_EVENT(kvm_set_irq, 42 42 TP_PROTO(unsigned int gsi, int level, int irq_source_id), 43 43 TP_ARGS(gsi, level, irq_source_id), ··· 57 57 TP_printk("gsi %u level %d source %d", 58 58 __entry->gsi, __entry->level, __entry->irq_source_id) 59 59 ); 60 - #endif 60 + #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */ 61 61 62 62 #if defined(__KVM_HAVE_IOAPIC) 63 63 #define kvm_deliver_mode \ ··· 124 124 125 125 #endif /* defined(__KVM_HAVE_IOAPIC) */ 126 126 127 - #if defined(CONFIG_HAVE_KVM_IRQCHIP) 127 + #if defined(CONFIG_HAVE_KVM_IRQFD) 128 128 129 129 TRACE_EVENT(kvm_ack_irq, 130 130 TP_PROTO(unsigned int irqchip, unsigned int pin), ··· 149 149 #endif 150 150 ); 151 151 152 - #endif /* defined(CONFIG_HAVE_KVM_IRQCHIP) */ 152 + #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */ 153 153 154 154 155 155
+4 -2
include/uapi/linux/kvm.h
··· 162 162 #define KVM_EXIT_TPR_ACCESS 12 163 163 #define KVM_EXIT_S390_SIEIC 13 164 164 #define KVM_EXIT_S390_RESET 14 165 - #define KVM_EXIT_DCR 15 165 + #define KVM_EXIT_DCR 15 /* deprecated */ 166 166 #define KVM_EXIT_NMI 16 167 167 #define KVM_EXIT_INTERNAL_ERROR 17 168 168 #define KVM_EXIT_OSI 18 ··· 268 268 __u64 trans_exc_code; 269 269 __u32 pgm_code; 270 270 } s390_ucontrol; 271 - /* KVM_EXIT_DCR */ 271 + /* KVM_EXIT_DCR (deprecated) */ 272 272 struct { 273 273 __u32 dcrn; 274 274 __u32 data; ··· 763 763 #define KVM_CAP_VM_ATTRIBUTES 101 764 764 #define KVM_CAP_ARM_PSCI_0_2 102 765 765 #define KVM_CAP_PPC_FIXUP_HCALL 103 766 + #define KVM_CAP_PPC_ENABLE_HCALL 104 767 + #define KVM_CAP_CHECK_EXTENSION_VM 105 766 768 767 769 #ifdef KVM_CAP_IRQ_ROUTING 768 770
+3
virt/kvm/Kconfig
··· 6 6 config HAVE_KVM_IRQCHIP 7 7 bool 8 8 9 + config HAVE_KVM_IRQFD 10 + bool 11 + 9 12 config HAVE_KVM_IRQ_ROUTING 10 13 bool 11 14
+265
virt/kvm/arm/vgic-v2.c
··· 1 + /* 2 + * Copyright (C) 2012,2013 ARM Limited, All Rights Reserved. 3 + * Author: Marc Zyngier <marc.zyngier@arm.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 + */ 17 + 18 + #include <linux/cpu.h> 19 + #include <linux/kvm.h> 20 + #include <linux/kvm_host.h> 21 + #include <linux/interrupt.h> 22 + #include <linux/io.h> 23 + #include <linux/of.h> 24 + #include <linux/of_address.h> 25 + #include <linux/of_irq.h> 26 + 27 + #include <linux/irqchip/arm-gic.h> 28 + 29 + #include <asm/kvm_emulate.h> 30 + #include <asm/kvm_arm.h> 31 + #include <asm/kvm_mmu.h> 32 + 33 + static struct vgic_lr vgic_v2_get_lr(const struct kvm_vcpu *vcpu, int lr) 34 + { 35 + struct vgic_lr lr_desc; 36 + u32 val = vcpu->arch.vgic_cpu.vgic_v2.vgic_lr[lr]; 37 + 38 + lr_desc.irq = val & GICH_LR_VIRTUALID; 39 + if (lr_desc.irq <= 15) 40 + lr_desc.source = (val >> GICH_LR_PHYSID_CPUID_SHIFT) & 0x7; 41 + else 42 + lr_desc.source = 0; 43 + lr_desc.state = 0; 44 + 45 + if (val & GICH_LR_PENDING_BIT) 46 + lr_desc.state |= LR_STATE_PENDING; 47 + if (val & GICH_LR_ACTIVE_BIT) 48 + lr_desc.state |= LR_STATE_ACTIVE; 49 + if (val & GICH_LR_EOI) 50 + lr_desc.state |= LR_EOI_INT; 51 + 52 + return lr_desc; 53 + } 54 + 55 + static void vgic_v2_set_lr(struct kvm_vcpu *vcpu, int lr, 56 + struct vgic_lr lr_desc) 57 + { 58 + u32 lr_val = (lr_desc.source << GICH_LR_PHYSID_CPUID_SHIFT) | lr_desc.irq; 59 + 60 + if (lr_desc.state & LR_STATE_PENDING) 61 + lr_val |= GICH_LR_PENDING_BIT; 62 + if (lr_desc.state & LR_STATE_ACTIVE) 63 + lr_val |= GICH_LR_ACTIVE_BIT; 64 + if (lr_desc.state & LR_EOI_INT) 65 + lr_val |= GICH_LR_EOI; 66 + 67 + vcpu->arch.vgic_cpu.vgic_v2.vgic_lr[lr] = lr_val; 68 + } 69 + 70 + static void vgic_v2_sync_lr_elrsr(struct kvm_vcpu *vcpu, int lr, 71 + struct vgic_lr lr_desc) 72 + { 73 + if (!(lr_desc.state & LR_STATE_MASK)) 74 + set_bit(lr, (unsigned long *)vcpu->arch.vgic_cpu.vgic_v2.vgic_elrsr); 75 + } 76 + 77 + static u64 vgic_v2_get_elrsr(const struct kvm_vcpu *vcpu) 78 + { 79 + u64 val; 80 + 81 + #if BITS_PER_LONG == 64 82 + val = vcpu->arch.vgic_cpu.vgic_v2.vgic_elrsr[1]; 83 + val <<= 32; 84 + val |= vcpu->arch.vgic_cpu.vgic_v2.vgic_elrsr[0]; 85 + #else 86 + val = *(u64 *)vcpu->arch.vgic_cpu.vgic_v2.vgic_elrsr; 87 + #endif 88 + return val; 89 + } 90 + 91 + static u64 vgic_v2_get_eisr(const struct kvm_vcpu *vcpu) 92 + { 93 + u64 val; 94 + 95 + #if BITS_PER_LONG == 64 96 + val = vcpu->arch.vgic_cpu.vgic_v2.vgic_eisr[1]; 97 + val <<= 32; 98 + val |= vcpu->arch.vgic_cpu.vgic_v2.vgic_eisr[0]; 99 + #else 100 + val = *(u64 *)vcpu->arch.vgic_cpu.vgic_v2.vgic_eisr; 101 + #endif 102 + return val; 103 + } 104 + 105 + static u32 vgic_v2_get_interrupt_status(const struct kvm_vcpu *vcpu) 106 + { 107 + u32 misr = vcpu->arch.vgic_cpu.vgic_v2.vgic_misr; 108 + u32 ret = 0; 109 + 110 + if (misr & GICH_MISR_EOI) 111 + ret |= INT_STATUS_EOI; 112 + if (misr & GICH_MISR_U) 113 + ret |= INT_STATUS_UNDERFLOW; 114 + 115 + return ret; 116 + } 117 + 118 + static void vgic_v2_enable_underflow(struct kvm_vcpu *vcpu) 119 + { 120 + vcpu->arch.vgic_cpu.vgic_v2.vgic_hcr |= GICH_HCR_UIE; 121 + } 122 + 123 + static void vgic_v2_disable_underflow(struct kvm_vcpu *vcpu) 124 + { 125 + vcpu->arch.vgic_cpu.vgic_v2.vgic_hcr &= ~GICH_HCR_UIE; 126 + } 127 + 128 + static void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) 129 + { 130 + u32 vmcr = vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr; 131 + 132 + vmcrp->ctlr = (vmcr & GICH_VMCR_CTRL_MASK) >> GICH_VMCR_CTRL_SHIFT; 133 + vmcrp->abpr = (vmcr & GICH_VMCR_ALIAS_BINPOINT_MASK) >> GICH_VMCR_ALIAS_BINPOINT_SHIFT; 134 + vmcrp->bpr = (vmcr & GICH_VMCR_BINPOINT_MASK) >> GICH_VMCR_BINPOINT_SHIFT; 135 + vmcrp->pmr = (vmcr & GICH_VMCR_PRIMASK_MASK) >> GICH_VMCR_PRIMASK_SHIFT; 136 + } 137 + 138 + static void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) 139 + { 140 + u32 vmcr; 141 + 142 + vmcr = (vmcrp->ctlr << GICH_VMCR_CTRL_SHIFT) & GICH_VMCR_CTRL_MASK; 143 + vmcr |= (vmcrp->abpr << GICH_VMCR_ALIAS_BINPOINT_SHIFT) & GICH_VMCR_ALIAS_BINPOINT_MASK; 144 + vmcr |= (vmcrp->bpr << GICH_VMCR_BINPOINT_SHIFT) & GICH_VMCR_BINPOINT_MASK; 145 + vmcr |= (vmcrp->pmr << GICH_VMCR_PRIMASK_SHIFT) & GICH_VMCR_PRIMASK_MASK; 146 + 147 + vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr = vmcr; 148 + } 149 + 150 + static void vgic_v2_enable(struct kvm_vcpu *vcpu) 151 + { 152 + /* 153 + * By forcing VMCR to zero, the GIC will restore the binary 154 + * points to their reset values. Anything else resets to zero 155 + * anyway. 156 + */ 157 + vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr = 0; 158 + 159 + /* Get the show on the road... */ 160 + vcpu->arch.vgic_cpu.vgic_v2.vgic_hcr = GICH_HCR_EN; 161 + } 162 + 163 + static const struct vgic_ops vgic_v2_ops = { 164 + .get_lr = vgic_v2_get_lr, 165 + .set_lr = vgic_v2_set_lr, 166 + .sync_lr_elrsr = vgic_v2_sync_lr_elrsr, 167 + .get_elrsr = vgic_v2_get_elrsr, 168 + .get_eisr = vgic_v2_get_eisr, 169 + .get_interrupt_status = vgic_v2_get_interrupt_status, 170 + .enable_underflow = vgic_v2_enable_underflow, 171 + .disable_underflow = vgic_v2_disable_underflow, 172 + .get_vmcr = vgic_v2_get_vmcr, 173 + .set_vmcr = vgic_v2_set_vmcr, 174 + .enable = vgic_v2_enable, 175 + }; 176 + 177 + static struct vgic_params vgic_v2_params; 178 + 179 + /** 180 + * vgic_v2_probe - probe for a GICv2 compatible interrupt controller in DT 181 + * @node: pointer to the DT node 182 + * @ops: address of a pointer to the GICv2 operations 183 + * @params: address of a pointer to HW-specific parameters 184 + * 185 + * Returns 0 if a GICv2 has been found, with the low level operations 186 + * in *ops and the HW parameters in *params. Returns an error code 187 + * otherwise. 188 + */ 189 + int vgic_v2_probe(struct device_node *vgic_node, 190 + const struct vgic_ops **ops, 191 + const struct vgic_params **params) 192 + { 193 + int ret; 194 + struct resource vctrl_res; 195 + struct resource vcpu_res; 196 + struct vgic_params *vgic = &vgic_v2_params; 197 + 198 + vgic->maint_irq = irq_of_parse_and_map(vgic_node, 0); 199 + if (!vgic->maint_irq) { 200 + kvm_err("error getting vgic maintenance irq from DT\n"); 201 + ret = -ENXIO; 202 + goto out; 203 + } 204 + 205 + ret = of_address_to_resource(vgic_node, 2, &vctrl_res); 206 + if (ret) { 207 + kvm_err("Cannot obtain GICH resource\n"); 208 + goto out; 209 + } 210 + 211 + vgic->vctrl_base = of_iomap(vgic_node, 2); 212 + if (!vgic->vctrl_base) { 213 + kvm_err("Cannot ioremap GICH\n"); 214 + ret = -ENOMEM; 215 + goto out; 216 + } 217 + 218 + vgic->nr_lr = readl_relaxed(vgic->vctrl_base + GICH_VTR); 219 + vgic->nr_lr = (vgic->nr_lr & 0x3f) + 1; 220 + 221 + ret = create_hyp_io_mappings(vgic->vctrl_base, 222 + vgic->vctrl_base + resource_size(&vctrl_res), 223 + vctrl_res.start); 224 + if (ret) { 225 + kvm_err("Cannot map VCTRL into hyp\n"); 226 + goto out_unmap; 227 + } 228 + 229 + if (of_address_to_resource(vgic_node, 3, &vcpu_res)) { 230 + kvm_err("Cannot obtain GICV resource\n"); 231 + ret = -ENXIO; 232 + goto out_unmap; 233 + } 234 + 235 + if (!PAGE_ALIGNED(vcpu_res.start)) { 236 + kvm_err("GICV physical address 0x%llx not page aligned\n", 237 + (unsigned long long)vcpu_res.start); 238 + ret = -ENXIO; 239 + goto out_unmap; 240 + } 241 + 242 + if (!PAGE_ALIGNED(resource_size(&vcpu_res))) { 243 + kvm_err("GICV size 0x%llx not a multiple of page size 0x%lx\n", 244 + (unsigned long long)resource_size(&vcpu_res), 245 + PAGE_SIZE); 246 + ret = -ENXIO; 247 + goto out_unmap; 248 + } 249 + 250 + vgic->vcpu_base = vcpu_res.start; 251 + 252 + kvm_info("%s@%llx IRQ%d\n", vgic_node->name, 253 + vctrl_res.start, vgic->maint_irq); 254 + 255 + vgic->type = VGIC_V2; 256 + *ops = &vgic_v2_ops; 257 + *params = vgic; 258 + goto out; 259 + 260 + out_unmap: 261 + iounmap(vgic->vctrl_base); 262 + out: 263 + of_node_put(vgic_node); 264 + return ret; 265 + }
+247
virt/kvm/arm/vgic-v3.c
··· 1 + /* 2 + * Copyright (C) 2013 ARM Limited, All Rights Reserved. 3 + * Author: Marc Zyngier <marc.zyngier@arm.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 + */ 17 + 18 + #include <linux/cpu.h> 19 + #include <linux/kvm.h> 20 + #include <linux/kvm_host.h> 21 + #include <linux/interrupt.h> 22 + #include <linux/io.h> 23 + #include <linux/of.h> 24 + #include <linux/of_address.h> 25 + #include <linux/of_irq.h> 26 + 27 + #include <linux/irqchip/arm-gic-v3.h> 28 + 29 + #include <asm/kvm_emulate.h> 30 + #include <asm/kvm_arm.h> 31 + #include <asm/kvm_mmu.h> 32 + 33 + /* These are for GICv2 emulation only */ 34 + #define GICH_LR_VIRTUALID (0x3ffUL << 0) 35 + #define GICH_LR_PHYSID_CPUID_SHIFT (10) 36 + #define GICH_LR_PHYSID_CPUID (7UL << GICH_LR_PHYSID_CPUID_SHIFT) 37 + 38 + /* 39 + * LRs are stored in reverse order in memory. make sure we index them 40 + * correctly. 41 + */ 42 + #define LR_INDEX(lr) (VGIC_V3_MAX_LRS - 1 - lr) 43 + 44 + static u32 ich_vtr_el2; 45 + 46 + static struct vgic_lr vgic_v3_get_lr(const struct kvm_vcpu *vcpu, int lr) 47 + { 48 + struct vgic_lr lr_desc; 49 + u64 val = vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[LR_INDEX(lr)]; 50 + 51 + lr_desc.irq = val & GICH_LR_VIRTUALID; 52 + if (lr_desc.irq <= 15) 53 + lr_desc.source = (val >> GICH_LR_PHYSID_CPUID_SHIFT) & 0x7; 54 + else 55 + lr_desc.source = 0; 56 + lr_desc.state = 0; 57 + 58 + if (val & ICH_LR_PENDING_BIT) 59 + lr_desc.state |= LR_STATE_PENDING; 60 + if (val & ICH_LR_ACTIVE_BIT) 61 + lr_desc.state |= LR_STATE_ACTIVE; 62 + if (val & ICH_LR_EOI) 63 + lr_desc.state |= LR_EOI_INT; 64 + 65 + return lr_desc; 66 + } 67 + 68 + static void vgic_v3_set_lr(struct kvm_vcpu *vcpu, int lr, 69 + struct vgic_lr lr_desc) 70 + { 71 + u64 lr_val = (((u32)lr_desc.source << GICH_LR_PHYSID_CPUID_SHIFT) | 72 + lr_desc.irq); 73 + 74 + if (lr_desc.state & LR_STATE_PENDING) 75 + lr_val |= ICH_LR_PENDING_BIT; 76 + if (lr_desc.state & LR_STATE_ACTIVE) 77 + lr_val |= ICH_LR_ACTIVE_BIT; 78 + if (lr_desc.state & LR_EOI_INT) 79 + lr_val |= ICH_LR_EOI; 80 + 81 + vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[LR_INDEX(lr)] = lr_val; 82 + } 83 + 84 + static void vgic_v3_sync_lr_elrsr(struct kvm_vcpu *vcpu, int lr, 85 + struct vgic_lr lr_desc) 86 + { 87 + if (!(lr_desc.state & LR_STATE_MASK)) 88 + vcpu->arch.vgic_cpu.vgic_v3.vgic_elrsr |= (1U << lr); 89 + } 90 + 91 + static u64 vgic_v3_get_elrsr(const struct kvm_vcpu *vcpu) 92 + { 93 + return vcpu->arch.vgic_cpu.vgic_v3.vgic_elrsr; 94 + } 95 + 96 + static u64 vgic_v3_get_eisr(const struct kvm_vcpu *vcpu) 97 + { 98 + return vcpu->arch.vgic_cpu.vgic_v3.vgic_eisr; 99 + } 100 + 101 + static u32 vgic_v3_get_interrupt_status(const struct kvm_vcpu *vcpu) 102 + { 103 + u32 misr = vcpu->arch.vgic_cpu.vgic_v3.vgic_misr; 104 + u32 ret = 0; 105 + 106 + if (misr & ICH_MISR_EOI) 107 + ret |= INT_STATUS_EOI; 108 + if (misr & ICH_MISR_U) 109 + ret |= INT_STATUS_UNDERFLOW; 110 + 111 + return ret; 112 + } 113 + 114 + static void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) 115 + { 116 + u32 vmcr = vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr; 117 + 118 + vmcrp->ctlr = (vmcr & ICH_VMCR_CTLR_MASK) >> ICH_VMCR_CTLR_SHIFT; 119 + vmcrp->abpr = (vmcr & ICH_VMCR_BPR1_MASK) >> ICH_VMCR_BPR1_SHIFT; 120 + vmcrp->bpr = (vmcr & ICH_VMCR_BPR0_MASK) >> ICH_VMCR_BPR0_SHIFT; 121 + vmcrp->pmr = (vmcr & ICH_VMCR_PMR_MASK) >> ICH_VMCR_PMR_SHIFT; 122 + } 123 + 124 + static void vgic_v3_enable_underflow(struct kvm_vcpu *vcpu) 125 + { 126 + vcpu->arch.vgic_cpu.vgic_v3.vgic_hcr |= ICH_HCR_UIE; 127 + } 128 + 129 + static void vgic_v3_disable_underflow(struct kvm_vcpu *vcpu) 130 + { 131 + vcpu->arch.vgic_cpu.vgic_v3.vgic_hcr &= ~ICH_HCR_UIE; 132 + } 133 + 134 + static void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) 135 + { 136 + u32 vmcr; 137 + 138 + vmcr = (vmcrp->ctlr << ICH_VMCR_CTLR_SHIFT) & ICH_VMCR_CTLR_MASK; 139 + vmcr |= (vmcrp->abpr << ICH_VMCR_BPR1_SHIFT) & ICH_VMCR_BPR1_MASK; 140 + vmcr |= (vmcrp->bpr << ICH_VMCR_BPR0_SHIFT) & ICH_VMCR_BPR0_MASK; 141 + vmcr |= (vmcrp->pmr << ICH_VMCR_PMR_SHIFT) & ICH_VMCR_PMR_MASK; 142 + 143 + vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr = vmcr; 144 + } 145 + 146 + static void vgic_v3_enable(struct kvm_vcpu *vcpu) 147 + { 148 + /* 149 + * By forcing VMCR to zero, the GIC will restore the binary 150 + * points to their reset values. Anything else resets to zero 151 + * anyway. 152 + */ 153 + vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr = 0; 154 + 155 + /* Get the show on the road... */ 156 + vcpu->arch.vgic_cpu.vgic_v3.vgic_hcr = ICH_HCR_EN; 157 + } 158 + 159 + static const struct vgic_ops vgic_v3_ops = { 160 + .get_lr = vgic_v3_get_lr, 161 + .set_lr = vgic_v3_set_lr, 162 + .sync_lr_elrsr = vgic_v3_sync_lr_elrsr, 163 + .get_elrsr = vgic_v3_get_elrsr, 164 + .get_eisr = vgic_v3_get_eisr, 165 + .get_interrupt_status = vgic_v3_get_interrupt_status, 166 + .enable_underflow = vgic_v3_enable_underflow, 167 + .disable_underflow = vgic_v3_disable_underflow, 168 + .get_vmcr = vgic_v3_get_vmcr, 169 + .set_vmcr = vgic_v3_set_vmcr, 170 + .enable = vgic_v3_enable, 171 + }; 172 + 173 + static struct vgic_params vgic_v3_params; 174 + 175 + /** 176 + * vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT 177 + * @node: pointer to the DT node 178 + * @ops: address of a pointer to the GICv3 operations 179 + * @params: address of a pointer to HW-specific parameters 180 + * 181 + * Returns 0 if a GICv3 has been found, with the low level operations 182 + * in *ops and the HW parameters in *params. Returns an error code 183 + * otherwise. 184 + */ 185 + int vgic_v3_probe(struct device_node *vgic_node, 186 + const struct vgic_ops **ops, 187 + const struct vgic_params **params) 188 + { 189 + int ret = 0; 190 + u32 gicv_idx; 191 + struct resource vcpu_res; 192 + struct vgic_params *vgic = &vgic_v3_params; 193 + 194 + vgic->maint_irq = irq_of_parse_and_map(vgic_node, 0); 195 + if (!vgic->maint_irq) { 196 + kvm_err("error getting vgic maintenance irq from DT\n"); 197 + ret = -ENXIO; 198 + goto out; 199 + } 200 + 201 + ich_vtr_el2 = kvm_call_hyp(__vgic_v3_get_ich_vtr_el2); 202 + 203 + /* 204 + * The ListRegs field is 5 bits, but there is a architectural 205 + * maximum of 16 list registers. Just ignore bit 4... 206 + */ 207 + vgic->nr_lr = (ich_vtr_el2 & 0xf) + 1; 208 + 209 + if (of_property_read_u32(vgic_node, "#redistributor-regions", &gicv_idx)) 210 + gicv_idx = 1; 211 + 212 + gicv_idx += 3; /* Also skip GICD, GICC, GICH */ 213 + if (of_address_to_resource(vgic_node, gicv_idx, &vcpu_res)) { 214 + kvm_err("Cannot obtain GICV region\n"); 215 + ret = -ENXIO; 216 + goto out; 217 + } 218 + 219 + if (!PAGE_ALIGNED(vcpu_res.start)) { 220 + kvm_err("GICV physical address 0x%llx not page aligned\n", 221 + (unsigned long long)vcpu_res.start); 222 + ret = -ENXIO; 223 + goto out; 224 + } 225 + 226 + if (!PAGE_ALIGNED(resource_size(&vcpu_res))) { 227 + kvm_err("GICV size 0x%llx not a multiple of page size 0x%lx\n", 228 + (unsigned long long)resource_size(&vcpu_res), 229 + PAGE_SIZE); 230 + ret = -ENXIO; 231 + goto out; 232 + } 233 + 234 + vgic->vcpu_base = vcpu_res.start; 235 + vgic->vctrl_base = NULL; 236 + vgic->type = VGIC_V3; 237 + 238 + kvm_info("%s@%llx IRQ%d\n", vgic_node->name, 239 + vcpu_res.start, vgic->maint_irq); 240 + 241 + *ops = &vgic_v3_ops; 242 + *params = vgic; 243 + 244 + out: 245 + of_node_put(vgic_node); 246 + return ret; 247 + }
+213 -176
virt/kvm/arm/vgic.c
··· 76 76 #define IMPLEMENTER_ARM 0x43b 77 77 #define GICC_ARCH_VERSION_V2 0x2 78 78 79 - /* Physical address of vgic virtual cpu interface */ 80 - static phys_addr_t vgic_vcpu_base; 81 - 82 - /* Virtual control interface base address */ 83 - static void __iomem *vgic_vctrl_base; 84 - 85 - static struct device_node *vgic_node; 86 - 87 79 #define ACCESS_READ_VALUE (1 << 0) 88 80 #define ACCESS_READ_RAZ (0 << 0) 89 81 #define ACCESS_READ_MASK(x) ((x) & (1 << 0)) ··· 86 94 #define ACCESS_WRITE_MASK(x) ((x) & (3 << 1)) 87 95 88 96 static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu); 97 + static void vgic_retire_lr(int lr_nr, int irq, struct kvm_vcpu *vcpu); 89 98 static void vgic_update_state(struct kvm *kvm); 90 99 static void vgic_kick_vcpus(struct kvm *kvm); 91 100 static void vgic_dispatch_sgi(struct kvm_vcpu *vcpu, u32 reg); 92 - static u32 vgic_nr_lr; 101 + static struct vgic_lr vgic_get_lr(const struct kvm_vcpu *vcpu, int lr); 102 + static void vgic_set_lr(struct kvm_vcpu *vcpu, int lr, struct vgic_lr lr_desc); 103 + static void vgic_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 104 + static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); 93 105 94 - static unsigned int vgic_maint_irq; 106 + static const struct vgic_ops *vgic_ops; 107 + static const struct vgic_params *vgic; 108 + 109 + /* 110 + * struct vgic_bitmap contains unions that provide two views of 111 + * the same data. In one case it is an array of registers of 112 + * u32's, and in the other case it is a bitmap of unsigned 113 + * longs. 114 + * 115 + * This does not work on 64-bit BE systems, because the bitmap access 116 + * will store two consecutive 32-bit words with the higher-addressed 117 + * register's bits at the lower index and the lower-addressed register's 118 + * bits at the higher index. 119 + * 120 + * Therefore, swizzle the register index when accessing the 32-bit word 121 + * registers to access the right register's value. 122 + */ 123 + #if defined(CONFIG_CPU_BIG_ENDIAN) && BITS_PER_LONG == 64 124 + #define REG_OFFSET_SWIZZLE 1 125 + #else 126 + #define REG_OFFSET_SWIZZLE 0 127 + #endif 95 128 96 129 static u32 *vgic_bitmap_get_reg(struct vgic_bitmap *x, 97 130 int cpuid, u32 offset) 98 131 { 99 132 offset >>= 2; 100 133 if (!offset) 101 - return x->percpu[cpuid].reg; 134 + return x->percpu[cpuid].reg + (offset ^ REG_OFFSET_SWIZZLE); 102 135 else 103 - return x->shared.reg + offset - 1; 136 + return x->shared.reg + ((offset - 1) ^ REG_OFFSET_SWIZZLE); 104 137 } 105 138 106 139 static int vgic_bitmap_get_irq_val(struct vgic_bitmap *x, ··· 258 241 259 242 static u32 mmio_data_read(struct kvm_exit_mmio *mmio, u32 mask) 260 243 { 261 - return *((u32 *)mmio->data) & mask; 244 + return le32_to_cpu(*((u32 *)mmio->data)) & mask; 262 245 } 263 246 264 247 static void mmio_data_write(struct kvm_exit_mmio *mmio, u32 mask, u32 value) 265 248 { 266 - *((u32 *)mmio->data) = value & mask; 249 + *((u32 *)mmio->data) = cpu_to_le32(value) & mask; 267 250 } 268 251 269 252 /** ··· 610 593 return false; 611 594 } 612 595 613 - #define LR_CPUID(lr) \ 614 - (((lr) & GICH_LR_PHYSID_CPUID) >> GICH_LR_PHYSID_CPUID_SHIFT) 615 - #define LR_IRQID(lr) \ 616 - ((lr) & GICH_LR_VIRTUALID) 617 - 618 - static void vgic_retire_lr(int lr_nr, int irq, struct vgic_cpu *vgic_cpu) 619 - { 620 - clear_bit(lr_nr, vgic_cpu->lr_used); 621 - vgic_cpu->vgic_lr[lr_nr] &= ~GICH_LR_STATE; 622 - vgic_cpu->vgic_irq_lr_map[irq] = LR_EMPTY; 623 - } 624 - 625 596 /** 626 597 * vgic_unqueue_irqs - move pending IRQs from LRs to the distributor 627 598 * @vgic_cpu: Pointer to the vgic_cpu struct holding the LRs ··· 627 622 struct vgic_dist *dist = &vcpu->kvm->arch.vgic; 628 623 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 629 624 int vcpu_id = vcpu->vcpu_id; 630 - int i, irq, source_cpu; 631 - u32 *lr; 625 + int i; 632 626 633 627 for_each_set_bit(i, vgic_cpu->lr_used, vgic_cpu->nr_lr) { 634 - lr = &vgic_cpu->vgic_lr[i]; 635 - irq = LR_IRQID(*lr); 636 - source_cpu = LR_CPUID(*lr); 628 + struct vgic_lr lr = vgic_get_lr(vcpu, i); 637 629 638 630 /* 639 631 * There are three options for the state bits: ··· 642 640 * If the LR holds only an active interrupt (not pending) then 643 641 * just leave it alone. 644 642 */ 645 - if ((*lr & GICH_LR_STATE) == GICH_LR_ACTIVE_BIT) 643 + if ((lr.state & LR_STATE_MASK) == LR_STATE_ACTIVE) 646 644 continue; 647 645 648 646 /* ··· 651 649 * is fine, then we are only setting a few bits that were 652 650 * already set. 653 651 */ 654 - vgic_dist_irq_set(vcpu, irq); 655 - if (irq < VGIC_NR_SGIS) 656 - dist->irq_sgi_sources[vcpu_id][irq] |= 1 << source_cpu; 657 - *lr &= ~GICH_LR_PENDING_BIT; 652 + vgic_dist_irq_set(vcpu, lr.irq); 653 + if (lr.irq < VGIC_NR_SGIS) 654 + dist->irq_sgi_sources[vcpu_id][lr.irq] |= 1 << lr.source; 655 + lr.state &= ~LR_STATE_PENDING; 656 + vgic_set_lr(vcpu, i, lr); 658 657 659 658 /* 660 659 * If there's no state left on the LR (it could still be 661 660 * active), then the LR does not hold any useful info and can 662 661 * be marked as free for other use. 663 662 */ 664 - if (!(*lr & GICH_LR_STATE)) 665 - vgic_retire_lr(i, irq, vgic_cpu); 663 + if (!(lr.state & LR_STATE_MASK)) 664 + vgic_retire_lr(i, lr.irq, vcpu); 666 665 667 666 /* Finally update the VGIC state. */ 668 667 vgic_update_state(vcpu->kvm); ··· 992 989 } 993 990 } 994 991 995 - #define MK_LR_PEND(src, irq) \ 996 - (GICH_LR_PENDING_BIT | ((src) << GICH_LR_PHYSID_CPUID_SHIFT) | (irq)) 992 + static struct vgic_lr vgic_get_lr(const struct kvm_vcpu *vcpu, int lr) 993 + { 994 + return vgic_ops->get_lr(vcpu, lr); 995 + } 996 + 997 + static void vgic_set_lr(struct kvm_vcpu *vcpu, int lr, 998 + struct vgic_lr vlr) 999 + { 1000 + vgic_ops->set_lr(vcpu, lr, vlr); 1001 + } 1002 + 1003 + static void vgic_sync_lr_elrsr(struct kvm_vcpu *vcpu, int lr, 1004 + struct vgic_lr vlr) 1005 + { 1006 + vgic_ops->sync_lr_elrsr(vcpu, lr, vlr); 1007 + } 1008 + 1009 + static inline u64 vgic_get_elrsr(struct kvm_vcpu *vcpu) 1010 + { 1011 + return vgic_ops->get_elrsr(vcpu); 1012 + } 1013 + 1014 + static inline u64 vgic_get_eisr(struct kvm_vcpu *vcpu) 1015 + { 1016 + return vgic_ops->get_eisr(vcpu); 1017 + } 1018 + 1019 + static inline u32 vgic_get_interrupt_status(struct kvm_vcpu *vcpu) 1020 + { 1021 + return vgic_ops->get_interrupt_status(vcpu); 1022 + } 1023 + 1024 + static inline void vgic_enable_underflow(struct kvm_vcpu *vcpu) 1025 + { 1026 + vgic_ops->enable_underflow(vcpu); 1027 + } 1028 + 1029 + static inline void vgic_disable_underflow(struct kvm_vcpu *vcpu) 1030 + { 1031 + vgic_ops->disable_underflow(vcpu); 1032 + } 1033 + 1034 + static inline void vgic_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr) 1035 + { 1036 + vgic_ops->get_vmcr(vcpu, vmcr); 1037 + } 1038 + 1039 + static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr) 1040 + { 1041 + vgic_ops->set_vmcr(vcpu, vmcr); 1042 + } 1043 + 1044 + static inline void vgic_enable(struct kvm_vcpu *vcpu) 1045 + { 1046 + vgic_ops->enable(vcpu); 1047 + } 1048 + 1049 + static void vgic_retire_lr(int lr_nr, int irq, struct kvm_vcpu *vcpu) 1050 + { 1051 + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1052 + struct vgic_lr vlr = vgic_get_lr(vcpu, lr_nr); 1053 + 1054 + vlr.state = 0; 1055 + vgic_set_lr(vcpu, lr_nr, vlr); 1056 + clear_bit(lr_nr, vgic_cpu->lr_used); 1057 + vgic_cpu->vgic_irq_lr_map[irq] = LR_EMPTY; 1058 + } 997 1059 998 1060 /* 999 1061 * An interrupt may have been disabled after being made pending on the ··· 1074 1006 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1075 1007 int lr; 1076 1008 1077 - for_each_set_bit(lr, vgic_cpu->lr_used, vgic_cpu->nr_lr) { 1078 - int irq = vgic_cpu->vgic_lr[lr] & GICH_LR_VIRTUALID; 1009 + for_each_set_bit(lr, vgic_cpu->lr_used, vgic->nr_lr) { 1010 + struct vgic_lr vlr = vgic_get_lr(vcpu, lr); 1079 1011 1080 - if (!vgic_irq_is_enabled(vcpu, irq)) { 1081 - vgic_retire_lr(lr, irq, vgic_cpu); 1082 - if (vgic_irq_is_active(vcpu, irq)) 1083 - vgic_irq_clear_active(vcpu, irq); 1012 + if (!vgic_irq_is_enabled(vcpu, vlr.irq)) { 1013 + vgic_retire_lr(lr, vlr.irq, vcpu); 1014 + if (vgic_irq_is_active(vcpu, vlr.irq)) 1015 + vgic_irq_clear_active(vcpu, vlr.irq); 1084 1016 } 1085 1017 } 1086 1018 } ··· 1092 1024 static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) 1093 1025 { 1094 1026 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1027 + struct vgic_lr vlr; 1095 1028 int lr; 1096 1029 1097 1030 /* Sanitize the input... */ ··· 1105 1036 lr = vgic_cpu->vgic_irq_lr_map[irq]; 1106 1037 1107 1038 /* Do we have an active interrupt for the same CPUID? */ 1108 - if (lr != LR_EMPTY && 1109 - (LR_CPUID(vgic_cpu->vgic_lr[lr]) == sgi_source_id)) { 1110 - kvm_debug("LR%d piggyback for IRQ%d %x\n", 1111 - lr, irq, vgic_cpu->vgic_lr[lr]); 1112 - BUG_ON(!test_bit(lr, vgic_cpu->lr_used)); 1113 - vgic_cpu->vgic_lr[lr] |= GICH_LR_PENDING_BIT; 1114 - return true; 1039 + if (lr != LR_EMPTY) { 1040 + vlr = vgic_get_lr(vcpu, lr); 1041 + if (vlr.source == sgi_source_id) { 1042 + kvm_debug("LR%d piggyback for IRQ%d\n", lr, vlr.irq); 1043 + BUG_ON(!test_bit(lr, vgic_cpu->lr_used)); 1044 + vlr.state |= LR_STATE_PENDING; 1045 + vgic_set_lr(vcpu, lr, vlr); 1046 + return true; 1047 + } 1115 1048 } 1116 1049 1117 1050 /* Try to use another LR for this interrupt */ 1118 1051 lr = find_first_zero_bit((unsigned long *)vgic_cpu->lr_used, 1119 - vgic_cpu->nr_lr); 1120 - if (lr >= vgic_cpu->nr_lr) 1052 + vgic->nr_lr); 1053 + if (lr >= vgic->nr_lr) 1121 1054 return false; 1122 1055 1123 1056 kvm_debug("LR%d allocated for IRQ%d %x\n", lr, irq, sgi_source_id); 1124 - vgic_cpu->vgic_lr[lr] = MK_LR_PEND(sgi_source_id, irq); 1125 1057 vgic_cpu->vgic_irq_lr_map[irq] = lr; 1126 1058 set_bit(lr, vgic_cpu->lr_used); 1127 1059 1060 + vlr.irq = irq; 1061 + vlr.source = sgi_source_id; 1062 + vlr.state = LR_STATE_PENDING; 1128 1063 if (!vgic_irq_is_edge(vcpu, irq)) 1129 - vgic_cpu->vgic_lr[lr] |= GICH_LR_EOI; 1064 + vlr.state |= LR_EOI_INT; 1065 + 1066 + vgic_set_lr(vcpu, lr, vlr); 1130 1067 1131 1068 return true; 1132 1069 } ··· 1230 1155 1231 1156 epilog: 1232 1157 if (overflow) { 1233 - vgic_cpu->vgic_hcr |= GICH_HCR_UIE; 1158 + vgic_enable_underflow(vcpu); 1234 1159 } else { 1235 - vgic_cpu->vgic_hcr &= ~GICH_HCR_UIE; 1160 + vgic_disable_underflow(vcpu); 1236 1161 /* 1237 1162 * We're about to run this VCPU, and we've consumed 1238 1163 * everything the distributor had in store for ··· 1245 1170 1246 1171 static bool vgic_process_maintenance(struct kvm_vcpu *vcpu) 1247 1172 { 1248 - struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1173 + u32 status = vgic_get_interrupt_status(vcpu); 1249 1174 bool level_pending = false; 1250 1175 1251 - kvm_debug("MISR = %08x\n", vgic_cpu->vgic_misr); 1176 + kvm_debug("STATUS = %08x\n", status); 1252 1177 1253 - if (vgic_cpu->vgic_misr & GICH_MISR_EOI) { 1178 + if (status & INT_STATUS_EOI) { 1254 1179 /* 1255 1180 * Some level interrupts have been EOIed. Clear their 1256 1181 * active bit. 1257 1182 */ 1258 - int lr, irq; 1183 + u64 eisr = vgic_get_eisr(vcpu); 1184 + unsigned long *eisr_ptr = (unsigned long *)&eisr; 1185 + int lr; 1259 1186 1260 - for_each_set_bit(lr, (unsigned long *)vgic_cpu->vgic_eisr, 1261 - vgic_cpu->nr_lr) { 1262 - irq = vgic_cpu->vgic_lr[lr] & GICH_LR_VIRTUALID; 1187 + for_each_set_bit(lr, eisr_ptr, vgic->nr_lr) { 1188 + struct vgic_lr vlr = vgic_get_lr(vcpu, lr); 1263 1189 1264 - vgic_irq_clear_active(vcpu, irq); 1265 - vgic_cpu->vgic_lr[lr] &= ~GICH_LR_EOI; 1190 + vgic_irq_clear_active(vcpu, vlr.irq); 1191 + WARN_ON(vlr.state & LR_STATE_MASK); 1192 + vlr.state = 0; 1193 + vgic_set_lr(vcpu, lr, vlr); 1266 1194 1267 1195 /* Any additional pending interrupt? */ 1268 - if (vgic_dist_irq_is_pending(vcpu, irq)) { 1269 - vgic_cpu_irq_set(vcpu, irq); 1196 + if (vgic_dist_irq_is_pending(vcpu, vlr.irq)) { 1197 + vgic_cpu_irq_set(vcpu, vlr.irq); 1270 1198 level_pending = true; 1271 1199 } else { 1272 - vgic_cpu_irq_clear(vcpu, irq); 1200 + vgic_cpu_irq_clear(vcpu, vlr.irq); 1273 1201 } 1274 1202 1275 1203 /* 1276 1204 * Despite being EOIed, the LR may not have 1277 1205 * been marked as empty. 1278 1206 */ 1279 - set_bit(lr, (unsigned long *)vgic_cpu->vgic_elrsr); 1280 - vgic_cpu->vgic_lr[lr] &= ~GICH_LR_ACTIVE_BIT; 1207 + vgic_sync_lr_elrsr(vcpu, lr, vlr); 1281 1208 } 1282 1209 } 1283 1210 1284 - if (vgic_cpu->vgic_misr & GICH_MISR_U) 1285 - vgic_cpu->vgic_hcr &= ~GICH_HCR_UIE; 1211 + if (status & INT_STATUS_UNDERFLOW) 1212 + vgic_disable_underflow(vcpu); 1286 1213 1287 1214 return level_pending; 1288 1215 } ··· 1297 1220 { 1298 1221 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1299 1222 struct vgic_dist *dist = &vcpu->kvm->arch.vgic; 1223 + u64 elrsr; 1224 + unsigned long *elrsr_ptr; 1300 1225 int lr, pending; 1301 1226 bool level_pending; 1302 1227 1303 1228 level_pending = vgic_process_maintenance(vcpu); 1229 + elrsr = vgic_get_elrsr(vcpu); 1230 + elrsr_ptr = (unsigned long *)&elrsr; 1304 1231 1305 1232 /* Clear mappings for empty LRs */ 1306 - for_each_set_bit(lr, (unsigned long *)vgic_cpu->vgic_elrsr, 1307 - vgic_cpu->nr_lr) { 1308 - int irq; 1233 + for_each_set_bit(lr, elrsr_ptr, vgic->nr_lr) { 1234 + struct vgic_lr vlr; 1309 1235 1310 1236 if (!test_and_clear_bit(lr, vgic_cpu->lr_used)) 1311 1237 continue; 1312 1238 1313 - irq = vgic_cpu->vgic_lr[lr] & GICH_LR_VIRTUALID; 1239 + vlr = vgic_get_lr(vcpu, lr); 1314 1240 1315 - BUG_ON(irq >= VGIC_NR_IRQS); 1316 - vgic_cpu->vgic_irq_lr_map[irq] = LR_EMPTY; 1241 + BUG_ON(vlr.irq >= VGIC_NR_IRQS); 1242 + vgic_cpu->vgic_irq_lr_map[vlr.irq] = LR_EMPTY; 1317 1243 } 1318 1244 1319 1245 /* Check if we still have something up our sleeve... */ 1320 - pending = find_first_zero_bit((unsigned long *)vgic_cpu->vgic_elrsr, 1321 - vgic_cpu->nr_lr); 1322 - if (level_pending || pending < vgic_cpu->nr_lr) 1246 + pending = find_first_zero_bit(elrsr_ptr, vgic->nr_lr); 1247 + if (level_pending || pending < vgic->nr_lr) 1323 1248 set_bit(vcpu->vcpu_id, &dist->irq_pending_on_cpu); 1324 1249 } 1325 1250 ··· 1511 1432 } 1512 1433 1513 1434 /* 1514 - * By forcing VMCR to zero, the GIC will restore the binary 1515 - * points to their reset values. Anything else resets to zero 1516 - * anyway. 1435 + * Store the number of LRs per vcpu, so we don't have to go 1436 + * all the way to the distributor structure to find out. Only 1437 + * assembly code should use this one. 1517 1438 */ 1518 - vgic_cpu->vgic_vmcr = 0; 1439 + vgic_cpu->nr_lr = vgic->nr_lr; 1519 1440 1520 - vgic_cpu->nr_lr = vgic_nr_lr; 1521 - vgic_cpu->vgic_hcr = GICH_HCR_EN; /* Get the show on the road... */ 1441 + vgic_enable(vcpu); 1522 1442 1523 1443 return 0; 1524 1444 } 1525 1445 1526 1446 static void vgic_init_maintenance_interrupt(void *info) 1527 1447 { 1528 - enable_percpu_irq(vgic_maint_irq, 0); 1448 + enable_percpu_irq(vgic->maint_irq, 0); 1529 1449 } 1530 1450 1531 1451 static int vgic_cpu_notify(struct notifier_block *self, ··· 1537 1459 break; 1538 1460 case CPU_DYING: 1539 1461 case CPU_DYING_FROZEN: 1540 - disable_percpu_irq(vgic_maint_irq); 1462 + disable_percpu_irq(vgic->maint_irq); 1541 1463 break; 1542 1464 } 1543 1465 ··· 1548 1470 .notifier_call = vgic_cpu_notify, 1549 1471 }; 1550 1472 1473 + static const struct of_device_id vgic_ids[] = { 1474 + { .compatible = "arm,cortex-a15-gic", .data = vgic_v2_probe, }, 1475 + { .compatible = "arm,gic-v3", .data = vgic_v3_probe, }, 1476 + {}, 1477 + }; 1478 + 1551 1479 int kvm_vgic_hyp_init(void) 1552 1480 { 1481 + const struct of_device_id *matched_id; 1482 + int (*vgic_probe)(struct device_node *,const struct vgic_ops **, 1483 + const struct vgic_params **); 1484 + struct device_node *vgic_node; 1553 1485 int ret; 1554 - struct resource vctrl_res; 1555 - struct resource vcpu_res; 1556 1486 1557 - vgic_node = of_find_compatible_node(NULL, NULL, "arm,cortex-a15-gic"); 1487 + vgic_node = of_find_matching_node_and_match(NULL, 1488 + vgic_ids, &matched_id); 1558 1489 if (!vgic_node) { 1559 - kvm_err("error: no compatible vgic node in DT\n"); 1490 + kvm_err("error: no compatible GIC node found\n"); 1560 1491 return -ENODEV; 1561 1492 } 1562 1493 1563 - vgic_maint_irq = irq_of_parse_and_map(vgic_node, 0); 1564 - if (!vgic_maint_irq) { 1565 - kvm_err("error getting vgic maintenance irq from DT\n"); 1566 - ret = -ENXIO; 1567 - goto out; 1568 - } 1494 + vgic_probe = matched_id->data; 1495 + ret = vgic_probe(vgic_node, &vgic_ops, &vgic); 1496 + if (ret) 1497 + return ret; 1569 1498 1570 - ret = request_percpu_irq(vgic_maint_irq, vgic_maintenance_handler, 1499 + ret = request_percpu_irq(vgic->maint_irq, vgic_maintenance_handler, 1571 1500 "vgic", kvm_get_running_vcpus()); 1572 1501 if (ret) { 1573 - kvm_err("Cannot register interrupt %d\n", vgic_maint_irq); 1574 - goto out; 1502 + kvm_err("Cannot register interrupt %d\n", vgic->maint_irq); 1503 + return ret; 1575 1504 } 1576 1505 1577 1506 ret = __register_cpu_notifier(&vgic_cpu_nb); ··· 1587 1502 goto out_free_irq; 1588 1503 } 1589 1504 1590 - ret = of_address_to_resource(vgic_node, 2, &vctrl_res); 1591 - if (ret) { 1592 - kvm_err("Cannot obtain VCTRL resource\n"); 1593 - goto out_free_irq; 1594 - } 1505 + /* Callback into for arch code for setup */ 1506 + vgic_arch_setup(vgic); 1595 1507 1596 - vgic_vctrl_base = of_iomap(vgic_node, 2); 1597 - if (!vgic_vctrl_base) { 1598 - kvm_err("Cannot ioremap VCTRL\n"); 1599 - ret = -ENOMEM; 1600 - goto out_free_irq; 1601 - } 1602 - 1603 - vgic_nr_lr = readl_relaxed(vgic_vctrl_base + GICH_VTR); 1604 - vgic_nr_lr = (vgic_nr_lr & 0x3f) + 1; 1605 - 1606 - ret = create_hyp_io_mappings(vgic_vctrl_base, 1607 - vgic_vctrl_base + resource_size(&vctrl_res), 1608 - vctrl_res.start); 1609 - if (ret) { 1610 - kvm_err("Cannot map VCTRL into hyp\n"); 1611 - goto out_unmap; 1612 - } 1613 - 1614 - if (of_address_to_resource(vgic_node, 3, &vcpu_res)) { 1615 - kvm_err("Cannot obtain VCPU resource\n"); 1616 - ret = -ENXIO; 1617 - goto out_unmap; 1618 - } 1619 - 1620 - if (!PAGE_ALIGNED(vcpu_res.start)) { 1621 - kvm_err("GICV physical address 0x%llx not page aligned\n", 1622 - (unsigned long long)vcpu_res.start); 1623 - ret = -ENXIO; 1624 - goto out_unmap; 1625 - } 1626 - 1627 - if (!PAGE_ALIGNED(resource_size(&vcpu_res))) { 1628 - kvm_err("GICV size 0x%llx not a multiple of page size 0x%lx\n", 1629 - (unsigned long long)resource_size(&vcpu_res), 1630 - PAGE_SIZE); 1631 - ret = -ENXIO; 1632 - goto out_unmap; 1633 - } 1634 - 1635 - vgic_vcpu_base = vcpu_res.start; 1636 - 1637 - kvm_info("%s@%llx IRQ%d\n", vgic_node->name, 1638 - vctrl_res.start, vgic_maint_irq); 1639 1508 on_each_cpu(vgic_init_maintenance_interrupt, NULL, 1); 1640 1509 1641 - goto out; 1510 + return 0; 1642 1511 1643 - out_unmap: 1644 - iounmap(vgic_vctrl_base); 1645 1512 out_free_irq: 1646 - free_percpu_irq(vgic_maint_irq, kvm_get_running_vcpus()); 1647 - out: 1648 - of_node_put(vgic_node); 1513 + free_percpu_irq(vgic->maint_irq, kvm_get_running_vcpus()); 1649 1514 return ret; 1650 1515 } 1651 1516 ··· 1628 1593 } 1629 1594 1630 1595 ret = kvm_phys_addr_ioremap(kvm, kvm->arch.vgic.vgic_cpu_base, 1631 - vgic_vcpu_base, KVM_VGIC_V2_CPU_SIZE); 1596 + vgic->vcpu_base, KVM_VGIC_V2_CPU_SIZE); 1632 1597 if (ret) { 1633 1598 kvm_err("Unable to remap VGIC CPU to VCPU\n"); 1634 1599 goto out; ··· 1674 1639 } 1675 1640 1676 1641 spin_lock_init(&kvm->arch.vgic.lock); 1677 - kvm->arch.vgic.vctrl_base = vgic_vctrl_base; 1642 + kvm->arch.vgic.in_kernel = true; 1643 + kvm->arch.vgic.vctrl_base = vgic->vctrl_base; 1678 1644 kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF; 1679 1645 kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF; 1680 1646 ··· 1774 1738 static bool handle_cpu_mmio_misc(struct kvm_vcpu *vcpu, 1775 1739 struct kvm_exit_mmio *mmio, phys_addr_t offset) 1776 1740 { 1777 - struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1778 - u32 reg, mask = 0, shift = 0; 1779 1741 bool updated = false; 1742 + struct vgic_vmcr vmcr; 1743 + u32 *vmcr_field; 1744 + u32 reg; 1745 + 1746 + vgic_get_vmcr(vcpu, &vmcr); 1780 1747 1781 1748 switch (offset & ~0x3) { 1782 1749 case GIC_CPU_CTRL: 1783 - mask = GICH_VMCR_CTRL_MASK; 1784 - shift = GICH_VMCR_CTRL_SHIFT; 1750 + vmcr_field = &vmcr.ctlr; 1785 1751 break; 1786 1752 case GIC_CPU_PRIMASK: 1787 - mask = GICH_VMCR_PRIMASK_MASK; 1788 - shift = GICH_VMCR_PRIMASK_SHIFT; 1753 + vmcr_field = &vmcr.pmr; 1789 1754 break; 1790 1755 case GIC_CPU_BINPOINT: 1791 - mask = GICH_VMCR_BINPOINT_MASK; 1792 - shift = GICH_VMCR_BINPOINT_SHIFT; 1756 + vmcr_field = &vmcr.bpr; 1793 1757 break; 1794 1758 case GIC_CPU_ALIAS_BINPOINT: 1795 - mask = GICH_VMCR_ALIAS_BINPOINT_MASK; 1796 - shift = GICH_VMCR_ALIAS_BINPOINT_SHIFT; 1759 + vmcr_field = &vmcr.abpr; 1797 1760 break; 1761 + default: 1762 + BUG(); 1798 1763 } 1799 1764 1800 1765 if (!mmio->is_write) { 1801 - reg = (vgic_cpu->vgic_vmcr & mask) >> shift; 1766 + reg = *vmcr_field; 1802 1767 mmio_data_write(mmio, ~0, reg); 1803 1768 } else { 1804 1769 reg = mmio_data_read(mmio, ~0); 1805 - reg = (reg << shift) & mask; 1806 - if (reg != (vgic_cpu->vgic_vmcr & mask)) 1770 + if (reg != *vmcr_field) { 1771 + *vmcr_field = reg; 1772 + vgic_set_vmcr(vcpu, &vmcr); 1807 1773 updated = true; 1808 - vgic_cpu->vgic_vmcr &= ~mask; 1809 - vgic_cpu->vgic_vmcr |= reg; 1774 + } 1810 1775 } 1811 1776 return updated; 1812 1777 }
+102 -32
virt/kvm/eventfd.c
··· 33 33 #include <linux/kernel.h> 34 34 #include <linux/srcu.h> 35 35 #include <linux/slab.h> 36 + #include <linux/seqlock.h> 37 + #include <trace/events/kvm.h> 36 38 39 + #include "irq.h" 37 40 #include "iodev.h" 38 41 39 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 42 + #ifdef CONFIG_HAVE_KVM_IRQFD 40 43 /* 41 44 * -------------------------------------------------------------------- 42 45 * irqfd: Allows an fd to be used to inject an interrupt to the guest ··· 78 75 struct kvm *kvm; 79 76 wait_queue_t wait; 80 77 /* Update side is protected by irqfds.lock */ 81 - struct kvm_kernel_irq_routing_entry __rcu *irq_entry; 78 + struct kvm_kernel_irq_routing_entry irq_entry; 79 + seqcount_t irq_entry_sc; 82 80 /* Used for level IRQ fast-path */ 83 81 int gsi; 84 82 struct work_struct inject; ··· 227 223 { 228 224 struct _irqfd *irqfd = container_of(wait, struct _irqfd, wait); 229 225 unsigned long flags = (unsigned long)key; 230 - struct kvm_kernel_irq_routing_entry *irq; 226 + struct kvm_kernel_irq_routing_entry irq; 231 227 struct kvm *kvm = irqfd->kvm; 228 + unsigned seq; 232 229 int idx; 233 230 234 231 if (flags & POLLIN) { 235 232 idx = srcu_read_lock(&kvm->irq_srcu); 236 - irq = srcu_dereference(irqfd->irq_entry, &kvm->irq_srcu); 233 + do { 234 + seq = read_seqcount_begin(&irqfd->irq_entry_sc); 235 + irq = irqfd->irq_entry; 236 + } while (read_seqcount_retry(&irqfd->irq_entry_sc, seq)); 237 237 /* An event has been signaled, inject an interrupt */ 238 - if (irq) 239 - kvm_set_msi(irq, kvm, KVM_USERSPACE_IRQ_SOURCE_ID, 1, 238 + if (irq.type == KVM_IRQ_ROUTING_MSI) 239 + kvm_set_msi(&irq, kvm, KVM_USERSPACE_IRQ_SOURCE_ID, 1, 240 240 false); 241 241 else 242 242 schedule_work(&irqfd->inject); ··· 280 272 } 281 273 282 274 /* Must be called under irqfds.lock */ 283 - static void irqfd_update(struct kvm *kvm, struct _irqfd *irqfd, 284 - struct kvm_irq_routing_table *irq_rt) 275 + static void irqfd_update(struct kvm *kvm, struct _irqfd *irqfd) 285 276 { 286 277 struct kvm_kernel_irq_routing_entry *e; 278 + struct kvm_kernel_irq_routing_entry entries[KVM_NR_IRQCHIPS]; 279 + int i, n_entries; 287 280 288 - if (irqfd->gsi >= irq_rt->nr_rt_entries) { 289 - rcu_assign_pointer(irqfd->irq_entry, NULL); 290 - return; 291 - } 281 + n_entries = kvm_irq_map_gsi(kvm, entries, irqfd->gsi); 292 282 293 - hlist_for_each_entry(e, &irq_rt->map[irqfd->gsi], link) { 283 + write_seqcount_begin(&irqfd->irq_entry_sc); 284 + 285 + irqfd->irq_entry.type = 0; 286 + 287 + e = entries; 288 + for (i = 0; i < n_entries; ++i, ++e) { 294 289 /* Only fast-path MSI. */ 295 290 if (e->type == KVM_IRQ_ROUTING_MSI) 296 - rcu_assign_pointer(irqfd->irq_entry, e); 297 - else 298 - rcu_assign_pointer(irqfd->irq_entry, NULL); 291 + irqfd->irq_entry = *e; 299 292 } 293 + 294 + write_seqcount_end(&irqfd->irq_entry_sc); 300 295 } 301 296 302 297 static int 303 298 kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) 304 299 { 305 - struct kvm_irq_routing_table *irq_rt; 306 300 struct _irqfd *irqfd, *tmp; 307 301 struct fd f; 308 302 struct eventfd_ctx *eventfd = NULL, *resamplefd = NULL; 309 303 int ret; 310 304 unsigned int events; 305 + int idx; 311 306 312 307 irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL); 313 308 if (!irqfd) ··· 321 310 INIT_LIST_HEAD(&irqfd->list); 322 311 INIT_WORK(&irqfd->inject, irqfd_inject); 323 312 INIT_WORK(&irqfd->shutdown, irqfd_shutdown); 313 + seqcount_init(&irqfd->irq_entry_sc); 324 314 325 315 f = fdget(args->fd); 326 316 if (!f.file) { ··· 404 392 goto fail; 405 393 } 406 394 407 - irq_rt = rcu_dereference_protected(kvm->irq_routing, 408 - lockdep_is_held(&kvm->irqfds.lock)); 409 - irqfd_update(kvm, irqfd, irq_rt); 395 + idx = srcu_read_lock(&kvm->irq_srcu); 396 + irqfd_update(kvm, irqfd); 397 + srcu_read_unlock(&kvm->irq_srcu, idx); 410 398 411 399 list_add_tail(&irqfd->list, &kvm->irqfds.items); 412 400 ··· 445 433 kfree(irqfd); 446 434 return ret; 447 435 } 436 + 437 + bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin) 438 + { 439 + struct kvm_irq_ack_notifier *kian; 440 + int gsi, idx; 441 + 442 + idx = srcu_read_lock(&kvm->irq_srcu); 443 + gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin); 444 + if (gsi != -1) 445 + hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, 446 + link) 447 + if (kian->gsi == gsi) { 448 + srcu_read_unlock(&kvm->irq_srcu, idx); 449 + return true; 450 + } 451 + 452 + srcu_read_unlock(&kvm->irq_srcu, idx); 453 + 454 + return false; 455 + } 456 + EXPORT_SYMBOL_GPL(kvm_irq_has_notifier); 457 + 458 + void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin) 459 + { 460 + struct kvm_irq_ack_notifier *kian; 461 + int gsi, idx; 462 + 463 + trace_kvm_ack_irq(irqchip, pin); 464 + 465 + idx = srcu_read_lock(&kvm->irq_srcu); 466 + gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin); 467 + if (gsi != -1) 468 + hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, 469 + link) 470 + if (kian->gsi == gsi) 471 + kian->irq_acked(kian); 472 + srcu_read_unlock(&kvm->irq_srcu, idx); 473 + } 474 + 475 + void kvm_register_irq_ack_notifier(struct kvm *kvm, 476 + struct kvm_irq_ack_notifier *kian) 477 + { 478 + mutex_lock(&kvm->irq_lock); 479 + hlist_add_head_rcu(&kian->link, &kvm->irq_ack_notifier_list); 480 + mutex_unlock(&kvm->irq_lock); 481 + #ifdef __KVM_HAVE_IOAPIC 482 + kvm_vcpu_request_scan_ioapic(kvm); 483 + #endif 484 + } 485 + 486 + void kvm_unregister_irq_ack_notifier(struct kvm *kvm, 487 + struct kvm_irq_ack_notifier *kian) 488 + { 489 + mutex_lock(&kvm->irq_lock); 490 + hlist_del_init_rcu(&kian->link); 491 + mutex_unlock(&kvm->irq_lock); 492 + synchronize_srcu(&kvm->irq_srcu); 493 + #ifdef __KVM_HAVE_IOAPIC 494 + kvm_vcpu_request_scan_ioapic(kvm); 495 + #endif 496 + } 448 497 #endif 449 498 450 499 void 451 500 kvm_eventfd_init(struct kvm *kvm) 452 501 { 453 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 502 + #ifdef CONFIG_HAVE_KVM_IRQFD 454 503 spin_lock_init(&kvm->irqfds.lock); 455 504 INIT_LIST_HEAD(&kvm->irqfds.items); 456 505 INIT_LIST_HEAD(&kvm->irqfds.resampler_list); ··· 520 447 INIT_LIST_HEAD(&kvm->ioeventfds); 521 448 } 522 449 523 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 450 + #ifdef CONFIG_HAVE_KVM_IRQFD 524 451 /* 525 452 * shutdown any irqfd's that match fd+gsi 526 453 */ ··· 539 466 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) { 540 467 if (irqfd->eventfd == eventfd && irqfd->gsi == args->gsi) { 541 468 /* 542 - * This rcu_assign_pointer is needed for when 469 + * This clearing of irq_entry.type is needed for when 543 470 * another thread calls kvm_irq_routing_update before 544 471 * we flush workqueue below (we synchronize with 545 472 * kvm_irq_routing_update using irqfds.lock). 546 - * It is paired with synchronize_srcu done by caller 547 - * of that function. 548 473 */ 549 - rcu_assign_pointer(irqfd->irq_entry, NULL); 474 + write_seqcount_begin(&irqfd->irq_entry_sc); 475 + irqfd->irq_entry.type = 0; 476 + write_seqcount_end(&irqfd->irq_entry_sc); 550 477 irqfd_deactivate(irqfd); 551 478 } 552 479 } ··· 601 528 } 602 529 603 530 /* 604 - * Change irq_routing and irqfd. 531 + * Take note of a change in irq routing. 605 532 * Caller must invoke synchronize_srcu(&kvm->irq_srcu) afterwards. 606 533 */ 607 - void kvm_irq_routing_update(struct kvm *kvm, 608 - struct kvm_irq_routing_table *irq_rt) 534 + void kvm_irq_routing_update(struct kvm *kvm) 609 535 { 610 536 struct _irqfd *irqfd; 611 537 612 538 spin_lock_irq(&kvm->irqfds.lock); 613 539 614 - rcu_assign_pointer(kvm->irq_routing, irq_rt); 615 - 616 540 list_for_each_entry(irqfd, &kvm->irqfds.items, list) 617 - irqfd_update(kvm, irqfd, irq_rt); 541 + irqfd_update(kvm, irqfd); 618 542 619 543 spin_unlock_irq(&kvm->irqfds.lock); 620 544 }
+10 -14
virt/kvm/irq_comm.c
··· 160 160 */ 161 161 int kvm_set_irq_inatomic(struct kvm *kvm, int irq_source_id, u32 irq, int level) 162 162 { 163 + struct kvm_kernel_irq_routing_entry entries[KVM_NR_IRQCHIPS]; 163 164 struct kvm_kernel_irq_routing_entry *e; 164 165 int ret = -EINVAL; 165 - struct kvm_irq_routing_table *irq_rt; 166 166 int idx; 167 167 168 168 trace_kvm_set_irq(irq, level, irq_source_id); ··· 176 176 * which is limited to 1:1 GSI mapping. 177 177 */ 178 178 idx = srcu_read_lock(&kvm->irq_srcu); 179 - irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu); 180 - if (irq < irq_rt->nr_rt_entries) 181 - hlist_for_each_entry(e, &irq_rt->map[irq], link) { 182 - if (likely(e->type == KVM_IRQ_ROUTING_MSI)) 183 - ret = kvm_set_msi_inatomic(e, kvm); 184 - else 185 - ret = -EWOULDBLOCK; 186 - break; 187 - } 179 + if (kvm_irq_map_gsi(kvm, entries, irq) > 0) { 180 + e = &entries[0]; 181 + if (likely(e->type == KVM_IRQ_ROUTING_MSI)) 182 + ret = kvm_set_msi_inatomic(e, kvm); 183 + else 184 + ret = -EWOULDBLOCK; 185 + } 188 186 srcu_read_unlock(&kvm->irq_srcu, idx); 189 187 return ret; 190 188 } ··· 262 264 int idx, gsi; 263 265 264 266 idx = srcu_read_lock(&kvm->irq_srcu); 265 - gsi = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu)->chip[irqchip][pin]; 267 + gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin); 266 268 if (gsi != -1) 267 269 hlist_for_each_entry_rcu(kimn, &kvm->mask_notifier_list, link) 268 270 if (kimn->irq == gsi) ··· 270 272 srcu_read_unlock(&kvm->irq_srcu, idx); 271 273 } 272 274 273 - int kvm_set_routing_entry(struct kvm_irq_routing_table *rt, 274 - struct kvm_kernel_irq_routing_entry *e, 275 + int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, 275 276 const struct kvm_irq_routing_entry *ue) 276 277 { 277 278 int r = -EINVAL; ··· 301 304 e->irqchip.pin = ue->u.irqchip.pin + delta; 302 305 if (e->irqchip.pin >= max_pin) 303 306 goto out; 304 - rt->chip[ue->u.irqchip.irqchip][e->irqchip.pin] = ue->gsi; 305 307 break; 306 308 case KVM_IRQ_ROUTING_MSI: 307 309 e->set = kvm_set_msi;
+37 -61
virt/kvm/irqchip.c
··· 31 31 #include <trace/events/kvm.h> 32 32 #include "irq.h" 33 33 34 - bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin) 34 + struct kvm_irq_routing_table { 35 + int chip[KVM_NR_IRQCHIPS][KVM_IRQCHIP_NUM_PINS]; 36 + struct kvm_kernel_irq_routing_entry *rt_entries; 37 + u32 nr_rt_entries; 38 + /* 39 + * Array indexed by gsi. Each entry contains list of irq chips 40 + * the gsi is connected to. 41 + */ 42 + struct hlist_head map[0]; 43 + }; 44 + 45 + int kvm_irq_map_gsi(struct kvm *kvm, 46 + struct kvm_kernel_irq_routing_entry *entries, int gsi) 35 47 { 36 - struct kvm_irq_ack_notifier *kian; 37 - int gsi, idx; 48 + struct kvm_irq_routing_table *irq_rt; 49 + struct kvm_kernel_irq_routing_entry *e; 50 + int n = 0; 38 51 39 - idx = srcu_read_lock(&kvm->irq_srcu); 40 - gsi = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu)->chip[irqchip][pin]; 41 - if (gsi != -1) 42 - hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, 43 - link) 44 - if (kian->gsi == gsi) { 45 - srcu_read_unlock(&kvm->irq_srcu, idx); 46 - return true; 47 - } 52 + irq_rt = srcu_dereference_check(kvm->irq_routing, &kvm->irq_srcu, 53 + lockdep_is_held(&kvm->irq_lock)); 54 + if (gsi < irq_rt->nr_rt_entries) { 55 + hlist_for_each_entry(e, &irq_rt->map[gsi], link) { 56 + entries[n] = *e; 57 + ++n; 58 + } 59 + } 48 60 49 - srcu_read_unlock(&kvm->irq_srcu, idx); 50 - 51 - return false; 52 - } 53 - EXPORT_SYMBOL_GPL(kvm_irq_has_notifier); 54 - 55 - void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin) 56 - { 57 - struct kvm_irq_ack_notifier *kian; 58 - int gsi, idx; 59 - 60 - trace_kvm_ack_irq(irqchip, pin); 61 - 62 - idx = srcu_read_lock(&kvm->irq_srcu); 63 - gsi = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu)->chip[irqchip][pin]; 64 - if (gsi != -1) 65 - hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, 66 - link) 67 - if (kian->gsi == gsi) 68 - kian->irq_acked(kian); 69 - srcu_read_unlock(&kvm->irq_srcu, idx); 61 + return n; 70 62 } 71 63 72 - void kvm_register_irq_ack_notifier(struct kvm *kvm, 73 - struct kvm_irq_ack_notifier *kian) 64 + int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin) 74 65 { 75 - mutex_lock(&kvm->irq_lock); 76 - hlist_add_head_rcu(&kian->link, &kvm->irq_ack_notifier_list); 77 - mutex_unlock(&kvm->irq_lock); 78 - #ifdef __KVM_HAVE_IOAPIC 79 - kvm_vcpu_request_scan_ioapic(kvm); 80 - #endif 81 - } 66 + struct kvm_irq_routing_table *irq_rt; 82 67 83 - void kvm_unregister_irq_ack_notifier(struct kvm *kvm, 84 - struct kvm_irq_ack_notifier *kian) 85 - { 86 - mutex_lock(&kvm->irq_lock); 87 - hlist_del_init_rcu(&kian->link); 88 - mutex_unlock(&kvm->irq_lock); 89 - synchronize_srcu(&kvm->irq_srcu); 90 - #ifdef __KVM_HAVE_IOAPIC 91 - kvm_vcpu_request_scan_ioapic(kvm); 92 - #endif 68 + irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu); 69 + return irq_rt->chip[irqchip][pin]; 93 70 } 94 71 95 72 int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi) ··· 92 115 int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, 93 116 bool line_status) 94 117 { 95 - struct kvm_kernel_irq_routing_entry *e, irq_set[KVM_NR_IRQCHIPS]; 96 - int ret = -1, i = 0, idx; 97 - struct kvm_irq_routing_table *irq_rt; 118 + struct kvm_kernel_irq_routing_entry irq_set[KVM_NR_IRQCHIPS]; 119 + int ret = -1, i, idx; 98 120 99 121 trace_kvm_set_irq(irq, level, irq_source_id); 100 122 ··· 102 126 * writes to the unused one. 103 127 */ 104 128 idx = srcu_read_lock(&kvm->irq_srcu); 105 - irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu); 106 - if (irq < irq_rt->nr_rt_entries) 107 - hlist_for_each_entry(e, &irq_rt->map[irq], link) 108 - irq_set[i++] = *e; 129 + i = kvm_irq_map_gsi(kvm, irq_set, irq); 109 130 srcu_read_unlock(&kvm->irq_srcu, idx); 110 131 111 132 while(i--) { ··· 144 171 145 172 e->gsi = ue->gsi; 146 173 e->type = ue->type; 147 - r = kvm_set_routing_entry(rt, e, ue); 174 + r = kvm_set_routing_entry(e, ue); 148 175 if (r) 149 176 goto out; 177 + if (e->type == KVM_IRQ_ROUTING_IRQCHIP) 178 + rt->chip[e->irqchip.irqchip][e->irqchip.pin] = e->gsi; 150 179 151 180 hlist_add_head(&e->link, &rt->map[e->gsi]); 152 181 r = 0; ··· 199 224 200 225 mutex_lock(&kvm->irq_lock); 201 226 old = kvm->irq_routing; 202 - kvm_irq_routing_update(kvm, new); 227 + rcu_assign_pointer(kvm->irq_routing, new); 228 + kvm_irq_routing_update(kvm); 203 229 mutex_unlock(&kvm->irq_lock); 204 230 205 231 synchronize_srcu_expedited(&kvm->irq_srcu);
+34 -28
virt/kvm/kvm_main.c
··· 465 465 466 466 #ifdef CONFIG_HAVE_KVM_IRQCHIP 467 467 INIT_HLIST_HEAD(&kvm->mask_notifier_list); 468 + #endif 469 + #ifdef CONFIG_HAVE_KVM_IRQFD 468 470 INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list); 469 471 #endif 470 472 ··· 2326 2324 return 0; 2327 2325 } 2328 2326 2327 + static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) 2328 + { 2329 + switch (arg) { 2330 + case KVM_CAP_USER_MEMORY: 2331 + case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: 2332 + case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS: 2333 + #ifdef CONFIG_KVM_APIC_ARCHITECTURE 2334 + case KVM_CAP_SET_BOOT_CPU_ID: 2335 + #endif 2336 + case KVM_CAP_INTERNAL_ERROR_DATA: 2337 + #ifdef CONFIG_HAVE_KVM_MSI 2338 + case KVM_CAP_SIGNAL_MSI: 2339 + #endif 2340 + #ifdef CONFIG_HAVE_KVM_IRQFD 2341 + case KVM_CAP_IRQFD_RESAMPLE: 2342 + #endif 2343 + case KVM_CAP_CHECK_EXTENSION_VM: 2344 + return 1; 2345 + #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 2346 + case KVM_CAP_IRQ_ROUTING: 2347 + return KVM_MAX_IRQ_ROUTES; 2348 + #endif 2349 + default: 2350 + break; 2351 + } 2352 + return kvm_vm_ioctl_check_extension(kvm, arg); 2353 + } 2354 + 2329 2355 static long kvm_vm_ioctl(struct file *filp, 2330 2356 unsigned int ioctl, unsigned long arg) 2331 2357 { ··· 2517 2487 r = 0; 2518 2488 break; 2519 2489 } 2490 + case KVM_CHECK_EXTENSION: 2491 + r = kvm_vm_ioctl_check_extension_generic(kvm, arg); 2492 + break; 2520 2493 default: 2521 2494 r = kvm_arch_vm_ioctl(filp, ioctl, arg); 2522 2495 if (r == -ENOTTY) ··· 2604 2571 return r; 2605 2572 } 2606 2573 2607 - static long kvm_dev_ioctl_check_extension_generic(long arg) 2608 - { 2609 - switch (arg) { 2610 - case KVM_CAP_USER_MEMORY: 2611 - case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: 2612 - case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS: 2613 - #ifdef CONFIG_KVM_APIC_ARCHITECTURE 2614 - case KVM_CAP_SET_BOOT_CPU_ID: 2615 - #endif 2616 - case KVM_CAP_INTERNAL_ERROR_DATA: 2617 - #ifdef CONFIG_HAVE_KVM_MSI 2618 - case KVM_CAP_SIGNAL_MSI: 2619 - #endif 2620 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 2621 - case KVM_CAP_IRQFD_RESAMPLE: 2622 - #endif 2623 - return 1; 2624 - #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING 2625 - case KVM_CAP_IRQ_ROUTING: 2626 - return KVM_MAX_IRQ_ROUTES; 2627 - #endif 2628 - default: 2629 - break; 2630 - } 2631 - return kvm_dev_ioctl_check_extension(arg); 2632 - } 2633 - 2634 2574 static long kvm_dev_ioctl(struct file *filp, 2635 2575 unsigned int ioctl, unsigned long arg) 2636 2576 { ··· 2620 2614 r = kvm_dev_ioctl_create_vm(arg); 2621 2615 break; 2622 2616 case KVM_CHECK_EXTENSION: 2623 - r = kvm_dev_ioctl_check_extension_generic(arg); 2617 + r = kvm_vm_ioctl_check_extension_generic(NULL, arg); 2624 2618 break; 2625 2619 case KVM_GET_VCPU_MMAP_SIZE: 2626 2620 r = -EINVAL;