Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp788003rwb; Fri, 7 Oct 2022 04:18:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM584YMXgvWYLRRgsPv9yAnq4jXPoh91MePzQFQjJYSa4nUcCv+DLBySuQ0hJsY5ci+uUF3N X-Received: by 2002:a63:525a:0:b0:42b:28a9:8a34 with SMTP id s26-20020a63525a000000b0042b28a98a34mr3971447pgl.269.1665141533977; Fri, 07 Oct 2022 04:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665141533; cv=none; d=google.com; s=arc-20160816; b=YNlCkfNeutSSlI9m32Yij65GK3lJWl40oTOpgqMNs6T42vIV2hjxFQo4dJ/UGjcn63 xBW1HUXjBqTj1LQ4OucDl9OPh01Y8t0OMk9lFXo5dersVnkDBB7MxXhEI9eN25o4uPdJ dTXONv4QUqij6SsbDCgX+d2JwiMptbvlISJEDKCmzcAYVMYn5jtItHSrBAqrWJGNOsgo nDDKtOBQrq444jH7EwFJKcrBUWJ7agwn/3VDUEphktZEw81bUiklavpxIY3LE3Sk3E7j JIO0KVm36Z86fDUGval4S6s+i3jdTamFZJcfN33YXRqhgosysghVDE8mjALgvBtiuntC +cng== 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=ylMaT+d6tmjinoUS+YA33dc3XWHNX1i4tTYbatTBtk8=; b=LeAZfxZxtdp+7wYDaGVPK8FMKultjYE6OK0pSFmW0A6P9nLfwBt82+B0fmmQU3t8nK 2gZ0UPxyHBZCwSJuuONfioqO8PpqDwCADUawy2OapWE4o2GF2xGT/1ME14KibwoXEnWE Kk3f7o0b2tnKDC1hlNIp6bTwicS10NPDuL9yINFQrfnaC6kBnRRQmjcDsgHgUsmi8wOC 0fCgi5+iSEQGUw3fPkVBunceLXm6aqZIN91Qdlj92gN1Ya+szZvwfsfM7WnTF31oDvpl OdZMCWpqI2S64YTvyFe0yy4qKtGNy3lxdCCM5r3MG9Xf7gR8xmC39TLGpBXEG9TV7R1A RRYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fmKEzZfv; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w15-20020a17090a15cf00b00200919a55b1si7596615pjd.180.2022.10.07.04.18.41; Fri, 07 Oct 2022 04:18:53 -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=@kernel.org header.s=k20201202 header.b=fmKEzZfv; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbiJGLOM (ORCPT + 99 others); Fri, 7 Oct 2022 07:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbiJGLOK (ORCPT ); Fri, 7 Oct 2022 07:14:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1519A223C; Fri, 7 Oct 2022 04:14:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8372961C4E; Fri, 7 Oct 2022 11:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FF19C433C1; Fri, 7 Oct 2022 11:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665141248; bh=iGUUEynvCAjegBrsy6JU4OD39853Ax+NThhfisNR9Vo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fmKEzZfv+NcFm5KZPC8vC7ZMGO+4smagpqxidG4f8sTZ/z8q2aoMCJSNtysPorB+u kk9P97XlyfQbbtnFo8LHPNJFX9dz+rglzxIJfihqhOEfRZ95SMPj67dZ/fvnuNbSqC jqfHkAdl/kZOqmVgzI+rs0S1M/uPV1KhYkYw7RvKkChyMhuiR2/2wEETdeyyy8vdL+ xSn8DoYpH/zTYYkmMvP9NOyVC0t2HvDfp9uL80OcPykiAatvUGYg8ebg5q6VkchIVf DXvK7t9XwhCTk3XnR5NXjkt3/qkelWVMPuwnPC3EPAwGRYke53ktd+UBomw4T2mbx6 O0+yu62YgKnxg== Date: Fri, 7 Oct 2022 14:14:03 +0300 From: Jarkko Sakkinen To: Sean Christopherson 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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 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. 2. Instead of introducing private_offset, use guest_phys_addr as the offset. BR, Jarkko