1bbf45ba5SHollis Blanchard /* 2bbf45ba5SHollis Blanchard * This program is free software; you can redistribute it and/or modify 3bbf45ba5SHollis Blanchard * it under the terms of the GNU General Public License, version 2, as 4bbf45ba5SHollis Blanchard * published by the Free Software Foundation. 5bbf45ba5SHollis Blanchard * 6bbf45ba5SHollis Blanchard * This program is distributed in the hope that it will be useful, 7bbf45ba5SHollis Blanchard * but WITHOUT ANY WARRANTY; without even the implied warranty of 8bbf45ba5SHollis Blanchard * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9bbf45ba5SHollis Blanchard * GNU General Public License for more details. 10bbf45ba5SHollis Blanchard * 11bbf45ba5SHollis Blanchard * You should have received a copy of the GNU General Public License 12bbf45ba5SHollis Blanchard * along with this program; if not, write to the Free Software 13bbf45ba5SHollis Blanchard * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14bbf45ba5SHollis Blanchard * 15bbf45ba5SHollis Blanchard * Copyright IBM Corp. 2007 16bbf45ba5SHollis Blanchard * 17bbf45ba5SHollis Blanchard * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18bbf45ba5SHollis Blanchard * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> 19bbf45ba5SHollis Blanchard */ 20bbf45ba5SHollis Blanchard 21bbf45ba5SHollis Blanchard #include <linux/errno.h> 22bbf45ba5SHollis Blanchard #include <linux/err.h> 23bbf45ba5SHollis Blanchard #include <linux/kvm_host.h> 24bbf45ba5SHollis Blanchard #include <linux/module.h> 25bbf45ba5SHollis Blanchard #include <linux/vmalloc.h> 26bbf45ba5SHollis Blanchard #include <linux/fs.h> 27bbf45ba5SHollis Blanchard #include <asm/cputable.h> 28bbf45ba5SHollis Blanchard #include <asm/uaccess.h> 29bbf45ba5SHollis Blanchard #include <asm/kvm_ppc.h> 3083aae4a8SHollis Blanchard #include <asm/tlbflush.h> 3173e75b41SHollis Blanchard #include "timing.h" 32fad7b9b5SPaul Mackerras #include "../mm/mmu_decl.h" 33bbf45ba5SHollis Blanchard 34bbf45ba5SHollis Blanchard gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn) 35bbf45ba5SHollis Blanchard { 36bbf45ba5SHollis Blanchard return gfn; 37bbf45ba5SHollis Blanchard } 38bbf45ba5SHollis Blanchard 39bbf45ba5SHollis Blanchard int kvm_cpu_has_interrupt(struct kvm_vcpu *v) 40bbf45ba5SHollis Blanchard { 4145c5eb67SHollis Blanchard return !!(v->arch.pending_exceptions); 42bbf45ba5SHollis Blanchard } 43bbf45ba5SHollis Blanchard 44bbf45ba5SHollis Blanchard int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) 45bbf45ba5SHollis Blanchard { 4645c5eb67SHollis Blanchard return !(v->arch.msr & MSR_WE); 47bbf45ba5SHollis Blanchard } 48bbf45ba5SHollis Blanchard 49bbf45ba5SHollis Blanchard 50bbf45ba5SHollis Blanchard int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu) 51bbf45ba5SHollis Blanchard { 52bbf45ba5SHollis Blanchard enum emulation_result er; 53bbf45ba5SHollis Blanchard int r; 54bbf45ba5SHollis Blanchard 55bbf45ba5SHollis Blanchard er = kvmppc_emulate_instruction(run, vcpu); 56bbf45ba5SHollis Blanchard switch (er) { 57bbf45ba5SHollis Blanchard case EMULATE_DONE: 58bbf45ba5SHollis Blanchard /* Future optimization: only reload non-volatiles if they were 59bbf45ba5SHollis Blanchard * actually modified. */ 60bbf45ba5SHollis Blanchard r = RESUME_GUEST_NV; 61bbf45ba5SHollis Blanchard break; 62bbf45ba5SHollis Blanchard case EMULATE_DO_MMIO: 63bbf45ba5SHollis Blanchard run->exit_reason = KVM_EXIT_MMIO; 64bbf45ba5SHollis Blanchard /* We must reload nonvolatiles because "update" load/store 65bbf45ba5SHollis Blanchard * instructions modify register state. */ 66bbf45ba5SHollis Blanchard /* Future optimization: only reload non-volatiles if they were 67bbf45ba5SHollis Blanchard * actually modified. */ 68bbf45ba5SHollis Blanchard r = RESUME_HOST_NV; 69bbf45ba5SHollis Blanchard break; 70bbf45ba5SHollis Blanchard case EMULATE_FAIL: 71bbf45ba5SHollis Blanchard /* XXX Deliver Program interrupt to guest. */ 72bbf45ba5SHollis Blanchard printk(KERN_EMERG "%s: emulation failed (%08x)\n", __func__, 73bbf45ba5SHollis Blanchard vcpu->arch.last_inst); 74bbf45ba5SHollis Blanchard r = RESUME_HOST; 75bbf45ba5SHollis Blanchard break; 76bbf45ba5SHollis Blanchard default: 77bbf45ba5SHollis Blanchard BUG(); 78bbf45ba5SHollis Blanchard } 79bbf45ba5SHollis Blanchard 80bbf45ba5SHollis Blanchard return r; 81bbf45ba5SHollis Blanchard } 82bbf45ba5SHollis Blanchard 83bbf45ba5SHollis Blanchard void kvm_arch_hardware_enable(void *garbage) 84bbf45ba5SHollis Blanchard { 85bbf45ba5SHollis Blanchard } 86bbf45ba5SHollis Blanchard 87bbf45ba5SHollis Blanchard void kvm_arch_hardware_disable(void *garbage) 88bbf45ba5SHollis Blanchard { 89bbf45ba5SHollis Blanchard } 90bbf45ba5SHollis Blanchard 91bbf45ba5SHollis Blanchard int kvm_arch_hardware_setup(void) 92bbf45ba5SHollis Blanchard { 93bbf45ba5SHollis Blanchard return 0; 94bbf45ba5SHollis Blanchard } 95bbf45ba5SHollis Blanchard 96bbf45ba5SHollis Blanchard void kvm_arch_hardware_unsetup(void) 97bbf45ba5SHollis Blanchard { 98bbf45ba5SHollis Blanchard } 99bbf45ba5SHollis Blanchard 100bbf45ba5SHollis Blanchard void kvm_arch_check_processor_compat(void *rtn) 101bbf45ba5SHollis Blanchard { 1029dd921cfSHollis Blanchard *(int *)rtn = kvmppc_core_check_processor_compat(); 103bbf45ba5SHollis Blanchard } 104bbf45ba5SHollis Blanchard 105bbf45ba5SHollis Blanchard struct kvm *kvm_arch_create_vm(void) 106bbf45ba5SHollis Blanchard { 107bbf45ba5SHollis Blanchard struct kvm *kvm; 108bbf45ba5SHollis Blanchard 109bbf45ba5SHollis Blanchard kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); 110bbf45ba5SHollis Blanchard if (!kvm) 111bbf45ba5SHollis Blanchard return ERR_PTR(-ENOMEM); 112bbf45ba5SHollis Blanchard 113bbf45ba5SHollis Blanchard return kvm; 114bbf45ba5SHollis Blanchard } 115bbf45ba5SHollis Blanchard 116bbf45ba5SHollis Blanchard static void kvmppc_free_vcpus(struct kvm *kvm) 117bbf45ba5SHollis Blanchard { 118bbf45ba5SHollis Blanchard unsigned int i; 119bbf45ba5SHollis Blanchard 120bbf45ba5SHollis Blanchard for (i = 0; i < KVM_MAX_VCPUS; ++i) { 121bbf45ba5SHollis Blanchard if (kvm->vcpus[i]) { 122bbf45ba5SHollis Blanchard kvm_arch_vcpu_free(kvm->vcpus[i]); 123bbf45ba5SHollis Blanchard kvm->vcpus[i] = NULL; 124bbf45ba5SHollis Blanchard } 125bbf45ba5SHollis Blanchard } 126bbf45ba5SHollis Blanchard } 127bbf45ba5SHollis Blanchard 128ad8ba2cdSSheng Yang void kvm_arch_sync_events(struct kvm *kvm) 129ad8ba2cdSSheng Yang { 130ad8ba2cdSSheng Yang } 131ad8ba2cdSSheng Yang 132bbf45ba5SHollis Blanchard void kvm_arch_destroy_vm(struct kvm *kvm) 133bbf45ba5SHollis Blanchard { 134bbf45ba5SHollis Blanchard kvmppc_free_vcpus(kvm); 135bbf45ba5SHollis Blanchard kvm_free_physmem(kvm); 136bbf45ba5SHollis Blanchard kfree(kvm); 137bbf45ba5SHollis Blanchard } 138bbf45ba5SHollis Blanchard 139bbf45ba5SHollis Blanchard int kvm_dev_ioctl_check_extension(long ext) 140bbf45ba5SHollis Blanchard { 141bbf45ba5SHollis Blanchard int r; 142bbf45ba5SHollis Blanchard 143bbf45ba5SHollis Blanchard switch (ext) { 144588968b6SLaurent Vivier case KVM_CAP_COALESCED_MMIO: 145588968b6SLaurent Vivier r = KVM_COALESCED_MMIO_PAGE_OFFSET; 146588968b6SLaurent Vivier break; 147bbf45ba5SHollis Blanchard default: 148bbf45ba5SHollis Blanchard r = 0; 149bbf45ba5SHollis Blanchard break; 150bbf45ba5SHollis Blanchard } 151bbf45ba5SHollis Blanchard return r; 152bbf45ba5SHollis Blanchard 153bbf45ba5SHollis Blanchard } 154bbf45ba5SHollis Blanchard 155bbf45ba5SHollis Blanchard long kvm_arch_dev_ioctl(struct file *filp, 156bbf45ba5SHollis Blanchard unsigned int ioctl, unsigned long arg) 157bbf45ba5SHollis Blanchard { 158bbf45ba5SHollis Blanchard return -EINVAL; 159bbf45ba5SHollis Blanchard } 160bbf45ba5SHollis Blanchard 161bbf45ba5SHollis Blanchard int kvm_arch_set_memory_region(struct kvm *kvm, 162bbf45ba5SHollis Blanchard struct kvm_userspace_memory_region *mem, 163bbf45ba5SHollis Blanchard struct kvm_memory_slot old, 164bbf45ba5SHollis Blanchard int user_alloc) 165bbf45ba5SHollis Blanchard { 166bbf45ba5SHollis Blanchard return 0; 167bbf45ba5SHollis Blanchard } 168bbf45ba5SHollis Blanchard 16934d4cb8fSMarcelo Tosatti void kvm_arch_flush_shadow(struct kvm *kvm) 17034d4cb8fSMarcelo Tosatti { 17134d4cb8fSMarcelo Tosatti } 17234d4cb8fSMarcelo Tosatti 173bbf45ba5SHollis Blanchard struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) 174bbf45ba5SHollis Blanchard { 17573e75b41SHollis Blanchard struct kvm_vcpu *vcpu; 17673e75b41SHollis Blanchard vcpu = kvmppc_core_vcpu_create(kvm, id); 17773e75b41SHollis Blanchard kvmppc_create_vcpu_debugfs(vcpu, id); 17873e75b41SHollis Blanchard return vcpu; 179bbf45ba5SHollis Blanchard } 180bbf45ba5SHollis Blanchard 181bbf45ba5SHollis Blanchard void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) 182bbf45ba5SHollis Blanchard { 18373e75b41SHollis Blanchard kvmppc_remove_vcpu_debugfs(vcpu); 184db93f574SHollis Blanchard kvmppc_core_vcpu_free(vcpu); 185bbf45ba5SHollis Blanchard } 186bbf45ba5SHollis Blanchard 187bbf45ba5SHollis Blanchard void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) 188bbf45ba5SHollis Blanchard { 189bbf45ba5SHollis Blanchard kvm_arch_vcpu_free(vcpu); 190bbf45ba5SHollis Blanchard } 191bbf45ba5SHollis Blanchard 192bbf45ba5SHollis Blanchard int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) 193bbf45ba5SHollis Blanchard { 1949dd921cfSHollis Blanchard return kvmppc_core_pending_dec(vcpu); 195bbf45ba5SHollis Blanchard } 196bbf45ba5SHollis Blanchard 197bbf45ba5SHollis Blanchard static void kvmppc_decrementer_func(unsigned long data) 198bbf45ba5SHollis Blanchard { 199bbf45ba5SHollis Blanchard struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; 200bbf45ba5SHollis Blanchard 2019dd921cfSHollis Blanchard kvmppc_core_queue_dec(vcpu); 20245c5eb67SHollis Blanchard 20345c5eb67SHollis Blanchard if (waitqueue_active(&vcpu->wq)) { 20445c5eb67SHollis Blanchard wake_up_interruptible(&vcpu->wq); 20545c5eb67SHollis Blanchard vcpu->stat.halt_wakeup++; 20645c5eb67SHollis Blanchard } 207bbf45ba5SHollis Blanchard } 208bbf45ba5SHollis Blanchard 209bbf45ba5SHollis Blanchard int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) 210bbf45ba5SHollis Blanchard { 211bbf45ba5SHollis Blanchard setup_timer(&vcpu->arch.dec_timer, kvmppc_decrementer_func, 212bbf45ba5SHollis Blanchard (unsigned long)vcpu); 213bbf45ba5SHollis Blanchard 214bbf45ba5SHollis Blanchard return 0; 215bbf45ba5SHollis Blanchard } 216bbf45ba5SHollis Blanchard 217bbf45ba5SHollis Blanchard void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) 218bbf45ba5SHollis Blanchard { 219*ecc0981fSHollis Blanchard kvmppc_mmu_destroy(vcpu); 220bbf45ba5SHollis Blanchard } 221bbf45ba5SHollis Blanchard 222bbf45ba5SHollis Blanchard void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 223bbf45ba5SHollis Blanchard { 2246a0ab738SHollis Blanchard if (vcpu->guest_debug.enabled) 2259dd921cfSHollis Blanchard kvmppc_core_load_guest_debugstate(vcpu); 22683aae4a8SHollis Blanchard 2279dd921cfSHollis Blanchard kvmppc_core_vcpu_load(vcpu, cpu); 228bbf45ba5SHollis Blanchard } 229bbf45ba5SHollis Blanchard 230bbf45ba5SHollis Blanchard void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) 231bbf45ba5SHollis Blanchard { 2326a0ab738SHollis Blanchard if (vcpu->guest_debug.enabled) 2339dd921cfSHollis Blanchard kvmppc_core_load_host_debugstate(vcpu); 23483aae4a8SHollis Blanchard 23583aae4a8SHollis Blanchard /* Don't leave guest TLB entries resident when being de-scheduled. */ 23683aae4a8SHollis Blanchard /* XXX It would be nice to differentiate between heavyweight exit and 23783aae4a8SHollis Blanchard * sched_out here, since we could avoid the TLB flush for heavyweight 23883aae4a8SHollis Blanchard * exits. */ 2392a4aca11SBenjamin Herrenschmidt _tlbil_all(); 2409dd921cfSHollis Blanchard kvmppc_core_vcpu_put(vcpu); 241bbf45ba5SHollis Blanchard } 242bbf45ba5SHollis Blanchard 243d0bfb940SJan Kiszka int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 244d0bfb940SJan Kiszka struct kvm_guest_debug *dbg) 245bbf45ba5SHollis Blanchard { 2466a0ab738SHollis Blanchard int i; 2476a0ab738SHollis Blanchard 2486a0ab738SHollis Blanchard vcpu->guest_debug.enabled = dbg->enabled; 2496a0ab738SHollis Blanchard if (vcpu->guest_debug.enabled) { 2506a0ab738SHollis Blanchard for (i=0; i < ARRAY_SIZE(vcpu->guest_debug.bp); i++) { 2516a0ab738SHollis Blanchard if (dbg->breakpoints[i].enabled) 2526a0ab738SHollis Blanchard vcpu->guest_debug.bp[i] = dbg->breakpoints[i].address; 2536a0ab738SHollis Blanchard else 2546a0ab738SHollis Blanchard vcpu->guest_debug.bp[i] = 0; 2556a0ab738SHollis Blanchard } 2566a0ab738SHollis Blanchard } 2576a0ab738SHollis Blanchard 2586a0ab738SHollis Blanchard return 0; 259bbf45ba5SHollis Blanchard } 260bbf45ba5SHollis Blanchard 261bbf45ba5SHollis Blanchard static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu, 262bbf45ba5SHollis Blanchard struct kvm_run *run) 263bbf45ba5SHollis Blanchard { 2645cf8ca22SHollis Blanchard ulong *gpr = &vcpu->arch.gpr[vcpu->arch.io_gpr]; 265bbf45ba5SHollis Blanchard *gpr = run->dcr.data; 266bbf45ba5SHollis Blanchard } 267bbf45ba5SHollis Blanchard 268bbf45ba5SHollis Blanchard static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu, 269bbf45ba5SHollis Blanchard struct kvm_run *run) 270bbf45ba5SHollis Blanchard { 2715cf8ca22SHollis Blanchard ulong *gpr = &vcpu->arch.gpr[vcpu->arch.io_gpr]; 272bbf45ba5SHollis Blanchard 273bbf45ba5SHollis Blanchard if (run->mmio.len > sizeof(*gpr)) { 274bbf45ba5SHollis Blanchard printk(KERN_ERR "bad MMIO length: %d\n", run->mmio.len); 275bbf45ba5SHollis Blanchard return; 276bbf45ba5SHollis Blanchard } 277bbf45ba5SHollis Blanchard 278bbf45ba5SHollis Blanchard if (vcpu->arch.mmio_is_bigendian) { 279bbf45ba5SHollis Blanchard switch (run->mmio.len) { 280bbf45ba5SHollis Blanchard case 4: *gpr = *(u32 *)run->mmio.data; break; 281bbf45ba5SHollis Blanchard case 2: *gpr = *(u16 *)run->mmio.data; break; 282bbf45ba5SHollis Blanchard case 1: *gpr = *(u8 *)run->mmio.data; break; 283bbf45ba5SHollis Blanchard } 284bbf45ba5SHollis Blanchard } else { 285bbf45ba5SHollis Blanchard /* Convert BE data from userland back to LE. */ 286bbf45ba5SHollis Blanchard switch (run->mmio.len) { 287bbf45ba5SHollis Blanchard case 4: *gpr = ld_le32((u32 *)run->mmio.data); break; 288bbf45ba5SHollis Blanchard case 2: *gpr = ld_le16((u16 *)run->mmio.data); break; 289bbf45ba5SHollis Blanchard case 1: *gpr = *(u8 *)run->mmio.data; break; 290bbf45ba5SHollis Blanchard } 291bbf45ba5SHollis Blanchard } 292bbf45ba5SHollis Blanchard } 293bbf45ba5SHollis Blanchard 294bbf45ba5SHollis Blanchard int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, 295bbf45ba5SHollis Blanchard unsigned int rt, unsigned int bytes, int is_bigendian) 296bbf45ba5SHollis Blanchard { 297bbf45ba5SHollis Blanchard if (bytes > sizeof(run->mmio.data)) { 298bbf45ba5SHollis Blanchard printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__, 299bbf45ba5SHollis Blanchard run->mmio.len); 300bbf45ba5SHollis Blanchard } 301bbf45ba5SHollis Blanchard 302bbf45ba5SHollis Blanchard run->mmio.phys_addr = vcpu->arch.paddr_accessed; 303bbf45ba5SHollis Blanchard run->mmio.len = bytes; 304bbf45ba5SHollis Blanchard run->mmio.is_write = 0; 305bbf45ba5SHollis Blanchard 306bbf45ba5SHollis Blanchard vcpu->arch.io_gpr = rt; 307bbf45ba5SHollis Blanchard vcpu->arch.mmio_is_bigendian = is_bigendian; 308bbf45ba5SHollis Blanchard vcpu->mmio_needed = 1; 309bbf45ba5SHollis Blanchard vcpu->mmio_is_write = 0; 310bbf45ba5SHollis Blanchard 311bbf45ba5SHollis Blanchard return EMULATE_DO_MMIO; 312bbf45ba5SHollis Blanchard } 313bbf45ba5SHollis Blanchard 314bbf45ba5SHollis Blanchard int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu, 315bbf45ba5SHollis Blanchard u32 val, unsigned int bytes, int is_bigendian) 316bbf45ba5SHollis Blanchard { 317bbf45ba5SHollis Blanchard void *data = run->mmio.data; 318bbf45ba5SHollis Blanchard 319bbf45ba5SHollis Blanchard if (bytes > sizeof(run->mmio.data)) { 320bbf45ba5SHollis Blanchard printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__, 321bbf45ba5SHollis Blanchard run->mmio.len); 322bbf45ba5SHollis Blanchard } 323bbf45ba5SHollis Blanchard 324bbf45ba5SHollis Blanchard run->mmio.phys_addr = vcpu->arch.paddr_accessed; 325bbf45ba5SHollis Blanchard run->mmio.len = bytes; 326bbf45ba5SHollis Blanchard run->mmio.is_write = 1; 327bbf45ba5SHollis Blanchard vcpu->mmio_needed = 1; 328bbf45ba5SHollis Blanchard vcpu->mmio_is_write = 1; 329bbf45ba5SHollis Blanchard 330bbf45ba5SHollis Blanchard /* Store the value at the lowest bytes in 'data'. */ 331bbf45ba5SHollis Blanchard if (is_bigendian) { 332bbf45ba5SHollis Blanchard switch (bytes) { 333bbf45ba5SHollis Blanchard case 4: *(u32 *)data = val; break; 334bbf45ba5SHollis Blanchard case 2: *(u16 *)data = val; break; 335bbf45ba5SHollis Blanchard case 1: *(u8 *)data = val; break; 336bbf45ba5SHollis Blanchard } 337bbf45ba5SHollis Blanchard } else { 338bbf45ba5SHollis Blanchard /* Store LE value into 'data'. */ 339bbf45ba5SHollis Blanchard switch (bytes) { 340bbf45ba5SHollis Blanchard case 4: st_le32(data, val); break; 341bbf45ba5SHollis Blanchard case 2: st_le16(data, val); break; 342bbf45ba5SHollis Blanchard case 1: *(u8 *)data = val; break; 343bbf45ba5SHollis Blanchard } 344bbf45ba5SHollis Blanchard } 345bbf45ba5SHollis Blanchard 346bbf45ba5SHollis Blanchard return EMULATE_DO_MMIO; 347bbf45ba5SHollis Blanchard } 348bbf45ba5SHollis Blanchard 349bbf45ba5SHollis Blanchard int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) 350bbf45ba5SHollis Blanchard { 351bbf45ba5SHollis Blanchard int r; 352bbf45ba5SHollis Blanchard sigset_t sigsaved; 353bbf45ba5SHollis Blanchard 35445c5eb67SHollis Blanchard vcpu_load(vcpu); 35545c5eb67SHollis Blanchard 356bbf45ba5SHollis Blanchard if (vcpu->sigset_active) 357bbf45ba5SHollis Blanchard sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 358bbf45ba5SHollis Blanchard 359bbf45ba5SHollis Blanchard if (vcpu->mmio_needed) { 360bbf45ba5SHollis Blanchard if (!vcpu->mmio_is_write) 361bbf45ba5SHollis Blanchard kvmppc_complete_mmio_load(vcpu, run); 362bbf45ba5SHollis Blanchard vcpu->mmio_needed = 0; 363bbf45ba5SHollis Blanchard } else if (vcpu->arch.dcr_needed) { 364bbf45ba5SHollis Blanchard if (!vcpu->arch.dcr_is_write) 365bbf45ba5SHollis Blanchard kvmppc_complete_dcr_load(vcpu, run); 366bbf45ba5SHollis Blanchard vcpu->arch.dcr_needed = 0; 367bbf45ba5SHollis Blanchard } 368bbf45ba5SHollis Blanchard 3699dd921cfSHollis Blanchard kvmppc_core_deliver_interrupts(vcpu); 370bbf45ba5SHollis Blanchard 371bbf45ba5SHollis Blanchard local_irq_disable(); 372bbf45ba5SHollis Blanchard kvm_guest_enter(); 373bbf45ba5SHollis Blanchard r = __kvmppc_vcpu_run(run, vcpu); 374bbf45ba5SHollis Blanchard kvm_guest_exit(); 375bbf45ba5SHollis Blanchard local_irq_enable(); 376bbf45ba5SHollis Blanchard 377bbf45ba5SHollis Blanchard if (vcpu->sigset_active) 378bbf45ba5SHollis Blanchard sigprocmask(SIG_SETMASK, &sigsaved, NULL); 379bbf45ba5SHollis Blanchard 38045c5eb67SHollis Blanchard vcpu_put(vcpu); 38145c5eb67SHollis Blanchard 382bbf45ba5SHollis Blanchard return r; 383bbf45ba5SHollis Blanchard } 384bbf45ba5SHollis Blanchard 385bbf45ba5SHollis Blanchard int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq) 386bbf45ba5SHollis Blanchard { 3879dd921cfSHollis Blanchard kvmppc_core_queue_external(vcpu, irq); 38845c5eb67SHollis Blanchard 38945c5eb67SHollis Blanchard if (waitqueue_active(&vcpu->wq)) { 39045c5eb67SHollis Blanchard wake_up_interruptible(&vcpu->wq); 39145c5eb67SHollis Blanchard vcpu->stat.halt_wakeup++; 39245c5eb67SHollis Blanchard } 39345c5eb67SHollis Blanchard 394bbf45ba5SHollis Blanchard return 0; 395bbf45ba5SHollis Blanchard } 396bbf45ba5SHollis Blanchard 397bbf45ba5SHollis Blanchard int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 398bbf45ba5SHollis Blanchard struct kvm_mp_state *mp_state) 399bbf45ba5SHollis Blanchard { 400bbf45ba5SHollis Blanchard return -EINVAL; 401bbf45ba5SHollis Blanchard } 402bbf45ba5SHollis Blanchard 403bbf45ba5SHollis Blanchard int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 404bbf45ba5SHollis Blanchard struct kvm_mp_state *mp_state) 405bbf45ba5SHollis Blanchard { 406bbf45ba5SHollis Blanchard return -EINVAL; 407bbf45ba5SHollis Blanchard } 408bbf45ba5SHollis Blanchard 409bbf45ba5SHollis Blanchard long kvm_arch_vcpu_ioctl(struct file *filp, 410bbf45ba5SHollis Blanchard unsigned int ioctl, unsigned long arg) 411bbf45ba5SHollis Blanchard { 412bbf45ba5SHollis Blanchard struct kvm_vcpu *vcpu = filp->private_data; 413bbf45ba5SHollis Blanchard void __user *argp = (void __user *)arg; 414bbf45ba5SHollis Blanchard long r; 415bbf45ba5SHollis Blanchard 416bbf45ba5SHollis Blanchard switch (ioctl) { 417bbf45ba5SHollis Blanchard case KVM_INTERRUPT: { 418bbf45ba5SHollis Blanchard struct kvm_interrupt irq; 419bbf45ba5SHollis Blanchard r = -EFAULT; 420bbf45ba5SHollis Blanchard if (copy_from_user(&irq, argp, sizeof(irq))) 421bbf45ba5SHollis Blanchard goto out; 422bbf45ba5SHollis Blanchard r = kvm_vcpu_ioctl_interrupt(vcpu, &irq); 423bbf45ba5SHollis Blanchard break; 424bbf45ba5SHollis Blanchard } 425bbf45ba5SHollis Blanchard default: 426bbf45ba5SHollis Blanchard r = -EINVAL; 427bbf45ba5SHollis Blanchard } 428bbf45ba5SHollis Blanchard 429bbf45ba5SHollis Blanchard out: 430bbf45ba5SHollis Blanchard return r; 431bbf45ba5SHollis Blanchard } 432bbf45ba5SHollis Blanchard 433bbf45ba5SHollis Blanchard int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) 434bbf45ba5SHollis Blanchard { 435bbf45ba5SHollis Blanchard return -ENOTSUPP; 436bbf45ba5SHollis Blanchard } 437bbf45ba5SHollis Blanchard 438bbf45ba5SHollis Blanchard long kvm_arch_vm_ioctl(struct file *filp, 439bbf45ba5SHollis Blanchard unsigned int ioctl, unsigned long arg) 440bbf45ba5SHollis Blanchard { 441bbf45ba5SHollis Blanchard long r; 442bbf45ba5SHollis Blanchard 443bbf45ba5SHollis Blanchard switch (ioctl) { 444bbf45ba5SHollis Blanchard default: 445bbf45ba5SHollis Blanchard r = -EINVAL; 446bbf45ba5SHollis Blanchard } 447bbf45ba5SHollis Blanchard 448bbf45ba5SHollis Blanchard return r; 449bbf45ba5SHollis Blanchard } 450bbf45ba5SHollis Blanchard 451bbf45ba5SHollis Blanchard int kvm_arch_init(void *opaque) 452bbf45ba5SHollis Blanchard { 453bbf45ba5SHollis Blanchard return 0; 454bbf45ba5SHollis Blanchard } 455bbf45ba5SHollis Blanchard 456bbf45ba5SHollis Blanchard void kvm_arch_exit(void) 457bbf45ba5SHollis Blanchard { 458bbf45ba5SHollis Blanchard } 459