From patchwork Mon Feb 12 15:36:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10213391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E261560329 for ; Mon, 12 Feb 2018 15:43:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BC06223A5 for ; Mon, 12 Feb 2018 15:43:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F34E928372; Mon, 12 Feb 2018 15:43:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE799223A5 for ; Mon, 12 Feb 2018 15:43:13 +0000 (UTC) Received: from localhost ([::1]:45562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elGG8-0007Yz-RD for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Feb 2018 10:43:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elGBR-0003M9-5z for qemu-devel@nongnu.org; Mon, 12 Feb 2018 10:38:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elGBO-00041q-MI for qemu-devel@nongnu.org; Mon, 12 Feb 2018 10:38:21 -0500 Received: from mail-by2nam01on0066.outbound.protection.outlook.com ([104.47.34.66]:9248 helo=NAM01-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1elGBO-0003yS-C3 for qemu-devel@nongnu.org; Mon, 12 Feb 2018 10:38:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=w3yU3rTza51HZ6adqOesV/+DkuFECKch+vRpfcixh9E=; b=nMtMZ8dOzMATGSzKHvIsr2A6X6a4GfOPE+XFrHvFnNozwvkQ1tytW8BCLgR+p3qpwDHSbIjiYvmCTjsQmCha0XAEUbU5AYRtY6oe3Vr1zq/h7/6WAW9h0xUmN2p/JXBVyHlTCg88rWaNMMt1C+ji+GQhvD0WT47OM23n3w+6ZHk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Mon, 12 Feb 2018 15:38:14 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Mon, 12 Feb 2018 09:36:56 -0600 Message-Id: <20180212153715.87555-10-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212153715.87555-1-brijesh.singh@amd.com> References: <20180212153715.87555-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: SN4PR0801CA0004.namprd08.prod.outlook.com (10.161.215.142) To BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d2aa0b52-8d59-49b8-84ab-08d5722ea275 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:BY2PR12MB0146; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 3:oFdtM3yV028HhVg/owQG/eVX9k9OJjLKcbuiXKx5vTFg1YBBfyvTdwTFsyAYFSO+qn4bpEszAloPn6n0BRJhRH+/fyepT62+JjmzqWjIAYQeVPyEE7k818ckKhhBn4TF/szetCrxP3zTX19b33PK7LaUt0L19Z6yA0fC1ekNlh3/9o+WIAlLmlOuefp3LNZbKoggYExLtq/2tx/y3HgP1qdppqnNokXaeiHVi16WDZ20DJGGH3bgWi89pfCzdUhc; 25:MqmBYQu7gwdJDpeUDMNZMfWD127ydj+qNlUKEYObQrrmqksA3gegvDdKyfkM4E8Lr0dGs1HC4E+T67gdQHEjNv07zFJnM5CqrEo1GBg2pQ3CIda6ZWYaGyU2irocZi7npN0iDU0X8/oBkXqetalLUsYvErdDpe5JqONdOS8zNy3Ja47XX67vmp4ezUu6OYaT/z6M1lMvi+n9fqpv1rES5K+ixu3wiVlbAST92uV5EK5QA+yviutxvQy3lg+0lsnOjBuKukvTmeXMGZSAvnKLsNMlqF5Gz7j8kBja2pwqTwD+NIH29VtIYiHNbFYS7Drot8cswDoT+Zd3I6LDdo0cUg==; 31:lO8QRdBxnkoGoaAzzUxxN+u7Fn20lot4uHTQo1WtGs8889mKtGGq4UkmKEfYyzeavaA0nzTjIH3XcXrk1liJ/61fP09RLwk+lILAC8Xavukdzvh8klkzfgyN9mAAzXXyQWKnPBY5i+zS7kqMxm7Dz841sCWpUi4o4O4DjiiSLCqh/5Bi1D3lMbh7PKuR+e/kePMuhzx4nu/k46KbCRJfY6qVvltzM8sflHp0TQ7PGxQ= X-MS-TrafficTypeDiagnostic: BY2PR12MB0146: X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 20:OtMNtCX2k3EDPE6R85Grz/bvqjzUatiWyrRTP+6kxnDHJgAUmraM7O/E+kcCqw/MI1u1//TQblm/CHBYLz3H7ulTjifHZXBbMOZkvL/BAIahXZcTfis5iUQVTfTg/EOd9WamKitad3umS4SrCJilZPTumPLdKhVolpjC+wyk0laMVIZM08hkSH+Biaq0C6br4r5G97q6MgF6bnpKdHPAvsf7zfuOgVcm5LaRBasxl9tNhvQDSUmYVgVuUslQ+jFYP/npi9PBG0Bn/XxJk1ie2NVUWAHZwiyqtPyovDgwdf07pnI4I6no034vgM92oZXo1FLiGhBHghlSMcGKDZcPdEQ7cqp8l/MRigrUDg2iGiwpj5lMWDUDfnU6tgZQZi+Fl+YK6PkPYrSiHmmREyWRgnoBuj4CBUk+AcSL5J2HVj2Ies2F7hWvJfQdLue2ZFvbyRtmSw1D3pluyi66s8zoL1oKkVEq5fL/m/YjC4CHHj5TVQsBL9IJHwKW9CCGnJ7v; 4:8B5PD+ptFYxSZ9WhakFxe4M7cpgF2jVJQghOBeIcS3zoWDxQuQWqWN3/JtvFpSOig0qX2FP8o3nPpI8wkBQfz4F0VbBdg20u5ydn0I46pxrvGHQLjKHP+LCUs/hkV3V8+F9WFm76VdTzKjK3wpDxEiiJJHaiV02sTpA4udgcOyx8CQhfC3mD0Bi2N3EiY70wzPDSDeConnunLxXsVD3MJSHoCQbe3KXBmIVPJF8hAKUNQuYI8uA1VY4kpJhdH2mopY7yWokj4ymT0CDxLWkVytf9JIrgCeKfhR+xi/H9lfgZMmuoV7PjwGMZ3Zc6P3H0/G1U7oj0+ETatSa1F2+Aww== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231101)(2400082)(944501161)(6055026)(6041288)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:BY2PR12MB0146; BCL:0; PCL:0; RULEID:; SRVR:BY2PR12MB0146; X-Forefront-PRVS: 0581B5AB35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(346002)(396003)(366004)(376002)(199004)(189003)(25786009)(53416004)(66066001)(8676002)(7416002)(105586002)(59450400001)(81156014)(76176011)(81166006)(5660300001)(97736004)(186003)(16526019)(8936002)(106356001)(50226002)(575784001)(2361001)(6116002)(3846002)(47776003)(305945005)(1076002)(86362001)(26005)(2351001)(7736002)(478600001)(51416003)(36756003)(4326008)(2906002)(53936002)(6666003)(2950100002)(8656006)(52116002)(6486002)(48376002)(39060400002)(68736007)(54906003)(16586007)(7696005)(386003)(316002)(6916009)(50466002)(8666007); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0146; H:wsp141597wss.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0146; 23:EJBfoZO2qS3uQYQQF77Kf1wT1Ip43eeOssO575Yfx?= =?us-ascii?Q?wmShQW8dFQSr5cUiL34yuyonP1m12pYRHZqOoLvrSwyGRQFnle0FF2mrwhoI?= =?us-ascii?Q?pOz3kE7CPZKJPS6A0iynJZdHtrNSYyg/CYvyW6EjGOE1/uyvc57jCTf1mv9W?= =?us-ascii?Q?j56O1Yxflt7g3TICDXGI0NBAxMugcGlZniu22EjkaF+/LlyhkOVtWFDKpNFJ?= =?us-ascii?Q?Qmp9ej3MlFF/ekLFxg6SEBEFyViWY4gywhor3qdNJML4fV0HK+TfVk/o0QXy?= =?us-ascii?Q?vWt9D4SSxBAB7m1QVjk+ghF9cPnSRdFOR2k6r5Qx1W2P735p31KHVOetHWge?= =?us-ascii?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trn/55yG/Qn77LV SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 20:gccPPbX5o5qbeQ81taOBJcUk0kN2UaFIyxKcujLcj7liI5Kn4KPdWWUeQbJiO5I262U6erveEBCZWO0MXfgmGCnQLa5T+xtWTrk2xaJcrFmYWdH8IJ/ifkzwh+ZjVI5dKNNo4qZdLrtRvYdZCMP4Uen6XC2qO+5jZ6uUxxp/A5iHgl/8VVadouFAHeVoQ5MlvgFVIaa4DKFdZP5vXb1hpp/CAWTF1oY+PzxDetyk2OPYAknOQgC2om0HJtJ+6bbd X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2018 15:38:14.7936 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2aa0b52-8d59-49b8-84ab-08d5722ea275 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0146 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.34.66 Subject: [Qemu-devel] [PATCH v8 09/28] target/i386: add Secure Encrypted Virtulization (SEV) object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Brijesh Singh , kvm@vger.kernel.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Alexander Graf , "Edgar E. Iglesias" , Markus Armbruster , Bruce Rogers , Christian Borntraeger , Marcel Apfelbaum , Borislav Petkov , Thomas Lendacky , Eduardo Habkost , Richard Henderson , "Dr. David Alan Gilbert" , Alistair Francis , Cornelia Huck , Richard Henderson , Peter Crosthwaite , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a new memory encryption object 'sev-guest'. The object will be used to create enrypted VMs on AMD EPYC CPU. The object provides the properties to pass guest owner's public Diffie-hellman key, guest policy and session information required to create the memory encryption context within the SEV firmware. e.g to launch SEV guest # $QEMU \ -object sev-guest,id=sev0 \ -machine ....,memory-encryption=sev0 Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Signed-off-by: Brijesh Singh --- docs/amd-memory-encryption.txt | 17 ++++ include/sysemu/sev.h | 54 +++++++++++ qemu-options.hx | 36 +++++++ target/i386/Makefile.objs | 2 +- target/i386/sev.c | 214 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 include/sysemu/sev.h create mode 100644 target/i386/sev.c diff --git a/docs/amd-memory-encryption.txt b/docs/amd-memory-encryption.txt index 72a92b6c6353..1527f603ea2a 100644 --- a/docs/amd-memory-encryption.txt +++ b/docs/amd-memory-encryption.txt @@ -35,10 +35,21 @@ in bad measurement). The guest policy is a 4-byte data structure containing several flags that restricts what can be done on running SEV guest. See KM Spec section 3 and 6.2 for more details. +The guest policy can be provided via the 'policy' property (see below) + +# ${QEMU} \ + sev-guest,id=sev0,policy=0x1...\ + Guest owners provided DH certificate and session parameters will be used to establish a cryptographic session with the guest owner to negotiate keys used for the attestation. +The DH certificate and session blob can be provided via 'dh-cert-file' and +'session-file' property (see below + +# ${QEMU} \ + sev-guest,id=sev0,dh-cert-file=,session-file= + LAUNCH_UPDATE_DATA encrypts the memory region using the cryptographic context created via LAUNCH_START command. If required, this command can be called multiple times to encrypt different memory regions. The command also calculates @@ -59,6 +70,12 @@ context. See SEV KM API Spec [1] 'Launching a guest' usage flow (Appendix A) for the complete flow chart. +To launch a SEV guest + +# ${QEMU} \ + -machine ...,memory-encryption=sev0 \ + -object sev-guest,id=sev0 + Debugging ----------- Since memory contents of SEV guest is encrypted hence hypervisor access to the diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h new file mode 100644 index 000000000000..eed679653dbc --- /dev/null +++ b/include/sysemu/sev.h @@ -0,0 +1,54 @@ +/* + * QEMU Secure Encrypted Virutualization (SEV) support + * + * Copyright: Advanced Micro Devices, 2016-2018 + * + * Authors: + * Brijesh Singh + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_SEV_H +#define QEMU_SEV_H + +#include "qom/object.h" +#include "qapi/error.h" +#include "sysemu/kvm.h" +#include "qemu/error-report.h" + +#define TYPE_QSEV_GUEST_INFO "sev-guest" +#define QSEV_GUEST_INFO(obj) \ + OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) + +typedef struct QSevGuestInfo QSevGuestInfo; +typedef struct QSevGuestInfoClass QSevGuestInfoClass; + +/** + * QSevGuestInfo: + * + * The QSevGuestInfo object is used for creating a SEV guest. + * + * # $QEMU \ + * -object sev-guest,id=sev0 \ + * -machine ...,memory-encryption=sev0 + */ +struct QSevGuestInfo { + Object parent_obj; + + char *sev_device; + uint32_t policy; + uint32_t handle; + char *dh_cert_file; + char *session_file; + uint32_t cbitpos; +}; + +struct QSevGuestInfoClass { + ObjectClass parent_class; +}; + +#endif + diff --git a/qemu-options.hx b/qemu-options.hx index e70c92db2323..b7e03ed5e671 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4304,6 +4304,42 @@ contents of @code{iv.b64} to the second secret data=$SECRET,iv=$( + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "qemu/base64.h" +#include "sysemu/kvm.h" +#include "sysemu/sev.h" +#include "sysemu/sysemu.h" + +#define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ +#define DEFAULT_SEV_DEVICE "/dev/sev" + +static void +qsev_guest_finalize(Object *obj) +{ +} + +static char * +qsev_guest_get_session_file(Object *obj, Error **errp) +{ + QSevGuestInfo *s = QSEV_GUEST_INFO(obj); + + return s->session_file ? g_strdup(s->session_file) : NULL; +} + +static void +qsev_guest_set_session_file(Object *obj, const char *value, Error **errp) +{ + QSevGuestInfo *s = QSEV_GUEST_INFO(obj); + + s->session_file = g_strdup(value); +} + +static char * +qsev_guest_get_dh_cert_file(Object *obj, Error **errp) +{ + QSevGuestInfo *s = QSEV_GUEST_INFO(obj); + + return g_strdup(s->dh_cert_file); +} + +static void +qsev_guest_set_dh_cert_file(Object *obj, const char *value, Error **errp) +{ + QSevGuestInfo *s = QSEV_GUEST_INFO(obj); + + s->dh_cert_file = g_strdup(value); +} + +static char * +qsev_guest_get_sev_device(Object *obj, Error **errp) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + return g_strdup(sev->sev_device); +} + +static void +qsev_guest_set_sev_device(Object *obj, const char *value, Error **errp) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + sev->sev_device = g_strdup(value); +} + +static void +qsev_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, + NULL); + object_class_property_set_description(oc, "sev-device", + "SEV device to use", NULL); + object_class_property_add_str(oc, "dh-cert-file", + qsev_guest_get_dh_cert_file, + qsev_guest_set_dh_cert_file, + NULL); + object_class_property_set_description(oc, "dh-cert-file", + "guest owners DH certificate (encoded with base64)", NULL); + object_class_property_add_str(oc, "session-file", + qsev_guest_get_session_file, + qsev_guest_set_session_file, + NULL); + object_class_property_set_description(oc, "session-file", + "guest owners session parameters (encoded with base64)", NULL); +} + +static void +qsev_guest_set_handle(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + uint32_t value; + + visit_type_uint32(v, name, &value, errp); + sev->handle = value; +} + +static void +qsev_guest_set_policy(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + uint32_t value; + + visit_type_uint32(v, name, &value, errp); + sev->policy = value; +} + +static void +qsev_guest_set_cbitpos(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + uint32_t value; + + visit_type_uint32(v, name, &value, errp); + sev->cbitpos = value; +} + +static void +qsev_guest_get_policy(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + uint32_t value; + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + value = sev->policy; + visit_type_uint32(v, name, &value, errp); +} + +static void +qsev_guest_get_handle(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + uint32_t value; + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + value = sev->handle; + visit_type_uint32(v, name, &value, errp); +} + +static void +qsev_guest_get_cbitpos(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + uint32_t value; + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + value = sev->cbitpos; + visit_type_uint32(v, name, &value, errp); +} + +static uint32_t +sev_get_host_cbitpos(void) +{ + uint32_t ebx; + + host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); + + return ebx & 0x3f; +} + +static void +qsev_guest_init(Object *obj) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + sev->sev_device = g_strdup(DEFAULT_SEV_DEVICE); + sev->policy = DEFAULT_GUEST_POLICY; + sev->cbitpos = sev_get_host_cbitpos(); + object_property_add(obj, "policy", "uint32", qsev_guest_get_policy, + qsev_guest_set_policy, NULL, NULL, NULL); + object_property_add(obj, "handle", "uint32", qsev_guest_get_handle, + qsev_guest_set_handle, NULL, NULL, NULL); + object_property_add(obj, "cbitpos", "uint32", qsev_guest_get_cbitpos, + qsev_guest_set_cbitpos, NULL, NULL, NULL); +} + +/* sev guest info */ +static const TypeInfo qsev_guest_info = { + .parent = TYPE_OBJECT, + .name = TYPE_QSEV_GUEST_INFO, + .instance_size = sizeof(QSevGuestInfo), + .instance_finalize = qsev_guest_finalize, + .class_size = sizeof(QSevGuestInfoClass), + .class_init = qsev_guest_class_init, + .instance_init = qsev_guest_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void +sev_register_types(void) +{ + type_register_static(&qsev_guest_info); +} + +type_init(sev_register_types);