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 266C3C433EF for ; Tue, 4 Jan 2022 17:43:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 821596B0071; Tue, 4 Jan 2022 12:43:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D1846B0072; Tue, 4 Jan 2022 12:43:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64A986B0073; Tue, 4 Jan 2022 12:43:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id 562CE6B0071 for ; Tue, 4 Jan 2022 12:43:56 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 13DBD1802EB2B for ; Tue, 4 Jan 2022 17:43:56 +0000 (UTC) X-FDA: 78993327672.21.76619AB Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf28.hostedemail.com (Postfix) with ESMTP id A23B2C000F for ; Tue, 4 Jan 2022 17:43:55 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id m1so32839311pfk.8 for ; Tue, 04 Jan 2022 09:43:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=13+cbru1EicSyFl290RL62qNhQ55+dHM2uIjjFzOwWQ=; b=qiqd4ZBl5BqJHPRL1WkKqev6zYNCBKXygXrnDR+B8P5U+ncr+nyYGcNLR7VtJRMbR+ nu+XvQR0ZvTHDgijE3+Ephw/fASHy6xXWP0G97pDtjkfz1dKRsQLmc6PexXKZ6eOiTmr wLjrAbgjf1xpI3WYhgSKqeScUoNRXJvAlDnLd371vsx/3pwzIE9KXiKfaj3I/ZdHjqA8 xBpOOwl5sZ+x9RvltjE0m8jfdToQt4TESxL7mb+P6lBPBE7kEi7z47aEbg/ZFbrTwxVh thDTi9pkTIUf/VFrmufk4T+y2xu0pNllCtxK03hhz2Xp5v22QQLi5JXx3XoNiDlljx2j eUEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=13+cbru1EicSyFl290RL62qNhQ55+dHM2uIjjFzOwWQ=; b=vhrMI2/2ubuG1rICVGQ5Ro3g9W2zywaNRelGR76UVkLcJtnsp2k9l8faY6x/lABNka cZKGoWU856SoEGVck9wWe9CLeVafuZIPuNxHu4UQwSqsIw/Iizm7qQzqN2NYZSqJQ2DV LutqDtDC0Bc5TbM2cavook2czEDnEN7YkZ9WUivX2IfmHJQ5yko6S4YBlTWZ+JcV68XW ni4w6RFgbshb4Lp61qD8Xn49SmiZLyR0wLS+3m8EBA2K+OfiHSPqNIdksLOlVTS/lZ/M 8e+i4Y9XocWg+p1aveH9/Z0kmE77gQAQcVoVwyA6M79MgH8kQZkQofCDNsLMezAl1Dmw qDqw== X-Gm-Message-State: AOAM5327rvjAbQS9g/Eyt8Tv8/KOzNTcMdY1ytk9eSsk7bWkn0Bjerw1 tJNqH4fDyUTLcl0DjRWBi7S+uA== X-Google-Smtp-Source: ABdhPJzQtrrXhdr9JNHtClHOyyxM1wCawkxYoqgHsdkj3QcxdAXEJm9cAZOEh3vO62LsqFUjGuIFog== X-Received: by 2002:a63:ba47:: with SMTP id l7mr46031570pgu.75.1641318234513; Tue, 04 Jan 2022 09:43:54 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id n14sm34881764pgd.80.2022.01.04.09.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:43:53 -0800 (PST) Date: Tue, 4 Jan 2022 17:43:50 +0000 From: Sean Christopherson To: Chao Peng 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: 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: <20211231022636.GA7025@chaop.bj.intel.com> X-Stat-Signature: iottqp3cbkhdsejhb47ftedkwu6b31mx X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A23B2C000F Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=qiqd4ZBl; spf=pass (imf28.hostedemail.com: domain of seanjc@google.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1641318235-319996 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 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.