Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp1080369pxb; Fri, 13 Aug 2021 13:03:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoTqKQP83P3pSP6jsLz26I3g0nB0L4oXr0Wv4L2VovHz7d1c6iSUlV29TV2qqEzEFPdVPq X-Received: by 2002:aa7:c606:: with SMTP id h6mr5192169edq.363.1628885028256; Fri, 13 Aug 2021 13:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628885028; cv=none; d=google.com; s=arc-20160816; b=J/g7cA5D9hLliQAAzDgjh4CeQc4iz/kzZicgYu4MrSfN2xqbE3W7SHNZzIe01ambkH 5AzmmnceetiZ74eNjGzS6s9QEP6fSpUOsLXFz7LKLjxACqajtThh8KrzCjGXFXwo8NEo jH6AsIGdi4QGiJNkjxgpVWqqWXICxpo4m19dfoeD6bETmyMI7HzHYDrdJL753tJZFnFZ /1DYTGtmbyUXeaG+EsQGsVQfj2M/er9T2c73uFJHWdKitksx15Bq16XUe4bDugo47zQN NEFUxWyEUUWZ0GVhHVTRv1RMjYCKNL43jU/7hQ8gESpbGtua+lmf6g+67VVlbFl8hRzZ J9oA== 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=XLi+9WMglF6G+a7shUDWS+7zXfgGHnCQFW/aIuUwegU=; b=UlSAPL2N/Z9qXO+OIf5ohZ118iOsqAZdYnZtcuG5dNdaDb0DEurVSmoARRZmPt4/iy ACiodMq3qd9/cddaujq42xGTqmkiOouIACll/pctkKjES6kdx4as81/F+PnrF5aXMKKW dgDZJvChG5297yO++dQ3XvDKpLNJ8Orssfaw6fkl0n6VcBn6ndZ6z4lVw/ZiXiyn3EKE LEAz/e66JOPZcgbxiuYUhwIcLuQRHMk9QnRWcnqsXwIdx0nMXSss0Hk2TE28U1hCEz5K smGguKNa0ExJ42MRRmTf7G/qdj8/VWSiB+bD6VrWeCJxB/G0cNgr0lLzG8BwpKfgCnQ2 C/wg== 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 jz20si2671617ejc.453.2021.08.13.13.03.24; Fri, 13 Aug 2021 13:03:48 -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 S234210AbhHMUB1 (ORCPT + 99 others); Fri, 13 Aug 2021 16:01:27 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:50296 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234251AbhHMUBY (ORCPT ); Fri, 13 Aug 2021 16:01:24 -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 1mEcw2-00041X-I6; Fri, 13 Aug 2021 21:33:42 +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 v4 02/13] KVM: x86: Don't call kvm_mmu_change_mmu_pages() if the count hasn't changed Date: Fri, 13 Aug 2021 21:33:15 +0200 Message-Id: X-Mailer: git-send-email 2.32.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 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6f9d9c7457d7..6bbfc53518d8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11588,20 +11588,22 @@ 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 (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) { - unsigned long nr_mmu_pages; + if (!kvm->arch.n_requested_mmu_pages) { + unsigned long nr_mmu_pages; - nr_mmu_pages = kvm->arch.n_memslots_pages * - KVM_PERMILLE_MMU_PAGES / 1000; - nr_mmu_pages = max(nr_mmu_pages, KVM_MIN_ALLOC_MMU_PAGES); - kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages); + nr_mmu_pages = kvm->arch.n_memslots_pages * + KVM_PERMILLE_MMU_PAGES / 1000; + nr_mmu_pages = max(nr_mmu_pages, KVM_MIN_ALLOC_MMU_PAGES); + kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages); + } } kvm_mmu_slot_apply_flags(kvm, old, new, change);