Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752845AbdGGNkw (ORCPT ); Fri, 7 Jul 2017 09:40:52 -0400 Received: from mail-by2nam03on0079.outbound.protection.outlook.com ([104.47.42.79]:65173 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752491AbdGGNkk (ORCPT ); Fri, 7 Jul 2017 09:40:40 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; From: Tom Lendacky Subject: [PATCH v9 13/38] 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, 07 Jul 2017 08:40:29 -0500 Message-ID: <20170707134028.29711.87630.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20170707133804.29711.1616.stgit@tlendack-t1.amdoffice.net> References: <20170707133804.29711.1616.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR06CA0014.namprd06.prod.outlook.com (10.174.172.155) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 726ae929-70e1-4039-fc30-08d4c53dbede 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:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;3:VvoyEhBQOwd/O2/J6prluxQNN/74rduNNGbEZzsFTzkkXtW1kpcZuHyZVBQLtdtITPuyDAjsqH5nXyY80KTKL/4bxmY1TdM18z4xdlwnOFg10BLj8aHgIX7KUvVgVxhSf+Fntc45083B1kJjv4e6GEIcRDwc8qHWDlalwWUv0TkigAhiCvMb5FAsNRy3ZUYmFk79z2nvAnMAboBuso2cvuR4JZb/S0Ab1308aVDYsoDIrLH4vy+uDt7gTu4pzCnTcS+Fh9NJMEnrT8jqBYoVs7xGyA8KarwgHfrDBjm9hpnlS7NqPHfkGXom+SCxgJjXoXLAPYAL5LNgKmEh/FrO9RyCKpQ68zQoYXw37qFluRmE2e33SFjsHFyg56n8lRaa2nI6Yy8/Q0MSErkbdWz+myCcYb5qdDa1u8LAwD8LQfYXnaR3Tn9S9ndarWyffdAkx6H13xPx8gP+5xN+FAwT64IkUinpxY8UzbQlm3ch6XZMWU8SgtU2Icemkt/qBDYVThwAAuH1XaiJ49h9RR4tC9SusIB8FeuD2ZW9mwhtH0Mvx1le/ZeRFg1zduKRW3xvbrxf9/87acRM+1yuh9yFcTIjdnMFAdNYffcy07HN8BSIEPWgvB+YZQwcIOCG3yJ3hIBqbGHDxGDa2Yz9ex4Lak+ju69avmMToq2fZP95upbfRZrG/EsZZ5c2LwoT0gF5KR9Av0dZJ00DANwSsPM/o4ZOfdpjfVI8+VREEEcDgR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YfQ6lIUGaeR7lw4HF3FrjhUrJQGo051/B3tjWfk+NQTwrS5U9YHtf5gB7J9/2QyHPg6dMGCR1w8M7Syl0iCPAfHMlXH6XorZR3zP1NMgQHtu6IFUaLW8HN95SUV4J9KcZ155rAeDwCRU2Z6p1AF/e9Gvkk/HPFNmdlLqy9eG0FcrYz0DyB X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(133145235818549)(236129657087228)(767451399110)(247924648384137); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(2017060910064)(5005006)(93006095)(93001095)(10201501046)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123564025)(20161123558100)(20161123555025)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(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?MTtDWTRQUjEyTUIxMTQxOzQ6LzFraHBzM2E5Z2d0R1lNeDRyZThtMGo0QVZX?= =?utf-8?B?dTBiZEtSd2xxZkZBRDlnZ211a3Jub2FaZnJiN3p5SmsxRDZzcE5FUGJHTXFM?= =?utf-8?B?QkNEaUc1VVNCL29nb3hvbjZVWlN6dCtkeUVweTdEaU9CbkdHU0c3SWVkMGla?= =?utf-8?B?alNGYVBINkkwaDY2Z21qQkRjZVhWcWZUbHMxTG9Va1dzQUxUTFhmaGR5MTRU?= =?utf-8?B?Tyt4bENnN0JqNGUvOW5hT1NGRFRmM0hJYkFybi9ZbTBVdmZoS1dGazV2UEFV?= =?utf-8?B?WkdaQ1g0NlJrMGlZdFpWS29QdFZEZ2hQdDd1djE3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NwS1dwVTFtekE5RFB2WEYvZjRTNDMyRUpYZENIZWwxYXAr?= =?utf-8?B?b1ZPdS9BVi9zVnVtdkhoYlY0RXM5OWJSM1YwYWlrZk56djBlWmV2eVpmVVE3?= =?utf-8?B?dGtvc0FLT2RSdSt6VEJpNHdQa1RDeGhJNVY0SEZoTko2cEdqVzFXYkpCeDlV?= =?utf-8?B?M3RIS1lZUU9aMFUxUDBwa1FjSEt5UjdlMXlkRWR2RWRvY1Y3Z0JaYjY1YzNl?= =?utf-8?B?blozaWU2NVJiU3BzSHpKSjlSeFBKb0w1QnF0d2g3SGZ2QUp4ZFNoS21QYU9N?= =?utf-8?B?Z3liZFIrZW00UWJNeGJjTEExczF4SFF0cEhLTmcvQ0p1TU4vK0ZvS2hBMXFS?= =?utf-8?B?ejloRjFGK3RHQTdXK3lrZEd0ZnlUdnNxZ2Z0cXBKcDk1SEF1NS9lbDVnaTFn?= =?utf-8?B?MkJUbXRNVXVyQ014VEI3TDBpVkdtQm9uaEJISTBRQlVSZHNNRlkvUzZVbG0r?= =?utf-8?B?YXRWanpSc1hUNTdwdTRSZkQ3aG10SHV2cEJheFJLZHBqU2NkcWVsT05RSDFQ?= =?utf-8?B?S3VhV1ZyL3dUc1pta0I2dXNvb044bGd1UGY2SFpzcXA2MkljUHY0NkpsZ2Nh?= =?utf-8?Q?3yD86Jmh7wpZ?= X-Forefront-PRVS: 0361212EA8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39840400002)(39860400002)(39450400003)(39850400002)(39400400002)(39410400002)(5660300001)(50466002)(23676002)(230700001)(305945005)(7406005)(66066001)(81166006)(7736002)(478600001)(8676002)(2906002)(47776003)(7416002)(83506001)(97746001)(53416004)(6666003)(54356999)(2950100002)(42186005)(103116003)(4326008)(6116002)(6506006)(25786009)(55016002)(1076002)(50986999)(189998001)(3846002)(54906002)(86362001)(72206003)(9686003)(33646002)(53936002)(76176999)(38730400002)(110136004)(921003)(1121003);DIR:OUT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pP5EUjt8kPJFhXJZH3m4myvS/Kwc34L363SOydy1Y6zjCVTMKveD5evjc+bewNKsaQA/Jbc56wjG0vlKdWGwfHyI5+X/ql0CYWBntliu;24:NIiTwUt3u/Tmv6ifkSVUKrWztOH3L0iC2MAu/rirvivKCEKfgQ0vHYC5CQetQz/9A0ft7B0SZvCNrury7sPbAwOgcCtirLy16u4VI0QNBMY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;7:GkmYt4Mph1r+L1qk/+Hgw/rHPHfXll4oSwtjnebapIjETYRosT432IKCaH9EHZqTtwW6fQzwjEbdKCesypGumdDmESXSg5gAOARZ4WsfAKvVqzKhq905kXK5SW4FTpWyih2KrKc3Qyfe0mLc+4Fo9sfrz5LS7mSpdbPF2qauqg2qcY/gfHOqZzloKUimVi+s7RY47bCXKrHgp3K7/9Z2WgcNRwhmEGC9ADsTWPNhC4DxRTjsoWW+JTV2dYFt0zK6sR8QSRB2edKgi9p5n33bzSY/V+0rgJuHlH3hjmVxi833Ydcoh6KNYF8HGIoT7WrXO0ezFLrzDx3SmCE77g9FKHjaagMga5FibvJqFCGr0K13+Qv9iCbi5SqYp/+u+Z3NOAuEPLA6rsqoSfFPBQlS3gn+mMg/9fx7290ZFqtRPj1BvtAT1O63KlVIccNOlydb2kA5OTsVx+xIufzx8HGyK7VioCceu66ko8LtxeUD3ij35HCQ33INlwrmrtcTMNUF06NIpAwd03WCPiL/kVpMiG2vPFkb1xTj8hlU1SIgdswDTeoVLHW5Wb54EpozYM9v9dqu96EE6762T91AvIVTl0QCwT1yAz4BZb4E27XWyOthDogL0+gh6GM0Oj6A7UVT142zYewg7o7mV8m653uosVD1z0GH1rZSpJNrIAttdLFVCQ2YwyllNZ4UWnkJXdDco+Brb1AMnpcIHlMQtP6uwgdZXKTNIvBKkNNZOeuGVdZ5TsLMv6oa61pXCnUvp5aatk8IUWP5ecZaxolnqhABeepML9nO0ceDqbckgjYSBzk= X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;20:rmZa0TNAA4WDvhZDPSkPQ/HGLgBdVLD/AaYqjdBV2+jJqFNvDkKuQk/cfwKO0VreJQTv1Q5ITENVnpKEqtJmEER0DoC9DQQLKDBKAjPorIZxSFi5Pu67rkbGGslXFIj+Nb+xv9KNq59Ma7gbWEQFsVes21MWGSnyd/M8QlljlZyzo/7CI5e5FvaJGR59pAb3Z0HdCWq+BwZIgMkoYJYQMor1UmKs636MY9UPuiPtvruPpW/+DYUFCZ2tJu+qQL7q X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2017 13:40:32.4231 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1141 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4204 Lines: 136 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;