All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>,
	kvm@vger.kernel.org, David Matlack <dmatlack@google.com>
Subject: [PATCH 1/2] KVM: Keep track of the number of memslots with dirty logging enabled
Date: Thu, 27 Oct 2022 13:03:15 -0700	[thread overview]
Message-ID: <20221027200316.2221027-2-dmatlack@google.com> (raw)
In-Reply-To: <20221027200316.2221027-1-dmatlack@google.com>

Add a new field to struct kvm that keeps track of the number of memslots
with dirty logging enabled. This will be used in a future commit to
cheaply check if any memslot is doing dirty logging.

Signed-off-by: David Matlack <dmatlack@google.com>
---
 include/linux/kvm_host.h |  2 ++
 virt/kvm/kvm_main.c      | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 32f259fa5801..25ed8c1725ff 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -709,6 +709,8 @@ struct kvm {
 	struct kvm_memslots __memslots[KVM_ADDRESS_SPACE_NUM][2];
 	/* The current active memslot set for each address space */
 	struct kvm_memslots __rcu *memslots[KVM_ADDRESS_SPACE_NUM];
+	/* The number of memslots with dirty logging enabled. */
+	int nr_memslots_dirty_logging;
 	struct xarray vcpu_array;
 
 	/* Used to wait for completion of MMU notifiers.  */
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e30f1b4ecfa5..57e4406005cd 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1641,6 +1641,9 @@ static void kvm_commit_memory_region(struct kvm *kvm,
 				     const struct kvm_memory_slot *new,
 				     enum kvm_mr_change change)
 {
+	int old_flags = old ? old->flags : 0;
+	int new_flags = new ? new->flags : 0;
+
 	/*
 	 * Update the total number of memslot pages before calling the arch
 	 * hook so that architectures can consume the result directly.
@@ -1650,6 +1653,13 @@ static void kvm_commit_memory_region(struct kvm *kvm,
 	else if (change == KVM_MR_CREATE)
 		kvm->nr_memslot_pages += new->npages;
 
+	if ((old_flags ^ new_flags) & KVM_MEM_LOG_DIRTY_PAGES) {
+		if (new_flags & KVM_MEM_LOG_DIRTY_PAGES)
+			kvm->nr_memslots_dirty_logging++;
+		else
+			kvm->nr_memslots_dirty_logging--;
+	}
+
 	kvm_arch_commit_memory_region(kvm, old, new, change);
 
 	switch (change) {
-- 
2.38.1.273.g43a17bfeac-goog


  reply	other threads:[~2022-10-27 20:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 20:03 [PATCH 0/2] KVM: x86/mmu: Do not recover NX Huge Pages when dirty logging is enabled David Matlack
2022-10-27 20:03 ` David Matlack [this message]
2022-10-27 20:34   ` [PATCH 1/2] KVM: Keep track of the number of memslots with dirty logging enabled Sean Christopherson
2022-10-27 22:15     ` David Matlack
2022-10-27 23:04       ` Sean Christopherson
2022-10-27 20:03 ` [PATCH 2/2] KVM: x86/mmu: Do not recover NX Huge Pages when dirty logging is enabled David Matlack
2022-10-28 10:58 ` [PATCH 0/2] " Paolo Bonzini
2022-10-28 20:05   ` David Matlack
2022-10-28 21:07     ` Sean Christopherson
2022-10-28 21:24       ` David Matlack
2022-10-28 21:42         ` Sean Christopherson

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=20221027200316.2221027-2-dmatlack@google.com \
    --to=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.