Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1088429pxb; Wed, 6 Apr 2022 08:26:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs870LawKOqIK5wWDfIy2SSCqR3Q80hJLBH93IpOxjQf+4JUd54zZ9QUJh3Esf0LZWYORu X-Received: by 2002:a63:f047:0:b0:399:24bb:7fa1 with SMTP id s7-20020a63f047000000b0039924bb7fa1mr7396275pgj.397.1649258796653; Wed, 06 Apr 2022 08:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649258796; cv=none; d=google.com; s=arc-20160816; b=d8LYPjqErVGQwyt2aHt7+dSyHmlmbjtxoVzZ+hLQUyu+b04P9vVlGHnVjc/DK+tq02 5+4tYhPA25JjlrutXf8qJJED6qjVlvC2pFEjgfUAyQ/MqwuJx6RHIez20V9xNNXylnOt ByWrneERFhZ2Fwp73BnsEfwNpOjDUEQVkbwGTISJ0Ys9eGRcPwDPGl31KIvCW0jeNs5b cvg8GTk6q/w9VWdsjtIRSEfRqWlfDxTehUX9s5ryqbs2YGotJl8Oasm1VlYE4hGBYsir o/9Ju8xKTZSf83nPvQ4rQRnBAlN9cEFHK5ddcNWFCCvsQr1sl4rIYORgRjpNjK4OoI6N Sy0w== 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=iTXPlXz9Zr5EQou03o/EzBtB8wT2GGE1Oxj4KHnssrs=; b=IFcfl4fPQ116fvdZYTLjq1fa/bw4pz8oLg9Y3xmJfDbd4SIWIuA1OLZyYnMw4BF4oY SCMElNlAtiHgaQybdXsqocsXHW2KsqhOLRbebLBMoU2siE7UwwwktEN3YFaEEsIr1l/s x1uXgeg8vitRrRxz+BmmwSVbhbKr/JzBDJy8j2XX4sCoJF9fyf3oI8OnYcnwNmfvPsU3 JraSn7ywBPRXdjzoIOcWL/jLZwAQCs1rWPM+o5xFICjUHLsDEDjMlPsq18Plf1Kh6LvR LhjmYF/T+4In+ez2suGQsaGheNpD3AsmYWty+T6pZ7HrHOxINsRjzdmbe6Y3z22MoCzM F35g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ayqp+jO7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y1-20020a63ad41000000b0039822e42cbasi16035642pgo.427.2022.04.06.08.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 08:26:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ayqp+jO7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 81B55D0A97; Wed, 6 Apr 2022 06:32:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233461AbiDFNeb (ORCPT + 99 others); Wed, 6 Apr 2022 09:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233456AbiDFNeL (ORCPT ); Wed, 6 Apr 2022 09:34:11 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015B84B63E1 for ; Wed, 6 Apr 2022 03:34:24 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id ot30so3258381ejb.12 for ; Wed, 06 Apr 2022 03:34:24 -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=iTXPlXz9Zr5EQou03o/EzBtB8wT2GGE1Oxj4KHnssrs=; b=ayqp+jO7yOZ05GUhmKmLMJU9illW53IQuWYj97Bq0h7OEyqmw3078v9FFmpHAsDAsX spKmsJURhryre2eQUlppZX9/HUMI+W6eoOizaX7iehhukxIce2QAtRFltzvot97mqi5g wkzLHd/GXAJerFP3q1x2xzOele+vfbjGw1VTYhqxLnyW66oK1u7wRDE72iuiN53gsanI rXtjHuLiferpfP6GaXR+e/2+55LTuT8kg2k0SD2i6I/8Spe3SQIHjv+mc1I1GC7cM2Bn lfPpqaubm9GgEOe61Moi+rdCo7ZOQ3yLidHpWgZcNsZorkDZClOB35C15vOMByW5gWia Ohgw== 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=iTXPlXz9Zr5EQou03o/EzBtB8wT2GGE1Oxj4KHnssrs=; b=t+DdmCk+IRE2nI7zX0ArzPCwSZA3oc/SeFaUSzrmsKPxB/7F3KS2g4MWnJ/Q03gGCx pRXqOZ+k9KK2qxF9u2V325BetyTL2eZgTdB/RPBucfNdCOychA9R9EE+kS1NiL7VbX6B fokt2AuD/6sA8NDRPjCp/vEinLyj6NDWh0/7qSVY+YYzxlMZMfngZ2hXZkukheO/3gam maTwXkDNQeu2izuX3hjKHAT0Y1lT8KOa8dJY8S6r0NihD81tJwwGuqplGCOnpJhG7igq oyrMZF0LhE8Dqaeu7i8kdt7G7HKEzgcAGSloIkKAppi7VM3pX5XyHsktQvmHRGaNsfV7 or6Q== X-Gm-Message-State: AOAM530d+AacRA8aKlgUajXKBiUnymg5ZOtSwuZq1iQrL4winHAwJR7n Rd1zy4p+XQU8BqRs539sucylnQ== X-Received: by 2002:a17:907:3f02:b0:6e7:7172:4437 with SMTP id hq2-20020a1709073f0200b006e771724437mr7358942ejc.361.1649241258989; Wed, 06 Apr 2022 03:34:18 -0700 (PDT) Received: from google.com (30.171.91.34.bc.googleusercontent.com. [34.91.171.30]) by smtp.gmail.com with ESMTPSA id x3-20020a50d9c3000000b0041c8ce4bcd7sm6543091edj.63.2022.04.06.03.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 03:34:18 -0700 (PDT) Date: Wed, 6 Apr 2022 10:34:15 +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: <80aad2f9-9612-4e87-a27a-755d3fa97c92@www.fastmail.com> <83fd55f8-cd42-4588-9bf6-199cbce70f33@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=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Tuesday 05 Apr 2022 at 18:03:21 (+0000), Sean Christopherson wrote: > On Tue, Apr 05, 2022, Quentin Perret wrote: > > On Monday 04 Apr 2022 at 15:04:17 (-0700), Andy Lutomirski wrote: > > > >> - it can be very useful for protected VMs to do shared=>private > > > >> conversions. Think of a VM receiving some data from the host in a > > > >> shared buffer, and then it wants to operate on that buffer without > > > >> risking to leak confidential informations in a transient state. In > > > >> that case the most logical thing to do is to convert the buffer back > > > >> to private, do whatever needs to be done on that buffer (decrypting a > > > >> frame, ...), and then share it back with the host to consume it; > > > > > > > > If performance is a motivation, why would the guest want to do two > > > > conversions instead of just doing internal memcpy() to/from a private > > > > page? I would be quite surprised if multiple exits and TLB shootdowns is > > > > actually faster, especially at any kind of scale where zapping stage-2 > > > > PTEs will cause lock contention and IPIs. > > > > > > I don't know the numbers or all the details, but this is arm64, which is a > > > rather better architecture than x86 in this regard. So maybe it's not so > > > bad, at least in very simple cases, ignoring all implementation details. > > > (But see below.) Also the systems in question tend to have fewer CPUs than > > > some of the massive x86 systems out there. > > > > Yep. I can try and do some measurements if that's really necessary, but > > I'm really convinced the cost of the TLBI for the shared->private > > conversion is going to be significantly smaller than the cost of memcpy > > the buffer twice in the guest for us. > > It's not just the TLB shootdown, the VM-Exits aren't free. Ack, but we can at least work on the rest (number of exits, locking, ...). The cost of the memcpy and the TLBI are really incompressible. > And barring non-trivial > improvements to KVM's MMU, e.g. sharding of mmu_lock, modifying the page tables will > block all other updates and MMU operations. Taking mmu_lock for read, should arm64 > ever convert to a rwlock, is not an option because KVM needs to block other > conversions to avoid races. FWIW the host mmu_lock isn't all that useful for pKVM. The host doesn't have _any_ control over guest page-tables, and the hypervisor can't safely rely on the host for locking, so we have hypervisor-level synchronization. > Hmm, though batching multiple pages into a single request would mitigate most of > the overhead. Yep, there are a few tricks we can play to make this fairly efficient in the most common cases. And fine-grain locking at EL2 is really high up on the todo list :-) Thanks, Quentin