From patchwork Fri Jul 7 13:39:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 9830537 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 9A56F60352 for ; Fri, 7 Jul 2017 13:53:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C4B3284FC for ; Fri, 7 Jul 2017 13:53:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8047D28676; Fri, 7 Jul 2017 13:53:02 +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=ham 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 90D1E284FC for ; Fri, 7 Jul 2017 13:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752578AbdGGNw7 (ORCPT ); Fri, 7 Jul 2017 09:52:59 -0400 Received: from mail-by2nam03on0061.outbound.protection.outlook.com ([104.47.42.61]:62222 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752633AbdGGNju (ORCPT ); Fri, 7 Jul 2017 09:39:50 -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=+suR0f3QJrs6nnkyh+5+qoNt3tgFdQL474fdMdtI9A8=; b=JIhNvOnnqwHDFJ5jKKlJFWQSlPjSPloaMtX0/kTbfuv7FSnYeiCuxLaFYIE1Z38gdXsHcZGzQv8jUI9mlVpA+9fbFQuWrR8li/ygE6i7H1+Ift8qLgBOIo1Lue4+0Dsxy/JkDRH+Shgv+/9ACC+TEyZJzJnYMYAT25xBIoDC/Nk= 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.1220.11; Fri, 7 Jul 2017 13:39:39 +0000 From: Tom Lendacky Subject: [PATCH v9 08/38] x86/mm: Add support to enable SME in early boot processing 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:39:36 -0500 Message-ID: <20170707133936.29711.56840.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 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0058.namprd03.prod.outlook.com (10.173.137.20) To CY4PR12MB1141.namprd12.prod.outlook.com (10.168.163.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3353d213-442d-416d-11cc-08d4c53d9f94 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:I90lZ1k5r2kMkLBREWhNVdCwrZi2LZWcl0LlEQncD+HftOjKYA/TBoMBAR6mtUxcSaKk7uj0XD6NFkq+dKPI7Y9nZV47onWLTfa5aJJNyZxp/IwyURZ0FXXx3YT7t1evgULqNfiwAY6aZopQgT2Ij84ZFwI1aoPURso2YGPAf2ji28UfwYCTQKSq1TDuuF3E5XyDxr1A4vgnZGEv3UcWi5IGOrSutIJePo0YtwxcrYBBGC2hrynP6CyetKunypO0Kghx8oJopOvu2/4D8jZfMKhuxPPHJAS9olUrvJPsH+Yn/ReNaj6GNC86tDajGyvsXjLiZsNfWaonc4TZxhxtcuRZ0pph1MsoepyJ4rzM69WEF57z1DQ+D6jxEEv9EA+xZOamHc8tMHY9+jIBsHAekeoPsjTRLVqmVvCFzNeerI0PuhjzM6p7s9UAAs39ZHPvtLNb4qCnmoIkBmOrmXSRnpaOp2USR7qzkMI7JUXzLiuNhz3ydfHhwqfClrcb6Gi8vmSA4QaZocxP0O6cIiEK1K+Ma4r9aOmc7iC48wCrrLZF0B4APBsJDLLw2krjCgkS/PIIONOAsGGvtLrUrd3sVhLSD1xi59OJUJIIZYXPl4bw+bEaEMFHlRm+nIFIHB4HMp0jieco+jRdkHo4cUGRbKVH6yBFhWOnOOQRhrACkgl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a8fNIB7aaqXPFXQQvyuWGHpewnlFtYwXxotEVFoWsv7Qm8qisL+y/3CYRmDFjrrjg6pcu6b6sOg7V0H34kjAxv0NwIUZJNQBqy7uxTIDvJFRv+RwrNiHdnuQf5xEkl7woIyokDbwBeVW/4cR/gExYLB6ZVaMltFu9gyK6sB7HR8zaN5hP9fqu5beX4yZ3UnWul15jDoxdphdTcPG/AL8Uw/6ULF3PqV2HCwg0VcM X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(125551606395959)(133145235818549)(236129657087228)(767451399110)(148574349560750)(167848164394848); 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?MTtDWTRQUjEyTUIxMTQxOzQ6RHl4Z25ucmhZMVhMeXczWjFRUTREMjFrdjFT?= =?utf-8?B?eCszU2NsSzFMOGZhZlJOMVdiZ2d5Z2kvcUFUYUFCRzNmUzJSbU1KcENmL3lU?= =?utf-8?B?VmNzU2lyT2lqMklFMTFrOHJ6bndnaGFmM093OWlETFNpNUczeUZLcnZGZ0RV?= =?utf-8?B?OGRURHQ4cEFlVEtIeEJZM3dFYXJHS1BnSGdOTisvVHAvdlk4cFNmbThJTndT?= =?utf-8?B?WmhPY1ZUcWM5ZCtadHFIdS9qUjNPa2tFZlVRTHBsK3FyTndtWT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09SUldTUmVtU0N3ZWx3?= =?utf-8?B?SVMzYmpLZG1sVE45OG8rUWJQbE5pYnZJSzhNamlSU1Jnek1RUzlWMlFKRi81?= =?utf-8?B?anNpaDVoZDdIVjh6elZiak03WS9wZDVjK25DazNMeXdFdVZ4YUJkeXl6djhm?= =?utf-8?B?MUpncFJ6UElPSWxxTkFGellWMGgwSTBIY3Zacmt6R3FZYXdwckp3SjFiV1hp?= =?utf-8?B?Z3ZCZm05ME9ZRVVnSkIvY0YxdUJ6TEhiaHBaSEpza2RWNFdvQ2djWE5vZWho?= =?utf-8?B?byszaW5iM0Mzaytpd1NDeHYvNXdRdEtCcWVGUnN6QlhxanVvNEovamt4ZWFp?= =?utf-8?B?VnJIVFZkN0Z3dXRJNXZnd1U3VDFubGh6eHFSL1d6bGhXMSt5d3BCd3lsSmlt?= =?utf-8?B?aXlmUmJJTFlFMGp5eWw3NVBIMkVwRVAvTElCV3hXV3BPZjIyVWJXbFBJalhJ?= =?utf-8?B?SVEzK21FZDUxK1ZsVVFUWEYyZnF4QWk4K0dJYkZWYmQvNXZONFJNa0dZaVFk?= =?utf-8?B?VDk5MlVmSjh5YzdBUDJKQmtDUXpKNjBXd3dFOXVsMEF6Ty83TTdBYmtrZW9M?= =?utf-8?B?K2dyZjdUdncrWkM2NlYrQmIwY3JjN25EdFpxWFFxajBsTVpxNktRSlhtWUNP?= =?utf-8?B?Y3dtNjN2NklucmZzdmpqQ0p6MDFzc3RTYmlCV3o2UURzNUhnNnY1cklQbDBF?= =?utf-8?B?Vi9wRENNbktmV1VSTGJyMnlwRzl6WnVUODNpSnU1N215bGcybFpweE00MHBS?= =?utf-8?B?Z1Z4NGFWOXc9PQ==?= 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)(575784001)(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; 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?MTtDWTRQUjEyTUIxMTQxOzIzOnJ6QStleHJhaVdieVJTUGVzVmsyYldZMmJS?= =?utf-8?B?OURxblZIdk5KSktaRTJNZGdNMCtMYXpBRUsxc1VyYldVZkt4YmU5VUtGWkcx?= =?utf-8?B?dUdHeGNSMmFyNkpsN3ZKYnhPUndaTXNWV1VyOWZlN1FYb1J5dDVGaXErNVJR?= =?utf-8?B?bFl2VzZ5TG9yczMvMVIvbGd1aFNJbmZKWnp4N011WW1Wb2xUWVhIVzU5Wmh2?= =?utf-8?B?SmZ4VXRUOHNyUXhQYWdsMlhzWmZMOGdWbDA4dGR0dHpnenY1OEdFUnNOZk5s?= =?utf-8?B?TVBLU2wyK2dBV09PQXIyZ2w2TTZSbzdUVFNEZXV5Tm1WbGlkdUMvSEpLbVNr?= =?utf-8?B?bmpnenlRekhwTmNmdzVMRVhTNUtmUEVhajNYbzV1SzlDSFFtbnNUR2k4N29N?= =?utf-8?B?dXBnQ041Lytod1dFcmpqcnV5ZzRISTVadlE2ai9LVUR0K1M4UHhlbFpSNEQy?= =?utf-8?B?a081elNwZE0vaFI0UHhVT2xpOGhPcHJJRkpyMmp6QWkybjRScGVvcEdScWgv?= =?utf-8?B?QXR3eC9xZDJFcldzM1lGSk1nTlBuUittalN5Y3N6dFgwN3F6NVJVbE1QOVpO?= =?utf-8?B?WTlSaVBrV2R5WmF1VFErUVdQeURXTFhseVpZUHlWWTJIcEZnWVc0dW5raUN1?= =?utf-8?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QPwdb4XYhFXcKRBAnHyd4ZYqde6mDkHZ8erH5csWHjT7WeQuHToLLgoelLrlCN81MLpuTVFdUODRDjbxQcRzrZekv5aCJHxcu+D8FR/WxyCoHYr9gM8+7WYXu7xCq35P9B+2K07NkbPy4PXWPuTCCRMZvGToIAVcRYhmZY6Xfq0RfEEBxRSowvH9hTjbvLRQL2AWPfy0FLIT4/F8tFkyfcT0hD8V6BTQfEB6MCcP1DwaaftnQ= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1141; 20:BRcQFI3pHwhrHMPuBKATy1mu2Wt09C00FHK9quFACGx+baTXjrQydVvBDztRQyKRPXhl5t0PO5I/gtIt2OeNOC6qNm2ObkWlo121XzEC0ahwtBpXt9G2SmE8KMQ/n/amAT/95Wpi67f5hUbA8ZQLJYuTi6sXGKsIW55Xh5xoRyYwOEKdPUn6uxGo45oJwzkNQobmmvw1xrXuMk2f1kPW8qFlhfXSNafLL38OepJjEm39ul8xazbSHIy/ZjarUyMO X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2017 13:39:39.4540 (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 the early boot code to use Secure Memory Encryption (SME). Since the kernel has been loaded into memory in a decrypted state, encrypt the kernel in place and update the early pagetables with the memory encryption mask so that new pagetable entries will use memory encryption. The routines to set the encryption mask and perform the encryption are stub routines for now with functionality to be added in a later patch. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 8 +++++ arch/x86/kernel/head64.c | 53 +++++++++++++++++++++++++++++------- arch/x86/kernel/head_64.S | 20 ++++++++++++-- arch/x86/mm/mem_encrypt.c | 9 ++++++ include/linux/mem_encrypt.h | 5 +++ 5 files changed, 82 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index a105796..475e34f 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -15,14 +15,22 @@ #ifndef __ASSEMBLY__ +#include + #ifdef CONFIG_AMD_MEM_ENCRYPT extern unsigned long sme_me_mask; +void __init sme_encrypt_kernel(void); +void __init sme_enable(void); + #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0UL +static inline void __init sme_encrypt_kernel(void) { } +static inline void __init sme_enable(void) { } + #endif /* CONFIG_AMD_MEM_ENCRYPT */ #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 46c3c73..1f0ddcc 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -45,9 +46,10 @@ static void __head *fixup_pointer(void *ptr, unsigned long physaddr) return ptr - (void *)_text + (void *)physaddr; } -void __head __startup_64(unsigned long physaddr) +unsigned long __head __startup_64(unsigned long physaddr) { unsigned long load_delta, *p; + unsigned long pgtable_flags; pgdval_t *pgd; p4dval_t *p4d; pudval_t *pud; @@ -68,6 +70,12 @@ void __head __startup_64(unsigned long physaddr) if (load_delta & ~PMD_PAGE_MASK) for (;;); + /* Activate Secure Memory Encryption (SME) if supported and enabled */ + sme_enable(); + + /* Include the SME encryption mask in the fixup value */ + load_delta += sme_get_me_mask(); + /* Fixup the physical addresses in the page table */ pgd = fixup_pointer(&early_top_pgt, physaddr); @@ -94,28 +102,30 @@ void __head __startup_64(unsigned long physaddr) pud = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr); pmd = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr); + pgtable_flags = _KERNPG_TABLE + sme_get_me_mask(); if (IS_ENABLED(CONFIG_X86_5LEVEL)) { p4d = fixup_pointer(early_dynamic_pgts[next_early_pgt++], physaddr); i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD; - pgd[i + 0] = (pgdval_t)p4d + _KERNPG_TABLE; - pgd[i + 1] = (pgdval_t)p4d + _KERNPG_TABLE; + pgd[i + 0] = (pgdval_t)p4d + pgtable_flags; + pgd[i + 1] = (pgdval_t)p4d + pgtable_flags; i = (physaddr >> P4D_SHIFT) % PTRS_PER_P4D; - p4d[i + 0] = (pgdval_t)pud + _KERNPG_TABLE; - p4d[i + 1] = (pgdval_t)pud + _KERNPG_TABLE; + p4d[i + 0] = (pgdval_t)pud + pgtable_flags; + p4d[i + 1] = (pgdval_t)pud + pgtable_flags; } else { i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD; - pgd[i + 0] = (pgdval_t)pud + _KERNPG_TABLE; - pgd[i + 1] = (pgdval_t)pud + _KERNPG_TABLE; + pgd[i + 0] = (pgdval_t)pud + pgtable_flags; + pgd[i + 1] = (pgdval_t)pud + pgtable_flags; } i = (physaddr >> PUD_SHIFT) % PTRS_PER_PUD; - pud[i + 0] = (pudval_t)pmd + _KERNPG_TABLE; - pud[i + 1] = (pudval_t)pmd + _KERNPG_TABLE; + pud[i + 0] = (pudval_t)pmd + pgtable_flags; + pud[i + 1] = (pudval_t)pmd + pgtable_flags; pmd_entry = __PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL; + pmd_entry += sme_get_me_mask(); pmd_entry += physaddr; for (i = 0; i < DIV_ROUND_UP(_end - _text, PMD_SIZE); i++) { @@ -136,9 +146,30 @@ void __head __startup_64(unsigned long physaddr) pmd[i] += load_delta; } - /* Fixup phys_base */ + /* + * Fixup phys_base - remove the memory encryption mask to obtain + * the true physical address. + */ p = fixup_pointer(&phys_base, physaddr); - *p += load_delta; + *p += load_delta - sme_get_me_mask(); + + /* Encrypt the kernel (if SME is active) */ + sme_encrypt_kernel(); + + /* + * Return the SME encryption mask (if SME is active) to be used as a + * modifier for the initial pgdir entry programmed into CR3. + */ + return sme_get_me_mask(); +} + +unsigned long __startup_secondary_64(void) +{ + /* + * Return the SME encryption mask (if SME is active) to be used as a + * modifier for the initial pgdir entry programmed into CR3. + */ + return sme_get_me_mask(); } /* Wipe all early page tables except for the kernel symbol map */ diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 6225550..ec5d5e9 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -73,12 +73,19 @@ startup_64: /* Sanitize CPU configuration */ call verify_cpu + /* + * Perform pagetable fixups. Additionally, if SME is active, encrypt + * the kernel and retrieve the modifier (SME encryption mask if SME + * is active) to be added to the initial pgdir entry that will be + * programmed into CR3. + */ leaq _text(%rip), %rdi pushq %rsi call __startup_64 popq %rsi - movq $(early_top_pgt - __START_KERNEL_map), %rax + /* Form the CR3 value being sure to include the CR3 modifier */ + addq $(early_top_pgt - __START_KERNEL_map), %rax jmp 1f ENTRY(secondary_startup_64) /* @@ -98,7 +105,16 @@ ENTRY(secondary_startup_64) /* Sanitize CPU configuration */ call verify_cpu - movq $(init_top_pgt - __START_KERNEL_map), %rax + /* + * Retrieve the modifier (SME encryption mask if SME is active) to be + * added to the initial pgdir entry that will be programmed into CR3. + */ + pushq %rsi + call __startup_secondary_64 + popq %rsi + + /* Form the CR3 value being sure to include the CR3 modifier */ + addq $(init_top_pgt - __START_KERNEL_map), %rax 1: /* Enable PAE mode, PGE and LA57 */ diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index b99d469..3ac6f99 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -11,6 +11,7 @@ */ #include +#include /* * Since SME related variables are set early in the boot process they must @@ -19,3 +20,11 @@ */ unsigned long sme_me_mask __section(.data) = 0; EXPORT_SYMBOL_GPL(sme_me_mask); + +void __init sme_encrypt_kernel(void) +{ +} + +void __init sme_enable(void) +{ +} diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h index 59769f7..570f4fc 100644 --- a/include/linux/mem_encrypt.h +++ b/include/linux/mem_encrypt.h @@ -30,6 +30,11 @@ static inline bool sme_active(void) return !!sme_me_mask; } +static inline unsigned long sme_get_me_mask(void) +{ + return sme_me_mask; +} + #endif /* __ASSEMBLY__ */ #endif /* __MEM_ENCRYPT_H__ */