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 22356C433F5 for ; Tue, 12 Apr 2022 13:11:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD46B6B0082; Tue, 12 Apr 2022 09:11:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A845F6B0083; Tue, 12 Apr 2022 09:11:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9247F6B0085; Tue, 12 Apr 2022 09:11:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 84E5E6B0082 for ; Tue, 12 Apr 2022 09:11:49 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3F9A8183A3505 for ; Tue, 12 Apr 2022 13:11:49 +0000 (UTC) X-FDA: 79348264338.25.692C982 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf12.hostedemail.com (Postfix) with ESMTP id 1AF1840006 for ; Tue, 12 Apr 2022 13:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649769108; x=1681305108; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=1KeYAHX9pm/ikMj2hiQRjLWmiTvrzP7m01hIo3GA0o4=; b=WkFj9jWnqUHgYPAhLfG22Fzci162FOuAhCNTCQrg0J71w4e4DiDak2Eu BcW4odFH8MKOZtO961u6GlYbalT6nNwjK8Z7GyMd8HEwkhoz3YdODRFs6 lC0qgEC1BeXGxPoYdBKD1evqVF4xBqgxMpmaA7mQCO6m4k6kEpdX4nvaP 4ZEGTsA5TlpyxL7P8b09jDalKuRL0xcg9yHCEYCzI6fdp74+fpQUvpyCI Zs2ZChzz2AD8vSIcdUzFrFlM80lQjrN8rr3sVkkSnUGGEfxwL9BDvHSF+ ltp9EMaSKw194/P0p6/QhVR0XdTSsdOGQtvmMOFG4eLutDbaCRcLNN+Zi A==; X-IronPort-AV: E=McAfee;i="6400,9594,10314"; a="322814052" X-IronPort-AV: E=Sophos;i="5.90,253,1643702400"; d="scan'208";a="322814052" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 06:11:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,253,1643702400"; d="scan'208";a="699828702" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by fmsmga001.fm.intel.com with ESMTP; 12 Apr 2022 06:11:38 -0700 Date: Tue, 12 Apr 2022 21:11:28 +0800 From: Chao Peng To: "Kirill A. Shutemov" Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, qemu-devel@nongnu.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 , 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, david@redhat.com Subject: Re: [PATCH v5 01/13] mm/memfd: Introduce MFD_INACCESSIBLE flag Message-ID: <20220412131128.GE8013@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-2-chao.p.peng@linux.intel.com> <20220411151023.4nx34pxyg5amj44m@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220411151023.4nx34pxyg5amj44m@box.shutemov.name> User-Agent: Mutt/1.9.4 (2018-02-28) X-Stat-Signature: td118pbhppr8663wauhpj6gro9p3hw76 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=WkFj9jWn; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf12.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 1AF1840006 X-HE-Tag: 1649769107-278983 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 Mon, Apr 11, 2022 at 06:10:23PM +0300, Kirill A. Shutemov wrote: > On Thu, Mar 10, 2022 at 10:08:59PM +0800, Chao Peng wrote: > > From: "Kirill A. Shutemov" > > > > 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. > > > > Since page migration/swapping is not yet supported for such usages > > so these pages are currently marked as UNMOVABLE and UNEVICTABLE > > which makes them behave like long-term pinned pages. > > > > The flag can not coexist with MFD_ALLOW_SEALING, future sealing is > > also impossible for a memfd created with this flag. > > > > At this time only shmem implements this flag. > > > > Signed-off-by: Kirill A. Shutemov > > Signed-off-by: Chao Peng > > --- > > include/linux/shmem_fs.h | 7 +++++ > > include/uapi/linux/memfd.h | 1 + > > mm/memfd.c | 26 +++++++++++++++-- > > mm/shmem.c | 57 ++++++++++++++++++++++++++++++++++++++ > > 4 files changed, 88 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h > > index e65b80ed09e7..2dde843f28ef 100644 > > --- a/include/linux/shmem_fs.h > > +++ b/include/linux/shmem_fs.h > > @@ -12,6 +12,9 @@ > > > > /* inode in-kernel data */ > > > > +/* shmem extended flags */ > > +#define SHM_F_INACCESSIBLE 0x0001 /* prevent ordinary MMU access (e.g. read/write/mmap) to file content */ > > + > > struct shmem_inode_info { > > spinlock_t lock; > > unsigned int seals; /* shmem seals */ > > @@ -24,6 +27,7 @@ struct shmem_inode_info { > > struct shared_policy policy; /* NUMA memory alloc policy */ > > struct simple_xattrs xattrs; /* list of xattrs */ > > atomic_t stop_eviction; /* hold when working on inode */ > > + unsigned int xflags; /* shmem extended flags */ > > struct inode vfs_inode; > > }; > > > > AFAICS, only two bits of 'flags' are used. And that's very strange that > VM_ flags are used for the purpose. My guess that someone was lazy to > introduce new constants for this. > > I think we should fix this: introduce SHM_F_LOCKED and SHM_F_NORESERVE > alongside with SHM_F_INACCESSIBLE and stuff them all into info->flags. > It also makes shmem_file_setup_xflags() go away. Did a quick search and sounds we only use SHM_F_LOCKED/SHM_F_NORESERVE and that definitely don't have to be VM_ flags. Chao > > -- > Kirill A. Shutemov