Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp6292830pxb; Mon, 8 Nov 2021 06:23:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+cwLBWWPh0VrVC9Jszx6PXpKQBQqQVixxgxNlRN7cMI4/HkbnPlAhpy9g+zlYGH5PTUnV X-Received: by 2002:a05:6402:254d:: with SMTP id l13mr51780195edb.165.1636381395201; Mon, 08 Nov 2021 06:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636381395; cv=none; d=google.com; s=arc-20160816; b=lu0QlnL3UbHeJTmzOaucdu8z9zxZD0FOYhYnpw4qMrmblkU7lzN1dl7QJYRjT3EkCQ zqIDDVUlAZZa6cf86LtLiIk8TgrG0918fdKKAJeGLGTVdi/DCM9GL6Xu/pZc9iL2DMkw t6ez5CvmTgsDqudZvhbeSIIOORpRYtyabQk08/HcLL+BkCYf10BtTB3l0G6sBQ62mO1g 2mXTORnFHkl8+lL1vPGRUIAZZdEjD/8oUthwyR3n8Y26BDYPYztLl6xVstIghLL5W3jC 9ojsJcq4/szermfGjyW91hCQcLQ9xctObAf3BAO+MS2C8C6Cd3ADMHHc0ZrkYglRp7OP A26g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=t0CLCOJqTl97SWBVXsn+FLxAY1FZRpeC0I3mqMnmY7M=; b=AFtLDZteWaT7x7ZSS/QCXYir0ycTBQgK2cz2QXsJBxayiKOjehCXgIx5gtjD5bJr1H dVcuRdT2ni26vvh1+PEe9jnMXIF76su8lur7NLh5m7V2nyKLHXEONwvINZ73Bgp9Ng2Q o5u68NBNtsqxSJ14nuroTIuTSWNt++Tc+PfCXHZ5Qu9ePWGj543jg/EelSXMdRM5Jgab CtVnkT+CribrFl5BVG8rfiW9qT6VxbysLt/lG4vSoaBYQbMCnpfsJlio2nA1qCMr8m8i RP24OZt/429xjWHepZLHyETLGEKc+mQodn1YcRbVstOsAXYwMUd3UYN/dyUNa563mrfx 0TZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YeQ9YEBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id m9si23973037edv.430.2021.11.08.06.22.52; Mon, 08 Nov 2021 06:23:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YeQ9YEBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239313AbhKHLpb (ORCPT + 99 others); Mon, 8 Nov 2021 06:45:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239326AbhKHLpa (ORCPT ); Mon, 8 Nov 2021 06:45:30 -0500 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C96C061714 for ; Mon, 8 Nov 2021 03:42:46 -0800 (PST) Received: by mail-oo1-xc33.google.com with SMTP id t7-20020a4aadc7000000b002b8733ab498so5777419oon.3 for ; Mon, 08 Nov 2021 03:42:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=t0CLCOJqTl97SWBVXsn+FLxAY1FZRpeC0I3mqMnmY7M=; b=YeQ9YEBX0/EP2xCb4Fta2SNFU7V+AoXW9wHVW96D2JLtRlaqyRxueKtSfWfueRA0Zy /mTnyskH/Ya3wSfbksZ5oTVSCRUsfZVQERTE9AKK1I8uceYm2F+AA2nvNKCTSSqjeOil egnAujjAzh6v6qasb5a2o5w1Hl5eEyjfng94BvfTRjUl8eYBK5BA4jcF9jqTACjn+k0B FE2npDNJWFqx4z5dbvMylRmamqqzBhH/13RNLjYYikMHx5iU5Ydg/E0V0afws/pVN/+h R4IUvfifL9C5AtMnTmxRdr/Li5RKVaHc35GvaUSJ3MOg29MpzfwuNkpS6XuusFt3z7Kt nMAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=t0CLCOJqTl97SWBVXsn+FLxAY1FZRpeC0I3mqMnmY7M=; b=4u6YpHRKsb6G6LFydwR8cHCeL1wVr1Uk5KVv/h0N2XhZslZ5/Hm6YSHD290u8AU8JF MX9O0Qu/0wLHjjJFlEyKAiVcNeGbrzOpuUbgjYZhtsZIy7pvm3R9Hr/kMBDpR6g7R6bx 16ecD21lzqDf/5kVW2eOeUQ+wBUE3FtteU9cYgROTSdeoobsezluc/xRj1Q2hpGrRkXJ hQBy+y2QpnfJcc2Less8Rej61HHt65KFgnwwYWAKVrhumqOe4SJipriUXmiLkBP3Rfku hcEBR6p7UZ1Ksv2OPb75oLZvtUvF5CdOIC+aZlN5M4evYDOQlWPZy+X41lTsm4tXpmdw mKbg== X-Gm-Message-State: AOAM533dZZxMbEOAshK+TZf1gcsayYfnYGe4paSZFsvxLWxoTedQnPN+ GNDmk4KEztzCyVGptAbl14W3c2sticcLsx8ARA1W7w== X-Received: by 2002:a4a:b385:: with SMTP id p5mr21194703ooo.21.1636371764628; Mon, 08 Nov 2021 03:42:44 -0800 (PST) MIME-Version: 1.0 References: <20211101103158.3725704-1-jun.miao@windriver.com> <96f9d669-b9da-f387-199e-e6bf36081fbd@windriver.com> <20211103181315.GT880162@paulmck-ThinkPad-P17-Gen-1> <20211103212117.GA631708@paulmck-ThinkPad-P17-Gen-1> <309b8284-1c31-7cc4-eb40-ba6d8d136c09@windriver.com> <20211104012843.GD641268@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20211104012843.GD641268@paulmck-ThinkPad-P17-Gen-1> From: Dmitry Vyukov Date: Mon, 8 Nov 2021 12:42:33 +0100 Message-ID: Subject: Re: [PATCH] rcu: avoid alloc_pages() when recording stack To: paulmck@kernel.org, kasan-dev Cc: Jun Miao , Uladzislau Rezki , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , qiang.zhang1211@gmail.com, RCU , LKML , miaojun0823@163.com, ryabinin.a.a@gmail.com, Alexander Potapenko , jianwei.hu@windriver.com, melver@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 4 Nov 2021 at 02:28, Paul E. McKenney wrote: > > On Thu, Nov 04, 2021 at 09:09:24AM +0800, Jun Miao wrote: > > > > On 11/4/21 5:21 AM, Paul E. McKenney wrote: > > > [Please note: This e-mail is from an EXTERNAL e-mail address] > > > > > > On Wed, Nov 03, 2021 at 11:13:15AM -0700, Paul E. McKenney wrote: > > > > On Wed, Nov 03, 2021 at 02:55:48PM +0100, Uladzislau Rezki wrote: > > > > > On Wed, Nov 3, 2021 at 7:51 AM Jun Miao = wrote: > > > > > > > > > > > > On 11/2/21 10:53 PM, Uladzislau Rezki wrote: > > > > > > > [Please note: This e-mail is from an EXTERNAL e-mail address] > > > > > > > > > > > > > > > Add KASAN maintainers > > > > > > > > > > > > > > > > On 11/1/21 6:31 PM, Jun Miao wrote: > > > > > > > > > The default kasan_record_aux_stack() calls stack_depot_sa= ve() with GFP_NOWAIT, > > > > > > > > > which in turn can then call alloc_pages(GFP_NOWAIT, ...).= In general, however, > > > > > > > > > it is not even possible to use either GFP_ATOMIC nor GFP_= NOWAIT in certain > > > > > > > > > non-preemptive contexts/RT kernel including raw_spin_lock= s (see gfp.h and ab00db216c9c7). > > > > > > > > > > > > > > > > > > Fix it by instructing stackdepot to not expand stack stor= age via alloc_pages() > > > > > > > > > in case it runs out by using kasan_record_aux_stack_noall= oc(). > > > > > > > > > > > > > > > > > > Jianwei Hu reported: > > > > > > > > > BUG: sleeping function called from invalid context at= kernel/locking/rtmutex.c:969 > > > > > > > > > in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid= : 15319, name: python3 > > > > > > > > > INFO: lockdep is turned off. > > > > > > > > > irq event stamp: 0 > > > > > > > > > hardirqs last enabled at (0): [<0000000000000000>] 0= x0 > > > > > > > > > hardirqs last disabled at (0): [] c= opy_process+0xaf3/0x2590 > > > > > > > > > softirqs last enabled at (0): [] c= opy_process+0xaf3/0x2590 > > > > > > > > > softirqs last disabled at (0): [<0000000000000000>] 0= x0 > > > > > > > > > CPU: 6 PID: 15319 Comm: python3 Tainted: G W = O 5.15-rc7-preempt-rt #1 > > > > > > > > > Hardware name: Supermicro SYS-E300-9A-8C/A2SDi-8C-HLN= 4F, BIOS 1.1b 12/17/2018 > > > > > > > > > Call Trace: > > > > > > > > > show_stack+0x52/0x58 > > > > > > > > > dump_stack+0xa1/0xd6 > > > > > > > > > ___might_sleep.cold+0x11c/0x12d > > > > > > > > > rt_spin_lock+0x3f/0xc0 > > > > > > > > > rmqueue+0x100/0x1460 > > > > > > > > > rmqueue+0x100/0x1460 > > > > > > > > > mark_usage+0x1a0/0x1a0 > > > > > > > > > ftrace_graph_ret_addr+0x2a/0xb0 > > > > > > > > > rmqueue_pcplist.constprop.0+0x6a0/0x6a0 > > > > > > > > > __kasan_check_read+0x11/0x20 > > > > > > > > > __zone_watermark_ok+0x114/0x270 > > > > > > > > > get_page_from_freelist+0x148/0x630 > > > > > > > > > is_module_text_address+0x32/0xa0 > > > > > > > > > __alloc_pages_nodemask+0x2f6/0x790 > > > > > > > > > __alloc_pages_slowpath.constprop.0+0x12d0/0x12d0 > > > > > > > > > create_prof_cpu_mask+0x30/0x30 > > > > > > > > > alloc_pages_current+0xb1/0x150 > > > > > > > > > stack_depot_save+0x39f/0x490 > > > > > > > > > kasan_save_stack+0x42/0x50 > > > > > > > > > kasan_save_stack+0x23/0x50 > > > > > > > > > kasan_record_aux_stack+0xa9/0xc0 > > > > > > > > > __call_rcu+0xff/0x9c0 > > > > > > > > > call_rcu+0xe/0x10 > > > > > > > > > put_object+0x53/0x70 > > > > > > > > > __delete_object+0x7b/0x90 > > > > > > > > > kmemleak_free+0x46/0x70 > > > > > > > > > slab_free_freelist_hook+0xb4/0x160 > > > > > > > > > kfree+0xe5/0x420 > > > > > > > > > kfree_const+0x17/0x30 > > > > > > > > > kobject_cleanup+0xaa/0x230 > > > > > > > > > kobject_put+0x76/0x90 > > > > > > > > > netdev_queue_update_kobjects+0x17d/0x1f0 > > > > > > > > > ... ... > > > > > > > > > ksys_write+0xd9/0x180 > > > > > > > > > __x64_sys_write+0x42/0x50 > > > > > > > > > do_syscall_64+0x38/0x50 > > > > > > > > > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > > > > > > > > > > > > > > > > > Fixes: 84109ab58590 ("rcu: Record kvfree_call_rcu() call = stack for KASAN") > > > > > > > > > Fixes: 26e760c9a7c8 ("rcu: kasan: record and print call_r= cu() call stack") > > > > > > > > > Reported-by: Jianwei Hu > > > > > > > > > Signed-off-by: Jun Miao > > > > > > > > > --- > > > > > > > > > kernel/rcu/tree.c | 4 ++-- > > > > > > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > > > > > > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > > > > > > > index 8270e58cd0f3..2c1034580f15 100644 > > > > > > > > > --- a/kernel/rcu/tree.c > > > > > > > > > +++ b/kernel/rcu/tree.c > > > > > > > > > @@ -3026,7 +3026,7 @@ __call_rcu(struct rcu_head *head, r= cu_callback_t func) > > > > > > > > > head->func =3D func; > > > > > > > > > head->next =3D NULL; > > > > > > > > > local_irq_save(flags); > > > > > > > > > - kasan_record_aux_stack(head); > > > > > > > > > + kasan_record_aux_stack_noalloc(head); > > > > > > > > > rdp =3D this_cpu_ptr(&rcu_data); > > > > > > > > > > > > > > > > > > /* Add the callback to our list. */ > > > > > > > > > @@ -3591,7 +3591,7 @@ void kvfree_call_rcu(struct rcu_hea= d *head, rcu_callback_t func) > > > > > > > > > return; > > > > > > > > > } > > > > > > > > > > > > > > > > > > - kasan_record_aux_stack(ptr); > > > > > > > > > + kasan_record_aux_stack_noalloc(ptr); > > > > > > > > > success =3D add_ptr_to_bulk_krc_lock(&krcp, &flag= s, ptr, !head); > > > > > > > > > if (!success) { > > > > > > > > > run_page_cache_worker(krcp); > > > > > > > Yep an allocation is tricky here. This change looks correct t= o me at > > > > > > > least from the point that it does not allocate. > > > > > > > > > > > > > > -- > > > > > > > Uladzislau Rezki > > > > > > Thanks your approval. Could you like to give me a review? > > > > > > > > > > > Reviewed-by: Uladzislau Rezki (Sony) > > > > I have queued it for review and testing, thank you both! I do have > > > > some remaining concerns about this code being starved for memory. = I am > > > > wondering if the code needs to check the interrupt state. And perh= aps > > > > also whether locks are held. I of course will refrain from sending > > > > this to mainline until these concerns are resolved. > > > > > > > > Marco, Dmitry, thoughts? > > > Well, the compiler does have an opinion: > > > > > > kernel/rcu/tree.c: In function =E2=80=98__call_rcu=E2=80=99: > > > kernel/rcu/tree.c:3029:2: error: implicit declaration of function =E2= =80=98kasan_record_aux_stack_noalloc=E2=80=99; did you mean =E2=80=98kasan_= record_aux_stack=E2=80=99? [-Werror=3Dimplicit-function-declaration] > > > 3029 | kasan_record_aux_stack_noalloc(head); > > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > | kasan_record_aux_stack > > > > > > I get the same message after merging in current mainline. > > > > > > I have therefore dropped this patch for the time being. > > > > > > Thanx, Paul > > Hi Paul E, > > The kasan_record_aux_stack_noalloc() is just introduce to linux-next no= w, > > and marking "Notice: this object is not reachable from any branch." in > > commit. > > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/com= mit/include/linux/kasan.h?h=3Dnext-20211029&id=3D2f64acf6b653d01fbdc92a693f= 12bbf71a205926 > > That would explain it! Feel free to resend once the functionality is > more generally available. +kasan-dev@googlegroups.com mailing list I found the full commit with kasan_record_aux_stack_noalloc() implementatio= n: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/= ?h=3Dnext-20211029&id=3D2f64acf6b653d01fbdc92a693f12bbf71a205926 but it calls kasan_save_stack() with second bool argument, and kasan_save_stack() accepts only 1 argument: https://elixir.bootlin.com/linux/latest/source/mm/kasan/common.c#L33 so I am lost and can't comment on any of the Paul's questions re interrupts/spinlocks. When re-sending this, please add kasan-dev@ mailing list and add links to the dependencies. Thanks