mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: fuqiang wang <fuqiang.wng@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: fuqiang wang <fuqiang.wng@gmail.com>,
	yaowenchao1 <yaowenchao@jd.com>, dongxu zhang <xu910121@sina.com>
Subject: [PATCH] KVM: x86/mmu: Respect user goal_nr_mmu_pages after zapping oldest pages
Date: Fri, 11 Sep 2026 14:41:12 +0800	[thread overview]
Message-ID: <20260911064112.10766-1-fuqiang.wng@gmail.com> (raw)

When kvm_mmu_change_mmu_pages() shrinks the shadow page limit and the
current number of shadow pages exceeds the requested goal, it zaps the
oldest MMU pages and then updates n_max_mmu_pages.

Previously the new limit was set unconditionally to the current
mmu_shadow_pages value observed after zapping. However, zapping can
reduce mmu_shadow_pages below the user-requested goal_nr_mmu_pages,
since a single __kvm_mmu_prepare_zap_page() may reclaim more than one
MMU page (it also zaps unsync/child pages). This could then clamp the
limit below the user's intent.

Use max(mmu_shadow_pages, goal_nr_mmu_pages) so the user-requested goal
is honored even if zapping overshoots.

Signed-off-by: fuqiang wang <fuqiang.wng@gmail.com>
---
 arch/x86/kvm/mmu/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 064ecc33b926..efeba58936a6 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2913,7 +2913,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned long goal_nr_mmu_pages)
 		kvm_mmu_zap_oldest_mmu_pages(kvm, kvm->stat.mmu_shadow_pages -
 						  goal_nr_mmu_pages);
 
-		goal_nr_mmu_pages = kvm->stat.mmu_shadow_pages;
+		goal_nr_mmu_pages = max(kvm->stat.mmu_shadow_pages, goal_nr_mmu_pages);
 	}
 
 	kvm->arch.n_max_mmu_pages = goal_nr_mmu_pages;
-- 
2.47.0


                 reply	other threads:[~2026-09-11  6:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260911064112.10766-1-fuqiang.wng@gmail.com \
    --to=fuqiang.wng@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=xu910121@sina.com \
    --cc=yaowenchao@jd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®