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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6DE7C43219 for ; Mon, 7 Mar 2022 13:26:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BC6B8D0002; Mon, 7 Mar 2022 08:26:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 575278D0001; Mon, 7 Mar 2022 08:26:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4331D8D0002; Mon, 7 Mar 2022 08:26:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 332748D0001 for ; Mon, 7 Mar 2022 08:26:30 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D801AA728A for ; Mon, 7 Mar 2022 13:26:29 +0000 (UTC) X-FDA: 79217664498.31.396248D Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf19.hostedemail.com (Postfix) with ESMTP id 8CFD01A000E for ; Mon, 7 Mar 2022 13:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646659588; x=1678195588; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=chZdczKRWiX0mygtvCioOFf/nQfwodUEadgTzmKZVhc=; b=P4k+VksjZM9lavN+FMTKksfHBdXypJ8W8AxI3BGvtYIJRpryNq0BUu7X PlrtiiVrThFA+585u1ILLmw7ISew6Xnr6a+QOc0qFj0nRV2FiLsqWYW6x 8nUUIPPO+6QPrKdCZtq8e7HhrxxT9K/X5ii6mYl/RuSeuA1HLdW2sif8X Xf/PFIecHkpflmeaPVOC1C4tUdttzIdfGgHjhjZ+MmuRPVBrz5z8+Towy tB4xt7lumfDfkK/VpkIa/c4IvNBK7N02ZwKAgdaIiZwTBfqz7n9dAFQZr D9jgJ7Rt1nYaB7vEMVsh/f2ELliqrTiaLNXDONN607I5zzBl/M+Iglenj g==; X-IronPort-AV: E=McAfee;i="6200,9189,10278"; a="279090583" X-IronPort-AV: E=Sophos;i="5.90,162,1643702400"; d="scan'208";a="279090583" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 05:26:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,162,1643702400"; d="scan'208";a="711103618" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga005.jf.intel.com with ESMTP; 07 Mar 2022 05:26:19 -0800 Date: Mon, 7 Mar 2022 21:26:02 +0800 From: Chao Peng To: Andy Lutomirski Cc: Steven Price , kvm list , Linux Kernel Mailing List , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org, Linux API , Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , the arch/x86 maintainers , "H. Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Yu Zhang , "Kirill A. Shutemov" , "Nakajima, Jun" , Dave Hansen , Andi Kleen , David Hildenbrand Subject: Re: [PATCH v4 01/12] mm/shmem: Introduce F_SEAL_INACCESSIBLE Message-ID: <20220307132602.GA58690@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220118132121.31388-1-chao.p.peng@linux.intel.com> <20220118132121.31388-2-chao.p.peng@linux.intel.com> <619547ad-de96-1be9-036b-a7b4e99b09a6@kernel.org> <20220217130631.GB32679@chaop.bj.intel.com> <2ca78dcb-61d9-4c9d-baa9-955b6f4298bb@www.fastmail.com> <20220223114935.GA53733@chaop.bj.intel.com> <71a06402-6743-bfd2-bbd4-997f8e256554@arm.com> <7cc65bbd-e323-eabb-c576-b5656a3355ac@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7cc65bbd-e323-eabb-c576-b5656a3355ac@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspamd-Queue-Id: 8CFD01A000E X-Stat-Signature: c3kz14coexcqycm4qe9t5n4twrya8p3w Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=P4k+Vksj; spf=none (imf19.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646659588-317396 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, Mar 04, 2022 at 11:24:30AM -0800, Andy Lutomirski wrote: > On 2/23/22 04:05, Steven Price wrote: > > On 23/02/2022 11:49, Chao Peng wrote: > > > On Thu, Feb 17, 2022 at 11:09:35AM -0800, Andy Lutomirski wrote: > > > > On Thu, Feb 17, 2022, at 5:06 AM, Chao Peng wrote: > > > > > On Fri, Feb 11, 2022 at 03:33:35PM -0800, Andy Lutomirski wrote: > > > > > > On 1/18/22 05:21, Chao Peng wrote: > > > > > > > From: "Kirill A. Shutemov" > > > > > > > > > > > > > > Introduce a new seal F_SEAL_INACCESSIBLE indicating the content of > > > > > > > the file is inaccessible from userspace through ordinary MMU access > > > > > > > (e.g., read/write/mmap). However, the file content can be accessed > > > > > > > via a different mechanism (e.g. KVM MMU) indirectly. > > > > > > > > > > > > > > It provides semantics required for KVM guest private memory support > > > > > > > that a file descriptor with this seal set is going to be used as the > > > > > > > source of guest memory in confidential computing environments such > > > > > > > as Intel TDX/AMD SEV but may not be accessible from host userspace. > > > > > > > > > > > > > > At this time only shmem implements this seal. > > > > > > > > > > > > > > > > > > > I don't dislike this *that* much, but I do dislike this. F_SEAL_INACCESSIBLE > > > > > > essentially transmutes a memfd into a different type of object. While this > > > > > > can apparently be done successfully and without races (as in this code), > > > > > > it's at least awkward. I think that either creating a special inaccessible > > > > > > memfd should be a single operation that create the correct type of object or > > > > > > there should be a clear justification for why it's a two-step process. > > > > > > > > > > Now one justification maybe from Stever's comment to patch-00: for ARM > > > > > usage it can be used with creating a normal memfd, (partially)populate > > > > > it with initial guest memory content (e.g. firmware), and then > > > > > F_SEAL_INACCESSIBLE it just before the first time lunch of the guest in > > > > > KVM (definitely the current code needs to be changed to support that). > > > > > > > > Except we don't allow F_SEAL_INACCESSIBLE on a non-empty file, right? So this won't work. > > > > > > Hmm, right, if we set F_SEAL_INACCESSIBLE on a non-empty file, we will > > > need to make sure access to existing mmap-ed area should be prevented, > > > but that is hard. > > > > > > > > > > > In any case, the whole confidential VM initialization story is a bit buddy. From the earlier emails, it sounds like ARM expects the host to fill in guest memory and measure it. From my recollection of Intel's scheme (which may well be wrong, and I could easily be confusing it with SGX), TDX instead measures what is essentially a transcript of the series of operations that initializes the VM. These are fundamentally not the same thing even if they accomplish the same end goal. For TDX, we unavoidably need an operation (ioctl or similar) that initializes things according to the VM's instructions, and ARM ought to be able to use roughly the same mechanism. > > > > > > Yes, TDX requires a ioctl. Steven may comment on the ARM part. > > > > The Arm story is evolving so I can't give a definite answer yet. Our > > current prototyping works by creating the initial VM content in a > > memslot as with a normal VM and then calling an ioctl which throws the > > big switch and converts all the (populated) pages to be protected. At > > this point the RMM performs a measurement of the data that the VM is > > being populated with. > > > > The above (in our prototype) suffers from all the expected problems with > > a malicious VMM being able to trick the host kernel into accessing those > > pages after they have been protected (causing a fault detected by the > > hardware). > > > > The ideal (from our perspective) approach would be to follow the same > > flow but where the VMM populates a memfd rather than normal anonymous > > pages. The memfd could then be sealed and the pages converted to > > protected ones (with the RMM measuring them in the process). > > > > The question becomes how is that memfd populated? It would be nice if > > that could be done using normal operations on a memfd (i.e. using > > mmap()) and therefore this code could be (relatively) portable. This > > would mean that any pages mapped from the memfd would either need to > > block the sealing or be revoked at the time of sealing. > > > > The other approach is we could of course implement a special ioctl which > > effectively does a memcpy into the (created empty and sealed) memfd and > > does the necessary dance with the RMM to measure the contents. This > > would match the "transcript of the series of operations" described above > > - but seems much less ideal from the viewpoint of the VMM. > > A VMM that supports Other Vendors will need to understand this sort of model > regardless. > > I don't particularly mind the idea of having the kernel consume a normal > memfd and spit out a new object, but I find the concept of changing the type > of the object in place, even if it has other references, and trying to > control all the resulting races to be somewhat alarming. > > In pseudo-Rust, this is the difference between: > > fn convert_to_private(in: &mut Memfd) > > and > > fn convert_to_private(in: Memfd) -> PrivateMemoryFd > > This doesn't map particularly nicely to the kernel, though. I understand this Rust semantics and the difficulty to handle races. Probably we should not expose F_SEAL_INACCESSIBLE to userspace, instead we can use a new in-kernel flag to indicate the same thing. That flag should be set only when the memfd is created with MFD_INACCESSIBLE. Chao > > --Andy\