From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FC66C4346E for ; Fri, 25 Sep 2020 02:35:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCEBD20888 for ; Fri, 25 Sep 2020 02:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601001347; bh=h8cNxVq9RlZhwkyWlveO24GTKKhDRZyr8kBn1AyCbqI=; h=Date:From:To:Subject:Reply-To:List-ID:From; b=bqC/966o00Ocq+IgOsBJv3ryMHinkycMAWJodgYlZ+poIxkuwTUun726bocSGEk0Q x1WD+Xner69iDzLU/6+V5AEgJTYQnPJAZJHwG9l9nxwQEyxtB7a2ipNMZPQ2dKCunR fkNDZxbnb83NoFodLBzdPkBeMzHDib8jvPR3lJTQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgIYCfr (ORCPT ); Thu, 24 Sep 2020 22:35:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:48096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726704AbgIYCfr (ORCPT ); Thu, 24 Sep 2020 22:35:47 -0400 Received: from X1 (unknown [104.245.68.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 12CDA207C4; Fri, 25 Sep 2020 02:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601001345; bh=h8cNxVq9RlZhwkyWlveO24GTKKhDRZyr8kBn1AyCbqI=; h=Date:From:To:Subject:From; b=0BlDJNxICUyrHXdDxUUKCztfn6/sGPEMQ5V7sWEqxIpQCqij06a72rgDV/dgl8Bzj TP/oTH4tKmIszTTXnvTCUillhTjeSxccHdwzhwEwhAXn8xRjsRx5EBjMaGCreMPz5z W62VRH3+zsxB9NZGuRnxF3YwcDCOhYxwV2wpFTA4= Date: Thu, 24 Sep 2020 19:35:43 -0700 From: akpm@linux-foundation.org To: mm-commits@vger.kernel.org, willy@infradead.org, will@kernel.org, viro@zeniv.linux.org.uk, tycho@tycho.ws, tglx@linutronix.de, shuah@kernel.org, peterz@infradead.org, paul.walmsley@sifive.com, palmerdabbelt@google.com, palmer@dabbelt.com, mtk.manpages@gmail.com, mingo@redhat.com, mark.rutland@arm.com, luto@kernel.org, kirill@shutemov.name, jejb@linux.ibm.com, idan.yaniv@ibm.com, hpa@zytor.com, elena.reshetova@intel.com, david@redhat.com, dave.hansen@linux.intel.com, dan.j.williams@intel.com, cl@linux.com, catalin.marinas@arm.com, bp@alien8.de, arnd@arndb.de, rppt@linux.ibm.com Subject: + mm-add-definition-of-pmd_page_order.patch added to -mm tree Message-ID: <20200925023543.6Jlsg%akpm@linux-foundation.org> User-Agent: s-nail v14.9.10 Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: mm: add definition of PMD_PAGE_ORDER has been added to the -mm tree. Its filename is mm-add-definition-of-pmd_page_order.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-add-definition-of-pmd_page_order.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-add-definition-of-pmd_page_order.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Mike Rapoport Subject: mm: add definition of PMD_PAGE_ORDER Patch series "mm: introduce memfd_secret system call to create "secret" memory areas", v6. This is an implementation of "secret" mappings backed by a file descriptor. I've dropped the boot time reservation patch for now as it is not strictly required for the basic usage and can be easily added later either with or without CMA. The file descriptor backing secret memory mappings is created using a dedicated memfd_secret system call The desired protection mode for the memory is configured using flags parameter of the system call. The mmap() of the file descriptor created with memfd_secret() will create a "secret" memory mapping. The pages in that mapping will be marked as not present in the direct map and will have desired protection bits set in the user page table. For instance, current implementation allows uncached mappings. Although normally Linux userspace mappings are protected from other users, such secret mappings are useful for environments where a hostile tenant is trying to trick the kernel into giving them access to other tenants mappings. Additionally, the secret mappings may be used as a mean to protect guest memory in a virtual machine host. For demonstration of secret memory usage we've created a userspace library [1] that does two things: the first is act as a preloader for openssl to redirect all the OPENSSL_malloc calls to secret memory meaning any secret keys get automatically protected this way and the other thing it does is expose the API to the user who needs it. We anticipate that a lot of the use cases would be like the openssl one: many toolkits that deal with secret keys already have special handling for the memory to try to give them greater protection, so this would simply be pluggable into the toolkits without any need for user application modification. I've hesitated whether to continue to use new flags to memfd_create() or to add a new system call and I've decided to use a new system call after I've started to look into man pages update. There would have been two completely independent descriptions and I think it would have been very confusing. Hiding secret memory mappings behind an anonymous file allows (ab)use of the page cache for tracking pages allocated for the "secret" mappings as well as using address_space_operations for e.g. page migration callbacks. The anonymous file may be also used implicitly, like hugetlb files, to implement mmap(MAP_SECRET) and use the secret memory areas with "native" mm ABIs in the future. As the fragmentation of the direct map was one of the major concerns raised during the previous postings, I've added an amortizing cache of PMD-size pages to each file descriptor that is used as an allocation pool for the secret memory areas. This patch (of 6): The definition of PMD_PAGE_ORDER denoting the number of base pages in the second-level leaf page is already used by DAX and maybe handy in other cases as well. Several architectures already have definition of PMD_ORDER as the size of second level page table, so to avoid conflict with these definitions use PMD_PAGE_ORDER name and update DAX respectively. Link: https://lkml.kernel.org/r/20200924132904.1391-1-rppt@kernel.org Link: https://lkml.kernel.org/r/20200924132904.1391-2-rppt@kernel.org Signed-off-by: Mike Rapoport Cc: Alexander Viro Cc: Andy Lutomirski Cc: Arnd Bergmann Cc: Borislav Petkov Cc: Catalin Marinas Cc: Christopher Lameter Cc: Dan Williams Cc: Dave Hansen Cc: David Hildenbrand Cc: Elena Reshetova Cc: "H. Peter Anvin" Cc: Idan Yaniv Cc: Ingo Molnar Cc: James Bottomley Cc: "Kirill A. Shutemov" Cc: Matthew Wilcox Cc: Mark Rutland Cc: Michael Kerrisk Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Shuah Khan Cc: Tycho Andersen Cc: Will Deacon Cc: Palmer Dabbelt Signed-off-by: Andrew Morton --- fs/dax.c | 11 ++++------- include/linux/pgtable.h | 3 +++ 2 files changed, 7 insertions(+), 7 deletions(-) --- a/fs/dax.c~mm-add-definition-of-pmd_page_order +++ a/fs/dax.c @@ -49,9 +49,6 @@ static inline unsigned int pe_order(enum #define PG_PMD_COLOUR ((PMD_SIZE >> PAGE_SHIFT) - 1) #define PG_PMD_NR (PMD_SIZE >> PAGE_SHIFT) -/* The order of a PMD entry */ -#define PMD_ORDER (PMD_SHIFT - PAGE_SHIFT) - static wait_queue_head_t wait_table[DAX_WAIT_TABLE_ENTRIES]; static int __init init_dax_wait_table(void) @@ -98,7 +95,7 @@ static bool dax_is_locked(void *entry) static unsigned int dax_entry_order(void *entry) { if (xa_to_value(entry) & DAX_PMD) - return PMD_ORDER; + return PMD_PAGE_ORDER; return 0; } @@ -1471,7 +1468,7 @@ static vm_fault_t dax_iomap_pmd_fault(st { struct vm_area_struct *vma = vmf->vma; struct address_space *mapping = vma->vm_file->f_mapping; - XA_STATE_ORDER(xas, &mapping->i_pages, vmf->pgoff, PMD_ORDER); + XA_STATE_ORDER(xas, &mapping->i_pages, vmf->pgoff, PMD_PAGE_ORDER); unsigned long pmd_addr = vmf->address & PMD_MASK; bool write = vmf->flags & FAULT_FLAG_WRITE; bool sync; @@ -1530,7 +1527,7 @@ static vm_fault_t dax_iomap_pmd_fault(st * entry is already in the array, for instance), it will return * VM_FAULT_FALLBACK. */ - entry = grab_mapping_entry(&xas, mapping, PMD_ORDER); + entry = grab_mapping_entry(&xas, mapping, PMD_PAGE_ORDER); if (xa_is_internal(entry)) { result = xa_to_internal(entry); goto fallback; @@ -1696,7 +1693,7 @@ dax_insert_pfn_mkwrite(struct vm_fault * if (order == 0) ret = vmf_insert_mixed_mkwrite(vmf->vma, vmf->address, pfn); #ifdef CONFIG_FS_DAX_PMD - else if (order == PMD_ORDER) + else if (order == PMD_PAGE_ORDER) ret = vmf_insert_pfn_pmd(vmf, pfn, FAULT_FLAG_WRITE); #endif else --- a/include/linux/pgtable.h~mm-add-definition-of-pmd_page_order +++ a/include/linux/pgtable.h @@ -28,6 +28,9 @@ #define USER_PGTABLES_CEILING 0UL #endif +/* Number of base pages in a second level leaf page */ +#define PMD_PAGE_ORDER (PMD_SHIFT - PAGE_SHIFT) + /* * A page table page can be thought of an array like this: pXd_t[PTRS_PER_PxD] * _ Patches currently in -mm which might be from rppt@linux.ibm.com are mm-account-pmd-tables-like-pte-tables-fix.patch kvm-ppc-book3s-hv-simplify-kvm_cma_reserve.patch dma-contiguous-simplify-cma_early_percent_memory.patch arm-xtensa-simplify-initialization-of-high-memory-pages.patch arm64-numa-simplify-dummy_numa_init.patch h8300-nds32-openrisc-simplify-detection-of-memory-extents.patch riscv-drop-unneeded-node-initialization.patch mircoblaze-drop-unneeded-numa-and-sparsemem-initializations.patch memblock-make-for_each_memblock_type-iterator-private.patch memblock-make-memblock_debug-and-related-functionality-private.patch memblock-reduce-number-of-parameters-in-for_each_mem_range.patch arch-mm-replace-for_each_memblock-with-for_each_mem_pfn_range.patch arch-drivers-replace-for_each_membock-with-for_each_mem_range.patch arch-drivers-replace-for_each_membock-with-for_each_mem_range-fix-2.patch x86-setup-simplify-initrd-relocation-and-reservation.patch x86-setup-simplify-reserve_crashkernel.patch memblock-remove-unused-memblock_mem_size.patch memblock-implement-for_each_reserved_mem_region-using-__next_mem_region.patch memblock-use-separate-iterators-for-memory-and-reserved-regions.patch mm-add-definition-of-pmd_page_order.patch mmap-make-mlock_future_check-global.patch mm-introduce-memfd_secret-system-call-to-create-secret-memory-areas.patch arch-mm-wire-up-memfd_secret-system-call-were-relevant.patch mm-secretmem-use-pmd-size-pages-to-amortize-direct-map-fragmentation.patch secretmem-test-add-basic-selftest-for-memfd_secret2.patch