Received: by 10.223.164.202 with SMTP id h10csp2730182wrb; Mon, 27 Nov 2017 23:50:58 -0800 (PST) X-Google-Smtp-Source: AGs4zMa+2lrZNOTcZfrlWBeQ0WJMmmhaZ8uOaAJHFbidDQC9H9aculPn6mPPlnddh26yRno5mXFZ X-Received: by 10.84.128.36 with SMTP id 33mr42564497pla.329.1511855458124; Mon, 27 Nov 2017 23:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511855458; cv=none; d=google.com; s=arc-20160816; b=aHyGWYIDIEESxAQt4PmuAtdLQeknPsERPIytogK6U1Gr2o43i9bWFfcwDX/D0H6SwB VR9+ADj0AgjUKlGyNtAUADKNubsAlk2JIM8Z+u/qOLWUBoGc3EKw+YF339lqTZGxvOio 99pV9MylL+enEQaw2QpeMCbUR8wiAF6tXsyjpMAGvbF+dexcQ3+KQ7p44BRFihPmEjYZ kEPFI4aMjFHllJvm4OkXocRGpZ/p6ABAMClzYD0YlQmXAATzWjj3G/1DU8AGL2Z2auZR ePhmT7D3d7OnKto81kYPUQzb186XRUk5G5U/NJjhkL0Fq8O8FUcBlvVbifVuGUnL3ZbX 3puQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=iYb0mJJj7I5WnUTZ8E26T2OXl3BoALm2lq6w4git1Zg=; b=RutALWMRIk3exJndtYbf8WylebaEEZAfRc6JJZsxm5FYZSApvmZQcHdgejU1flwFEx LL4tMmGpO2vDIszfFSN2uf7Hf1Odds8w2TKZue8SV8LLotcSU9PJvIW2lTvv6L3mBYC+ O55z7lj5PbpYu9v4Mm/7qpa98pgo875Ck+RSq8BYBnWNTLsBnpeHPRZohrdXTWMf63nQ pgFNTE5SEDXRCR8Mx02d5+DuAOXxQ2DdDmNj0uzPuEu3ocP6cU1xNjGxAnEDu4ju4emb 59VmauqgbKjtvO5fg7FhZ9hbPzqvZkS3y7ZoteYC0pIryGZOqOFtcIWEmiOuA0I/WtSq rV8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hzx/zhRi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si24043565pgq.423.2017.11.27.23.50.46; Mon, 27 Nov 2017 23:50:58 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=hzx/zhRi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752232AbdK1Htp (ORCPT + 78 others); Tue, 28 Nov 2017 02:49:45 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34652 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176AbdK1Htk (ORCPT ); Tue, 28 Nov 2017 02:49:40 -0500 Received: by mail-pg0-f67.google.com with SMTP id 4so19936111pge.1 for ; Mon, 27 Nov 2017 23:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iYb0mJJj7I5WnUTZ8E26T2OXl3BoALm2lq6w4git1Zg=; b=hzx/zhRi9jxBTgX6kMxj5genw/KanCzcyqRDst4F39H+YzTD57EthoJpxS4ZkZxDyx A4J0eNaR5XbHfnKNUy2MYvGWvPteUeqzYo9kNxOGS+G7D1yib1dxp5+s4zyXHPkWDMEu 9u7ZkGTjyupyI5rOD+/OZTdm2ufOr/R3PeS0S0MFZgkyZXjEUsMt3+u7nf2eO0A8bS5/ r+0bLrpUwdd8JkVNlPv+GJawBgq2eWtmCEA/+5m4sA/Vcm1opZyZmqmop7fHmVEeYnfq RWdXtjw+Ml80aS0DqY9HcB7tKPERnXRDQ/CqXjBI87pmZ3yvfGMJU1aSoL/jP5p2VY6P JmGA== 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; bh=iYb0mJJj7I5WnUTZ8E26T2OXl3BoALm2lq6w4git1Zg=; b=tfF7VrH45s2LQN73oPjNSpCGTpfBXzl1VOvMyn7jKI2VWbOKGvX+vP+fb57QQYYO9Q aiw6n6U0zr5e+i+3kS5bipgl44XbZ4yC+VOc5ivux0mp+NULGCDmPTseJbE+PSEn6vG/ GDI0rPukaBaijsM6xVs+b83V7Svj8Y4xwRIkBwtKXJzj3u+ilLF8/7jUoPFF/9tJBcRw g4mxDwHOrZ/T1ZWZXgIX6Z3jed4dg9NIvmtpTwwsm3PfQ5WQ3MHsbF04bnr/PETHtxWs FCYIjtxcGFylwgPt2zMV/1n0rwblQ0q4mRoiujYqfb3c9qe3s0lNFm5exy25ZXBRsDoe zxGA== X-Gm-Message-State: AJaThX6pq00Iux6G6F/7NyyMW74G/NBFa6jl/noTbEBKK42oa2FjgpiR sf21dD1CjsgqGspQEeIGY+cRJg== X-Received: by 10.98.60.209 with SMTP id b78mr39562287pfk.144.1511855380031; Mon, 27 Nov 2017 23:49:40 -0800 (PST) Received: from localhost.localdomain ([124.56.155.17]) by smtp.gmail.com with ESMTPSA id 67sm39403946pfz.171.2017.11.27.23.49.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Nov 2017 23:49:39 -0800 (PST) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Namhyung Kim , Wengang Wang , Joonsoo Kim Subject: [PATCH 06/18] lib/stackdepot: Add is_new arg to depot_save_stack Date: Tue, 28 Nov 2017 16:48:41 +0900 Message-Id: <1511855333-3570-7-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Namhyung Kim The is_new argument is to check whether the given stack trace was already in the stack depot or newly added. It'll be used by vchecker callstack in the next patch. Also add WARN_ONCE if stack depot failed to allocate stack slab for some reason. This is unusual as it allocates the stack slab before its use but sometimes users might want to know its failure. Passing __GFP_NOWARN in the alloc_flags will bypass it though. Signed-off-by: Namhyung Kim Signed-off-by: Joonsoo Kim --- include/linux/stackdepot.h | 3 ++- lib/stackdepot.c | 15 +++++++++++++-- mm/kasan/kasan.c | 2 +- mm/kasan/vchecker.c | 2 +- mm/page_owner.c | 4 ++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 7978b3e..93363f2 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -25,7 +25,8 @@ typedef u32 depot_stack_handle_t; struct stack_trace; -depot_stack_handle_t depot_save_stack(struct stack_trace *trace, gfp_t flags); +depot_stack_handle_t depot_save_stack(struct stack_trace *trace, gfp_t flags, + bool *is_new); void depot_fetch_stack(depot_stack_handle_t handle, struct stack_trace *trace); diff --git a/lib/stackdepot.c b/lib/stackdepot.c index f87d138..e40ccb6 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -130,8 +130,11 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size, smp_store_release(&next_slab_inited, 0); } init_stack_slab(prealloc); - if (stack_slabs[depot_index] == NULL) + if (stack_slabs[depot_index] == NULL) { + if (!(alloc_flags & __GFP_NOWARN)) + WARN_ONCE(1, "Stack depot failed to allocate stack_slabs"); return NULL; + } stack = stack_slabs[depot_index] + depot_offset; @@ -198,11 +201,12 @@ EXPORT_SYMBOL_GPL(depot_fetch_stack); * depot_save_stack - save stack in a stack depot. * @trace - the stacktrace to save. * @alloc_flags - flags for allocating additional memory if required. + * @is_new - set #true when @trace was not in the stack depot. * * Returns the handle of the stack struct stored in depot. */ depot_stack_handle_t depot_save_stack(struct stack_trace *trace, - gfp_t alloc_flags) + gfp_t alloc_flags, bool *is_new) { u32 hash; depot_stack_handle_t retval = 0; @@ -236,6 +240,8 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace, * |next_slab_inited| in depot_alloc_stack() and init_stack_slab(). */ if (unlikely(!smp_load_acquire(&next_slab_inited))) { + gfp_t orig_flags = alloc_flags; + /* * Zero out zone modifiers, as we don't have specific zone * requirements. Keep the flags related to allocation in atomic @@ -247,6 +253,9 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace, page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER); if (page) prealloc = page_address(page); + + /* restore flags to report failure in depot_alloc_stack() */ + alloc_flags = orig_flags; } spin_lock_irqsave(&depot_lock, flags); @@ -264,6 +273,8 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace, */ smp_store_release(bucket, new); found = new; + if (is_new) + *is_new = true; } } else if (prealloc) { /* diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c index 8fc4ad8..1b37e12 100644 --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -454,7 +454,7 @@ static inline depot_stack_handle_t save_stack(gfp_t flags) trace.entries[trace.nr_entries-1] == ULONG_MAX) trace.nr_entries--; - return depot_save_stack(&trace, flags); + return depot_save_stack(&trace, flags, NULL); } static inline void set_track(struct kasan_track *track, gfp_t flags) diff --git a/mm/kasan/vchecker.c b/mm/kasan/vchecker.c index 2e9f461..82d4f1d 100644 --- a/mm/kasan/vchecker.c +++ b/mm/kasan/vchecker.c @@ -299,7 +299,7 @@ static noinline depot_stack_handle_t save_stack(void) trace.entries[trace.nr_entries-1] == ULONG_MAX) trace.nr_entries--; - return depot_save_stack(&trace, GFP_NOWAIT); + return depot_save_stack(&trace, GFP_NOWAIT, NULL); } static ssize_t vchecker_type_write(struct file *filp, const char __user *ubuf, diff --git a/mm/page_owner.c b/mm/page_owner.c index f948acc..0e22eee 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -66,7 +66,7 @@ static __always_inline depot_stack_handle_t create_dummy_stack(void) dummy.skip = 0; save_stack_trace(&dummy); - return depot_save_stack(&dummy, GFP_KERNEL); + return depot_save_stack(&dummy, GFP_KERNEL, NULL); } static noinline void register_dummy_stack(void) @@ -162,7 +162,7 @@ static noinline depot_stack_handle_t save_stack(gfp_t flags) if (check_recursive_alloc(&trace, _RET_IP_)) return dummy_handle; - handle = depot_save_stack(&trace, flags); + handle = depot_save_stack(&trace, flags, NULL); if (!handle) handle = failure_handle; -- 2.7.4 From 1585312107841154084@xxx Tue Nov 28 12:17:20 +0000 2017 X-GM-THRID: 1585304908547308472 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread