From patchwork Fri Oct 26 15:12:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Soliman X-Patchwork-Id: 10657589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83E4217DE for ; Fri, 26 Oct 2018 15:19:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 775732C9DA for ; Fri, 26 Oct 2018 15:19:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B4732C9DC; Fri, 26 Oct 2018 15:19:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id A1E7F2C9DA for ; Fri, 26 Oct 2018 15:19:13 +0000 (UTC) Received: (qmail 13795 invoked by uid 550); 26 Oct 2018 15:19:12 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 13767 invoked from network); 26 Oct 2018 15:19:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=yE/YW6fK24VOhbIjt3XPpOViKqn92I+EGRJYSjO4hqg=; b=Fnuy5daA47mKSFuxswUk3qDfHCTbtlSFXMbP+RMdhCukppkmlS6mj6bPnfdMuwJino A+sa3lfvkb7o4LfPFDPLx+8RfgqBOHspU/V7bPT4HtLjHEGp+DGHOV2JfGToIgaKfsgc Z8km+ee4mx1nNKn/YUfYGKPshTEoy1meXXpUnqANqFj2JaKiGW63HjY+pa/BVKhJKxpQ gHN3HtO0w4qvsZFlzVKLqrb/5Tx0wvoRu2NrSrCNAoOZADtsKjH/s3fttM1uE7YRx+He 5Cw/mNPGz/gbGFnQblq5ULZzafdKWTEGhCwHnXkHs+Iqi3ei9B9iQb/yFbqJNcu2bcbE 1RXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yE/YW6fK24VOhbIjt3XPpOViKqn92I+EGRJYSjO4hqg=; b=Hhw2VreksItzTnBGNiR9CwKghRkDLxCuyhp1PdssjBEc+RKnORaB+FvHAv8q1/8KBo jgKugAoUmbVo8fuj9o0Y41RkkkWdwP1DshOgd8gMgKNw/8HZLfuD1PRELFwU19RIJNsj PbIQTBG/W/YgaLCzc/yohOadY6KJVAgzLrPz9BUNxcYRMaLqqcSN3g4EiUub/xbdlsR1 bGHV1ws56c6rS7OWP7ru+qovbbgpS5q7V5SceKJseWRDHOBpRiAiLN0bFr6mIbuQWrM4 KbZUEe44rvaRkOtf3rD+cgqG3lgHJDo7kKGhRgZzJrLvT1u8E9wG5Wyd3Ak2cnIsg4Ex m/7w== X-Gm-Message-State: AGRZ1gLKSbqt6ZDQUL9uJs67Wy2tA6DxZX0g1AdTJlaDqVYNGrKKGUIX W+PyNrSZYIJKbsxMh84SxcA= X-Google-Smtp-Source: AJdET5fwUQRKfoSaQ3JHCKlrr+Y/fJUhljyg+itVp3J3K2iw/l+QS43s1w5/Wgsi/DImjb4FUa0dHQ== X-Received: by 2002:adf:db8e:: with SMTP id u14-v6mr6251764wri.217.1540567139748; Fri, 26 Oct 2018 08:18:59 -0700 (PDT) From: Ahmed Abd El Mawgood To: Paolo Bonzini , rkrcmar@redhat.com, Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, ahmedsoliman0x666@gmail.com, ovich00@gmail.com, kernel-hardening@lists.openwall.com, nigel.edwards@hpe.com, Boris Lukashev , Hossam Hassan <7ossam9063@gmail.com>, Ahmed Lotfy Subject: [PATCH V5 5/5] KVM: Small Refactoring to kvm_free_memslot Date: Fri, 26 Oct 2018 17:12:23 +0200 Message-Id: <20181026151223.16810-6-ahmedsoliman0x666@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181026151223.16810-1-ahmedsoliman0x666@gmail.com> References: <20181026151223.16810-1-ahmedsoliman0x666@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP This should be a little bit more readable and prone to memory leaks Signed-off-by: Ahmed Abd El Mawgood --- virt/kvm/kvm_main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2d3011e8490e..79c98db03c84 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -550,11 +550,11 @@ static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot) * Free any memory in @free but not in @dont. */ static void kvm_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, - struct kvm_memory_slot *dont) + struct kvm_memory_slot *dont, + enum kvm_mr_change change) { + if (change == KVM_MR_DELETE) { #ifdef CONFIG_KVM_ROE - if (!dont) { - //TODO still this might leak struct protected_chunk *pos, *n; struct list_head *head = free->prot_list; kvfree(free->roe_bitmap); @@ -564,10 +564,9 @@ static void kvm_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, kvfree(pos); } kvfree(free->prot_list); - } #endif - if (!dont || free->dirty_bitmap != dont->dirty_bitmap) kvm_destroy_dirty_bitmap(free); + } kvm_arch_free_memslot(kvm, free, dont); @@ -582,7 +581,7 @@ static void kvm_free_memslots(struct kvm *kvm, struct kvm_memslots *slots) return; kvm_for_each_memslot(memslot, slots) - kvm_free_memslot(kvm, memslot, NULL); + kvm_free_memslot(kvm, memslot, NULL, KVM_MR_DELETE); kvfree(slots); } @@ -1100,14 +1099,14 @@ int __kvm_set_memory_region(struct kvm *kvm, kvm_arch_commit_memory_region(kvm, mem, &old, &new, change); - kvm_free_memslot(kvm, &old, &new); + kvm_free_memslot(kvm, &old, &new, change); kvfree(old_memslots); return 0; out_slots: kvfree(slots); out_free: - kvm_free_memslot(kvm, &new, &old); + kvm_free_memslot(kvm, &new, &old, change); out: return r; }