Re: [PATCH v3 2/9] igvm: track memory regions

Ani Sinha <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>

> On 31 Jul 2026, at 3:28 PM, Alexander Graf <[email protected]> wrote:
> 
> 
> On 30.07.26 09:12, Ani Sinha wrote:
>> From: Gerd Hoffmann <[email protected]>
>> 
>> Memory regions added by the current IGVM needs to be tracked so that they can be
>> freed when a new IGVM is loaded.
>> 
>> Reviewed-by: Ani Sinha <[email protected]>
>> Signed-off-by: Gerd Hoffmann <[email protected]>
>> ---
>>  backends/igvm-cfg.c            |  1 +
>>  backends/igvm.c                | 20 ++++++++++++--------
>>  include/system/igvm-internal.h |  6 ++++++
>>  3 files changed, 19 insertions(+), 8 deletions(-)
>> 
>> diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
>> index e1f09855f6..38438a7b1e 100644
>> --- a/backends/igvm-cfg.c
>> +++ b/backends/igvm-cfg.c
>> @@ -65,6 +65,7 @@ static void igvm_complete(UserCreatable *uc, Error **errp)
>>      IgvmCfg *igvm = IGVM_CFG(uc);
>>        igvm->file = qigvm_file_init(igvm->filename, errp);
>> +    QTAILQ_INIT(&igvm->memory_regions);
>>  }
>>    OBJECT_DEFINE_TYPE_WITH_INTERFACES(IgvmCfg, igvm_cfg, IGVM_CFG, OBJECT,
>> diff --git a/backends/igvm.c b/backends/igvm.c
>> index 534032fed8..9e7c90d386 100644
>> --- a/backends/igvm.c
>> +++ b/backends/igvm.c
>> @@ -220,7 +220,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;
>> +    IgvmMemoryRegion *imr = NULL;
>>      Int128 gpa_region_size;
>>      MemoryRegionSection mrs =
>>          memory_region_find(get_system_memory(), addr, size);
>> @@ -254,23 +254,27 @@ 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);
>> +        imr = g_new0(IgvmMemoryRegion, 1);
>> +        imr->mr = g_new0(MemoryRegion, 1);
>>          if (ctx->machine_state->cgs &&
>>              ctx->machine_state->cgs->require_guest_memfd) {
>> -            if (!memory_region_init_ram_guest_memfd(igvm_pages, NULL,
>> +            if (!memory_region_init_ram_guest_memfd(imr->mr, NULL,
> 
> 
> Please make sure to track them with owner set to OBJECT(ctx->machine_state).

This will not work as the owner will have to be of TYPE_DEVICE not of TYPE_MACHINE.

> Without owner, reference counting is disabled and we end up leaking memory regions on cleanup you introduce in patch 3 later.
> 
> 
> Alex
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.