From patchwork Sun Jan 6 19:23:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Abd El Mawgood X-Patchwork-Id: 10749607 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 0696B6C5 for ; Sun, 6 Jan 2019 19:25:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC04A288ED for ; Sun, 6 Jan 2019 19:25:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFAD428918; Sun, 6 Jan 2019 19:25:18 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 12640288ED for ; Sun, 6 Jan 2019 19:25:17 +0000 (UTC) Received: (qmail 18208 invoked by uid 550); 6 Jan 2019 19:25:11 -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 18134 invoked from network); 6 Jan 2019 19:25:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mena-vt-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vs+bNFu0yF1CxUiI9KZwr438wTX73TGD5F830H4iAIA=; b=Wo5h6zjvycB8zOxoh15YyWO9D/VU+c2H5+SKQHj5GUO+LOeXkkB3fwUheyny3S9nPy zJxDbPprk1o11616tJoUP5qpiCqdKEG6SWPS0ItQx/BFvUytSytsYYEnGdnjxjPnuC0p K82M0pXAKU1vPdSYoIkZvs0K+n9i3HIIgUdZFzIDY32Ko7aLNKoNJcpCwnXHWseqGHJq XFsc7Y9kkDo9OcGLf5alQCxW80GW40vo9FUHYTtIt+yE5A+b9bjOXVi0F1C0/q86Go4C njXy8NR5VspfiZo4pi+usTZ1xYvpYdKkoyjDWsaFUhln07pK7hhvA8UZmBVxUzOqtB+a QIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vs+bNFu0yF1CxUiI9KZwr438wTX73TGD5F830H4iAIA=; b=MOIcV3Y6tyLQQggt2XMAv89MNMJUjIKTfVmqEYqgkOrZWsjLgOZHL0wWxni1ReklOi yU5VfnIlAcGXSjN4IFQf6evNmRbd+w3GmEmzUgRihaNCwAA5PR5SsHNhYjziwbKgDxS/ HIaWfaw4H9aBUFRHFFtPOHBk60J0xT5KkEiGIxRlA5PFJGTX7YVV7Wawgm1pYYVV+KTG I3FWdZ6g7Lck+eHi4vwKSKx20P9PORnTEJ3pjD/UvXu6Ut/f4VyhgK/ZidwBhcoPaAtJ T+CsbWerjtgENJDoQhwnxlgyvbnU0Wj8/TKYdC3AscHWNQHCDPp9KAeQy5owTEhq+CWQ +E3g== X-Gm-Message-State: AA+aEWbc0lCLq9RSLUIOIMQTZCwAVzQ3t0Q6FWZDwLXarDfFgu7WnJ5v FiXLvcGN0spu9lJdIk5ELUG8lA== X-Google-Smtp-Source: AFSGD/V2HOGzNw9EglnSRXwlKhwoja1ooRczmbI7hSqUdESJLQKq8KwHufaIjPgSXaKanXnkJTPD0w== X-Received: by 2002:a50:b7d6:: with SMTP id i22mr52061815ede.27.1546802699386; Sun, 06 Jan 2019 11:24:59 -0800 (PST) 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 , Igor Stoppa Cc: Ahmed Abd El Mawgood Subject: [PATCH V8 01/11] KVM: State whether memory should be freed in kvm_free_memslot Date: Sun, 6 Jan 2019 21:23:35 +0200 Message-Id: <20190106192345.13578-2-ahmedsoliman@mena.vt.edu> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190106192345.13578-1-ahmedsoliman@mena.vt.edu> References: <20190106192345.13578-1-ahmedsoliman@mena.vt.edu> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP The conditions upon which kvm_free_memslot are kind of ad-hock, it will be hard to extend memslot with allocatable data that needs to be freed, so I replaced the current mechanism by clear flag that states if the memory slot should be freed. Signed-off-by: Ahmed Abd El Mawgood --- virt/kvm/kvm_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1f888a103f..2f37b4b6a2 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -548,9 +548,10 @@ 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 (!dont || free->dirty_bitmap != dont->dirty_bitmap) + if (change == KVM_MR_DELETE) kvm_destroy_dirty_bitmap(free); kvm_arch_free_memslot(kvm, free, dont); @@ -566,7 +567,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); } @@ -1061,14 +1062,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; }