From nobody Tue May 21 04:42:57 2024 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=1591253005; cv=none; d=zohomail.com; s=zohoarc; b=guSm9KQLMt8IGyKAzCHNqYEen9KEn5ez5ccf3OyhthBTIWi6N9cXzV68e1JmBNR5YcWFvutoHeazsB3VWF86Xht9IRgGPR1neN31cIzkSnWj1SO4N+7UknC34dM62ScNZc7DJ9U1zF8HyW+jEiZ+E/bwOOnAw2R6NxUKUqKWiXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253005; h=Content-Type: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=ub+Z3xYzpGcAUIzl2jwy8XMKQthP20UZhT1/8DDqE/Y=; b=MMD0RUWF+x/3OcE8AFalWn/WlTFu2J9IpVQEQV31M2YxVbtVgrZ6dJENUivfLKpkaCXFMK9Vom9l29naYAWKoKO8uopiuiz3Yf2YG3PnTyf7G8njAuYneXzMVjX06y9en92G1S5nlRh/l6qSw+sc+GxCVzh9AjDk0pEIA2VgpaE= 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 1591253004981283.1313003602671; Wed, 3 Jun 2020 23:43:24 -0700 (PDT) Received: from localhost ([::1]:56962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjb1-0006Lv-Ho for importer@patchew.org; Thu, 04 Jun 2020 02:43:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaD-0004yG-K8 for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:33 -0400 Received: from ozlabs.org ([203.11.71.1]:38327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaB-0000mq-GR for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6C1TGJz9sSy; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252947; bh=xkT1FQ1tlWIodI9BBRKL+4b/EXFmxDrPZ0u1FPIW7HI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QR2zh33qP7gj/TB0dA7oLnQ+vEpmbGqoA2wfiM0EiCBp41eF/iMONXw5vFsneh6sc zYMWKWeBmbwk/ptAnuv+EfARjbItYcsmSUa15zgF7t+2HHmt8g/AAOVEpTWTKzGGU/ 9AXFAXt0P9pgskrcR63dWABn7OXHjD2eUB8Tx92A= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 1/9] target/i386: sev: Remove unused QSevGuestInfoClass Date: Thu, 4 Jun 2020 16:42:11 +1000 Message-Id: <20200604064219.436242-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/06/04 02:12:28 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This structure is nothing but an empty wrapper around the parent class, which by QOM conventions means we don't need it at all. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/i386/sev.c | 1 - target/i386/sev_i386.h | 5 ----- 2 files changed, 6 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 51cdbe5496..2312510cf2 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -287,7 +287,6 @@ static const TypeInfo qsev_guest_info =3D { .name =3D TYPE_QSEV_GUEST_INFO, .instance_size =3D sizeof(QSevGuestInfo), .instance_finalize =3D qsev_guest_finalize, - .class_size =3D sizeof(QSevGuestInfoClass), .class_init =3D qsev_guest_class_init, .instance_init =3D qsev_guest_init, .interfaces =3D (InterfaceInfo[]) { diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h index 8ada9d385d..4f193642ac 100644 --- a/target/i386/sev_i386.h +++ b/target/i386/sev_i386.h @@ -41,7 +41,6 @@ extern char *sev_get_launch_measurement(void); extern SevCapability *sev_get_capabilities(void); =20 typedef struct QSevGuestInfo QSevGuestInfo; -typedef struct QSevGuestInfoClass QSevGuestInfoClass; =20 /** * QSevGuestInfo: @@ -64,10 +63,6 @@ struct QSevGuestInfo { uint32_t reduced_phys_bits; }; =20 -struct QSevGuestInfoClass { - ObjectClass parent_class; -}; - struct SEVState { QSevGuestInfo *sev_info; uint8_t api_major; --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253147; cv=none; d=zohomail.com; s=zohoarc; b=hGIQIaydmjKID54zZB9PlJEuSBjz0leO0d0vR44f48C3yqaKgkuIREBFtVmnTlIHEi/Cid4VneJIwFYUbUaPiSnruflc4Y6KXqzTVhkPhtqaIt9cl30MxZI5+U4Mj1vYaSUvRbZeRtBjvLnA5qHRwZ/oN+4tResLkwlpd+575GA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253147; h=Content-Type: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=hosQ38ldfziPR+hg1N86nYDlkEh5f6a6Dd6joa+bEEg=; b=HWE7yKqIUZs1cblz/zcTe2gB0qZtXD7hBrrMl0zWxj+GU7m20pCOqsJAUU96deOYrUV0UajpC2zAWotHiBgIlr2DQhN+nPVQnnLkV53uWIHZetxyAKFm+x+hJJ8VZrmywrJLwdzU+lFL+N+zfP/zIcK4NAqb44U+MnRmkt1x/Z8= 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 1591253147198998.3730272571337; Wed, 3 Jun 2020 23:45:47 -0700 (PDT) Received: from localhost ([::1]:35718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjdJ-0000rt-Uh for importer@patchew.org; Thu, 04 Jun 2020 02:45:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaD-0004y2-8v for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:33 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:52547 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaB-0000mn-GQ for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:32 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6C2j6mz9sT2; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252947; bh=b70ol4AwRW7a/EV2Hqh72SgevUQ9Bq55LIXZW4grnkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ieXFvT7H9I8p+r5TBGCmnbCqn9mmAjMqFdhCy7CEoWvRW398LeE9UnLiJAbfFrv/2 mdzqBCMWSPovIHs0+rXihDnEI6Yc0rvTAcEcb5oZg7jq8h4xC3SsvNixvDMeEwfCtS f/OmUkAokjmrBA38pmc8Vs3AwwErptIaeJUzob9w= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 2/9] target/i386: sev: Move local structure definitions into .c file Date: Thu, 4 Jun 2020 16:42:12 +1000 Message-Id: <20200604064219.436242-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/06/04 02:12:28 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Neither QSevGuestInfo nor SEVState (not to be confused with SevState) is used anywhere outside target/i386/sev.c, so they might as well live in there rather than in a (somewhat) exposed header. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/i386/sev.c | 44 ++++++++++++++++++++++++++++++++++++++++++ target/i386/sev_i386.h | 44 ------------------------------------------ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 2312510cf2..53def5f41a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -29,6 +29,50 @@ #include "trace.h" #include "migration/blocker.h" =20 +#define TYPE_QSEV_GUEST_INFO "sev-guest" +#define QSEV_GUEST_INFO(obj) \ + OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) + +typedef struct QSevGuestInfo QSevGuestInfo; + +/** + * QSevGuestInfo: + * + * The QSevGuestInfo object is used for creating a SEV guest. + * + * # $QEMU \ + * -object sev-guest,id=3Dsev0 \ + * -machine ...,memory-encryption=3Dsev0 + */ +struct QSevGuestInfo { + Object parent_obj; + + char *sev_device; + uint32_t policy; + uint32_t handle; + char *dh_cert_file; + char *session_file; + uint32_t cbitpos; + uint32_t reduced_phys_bits; +}; + +struct SEVState { + QSevGuestInfo *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; +}; + +typedef struct SEVState SEVState; + #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" =20 diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h index 4f193642ac..8eb7de1bef 100644 --- a/target/i386/sev_i386.h +++ b/target/i386/sev_i386.h @@ -28,10 +28,6 @@ #define SEV_POLICY_DOMAIN 0x10 #define SEV_POLICY_SEV 0x20 =20 -#define TYPE_QSEV_GUEST_INFO "sev-guest" -#define QSEV_GUEST_INFO(obj) \ - OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) - extern bool sev_enabled(void); extern uint64_t sev_get_me_mask(void); extern SevInfo *sev_get_info(void); @@ -40,44 +36,4 @@ extern uint32_t sev_get_reduced_phys_bits(void); extern char *sev_get_launch_measurement(void); extern SevCapability *sev_get_capabilities(void); =20 -typedef struct QSevGuestInfo QSevGuestInfo; - -/** - * QSevGuestInfo: - * - * The QSevGuestInfo object is used for creating a SEV guest. - * - * # $QEMU \ - * -object sev-guest,id=3Dsev0 \ - * -machine ...,memory-encryption=3Dsev0 - */ -struct QSevGuestInfo { - Object parent_obj; - - char *sev_device; - uint32_t policy; - uint32_t handle; - char *dh_cert_file; - char *session_file; - uint32_t cbitpos; - uint32_t reduced_phys_bits; -}; - -struct SEVState { - QSevGuestInfo *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; -}; - -typedef struct SEVState SEVState; - #endif --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253149; cv=none; d=zohomail.com; s=zohoarc; b=crWHcPxqHoMW6uCG9UDp4HMEkq4lpvz5y0fsIHEUjXJpus3G8I3h1087x+XBdYbd1t+KZw69SHDJLWNlOogsZIco8YDhS6T2QzMSpaUQSpi0E/LUxafgg73KeuNzs4VAdD1+ww9c1dPF7FaBAdbCyex7u7FDOYJNC0qFs+YK5uQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253149; h=Content-Type: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=VPMrSIeKD30CydJ/fy0miWusz+J8lKQUUpyMGG/1yyA=; b=XlciNg+nnL96x+3fUTg8n5ayzlyD0Ifrj1TkgEvSAKXdGln9ZjPRCq68oDFII1kpxYumrbZaBiSWSzIPTj73i1VX47LfpnCxAPZgLo862xPO5k/9oLr2Qmrm64PVTLjk5Tpt/rcXSx5L936N2gprt4qM3o+nCQceN30ZaRr5Mw4= 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 1591253149792861.6756755186268; Wed, 3 Jun 2020 23:45:49 -0700 (PDT) Received: from localhost ([::1]:35954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjdM-00012b-II for importer@patchew.org; Thu, 04 Jun 2020 02:45:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaG-00052E-Ob for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: from ozlabs.org ([203.11.71.1]:52741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaF-0000nT-Fo for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6C4mkgz9sTP; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252947; bh=ldWYlnk7sDyLihq8ugblJL+B/6PQKCRla6JRAZXFnAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C9MAia5rXWdS+vQUbrF+cVIvQ5jbCdX0ibXr3lC13Zv0JgOhXRGWM58B4kfnNJLnz 4WZUm5HPAUU354lIX9+hDTCQvMZ7zIvFzK2H39f5mJMjdOlhuSFF5an24r/2/RDqQe lOEc2cDK3zgk1d8grt5ophLFFugTShP76t5Isi0E= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 3/9] target/i386: sev: Rename QSevGuestInfo Date: Thu, 4 Jun 2020 16:42:13 +1000 Message-Id: <20200604064219.436242-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/06/04 02:12:28 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) At the moment this is a purely passive object which is just a container for information used elsewhere, hence the name. I'm going to change that though, so as a preliminary rename it to SevGuestState. That name risks confusion with both SEVState and SevState, but I'll be working on that in following patches. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/i386/sev.c | 87 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 53def5f41a..b6ed719fb5 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -29,22 +29,23 @@ #include "trace.h" #include "migration/blocker.h" =20 -#define TYPE_QSEV_GUEST_INFO "sev-guest" -#define QSEV_GUEST_INFO(obj) \ - OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) +#define TYPE_SEV_GUEST "sev-guest" +#define SEV_GUEST(obj) \ + OBJECT_CHECK(SevGuestState, (obj), TYPE_SEV_GUEST) =20 -typedef struct QSevGuestInfo QSevGuestInfo; +typedef struct SevGuestState SevGuestState; =20 /** - * QSevGuestInfo: + * SevGuestState: * - * The QSevGuestInfo object is used for creating a SEV guest. + * The SevGuestState object is used for creating and managing a SEV + * guest. * * # $QEMU \ * -object sev-guest,id=3Dsev0 \ * -machine ...,memory-encryption=3Dsev0 */ -struct QSevGuestInfo { +struct SevGuestState { Object parent_obj; =20 char *sev_device; @@ -57,7 +58,7 @@ struct QSevGuestInfo { }; =20 struct SEVState { - QSevGuestInfo *sev_info; + SevGuestState *sev_info; uint8_t api_major; uint8_t api_minor; uint8_t build_id; @@ -235,82 +236,82 @@ static struct RAMBlockNotifier sev_ram_notifier =3D { }; =20 static void -qsev_guest_finalize(Object *obj) +sev_guest_finalize(Object *obj) { } =20 static char * -qsev_guest_get_session_file(Object *obj, Error **errp) +sev_guest_get_session_file(Object *obj, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 return s->session_file ? g_strdup(s->session_file) : NULL; } =20 static void -qsev_guest_set_session_file(Object *obj, const char *value, Error **errp) +sev_guest_set_session_file(Object *obj, const char *value, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 s->session_file =3D g_strdup(value); } =20 static char * -qsev_guest_get_dh_cert_file(Object *obj, Error **errp) +sev_guest_get_dh_cert_file(Object *obj, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 return g_strdup(s->dh_cert_file); } =20 static void -qsev_guest_set_dh_cert_file(Object *obj, const char *value, Error **errp) +sev_guest_set_dh_cert_file(Object *obj, const char *value, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 s->dh_cert_file =3D g_strdup(value); } =20 static char * -qsev_guest_get_sev_device(Object *obj, Error **errp) +sev_guest_get_sev_device(Object *obj, Error **errp) { - QSevGuestInfo *sev =3D QSEV_GUEST_INFO(obj); + SevGuestState *sev =3D SEV_GUEST(obj); =20 return g_strdup(sev->sev_device); } =20 static void -qsev_guest_set_sev_device(Object *obj, const char *value, Error **errp) +sev_guest_set_sev_device(Object *obj, const char *value, Error **errp) { - QSevGuestInfo *sev =3D QSEV_GUEST_INFO(obj); + SevGuestState *sev =3D SEV_GUEST(obj); =20 sev->sev_device =3D g_strdup(value); } =20 static void -qsev_guest_class_init(ObjectClass *oc, void *data) +sev_guest_class_init(ObjectClass *oc, void *data) { object_class_property_add_str(oc, "sev-device", - qsev_guest_get_sev_device, - qsev_guest_set_sev_device); + sev_guest_get_sev_device, + sev_guest_set_sev_device); object_class_property_set_description(oc, "sev-device", "SEV device to use"); object_class_property_add_str(oc, "dh-cert-file", - qsev_guest_get_dh_cert_file, - qsev_guest_set_dh_cert_file); + sev_guest_get_dh_cert_file, + sev_guest_set_dh_cert_file); object_class_property_set_description(oc, "dh-cert-file", "guest owners DH certificate (encoded with base64)"); object_class_property_add_str(oc, "session-file", - qsev_guest_get_session_file, - qsev_guest_set_session_file); + sev_guest_get_session_file, + sev_guest_set_session_file); object_class_property_set_description(oc, "session-file", "guest owners session parameters (encoded with base64)"); } =20 static void -qsev_guest_init(Object *obj) +sev_guest_instance_init(Object *obj) { - QSevGuestInfo *sev =3D QSEV_GUEST_INFO(obj); + SevGuestState *sev =3D SEV_GUEST(obj); =20 sev->sev_device =3D g_strdup(DEFAULT_SEV_DEVICE); sev->policy =3D DEFAULT_GUEST_POLICY; @@ -326,32 +327,32 @@ qsev_guest_init(Object *obj) } =20 /* sev guest info */ -static const TypeInfo qsev_guest_info =3D { +static const TypeInfo sev_guest_info =3D { .parent =3D TYPE_OBJECT, - .name =3D TYPE_QSEV_GUEST_INFO, - .instance_size =3D sizeof(QSevGuestInfo), - .instance_finalize =3D qsev_guest_finalize, - .class_init =3D qsev_guest_class_init, - .instance_init =3D qsev_guest_init, + .name =3D TYPE_SEV_GUEST, + .instance_size =3D sizeof(SevGuestState), + .instance_finalize =3D sev_guest_finalize, + .class_init =3D sev_guest_class_init, + .instance_init =3D sev_guest_instance_init, .interfaces =3D (InterfaceInfo[]) { { TYPE_USER_CREATABLE }, { } } }; =20 -static QSevGuestInfo * +static SevGuestState * lookup_sev_guest_info(const char *id) { Object *obj; - QSevGuestInfo *info; + SevGuestState *info; =20 obj =3D object_resolve_path_component(object_get_objects_root(), id); if (!obj) { return NULL; } =20 - info =3D (QSevGuestInfo *) - object_dynamic_cast(obj, TYPE_QSEV_GUEST_INFO); + info =3D (SevGuestState *) + object_dynamic_cast(obj, TYPE_SEV_GUEST); if (!info) { return NULL; } @@ -510,7 +511,7 @@ sev_launch_start(SEVState *s) gsize sz; int ret =3D 1; int fw_error, rc; - QSevGuestInfo *sev =3D s->sev_info; + SevGuestState *sev =3D s->sev_info; struct kvm_sev_launch_start *start; guchar *session =3D NULL, *dh_cert =3D NULL; =20 @@ -696,7 +697,7 @@ sev_guest_init(const char *id) s->sev_info =3D lookup_sev_guest_info(id); if (!s->sev_info) { error_report("%s: '%s' is not a valid '%s' object", - __func__, id, TYPE_QSEV_GUEST_INFO); + __func__, id, TYPE_SEV_GUEST); goto err; } =20 @@ -786,7 +787,7 @@ sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t l= en) static void sev_register_types(void) { - type_register_static(&qsev_guest_info); + type_register_static(&sev_guest_info); } =20 type_init(sev_register_types); --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253004; cv=none; d=zohomail.com; s=zohoarc; b=GHcGzoTbm9fvvBzkzkmYMAkRGbKnwSsZi/YVJOkvIFaIXicpNcfsW8c6Alsx7iHN61wDuqSgyLtogRcz7EsN+T59la0+zORjchEzSJ9kvgegOVgLqJykOuxDbr7bbM2S+OQxV7Zv+6RFctK35F1dTGFW9MhU3Y1v0u4qTKtEwPg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253004; h=Content-Type: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=g5PrnvLXWbfPJ1inOdhDlwKg4LdB5JQRZXk0AlTaGnQ=; b=dICIKk/KVLuTTgiSHeVtxC1W9dTD3ACrjpctJoO9Xia8bkBYggjyfj0pIrDAD55ulIrv9gFG2kYrfvjpcnc1FdnPVuFWsKPAxfChUm47qIjWZ+c9Otkcw/QrNqRJCVENC8EqJlYLunEYrmpeDwMnqyVP7iqilKG2TbdCN3oD4bw= 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 1591253004840838.0212246240076; Wed, 3 Jun 2020 23:43:24 -0700 (PDT) Received: from localhost ([::1]:57020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjb1-0006NO-Ni for importer@patchew.org; Thu, 04 Jun 2020 02:43:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaD-0004yJ-Pa for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:33 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:45963) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaB-0000mp-GQ for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6C3x7Pz9sTG; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252947; bh=FTQ7m07v8BgK5bUbT3s95D7yiqpW26UZ7gLCPq5T3cE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fSHI6dowy1vZ5HgJ2QyUL2dmuIuYY4wabE4Pboo2LlWo7MDaqalZSV0SM3OR5EDvN UZkXidm9G7lmDVEQYWx2E/DvXAPr4ib/8FWiZTvmP2URX6zqML7Z+nn2B4vjsexQEb /LDmLxKggVyii1b6s5uTJPPcHOmAitjzFqK/m8TU= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 4/9] target/i386: sev: Embed SEVState in SevGuestState Date: Thu, 4 Jun 2020 16:42:14 +1000 Message-Id: <20200604064219.436242-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 From nobody Tue May 21 04:42:57 2024 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=1591253239; cv=none; d=zohomail.com; s=zohoarc; b=i8o2gyD4FwGty+8zw9RtTv5OtbgLYHDOWfdr0PModp+cU/s/Me7fJRQq5GSel/yr303GuOe4uuUhftfD2bbKm5l6Hd+wEXxXkgc0WMEetyMTAzrMUx6vdFpnOUeYmXC6d0SXbWLbicNihgTT3g/Wl9kSv+PXKAFMw//DYfZkzy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253239; 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=6O4iPH7iF8LKIfGIFOC0V+6+61u2tBiU/nMdCjsPdrU=; b=d4CM82zD2aZ3ipBGzFyZwhyzipkrMnxiiUXFnjDhluRkOwyrO78oFWVekfBi8Ipk8y3W+dLHkpeobnr52fE5Isj4z2j+6+BcDNX2rPthTSKqgA8r8BFhNYhErtv1KHekG6SWjioByJPBqwt6kXpNbZgVzywi9fp8vT+kLVRrKi8= 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 159125323917414.272073432162188; Wed, 3 Jun 2020 23:47:19 -0700 (PDT) Received: from localhost ([::1]:44560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjen-0005Ax-UQ for importer@patchew.org; Thu, 04 Jun 2020 02:47:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaH-00053E-30 for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:37 -0400 Received: from ozlabs.org ([203.11.71.1]:47113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaF-0000nb-K6 for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6C6VYJz9sTS; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252947; bh=b1j6omAe9XgeHM0BU9Jzn1mQzx20+TzZhGytbq8GQGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gRX9Jh7MSl7vyOAgfoVU75W9xanJaVUgxHP4WJ5TidKstxubzfpWzPu+y92n2aSZC YNMRRf+MuOMMxTqnzUrYPQs/6US3C1JFd1F/ds/juomKHD7IlOZhdR2zuqV3A3/Itk h8VNAQpm1RJZMiWoUMkSmzcMDdvzQ9jUPFneVk/A= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 5/9] target/i386: sev: Partial cleanup to sev_state global Date: Thu, 4 Jun 2020 16:42:15 +1000 Message-Id: <20200604064219.436242-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-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/06/04 02:12:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 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, T_FILL_THIS_FORM_SHORT=0.01, 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, 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" The SEV code uses a pretty ugly global to access its internal state. Now that SEVState is embedded in SevGuestState, we can avoid accessing it via the global in some cases. In the remaining cases use a new global referencing the containing SevGuestState which will simplify some future transformations. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/i386/sev.c | 92 ++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index b4ab9720d6..9e8ab7b056 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -80,7 +80,7 @@ struct SevGuestState { #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" =20 -static SEVState *sev_state; +static SevGuestState *sev_guest; static Error *sev_mig_blocker; =20 static const char *const sev_fw_errlist[] =3D { @@ -159,21 +159,21 @@ fw_error_to_str(int code) } =20 static bool -sev_check_state(SevState state) +sev_check_state(const SevGuestState *sev, SevState state) { - assert(sev_state); - return sev_state->state =3D=3D state ? true : false; + assert(sev); + return sev->state.state =3D=3D state ? true : false; } =20 static void -sev_set_guest_state(SevState new_state) +sev_set_guest_state(SevGuestState *sev, SevState new_state) { assert(new_state < SEV_STATE__MAX); - assert(sev_state); + assert(sev); =20 - trace_kvm_sev_change_state(SevState_str(sev_state->state), + trace_kvm_sev_change_state(SevState_str(sev->state.state), SevState_str(new_state)); - sev_state->state =3D new_state; + sev->state.state =3D new_state; } =20 static void @@ -366,25 +366,25 @@ lookup_sev_guest_info(const char *id) bool sev_enabled(void) { - return sev_state ? true : false; + return !!sev_guest; } =20 uint64_t sev_get_me_mask(void) { - return sev_state ? sev_state->me_mask : ~0; + return sev_guest ? sev_guest->state.me_mask : ~0; } =20 uint32_t sev_get_cbit_position(void) { - return sev_state ? sev_state->cbitpos : 0; + return sev_guest ? sev_guest->state.cbitpos : 0; } =20 uint32_t sev_get_reduced_phys_bits(void) { - return sev_state ? sev_state->reduced_phys_bits : 0; + return sev_guest ? sev_guest->state.reduced_phys_bits : 0; } =20 SevInfo * @@ -393,15 +393,15 @@ sev_get_info(void) SevInfo *info; =20 info =3D g_new0(SevInfo, 1); - info->enabled =3D sev_state ? true : false; + info->enabled =3D sev_enabled(); =20 if (info->enabled) { - info->api_major =3D sev_state->api_major; - info->api_minor =3D sev_state->api_minor; - info->build_id =3D sev_state->build_id; - info->policy =3D sev_state->policy; - info->state =3D sev_state->state; - info->handle =3D sev_state->handle; + info->api_major =3D sev_guest->state.api_major; + info->api_minor =3D sev_guest->state.api_minor; + info->build_id =3D sev_guest->state.build_id; + info->policy =3D sev_guest->state.policy; + info->state =3D sev_guest->state.state; + info->handle =3D sev_guest->state.handle; } =20 return info; @@ -550,7 +550,7 @@ sev_launch_start(SevGuestState *sev) =20 object_property_set_int(OBJECT(sev), start->handle, "handle", &error_abort); - sev_set_guest_state(SEV_STATE_LAUNCH_UPDATE); + sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); s->handle =3D start->handle; s->policy =3D start->policy; ret =3D 0; @@ -563,7 +563,7 @@ out: } =20 static int -sev_launch_update_data(uint8_t *addr, uint64_t len) +sev_launch_update_data(SevGuestState *sev, uint8_t *addr, uint64_t len) { int ret, fw_error; struct kvm_sev_launch_update_data update; @@ -575,7 +575,7 @@ sev_launch_update_data(uint8_t *addr, uint64_t len) update.uaddr =3D (__u64)(unsigned long)addr; update.len =3D len; trace_kvm_sev_launch_update_data(addr, len); - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, + ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, &update, &fw_error); if (ret) { error_report("%s: LAUNCH_UPDATE ret=3D%d fw_error=3D%d '%s'", @@ -588,19 +588,20 @@ sev_launch_update_data(uint8_t *addr, uint64_t len) static void sev_launch_get_measure(Notifier *notifier, void *unused) { + SevGuestState *sev =3D sev_guest; int ret, error; guchar *data; - SEVState *s =3D sev_state; + SEVState *s =3D &sev->state; struct kvm_sev_launch_measure *measurement; =20 - if (!sev_check_state(SEV_STATE_LAUNCH_UPDATE)) { + if (!sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { return; } =20 measurement =3D g_new0(struct kvm_sev_launch_measure, 1); =20 /* query the measurement blob length */ - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (!measurement->len) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -612,7 +613,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) measurement->uaddr =3D (unsigned long)data; =20 /* get the measurement blob */ - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (ret) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -620,7 +621,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) goto free_data; } =20 - sev_set_guest_state(SEV_STATE_LAUNCH_SECRET); + sev_set_guest_state(sev, SEV_STATE_LAUNCH_SECRET); =20 /* encode the measurement value and emit the event */ s->measurement =3D g_base64_encode(data, measurement->len); @@ -635,9 +636,9 @@ free_measurement: char * sev_get_launch_measurement(void) { - if (sev_state && - sev_state->state >=3D SEV_STATE_LAUNCH_SECRET) { - return g_strdup(sev_state->measurement); + if (sev_guest && + sev_guest->state.state >=3D SEV_STATE_LAUNCH_SECRET) { + return g_strdup(sev_guest->state.measurement); } =20 return NULL; @@ -648,20 +649,21 @@ static Notifier sev_machine_done_notify =3D { }; =20 static void -sev_launch_finish(SEVState *s) +sev_launch_finish(SevGuestState *sev) { + SEVState *s =3D &sev->state; int ret, error; Error *local_err =3D NULL; =20 trace_kvm_sev_launch_finish(); - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); + ret =3D sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); if (ret) { error_report("%s: LAUNCH_FINISH ret=3D%d fw_error=3D%d '%s'", __func__, ret, error, fw_error_to_str(error)); exit(1); } =20 - sev_set_guest_state(SEV_STATE_RUNNING); + sev_set_guest_state(sev, SEV_STATE_RUNNING); =20 /* add migration blocker */ error_setg(&sev_mig_blocker, @@ -677,11 +679,11 @@ sev_launch_finish(SEVState *s) static void sev_vm_state_change(void *opaque, int running, RunState state) { - SEVState *s =3D opaque; + SevGuestState *sev =3D opaque; =20 if (running) { - if (!sev_check_state(SEV_STATE_RUNNING)) { - sev_launch_finish(s); + if (!sev_check_state(sev, SEV_STATE_RUNNING)) { + sev_launch_finish(sev); } } } @@ -704,7 +706,8 @@ sev_guest_init(const char *id) goto err; } =20 - sev_state =3D s =3D &sev->state; + sev_guest =3D sev; + s =3D &sev->state; s->state =3D SEV_STATE_UNINIT; =20 host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); @@ -766,23 +769,24 @@ sev_guest_init(const char *id) =20 ram_block_notifier_add(&sev_ram_notifier); qemu_add_machine_init_done_notifier(&sev_machine_done_notify); - qemu_add_vm_change_state_handler(sev_vm_state_change, s); + qemu_add_vm_change_state_handler(sev_vm_state_change, sev); =20 - return s; + return sev; err: - g_free(sev_state); - sev_state =3D NULL; + sev_guest =3D NULL; return NULL; } =20 int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len) { - assert(handle); + SevGuestState *sev =3D handle; + + assert(sev); =20 /* if SEV is in update state then encrypt the data else do nothing */ - if (sev_check_state(SEV_STATE_LAUNCH_UPDATE)) { - return sev_launch_update_data(ptr, len); + if (sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { + return sev_launch_update_data(sev, ptr, len); } =20 return 0; --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253236; cv=none; d=zohomail.com; s=zohoarc; b=jlnjejRW8WZpPiaiW+k0CYHjsWv0fCYKv6dzLaHzdP/g+P13aTAAW2RSWzVdCwpU2lVYDfpwNfgeE254CbXaheJQKLHCl+BSkqxL/vrX/UdgiP3xRRquVnDZ7MYI4vj+/Bdqt2hFYmWlTWgN6u1jSu43ytMB9vsjfu4ScnycWFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253236; h=Content-Type: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=cCdIM02MG1i6dSG7FEM1Q2fErDZIMonT3BIQ5nAbNqw=; b=HcxMqHI5K2fHAwWntVqL3nwjZLMuc/rkMq9/o/t7Af62XEbRXyJoncl3OnJrr3LjR7c/57YJM+1HlhJJlk4wo69Wi0+xXSEFSnVfJ2sTCBdxjrgzQiHQbkyDNwJoD8hIaG4LRfARFrE3eZNrIKvfbwpWmOHdyeyK172r9B4RK5U= 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 1591253236739920.2009514013697; Wed, 3 Jun 2020 23:47:16 -0700 (PDT) Received: from localhost ([::1]:44242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjel-00052p-Iy for importer@patchew.org; Thu, 04 Jun 2020 02:47:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaG-00051E-Dn for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: from ozlabs.org ([203.11.71.1]:41657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaF-0000nU-FC for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6C5g18z9sTL; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252947; bh=GLsLYxc2PjN1+1LUp/caZlHg/ICb1byIBHQiQsQcEYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W8Kv2kcJEBAFmJoDP+vTL9By+ABtQfLK6JmmGaHLX6tIzL5W2/9l/QRbfbhHOUbHP CTbYKe0Apa1qwVZvgTcbXrm2uuqkBArsHd6M9L45z4M54DtVXdZA6z9TSEsjVSSiIN jhOZjlTBJmXlJMHJGv1jmtHbwcFnnhmZObzyyYNY= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 6/9] target/i386: sev: Remove redundant cbitpos and reduced_phys_bits fields Date: Thu, 4 Jun 2020 16:42:16 +1000 Message-Id: <20200604064219.436242-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/06/04 02:12:28 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The SEVState structure has cbitpos and reduced_phys_bits fields which are simply copied from the SevGuestState structure and never changed. Now that SEVState is embedded in SevGuestState we can just access the original copy directly. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/i386/sev.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 9e8ab7b056..d25af37136 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -41,8 +41,6 @@ struct SEVState { 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; @@ -378,13 +376,13 @@ sev_get_me_mask(void) uint32_t sev_get_cbit_position(void) { - return sev_guest ? sev_guest->state.cbitpos : 0; + return sev_guest ? sev_guest->cbitpos : 0; } =20 uint32_t sev_get_reduced_phys_bits(void) { - return sev_guest ? sev_guest->state.reduced_phys_bits : 0; + return sev_guest ? sev_guest->reduced_phys_bits : 0; } =20 SevInfo * @@ -713,22 +711,19 @@ sev_guest_init(const char *id) host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos =3D ebx & 0x3f; =20 - s->cbitpos =3D object_property_get_int(OBJECT(sev), "cbitpos", NULL); - if (host_cbitpos !=3D s->cbitpos) { + if (host_cbitpos !=3D sev->cbitpos) { error_report("%s: cbitpos check failed, host '%d' requested '%d'", - __func__, host_cbitpos, s->cbitpos); + __func__, host_cbitpos, sev->cbitpos); goto err; } =20 - s->reduced_phys_bits =3D object_property_get_int(OBJECT(sev), - "reduced-phys-bits", NULL); - if (s->reduced_phys_bits < 1) { + if (sev->reduced_phys_bits < 1) { error_report("%s: reduced_phys_bits check failed, it should be >= =3D1," - " requested '%d'", __func__, s->reduced_phys_bits); + " requested '%d'", __func__, sev->reduced_phys_bits); goto err; } =20 - s->me_mask =3D ~(1UL << s->cbitpos); + s->me_mask =3D ~(1UL << sev->cbitpos); =20 devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); s->sev_fd =3D open(devname, O_RDWR); --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253327; cv=none; d=zohomail.com; s=zohoarc; b=fwP7FhnaHGVxX6p0JjA6hgtvmubW3kgKLgjJPOzmbEgTyVD9MCcm9gylpYBZzT7ai/cmwItNTr45v6qKPQSE1ufH8oxAjgmdgVYuCysukVU4bCeAl5MWZ+yqRsYTb9xeDHKxyIRGEtraGzW3U/EzPqrczlgGylD6UyBdbA7YN5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253327; 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=S8RJz4n/mUhsoh9ALn/rRXPRrxEoMntsI4mB7CRC0Uk=; b=edzqQAAUHyGrQ6uUrnm2dE6wq5KS5wyF3ZMMzMGlgV8VLnk6SVUzbYvnv1qfGu2MzZrKZAbFEHWDui0m7iwEi6kzf2DvL4GqLcFFZkAO0B+2Bb9a9N4Vk/C/OLL/y4tg6sS+fAr5qchvxLQ59dc+lAcbns0vqQ9ENCw9V2AvcpM= 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 1591253327437148.64694814300015; Wed, 3 Jun 2020 23:48:47 -0700 (PDT) Received: from localhost ([::1]:50906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjgD-0007i0-Ss for importer@patchew.org; Thu, 04 Jun 2020 02:48:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaG-00052N-Sy for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:45387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaF-0000ni-Hk for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6D0yx1z9sTV; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252948; bh=6MG/UBS88R7qdMJG8taGdNHmp5J64Yq8vcEMkHSWD7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CHV4tGbhvtnF2MNap+rM5TvnxKbVKH2I5Qs/263/iOUjUxymNXA+1W1tfSajA74X7 K+2UQqhJFPRDeikkUWJDRxrDQ9Dgh+CAkD1dIUbwr9rvfF5f28m5qBW43O+5z1eI8H HYoCFGdKuaPgRUQpid9QYb21y7X/4pDkcVGLteh8= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 7/9] target/i386: sev: Remove redundant policy field Date: Thu, 4 Jun 2020 16:42:17 +1000 Message-Id: <20200604064219.436242-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, 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" SEVState::policy is set from the final value of the policy field in the parameter structure for the KVM_SEV_LAUNCH_START ioctl(). But, AFAICT that ioctl() won't ever change it from the original supplied value which comes from SevGuestState::policy. So, remove this field and just use SevGuestState::policy directly. Signed-off-by: David Gibson Reviewed-by: Richard Henderson --- target/i386/sev.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index d25af37136..4b261beaa7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -39,7 +39,6 @@ struct SEVState { uint8_t api_major; uint8_t api_minor; uint8_t build_id; - uint32_t policy; uint64_t me_mask; uint32_t handle; int sev_fd; @@ -397,7 +396,7 @@ sev_get_info(void) info->api_major =3D sev_guest->state.api_major; info->api_minor =3D sev_guest->state.api_minor; info->build_id =3D sev_guest->state.build_id; - info->policy =3D sev_guest->state.policy; + info->policy =3D sev_guest->policy; info->state =3D sev_guest->state.state; info->handle =3D sev_guest->state.handle; } @@ -520,8 +519,7 @@ sev_launch_start(SevGuestState *sev) =20 start->handle =3D object_property_get_int(OBJECT(sev), "handle", &error_abort); - start->policy =3D object_property_get_int(OBJECT(sev), "policy", - &error_abort); + start->policy =3D sev->policy; if (sev->session_file) { if (sev_read_file_base64(sev->session_file, &session, &sz) < 0) { goto out; @@ -550,7 +548,6 @@ sev_launch_start(SevGuestState *sev) &error_abort); sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); s->handle =3D start->handle; - s->policy =3D start->policy; ret =3D 0; =20 out: --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253237; cv=none; d=zohomail.com; s=zohoarc; b=iAtUrqyNXrI7ud4P+/8vF+K4DUPydMSmxrxKz4Uxbd2mBLznOdicYvCpr3hK6QhA3vsvuUt6EMYtkVdnhJ03bIV/AijH28IG4Nmnds0dt7ixx1+qFFhChihHasKgWR+cksF757Hte+131SgTQcTVNwxxXQVt73/HTGtRXnq7Ry4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253237; 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=EGt1kI6Hz7BujQYbazgJ6OD8K5yTegswlxKNSrdU9AI=; b=XASn+UIdgXqa7iB39ef4PH/VBtQxaKkMJnBlWa5+MbWTZWkAkS+E1EwGX02j1IAkG2W/RxO2J7CLtEJBGNEbdmUODl4a4cQGvUKvFJ42MRrtysLgCJXVWvQvLTqhdbEO4zwbiCW87oOSAqGEnnLViRScSgHDnWeZ+HjqqVUWEc4= 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 159125323719443.395156199782036; Wed, 3 Jun 2020 23:47:17 -0700 (PDT) Received: from localhost ([::1]:44390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjem-00056O-0H for importer@patchew.org; Thu, 04 Jun 2020 02:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaG-00050g-7E for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:51619) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaF-0000nX-Ab for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:35 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6D0D02z9sTR; Thu, 4 Jun 2020 16:42:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252948; bh=A3PAjiRQqKl9hfB8R8V83gpgLEOrxMNBxGAfULeW6JA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fYPgJp43wTfIc597kgX6lH5DcKQAUEWrazYjIpJWYcZY+fwqeVjf0AcF9Sk1V3JcU blbJthmppYKSHOg96Q6A/jtWCslf90YrmM6xV/CYrGsc/OWSFjCUL+G40bhp3GNOUn vF8BLW2l2+eviso+LX47IMPS7KaLNkrH05sHtN4A= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 8/9] target/i386: sev: Remove redundant handle field Date: Thu, 4 Jun 2020 16:42:18 +1000 Message-Id: <20200604064219.436242-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, 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" The user can explicitly specify a handle via the "handle" property wired to SevGuestState::handle. That gets passed to the KVM_SEV_LAUNCH_START ioctl() which may update it, the final value being copied back to both SevGuestState::handle and SEVState::handle. AFAICT, nothing will be looking SEVState::handle before it and SevGuestState::handle have been updated from the ioctl(). So, remove the field and just use SevGuestState::handle directly. Signed-off-by: David Gibson Reviewed-by: Richard Henderson --- target/i386/sev.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 4b261beaa7..24e2dea9b8 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -40,7 +40,6 @@ struct SEVState { uint8_t api_minor; uint8_t build_id; uint64_t me_mask; - uint32_t handle; int sev_fd; SevState state; gchar *measurement; @@ -64,13 +63,13 @@ struct SevGuestState { /* configuration parameters */ char *sev_device; uint32_t policy; - uint32_t handle; char *dh_cert_file; char *session_file; uint32_t cbitpos; uint32_t reduced_phys_bits; =20 /* runtime state */ + uint32_t handle; SEVState state; }; =20 @@ -398,7 +397,7 @@ sev_get_info(void) info->build_id =3D sev_guest->state.build_id; info->policy =3D sev_guest->policy; info->state =3D sev_guest->state.state; - info->handle =3D sev_guest->state.handle; + info->handle =3D sev_guest->handle; } =20 return info; @@ -517,8 +516,7 @@ sev_launch_start(SevGuestState *sev) =20 start =3D g_new0(struct kvm_sev_launch_start, 1); =20 - start->handle =3D object_property_get_int(OBJECT(sev), "handle", - &error_abort); + start->handle =3D sev->handle; start->policy =3D sev->policy; if (sev->session_file) { if (sev_read_file_base64(sev->session_file, &session, &sz) < 0) { @@ -544,10 +542,8 @@ sev_launch_start(SevGuestState *sev) goto out; } =20 - object_property_set_int(OBJECT(sev), start->handle, "handle", - &error_abort); sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); - s->handle =3D start->handle; + sev->handle =3D start->handle; ret =3D 0; =20 out: --=20 2.26.2 From nobody Tue May 21 04:42:57 2024 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=1591253390; cv=none; d=zohomail.com; s=zohoarc; b=lmskJ/oPP9BL2O7Xc/Fy7Ev96AB0bYQxynX1Jh8IynMzQChTbs8h4YKqdCnjwwpC5AnaEjbXGoZ3bG0iDBFEb9u7D0tOSu/CRbieqc3eghAxcB6TYA721cK9jEJaL+fzNizdv4r2lo+I+tcF4YBmhxxlbb70NY0VSfoovFYBb+k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591253390; h=Content-Type: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=ng+ZRzGG6polsnnYML/jiRO5beHBMcEMvr2JPDcNJjE=; b=Tcjjw7OGAA0w0jWARhUwOd0HjGqqeL1IVhd7HDB2+jv7fE6vfVJKHRJshZe61BynZ6MNo1v17uh/L45miGdZDqtkXsgcyQ6zUW5PoqjhMwO1j0fnqvCsnEFqxWpUh9aLVMQ/wJd19RwdX3usla0yxtvzKNFl/1MpDzna3CDMp20= 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 1591253390743658.5519425061296; Wed, 3 Jun 2020 23:49:50 -0700 (PDT) Received: from localhost ([::1]:56190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgjhF-0001W1-JC for importer@patchew.org; Thu, 04 Jun 2020 02:49:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaH-00053Q-5I for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:37 -0400 Received: from ozlabs.org ([203.11.71.1]:39501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgjaF-0000nk-To for qemu-devel@nongnu.org; Thu, 04 Jun 2020 02:42:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49cx6D1pVnz9sTT; Thu, 4 Jun 2020 16:42:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1591252948; bh=9XFgDESJPgFUKQthTa2aOPuUw2nAgG46DWdbRXnKPl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEQl3sSY0uZ7j9qiCVm/NLY+yG2ezLFIxpurtxnqvuwZf0t1uHT+nYPvy5YYCnXsQ 8LKdPZknYJawiyAPcovOz6fD1xqI+EOv7+wwPwXOA6OfYZkAfcyxQke1RTg/BPV3Kz bcyKLeYzu3G4UqO4ms172P8rnJx1DK9plSuSb0Es= From: David Gibson To: rth@twiddle.net, pbonzini@redhat.com, ekabkost@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 9/9] target/i386: sev: Unify SEVState and SevGuestState Date: Thu, 4 Jun 2020 16:42:19 +1000 Message-Id: <20200604064219.436242-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604064219.436242-1-david@gibson.dropbear.id.au> References: <20200604064219.436242-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/06/04 02:12:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 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, T_FILL_THIS_FORM_SHORT=0.01, 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: brijesh.singh@amd.com, Eduardo Habkost , Richard Henderson , dgilbert@redhat.com, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) SEVState is contained with SevGuestState. We've now fixed redundancies and name conflicts, so there's no real point to the nested structure. Just move all the fields of SEVState into SevGuestState. This eliminates the SEVState structure, which as a bonus removes the confusion with the SevState enum. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- target/i386/sev.c | 79 ++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 24e2dea9b8..d273174ad3 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -35,18 +35,6 @@ =20 typedef struct SevGuestState SevGuestState; =20 -struct SEVState { - uint8_t api_major; - uint8_t api_minor; - uint8_t build_id; - uint64_t me_mask; - int sev_fd; - SevState state; - gchar *measurement; -}; - -typedef struct SEVState SEVState; - /** * SevGuestState: * @@ -70,7 +58,13 @@ struct SevGuestState { =20 /* runtime state */ uint32_t handle; - SEVState state; + uint8_t api_major; + uint8_t api_minor; + uint8_t build_id; + uint64_t me_mask; + int sev_fd; + SevState state; + gchar *measurement; }; =20 #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ @@ -158,7 +152,7 @@ static bool sev_check_state(const SevGuestState *sev, SevState state) { assert(sev); - return sev->state.state =3D=3D state ? true : false; + return sev->state =3D=3D state ? true : false; } =20 static void @@ -167,9 +161,9 @@ sev_set_guest_state(SevGuestState *sev, SevState new_st= ate) assert(new_state < SEV_STATE__MAX); assert(sev); =20 - trace_kvm_sev_change_state(SevState_str(sev->state.state), + trace_kvm_sev_change_state(SevState_str(sev->state), SevState_str(new_state)); - sev->state.state =3D new_state; + sev->state =3D new_state; } =20 static void @@ -368,7 +362,7 @@ sev_enabled(void) uint64_t sev_get_me_mask(void) { - return sev_guest ? sev_guest->state.me_mask : ~0; + return sev_guest ? sev_guest->me_mask : ~0; } =20 uint32_t @@ -392,11 +386,11 @@ sev_get_info(void) info->enabled =3D sev_enabled(); =20 if (info->enabled) { - info->api_major =3D sev_guest->state.api_major; - info->api_minor =3D sev_guest->state.api_minor; - info->build_id =3D sev_guest->state.build_id; + info->api_major =3D sev_guest->api_major; + info->api_minor =3D sev_guest->api_minor; + info->build_id =3D sev_guest->build_id; info->policy =3D sev_guest->policy; - info->state =3D sev_guest->state.state; + info->state =3D sev_guest->state; info->handle =3D sev_guest->handle; } =20 @@ -507,7 +501,6 @@ sev_read_file_base64(const char *filename, guchar **dat= a, gsize *len) static int sev_launch_start(SevGuestState *sev) { - SEVState *s =3D &sev->state; gsize sz; int ret =3D 1; int fw_error, rc; @@ -535,7 +528,7 @@ sev_launch_start(SevGuestState *sev) } =20 trace_kvm_sev_launch_start(start->policy, session, dh_cert); - rc =3D sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error); + rc =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error); if (rc < 0) { error_report("%s: LAUNCH_START ret=3D%d fw_error=3D%d '%s'", __func__, ret, fw_error, fw_error_to_str(fw_error)); @@ -566,7 +559,7 @@ sev_launch_update_data(SevGuestState *sev, uint8_t *add= r, uint64_t len) update.uaddr =3D (__u64)(unsigned long)addr; update.len =3D len; trace_kvm_sev_launch_update_data(addr, len); - ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, &update, &fw_error); if (ret) { error_report("%s: LAUNCH_UPDATE ret=3D%d fw_error=3D%d '%s'", @@ -582,7 +575,6 @@ sev_launch_get_measure(Notifier *notifier, void *unused) SevGuestState *sev =3D sev_guest; int ret, error; guchar *data; - SEVState *s =3D &sev->state; struct kvm_sev_launch_measure *measurement; =20 if (!sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { @@ -592,7 +584,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) measurement =3D g_new0(struct kvm_sev_launch_measure, 1); =20 /* query the measurement blob length */ - ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (!measurement->len) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -604,7 +596,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) measurement->uaddr =3D (unsigned long)data; =20 /* get the measurement blob */ - ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (ret) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -615,8 +607,8 @@ sev_launch_get_measure(Notifier *notifier, void *unused) sev_set_guest_state(sev, SEV_STATE_LAUNCH_SECRET); =20 /* encode the measurement value and emit the event */ - s->measurement =3D g_base64_encode(data, measurement->len); - trace_kvm_sev_launch_measurement(s->measurement); + sev->measurement =3D g_base64_encode(data, measurement->len); + trace_kvm_sev_launch_measurement(sev->measurement); =20 free_data: g_free(data); @@ -628,8 +620,8 @@ char * sev_get_launch_measurement(void) { if (sev_guest && - sev_guest->state.state >=3D SEV_STATE_LAUNCH_SECRET) { - return g_strdup(sev_guest->state.measurement); + sev_guest->state >=3D SEV_STATE_LAUNCH_SECRET) { + return g_strdup(sev_guest->measurement); } =20 return NULL; @@ -642,12 +634,11 @@ static Notifier sev_machine_done_notify =3D { static void sev_launch_finish(SevGuestState *sev) { - SEVState *s =3D &sev->state; int ret, error; Error *local_err =3D NULL; =20 trace_kvm_sev_launch_finish(); - ret =3D sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); if (ret) { error_report("%s: LAUNCH_FINISH ret=3D%d fw_error=3D%d '%s'", __func__, ret, error, fw_error_to_str(error)); @@ -683,7 +674,6 @@ void * sev_guest_init(const char *id) { SevGuestState *sev; - SEVState *s; char *devname; int ret, fw_error; uint32_t ebx; @@ -698,8 +688,7 @@ sev_guest_init(const char *id) } =20 sev_guest =3D sev; - s =3D &sev->state; - s->state =3D SEV_STATE_UNINIT; + sev->state =3D SEV_STATE_UNINIT; =20 host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos =3D ebx & 0x3f; @@ -716,20 +705,20 @@ sev_guest_init(const char *id) goto err; } =20 - s->me_mask =3D ~(1UL << sev->cbitpos); + sev->me_mask =3D ~(1UL << sev->cbitpos); =20 devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); - s->sev_fd =3D open(devname, O_RDWR); - if (s->sev_fd < 0) { + sev->sev_fd =3D open(devname, O_RDWR); + if (sev->sev_fd < 0) { error_report("%s: Failed to open %s '%s'", __func__, devname, strerror(errno)); } g_free(devname); - if (s->sev_fd < 0) { + if (sev->sev_fd < 0) { goto err; } =20 - ret =3D sev_platform_ioctl(s->sev_fd, SEV_PLATFORM_STATUS, &status, + ret =3D sev_platform_ioctl(sev->sev_fd, SEV_PLATFORM_STATUS, &status, &fw_error); if (ret) { error_report("%s: failed to get platform status ret=3D%d " @@ -737,12 +726,12 @@ sev_guest_init(const char *id) fw_error_to_str(fw_error)); goto err; } - s->build_id =3D status.build; - s->api_major =3D status.api_major; - s->api_minor =3D status.api_minor; + sev->build_id =3D status.build; + sev->api_major =3D status.api_major; + sev->api_minor =3D status.api_minor; =20 trace_kvm_sev_init(); - ret =3D sev_ioctl(s->sev_fd, KVM_SEV_INIT, NULL, &fw_error); + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error); if (ret) { error_report("%s: failed to initialize ret=3D%d fw_error=3D%d '%s'= ", __func__, ret, fw_error, fw_error_to_str(fw_error)); --=20 2.26.2