Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1088819rwb; Thu, 6 Oct 2022 08:18:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Wf4KutrEx1eohruFL1525yCYY2USo1g8qgOElWH4gyK+T1n8sFN6b971akxLuBBoVZKVH X-Received: by 2002:a05:6402:3221:b0:459:61c3:eea0 with SMTP id g33-20020a056402322100b0045961c3eea0mr249302eda.225.1665069536827; Thu, 06 Oct 2022 08:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665069536; cv=none; d=google.com; s=arc-20160816; b=AP0lleeBjJ3PeQFihbwDZWrIvvAs0nCV5okJduoMwP8m78TISRFcuzR8DDN+Jhj8d5 0784z72gx9Y9MMPDzBodhHdV/LKGIexLMJ7dh5Q5dbb466uOIBLLbGYZ2Q1mkH+2iXKt KghtKCJ7/sRHr+jDbW365Bcve+ATOQTwQsTLBjGPMZAwtMwFoDp74xvMQ2JswFzk4Lqn SlmgEIPVr0yJaHjlTXh1zVi0paRb7OIodhNRI/k6GaBkBaWDRSskNnvHt1dg/nz2eypd I0r9Ri3nJUkAsKEsQ/m2TBWwmL+A+0/gqPzg2QyO9qCBr+tyJnDU6IjVzVTG4vvK1bbh ydNg== 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=FN1hS+Pq0UrG6SAfV8+9rjVAz5w2MtqpsI0JDrcKQn0=; b=WjIko+pmrDOaWr/hx4/uI4kBz/ddrFqbNAOsOFvWgyK1hMPSiGVB9KMzUm86i570jS 5vcw9dvuajUsO6DAHO5ov68hLDw3mEl3BD5U/xyfDf9VKl+DJakOFIF2VEbybhoTenQj 7SZPPqhniAoJCpDnkGRJqpGGbmdrq4B8aPgV8iQzakiFaNdffljpCEmKFdLm9t4IcZo5 W0qPXoTW2iKapBL/pjyLUNzVlqI4NfZgk3jUFa4Z8F3qnaRDjiB4glL+hGR/y2CKFAqu qaETKCJOBBoYGbEfd5wJQbD4rRYzQIn8JZCT2MvScONcSrR5EfWhIl19c+XxdrbspfCe fgKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ipL5LglS; 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 e5-20020a17090658c500b0077afe48c791si20013929ejs.538.2022.10.06.08.18.29; Thu, 06 Oct 2022 08:18:56 -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=ipL5LglS; 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 S231810AbiJFPHS (ORCPT + 99 others); Thu, 6 Oct 2022 11:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbiJFPHQ (ORCPT ); Thu, 6 Oct 2022 11:07:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE3B88DFB; Thu, 6 Oct 2022 08:07:15 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2CA4CB820D6; Thu, 6 Oct 2022 15:07:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FB2EC433D6; Thu, 6 Oct 2022 15:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665068832; bh=aOkXuECcbSjQISc+01I1tvXXXenJbSlH28e8M1BvI94=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ipL5LglSgB96d6J8L2HRVMl+jXPn9WaZCDeQ01bYQBl4fNvQ1dM3lsq4Q1rZT43/e 04qttZa16SWURI2GfkK0oPR51suEX+KmL9EsCjFdWia96LnfzBWvtuqNVtpUW3BtJU vcNgsuDIFvSsLikBs88sxH/LdhpbfjE4y6loO4Mu7LZwOPT9sRBT/8sLT04H22RAal QWzkjxZVHXql+4CQTc3Zt3ML52Z7jwbzo3dBaWVQ7tNHxkNILSrzI4WPmGEaVVk6pI qS7RDP6QwQGatrjUNvs0hohnNuzTtFZ1Mq8tk9g2NPUW0j9qCUC4fQjJGqzWtnoJZi NyQ6cXDs2lPnw== Date: Thu, 6 Oct 2022 18:07:09 +0300 From: Jarkko Sakkinen To: Chao Peng Cc: 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 , Sean Christopherson , 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 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? > > If this was the case, then an extended struct would not be needed in the > first place. A simple union inside the existing struct would do: > > union { > __u64 userspace_addr, > __u64 private_fd, > }; Also, why is this mechanism just for fd's with MFD_INACCESSIBLE flag? I'd consider instead having KVM_MEM_FD flag. For generic KVM (if memfd does not have MFD_INACCESSIBLE set), KVM could just use the memory as it is using mapped memory. This would simplify user space code, as you can the use the same thing for both cases. BR, Jarkko