Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp842463rwb; Tue, 29 Nov 2022 06:07:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fUeGPu0C72O4ZlC08AxMH6EZacSvaZ7n24w3a//xFQGKeG6JA8WoVe7TMzHPHkgvnB9kp X-Received: by 2002:a2e:5008:0:b0:279:a10b:7c1 with SMTP id e8-20020a2e5008000000b00279a10b07c1mr3783031ljb.361.1669730842811; Tue, 29 Nov 2022 06:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669730842; cv=none; d=google.com; s=arc-20160816; b=ghqye6qecIh7zWGREzXusJuAhTqvGIEkkV2IK+R233aXglHXspDjbOnjwAXdmZ4Vpy 1ZJ9XsttkYsvLbhjqbV9OA/Df7b244q0mxwwpGazXDEnJz/T0+7UplAKta1yBR5EDJpr Q2gIEbBn/r0ZkcZ+vr1zzzS3AsXMhlb715abQLAEZVR6XpBQN+EpIdN/LsWhA3bfd8/7 Munz3SmiFVzN98oymbKPC87JhpXd0Fc+KQ8fxHOoqKu8qmt6zmx28SYCbQH2kKzrXcca 9gsBeD9kFEiC6EsVojh+im5n4ePJcnKYAoa+7kleUkgw7x6pKz6r2pdULVsxc4BRl70P SUsw== 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=ru/SgZIo97dVU0HZL3d2J+2V/vhcPGsZvQR6D+n8dQI=; b=I+lqYWIMfdjyIcOOF+ZI8PCW/aGXFpRoGeNAip+MRpgnU+rSSV3utZgvtq7VY/oc4c HjVbh/n+8HUwr8YfAdQB4qcqVqfxEiEoql1eaPYYk5ZOillXMs3IxkNffG8Lvbjtbc1w rv90b2pFN/qZKVRyhiLs4Tz49Nvm1XIq1WPp9Mf1fyzVBC3n7j1fLVaRWrk/B8c5vdQs qKBEgQm0Y7at+CqWUFseW7jw44G0YkdpGoRto1A7c0hKXNEU7Az9VhTdl2SzVn473lFa DQsOoWq7+uSBxSQ39dj+G4LwH65yQulnUgLWWDJN5XszrSpg192LJ3Qp3ZH5V004KTNa 8d2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GOTJBVPw; 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 y14-20020a056402270e00b0046abe52aca7si11033013edd.486.2022.11.29.06.06.49; Tue, 29 Nov 2022 06:07:22 -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=GOTJBVPw; 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 S234951AbiK2OD6 (ORCPT + 84 others); Tue, 29 Nov 2022 09:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbiK2ODk (ORCPT ); Tue, 29 Nov 2022 09:03:40 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3CB49081; Tue, 29 Nov 2022 06:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669730619; x=1701266619; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=RRv6X9kxxmg0r2Bt/bN85+Xzhbzh0Sz0OFcppuwQCsk=; b=GOTJBVPwrjlex7VY0yK8at7YkujTbm5WSbk9MkRHVv08akW99oJQoLn4 EbB+i39Kt6zzzeD52+JSDzVG+KHbAJcOg9VoTvXtEQNTVsJL4md1TFRi3 D/nAik/sA36SpHxXXGhs2UoJwK/dNVhQTXr4TAsX24aitkXwJeUHY/BVE J+smxfnAUSVWNNcp+QzDgr3xA3UArOLkJozgJZBjlXa4lBo9JHjC/zpc5 P+/Ldl6YOly1+yzvVBMigOpl4nG/5pUf/bx6LCp7/8I+eeGVaOujzpYqi 7QTntPVUe5Wns6Cre5dQcPTFJvj2UxH3uSHtwIbTqW3krodOutAzC3ch9 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="316948114" X-IronPort-AV: E=Sophos;i="5.96,203,1665471600"; d="scan'208";a="316948114" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2022 06:03:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="707221475" X-IronPort-AV: E=Sophos;i="5.96,203,1665471600"; d="scan'208";a="707221475" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2022 06:03:05 -0800 Date: Tue, 29 Nov 2022 21:58:44 +0800 From: Chao Peng To: "Kirill A. Shutemov" Cc: Michael Roth , 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 , 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 , tabba@google.com, 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: <20221129135844.GA902164@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> <20221129000632.sz6pobh6p7teouiu@amd.com> <20221129112139.usp6dqhbih47qpjl@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221129112139.usp6dqhbih47qpjl@box.shutemov.name> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Tue, Nov 29, 2022 at 02:21:39PM +0300, Kirill A. Shutemov wrote: > On Mon, Nov 28, 2022 at 06:06:32PM -0600, Michael Roth wrote: > > On Tue, Oct 25, 2022 at 11:13:37PM +0800, Chao Peng wrote: > > > From: "Kirill A. Shutemov" > > > > > > > > > > > > +static struct file *restrictedmem_file_create(struct file *memfd) > > > +{ > > > + struct restrictedmem_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(restrictedmem_mnt->mnt_sb); > > > + if (IS_ERR(inode)) { > > > + kfree(data); > > > + return ERR_CAST(inode); > > > + } > > > + > > > + inode->i_mode |= S_IFREG; > > > + inode->i_op = &restrictedmem_iops; > > > + inode->i_mapping->private_data = data; > > > + > > > + file = alloc_file_pseudo(inode, restrictedmem_mnt, > > > + "restrictedmem", O_RDWR, > > > + &restrictedmem_fops); > > > + if (IS_ERR(file)) { > > > + iput(inode); > > > + kfree(data); > > > + return ERR_CAST(file); > > > + } > > > + > > > + file->f_flags |= O_LARGEFILE; > > > + > > > + mapping = memfd->f_mapping; > > > + mapping_set_unevictable(mapping); > > > + mapping_set_gfp_mask(mapping, > > > + mapping_gfp_mask(mapping) & ~__GFP_MOVABLE); > > > > Is this supposed to prevent migration of pages being used for > > restrictedmem/shmem backend? > > Yes, my bad. I expected it to prevent migration, but it is not true. > > Looks like we need to bump refcount in restrictedmem_get_page() and reduce > it back when KVM is no longer use it. The restrictedmem_get_page() has taken a reference, but later KVM put_page() after populating the secondary page table entry through kvm_release_pfn_clean(). One option would let the user feature(e.g. TDX/SEV) to get_page/put_page() during populating the secondary page table entry, AFAICS, this requirement also comes from these features. Chao > > Chao, could you adjust it? > > -- > Kiryl Shutsemau / Kirill A. Shutemov