Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3719285pxb; Mon, 24 Jan 2022 16:15:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXrYMMBk5fO4bAgp6dHsx5tUS+t+ttytn58K+V1kO0/IgH0PoOH/GyXulLqF/pOV17bmS/ X-Received: by 2002:a17:902:b189:b0:143:8079:3d3b with SMTP id s9-20020a170902b18900b0014380793d3bmr16560878plr.71.1643069713373; Mon, 24 Jan 2022 16:15:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069713; cv=none; d=google.com; s=arc-20160816; b=pJSBbHxC20OQ3HiWU8ZiUYCKPZ/eUPP9eX/Ga8AfkO06J3fTVS6kNhbCz2bfp7SgGu 4GuBZgSuSuOf4hxRc1eqIAuhgtOsfx3hUDczX9uQGDToeKLQUDw6CZuOvoyF++38Fzw/ Ew2gi1BbtPU7AkjbFodj5/ZASQkImBtFnglh3WGj7FY406JxSv0mfZx5JMTAXg2Bz1BC IMZCSnYx+GKyVuHm0fDcIwP1lRJIXzC9pWewkM9EQkeOw+Exfe2GpnO7XWoOpNwlp4lc xkENGGD3fIpNn2M8z6j40/M74i9+F8MKUaSSIemgDLMKXQbO7Bvn++bS/qIJ0VkEIhzQ JueQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gyg3n3MVyZ3uPVpWlUDudVNmBT0jXf8oAHAgWw/TKF0=; b=ry2y5xEAXZPacuphukLFIvpumdioZx4fEkqb34+mvcxgyDeXsyaAlC2EDoAF08UhJ8 UkzaeQ0GRNqcA/kW6e0RFyKXpRbj0xYH838HYcaPGR8yCfWCycMShV9N30J7vRay7Ny+ d3DnZGQSaoJOR1i+cDOIXfhP+I0KR0OAtgV516dOUmY8tc9hjeUbi9c93l/i4039FbYX opMiZ+u01wErWL2rj5OsBROk/DXzmnwpzZhiPgunw3ej25ngMVo0wj8EXeHpDhYhuGHy MGHFsdbAOqq1sufaEaB3zL0kYFc2lJQELF6txy67sK6yRWE7GIKdh0t17FcMHkU0d25c Z1Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XgSjUiBI; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si794091pjg.78.2022.01.24.16.15.01; Mon, 24 Jan 2022 16:15:13 -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=@linuxfoundation.org header.s=korg header.b=XgSjUiBI; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2372510AbiAYALs (ORCPT + 99 others); Mon, 24 Jan 2022 19:11:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356615AbiAXWjo (ORCPT ); Mon, 24 Jan 2022 17:39:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71973C05487E; Mon, 24 Jan 2022 13:02:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 39B3FB8123D; Mon, 24 Jan 2022 21:02:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D0C4C340E5; Mon, 24 Jan 2022 21:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058174; bh=YIVcffIQyq2XLA6aoqQ7+F5OrkIe5KlOSYgHLVyqGi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgSjUiBI4umC08n9iC9OgAtG/rap2RaSmG92rVgfVVP02nIlGUK0FZTrEKjxLsVJe Nngjbg1iP2NwH5n9fdJjSEqS+C/B7w/ic5ZTTsLucsZKYE/emd574TluZ0F2CwCBvJ 7VJ4wjqFz4ipP9SNBUekWl+16TpcRYh8l6bNLSNQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianwei Hu , "Uladzislau Rezki (Sony)" , Marco Elver , Juri Lelli , Jun Miao , "Paul E. McKenney" , Sasha Levin Subject: [PATCH 5.16 0204/1039] rcu: Avoid alloc_pages() when recording stack Date: Mon, 24 Jan 2022 19:33:13 +0100 Message-Id: <20220124184132.181097293@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jun Miao [ Upstream commit 300c0c5e721834f484b03fa3062602dd8ff48413 ] The default kasan_record_aux_stack() calls stack_depot_save() 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_locks (see gfp.h and ab00db216c9c7). Fix it by instructing stackdepot to not expand stack storage via alloc_pages() in case it runs out by using kasan_record_aux_stack_noalloc(). 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>] 0x0 hardirqs last disabled at (0): [] copy_process+0xaf3/0x2590 softirqs last enabled at (0): [] copy_process+0xaf3/0x2590 softirqs last disabled at (0): [<0000000000000000>] 0x0 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-HLN4F, 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 Links: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/kasan.h?id=7cb3007ce2da27ec02a1a3211941e7fe6875b642 Fixes: 84109ab58590 ("rcu: Record kvfree_call_rcu() call stack for KASAN") Fixes: 26e760c9a7c8 ("rcu: kasan: record and print call_rcu() call stack") Reported-by: Jianwei Hu Reviewed-by: Uladzislau Rezki (Sony) Acked-by: Marco Elver Tested-by: Juri Lelli Signed-off-by: Jun Miao Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- 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 ef8d36f580fc3..906b6887622d3 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2982,7 +2982,7 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) head->func = func; head->next = NULL; local_irq_save(flags); - kasan_record_aux_stack(head); + kasan_record_aux_stack_noalloc(head); rdp = this_cpu_ptr(&rcu_data); /* Add the callback to our list. */ @@ -3547,7 +3547,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) return; } - kasan_record_aux_stack(ptr); + kasan_record_aux_stack_noalloc(ptr); success = add_ptr_to_bulk_krc_lock(&krcp, &flags, ptr, !head); if (!success) { run_page_cache_worker(krcp); -- 2.34.1