Lines Matching refs:svm
552 static int sev_es_sync_vmsa(struct vcpu_svm *svm) in sev_es_sync_vmsa() argument
554 struct vmcb_save_area *save = &svm->vmcb->save; in sev_es_sync_vmsa()
557 if (svm->vcpu.guest_debug || (save->dr7 & ~DR7_FIXED_1)) in sev_es_sync_vmsa()
561 save->rax = svm->vcpu.arch.regs[VCPU_REGS_RAX]; in sev_es_sync_vmsa()
562 save->rbx = svm->vcpu.arch.regs[VCPU_REGS_RBX]; in sev_es_sync_vmsa()
563 save->rcx = svm->vcpu.arch.regs[VCPU_REGS_RCX]; in sev_es_sync_vmsa()
564 save->rdx = svm->vcpu.arch.regs[VCPU_REGS_RDX]; in sev_es_sync_vmsa()
565 save->rsp = svm->vcpu.arch.regs[VCPU_REGS_RSP]; in sev_es_sync_vmsa()
566 save->rbp = svm->vcpu.arch.regs[VCPU_REGS_RBP]; in sev_es_sync_vmsa()
567 save->rsi = svm->vcpu.arch.regs[VCPU_REGS_RSI]; in sev_es_sync_vmsa()
568 save->rdi = svm->vcpu.arch.regs[VCPU_REGS_RDI]; in sev_es_sync_vmsa()
570 save->r8 = svm->vcpu.arch.regs[VCPU_REGS_R8]; in sev_es_sync_vmsa()
571 save->r9 = svm->vcpu.arch.regs[VCPU_REGS_R9]; in sev_es_sync_vmsa()
572 save->r10 = svm->vcpu.arch.regs[VCPU_REGS_R10]; in sev_es_sync_vmsa()
573 save->r11 = svm->vcpu.arch.regs[VCPU_REGS_R11]; in sev_es_sync_vmsa()
574 save->r12 = svm->vcpu.arch.regs[VCPU_REGS_R12]; in sev_es_sync_vmsa()
575 save->r13 = svm->vcpu.arch.regs[VCPU_REGS_R13]; in sev_es_sync_vmsa()
576 save->r14 = svm->vcpu.arch.regs[VCPU_REGS_R14]; in sev_es_sync_vmsa()
577 save->r15 = svm->vcpu.arch.regs[VCPU_REGS_R15]; in sev_es_sync_vmsa()
579 save->rip = svm->vcpu.arch.regs[VCPU_REGS_RIP]; in sev_es_sync_vmsa()
582 save->xcr0 = svm->vcpu.arch.xcr0; in sev_es_sync_vmsa()
583 save->pkru = svm->vcpu.arch.pkru; in sev_es_sync_vmsa()
584 save->xss = svm->vcpu.arch.ia32_xss; in sev_es_sync_vmsa()
585 save->dr6 = svm->vcpu.arch.dr6; in sev_es_sync_vmsa()
593 memcpy(svm->vmsa, save, sizeof(*save)); in sev_es_sync_vmsa()
602 struct vcpu_svm *svm = to_svm(vcpu); in __sev_launch_update_vmsa() local
606 ret = sev_es_sync_vmsa(svm); in __sev_launch_update_vmsa()
615 clflush_cache_range(svm->vmsa, PAGE_SIZE); in __sev_launch_update_vmsa()
619 vmsa.address = __sme_pa(svm->vmsa); in __sev_launch_update_vmsa()
1990 static void sev_flush_guest_memory(struct vcpu_svm *svm, void *va, in sev_flush_guest_memory() argument
2018 sev = &to_kvm_svm(svm->vcpu.kvm)->sev_info; in sev_flush_guest_memory()
2051 struct vcpu_svm *svm; in sev_free_vcpu() local
2056 svm = to_svm(vcpu); in sev_free_vcpu()
2059 sev_flush_guest_memory(svm, svm->vmsa, PAGE_SIZE); in sev_free_vcpu()
2060 __free_page(virt_to_page(svm->vmsa)); in sev_free_vcpu()
2062 if (svm->ghcb_sa_free) in sev_free_vcpu()
2063 kfree(svm->ghcb_sa); in sev_free_vcpu()
2066 static void dump_ghcb(struct vcpu_svm *svm) in dump_ghcb() argument
2068 struct ghcb *ghcb = svm->ghcb; in dump_ghcb()
2079 pr_err("GHCB (GPA=%016llx):\n", svm->vmcb->control.ghcb_gpa); in dump_ghcb()
2091 static void sev_es_sync_to_ghcb(struct vcpu_svm *svm) in sev_es_sync_to_ghcb() argument
2093 struct kvm_vcpu *vcpu = &svm->vcpu; in sev_es_sync_to_ghcb()
2094 struct ghcb *ghcb = svm->ghcb; in sev_es_sync_to_ghcb()
2110 static void sev_es_sync_from_ghcb(struct vcpu_svm *svm) in sev_es_sync_from_ghcb() argument
2112 struct vmcb_control_area *control = &svm->vmcb->control; in sev_es_sync_from_ghcb()
2113 struct kvm_vcpu *vcpu = &svm->vcpu; in sev_es_sync_from_ghcb()
2114 struct ghcb *ghcb = svm->ghcb; in sev_es_sync_from_ghcb()
2137 svm->vmcb->save.cpl = ghcb_get_cpl_if_valid(ghcb); in sev_es_sync_from_ghcb()
2155 static int sev_es_validate_vmgexit(struct vcpu_svm *svm) in sev_es_validate_vmgexit() argument
2161 ghcb = svm->ghcb; in sev_es_validate_vmgexit()
2257 vcpu = &svm->vcpu; in sev_es_validate_vmgexit()
2265 dump_ghcb(svm); in sev_es_validate_vmgexit()
2277 void sev_es_unmap_ghcb(struct vcpu_svm *svm) in sev_es_unmap_ghcb() argument
2279 if (!svm->ghcb) in sev_es_unmap_ghcb()
2282 if (svm->ghcb_sa_free) { in sev_es_unmap_ghcb()
2288 if (svm->ghcb_sa_sync) { in sev_es_unmap_ghcb()
2289 kvm_write_guest(svm->vcpu.kvm, in sev_es_unmap_ghcb()
2290 ghcb_get_sw_scratch(svm->ghcb), in sev_es_unmap_ghcb()
2291 svm->ghcb_sa, svm->ghcb_sa_len); in sev_es_unmap_ghcb()
2292 svm->ghcb_sa_sync = false; in sev_es_unmap_ghcb()
2295 kfree(svm->ghcb_sa); in sev_es_unmap_ghcb()
2296 svm->ghcb_sa = NULL; in sev_es_unmap_ghcb()
2297 svm->ghcb_sa_free = false; in sev_es_unmap_ghcb()
2300 trace_kvm_vmgexit_exit(svm->vcpu.vcpu_id, svm->ghcb); in sev_es_unmap_ghcb()
2302 sev_es_sync_to_ghcb(svm); in sev_es_unmap_ghcb()
2304 kvm_vcpu_unmap(&svm->vcpu, &svm->ghcb_map, true); in sev_es_unmap_ghcb()
2305 svm->ghcb = NULL; in sev_es_unmap_ghcb()
2308 void pre_sev_run(struct vcpu_svm *svm, int cpu) in pre_sev_run() argument
2311 int asid = sev_get_asid(svm->vcpu.kvm); in pre_sev_run()
2314 svm->asid = asid; in pre_sev_run()
2322 if (sd->sev_vmcbs[asid] == svm->vmcb && in pre_sev_run()
2323 svm->vcpu.arch.last_vmentry_cpu == cpu) in pre_sev_run()
2326 sd->sev_vmcbs[asid] = svm->vmcb; in pre_sev_run()
2327 svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID; in pre_sev_run()
2328 vmcb_mark_dirty(svm->vmcb, VMCB_ASID); in pre_sev_run()
2332 static int setup_vmgexit_scratch(struct vcpu_svm *svm, bool sync, u64 len) in setup_vmgexit_scratch() argument
2334 struct vmcb_control_area *control = &svm->vmcb->control; in setup_vmgexit_scratch()
2335 struct ghcb *ghcb = svm->ghcb; in setup_vmgexit_scratch()
2371 scratch_va = (void *)svm->ghcb; in setup_vmgexit_scratch()
2387 if (kvm_read_guest(svm->vcpu.kvm, scratch_gpa_beg, scratch_va, len)) { in setup_vmgexit_scratch()
2401 svm->ghcb_sa_sync = sync; in setup_vmgexit_scratch()
2402 svm->ghcb_sa_free = true; in setup_vmgexit_scratch()
2405 svm->ghcb_sa = scratch_va; in setup_vmgexit_scratch()
2406 svm->ghcb_sa_len = len; in setup_vmgexit_scratch()
2411 static void set_ghcb_msr_bits(struct vcpu_svm *svm, u64 value, u64 mask, in set_ghcb_msr_bits() argument
2414 svm->vmcb->control.ghcb_gpa &= ~(mask << pos); in set_ghcb_msr_bits()
2415 svm->vmcb->control.ghcb_gpa |= (value & mask) << pos; in set_ghcb_msr_bits()
2418 static u64 get_ghcb_msr_bits(struct vcpu_svm *svm, u64 mask, unsigned int pos) in get_ghcb_msr_bits() argument
2420 return (svm->vmcb->control.ghcb_gpa >> pos) & mask; in get_ghcb_msr_bits()
2423 static void set_ghcb_msr(struct vcpu_svm *svm, u64 value) in set_ghcb_msr() argument
2425 svm->vmcb->control.ghcb_gpa = value; in set_ghcb_msr()
2428 static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) in sev_handle_vmgexit_msr_protocol() argument
2430 struct vmcb_control_area *control = &svm->vmcb->control; in sev_handle_vmgexit_msr_protocol()
2431 struct kvm_vcpu *vcpu = &svm->vcpu; in sev_handle_vmgexit_msr_protocol()
2437 trace_kvm_vmgexit_msr_protocol_enter(svm->vcpu.vcpu_id, in sev_handle_vmgexit_msr_protocol()
2442 set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX, in sev_handle_vmgexit_msr_protocol()
2449 cpuid_fn = get_ghcb_msr_bits(svm, in sev_handle_vmgexit_msr_protocol()
2463 cpuid_reg = get_ghcb_msr_bits(svm, in sev_handle_vmgexit_msr_protocol()
2475 set_ghcb_msr_bits(svm, cpuid_value, in sev_handle_vmgexit_msr_protocol()
2479 set_ghcb_msr_bits(svm, GHCB_MSR_CPUID_RESP, in sev_handle_vmgexit_msr_protocol()
2487 reason_set = get_ghcb_msr_bits(svm, in sev_handle_vmgexit_msr_protocol()
2490 reason_code = get_ghcb_msr_bits(svm, in sev_handle_vmgexit_msr_protocol()
2501 trace_kvm_vmgexit_msr_protocol_exit(svm->vcpu.vcpu_id, in sev_handle_vmgexit_msr_protocol()
2509 struct vcpu_svm *svm = to_svm(vcpu); in sev_handle_vmgexit() local
2510 struct vmcb_control_area *control = &svm->vmcb->control; in sev_handle_vmgexit()
2518 return sev_handle_vmgexit_msr_protocol(svm); in sev_handle_vmgexit()
2525 if (kvm_vcpu_map(vcpu, ghcb_gpa >> PAGE_SHIFT, &svm->ghcb_map)) { in sev_handle_vmgexit()
2532 svm->ghcb = svm->ghcb_map.hva; in sev_handle_vmgexit()
2533 ghcb = svm->ghcb_map.hva; in sev_handle_vmgexit()
2539 ret = sev_es_validate_vmgexit(svm); in sev_handle_vmgexit()
2543 sev_es_sync_from_ghcb(svm); in sev_handle_vmgexit()
2549 ret = setup_vmgexit_scratch(svm, true, control->exit_info_2); in sev_handle_vmgexit()
2556 svm->ghcb_sa); in sev_handle_vmgexit()
2559 ret = setup_vmgexit_scratch(svm, false, control->exit_info_2); in sev_handle_vmgexit()
2566 svm->ghcb_sa); in sev_handle_vmgexit()
2612 int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in) in sev_es_string_io() argument
2618 if (svm->vmcb->control.exit_info_2 > INT_MAX) in sev_es_string_io()
2621 count = svm->vmcb->control.exit_info_2; in sev_es_string_io()
2625 r = setup_vmgexit_scratch(svm, in, bytes); in sev_es_string_io()
2629 return kvm_sev_es_string_io(&svm->vcpu, size, port, svm->ghcb_sa, count, in); in sev_es_string_io()
2632 void sev_es_init_vmcb(struct vcpu_svm *svm) in sev_es_init_vmcb() argument
2634 struct kvm_vcpu *vcpu = &svm->vcpu; in sev_es_init_vmcb()
2636 svm->vmcb->control.nested_ctl |= SVM_NESTED_CTL_SEV_ES_ENABLE; in sev_es_init_vmcb()
2637 svm->vmcb->control.virt_ext |= LBR_CTL_ENABLE_MASK; in sev_es_init_vmcb()
2644 svm->vmcb->control.vmsa_pa = __pa(svm->vmsa); in sev_es_init_vmcb()
2647 svm_clr_intercept(svm, INTERCEPT_CR0_READ); in sev_es_init_vmcb()
2648 svm_clr_intercept(svm, INTERCEPT_CR4_READ); in sev_es_init_vmcb()
2649 svm_clr_intercept(svm, INTERCEPT_CR8_READ); in sev_es_init_vmcb()
2650 svm_clr_intercept(svm, INTERCEPT_CR0_WRITE); in sev_es_init_vmcb()
2651 svm_clr_intercept(svm, INTERCEPT_CR4_WRITE); in sev_es_init_vmcb()
2652 svm_clr_intercept(svm, INTERCEPT_CR8_WRITE); in sev_es_init_vmcb()
2654 svm_clr_intercept(svm, INTERCEPT_SELECTIVE_CR0); in sev_es_init_vmcb()
2657 svm_set_intercept(svm, TRAP_EFER_WRITE); in sev_es_init_vmcb()
2658 svm_set_intercept(svm, TRAP_CR0_WRITE); in sev_es_init_vmcb()
2659 svm_set_intercept(svm, TRAP_CR4_WRITE); in sev_es_init_vmcb()
2660 svm_set_intercept(svm, TRAP_CR8_WRITE); in sev_es_init_vmcb()
2663 clr_exception_intercept(svm, GP_VECTOR); in sev_es_init_vmcb()
2666 svm_clr_intercept(svm, INTERCEPT_XSETBV); in sev_es_init_vmcb()
2669 set_msr_interception(vcpu, svm->msrpm, MSR_EFER, 1, 1); in sev_es_init_vmcb()
2670 set_msr_interception(vcpu, svm->msrpm, MSR_IA32_CR_PAT, 1, 1); in sev_es_init_vmcb()
2671 set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTBRANCHFROMIP, 1, 1); in sev_es_init_vmcb()
2672 set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTBRANCHTOIP, 1, 1); in sev_es_init_vmcb()
2673 set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTINTFROMIP, 1, 1); in sev_es_init_vmcb()
2674 set_msr_interception(vcpu, svm->msrpm, MSR_IA32_LASTINTTOIP, 1, 1); in sev_es_init_vmcb()
2677 void sev_es_create_vcpu(struct vcpu_svm *svm) in sev_es_create_vcpu() argument
2683 set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX, in sev_es_create_vcpu()
2688 void sev_es_prepare_guest_switch(struct vcpu_svm *svm, unsigned int cpu) in sev_es_prepare_guest_switch() argument
2713 struct vcpu_svm *svm = to_svm(vcpu); in sev_vcpu_deliver_sipi_vector() local
2716 if (!svm->received_first_sipi) { in sev_vcpu_deliver_sipi_vector()
2717 svm->received_first_sipi = true; in sev_vcpu_deliver_sipi_vector()
2726 if (!svm->ghcb) in sev_vcpu_deliver_sipi_vector()
2729 ghcb_set_sw_exit_info_2(svm->ghcb, 1); in sev_vcpu_deliver_sipi_vector()