igvm: add support for igvm memory map parameter in native mode
v3 cover igvm: add support for igvm memory map parameter in native mode
v3:
- Oh crap, no MAINTAINERS entry, so v1 + v2 probably went largely unnoticed. Added a patch adding an entry, comments welcome. Also added some people to Cc.
- code is mostly unchanged.
v2:
- add support for loading the initial register state
Gerd Hoffmann (5):
igvm: move igvm.h file to include/system
igvm: add support for igvm memory map parameter in native mode
igvm: add support for initial register state load in native mode
igvm: track memory regions created
igvm: add MAINTAINERS entry
{backends => include/system}/igvm.h | 7 ++
target/i386/cpu.h | 3 +
backends/igvm-cfg.c | 2 +-
backends/igvm.c | 70 +++++++----
stubs/igvm.c | 26 ++++
target/i386/cpu.c | 4 +
target/i386/igvm.c | 179 ++++++++++++++++++++++++++++
MAINTAINERS | 9 ++
stubs/meson.build | 1 +
target/i386/meson.build | 3 +
10 files changed, 277 insertions(+), 27 deletions(-)
rename {backends => include/system}/igvm.h (64%)
create mode 100644 stubs/igvm.c
create mode 100644 target/i386/igvm.cSignature · 1 line
2.51.0
PATCH v3 1/5 igvm: move igvm.h file to include/system
Prepare for arch-specific igvm code being added to the code base.
---
{backends => include/system}/igvm.h | 0
backends/igvm-cfg.c | 2 +-
backends/igvm.c | 2 +-
3 files changed, 2 insertions(+), 2 deletions(-)
rename {backends => include/system}/igvm.h (100%)include/system/igvm.h renamed from backends/igvm.h +0 -0
backends/igvm-cfg.c +1 -1
@@ -12,7 +12,7 @@#include "qemu/osdep.h" #include "system/igvm-cfg.h" -#include "igvm.h" +#include "system/igvm.h" #include "qom/object_interfaces.h" static char *get_igvm (Object *obj,Error **errp)
backends/igvm.c +1 -1
@@ -11,8 +11,8 @@#include "qemu/osdep.h" -#include "igvm.h" #include "qapi/error.h" +#include "system/igvm.h" #include "system/memory.h" #include "system/address-spaces.h" #include "hw/core/cpu.h"
Signature · 1 line
2.51.0
Re: [PATCH v3 1/5] igvm: move igvm.h file to include/system
Quoted 7 lines · Gerd Hoffmann
Prepare for arch-specific igvm code being added to the code base.
Signed-off-by Gerd Hoffmann <[email protected]>
Quoted 41 lines
---
{backends => include/system}/igvm.h | 0 backends/igvm-cfg.c | 2 +- backends/igvm.c | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-)rename {backends =>
include/system}/igvm.h(100%)include/system/igvm.h renamed from backends/igvm.h +0
-0backends/igvm-cfg.c +1
-1@@ -12,7 +12,7 @@#include "qemu/osdep.h" #include "system/igvm-cfg.h" -#include "igvm.h" +#include "system/igvm.h" #include "qom/object_interfaces.h" static char *get_igvm (Object *obj,Error **errp)backends/igvm.c +1
-1@@ -11,8 +11,8 @@#include "qemu/osdep.h" -#include "igvm.h" #include "qapi/error.h" +#include "system/igvm.h" #include "system/memory.h" #include "system/address-spaces.h" #include "hw/core/cpu.h" Signature · 1 line
2.51.0
Re: [PATCH v3 1/5] igvm: move igvm.h file to include/system
In reply to Gerd HoffmannQuoted 9 lines · Gerd Hoffmann
Prepare for arch-specific igvm code being added to the code base.
Signed-off-by Gerd Hoffmann <[email protected]>---
{backends => include/system}/igvm.h | 0 backends/igvm-cfg.c | 2 +- backends/igvm.c | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-)rename {backends =>
include/system}/igvm.h(100%)
Quoted 35 lines
include/system/igvm.h renamed from backends/igvm.h +0
-0backends/igvm-cfg.c +1
-1@@ -12,7 +12,7 @@#include "qemu/osdep.h" #include "system/igvm-cfg.h" -#include "igvm.h" +#include "system/igvm.h" #include "qom/object_interfaces.h" static char *get_igvm (Object *obj,Error **errp)backends/igvm.c +1
-1@@ -11,8 +11,8 @@#include "qemu/osdep.h" -#include "igvm.h" #include "qapi/error.h" +#include "system/igvm.h" #include "system/memory.h" #include "system/address-spaces.h" #include "hw/core/cpu.h" Signature · 1 line
2.51.0
PATCH v3 2/5 igvm: add support for igvm memory map parameter in native mode
In reply to Gerd HoffmannAdd 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.
--- include/system/igvm.h | 5 +++++ backends/igvm.c | 18 ++++++++++++---- stubs/igvm.c | 21 +++++++++++++++++++ target/i386/igvm.c | 46 +++++++++++++++++++++++++++++++++++++++++ stubs/meson.build | 1 + target/i386/meson.build | 3 +++ 6 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 stubs/igvm.c create mode 100644 target/i386/igvm.c
include/system/igvm.h +5 -0
@@ -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
backends/igvm.c +14 -4
@@ -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,15 @@ 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; + } + +if (!get_mem_map_entry &&target_arch () ==SYS_EMU_TARGET_X86_64 ) { + get_mem_map_entry = qigvm_x86_get_mem_map_entry; + } + +if (!get_mem_map_entry) {error_setg (errp,"IGVM file contains a memory map but this is not supported " "by the current system." );
@@ -565,7 +576,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 +609,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;
stubs/igvm.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* QEMU IGVM, stubs +* +* Copyright (C) 2026 Red Hat +* +* Authors: +* Gerd Hoffmann <[email protected]> +* +* 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 ; +}
target/i386/igvm.c new file +46 -0
46 lines not on this page · raw message
stubs/meson.build +1 -0
@@ -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'))
target/i386/meson.build +3 -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()
Signature · 1 line
2.51.0
Quoted 52 lines · Gerd Hoffmann
Add and wire up
qigvm_x86_get_mem_map_entryfunction 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.Signed-off-by Gerd Hoffmann <[email protected]>---
include/system/igvm.h | 5 +++++ backends/igvm.c | 18 ++++++++++++---- stubs/igvm.c | 21 +++++++++++++++++++ target/i386/igvm.c | 46 +++++++++++++++++++++++++++++++++++++++++ stubs/meson.build | 1 + target/i386/meson.build | 3 +++ 6 files changed, 90 insertions(+), 4 deletions(-)create mode 100644
stubs/igvm.c
create mode 100644target/i386/igvm.cinclude/system/igvm.h +5
-0@@ -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 backends/igvm.c +3
-0@@ -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 ;
backends/igvm.c static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data, · line 560
Quoted 9 lines
backends/igvm.c +5
-1@@ -550,7 +553,15 @@ 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; + } + +if (!get_mem_map_entry &&target_arch () ==SYS_EMU_TARGET_X86_64 ) {
nit: we can avoid to re-evaluate get_mem_map_entry again, so we can
do: (not a strong opinion, just more readable IMHO)
else if (target_arch() == SYS_EMU_TARGET_X86_64) {Quoted 8 lines
backends/igvm.c +4
-0+ get_mem_map_entry = qigvm_x86_get_mem_map_entry; + } + +if (!get_mem_map_entry) {error_setg (errp,"IGVM file contains a memory map but this is not supported " "by the current system." );
backends/igvm.c static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data, · line 581
Quoted 7 lines
backends/igvm.c +1
-1@@ -565,7 +576,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) {
pre-existing, but should this be entry >= max_entry_count ?
BTW this should be eventually fixed in another patch, so for this patch:
Quoted 119 lines
backends/igvm.c +1
-2error_setg(@@ -598,8 +609,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;stubs/igvm.c new file +21
-0@@ -0,0 +1,21 @@ +/* +* QEMU IGVM, stubs +* +* Copyright (C) 2026 Red Hat +* +* Authors: +* Gerd Hoffmann <[email protected]> +* +* 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 ; +}target/i386/igvm.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* QEMU IGVM, support for native x86 guests +* +* Copyright (C) 2026 Red Hat +* +* Authors: +* Gerd Hoffmann <[email protected]> +* +* 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 ; +}stubs/meson.build +1
-0@@ -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'))target/i386/meson.build +3
-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()Signature · 1 line
2.51.0
PATCH v3 3/5 igvm: add support for initial register state load in native mode
In reply to Gerd HoffmannAdd IgvmNativeVpContextX64 struct holding the register state (see igvm spec), and the qigvm_x86_load_context() function to load the register state.
Wire up using two new functions: qigvm_x86_set_vp_context() is called from igvm file handling code and stores the boot processor context. qigvm_x86_bsp_reset() is called from i386 target cpu reset code and loads the context into the cpu registers.
--- include/system/igvm.h | 2 + target/i386/cpu.h | 3 + backends/igvm.c | 30 +++++----- stubs/igvm.c | 5 ++ target/i386/cpu.c | 4 ++ target/i386/igvm.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 15 deletions(-)
include/system/igvm.h +2 -0
@@ -23,5 +23,7 @@ int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,int qigvm_x86_get_mem_map_entry (int index,ConfidentialGuestMemoryMapEntry *entry,Error **errp); +int qigvm_x86_set_vp_context (void *data,int index, +Error **errp);#endif
target/i386/cpu.h +3 -0
@@ -2867,6 +2867,9 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);#endif +/* igvm.c */ +void qigvm_x86_bsp_reset (CPUX86State *env); +/* cpu.c */ bool cpu_is_bsp (X86CPU *cpu);
backends/igvm.c +15 -15
@@ -432,18 +432,6 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,return 0 ; } -/* -* A confidential guest support object must be provided for setting -* a VP context. -*/ -if (!ctx->cgs) { -error_setg ( - errp, -"A VP context is present in the IGVM file but is not supported " -"by the current system." ); -return -1 ; - } - data_handle =igvm_get_header_data (ctx->file,IGVM_HEADER_SECTION_DIRECTIVE , ctx->current_header_index);if (data_handle <0 ) {
@@ -453,9 +441,21 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data, } data = (uint8_t *)igvm_get_buffer (ctx->file, data_handle); - result = ctx->cgsc->set_guest_state ( - vp_context->gpa, data,igvm_get_buffer_size (ctx->file, data_handle), -CGS_PAGE_TYPE_VMSA , vp_context->vp_index, errp); + +if (ctx->cgs) { + result = ctx->cgsc->set_guest_state ( + vp_context->gpa, data,igvm_get_buffer_size (ctx->file, data_handle), +CGS_PAGE_TYPE_VMSA , vp_context->vp_index, errp); + }else if (target_arch () ==SYS_EMU_TARGET_X86_64 ) { + result =qigvm_x86_set_vp_context (data, vp_context->vp_index, errp); + }else { +error_setg ( + errp, +"A VP context is present in the IGVM file but is not supported " +"by the current system." ); + result =-1 ; + } +igvm_free_buffer (ctx->file, data_handle);if (result <0 ) {return result;
stubs/igvm.c +5 -0
@@ -19,3 +19,8 @@ int qigvm_x86_get_mem_map_entry(int index, {return -1 ; } + +int qigvm_x86_set_vp_context (void *data,int index,Error **errp) +{ +return -1 ; +}
target/i386/cpu.c +4 -0
@@ -8770,6 +8770,10 @@ static void x86_cpu_reset_hold(Object *obj, ResetType type) cs->halted = !cpu_is_bsp (cpu); +if (cpu_is_bsp (cpu)) { +qigvm_x86_bsp_reset (env); + } +if (kvm_enabled ()) {kvm_arch_reset_vcpu (cpu); }
target/i386/igvm.c +133 -0
145 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v3 3/5] igvm: add support for initial register state load in native mode
Quoted 77 lines · Gerd Hoffmann
Add IgvmNativeVpContextX64 struct holding the register state (see igvm spec), and the
qigvm_x86_load_context()function to load the register state.Wire up using two new functions:
qigvm_x86_set_vp_context()is called from igvm file handling code and stores the boot processor context.qigvm_x86_bsp_reset()is called from i386 target cpu reset code and loads the context into the cpu registers.Signed-off-by Gerd Hoffmann <[email protected]>---
include/system/igvm.h | 2 + target/i386/cpu.h | 3 + backends/igvm.c | 30 +++++----- stubs/igvm.c | 5 ++ target/i386/cpu.c | 4 ++ target/i386/igvm.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 15 deletions(-)include/system/igvm.h +2
-0@@ -23,5 +23,7 @@ int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,int qigvm_x86_get_mem_map_entry (int index,ConfidentialGuestMemoryMapEntry *entry,Error **errp); +int qigvm_x86_set_vp_context (void *data,int index, +Error **errp);#endif target/i386/cpu.h +3
-0@@ -2867,6 +2867,9 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);#endif +/* igvm.c */ +void qigvm_x86_bsp_reset (CPUX86State *env); +/* cpu.c */ bool cpu_is_bsp (X86CPU *cpu);backends/igvm.c +2
-15@@ -432,18 +432,6 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,return 0 ; } -/* -* A confidential guest support object must be provided for setting -* a VP context. -*/ -if (!ctx->cgs) { -error_setg ( - errp, -"A VP context is present in the IGVM file but is not supported " -"by the current system." ); -return -1 ; - } - data_handle =igvm_get_header_data (ctx->file,IGVM_HEADER_SECTION_DIRECTIVE , ctx->current_header_index);if (data_handle <0 ) {@@ -453,9 +441,21 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data, } data = (uint8_t *)igvm_get_buffer (ctx->file, data_handle); - result = ctx->cgsc->set_guest_state ( - vp_context->gpa, data,igvm_get_buffer_size (ctx->file, data_handle), -CGS_PAGE_TYPE_VMSA , vp_context->vp_index, errp); + +if (ctx->cgs) {
backends/igvm.c static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data, · line 455
Quoted 10 lines
backends/igvm.c +10
-0+ result = ctx->cgsc->set_guest_state ( + vp_context->gpa, data,igvm_get_buffer_size (ctx->file, data_handle), +CGS_PAGE_TYPE_VMSA , vp_context->vp_index, errp); + }else if (target_arch () ==SYS_EMU_TARGET_X86_64 ) { + result =qigvm_x86_set_vp_context (data, vp_context->vp_index, errp); + }else { +error_setg ( + errp, +"A VP context is present in the IGVM file but is not supported " +"by the current system." );
It is pre-existing, but should we avoid splitting error messages to simplify searching for them in the code?
I don't remember if it's the same thing in QEMU, but in Linux we prefer this one, IIRC.
Quoted 39 lines
backends/igvm.c +3
-0+ result =-1 ; + } +igvm_free_buffer (ctx->file, data_handle);if (result <0 ) {return result;stubs/igvm.c +5
-0@@ -19,3 +19,8 @@ int qigvm_x86_get_mem_map_entry(int index, {return -1 ; } + +int qigvm_x86_set_vp_context (void *data,int index,Error **errp) +{ +return -1 ; +}target/i386/cpu.c +4
-0@@ -8770,6 +8770,10 @@ static void x86_cpu_reset_hold(Object *obj, ResetType type) cs->halted = !cpu_is_bsp (cpu); +if (cpu_is_bsp (cpu)) { +qigvm_x86_bsp_reset (env); + } +if (kvm_enabled ()) {kvm_arch_reset_vcpu (cpu); }target/i386/igvm.c +0
-0
target/i386/igvm.c line 18
Quoted 8 lines
target/i386/igvm.c +2
-0@@ -11,9 +11,114 @@#include "qemu/osdep.h" +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "system/igvm.h" +struct IgvmNativeVpContextX64 {
Do you know why this is not exposed by igvm headers?
BTW this patch LGTM:
Quoted 141 lines
target/i386/igvm.c +131
-0+uint64_t rax; +uint64_t rcx; +uint64_t rdx; +uint64_t rbx; +uint64_t rsp; +uint64_t rbp; +uint64_t rsi; +uint64_t rdi; +uint64_t r8; +uint64_t r9; +uint64_t r10; +uint64_t r11; +uint64_t r12; +uint64_t r13; +uint64_t r14; +uint64_t r15; +uint64_t rip; +uint64_t rflags; +uint64_t idtr_base; +uint16_t idtr_limit; +uint16_t reserved[2 ]; +uint16_t gdtr_limit; +uint64_t gdtr_base; + +uint16_t code_selector; +uint16_t code_attributes; +uint32_t code_base; +uint32_t code_limit; + +uint16_t data_selector; +uint16_t data_attributes; +uint32_t data_base; +uint32_t data_limit; + +uint64_t gs_base; +uint64_t cr0; +uint64_t cr3; +uint64_t cr4; +uint64_t efer; +}; + +#define FLAGS_TO_SEGCACHE (flags) \ + (((unsigned int)flags) << 8) + +static void qigvm_x86_load_context (struct IgvmNativeVpContextX64 *context,CPUX86State *env) +{ +cpu_load_efer (env, context->efer); +cpu_x86_update_cr4 (env, context->cr4); +cpu_x86_update_cr0 (env, context->cr0); +cpu_x86_update_cr3 (env, context->cr3); + +cpu_x86_load_seg_cache ( + env,R_CS , context->code_selector, + context->code_base, context->code_limit, +FLAGS_TO_SEGCACHE (context->code_attributes)); +cpu_x86_load_seg_cache ( + env,R_DS , context->data_selector, + context->data_base, context->data_limit, +FLAGS_TO_SEGCACHE (context->data_attributes)); +cpu_x86_load_seg_cache ( + env,R_ES , context->data_selector, + context->data_base, context->data_limit, +FLAGS_TO_SEGCACHE (context->data_attributes)); +cpu_x86_load_seg_cache ( + env,R_FS , context->data_selector, + context->data_base, context->data_limit, +FLAGS_TO_SEGCACHE (context->data_attributes)); +cpu_x86_load_seg_cache ( + env,R_GS , context->data_selector, + context->data_base, context->data_limit, +FLAGS_TO_SEGCACHE (context->data_attributes)); +cpu_x86_load_seg_cache ( + env,R_SS , context->data_selector, + context->data_base, context->data_limit, +FLAGS_TO_SEGCACHE (context->data_attributes)); + + env->gdt.base = context->gdtr_base; + env->gdt.limit = context->gdtr_limit; + env->idt.base = context->idtr_base; + env->idt.limit = context->idtr_limit; + + env->regs[R_EAX ] = context->rax; + env->regs[R_ECX ] = context->rcx; + env->regs[R_EDX ] = context->rdx; + env->regs[R_EBX ] = context->rbx; + env->regs[R_ESP ] = context->rsp; + env->regs[R_EBP ] = context->rbp; + env->regs[R_ESI ] = context->rsi; + env->regs[R_EDI ] = context->rdi; +#ifdef TARGET_X86_64 + env->regs[R_R8 ] = context->r8; + env->regs[R_R9 ] = context->r9; + env->regs[R_R10 ] = context->r10; + env->regs[R_R11 ] = context->r11; + env->regs[R_R12 ] = context->r12; + env->regs[R_R13 ] = context->r13; + env->regs[R_R14 ] = context->r14; + env->regs[R_R15 ] = context->r15; +#endif + env->eip = context->rip; + env->eflags = context->rflags; +} +/* * convert e820 table into igvm memory map */ @@ -44,3 +149,31 @@ int qigvm_x86_get_mem_map_entry(int index, }return 0 ; } + +/* +* set initial cpu context +*/ +static struct IgvmNativeVpContextX64 *bsp_context; + +int qigvm_x86_set_vp_context (void *data,int index,Error **errp) +{ +if (index !=0 ) { +error_setg (errp,"context can be set for BSP only" ); +return -1 ; + } + +if (bsp_context ==NULL ) { + bsp_context = g_new0(struct IgvmNativeVpContextX64, 1); + } +memcpy (bsp_context, data,sizeof (struct IgvmNativeVpContextX64 )); +return 0 ; +} + +void qigvm_x86_bsp_reset (CPUX86State *env) +{ +if (bsp_context ==NULL ) { +return ; + } + +qigvm_x86_load_context (bsp_context, env); +}Signature · 1 line
2.51.0
Re: [PATCH v3 3/5] igvm: add support for initial register state load in native mode
Hi,
Quoted 7 lines
backends/igvm.c static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data, · line 455
Quoted 4 lines
backends/igvm.c +4
-0+error_setg ( + errp, +"A VP context is present in the IGVM file but is not supported " +"by the current system." );It is pre-existing, but should we avoid splitting error messages to simplify searching for them in the code?
checkpatch.pl throws an error about a long line if I drop the split.
take care,
Gerd
Re: [PATCH v3 3/5] igvm: add support for initial register state load in native mode
In reply to Stefano GarzarellaHi,
Quoted 3 lines
Quoted 1 line
+struct IgvmNativeVpContextX64 {
Do you know why this is not exposed by igvm headers?
No idea. Given this is part of the file format it is highly unlikely to ever change, so having our own copy shouldn't be much of a maintenance problem.
take care,
Gerd
PATCH v3 4/5 igvm: track memory regions created
In reply to Gerd HoffmannKeep a linked list of the memory regions created by igvm.
--- backends/igvm.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
backends/igvm.c +14 -6
@@ -28,6 +28,11 @@ typedef struct QIgvmParameterData {uint32_t index; } QIgvmParameterData; +typedef struct QIgvmMemoryRegion { +QTAILQ_ENTRY (QIgvmMemoryRegion) next; +MemoryRegion mr; +}QIgvmMemoryRegion ; +/* * Some directives are specific to particular confidential computing platforms. * Define required types for each of those platforms here.
@@ -73,6 +78,7 @@ typedef struct QIgvm {uint32_t compatibility_mask;unsigned current_header_index; QTAILQ_HEAD(, QIgvmParameterData) parameter_data; + QTAILQ_HEAD(, QIgvmMemoryRegion) memory_regions;IgvmPlatformType platform_type;/*
@@ -185,7 +191,7 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size, int region_identifier, Error **errp) {ERRP_GUARD (); -MemoryRegion *igvm_pages =NULL ; +QIgvmMemoryRegion *pages =NULL ;Int128 gpa_region_size;MemoryRegionSection mrs =memory_region_find (get_system_memory (), addr, size);
@@ -219,20 +225,21 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,*/ g_autofree char *region_name =g_strdup_printf ("igvm.%X" , region_identifier); - igvm_pages =g_new0 (MemoryRegion,1 ); + pages =g_new0 (QIgvmMemoryRegion,1 );if (ctx->cgs && ctx->cgs->require_guest_memfd) { -if (!memory_region_init_ram_guest_memfd (igvm_pages,NULL , +if (!memory_region_init_ram_guest_memfd (&pages->mr,NULL , region_name, size, errp)) {return NULL ; } }else { -if (!memory_region_init_ram (igvm_pages,NULL , region_name, size, +if (!memory_region_init_ram (&pages->mr,NULL , region_name, size, errp)) {return NULL ; } } -memory_region_add_subregion (get_system_memory (), addr, igvm_pages); -return memory_region_get_ram_ptr (igvm_pages); +memory_region_add_subregion (get_system_memory (), addr, &pages->mr); +QTAILQ_INSERT_TAIL (&ctx->memory_regions, pages, next); +return memory_region_get_ram_ptr (&pages->mr); } }
@@ -928,6 +935,7 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, }QTAILQ_INIT (&ctx.parameter_data); +QTAILQ_INIT (&ctx.memory_regions); for (ctx.current_header_index = 0; ctx.current_header_index < (unsigned)header_count;
Signature · 1 line
2.51.0
Re: [PATCH v3 4/5] igvm: track memory regions created
Quoted 7 lines · Gerd Hoffmann
Keep a linked list of the memory regions created by igvm.
Signed-off-by Gerd Hoffmann <[email protected]>
Quoted 75 lines
---
backends/igvm.c| 20 ++++++++++++++------1 file changed, 14 insertions(+), 6 deletions(-)backends/igvm.c +14
-6@@ -28,6 +28,11 @@ typedef struct QIgvmParameterData {uint32_t index; } QIgvmParameterData; +typedef struct QIgvmMemoryRegion { +QTAILQ_ENTRY (QIgvmMemoryRegion) next; +MemoryRegion mr; +}QIgvmMemoryRegion ; +/* * Some directives are specific to particular confidential computing platforms. * Define required types for each of those platforms here. @@ -73,6 +78,7 @@ typedef struct QIgvm {uint32_t compatibility_mask;unsigned current_header_index; QTAILQ_HEAD(, QIgvmParameterData) parameter_data; + QTAILQ_HEAD(, QIgvmMemoryRegion) memory_regions;IgvmPlatformType platform_type;/* @@ -185,7 +191,7 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size, int region_identifier, Error **errp) {ERRP_GUARD (); -MemoryRegion *igvm_pages =NULL ; +QIgvmMemoryRegion *pages =NULL ;Int128 gpa_region_size;MemoryRegionSection mrs =memory_region_find (get_system_memory (), addr, size);@@ -219,20 +225,21 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,*/ g_autofree char *region_name =g_strdup_printf ("igvm.%X" , region_identifier); - igvm_pages =g_new0 (MemoryRegion,1 ); + pages =g_new0 (QIgvmMemoryRegion,1 );if (ctx->cgs && ctx->cgs->require_guest_memfd) { -if (!memory_region_init_ram_guest_memfd (igvm_pages,NULL , +if (!memory_region_init_ram_guest_memfd (&pages->mr,NULL , region_name, size, errp)) {return NULL ; } }else { -if (!memory_region_init_ram (igvm_pages,NULL , region_name, size, +if (!memory_region_init_ram (&pages->mr,NULL , region_name, size, errp)) {return NULL ; } } -memory_region_add_subregion (get_system_memory (), addr, igvm_pages); -return memory_region_get_ram_ptr (igvm_pages); +memory_region_add_subregion (get_system_memory (), addr, &pages->mr); +QTAILQ_INSERT_TAIL (&ctx->memory_regions, pages, next); +return memory_region_get_ram_ptr (&pages->mr); } }@@ -928,6 +935,7 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, }QTAILQ_INIT (&ctx.parameter_data); +QTAILQ_INIT (&ctx.memory_regions); for (ctx.current_header_index = 0; ctx.current_header_index < (unsigned)header_count;Signature · 1 line
2.51.0
Re: [PATCH v3 4/5] igvm: track memory regions created
In reply to Gerd HoffmannQuoted 1 line · Gerd Hoffmann
Keep a linked list of the memory regions created by igvm.
Sorry, my knowledge of MemoryRegions is limited, but why do we need to do this if we never access the list? To keep references to regions?
Thanks,
Stefano
Quoted 77 lines
Signed-off-by Gerd Hoffmann <[email protected]>---
backends/igvm.c| 20 ++++++++++++++------1 file changed, 14 insertions(+), 6 deletions(-)backends/igvm.c +14
-6@@ -28,6 +28,11 @@ typedef struct QIgvmParameterData {uint32_t index; } QIgvmParameterData; +typedef struct QIgvmMemoryRegion { +QTAILQ_ENTRY (QIgvmMemoryRegion) next; +MemoryRegion mr; +}QIgvmMemoryRegion ; +/* * Some directives are specific to particular confidential computing platforms. * Define required types for each of those platforms here. @@ -73,6 +78,7 @@ typedef struct QIgvm {uint32_t compatibility_mask;unsigned current_header_index; QTAILQ_HEAD(, QIgvmParameterData) parameter_data; + QTAILQ_HEAD(, QIgvmMemoryRegion) memory_regions;IgvmPlatformType platform_type;/* @@ -185,7 +191,7 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size, int region_identifier, Error **errp) {ERRP_GUARD (); -MemoryRegion *igvm_pages =NULL ; +QIgvmMemoryRegion *pages =NULL ;Int128 gpa_region_size;MemoryRegionSection mrs =memory_region_find (get_system_memory (), addr, size);@@ -219,20 +225,21 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,*/ g_autofree char *region_name =g_strdup_printf ("igvm.%X" , region_identifier); - igvm_pages =g_new0 (MemoryRegion,1 ); + pages =g_new0 (QIgvmMemoryRegion,1 );if (ctx->cgs && ctx->cgs->require_guest_memfd) { -if (!memory_region_init_ram_guest_memfd (igvm_pages,NULL , +if (!memory_region_init_ram_guest_memfd (&pages->mr,NULL , region_name, size, errp)) {return NULL ; } }else { -if (!memory_region_init_ram (igvm_pages,NULL , region_name, size, +if (!memory_region_init_ram (&pages->mr,NULL , region_name, size, errp)) {return NULL ; } } -memory_region_add_subregion (get_system_memory (), addr, igvm_pages); -return memory_region_get_ram_ptr (igvm_pages); +memory_region_add_subregion (get_system_memory (), addr, &pages->mr); +QTAILQ_INSERT_TAIL (&ctx->memory_regions, pages, next); +return memory_region_get_ram_ptr (&pages->mr); } }@@ -928,6 +935,7 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestSupport *cgs, }QTAILQ_INIT (&ctx.parameter_data); +QTAILQ_INIT (&ctx.memory_regions); for (ctx.current_header_index = 0; ctx.current_header_index < (unsigned)header_count;Signature · 1 line
2.51.0
Re: [PATCH v3 4/5] igvm: track memory regions created
Quoted 6 lines · Stefano Garzarella
Quoted 1 line · Gerd Hoffmann
Keep a linked list of the memory regions created by igvm.
Sorry, my knowledge of MemoryRegions is limited, but why do we need to do this if we never access the list?
To keep references to regions?
Keep track of the things we have created, so we can clean them up properly. Which is indeed not needed in this patch, but we will probably need that in the future for the bring-your-own-firmware project (aka reboot guest with new IGVM image).
take care,
Gerd
Re: [PATCH v3 4/5] igvm: track memory regions created
Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines · Stefano Garzarella
Quoted 1 line · Gerd Hoffmann
Keep a linked list of the memory regions created by igvm.
Quoted 8 lines
Quoted 3 lines
Sorry, my knowledge of MemoryRegions is limited, but why do we need to do this if we never access the list?
To keep references to regions?Keep track of the things we have created, so we can clean them up properly. Which is indeed not needed in this patch, but we will probably need that in the future for the bring-your-own-firmware project (aka reboot guest with new IGVM image).
I see, so perhaps it makes sense to add this to the description, or postpone the patch until it is needed (not a strong opinion, but I'm not a fan of having code that isn't used).
Thanks,
Stefano
PATCH v3 5/5 igvm: add MAINTAINERS entry
In reply to Gerd HoffmannAdd Roy (being the original author) as maintainer. Add myself as reviewer. Status to be decided.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -3893,6 +3893,15 @@ F: roms/edk2-* F: tests/data/uefi-boot-images/ F: tests/uefi-test-tools/ +IGVM Firmware +M: Roy Hopkins <[email protected]> +R: Gerd Hoffmann <[email protected]> +S: TBD +F: backends/igvm*.c +F: include/system/igvm*.h +F: stubs/igvm.c +F: target/i386/igvm.c + VT-d Emulation M: Michael S. Tsirkin <[email protected]> R: Jason Wang <[email protected]>
Signature · 1 line
2.51.0
Re: [PATCH v3 5/5] igvm: add MAINTAINERS entry
Quoted 20 lines · Gerd Hoffmann
Add Roy (being the original author) as maintainer. Add myself as reviewer. Status to be decided.
Signed-off-by Gerd Hoffmann <[email protected]>---
MAINTAINERS| 9 +++++++++1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -3893,6 +3893,15 @@ F: roms/edk2-*F: tests/data/uefi-boot-images/
F: tests/uefi-test-tools/
MAINTAINERS F: roms/edk2-* · line 3898
Quoted 3 lines
MAINTAINERS +3
-0+IGVM Firmware +M: Roy Hopkins <[email protected]> +R: Gerd Hoffmann <[email protected]>
I would also like to add myself as a reviewer as well.
R: Ani Sinha <[email protected]>
Quoted 12 lines
MAINTAINERS +6
-0+S: TBD +F: backends/igvm*.c +F: include/system/igvm*.h +F: stubs/igvm.c +F: target/i386/igvm.c +VT-d Emulation
M: Michael S. Tsirkin <[email protected]>
R: Jason Wang <[email protected]>Signature · 1 line
2.51.0
Re: [PATCH v3 5/5] igvm: add MAINTAINERS entry
In reply to Gerd HoffmannQuoted 13 lines · Gerd Hoffmann
Add Roy (being the original author) as maintainer. Add myself as reviewer. Status to be decided.
Signed-off-by Gerd Hoffmann <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0
MAINTAINERS F: roms/edk2-* · line 3899
Quoted 7 lines
MAINTAINERS +4
-0@@ -3893,6 +3893,15 @@ F: roms/edk2-* F: tests/data/uefi-boot-images/ F: tests/uefi-test-tools/ +IGVM Firmware +M: Roy Hopkins <[email protected]> +R: Gerd Hoffmann <[email protected]> +S: TBD
If not Supported, then Maintained?
MAINTAINERS F: roms/edk2-* · line 3903
Quoted 4 lines
MAINTAINERS +4
-0+F: backends/igvm*.c +F: include/system/igvm*.h +F: stubs/igvm.c +F: target/i386/igvm.c
Re: [PATCH v3 5/5] igvm: add MAINTAINERS entry
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Gerd Hoffmann
Add Roy (being the original author) as maintainer. Add myself as reviewer. Status to be decided.
Signed-off-by Gerd Hoffmann <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
Quoted 13 lines
MAINTAINERS F: roms/edk2-* · line 3898
Quoted 11 lines
MAINTAINERS +4
-0@@ -3893,6 +3893,15 @@ F: roms/edk2-* F: tests/data/uefi-boot-images/ F: tests/uefi-test-tools/ +IGVM Firmware +M: Roy Hopkins <[email protected]> +R: Gerd Hoffmann <[email protected]> +S: TBDIf not Supported, then Maintained?
I was hoping for Roy (as original igvm author) offers an opinion on this. Not sure he is still working on igvm though given that there wasn't a single reply from him so far. Should he moved on to other things it doesn't make much sense to add him as maintainer ...
Roy?
take care,
Gerd