Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753438AbcDZW5Z (ORCPT ); Tue, 26 Apr 2016 18:57:25 -0400 Received: from mail-bn1on0077.outbound.protection.outlook.com ([157.56.110.77]:43264 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752627AbcDZW5R (ORCPT ); Tue, 26 Apr 2016 18:57:17 -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: [RFC PATCH v1 07/18] x86: Extend the early_memmap support with additional attrs To: , , , , , , , , CC: Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , "Konrad Rzeszutek Wilk" , Paolo Bonzini , "Ingo Molnar" , Borislav Petkov , "H. Peter Anvin" , Andrey Ryabinin , "Alexander Potapenko" , Thomas Gleixner , "Dmitry Vyukov" Date: Tue, 26 Apr 2016 17:57:07 -0500 Message-ID: <20160426225707.13567.10656.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20160426225553.13567.19459.stgit@tlendack-t1.amdoffice.net> References: <20160426225553.13567.19459.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: BLUPR13CA0060.namprd13.prod.outlook.com (10.160.82.31) To DM3PR1201MB1120.namprd12.prod.outlook.com (10.164.198.20) X-MS-Office365-Filtering-Correlation-Id: c764f18d-fb1c-42a8-1064-08d36e261af6 X-Microsoft-Exchange-Diagnostics: 1;DM3PR1201MB1120;2:slrhMQ8xCPWdzB1Kqm/icxFqEfFEm/lhRRo8elHsEkq6XeNY7/9l497s1r/b011fjikbGhbDnO6FBfFbP1lAyrMSTB6CbpbsuI2nVDSnGalJqJ0EY2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nDtll4TRk7d1gWXstbacGRkqCJ7NKyR6ZX6WE3qbc9L+pwXxHXKIjGweOW7kwzVEX1TBcIRaGvUoNkQBMFpBE34ik2lnY5j+0e7V0+QUJujzWrCVl9iJgrYfrSz2i+4OjvVmvogiLeRKrR3/HuUXnvsvGKALqrwgTfYGQ1KTgx2sv3AFxNy0qFy++gwM2oIuTVtvxtLek4OuMIpIOTQTUBMTsLrfHDmDLllBLp24w+uVa9afGCFV7UD6MJ20ddD4VAoXZTK0F6eBbm7/NKXvFYIiSdysWIi7/gH0a3bu5fnqxZ7fJ0yHij+Eio8skJ+rzfEXH5ho3iDeA5P+53dhV6+FP+nNUY/jkW6vT6lL5So0MnU9jKu5pUIuvdebQwCuFP;4:XyrXMAXP0KMWJOWAwASwU1Oc9EiNpPJ1v3gc+zJe/mLDiaK/n5IY/kEEGYavh0C2aOZL+jxwKoYKiWUOJ1J/OSirlCadAbhLOJF/s7ItUPhVBHMGjsWPlwNxyvDVZsVJ9sWNJW3AgYLjhvYVwrQnxU6jf9pI+a7sAlzzEo6RPx872Aps/82awNMNKMs7fpZcIk9H8FBHPcr/5jQhulX9auw8pPj3Jq0f+TMSnBWuu6lhXsGXcJm9uX3KHsnGMLCU0LyL0End2+z8RysuZZuSQ93WRS7T4kKcRvXh8kKM1oZjexnZKLRMCIG1ANP5JRO8QTCGt1aFyfBgyMfumoDWxsAQ9Ff8lTPezsTTLxqQiK13y3RIuNLBFZKmYX3HWItWMuXzL3dCXRvmHb6FG+003NtOjqRr7BE/r5jAVUSZ0HA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521072)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026);SRVR:DM3PR1201MB1120;BCL:0;PCL:0;RULEID:;SRVR:DM3PR1201MB1120; X-Forefront-PRVS: 0924C6A0D5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(42186005)(97746001)(81166005)(5008740100001)(5004730100002)(66066001)(47776003)(2201001)(2950100001)(92566002)(103116003)(53416004)(19580395003)(77096005)(19580405001)(50466002)(86362001)(5001770100001)(4326007)(4001350100001)(23676002)(33646002)(230700001)(9686002)(76176999)(50986999)(189998001)(2906002)(1096002)(1076002)(6116002)(586003)(54356999)(229853001)(71626007)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM3PR1201MB1120;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTNQUjEyMDFNQjExMjA7MjM6bkd1ckQvZERBUUYrcDFmblBFQUdRUEt3?= =?utf-8?B?dzhEbHpDeVlKTTdTTkdmcldxa2ZGaXhqQnBvRkdoU2k5NDkvcVg3aHlpOXFy?= =?utf-8?B?NWdlQ2FGTnBueXdwRFB2V29ETjZad2xGSTczY0ppNVVrSVBEVmRYZlB1Yldm?= =?utf-8?B?OWVQK2ZBaTA4YkIwR3FyNU9UVFgwbDloWTZ4UGg5aGthYzNVRGJ5T1d5VzBJ?= =?utf-8?B?cVhGdkVMQnZNdnpqSHQ5emFtQzRsRk9uQlFTVXEyaktzeFJpNlNaY3h5NFRh?= =?utf-8?B?WlNyNXo0ZVladHUwTHg3eWo1WUdPNGgwSXFrdVZvQk5lQkdWeENxVVAyL0Rp?= =?utf-8?B?NHJwMEx2TDY1ZWphNjc5Q2g3Z0dqcklMcjN3a0kwZ0xWdmYzOENaOHJPdVUr?= =?utf-8?B?Y2lrdEFYS0UyUGxwWTBUZU1ZOTFra0V6d2lKajBvY2p5dGxzMWIvQU00UVJj?= =?utf-8?B?alk1TFRNN0lvRnlCMFB5ZUYrZVhZTkxKMWZkY0gxOG1SdE9ua1NvMVB1eFJQ?= =?utf-8?B?c1BqM3ZLcllyUFZ1Y0tGTW9Sc24wb0hKYXg2YTlRZnd6bExJemRwLzByVk52?= =?utf-8?B?TTN4dlNSOXJRV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H6E/TvVy+k2swkWrsbM1MXDyRdyduPA73chsgj1klMjdqCWUWRYEQC+5mjvqNUsp0pg92L8WDhGZkBlab0CSUVZEybbq31sePkguBgn/yw==;24:DnJT+c5bxRgdUcH5BXiA2Accx+FGCIWzThh3TW7Vb9myCoDKX4ftZciTp4WxBdTkZkBnxU153TLIBh0bdfpHrFbkyBY6mlj8Kt6mRt8xPQ0=;7:hv0fQlAp8EKJF5lYLjLa4N0n27ws3HVYHpQCpKQADJpiakl1TvFm7y6VFtWY2nQp+PsLi2vZq6RalsBZzXLt4z7H+GoZn5NgyhJ7BQdOssaGXf6UtdZzFAPRP8YmmFYtR9Q/WQRDHVHq5PcmziyLfjsJhUUShODwWwpC3b7Wplo=;20:uhRFp/gXVWWOF65JXAFTBjfxf8RNbd8TtGnthd92pmcazVdvHxl9rWLF27uhab7UKGZoDkmS8AzJgv7OZ8kp2ylIznMCvbfwMUJcY/QL+zMMZvMYIN7CG6jUcezrB8tpDeHaOmlLo7+EzFD31EmIjTFDFuQK7TG5nAWzRzOfqnyq8KMpafRAJuQgTSrVjYdYN4FB/fU7dwQWm1U9eiD+WUkurM3RsbAjd0elEZGlU37U/sKC9tk81nshwvHwxIwT X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2016 22:57:11.0454 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR1201MB1120 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5884 Lines: 154 Add to the early_memmap support to be able to specify encrypted and un-encrypted mappings with and without write-protection. The use of write-protection is necessary when encrypting data "in place". The write-protect attribute is considered cacheable for loads, but not stores. This implies that the hardware will never give the core a dirty line with this memtype. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/fixmap.h | 9 +++++++++ arch/x86/include/asm/pgtable_types.h | 8 ++++++++ arch/x86/mm/ioremap.c | 28 ++++++++++++++++++++++++++++ include/asm-generic/early_ioremap.h | 2 ++ mm/early_ioremap.c | 15 +++++++++++++++ 5 files changed, 62 insertions(+) diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h index 83e91f0..4d41878 100644 --- a/arch/x86/include/asm/fixmap.h +++ b/arch/x86/include/asm/fixmap.h @@ -160,6 +160,15 @@ static inline void __set_fixmap(enum fixed_addresses idx, */ #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_IO_NOCACHE +void __init *early_memremap_enc(resource_size_t phys_addr, + unsigned long size); +void __init *early_memremap_enc_wp(resource_size_t phys_addr, + unsigned long size); +void __init *early_memremap_dec(resource_size_t phys_addr, + unsigned long size); +void __init *early_memremap_dec_wp(resource_size_t phys_addr, + unsigned long size); + #include #define __late_set_fixmap(idx, phys, flags) __set_fixmap(idx, phys, flags) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index fda7877..6291248 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -154,6 +154,7 @@ enum page_cache_mode { #define _PAGE_CACHE_MASK (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT) #define _PAGE_NOCACHE (cachemode2protval(_PAGE_CACHE_MODE_UC)) +#define _PAGE_CACHE_WP (cachemode2protval(_PAGE_CACHE_MODE_WP)) #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED) #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ @@ -182,6 +183,7 @@ enum page_cache_mode { #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER) #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE) #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE) +#define __PAGE_KERNEL_WP (__PAGE_KERNEL | _PAGE_CACHE_WP) #define __PAGE_KERNEL_IO (__PAGE_KERNEL) #define __PAGE_KERNEL_IO_NOCACHE (__PAGE_KERNEL_NOCACHE) @@ -196,6 +198,12 @@ enum page_cache_mode { #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | \ _PAGE_DIRTY | _PAGE_ENC) +#define __PAGE_KERNEL_ENC (__PAGE_KERNEL | _PAGE_ENC) +#define __PAGE_KERNEL_ENC_WP (__PAGE_KERNEL_WP | _PAGE_ENC) + +#define __PAGE_KERNEL_DEC (__PAGE_KERNEL) +#define __PAGE_KERNEL_DEC_WP (__PAGE_KERNEL_WP) + #define PAGE_KERNEL __pgprot(__PAGE_KERNEL | _PAGE_ENC) #define PAGE_KERNEL_RO __pgprot(__PAGE_KERNEL_RO | _PAGE_ENC) #define PAGE_KERNEL_EXEC __pgprot(__PAGE_KERNEL_EXEC | _PAGE_ENC) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 77dadf5..14c7ed5 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -420,6 +420,34 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr) iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK)); } +/* Remap memory with encryption */ +void __init *early_memremap_enc(resource_size_t phys_addr, + unsigned long size) +{ + return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_ENC); +} + +/* Remap memory with encryption and write-protected */ +void __init *early_memremap_enc_wp(resource_size_t phys_addr, + unsigned long size) +{ + return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_ENC_WP); +} + +/* Remap memory without encryption */ +void __init *early_memremap_dec(resource_size_t phys_addr, + unsigned long size) +{ + return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_DEC); +} + +/* Remap memory without encryption and write-protected */ +void __init *early_memremap_dec_wp(resource_size_t phys_addr, + unsigned long size) +{ + return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_DEC_WP); +} + static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss; static inline pmd_t * __init early_ioremap_pmd(unsigned long addr) diff --git a/include/asm-generic/early_ioremap.h b/include/asm-generic/early_ioremap.h index 734ad4d..2edef8d 100644 --- a/include/asm-generic/early_ioremap.h +++ b/include/asm-generic/early_ioremap.h @@ -13,6 +13,8 @@ extern void *early_memremap(resource_size_t phys_addr, unsigned long size); extern void *early_memremap_ro(resource_size_t phys_addr, unsigned long size); +extern void *early_memremap_prot(resource_size_t phys_addr, + unsigned long size, unsigned long prot_val); extern void early_iounmap(void __iomem *addr, unsigned long size); extern void early_memunmap(void *addr, unsigned long size); diff --git a/mm/early_ioremap.c b/mm/early_ioremap.c index 6d5717b..d71b98b 100644 --- a/mm/early_ioremap.c +++ b/mm/early_ioremap.c @@ -226,6 +226,14 @@ early_memremap_ro(resource_size_t phys_addr, unsigned long size) } #endif +void __init * +early_memremap_prot(resource_size_t phys_addr, unsigned long size, + unsigned long prot_val) +{ + return (__force void *)__early_ioremap(phys_addr, size, + __pgprot(prot_val)); +} + #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT) void __init copy_from_early_mem(void *dest, phys_addr_t src, unsigned long size) @@ -267,6 +275,13 @@ early_memremap_ro(resource_size_t phys_addr, unsigned long size) return (void *)phys_addr; } +void __init * +early_memremap_prot(resource_size_t phys_addr, unsigned long size, + unsigned long prot_val) +{ + return (void *)phys_addr; +} + void __init early_iounmap(void __iomem *addr, unsigned long size) { }