Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1026940yba; Thu, 4 Apr 2019 02:44:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjB/xs99n5I+yd1LenRYQrNDIsFZBG0YdoOKaTkAfs9N7qJ7NBBLL8iEDQH0iXzSR6O3PU X-Received: by 2002:a63:4e64:: with SMTP id o36mr4916500pgl.213.1554371085560; Thu, 04 Apr 2019 02:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554371085; cv=none; d=google.com; s=arc-20160816; b=fig9vZnhrLqgtZt7kkaRakXqfxpuTKiAbw4Vb3p+pCI07zo4jd+TiVAOvpwtArgiVs l1qH/lYMvqrKgCw1qzyzqLFIvalqTluaN7/L0bb3L7aiZmzL57Gp4+E1+h8PufD/Pw3J kAHJSOx6buskETa+juSKtY308ngR1HNWfG7ASgCdyt/10u4r0gSnduW14zgXM+mLYcah vbZKcv3jb/XLJFjPKDCnXEvU+Rd97L03zL/o5vBIDXG6ZmczsEbRcJQg5Wm3OUvE82vK dVvzcNZUOrM6077ZVxHqmZAhjYgtx/xZWyVnCtX8rOk8d0T1PRAgRQnXniG8q+0vDuNo bWyg== 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=nttmCCDHVih27+EBfW6Moansq1+NFrlr0dnEguRzwk8=; b=mwgV0ks/xj6+sgyeS5u81iyIeirIWb5HL0JSMTQ2BaVSTTOBByHMFTyOUd3RCjmHYv 7ZvW2uPmIwjxtQkUJQmjuhds3DZzQmzDYPXrh5bQdRQ7X0CQFHOsIvbXTyCsKmrAl1jJ 7TltCsxYXgQVp9HCxDgIiM4b3hyVsGSQoZpJctuKwno0aAwnQ53nwDkZo2IALqk3JMFB LVLppMUPiouaV3hVptSK4npQ/DngHxAII0ID1MO6s7ir/IjySUlca4IibBv835etuurn TycvxEPUARy2Xfchct1sR5Xm5zJ0rONtpiRQA+xAnJ22hI8a49OjdSaOpuo1AXDX14cP 6cBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ok+5kLZN; 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 o123si16556038pfb.116.2019.04.04.02.44.29; Thu, 04 Apr 2019 02:44:45 -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=ok+5kLZN; 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 S1731222AbfDDJAT (ORCPT + 99 others); Thu, 4 Apr 2019 05:00:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:36918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731218AbfDDJAQ (ORCPT ); Thu, 4 Apr 2019 05:00:16 -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 EDA8121741; Thu, 4 Apr 2019 09:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368415; bh=zeI2Mr5uTrqyG+8bbO4n7HhAWHE1qVNaciqDtlRm9cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ok+5kLZNbl/2ellZdk37BnEmDJu6kwQsgp6BX7ffI2V9Yp3H+bq18fdNjEtWbGtgP RB+MK+bhGqa9D0Zm3UgfpSufT/fzkB7DjaAYUv74D2xToQ0d86p8rt6i++tFdMf6JS pUguzY0U/v/9nlLqI/gXO+gCNzFyKTk4qe/Bl4JA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Catalin Marinas , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 031/187] mm/slab.c: kmemleak no scan alien caches Date: Thu, 4 Apr 2019 10:46:08 +0200 Message-Id: <20190404084604.534211048@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 92d1d07daad65c300c7d0b68bbef8867e9895d54 ] Kmemleak throws endless warnings during boot due to in __alloc_alien_cache(), alc = kmalloc_node(memsize, gfp, node); init_arraycache(&alc->ac, entries, batch); kmemleak_no_scan(ac); Kmemleak does not track the array cache (alc->ac) but the alien cache (alc) instead, so let it track the latter by lifting kmemleak_no_scan() out of init_arraycache(). There is another place that calls init_arraycache(), but alloc_kmem_cache_cpus() uses the percpu allocation where will never be considered as a leak. kmemleak: Found object by alias at 0xffff8007b9aa7e38 CPU: 190 PID: 1 Comm: swapper/0 Not tainted 5.0.0-rc2+ #2 Call trace: dump_backtrace+0x0/0x168 show_stack+0x24/0x30 dump_stack+0x88/0xb0 lookup_object+0x84/0xac find_and_get_object+0x84/0xe4 kmemleak_no_scan+0x74/0xf4 setup_kmem_cache_node+0x2b4/0x35c __do_tune_cpucache+0x250/0x2d4 do_tune_cpucache+0x4c/0xe4 enable_cpucache+0xc8/0x110 setup_cpu_cache+0x40/0x1b8 __kmem_cache_create+0x240/0x358 create_cache+0xc0/0x198 kmem_cache_create_usercopy+0x158/0x20c kmem_cache_create+0x50/0x64 fsnotify_init+0x58/0x6c do_one_initcall+0x194/0x388 kernel_init_freeable+0x668/0x688 kernel_init+0x18/0x124 ret_from_fork+0x10/0x18 kmemleak: Object 0xffff8007b9aa7e00 (size 256): kmemleak: comm "swapper/0", pid 1, jiffies 4294697137 kmemleak: min_count = 1 kmemleak: count = 0 kmemleak: flags = 0x1 kmemleak: checksum = 0 kmemleak: backtrace: kmemleak_alloc+0x84/0xb8 kmem_cache_alloc_node_trace+0x31c/0x3a0 __kmalloc_node+0x58/0x78 setup_kmem_cache_node+0x26c/0x35c __do_tune_cpucache+0x250/0x2d4 do_tune_cpucache+0x4c/0xe4 enable_cpucache+0xc8/0x110 setup_cpu_cache+0x40/0x1b8 __kmem_cache_create+0x240/0x358 create_cache+0xc0/0x198 kmem_cache_create_usercopy+0x158/0x20c kmem_cache_create+0x50/0x64 fsnotify_init+0x58/0x6c do_one_initcall+0x194/0x388 kernel_init_freeable+0x668/0x688 kernel_init+0x18/0x124 kmemleak: Not scanning unknown object at 0xffff8007b9aa7e38 CPU: 190 PID: 1 Comm: swapper/0 Not tainted 5.0.0-rc2+ #2 Call trace: dump_backtrace+0x0/0x168 show_stack+0x24/0x30 dump_stack+0x88/0xb0 kmemleak_no_scan+0x90/0xf4 setup_kmem_cache_node+0x2b4/0x35c __do_tune_cpucache+0x250/0x2d4 do_tune_cpucache+0x4c/0xe4 enable_cpucache+0xc8/0x110 setup_cpu_cache+0x40/0x1b8 __kmem_cache_create+0x240/0x358 create_cache+0xc0/0x198 kmem_cache_create_usercopy+0x158/0x20c kmem_cache_create+0x50/0x64 fsnotify_init+0x58/0x6c do_one_initcall+0x194/0x388 kernel_init_freeable+0x668/0x688 kernel_init+0x18/0x124 ret_from_fork+0x10/0x18 Link: http://lkml.kernel.org/r/20190129184518.39808-1-cai@lca.pw Fixes: 1fe00d50a9e8 ("slab: factor out initialization of array cache") Signed-off-by: Qian Cai Reviewed-by: Andrew Morton Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Catalin Marinas Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/slab.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 364e42d5a399..b8e0ec74330f 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -563,14 +563,6 @@ static void start_cpu_timer(int cpu) static void init_arraycache(struct array_cache *ac, int limit, int batch) { - /* - * The array_cache structures contain pointers to free object. - * However, when such objects are allocated or transferred to another - * cache the pointers are not cleared and they could be counted as - * valid references during a kmemleak scan. Therefore, kmemleak must - * not scan such objects. - */ - kmemleak_no_scan(ac); if (ac) { ac->avail = 0; ac->limit = limit; @@ -586,6 +578,14 @@ static struct array_cache *alloc_arraycache(int node, int entries, struct array_cache *ac = NULL; ac = kmalloc_node(memsize, gfp, node); + /* + * The array_cache structures contain pointers to free object. + * However, when such objects are allocated or transferred to another + * cache the pointers are not cleared and they could be counted as + * valid references during a kmemleak scan. Therefore, kmemleak must + * not scan such objects. + */ + kmemleak_no_scan(ac); init_arraycache(ac, entries, batchcount); return ac; } @@ -680,6 +680,7 @@ static struct alien_cache *__alloc_alien_cache(int node, int entries, alc = kmalloc_node(memsize, gfp, node); if (alc) { + kmemleak_no_scan(alc); init_arraycache(&alc->ac, entries, batch); spin_lock_init(&alc->lock); } -- 2.19.1