Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756719AbdGXTPR (ORCPT ); Mon, 24 Jul 2017 15:15:17 -0400 Received: from mail-sn1nam01on0083.outbound.protection.outlook.com ([104.47.32.83]:8000 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756589AbdGXTLx (ORCPT ); Mon, 24 Jul 2017 15:11:53 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-efi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Borislav Petkov , Andy Lutomirski , Tony Luck , Piotr Luc , Tom Lendacky , Fenghua Yu , Lu Baolu , Reza Arbab , David Howells , Matt Fleming , "Kirill A . Shutemov" , Laura Abbott , Ard Biesheuvel , Andrew Morton , Eric Biederman , Benjamin Herrenschmidt , Paul Mackerras , Konrad Rzeszutek Wilk , Jonathan Corbet , Dave Airlie , Kees Cook , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Arnd Bergmann , Tejun Heo , Christoph Lameter , Brijesh Singh Subject: [RFC Part1 PATCH v3 15/17] x86: Add support for changing memory encryption attribute in early boot Date: Mon, 24 Jul 2017 14:07:55 -0500 Message-Id: <20170724190757.11278-16-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170724190757.11278-1-brijesh.singh@amd.com> References: <20170724190757.11278-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: CY4PR04CA0049.namprd04.prod.outlook.com (10.171.243.142) To CY1PR12MB0150.namprd12.prod.outlook.com (10.161.173.20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca27d2fb-ff55-48f7-6e9c-08d4d2c7664b 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:CY1PR12MB0150; X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;3:mH1+iWLhOzDBaEmjvZLi804OpxnWM1O2cRCzYP61cuiSgACxLmw79ay0OIePCz4qAK+KyhAUbe7LBP8qRVDpJF8IHQaN/28Py5+WTWaEeLLJ/bxEWwz61rUtdNr+zDI6ueQS0+7d2RlaNcyvDrc71Vfi7Fbnr/aQBPJ0jVCtBuDIXFwmpOwXdBDu10aPhTFq3cOkDG8SeOdT6KOP/VJ/SyFojXlugn4vdaLg1Eq3VC9LjGC4QUn4oxquFVL12CjyhEMkT1pV67AVo3YpPgb5eV4Tg+j0Ch2okCmlf2lbrKKibg1Wk+M9mUNXJnoP7G9dpSl15HXr5I4xLjE8VOlKGAxuxzs+HyGYCer9Yi8agizatSapCy3/wTywkTaf1mJ6qax3+/SAwNbD2DmBY7TYkIkivGSXgg018TfzqHwYvhFLgu1z6xe03JkpzV1qaw1RpAdB9bvWnwwFYxQgqo/33D3Rcvj1BGhPQaZrMMfaLCQhFTpGB2HGKmXxU1c3/dLKjgBgpR/8ebVvmxlWbb3lur0jV5TQdTHg71YIvTozZlsfJwUonV8OxdbEa9mdfgUXMCjP73pZqI7i5uvYvWyRR8GS6eZHCZol2Epp1cdWCnHKssNZT08NLkMqBkNjR+qtxncSCLXc0JgB0hkCd0N++l7UZt20JGk0cFZiAye/XfpQfXATI6xPDTUAe7mDgnZJ91KrpwouRbGQ+31LnqOwmQ/ByU4RhRt3kPzbC5mW6h2gNdpym2bHMvt0rxtFWaoM9sGje5Jzamebj47keQjNBg== X-MS-TrafficTypeDiagnostic: CY1PR12MB0150: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u7QqeyThct1SZ1+J8E3wM6JOdCDYdQlAudQg7NHv3VQd2OTb4RTPl8CNaVsF4gAZ8fQTKFkM86nufko/b56CJKig X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123564025)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY1PR12MB0150;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY1PR12MB0150; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR12MB0150;4:Xnow6KlBxCtHULItg2Dzig+MGL/ammv489Qbg140k5?= =?us-ascii?Q?pTVQ3H6wvQKeD/hQ7NxEyNNy280AHlUWOe7+wQGLDgyH0DIZnjncqpWBY7db?= =?us-ascii?Q?Aq57bHaPhGCzu38EU8mk4uyFjgLML8utfna0duT5lZwPO8C9vkYn2TTiLQIC?= =?us-ascii?Q?Rd0rHGZ72rsgouYnmyhLL1m3Zgd0QYjaNdzJlAnJitASPQoYkmkPfuCj/0s/?= =?us-ascii?Q?+ULUngLx+yg7lQVnvl+uMSc7r7TCEstrBJfbM3OKwLf2zJ5QzvMQpBPqUUZZ?= =?us-ascii?Q?nJ176ySaoVWpp6NaTal07X7vztVmqYVMlQImoEtyiNHBcY4k58bycM6UCpKk?= =?us-ascii?Q?1HakAEmbkY3CvqNDEEP4CD1ZNWd11QPu+i9Cp0IBWG7FLt9ZetXbdHA6zhAU?= =?us-ascii?Q?ce9oaBLcHJ3dT/wbUR/thlOvBtZ1N3eNGRsruF05Nu5I3moUANFkX4a0ekZU?= =?us-ascii?Q?Y2VJ4qY8LXHvXvaLfedZWtvezkZ5W7aIs40jie3QMCeiJa8O/oRt6pTgcGMR?= =?us-ascii?Q?cegS+1vaubF97F5J8v1TGH0VO5WdTscEfLqGXiKN1ohJOEbx1eI25CpFHO6d?= =?us-ascii?Q?Th0xjsBRBLUP7SFVIRDqqQo2LrU6Xs+1uUT/yDKVigxXDvIQ17iplyXAyTKk?= =?us-ascii?Q?CFvKE44Taz/f8xmoAnH0r+TWiHFYWTGrS7cneMB58n7dKKwOi0xFFUspXG1o?= =?us-ascii?Q?rfqDTcvFn3SoLu3OzJfGTmPYzWCLeKpEGQmRf7aHbuP9WC4u4E1ROUQbWDOT?= =?us-ascii?Q?0u9FMougzVH68Wz8ntSaqtuxq88Hcn3eNw5emAXlwpfUDrQ5+kO282cooJQI?= =?us-ascii?Q?G0O+ojU2NTPlFu11j1IeYULOD+pY/UQbQtji9sBuIIGoq0WE2aMh97ufRtEg?= =?us-ascii?Q?as/Ct7MZpYz4rRS6MEftULIGn/uvy3K6omtOl3M3JR2AKX/cSlPQQF+zrNG5?= =?us-ascii?Q?v5dpENpSwuNYnQ8J+JEqcS4Th4NDTzlreq6pTLeDrWTQNxJ0zOGznYoqC/MJ?= =?us-ascii?Q?HHeZLnmd3RH0eXOzbcBlO6tkCq40O5v7qzZcSfhx7qUyTIVtJePvVTKAEf9H?= =?us-ascii?Q?eCHApwAMcRdcaD6PZ9xhXKPvCDxknwZiFdXPk+L9UGZ+30bw4MF2Goybcb8T?= =?us-ascii?Q?W884kBdFMU+E7vJeef1VCk1SsTATmmT/lo8c52nwc0YBKXFz24Cxa2hmTlYY?= =?us-ascii?Q?QsvQzC2nAGR+dJp2yUWAGvXAbTmQ2f2rjf?= X-Forefront-PRVS: 0378F1E47A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6009001)(39840400002)(39850400002)(39450400003)(39400400002)(39410400002)(39860400002)(199003)(189002)(4326008)(81156014)(7350300001)(81166006)(50226002)(50466002)(68736007)(36756003)(38730400002)(1076002)(110136004)(53936002)(6116002)(25786009)(48376002)(8676002)(86362001)(305945005)(54906002)(7736002)(2950100002)(6666003)(50986999)(101416001)(47776003)(105586002)(5660300001)(5003940100001)(7416002)(33646002)(106356001)(66066001)(6486002)(7406005)(97736004)(189998001)(3846002)(76176999)(2906002)(53416004)(42186005)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR12MB0150;H:ubuntu-010236106000.amd.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR12MB0150;23:BHplzpCg5SrcvyQUYPksZ8NEyfEZf+8Flif52zMES?= =?us-ascii?Q?92t716grO7owT6Ro9/fjBCqo6zyvGvCNHead3N7SXxYh2aHM7FFiwnwLrcLq?= =?us-ascii?Q?t0EEM0Hnxyq9ViBrItkrH9P4PiI4yCFl7UjXgZ4+3D85Ro1W/cVjXv+Zad3R?= =?us-ascii?Q?rW9dLh31as8oBYat75lTm/h/Ca7GX9EeikiNH04gsqUhDqvVvdcv3KTUCO7h?= =?us-ascii?Q?xg5/Rt4Hk5HXedQsTEzlWEivw4F9myr25vkR/rGoXaVAedcxe0WxkfVVHibd?= =?us-ascii?Q?SXjZUxJwYaDG53Md5bobXdhK5tpBbZqZbD7BMYfA0FWz8ij10o2Cs4BkoqIq?= =?us-ascii?Q?iYORzSDREmAxIqhlRPgGnFJXB1eBZYA+4ky5Sb2rRt+DB12cHmqp79rUKIz3?= =?us-ascii?Q?KwW7aOSV33kAHf0x9z4tDvoDB14pKMY4eiEjTQd68NgCkM/dLI5PrnijAGCs?= =?us-ascii?Q?8jWXEivwSS2dIxKPFR6buMC0HOxytHLQ9ow6wGo6gjry/ZC0HjZ2Qh1mH5Yu?= =?us-ascii?Q?g64QHevLMw20tahKvzHX+CWEV62j5sXum9Srr1nRr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?Q?jqyav73444LkFPaUIyPPm7C2Eu7av8lFHtqtMcOgu8BuYDiHcpkNMiqUc4uE?= =?us-ascii?Q?jmoGXJ3fuQHQo+OFeGKJlK?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;5:oRI5xG80Paa0UEBcc8QM6dKRebA8i/7W1S7414CSp2InUAoO8A6pGMUfBNaZzjz2CczusrrXoD7k0PKNgoqeE67ZYJpzVCpRDQQy6Mee6SFbokwHMYbdd+06Inqrvpvge0qTeZhvDYFy2tNLQMhbR/woiR93Uvar+xqaNH2RDf7wEuusJmS1u8bEyinhO5IxNCG+rqtfR4W7IanpdiUyqrcZUcMAxH+kNybAFT1uyJ/Y4u61PavOYBQ4/ytDfBUFD9kimifcHjt9ZrykdHlnUY09T/RyoSSfEb8iSKO3BQtfMvE4U2g1CoEBGl7G47xwqaYXHo/U4g3E3lFtJjTxjzksfOs8MfWHlN+m8JlP3d7r50FQokJ2DqoJPqTrdj/GnwwLsegiPEj/pDfC2RVTeOq0HTai9hCaoWn+6Zpab2IXvZAV6M1zatM7nI3OXkhHI7bbRjv9AtAlMKt4OTH6apgkqZPxNT+XIddljs6FUSa27KDi6HrDDxtf6hCz3OEm;24:46m6YrL5TN4IJe4Bvq0deBhloFgy2xRNi+rm7p8w3BtejqFcfPFVWh4tXcsFi11IeEyaXeCMrWOUdb7PRoRqDFzHqx0lVRKvby/7Bbh6kgQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;7:Vruqpmot58VQY2oITtEkPVBzgUKsGenNfWLETMrI3K8j5qiKpGul5IotrLonaGHpR2uyJjlet+N93G2gKvMjGFf9uMNCnKdWkXbR/w+45+uSD+F349lx+f6CoKGkMBDaKm34Hbyz7XvwRGPHg1z1/8QQMD/jjhj5ATuLL9lDsDa2EvYHNQ1BXggPpuxIdBjhnvhlyAyVGuf9Zx26iqoNTw4nMd13rIzx6bQJCPTY0zcp4pDuPskN2LJW+NMB7G7gfreSzultEolOffjRSPsQlxHkb3MHlO/6FBEJITkaz/F24FQuABKqnjjlO5dGpb0ld6TdxzSQRVmnUlf5iGwSEmjRyWc8QWWR55doCg1tiCP05MwJgj2p7VMWt5HEkj7SY5+M4fXU2vl5RxnLDXvhLeaVhiDZgblmXWkb1T4HKyLWf9oxqV8qwozCglGHvc7uUFViuRi/+HSvbtijvKC1vP9t8dKlaHCM8Ldj2Edvf8gFQF1fTj0y2RqPKquRWxTLC4IlDRNLS5D5Y9TJqd7xMP52f2AVX5WnnMyLaLMuJrempqAh0xL8GAD86n4CkujsKIDaHRGW1KgkLkHzO88ghEPFrmMW+ZXvxlxhDm3/rdR+/9dB7L/uShDHisUl4kClT6wz4don88W66e+kskADZMl4dxHm60zIs998aAGIZnTnfYfrUL3ybO56tnT2dWxSF5Uxd+46EEVxUIe/C83dAvJEo+GA9t6pohGMuj3BWHfy5w6lE6bNdxne6VH+7Erebtblil7MMYxQLxD77JYvXM+HSDJ887ezlRQyWkB/Qow= X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0150;20:GtoCSU3HAaCw1l117ukKAdQOCwH6LZI686YuRngKoDlob/vHK8e9k1FMBjjyENZbMqnYL5yf2Rd1GpWCEQ8BAYVG896A8qjR9HsMTjcdJ0q1bGs/Nrcr6JpVUnXUa3sxUZ/ySyb8iDA58hH/A/kAuEBIOiPH2Xrg+O85kRy59f5l6I3cOFfp5whHc1Cfpj4Nuggq+/twsFOab6M44MtQK6CxWoawXaVS2mLm2VHK81RR/oMvtkrdJ8Azg7+02G1d X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2017 19:08:40.7939 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0150 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5376 Lines: 185 Some KVM-specific custom MSRs shares the guest physical address with hypervisor. When SEV is active, the shared physical address must be mapped with encryption attribute cleared so that both hypervsior and guest can access the data. Add APIs to change memory encryption attribute in early boot code. Signed-off-by: Brijesh Singh --- arch/x86/include/asm/mem_encrypt.h | 17 ++++++ arch/x86/mm/mem_encrypt.c | 117 +++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 9cb6472..30b539e 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -46,6 +46,11 @@ void __init sme_early_init(void); void __init sme_encrypt_kernel(void); void __init sme_enable(struct boot_params *bp); +int __init early_set_memory_decrypted(resource_size_t paddr, + unsigned long size); +int __init early_set_memory_encrypted(resource_size_t paddr, + unsigned long size); + /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void); @@ -69,6 +74,18 @@ static inline void __init sme_early_init(void) { } static inline void __init sme_encrypt_kernel(void) { } static inline void __init sme_enable(struct boot_params *bp) { } +static inline int __init early_set_memory_decrypted(resource_size_t paddr, + unsigned long size) +{ + return 0; +} + +static inline int __init early_set_memory_encrypted(resource_size_t paddr, + unsigned long size) +{ + return 0; +} + #endif /* CONFIG_AMD_MEM_ENCRYPT */ /* diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index ed8780e..d174b1c 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -28,6 +28,8 @@ #include #include +#include "mm_internal.h" + static char sme_cmdline_arg[] __initdata = "mem_encrypt"; static char sme_cmdline_on[] __initdata = "on"; static char sme_cmdline_off[] __initdata = "off"; @@ -257,6 +259,121 @@ static void sme_free(struct device *dev, size_t size, void *vaddr, swiotlb_free_coherent(dev, size, vaddr, dma_handle); } +static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) +{ + pgprot_t old_prot, new_prot; + unsigned long pfn; + pte_t new_pte; + + switch (level) { + case PG_LEVEL_4K: + pfn = pte_pfn(*kpte); + old_prot = pte_pgprot(*kpte); + break; + case PG_LEVEL_2M: + pfn = pmd_pfn(*(pmd_t *)kpte); + old_prot = pmd_pgprot(*(pmd_t *)kpte); + break; + case PG_LEVEL_1G: + pfn = pud_pfn(*(pud_t *)kpte); + old_prot = pud_pgprot(*(pud_t *)kpte); + break; + default: + return; + } + + new_prot = old_prot; + if (enc) + pgprot_val(new_prot) |= _PAGE_ENC; + else + pgprot_val(new_prot) &= ~_PAGE_ENC; + + /* if prot is same then do nothing */ + if (pgprot_val(old_prot) == pgprot_val(new_prot)) + return; + + new_pte = pfn_pte(pfn, new_prot); + set_pte_atomic(kpte, new_pte); +} + +static int __init early_set_memory_enc_dec(resource_size_t paddr, + unsigned long size, bool enc) +{ + unsigned long vaddr, vaddr_end, vaddr_next; + unsigned long psize, pmask; + int split_page_size_mask; + pte_t *kpte; + int level; + + vaddr = (unsigned long)__va(paddr); + vaddr_next = vaddr; + vaddr_end = vaddr + size; + + /* + * We are going to change the physical page attribute from C=1 to C=0 + * or vice versa. Flush the caches to ensure that data is written into + * memory with correct C-bit before we change attribute. + */ + clflush_cache_range(__va(paddr), size); + + for (; vaddr < vaddr_end; vaddr = vaddr_next) { + kpte = lookup_address(vaddr, &level); + if (!kpte || pte_none(*kpte)) + return 1; + + if (level == PG_LEVEL_4K) { + __set_clr_pte_enc(kpte, level, enc); + vaddr_next = (vaddr & PAGE_MASK) + PAGE_SIZE; + continue; + } + + psize = page_level_size(level); + pmask = page_level_mask(level); + + /* + * Check, whether we can change the large page in one go. + * We request a split, when the address is not aligned and + * the number of pages to set/clear encryption bit is smaller + * than the number of pages in the large page. + */ + if (vaddr == (vaddr & pmask) && + ((vaddr_end - vaddr) >= psize)) { + __set_clr_pte_enc(kpte, level, enc); + vaddr_next = (vaddr & pmask) + psize; + continue; + } + + /* + * virtual address is part of large page, create the page table + * mapping to use smaller pages (4K or 2M). If virtual address + * is part of 2M page the we request spliting the large page + * into 4K, similarly 1GB large page is requested to split into + * 2M pages. + */ + if (level == PG_LEVEL_2M) + split_page_size_mask = 0; + else + split_page_size_mask = 1 << PG_LEVEL_2M; + + kernel_physical_mapping_init(__pa(vaddr & pmask), + __pa((vaddr_end & pmask) + psize), + split_page_size_mask); + } + + __flush_tlb_all(); + return 0; +} + +int __init early_set_memory_decrypted(resource_size_t paddr, unsigned long size) +{ + return early_set_memory_enc_dec(paddr, size, false); +} + +int __init early_set_memory_encrypted(resource_size_t paddr, unsigned long size) +{ + return early_set_memory_enc_dec(paddr, size, true); +} + static const struct dma_map_ops sme_dma_ops = { .alloc = sme_alloc, .free = sme_free, -- 2.9.4