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 43609C433FE for ; Wed, 5 Jan 2022 06:10:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D42B36B0071; Wed, 5 Jan 2022 01:10:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF2A06B0073; Wed, 5 Jan 2022 01:10:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE14F6B0074; Wed, 5 Jan 2022 01:10:01 -0500 (EST) 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 AF5756B0071 for ; Wed, 5 Jan 2022 01:10:01 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 711898E569 for ; Wed, 5 Jan 2022 06:10:01 +0000 (UTC) X-FDA: 78995207802.06.363D247 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf25.hostedemail.com (Postfix) with ESMTP id A69E4A000A for ; Wed, 5 Jan 2022 06:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641363000; x=1672899000; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=neMYafxOw6RMBRe+E68I7vpqrbUkO5bFR8JYJ2KBVLo=; b=THrx3TOv6tE/Mcm7zYP9VSW0YEKqKVweIHr7MVfkvZc4b/f2e/0FooDr Q+Q+h64ChGXocQagOs825gRG1AOJOWQrDJZCxr/n6whIUsMDbZonvvYQu 6l8H6mkvptkVe3Y8C9HFkWTaaQA9R6YhX6fdZVPVy4Noe0IAcvDZyZfiS DQyXhfbDHlpjNgEL9zz/13InPP3b+xUkeiEhy0U9ead7Y8sKY3Knld8VD /I3DHrCwXcp9tp7KPGk5Vtt9xYOQma+yfYJWmi7FnnbrHYaax6/mOccyD WiYmZnef5uUtP/mg6MncsewPdtBhBzZwEHZJYr9bCbnRr8nMuqbte6eZU A==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="242174798" X-IronPort-AV: E=Sophos;i="5.88,262,1635231600"; d="scan'208";a="242174798" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2022 22:09:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,262,1635231600"; d="scan'208";a="526380386" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga008.jf.intel.com with ESMTP; 04 Jan 2022 22:09:52 -0800 Date: Wed, 5 Jan 2022 14:09: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: <20220105060918.GB25009@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> <20211224035418.GA43608@chaop.bj.intel.com> <20211231022636.GA7025@chaop.bj.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-Queue-Id: A69E4A000A X-Stat-Signature: mjwqupzcw6rstoo49fct4cg1n1w14ihe Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=THrx3TOv; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf25.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=chao.p.peng@linux.intel.com X-Rspamd-Server: rspam11 X-HE-Tag: 1641362982-438734 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 04, 2022 at 05:43:50PM +0000, Sean Christopherson wrote: > On Fri, Dec 31, 2021, Chao Peng wrote: > > On Tue, Dec 28, 2021 at 09:48:08PM +0000, Sean Christopherson wrote: > > >KVM handles > > > reverse engineering the memslot to get the offset and whatever else it needs. > > > notify_fallocate() and other callbacks are unchanged, though they probably can > > > drop the inode. > > > > > > E.g. likely with bad math and handwaving on the overlap detection: > > > > > > int kvm_private_fd_fallocate_range(void *owner, pgoff_t start, pgoff_t end) > > > { > > > struct kvm_memory_slot *slot = owner; > > > struct kvm_gfn_range gfn_range = { > > > .slot = slot, > > > .start = (start - slot->private_offset) >> PAGE_SHIFT, > > > .end = (end - slot->private_offset) >> PAGE_SHIFT, > > > .may_block = true, > > > }; > > > > > > if (!has_overlap(slot, start, end)) > > > return 0; > > > > > > gfn_range.end = min(gfn_range.end, slot->base_gfn + slot->npages); > > > > > > kvm_unmap_gfn_range(slot->kvm, &gfn_range); > > > return 0; > > > } > > > > I understand this KVM side handling, but again one fd can have multiple > > memslots. How shmem decides to notify which memslot from a list of > > memslots when it invokes the notify_fallocate()? Or just notify all > > the possible memslots then let KVM to check? > > Heh, yeah, those are the two choices. :-) > > Either the backing store needs to support registering callbacks for specific, > arbitrary ranges, or it needs to invoke all registered callbacks. Invoking all > callbacks has my vote; it's much simpler to implement and is unlikely to incur > meaningful overhead. _Something_ has to find the overlapping ranges, that cost > doesn't magically go away if it's pushed into the backing store. > > Note, invoking all notifiers is also aligned with the mmu_notifier behavior. Sounds a good reason. Then shmem side only needs to maintain a list of users. Chao