Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2357884pxb; Mon, 20 Sep 2021 20:01:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVrbdKtkP9nTxgmhV5pWYSiEG+agQXH0oHM2evaRWVoYMxLWKJ4jpnabEmAhVm0AQVDfVG X-Received: by 2002:a05:6402:886:: with SMTP id e6mr32596228edy.41.1632193264087; Mon, 20 Sep 2021 20:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632193264; cv=none; d=google.com; s=arc-20160816; b=oN5S1Kxm/TCDDagzoc3MGpgW4jSIbPF8N6TmJIpxbQAtwSLoXCjk2u3hd1iwtYF4F+ UJzW7ZDnIUAlCmv77DyB6b2qIFzSKYaDYaiRebdp3Tc4RTG0o9yvLbgjy1Fzhr9/kThT NOE5U7pXXSDJwm7Kq2xyXlhLNP/mhRo5IiQxBtRNrbrUfeuvWVPXg5Bt01d8k12ytOb6 ES0ee4uK9DEYTpUoFD5vBaCNF5aW3smhNBu2QjRu0XMhDDQrJYIgvYyZlbYraMGLbWWc 9qrabr0o5yctqpy2D49wPTQPsHk0f1ADRoAAeu+XRkD2ceackTrg9Gmw5zaj1ZU1bL0d zTLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Zd3cynPfQmSSh33NTCi9ZeeIAR/3rfjn13Zot2qPIQ8=; b=khrj5PoG6D44JgSAVU7dKLtBlIYK0xF//3KhTWKczk2FcdxGaIIRcOR3z5z/zg4DGa NfNROdg8jNnt3gBGxKGptL0c/Zi56kGDva6Hk1ZfTbh6WPxRJrwM41djWSOKpz0Fzi5O QWN8jMz6ixKhRGRg6ISSNP06jyduWwsCdMjo7ZSpxNXEo/2FFYg8DBI+FS8yUuAEYmd9 0OMykWtGd4JqqpCk26Gc+tx0Lj2uMnaNf+tG5g9JdA1TAt/7rurTEcWHf1rIk1VnV1BZ o+Icl+2B33fUDUKrWYL4epds6vKBSmyAWLbc8ge9Qf5XkKZ+UqaCsb8Eri5vwiaYFxiV UlbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si17868839eda.74.2021.09.20.20.00.37; Mon, 20 Sep 2021 20:01:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243242AbhITVnQ (ORCPT + 99 others); Mon, 20 Sep 2021 17:43:16 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:45368 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbhITVlM (ORCPT ); Mon, 20 Sep 2021 17:41:12 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mSR0Q-0006PA-1D; Mon, 20 Sep 2021 23:39:18 +0200 From: "Maciej S. Szmigiero" To: Paolo Bonzini , Vitaly Kuznetsov Cc: Sean Christopherson , 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 Subject: [PATCH v5 02/13] KVM: x86: Don't call kvm_mmu_change_mmu_pages() if the count hasn't changed Date: Mon, 20 Sep 2021 23:38:50 +0200 Message-Id: <8a94e762e212d2e347ebf5b19cb05f8447c33b29.1632171479.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Maciej S. Szmigiero" There is no point in calling kvm_mmu_change_mmu_pages() for memslot operations that don't change the total page count, so do it just for KVM_MR_CREATE and KVM_MR_DELETE. Signed-off-by: Maciej S. Szmigiero --- arch/x86/kvm/x86.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 65fdf27b9423..2e4fe2511c5d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11609,22 +11609,24 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, const struct kvm_memory_slot *new, enum kvm_mr_change change) { - if (change == KVM_MR_CREATE) - kvm->arch.n_memslots_pages += new->npages; - else if (change == KVM_MR_DELETE) { - WARN_ON(kvm->arch.n_memslots_pages < old->npages); - kvm->arch.n_memslots_pages -= old->npages; - } - - if (!kvm->arch.n_requested_mmu_pages) { - u64 memslots_pages; - unsigned long nr_mmu_pages; - - memslots_pages = kvm->arch.n_memslots_pages * KVM_PERMILLE_MMU_PAGES; - do_div(memslots_pages, 1000); - nr_mmu_pages = max_t(typeof(nr_mmu_pages), - memslots_pages, KVM_MIN_ALLOC_MMU_PAGES); - kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages); + if (change == KVM_MR_CREATE || change == KVM_MR_DELETE) { + if (change == KVM_MR_CREATE) + kvm->arch.n_memslots_pages += new->npages; + else { + WARN_ON(kvm->arch.n_memslots_pages < old->npages); + kvm->arch.n_memslots_pages -= old->npages; + } + + if (!kvm->arch.n_requested_mmu_pages) { + u64 memslots_pages; + unsigned long nr_mmu_pages; + + memslots_pages = kvm->arch.n_memslots_pages * KVM_PERMILLE_MMU_PAGES; + do_div(memslots_pages, 1000); + nr_mmu_pages = max_t(typeof(nr_mmu_pages), + memslots_pages, KVM_MIN_ALLOC_MMU_PAGES); + kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages); + } } kvm_mmu_slot_apply_flags(kvm, old, new, change);