From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756520AbcHVXJW (ORCPT ); Mon, 22 Aug 2016 19:09:22 -0400 Received: from mail-cys01nam02on0065.outbound.protection.outlook.com ([104.47.37.65]:20230 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754818AbcHVXJR (ORCPT ); Mon, 22 Aug 2016 19:09:17 -0400 X-Greylist: delayed 1065 seconds by postgrey-1.27 at vger.kernel.org; Mon, 22 Aug 2016 19:09:16 EDT Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [RFC PATCH v2 00/20] x86: Secure Memory Encryption (AMD) To: , , , , , , , , CC: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , "Konrad Rzeszutek Wilk" , Andrey Ryabinin , Ingo Molnar , Borislav Petkov , "Andy Lutomirski" , "H. Peter Anvin" , "Paolo Bonzini" , Alexander Potapenko , Thomas Gleixner , Dmitry Vyukov Date: Mon, 22 Aug 2016 17:35:29 -0500 Message-ID: <20160822223529.29880.50884.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: CY1PR04CA0015.namprd04.prod.outlook.com (10.166.187.25) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-Office365-Filtering-Correlation-Id: 85ad9ebf-364e-4173-52b8-08d3cadca0fa X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;2:KJjeEy3TKb3UykLga4PGZPkWTPuhX94BAMi6iWmc/KHjbU1OLPq5YG+VxdxJ4FcIk0MmbfvHz4Aug595ycOmFYC97sWQw0/lVSA2YrH8nBW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zuEFBHD1lq4AUXSMP/ZrFyMSYn7REeDQw7eCFv6yMYchn9QJ5hxr/HFG54tltEjheanxOkXB+s X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;31:OmeWzRpzrOSh2PvbM1P9Ns3ILaBqTeecQwwuUYnnP+NKk6FzzM0W48MEzUC+0aFKUeKxgYorZr9BclwXxyziRGE8FdLQUkqpu5fmVARTlIPptIqWosMCoCc9ih2Y1qoGy+4RjR7gfbVjJn76Ve7FqCwyRiZP2rHA5I44dJ8Opvrc80BliTbnZLmZ6dL5QtVBSM9k711wbUAK/AP2G4RiPNmxIAr95jWVu9jqaj9EY2s=;20:v2nb7y45l+5U2ozYGFNAVBD3j+woelCsuzJnhPNT3IxVIC6MM9PnKXZDnFse8eCs+78JM8e2YT8h+GggU4oRAhOIZjxluMLCS7QEYqq6jRG0IZl6K4hVYIFVUoi1+EFBwFOOc3l4baektGCYhseS8fOUdw2LQvAriqvkwWoyFLE0c5irzLO2Ytwy4oBBGlM73V4Cl5Ey3DWQNnMS1bH593MnvRMyjMQfSEPT9uyLIoqDHOiURcmiwaHOPBE7LHiKOlWL7zMZOKSjr0DSCHD48VxvvauomduC3Utyn8ewg31YfN33QS4RWb83sIXKH6kbJNuh2S2VBQnK7108DaM5snmi9DTwp14Wf1P09lmWkelplUnh40Fl4MGLVpFBZTZNQ1/uPF0aZyf+ZxilSaHbba7HL3qwotFNXggz0fWN7oloeoA+NIc4XPOs0odH00er/zj+kFdUok3e1tlXAKDsOixYDzs8VBZB7bVTdOzpYVbmcb4acdqw+/gkbq0KMr/k X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026);SRVR:CY4PR12MB1141;BCL:0;PCL:0;RULEID:;SRVR:CY4PR12MB1141; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;4:38Nub1dxwTkHOHo3bTQD5vnkitZO9RXe1f7tpg3UdNL/YbZq+KuW1X0aOlXKxIJ8dQZgOtiEV3GxoHknItlD5ax/eeHxudLRw1VsLJ4KLhnBWxiTtha90cvOpyEBkSoCu0dQza33LvOjWPzuBmNP8pgQimxNvT0tCJZGnvGL4VZfLua4zXOw9yps2cd5eww36OMbM0y3Kq9EmdLg5Q2+Evx7Q2pCT8XmMBZFkkPGYzCatQEyPuuVH7mux9eTh9nKHSl8Yc0X3WGJbMI+XdJP1tZgJ2Y++K3jMHD2pYO+ROpi+UCTl1rSHMI3IkCgnoc8PKVkzkx7CeY1A3CyLXx+9eWALCqXlQbZ87o4EDz/VRjrKv4VrgbXTpfYdp37Ctp9ZZkpmoSG5Fgp+XF67vWA6d1+YXrPHcahd4JCiO7ScpvS16UAyYzOj80mcWgZetFe X-Forefront-PRVS: 00429279BA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(23676002)(106356001)(229853001)(105586002)(50986999)(83506001)(33646002)(97746001)(54356999)(42186005)(101416001)(2201001)(86362001)(5660300001)(103116003)(66066001)(47776003)(50466002)(97736004)(19580395003)(5001770100001)(4001350100001)(7846002)(53416004)(189998001)(77096005)(305945005)(230700001)(81156014)(4326007)(7416002)(586003)(7736002)(3846002)(6116002)(8676002)(2906002)(81166006)(9686002)(92566002)(68736007)(1076002)(15975445007)(69596002)(71626007)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1141;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQxOzIzOnJUZjZUU1RFZU9rR29ZTGZZWDZHbWlMdmNy?= =?utf-8?B?WGswNXZxMmU5MDJpVjA5N1k0d3lQVEpkZmJKUFJqUEFxTXUwa3ZNcUdLT3Ux?= =?utf-8?B?TURyZm5yQlZXK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V2ZvVOavggE7aptZbuXT5NYhWEWHrQqFg1sHWNI8K2uphD7X36Yh7MmQyU7o7KFC7wP7WmNsv0O9VGnGUM+nyva509rVwOckMn8KwKq8F7DiBhMvyph5KQrm/9jg/09FlYbcyJOB0iSpBLrVYKFw1cU8g==;5:vk5b5fFyEVC0pNiauEGzs6m0HlsvK3P4lltiFe79uA1wPtwap6d9tJqlHiV401Hczj6WpGAwNmtrxHptRuaSWiyJ3oMlWJcoWCBtZjeqcfiwEP/Z1DHr7JlkwJG2rUPvrvg1lE2JeO84yArzxt52kg==;24:rw/YtzrbSbMWa2J5WAL9ATWQ+4Mb+p4KMlPg3yypXoBrds6uFppgE1xTQJEb0HmZdmDBzaO81+wB2WYRoKCKU2Cnp+jS7UqavCRwNb+AAf8=;7:0PWphlwZ2aaq6neE2ujryEpODz7lAyGlX31DhBQE9oYaxI2OngaMeT13vSc55n4kO22k/fAXFepOfj5WBn2BLMTiwanzCwv0gHAXu3todxG3G94kkecxhaELVSfRCRs3mS9Q1yl/nuBm6ZYjd2e3WnN/Sm84mibBdgy2GAmuc56Xzizlj0S/Z0TwPC8f7Zg5f5GYYfQLcEASAciMarVYFOh5Azt+fAKapXNyCQqOzZQQIeHnW4bSJQaRxys3XYnJ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1141;20:tFgl2L01qBytYmeL1kwmtCLXjorJDIT7BpWyxM39IPBh0fjS82IN80iXuIx+DvQ5DjOOT5I9pWisQKMCClPW0Y5NIOLsg+iENHR3kb/oPVT003So0Jicta86WFjlqfS/nS4BoRxPvwB48bRNgzYNodAgWKTSHjXfT85meOMplUZ9hREKNuNrv9MD4moiPOjWd9ZLUIrTpSc06dYkm+NreHjYyKjsFV7ryJrubGdpG4GPARBVyPYwNxEw7i7uLh6F X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2016 22:35:32.3340 (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 This RFC patch series provides support for AMD's new Secure Memory Encryption (SME) feature. SME can be used to mark individual pages of memory as encrypted through the page tables. A page of memory that is marked encrypted will be automatically decrypted when read from DRAM and will be automatically encrypted when written to DRAM. Details on SME can found in the links below. The SME feature is identified through a CPUID function and enabled through the SYSCFG MSR. Once enabled, page table entries will determine how the memory is accessed. If a page table entry has the memory encryption mask set, then that memory will be accessed as encrypted memory. The memory encryption mask (as well as other related information) is determined from settings returned through the same CPUID function that identifies the presence of the feature. The approach that this patch series takes is to encrypt everything possible starting early in the boot where the kernel is encrypted. Using the page table macros the encryption mask can be incorporated into all page table entries and page allocations. By updating the protection map, userspace allocations are also marked encrypted. Certain data must be accounted for as having been placed in memory before SME was enabled (EFI, initrd, etc.) and accessed accordingly. This patch series is a pre-cursor to another AMD processor feature called Secure Encrypted Virtualization (SEV). The support for SEV will build upon the SME support and will be submitted later. Details on SEV can be found in the links below. The following links provide additional detail: AMD Memory Encryption whitepaper: http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_Memory_Encryption_Whitepaper_v7-Public.pdf AMD64 Architecture Programmer's Manual: http://support.amd.com/TechDocs/24593.pdf SME is section 7.10 SEV is section 15.34 This patch series is based off of the master branch of tip. Commit 9fc6ddd95cbb ("Merge branch 'x86/platform'") --- Sorry for the delay in getting v2 out. Still to do: kexec support Changes since v1: - Added Documentation. - Removed AMD vendor check for setting the PAT write protect mode - Updated naming of trampoline flag for SME as well as moving of the SME check to before paging is enabled. - Change to early_memremap to identify the data being mapped as either boot data or kernel data. The idea being that boot data will have been placed in memory as un-encrypted data and would need to be accessed as such. - Updated debugfs support for the bootparams to access the data properly. - Do not set the SYSCFG[MEME] bit, only check it. The setting of the MemEncryptionModeEn bit results in a reduction of physical address size of the processor. It is possible that BIOS could have configured resources resources into a range that will now not be addressable. To prevent this, rely on BIOS to set the SYSCFG[MEME] bit and only then enable memory encryption support in the kernel. Tom Lendacky (20): x86: Documentation for AMD Secure Memory Encryption (SME) x86: Set the write-protect cache mode for full PAT support x86: Secure Memory Encryption (SME) build enablement x86: Secure Memory Encryption (SME) support x86: Add the Secure Memory Encryption cpu feature x86: Handle reduction in physical address size with SME x86: Provide general kernel support for memory encryption x86: Extend the early_memmap support with additional attrs x86: Add support for early encryption/decryption of memory x86: Insure that memory areas are encrypted when possible mm: Access BOOT related data in the clear x86: Add support for changing memory encryption attribute x86: Decrypt trampoline area if memory encryption is active x86: DMA support for memory encryption iommu/amd: AMD IOMMU support for memory encryption x86: Check for memory encryption on the APs x86: Do not specify encrypted memory for VGA mapping x86/kvm: Enable Secure Memory Encryption of nested page tables x86: Access the setup data through debugfs un-encrypted x86: Add support to make use of Secure Memory Encryption Documentation/kernel-parameters.txt | 3 Documentation/x86/amd-memory-encryption.txt | 35 +++ arch/arm64/kernel/acpi.c | 2 arch/ia64/include/asm/early_ioremap.h | 2 arch/x86/Kconfig | 9 + arch/x86/boot/compressed/pagetable.c | 7 + arch/x86/include/asm/cacheflush.h | 3 arch/x86/include/asm/cpufeature.h | 7 - arch/x86/include/asm/cpufeatures.h | 5 arch/x86/include/asm/disabled-features.h | 3 arch/x86/include/asm/dma-mapping.h | 5 arch/x86/include/asm/fixmap.h | 16 + arch/x86/include/asm/kvm_host.h | 3 arch/x86/include/asm/mem_encrypt.h | 91 +++++++ arch/x86/include/asm/msr-index.h | 2 arch/x86/include/asm/pgtable.h | 26 +- arch/x86/include/asm/pgtable_types.h | 49 +++- arch/x86/include/asm/processor.h | 3 arch/x86/include/asm/realmode.h | 12 + arch/x86/include/asm/required-features.h | 3 arch/x86/include/asm/vga.h | 13 + arch/x86/kernel/Makefile | 2 arch/x86/kernel/asm-offsets.c | 2 arch/x86/kernel/cpu/common.c | 2 arch/x86/kernel/cpu/scattered.c | 1 arch/x86/kernel/devicetree.c | 6 arch/x86/kernel/e820.c | 2 arch/x86/kernel/espfix_64.c | 2 arch/x86/kernel/head64.c | 103 ++++++++ arch/x86/kernel/head_64.S | 42 +++ arch/x86/kernel/kdebugfs.c | 30 +- arch/x86/kernel/machine_kexec_64.c | 2 arch/x86/kernel/mem_encrypt.S | 339 +++++++++++++++++++++++++++ arch/x86/kernel/pci-dma.c | 11 + arch/x86/kernel/pci-nommu.c | 2 arch/x86/kernel/pci-swiotlb.c | 8 - arch/x86/kernel/setup.c | 17 + arch/x86/kernel/x8664_ksyms_64.c | 6 arch/x86/kvm/mmu.c | 8 - arch/x86/kvm/vmx.c | 3 arch/x86/kvm/x86.c | 3 arch/x86/mm/Makefile | 1 arch/x86/mm/fault.c | 5 arch/x86/mm/ioremap.c | 50 ++++ arch/x86/mm/kasan_init_64.c | 4 arch/x86/mm/mem_encrypt.c | 203 ++++++++++++++++ arch/x86/mm/pageattr.c | 78 ++++++ arch/x86/mm/pat.c | 4 arch/x86/platform/efi/efi.c | 15 + arch/x86/platform/efi/efi_64.c | 13 + arch/x86/platform/efi/quirks.c | 4 arch/x86/realmode/init.c | 13 + arch/x86/realmode/rm/trampoline_64.S | 19 ++ arch/x86/xen/mmu.c | 9 - arch/x86/xen/setup.c | 6 drivers/acpi/tables.c | 2 drivers/firmware/efi/arm-init.c | 13 + drivers/firmware/efi/efi.c | 7 - drivers/firmware/efi/esrt.c | 4 drivers/firmware/efi/fake_mem.c | 3 drivers/firmware/efi/memattr.c | 2 drivers/iommu/amd_iommu.c | 10 + include/asm-generic/early_ioremap.h | 17 + include/linux/swiotlb.h | 1 init/main.c | 13 + lib/swiotlb.c | 64 ++++- mm/early_ioremap.c | 51 +++- 67 files changed, 1351 insertions(+), 150 deletions(-) create mode 100644 Documentation/x86/amd-memory-encryption.txt create mode 100644 arch/x86/include/asm/mem_encrypt.h create mode 100644 arch/x86/kernel/mem_encrypt.S create mode 100644 arch/x86/mm/mem_encrypt.c -- Tom Lendacky