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 C0947C433EF for ; Thu, 17 Feb 2022 13:46:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A5856B0078; Thu, 17 Feb 2022 08:46:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42E3C6B007B; Thu, 17 Feb 2022 08:46:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CFAD6B007D; Thu, 17 Feb 2022 08:46:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 173176B0078 for ; Thu, 17 Feb 2022 08:46:20 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CD1AF236D0 for ; Thu, 17 Feb 2022 13:46:19 +0000 (UTC) X-FDA: 79152396078.04.B4B2E1F Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf29.hostedemail.com (Postfix) with ESMTP id B75FF120012 for ; Thu, 17 Feb 2022 13:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645105578; x=1676641578; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=8+xFg8pu7fX7w5OrNIMbop+pkXQzV4mq0rLcHHtAokE=; b=c2cyrNQ3L93mrat/E3kcpy//tccWaEDq8bUnP7Jjrxbl9bX7Y4slIiZs r+mqyjBCQNA12RJHJeG/FvR5ureN6zySR3PBENrqUFt5RhZFcBGOhMqFw akrUqX90XbZBtz5orsRCmCnlKK1uGTTpDR5nE6MYs6KIrEz2kyFgff5T/ +P0QOV5TyctV4BwnEVP4/fMgZSjQtFyrd/J0cwC/nZt3F+mR2QyP37k6O BneMUqYxVwUFcPUv0jF3rFDcR5eLKOGfhVXGt4bWDIGJlKxULaLOXXYVB oEq9v+1sesraAZMaP6TYaDnOZnTzR6F8xE7y0kOtxDeIDys2gDduysYTx g==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="230837118" X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="230837118" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B75FF120012 X-Stat-Signature: xw6dx3k1zjk3e3mx5swyrikufwmzmamf X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=c2cyrNQ3; spf=none (imf29.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1645105578-447305 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 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