diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-01-23 22:24:55 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-01-23 22:24:55 +0100 |
| commit | 1fe8249bbc782d28185e0e893504e8ac3a1fcaec (patch) | |
| tree | 15790721d2806918327d62e9c4448fc68ef34cd2 /test/kvm.c | |
| parent | 0dc0595ee1d84bc77cb431b2417223f3b4a5bd57 (diff) | |
| download | cachepc-1fe8249bbc782d28185e0e893504e8ac3a1fcaec.tar.gz cachepc-1fe8249bbc782d28185e0e893504e8ac3a1fcaec.zip | |
Move kvm to guest process and add ipc for synchronization
Diffstat (limited to 'test/kvm.c')
| -rw-r--r-- | test/kvm.c | 57 |
1 files changed, 57 insertions, 0 deletions
@@ -29,6 +29,7 @@ #include <stdlib.h> int kvm_dev, sev_dev; +const char *vmtype; const char *sev_fwerr_strs[] = { [0x00] = "Success", @@ -466,6 +467,62 @@ kvm_deinit(struct kvm *kvm) } void +parse_vmtype(int argc, const char **argv) +{ + vmtype = "kvm"; + if (argc > 1) vmtype = argv[1]; + if (strcmp(vmtype, "kvm") && strcmp(vmtype, "sev") + && strcmp(vmtype, "sev-es") + && strcmp(vmtype, "sev-snp")) + errx(1, "invalid vm mode: %s", vmtype); +} + +uint64_t +vm_get_rip(struct kvm *kvm) +{ + struct kvm_regs regs; + uint64_t rip; + int ret; + + if (!strcmp(vmtype, "sev-snp")) { + rip = snp_dbg_decrypt_rip(kvm->vmfd); + } else if (!strcmp(vmtype, "sev-es")) { + rip = sev_dbg_decrypt_rip(kvm->vmfd); + } else { + ret = ioctl(kvm_dev, KVM_CPC_GET_REGS, ®s); + if (ret == -1) err(1, "KVM_CPC_GET_REGS"); + rip = regs.rip; + } + + return rip; +} + +void +vm_init(struct kvm *kvm, void *code_start, void *code_end) +{ + size_t ramsize; + + ramsize = L1_SIZE * 2; + if (!strcmp(vmtype, "kvm")) { + kvm_init(kvm, ramsize, code_start, code_end); + } else if (!strcmp(vmtype, "sev")) { + sev_kvm_init(kvm, ramsize, code_start, code_end); + } else if (!strcmp(vmtype, "sev-es")) { + sev_es_kvm_init(kvm, ramsize, code_start, code_end); + } else if (!strcmp(vmtype, "sev-snp")) { + sev_snp_kvm_init(kvm, ramsize, code_start, code_end); + } else { + errx(1, "invalid version"); + } +} + +void +vm_deinit(struct kvm *kvm) +{ + kvm_deinit(kvm); +} + +void kvm_setup_init(void) { int ret; |
