2 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
3 * Author: Christoffer Dall <c.dall@virtualopensystems.com>
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.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <linux/errno.h>
20 #include <linux/err.h>
21 #include <linux/kvm_host.h>
22 #include <linux/module.h>
23 #include <linux/vmalloc.h>
25 #include <linux/mman.h>
26 #include <linux/sched.h>
27 #include <linux/kvm.h>
28 #include <trace/events/kvm.h>
30 #define CREATE_TRACE_POINTS
33 #include <asm/uaccess.h>
34 #include <asm/ptrace.h>
36 #include <asm/tlbflush.h>
37 #include <asm/cacheflush.h>
39 #include <asm/kvm_arm.h>
40 #include <asm/kvm_asm.h>
41 #include <asm/kvm_mmu.h>
42 #include <asm/kvm_emulate.h>
43 #include <asm/kvm_coproc.h>
44 #include <asm/kvm_psci.h>
47 __asm__(".arch_extension virt");
50 static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
51 static kvm_kernel_vfp_t __percpu *kvm_host_vfp_state;
52 static unsigned long hyp_default_vectors;
54 /* Per-CPU variable containing the currently running vcpu. */
55 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
57 /* The VMID used in the VTTBR */
58 static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
59 static u8 kvm_next_vmid;
60 static DEFINE_SPINLOCK(kvm_vmid_lock);
62 static bool vgic_present;
64 static void kvm_arm_set_running_vcpu(struct kvm_vcpu *vcpu)
66 BUG_ON(preemptible());
67 __get_cpu_var(kvm_arm_running_vcpu) = vcpu;
71 * kvm_arm_get_running_vcpu - get the vcpu running on the current CPU.
72 * Must be called from non-preemptible context
74 struct kvm_vcpu *kvm_arm_get_running_vcpu(void)
76 BUG_ON(preemptible());
77 return __get_cpu_var(kvm_arm_running_vcpu);
81 * kvm_arm_get_running_vcpus - get the per-CPU array of currently running vcpus.
83 struct kvm_vcpu __percpu **kvm_get_running_vcpus(void)
85 return &kvm_arm_running_vcpu;
88 int kvm_arch_hardware_enable(void *garbage)
93 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
95 return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
98 void kvm_arch_hardware_disable(void *garbage)
102 int kvm_arch_hardware_setup(void)
107 void kvm_arch_hardware_unsetup(void)
111 void kvm_arch_check_processor_compat(void *rtn)
116 void kvm_arch_sync_events(struct kvm *kvm)
121 * kvm_arch_init_vm - initializes a VM data structure
122 * @kvm: pointer to the KVM struct
124 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
131 ret = kvm_alloc_stage2_pgd(kvm);
135 ret = create_hyp_mappings(kvm, kvm + 1);
137 goto out_free_stage2_pgd;
139 /* Mark the initial VMID generation invalid */
140 kvm->arch.vmid_gen = 0;
144 kvm_free_stage2_pgd(kvm);
149 int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
151 return VM_FAULT_SIGBUS;
154 void kvm_arch_free_memslot(struct kvm_memory_slot *free,
155 struct kvm_memory_slot *dont)
159 int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages)
165 * kvm_arch_destroy_vm - destroy the VM data structure
166 * @kvm: pointer to the KVM struct
168 void kvm_arch_destroy_vm(struct kvm *kvm)
172 kvm_free_stage2_pgd(kvm);
174 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
176 kvm_arch_vcpu_free(kvm->vcpus[i]);
177 kvm->vcpus[i] = NULL;
182 int kvm_dev_ioctl_check_extension(long ext)
186 case KVM_CAP_IRQCHIP:
189 case KVM_CAP_USER_MEMORY:
190 case KVM_CAP_SYNC_MMU:
191 case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
192 case KVM_CAP_ONE_REG:
193 case KVM_CAP_ARM_PSCI:
196 case KVM_CAP_COALESCED_MMIO:
197 r = KVM_COALESCED_MMIO_PAGE_OFFSET;
199 case KVM_CAP_ARM_SET_DEVICE_ADDR:
201 case KVM_CAP_NR_VCPUS:
202 r = num_online_cpus();
204 case KVM_CAP_MAX_VCPUS:
214 long kvm_arch_dev_ioctl(struct file *filp,
215 unsigned int ioctl, unsigned long arg)
220 int kvm_arch_set_memory_region(struct kvm *kvm,
221 struct kvm_userspace_memory_region *mem,
222 struct kvm_memory_slot old,
228 int kvm_arch_prepare_memory_region(struct kvm *kvm,
229 struct kvm_memory_slot *memslot,
230 struct kvm_memory_slot old,
231 struct kvm_userspace_memory_region *mem,
237 void kvm_arch_commit_memory_region(struct kvm *kvm,
238 struct kvm_userspace_memory_region *mem,
239 struct kvm_memory_slot old,
244 void kvm_arch_flush_shadow_all(struct kvm *kvm)
248 void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
249 struct kvm_memory_slot *slot)
253 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
256 struct kvm_vcpu *vcpu;
258 vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
264 err = kvm_vcpu_init(vcpu, kvm, id);
268 err = create_hyp_mappings(vcpu, vcpu + 1);
274 kvm_vcpu_uninit(vcpu);
276 kmem_cache_free(kvm_vcpu_cache, vcpu);
281 int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
286 void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
288 kvm_mmu_free_memory_caches(vcpu);
289 kvm_timer_vcpu_terminate(vcpu);
290 kmem_cache_free(kvm_vcpu_cache, vcpu);
293 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
295 kvm_arch_vcpu_free(vcpu);
298 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
303 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
307 /* Force users to call KVM_ARM_VCPU_INIT */
308 vcpu->arch.target = -1;
311 ret = kvm_vgic_vcpu_init(vcpu);
315 /* Set up the timer */
316 kvm_timer_vcpu_init(vcpu);
321 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
325 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
328 vcpu->arch.vfp_host = this_cpu_ptr(kvm_host_vfp_state);
331 * Check whether this vcpu requires the cache to be flushed on
332 * this physical CPU. This is a consequence of doing dcache
333 * operations by set/way on this vcpu. We do it here to be in
334 * a non-preemptible section.
336 if (cpumask_test_and_clear_cpu(cpu, &vcpu->arch.require_dcache_flush))
337 flush_cache_all(); /* We'd really want v7_flush_dcache_all() */
339 kvm_arm_set_running_vcpu(vcpu);
342 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
344 kvm_arm_set_running_vcpu(NULL);
347 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
348 struct kvm_guest_debug *dbg)
354 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
355 struct kvm_mp_state *mp_state)
360 int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
361 struct kvm_mp_state *mp_state)
367 * kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled
368 * @v: The VCPU pointer
370 * If the guest CPU is not waiting for interrupts or an interrupt line is
371 * asserted, the CPU is by definition runnable.
373 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
375 return !!v->arch.irq_lines || kvm_vgic_vcpu_pending_irq(v);
378 /* Just ensure a guest exit from a particular CPU */
379 static void exit_vm_noop(void *info)
383 void force_vm_exit(const cpumask_t *mask)
385 smp_call_function_many(mask, exit_vm_noop, NULL, true);
389 * need_new_vmid_gen - check that the VMID is still valid
390 * @kvm: The VM's VMID to checkt
392 * return true if there is a new generation of VMIDs being used
394 * The hardware supports only 256 values with the value zero reserved for the
395 * host, so we check if an assigned value belongs to a previous generation,
396 * which which requires us to assign a new value. If we're the first to use a
397 * VMID for the new generation, we must flush necessary caches and TLBs on all
400 static bool need_new_vmid_gen(struct kvm *kvm)
402 return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
406 * update_vttbr - Update the VTTBR with a valid VMID before the guest runs
407 * @kvm The guest that we are about to run
409 * Called from kvm_arch_vcpu_ioctl_run before entering the guest to ensure the
410 * VM has a valid VMID, otherwise assigns a new one and flushes corresponding
413 static void update_vttbr(struct kvm *kvm)
415 phys_addr_t pgd_phys;
418 if (!need_new_vmid_gen(kvm))
421 spin_lock(&kvm_vmid_lock);
424 * We need to re-check the vmid_gen here to ensure that if another vcpu
425 * already allocated a valid vmid for this vm, then this vcpu should
428 if (!need_new_vmid_gen(kvm)) {
429 spin_unlock(&kvm_vmid_lock);
433 /* First user of a new VMID generation? */
434 if (unlikely(kvm_next_vmid == 0)) {
435 atomic64_inc(&kvm_vmid_gen);
439 * On SMP we know no other CPUs can use this CPU's or each
440 * other's VMID after force_vm_exit returns since the
441 * kvm_vmid_lock blocks them from reentry to the guest.
443 force_vm_exit(cpu_all_mask);
445 * Now broadcast TLB + ICACHE invalidation over the inner
446 * shareable domain to make sure all data structures are
449 kvm_call_hyp(__kvm_flush_vm_context);
452 kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
453 kvm->arch.vmid = kvm_next_vmid;
456 /* update vttbr to be used with the new vmid */
457 pgd_phys = virt_to_phys(kvm->arch.pgd);
458 vmid = ((u64)(kvm->arch.vmid) << VTTBR_VMID_SHIFT) & VTTBR_VMID_MASK;
459 kvm->arch.vttbr = pgd_phys & VTTBR_BADDR_MASK;
460 kvm->arch.vttbr |= vmid;
462 spin_unlock(&kvm_vmid_lock);
465 static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
467 if (likely(vcpu->arch.has_run_once))
470 vcpu->arch.has_run_once = true;
473 * Initialize the VGIC before running a vcpu the first time on
476 if (irqchip_in_kernel(vcpu->kvm) &&
477 unlikely(!vgic_initialized(vcpu->kvm))) {
478 int ret = kvm_vgic_init(vcpu->kvm);
484 * Handle the "start in power-off" case by calling into the
487 if (test_and_clear_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) {
488 *vcpu_reg(vcpu, 0) = KVM_PSCI_FN_CPU_OFF;
495 static void vcpu_pause(struct kvm_vcpu *vcpu)
497 wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu);
499 wait_event_interruptible(*wq, !vcpu->arch.pause);
503 * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
504 * @vcpu: The VCPU pointer
505 * @run: The kvm_run structure pointer used for userspace state exchange
507 * This function is called through the VCPU_RUN ioctl called from user space. It
508 * will execute VM code in a loop until the time slice for the process is used
509 * or some emulation is needed from user space in which case the function will
510 * return with return value 0 and with the kvm_run structure filled in with the
511 * required data for the requested emulation.
513 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
518 /* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */
519 if (unlikely(vcpu->arch.target < 0))
522 ret = kvm_vcpu_first_run_init(vcpu);
526 if (run->exit_reason == KVM_EXIT_MMIO) {
527 ret = kvm_handle_mmio_return(vcpu, vcpu->run);
532 if (vcpu->sigset_active)
533 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
536 run->exit_reason = KVM_EXIT_UNKNOWN;
539 * Check conditions before entering the guest
543 update_vttbr(vcpu->kvm);
545 if (vcpu->arch.pause)
548 kvm_vgic_flush_hwstate(vcpu);
549 kvm_timer_flush_hwstate(vcpu);
554 * Re-check atomic conditions
556 if (signal_pending(current)) {
558 run->exit_reason = KVM_EXIT_INTR;
561 if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) {
563 kvm_timer_sync_hwstate(vcpu);
564 kvm_vgic_sync_hwstate(vcpu);
568 /**************************************************************
571 trace_kvm_entry(*vcpu_pc(vcpu));
573 vcpu->mode = IN_GUEST_MODE;
575 ret = kvm_call_hyp(__kvm_vcpu_run, vcpu);
577 vcpu->mode = OUTSIDE_GUEST_MODE;
578 vcpu->arch.last_pcpu = smp_processor_id();
580 trace_kvm_exit(*vcpu_pc(vcpu));
582 * We may have taken a host interrupt in HYP mode (ie
583 * while executing the guest). This interrupt is still
584 * pending, as we haven't serviced it yet!
586 * We're now back in SVC mode, with interrupts
587 * disabled. Enabling the interrupts now will have
588 * the effect of taking the interrupt again, in SVC
595 *************************************************************/
597 kvm_timer_sync_hwstate(vcpu);
598 kvm_vgic_sync_hwstate(vcpu);
600 ret = handle_exit(vcpu, run, ret);
603 if (vcpu->sigset_active)
604 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
608 static int vcpu_interrupt_line(struct kvm_vcpu *vcpu, int number, bool level)
614 if (number == KVM_ARM_IRQ_CPU_IRQ)
615 bit_index = __ffs(HCR_VI);
616 else /* KVM_ARM_IRQ_CPU_FIQ */
617 bit_index = __ffs(HCR_VF);
619 ptr = (unsigned long *)&vcpu->arch.irq_lines;
621 set = test_and_set_bit(bit_index, ptr);
623 set = test_and_clear_bit(bit_index, ptr);
626 * If we didn't change anything, no need to wake up or kick other CPUs
632 * The vcpu irq_lines field was updated, wake up sleeping VCPUs and
633 * trigger a world-switch round on the running physical CPU to set the
634 * virtual IRQ/FIQ fields in the HCR appropriately.
641 int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level)
643 u32 irq = irq_level->irq;
644 unsigned int irq_type, vcpu_idx, irq_num;
645 int nrcpus = atomic_read(&kvm->online_vcpus);
646 struct kvm_vcpu *vcpu = NULL;
647 bool level = irq_level->level;
649 irq_type = (irq >> KVM_ARM_IRQ_TYPE_SHIFT) & KVM_ARM_IRQ_TYPE_MASK;
650 vcpu_idx = (irq >> KVM_ARM_IRQ_VCPU_SHIFT) & KVM_ARM_IRQ_VCPU_MASK;
651 irq_num = (irq >> KVM_ARM_IRQ_NUM_SHIFT) & KVM_ARM_IRQ_NUM_MASK;
653 trace_kvm_irq_line(irq_type, vcpu_idx, irq_num, irq_level->level);
656 case KVM_ARM_IRQ_TYPE_CPU:
657 if (irqchip_in_kernel(kvm))
660 if (vcpu_idx >= nrcpus)
663 vcpu = kvm_get_vcpu(kvm, vcpu_idx);
667 if (irq_num > KVM_ARM_IRQ_CPU_FIQ)
670 return vcpu_interrupt_line(vcpu, irq_num, level);
671 case KVM_ARM_IRQ_TYPE_PPI:
672 if (!irqchip_in_kernel(kvm))
675 if (vcpu_idx >= nrcpus)
678 vcpu = kvm_get_vcpu(kvm, vcpu_idx);
682 if (irq_num < VGIC_NR_SGIS || irq_num >= VGIC_NR_PRIVATE_IRQS)
685 return kvm_vgic_inject_irq(kvm, vcpu->vcpu_id, irq_num, level);
686 case KVM_ARM_IRQ_TYPE_SPI:
687 if (!irqchip_in_kernel(kvm))
690 if (irq_num < VGIC_NR_PRIVATE_IRQS ||
691 irq_num > KVM_ARM_IRQ_GIC_MAX)
694 return kvm_vgic_inject_irq(kvm, 0, irq_num, level);
700 long kvm_arch_vcpu_ioctl(struct file *filp,
701 unsigned int ioctl, unsigned long arg)
703 struct kvm_vcpu *vcpu = filp->private_data;
704 void __user *argp = (void __user *)arg;
707 case KVM_ARM_VCPU_INIT: {
708 struct kvm_vcpu_init init;
710 if (copy_from_user(&init, argp, sizeof(init)))
713 return kvm_vcpu_set_target(vcpu, &init);
716 case KVM_SET_ONE_REG:
717 case KVM_GET_ONE_REG: {
718 struct kvm_one_reg reg;
719 if (copy_from_user(®, argp, sizeof(reg)))
721 if (ioctl == KVM_SET_ONE_REG)
722 return kvm_arm_set_reg(vcpu, ®);
724 return kvm_arm_get_reg(vcpu, ®);
726 case KVM_GET_REG_LIST: {
727 struct kvm_reg_list __user *user_list = argp;
728 struct kvm_reg_list reg_list;
731 if (copy_from_user(®_list, user_list, sizeof(reg_list)))
734 reg_list.n = kvm_arm_num_regs(vcpu);
735 if (copy_to_user(user_list, ®_list, sizeof(reg_list)))
739 return kvm_arm_copy_reg_indices(vcpu, user_list->reg);
746 int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
751 static int kvm_vm_ioctl_set_device_addr(struct kvm *kvm,
752 struct kvm_arm_device_addr *dev_addr)
754 unsigned long dev_id, type;
756 dev_id = (dev_addr->id & KVM_ARM_DEVICE_ID_MASK) >>
757 KVM_ARM_DEVICE_ID_SHIFT;
758 type = (dev_addr->id & KVM_ARM_DEVICE_TYPE_MASK) >>
759 KVM_ARM_DEVICE_TYPE_SHIFT;
762 case KVM_ARM_DEVICE_VGIC_V2:
765 return kvm_vgic_set_addr(kvm, type, dev_addr->addr);
771 long kvm_arch_vm_ioctl(struct file *filp,
772 unsigned int ioctl, unsigned long arg)
774 struct kvm *kvm = filp->private_data;
775 void __user *argp = (void __user *)arg;
778 case KVM_CREATE_IRQCHIP: {
780 return kvm_vgic_create(kvm);
784 case KVM_ARM_SET_DEVICE_ADDR: {
785 struct kvm_arm_device_addr dev_addr;
787 if (copy_from_user(&dev_addr, argp, sizeof(dev_addr)))
789 return kvm_vm_ioctl_set_device_addr(kvm, &dev_addr);
796 static void cpu_init_hyp_mode(void *vector)
798 unsigned long long pgd_ptr;
799 unsigned long hyp_stack_ptr;
800 unsigned long stack_page;
801 unsigned long vector_ptr;
803 /* Switch from the HYP stub to our own HYP init vector */
804 __hyp_set_vectors((unsigned long)vector);
806 pgd_ptr = (unsigned long long)kvm_mmu_get_httbr();
807 stack_page = __get_cpu_var(kvm_arm_hyp_stack_page);
808 hyp_stack_ptr = stack_page + PAGE_SIZE;
809 vector_ptr = (unsigned long)__kvm_hyp_vector;
811 __cpu_init_hyp_mode(pgd_ptr, hyp_stack_ptr, vector_ptr);
815 * Inits Hyp-mode on all online CPUs
817 static int init_hyp_mode(void)
819 phys_addr_t init_phys_addr;
824 * Allocate Hyp PGD and setup Hyp identity mapping
826 err = kvm_mmu_init();
831 * It is probably enough to obtain the default on one
832 * CPU. It's unlikely to be different on the others.
834 hyp_default_vectors = __hyp_get_vectors();
837 * Allocate stack pages for Hypervisor-mode
839 for_each_possible_cpu(cpu) {
840 unsigned long stack_page;
842 stack_page = __get_free_page(GFP_KERNEL);
845 goto out_free_stack_pages;
848 per_cpu(kvm_arm_hyp_stack_page, cpu) = stack_page;
852 * Execute the init code on each CPU.
854 * Note: The stack is not mapped yet, so don't do anything else than
855 * initializing the hypervisor mode on each CPU using a local stack
856 * space for temporary storage.
858 init_phys_addr = virt_to_phys(__kvm_hyp_init);
859 for_each_online_cpu(cpu) {
860 smp_call_function_single(cpu, cpu_init_hyp_mode,
861 (void *)(long)init_phys_addr, 1);
865 * Unmap the identity mapping
867 kvm_clear_hyp_idmap();
870 * Map the Hyp-code called directly from the host
872 err = create_hyp_mappings(__kvm_hyp_code_start, __kvm_hyp_code_end);
874 kvm_err("Cannot map world-switch code\n");
875 goto out_free_mappings;
879 * Map the Hyp stack pages
881 for_each_possible_cpu(cpu) {
882 char *stack_page = (char *)per_cpu(kvm_arm_hyp_stack_page, cpu);
883 err = create_hyp_mappings(stack_page, stack_page + PAGE_SIZE);
886 kvm_err("Cannot map hyp stack\n");
887 goto out_free_mappings;
892 * Map the host VFP structures
894 kvm_host_vfp_state = alloc_percpu(kvm_kernel_vfp_t);
895 if (!kvm_host_vfp_state) {
897 kvm_err("Cannot allocate host VFP state\n");
898 goto out_free_mappings;
901 for_each_possible_cpu(cpu) {
902 kvm_kernel_vfp_t *vfp;
904 vfp = per_cpu_ptr(kvm_host_vfp_state, cpu);
905 err = create_hyp_mappings(vfp, vfp + 1);
908 kvm_err("Cannot map host VFP state: %d\n", err);
914 * Init HYP view of VGIC
916 err = kvm_vgic_hyp_init();
920 #ifdef CONFIG_KVM_ARM_VGIC
925 * Init HYP architected timer support
927 err = kvm_timer_hyp_init();
929 goto out_free_mappings;
933 kvm_info("Hyp mode initialized successfully\n");
937 free_percpu(kvm_host_vfp_state);
940 out_free_stack_pages:
941 for_each_possible_cpu(cpu)
942 free_page(per_cpu(kvm_arm_hyp_stack_page, cpu));
944 kvm_err("error initializing Hyp mode: %d\n", err);
949 * Initialize Hyp-mode and memory mappings on all CPUs.
951 int kvm_arch_init(void *opaque)
955 if (!is_hyp_mode_available()) {
956 kvm_err("HYP mode not available\n");
960 if (kvm_target_cpu() < 0) {
961 kvm_err("Target CPU not supported!\n");
965 err = init_hyp_mode();
969 kvm_coproc_table_init();
975 /* NOP: Compiling as a module not supported */
976 void kvm_arch_exit(void)
981 static int arm_init(void)
983 int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
987 module_init(arm_init);