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 X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF0E8C432BE for ; Tue, 31 Aug 2021 19:07:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 26BE76056B for ; Tue, 31 Aug 2021 19:07:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 26BE76056B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id ABE3C6B006C; Tue, 31 Aug 2021 15:07:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A46DA6B0071; Tue, 31 Aug 2021 15:07:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C06F8D0001; Tue, 31 Aug 2021 15:07:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 757406B006C for ; Tue, 31 Aug 2021 15:07:15 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 300E3253CA for ; Tue, 31 Aug 2021 19:07:15 +0000 (UTC) X-FDA: 78536308830.10.1F327F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf19.hostedemail.com (Postfix) with ESMTP id A3757B0000A2 for ; Tue, 31 Aug 2021 19:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630436834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L5ykmaiBHLn8tM3nLNz5TAEpWwFHOANe8ir9pHZRCuw=; b=W72KEYiiQodSdv0shPwFQSGt6UMdhRWVeZTm8C5meuYgxUqu/zYX3Jb/uzEQ56c1GllvqK SGVBl08sh4UmS0YhCw6uDRKSAnotkNA6ze4zY3uzZz4kCSTCNtESpGbaO2k50I4bDVqbkA 28wc4R2kyVc6zom4+38/JTDt3Z9sCgU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-6gXCq5c_OPCXQMXLgiDN0A-1; Tue, 31 Aug 2021 15:07:11 -0400 X-MC-Unique: 6gXCq5c_OPCXQMXLgiDN0A-1 Received: by mail-wm1-f72.google.com with SMTP id y24-20020a7bcd98000000b002eb50db2b62so81253wmj.5 for ; Tue, 31 Aug 2021 12:07:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=L5ykmaiBHLn8tM3nLNz5TAEpWwFHOANe8ir9pHZRCuw=; b=VG+gqxL9kxtS+ZblhrCvdeZSsPJvH1dhsjr5GAk/9sT3XFytGG8iCs32v7/QwIDitp kCjGMZAYvAvIN6HoF++2vKJ7/vVV0xCYyEISt9rmVA+bn0bI8wtQEY18Rdo9THL/5g6d 2RBB1nuIboncy/fXGQOXdwHFkPFZL3qRkxSJ2Kc9y7HtQo1ipXEfTNgLFIBJlAt8Pxo8 Bo8nZh3hHuIvJZLOH7gntR0uJjRnenZPjTzxqRHmG8zSRkiagtISKC2kL1nhT3yX/kOk MzRXy/24YIAx1MGYkiLlw/HFmTxhVZxEvySM1sLKhJYVC8nly0f9RF+yBMolS56e3n0D EvHA== X-Gm-Message-State: AOAM5314c4fDk1a4qUlWdtkZurWnmm2kfysxqh6ngc2LjYRsjhByOYkp k+sJMbAgUPX+Up6dgZXVrHZjnV2Vnki4xaBqmmeVSLUlBHPesLv6wBUi3LDVUS2i39bl92oZsMv lj6Efz2HO1w4= X-Received: by 2002:a1c:f414:: with SMTP id z20mr5923504wma.94.1630436830364; Tue, 31 Aug 2021 12:07:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQWrSDLLp1TcV1T+/bO+ed5HqV84f+I7rn+Kp+Rm6ixxZf1kGZm5sU+cR1zQ/9IfVLm1yr5g== X-Received: by 2002:a1c:f414:: with SMTP id z20mr5923456wma.94.1630436830087; Tue, 31 Aug 2021 12:07:10 -0700 (PDT) Received: from [192.168.3.132] (p4ff23bf5.dip0.t-ipconnect.de. [79.242.59.245]) by smtp.gmail.com with ESMTPSA id n1sm18760006wrp.49.2021.08.31.12.07.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Aug 2021 12:07:09 -0700 (PDT) To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , Andy Lutomirski , Andrew Morton , Joerg Roedel , Andi Kleen , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Varad Gautam , Dario Faggioli , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, "Kirill A . Shutemov" , "Kirill A . Shutemov" , Kuppuswamy Sathyanarayanan , Dave Hansen , Yu Zhang References: <20210824005248.200037-1-seanjc@google.com> <307d385a-a263-276f-28eb-4bc8dd287e32@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [RFC] KVM: mm: fd-based approach for supporting KVM guest private memory Message-ID: <61ea53ce-2ba7-70cc-950d-ca128bcb29c5@redhat.com> Date: Tue, 31 Aug 2021 21:07:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Queue-Id: A3757B0000A2 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W72KEYii; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf19.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam01 X-Stat-Signature: tzkxy7b4csqzobx1hzjezx6wz8zkbodj X-HE-Tag: 1630436834-979154 Content-Transfer-Encoding: quoted-printable 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 28.08.21 00:18, Sean Christopherson wrote: > On Thu, Aug 26, 2021, David Hildenbrand wrote: >> You'll end up with a VMA that corresponds to the whole file in a singl= e >> process only, and that cannot vanish, not even in parts. >=20 > How would userspace tell the kernel to free parts of memory that it doe= sn't want > assigned to the guest, e.g. to free memory that the guest has converted= to > not-private? I'd guess one possibility could be fallocate(FALLOC_FL_PUNCH_HOLE). Questions are: when would it actually be allowed to perform such a=20 destructive operation? Do we have to protect from that? How would KVM=20 protect from user space replacing private pages by shared pages in any=20 of the models we discuss? >=20 >> Define "ordinary" user memory slots as overlay on top of "encrypted" m= emory >> slots. Inside KVM, bail out if you encounter such a VMA inside a norm= al >> user memory slot. When creating a "encryped" user memory slot, require= that >> the whole VMA is covered at creation time. You know the VMA can't chan= ge >> later. >=20 > This can work for the basic use cases, but even then I'd strongly prefe= r not to > tie memslot correctness to the VMAs. KVM doesn't truly care what lies = behind > the virtual address of a memslot, and when it does care, it tends to do= poorly, > e.g. see the whole PFNMAP snafu. KVM cares about the pfn<->gfn mapping= s, and > that's reflected in the infrastructure. E.g. KVM relies on the mmu_not= ifiers > to handle mprotect()/munmap()/etc... Right, and for the existing use cases this worked. But encrypted memory=20 breaks many assumptions we once made ... I have somewhat mixed feelings about pages that are mapped into=20 $WHATEVER page tables but not actually mapped into user space page=20 tables. There is no way to reach these via the rmap. We have something like that already via vfio. And that is fundamentally=20 broken when it comes to mmu notifiers, page pinning, page migration, ... >=20 > As is, I don't think KVM would get any kind of notification if userpace= s unmaps > the VMA for a private memslot that does not have any entries in the hos= t page > tables. I'm sure it's a solvable problem, e.g. by ensuring at least o= ne page > is touched by the backing store, but I don't think the end result would= be any > prettier than a dedicated API for KVM to consume. >=20 > Relying on VMAs, and thus the mmu_notifiers, also doesn't provide line = of sight > to page migration or swap. For those types of operations, KVM currentl= y just > reacts to invalidation notifications by zapping guest PTEs, and then ge= ts the > new pfn when the guest re-faults on the page. That sequence doesn't wo= rk for > TDX or SEV-SNP because the trusteday agent needs to do the memcpy() of = the page > contents, i.e. the host needs to call into KVM for the actual migration= . Right, but I still think this is a kernel internal. You can do such=20 handshake later in the kernel IMHO. But I also already thought: is it really KVM that is to perform the=20 migration or is it the fd-provider that performs the migration? Who says=20 memfd_encrypted() doesn't default to a TDX "backend" on Intel CPUs that=20 just knows how to migrate such a page? I'd love to have some details on how that's supposed to work, and which=20 information we'd need to migrate/swap/... in addition to the EPFN and a=20 new SPFN. >=20 > There's also the memory footprint side of things; the fd-based approach= avoids > having to create host page tables for memory that by definition will ne= ver be > used by the host. While that is true, that is not a compelling argument IMHO. No need to=20 try to be better than state of the art if it results in something=20 cleaner/better* just sticking with state of the art. Just like we don't=20 have special interfaces to map $WHATEVER into a guest and bypassing user=20 space page tables. * to be shown what actually is cleaner/better. We don't really have=20 prototypes for either. --=20 Thanks, David / dhildenb