Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2538094yba; Mon, 6 May 2019 07:41:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbirnfOac4YGgsmHcQuvPTc1OiXIB9hRezz0bBmw2+JoB+7qjnmePFovg1RLBkjXap1avg X-Received: by 2002:a17:902:b490:: with SMTP id y16mr5337628plr.161.1557153678799; Mon, 06 May 2019 07:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153678; cv=none; d=google.com; s=arc-20160816; b=JceYhGkQzLdF/j8gv40DHkkccKerOlI/6JYJuKJeoYEgPPUK9jiGamut36geHlLqVe vnkX1UBvgx2IyIVllEcJLVwC0L+f3MeWNgp6dwZakbbQ5L4j/QQ0fxbQE/9wYnPedwci TEa4yCpZZfYbuQjfcftSwBkgFM+A+Ae8nAm5G7ajSXDfAJ9w9XRlBL2KxcO/Hw1WvfMZ sE2iPD8JP5zlaZbV2mrS01hMz8W7xmsfi2g52ek0yRucuLcbKCvU5DUNNkfzumAaCrg8 tAFVyblLqfb59yTRBxw1NzskucIw2QEOKyR07enl2m0DyVGqAKYrrbOAKtrTKDzaisAX Vu3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rWXIZoCu/lgMMgd6JFMNmlzBJ2mr+2KezVQgL3rmLn8=; b=cvw4fgvkzdl+//ms2hEVfolcD2FOXB9h9zKAKj5UHAV2lCahkdFl+8kshMzJXZh1Ox OdkIsfYwKA8boLMm0r3eAf3/8r6SLZ83pnRXGBEXPwBheFwHh4KIuk3xDCJnzIBOrwF1 KCvnP09Msd0jivwoxQFVVJGCvf5XMcHOpfTFHT++I57S0QueNnIOFcQu26fEIW7iDfXf nw8E6ckOMKQB7pkUQqFKNyd0BwX5VkvPYO+UNBskUW8eh9MNo/yGsUsUfTz7NGBhwuId TT96bpjqZi0++oNnhnB5UDBLZfQ1snu5hRgXJvtOoZwIVwF1CXTuanXpvGrfT9uN1beV l2hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LXdlg9mP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si15112603pgg.83.2019.05.06.07.40.57; Mon, 06 May 2019 07:41:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LXdlg9mP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727525AbfEFOiH (ORCPT + 99 others); Mon, 6 May 2019 10:38:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:59078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbfEFOiF (ORCPT ); Mon, 6 May 2019 10:38:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE89E214AE; Mon, 6 May 2019 14:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153484; bh=Ks4IhupySPKOGfhYMtULW/Pq6Zqh/yXRgg58Nf33rLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LXdlg9mPwwFrL2Tp6lzokVAgnj6vwJx8etb2tgnUDjKbK0w2VB44AAlJmrifXs55H /bdKsTQXAICvdt+FvnHit9inqBxUwEdJM5e6yS3hS2wAVP5ByJlQwSORk2YHmMRY96 0Eyrfaw/8l3fYge6GLpcdCUhhD0ArhKdK0Ge9MrQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Qian Cai , Paul Mackerras , Benjamin Herrenschmidt , Avi Kivity , Paolo Bonzini , Radim Krcmar , Andrew Morton , Linus Torvalds , "Sasha Levin (Microsoft)" , Michael Ellerman Subject: [PATCH 5.0 075/122] kmemleak: powerpc: skip scanning holes in the .bss section Date: Mon, 6 May 2019 16:32:13 +0200 Message-Id: <20190506143101.613229428@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 298a32b132087550d3fa80641ca58323c5dfd4d9 ] Commit 2d4f567103ff ("KVM: PPC: Introduce kvm_tmp framework") adds kvm_tmp[] into the .bss section and then free the rest of unused spaces back to the page allocator. kernel_init kvm_guest_init kvm_free_tmp free_reserved_area free_unref_page free_unref_page_prepare With DEBUG_PAGEALLOC=y, it will unmap those pages from kernel. As the result, kmemleak scan will trigger a panic when it scans the .bss section with unmapped pages. This patch creates dedicated kmemleak objects for the .data, .bss and potentially .data..ro_after_init sections to allow partial freeing via the kmemleak_free_part() in the powerpc kvm_free_tmp() function. Link: http://lkml.kernel.org/r/20190321171917.62049-1-catalin.marinas@arm.com Signed-off-by: Catalin Marinas Reported-by: Qian Cai Acked-by: Michael Ellerman (powerpc) Tested-by: Qian Cai Cc: Paul Mackerras Cc: Benjamin Herrenschmidt Cc: Avi Kivity Cc: Paolo Bonzini Cc: Radim Krcmar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin (Microsoft) --- arch/powerpc/kernel/kvm.c | 7 +++++++ mm/kmemleak.c | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c index 683b5b3805bd..cd381e2291df 100644 --- a/arch/powerpc/kernel/kvm.c +++ b/arch/powerpc/kernel/kvm.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -712,6 +713,12 @@ static void kvm_use_magic_page(void) static __init void kvm_free_tmp(void) { + /* + * Inform kmemleak about the hole in the .bss section since the + * corresponding pages will be unmapped with DEBUG_PAGEALLOC=y. + */ + kmemleak_free_part(&kvm_tmp[kvm_tmp_index], + ARRAY_SIZE(kvm_tmp) - kvm_tmp_index); free_reserved_area(&kvm_tmp[kvm_tmp_index], &kvm_tmp[ARRAY_SIZE(kvm_tmp)], -1, NULL); } diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 707fa5579f66..6c318f5ac234 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1529,11 +1529,6 @@ static void kmemleak_scan(void) } rcu_read_unlock(); - /* data/bss scanning */ - scan_large_block(_sdata, _edata); - scan_large_block(__bss_start, __bss_stop); - scan_large_block(__start_ro_after_init, __end_ro_after_init); - #ifdef CONFIG_SMP /* per-cpu sections scanning */ for_each_possible_cpu(i) @@ -2071,6 +2066,17 @@ void __init kmemleak_init(void) } local_irq_restore(flags); + /* register the data/bss sections */ + create_object((unsigned long)_sdata, _edata - _sdata, + KMEMLEAK_GREY, GFP_ATOMIC); + create_object((unsigned long)__bss_start, __bss_stop - __bss_start, + KMEMLEAK_GREY, GFP_ATOMIC); + /* only register .data..ro_after_init if not within .data */ + if (__start_ro_after_init < _sdata || __end_ro_after_init > _edata) + create_object((unsigned long)__start_ro_after_init, + __end_ro_after_init - __start_ro_after_init, + KMEMLEAK_GREY, GFP_ATOMIC); + /* * This is the point where tracking allocations is safe. Automatic * scanning is started during the late initcall. Add the early logged -- 2.20.1