Lines Matching +full:iov +full:- +full:supply

4  * Copyright Advanced Micro Devices 2016-2018
10 * See the COPYING file in the top-level directory.
18 #include <linux/psp-sev.h>
27 #include "qemu/error-report.h"
38 #include "monitor/hmp-target.h"
39 #include "qapi/qapi-commands-misc-target.h"
40 #include "confidential-guest.h"
42 #include "exec/address-spaces.h"
72 uint8_t padding[ROUND_UP(sizeof(SevHashTable), 16) - sizeof(SevHashTable)];
77 #define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e"
79 /* SEV-ES Reset Vector Address */
83 #define SEV_HASH_TABLE_RV_GUID "7255371f-3a3b-4b04-927b-1da6efa8d454"
135 * -object sev-guest,id=sev0 \
136 * -machine ...,memory-encryption=sev0
209 [SEV_RET_SECURE_DATA_INVALID] = "Part-specific integrity check failure",
214 /* <linux/kvm.h> doesn't expose this, so re-use the max from kvm.c */
295 return sev_common->state == state ? true : false; in sev_check_state()
304 trace_kvm_sev_change_state(SevState_str(sev_common->state), in sev_set_guest_state()
306 sev_common->state = new_state; in sev_set_guest_state()
376 ConfidentialGuestSupport *cgs = MACHINE(qdev_get_machine())->cgs; in sev_enabled()
384 ConfidentialGuestSupport *cgs = MACHINE(qdev_get_machine())->cgs; in sev_snp_enabled()
392 ConfidentialGuestSupport *cgs = MACHINE(qdev_get_machine())->cgs; in sev_es_enabled()
395 (sev_enabled() && SEV_GUEST(cgs)->policy & SEV_POLICY_ES); in sev_es_enabled()
401 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_get_cbit_position()
403 return sev_common ? sev_common->cbitpos : 0; in sev_get_cbit_position()
409 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_get_reduced_phys_bits()
411 return sev_common ? sev_common->reduced_phys_bits : 0; in sev_get_reduced_phys_bits()
417 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_get_info()
420 info->enabled = sev_enabled(); in sev_get_info()
422 if (info->enabled) { in sev_get_info()
423 info->api_major = sev_common->api_major; in sev_get_info()
424 info->api_minor = sev_common->api_minor; in sev_get_info()
425 info->build_id = sev_common->build_id; in sev_get_info()
426 info->state = sev_common->state; in sev_get_info()
429 info->sev_type = SEV_GUEST_TYPE_SEV_SNP; in sev_get_info()
430 info->u.sev_snp.snp_policy = in sev_get_info()
433 info->sev_type = SEV_GUEST_TYPE_SEV; in sev_get_info()
434 info->u.sev.handle = SEV_GUEST(sev_common)->handle; in sev_get_info()
435 info->u.sev.policy = in sev_get_info()
461 if (!info || !info->enabled) { in hmp_info_sev()
466 monitor_printf(mon, "SEV type: %s\n", SevGuestType_str(info->sev_type)); in hmp_info_sev()
467 monitor_printf(mon, "state: %s\n", SevState_str(info->state)); in hmp_info_sev()
468 monitor_printf(mon, "build: %d\n", info->build_id); in hmp_info_sev()
469 monitor_printf(mon, "api version: %d.%d\n", info->api_major, in hmp_info_sev()
470 info->api_minor); in hmp_info_sev()
474 info->u.sev_snp.snp_policy & SEV_SNP_POLICY_DBG ? "on" in hmp_info_sev()
477 info->u.sev_snp.snp_policy & SEV_SNP_POLICY_SMT ? "on" in hmp_info_sev()
480 monitor_printf(mon, "handle: %d\n", info->u.sev.handle); in hmp_info_sev()
482 info->u.sev.policy & SEV_POLICY_NODBG ? "off" : "on"); in hmp_info_sev()
483 monitor_printf(mon, "key-sharing: %s\n", in hmp_info_sev()
484 info->u.sev.policy & SEV_POLICY_NOKS ? "off" : "on"); in hmp_info_sev()
589 sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_get_capabilities()
591 sev_device = object_property_get_str(OBJECT(sev_common), "sev-device", in sev_get_capabilities()
616 cap->pdh = g_base64_encode(pdh_data, pdh_len); in sev_get_capabilities()
617 cap->cert_chain = g_base64_encode(cert_chain_data, cert_chain_len); in sev_get_capabilities()
618 cap->cpu0_id = g_base64_encode(cpu0_id_data, cpu0_id_len); in sev_get_capabilities()
621 cap->cbitpos = ebx & 0x3f; in sev_get_capabilities()
627 cap->reduced_phys_bits = 1; in sev_get_capabilities()
644 #define OVMF_SEV_META_DATA_GUID "dc886566-984a-4798-A75e-5585a7bf67cc"
664 metadata = (OvmfSevMetadata *)(flash_ptr + flash_size - data->offset); in pc_system_parse_sev_metadata()
665 if (memcmp(metadata->signature, "ASEV", 4) != 0 || in pc_system_parse_sev_metadata()
666 metadata->len < sizeof(OvmfSevMetadata) || in pc_system_parse_sev_metadata()
667 metadata->len > flash_size - data->offset) { in pc_system_parse_sev_metadata()
671 ovmf_sev_metadata_table = g_memdup2(metadata, metadata->len); in pc_system_parse_sev_metadata()
704 sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_get_attestation_report()
707 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_GET_ATTESTATION_REPORT, in sev_get_attestation_report()
723 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_GET_ATTESTATION_REPORT, in sev_get_attestation_report()
732 report->data = g_base64_encode(data, input.len); in sev_get_attestation_report()
734 trace_kvm_sev_attestation_report(mnonce, report->data); in sev_get_attestation_report()
753 error_report("SEV: Failed to read '%s' (%s)", filename, error->message); in sev_read_file_base64()
755 return -1; in sev_read_file_base64()
767 struct kvm_sev_snp_launch_start *start = &sev_snp_guest->kvm_start_conf; in sev_snp_launch_start()
769 trace_kvm_sev_snp_launch_start(start->policy, in sev_snp_launch_start()
770 sev_snp_guest->guest_visible_workarounds); in sev_snp_launch_start()
776 rc = sev_ioctl(sev_common->sev_fd, KVM_SEV_SNP_LAUNCH_START, in sev_snp_launch_start()
799 .handle = sev_guest->handle, .policy = sev_guest->policy in sev_launch_start()
803 if (sev_guest->session_file) { in sev_launch_start()
804 if (sev_read_file_base64(sev_guest->session_file, &session, &sz) < 0) { in sev_launch_start()
811 if (sev_guest->dh_cert_file) { in sev_launch_start()
812 if (sev_read_file_base64(sev_guest->dh_cert_file, &dh_cert, &sz) < 0) { in sev_launch_start()
820 rc = sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_START, &start, &fw_error); in sev_launch_start()
828 sev_guest->handle = start.handle; in sev_launch_start()
843 if (old->count != new->count) { in sev_snp_cpuid_report_mismatches()
844 error_report("SEV-SNP: CPUID validation failed due to count mismatch, " in sev_snp_cpuid_report_mismatches()
845 "provided: %d, expected: %d", old->count, new->count); in sev_snp_cpuid_report_mismatches()
849 for (i = 0; i < old->count; i++) { in sev_snp_cpuid_report_mismatches()
852 old_func = &old->entries[i]; in sev_snp_cpuid_report_mismatches()
853 new_func = &new->entries[i]; in sev_snp_cpuid_report_mismatches()
856 error_report("SEV-SNP: CPUID validation failed for function 0x%x, index: 0x%x, " in sev_snp_cpuid_report_mismatches()
859 old_func->eax_in, old_func->ecx_in, in sev_snp_cpuid_report_mismatches()
860 old_func->eax, old_func->ebx, old_func->ecx, old_func->edx, in sev_snp_cpuid_report_mismatches()
861 new_func->eax, new_func->ebx, new_func->ecx, new_func->edx); in sev_snp_cpuid_report_mismatches()
887 if (!data->hva || !data->len) { in sev_snp_launch_update()
890 data->hva, data->len); in sev_snp_launch_update()
894 if (data->type == KVM_SEV_SNP_PAGE_TYPE_CPUID) { in sev_snp_launch_update()
896 memcpy(&snp_cpuid_info, data->hva, sizeof(snp_cpuid_info)); in sev_snp_launch_update()
899 update.uaddr = (__u64)(unsigned long)data->hva; in sev_snp_launch_update()
900 update.gfn_start = data->gpa >> TARGET_PAGE_BITS; in sev_snp_launch_update()
901 update.len = data->len; in sev_snp_launch_update()
902 update.type = data->type; in sev_snp_launch_update()
908 ret = kvm_set_memory_attributes_private(data->gpa, data->len); in sev_snp_launch_update()
910 error_report("SEV-SNP: failed to configure initial" in sev_snp_launch_update()
915 while (update.len || ret == -EAGAIN) { in sev_snp_launch_update()
920 ret = sev_ioctl(SEV_COMMON(sev_snp_guest)->sev_fd, in sev_snp_launch_update()
923 if (ret && ret != -EAGAIN) { in sev_snp_launch_update()
927 if (data->type == KVM_SEV_SNP_PAGE_TYPE_CPUID) { in sev_snp_launch_update()
928 sev_snp_cpuid_report_mismatches(&snp_cpuid_info, data->hva); in sev_snp_launch_update()
929 error_report("SEV-SNP: failed update CPUID page"); in sev_snp_launch_update()
936 if (!ret && update.gfn_start << TARGET_PAGE_BITS != data->gpa + data->len) { in sev_snp_launch_update()
937 error_report("SEV-SNP: expected update of GPA range %" in sev_snp_launch_update()
938 HWADDR_PRIx "-%" HWADDR_PRIx "," in sev_snp_launch_update()
939 "got GPA range %" HWADDR_PRIx "-%llx", in sev_snp_launch_update()
940 data->gpa, data->gpa + data->len, data->gpa, in sev_snp_launch_update()
942 ret = -EIO; in sev_snp_launch_update()
994 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, in sev_launch_update_data()
1009 ret = sev_ioctl(SEV_COMMON(sev_guest)->sev_fd, KVM_SEV_LAUNCH_UPDATE_VMSA, in sev_launch_update_vmsa()
1022 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_launch_get_measure()
1042 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_MEASURE, in sev_launch_get_measure()
1054 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_MEASURE, in sev_launch_get_measure()
1065 sev_guest->measurement = g_base64_encode(data, measurement.len); in sev_launch_get_measure()
1066 trace_kvm_sev_launch_measurement(sev_guest->measurement); in sev_launch_get_measure()
1071 ConfidentialGuestSupport *cgs = MACHINE(qdev_get_machine())->cgs; in sev_get_launch_measurement()
1076 SEV_COMMON(sev_guest)->state >= SEV_STATE_LAUNCH_SECRET) { in sev_get_launch_measurement()
1077 return g_strdup(sev_guest->measurement); in sev_get_launch_measurement()
1095 info->data = data; in qmp_query_sev_launch_measure()
1110 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, in sev_launch_finish()
1132 data->gpa = gpa; in snp_launch_update_data()
1133 data->hva = hva; in snp_launch_update_data()
1134 data->len = len; in snp_launch_update_data()
1135 data->type = type; in snp_launch_update_data()
1157 if (kvm_cpuid_info->cpuid.nent > SNP_CPUID_FUNCTION_MAXCOUNT) { in sev_snp_cpuid_info_fill()
1158 error_report("SEV-SNP: CPUID entry count (%d) exceeds max (%d)", in sev_snp_cpuid_info_fill()
1159 kvm_cpuid_info->cpuid.nent, SNP_CPUID_FUNCTION_MAXCOUNT); in sev_snp_cpuid_info_fill()
1160 return -1; in sev_snp_cpuid_info_fill()
1165 for (i = 0; i < kvm_cpuid_info->cpuid.nent; i++) { in sev_snp_cpuid_info_fill()
1169 kvm_cpuid_entry = &kvm_cpuid_info->entries[i]; in sev_snp_cpuid_info_fill()
1170 snp_cpuid_entry = &snp_cpuid_info->entries[i]; in sev_snp_cpuid_info_fill()
1172 snp_cpuid_entry->eax_in = kvm_cpuid_entry->function; in sev_snp_cpuid_info_fill()
1173 if (kvm_cpuid_entry->flags == KVM_CPUID_FLAG_SIGNIFCANT_INDEX) { in sev_snp_cpuid_info_fill()
1174 snp_cpuid_entry->ecx_in = kvm_cpuid_entry->index; in sev_snp_cpuid_info_fill()
1176 snp_cpuid_entry->eax = kvm_cpuid_entry->eax; in sev_snp_cpuid_info_fill()
1177 snp_cpuid_entry->ebx = kvm_cpuid_entry->ebx; in sev_snp_cpuid_info_fill()
1178 snp_cpuid_entry->ecx = kvm_cpuid_entry->ecx; in sev_snp_cpuid_info_fill()
1179 snp_cpuid_entry->edx = kvm_cpuid_entry->edx; in sev_snp_cpuid_info_fill()
1187 if (snp_cpuid_entry->eax_in == 0xD && in sev_snp_cpuid_info_fill()
1188 (snp_cpuid_entry->ecx_in == 0x0 || snp_cpuid_entry->ecx_in == 0x1)) { in sev_snp_cpuid_info_fill()
1189 snp_cpuid_entry->ebx = 0x240; in sev_snp_cpuid_info_fill()
1190 snp_cpuid_entry->xcr0_in = 1; in sev_snp_cpuid_info_fill()
1191 snp_cpuid_entry->xss_in = 0; in sev_snp_cpuid_info_fill()
1195 snp_cpuid_info->count = i; in sev_snp_cpuid_info_fill()
1215 } while (ret == -E2BIG); in snp_launch_update_cpuid()
1218 error_report("SEV-SNP: unable to query CPUID values for CPU: '%s'", in snp_launch_update_cpuid()
1219 strerror(-ret)); in snp_launch_update_cpuid()
1225 error_report("SEV-SNP: failed to generate CPUID table information"); in snp_launch_update_cpuid()
1240 if (sev_snp->parent_obj.kernel_hashes) { in snp_launch_update_kernel_hashes()
1241 assert(sev_snp->kernel_hashes_data); in snp_launch_update_kernel_hashes()
1242 assert((sev_snp->kernel_hashes_offset + in snp_launch_update_kernel_hashes()
1243 sizeof(*sev_snp->kernel_hashes_data)) <= len); in snp_launch_update_kernel_hashes()
1245 memcpy(hva + sev_snp->kernel_hashes_offset, sev_snp->kernel_hashes_data, in snp_launch_update_kernel_hashes()
1246 sizeof(*sev_snp->kernel_hashes_data)); in snp_launch_update_kernel_hashes()
1274 for (i = 0; i < metadata->num_desc; i++) { in snp_populate_metadata_pages()
1275 desc = &metadata->descs[i]; in snp_populate_metadata_pages()
1277 type = snp_metadata_desc_to_page_type(desc->type); in snp_populate_metadata_pages()
1279 hva = gpa2hva(&mr, desc->base, desc->len, NULL); in snp_populate_metadata_pages()
1282 __func__, desc->base, desc->len); in snp_populate_metadata_pages()
1287 ret = snp_launch_update_cpuid(desc->base, hva, desc->len); in snp_populate_metadata_pages()
1288 } else if (desc->type == SEV_DESC_TYPE_SNP_KERNEL_HASHES) { in snp_populate_metadata_pages()
1289 ret = snp_launch_update_kernel_hashes(sev_snp, desc->base, hva, in snp_populate_metadata_pages()
1290 desc->len); in snp_populate_metadata_pages()
1292 ret = snp_launch_update_data(desc->base, hva, desc->len, type); in snp_populate_metadata_pages()
1297 __func__, desc->base, desc->len, desc->type); in snp_populate_metadata_pages()
1311 struct kvm_sev_snp_launch_finish *finish = &sev_snp->kvm_finish_conf; in sev_snp_launch_finish()
1334 trace_kvm_sev_snp_launch_finish(sev_snp->id_block_base64, sev_snp->id_auth_base64, in sev_snp_launch_finish()
1335 sev_snp->host_data); in sev_snp_launch_finish()
1336 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_SNP_LAUNCH_FINISH, in sev_snp_launch_finish()
1349 "SEV-SNP: Migration is not implemented"); in sev_snp_launch_finish()
1367 klass->launch_finish(sev_common); in sev_vm_state_change()
1373 * This helper is to examine sev-guest properties and determine if any options
1379 /* Currently no KVM_SEV_INIT2-specific options are exposed via QEMU */ in sev_init2_required()
1389 if (sev_common->kvm_type != -1) { in sev_kvm_type()
1394 if (sev_guest->legacy_vm_type == ON_OFF_AUTO_ON || in sev_kvm_type()
1395 (sev_guest->legacy_vm_type == ON_OFF_AUTO_AUTO && in sev_kvm_type()
1397 sev_common->kvm_type = KVM_X86_DEFAULT_VM; in sev_kvm_type()
1402 * Newer VM types are required, either explicitly via legacy-vm-type=on, or in sev_kvm_type()
1403 * implicitly via legacy-vm-type=auto along with additional sev-guest in sev_kvm_type()
1406 kvm_type = (sev_guest->policy & SEV_POLICY_ES) ? in sev_kvm_type()
1409 if (sev_guest->legacy_vm_type == ON_OFF_AUTO_AUTO) { in sev_kvm_type()
1417 "the legacy KVM_X86_DEFAULT_VM VM type, the 'legacy-vm-type' argument " in sev_kvm_type()
1418 "must be set to 'on' or 'auto' for the sev-guest object.", in sev_kvm_type()
1422 return -1; in sev_kvm_type()
1425 sev_common->kvm_type = kvm_type; in sev_kvm_type()
1427 return sev_common->kvm_type; in sev_kvm_type()
1447 sev_common->state = SEV_STATE_UNINIT; in sev_common_kvm_init()
1457 if (host_cbitpos != sev_common->cbitpos) { in sev_common_kvm_init()
1459 __func__, host_cbitpos, sev_common->cbitpos); in sev_common_kvm_init()
1460 return -1; in sev_common_kvm_init()
1464 * The reduced-phys-bits value will be placed in bit positions 11:6 of in sev_common_kvm_init()
1468 if (sev_common->reduced_phys_bits < 1 || in sev_common_kvm_init()
1469 sev_common->reduced_phys_bits > 63) { in sev_common_kvm_init()
1472 __func__, sev_common->reduced_phys_bits); in sev_common_kvm_init()
1473 return -1; in sev_common_kvm_init()
1476 devname = object_property_get_str(OBJECT(sev_common), "sev-device", NULL); in sev_common_kvm_init()
1477 sev_common->sev_fd = open(devname, O_RDWR); in sev_common_kvm_init()
1478 if (sev_common->sev_fd < 0) { in sev_common_kvm_init()
1482 return -1; in sev_common_kvm_init()
1486 ret = sev_platform_ioctl(sev_common->sev_fd, SEV_PLATFORM_STATUS, &status, in sev_common_kvm_init()
1492 return -1; in sev_common_kvm_init()
1494 sev_common->build_id = status.build; in sev_common_kvm_init()
1495 sev_common->api_major = status.api_major; in sev_common_kvm_init()
1496 sev_common->api_minor = status.api_minor; in sev_common_kvm_init()
1500 error_setg(errp, "%s: SEV-ES guests require in-kernel irqchip" in sev_common_kvm_init()
1502 return -1; in sev_common_kvm_init()
1508 error_setg(errp, "%s: guest policy requires SEV-ES, but " in sev_common_kvm_init()
1509 "host SEV-ES support unavailable", in sev_common_kvm_init()
1511 return -1; in sev_common_kvm_init()
1516 switch (x86_klass->kvm_type(X86_CONFIDENTIAL_GUEST(sev_common))) { in sev_common_kvm_init()
1520 ret = sev_ioctl(sev_common->sev_fd, cmd, NULL, &fw_error); in sev_common_kvm_init()
1527 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_INIT2, &args, &fw_error); in sev_common_kvm_init()
1533 return -1; in sev_common_kvm_init()
1539 return -1; in sev_common_kvm_init()
1542 ret = klass->launch_start(sev_common); in sev_common_kvm_init()
1546 return -1; in sev_common_kvm_init()
1549 if (klass->kvm_init && klass->kvm_init(cgs, errp)) { in sev_common_kvm_init()
1550 return -1; in sev_common_kvm_init()
1555 cgs->ready = true; in sev_common_kvm_init()
1565 * SEV/SEV-ES rely on pinned memory to back guest RAM so discarding in sev_kvm_init()
1573 return -1; in sev_kvm_init()
1585 * measurement of the encrypted images. When SEV-SNP is enabled, the in sev_kvm_init()
1600 if (x86ms->smm == ON_OFF_AUTO_AUTO) { in sev_snp_kvm_init()
1601 x86ms->smm = ON_OFF_AUTO_OFF; in sev_snp_kvm_init()
1602 } else if (x86ms->smm == ON_OFF_AUTO_ON) { in sev_snp_kvm_init()
1603 error_setg(errp, "SEV-SNP does not support SMM."); in sev_snp_kvm_init()
1604 return -1; in sev_snp_kvm_init()
1613 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_encrypt_flash()
1625 ret = klass->launch_update_data(sev_common, gpa, ptr, len); in sev_encrypt_flash()
1645 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_inject_launch_secret()
1655 sev_common->state); in sev_inject_launch_secret()
1689 ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_LAUNCH_SECRET, in sev_inject_launch_secret()
1700 #define SEV_SECRET_GUID "4c2eb361-7d9b-4cc3-8081-127c90d3d294"
1725 gpa = area->base; in qmp_sev_inject_launch_secret()
1734 if (!info->reset_addr) { in sev_es_parse_reset_block()
1735 error_report("SEV-ES reset address is zero"); in sev_es_parse_reset_block()
1739 *addr = info->reset_addr; in sev_es_parse_reset_block()
1755 * return code indicates that SEV-ES is not active. in sev_es_find_reset_vector()
1760 * Extract the AP reset vector for SEV-ES guests by locating the SEV GUID. in sev_es_find_reset_vector()
1775 data = flash_ptr + flash_size - 0x20; in sev_es_find_reset_vector()
1780 guid = (QemuUUID *)(data - sizeof(info_guid)); in sev_es_find_reset_vector()
1786 len = (uint16_t *)((uint8_t *)guid - sizeof(*len)); in sev_es_find_reset_vector()
1787 info = (SevInfoBlock *)(data - le16_to_cpu(*len)); in sev_es_find_reset_vector()
1796 ConfidentialGuestSupport *cgs = MACHINE(qdev_get_machine())->cgs; in sev_es_set_reset_vector()
1801 if (!sev_common || !sev_common->reset_data_valid) { in sev_es_set_reset_vector()
1806 if (cpu->cpu_index == 0) { in sev_es_set_reset_vector()
1811 env = &x86->env; in sev_es_set_reset_vector()
1813 cpu_x86_load_seg_cache(env, R_CS, 0xf000, sev_common->reset_cs, 0xffff, in sev_es_set_reset_vector()
1817 env->eip = sev_common->reset_ip; in sev_es_set_reset_vector()
1825 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_es_save_reset_vector()
1839 sev_common->reset_cs = addr & 0xffff0000; in sev_es_save_reset_vector()
1840 sev_common->reset_ip = addr & 0x0000ffff; in sev_es_save_reset_vector()
1841 sev_common->reset_data_valid = true; in sev_es_save_reset_vector()
1881 * Calculate hash of kernel command-line with the terminating null byte. If in build_kernel_loader_hashes()
1882 * the user doesn't supply a command-line via -append, the 1-byte "\0" will in build_kernel_loader_hashes()
1886 if (qcrypto_hash_bytes(QCRYPTO_HASH_ALGO_SHA256, ctx->cmdline_data, in build_kernel_loader_hashes()
1887 ctx->cmdline_size, &hashp, &hash_len, errp) < 0) { in build_kernel_loader_hashes()
1893 * Calculate hash of initrd. If the user doesn't supply an initrd via in build_kernel_loader_hashes()
1894 * -initrd, an empty buffer will be used (ctx->initrd_size == 0). in build_kernel_loader_hashes()
1897 if (qcrypto_hash_bytes(QCRYPTO_HASH_ALGO_SHA256, ctx->initrd_data, in build_kernel_loader_hashes()
1898 ctx->initrd_size, &hashp, &hash_len, errp) < 0) { in build_kernel_loader_hashes()
1905 struct iovec iov[2] = { in build_kernel_loader_hashes() local
1906 { .iov_base = ctx->setup_data, .iov_len = ctx->setup_size }, in build_kernel_loader_hashes()
1907 { .iov_base = ctx->kernel_data, .iov_len = ctx->kernel_size } in build_kernel_loader_hashes()
1909 if (qcrypto_hash_bytesv(QCRYPTO_HASH_ALGO_SHA256, iov, ARRAY_SIZE(iov), in build_kernel_loader_hashes()
1915 ht = &padded_ht->ht; in build_kernel_loader_hashes()
1917 ht->guid = sev_hash_table_header_guid; in build_kernel_loader_hashes()
1918 ht->len = sizeof(*ht); in build_kernel_loader_hashes()
1920 ht->cmdline.guid = sev_cmdline_entry_guid; in build_kernel_loader_hashes()
1921 ht->cmdline.len = sizeof(ht->cmdline); in build_kernel_loader_hashes()
1922 memcpy(ht->cmdline.hash, cmdline_hash, sizeof(ht->cmdline.hash)); in build_kernel_loader_hashes()
1924 ht->initrd.guid = sev_initrd_entry_guid; in build_kernel_loader_hashes()
1925 ht->initrd.len = sizeof(ht->initrd); in build_kernel_loader_hashes()
1926 memcpy(ht->initrd.hash, initrd_hash, sizeof(ht->initrd.hash)); in build_kernel_loader_hashes()
1928 ht->kernel.guid = sev_kernel_entry_guid; in build_kernel_loader_hashes()
1929 ht->kernel.len = sizeof(ht->kernel); in build_kernel_loader_hashes()
1930 memcpy(ht->kernel.hash, kernel_hash, sizeof(ht->kernel.hash)); in build_kernel_loader_hashes()
1933 memset(padded_ht->padding, 0, sizeof(padded_ht->padding)); in build_kernel_loader_hashes()
1949 sev_snp_guest->kernel_hashes_offset = area->base & ~TARGET_PAGE_MASK; in sev_snp_build_kernel_loader_hashes()
1950 sev_snp_guest->kernel_hashes_data = g_new0(PaddedSevHashTable, 1); in sev_snp_build_kernel_loader_hashes()
1951 return build_kernel_loader_hashes(sev_snp_guest->kernel_hashes_data, ctx, errp); in sev_snp_build_kernel_loader_hashes()
1965 * Populate the hashes table in the guest's memory at the OVMF-designated in sev_build_kernel_loader_hashes()
1968 padded_ht = address_space_map(&address_space_memory, area->base, in sev_build_kernel_loader_hashes()
1976 if (sev_encrypt_flash(area->base, (uint8_t *)padded_ht, in sev_build_kernel_loader_hashes()
1998 SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); in sev_add_kernel_loader_hashes()
2002 * Only add the kernel hashes if the sev-guest configuration explicitly in sev_add_kernel_loader_hashes()
2003 * stated kernel-hashes=on. in sev_add_kernel_loader_hashes()
2005 if (!sev_common->kernel_hashes) { in sev_add_kernel_loader_hashes()
2016 if (!area->base || area->size < sizeof(PaddedSevHashTable)) { in sev_add_kernel_loader_hashes()
2018 "(base=0x%x size=0x%x)", area->base, area->size); in sev_add_kernel_loader_hashes()
2022 return klass->build_kernel_loader_hashes(sev_common, area, ctx, errp); in sev_add_kernel_loader_hashes()
2028 return g_strdup(SEV_COMMON(obj)->sev_device); in sev_common_get_sev_device()
2034 SEV_COMMON(obj)->sev_device = g_strdup(value); in sev_common_set_sev_device()
2039 return SEV_COMMON(obj)->kernel_hashes; in sev_common_get_kernel_hashes()
2044 SEV_COMMON(obj)->kernel_hashes = value; in sev_common_set_kernel_hashes()
2052 klass->kvm_init = sev_common_kvm_init; in sev_common_class_init()
2054 object_class_property_add_str(oc, "sev-device", in sev_common_class_init()
2057 object_class_property_set_description(oc, "sev-device", in sev_common_class_init()
2059 object_class_property_add_bool(oc, "kernel-hashes", in sev_common_class_init()
2062 object_class_property_set_description(oc, "kernel-hashes", in sev_common_class_init()
2071 sev_common->kvm_type = -1; in sev_common_instance_init()
2073 sev_common->sev_device = g_strdup(DEFAULT_SEV_DEVICE); in sev_common_instance_init()
2075 object_property_add_uint32_ptr(obj, "cbitpos", &sev_common->cbitpos, in sev_common_instance_init()
2077 object_property_add_uint32_ptr(obj, "reduced-phys-bits", in sev_common_instance_init()
2078 &sev_common->reduced_phys_bits, in sev_common_instance_init()
2082 /* sev guest info common to sev/sev-es/sev-snp */
2100 return g_strdup(SEV_GUEST(obj)->dh_cert_file); in sev_guest_get_dh_cert_file()
2106 SEV_GUEST(obj)->dh_cert_file = g_strdup(value); in sev_guest_set_dh_cert_file()
2114 return sev_guest->session_file ? g_strdup(sev_guest->session_file) : NULL; in sev_guest_get_session_file()
2120 SEV_GUEST(obj)->session_file = g_strdup(value); in sev_guest_set_session_file()
2128 OnOffAuto legacy_vm_type = sev_guest->legacy_vm_type; in sev_guest_get_legacy_vm_type()
2139 visit_type_OnOffAuto(v, name, &sev_guest->legacy_vm_type, errp); in sev_guest_set_legacy_vm_type()
2148 klass->build_kernel_loader_hashes = sev_build_kernel_loader_hashes; in sev_guest_class_init()
2149 klass->launch_start = sev_launch_start; in sev_guest_class_init()
2150 klass->launch_finish = sev_launch_finish; in sev_guest_class_init()
2151 klass->launch_update_data = sev_launch_update_data; in sev_guest_class_init()
2152 klass->kvm_init = sev_kvm_init; in sev_guest_class_init()
2153 x86_klass->kvm_type = sev_kvm_type; in sev_guest_class_init()
2155 object_class_property_add_str(oc, "dh-cert-file", in sev_guest_class_init()
2158 object_class_property_set_description(oc, "dh-cert-file", in sev_guest_class_init()
2160 object_class_property_add_str(oc, "session-file", in sev_guest_class_init()
2163 object_class_property_set_description(oc, "session-file", in sev_guest_class_init()
2165 object_class_property_add(oc, "legacy-vm-type", "OnOffAuto", in sev_guest_class_init()
2168 object_class_property_set_description(oc, "legacy-vm-type", in sev_guest_class_init()
2177 sev_guest->policy = DEFAULT_GUEST_POLICY; in sev_guest_instance_init()
2178 object_property_add_uint32_ptr(obj, "handle", &sev_guest->handle, in sev_guest_instance_init()
2180 object_property_add_uint32_ptr(obj, "policy", &sev_guest->policy, in sev_guest_instance_init()
2184 sev_guest->legacy_vm_type = ON_OFF_AUTO_AUTO; in sev_guest_instance_init()
2187 /* guest info specific sev/sev-es */
2201 (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_start_conf.policy, in sev_snp_guest_get_policy()
2210 (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_start_conf.policy, in sev_snp_guest_set_policy()
2217 return g_strdup(SEV_SNP_GUEST(obj)->guest_visible_workarounds); in sev_snp_guest_get_guest_visible_workarounds()
2225 struct kvm_sev_snp_launch_start *start = &sev_snp_guest->kvm_start_conf; in sev_snp_guest_set_guest_visible_workarounds()
2229 g_free(sev_snp_guest->guest_visible_workarounds); in sev_snp_guest_set_guest_visible_workarounds()
2231 /* store the base64 str so we don't need to re-encode in getter */ in sev_snp_guest_set_guest_visible_workarounds()
2232 sev_snp_guest->guest_visible_workarounds = g_strdup(value); in sev_snp_guest_set_guest_visible_workarounds()
2234 blob = qbase64_decode(sev_snp_guest->guest_visible_workarounds, in sev_snp_guest_set_guest_visible_workarounds()
2235 -1, &len, errp); in sev_snp_guest_set_guest_visible_workarounds()
2240 if (len != sizeof(start->gosvw)) { in sev_snp_guest_set_guest_visible_workarounds()
2243 len, sizeof(start->gosvw)); in sev_snp_guest_set_guest_visible_workarounds()
2247 memcpy(start->gosvw, blob, len); in sev_snp_guest_set_guest_visible_workarounds()
2255 return g_strdup(sev_snp_guest->id_block_base64); in sev_snp_guest_get_id_block()
2262 struct kvm_sev_snp_launch_finish *finish = &sev_snp_guest->kvm_finish_conf; in sev_snp_guest_set_id_block()
2265 finish->id_block_en = 0; in sev_snp_guest_set_id_block()
2266 g_free(sev_snp_guest->id_block); in sev_snp_guest_set_id_block()
2267 g_free(sev_snp_guest->id_block_base64); in sev_snp_guest_set_id_block()
2269 /* store the base64 str so we don't need to re-encode in getter */ in sev_snp_guest_set_id_block()
2270 sev_snp_guest->id_block_base64 = g_strdup(value); in sev_snp_guest_set_id_block()
2271 sev_snp_guest->id_block = in sev_snp_guest_set_id_block()
2272 qbase64_decode(sev_snp_guest->id_block_base64, -1, &len, errp); in sev_snp_guest_set_id_block()
2274 if (!sev_snp_guest->id_block) { in sev_snp_guest_set_id_block()
2285 finish->id_block_en = 1; in sev_snp_guest_set_id_block()
2286 finish->id_block_uaddr = (uintptr_t)sev_snp_guest->id_block; in sev_snp_guest_set_id_block()
2294 return g_strdup(sev_snp_guest->id_auth_base64); in sev_snp_guest_get_id_auth()
2301 struct kvm_sev_snp_launch_finish *finish = &sev_snp_guest->kvm_finish_conf; in sev_snp_guest_set_id_auth()
2304 finish->id_auth_uaddr = 0; in sev_snp_guest_set_id_auth()
2305 g_free(sev_snp_guest->id_auth); in sev_snp_guest_set_id_auth()
2306 g_free(sev_snp_guest->id_auth_base64); in sev_snp_guest_set_id_auth()
2308 /* store the base64 str so we don't need to re-encode in getter */ in sev_snp_guest_set_id_auth()
2309 sev_snp_guest->id_auth_base64 = g_strdup(value); in sev_snp_guest_set_id_auth()
2310 sev_snp_guest->id_auth = in sev_snp_guest_set_id_auth()
2311 qbase64_decode(sev_snp_guest->id_auth_base64, -1, &len, errp); in sev_snp_guest_set_id_auth()
2313 if (!sev_snp_guest->id_auth) { in sev_snp_guest_set_id_auth()
2324 finish->id_auth_uaddr = (uintptr_t)sev_snp_guest->id_auth; in sev_snp_guest_set_id_auth()
2332 return !!sev_snp_guest->kvm_finish_conf.auth_key_en; in sev_snp_guest_get_author_key_enabled()
2340 sev_snp_guest->kvm_finish_conf.auth_key_en = value; in sev_snp_guest_set_author_key_enabled()
2348 return !!sev_snp_guest->kvm_finish_conf.vcek_disabled; in sev_snp_guest_get_vcek_disabled()
2356 sev_snp_guest->kvm_finish_conf.vcek_disabled = value; in sev_snp_guest_set_vcek_disabled()
2364 return g_strdup(sev_snp_guest->host_data); in sev_snp_guest_get_host_data()
2371 struct kvm_sev_snp_launch_finish *finish = &sev_snp_guest->kvm_finish_conf; in sev_snp_guest_set_host_data()
2375 g_free(sev_snp_guest->host_data); in sev_snp_guest_set_host_data()
2377 /* store the base64 str so we don't need to re-encode in getter */ in sev_snp_guest_set_host_data()
2378 sev_snp_guest->host_data = g_strdup(value); in sev_snp_guest_set_host_data()
2380 blob = qbase64_decode(sev_snp_guest->host_data, -1, &len, errp); in sev_snp_guest_set_host_data()
2386 if (len != sizeof(finish->host_data)) { in sev_snp_guest_set_host_data()
2389 len, sizeof(finish->host_data)); in sev_snp_guest_set_host_data()
2393 memcpy(finish->host_data, blob, len); in sev_snp_guest_set_host_data()
2402 klass->build_kernel_loader_hashes = sev_snp_build_kernel_loader_hashes; in sev_snp_guest_class_init()
2403 klass->launch_start = sev_snp_launch_start; in sev_snp_guest_class_init()
2404 klass->launch_finish = sev_snp_launch_finish; in sev_snp_guest_class_init()
2405 klass->launch_update_data = sev_snp_launch_update_data; in sev_snp_guest_class_init()
2406 klass->kvm_init = sev_snp_kvm_init; in sev_snp_guest_class_init()
2407 x86_klass->mask_cpuid_features = sev_snp_mask_cpuid_features; in sev_snp_guest_class_init()
2408 x86_klass->kvm_type = sev_snp_kvm_type; in sev_snp_guest_class_init()
2413 object_class_property_add_str(oc, "guest-visible-workarounds", in sev_snp_guest_class_init()
2416 object_class_property_add_str(oc, "id-block", in sev_snp_guest_class_init()
2419 object_class_property_add_str(oc, "id-auth", in sev_snp_guest_class_init()
2422 object_class_property_add_bool(oc, "author-key-enabled", in sev_snp_guest_class_init()
2425 object_class_property_add_bool(oc, "vcek-disabled", in sev_snp_guest_class_init()
2428 object_class_property_add_str(oc, "host-data", in sev_snp_guest_class_init()
2439 cgs->require_guest_memfd = true; in sev_snp_guest_instance_init()
2442 sev_snp_guest->kvm_start_conf.policy = DEFAULT_SEV_SNP_POLICY; in sev_snp_guest_instance_init()
2445 /* guest info specific to sev-snp */