Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1922272rwn; Fri, 16 Sep 2022 03:00:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6omUBUhXwwliNXfGuWLZvIZic2nKfQD/hx6YS4quKocNUVeGt62ZJAMP6nxIemMpikEWiv X-Received: by 2002:a63:2a57:0:b0:439:42f4:97e1 with SMTP id q84-20020a632a57000000b0043942f497e1mr3858442pgq.190.1663322436892; Fri, 16 Sep 2022 03:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663322436; cv=none; d=google.com; s=arc-20160816; b=yWvaUNFaRs6r0msuBuVnzMyPk3JiQuNEUYkC5k+vSCY0ngk3KkoGSYSeuQaQncEAFy mJZLNgEabb7qBaFN7t480CFtZ3sGuXDPi737BHK22EbySsBYAUIFU9GS4u8j2t3QUX8Q Co5ISVMSDyDYB3yof9v/Meqykw0GJInijRCEVjLcYTyA6ouv5BsdE48wy4wiUqTiDCKO kq3h5uM8Z/xz46lzPmiW+6cTUPRetoO6bphd8GGfTFTUKi/+QjaQxY//DTodEYvSp5Bd /ZMUBB3ix2HVNpcpbcLEyDomsrwscbS/L+Cnex2oON3nKTPUqjnVumk5HPh0EGoHdSf0 M6dg== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Cs3Dt4YgF9StsuVRQMfJm+HsbymSqoiRiE/3DLxYi6Y=; b=yzH0JoVbChl43K4gMEkM/Qx+buZ5UsLFC5zv2ISOuTs3h/bb28AxkTW5c16i5Dfdld 68J0eKCVRJrV17irIfOOGcZE8VTBF1Pkdqh/jZKehWtJKQ9pSbtfeYzBI8yZD+rtsqDA 3osqTp3KJtSDzYNmfEU+HVPIjeB9XmHnJzxsb4VpC2BtGHHNZCXa1CpzYLiipY+1+44q rB5BjMwORz84bW7yid79B2mA9FbHt0qxaND5g6sZymU//5xFV5aIHxoQl0PvBfkvvF4w 1MZilhTvzaKsxTQjA0bvokCVruDGjBPm+2gXfezOGTBDgOUjqUJKQDx6ASN7M6Oonv6y +rpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hK7Z2muP; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a23-20020a63d417000000b0042bc2bd5797si21888199pgh.278.2022.09.16.03.00.24; Fri, 16 Sep 2022 03:00:36 -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=@intel.com header.s=Intel header.b=hK7Z2muP; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbiIPJ6n (ORCPT + 99 others); Fri, 16 Sep 2022 05:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbiIPJ6d (ORCPT ); Fri, 16 Sep 2022 05:58:33 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D1E8AA4DF; Fri, 16 Sep 2022 02:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663322311; x=1694858311; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=12OZBcnGODAmYZ+AQhyX6U0d1a9s5HIpAjq3AWPtWJs=; b=hK7Z2muPoe51t+mAtm3DCPxAFrwHkUH4KdVddLvWyC5NdgoSi7SJwMAm 7QXpD1QkARfIZ8SBmQ27HRCShf8Iflxv6Q/7/5dad5GaXbZR6W+ojV8F1 aWGG3mBJ9KH8/8Eb2e3cecxO76Px9lQUkvwrPchRKOGpzcu5rjpZ/oG4X jPRBQ+0d+ZNec65VmYnU6KvNtpUI0tMjcyUnEPT0wjaFxM9YYQM0vF1xB c8rZ9NXL+FxLcDFfLvxQNbD8yk1KYTQNeUNrXNCgS8FzfynSdyfh2ymfj brlycSVwwLc7dJ7biIByg8EJoBkCSN/AL/yTWn6hnbvP6EUePyPFmaeNU A==; X-IronPort-AV: E=McAfee;i="6500,9779,10471"; a="298950578" X-IronPort-AV: E=Sophos;i="5.93,320,1654585200"; d="scan'208";a="298950578" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2022 02:58:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,320,1654585200"; d="scan'208";a="620036603" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga007.fm.intel.com with ESMTP; 16 Sep 2022 02:58:21 -0700 Date: Fri, 16 Sep 2022 17:53:42 +0800 From: Chao Peng To: Bagas Sanjaya 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: <20220916095342.GA2261402@chaop.bj.intel.com> Reply-To: Chao Peng 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.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE 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 Fri, Sep 16, 2022 at 04:14:29PM +0700, Bagas Sanjaya wrote: > On Thu, Sep 15, 2022 at 10:29:07PM +0800, Chao Peng wrote: > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index abd7c32126ce..c1fac1e9f820 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -1319,7 +1319,7 @@ yet and must be cleared on entry. > > :Capability: KVM_CAP_USER_MEMORY > > :Architectures: all > > :Type: vm ioctl > > -:Parameters: struct kvm_userspace_memory_region (in) > > +:Parameters: struct kvm_userspace_memory_region(_ext) (in) > > :Returns: 0 on success, -1 on error > > > > :: > > @@ -1332,9 +1332,18 @@ yet and must be cleared on entry. > > __u64 userspace_addr; /* start of the userspace allocated memory */ > > }; > > > > + struct kvm_userspace_memory_region_ext { > > + struct kvm_userspace_memory_region region; > > + __u64 private_offset; > > + __u32 private_fd; > > + __u32 pad1; > > + __u64 pad2[14]; > > + }; > > + > > /* for kvm_memory_region::flags */ > > #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) > > #define KVM_MEM_READONLY (1UL << 1) > > + #define KVM_MEM_PRIVATE (1UL << 2) > > > > This ioctl allows the user to create, modify or delete a guest physical > > memory slot. Bits 0-15 of "slot" specify the slot id and this value > > @@ -1365,12 +1374,27 @@ It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr > > be identical. This allows large pages in the guest to be backed by large > > pages in the host. > > > > -The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and > > -KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of > > -writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to > > -use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it, > > -to make a new slot read-only. In this case, writes to this memory will be > > -posted to userspace as KVM_EXIT_MMIO exits. > > +kvm_userspace_memory_region_ext includes all the kvm_userspace_memory_region > > +fields. It also includes additional fields for some specific features. See > > +below description of flags field for more information. It's recommended to use > > +kvm_userspace_memory_region_ext in new userspace code. > > Better say "kvm_userspace_memory_region_ext includes all fields of > kvm_userspace_memory_region struct, while also adds additional fields ..." > > > + > > +The flags field supports below flags: > > s/below/following/ > > > + > > +- KVM_MEM_LOG_DIRTY_PAGES can be set to instruct KVM to keep track of writes to > > + memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to use it. > > + > > Better say "... For more details, see KVM_GET_DIRTY_LOG." > > > +- KVM_MEM_READONLY can be set, if KVM_CAP_READONLY_MEM capability allows it, to > > + make a new slot read-only. In this case, writes to this memory will be posted > > + to userspace as KVM_EXIT_MMIO exits. > > + > > Better say "if KVM_CAP_READONLY_MEM allows, KVM_MEM_READONLY makes a new > slot read-only ..." > > > +- KVM_MEM_PRIVATE can be set to indicate a new slot has private memory backed by > > + a file descirptor(fd) and the content of the private memory is invisible to > > + userspace. In this case, userspace should use private_fd/private_offset in > > + kvm_userspace_memory_region_ext to instruct KVM to provide private memory to > > + guest. Userspace should guarantee not to map the same pfn indicated by > > + private_fd/private_offset to different gfns with multiple memslots. Failed to > > + do this may result undefined behavior. > > > > For the lists above, > s/can be set/ It all looks good, thanks! > > Thanks. > > -- > An old man doll... just what I always wanted! - Clara