All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "James Hogan" <jhogan@kernel.org>,
	"Paul Mackerras" <paulus@ozlabs.org>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Janosch Frank" <frankja@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Marc Zyngier" <maz@kernel.org>
Cc: David Hildenbrand <david@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	James Morse <james.morse@arm.com>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org,
	kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org,
	Christoffer Dall <christoffer.dall@arm.com>
Subject: [PATCH v3 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap
Date: Thu, 24 Oct 2019 16:07:35 -0700	[thread overview]
Message-ID: <20191024230744.14543-7-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191024230744.14543-1-sean.j.christopherson@intel.com>

Explicitly free an allocated-but-unused dirty bitmap instead of relying
on kvm_free_memslot() if an error occurs in __kvm_set_memory_region().
There is no longer a need to abuse kvm_free_memslot() to free arch
specific resources as arch specific code is now called only after the
common flow is guaranteed to succeed.  Arch code can still fail, but
it's responsible for its own cleanup in that case.

Eliminating the error path's abuse of kvm_free_memslot() paves the way
for simplifying kvm_free_memslot(), i.e. dropping its @dont param.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 virt/kvm/kvm_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9d6af9044304..a43902d9036d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1030,7 +1030,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
 	slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
 	if (!slots)
-		goto out_free;
+		goto out_bitmap;
 	memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));
 
 	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
@@ -1078,8 +1078,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	if (change == KVM_MR_DELETE || change == KVM_MR_MOVE)
 		slots = install_new_memslots(kvm, as_id, slots);
 	kvfree(slots);
-out_free:
-	kvm_free_memslot(kvm, &new, &old);
+out_bitmap:
+	if (new.dirty_bitmap && !old.dirty_bitmap)
+		kvm_destroy_dirty_bitmap(&new);
 out:
 	return r;
 }
-- 
2.22.0


WARNING: multiple messages have this Message-ID (diff)
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "James Hogan" <jhogan@kernel.org>,
	"Paul Mackerras" <paulus@ozlabs.org>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Janosch Frank" <frankja@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Marc Zyngier" <maz@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Wanpeng Li <wanpengli@tencent.com>,
	kvm@vger.kernel.org, David Hildenbrand <david@redhat.com>,
	Joerg Roedel <joro@8bytes.org>, Cornelia Huck <cohuck@redhat.com>,
	linux-mips@vger.kernel.org,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	linux-kernel@vger.kernel.org, kvm-ppc@vger.kernel.org,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	kvmarm@lists.cs.columbia.edu, Jim Mattson <jmattson@google.com>
Subject: [PATCH v3 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap
Date: Thu, 24 Oct 2019 16:07:35 -0700	[thread overview]
Message-ID: <20191024230744.14543-7-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191024230744.14543-1-sean.j.christopherson@intel.com>

Explicitly free an allocated-but-unused dirty bitmap instead of relying
on kvm_free_memslot() if an error occurs in __kvm_set_memory_region().
There is no longer a need to abuse kvm_free_memslot() to free arch
specific resources as arch specific code is now called only after the
common flow is guaranteed to succeed.  Arch code can still fail, but
it's responsible for its own cleanup in that case.

Eliminating the error path's abuse of kvm_free_memslot() paves the way
for simplifying kvm_free_memslot(), i.e. dropping its @dont param.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 virt/kvm/kvm_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9d6af9044304..a43902d9036d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1030,7 +1030,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
 	slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
 	if (!slots)
-		goto out_free;
+		goto out_bitmap;
 	memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));
 
 	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
@@ -1078,8 +1078,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	if (change == KVM_MR_DELETE || change == KVM_MR_MOVE)
 		slots = install_new_memslots(kvm, as_id, slots);
 	kvfree(slots);
-out_free:
-	kvm_free_memslot(kvm, &new, &old);
+out_bitmap:
+	if (new.dirty_bitmap && !old.dirty_bitmap)
+		kvm_destroy_dirty_bitmap(&new);
 out:
 	return r;
 }
-- 
2.22.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "James Hogan" <jhogan@kernel.org>,
	"Paul Mackerras" <paulus@ozlabs.org>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Janosch Frank" <frankja@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Marc Zyngier" <maz@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Christoffer Dall <christoffer.dall@arm.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	kvm@vger.kernel.org, David Hildenbrand <david@redhat.com>,
	Joerg Roedel <joro@8bytes.org>, Cornelia Huck <cohuck@redhat.com>,
	linux-mips@vger.kernel.org,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	linux-kernel@vger.kernel.org, James Morse <james.morse@arm.com>,
	kvm-ppc@vger.kernel.org, Vitaly Kuznetsov <vkuznets@redhat.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	kvmarm@lists.cs.columbia.edu,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	Jim Mattson <jmattson@google.com>
Subject: [PATCH v3 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap
Date: Thu, 24 Oct 2019 16:07:35 -0700	[thread overview]
Message-ID: <20191024230744.14543-7-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191024230744.14543-1-sean.j.christopherson@intel.com>

Explicitly free an allocated-but-unused dirty bitmap instead of relying
on kvm_free_memslot() if an error occurs in __kvm_set_memory_region().
There is no longer a need to abuse kvm_free_memslot() to free arch
specific resources as arch specific code is now called only after the
common flow is guaranteed to succeed.  Arch code can still fail, but
it's responsible for its own cleanup in that case.

Eliminating the error path's abuse of kvm_free_memslot() paves the way
for simplifying kvm_free_memslot(), i.e. dropping its @dont param.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 virt/kvm/kvm_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9d6af9044304..a43902d9036d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1030,7 +1030,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
 	slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
 	if (!slots)
-		goto out_free;
+		goto out_bitmap;
 	memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));
 
 	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
@@ -1078,8 +1078,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	if (change == KVM_MR_DELETE || change == KVM_MR_MOVE)
 		slots = install_new_memslots(kvm, as_id, slots);
 	kvfree(slots);
-out_free:
-	kvm_free_memslot(kvm, &new, &old);
+out_bitmap:
+	if (new.dirty_bitmap && !old.dirty_bitmap)
+		kvm_destroy_dirty_bitmap(&new);
 out:
 	return r;
 }
-- 
2.22.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "James Hogan" <jhogan@kernel.org>,
	"Paul Mackerras" <paulus@ozlabs.org>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Janosch Frank" <frankja@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Marc Zyngier" <maz@kernel.org>
Cc: David Hildenbrand <david@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	James Morse <james.morse@arm.com>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org,
	kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org,
	Christoffer Dall <christoffer.dall@arm.com>
Subject: [PATCH v3 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap
Date: Thu, 24 Oct 2019 23:07:35 +0000	[thread overview]
Message-ID: <20191024230744.14543-7-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191024230744.14543-1-sean.j.christopherson@intel.com>

Explicitly free an allocated-but-unused dirty bitmap instead of relying
on kvm_free_memslot() if an error occurs in __kvm_set_memory_region().
There is no longer a need to abuse kvm_free_memslot() to free arch
specific resources as arch specific code is now called only after the
common flow is guaranteed to succeed.  Arch code can still fail, but
it's responsible for its own cleanup in that case.

Eliminating the error path's abuse of kvm_free_memslot() paves the way
for simplifying kvm_free_memslot(), i.e. dropping its @dont param.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 virt/kvm/kvm_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9d6af9044304..a43902d9036d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1030,7 +1030,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
 	slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
 	if (!slots)
-		goto out_free;
+		goto out_bitmap;
 	memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));
 
 	if ((change = KVM_MR_DELETE) || (change = KVM_MR_MOVE)) {
@@ -1078,8 +1078,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	if (change = KVM_MR_DELETE || change = KVM_MR_MOVE)
 		slots = install_new_memslots(kvm, as_id, slots);
 	kvfree(slots);
-out_free:
-	kvm_free_memslot(kvm, &new, &old);
+out_bitmap:
+	if (new.dirty_bitmap && !old.dirty_bitmap)
+		kvm_destroy_dirty_bitmap(&new);
 out:
 	return r;
 }
-- 
2.22.0

  parent reply	other threads:[~2019-10-24 23:09 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 23:07 [PATCH v3 00/15] KVM: Dynamically size memslot arrays Sean Christopherson
2019-10-24 23:07 ` Sean Christopherson
2019-10-24 23:07 ` Sean Christopherson
2019-10-24 23:07 ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 01/15] KVM: Reinstall old memslots if arch preparation fails Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 02/15] KVM: Don't free new memslot if allocation of said memslot fails Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 03/15] KVM: PPC: Move memslot memory allocation into prepare_memory_region() Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 04/15] KVM: x86: Allocate memslot resources during prepare_memory_region() Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 05/15] KVM: Drop kvm_arch_create_memslot() Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-12-16  8:04   ` Christian Borntraeger
2019-12-16  8:04     ` Christian Borntraeger
2019-12-16  8:04     ` Christian Borntraeger
2019-12-16  8:04     ` Christian Borntraeger
2019-10-24 23:07 ` Sean Christopherson [this message]
2019-10-24 23:07   ` [PATCH v3 06/15] KVM: Explicitly free allocated-but-unused dirty bitmap Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 07/15] KVM: Refactor error handling for setting memory region Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-12-05  9:49   ` Philippe Mathieu-Daudé
2019-12-05  9:49     ` Philippe Mathieu-Daudé
2019-12-05  9:49     ` Philippe Mathieu-Daudé
2019-12-05  9:49     ` Philippe Mathieu-Daudé
2019-10-24 23:07 ` [PATCH v3 08/15] KVM: Move setting of memslot into helper routine Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-12-05  9:54   ` Philippe Mathieu-Daudé
2019-12-05  9:54     ` Philippe Mathieu-Daudé
2019-12-05  9:54     ` Philippe Mathieu-Daudé
2019-12-05  9:54     ` Philippe Mathieu-Daudé
2019-10-24 23:07 ` [PATCH v3 09/15] KVM: Move memslot deletion to helper function Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 10/15] KVM: Simplify kvm_free_memslot() and all its descendents Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 11/15] KVM: Clean up local variable usage in __kvm_set_memory_region() Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 12/15] KVM: Provide common implementation for generic dirty log functions Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 13/15] KVM: Ensure validity of memslot with respect to kvm_get_dirty_log() Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 14/15] KVM: Terminate memslot walks via used_slots Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07 ` [PATCH v3 15/15] KVM: Dynamically size memslot array based on number of used slots Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-24 23:07   ` Sean Christopherson
2019-10-25 13:28 ` [PATCH v3 00/15] KVM: Dynamically size memslot arrays Christoffer Dall
2019-10-25 13:28   ` Christoffer Dall
2019-10-25 13:28   ` Christoffer Dall
2019-10-25 13:28   ` Christoffer Dall
2019-10-25 16:30 ` Marc Zyngier
2019-10-25 16:30   ` Marc Zyngier
2019-10-25 16:30   ` Marc Zyngier
2019-10-25 16:30   ` Marc Zyngier
2019-12-03 22:14 ` Sean Christopherson
2019-12-03 22:14   ` Sean Christopherson
2019-12-03 22:14   ` Sean Christopherson
2019-12-03 22:14   ` Sean Christopherson
2019-12-13 20:01   ` Sean Christopherson
2019-12-13 20:01     ` Sean Christopherson
2019-12-13 20:01     ` Sean Christopherson
2019-12-13 20:01     ` Sean Christopherson
2019-12-16  8:25     ` Christian Borntraeger
2019-12-16  8:25       ` Christian Borntraeger
2019-12-16  8:25       ` Christian Borntraeger
2019-12-16  8:25       ` Christian Borntraeger
2019-12-17 17:55       ` Sean Christopherson
2019-12-17 17:55         ` Sean Christopherson
2019-12-17 17:55         ` Sean Christopherson
2019-12-17 17:55         ` 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=20191024230744.14543-7-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=borntraeger@de.ibm.com \
    --cc=christoffer.dall@arm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=james.morse@arm.com \
    --cc=jhogan@kernel.org \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=paulus@ozlabs.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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.