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 8D637C433F5 for ; Thu, 23 Dec 2021 18:02:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A75126B0072; Thu, 23 Dec 2021 13:02:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A247E6B0073; Thu, 23 Dec 2021 13:02:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ED7C6B0074; Thu, 23 Dec 2021 13:02:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 7C9356B0072 for ; Thu, 23 Dec 2021 13:02:39 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3A17C82499B9 for ; Thu, 23 Dec 2021 18:02:39 +0000 (UTC) X-FDA: 78949829238.06.E5159DA Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf20.hostedemail.com (Postfix) with ESMTP id D4B4E1C0054 for ; Thu, 23 Dec 2021 18:02:33 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id b22so5888721pfb.5 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=BX1T91cTh8FBaDwPPvruZYFPx9ZjDkW8CIbU86L53Za5g1Pz5IUqv3w8MvSYp+iSZh AU2UvSNvyYhcfCM9qG6zgMtasKROXIFsQXhjvEdgZGHiZumFOCJuS0FN6C/g7hXcWiIK HBlPNc33WUHja5Q7xYk6nQ6L51f/8ngonHmIRjumuG+EZYh+5dVD1YGQFWxrrTt4ZKfI v9vinpfzaW1+lG3qzFI1pkawpHCkXvA01K2Y9Ivdz3L2eIjvf6F/PrJj2sxrOZdIXHHE 7aLFTaDddNFc+I7PkIVit1b+obAlPid5fxEB7B7UEDUa6NFCCYkpa3dOF4PgNP7XMtWx MyKA== X-Gm-Message-State: AOAM533COEBy5eZpcHEzPL4EtD0LDTc8zmqbVneoV204MXKrOiVAb8nb ifu2J9/EZ+OxN/vOiTE5cUlHJw== 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> X-Rspamd-Queue-Id: D4B4E1C0054 X-Stat-Signature: gf3aodrk81ypb4ijfnznpcsxuyfxg4jc Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="V6LVAQd/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of seanjc@google.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=seanjc@google.com X-Rspamd-Server: rspam11 X-HE-Tag: 1640282553-628757 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, 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().