Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3011771pxp; Tue, 8 Mar 2022 06:15:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpoQ0xExaXFjbFBlAqeTRUmzotCh4Lh5xo+u5YzpncJFsq7TR4mses1vems02SIGh1NHop X-Received: by 2002:a17:906:16cc:b0:6ce:e607:ff02 with SMTP id t12-20020a17090616cc00b006cee607ff02mr13051365ejd.418.1646748935255; Tue, 08 Mar 2022 06:15:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646748935; cv=none; d=google.com; s=arc-20160816; b=lXweujAzyhKRZBl/ScqMu80WBe5D61cMXRXHwGZ5r6LmSecZSmdojwqWAUzsFuz9wA dsPqDjMdNBEVBSEiqpD3nrN7nmQjYPcDTDL+jtbOiVGHsenM/qjiXkm8gAwZlW6PL0zN hfe8K3/J4+9mNUj6C7TSZNwPnytDk6TsN0KqUyCpgeSg33msDdlnshcuWqE+lGMPJo1g SS8Hy46MPu2HeuwKMigxYqklt8jBKw5chtPJWU/9JJI1Ljo7tzTEfFmL/IsqovWZ5yTx zB/z9xmkA8/BhaAlL3t+3ars+cv5qF9JoFpYVtnolrlt48rQtS7NMBXeNNA2XJmPfuQL 86yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=eQZH+t4UmSeb65BCY5uQV7fqHoYrH355u0yGS9QcyUc=; b=wiOXD26NUu+QVnYblloLMnOv8S8HsJA4sxr3lf0HUq5nSP8UEf3oZuYfB8Bocwgzk7 tYNCT06CWwaPeD5di/YXT8AfXHbvXLSHVncBVs3aMHOV+yZ6mPZCIzr1AbVhPMMaq7SQ a9zErIbBwxmoGLV5BtFYOIM33vt6t2pMtErnNCE18dbwKBRtm0vNMsPwNI04LNgYJ+aM +/zZjVog7XjpU79Tf1VbtYgxvJehmSzyLZ3Zdd0j3cfAk0clTEEYvD+4gEC9iHmhVFCF ge519hZ/Q5Xt8gjNT/qPY9XQ0mHfAi8JMKQXohl8J/qljll4s8I0fSXoDFcUSqzm2z1Z JXfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Q/xRd2Q7"; 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 ka4-20020a170907990400b006cd93b40f4bsi9498443ejc.627.2022.03.08.06.15.10; Tue, 08 Mar 2022 06:15:35 -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="Q/xRd2Q7"; 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 S242846AbiCGN1X (ORCPT + 99 others); Mon, 7 Mar 2022 08:27:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242830AbiCGN1V (ORCPT ); Mon, 7 Mar 2022 08:27:21 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E1038A6C2; Mon, 7 Mar 2022 05:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646659587; x=1678195587; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=chZdczKRWiX0mygtvCioOFf/nQfwodUEadgTzmKZVhc=; b=Q/xRd2Q7ANifNpgJYHw1g+F0MVM0jDeAU2v+0LFifGNuwdEg7b/+HStQ WQk7VE6n5t491VTN7SmJC0cEOhSOm1A08q1N4RdGhjwylujOOmHDxGTXC DwtBeA3WAJ/A4AP6GB9VGObdXFuLNYLbZEMX4d1n1mdiQoKVSwrpIVFNd sxEVN+6g/FR9zqEGFN60gJilqz08eDGsrPpLATmIMtlzNuhhEFIggo0w+ Z1ywOfwxPzArWvgCe7i+5i9kFqaDxRFE4bDW5eiMNnnWyIVotinmsNHcg JR+DqYIfkGKfQEea0Ga9AFDaZjwaAtEA7rN5DAVAPhRbBcu4haKdB96s0 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10278"; a="279090582" X-IronPort-AV: E=Sophos;i="5.90,162,1643702400"; d="scan'208";a="279090582" 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-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 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\