From patchwork Sun Nov 4 17:11:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Soliman X-Patchwork-Id: 10666935 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 B3E5D13A4 for ; Sun, 4 Nov 2018 17:12:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AEE0295AE for ; Sun, 4 Nov 2018 17:12:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F19B295CB; Sun, 4 Nov 2018 17:12:33 +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 C57F0295AE for ; Sun, 4 Nov 2018 17:12:32 +0000 (UTC) Received: (qmail 28471 invoked by uid 550); 4 Nov 2018 17:12:27 -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 28416 invoked from network); 4 Nov 2018 17:12:26 -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=K83MXMKnKynCqSGpEAGqilub5PPGoz3eEK23HTZ8YhQ=; b=N6FGvY/NYAFUMsnDD39lrWWLMzDPDQefmYJ5naoiet50aA1WqSrX/XiC87EeZffT39 AoSx98S6LP4rPzTSnKsDcHh8LvtW0TIWKY3ut77+680gFsIUvv/GvXAwPnqIMbMgIUdB hMrGE5YgbvJvdOXZdjHLJ18y2Jkx+tGui/E1z1/rm7VZPepjIzecEwXk8+V2SAkB3k9w Wq8f8Aqny9zZ4RjW8JyjDb6uQ9xnx7TTh4L9qcEdqZPRMtqzhppTRkHLFvwKnFGf0qy6 skt/Lft055jd200W9tNnj0yN2mimBBToElCDjc/QR1b5LgJHfyrOVRt/rX/xXZwQAfUo zT9Q== 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=K83MXMKnKynCqSGpEAGqilub5PPGoz3eEK23HTZ8YhQ=; b=M1eQBGwCo0iS4wypSUYzVrP2UJWjWUKOQ5k8h/uP70gzExCG1DQve/J5yAljKnWriT bzanTdkJ0pY+5seyLMdNBfUfLs1t5uybeeVgzKZvRjXRsWWJ9sPXRwQKLTWha1FNOyLe c71dVPWluGGVAHz76aqqf4PFpT0eUZEZpHkM1u831Xm6+ASyvDUcePdqZTLFXl/WLUYc LDleXhprgK+2TzsbdGG2k+OdHS0/1I7bN5jGB99YzJiE9TubbcPWyhnsJOrcS60iIixB q9hylY5gJGn2QHh7y+8BjeWIirHgwm7ogfUdJCV6ZSLqo+XGaFlSUYdZsd1aBtU2b2ZW 8mgQ== X-Gm-Message-State: AGRZ1gK/Sjp6ex8pikK2ZRMaAe0SzDNQ/9LneruNPEB2WPOWEUFxXL3A K6KuwVcPAOY5OGctLJJlq7E= X-Google-Smtp-Source: AJdET5cQ3WZTW+AYb94a97tNBct6qOTGljjvw5Vecie00821Zbfei8diLvIUTGbfbdyRro7e8kTPQA== X-Received: by 2002:a1c:2e50:: with SMTP id u77-v6mr3889431wmu.106.1541351534712; Sun, 04 Nov 2018 09:12:14 -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 , Hossam Hassan <7ossam9063@gmail.com>, "Ahmed Lotfy igor . stoppa @ gmail . com" Subject: [PATCH V6 1/8] KVM: State whether memory should be freed in kvm_free_memslot Date: Sun, 4 Nov 2018 19:11:17 +0200 Message-Id: <20181104171124.5717-2-ahmedsoliman0x666@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181104171124.5717-1-ahmedsoliman0x666@gmail.com> References: <20181104171124.5717-1-ahmedsoliman0x666@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP The conditions upon which kvm_free_memslot are kind of confusing, it will be hard to extend memslot with allocatable data that needs to be freed, so I replaced the current mechanism by the change flag, it states if the memory slot should be freed or not. 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 2679e476b6c3..039c1ef9a786 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -549,9 +549,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); @@ -567,7 +568,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); } @@ -1063,14 +1064,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; }