Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1702821rwb; Thu, 1 Dec 2022 23:11:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GWQIZ5KGaCEbbtRN1S1WH7T/+8P/VrZiq5hsHNhgk7ZJQSLU0UsB5vOCkfCW+F/KgKen+ X-Received: by 2002:a63:4c58:0:b0:476:b165:c83f with SMTP id m24-20020a634c58000000b00476b165c83fmr46762741pgl.602.1669965065090; Thu, 01 Dec 2022 23:11:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669965065; cv=none; d=google.com; s=arc-20160816; b=BYv/EynXDPmsFRU0/17jB01ut+4iMMnENJ4BLfTWXbr1b0a2ml0AFChZW9QZ7c2pzL qKIvBplafToYqfM0/slVKMg/1awBzoAZcB7+Poyv1sQ0wH06z04DVYQVdEypZTslfwKn xvZhLB+7tejBAwuUwkp6QIiNbs0e/h3kvIsDSpAFxv6g6g6wAIJhubXderxVbY39fSZd EcPGqEugf/C0pcsetK9/I70iP927VGgWJ0aK8srd3D25eXlQchTLJbhbSdEirC53mzBg kYLdr9DHM7XSmQsKJpQeQ60fe8ah/JBDLtfG6l66KPWBNcJ1N9ueFK+TA1nMkYOqongs WtEQ== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JM2rmoE5RvvU7lOMISBUQkmMWM9rsZae6ZcbQ/wR0E8=; b=rMSYQijSuZqdekEA2oZNbxyVPYap42nB1DIdYAhQU9kATvUIa6zut0i9Nb/iBGNR65 jmgl26v6yO2vDn0+lfCGiE5RmtwWIcQyFn6mruWR1l0qiCKHie7jvpzjAzNypHhsGpKB 2T4asRVL6Y1Wy348l/isQjH5spI76MHsLRWJpAXQA3gZtDlo3TT/SfvxqQ1dFRWMMlPY FKC87eMnBYlXdcV/+g+LwKFlz6LNbWAc+PDvQH6b+oT6ov8XVEYm5FQ9/JfCMpV6Oprq 7kfNrX7t2k8+yMgttDaiXGsdn0t5UbrS5LtltAKu1KKS+/jDDzCIx3ojibMAq0H+0ir2 5n6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eT0WFURX; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a170902bc4b00b001869de3edcasi5734619plz.466.2022.12.01.23.10.54; Thu, 01 Dec 2022 23:11:05 -0800 (PST) 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=@intel.com header.s=Intel header.b=eT0WFURX; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232435AbiLBGxr (ORCPT + 83 others); Fri, 2 Dec 2022 01:53:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232314AbiLBGxn (ORCPT ); Fri, 2 Dec 2022 01:53:43 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2254BB7C1; Thu, 1 Dec 2022 22:53:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669964022; x=1701500022; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=hsL57ikcNVoLHdsSPb/2quBPJAcrsHQWRoxcjDJhwfk=; b=eT0WFURXcMGeVYPNWIXxRON88XkgDgnK57MP8L9HBxKxsLmaAF3wJG7q rnDKkrgZoX9TcVbQjFOyiHKO0gbbZ9fcMwwssDAXYyl0WJvN4OeI0hfn/ Kn0FuzeN0TDa37Lo4FaguVQsHPwL8t1p0mbouzgGyTeMfR+/WJw28w2b8 rh2r81QD8/4ACEi8dpcM54W2kVY5TcI1TPegcZnSzlgwg7wDRxmJr7X5t P2v2sBsKA3vddkTIPlScUBDZCzecu1t1zNo639kpdVQMg7YY5Tl2lDL/u KEf8CmRexAJLimiQPuCvaGZlDcib1wrhzm98hW6Vv0ekfUBtGpO0LdthQ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10548"; a="299253379" X-IronPort-AV: E=Sophos;i="5.96,210,1665471600"; d="scan'208";a="299253379" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2022 22:53:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10548"; a="708374082" X-IronPort-AV: E=Sophos;i="5.96,210,1665471600"; d="scan'208";a="708374082" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga008.fm.intel.com with ESMTP; 01 Dec 2022 22:53:30 -0800 Date: Fri, 2 Dec 2022 14:49:09 +0800 From: Chao Peng To: Vishal Annapurve Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@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 , 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 , tabba@google.com, Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Subject: Re: [PATCH v9 1/8] mm: Introduce memfd_restricted system call to create restricted user memory Message-ID: <20221202064909.GA1070297@chaop.bj.intel.com> Reply-To: Chao Peng References: <20221025151344.3784230-1-chao.p.peng@linux.intel.com> <20221025151344.3784230-2-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 On Thu, Dec 01, 2022 at 06:16:46PM -0800, Vishal Annapurve wrote: > On Tue, Oct 25, 2022 at 8:18 AM Chao Peng wrote: > > ... > > +} > > + > > +SYSCALL_DEFINE1(memfd_restricted, unsigned int, flags) > > +{ > > Looking at the underlying shmem implementation, there seems to be no > way to enable transparent huge pages specifically for restricted memfd > files. > > Michael discussed earlier about tweaking > /sys/kernel/mm/transparent_hugepage/shmem_enabled setting to allow > hugepages to be used while backing restricted memfd. Such a change > will affect the rest of the shmem usecases as well. Even setting the > shmem_enabled policy to "advise" wouldn't help unless file based > advise for hugepage allocation is implemented. Had a look at fadvise() and looks it does not support HUGEPAGE for any filesystem yet. > > Does it make sense to provide a flag here to allow creating restricted > memfds backed possibly by huge pages to give a more granular control? We do have a unused 'flags' can be extended for such usage, but I would let Kirill have further look, perhaps need more discussions. Chao > > > + struct file *file, *restricted_file; > > + int fd, err; > > + > > + if (flags) > > + return -EINVAL; > > + > > + fd = get_unused_fd_flags(0); > > + if (fd < 0) > > + return fd; > > + > > + file = shmem_file_setup("memfd:restrictedmem", 0, VM_NORESERVE); > > + if (IS_ERR(file)) { > > + err = PTR_ERR(file); > > + goto err_fd; > > + } > > + file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; > > + file->f_flags |= O_LARGEFILE; > > + > > + restricted_file = restrictedmem_file_create(file); > > + if (IS_ERR(restricted_file)) { > > + err = PTR_ERR(restricted_file); > > + fput(file); > > + goto err_fd; > > + } > > + > > + fd_install(fd, restricted_file); > > + return fd; > > +err_fd: > > + put_unused_fd(fd); > > + return err; > > +} > > + > > +void restrictedmem_register_notifier(struct file *file, > > + struct restrictedmem_notifier *notifier) > > +{ > > + struct restrictedmem_data *data = file->f_mapping->private_data; > > + > > + mutex_lock(&data->lock); > > + list_add(¬ifier->list, &data->notifiers); > > + mutex_unlock(&data->lock); > > +} > > +EXPORT_SYMBOL_GPL(restrictedmem_register_notifier); > > + > > +void restrictedmem_unregister_notifier(struct file *file, > > + struct restrictedmem_notifier *notifier) > > +{ > > + struct restrictedmem_data *data = file->f_mapping->private_data; > > + > > + mutex_lock(&data->lock); > > + list_del(¬ifier->list); > > + mutex_unlock(&data->lock); > > +} > > +EXPORT_SYMBOL_GPL(restrictedmem_unregister_notifier); > > + > > +int restrictedmem_get_page(struct file *file, pgoff_t offset, > > + struct page **pagep, int *order) > > +{ > > + struct restrictedmem_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; > > + > > + *pagep = page; > > + if (order) > > + *order = thp_order(compound_head(page)); > > + > > + SetPageUptodate(page); > > + unlock_page(page); > > + > > + return 0; > > +} > > +EXPORT_SYMBOL_GPL(restrictedmem_get_page); > > -- > > 2.25.1 > >