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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F420C4332F for ; Thu, 23 Dec 2021 18:02:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244655AbhLWSCj (ORCPT ); Thu, 23 Dec 2021 13:02:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244522AbhLWSCi (ORCPT ); Thu, 23 Dec 2021 13:02:38 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6484AC061757 for ; Thu, 23 Dec 2021 10:02:38 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id 196so5872760pfw.10 for ; Thu, 23 Dec 2021 10:02:38 -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=F3vp7cNpz2qk0OIvJVZgGpZrlLI8cGs8eddNh3pH4O0=; b=V6LVAQd/8UIn8ldsx5JR1O9YpJZeToHbDLZbS7mg8/+loFV7/N7sZ+XhcLN4ER+wrt a4OJl94CKbfUSCf2rds4kBh5Lrrm72ej4Vw2jCZdwyaTpvW1Rfri5/b6D0d+XdP6rcLq EnCBOIjnXfg4hlKeBatFlHOFTTdwmCQQ6xeF/Ly1U82igCJHWiW1VL+d3kr+QmXcuLv8 0JyTkQyChwcIVqzmWpqo1NlewbWrHW4RFSMnsRxLAB2r1vNJbOQ7FxBRMK3jdWuCu2Zf vQb1n9Yb12+2OopiSqPqPM/6Qm6od8AV54HqElWU29SUVdpkee1DGnFa+7+XiW0B251Y fEzw== 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=F3vp7cNpz2qk0OIvJVZgGpZrlLI8cGs8eddNh3pH4O0=; b=lI+2mwjro9x3a6Q59KPyxAT/4FFqxOUWfU5agtsAG5WEaedUys1wc5ltTxQfHDEkne VwuuYyiMelyRsUEELIPJZOT+e7jpIOXtkfrnYjtjee2A1H4sYE5s0R3jkA0ZgvolyJNd YZX97fKnvCFPLJfewUv3S85rAKH88+d4YHjxO+EXoPqw/RKiamNRmxnu1fYykLTqbuIz sd/rmEsmmzivxlb+mK1+TKAz7CfXdbw8zy7uvP56jLhvli5dNa939YjfXKjR3rrL05oA s7LoeY230zAkw+debp5CC3ejYCqkghSLARBEUvlWQVPe/S96MI5CF4yLtNRrDarzXRWt MtTA== X-Gm-Message-State: AOAM530uTajwTUMDuTRRALh23N6s4i+QE0h92xxI2R7L9pL9vXW2Kn5s yk+/smxtp6A05g3IIHrFmTR9jg== X-Google-Smtp-Source: ABdhPJwrV3ydO2yyHoylZ6+Gjlc1pXLEXn2GLpfX+eRE21Of6xThdp2NrJD74NCN2Jt8w5I9duli3Q== X-Received: by 2002:a65:648b:: with SMTP id e11mr3022987pgv.138.1640282557705; Thu, 23 Dec 2021 10:02:37 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id gg23sm9329532pjb.31.2021.12.23.10.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 10:02:36 -0800 (PST) Date: Thu, 23 Dec 2021 18:02:33 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211223123011.41044-6-chao.p.peng@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. 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. 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().