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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5F4CC19F2A for ; Thu, 11 Aug 2022 13:22:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 283296B0074; Thu, 11 Aug 2022 09:22:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 231786B0075; Thu, 11 Aug 2022 09:22:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D2D58E0001; Thu, 11 Aug 2022 09:22:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F40776B0074 for ; Thu, 11 Aug 2022 09:22:35 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D44A71A1630 for ; Thu, 11 Aug 2022 13:22:35 +0000 (UTC) X-FDA: 79787376270.13.8926062 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf23.hostedemail.com (Postfix) with ESMTP id B1DC8140072 for ; Thu, 11 Aug 2022 13:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660224154; x=1691760154; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=TXGp2l7srz7CG/35HC62yaH3SzOuZ/KTY0IN1dEpGAI=; b=T85cNzFMhuDp/oYPWSiQhx39YBv6Sr4LCIa+pHqdcotKZbewl5QK2xj1 veGjvvOn6TyYM8byt0LgrpvrVf5l9/ZWloHBEuswTHlL2XKjvF5ySSt8c l6JyZvKrjTDC5Y+ZGlbZT+sM6xxHXT7Wnz3MseVaEtWUixNdo0JoOjvpY 2erlI6jwbxbPHKo6HkyNu/XieZdxnQWCaYmPnEYu+rWnkSr3JZQbuYXRN YoFZlV425M/2/i4IG5D0qt59eP4ONkSOLjJ5eqvxT/bRq1XThZDw/iXE7 oTD2IO2OG/zgOmB/g1UMSkvByChlW2uZIz6bERW+uLiIbHE59Klfv4hk0 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10435"; a="290096107" X-IronPort-AV: E=Sophos;i="5.93,228,1654585200"; d="scan'208";a="290096107" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2022 06:22:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,228,1654585200"; d="scan'208";a="608920719" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga007.fm.intel.com with ESMTP; 11 Aug 2022 06:22:23 -0700 Date: Thu, 11 Aug 2022 21:17:38 +0800 From: Chao Peng To: David Hildenbrand Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, linux-kselftest@vger.kernel.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song Subject: Re: [PATCH v7 05/14] mm/memfd: Introduce MFD_INACCESSIBLE flag Message-ID: <20220811131738.GA916119@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220706082016.2603916-1-chao.p.peng@linux.intel.com> <20220706082016.2603916-6-chao.p.peng@linux.intel.com> <203c752f-9439-b5ae-056c-27b2631dcb81@redhat.com> <20220810093741.GE862421@chaop.bj.intel.com> <64ab9678-c72d-b6d9-8532-346cc9c06814@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <64ab9678-c72d-b6d9-8532-346cc9c06814@redhat.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660224155; a=rsa-sha256; cv=none; b=awwsXBY2hjAyKvsFxD2vOjRTVLj+SRjVh6qu22QFlPyRKCBmi/3jCH47zvCORyhbgU4DdG LQOgoRfKj+zWD9z1YyoYzDkacOC9YSTIC8WXO0Y4H+Xpqy3x9erM7wwQMKCg7iW2hHaafL 3WvRcoldZHosg90XjOFCI21FdOysDyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660224155; h=from:from:sender:reply-to: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+1+9uBDO3jezFgouBT/27DhVziYbPzIVah3TUWY75mc=; b=6pfx9oMbbbiQQTrYncqOh0NPHteouMJ0WlbBnQiH9ardcgxGSJ4HT9YghCIDSkMVf3x79s fsKs9/yE6PiOzEqe+VnDsqNPzL1u/BUM2Yn85euWeNeaHBuZp6pY6XnGCuqbFc2TUTKcq0 1Dm6l85iPG15uamJim8YQDBboFoPCao= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=T85cNzFM; spf=none (imf23.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) X-Stat-Signature: 1ysdq5ox5dsffsmrwtr3mw6me7eus3jg X-Rspamd-Queue-Id: B1DC8140072 Authentication-Results: imf23.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=T85cNzFM; spf=none (imf23.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1660224154-952960 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: On Wed, Aug 10, 2022 at 11:55:19AM +0200, David Hildenbrand wrote: > On 10.08.22 11:37, Chao Peng wrote: > > On Fri, Aug 05, 2022 at 03:28:50PM +0200, David Hildenbrand wrote: > >> On 06.07.22 10:20, Chao Peng wrote: > >>> Introduce a new memfd_create() flag indicating the content of the > >>> created memfd is inaccessible from userspace through ordinary MMU > >>> access (e.g., read/write/mmap). However, the file content can be > >>> accessed via a different mechanism (e.g. KVM MMU) indirectly. > >>> > >>> It provides semantics required for KVM guest private memory support > >>> that a file descriptor with this flag set is going to be used as the > >>> source of guest memory in confidential computing environments such > >>> as Intel TDX/AMD SEV but may not be accessible from host userspace. > >>> > >>> The flag can not coexist with MFD_ALLOW_SEALING, future sealing is > >>> also impossible for a memfd created with this flag. > >> > >> It's kind of weird to have it that way. Why should the user have to > >> care? It's the notifier requirement to have that, no? > >> > >> Why can't we handle that when register a notifier? If anything is > >> already mapped, fail registering the notifier if the notifier has these > >> demands. If registering succeeds, block it internally. > >> > >> Or what am I missing? We might not need the memfile set flag semantics > >> eventually and would not have to expose such a flag to user space. > > > > This makes sense if doable. The major concern was: is there a reliable > > way to detect this (already mapped) at the time of memslot registering. > > If too complicated, we could simplify to "was this ever mapped" and fail > for now. Hooking into shmem_mmap() might be sufficient for that to get > notified about the first mmap. > > As an alternative, mapping_mapped() or similar *might* do what we want. mapping_mapped() sounds the right one, I remember SEV people want first map then unmap. "was this ever mapped" may not work for them. Thanks, Chao > > > > -- > Thanks, > > David / dhildenb