From nobody Fri Dec 19 20:34:44 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1630017201; cv=pass; d=zohomail.com; s=zohoarc; b=PCFJ0gOauo5OxZAWVscufx9JWOHhl9bQu3h0luTMCeBBCQGg5k2zCjcEYCq4Deqn/hWKxa40Ci9S3rKB/N3oIEYjG5tlvkSHklaWdUq6AciJqCBfeVsZhb8A3uOc5QcapWm9WXO/Azz2waFSarY/RpJU120ttHeg5sCdOr7ITDY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630017201; 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=HV7v0NmLhzPtEFGMzP5rFBe6CQyNABf3k+MF8AZqoyA=; b=l8SxeTCW0r8UXt6FIGEZzW7luXMAyTAouanmhCGvua+3+LMuwr71uId+V+j6PQ945ymsbZYbvDQO+RjtUYA+9YEHuq8JdyWlLPr99RMWO7BkV4UHpyJtcMpreH3zM1U2IbDpD5z1MM/DfXrfXBsvjaXmj8z6l4WXCdHSZ4673qc= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630017201447172.6227400996073; Thu, 26 Aug 2021 15:33:21 -0700 (PDT) Received: from localhost ([::1]:50308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJNw0-0002pi-EC for importer@patchew.org; Thu, 26 Aug 2021 18:33:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJNqS-0000n9-Ir for qemu-devel@nongnu.org; Thu, 26 Aug 2021 18:27:36 -0400 Received: from mail-bn8nam12hn2249.outbound.protection.outlook.com ([52.100.165.249]:63574 helo=NAM12-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJNqO-0005Vm-Bg for qemu-devel@nongnu.org; Thu, 26 Aug 2021 18:27:36 -0400 Received: from CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) by CH2PR12MB3925.namprd12.prod.outlook.com (2603:10b6:610:21::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Thu, 26 Aug 2021 22:27:19 +0000 Received: from CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::d19e:b657:5259:24d0]) by CH2PR12MB4133.namprd12.prod.outlook.com ([fe80::d19e:b657:5259:24d0%8]) with mapi id 15.20.4436.019; Thu, 26 Aug 2021 22:27:19 +0000 Received: from localhost (165.204.77.1) by SA9P221CA0003.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.21 via Frontend Transport; Thu, 26 Aug 2021 22:27:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bWYTN6xLON8vWjQDWxRFwtGaf0y/dIVZsdsZOrewHcLctQMqqtimDs5N9PWRsYLQiKiC47rZu2lbJCYJ52mWeeXhgNBtFzJQvp0PmOJrvtxEgB/DyXiUo4jyVTHYUrB/wKPXC8MYGgNV+bRb/0H+CdOWksZCED2p7AnFAj+k4QwQhasSKiAKrRzuifn/pfDh2/Lb6ipGY0+2SNiJ5N6mHLwlquuA6fpx2m39bvU8eJRgKs4hUfZZK3os7K9DO8ksGz+2n9VF2cDMTr3mlKfpslp0xZmdDic/V37LEvUyNyRYzfDML3EuAxo3/x3aOpNcLLgjSiwoHHX8M0BNZunHzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HV7v0NmLhzPtEFGMzP5rFBe6CQyNABf3k+MF8AZqoyA=; b=R84kpH9UjFC6u3XA3x57zUGA4Cxki/H8Ez9iljqk5hTmUM5Lvzq57IfeknC0R9BSP9NFauQGa5zJgR1Ea/m0y72TUhvQdwo4cwflSB1vJ4bWKC5b+97937bPNfOetIb+7z9eUFE5FV8333CU+w14LPcNe3ID2lSOfoh3hiBfDR1xx5m+6PE9Mkej0quJ9KW7dUu/OEsmVY6wRiTsD3ILjCXArx2AdRrwoYx2gtwwLZZraw13F/iNQ72022oT6U+Au5AQvU/YmD0uO+HAad90iFx4oRqbT9SgaX47ULv2zId1CXM9p0Dqljrz35L6nSZiidVS7AiSdkXQv5Yhmj5QYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HV7v0NmLhzPtEFGMzP5rFBe6CQyNABf3k+MF8AZqoyA=; b=Xoj1wjdFBAcNfZsh4rnQCL0MAWhFK58HxX2opWXO5rYsIOElq7ffZxvu4io/T99n3ZTrJ0JfcV+qs+L8DLBwYV16rkElEweMBqfdUn7EtrYMmqnJ9DnnoUXZBgMUrX6kyP3UE6oqebYccagLocDzvmsgif9yJTzJPAhoV6ha75Y= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; From: Michael Roth To: qemu-devel@nongnu.org Cc: Connor Kuehl , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S . Tsirkin" , James Bottomley , "Dr . David Alan Gilbert" , Tom Lendacky , Paolo Bonzini , Dov Murik , David Gibson , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , kvm@vger.kernel.org, Eduardo Habkost , Brijesh Singh , Markus Armbruster , Eric Blake Subject: [RFC PATCH v2 03/12] i386/sev: introduce 'sev-snp-guest' object Date: Thu, 26 Aug 2021 17:26:18 -0500 Message-Id: <20210826222627.3556-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210826222627.3556-1-michael.roth@amd.com> References: <20210826222627.3556-1-michael.roth@amd.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SA9P221CA0003.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::8) To CH2PR12MB4133.namprd12.prod.outlook.com (2603:10b6:610:7a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21bf55d1-ce56-42c8-06c8-08d968e0aac4 X-MS-TrafficTypeDiagnostic: CH2PR12MB3925: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?kBmCEaAkZ7L+2a7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bFq+a5zD7/3n?= =?us-ascii?Q?gCE9aaDbOoisE+lz4xAHMuR2dcDBpuObgHEy6UpjM3Gi7X7hi6wznjJGmKPP?= =?us-ascii?Q?Jd8JvQOIMG3gsjuNdDkio/AN9y2MMtC9yg1Gnq06Xsiz1wEAzzWZHO4bsjI0?= =?us-ascii?Q?3Ow83Et1XFL6f9mgMO7zprOpHZqk30ky9vS+JAocALsubPY=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:5; SRV:; IPV:NLI; SFV:SPM; H:CH2PR12MB4133.namprd12.prod.outlook.com; PTR:; CAT:OSPM; SFS:(4636009)(376002)(396003)(346002)(136003)(39860400002)(366004)(8676002)(38350700002)(66476007)(38100700002)(956004)(2616005)(66556008)(83380400001)(186003)(30864003)(6916009)(478600001)(36756003)(316002)(4326008)(44832011)(54906003)(66946007)(52116002)(6496006)(2906002)(86362001)(1076003)(6486002)(5660300002)(7416002)(8936002)(26005)(23200700001); DIR:OUT; SFP:1501; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?LjQ5/5nmPQE4r/z9m6AE7O4Mz/F72gA1aRiJxoRrlc7T/SSWjgLavKn9ZOyl?= =?us-ascii?Q?YUXqR4u9FBJYEy+jBbEqPnuXkpUD6DjJp03iY2lWjrmHp/LCgx+EPQRLWndH?= =?us-ascii?Q?xs2E0rHq+am7nGqtXSIfTiEhjJnqmByokz5pGYVXKp6cFX5DfHGqdwDyEb3v?= =?us-ascii?Q?EL2p98XlEttWRPAQWihcQ+HZbkkT++rMCeY8yVUiihhU2y6M0d1/Gc8oJORu?= =?us-ascii?Q?TKertK6vtbGUCMaHtAwT7uJ0WD6+iywm1Sy34NbwSLcWep+5saSbZnOJmM/o?= =?us-ascii?Q?Wux8suZTqrWHPd5DWBS5VvSLle4uhEjuz+H07u7ir6raKrntI6/iNu8zbpE0?= =?us-ascii?Q?MOt9LkB/VWWT2+H6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?Ne6PPJNBvwXAOUvkhIEcprbkxC9ifcnijw/3XkHD3VZohpnAFjaLhiSviaEX?= =?us-ascii?Q?R8GxezS7COvkucu8ynBnTfls?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21bf55d1-ce56-42c8-06c8-08d968e0aac4 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4133.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2021 22:27:19.8155 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z3gzyGPDKyluR+aeoazTi21a7Tt88iQL5fnSO5NyWhdPY326Cbi/XkMC5UyY9LJecKJcOBVN8Y/hcCq5ez3OCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3925 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: softfail client-ip=52.100.165.249; envelope-from=Michael.Roth@amd.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1630017203441100001 Content-Type: text/plain; charset="utf-8" From: Brijesh Singh SEV-SNP support relies on a different set of properties/state than the existing 'sev-guest' object. This patch introduces the 'sev-snp-guest' object, which can be used to configure an SEV-SNP guest. For example, a default-configured SEV-SNP guest with no additional information passed in for use with attestation: -object sev-snp-guest,id=3Dsev0 or a fully-specified SEV-SNP guest where all spec-defined binary blobs are passed in as base64-encoded strings: -object sev-snp-guest,id=3Dsev0, \ policy=3D0x30000, \ init-flags=3D0, \ id-block=3DYWFhYWFhYWFhYWFhYWFhCg=3D=3D, \ id-auth=3DCxHK/OKLkXGn/KpAC7Wl1FSiisWDbGTEKz..., \ auth-key-enabled=3Don, \ host-data=3DLNkCWBRC5CcdGXirbNUV1OrsR28s..., \ guest-visible-workarounds=3DAA=3D=3D, \ See the QAPI schema updates included in this patch for more usage details. In some cases these blobs may be up to 4096 characters, but this is generally well below the default limit for linux hosts where command-line sizes are defined by the sysconf-configurable ARG_MAX value, which defaults to 2097152 characters for Ubuntu hosts, for example. Co-developed-by: Michael Roth Signed-off-by: Brijesh Singh Signed-off-by: Michael Roth Acked-by: Markus Armbruster --- docs/amd-memory-encryption.txt | 77 ++++++++++- qapi/qom.json | 60 ++++++++ target/i386/sev.c | 245 ++++++++++++++++++++++++++++++++- 3 files changed, 379 insertions(+), 3 deletions(-) diff --git a/docs/amd-memory-encryption.txt b/docs/amd-memory-encryption.txt index ffca382b5f..0d82e67fa1 100644 --- a/docs/amd-memory-encryption.txt +++ b/docs/amd-memory-encryption.txt @@ -22,8 +22,8 @@ support for notifying a guest's operating system when cer= tain types of VMEXITs are about to occur. This allows the guest to selectively share information= with the hypervisor to satisfy the requested function. =20 -Launching ---------- +Launching (SEV and SEV-ES) +-------------------------- Boot images (such as bios) must be encrypted before a guest can be booted.= The MEMORY_ENCRYPT_OP ioctl provides commands to encrypt the images: LAUNCH_ST= ART, LAUNCH_UPDATE_DATA, LAUNCH_MEASURE and LAUNCH_FINISH. These four commands @@ -113,6 +113,79 @@ a SEV-ES guest: - Requires in-kernel irqchip - the burden is placed on the hypervisor to manage booting APs. =20 +Launching (SEV-SNP) +------------------- +Boot images (such as bios) must be encrypted before a guest can be booted.= The +MEMORY_ENCRYPT_OP ioctl provides commands to encrypt the images: +KVM_SNP_INIT, SNP_LAUNCH_START, SNP_LAUNCH_UPDATE, and SNP_LAUNCH_FINISH. = These +four commands together generate a fresh memory encryption key for the VM, +encrypt the boot images for a successful launch. + +KVM_SNP_INIT is called first to initialize the SEV-SNP firmware and SNP +features in the KVM. The feature flags value can be provided through the +'init-flags' property of the 'sev-snp-guest' object. + ++------------+-------+----------+---------------------------------+ +| key | type | default | meaning | ++------------+-------+----------+---------------------------------+ +| init_flags | hex | 0 | SNP feature flags | ++-----------------------------------------------------------------+ + +Note: currently the init_flags must be zero. + +SNP_LAUNCH_START is called first to create a cryptographic launch context +within the firmware. To create this context, guest owner must provide a gu= est +policy and other parameters as described in the SEV-SNP firmware +specification. The launch parameters should be specified as described in t= he +QAPI schema for the 'sev-snp-guest' object. + +The SNP_LAUNCH_START uses the following parameters (see the SEV-SNP +specification for more details): + ++--------+-------+----------+---------------------------------------------= -+ +| key | type | default | meaning = | ++--------+-------+----------+---------------------------------------------= -+ +| policy | hex | 0x30000 | a 64-bit guest policy = | +| imi_en | bool | 0 | 1 when IMI is enabled = | +| ma_end | bool | 0 | 1 when migration agent is used = | +| gosvw | string| 0 | 16-byte base64 encoded string for the guest = | +| | | | OS visible workaround. = | ++--------+-------+----------+---------------------------------------------= -+ + +SNP_LAUNCH_UPDATE encrypts the memory region using the cryptographic conte= xt +created via the SNP_LAUNCH_START command. If required, this command can be= called +multiple times to encrypt different memory regions. The command also calcu= lates +the measurement of the memory contents as it encrypts. + +SNP_LAUNCH_FINISH finalizes the guest launch flow. Optionally, while final= izing +the launch the firmware can perform checks on the launch digest computing +through the SNP_LAUNCH_UPDATE. To perform the check the user must supply +the id block, authentication blob and host data that should be included in= the +attestation report. See the SEV-SNP spec for further details. + +The SNP_LAUNCH_FINISH uses the following parameters, which can be configur= ed +by the corresponding parameters documented in the QAPI schema for the +'sev-snp-guest' object. + ++------------+-------+----------+-----------------------------------------= -----+ +| key | type | default | meaning = | ++------------+-------+----------+-----------------------------------------= -----+ +| id_block | string| none | base64 encoded ID block = | ++------------+-------+----------+-----------------------------------------= -----+ +| id_auth | string| none | base64 encoded authentication informatio= n | ++------------+-------+----------+-----------------------------------------= -----+ +| auth_key_en| bool | 0 | auth block contains author key = | ++------------+-------+----------+-----------------------------------------= -----+ +| host_data | string| none | host provided data = | ++------------+-------+----------+-----------------------------------------= -----+ + +To launch a SEV-SNP guest (additional parameters are documented in the QAPI +schema for the 'sev-snp-guest' object): + +# ${QEMU} \ + -machine ...,confidential-guest-support=3Dsev0 \ + -object sev-snp-guest,id=3Dsev0,cbitpos=3D51,reduced-phys-bits=3D1 + Debugging ----------- Since the memory contents of a SEV guest are encrypted, hypervisor access = to diff --git a/qapi/qom.json b/qapi/qom.json index 211e083727..ea39585026 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -775,6 +775,64 @@ '*policy': 'uint32', '*handle': 'uint32' } } =20 +## +# @SevSnpGuestProperties: +# +# Properties for sev-snp-guest objects. Many of these are direct arguments +# for the SEV-SNP KVM interfaces documented in the linux kernel source +# documentation under 'amd-memory-encryption.rst'. Additional documentation +# is also available in the QEMU source tree under +# 'amd-memory-encryption.rst'. +# +# In addition to those files, please see the SEV-SNP Firmware Specification +# (Rev 0.9) documentation for the SNP_INIT and +# SNP_LAUNCH_{START,UPDATE,FINISH} firmware interfaces, which the KVM +# interfaces are written against. +# +# @init-flags: as documented for the 'flags' parameter of the +# KVM_SNP_INIT KVM command (default: 0) +# +# @policy: as documented for the 'policy' parameter of the +# KVM_SNP_LAUNCH_START KVM command (default: 0x30000) +# +# @guest-visible-workarounds: 16-byte, base64-encoded blob to report +# hypervisor-defined workarounds, as documented +# for the 'gosvm' parameter of the +# KVM_SNP_LAUNCH_START KVM command. +# (default: all-zero) +# +# @id-block: 8-byte, base64-encoded blob to provide the ID Block +# structure documented in SEV-SNP spec, as documented for the +# 'id_block_uaddr' parameter of the KVM_SNP_LAUNCH_FINISH +# command (default: all-zero) +# +# @id-auth: 4096-byte, base64-encoded blob to provide the ID Authentication +# Information Structure documented in SEV-SNP spec, as documented +# for the 'id_auth_uaddr' parameter of the KVM_SNP_LAUNCH_FINISH +# command (default: all-zero) +# +# @auth-key-enabled: true if 'id-auth' blob contains the Author Key +# documented in the SEV-SNP spec, as documented for the +# 'auth_key_en' parameter of the KVM_SNP_LAUNCH_FINISH +# command (default: false) +# +# @host-data: 32-byte, base64-encoded user-defined blob to provide to the +# guest, as documented for the 'host_data' parameter of the +# KVM_SNP_LAUNCH_FINISH command (default: all-zero) +# +# Since: 6.2 +## +{ 'struct': 'SevSnpGuestProperties', + 'base': 'SevCommonProperties', + 'data': { + '*init-flags': 'uint64', + '*policy': 'uint64', + '*guest-visible-workarounds': 'str', + '*id-block': 'str', + '*id-auth': 'str', + '*auth-key-enabled': 'bool', + '*host-data': 'str' } } + ## # @ObjectType: # @@ -816,6 +874,7 @@ 'secret', 'secret_keyring', 'sev-guest', + 'sev-snp-guest', 's390-pv-guest', 'throttle-group', 'tls-creds-anon', @@ -873,6 +932,7 @@ 'secret': 'SecretProperties', 'secret_keyring': 'SecretKeyringProperties', 'sev-guest': 'SevGuestProperties', + 'sev-snp-guest': 'SevSnpGuestProperties', 'throttle-group': 'ThrottleGroupProperties', 'tls-creds-anon': 'TlsCredsAnonProperties', 'tls-creds-psk': 'TlsCredsPskProperties', diff --git a/target/i386/sev.c b/target/i386/sev.c index 6acebfbd53..ba08b7d3ab 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -38,7 +38,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(SevCommonState, SEV_COMMON) #define TYPE_SEV_GUEST "sev-guest" OBJECT_DECLARE_SIMPLE_TYPE(SevGuestState, SEV_GUEST) - +#define TYPE_SEV_SNP_GUEST "sev-snp-guest" +OBJECT_DECLARE_SIMPLE_TYPE(SevSnpGuestState, SEV_SNP_GUEST) =20 /** * SevGuestState: @@ -82,8 +83,23 @@ struct SevGuestState { char *session_file; }; =20 +struct SevSnpGuestState { + SevCommonState sev_common; + + /* configuration parameters */ + char *guest_visible_workarounds; + char *id_block; + char *id_auth; + char *host_data; + + struct kvm_snp_init kvm_init_conf; + struct kvm_sev_snp_launch_start kvm_start_conf; + struct kvm_sev_snp_launch_finish kvm_finish_conf; +}; + #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" +#define DEFAULT_SEV_SNP_POLICY 0x30000 =20 #define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e" typedef struct __attribute__((__packed__)) SevInfoBlock { @@ -364,6 +380,232 @@ static const TypeInfo sev_guest_info =3D { .class_init =3D sev_guest_class_init, }; =20 +static void +sev_snp_guest_get_init_flags(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint64(v, name, + (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_init_conf.flags, + errp); +} + +static void +sev_snp_guest_set_init_flags(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint64(v, name, + (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_init_conf.flags, + errp); +} + +static void +sev_snp_guest_get_policy(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint64(v, name, + (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_start_conf.poli= cy, + errp); +} + +static void +sev_snp_guest_set_policy(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint64(v, name, + (uint64_t *)&SEV_SNP_GUEST(obj)->kvm_start_conf.poli= cy, + errp); +} + +static char * +sev_snp_guest_get_guest_visible_workarounds(Object *obj, Error **errp) +{ + return g_strdup(SEV_SNP_GUEST(obj)->guest_visible_workarounds); +} + +static void +sev_snp_guest_set_guest_visible_workarounds(Object *obj, const char *value, + Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + struct kvm_sev_snp_launch_start *start =3D &sev_snp_guest->kvm_start_c= onf; + g_autofree guchar *blob; + gsize len; + + if (sev_snp_guest->guest_visible_workarounds) { + g_free(sev_snp_guest->guest_visible_workarounds); + } + + /* store the base64 str so we don't need to re-encode in getter */ + sev_snp_guest->guest_visible_workarounds =3D g_strdup(value); + + blob =3D g_base64_decode(sev_snp_guest->guest_visible_workarounds, &le= n); + if (len > sizeof(start->gosvw)) { + error_setg(errp, "parameter length of %lu exceeds max of %lu", + len, sizeof(start->gosvw)); + return; + } + + memcpy(start->gosvw, blob, len); +} + +static char * +sev_snp_guest_get_id_block(Object *obj, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + + return g_strdup(sev_snp_guest->id_block); +} + +static void +sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + struct kvm_sev_snp_launch_finish *finish =3D &sev_snp_guest->kvm_finis= h_conf; + gsize len; + + if (sev_snp_guest->id_block) { + g_free(sev_snp_guest->id_block); + g_free((guchar *)finish->id_block_uaddr); + } + + /* store the base64 str so we don't need to re-encode in getter */ + sev_snp_guest->id_block =3D g_strdup(value); + + finish->id_block_uaddr =3D (uint64_t)g_base64_decode(sev_snp_guest->id= _block, &len); + if (len > KVM_SEV_SNP_ID_BLOCK_SIZE) { + error_setg(errp, "parameter length of %lu exceeds max of %u", + len, KVM_SEV_SNP_ID_BLOCK_SIZE); + return; + } + finish->id_block_en =3D 1; +} + +static char * +sev_snp_guest_get_id_auth(Object *obj, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + + return g_strdup(sev_snp_guest->id_auth); +} + +static void +sev_snp_guest_set_id_auth(Object *obj, const char *value, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + struct kvm_sev_snp_launch_finish *finish =3D &sev_snp_guest->kvm_finis= h_conf; + gsize len; + + if (sev_snp_guest->id_auth) { + g_free(sev_snp_guest->id_auth); + g_free((guchar *)finish->id_auth_uaddr); + } + + /* store the base64 str so we don't need to re-encode in getter */ + sev_snp_guest->id_auth =3D g_strdup(value); + + finish->id_auth_uaddr =3D (uint64_t)g_base64_decode(sev_snp_guest->id_= auth, &len); + if (len > KVM_SEV_SNP_ID_AUTH_SIZE) { + error_setg(errp, "parameter length of %lu exceeds max of %u", + len, KVM_SEV_SNP_ID_AUTH_SIZE); + return; + } +} + +static bool +sev_snp_guest_get_auth_key_en(Object *obj, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + + return !!sev_snp_guest->kvm_finish_conf.auth_key_en; +} + +static void +sev_snp_guest_set_auth_key_en(Object *obj, bool value, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + + sev_snp_guest->kvm_finish_conf.auth_key_en =3D value; +} + +static char * +sev_snp_guest_get_host_data(Object *obj, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + + return g_strdup(sev_snp_guest->host_data); +} + +static void +sev_snp_guest_set_host_data(Object *obj, const char *value, Error **errp) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + struct kvm_sev_snp_launch_finish *finish =3D &sev_snp_guest->kvm_finis= h_conf; + g_autofree guchar *blob; + gsize len; + + if (sev_snp_guest->host_data) { + g_free(sev_snp_guest->host_data); + } + + /* store the base64 str so we don't need to re-encode in getter */ + sev_snp_guest->host_data =3D g_strdup(value); + + blob =3D g_base64_decode(sev_snp_guest->host_data, &len); + if (len > sizeof(finish->host_data)) { + error_setg(errp, "parameter length of %lu exceeds max of %lu", + len, sizeof(finish->host_data)); + return; + } + + memcpy(finish->host_data, blob, len); +} + +static void +sev_snp_guest_class_init(ObjectClass *oc, void *data) +{ + object_class_property_add(oc, "init-flags", "uint64", + sev_snp_guest_get_init_flags, + sev_snp_guest_set_init_flags, NULL, NULL); + object_class_property_set_description(oc, "init-flags", + "guest initialization flags"); + object_class_property_add(oc, "policy", "uint64", + sev_snp_guest_get_policy, + sev_snp_guest_set_policy, NULL, NULL); + object_class_property_add_str(oc, "guest-visible-workarounds", + sev_snp_guest_get_guest_visible_workarou= nds, + sev_snp_guest_set_guest_visible_workarou= nds); + object_class_property_add_str(oc, "id-block", + sev_snp_guest_get_id_block, + sev_snp_guest_set_id_block); + object_class_property_add_str(oc, "id-auth", + sev_snp_guest_get_id_auth, + sev_snp_guest_set_id_auth); + object_class_property_add_bool(oc, "auth-key-enabled", + sev_snp_guest_get_auth_key_en, + sev_snp_guest_set_auth_key_en); + object_class_property_add_str(oc, "host-data", + sev_snp_guest_get_host_data, + sev_snp_guest_set_host_data); +} + +static void +sev_snp_guest_instance_init(Object *obj) +{ + SevSnpGuestState *sev_snp_guest =3D SEV_SNP_GUEST(obj); + + /* default init/start/finish params for kvm */ + sev_snp_guest->kvm_start_conf.policy =3D DEFAULT_SEV_SNP_POLICY; +} + +/* guest info specific to sev-snp */ +static const TypeInfo sev_snp_guest_info =3D { + .parent =3D TYPE_SEV_COMMON, + .name =3D TYPE_SEV_SNP_GUEST, + .instance_size =3D sizeof(SevSnpGuestState), + .class_init =3D sev_snp_guest_class_init, + .instance_init =3D sev_snp_guest_instance_init, +}; + bool sev_enabled(void) { @@ -1136,6 +1378,7 @@ sev_register_types(void) { type_register_static(&sev_common_info); type_register_static(&sev_guest_info); + type_register_static(&sev_snp_guest_info); } =20 type_init(sev_register_types); --=20 2.25.1