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=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 07F3DC433DF for ; Mon, 6 Jul 2020 17:21:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A0A0E20722 for ; Mon, 6 Jul 2020 17:21:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="l76C5n6D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0A0E20722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0C50C6B0002; Mon, 6 Jul 2020 13:21:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 076366B0005; Mon, 6 Jul 2020 13:21:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA6A96B0006; Mon, 6 Jul 2020 13:21:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id D1AF86B0002 for ; Mon, 6 Jul 2020 13:21:01 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 702A0180AD801 for ; Mon, 6 Jul 2020 17:21:01 +0000 (UTC) X-FDA: 77008316322.22.stone81_3b02c7926ead Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 3EA8D18038E60 for ; Mon, 6 Jul 2020 17:21:01 +0000 (UTC) X-HE-Tag: stone81_3b02c7926ead X-Filterd-Recvd-Size: 5245 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Mon, 6 Jul 2020 17:21:00 +0000 (UTC) Received: from aquarius.haifa.ibm.com (nesher1.haifa.il.ibm.com [195.110.40.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 28431206CD; Mon, 6 Jul 2020 17:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594056059; bh=rp3iLbG4NzFQ6srRlKxeSGp+kPRUVlRaIbnd6z2D5UY=; h=From:To:Cc:Subject:Date:From; b=l76C5n6D647knTaiC1Ofb1gHincOwMnY9GaLtoXpCGO4qWLWz68KmJY4gVJQ/6d/k VR/PWu6VIqUgb9u1FiEtG5Gf3RnfhjbueTLXu9dsFSDOZ2ky6V19VYmfJjX5c3HeU/ pCMYh7UCO/5pYVrWEUvl/qjqN1iCeEqppXWkAh9c= From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alan Cox , Andrew Morton , Andy Lutomirski , Christopher Lameter , Dave Hansen , Idan Yaniv , James Bottomley , "Kirill A. Shutemov" , Matthew Wilcox , Peter Zijlstra , "Reshetova, Elena" , Thomas Gleixner , Tycho Andersen , linux-api@vger.kernel.org, linux-mm@kvack.org, Mike Rapoport Subject: [RFC PATCH v2 0/5] mm: extend memfd with ability to create "secret" memory areas Date: Mon, 6 Jul 2020 20:20:46 +0300 Message-Id: <20200706172051.19465-1-rppt@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 3EA8D18038E60 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Mike Rapoport Hi, This is a second version of "secret" mappings implementation backed by a file descriptor.=20 The file descriptor is created using memfd_create() syscall with a new MFD_SECRET flag. The file descriptor should be configured using ioctl() t= o define the desired protection and then mmap() of the fd 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 th= e user page table. For instance, current implementation allows uncached mappings. 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. As the fragmentation of the direct map was one of the major concerns rais= ed during the previous postings, I've added an amortizing cache of PMD-size pages to each file descriptor and an ability to reserve large chunks of t= he physical memory at boot time and then use this memory as an allocation po= ol for the secret memory areas. In addition, I've tried to find some numbers that show the benefit of usi= ng larger pages in the direct map, but I couldn't find anything so I've run = a couple of benchmarks from phoronix-test-suite on my laptop (i7-8650U with 32G RAM). I've tested three variants: the default with 28G of the physical memory covered with 1G pages, then I disabled 1G pages using "nogbpages" in the kernel command line and at last I've forced the entire direct map to use = 4K pages using a simple patch to arch/x86/mm/init.c. I've made runs of the benchmarks with SSD and tmpfs. Surprisingly, the results does not show huge advantage for large pages. F= or instance, here the results for kernel build with 'make -j8', in seconds: | 1G | 2M | 4K ------------------------+--------+--------+--------- ssd, mitigations=3Don | 308.75 | 317.37 | 314.9=20 ssd, mitigations=3Doff | 305.25 | 295.32 | 304.92=20 ram, mitigations=3Don | 301.58 | 322.49 | 306.54=20 ram, mitigations=3Doff | 299.32 | 288.44 | 310.65 All the results I have are available at [1]. If anybody is interested in plain text, please let me know. [1] https://docs.google.com/spreadsheets/d/1tdD-cu8e93vnfGsTFxZ5YdaEfs2E1= GELlvWNOGkJV2U/edit?usp=3Dsharing Mike Rapoport (5): mm: make HPAGE_PxD_{SHIFT,MASK,SIZE} always available mmap: make mlock_future_check() global mm: extend memfd with ability to create "secret" memory areas mm: secretmem: use PMD-size pages to amortize direct map fragmentation mm: secretmem: add ability to reserve memory at boot include/linux/huge_mm.h | 10 +- include/linux/memfd.h | 9 + include/uapi/linux/magic.h | 1 + include/uapi/linux/memfd.h | 6 + mm/Kconfig | 3 + mm/Makefile | 1 + mm/internal.h | 3 + mm/memfd.c | 10 +- mm/mmap.c | 5 +- mm/secretmem.c | 445 +++++++++++++++++++++++++++++++++++++ 10 files changed, 480 insertions(+), 13 deletions(-) create mode 100644 mm/secretmem.c base-commit: 7c30b859a947535f2213277e827d7ac7dcff9c84 --=20 2.26.2