Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp596854pxb; Thu, 17 Feb 2022 10:25:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOk2DyRLFPVd2l6yvsEbWpvfyODhiJwtDzUvU7DlChGdJ4XeJG8EwzkbKe0mYyuJYtY64g X-Received: by 2002:a05:6a00:130b:b0:4e1:7b1e:6c6 with SMTP id j11-20020a056a00130b00b004e17b1e06c6mr4333797pfu.22.1645122311911; Thu, 17 Feb 2022 10:25:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645122311; cv=none; d=google.com; s=arc-20160816; b=zQBalSFQAEkZAvRxaPF36YnhVuYm3fxm7HUXrVYVFOQEJS5CvE2uG7qrXkt8SOIQTE WZcMnsWU1HakJgHepoBIa57CDcgw1wR/cXww3HSEUE4akEomoq0K2TjhXZeggmUqQ+of qEm97RphEqOzdQCswn+sl2/1zZo4tcu0/nvTZe7BLc1NLfqNl6M9Bs11mxkqMo0QSHNZ ijX/HcEOGUdPV05NtUeeNiJHM/PBbWcGVh0cjiHVhhZjSw57vlucy3pIt8fJxVHI80YC +ADZAgheawE1Rdz88++W0J01lXf0tow6b82315YQSN6BiRodF37Nt7h5GDW1ErCFC0/i FdkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=oBeSzYBiUEy48N0RmvoQFqE0niOHRrPRvEW9NE+J/Mo=; b=b4tOyqaytPH4a9JPzLtJMFevPf5QQi5IFZ6wf78zYG6dpT0QIc1BElSy0o9Ewicx/0 U6/oPARVMMmiwnS+ogLai/AQ/MwU61zG4NkysDSwTCTm1gK2sQOrUuTh6/ViuQwIPnol 1J5XRFcoOQ8peNl8KQoD/EV6dnXtRq9hIUGWzVfDeYud3/6yjsv+X8g4cm3zV/TeR6AM b0bCNcq4IuAVGTO5qiwJSexwvhxWi0JCby+JSMfzb1E/636dMdUAI6+pqtiOcHtocQ8p oFCz0LdAQa6NW+WFInXRH0OatqL1+bQS59hvDyDBQZZfrNe4x4T3TTYxHUVJ16Xs9o+H tz3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KyH2syqz; 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 w8si26347329plg.490.2022.02.17.10.24.55; Thu, 17 Feb 2022 10:25:11 -0800 (PST) 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=KyH2syqz; 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 S241416AbiBQNqe (ORCPT + 99 others); Thu, 17 Feb 2022 08:46:34 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237030AbiBQNqc (ORCPT ); Thu, 17 Feb 2022 08:46:32 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A249F2AF91B; Thu, 17 Feb 2022 05:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645105577; x=1676641577; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=8+xFg8pu7fX7w5OrNIMbop+pkXQzV4mq0rLcHHtAokE=; b=KyH2syqz/8lV+/aUSKd7shF5ekhfitmw6ENLWNQrOyiDT2NuEk2DQe9V 5E+sjQ8CYA2kI+oTqW30Xb1K7+DBrbCizknYoGt/Ms7RISsbQW1/aiDs6 sp776BTtxRQbOyZBSzX8RgPVyRDLLtmwqLoTA6IaQJn8IfJa5GDDLfv4t jFhVZZ1xmS/an0HIQ7JRltdZp66jdMBQY0mmUec0z/6M4Qab0MR1CikZG Vpn3z32PQ8YvoE5R4WbZPF7SAA1+v4jZOB/lrs+wyTaXhrNFSg+GCDJCJ KLcmZluts0SN43bk5ZndqHMTsDzUPUhQ8MG61k06tV/PISLtG82+lpzfm A==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="249710570" X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="249710570" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 05:46:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="503513631" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga002.jf.intel.com with ESMTP; 17 Feb 2022 05:46:10 -0800 Date: Thu, 17 Feb 2022 21:45:48 +0800 From: Chao Peng To: "Maciej S. Szmigiero" Cc: Yu Zhang , 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 Subject: Re: [PATCH v4 12/12] KVM: Expose KVM_MEM_PRIVATE Message-ID: <20220217134548.GA33836@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220118132121.31388-1-chao.p.peng@linux.intel.com> <20220118132121.31388-13-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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Tue, Jan 25, 2022 at 09:20:39PM +0100, Maciej S. Szmigiero wrote: > 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. In the last version I tried to solve this problem by using interval tree (just like existing hva_tree), but finally we realized that in one VM we can have multiple fds with overlapped offsets so that approach is incorrect. See https://lkml.org/lkml/2021/12/28/480 for the discussion. So linear scan is used before I can find a better way. Chao