From patchwork Wed Feb 28 21:10:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10249857 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 4739C60211 for ; Wed, 28 Feb 2018 21:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3456928DB3 for ; Wed, 28 Feb 2018 21:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 285B128DCE; Wed, 28 Feb 2018 21:29:09 +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 5F97828DB3 for ; Wed, 28 Feb 2018 21:29:08 +0000 (UTC) Received: from localhost ([::1]:47054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er9Hf-0000PZ-Jf for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Feb 2018 16:29:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er90I-0001JV-Ki for qemu-devel@nongnu.org; Wed, 28 Feb 2018 16:11:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1er90F-0005lc-7J for qemu-devel@nongnu.org; Wed, 28 Feb 2018 16:11:10 -0500 Received: from mail-sn1nam02on0070.outbound.protection.outlook.com ([104.47.36.70]:44829 helo=NAM02-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 1er90E-0005jA-UI for qemu-devel@nongnu.org; Wed, 28 Feb 2018 16:11:07 -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=ZVExlbGHVFEGy6qxYIpKzGK89UZ2R9/8R7hGyP3onSs=; b=3T+C4mYAc0ODUIipyXwjzN6uIhCvoKKtf0kbtq0UMNqB+146RJLfZQJsAfp1pSM5GGMu+XF9QJZsXiNE/YftlPaFDGhq9j5m1Yt/YJvVzt3PDf/+gpki3ZtLZDz1BF+fO+H4hZEbwIiOhECQkh908D1ZFpfLJTiDNnjdSzfGg7Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Wed, 28 Feb 2018 21:11:03 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 15:10:13 -0600 Message-Id: <20180228211028.83970-14-brijesh.singh@amd.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180228211028.83970-1-brijesh.singh@amd.com> References: <20180228211028.83970-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR10CA0008.namprd10.prod.outlook.com (2603:10b6:4:2::18) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 25e7a9d8-efc8-421b-420a-08d57eefc79d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:kcMCvzDc8OlcyvMuFdQjRvjFqRUkfPo12vR2ITZumF9mWdTDkpjNLRAdgw6kILD1osrfvKvAo/LNcmI0t8MN8qPIqjUsR6MMJkLbsDevK+u8rvdeVfrYTC60zfNJXmOdqailxmjugKyM6H04mFTfzKrc6JaYDCZelmfNZCeaWHsGzRQPoDT14kR5EKnwbISKnsCq+JkUqjJgqg2mnKv072S8fG6BqWNsBR2idn4+p4Z5EcT578AWq/DDgJ2r++wZ; 25:mHMlTAPp1IIF5l4JAt2a7MD2JwbGCXP+INMY2XVdOvP8ot9Am/ZSYbyyTO0nHBwq+UMtHbcyW60A1TLQGn+2MDtiAb90aLFVDuzaxUOPLAjf2/lCi2K+NbpSON6UIOKWCq0S7X9ztX7ZM5sRCsD+ygyvQe3PEx8bixbW6keC4vIoY9z1IYATkJzLIiOyfq1CVMCtsN8/k6SjEiNRsHJim3f1ZgjcvCh3Oql+3hytiTO2LgzuTJS3vUwXfPY29V5GqIYXRbv/MLWuTJXRdv75uh5VS1fDHN2m1czbtCfBLCHNivTx0nW6sjJp/UFjaKkqaxmt9AsMPHABseBbukAKFA==; 31:C1/n/eZPC8s0rR/jUBPOb4XRqZC3+abF+DNgxGPDA+faS0FcadGSuZN/FTZLJTH/Eya6lXRoW29+GIbkIiSSvEWvqT2z+iP6OdM4zS1TZ8Uj01SkLIB6/Ubts86oOU2yy/+Jxka7J/AZxsXzteASKkdHqU5lc0hcyplNAFRZt26Lu9OusMVqdizI2HWpIr8h2NhrSE5Wmd8ScFBRhKVxukk6Th3aOoTNAIkTRBBiuaw= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:1bbNgjJFi5SXCFd9m2Wd8TEIuxXww/8U5lLurhDu1FHHCMSmeVSYQ2OITSHPbQmYPGfDIokP21zUtIAQY4vJbU4iQe+MOQhIL8bvOkYYmJYSVmDViNTqrLmEiEizutOZbbOzkmSN7fRUpUQ0qF4vgKN+Rc044kVvpS9f6XDoiWvMGrMcRByXb7lrtY7beAK1Ccb9e8ObR1RWmDZwYhaS9N+lUzTbfbV0mVhaiZ49MMH4vRWiTAubj1oOVodRuOkV1F7bf2NcDGuP1GTmUeWN5ik3VlfD6B8Jk2RFrylR61WMetF4awF+GvkhBkawCIwKDZp5nBo0oFN6xZs1tymyixNnMcJN9tkm3WhgMCbghz9Mv0/qYvj85XrCIDbbupAmpfCQ4UKiobXHYT4kA88yFYT5H4aD37vdy4M26zav0lWqv0OzTYU2/kl0W2MuPz6ELYmrPWbjq4zMayDGuVcnzKGoUJsrMJSwA+DT7AdMhmxWkL+ti7tDrGlIitH0Q06S; 4:b0YJCFX5TIIlGjQxx+8HkPl/3JaUq07uyNJIJqFbukDNeHNg+Ebsy6yaSEA8Wcy0SlR1bzCCLbkxlud5NdqxU84il4R909284hRQKfkEEJ88DlfvMQwAKBlQkVNxrIVHIg1T5tzdyv+C961SAzyhW3Rn0ATFeT637OVYz7uM5CehsHj22pXn3f5DGyHfeOPxkQ/NVlGcPUj5sZI2Eg9qTX1ulZ2XlS1gJETV+ZfLi4zVuc4hW5Zp3SF+UsVxzZVnDDoyno+weWucRQn0BfGwoPuNqSQPtakZ9DG6DErtLttVNXE9tSpIKXtPDjLBX+LP2ODi5AwOhKvk8SlR2KFajw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040501)(2401047)(8121501046)(5005006)(3231220)(944501219)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041288)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0155; X-Forefront-PRVS: 0597911EE1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(1496009)(39860400002)(39380400002)(396003)(346002)(366004)(376002)(189003)(199004)(6486002)(6116002)(1076002)(2351001)(36756003)(16526019)(16586007)(54906003)(53416004)(26005)(53936002)(66066001)(186003)(47776003)(59450400001)(2361001)(478600001)(8666007)(316002)(81166006)(50226002)(8676002)(8936002)(386003)(106356001)(97736004)(5660300001)(2950100002)(6666003)(305945005)(4326008)(76176011)(7736002)(39060400002)(8656006)(105586002)(68736007)(50466002)(7696005)(51416003)(25786009)(48376002)(52116002)(3846002)(2906002)(86362001)(81156014)(7416002)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; 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; DM2PR12MB0155; 23:IXKrMfm1vKC9KBrwy3lO7KaqD5g6u+0mtfEQD7Orh?= =?us-ascii?Q?qPq5Tkedvx25Qp2EkqXO44XQRgjMJ7Bs5ywgvT2yHiQ0NI/Qs3a+ivAWTdvI?= =?us-ascii?Q?SGV/GeNLVs6oMlTWkTR6TO3y4L6E8y3QGU6gq8YBpgyAbkY4NjWraRvElP0m?= =?us-ascii?Q?oi8qNaBtKHbMPXBeRL/Ojtdz0bzUIcg5Qh1KfOQkgb0WRn/Sg5W9McDaZ3x2?= =?us-ascii?Q?PKqiZgQwhycTza3jbtIo8v0AHujMp2s31rKebXozTdk4NQgDteLaTiVs/hbb?= =?us-ascii?Q?L8WQ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qqA7WosRUa8EOwyUgEiN2AbvDAyD7+BhGKD2f01t0d2AnDWKy2mtKXsDTdQaFcjCPB1706u6 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:f81gLJ1IA+RVuWEDknz2/PHeyrw/8x63umjWDSZoC0H7UKLSZvduzGIKO43ZQ3W/JI/lDzRjzBf/scOumk1tVEbrUPUdsYSRXIyl2dK2h+42UkaRfrssd9/ouHt6CeJIGwSMPpWuFt9FsFQJBc1YlPTKNulegHrfVKGOnZ6dsmT0GDG0k89RCCJWP6zQT0KWnyJri1TEZ9Fb01Zk5DjsoMtNsmi5WT+1APqeAQRHPlZjb8r8In9W6KIgaDRSwsXn X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2018 21:11:03.8580 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25e7a9d8-efc8-421b-420a-08d57eefc79d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.70 Subject: [Qemu-devel] [PATCH v10 13/28] 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 85002ac49a54..d69bd1ff2b07 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"