From patchwork Sun Jan 20 23:39:30 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: 10772531 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 DAB4417E9 for ; Sun, 20 Jan 2019 23:41:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA4E229CB1 for ; Sun, 20 Jan 2019 23:41:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBF3D29CC0; Sun, 20 Jan 2019 23:41:24 +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 F0E7329CB1 for ; Sun, 20 Jan 2019 23:41:23 +0000 (UTC) Received: (qmail 25867 invoked by uid 550); 20 Jan 2019 23:41:17 -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 25808 invoked from network); 20 Jan 2019 23:41:17 -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=oQMSxgeWwvX3fxnLAJIhrPzeISSSa757Vq1K2z2xXFfbGMJNm+mNFmdOPlzRygbHlM 5zGbjPbW/hSEvWy7F/KCTZPeDnl5hL7P+Eii3cu15r4wxdMTY/0ArkUF1lrhPq5GTHH5 41MAsV9b64OSoAX8RNfLkmyk8/yZ/7splCiI41pnzF41mDlZ23BPaAhUKQYcLqO5RvrO liU9DxfBLkv4OPAlj3EIOvJxvWAiT60VeLXoQLD+nF5QpktvP0XtDD2hWckJMVWt8cYH W9VbmZW81UdFbBnNEYvZOG3QTqFEgACaCl4c0Xu8L/9eZnihyWQvBa2cjjWc3oeG0thY CXSQ== 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=jySDNmX8jihA59tRNZvebb6yD3hd+e0BwrgLQqqkwqrPctmjEBnlM8fCMaluQK5A5q /fmFKOvYsGxRXpEirEshdN75Nxdig04lBR6FZVZmi7qNdnRzBzZhNJl852VaWJHclHXM wMcTWHomLYYMmRzOBXhNll1hX5byokf0Js8ygDAz8BTjEERcw/uqVAOaCa0yOLPrcgvg 93GmXLbmFJfneAkcEzk6oR+8/0Y0WkUVsVC2l/F/DLt5YDTJI4O3bcVyez8HdK4y4qYK ZovG1JFZL/uXhzRq4RVa6ydrBA47k4GmlcmV7HjOTmMLRhifbK1fqreTTgNH6D3O9JuZ 5APQ== X-Gm-Message-State: AJcUukfu/Nv+P6Huq5Ubwt7syViJXPuaWhsu2iw0uRiJ61eLrDm41Nvk hubcFS4QL5hfKRZp5MW4tLQsIw== X-Google-Smtp-Source: ALg8bN5FZlmXzIT2hTz+cxotHPasI5Ywv/1TMW+F1EmUBuKhIt3uhvjkzNB2etOELjfHhmG1GUQ/rQ== X-Received: by 2002:adf:f605:: with SMTP id t5mr24033912wrp.229.1548027665620; Sun, 20 Jan 2019 15:41:05 -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: [RESEND PATCH V8 01/11] KVM: State whether memory should be freed in kvm_free_memslot Date: Mon, 21 Jan 2019 01:39:30 +0200 Message-Id: <20190120233940.15282-2-ahmedsoliman@mena.vt.edu> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190120233940.15282-1-ahmedsoliman@mena.vt.edu> References: <20190120233940.15282-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; }