From patchwork Thu Feb 15 15:39:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10222137 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 D3D52602CB for ; Thu, 15 Feb 2018 15:57:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C42CD2890E for ; Thu, 15 Feb 2018 15:57:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B834B2896D; Thu, 15 Feb 2018 15:57:32 +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=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 89C9A2890E for ; Thu, 15 Feb 2018 15:57:31 +0000 (UTC) Received: from localhost ([::1]:32906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emLuc-0005Am-NX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Feb 2018 10:57:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emLeY-0004NG-Am for qemu-devel@nongnu.org; Thu, 15 Feb 2018 10:40:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emLeS-0003Xa-G8 for qemu-devel@nongnu.org; Thu, 15 Feb 2018 10:40:54 -0500 Received: from mail-bn3nam01on0086.outbound.protection.outlook.com ([104.47.33.86]:15748 helo=NAM01-BN3-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 1emLeS-0003XN-9q for qemu-devel@nongnu.org; Thu, 15 Feb 2018 10:40:48 -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=L4DdoriXEEzXzafN00aXHcLZDcEXRXfJAwr0HN04PlE=; b=Q6xBmW5Rmgz9P/e+bXzdIR5gaW9HR0b2ZvSh6zHP0mDzm7AnW6T8QgfcShOyPKOvDhth32PMYUlDFbQYxZAlBOY9/f9trsWKM9Ep3auMTCBLdqMONIbjqMego/qhZHEA4vY/Mmwhg+Vnk4o0tiH+vqEujCHMtVjhm9TFUlXTfOg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by SN1PR12MB0157.namprd12.prod.outlook.com (10.162.3.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Thu, 15 Feb 2018 15:40:44 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Thu, 15 Feb 2018 09:39:39 -0600 Message-Id: <20180215153955.3253-14-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180215153955.3253-1-brijesh.singh@amd.com> References: <20180215153955.3253-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: CY4PR04CA0044.namprd04.prod.outlook.com (10.172.133.30) To SN1PR12MB0157.namprd12.prod.outlook.com (10.162.3.144) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cca44119-f18e-442b-9185-08d5748a7abd X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:SN1PR12MB0157; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 3:LGsdHGKWRqVnRYLCPXUa4AGa6jHBiiryvmNjS+lMw37u6lZ1AXotYSDocWpZv6RAxKbT7SXWfgDbdaJ0P83ROjYoGHcfTZPTBzPkSxyHJ+itGmBIuCnnIumq4k0oTt21TtWhBIFi0lE7u9Sp7z4daty0i1qtpoIB51D5w0u2Lc3PmHTtdSjM8wMUBl8IVCEZICz0RN0yvE3I86d/ukzupyE8FaFaNTfmGARDKIhPP2ao8joHsZdKQJzBUdI/nGqo; 25:e4RZSyskF4W2RI3h6MOhcFroupVi7PBQA16ZB4ZCyy/rzkYXH8P5Rdi1j4DmnzfAY+PhlNabKg5hYsywQBrIlzA+2GDO/dtkfieycZavMBBt6c1GvAhyDVbSYwxq+P5hQFpozGX05QRd9cBop14Uedwv1Y9LDGeS1u93F0xyy9OTj0hwC/aGjvI8kA5izlVj+SFJJtSMWMuDNQDS+7poPkinGAK8dwbowHA4Sq9XG6L3TWw2mvuT1A0S1Wu+mRO+0/61N2eb/pskn+nyG5FLkCjQmmp/fIu4bKvYc9VKdbStCLsW5TXcyMOMqvZu0tSd2+ymk2vIGEq1j1iM2HMWCA==; 31:PkStOvB2hjMxv5IApyZ3ocVZ4Dc/D5uz5S+8qMvoBfIf9mdbP62FHidueXSyQ/az+1uTgR5pNUVwhLhbB+ihNu0e8KWs7Jei+BFmIb/Dm6ddc7qAWVCdiIHpdpzWzpkZeS1XaabAe8adpo6IfE2YRJDnUhcM+BDEdTuTK8cXLQera6kWpy3zopmRYoA2vidAQ8ZD1Qqece5xgBMn/y8Dt1zWXZ5XjkH58bYc22Mh8fs= X-MS-TrafficTypeDiagnostic: SN1PR12MB0157: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 20:QSRlg6kjyaEG4tFDOatwHmjB4RShoJRtIxp4ux2FDlWpUHUGG7BMX/bgv8/Dxa8CezVPoMCGispWf16SQ5tG3n1YhPErglWdJ8ABhIC6J83ZXy1UceG2Zm5gSQUDpdZiMX0ntlz0mFTHRzQ3Iudg4HwJlLtolZJXmAH0BpE/BQVly3heIEUbIbwh5jMmnibMzeWvawCcX6dzJgrvnLPerAEy4IhSNq+B6snrOY+M1X6c9rv/DMVAJmyYGbJFUUFJlQ39i/aHGPJLi/xNm+01JvmtSGtE6BAan3RT4H9j2BCPvsMbyDK7yQ/twuj0Lmoc6CC4go8KtNoWVZJbOgW744JTkRdfkJ2/Upqy2bWQ4UTkXCRT/yk9pXzQhYX2mrWqJjGxFWqUYirrAZb1ut7o59p+HATsS/HXD7XCdrOF0Ct+cSHNhRTUPM3WmQ7uhCzi0Ggd7WAHC8nkCoWdrHlSdc+N+99iSYtI2R9VwdX5LXliU4aolTcVZNrdEN2IzUdp; 4:FRTIWqd1A/7M4ui9oj06+H4GjFNn2tuqO88wcdOeVcBCRFpfqtoHBff1/Dm2uspluFaUZiToW86y1eFahl2QLFuPA1dC+nxjkhFUuPhjb7HEO4pH+IhoFKxZ95E3i4GlgV01blVFXzCxdP7Nwhd4bsY72Sc7rf6wnoPCVgo2QVxp2PNivHZxG1Y56fjbme/cSaCtaMQrYGwoJTwmqlfNoegYtkZHWbEBk7rHjhhaEdD+GLXRQ06Xr58NipS2IeREoFhWhNA5Tcj9a72PzPdlneofOPQN6fuPY/XszeeUKZmSwLQldUtniQa2oh5WJwnzC8TBgLEx/bgP3dZbKctHjg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231101)(944501161)(6055026)(6041288)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:SN1PR12MB0157; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0157; X-Forefront-PRVS: 058441C12A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(1496009)(376002)(39380400002)(346002)(396003)(39860400002)(366004)(189003)(199004)(26005)(3846002)(386003)(8936002)(5660300001)(186003)(16526019)(316002)(6666003)(8666007)(1076002)(54906003)(6116002)(48376002)(50466002)(7416002)(478600001)(59450400001)(8676002)(68736007)(86362001)(16586007)(2906002)(50226002)(39060400002)(2351001)(6916009)(7736002)(106356001)(51416003)(8656006)(52116002)(25786009)(4326008)(97736004)(2950100002)(6486002)(2361001)(36756003)(76176011)(81166006)(53416004)(66066001)(53936002)(81156014)(47776003)(305945005)(105586002)(7696005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0157; H:wsp141597wss.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0157; 23:HwrkM1iOcxLSWij6WyOvmflfe2g6xkdL9YnykKcm6?= =?us-ascii?Q?cwob9O3DyY9fvbwMf/NBS7BRm+x0KjhJb8BjNPoORYSkxy6dm382BrgrgHog?= =?us-ascii?Q?UfR2a8eSEetC0OSt6a6GfdCX/II5p1GoyWPQrtgQWpWjK0do7XC+c5LctKXK?= =?us-ascii?Q?8PsNaZXilQO9j2X56WFLrIAC0KmmHa6s4Xy4ktK5OyG1Wn+VsdKVmyGou0Vv?= =?us-ascii?Q?v7IqCiPXjv3QEdB4jW+QEpALTrfpHbYbTqkhn3N/5tv1WS++eg3b/ewXwKYh?= =?us-ascii?Q?omzdPx90/akWCQkxkPstat8xP3jeqNvN1fXRRegwlzCz+y5hqFUMiE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RM0XwPasovg9BC71lygN4R1Egb SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0157; 20:AV7VS5KT0Q3F6UOy+0Yy8kl5iHmFmJlV/n5ti7eXdR+t7hdmu2lToq4lAZ1svLdapPRqZAPIQgbx5RA3E4pxamP/rIXxF6ysNGYxRwusEb1aA2kS3e58Tu620RBFJcs0RY3zzyURx5wX3B8bDkK9xeXn9ezJkml20I1NKHrBNx1tOB3IIFJ8nBjQSX8yzJmT/9SzPwUBHNbDsJJiFCUjx7lRlGlwaz2cvInCAian+LeLmSLbfbpgSwHApTPOXM+S X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2018 15:40:44.0408 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cca44119-f18e-442b-9185-08d5748a7abd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0157 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.33.86 Subject: [Qemu-devel] [PATCH v9 13/29] kvm: introduce memory encryption APIs 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 , 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 Inorder to integerate the Secure Encryption Virtualization (SEV) support add few high-level memory encryption APIs which can be used for encrypting the guest memory region. Cc: Paolo Bonzini Cc: kvm@vger.kernel.org Signed-off-by: Brijesh Singh --- accel/kvm/kvm-all.c | 30 ++++++++++++++++++++++++++++++ accel/stubs/kvm-stub.c | 14 ++++++++++++++ include/sysemu/kvm.h | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 300fc3cd44ce..4468c8fe002c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -107,6 +107,8 @@ struct KVMState /* memory encryption */ void *memcrypt_handle; + int (*memcrypt_encrypt_data)(void *handle, uint8_t *ptr, uint64_t len); + void (*memcrypt_debug_ops)(void *handle, MemoryRegion *mr); }; KVMState *kvm_state; @@ -142,6 +144,34 @@ int kvm_get_max_memslots(void) return s->nr_slots; } +bool kvm_memcrypt_enabled(void) +{ + if (kvm_state && kvm_state->memcrypt_handle) { + return true; + } + + return false; +} + +int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) +{ + if (kvm_state->memcrypt_handle && + kvm_state->memcrypt_encrypt_data) { + return kvm_state->memcrypt_encrypt_data(kvm_state->memcrypt_handle, + ptr, len); + } + + return 1; +} + +void kvm_memcrypt_set_debug_ops(MemoryRegion *mr) +{ + if (kvm_state->memcrypt_handle && + kvm_state->memcrypt_debug_ops) { + kvm_state->memcrypt_debug_ops(kvm_state->memcrypt_handle, mr); + } +} + static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { KVMState *s = kvm_state; diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index c964af3e1c97..5739712a67e3 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -105,6 +105,20 @@ int kvm_on_sigbus(int code, void *addr) return 1; } +bool kvm_memcrypt_enabled(void) +{ + return false; +} + +int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) +{ + return 1; +} + +void kvm_memcrypt_set_debug_ops(MemoryRegion *mr) +{ +} + #ifndef CONFIG_USER_ONLY int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) { diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index bbf12a172339..4a5db5dde390 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -231,6 +231,31 @@ int kvm_destroy_vcpu(CPUState *cpu); */ bool kvm_arm_supports_user_irq(void); +/** + * kvm_memcrypt_enabled - return boolean indicating whether memory encryption + * is enabled + * Returns: 1 memory encryption is enabled + * 0 memory encryption is disabled + */ +bool kvm_memcrypt_enabled(void); + +/** + * kvm_memcrypt_encrypt_data: encrypt the memory range + * + * Return: 1 failed to encrypt the range + * 0 succesfully encrypted memory region + */ +int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len); + +/** + * kvm_memcrypt_set_debug_ram_ops: set debug_ram_ops callback + * + * When debug_ram_ops is set, debug access to this memory region will use + * memory encryption APIs. + */ +void kvm_memcrypt_set_debug_ops(MemoryRegion *mr); + + #ifdef NEED_CPU_H #include "cpu.h"