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=-5.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 98F3DC00A89 for ; Mon, 2 Nov 2020 09:11:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1668B2231B for ; Mon, 2 Nov 2020 09:11:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MHRKvCgd"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TvonQJwk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1668B2231B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LsJz28BvQ85QcCE/YkBPfMw+NCqxLtGO0pE2j67LNa0=; b=MHRKvCgdiToewOB9Y1N1O2f5G QxuAeKdDaTmKKvvkyuSSQjSGyBi+47cND4oR+FG11FulwoHPEHztuQk55jcC78DpgvWMWPo0A6dgH hWRJ5egRLXHbmRUi791XRblTTcgJMW4V6HC3SBu0ZntZCg5+87g1++x6tqeTcCJR+rewG/bVk7Gz8 yVyLHfSuz699z2jms7stpZUJ34GUShu6+h0OsqN2RaJJEiM1fHYXGHVuC97FteNPaQ3XMfPMurJDt RKk167zbDpY589r2Ie05LZ8ilOS8AnvChCCYvzi14kvj2pzJ51elB1giqpB17UsbvsuCa5kPoaejX AJSgFjJow==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZVsG-000556-Bv; Mon, 02 Nov 2020 09:11:36 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZVsB-00052h-QA for linux-riscv@lists.infradead.org; Mon, 02 Nov 2020 09:11:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604308290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wsx9rV62BpQWr7OrGkSf+6thseF+6yM3BDN31bmg5MQ=; b=TvonQJwkqVfxbePBPyLAhhMGFOHNK0//eDZUnuQKJ8KOQXRzG8xTZ+pEBJxVbtAxN5GtPB OjZI3UocJHbPnxJ/PPbeMuGYGOksHFF76aFnsqiFeUhXu9xEW0d6/xRDo8LHPsvt/Pwymb bMK222WaKSH0l4eJSWUTWM1gaEz10ZA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-ghMbzMWdOp2vAAAUSLZQlg-1; Mon, 02 Nov 2020 04:11:26 -0500 X-MC-Unique: ghMbzMWdOp2vAAAUSLZQlg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 744641009E28; Mon, 2 Nov 2020 09:11:21 +0000 (UTC) Received: from [10.36.113.163] (ovpn-113-163.ams2.redhat.com [10.36.113.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02AF25D9D2; Mon, 2 Nov 2020 09:11:12 +0000 (UTC) Subject: Re: [PATCH v6 0/6] mm: introduce memfd_secret system call to create "secret" memory areas To: Mike Rapoport , Andrew Morton References: <20200924132904.1391-1-rppt@kernel.org> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <9c38ac3b-c677-6a87-ce82-ec53b69eaf71@redhat.com> Date: Mon, 2 Nov 2020 10:11:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200924132904.1391-1-rppt@kernel.org> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_041131_910150_0A4DBDFE X-CRM114-Status: GOOD ( 37.47 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-mm@kvack.org, Will Deacon , linux-kselftest@vger.kernel.org, "H. Peter Anvin" , Christopher Lameter , Idan Yaniv , Dan Williams , Elena Reshetova , linux-arch@vger.kernel.org, Tycho Andersen , linux-nvdimm@lists.01.org, Shuah Khan , x86@kernel.org, Matthew Wilcox , Mike Rapoport , Ingo Molnar , Michael Kerrisk , Arnd Bergmann , James Bottomley , Borislav Petkov , Alexander Viro , Andy Lutomirski , Paul Walmsley , "Kirill A. Shutemov" , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , linux-fsdevel@vger.kernel.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On 24.09.20 15:28, Mike Rapoport wrote: > From: Mike Rapoport > > Hi, > > 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. Hi Mike, I'd like to stress again that I'd prefer *any* secretmem allocations going via CMA as long as these pages are unmovable. The user can allocate a non-significant amount of unmovable allocations only fenced by the mlock limit, which behave very different to mlocked pages - they are not movable for page compaction/migration. Assume you have a system with quite some ZONE_MOVABLE memory (esp. in virtualized environments), eating up a significant amount of !ZONE_MOVABLE memory dynamically at runtime can lead to non-obvious issues. It looks like you have plenty of free memory, but the kernel might still OOM when trying to do kernel allocations e.g., for pagetables. With CMA we at least know what we're dealing with - it behaves like ZONE_MOVABLE except for the owner that can place unmovable pages there. We can use it to compute statically the amount of ZONE_MOVABLE memory we can have in the system without doing harm to the system. Ideally, we would want to support page migration/compaction and allow for allocation from ZONE_MOVABLE as well. Would involve temporarily mapping, copying, unmapping. Sounds feasible, but not sure which roadblocks we would find on the way. [...] > > 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. This was also raised on lwn.net by "dullfire" [1]. I do wonder if it would be the right place as well. [1] https://lwn.net/Articles/835342/#Comments > > 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. -- Thanks, David / dhildenb _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv