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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 245FFC433F5 for ; Tue, 25 Jan 2022 20:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231824AbiAYUVb (ORCPT ); Tue, 25 Jan 2022 15:21:31 -0500 Received: from vps-vb.mhejs.net ([37.28.154.113]:58180 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbiAYUVX (ORCPT ); Tue, 25 Jan 2022 15:21:23 -0500 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nCSJ4-0006nf-3P; Tue, 25 Jan 2022 21:20:46 +0100 Message-ID: Date: Tue, 25 Jan 2022 21:20:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: Chao Peng , Yu Zhang Cc: Paolo Bonzini , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , kvm@vger.kernel.org, Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, qemu-devel@nongnu.org References: <20220118132121.31388-1-chao.p.peng@linux.intel.com> <20220118132121.31388-13-chao.p.peng@linux.intel.com> From: "Maciej S. Szmigiero" Subject: Re: [PATCH v4 12/12] KVM: Expose KVM_MEM_PRIVATE In-Reply-To: <20220118132121.31388-13-chao.p.peng@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18.01.2022 14:21, Chao Peng wrote: > KVM_MEM_PRIVATE is not exposed by default but architecture code can turn > on it by implementing kvm_arch_private_memory_supported(). > > Also private memslot cannot be movable and the same file+offset can not > be mapped into different GFNs. > > Signed-off-by: Yu Zhang > Signed-off-by: Chao Peng > --- (..) > > static bool kvm_check_memslot_overlap(struct kvm_memslots *slots, int id, > - gfn_t start, gfn_t end) > + struct file *file, > + gfn_t start, gfn_t end, > + loff_t start_off, loff_t end_off) > { > struct kvm_memslot_iter iter; > + struct kvm_memory_slot *slot; > + struct inode *inode; > + int bkt; > > kvm_for_each_memslot_in_gfn_range(&iter, slots, start, end) { > if (iter.slot->id != id) > return true; > } > > + /* Disallow mapping the same file+offset into multiple gfns. */ > + if (file) { > + inode = file_inode(file); > + kvm_for_each_memslot(slot, bkt, slots) { > + if (slot->private_file && > + file_inode(slot->private_file) == inode && > + !(end_off <= slot->private_offset || > + start_off >= slot->private_offset > + + (slot->npages >> PAGE_SHIFT))) > + return true; > + } > + } That's a linear scan of all memslots on each CREATE (and MOVE) operation with a fd - we just spent more than a year rewriting similar linear scans into more efficient operations in KVM. Thanks, Maciej 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40BF8C4332F for ; Tue, 25 Jan 2022 20:24:06 +0000 (UTC) Received: from localhost ([::1]:47740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCSMG-0003HL-Mf for qemu-devel@archiver.kernel.org; Tue, 25 Jan 2022 15:24:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCSKR-0002Uw-16 for qemu-devel@nongnu.org; Tue, 25 Jan 2022 15:22:11 -0500 Received: from vps-vb.mhejs.net ([37.28.154.113]:44750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCSKP-0001Ji-5c for qemu-devel@nongnu.org; Tue, 25 Jan 2022 15:22:10 -0500 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nCSJ4-0006nf-3P; Tue, 25 Jan 2022 21:20:46 +0100 Message-ID: Date: Tue, 25 Jan 2022 21:20:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: Chao Peng , Yu Zhang References: <20220118132121.31388-1-chao.p.peng@linux.intel.com> <20220118132121.31388-13-chao.p.peng@linux.intel.com> From: "Maciej S. Szmigiero" Subject: Re: [PATCH v4 12/12] KVM: Expose KVM_MEM_PRIVATE In-Reply-To: <20220118132121.31388-13-chao.p.peng@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=37.28.154.113; envelope-from=mail@maciej.szmigiero.name; helo=vps-vb.mhejs.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wanpeng Li , jun.nakajima@intel.com, kvm@vger.kernel.org, david@redhat.com, qemu-devel@nongnu.org, "J . Bruce Fields" , linux-mm@kvack.org, "H . Peter Anvin" , ak@linux.intel.com, Jonathan Corbet , Joerg Roedel , x86@kernel.org, Hugh Dickins , Ingo Molnar , Borislav Petkov , luto@kernel.org, Thomas Gleixner , Vitaly Kuznetsov , Jim Mattson , dave.hansen@intel.com, Sean Christopherson , Jeff Layton , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Paolo Bonzini , Andrew Morton , "Kirill A . Shutemov" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 18.01.2022 14:21, Chao Peng wrote: > KVM_MEM_PRIVATE is not exposed by default but architecture code can turn > on it by implementing kvm_arch_private_memory_supported(). > > Also private memslot cannot be movable and the same file+offset can not > be mapped into different GFNs. > > Signed-off-by: Yu Zhang > Signed-off-by: Chao Peng > --- (..) > > static bool kvm_check_memslot_overlap(struct kvm_memslots *slots, int id, > - gfn_t start, gfn_t end) > + struct file *file, > + gfn_t start, gfn_t end, > + loff_t start_off, loff_t end_off) > { > struct kvm_memslot_iter iter; > + struct kvm_memory_slot *slot; > + struct inode *inode; > + int bkt; > > kvm_for_each_memslot_in_gfn_range(&iter, slots, start, end) { > if (iter.slot->id != id) > return true; > } > > + /* Disallow mapping the same file+offset into multiple gfns. */ > + if (file) { > + inode = file_inode(file); > + kvm_for_each_memslot(slot, bkt, slots) { > + if (slot->private_file && > + file_inode(slot->private_file) == inode && > + !(end_off <= slot->private_offset || > + start_off >= slot->private_offset > + + (slot->npages >> PAGE_SHIFT))) > + return true; > + } > + } That's a linear scan of all memslots on each CREATE (and MOVE) operation with a fd - we just spent more than a year rewriting similar linear scans into more efficient operations in KVM. Thanks, Maciej