Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp622407rwb; Thu, 6 Oct 2022 02:03:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5oh1moDhigwVhezoq6nH4GaUSFn4YyQl1qdCa4uGj25AlvYLtywD6Wn2T9tYQEF8DK9u+3 X-Received: by 2002:a50:ec84:0:b0:459:ae8:8025 with SMTP id e4-20020a50ec84000000b004590ae88025mr3566304edr.321.1665046996733; Thu, 06 Oct 2022 02:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665046996; cv=none; d=google.com; s=arc-20160816; b=ed+1hCpgHwSJkKZzdPLBJM0Qe60H5ka88jz0yYd6849qNwRnV8naRFweqUkkXykZxA H53CuZVKmmg92tnMg481Jz8PNujw95U78S/LctDwWK+hd5yDD98kK8D8h/0b0LPJbRrd j+sRXXKmcV7ShhAWln4f7BXzFq95pavE931FRc5p/UsUxh9eA5PfnzskHXXMdGXEXCjI O8eb2UAqUqRaVX0Wr79Wzv7ofYxMKR8WJPK8NC6oFkgHppOkPe3OPtu0P7DWjIFcYvDl Ygg88FbAqFbM9xR1CMh16yaUhOIv9M2JjrwpL9XZxxoSghs1kJvK1UK3HbGYhTxYss9C xv1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tIvLoyAzCOVKOX99D0R9AADU51C3uknT25CXCqDgD1U=; b=YoxntN9Eob46LnhGuwjMULqOGRD0kuneXQzNAbPrC04QX17RPFelOnXKe0c0QLLWVY ZDYLxhfQVBIj3u4s/gDSSjp3fsFwO8DJdSCzW/k3EzC1Rj39zANNf2L0+/WcFGX4diep Xs1oXwrqTXvX2zF6Zbpds4rgZeGvFYPbHgyXCR1DJYUgq1z55F9oin0lVL0r87JVPfx8 v28ubMd5YHs246UsYC2LDkg1dJOOqH3oMpXgEW21xXAeCn/11JPx8z59cEf1vAxAAx6i XN7GPQNHy1i8Ext5XzUIvp4CjmueGcRI5o1Umalm7l07yc3B2KzcIV8WQykLbiZ58lV3 sT4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=syjvuFsl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lg15-20020a170906f88f00b00781c1645926si12666125ejb.524.2022.10.06.02.02.45; Thu, 06 Oct 2022 02:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=syjvuFsl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbiJFIvL (ORCPT + 99 others); Thu, 6 Oct 2022 04:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230284AbiJFIvI (ORCPT ); Thu, 6 Oct 2022 04:51:08 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A48D46DAC2 for ; Thu, 6 Oct 2022 01:51:06 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id m19so332417lfq.9 for ; Thu, 06 Oct 2022 01:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=tIvLoyAzCOVKOX99D0R9AADU51C3uknT25CXCqDgD1U=; b=syjvuFslfwj1fipmU574j5/yWZL2S3jYhnbWtJ5/bW8iUM/V71vSmb5AsxhaQ/2G0o ctXQnXj/0GSOAbOLK304yQgqsFpIlw2wn3vENsIXReAQESQ7FYQ3e3iDUnXAdUxwt4Td kB2rW56eQNiKHDXyNU3pU/c0Ku79mAkkC7m5TZZLTqHBqVkt65rb0q9hLTPBpEEa/mRq eX1zzMQ6IXkPCewSrX8mVTXOcPVRl/qAef1AVJ52kW5/Ujtn6X047jAV62EnnUX9Aztm 0/+I6X+EdhcVKtpUJDxafJIJ2F5NBl87Wqp+wSebFHrCPcoC3fkGq5u8ifnCkUUfBbKO WVFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=tIvLoyAzCOVKOX99D0R9AADU51C3uknT25CXCqDgD1U=; b=eWkRPajoe9PdQGptLlUqfxCYSvl+ZmHCe5HBj4WKsoJEK6DClT3m8QwAHgjD4qycN0 fWCUU9iUxyAec5jT0QLpRorA3cQ+Hqw08QRk+YuRTpfyowJNSk3FBCY9hMxFZ6Q1bVuu +9VOgGu4Dk25q/yJt3NuEpG1DrgLJH3ve9k+vrznB5sovvnoRQU7PTX5F2Q3wGgZ+uEj CroRwFJahEUdRYCWY5BmimWXajWCyb72vSWBHdoR6hChku0Ncz0UpbyYG/qd8gobyQh7 lCAZvevPOfdNwZJnxm6J6tqPP/8glx5vZ2XgWg6vEEhNMfuBsK7mhFJXMWDVhP6oBUw3 MmGg== X-Gm-Message-State: ACrzQf3XCJxcGTygyrkYcyR1Hc3gcdcUpL0L/+0RsF1MefgEDoqs8NCF Ky/ZLWIR1/97KFGXK7/jHwsGu6sKmqSCWe/HEA99uQ== X-Received: by 2002:ac2:4c8b:0:b0:4a2:2432:93ff with SMTP id d11-20020ac24c8b000000b004a2243293ffmr1387544lfl.26.1665046264888; Thu, 06 Oct 2022 01:51:04 -0700 (PDT) MIME-Version: 1.0 References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-2-chao.p.peng@linux.intel.com> In-Reply-To: <20220915142913.2213336-2-chao.p.peng@linux.intel.com> From: Fuad Tabba Date: Thu, 6 Oct 2022 09:50:28 +0100 Message-ID: Subject: Re: [PATCH v8 1/8] mm/memfd: Introduce userspace inaccessible memfd 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, linux-doc@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 , 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, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 Hi, <...> > diff --git a/mm/memfd_inaccessible.c b/mm/memfd_inaccessible.c > new file mode 100644 > index 000000000000..2d33cbdd9282 > --- /dev/null > +++ b/mm/memfd_inaccessible.c <...> > +struct file *memfd_mkinaccessible(struct file *memfd) > +{ > + struct inaccessible_data *data; > + struct address_space *mapping; > + struct inode *inode; > + struct file *file; > + > + data = kzalloc(sizeof(*data), GFP_KERNEL); > + if (!data) > + return ERR_PTR(-ENOMEM); > + > + data->memfd = memfd; > + mutex_init(&data->lock); > + INIT_LIST_HEAD(&data->notifiers); > + > + inode = alloc_anon_inode(inaccessible_mnt->mnt_sb); > + if (IS_ERR(inode)) { > + kfree(data); > + return ERR_CAST(inode); > + } > + > + inode->i_mode |= S_IFREG; > + inode->i_op = &inaccessible_iops; > + inode->i_mapping->private_data = data; > + > + file = alloc_file_pseudo(inode, inaccessible_mnt, > + "[memfd:inaccessible]", O_RDWR, > + &inaccessible_fops); > + if (IS_ERR(file)) { > + iput(inode); > + kfree(data); I think this might be missing a return at this point. > + } > + > + file->f_flags |= O_LARGEFILE; > + > + mapping = memfd->f_mapping; > + mapping_set_unevictable(mapping); > + mapping_set_gfp_mask(mapping, > + mapping_gfp_mask(mapping) & ~__GFP_MOVABLE); > + > + return file; > +} Thanks, /fuad > + > +void inaccessible_register_notifier(struct file *file, > + struct inaccessible_notifier *notifier) > +{ > + struct inaccessible_data *data = file->f_mapping->private_data; > + > + mutex_lock(&data->lock); > + list_add(¬ifier->list, &data->notifiers); > + mutex_unlock(&data->lock); > +} > +EXPORT_SYMBOL_GPL(inaccessible_register_notifier); > + > +void inaccessible_unregister_notifier(struct file *file, > + struct inaccessible_notifier *notifier) > +{ > + struct inaccessible_data *data = file->f_mapping->private_data; > + > + mutex_lock(&data->lock); > + list_del(¬ifier->list); > + mutex_unlock(&data->lock); > +} > +EXPORT_SYMBOL_GPL(inaccessible_unregister_notifier); > + > +int inaccessible_get_pfn(struct file *file, pgoff_t offset, pfn_t *pfn, > + int *order) > +{ > + struct inaccessible_data *data = file->f_mapping->private_data; > + struct file *memfd = data->memfd; > + struct page *page; > + int ret; > + > + ret = shmem_getpage(file_inode(memfd), offset, &page, SGP_WRITE); > + if (ret) > + return ret; > + > + *pfn = page_to_pfn_t(page); > + *order = thp_order(compound_head(page)); > + SetPageUptodate(page); > + unlock_page(page); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(inaccessible_get_pfn); > + > +void inaccessible_put_pfn(struct file *file, pfn_t pfn) > +{ > + struct page *page = pfn_t_to_page(pfn); > + > + if (WARN_ON_ONCE(!page)) > + return; > + > + put_page(page); > +} > +EXPORT_SYMBOL_GPL(inaccessible_put_pfn); > -- > 2.25.1 >