Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3050367pxb; Mon, 4 Apr 2022 06:42:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrAPHi0OTx/XdbWbffIRY9jNU0NwyxfDuhTcvJu/16wQ2pxYZ9mSECxaSTOKytcTmySdSU X-Received: by 2002:a17:90b:1c02:b0:1c8:da30:5ed7 with SMTP id oc2-20020a17090b1c0200b001c8da305ed7mr26578085pjb.28.1649079733437; Mon, 04 Apr 2022 06:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649079733; cv=none; d=google.com; s=arc-20160816; b=V5hsQpp94nQcgMs4RpwaIi/zYGoVNP5HGjYuNDR8lpoexGf7aO7tMlUJyk8MAbl/f/ +Wr8tLRXS6No6RqBH6xINuTZxIrwbDn5L4WvmiG/7UW0erh7RyiHBjmp+6lCxrelG1RS /O6QtTnxNn2+XwzDoNYA5/GyXJuBH1dHwfnRP0rVETozLe6DENgyCGhjEte7Bgm/0CtY 0y9lPIczDfhE5w72BwfmHEezabiGwNud17UjpA/m9gw2sbf4Zy0PjQlrvMD65cqnadcj VQmC8m+2U5MQh4KmXvckAKpLaukUUGw7pcbELT14MbnLDs7XEk5slWA7Fyuqi+MUMJfI LPCQ== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=lhxxWKT9SwwnWJkm39OZn7IwwCKXG3b/O/9dQouxNPo=; b=H38VM2GiZCodCOMak6CL4QyLCBuEPf1sFzJTGcbY6Rm8MceIymTnKxVrqCfb4DM+Yn V0Qgr2ln2uV2t15AfbpQ6fm5dB6UTFqkJLjPMZiPZvyaZiZy5KkxbmwdjMDn5ajFBeDn 7CF0y7u3tU9SbhMrKNyBuqif/v6L8F9vz2lAr4dkKQ2YsO61j0Jmb6fS3ALP3ecRkmDE aZcqowsQlTZnVEvM+4Asm3PfflZK8+XNs9dATjvPTOfMYqCPCrOApjR5FEifvXVCNOpS NmTPJzulj+0ViOvUrkDyR5GGSsp7uhZLp/FGkLX5lBe5e3fi4YEe0JeBczDUcuiOMdyN Yokg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Lr8A3p7E; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a170903024700b00153bb806739si10390765plh.478.2022.04.04.06.41.57; Mon, 04 Apr 2022 06:42:13 -0700 (PDT) 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=@google.com header.s=20210112 header.b=Lr8A3p7E; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350526AbiDASFU (ORCPT + 99 others); Fri, 1 Apr 2022 14:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348299AbiDASFP (ORCPT ); Fri, 1 Apr 2022 14:05:15 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72ED06A06C for ; Fri, 1 Apr 2022 11:03:22 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id g22so3864706edz.2 for ; Fri, 01 Apr 2022 11:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lhxxWKT9SwwnWJkm39OZn7IwwCKXG3b/O/9dQouxNPo=; b=Lr8A3p7Ekj/xeqHFv/FPraXvj8lmfHwD95Tyh0wBLtHKMerFISovW3cP911Cv1OBMv LV/OgGxHqX6rFmQDgLqdILULRzc7+aWuNiPU+Sk8Vtloe5edefA/RKnzKDbH1r5KuBbZ kev1t4QLJXESZh3mGGAntIMgi47syaHwmLXLjV4jdlQobqziGAHtJIA2WFfzfe5cFIjV fqcPM0a1TZGP94MxJrnUfa3F6LyGzWdGmQaH2OoT4mLR0RmukUXT9LXwNpTFQKZVcRf/ aIWCTNM3KQyU809xH2hE5O+R6+Ekag5oYXwycP+wVr1LXAKbwyLENB8lf5HV4rz1dgco C/kQ== 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=lhxxWKT9SwwnWJkm39OZn7IwwCKXG3b/O/9dQouxNPo=; b=IBSE/Os5g8V/l0ADng83K3HWMeNwegwLCq+TdoVs//mpJVh/MgFW3m34/TL5M0IzF7 XrnHgwKYuIoJf2onZJxXei/ZsA2xTXBY0QZrkbpd6zyF5u1/p0Ldyc6Fd/Z/GvwHRg6Y kDTNC6Uce7O1YjjDubS/9jMJcqnEmMvGONzQAD98OwLKY02a6FcADOXIuLrCZh/6W2bv AE2a0fFMSLf4FB7QfX68QNdiJS20bd79yob9xQeV5AUSuFfeghKycbrQ6UyKbgXCYTZC hzdb0uh/pOUwlbhIz6p9OcbN2XqrXeNJLBZkz+Z8VPeESTrfh5xph4TjDmYxM2OfgZ39 NIzA== X-Gm-Message-State: AOAM531msnDKA3DHugFGPHzznnkAqNdWW4X1k7EYFEJcazH/NAHk/+6Y CgJ7xQuNLO1M3xE1FMgqCsnDSw== X-Received: by 2002:a05:6402:438d:b0:419:4550:d52b with SMTP id o13-20020a056402438d00b004194550d52bmr22227721edc.83.1648836200464; Fri, 01 Apr 2022 11:03:20 -0700 (PDT) Received: from google.com (30.171.91.34.bc.googleusercontent.com. [34.91.171.30]) by smtp.gmail.com with ESMTPSA id w14-20020a170906d20e00b006cee22553f7sm1261239ejz.213.2022.04.01.11.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 11:03:20 -0700 (PDT) Date: Fri, 1 Apr 2022 18:03:16 +0000 From: Quentin Perret To: Sean Christopherson Cc: Andy Lutomirski , Steven Price , Chao Peng , kvm list , Linux Kernel Mailing List , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Linux API , qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , 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 , Mike Rapoport , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A. Shutemov" , "Nakajima, Jun" , Dave Hansen , Andi Kleen , David Hildenbrand , Marc Zyngier , Will Deacon Subject: Re: [PATCH v5 00/13] KVM: mm: fd-based approach for supporting KVM guest private memory Message-ID: References: <88620519-029e-342b-0a85-ce2a20eaf41b@arm.com> <80aad2f9-9612-4e87-a27a-755d3fa97c92@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Friday 01 Apr 2022 at 17:14:21 (+0000), Sean Christopherson wrote: > On Fri, Apr 01, 2022, Quentin Perret wrote: > > The typical flow is as follows: > > > > - the host asks the hypervisor to run a guest; > > > > - the hypervisor does the context switch, which includes switching > > stage-2 page-tables; > > > > - initially the guest has an empty stage-2 (we don't require > > pre-faulting everything), which means it'll immediately fault; > > > > - the hypervisor switches back to host context to handle the guest > > fault; > > > > - the host handler finds the corresponding memslot and does the > > ipa->hva conversion. In our current implementation it uses a longterm > > GUP pin on the corresponding page; > > > > - once it has a page, the host handler issues a hypercall to donate the > > page to the guest; > > > > - the hypervisor does a bunch of checks to make sure the host owns the > > page, and if all is fine it will unmap it from the host stage-2 and > > map it in the guest stage-2, and do some bookkeeping as it needs to > > track page ownership, etc; > > > > - the guest can then proceed to run, and possibly faults in many more > > pages; > > > > - when it wants to, the guest can then issue a hypercall to share a > > page back with the host; > > > > - the hypervisor checks the request, maps the page back in the host > > stage-2, does more bookkeeping and returns back to the host to notify > > it of the share; > > > > - the host kernel at that point can exit back to userspace to relay > > that information to the VMM; > > > > - rinse and repeat. > > I assume there is a scenario where a page can be converted from shared=>private? > If so, is there a use case where that happens post-boot _and_ the contents of the > page are preserved? I think most our use-cases are private=>shared, but how is that different? > > We currently don't allow the host punching holes in the guest IPA space. > > The hole doesn't get punched in guest IPA space, it gets punched in the private > backing store, which is host PA space. Hmm, in a previous message I thought that you mentioned when a whole gets punched in the fd KVM will go and unmap the page in the private SPTEs, which will cause a fatal error for any subsequent access from the guest to the corresponding IPA? If that's correct, I meant that we currently don't support that - the host can't unmap anything from the guest stage-2, it can only tear it down entirely. But again, I'm not too worried about that, we could certainly implement that part without too many issues. > > Once it has donated a page to a guest, it can't have it back until the > > guest has been entirely torn down (at which point all of memory is > > poisoned by the hypervisor obviously). > > The guest doesn't have to know that it was handed back a different page. It will > require defining the semantics to state that the trusted hypervisor will clear > that page on conversion, but IMO the trusted hypervisor should be doing that > anyways. IMO, forcing on the guest to correctly zero pages on conversion is > unnecessarily risky because converting private=>shared and preserving the contents > should be a very, very rare scenario, i.e. it's just one more thing for the guest > to get wrong. I'm not sure I agree. The guest is going to communicate with an untrusted entity via that shared page, so it better be careful. Guest hardening in general is a major topic, and of all problems, zeroing the page before sharing is probably one of the simplest to solve. Also, note that in pKVM all the hypervisor code at EL2 runs with preemption disabled, which is a strict constraint. As such one of the main goals is the spend as little time as possible in that context. We're trying hard to keep the amount of zeroing/memcpy-ing to an absolute minimum. And that's especially true as we introduce support for huge pages. So, we'll take every opportunity we get to have the guest or the host do that work.