Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757080AbbFQQSq (ORCPT ); Wed, 17 Jun 2015 12:18:46 -0400 Received: from mail-ob0-f179.google.com ([209.85.214.179]:35958 "EHLO mail-ob0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754490AbbFQQSi (ORCPT ); Wed, 17 Jun 2015 12:18:38 -0400 From: Larry Finger To: Tejun Heo Cc: Larry Finger , Martin KaFai Lau , Catalin Marinas , Christoph Lameter , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Subject: [PATCH V2] mm: kmemleak_alloc_percpu() should follow the gfp from Date: Wed, 17 Jun 2015 11:18:20 -0500 Message-Id: <1434557900-7965-1-git-send-email-Larry.Finger@lwfinger.net> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5391 Lines: 128 Beginning at commit d52d3997f843 ("ipv6: Create percpu rt6_info"), the following INFO splat is logged: =============================== [ INFO: suspicious RCU usage. ] 4.1.0-rc7-next-20150612 #1 Not tainted ------------------------------- kernel/sched/core.c:7318 Illegal context switch in RCU-bh read-side critical section! other info that might help us debug this: rcu_scheduler_active = 1, debug_locks = 0 3 locks held by systemd/1: #0: (rtnl_mutex){+.+.+.}, at: [] rtnetlink_rcv+0x1f/0x40 #1: (rcu_read_lock_bh){......}, at: [] ipv6_add_addr+0x62/0x540 #2: (addrconf_hash_lock){+...+.}, at: [] ipv6_add_addr+0x184/0x540 stack backtrace: CPU: 0 PID: 1 Comm: systemd Not tainted 4.1.0-rc7-next-20150612 #1 Hardware name: TOSHIBA TECRA A50-A/TECRA A50-A, BIOS Version 4.20 04/17/2014 0000000000000001 ffff880224e07838 ffffffff817263a4 ffffffff810ccf2a ffff880224e08000 ffff880224e07868 ffffffff810b6827 0000000000000000 ffffffff81a445d3 00000000000004f4 ffff88022682e100 ffff880224e07898 Call Trace: [] dump_stack+0x4c/0x6e [] ? console_unlock+0x1ca/0x510 [] lockdep_rcu_suspicious+0xe7/0x120 [] ___might_sleep+0x1d5/0x1f0 [] __might_sleep+0x4d/0x90 [] ? create_object+0x39/0x2e0 [] kmem_cache_alloc+0x47/0x250 [] ? find_next_zero_bit+0x1e/0x20 [] create_object+0x39/0x2e0 [] ? mark_held_locks+0x66/0x90 [] ? _raw_spin_unlock_irqrestore+0x4b/0x60 [] kmemleak_alloc_percpu+0x61/0xe0 [] pcpu_alloc+0x370/0x630 Additional backtrace lines are truncated. In addition, the above splat is followed by several "BUG: sleeping function called from invalid context at mm/slub.c:1268" outputs. As suggested by Martin KaFai Lau, these are the clue to the fix. Routine kmemleak_alloc_percpu() always uses GFP_KERNEL for its allocations, whereas it should follow the gfp from its callers. Reviewed-by: Catalin Marinas Reviewed-by: Kamalesh Babulal Signed-off-by: Larry Finger Cc: Martin KaFai Lau Cc: Catalin Marinas To: Tejun Heo Cc: Christoph Lameter Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: # v3.18+ Acked-by: Martin KaFai Lau --- V2 - Remove extraneous file added by mistake as noted by Catalin and Kamalesh Comment revised and Stable added as suggested by Catalin Wording changes in commit message suggested by Martin --- include/linux/kmemleak.h | 3 ++- mm/kmemleak.c | 9 +++++---- mm/percpu.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h index e705467..ec4437b 100644 --- a/include/linux/kmemleak.h +++ b/include/linux/kmemleak.h @@ -28,7 +28,8 @@ extern void kmemleak_init(void) __ref; extern void kmemleak_alloc(const void *ptr, size_t size, int min_count, gfp_t gfp) __ref; -extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size) __ref; +extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size, + gfp_t gfp) __ref; extern void kmemleak_free(const void *ptr) __ref; extern void kmemleak_free_part(const void *ptr, size_t size) __ref; extern void kmemleak_free_percpu(const void __percpu *ptr) __ref; diff --git a/mm/kmemleak.c b/mm/kmemleak.c index ca9e5a5..cf79f11 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -930,12 +930,13 @@ EXPORT_SYMBOL_GPL(kmemleak_alloc); * kmemleak_alloc_percpu - register a newly allocated __percpu object * @ptr: __percpu pointer to beginning of the object * @size: size of the object + * @gfp: flags used for kmemleak internal memory allocations * * This function is called from the kernel percpu allocator when a new object - * (memory block) is allocated (alloc_percpu). It assumes GFP_KERNEL - * allocation. + * (memory block) is allocated (alloc_percpu). */ -void __ref kmemleak_alloc_percpu(const void __percpu *ptr, size_t size) +void __ref kmemleak_alloc_percpu(const void __percpu *ptr, size_t size, + gfp_t gfp) { unsigned int cpu; @@ -948,7 +949,7 @@ void __ref kmemleak_alloc_percpu(const void __percpu *ptr, size_t size) if (kmemleak_enabled && ptr && !IS_ERR(ptr)) for_each_possible_cpu(cpu) create_object((unsigned long)per_cpu_ptr(ptr, cpu), - size, 0, GFP_KERNEL); + size, 0, gfp); else if (kmemleak_early_log) log_early(KMEMLEAK_ALLOC_PERCPU, ptr, size, 0); } diff --git a/mm/percpu.c b/mm/percpu.c index dfd0248..2dd7448 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1030,7 +1030,7 @@ area_found: memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size); ptr = __addr_to_pcpu_ptr(chunk->base_addr + off); - kmemleak_alloc_percpu(ptr, size); + kmemleak_alloc_percpu(ptr, size, gfp); return ptr; fail_unlock: -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/