From nobody Sun Sep 28 15:26:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758884566; cv=none; d=zohomail.com; s=zohoarc; b=Sel5P77QcPgzz7njnnKqL98Sbsq5MT//FgBfu9NDxgoj7ptEpdrWBrq91fDvA2GdH/cd4ipZUntWJkEonGmYoREzemDre1IrNoPYD/jUEc8+M78PNpwA36+jv5EnqO71Uiq9EhASku2kTVjiCK0h3R0nxGSfoKs5DfSMJPXV7JE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758884566; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HoLLtDqNGVTdiRisEdK/jURVkbxy+tmYmSz13Vku/6Y=; b=OiIZ8JGG10sX4p/a9D+Z3vgve5Yvl3eiYuAp9to788eyJXUUGwbAu2P0SNKnvAbLlBTr4ArKELanJ7Agov2gQ7MVjGEmJk/4NGjBHdVhWPGA6bScCD4HEWNnHMcWthWYst3l+wxVwtrk/vgDr7qV4AH/TzAfmOmxvcBo4IKAtyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17588845661337.2881818448937565; Fri, 26 Sep 2025 04:02:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v26BT-0007Cr-Nv; Fri, 26 Sep 2025 07:00:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26BO-0007CY-L9 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26B8-0007RU-N3 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:09 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-tN9TRIwTNLGwyCiLetaHCA-1; Fri, 26 Sep 2025 06:59:31 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3C47D195608C; Fri, 26 Sep 2025 10:59:30 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9929119560A2; Fri, 26 Sep 2025 10:59:29 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 001FE180060A; Fri, 26 Sep 2025 12:59:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758884372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HoLLtDqNGVTdiRisEdK/jURVkbxy+tmYmSz13Vku/6Y=; b=erWDHxbtyQxhf9AO6fBXrcaw7uqiUuZzTO1zAuGlU8ZEOBkzJZwLxpAOto+6r5FAPk9XC0 fBYCXswFIagatbqRbf4kPjpq7TPnfnJKLc+X+KZ0j57PcmgwYHXikS60OwvEh2Y/qS1hB0 9i9CSPZ+2gbvMFItnbrs64/iRpd0rX4= X-MC-Unique: tN9TRIwTNLGwyCiLetaHCA-1 X-Mimecast-MFC-AGG-ID: tN9TRIwTNLGwyCiLetaHCA_1758884370 From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Zhao Liu , Paolo Bonzini , Gerd Hoffmann Subject: [PATCH v2 1/4] igvm: move igvm.h file to include/system Date: Fri, 26 Sep 2025 12:59:23 +0200 Message-ID: <20250926105926.121890-2-kraxel@redhat.com> In-Reply-To: <20250926105926.121890-1-kraxel@redhat.com> References: <20250926105926.121890-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.446, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758884568458116600 Content-Type: text/plain; charset="utf-8" Prepare for arch-specific igvm code being added to the code base. Signed-off-by: Gerd Hoffmann --- {backends =3D> include/system}/igvm.h | 0 backends/igvm-cfg.c | 2 +- backends/igvm.c | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename {backends =3D> include/system}/igvm.h (100%) diff --git a/backends/igvm.h b/include/system/igvm.h similarity index 100% rename from backends/igvm.h rename to include/system/igvm.h diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c index 45df63e06c1a..d00acf351249 100644 --- a/backends/igvm-cfg.c +++ b/backends/igvm-cfg.c @@ -12,7 +12,7 @@ #include "qemu/osdep.h" =20 #include "system/igvm-cfg.h" -#include "igvm.h" +#include "system/igvm.h" #include "qom/object_interfaces.h" =20 static char *get_igvm(Object *obj, Error **errp) diff --git a/backends/igvm.c b/backends/igvm.c index 9ad41582ee5e..723d45b755a0 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -11,8 +11,8 @@ =20 #include "qemu/osdep.h" =20 -#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" --=20 2.51.0 From nobody Sun Sep 28 15:26:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758884574; cv=none; d=zohomail.com; s=zohoarc; b=CbtQZGF6xod/T84W1RApgKUshKOMnCB4jD2b82YAgg+Ca26vPqjsyYuReIiGjxTol4czVHrMe25mtQ1NYWPyrXZosX7WZdFKOgbXj/QNbHlySlNOdH33EF0h2IqRDnlCRjZSlv2XPTpQYmsMCASdD7nIdIRhDOY8VR6y4tzecRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758884574; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K/gtmZh0zr1s60tL23O40RB0ztD5L1nJW5OpDcx0GCc=; b=ROYsMZf17ubyAfFAL0n5t5TgMw6giNjkQCYxPB7dMwZoIPe9nJYQVWZVrkxS2tO097oNN3ZQgzpxp2oaP+egsHxEmlVONafUdezq1phhBgjZwDslQxk0vrWGjZiA2YwT/kyo9m9PJKHmoWB8PeDa1SX8+Pb5FcJrt0DQ4WMWrjw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758884574006312.6653341331498; Fri, 26 Sep 2025 04:02:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v26BZ-0007II-8S; Fri, 26 Sep 2025 07:00:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26BS-0007Dp-2b for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26B9-0007Ro-Pz for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:13 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-PiKwRgdjMy-tGzv3BpK6Tw-1; Fri, 26 Sep 2025 06:59:34 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 261E2180057A; Fri, 26 Sep 2025 10:59:33 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.32.43]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 76B70180035E; Fri, 26 Sep 2025 10:59:32 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 221D9180060B; Fri, 26 Sep 2025 12:59:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758884375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K/gtmZh0zr1s60tL23O40RB0ztD5L1nJW5OpDcx0GCc=; b=MwiDcFaJi9Ln/65evOVUIT1Gmrc2chNmeIZ5LgiqM5oOGGkJXOR6yNA+mb23XQ7vK+xIvz 7vuYdLjOR2MxJtCXy42yPx+iWRwbUzJcaiC/2nHkrfH+yq7w7icr2DaPy6kG+fVu/kB40Q tUYnjq18DbScKT1xwurmgT/hO0MdevY= X-MC-Unique: PiKwRgdjMy-tGzv3BpK6Tw-1 X-Mimecast-MFC-AGG-ID: PiKwRgdjMy-tGzv3BpK6Tw_1758884373 From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Zhao Liu , Paolo Bonzini , Gerd Hoffmann Subject: [PATCH v2 2/4] igvm: add support for igvm memory map parameter in native mode Date: Fri, 26 Sep 2025 12:59:24 +0200 Message-ID: <20250926105926.121890-3-kraxel@redhat.com> In-Reply-To: <20250926105926.121890-1-kraxel@redhat.com> References: <20250926105926.121890-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.446, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758884574649116600 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Gerd Hoffmann --- include/system/igvm.h | 5 +++++ backends/igvm.c | 24 +++++++++++++++++---- stubs/igvm.c | 21 +++++++++++++++++++ target/i386/igvm.c | 46 +++++++++++++++++++++++++++++++++++++++++ stubs/meson.build | 1 + target/i386/meson.build | 3 +++ 6 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 stubs/igvm.c create mode 100644 target/i386/igvm.c diff --git a/include/system/igvm.h b/include/system/igvm.h index a4abab043a1f..3f72a40b8897 100644 --- a/include/system/igvm.h +++ b/include/system/igvm.h @@ -19,4 +19,9 @@ int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs, bool onlyVpContext, Error **errp); =20 +/* x86 native */ +int qigvm_x86_get_mem_map_entry(int index, + ConfidentialGuestMemoryMapEntry *entry, + Error **errp); + #endif diff --git a/backends/igvm.c b/backends/igvm.c index 723d45b755a0..40b60f8cb48f 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" =20 #include "qapi/error.h" +#include "qemu/target-info.h" #include "system/igvm.h" #include "system/memory.h" #include "system/address-spaces.h" @@ -20,6 +21,12 @@ #include #include =20 +/* temporary stopgap until this lands in target-info.h */ +static bool target_x86_64(void) +{ + return strcmp(target_name(), "x86_64") =3D=3D 0; +} + typedef struct QIgvmParameterData { QTAILQ_ENTRY(QIgvmParameterData) next; uint8_t *data; @@ -543,6 +550,8 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const= uint8_t *header_data, Error **errp) { const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; + int (*get_mem_map_entry)(int index, ConfidentialGuestMemoryMapEntry *e= ntry, + Error **errp) =3D NULL; QIgvmParameterData *param_entry; int max_entry_count; int entry =3D 0; @@ -550,7 +559,15 @@ static int qigvm_directive_memory_map(QIgvm *ctx, cons= t uint8_t *header_data, ConfidentialGuestMemoryMapEntry cgmm_entry; int retval =3D 0; =20 - if (!ctx->cgs) { + if (ctx->cgs && ctx->cgsc->get_mem_map_entry) { + get_mem_map_entry =3D ctx->cgsc->get_mem_map_entry; + } + + if (!get_mem_map_entry && target_x86_64()) { + get_mem_map_entry =3D qigvm_x86_get_mem_map_entry; + } + + if (!get_mem_map_entry) { error_setg(errp, "IGVM file contains a memory map but this is not suppor= ted " "by the current system."); @@ -565,7 +582,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 =3D (IGVM_VHS_MEMORY_MAP_ENTRY *)param_entry->data; =20 - retval =3D ctx->cgsc->get_mem_map_entry(entry, &cgmm_entry, er= rp); + retval =3D get_mem_map_entry(entry, &cgmm_entry, errp); while (retval =3D=3D 0) { if (entry > max_entry_count) { error_setg( @@ -598,8 +615,7 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const= uint8_t *header_data, IGVM_MEMORY_MAP_ENTRY_TYPE_PLATFORM_RESERVED; break; } - retval =3D - ctx->cgsc->get_mem_map_entry(++entry, &cgmm_entry, err= p); + retval =3D get_mem_map_entry(++entry, &cgmm_entry, errp); } if (retval < 0) { return retval; diff --git a/stubs/igvm.c b/stubs/igvm.c new file mode 100644 index 000000000000..c32058eb2a6e --- /dev/null +++ b/stubs/igvm.c @@ -0,0 +1,21 @@ +/* + * QEMU IGVM, stubs + * + * Copyright (C) 2026 Red Hat + * + * Authors: + * Gerd Hoffmann + * + * 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; +} diff --git a/target/i386/igvm.c b/target/i386/igvm.c new file mode 100644 index 000000000000..2ed6cd052c79 --- /dev/null +++ b/target/i386/igvm.c @@ -0,0 +1,46 @@ +/* + * QEMU IGVM, support for native x86 guests + * + * Copyright (C) 2026 Red Hat + * + * Authors: + * Gerd Hoffmann + * + * 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 =3D e820_get_table(&table); + if ((index < 0) || (index >=3D num_entries)) { + return 1; + } + entry->gpa =3D table[index].address; + entry->size =3D table[index].length; + switch (table[index].type) { + case E820_RAM: + entry->type =3D CGS_MEM_RAM; + break; + case E820_RESERVED: + entry->type =3D CGS_MEM_RESERVED; + break; + default: + /* should not happen */ + error_setg(errp, "unknown e820 type"); + return -1; + } + return 0; +} diff --git a/stubs/meson.build b/stubs/meson.build index cef046e6854d..b362b2472373 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -73,6 +73,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')) diff --git a/target/i386/meson.build b/target/i386/meson.build index 092af34e2d85..da2d5d80792b 100644 --- a/target/i386/meson.build +++ b/target/i386/meson.build @@ -25,6 +25,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 =20 i386_user_ss =3D ss.source_set() =20 --=20 2.51.0 From nobody Sun Sep 28 15:26:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758884587; cv=none; d=zohomail.com; s=zohoarc; b=SElq5UkpAg4GuS+GwCOgadZg9glnWcfAPMPRiw3njj/0spodOBMwc3+VXhq8iRN+KQEavy45mbx8bg3v12mA+7SvWbqNQGsIVpID9ZIYHrHEbeKtoO0e+5ktHjWkNZEc+wAi6Gi80KRwjd5LEwwMLc/MBBSv3LRxZUVtE23au/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758884587; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oEwHc6uI4cPIYskqOSNik2lG7GKUuyULeM0TuwwPqSg=; b=NqXVUogqa2zKhd0oSrf8bS3fti0CeMBtaEegx8eEbJEwA6djCgvNm1MWmWyO/dK6eKo9+K8iihvt1TbxUAXHXArBD1EO3iFXWd7Q1+ADV1X9Y6mSTt9UKOw3aE6eDujnZawbBD0j+3DwUBxnb65MBkenNu3uTSsABIAfrqMyhp4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758884587578830.3975047301575; Fri, 26 Sep 2025 04:03:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v26BX-0007H7-6R; Fri, 26 Sep 2025 07:00:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26BP-0007Ck-I7 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26B5-0007Rl-3l for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:02 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672-DWPeK33dOMiuf6KZQ07u8w-1; Fri, 26 Sep 2025 06:59:34 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 254AC180048E; Fri, 26 Sep 2025 10:59:33 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.32.43]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 79F611800579; Fri, 26 Sep 2025 10:59:32 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3FF8C1800615; Fri, 26 Sep 2025 12:59:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758884375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oEwHc6uI4cPIYskqOSNik2lG7GKUuyULeM0TuwwPqSg=; b=YF3ZgfGJSTIPEaWYfBBqXC9KnhVqlcDIrJegIIgw4319pzfgF3u2MMp4uEgYMG5syYPlSR y5a73aCq1+zbp3WALpnSKzvSqq57t6kGbT57r0Yq/PR36Tn6mb65jgJSFoNBMJGNpSQLcK 88N3E6+RVubrnxVxsFvaBAC1G1e+4AQ= X-MC-Unique: DWPeK33dOMiuf6KZQ07u8w-1 X-Mimecast-MFC-AGG-ID: DWPeK33dOMiuf6KZQ07u8w_1758884373 From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Zhao Liu , Paolo Bonzini , Gerd Hoffmann Subject: [PATCH v2 3/4] igvm: add support for initial register state load in native mode Date: Fri, 26 Sep 2025 12:59:25 +0200 Message-ID: <20250926105926.121890-4-kraxel@redhat.com> In-Reply-To: <20250926105926.121890-1-kraxel@redhat.com> References: <20250926105926.121890-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.446, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758884588607116600 Content-Type: text/plain; charset="utf-8" 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 --- 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(-) diff --git a/include/system/igvm.h b/include/system/igvm.h index 3f72a40b8897..48ce20604259 100644 --- a/include/system/igvm.h +++ b/include/system/igvm.h @@ -23,5 +23,7 @@ int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSu= pport *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); =20 #endif diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e0be7a740685..5de0b3bd1553 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2845,6 +2845,9 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int = flags); =20 #endif =20 +/* igvm.c */ +void qigvm_x86_bsp_reset(CPUX86State *env); + /* cpu.c */ bool cpu_is_bsp(X86CPU *cpu); =20 diff --git a/backends/igvm.c b/backends/igvm.c index 40b60f8cb48f..47600c361db4 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -438,18 +438,6 @@ static int qigvm_directive_vp_context(QIgvm *ctx, cons= t uint8_t *header_data, return 0; } =20 - /* - * 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 =3D igvm_get_header_data(ctx->file, IGVM_HEADER_SECTION_DI= RECTIVE, ctx->current_header_index); if (data_handle < 0) { @@ -459,9 +447,21 @@ static int qigvm_directive_vp_context(QIgvm *ctx, cons= t uint8_t *header_data, } =20 data =3D (uint8_t *)igvm_get_buffer(ctx->file, data_handle); - result =3D 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 =3D ctx->cgsc->set_guest_state( + vp_context->gpa, data, igvm_get_buffer_size(ctx->file, data_ha= ndle), + CGS_PAGE_TYPE_VMSA, vp_context->vp_index, errp); + } else if (target_x86_64()) { + result =3D qigvm_x86_set_vp_context(data, vp_context->vp_index, er= rp); + } else { + error_setg( + errp, + "A VP context is present in the IGVM file but is not supported= " + "by the current system."); + result =3D -1; + } + igvm_free_buffer(ctx->file, data_handle); if (result < 0) { return result; diff --git a/stubs/igvm.c b/stubs/igvm.c index c32058eb2a6e..17cd1e903e35 100644 --- a/stubs/igvm.c +++ b/stubs/igvm.c @@ -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; +} diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6d85149e6e1b..f38651e0c8cf 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8730,6 +8730,10 @@ static void x86_cpu_reset_hold(Object *obj, ResetTyp= e type) =20 cs->halted =3D !cpu_is_bsp(cpu); =20 + if (cpu_is_bsp(cpu)) { + qigvm_x86_bsp_reset(env); + } + if (kvm_enabled()) { kvm_arch_reset_vcpu(cpu); } diff --git a/target/i386/igvm.c b/target/i386/igvm.c index 2ed6cd052c79..0921ec830508 100644 --- a/target/i386/igvm.c +++ b/target/i386/igvm.c @@ -11,9 +11,114 @@ =20 #include "qemu/osdep.h" =20 +#include "cpu.h" #include "hw/i386/e820_memory_layout.h" #include "system/igvm.h" =20 +struct IgvmNativeVpContextX64 { + 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 =3D context->gdtr_base; + env->gdt.limit =3D context->gdtr_limit; + env->idt.base =3D context->idtr_base; + env->idt.limit =3D context->idtr_limit; + + env->regs[R_EAX] =3D context->rax; + env->regs[R_ECX] =3D context->rcx; + env->regs[R_EDX] =3D context->rdx; + env->regs[R_EBX] =3D context->rbx; + env->regs[R_ESP] =3D context->rsp; + env->regs[R_EBP] =3D context->rbp; + env->regs[R_ESI] =3D context->rsi; + env->regs[R_EDI] =3D context->rdi; +#ifdef TARGET_X86_64 + env->regs[R_R8] =3D context->r8; + env->regs[R_R9] =3D context->r9; + env->regs[R_R10] =3D context->r10; + env->regs[R_R11] =3D context->r11; + env->regs[R_R12] =3D context->r12; + env->regs[R_R13] =3D context->r13; + env->regs[R_R14] =3D context->r14; + env->regs[R_R15] =3D context->r15; +#endif + env->eip =3D context->rip; + env->eflags =3D 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 !=3D 0) { + error_setg(errp, "context can be set for BSP only"); + return -1; + } + + if (bsp_context =3D=3D NULL) { + bsp_context =3D g_new0(struct IgvmNativeVpContextX64, 1); + } + memcpy(bsp_context, data, sizeof(struct IgvmNativeVpContextX64)); + return 0; +} + +void qigvm_x86_bsp_reset(CPUX86State *env) +{ + if (bsp_context =3D=3D NULL) { + return; + } + + qigvm_x86_load_context(bsp_context, env); +} --=20 2.51.0 From nobody Sun Sep 28 15:26:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758884561; cv=none; d=zohomail.com; s=zohoarc; b=mqUHh8p1YZKdtO5bdTDR/uB/J2x4OJZON714hupFyVyLSe76oqcM0uyoTtbeH0xu/nT6oedBpfdjQvd6+4MoKjIKcoHxItJXvoucVNnVZwz/4GTlRtnNzwTbQFHiobB+kFtKf8FC3rnslmx5XpGznHcR/88JX6z94QHz7LoqgEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758884561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FBEMiCFVj3xvS3M2nmY01HIfGjSvVC9LBpvAbZyiaFI=; b=OH7TOejZgMfGKY64e7jMBYjjSlUULYBnnAYccPKuOk5/XJzdzhXf75cBKjGBVynevfbozONPPXElFOrG5fsPDvfcJIMwjyfFQisVwkmSQQZbPX2JT6XF8OVn4zP03Q5m5T9CgIiFrOrJxo170/uxJsNSVa2MTxT24vJ6FM9/Jgk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758884561950783.9423777303517; Fri, 26 Sep 2025 04:02:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v26BO-0007Bz-2U; Fri, 26 Sep 2025 07:00:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26BH-0007At-B7 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v26B4-0007SY-Tx for qemu-devel@nongnu.org; Fri, 26 Sep 2025 07:00:01 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-3V-8H5E2PvCXV_Xg2O_6JA-1; Fri, 26 Sep 2025 06:59:36 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E6B5C19774E5; Fri, 26 Sep 2025 10:59:35 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.32.43]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A20C1195419F; Fri, 26 Sep 2025 10:59:35 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 4E9ED1800619; Fri, 26 Sep 2025 12:59:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758884379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FBEMiCFVj3xvS3M2nmY01HIfGjSvVC9LBpvAbZyiaFI=; b=Zes8eZMY+P4Ei06tFDipnlR8qjGjlXHLK8qLgiOQBe3++P4EleXO/i0Acry3gmdBo9UFyl PfRsO/5mTBiWa9wYJl3cgbFYgxuZ88iewvaZp2EkNVRV4Cu+bELyGV1qv6DGCAyFWwYJkt lXnye83gYYox4/nC6II+BlkJ8+GkLSs= X-MC-Unique: 3V-8H5E2PvCXV_Xg2O_6JA-1 X-Mimecast-MFC-AGG-ID: 3V-8H5E2PvCXV_Xg2O_6JA_1758884376 From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Zhao Liu , Paolo Bonzini , Gerd Hoffmann Subject: [PATCH v2 4/4] igvm: track memory regions created Date: Fri, 26 Sep 2025 12:59:26 +0200 Message-ID: <20250926105926.121890-5-kraxel@redhat.com> In-Reply-To: <20250926105926.121890-1-kraxel@redhat.com> References: <20250926105926.121890-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.446, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1758884568495116600 Content-Type: text/plain; charset="utf-8" Keep a linked list of the memory regions created by igvm. Signed-off-by: Gerd Hoffmann --- backends/igvm.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backends/igvm.c b/backends/igvm.c index 47600c361db4..5a8b4196149c 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -34,6 +34,11 @@ typedef struct QIgvmParameterData { uint32_t index; } QIgvmParameterData; =20 +typedef struct QIgvmMemoryRegion { + QTAILQ_ENTRY(QIgvmMemoryRegion) next; + MemoryRegion mr; +} QIgvmMemoryRegion; + /* * Some directives are specific to particular confidential computing platf= orms. * Define required types for each of those platforms here. @@ -79,6 +84,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; =20 /* @@ -191,7 +197,7 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t = addr, uint64_t size, int region_identifier, Error **errp) { ERRP_GUARD(); - MemoryRegion *igvm_pages =3D NULL; + QIgvmMemoryRegion *pages =3D NULL; Int128 gpa_region_size; MemoryRegionSection mrs =3D memory_region_find(get_system_memory(), addr, size); @@ -225,20 +231,21 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_= t addr, uint64_t size, */ g_autofree char *region_name =3D g_strdup_printf("igvm.%X", region_identifier); - igvm_pages =3D g_new0(MemoryRegion, 1); + pages =3D 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, err= p)) { return NULL; } } else { - if (!memory_region_init_ram(igvm_pages, NULL, region_name, siz= e, + if (!memory_region_init_ram(&pages->mr, NULL, region_name, siz= e, 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); } } =20 @@ -934,6 +941,7 @@ int qigvm_process_file(IgvmCfg *cfg, ConfidentialGuestS= upport *cgs, } =20 QTAILQ_INIT(&ctx.parameter_data); + QTAILQ_INIT(&ctx.memory_regions); =20 for (ctx.current_header_index =3D 0; ctx.current_header_index < (unsigned)header_count; --=20 2.51.0