Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp744726pxp; Fri, 11 Mar 2022 14:01:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5tmvL27W0TbU4wBMUMfyX6htKY33lpgs/PHbgfgLvMq1JksGhg7gWiJ2hAyF7H+/YxYey X-Received: by 2002:a63:447:0:b0:37d:b683:2c06 with SMTP id 68-20020a630447000000b0037db6832c06mr10217662pge.16.1647036081299; Fri, 11 Mar 2022 14:01:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647036081; cv=none; d=google.com; s=arc-20160816; b=TVpdCYjTdnQOCzH59evIWUfF2floOABHV4pZ8S3+RnHsDs3dq1cpjrY76lFv+lmF4J IzhxxjdkBSuUiqT0+BfK1x4cScudEk+Hxw9a4HnYJZh+55ob5shFuU+YJgfm1YY631gA giO5a6McTvBT3TODBP7Q/Rhn8UGV7Ci5BQF+Rv4VnxC2tAOITq+E3ioeG9QsEOJNe0IN RjysQuIjGlHc+VGx2rgCX+GRm64t0e/TBTAaNYpmwoU7BrMgseVttWor5gdySJNJ+S0n /aCfhq5rHoOLTVsR9nxLPqmkEExUE189g8LVald9uG10+mTuRs1/bJ7j5svk9r6DtSgM Mb/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wm/VVWkaicCATRWZVbFTqTGN0qvjjSSE8mvGTeIYzIA=; b=Uhyrdf3TJdsr8iEq8XiZ7YC+zb27ykyJx8wh8ij8QoN/tHaNyvBR+d7yMSlZ1F9E5w oM5ASCzHvEDg444vQJgGPFG9qaEU96HRPG1hpyiS4uGMQOZGF46nAPr1P5O0nGNIeVdD rN8LHFr/I8RuABRyyUqMnpwEcz9SyY2LJ8YmRLmhrn+oTPk7N8bu857TL6NdbJHD7gH9 hF7YL3mXtIMKfbZbnAWYgNSHY247Oj+Wd5rVG7hFXnslpjimG4HxN1/A3+QFCE1oHfPk jQgpS9VWlhDuUiT0gHS28o3uh6j4pPVi3oGP94HehUABh6OytJfJLeY3jXxlaSlze8KO R9hA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u8-20020a17090341c800b00151d046ad89si9465381ple.35.2022.03.11.14.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:01:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 697F027EDB5; Fri, 11 Mar 2022 13:17:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344559AbiCJXJj (ORCPT + 99 others); Thu, 10 Mar 2022 18:09:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbiCJXJe (ORCPT ); Thu, 10 Mar 2022 18:09:34 -0500 Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE6F8119F3E; Thu, 10 Mar 2022 15:08:32 -0800 (PST) Received: from dread.disaster.area (pa49-186-150-27.pa.vic.optusnet.com.au [49.186.150.27]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 73D1310E29AA; Fri, 11 Mar 2022 10:08:23 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1nSRtO-003xhf-9L; Fri, 11 Mar 2022 10:08:22 +1100 Date: Fri, 11 Mar 2022 10:08:22 +1100 From: Dave Chinner To: Chao Peng 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 03/13] mm/shmem: Support memfile_notifier Message-ID: <20220310230822.GO661808@dread.disaster.area> References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-4-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220310140911.50924-4-chao.p.peng@linux.intel.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.4 cv=deDjYVbe c=1 sm=1 tr=0 ts=622a84f0 a=sPqof0Mm7fxWrhYUF33ZaQ==:117 a=sPqof0Mm7fxWrhYUF33ZaQ==:17 a=kj9zAlcOel0A:10 a=o8Y5sQTvuykA:10 a=QyXUC8HyAAAA:8 a=7-415B0cAAAA:8 a=RCrhQ6IY2R1Uy-UsxHgA:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 10, 2022 at 10:09:01PM +0800, Chao Peng wrote: > From: "Kirill A. Shutemov" > > It maintains a memfile_notifier list in shmem_inode_info structure and > implements memfile_pfn_ops callbacks defined by memfile_notifier. It > then exposes them to memfile_notifier via > shmem_get_memfile_notifier_info. > > We use SGP_NOALLOC in shmem_get_lock_pfn since the pages should be > allocated by userspace for private memory. If there is no pages > allocated at the offset then error should be returned so KVM knows that > the memory is not private memory. > > Signed-off-by: Kirill A. Shutemov > Signed-off-by: Chao Peng > --- > include/linux/shmem_fs.h | 4 +++ > mm/shmem.c | 76 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 80 insertions(+) > > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h > index 2dde843f28ef..7bb16f2d2825 100644 > --- a/include/linux/shmem_fs.h > +++ b/include/linux/shmem_fs.h > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > /* inode in-kernel data */ > > @@ -28,6 +29,9 @@ struct shmem_inode_info { > struct simple_xattrs xattrs; /* list of xattrs */ > atomic_t stop_eviction; /* hold when working on inode */ > unsigned int xflags; /* shmem extended flags */ > +#ifdef CONFIG_MEMFILE_NOTIFIER > + struct memfile_notifier_list memfile_notifiers; > +#endif > struct inode vfs_inode; > }; > > diff --git a/mm/shmem.c b/mm/shmem.c > index 9b31a7056009..7b43e274c9a2 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -903,6 +903,28 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) > return page ? page_folio(page) : NULL; > } > > +static void notify_fallocate(struct inode *inode, pgoff_t start, pgoff_t end) > +{ > +#ifdef CONFIG_MEMFILE_NOTIFIER > + struct shmem_inode_info *info = SHMEM_I(inode); > + > + memfile_notifier_fallocate(&info->memfile_notifiers, start, end); > +#endif > +} *notify_populate(), not fallocate. This is a notification that a range has been populated, not that the fallocate() syscall was run to populate the backing store of a file. i.e. fallocate is the name of a userspace filesystem API that can be used to manipulate the backing store of a file in various ways. It can both populate and punch away the backing store of a file, and some operations that fallocate() can run will do both (e.g. FALLOC_FL_ZERO_RANGE) and so could generate both notify_invalidate() and a notify_populate() events. Hence "fallocate" as an internal mm namespace or operation does not belong anywhere in core MM infrastructure - it should never get used anywhere other than the VFS/filesystem layers that implement the fallocate() syscall or use it directly. Cheers, Dave. -- Dave Chinner david@fromorbit.com