From nobody Tue Feb 10 12:42:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1590032810; cv=none; d=zohomail.com; s=zohoarc; b=isn4BKNbvhO1av6HVE38ytZhpMg0aEzRg78hpIxdxUKSzCIo/F3aGHuB9/d2ojFydUsGtRsyo8xYbV52sP4IoPpBd9khV8VEogjSPewYOq4P1Jx7WtZZceZmxtuWeWtEJI8KiX/aXI0DGU+cOqDvISFLAc08B7IT9qhep19KM7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032810; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=i2CWgZVd9NV/3OEV+1jPG2aM5lL/SThr7+8QPptMm28=; b=jh5iiofNzi0B4SfTAUVfhun3jlx7Wv/M0kcnM5bd9RMPFqomKOWehUdkLiAEjbXgjnW0pUBm8Ry4QgdHbj8lOK0LFTAsZqrMUbxKsRzGJsgBNENIV28hPO2EVHjMiNSngKjgOjhMynjPLviO5oYwce5+P+o6/jp5glZga77k7G0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590032810117582.5889458148404; Wed, 20 May 2020 20:46:50 -0700 (PDT) Received: from localhost ([::1]:60408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcAS-0008Lg-R7 for importer@patchew.org; Wed, 20 May 2020 23:46:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7E-0002rw-C7; Wed, 20 May 2020 23:43:28 -0400 Received: from ozlabs.org ([203.11.71.1]:52143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7C-0003Tt-8k; Wed, 20 May 2020 23:43:27 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnr5r2Xz9sTR; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032592; bh=ScMyXOHqlJVI3Y1EURo7w0uOiUqN2ce3gWfMmvqVEj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knDP1MsAdW5AS+OF9SvJzk38ZzvnXZIHwzpMsGnn8Mrgpb6ONJSXQfLIS64r1ZVfa QvFYVtVJGCVB9dMtxu5MO26mlnrNnEFfWVbJcr/uKzQ63eOjnl1kjP39kERMJwnx+Z Ekprw22f8M9nnt/GzDOBfRKYi0e5tJU89B6rP4is= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 04/18] target/i386: sev: Embed SEVState in SevGuestState Date: Thu, 21 May 2020 13:42:50 +1000 Message-Id: <20200521034304.340040-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , Richard Henderson , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently SevGuestState contains only configuration information. For runtime state another non-QOM struct SEVState is allocated separately. Simplify things by instead embedding the SEVState structure in SevGuestState. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/i386/sev.c | 54 +++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index b6ed719fb5..b4ab9720d6 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -35,6 +35,22 @@ =20 typedef struct SevGuestState SevGuestState; =20 +struct SEVState { + uint8_t api_major; + uint8_t api_minor; + uint8_t build_id; + uint32_t policy; + uint64_t me_mask; + uint32_t cbitpos; + uint32_t reduced_phys_bits; + uint32_t handle; + int sev_fd; + SevState state; + gchar *measurement; +}; + +typedef struct SEVState SEVState; + /** * SevGuestState: * @@ -48,6 +64,7 @@ typedef struct SevGuestState SevGuestState; struct SevGuestState { Object parent_obj; =20 + /* configuration parameters */ char *sev_device; uint32_t policy; uint32_t handle; @@ -55,25 +72,11 @@ struct SevGuestState { char *session_file; uint32_t cbitpos; uint32_t reduced_phys_bits; -}; =20 -struct SEVState { - SevGuestState *sev_info; - uint8_t api_major; - uint8_t api_minor; - uint8_t build_id; - uint32_t policy; - uint64_t me_mask; - uint32_t cbitpos; - uint32_t reduced_phys_bits; - uint32_t handle; - int sev_fd; - SevState state; - gchar *measurement; + /* runtime state */ + SEVState state; }; =20 -typedef struct SEVState SEVState; - #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" =20 @@ -506,12 +509,12 @@ sev_read_file_base64(const char *filename, guchar **d= ata, gsize *len) } =20 static int -sev_launch_start(SEVState *s) +sev_launch_start(SevGuestState *sev) { + SEVState *s =3D &sev->state; gsize sz; int ret =3D 1; int fw_error, rc; - SevGuestState *sev =3D s->sev_info; struct kvm_sev_launch_start *start; guchar *session =3D NULL, *dh_cert =3D NULL; =20 @@ -686,6 +689,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) void * sev_guest_init(const char *id) { + SevGuestState *sev; SEVState *s; char *devname; int ret, fw_error; @@ -693,27 +697,27 @@ sev_guest_init(const char *id) uint32_t host_cbitpos; struct sev_user_data_status status =3D {}; =20 - sev_state =3D s =3D g_new0(SEVState, 1); - s->sev_info =3D lookup_sev_guest_info(id); - if (!s->sev_info) { + sev =3D lookup_sev_guest_info(id); + if (!sev) { error_report("%s: '%s' is not a valid '%s' object", __func__, id, TYPE_SEV_GUEST); goto err; } =20 + sev_state =3D s =3D &sev->state; s->state =3D SEV_STATE_UNINIT; =20 host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos =3D ebx & 0x3f; =20 - s->cbitpos =3D object_property_get_int(OBJECT(s->sev_info), "cbitpos",= NULL); + s->cbitpos =3D object_property_get_int(OBJECT(sev), "cbitpos", NULL); if (host_cbitpos !=3D s->cbitpos) { error_report("%s: cbitpos check failed, host '%d' requested '%d'", __func__, host_cbitpos, s->cbitpos); goto err; } =20 - s->reduced_phys_bits =3D object_property_get_int(OBJECT(s->sev_info), + s->reduced_phys_bits =3D object_property_get_int(OBJECT(sev), "reduced-phys-bits", NULL); if (s->reduced_phys_bits < 1) { error_report("%s: reduced_phys_bits check failed, it should be >= =3D1," @@ -723,7 +727,7 @@ sev_guest_init(const char *id) =20 s->me_mask =3D ~(1UL << s->cbitpos); =20 - devname =3D object_property_get_str(OBJECT(s->sev_info), "sev-device",= NULL); + devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); s->sev_fd =3D open(devname, O_RDWR); if (s->sev_fd < 0) { error_report("%s: Failed to open %s '%s'", __func__, @@ -754,7 +758,7 @@ sev_guest_init(const char *id) goto err; } =20 - ret =3D sev_launch_start(s); + ret =3D sev_launch_start(sev); if (ret) { error_report("%s: failed to create encryption context", __func__); goto err; --=20 2.26.2