igvm: add support for igvm memory map parameter in native mode
Add and wire up qigvm_x86_get_mem_map_entry function which converts the e820 table into an igvm memory map parameter. This makes igvm files for the native (non-confidential) platform with memory map parameter work. Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Luigi Leonardi <leonardi@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-ID: <20251029105555.2492276-4-kraxel@redhat.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/target-info-qapi.h"
|
||||
#include "system/igvm.h"
|
||||
#include "system/memory.h"
|
||||
#include "system/address-spaces.h"
|
||||
@@ -543,6 +544,8 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
|
||||
Error **errp)
|
||||
{
|
||||
const IGVM_VHS_PARAMETER *param = (const IGVM_VHS_PARAMETER *)header_data;
|
||||
int (*get_mem_map_entry)(int index, ConfidentialGuestMemoryMapEntry *entry,
|
||||
Error **errp) = NULL;
|
||||
QIgvmParameterData *param_entry;
|
||||
int max_entry_count;
|
||||
int entry = 0;
|
||||
@@ -550,7 +553,13 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
|
||||
ConfidentialGuestMemoryMapEntry cgmm_entry;
|
||||
int retval = 0;
|
||||
|
||||
if (!ctx->cgs) {
|
||||
if (ctx->cgs && ctx->cgsc->get_mem_map_entry) {
|
||||
get_mem_map_entry = ctx->cgsc->get_mem_map_entry;
|
||||
|
||||
} else if (target_arch() == SYS_EMU_TARGET_X86_64) {
|
||||
get_mem_map_entry = qigvm_x86_get_mem_map_entry;
|
||||
|
||||
} else {
|
||||
error_setg(errp,
|
||||
"IGVM file contains a memory map but this is not supported "
|
||||
"by the current system.");
|
||||
@@ -565,7 +574,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
|
||||
param_entry->size / sizeof(IGVM_VHS_MEMORY_MAP_ENTRY);
|
||||
mm_entry = (IGVM_VHS_MEMORY_MAP_ENTRY *)param_entry->data;
|
||||
|
||||
retval = ctx->cgsc->get_mem_map_entry(entry, &cgmm_entry, errp);
|
||||
retval = get_mem_map_entry(entry, &cgmm_entry, errp);
|
||||
while (retval == 0) {
|
||||
if (entry >= max_entry_count) {
|
||||
error_setg(
|
||||
@@ -598,8 +607,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
|
||||
IGVM_MEMORY_MAP_ENTRY_TYPE_PLATFORM_RESERVED;
|
||||
break;
|
||||
}
|
||||
retval =
|
||||
ctx->cgsc->get_mem_map_entry(++entry, &cgmm_entry, errp);
|
||||
retval = get_mem_map_entry(++entry, &cgmm_entry, errp);
|
||||
}
|
||||
if (retval < 0) {
|
||||
return retval;
|
||||
|
||||
@@ -19,4 +19,9 @@
|
||||
int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
|
||||
bool onlyVpContext, Error **errp);
|
||||
|
||||
/* x86 native */
|
||||
int qigvm_x86_get_mem_map_entry(int index,
|
||||
ConfidentialGuestMemoryMapEntry *entry,
|
||||
Error **errp);
|
||||
|
||||
#endif
|
||||
|
||||
21
stubs/igvm.c
Normal file
21
stubs/igvm.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* QEMU IGVM, stubs
|
||||
*
|
||||
* Copyright (C) 2026 Red Hat
|
||||
*
|
||||
* Authors:
|
||||
* Gerd Hoffmann <kraxel@redhat.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "system/igvm.h"
|
||||
|
||||
int qigvm_x86_get_mem_map_entry(int index,
|
||||
ConfidentialGuestMemoryMapEntry *entry,
|
||||
Error **errp)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -74,6 +74,7 @@ if have_system
|
||||
stub_ss.add(files('dump.c'))
|
||||
stub_ss.add(files('cmos.c'))
|
||||
stub_ss.add(files('fw_cfg.c'))
|
||||
stub_ss.add(files('igvm.c'))
|
||||
stub_ss.add(files('target-get-monitor-def.c'))
|
||||
stub_ss.add(files('target-monitor-defs.c'))
|
||||
stub_ss.add(files('win32-kbd-hook.c'))
|
||||
|
||||
46
target/i386/igvm.c
Normal file
46
target/i386/igvm.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* QEMU IGVM, support for native x86 guests
|
||||
*
|
||||
* Copyright (C) 2026 Red Hat
|
||||
*
|
||||
* Authors:
|
||||
* Gerd Hoffmann <kraxel@redhat.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "hw/i386/e820_memory_layout.h"
|
||||
#include "system/igvm.h"
|
||||
|
||||
/*
|
||||
* convert e820 table into igvm memory map
|
||||
*/
|
||||
int qigvm_x86_get_mem_map_entry(int index,
|
||||
ConfidentialGuestMemoryMapEntry *entry,
|
||||
Error **errp)
|
||||
{
|
||||
struct e820_entry *table;
|
||||
int num_entries;
|
||||
|
||||
num_entries = e820_get_table(&table);
|
||||
if ((index < 0) || (index >= num_entries)) {
|
||||
return 1;
|
||||
}
|
||||
entry->gpa = table[index].address;
|
||||
entry->size = table[index].length;
|
||||
switch (table[index].type) {
|
||||
case E820_RAM:
|
||||
entry->type = CGS_MEM_RAM;
|
||||
break;
|
||||
case E820_RESERVED:
|
||||
entry->type = CGS_MEM_RESERVED;
|
||||
break;
|
||||
default:
|
||||
/* should not happen */
|
||||
error_setg(errp, "unknown e820 type");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -26,6 +26,9 @@ i386_system_ss.add(files(
|
||||
))
|
||||
i386_system_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'),
|
||||
if_false: files('sev-system-stub.c'))
|
||||
if igvm.found()
|
||||
i386_system_ss.add(files('igvm.c'))
|
||||
endif
|
||||
|
||||
i386_user_ss = ss.source_set()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user