From patchwork Mon Jul 17 21:10:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9846251 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 1868360392 for ; Mon, 17 Jul 2017 21:22:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EF3825223 for ; Mon, 17 Jul 2017 21:22:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4339427F91; Mon, 17 Jul 2017 21:22:33 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FC6125223 for ; Mon, 17 Jul 2017 21:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752331AbdGQVW3 (ORCPT ); Mon, 17 Jul 2017 17:22:29 -0400 Received: from mail-bn3nam01on0076.outbound.protection.outlook.com ([104.47.33.76]:46539 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751367AbdGQVLu (ORCPT ); Mon, 17 Jul 2017 17:11:50 -0400 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=GvKAnA4Ctai6ts1UlgHE/+KrhU4bGwQQYhkvUE36lYM=; b=rNuKeVAFSnw4Y3tQT6iq5LhuplyxsRtjM5lQVGCZ3HgUpZmFRccMJW0MgHInZCzqrYRCxmWMyqDti5WtgdiH6ruYS5Kj6WOA4M973EDFwOOWCs5+gf10bTs3qJu9hRb0RoFY3i2m4nhuOwMqFjYELapdyi7dXeiXzi+qSLdM7UQ= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=none action=none header.from=amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by MWHPR12MB1151.namprd12.prod.outlook.com (10.169.204.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.13; Mon, 17 Jul 2017 21:11:34 +0000 From: Tom Lendacky To: x86@kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kasan-dev@googlegroups.com Cc: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Konrad Rzeszutek Wilk , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Paolo Bonzini , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov , Rik van Riel , Larry Woodman , Dave Young , Toshimitsu Kani , "Michael S. Tsirkin" , Brijesh Singh Subject: [PATCH v10 13/38] x86/mm: Add support for early encrypt/decrypt of memory Date: Mon, 17 Jul 2017 16:10:10 -0500 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0008.namprd03.prod.outlook.com (10.168.230.146) To MWHPR12MB1151.namprd12.prod.outlook.com (10.169.204.15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d29fb23-d5c2-4be0-d232-08d4cd586995 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:MWHPR12MB1151; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1151; 3:aOWoBJciqZ3RQN3BY8KJdJFqcLqQQvEio461P/q/qRVGvza8fM1wVpCeDjNR3/pDoFGf1BlGc8xWr8XcuX5UtRQlqyt1+Xu5O8FYpl8uJyCsnMq4UQrveZB8uj+A0u5WemKnquwvVt8ZCwxOFjwIfwsQNKIIc/5j6t0CIfjUU2gYU0g1f5bXYLcw5ZfFXNlPRVngzsHkxvnyHBROjlGRgnve9zhVpswmh4up06+DvbJdY3jupZJFersVOKId+7mXIK8rUMoszwpSBEpm2tEkGx7J1S9BGIanEiHhp9zlgZ06enGopVz/PJ96bc8doCXi/jKmN1JkvqmDjvcKSQ+gb71I3aH4Cx7QBqPAKM7tqvZiX4aSnYRq3Viac8A/OFERQ4KoDguM+TKE3V9n4ZQttg0zthfb8xu23bS0dBwelgWq35MF7mfUaM6fT0Iq36gKuZlIDDeHok711hpNGM4vD1RiM/ixRIzBk8O0M8mD/5VRibCu3QR+evnVAIWbcMm26NVhFg7k+/Qek8Ad1QG5HBucgrhckMrPyhaSivfO92otBbeWFlsRtEhBNtxypPFTAeUzsuBHqFHVuN/LXLjqesYS4T8vGt/WePHbeqhlYFGwyKpdUp9ySv65Rlqql9I7+tu6Sk1wVAHNh7PHZm+Zo6IVsm72dHZXExJsrlxNMnzPt9WiONL8QxFLRqnBlczNtFr//0qDW5ZxKq8Q6osCeTg6SPMwg0RaOrDbQTDrG4C7gUEAem0eMSm74daYFD+gCXOMf4OelBlCCwyJfXgIhQ== X-MS-TrafficTypeDiagnostic: MWHPR12MB1151: X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1151;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bvksB80Z1aXRED3jDKDD6xkUg6aoMDqNYCQA+9hgH9a83Mfz X-Exchange-Antispam-Report-Test: UriScan:(133145235818549)(236129657087228)(767451399110)(247924648384137); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(2017060910075)(5005006)(8121501046)(100000703101)(100105400095)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123558100)(20161123555025)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR12MB1151; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR12MB1151; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1151; 4:JQamrk4aKW2ETJ5aDcvSTIkSgXvebE7BT+cXw+flCX?= =?us-ascii?Q?u8q75LBkVwHdYZabPjdze3bN1yrdGxIbmRH6fenkfKOzfB55uoNuzobx3mbi?= =?us-ascii?Q?u11qa+lF0tTRoxDBvrduyNiyml3xu0RHPaGMGdh97Dt5m31vQX30AUFjfmVQ?= =?us-ascii?Q?87I1/ZZ2eokDrKk5BjnpcGca1vTpPe6MzzD4W6DmY4zX3veKakCr5leNB5Ha?= =?us-ascii?Q?AAqyPVZmJ6HpkTSi9Rbtb89mnqsKB7qjCazwY8shByrt1EMkcc9o7hKZpEmS?= =?us-ascii?Q?8MgyosKFmqktH38G6dVNK3e5nfMq6uIOQ6yQXswUwZBUBxjsEBabMJkF4Qox?= =?us-ascii?Q?fc50IKuDMIcArz6L+OMXBiQEwgXlpc5fAizE4rmi1n1F8u2PeCiNLWkb95vY?= =?us-ascii?Q?OEo9Ca+t6KImgz8O+K2ebU/QRlwwXX8n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UR22TWEca6OGVnIv9Qc8yIPgn+BTAP?= X-Forefront-PRVS: 0371762FE7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(39410400002)(39850400002)(39840400002)(39860400002)(39400400002)(39450400003)(25786009)(6506006)(33646002)(54906002)(7416002)(76176999)(478600001)(8676002)(50986999)(6486002)(47776003)(5660300001)(189998001)(42186005)(38730400002)(305945005)(72206003)(53416004)(66066001)(50466002)(48376002)(110136004)(118296001)(2950100002)(81166006)(5003940100001)(3846002)(6666003)(36756003)(53936002)(7350300001)(6512007)(2906002)(7736002)(6116002)(86362001)(4326008)(50226002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1151; H:tlendack-t1.amdoffice.net; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1151; 23:yxDTRnbAYf0+XbdMqknk06IlC36+uhunSr1qFqJHj?= =?us-ascii?Q?xZz5/IbqHJRHuILk3vkhmrrHIGbYaS/rXNWRGcVlRQ4cpQ32PfksOuQtlt6c?= =?us-ascii?Q?Jsk4melm3Z+Tors3erJjp1PAOc9DpPm12jSCWNGmzipe0R8TN6gcgOjmUqN2?= =?us-ascii?Q?F5WyLTbNSlGj0YatB2mtKa0SWNxbJYJnuX7R1MHkMChe3Z0GNDHRNM1Nnj4b?= =?us-ascii?Q?6eLVyD34ycoUFISNH/AkUb2G9Oosef4CV6g7LOPEmu38VeQUamiF5IBbI9XV?= =?us-ascii?Q?MrAe/aMQbQvL1xaAdLtZQYUg3Ke7gvELYpJqnCL9nBvyxXMvbfj9BHn4s8p4?= =?us-ascii?Q?d+qUVAtvk/Cicyaz42YGpWz5I1C4C5/9GwWjUukKac02rHYRFu34//urCsQO?= =?us-ascii?Q?phlPGjNvcvhtMkyKZEemjI7jeUeUvvG6RCJUEimd2rnjg047wKwqOFUuTRs2?= =?us-ascii?Q?veV9Oi/j1xB9ZktO9ziE9txALfss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IIyxyxtVL/lTDYVJMMNFXfjno86SIpkhS+bhjPbCd7JS++HP8k9wN4kGbenHmOMqDxx6BdpdsoHjNdaRP91yZwaODmbr5BB0FFr2cb7hTkaGR/IDM+opo/5SNobzCRX9/dOAlGUmb14s+ou/SReqt2QA1qMeRAGVfG+TEsMoiU2FoohUD7fteZIOkeQrWcxPC1/iGIeCs40x1nbLByx73IRalYvQDSFM8RvAIDiIVBarAIPLATNm0Y7t/rkA7Y3fX0AlKJx7lSJyWuRRFPTxY/jVPH49GYiMZgAi4b0ZBsIv8WpUTc9n/kfbQH+6+zNFhID/t/9onpnT3tItTAtCvjaWidACyAZTl79j/6cuIfbe7X2okv4HNq2IrqivEcmrbueP9fpkUmOAmdY5PjQR6HJNRbER4ke4hEy73NWPZf0120uA2H6OFXwxDWfHw3yBSHU2/RDSTuSG9Zc79ml4TJ/MmWQw6Bx+S+H9rWIWCTmdBr3L7tNiOPhryon2P7TMzyR1lhqaN6WyA= X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1151; 20:hcV8wJ5B80BMTkYuWc9KZbFkq/oPvb1gHXfm0JyQGwgEBdi9PeTHHnW33y+7K7H+la9nPjFA04y25+BTe5fvng/PL76GoUdEhGaPckZExcUmWNVwziQLJdItMI+WKC5HBp9utE4UyU6/CSKR3AyLfKl+ZDe9tLh/9DuGMUnVsoP2rJIJSUyAfeTYFMxW5rDuRBOYf5K0cvgiiFJkKRWvco8MgiW63EIFB6xfxH2lSTYqKn4sHpir0rhJ/n8YeYIi X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2017 21:11:34.3766 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1151 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support to be able to either encrypt or decrypt data in place during the early stages of booting the kernel. This does not change the memory encryption attribute - it is used for ensuring that data present in either an encrypted or decrypted memory area is in the proper state (for example the initrd will have been loaded by the boot loader and will not be encrypted, but the memory that it resides in is marked as encrypted). Reviewed-by: Borislav Petkov Signed-off-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 10 +++++ arch/x86/mm/mem_encrypt.c | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index dbae7a5..8baa35b 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -21,6 +21,11 @@ extern unsigned long sme_me_mask; +void __init sme_early_encrypt(resource_size_t paddr, + unsigned long size); +void __init sme_early_decrypt(resource_size_t paddr, + unsigned long size); + void __init sme_early_init(void); void __init sme_encrypt_kernel(void); @@ -30,6 +35,11 @@ #define sme_me_mask 0UL +static inline void __init sme_early_encrypt(resource_size_t paddr, + unsigned long size) { } +static inline void __init sme_early_decrypt(resource_size_t paddr, + unsigned long size) { } + static inline void __init sme_early_init(void) { } static inline void __init sme_encrypt_kernel(void) { } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index f973d3d..54bb73c 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -14,6 +14,9 @@ #include #include +#include +#include + /* * Since SME related variables are set early in the boot process they must * reside in the .data section so as not to be zeroed out when the .bss @@ -22,6 +25,79 @@ unsigned long sme_me_mask __section(.data) = 0; EXPORT_SYMBOL_GPL(sme_me_mask); +/* Buffer used for early in-place encryption by BSP, no locking needed */ +static char sme_early_buffer[PAGE_SIZE] __aligned(PAGE_SIZE); + +/* + * This routine does not change the underlying encryption setting of the + * page(s) that map this memory. It assumes that eventually the memory is + * meant to be accessed as either encrypted or decrypted but the contents + * are currently not in the desired state. + * + * This routine follows the steps outlined in the AMD64 Architecture + * Programmer's Manual Volume 2, Section 7.10.8 Encrypt-in-Place. + */ +static void __init __sme_early_enc_dec(resource_size_t paddr, + unsigned long size, bool enc) +{ + void *src, *dst; + size_t len; + + if (!sme_me_mask) + return; + + local_flush_tlb(); + wbinvd(); + + /* + * There are limited number of early mapping slots, so map (at most) + * one page at time. + */ + while (size) { + len = min_t(size_t, sizeof(sme_early_buffer), size); + + /* + * Create mappings for the current and desired format of + * the memory. Use a write-protected mapping for the source. + */ + src = enc ? early_memremap_decrypted_wp(paddr, len) : + early_memremap_encrypted_wp(paddr, len); + + dst = enc ? early_memremap_encrypted(paddr, len) : + early_memremap_decrypted(paddr, len); + + /* + * If a mapping can't be obtained to perform the operation, + * then eventual access of that area in the desired mode + * will cause a crash. + */ + BUG_ON(!src || !dst); + + /* + * Use a temporary buffer, of cache-line multiple size, to + * avoid data corruption as documented in the APM. + */ + memcpy(sme_early_buffer, src, len); + memcpy(dst, sme_early_buffer, len); + + early_memunmap(dst, len); + early_memunmap(src, len); + + paddr += len; + size -= len; + } +} + +void __init sme_early_encrypt(resource_size_t paddr, unsigned long size) +{ + __sme_early_enc_dec(paddr, size, true); +} + +void __init sme_early_decrypt(resource_size_t paddr, unsigned long size) +{ + __sme_early_enc_dec(paddr, size, false); +} + void __init sme_early_init(void) { unsigned int i;