From patchwork Wed Mar 8 20:52:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9611975 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 861F86016C for ; Wed, 8 Mar 2017 21:25:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76D4A2863B for ; Wed, 8 Mar 2017 21:25:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B2522863F; Wed, 8 Mar 2017 21:25:48 +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=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 EA2EE2863B for ; Wed, 8 Mar 2017 21:25:46 +0000 (UTC) Received: from localhost ([::1]:58517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clj5d-0005VY-Qn for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Mar 2017 16:25:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clj5G-0005T1-0X for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:25:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clj5C-0005M8-Lm for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:25:22 -0500 Received: from mail-sn1nam01on0055.outbound.protection.outlook.com ([104.47.32.55]:37952 helo=NAM01-SN1-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 1clj5C-0005Lw-9S for qemu-devel@nongnu.org; Wed, 08 Mar 2017 16:25: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=YZhdwY+RTHgT0DQhfDinkpkpXNigaIT80L1GaudjLGc=; b=CqyM7kgIVLzTOz9atNCczDUYW1o0RB+AZkAJneHU0EvO9AsBGYob/6JG/VAw0/06pUc/frm1CjAnAHc+OEehJjDII7Hp4sMD0lhfeZh1D1k6onNgleFVWu/eBxcvhaiIEVkD7RyF0RG182yBAjY9KNvXPiG7vzWH4InNpeGr/qI= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by MWHPR12MB1616.namprd12.prod.outlook.com (10.172.56.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Wed, 8 Mar 2017 20:52:39 +0000 From: Brijesh Singh To: , , , , , , , , Date: Wed, 8 Mar 2017 15:52:37 -0500 Message-ID: <148900635729.27090.16897035853016859795.stgit@brijesh-build-machine> In-Reply-To: <148900626714.27090.1616990932333159904.stgit@brijesh-build-machine> References: <148900626714.27090.1616990932333159904.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR13CA0011.namprd13.prod.outlook.com (10.168.161.149) To MWHPR12MB1616.namprd12.prod.outlook.com (10.172.56.17) X-MS-Office365-Filtering-Correlation-Id: 1b52b60d-5f1e-42b8-a665-08d466650f81 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:MWHPR12MB1616; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1616; 3:mGjjZghYshTdCoFKbwrerPz6JF4jokrFZWe1yP+j0r5bhgYI7Gk5Fme0aw8QZNHE001uES6/3ezQGm1Efh4yJEb2gs1T+CaXmdudDS204ETiLX9wzfAjgJ0xsqwezs62ja34MsMk9/1CHu2+VZBMjSxo1dgz3WPpwBXvk0LYZ/rm32CmYE55MSys8nRb6ayhYWhiOdPF0DiPbhN8UhVRB/hg8ZRvzYfiMu77MufVbSYgvBZUCFSX1bd6UA1bZ4rQqye/u6m/iVKGeJiNrHAsUF99+Lr8+LAs1VXhrR11lsE=; 25:bPDlv1rOwpuy3R9B4xtvO4RkKRiNnINJmF6dYiQruM0zIhbl9FCrw9esys15zBPSYLLggzacNpx305ZvB7Nb2yu9O05HKHF1YrQt82oXGwkO5bTZKpBqxPAr8q4MRNx9mmNCh/L4IIFZoLEfAKX9ndok9JftUW3UzbOs8ClyCBWyu678TYa5lxx1OMM9t2wQ4ky48Mp/CuiBxpWOduU+hZF9qxY+OltIlmD6Zzb+bSI5T6ihtu+MkLHrQC4HBMYyQTKuFBtlA1guYt7g7JgNrrPy/a2NBA/S3w2c6qn+98hs4sweXDF1cHGjeSkWE8DUzhmKkHtEf8tUVqkHA8fRpOFss6qlzgkeMXUN2ZJy0ohvc034SIwnk8sD7ogKrfJpUjJ7b3yjwUNBthE8jXH7OLQwfpAtpuUo0xkVHyuJMRF95YrpCCRtEHO6PrJvdDOe X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1616; 31:LMdwn9s/EiBRCHss2AbubhiC23vdtNTjrgZHHwBH2pwhhBuBXSh08+OetEJzpV5KoQ4cq6aC5Z/gdQaGi7qJZxvf1XopfqgaDocJX7g+FJzXqSNu4YR1eqjXJEMN9FJ+JLBllDKmcRBkt2/+R07Q4Qp8Tpcmx56cs5QcOHifswrtiGtRQVthLb9Zv462CJoGcWPphKjZZFdU05/lXNP3W9Cr++QoTqPhek/yQ+ZYj7o=; 20:Vo7Qj7UXUKF/BG4e443eeR8lCxAMbBjVyaDQqjHWFTUkV1VxoPTHigqfczRnxBaHTs7wsliiu9XNOk8LErV2Z5JUEU5fyXqSN3D4aZ8DEfNtZR5uab6h4lWBf9RsJ5N80YB31+cpNaFae9s08JHe7pduKk4UOnd9mOS6skA0Q5aXiPBhPOINJNNC+SppcaLx1EU346jizkdWJmF92/onbr0ffHrdBCbpCXrLqHJ6VoRJzULhN4wIwawuJJ2PePHGVRiMHYBNvicWb6WWOv+BagLHC+AiFptY/esVSvxndzFOpS7QKf3VgBMt5OagLo5+QWFnGkypoHpXhpNPXqooi7N4WwoFAATMpnmMKpgVAeim1S8FmePts1OqZ5mVn/QysGIrHQJes8vonEQUdoFx6PX8JQHbEkogMQzRMLArjeMYeRq/hs9ElhLe+gOo5NWK2WJy1nqb5/DJYxpV001QhZjhlqaTJIxIZrAqMOtZ/kILJkxBYGFhfxOFOdFuibTX X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123558025)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(6042181)(6072148); SRVR:MWHPR12MB1616; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1616; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1616; 4:khPaHa04cmH3ALMy+0HJ9Vd6FQWpAqWWK+wTWKmCpDS/va0KK5N8hPcswzFp4acKTTJEDrur8+QBxITjAYsgPCOeXHLgSjoEk3sJGro1vYJ3nPzIvbSDdNXV3WlzhZ3uPjPHOxTclvxuRWYxCV19Jb7ucNKWRqV3SzxqFdq0LkJJzbDY1Xw9N3H/59oGsIwOSu012US8s+CHt7haXcHF8ITX8BrCIh49op7TM39nxCZ7EKbiihWm46n/ncE+KGa+ko3aZCqz36my4PYAWoWYzTYnpg6wFyWaOWOY38pe0Ym7QHhiCVATfLoWXb5AZX6GJUa/UFytdTCwoA/seF0AmNX7o8+xe5bFgQW46vLJ2yIR77/6A6SSXsM0+NMPwaCfhKEUdLuIG8AaH2J+vE4f5dFx176XhPa5qCe3ZwPGCa7Lfz7A2wpe3+jGpsQcqMDrRaCXCkBPa4SS5lKWHcPQXCwvJrCyT+xaZIo/+NJccNDHi4HbeS44+Rzeo7791DPkup6qZuMDH6IVJTWDsKA2JJU0HLhaGR77FRnVhkJpFE+jSJm/CdlJk3c0DgEZ+0Y1BXS8E0Y9yxzL4+oufDy1eAUY84Rw3iJwmD6Jsv8yDucezLibS0EILeNSCnjHl7I6dQXcfOmtzZ663ZFJmUXOKNxia8Z/BK5b8XFasNNx8nCJuh987Hkjl05F2mCZJIK57uLAK4gEURqRTPio56pm3MNYKxSgtdkckPlP51SZNmQ= X-Forefront-PRVS: 02408926C4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(86362001)(5660300001)(2201001)(575784001)(1720100001)(33716001)(3846002)(54906002)(103116003)(4326008)(305945005)(966004)(189998001)(53936002)(9686003)(38730400002)(6306002)(7736002)(6486002)(77096006)(90366009)(6116002)(230700001)(25786008)(50466002)(33646002)(81166006)(76176999)(42186005)(66066001)(8676002)(23676002)(83506001)(47776003)(54356999)(2906002)(2950100002)(50986999)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1616; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxNjE2OzIzOkxmc1dEYjRGUGJhelAxdFRGQkFreGtOMzBB?= =?utf-8?B?YU1GQVI1VEpqU0k0UmJ1bDNFcEtyYmpocHoxejlUV3FTWVVSSm5TRmd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O20uvl2FKQhrx6UeaP2683qm7qPbiC+V3yuSbHHi/NklEnFYkdGwHhsD+UJmNvgWc6XRKctLgOTb3qc=; 24:UfnecHKTnexDlYuW6yYy5u1RCI9k9lFEu03cepjpXIWSFGlcrTmJjL2fw0X7qx2e0zhjVzQIAkNjthNiu8GLfN5hjpQREXBL025aZ2K7ia8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1616; 7:YWIsLwQeTX+weErXO3oyoeClKjGNySVGvdg+Jlbe/nLQvA7Q862kGZdDEO/Iaj4DZ1GHTHQV+64pxjJUwegkUoZ3OOvcu2TGg7vrIPgyjwak/4u0MAot+oBK6k0vBaNfiTX7vJzGSP+Edk2L5RqO4/RjOqVGhqINdmU9NQAjv2oCbIYmZDm4h1TOXtK5bL7AknaZhpz7C81+MrfM3yTxk6iHj1mGxqNjStWzbZswULFdTC8gqMtL8CLVjTTpGGztyJGCYH3NA0GRxyoV8fWmHNaI2bLaP7t2gCzsrtvsIQlhkyXgjWT4IrWuQZlDpVDMYS3ghLfgqEQPVBiG2zTetQ==; 20:3t12cPDdUvJQ03j7Zd2nAxVYB4+2agvfCZ32mJRtgKEwyUTt9jbQKsr/nuIMLvbjuPRkbt/DAhfnDPJo6HbCYqHtBq/o652DTRy/edT8CyPeFo6mRP32zthj7C/wrS8Eh9UK6JawO0GMVKw/ghKVEnSDz5zXVh1KvNI8LGs+M1w7JUIIyvSGhRcYNkgkzmXSXf+1FEeMt8ZDkt3lJ2xansLwJPWeQPE92MA8Fcs3br+eUd4yR62V8uWL+tGKd0x1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2017 20:52:39.5970 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1616 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.32.55 Subject: [Qemu-devel] [RFC PATCH v4 08/20] sev: add Secure Encrypted Virtulization (SEV) support 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: Thomas.Lendacky@amd.com, brijesh.singh@amd.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Adds initial support required to integrate Secure Encrypted Virtualization (SEV) feature. SEV is an extension to the existing AMD-V technology found on AMD processors. The SEV feature allows the memory contents of a virtual machine to be transparently encrypted with a key unique to the guest VM. In QEMU command line, SEV can be enabled via memory-encryption property defined in security-policy object. Patch adds the following new objects: - sev-launch-info: provides the properties to get and set various parameters used to boot SEV guest from unencrypted boot images. In this mode the OS images (kernel, initrd and bios) provides by guest owner are unencrypted. The SEV guest boot process would encrypt the images using the guest owners PDH key provided through this object. - sev-guest: a top level object to transition a guest into SEV-enabled e.g to launch SEV guest from unencrypted boot images # $QEMU \ -object sev-launch-info,id=launch0 \ -object sev-guest,id=sev0 \ -object security-policy,id=secure0,memory-encryption=sev0 \ -machine ....,security-policy=secure0 Signed-off-by: Brijesh Singh --- Makefile.target | 2 docs/amd-memory-encryption.txt | 121 ++++++++++++++++++++++ include/sysemu/sev.h | 91 ++++++++++++++++ kvm-all.c | 22 ++++ kvm-stub.c | 5 + qemu-options.hx | 27 +++++ sev.c | 225 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 492 insertions(+), 1 deletion(-) create mode 100644 docs/amd-memory-encryption.txt create mode 100644 include/sysemu/sev.h create mode 100644 sev.c diff --git a/Makefile.target b/Makefile.target index 924304c..5150c12 100644 --- a/Makefile.target +++ b/Makefile.target @@ -142,7 +142,7 @@ ifdef CONFIG_SOFTMMU obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o numa.o obj-y += qtest.o bootdevice.o obj-y += hw/ -obj-$(CONFIG_KVM) += kvm-all.o +obj-$(CONFIG_KVM) += kvm-all.o sev.o obj-y += memory.o cputlb.o obj-y += memory_mapping.o obj-y += dump.o diff --git a/docs/amd-memory-encryption.txt b/docs/amd-memory-encryption.txt new file mode 100644 index 0000000..03e31c0 --- /dev/null +++ b/docs/amd-memory-encryption.txt @@ -0,0 +1,121 @@ +Secure Encrypted Virtualization (SEV) is a feature found on AMD processors. + +SEV feature allows the memory contents of a virtual machine (VM) to be +transparently encrypted with a key unique to the guest VM. The memory +controller contains a high performance encryption engine which can be +programmed with multiple keys for used by different VMs in the system. +The programming and management of these keys is handled by the AMD Secure +Processor firmware which exposes commands for these tasks. + +At highest level the SEV key management APIs are divided into two sections: + +* Platform management commands +* Guest management commands + +In this doc we will focus on Guest management commands. + +SEV is capable of supporting both light-weight virtual containers as well as +conventional VM within an enterprise cloud environment. In either case, there +are two parties concerned in the deployment of SEV guest: the guest owner and +the platform owner. For example, in a cloud environment, the platform owner +would be cloud vendor and the guest owner would be the user that wishes to run +their workload in the cloud. + +1. Guest Management Commands +----------------------------- + +The guest management commands provide the support for common guest lifecycle +events. These events include launching, running, snapshotting, migrating and +decommission guest. The guest management commands are issued through +KVM_MEMORY_ENCRYPTION_OPS ioctl. + +1.1 Launch + +When a guest is launched, its memory must first be encrypted using guest owners +key before SEV can be enabled in hardware. There are two types of launches: + +1.1.1 unencrypted + +Boot images (such as bios, kernel, initrd) provided by the guest owner to +bootstrap the guest is unencrypted. The firmware provides interfaces to +bootstrap the memory encryption for this purpose: LAUNCH_START, LAUNCH_UPDATE, +, LAUNCH_MEASURE and LAUNCH_FINISH. These four commands together generate a fresh +memory encryption key for the guest, encrypt guest memory and provide an +attestation of the successful launch. + +LAUNCH_START is called first to create a cryptographic launch context within the +firmware. To create this context, guest owner must provide security policy, +public Diffie-Hellman key (PDH defined in section 12 of SEV key API management) +and session data. If PDH certificate blob is not provided by guest owner then +firmware will auto generate a key and use that key for memory encryption. Guest +owners PDH key is used to establish a cryptographic session with the guest owner +to negotiate keys used for attestation. The guest security policy is a 4-byte +data structure containing several flags that restrict what the hypervisor can do +on the running SEV guest. If the hypervisor requests this guest to share key +with another SEV guest then hypervisor must set 'key-sharing' field in guest +security policy and a shared SEV handle must be provided in LAUNCH_START command. + +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 the +measurement of the memory contents as it encrypts. + +LAUNCH_MEASURE command can be used to retrieve the measurement of encrypted memory. +This measurement is a signature of the memory contents that can be sent to the +guest owner as an attestation that the memory was encrypted correctly by the +firmware. The guest owner may wait to provide the guest confidential information +until it can verify the attestation measurement. Since the guest owner knows the +initial contents of the guest at boot, the attestation measurement can be +verified by comparing it to what the guest owner expects. + +LAUNCH_FINISH command finalizes the guest launch and destory's the cryptographic +context. + +See SEV API Spec [1] 'Launching a guest' usage flow (Appendix A) for the +complete flow chart. + +SEV support can be enabled via 'memory-encryption' parameters defined in +security-policy object. + +Input to LAUNCH_START command can be provided through the properties defined in +'sev-launch-info' object. + +e.g to launch SEV guest from unencrypted boot images + +# ${QEMU} \ + -object sev-launch-info,id=launch0\ + -object sev-guest,id=sev0\ + -object security-policy,id=mypolicy,memory-encryption=sev0\ + -machine ...,security-policy=mypolicy + +1.1.2 pre-encrypted + +1.2 Snapshot + +1.3 Restore + +1.4 Live Migration + +1.5 Debugging + +Since memory contents of SEV guest is encrypted hence hypervisor access to the +guest memory will get a cipher text. If guest policy allows debugging, then +hypervisor can use SEV debug command to decrypt guest memory region for debug +purposes. + +2. References +----------------- + +AMD Memory Encryption whitepaper: +http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_Memory_Encryption_Whitepaper_v7-Public.pdf + +Secure Encrypted Virutualization Key Management: +[1] http://support.amd.com/TechDocs/55766_SEV-KM API_Specification.pdf + +KVM Forum slides: +http://www.linux-kvm.org/images/7/74/02x08A-Thomas_Lendacky-AMDs_Virtualizatoin_Memory_Encryption_Technology.pdf + +AMD64 Architecture Programmer's Manual: + http://support.amd.com/TechDocs/24593.pdf + SME is section 7.10 + SEV is section 15.34 diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h new file mode 100644 index 0000000..dbc3c6c --- /dev/null +++ b/include/sysemu/sev.h @@ -0,0 +1,91 @@ +/* + * QEMU Secure Encrypted Virutualization (SEV) support + * + * Copyright: Advanced Micro Devices, 2016-2017 + * + * 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 + +#include "qom/object.h" +#include "qapi/error.h" +#include "sysemu/kvm.h" + +#define TYPE_QSEV_LAUNCH_INFO "sev-launch-info" +#define QSEV_LAUNCH_INFO(obj) \ + OBJECT_CHECK(QSevLaunchInfo, (obj), TYPE_QSEV_LAUNCH_INFO) + +typedef struct QSevLaunchInfo QSevLaunchInfo; +typedef struct QSevLaunchInfoClass QSevLaunchInfoClass; + +/** + * QSevLaunchInfo: + * + * The QSevLaunchInfo object provides parameters to launch a SEV + * guest from unnencrypted boot images. SEV will encrypt the boot images using + * guest owner's key before launching the guest. + * + * # $QEMU -object sev-launch-info,id=launch0,dh-cert=0000,session=abcd \ + * .... + */ +struct QSevLaunchInfo { + Object parent_obj; +}; + +struct QSevLaunchInfoClass { + ObjectClass parent_class; +}; + +#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. + * + * e.g to launch a SEV guest from unencrypted boot images + * + * # $QEMU -object sev-launch-info,id=launch0 \ + * -object sev-guest,id=sev0,sev-device=/dev/sev \ + * -object security-policy,id=secure0,memory-encryption=sev0 \ + * -machine ...security-policy=secure0 + */ +struct QSevGuestInfo { + Object parent_obj; + + char *sev_device; + + QSevLaunchInfo *launch_info; +}; + +struct QSevGuestInfoClass { + ObjectClass parent_class; +}; + +struct SEVState { + QSevGuestInfo *sev_info; +}; + +typedef struct SEVState SEVState; + + +bool sev_enabled(void); +void *sev_guest_init(const char *keyid); +void sev_set_debug_ops(void *handle, MemoryRegion *mr); + +#endif + diff --git a/kvm-all.c b/kvm-all.c index bba0f39..1fa6413 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -37,6 +37,7 @@ #include "trace-root.h" #include "hw/irq.h" #include "sysemu/security-policy.h" +#include "sysemu/sev.h" #include "hw/boards.h" @@ -1808,6 +1809,27 @@ static int kvm_init(MachineState *ms) kvm_state = s; + if (ms->security_policy) { + char *id; + + /* if security-policy is enabled then check whether memory encryption + * property is defined. If so, enable hardware memory encryption. + */ + id = security_policy_get_memory_encryption_id(ms->security_policy); + if (id) { + + /* check if its SEV guest policy */ + kvm_state->ehandle = sev_guest_init(id); + if (!kvm_state->ehandle) { + fprintf(stderr, + "failed to initialize SEV guest\n"); + goto err; + } + kvm_state->memcrypt_debug_ops = sev_set_debug_ops; + g_free(id); + } + } + if (kvm_eventfds_allowed) { s->memory_listener.listener.eventfd_add = kvm_mem_ioeventfd_add; s->memory_listener.listener.eventfd_del = kvm_mem_ioeventfd_del; diff --git a/kvm-stub.c b/kvm-stub.c index 20920aa..1a9838d 100644 --- a/kvm-stub.c +++ b/kvm-stub.c @@ -14,6 +14,7 @@ #include "qemu-common.h" #include "cpu.h" #include "sysemu/kvm.h" +#include "sysemu/sev.h" #ifndef CONFIG_USER_ONLY #include "hw/pci/msi.h" @@ -135,6 +136,10 @@ int kvm_memcrypt_encrypt_launch_data(uint8_t *ptr, uint64_t len) return 1; } +bool sev_enabled(void) +{ + return false; +} #ifndef CONFIG_USER_ONLY int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) diff --git a/qemu-options.hx b/qemu-options.hx index 536db1b..2b2d8c3 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4161,6 +4161,33 @@ can be set to the unquie ID of memory encryption object. On AMD processor, memory encryption is supported via 'sev-guest' object. +@item -object sev-guest,id=@var{id},sev-device=@var{string} + +Create a Secure Encrypted Virtualization (SEV) guest object, which be used to +provide the memory encryption support on AMD processors. + +e.g to launch a SEV guest +@example + # $QEMU \ + -object sev-launch-info,id=launch0,sev-device=/dev/sev0 \ + -object sev-guest-info,id=sev0 \ + -object security-policy,id=secure0-guest,memory-encryption=sev0 \ + -machine ...,security-policy=secure0 +@end example + +@item -object sev-launch-info,id=@var{id} + +Create a SEV launch info object, which can be used to pass various parameters +required to boot SEV guest from unencrypted boot images. +The id parameter is a unique ID that should be used in sev-guest-info object +when creating a unencrypted SEV guest. + +e.g to launch SEV guest from unencrypted boot images +@example + # $QEMU \ + -object sev-launch-info,id=launch0\ + -object sev-guest,id=sev0 \ +@end example ETEXI diff --git a/sev.c b/sev.c new file mode 100644 index 0000000..3e02453 --- /dev/null +++ b/sev.c @@ -0,0 +1,225 @@ +/* + * QEMU SEV support + * + * Copyright Advanced Micro Devices 2016-2017 + * + * Author: + * 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. + * + */ + +#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" +#include "trace.h" + +#define DEBUG_SEV +#ifdef DEBUG_SEV +#define DPRINTF(fmt, ...) \ + do { fprintf(stdout, fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) \ + do { } while (0) +#endif + +#define DEFAULT_SEV_DEVICE "/dev/sev1" + +static MemoryRegionRAMReadWriteOps sev_ops; +static bool sev_allowed; +static int sev_fd; + +static void +qsev_guest_finalize(Object *obj) +{ +} + +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", + "device to use for SEV command", NULL); +} + +static QSevGuestInfo * +lookup_sev_guest_info(const char *id) +{ + Object *obj; + QSevGuestInfo *info; + + obj = object_resolve_path_component( + object_get_objects_root(), id); + if (!obj) { + return NULL; + } + + info = (QSevGuestInfo *) + object_dynamic_cast(obj, TYPE_QSEV_GUEST_INFO); + if (!info) { + return NULL; + } + + return info; +} + +static void +qsev_guest_init(Object *obj) +{ + QSevGuestInfo *sev = QSEV_GUEST_INFO(obj); + + object_property_add_link(obj, "launch", TYPE_QSEV_LAUNCH_INFO, + (Object **)&sev->launch_info, + object_property_allow_set_link, + OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL); + + sev->sev_device = g_strdup(DEFAULT_SEV_DEVICE); +} + +/* 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 +qsev_launch_finalize(Object *obj) +{ +} + +static void +qsev_launch_class_init(ObjectClass *oc, void *data) +{ + /* add launch properties */ +} + +static void +qsev_launch_init(Object *obj) +{ +} + +/* guest launch */ +static const TypeInfo qsev_launch_info = { + .parent = TYPE_OBJECT, + .name = TYPE_QSEV_LAUNCH_INFO, + .instance_size = sizeof(QSevLaunchInfo), + .instance_finalize = qsev_launch_finalize, + .class_size = sizeof(QSevLaunchInfoClass), + .class_init = qsev_launch_class_init, + .instance_init = qsev_launch_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static int +sev_mem_write(uint8_t *dst, const uint8_t *src, uint32_t len, MemTxAttrs attrs) +{ + return 0; +} + +static int +sev_mem_read(uint8_t *dst, const uint8_t *src, uint32_t len, MemTxAttrs attrs) +{ + return 0; +} + +void * +sev_guest_init(const char *id) +{ + Object *obj; + SEVState *s; + char *sev_device_name; + + s = g_malloc0(sizeof(SEVState)); + if (!s) { + return NULL; + } + + s->sev_info = lookup_sev_guest_info(id); + if (!s->sev_info) { + fprintf(stderr, "'%s' not a valid '%s' object\n", + id, TYPE_QSEV_GUEST_INFO); + goto err; + } + + sev_device_name = object_property_get_str(OBJECT(s->sev_info), + "sev-device", NULL); + sev_fd = open(sev_device_name, O_RDWR); + if (sev_fd < 0) { + fprintf(stderr, "%s:%s\n", sev_device_name, strerror(errno)); + goto err; + } + g_free(sev_device_name); + + obj = object_resolve_path_type("", TYPE_QSEV_LAUNCH_INFO, NULL); + if (obj) { + object_property_set_link(OBJECT(s->sev_info), obj, "launch", + &error_abort); + } + + sev_allowed = true; + return s; +err: + g_free(s); + return NULL; +} + +void +sev_set_debug_ops(void *handle, MemoryRegion *mr) +{ + sev_ops.read = sev_mem_read; + sev_ops.write = sev_mem_write; + + memory_region_set_ram_debug_ops(mr, &sev_ops); +} + +bool +sev_enabled(void) +{ + return sev_allowed; +} + +static void +sev_policy_register_types(void) +{ + type_register_static(&qsev_guest_info); + type_register_static(&qsev_launch_info); +} + +type_init(sev_policy_register_types);