From patchwork Fri Jun 16 18:52:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9793383 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 33AB560325 for ; Fri, 16 Jun 2017 19:00:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 259DC2865B for ; Fri, 16 Jun 2017 19:00:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A00B28670; Fri, 16 Jun 2017 19:00:56 +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=unavailable 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 945D32865B for ; Fri, 16 Jun 2017 19:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752637AbdFPSwi (ORCPT ); Fri, 16 Jun 2017 14:52:38 -0400 Received: from mail-bl2nam02on0044.outbound.protection.outlook.com ([104.47.38.44]:1653 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752087AbdFPSwa (ORCPT ); Fri, 16 Jun 2017 14:52:30 -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=+j4DHpBvkpagfG2C6WeYeDzaNeW1EZrhmMM093db8uk=; b=b5b/8C8g4fIErkR1ZcnPsPWofdef2L5ij0adztSLtYQTx8fSmCfQ54B6/fAmcpW1x4/icZixcaSRXQRia+scIR56glSnHcefVOm1SnWfzQL7GGLfeAaNMHih7aXuBobdNPGL/7QY5F+jJMF/FX/YgviS4SnQ3i2ZZNpVkdOdLmc= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from tlendack-t1.amdoffice.net (165.204.77.1) by CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1157.12; Fri, 16 Jun 2017 18:52:23 +0000 From: Tom Lendacky Subject: [PATCH v7 13/36] x86/mm: Add support for early encrypt/decrypt of memory To: linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, xen-devel@lists.xen.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Brijesh Singh , Toshimitsu Kani , Radim =?utf-8?b?S3LEjW3DocWZ?= , Matt Fleming , Alexander Potapenko , "H. Peter Anvin" , Larry Woodman , Jonathan Corbet , Joerg Roedel , "Michael S. Tsirkin" , Ingo Molnar , Andrey Ryabinin , Dave Young , Rik van Riel , Arnd Bergmann , Konrad Rzeszutek Wilk , Borislav Petkov , Andy Lutomirski , Boris Ostrovsky , Dmitry Vyukov , Juergen Gross , Thomas Gleixner , Paolo Bonzini Date: Fri, 16 Jun 2017 13:52:20 -0500 Message-ID: <20170616185220.18967.78204.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170616184947.18967.84890.stgit@tlendack-t1.amdoffice.net> References: <20170616184947.18967.84890.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR11CA0020.namprd11.prod.outlook.com (10.172.17.30) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PR12MB1141: X-MS-Office365-Filtering-Correlation-Id: 5c0f9ba7-1d51-441e-9d77-08d4b4e8d527 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 3:qDb1S5DWzBWfa85nlKJjRVUhEasHBe7jIPaXBRamXe/K63dU6AQ+6FdI9HUeC5mULPZvByfWW86M70iAI1mIMwJh7TdWqNXnPIlVEwALDfcPA8qRKRu3MIzyp5R/9vngQDkraioN9oRVpdXXuwZK5qvNLL3KIpOpQ5LKQZbEj1/yY2ET4dpCxnjVxZqT9pjQJnBCbnq49dU/5tkCMisC6stqgem0MkeMACw6N67wtKcR11g1Jb8jawxvnXSriowTJbtpPnu2MP9z8LLTmaJbqzG/k/F27LnRi1ZG0HcT+Ap6PFD6yF/7EDfcF+aaNEsS2or5QqtO2PLkdo/VHHLxU6L7gVjnwSyLhbiFabKSSVs=; 25:EUJphTG09vz20EfgG6zltlzfZOq8COFknAkvDBefNgsT0OhJH8APIQiZ05fz7M1tyXHnvDICrV2/+NlY6hTjZbOyXPjElT+sHCYA+A9aWDMRaAx1pBQloHFfdsQOPw6mTFAAdQAxQvAopxnPma8vIH6OQjAvj50sXQxBdtlAc5Rv5i+LLdK2MUdyPW/pbbXcQXqDzPg+IPbG2Fw1uS1OcI6YQvDde+2ULLHrglPsecprOY27uzRVl+iDWhy4SF6WMspjIb9doEYzfsvtuABsh9YhmfzQdhqvlNRVKTnia7Sgn6v/Zder+bMGOyEd4Cdan9emuS77g8S7UiyKSonfQeav3YVXxm20/pdxG7ppIqgXidMphH8rXD54KRVjmbKf+NUXBBljRpsK8YoAZMCP6hB56oOLwHH4IUWbFUtNTNdkyv1NdBNdh3c+GwoONtf++U9aXcTC01uAbDFeo1w+mYRSyJhTN43pOmvciYcj0ik= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 31:9HTQ/VVkl29UL1Cquo03UAsefHUJtj6QM99iAGjvxsojrWFx32yOL64YXyTH/d4xZrS8RcW5BPSZ9vZps5LTI2AgqRETDWQP1O5Th6nxQPAk+nmHpGvZzYHcIkuIcy6YEA2hHHRhk8WkDExJNQ2XTNc2WzP1UFoBS5T5x6fABzoEBiN5lM5XRj+XHeOgNuNGLPTTzk3W+9QL5DgdX+1/m+Garj5q7lDUVphI2Mm5duQ=; 20:yEnH/pCKhyVMoy9gIDNPEOc3+LT8ed3eVJYfN2U2WPFIMOsKMNt/pEFdW0+soj8YCgKdGf+U8TSmiP8JTSREudBxTw6GcqmJ2SrBNZ5vXA8BWypFCpr1f9ZHCNA79Og4e5/xsv2JcivD1+TN0M816DQBPIZgCVH+r+Ga7558VIHUZHzRR3sHBqDRbW+JqEzvksDGwCVLQVNAVHpp69Kjy0Fx/BLdK4nDED+R6UIx8T3BJYOOAX4AjYKOx8tMLzqu14hAwPi2m5PuuT/50/ettYGiNaG7f0RlJPfw/aucL3VqeKUjfzyYwxFIpshIya2IqN20dWN0uDJX6JvGvSjyAG6ae94dWoCrVDKK7Z3IOumXjMQ/o6jaoKPp7zllDHpelAWDJe6D5A+i7HQvgM9XMtZEl/0GnRW2jkXssTlM5vbgCiiV4kqjtfilBQFbfFOSzaPg3ygx9N8XPBm03BvlLdVP0zivHIJKAwjQJIdOBdxPYYmgkzMvYdCt4ncDfW12 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY4PR12MB1141; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQxOzQ6ZTRTeWFodXNOMG1KRTRuUHBzNWhnd2NIVWoz?= =?utf-8?B?aTJSc3Q0RUtmRzlVd20wT1pJWGtqdXpNdWdsRVpkM0JEaTRndWU5NDdpUE1q?= =?utf-8?B?djRJQmw5OWhEUEg3Z0ZyaUVZaFQyaVFMYm40UUI1djhaaUFMSUl6OGRhU2pa?= =?utf-8?B?eG1UU0JEa3JjT2pYNGhDSHN1MjVobDI3Vm9aUWRXWUpxYkp4QUYyR0I3cysx?= =?utf-8?B?eW5WUUJZb01yVFU1QytwVXRQcEdaNDYwVkQ0cUVQZGFnRkdmY2xVdjEzM3d0?= =?utf-8?B?QTVDOGFiaXFCL2s4MmYrZmFpUURtaDlBWmMwcFIwLzhSVlJLeTcra01GRjVt?= =?utf-8?B?cEFMekdvbzUzRFJUUWFKR3d1VWswQVJiZVIxb1p2U1JCZXF0R1VkYVE5UDEv?= =?utf-8?B?WldTdUlZRUJYcG13S0ZYTzd4ME9KUkVWMW9YcnF1M2NmSWpWdDdJWmJWTE05?= =?utf-8?B?V0Foc1o1NlBqNVBxSjZLbWVNZVRVa2RpU1V2cmpqbDE4bU9wd01XNEtoNkIx?= =?utf-8?B?b0N6QUd1WTJjYkhidnFKS2tVUDlWRnJCVHRvZHc0bVJ5SHJOUllabjBYeDQz?= =?utf-8?B?WEhONE04RWRubUtoQVgrM1ZkbU5UY2pjcHlZWXFaVUZNc0hPU2ZocVpKQ2Ny?= =?ut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Ixbm55S01BOGNDR3pwbWdF?= =?utf-8?B?b3I5VWdrSWdtMUhvUjgwamsySkVVUVNUWjNSZnRwamxmZjNsY2haQ0RwQU1O?= =?utf-8?Q?O5HUywqXyGRjInVW8t5?= X-Forefront-PRVS: 0340850FCD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(39840400002)(39400400002)(39860400002)(39410400002)(39850400002)(54356999)(4001350100001)(50986999)(305945005)(86362001)(76176999)(8676002)(81166006)(6506006)(7736002)(4326008)(189998001)(83506001)(25786009)(5660300001)(1076002)(230700001)(9686003)(3846002)(6116002)(47776003)(66066001)(2906002)(23676002)(33646002)(103116003)(2950100002)(7416002)(50466002)(54906002)(7406005)(110136004)(478600001)(38730400002)(55016002)(53416004)(72206003)(42186005)(53936002)(921003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1141; H:tlendack-t1.amdoffice.net; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQxOzIzOmNHQUZETUlyYzZxZXU5M01lK0VobGsxeVlr?= =?utf-8?B?aE82V0JJU2hxWVRIaEwwZWlVZzJtS3RsZTJvZHRNQ3lleEJ4ZXl0Z2JWSnUy?= =?utf-8?B?TkFKc0NiZnJNVGtHMzNiUUY5KzJoRjZmbmZySlBtZ3lHNVZCYU1NWXJuTlBx?= =?utf-8?B?amRNOU5kTTFFRWJSeThVWE9uUlc2bW5WUHVqTXhKanlOOU0xUVF1WHRGQ1Rn?= =?utf-8?B?c1YyNTZPeEJmYzdpYUJGRndoRWdjV0lpNjVLaG93VTBvWnRGOS9jQ0d1dzg3?= =?utf-8?B?RFJqODV5cExCOE9ja3M4aDkrdGJVZEtVM0Yxeng1U3Jod0RJZWtvWTZRWmx6?= =?utf-8?B?RVVvTjY2MFVyK3pITkpqNjZYUFg0RUx2RUxJT2tMSkhZdFdRMHFROExtZ3NL?= =?utf-8?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gsYckpQYvHAyrqfib5wi2EU7NHJcURlooFtyKGqWrQ/6tF1IDv7Q72V2BwI9c8kmOvxPGzGnEpcWTBedU2EjTPIedvLppxt0JdFJfM5yqiarYUA5uQRkuTJTZhkwqJGYydhCXORxcyl3Yq432m4DrbSb5nE8VIiuuVDt24xfZ4wXP0ki3wa1jAVrDIiaf3M2WUUY8EaL5DKLjuwnZCHowyjNTCFMFwROu/QCChkbcHoiURF8yuaEn6PS4/5gIarL6ei+U63urITIZuOZqS8ChAZciJvj/OhiKr77+vhUU1igAbe7x4x3NtCDSUwr2cBi3lAGgo7EImzKs+16vUpbNZerlpTHH2+orqlxMmNJxm0YU20dKZJCVmm+u8WEKMrpeX7pcDEaAzQnTfnftPseb8ZOjXjd6IBUQTmH87gPkgw1GTDxVQxulWLOpbSpp4HUdUULVF3Y4n1k0r653M+VNKD39Q9BJPG7scbXabHvE8M2RE0ZDv2QQuJ4= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 20:Osenkcz7TRlhYvekPfZNNMR8yQ+xNln8vm/ZwMwfP8hahqAkFRqa9MMOOQH4b2wYOV+dJ7hah8aMWr59jpyNGFJCFn5n4AneyQCalUtlPwRn1RmKNapCHEtPrb6vePSFPF2Br/pHrOLJcsgdPlBHD6k4TOHEzC+GH+LJmdZnEOe93vCKlVTTdIY2GWniCZIDeA5dYjbxh+GacJ8TvpYHUYaXVqzsMgPlG3bxiawgl8VLCPBQ27L4eE64q4giceUB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2017 18:52:23.4900 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1141 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 faae4e1..6508ec9 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_enable(void); @@ -29,6 +34,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_enable(void) { } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index b2d1cdf..b7671b9 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -17,6 +17,9 @@ #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 @@ -25,6 +28,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;