igvm: store IgvmCfg pointer in QIgvm
Store a pointer to IgvmCfg instead of only IgvmFile in QIgvm. Allows to store additional state in the (persistent) IgvmCfg struct. Reviewed-by: Ani Sinha <anisinha@redhat.com> Reviewed-by: Alexander Graf <graf@amazon.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-ID: <20260817142010.80693-2-anisinha@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Gerd Hoffmann committed
Aug 17, 2026 at 19:49 UTC
acce06adc0651fe5a19596ac5733142031343c60
2 files changed
+34
-25
backends/igvm.c
+33
-24
@@ -178,7 +178,8 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
178
if (handlers[handler].type != type) {
179
continue;
180
}
181
- header_handle = igvm_get_header(ctx->file, handlers[handler].section,
181
+ header_handle = igvm_get_header(ctx->cfg->file,
182
+ handlers[handler].section,
183
ctx->current_header_index);
184
if (header_handle < 0) {
185
error_setg(
@@ -187,7 +188,7 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
188
(int)header_handle);
189
return -1;
190
}
190
- header_data = igvm_get_buffer(ctx->file, header_handle);
191
+ header_data = igvm_get_buffer(ctx->cfg->file, header_handle);
192
if (header_data != NULL) {
193
header_data += sizeof(IGVM_VHS_VARIABLE_HEADER);
194
result = handlers[handler].handler(ctx, header_data, errp);
@@ -198,7 +199,7 @@ static int qigvm_handler(QIgvm *ctx, IgvmVariableHeaderType raw_type,
199
header_handle, type);
200
result = -1;
201
}
201
- igvm_free_buffer(ctx->file, header_handle);
202
+ igvm_free_buffer(ctx->cfg->file, header_handle);
203
return result;
204
}
205
@@ -344,7 +345,8 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
345
346
for (page_index = 0; page_index < page_count; page_index++) {
347
data_handle = igvm_get_header_data(
347
- ctx->file, IGVM_HEADER_SECTION_DIRECTIVE, page_index + start_index);
348
+ ctx->cfg->file, IGVM_HEADER_SECTION_DIRECTIVE,
349
+ page_index + start_index);
350
if (data_handle == IGVMAPI_NO_DATA) {
351
/* No data indicates a zero page */
352
memset(®ion[page_index * page_size], 0, page_size);
@@ -357,7 +359,7 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
359
return -1;
360
} else {
361
zero = false;
360
- data_size = igvm_get_buffer_size(ctx->file, data_handle);
362
+ data_size = igvm_get_buffer_size(ctx->cfg->file, data_handle);
363
if (data_size < page_size) {
364
memset(®ion[page_index * page_size], 0, page_size);
365
} else if (data_size > page_size) {
@@ -367,14 +369,14 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
369
page_index + start_index);
370
return -1;
371
}
370
- data = igvm_get_buffer(ctx->file, data_handle);
372
+ data = igvm_get_buffer(ctx->cfg->file, data_handle);
373
if (data == NULL) {
374
error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
373
- igvm_free_buffer(ctx->file, data_handle);
375
+ igvm_free_buffer(ctx->cfg->file, data_handle);
376
return -1;
377
}
378
memcpy(®ion[page_index * page_size], data, data_size);
377
- igvm_free_buffer(ctx->file, data_handle);
379
+ igvm_free_buffer(ctx->cfg->file, data_handle);
380
}
381
}
382
@@ -411,7 +413,8 @@ static int qigvm_process_mem_page(QIgvm *ctx,
413
ctx->region_start = page_data->gpa;
414
ctx->region_start_index = ctx->current_header_index;
415
} else {
414
- if (!qigvm_page_attrs_equal(ctx->file, ctx->current_header_index,
416
+ if (!qigvm_page_attrs_equal(ctx->cfg->file,
417
+ ctx->current_header_index,
418
page_data,
419
&ctx->region_prev_page_data) ||
420
((ctx->region_prev_page_data.gpa +
@@ -474,7 +477,8 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
477
return 0;
478
}
479
477
- data_handle = igvm_get_header_data(ctx->file, IGVM_HEADER_SECTION_DIRECTIVE,
480
+ data_handle = igvm_get_header_data(ctx->cfg->file,
481
+ IGVM_HEADER_SECTION_DIRECTIVE,
482
ctx->current_header_index);
483
if (data_handle < 0) {
484
error_setg(errp, "Invalid VP context in IGVM file. Error code: %X",
@@ -482,7 +486,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
486
return -1;
487
}
488
485
- data = (uint8_t *)igvm_get_buffer(ctx->file, data_handle);
489
+ data = (uint8_t *)igvm_get_buffer(ctx->cfg->file, data_handle);
490
if (data == NULL) {
491
error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
492
result = -1;
@@ -491,7 +495,8 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
495
496
if (ctx->machine_state->cgs) {
497
result = ctx->cgsc->set_guest_state(
494
- vp_context->gpa, data, igvm_get_buffer_size(ctx->file, data_handle),
498
+ vp_context->gpa, data,
499
+ igvm_get_buffer_size(ctx->cfg->file, data_handle),
500
CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp);
501
} else if (target_arch() == SYS_EMU_TARGET_X86_64) {
502
result = qigvm_x86_set_vp_context(data, vp_context->vp_index, errp);
@@ -504,7 +509,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
509
}
510
511
exit:
507
- igvm_free_buffer(ctx->file, data_handle);
512
+ igvm_free_buffer(ctx->cfg->file, data_handle);
513
if (result < 0) {
514
return result;
515
}
@@ -863,7 +868,8 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
868
uint32_t compatibility_mask_sev_snp = 0;
869
uint32_t compatibility_mask = 0;
870
866
- header_count = igvm_header_count(ctx->file, IGVM_HEADER_SECTION_PLATFORM);
871
+ header_count = igvm_header_count(ctx->cfg->file,
872
+ IGVM_HEADER_SECTION_PLATFORM);
873
if (header_count < 0) {
874
error_setg(errp,
875
"Invalid platform header count in IGVM file. Error code: %X",
@@ -874,11 +880,11 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
880
for (header_index = 0; header_index < (unsigned)header_count;
881
header_index++) {
882
IgvmVariableHeaderType typ = igvm_get_header_type(
877
- ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
883
+ ctx->cfg->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
884
typ = igvm_vht_type(typ);
885
if (typ == IGVM_VHT_SUPPORTED_PLATFORM) {
886
header_handle = igvm_get_header(
881
- ctx->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
887
+ ctx->cfg->file, IGVM_HEADER_SECTION_PLATFORM, header_index);
888
if (header_handle < 0) {
889
error_setg(errp,
890
"Invalid platform header in IGVM file. "
@@ -887,11 +893,11 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
893
return -1;
894
}
895
platform =
890
- (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->file,
896
+ (IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->cfg->file,
897
header_handle));
898
if (platform == NULL) {
899
error_setg(errp, "IGVM: No buffer for handle %d", header_handle);
894
- igvm_free_buffer(ctx->file, header_handle);
900
+ igvm_free_buffer(ctx->cfg->file, header_handle);
901
return -1;
902
}
903
@@ -922,7 +928,7 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
928
} else if (platform->platform_type == IGVM_PLATFORM_TYPE_NATIVE) {
929
compatibility_mask = platform->compatibility_mask;
930
}
925
- igvm_free_buffer(ctx->file, header_handle);
931
+ igvm_free_buffer(ctx->cfg->file, header_handle);
932
}
933
}
934
/* Choose the strongest supported isolation technology */
@@ -999,7 +1005,7 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
1005
error_setg(errp, "No IGVM file loaded.");
1006
return -1;
1007
}
1002
- ctx.file = cfg->file;
1008
+ ctx.cfg = cfg;
1009
trace_igvm_process_file(cfg->file, onlyVpContext);
1010
1011
ctx.machine_state = machine_state;
@@ -1021,7 +1027,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
1027
goto cleanup;
1028
}
1029
1024
- header_count = igvm_header_count(ctx.file, IGVM_HEADER_SECTION_DIRECTIVE);
1030
+ header_count = igvm_header_count(ctx.cfg->file,
1031
+ IGVM_HEADER_SECTION_DIRECTIVE);
1032
if (header_count <= 0) {
1033
error_setg(
1034
errp, "Invalid directive header count in IGVM file. Error code: %X",
@@ -1035,7 +1042,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
1042
ctx.current_header_index < (unsigned)header_count;
1043
ctx.current_header_index++) {
1044
IgvmVariableHeaderType raw_type = igvm_get_header_type(
1038
- ctx.file, IGVM_HEADER_SECTION_DIRECTIVE, ctx.current_header_index);
1045
+ ctx.cfg->file, IGVM_HEADER_SECTION_DIRECTIVE,
1046
+ ctx.current_header_index);
1047
if (!onlyVpContext || igvm_vht_type(raw_type) == IGVM_VHT_VP_CONTEXT) {
1048
if (qigvm_handler(&ctx, raw_type, errp) < 0) {
1049
goto cleanup_parameters;
@@ -1053,7 +1061,7 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
1061
}
1062
1063
header_count =
1056
- igvm_header_count(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION);
1064
+ igvm_header_count(ctx.cfg->file, IGVM_HEADER_SECTION_INITIALIZATION);
1065
if (header_count < 0) {
1066
error_setg(
1067
errp,
@@ -1066,7 +1074,8 @@ int qigvm_process_file(IgvmCfg *cfg, MachineState *machine_state,
1074
ctx.current_header_index < (unsigned)header_count;
1075
ctx.current_header_index++) {
1076
IgvmVariableHeaderType type =
1069
- igvm_get_header_type(ctx.file, IGVM_HEADER_SECTION_INITIALIZATION,
1077
+ igvm_get_header_type(ctx.cfg->file,
1078
+ IGVM_HEADER_SECTION_INITIALIZATION,
1079
ctx.current_header_index);
1080
if (qigvm_handler(&ctx, type, errp) < 0) {
1081
goto cleanup_parameters;
include/system/igvm-internal.h
+1
-1
@@ -43,7 +43,7 @@ typedef struct QIgvmParameterData {
43
* file.
44
*/
45
struct QIgvm {
46
- IgvmHandle file;
46
+ IgvmCfg *cfg;
47
MachineState *machine_state;
48
ConfidentialGuestSupportClass *cgsc;
49
uint32_t compatibility_mask;