Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1146406rwb; Fri, 7 Oct 2022 08:41:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MDV5+A25OpVa8oz78Bdn9JeqtidyAtWyA6RVv+KfTpAdA0AH7mGrFhUmz87l3Ljoo2KNq X-Received: by 2002:a17:906:dc8b:b0:787:8f41:d231 with SMTP id cs11-20020a170906dc8b00b007878f41d231mr4630252ejc.547.1665157264312; Fri, 07 Oct 2022 08:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665157264; cv=none; d=google.com; s=arc-20160816; b=ChSW0FMfOMlVkQJRonuRoYGCsIFSM45UcAWjX6Zww3qsgEPjxSnbBglw+Q40HO2Ccx FEQFkmX9DiXw0ZfrJrBXIvLquWSf8918JiuX7Elzm9lipj6VdcRjtVUIxpY4z7t+MqSK UAhoYQesWerY0T4VE8kBPmTaijrsGG8lnLVet+Ntr8UiAJicr9FBszkmaY8bmorCySK2 sVZ9LyLk5kyhF5ar05deZ98tfa60eqxl2dF4XP/EBhNFvVYRohYK16xmuElzch6WKzOk LT+v8nV9d7UfBkHcDCoa6tfW7Iqheut+p15O2n0ibBh6gC6DKH6z/O3mtenb+ZyLwC1m +61w== 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=ApS1gjiguDXZcZz0fMT7VsMAGGvTEXNN7etXS65aF2E=; b=bx4GVHjlrP4yNHEoa36f2D7W9crRb4DTeyNC6QgGyeXrZZWiOtxGtVPEDcpAhLR2HD P26fNSquCIacYo2tACc7elRDy/a2PjuC66kwfTUzJGGq4PUSJ/5QuQW646XOlQKKynd4 wfYHISMRY4g/3uyGwfcIvFHFa6rueOOf19JVyOTwajF+SNzQcib1teL+rdVkJf/HsLAy 0tZox24iZLUToZ5AhZifDcfTquBlRty5vtH8SbGHfB/Kc6KhibjLgQkRiQocr/ggrsnk r+jz7+aoBePQQpk4Wq+ZqHusKtyEZjZyBCa/RxEn6Qn/gsJXOgctNAswlGUnbkf5CWVa /Rrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=P9at1gy0; 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 c24-20020aa7c758000000b0045a0e39062esi2278408eds.76.2022.10.07.08.40.38; Fri, 07 Oct 2022 08:41:04 -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=P9at1gy0; 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 S229894AbiJGO7X (ORCPT + 99 others); Fri, 7 Oct 2022 10:59:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbiJGO7D (ORCPT ); Fri, 7 Oct 2022 10:59:03 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BAD8DD8B2 for ; Fri, 7 Oct 2022 07:58:59 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id gf8so4618458pjb.5 for ; Fri, 07 Oct 2022 07:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ApS1gjiguDXZcZz0fMT7VsMAGGvTEXNN7etXS65aF2E=; b=P9at1gy00LaQ67U9E1PqFxXj/+/Ep5lZ2MxNKcytXi47pMqLiyWzEa/Xe2j6FHWM4y /hs7KujqnFNPAE3jZS5MWMfe3+xQAhIhJuW1dyoA1ekhjNaxULNBuqb/2klgeUPGWkYF 5S5WGPJDOLGI8G3dhBrFVznCIwrT7f7u07MoT7kQCn0HddgT1cP9+6D1aAApMjbGxIQJ KQ5lGGS71MMnAnQJ7FClUslBS7YWByNlLuUfhv2PRp7+0dcRnApGUnnJxK061ld3oLrF aqw3+neqPNcUW0v6HArS65p+1L4Mc4p5Eyi3bOlG00rA6Ll3S9qG/ECPlhkMQusT3cha xF/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ApS1gjiguDXZcZz0fMT7VsMAGGvTEXNN7etXS65aF2E=; b=Bb//JkaBHW5ew2coVisc3tkPk6dPTc5eNqYEgVsTts9MXX+eVcBR3QoyN/DnTrjdeH cggKT8154eG7K29msm629o0u10RzBk1oaMS/OlXNFKRlXX7o0vbCqcnJqD5KSwKHF2vP NY6X8RtBIlF7zQvduIM1DcPkeKawZMVSFdABFvPfwjl9nIdggVQLgKB2dkUIVrW5EbMA QgcmQ3kP7rReg9ebJVN2ZFLugpCb8Qoh6A53vLHGriHzI8F0IGW5pLJK9yqTRSQ8Zu9U 1+WcltWcAexeYutcBemsoyNlKVCBz9icX0ft3GbmqXHiZALkzVK9bm6nDOMw3W5t/sOk F82Q== X-Gm-Message-State: ACrzQf0EksB7yvxxOhMyO6UepmlLOGywnV9B3QblycOmdaCPD2ke9Pag CoHPZwkH9+hdAaXFsLwJNAXIqA== X-Received: by 2002:a17:90b:3ec1:b0:202:f490:e508 with SMTP id rm1-20020a17090b3ec100b00202f490e508mr5980841pjb.156.1665154738493; Fri, 07 Oct 2022 07:58:58 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id m22-20020a63ed56000000b0043a0de69c94sm1750587pgk.14.2022.10.07.07.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 07:58:57 -0700 (PDT) Date: Fri, 7 Oct 2022 14:58:54 +0000 From: Sean Christopherson To: Jarkko Sakkinen Cc: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Subject: Re: [PATCH v8 2/8] KVM: Extend the memslot to support fd-based private memory Message-ID: References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-3-chao.p.peng@linux.intel.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, 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 Fri, Oct 07, 2022, Jarkko Sakkinen wrote: > On Thu, Oct 06, 2022 at 03:34:58PM +0000, Sean Christopherson wrote: > > On Thu, Oct 06, 2022, Jarkko Sakkinen wrote: > > > On Thu, Oct 06, 2022 at 05:58:03PM +0300, Jarkko Sakkinen wrote: > > > > On Thu, Sep 15, 2022 at 10:29:07PM +0800, Chao Peng wrote: > > > > > This new extension, indicated by the new flag KVM_MEM_PRIVATE, adds two > > > > > additional KVM memslot fields private_fd/private_offset to allow > > > > > userspace to specify that guest private memory provided from the > > > > > private_fd and guest_phys_addr mapped at the private_offset of the > > > > > private_fd, spanning a range of memory_size. > > > > > > > > > > The extended memslot can still have the userspace_addr(hva). When use, a > > > > > single memslot can maintain both private memory through private > > > > > fd(private_fd/private_offset) and shared memory through > > > > > hva(userspace_addr). Whether the private or shared part is visible to > > > > > guest is maintained by other KVM code. > > > > > > > > What is anyway the appeal of private_offset field, instead of having just > > > > 1:1 association between regions and files, i.e. one memfd per region? > > > > Modifying memslots is slow, both in KVM and in QEMU (not sure about Google's VMM). > > E.g. if a vCPU converts a single page, it will be forced to wait until all other > > vCPUs drop SRCU, which can have severe latency spikes, e.g. if KVM is faulting in > > memory. KVM's memslot updates also hold a mutex for the entire duration of the > > update, i.e. conversions on different vCPUs would be fully serialized, exacerbating > > the SRCU problem. > > > > KVM also has historical baggage where it "needs" to zap _all_ SPTEs when any > > memslot is deleted. > > > > Taking both a private_fd and a shared userspace address allows userspace to convert > > between private and shared without having to manipulate memslots. > > Right, this was really good explanation, thank you. > > Still wondering could this possibly work (or not): > > 1. Union userspace_addr and private_fd. No, because userspace needs to be able to provide both userspace_addr (shared memory) and private_fd (private memory) for a single memslot. > 2. Instead of introducing private_offset, use guest_phys_addr as the > offset. No, because that would force userspace to use a single private_fd for all of guest memory since it effectively means private_offset=0. And userspace couldn't skip over holes in guest memory, i.e. the size of the memfd would need to follow the max guest gpa. In other words, dropping private_offset could work, but it'd be quite kludgy and not worth saving 8 bytes.