diff mbox series

[RESEND] KVM: X86: conditionally call the release operation of memslot rmap

Message ID 20240731093129.46143-1-flyingpeng@tencent.com (mailing list archive)
State New, archived
Headers show
Series [RESEND] KVM: X86: conditionally call the release operation of memslot rmap | expand

Commit Message

Hao Peng July 31, 2024, 9:31 a.m. UTC
From: Peng Hao <flyingpeng@tencent.com>

memslot_rmap_alloc is called when kvm_memslot_have_rmaps is enabled,
so memslot_rmap_free in the exception process should also be called
under the same conditions.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 arch/x86/kvm/x86.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini July 31, 2024, 9:53 a.m. UTC | #1
On Wed, Jul 31, 2024 at 11:31 AM <flyingpenghao@gmail.com> wrote:
>
> From: Peng Hao <flyingpeng@tencent.com>
>
> memslot_rmap_alloc is called when kvm_memslot_have_rmaps is enabled,
> so memslot_rmap_free in the exception process should also be called
> under the same conditions.
>
> Signed-off-by: Peng Hao <flyingpeng@tencent.com>

The cost of this is basically irrelevant; in fact the same
unconditional call is present in kvm_arch_free_memslot().

However, changing kvm_alloc_memslot_metadata's out_free label to call
kvm_arch_free_memslot(slot) could be a small but valid cleanup.

Paolo

> ---
>  arch/x86/kvm/x86.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index af6c8cf6a37a..00a1d96699b8 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -12947,7 +12947,8 @@ static int kvm_alloc_memslot_metadata(struct kvm *kvm,
>         return 0;
>
>  out_free:
> -       memslot_rmap_free(slot);
> +       if (kvm_memslots_have_rmaps(kvm))
> +               memslot_rmap_free(slot);
>
>         for (i = 1; i < KVM_NR_PAGE_SIZES; ++i) {
>                 vfree(slot->arch.lpage_info[i - 1]);
> --
> 2.27.0
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index af6c8cf6a37a..00a1d96699b8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12947,7 +12947,8 @@  static int kvm_alloc_memslot_metadata(struct kvm *kvm,
 	return 0;
 
 out_free:
-	memslot_rmap_free(slot);
+	if (kvm_memslots_have_rmaps(kvm))
+		memslot_rmap_free(slot);
 
 	for (i = 1; i < KVM_NR_PAGE_SIZES; ++i) {
 		vfree(slot->arch.lpage_info[i - 1]);