From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD7E6C433EF for ; Fri, 8 Apr 2022 13:21:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E48266B0071; Fri, 8 Apr 2022 09:21:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD00C6B0072; Fri, 8 Apr 2022 09:21:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C49FC6B0074; Fri, 8 Apr 2022 09:21:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id AF67A6B0071 for ; Fri, 8 Apr 2022 09:21:27 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5E76D18478D82 for ; Fri, 8 Apr 2022 13:21:27 +0000 (UTC) X-FDA: 79333773414.28.A3933EF Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by imf05.hostedemail.com (Postfix) with ESMTP id 6375510000C for ; Fri, 8 Apr 2022 13:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649424086; x=1680960086; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=yJ+a09qZfU8xn/sBjF/pizQ4GwvK+1hMB8dFu0xFHhY=; b=Bqgh2FZ3UnnnyGlWDOAe19xfgxc3Nx866QqhL7/jz2DDfK+41XmVRDDe ukJ4iTxtjlLtVCh5jwbl/hVQSTNLxZ+Atv6UGBJ1CDkOVSL3HkIXCLHR1 ZTFT/3PtBfhCwLC6FrUXVzlPTNCW3AZBih8rXCOPXO+RBnPKOMzuyB/tN 0BMf2nlWnyBgoJV+5IXNwdXPGOmdB1PP6NaylsWr/YvRdTKQQzqT+8qry rK6I4iIiiesaE8LiGl636YU95/ZBxFpcCcoF0//sWuouMjItQbxiKxU3F 4HW7WRvQubj4m0aC4m0bZwQ71xHBd9q3iHV9FUiZYmtXq3doQQvsgUATd g==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="322278166" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="322278166" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:21:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="571485977" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga008.jf.intel.com with ESMTP; 08 Apr 2022 06:21:16 -0700 Date: Fri, 8 Apr 2022 21:21:05 +0800 From: Chao Peng To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@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 , 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 Subject: Re: [PATCH v5 05/13] KVM: Extend the memslot to support fd-based private memory Message-ID: <20220408132105.GC57095@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-6-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspam-User: X-Stat-Signature: ojhzqz5xceppbjitunxfrdctn179yk3p Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Bqgh2FZ3; spf=none (imf05.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6375510000C X-HE-Tag: 1649424086-194073 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Mar 28, 2022 at 09:27:32PM +0000, Sean Christopherson wrote: > On Thu, Mar 10, 2022, Chao Peng wrote: > > Extend the memslot definition to provide fd-based private memory support > > by adding two new fields (private_fd/private_offset). The memslot then > > can maintain memory for both shared pages and private pages in a single > > memslot. Shared pages are provided by existing userspace_addr(hva) field > > and private pages are provided through the new private_fd/private_offset > > fields. > > > > Since there is no 'hva' concept anymore for private memory so we cannot > > rely on get_user_pages() to get a pfn, instead we use the newly added > > memfile_notifier to complete the same job. > > > > This new extension is indicated by a new flag KVM_MEM_PRIVATE. > > > > Signed-off-by: Yu Zhang > > Needs a Co-developed-by: for Yu, or a From: if Yu is the sole author. Yes a Co-developed-by for Yu is needed, for all the patches throught the series. > > > Signed-off-by: Chao Peng > > --- > > Documentation/virt/kvm/api.rst | 37 +++++++++++++++++++++++++++------- > > include/linux/kvm_host.h | 7 +++++++ > > include/uapi/linux/kvm.h | 8 ++++++++ > > 3 files changed, 45 insertions(+), 7 deletions(-) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index 3acbf4d263a5..f76ac598606c 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -1307,7 +1307,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 > > > > :: > > @@ -1320,9 +1320,17 @@ 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 padding[5]; > > Uber nit, I'd prefer we pad u32 for private_fd separate from padding the size of > the structure for future expansion. > > Regarding future expansion, any reason not to go crazy and pad like 128+ bytes? > It'd be rather embarassing if the next memslot extension needs 3 u64s and we end > up with region_ext2 :-) OK, so maybe: __u64 private_offset; __u32 private_fd; __u32 pad1; __u32 pad2[28]; > > > +}; > > + > > /* 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 > > ... > > > +static inline bool kvm_slot_is_private(const struct kvm_memory_slot *slot) > > I 100% think we should usurp the name "private" for these memslots, but as prep > work this series should first rename KVM_PRIVATE_MEM_SLOTS to avoid confusion. > Maybe KVM_INTERNAL_MEM_SLOTS? Oh, I didn't realized 'PRIVATE' is already taken. KVM_INTERNAL_MEM_SLOTS sounds good. Thanks, Chao