From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10DBFC433F5 for ; Fri, 19 Nov 2021 15:20:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5D273611C0 for ; Fri, 19 Nov 2021 15:20:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5D273611C0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id ED8A66B0075; Fri, 19 Nov 2021 10:19:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8B066B007B; Fri, 19 Nov 2021 10:19:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D501C6B007D; Fri, 19 Nov 2021 10:19:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id C0BCB6B0075 for ; Fri, 19 Nov 2021 10:19:55 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7864680D3828 for ; Fri, 19 Nov 2021 15:19:45 +0000 (UTC) X-FDA: 78826039530.12.C407E3E Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf08.hostedemail.com (Postfix) with ESMTP id E691C30000B9 for ; Fri, 19 Nov 2021 15:19:42 +0000 (UTC) Received: by mail-qt1-f180.google.com with SMTP id v22so9726721qtx.8 for ; Fri, 19 Nov 2021 07:19:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0+oKCHlqOeL41R0XCrWbPi4i3qyXHn6RmL7MeAl4NL8=; b=lPGpGcid8QXwelr7zzSt5VTkDWstEKhmIVZjDI/gptTZ1XB8fRlCJsY82dS22YEbbI GADEuew95VumLWojAcQF6/3Rj7N9VtmARWHCGzMlbaVOuA5B2Iy8CEcEelQIeeRTPjCb /UriGVwYo5CnjPZCDlOVP8JIARNcJaTQUz01jDwgOeu3eE5FmpCC10B9LQ/D1G1T0tx4 iQg2Eg0YoxH/lMrAwoMlca7V5PAbid3j8gMabaFjohga4jUqveMxv4mUiSKJmYsSXZJ9 w9340v2YmW88xNRP0Sl+7ZXF9oISeC5mr2uPkE4vqO+Lek1l1/D1zTf+VnU59MujzXzD zgyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0+oKCHlqOeL41R0XCrWbPi4i3qyXHn6RmL7MeAl4NL8=; b=0U2RgdHtO5oamrmuZybLTENbqtO1VBSLYX9xwRre8lUm8M88gukYyOc9KyA8TzOV+Y nvUlT+goEX/vWwFG3Y2Yb7ipcQrIqAambGyGteJVnxd4fkcOs+kkJLyE3B9J8WJR1YX2 iEnITi7VwmgeRma0l5G6XwXv+mzz7rRMMDI37Y/cY2yThTb0GHSx1kXAXs6C1+a1iNz8 oQXuUvqCszN17NSA5rOYryCtNiZF4kKRy38i9B7wv2LDl+qV3xQ1qgZglB1cqF3u6YoX eMTvMUuwJmJzIiKqK4LLhZPmNhLJicm4q/DNAFWZyorgrpW483PfDDmn9wosQyNrmmrc F5RA== X-Gm-Message-State: AOAM5328IAWFcTyQARgPjeMh7FdN0yG2wbnGqKqfGC8AmUx/UbYki9q/ oRpr3GwokBAaLTPtlF4RtfGckQ== X-Google-Smtp-Source: ABdhPJzBFCjiPUEhMyOCMWRnIUW5f5YGg2HohyzeoXo1q5KwzNya5wlMfrrS3JbWjHX+xZcOYu6I9Q== X-Received: by 2002:a05:622a:1a93:: with SMTP id s19mr7169174qtc.291.1637335184307; Fri, 19 Nov 2021 07:19:44 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id o126sm11039qke.11.2021.11.19.07.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 07:19:43 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mo5fz-00CHGM-Aq; Fri, 19 Nov 2021 11:19:43 -0400 Date: Fri, 19 Nov 2021 11:19:43 -0400 From: Jason Gunthorpe To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@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 , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, john.ji@intel.com, susie.li@intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: Re: [RFC v2 PATCH 01/13] mm/shmem: Introduce F_SEAL_GUEST Message-ID: <20211119151943.GH876299@ziepe.ca> References: <20211119134739.20218-1-chao.p.peng@linux.intel.com> <20211119134739.20218-2-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211119134739.20218-2-chao.p.peng@linux.intel.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E691C30000B9 X-Stat-Signature: u3x8e6o5rwxewgzn4r9kezc3bji87jfj Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=lPGpGcid; spf=pass (imf08.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.180 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-HE-Tag: 1637335182-892075 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Nov 19, 2021 at 09:47:27PM +0800, Chao Peng wrote: > From: "Kirill A. Shutemov" > > The new seal type provides semantics required for KVM guest private > memory support. A file descriptor with the seal set is going to be used > as source of guest memory in confidential computing environments such as > Intel TDX and AMD SEV. > > F_SEAL_GUEST can only be set on empty memfd. After the seal is set > userspace cannot read, write or mmap the memfd. > > Userspace is in charge of guest memory lifecycle: it can allocate the > memory with falloc or punch hole to free memory from the guest. > > The file descriptor passed down to KVM as guest memory backend. KVM > register itself as the owner of the memfd via memfd_register_guest(). > > KVM provides callback that needed to be called on fallocate and punch > hole. > > memfd_register_guest() returns callbacks that need be used for > requesting a new page from memfd. > > Signed-off-by: Kirill A. Shutemov > Signed-off-by: Chao Peng > include/linux/memfd.h | 24 ++++++++ > include/linux/shmem_fs.h | 9 +++ > include/uapi/linux/fcntl.h | 1 + > mm/memfd.c | 33 +++++++++- > mm/shmem.c | 123 ++++++++++++++++++++++++++++++++++++- > 5 files changed, 186 insertions(+), 4 deletions(-) > > diff --git a/include/linux/memfd.h b/include/linux/memfd.h > index 4f1600413f91..ff920ef28688 100644 > +++ b/include/linux/memfd.h > @@ -4,13 +4,37 @@ > > #include > > +struct guest_ops { > + void (*invalidate_page_range)(struct inode *inode, void *owner, > + pgoff_t start, pgoff_t end); > + void (*fallocate)(struct inode *inode, void *owner, > + pgoff_t start, pgoff_t end); > +}; > + > +struct guest_mem_ops { > + unsigned long (*get_lock_pfn)(struct inode *inode, pgoff_t offset, > + bool alloc, int *order); > + void (*put_unlock_pfn)(unsigned long pfn); > + > +}; Ignoring confidential compute for a moment If qmeu can put all the guest memory in a memfd and not map it, then I'd also like to see that the IOMMU can use this interface too so we can have VFIO working in this configuration. As designed the above looks useful to import a memfd to a VFIO container but could you consider some more generic naming than calling this 'guest' ? Along the same lines, to support fast migration, we'd want to be able to send these things to the RDMA subsytem as well so we can do data xfer. Very similar to VFIO. Also, shouldn't this be two patches? F_SEAL is not really related to these acessors, is it? > +extern inline int memfd_register_guest(struct inode *inode, void *owner, > + const struct guest_ops *guest_ops, > + const struct guest_mem_ops **guest_mem_ops); Why does this take an inode and not a file *? > +int shmem_register_guest(struct inode *inode, void *owner, > + const struct guest_ops *guest_ops, > + const struct guest_mem_ops **guest_mem_ops) > +{ > + struct shmem_inode_info *info = SHMEM_I(inode); > + > + if (!owner) > + return -EINVAL; > + > + if (info->guest_owner && info->guest_owner != owner) > + return -EPERM; And this looks like it means only a single subsytem can use this API at once, not so nice.. Jason