Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3256635iog; Mon, 20 Jun 2022 15:23:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tA68tHBiUJ+JiG89KFECFemV2PxI6PHmPGVN/LHbBRwTnWJLJ1gXi/YEU5SImwthjDyuh5 X-Received: by 2002:a17:907:6eab:b0:722:dbb8:8e2 with SMTP id sh43-20020a1709076eab00b00722dbb808e2mr2511854ejc.746.1655763822984; Mon, 20 Jun 2022 15:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655763822; cv=none; d=google.com; s=arc-20160816; b=MD7odwX1b01c4xXmzcSPKSfq4yhYjhfjaaTZbqETkr1SGTuY10nq9k+8g8/7ZN3xsZ Olei48IRGHgP+hFTwoSCWa/UZELHM3oVAbGJZNC7wcS/36xQZBa8Lz8WIA5i0fZYm1yb GpNoN+S9CTscwSNRNuZi07dJk7JmU35mtICmPBXA+WO3ATZtBqly3yvbBKz+UMKTAhFT JIVNfZLZmPTn2Kn2NU5w0THtReuu8nl800i7fgMVIux763n5EuChtjPksSXymdil1YaJ ZoOxkSAzLYw0CEJtpWBrUxR1rJrpMpqc4h4dHSVQYhqkiFG2sOm8zm3vnmGMhZuzyWKA yXMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8Zce+Y1SDz/BWUiEM2Bllr9l+jWBAi2p5/OiSkRRlEo=; b=yw4qjVQbSOpaw0MJ2vv0h82/x9jeHePWgS5s3ybrP++0kDgix8GKrp6+NcoA8rBsP3 dK/kKR5rwKacpruH85c0L9B7yzXZ/Zuo9Z9pNEbYYCDG3VZ0MUOC1Eqbzvnl3+zSygdx 0QEKaiN/gtM8BrRwMWUjCxN/3+zfOcBOWbxaIUCoIN+avztWSQsWxC3gvSUZZfQpLcKm R9DVj01GyG4nM5qI/zjj6xBCWJleNQtXTYg6Ch7jxB7Kr5cucASAPzJSjBtitXB8pBMv VgCdn04RBT8wqGY3kr4ByIqylopu2Qi+6fBbyfw1PlBitWbYNC9TOd9qLUFcfdq+pj28 nmqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KXwIw1ho; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw12-20020a170906478c00b0070e06c115b0si11042161ejc.235.2022.06.20.15.23.18; Mon, 20 Jun 2022 15:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KXwIw1ho; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344335AbiFTWVR (ORCPT + 99 others); Mon, 20 Jun 2022 18:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244546AbiFTWUm (ORCPT ); Mon, 20 Jun 2022 18:20:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C30D1B7BC; Mon, 20 Jun 2022 15:20:37 -0700 (PDT) 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 15BCEB8164C; Mon, 20 Jun 2022 22:20:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C325C341CE; Mon, 20 Jun 2022 22:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655763634; bh=dvayfTMczyv3C6g8GjwtjDg8jUO9BjwWnCpcNP6JWoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KXwIw1hoF6M8JmrZhNW6N32tDGxEXEY7fyaa5fmnMwUGYflOYI+KdJE791fCCyVJs 9WNtr2SwLSDmce5jZhN7Fq3bsO7LK3KpsXsC4UXWJgvOg3w7UCiTQttRp3jDB7S/K9 WClbicMt+afMnOpGsrfOHuxBvGr9lofxt+R6mTUkOLCdEg2AwEBJ3BXo1agH6wFRj+ 5bTmuGRmoIgCloVv9meIHcbAho6yh6M7adTNhAA+Hg/Hvp3xmCq0IzEdUW7Mj7b7hf lCf8lDX4FmGSWQiewxv3KHP+TJB36fJdUakciOPOZPaPvLILH9UDWkkdTSACT5v2YV 1Vsm1DW32i0oQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 094375C0BCC; Mon, 20 Jun 2022 15:20:34 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, rostedt@goodmis.org, Johannes Berg , Dmitry Vyukov , "Paul E . McKenney" Subject: [PATCH rcu 07/12] rcu: tiny: Record kvfree_call_rcu() call stack for KASAN Date: Mon, 20 Jun 2022 15:20:27 -0700 Message-Id: <20220620222032.3839547-7-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20220620222022.GA3839466@paulmck-ThinkPad-P17-Gen-1> References: <20220620222022.GA3839466@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg When running KASAN with Tiny RCU (e.g. under ARCH=um, where a working KASAN patch is now available), we don't get any information on the original kfree_rcu() (or similar) caller when a problem is reported, as Tiny RCU doesn't record this. Add the recording, which required pulling kvfree_call_rcu() out of line for the KASAN case since the recording function (kasan_record_aux_stack_noalloc) is neither exported, nor can we include kasan.h into rcutiny.h. without KASAN, the patch has no size impact (ARCH=um kernel): text data bss dec hex filename 6151515 4423154 33148520 43723189 29b29b5 linux 6151515 4423154 33148520 43723189 29b29b5 linux + patch with KASAN, the impact on my build was minimal: text data bss dec hex filename 13915539 7388050 33282304 54585893 340ea25 linux 13911266 7392114 33282304 54585684 340e954 linux + patch -4273 +4064 +-0 -209 Acked-by: Dmitry Vyukov Signed-off-by: Johannes Berg Signed-off-by: Paul E. McKenney --- include/linux/rcutiny.h | 11 ++++++++++- kernel/rcu/tiny.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h index 5fed476f977f6..d84e13f2c3848 100644 --- a/include/linux/rcutiny.h +++ b/include/linux/rcutiny.h @@ -38,7 +38,7 @@ static inline void synchronize_rcu_expedited(void) */ extern void kvfree(const void *addr); -static inline void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) +static inline void __kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) { if (head) { call_rcu(head, func); @@ -51,6 +51,15 @@ static inline void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) kvfree((void *) func); } +#ifdef CONFIG_KASAN_GENERIC +void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func); +#else +static inline void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) +{ + __kvfree_call_rcu(head, func); +} +#endif + void rcu_qs(void); static inline void rcu_softirq_qs(void) diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c index 340b3f8b090d4..58ff3721d975c 100644 --- a/kernel/rcu/tiny.c +++ b/kernel/rcu/tiny.c @@ -217,6 +217,20 @@ bool poll_state_synchronize_rcu(unsigned long oldstate) } EXPORT_SYMBOL_GPL(poll_state_synchronize_rcu); +#ifdef CONFIG_KASAN_GENERIC +void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) +{ + if (head) { + void *ptr = (void *) head - (unsigned long) func; + + kasan_record_aux_stack_noalloc(ptr); + } + + __kvfree_call_rcu(head, func); +} +EXPORT_SYMBOL_GPL(kvfree_call_rcu); +#endif + void __init rcu_init(void) { open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); -- 2.31.1.189.g2e36527f23