Received: by 10.213.65.68 with SMTP id h4csp1312633imn; Mon, 26 Mar 2018 05:16:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELv6G0Ncit6XDa9mnW1AtPmwUNB8hyS5LoyAOV05yP0loFTQfs84663x83U+oki19beEnKLU X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr28587490pli.176.1522066576463; Mon, 26 Mar 2018 05:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522066576; cv=none; d=google.com; s=arc-20160816; b=XsAsF+7QSBQ/BQQoVzfIIEWPtwMgd70sdVrexFrhDurlK4fAhWwnXjcRz/CRCcRTPP vT+Y08q1JWzZ2gVit/gpotryYh5h/K1CKI0+xoeO8xMYRXdWbWkpHs9tngIx1d2Cb+h4 qum7DV2q89g2hTkvUXPP8MwOhbMw6bs+B2tCmAWIK3pPOcgAW9R6s/AHKrGhiP19L+h7 HE0QqqnghJrw0w5Unc5Js/Igk8VT/rVHjFBgX3/OA9LOYsaXtD0wULK24MHZ1SgOF1Ow dbLcUufaSvll4tCBTW2J8h8YQw9XKpdCXfuZysLbAfIx8PKR5+OleXJgzSXDo9swtJOw tCDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=VFDDoEaB02Y1WQBpZAiKx30kvPi9O1ZIDqgNQpxyJxQ=; b=p13WwmrpyG/FOtmGv4qeSLpkRKUl9cgaM7dfThpfrcpRK1mOS/5r4gWTaGzIJsLGo9 eT2PZ3fAHPNfcySj5WTQTb/GPUVhZS5pBZ6pPYYvarkW5GFuCdIskS9voIo9YD06Zrff bE08w8aHaRYNMI8pdreOvACn5Yr6FBVI1dDNmzZ6lbOKMWqOqy7INwZvySFKrSKSNW1q nDS5m4/eROvXd0myamWaCcVrh3x+ydbxB8wWHo+LlRRU5vuEjPsND6pTH1puBj81Ss41 oYoypdlscFg8IyNB1EJ2E2x8H6sjiMnO9kbUlr6X5ufReEV15rk2FRZD5NsCNp1jF0uV asOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wQI0VJbL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 30-v6si15122581plb.316.2018.03.26.05.16.02; Mon, 26 Mar 2018 05:16:16 -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=@google.com header.s=20161025 header.b=wQI0VJbL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752105AbeCZMOw (ORCPT + 99 others); Mon, 26 Mar 2018 08:14:52 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36646 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751686AbeCZMOr (ORCPT ); Mon, 26 Mar 2018 08:14:47 -0400 Received: by mail-pl0-f68.google.com with SMTP id 91-v6so3998961pld.3 for ; Mon, 26 Mar 2018 05:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VFDDoEaB02Y1WQBpZAiKx30kvPi9O1ZIDqgNQpxyJxQ=; b=wQI0VJbL+rbtwl13UdGxrM0fxk6Nq5D0Z/iutIuG+Cztji2FoPu6Yn7WXThsZzRmN/ uNKGocNLuqTKnNycnSfns7e3xFtk8aAsKMCRavbTgnGnuZyHm51a8LQmOa88ATEiTHhn SOPuhG1luAWfywmi2tJnl6CG0bJeu9N32tDd6dr/DU2kiuE8QGRqlVwEI0JXe0R/QJMf 1EoWJipKaCBUEVQh/ZryYvIRJeMYrX+iWHRFDwenqqoyYBtoHwpNUEcmMWqkS2b1V0bC cDbuXojQLw/3+W8rKocyxweOcpLqLa8W3jKiCvVrHWBrgjX3uzhuc2R/aMDVHvjidpby iCdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VFDDoEaB02Y1WQBpZAiKx30kvPi9O1ZIDqgNQpxyJxQ=; b=rSDTvAlBlGp3qAEL+bwJOEjmmV3U9OUuylUv0BSITFh4qb7UhMRhpDVE+UkKajJblp ylAY9PR0uCggrkCdeog9QSYc5KLAlqTU5A0JctIoHh8z2yZvUIr+TqH/UbjGhxOvvwJB cb/49crZKbhZEVgz7Uotz3kLmL92a7pztmq4LX2Tomj3csq8OnAbK8J/zXhq6ZKJ5VIV aT00dob4hLgJtxdocqnhyb5/Gv29+cjxMazwdYVcuoqeTXh4zXnI7qoiVDfWpyvLX7dQ 8mRe64G0inLVFX6jY+HovjRpfvwluflImI1dwMQ5wxsIyXSCLMSbLVNkkWEDs5B2rofl o2WQ== X-Gm-Message-State: AElRT7Gb6bW1fDZrGrcDs7zB2bqRvnlynZXv1Dku5N1QjUedm2sVefRd cNEKIh2ILeerjWT/drbSWWqE4N7dXvU68t6HLJPHJw== X-Received: by 2002:a17:902:bd4b:: with SMTP id b11-v6mr12435665plx.225.1522066487057; Mon, 26 Mar 2018 05:14:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.182.136 with HTTP; Mon, 26 Mar 2018 05:14:26 -0700 (PDT) In-Reply-To: <1522058304-35934-1-git-send-email-maninder1.s@samsung.com> References: <1522058304-35934-1-git-send-email-maninder1.s@samsung.com> From: Dmitry Vyukov Date: Mon, 26 Mar 2018 14:14:26 +0200 Message-ID: Subject: Re: [PATCH v2] mm/page_owner: ignore everything below the IRQ entry point To: Maninder Singh Cc: Andrey Ryabinin , Alexander Potapenko , Kate Stewart , Thomas Gleixner , Philippe Ombredanne , Greg Kroah-Hartman , Andrew Morton , Vlastimil Babka , Stephen Rothwell , Michal Hocko , vinmenon@codeaurora.org, gomonovych@gmail.com, ayush.m@samsung.com, LKML , kasan-dev , Linux-MM , AMIT SAHRAWAT , PANKAJ MISHRA , Vaneet narang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 26, 2018 at 11:58 AM, Maninder Singh wrote: > Check whether the allocation happens in an IRQ handler. > This lets us strip everything below the IRQ entry point to reduce the > number of unique stack traces needed to be stored. > > so moved code of KASAN in generic file so that page_owner can also > do same filteration. > > Initial KASAN commit > id=be7635e7287e0e8013af3c89a6354a9e0182594c > > original:- > __alloc_pages_nodemask+0xfc/0x220 > page_frag_alloc+0x84/0x140 > __napi_alloc_skb+0x83/0xe0 > rtl8169_poll+0x1e5/0x670 > net_rx_action+0x132/0x3a0 > __do_softirq+0xce/0x298 > irq_exit+0xa3/0xb0 > do_IRQ+0x72/0xc0 > ret_from_intr+0x0/0x18 > cpuidle_enter_state+0x96/0x290 > do_idle+0x163/0x1a0 > > After patch:- > __alloc_pages_nodemask+0xfc/0x220 > page_frag_alloc+0x84/0x140 > __napi_alloc_skb+0x83/0xe0 > rtl8169_poll+0x1e5/0x670 > net_rx_action+0x132/0x3a0 > __do_softirq+0xce/0x298 > > Signed-off-by: Vaneet Narang > Signed-off-by: Maninder Singh > --- > v1->v2: fix build break for tile and blackfin > (https://lkml.org/lkml/2017/12/3/287, verified for blackfin) > > include/linux/stacktrace.h | 26 ++++++++++++++++++++++++++ > mm/kasan/kasan.c | 22 ---------------------- > mm/page_owner.c | 1 + > 3 files changed, 27 insertions(+), 22 deletions(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index ba29a06..3d3e49d 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -4,6 +4,8 @@ > > #include > > +extern char __irqentry_text_start[], __irqentry_text_end[]; > +extern char __softirqentry_text_start[], __softirqentry_text_end[]; > struct task_struct; > struct pt_regs; > > @@ -26,6 +28,28 @@ extern int save_stack_trace_tsk_reliable(struct task_struct *tsk, > extern int snprint_stack_trace(char *buf, size_t size, > struct stack_trace *trace, int spaces); > > +static inline int in_irqentry_text(unsigned long ptr) > +{ > + return (ptr >= (unsigned long)&__irqentry_text_start && > + ptr < (unsigned long)&__irqentry_text_end) || > + (ptr >= (unsigned long)&__softirqentry_text_start && > + ptr < (unsigned long)&__softirqentry_text_end); > +} > + > +static inline void filter_irq_stacks(struct stack_trace *trace) > +{ > + int i; > + > + if (!trace->nr_entries) > + return; > + for (i = 0; i < trace->nr_entries; i++) > + if (in_irqentry_text(trace->entries[i])) { > + /* Include the irqentry function into the stack. */ > + trace->nr_entries = i + 1; > + break; > + } > +} > + > #ifdef CONFIG_USER_STACKTRACE_SUPPORT > extern void save_stack_trace_user(struct stack_trace *trace); > #else > @@ -38,6 +62,8 @@ extern int snprint_stack_trace(char *buf, size_t size, > # define save_stack_trace_user(trace) do { } while (0) > # define print_stack_trace(trace, spaces) do { } while (0) > # define snprint_stack_trace(buf, size, trace, spaces) do { } while (0) > +# define filter_irq_stacks(trace) do { } while (0) > +# define in_irqentry_text(ptr) do { } while (0) Hi, Every user of stack_depot should filter out irq frames, without that stack_depot will run out of memory sooner or later. so this is a change in the right direction. Do we need to define empty version of in_irqentry_text? Shouldn't only filter_irq_stacks be used by kernel code? > # define save_stack_trace_tsk_reliable(tsk, trace) ({ -ENOSYS; }) > #endif /* CONFIG_STACKTRACE */ > > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c > index 405bba4..129e7b8 100644 > --- a/mm/kasan/kasan.c > +++ b/mm/kasan/kasan.c > @@ -412,28 +412,6 @@ void kasan_poison_object_data(struct kmem_cache *cache, void *object) > KASAN_KMALLOC_REDZONE); > } > > -static inline int in_irqentry_text(unsigned long ptr) > -{ > - return (ptr >= (unsigned long)&__irqentry_text_start && > - ptr < (unsigned long)&__irqentry_text_end) || > - (ptr >= (unsigned long)&__softirqentry_text_start && > - ptr < (unsigned long)&__softirqentry_text_end); > -} > - > -static inline void filter_irq_stacks(struct stack_trace *trace) > -{ > - int i; > - > - if (!trace->nr_entries) > - return; > - for (i = 0; i < trace->nr_entries; i++) > - if (in_irqentry_text(trace->entries[i])) { > - /* Include the irqentry function into the stack. */ > - trace->nr_entries = i + 1; > - break; > - } > -} > - > static inline depot_stack_handle_t save_stack(gfp_t flags) > { > unsigned long entries[KASAN_STACK_DEPTH]; > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 8602fb4..30e9cb2 100644 > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > @@ -148,6 +148,7 @@ static noinline depot_stack_handle_t save_stack(gfp_t flags) > depot_stack_handle_t handle; > > save_stack_trace(&trace); > + filter_irq_stacks(&trace); > if (trace.nr_entries != 0 && > trace.entries[trace.nr_entries-1] == ULONG_MAX) > trace.nr_entries--; > -- > 1.9.1 >