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 D7A0AC433FE for ; Fri, 24 Dec 2021 03:55:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FF9D6B0072; Thu, 23 Dec 2021 22:55:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 089C26B0073; Thu, 23 Dec 2021 22:55:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E447E6B0074; Thu, 23 Dec 2021 22:55:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id D33B16B0072 for ; Thu, 23 Dec 2021 22:55:08 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8F9F1181AC9CC for ; Fri, 24 Dec 2021 03:55:08 +0000 (UTC) X-FDA: 78951322296.04.8425928 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf18.hostedemail.com (Postfix) with ESMTP id D45681C0046 for ; Fri, 24 Dec 2021 03:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1640318107; x=1671854107; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=WZb4+/Ks4LDsAyLJCQPSXmUGHI2zwvNb+vAIAemyck0=; b=cKHle3yh+8o6CmixL0k7IbmoSnC3lEGZXXfGcf1gpZJuQpGe2WhiLp6H NZ/JNQgUGWiDkOY3u8/eeEKbyqQb0IvJxvfdd65yrEMza0/+AMVV+iMa4 gfVhdAkT3zep1Xt/kZ6a0I3RPFk7npCnQDgg6wML8dbQgu4sgSHgvwPRB WzgwTbjcMYB5kqSLrFrfFfPSsGflRA1SDoETF7KBA75mcykUaI2L1FD1J aSwiNUqwNMZKcO7Or4eTWBaUuONUbpxH0KAtW6tRudamz99r/Pd/3s15e 3h1mk476F0Rvxil1dSMiqKqtKMb94vra7pq789vEaXFLKMZK/C7H2DA1k w==; X-IronPort-AV: E=McAfee;i="6200,9189,10207"; a="220933689" X-IronPort-AV: E=Sophos;i="5.88,231,1635231600"; d="scan'208";a="220933689" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Dec 2021 19:55:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,231,1635231600"; d="scan'208";a="607950579" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by FMSMGA003.fm.intel.com with ESMTP; 23 Dec 2021 19:54:56 -0800 Date: Fri, 24 Dec 2021 11:54:18 +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, 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 , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, john.ji@intel.com, susie.li@intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: Re: [PATCH v3 kvm/queue 05/16] KVM: Maintain ofs_tree for fast memslot lookup by file offset Message-ID: <20211224035418.GA43608@chaop.bj.intel.com> Reply-To: Chao Peng References: <20211223123011.41044-1-chao.p.peng@linux.intel.com> <20211223123011.41044-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D45681C0046 X-Stat-Signature: hf6s84qwfp8d4hh63dd8qwbnhmu3qcis Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cKHle3yh; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf18.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 X-HE-Tag: 1640318100-962482 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 Thu, Dec 23, 2021 at 06:02:33PM +0000, Sean Christopherson wrote: > On Thu, Dec 23, 2021, Chao Peng wrote: > > Similar to hva_tree for hva range, maintain interval tree ofs_tree for > > offset range of a fd-based memslot so the lookup by offset range can be > > faster when memslot count is high. > > This won't work. The hva_tree relies on there being exactly one virtual address > space, whereas with private memory, userspace can map multiple files into the > guest at different gfns, but with overlapping offsets. OK, that's the point. > > I also dislike hijacking __kvm_handle_hva_range() in patch 07. > > KVM also needs to disallow mapping the same file+offset into multiple gfns, which > I don't see anywhere in this series. This can be checked against file+offset overlapping with existing slots when register a new one. > > In other words, there needs to be a 1:1 gfn:file+offset mapping. Since userspace > likely wants to allocate a single file for guest private memory and map it into > multiple discontiguous slots, e.g. to skip the PCI hole, the best idea off the top > of my head would be to register the notifier on a per-slot basis, not a per-VM > basis. It would require a 'struct kvm *' in 'struct kvm_memory_slot', but that's > not a huge deal. > > That way, KVM's notifier callback already knows the memslot and can compute overlap > between the memslot and the range by reversing the math done by kvm_memfd_get_pfn(). > Then, armed with the gfn and slot, invalidation is just a matter of constructing > a struct kvm_gfn_range and invoking kvm_unmap_gfn_range(). KVM is easy but the kernel bits would be difficulty, it has to maintain fd+offset to memslot mapping because one fd can have multiple memslots, it need decide which memslot needs to be notified. Thanks, Chao