linux/virt/kvm/arm/arm.c
/**
 * Inits Hyp-mode on all online CPUs
 */
Inits Hyp-mode on all online CPUs
Inits Hyp - mode on all online CPUs
static int init_hyp_mode(void)
{
	int cpu;
	int err = 0;
	err = kvm_mmu_init();
	if (err)
		goto out_err;
	for_each_possible_cpu(cpu) {
		unsigned long stack_page;
		stack_page = __get_free_page(GFP_KERNEL);
		if (!stack_page) {
			err = -ENOMEM;
			goto out_err;
		}
		per_cpu(kvm_arm_hyp_stack_page, cpu) = stack_page;
	}
	err = create_hyp_mappings(kvm_ksym_ref(__hyp_text_start),
				  kvm_ksym_ref(__hyp_text_end), PAGE_HYP_EXEC);
	if (err) {
		kvm_err("Cannot map world-switch code\n");
		goto out_err;
	}
	err = create_hyp_mappings(kvm_ksym_ref(__start_rodata),
				  kvm_ksym_ref(__end_rodata), PAGE_HYP_RO);
	if (err) {
		kvm_err("Cannot map rodata section\n");
		goto out_err;
	}
	err = create_hyp_mappings(kvm_ksym_ref(__bss_start),
				  kvm_ksym_ref(__bss_stop), PAGE_HYP_RO);
	if (err) {
		kvm_err("Cannot map bss section\n");
		goto out_err;
	}
	err = kvm_map_vectors();
	if (err) {
		kvm_err("Cannot map vectors\n");
		goto out_err;
	}
	for_each_possible_cpu(cpu) {
		char *stack_page = (char *)per_cpu(kvm_arm_hyp_stack_page, cpu);
		err = create_hyp_mappings(stack_page, stack_page + PAGE_SIZE,
					  PAGE_HYP);
		if (err) {
			kvm_err("Cannot map hyp stack\n");
			goto out_err;
		}
	}
	for_each_possible_cpu(cpu) {
		kvm_cpu_context_t *cpu_ctxt;
		cpu_ctxt = per_cpu_ptr(&kvm_host_cpu_state, cpu);
		err = create_hyp_mappings(cpu_ctxt, cpu_ctxt + 1, PAGE_HYP);
		if (err) {
			kvm_err("Cannot map host CPU state: %d\n", err);
			goto out_err;
		}
	}
	err = hyp_map_aux_data();
	if (err)
		kvm_err("Cannot map host auxilary data: %d\n", err);
	return 0;
out_err:
	teardown_hyp_mode();
	kvm_err("error initializing Hyp mode: %d\n", err);
	return err;
}
static int init_hyp_mode ( void ) { int cpu ; int err = 0 ; err = kvm_mmu_init ( ) ; if ( err ) goto out_err ; for_each_possible_cpu ( cpu ) { unsigned long stack_page ; stack_page = __get_free_page ( GFP_KERNEL ) ; if ( ! stack_page ) { err = - ENOMEM ; goto out_err ; } per_cpu ( kvm_arm_hyp_stack_page , cpu ) = stack_page ; } err = create_hyp_mappings ( kvm_ksym_ref ( __hyp_text_start ) , kvm_ksym_ref ( __hyp_text_end ) , PAGE_HYP_EXEC ) ; if ( err ) { kvm_err ( " \n " ) ; goto out_err ; } err = create_hyp_mappings ( kvm_ksym_ref ( __start_rodata ) , kvm_ksym_ref ( __end_rodata ) , PAGE_HYP_RO ) ; if ( err ) { kvm_err ( " \n " ) ; goto out_err ; } err = create_hyp_mappings ( kvm_ksym_ref ( __bss_start ) , kvm_ksym_ref ( __bss_stop ) , PAGE_HYP_RO ) ; if ( err ) { kvm_err ( " \n " ) ; goto out_err ; } err = kvm_map_vectors ( ) ; if ( err ) { kvm_err ( " \n " ) ; goto out_err ; } for_each_possible_cpu ( cpu ) { char * stack_page = ( char * ) per_cpu ( kvm_arm_hyp_stack_page , cpu ) ; err = create_hyp_mappings ( stack_page , stack_page + PAGE_SIZE , PAGE_HYP ) ; if ( err ) { kvm_err ( " \n " ) ; goto out_err ; } } for_each_possible_cpu ( cpu ) { kvm_cpu_context_t * cpu_ctxt ; cpu_ctxt = per_cpu_ptr ( & kvm_host_cpu_state , cpu ) ; err = create_hyp_mappings ( cpu_ctxt , cpu_ctxt + 1 , PAGE_HYP ) ; if ( err ) { kvm_err ( " \n " , err ) ; goto out_err ; } } err = hyp_map_aux_data ( ) ; if ( err ) kvm_err ( " \n " , err ) ; return 0 ; out_err : teardown_hyp_mode ( ) ; kvm_err ( " \n " , err ) ; return err ; }
Inits Hyp-mode on all online CPUs
Inits Hyp - mode on all online CPUs
/*
	 * Allocate Hyp PGD and setup Hyp identity mapping
	 */ /*
	 * Allocate stack pages for Hypervisor-mode
	 */ /*
	 * Map the Hyp-code called directly from the host
	 */ /*
	 * Map the Hyp stack pages
	 */