Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp793055pxp; Fri, 11 Mar 2022 15:16:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCmFU8w+vvXDdKDC/fgGZr0+weGjjC29j6wiSVoTJcFM92oXUBAgvJ+KWT3VUdNdvi0Gwe X-Received: by 2002:a63:88c8:0:b0:380:b64e:df8e with SMTP id l191-20020a6388c8000000b00380b64edf8emr10314833pgd.129.1647040605224; Fri, 11 Mar 2022 15:16:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647040605; cv=none; d=google.com; s=arc-20160816; b=klyxkM4Hxnmq4YCqkaYzKpY3Pec6Ef5YAUvxJBbiBDGANkX6c5M4Xv1nYktvDmXECY KOzwhjEmDl6MvJxNOElLbPu/yJlaA6eLRbly5AdroZ9XaXeBEADK4QAxnjbPLprttsFC NEENl3Dp3a+PA5R7uUKxUz82Rf+UlVUMgtjqmuk0EHFjd+vd3tU7PNCtW6ikv2ia+Pay Uyx81v4Xk5pfpdmTOdVOgv6OrbdYibtvCklY5JltU0voBosClI2f4YleOBMZSAH8f0gx gT6mgGXhZjnAmRuvnyS/RDhoP+VOVcBkkx4X4Y1U2Ks5waL8KGFbbu7VNZD7IDYxKp+C /rGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=S30pBlY6m8bibpLxVWgy/7oM22JIpA4JUSoWV0UB2HA=; b=MI3ShajdTYTQ8pOZx5vVxaMd3fyYrUzRaXtPUYxQfxLnV3kLiLOYAH65ulJKI7xKs8 3RUWO10wnc1vI66Y8W2TK34tD2fDE/awRrP8Vo+pYVKTjXlcbNiV8IZ3t3A3plhhhG9C A5q25551s54OcGChelbhlerIVSWsW9czBBjN9KMOFl3LTZlBa/nWLUZRHIBB3Xa9YGng RqJP1CU2fDJPNujKkVqpZEeCIHeaYcAd7CZnynkbp80ERBwUk2pRirxmvH/a87DNwsgU WlsiknFSJLSJzHVKu+f8hQu3MpnjVo1bqylXuhDIsLpikI/ybIH7lYYAvTuhsoRGTvun xbHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TSElsKll; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v9-20020a170902e8c900b0014daa132f6csi9926738plg.589.2022.03.11.15.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 15:16:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TSElsKll; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 049442017DB; Fri, 11 Mar 2022 14:02:52 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238887AbiCKInm (ORCPT + 99 others); Fri, 11 Mar 2022 03:43:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238414AbiCKInk (ORCPT ); Fri, 11 Mar 2022 03:43:40 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D3B73B3F4; Fri, 11 Mar 2022 00:42:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646988157; x=1678524157; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=rnnCy0Hbi4uhBKWJV93SLPhz7c/vwnMymNdqjK9CGiI=; b=TSElsKllxlM6Vbk/Yu5miqQ82L2dxUe/dDgksMB0D2EdOXf8XYk2WkEj myfQNcCnR6zYAGT12LUIKb8v3YV9o/90cR3BDbuXEH+LX9DqDeVD32A1M 8rNxfacfmDOdjrJiizTANRs3sG23rLUpT9TSd9jxsx1ZO2+pX2Kxy+Cq8 nNPz0jbwJzTVG/OayqiycDDw3+vZOaAntqGF4w+S4wRM1YExYLl09AMQ6 vkqLelSenko/TAyf/FG1Ngp00gfmzfLgYgD4beHN9Op/lpMch9ZLhABxN u1g/19eSh9AuGotby4eBXtAboRcwbyLK/1dgRkKnzlZJtpeEgILjBNmVD A==; X-IronPort-AV: E=McAfee;i="6200,9189,10282"; a="341958572" X-IronPort-AV: E=Sophos;i="5.90,173,1643702400"; d="scan'208";a="341958572" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2022 00:42:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,173,1643702400"; d="scan'208";a="538926645" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga007.jf.intel.com with ESMTP; 11 Mar 2022 00:42:24 -0800 Date: Fri, 11 Mar 2022 16:42:08 +0800 From: Chao Peng To: Dave Chinner 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: <20220311084208.GB56193@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-4-chao.p.peng@linux.intel.com> <20220310230822.GO661808@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220310230822.GO661808@dread.disaster.area> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Fri, Mar 11, 2022 at 10:08:22AM +1100, Dave Chinner wrote: > 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. Yes, I fully agreed fallocate syscall has both populating and hole punching semantics so notify_fallocate can be misleading since we actually mean populate here. > > 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. Will use your suggestion through the series where applied. Thanks for your suggestion. Chao > > Cheers, > > Dave. > > -- > Dave Chinner > david@fromorbit.com