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 X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D215AC433E0 for ; Wed, 3 Feb 2021 13:43:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BACC64F74 for ; Wed, 3 Feb 2021 13:43:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231740AbhBCNnA (ORCPT ); Wed, 3 Feb 2021 08:43:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33667 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbhBCNmj (ORCPT ); Wed, 3 Feb 2021 08:42:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=msAcTyPpH0uhCVhlJSk7w3lzIdisxEsipIij/eqjQsw=; b=D7bAo1A1hs91LgcWk8eA014fS2TyxkAr3qXK+Kt9tfL0PtSe5pj2Y08/ISXBW+jA6yipOO V64lBcdO5HGWttOyv8B68Ff/7HG/SDclSJbXsjnOQ+8HZPbHvb2P67nEbMvi7o9s7g6xV9 kf9YlmEK/E3YU+TOr16ANRI05MysO4Y= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-62-x3DJ7k6LNjeJzy9zSXiJKQ-1; Wed, 03 Feb 2021 08:41:06 -0500 X-MC-Unique: x3DJ7k6LNjeJzy9zSXiJKQ-1 Received: by mail-ed1-f72.google.com with SMTP id g6so3738019edy.9 for ; Wed, 03 Feb 2021 05:41:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=msAcTyPpH0uhCVhlJSk7w3lzIdisxEsipIij/eqjQsw=; b=K+N8C0fcFoadLS7FDwnVG/bNHRg6NQOkNdgWcEqHz7LwLENKs7wPY5QtY2T53xyN7A UtHROX0s7QK5F1CRZk5QcSw5qReAfEOMtQOKZ6PvTUPNyI1N3vGRALcOYJpHZ30jpi7p Hbqv2Xa2FgcKitjuXOYZHCAtT8gPJOlh67zAajJS/vrWLZRlrU4ILC7mvY1pAdUaIUKq JtWI1AQGhsx6T1YtjQgn3N5FEr1VOEWvhGz7gjKj0XN5SvQjd+jso2aoBRPbj2dM1aYg DXkcccMteIU2fnwgQUhUiIDtI0gODJH+VLUg7SguooiQZ319atslQ+9RvSUPgJMqhzC/ 1Jug== X-Gm-Message-State: AOAM533Emb8tOkZFtFLaUj1LYiD0lhpevsVw8uCGz3K/6fjtuxNhQyvd 7GiMTgF8d+xI6r5GAYsNUm3QFA4K198ZLM42iMPNc8lInIALTEP3SYmQj/CJKhdsXLpAjxMlMzT I6RqZua65v/JZ X-Received: by 2002:aa7:dbd4:: with SMTP id v20mr3099888edt.330.1612359664819; Wed, 03 Feb 2021 05:41:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5RqYAPRRgfzLBlQj3QtEFUTTMAWVBk2kNfGn0CfoyXUMV2LaPkgLSfawvzDEpBA6U8agzMA== X-Received: by 2002:aa7:dbd4:: with SMTP id v20mr3099857edt.330.1612359664645; Wed, 03 Feb 2021 05:41:04 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id s15sm1010923ejy.68.2021.02.03.05.41.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Feb 2021 05:41:03 -0800 (PST) To: "Maciej S. Szmigiero" , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Igor Mammedov , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <4d748e0fd50bac68ece6952129aed319502b6853.1612140117.git.maciej.szmigiero@oracle.com> <9e6ca093-35c3-7cca-443b-9f635df4891d@maciej.szmigiero.name> From: Paolo Bonzini Subject: Re: [PATCH 2/2] KVM: Scalable memslots implementation Message-ID: <4bdcb44c-c35d-45b2-c0c1-e857e0fd383e@redhat.com> Date: Wed, 3 Feb 2021 14:41:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <9e6ca093-35c3-7cca-443b-9f635df4891d@maciej.szmigiero.name> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 02/02/21 23:42, Maciej S. Szmigiero wrote: >> I'm not opposed to using more sophisticated storage for the gfn >> lookups, but only if there's a good reason for doing so. IMO, the >> rbtree isn't simpler, just different. And it also has worse cache utilization than an array, due to memory footprint (as you point out below) but also pointer chasing. >> Memslot modifications are >> unlikely to be a hot path (and if it is, x86's "zap everything" >> implementation is a far bigger problem), and it's hard to beat the >> memory footprint of a raw array. That doesn't leave much >> motivation for such a big change to some of KVM's scariest (for me) >> code. >> > > Improvements can be done step-by-step, > kvm_mmu_invalidate_zap_pages_in_memslot() can be rewritten, too in > the future, if necessary. After all, complains are that this change > alone is too big. > > I think that if you look not at the patch itself but at the > resulting code the new implementation looks rather straightforward, > there are comments at every step in kvm_set_memslot() to explain > exactly what is being done. Not only it already scales well, but it > is also flexible to accommodate further improvements or even new > operations. > > The new implementation also uses standard kernel {rb,interval}-tree > and hash table implementation as its basic data structures, so it > automatically benefits from any generic improvements to these. > > All for the low price of just 174 net lines of code added. I think the best thing to do here is to provide a patch series that splits the individual changes so that they can be reviewed and their separate merits evaluated. Another thing that I dislike about KVM_SET_USER_MEMORY_REGION is that IMO userspace should provide all memslots at once, for an atomic switch of the whole memory array. (Or at least I would like to see the code; it might be a bit tricky because you'll need code to compute the difference between the old and new arrays and invoke kvm_arch_prepare/commit_memory_region). I'm not sure how that would interact with the active/inactive pair that you introduce here. Paolo