Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp612722iof; Mon, 6 Jun 2022 09:22:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySfhiVw/igQgD1mccOb4l3HCorHKo4V7V8WEiNCJY2dMRWFAKhrrk3QxdTKX7GbEW4bZfk X-Received: by 2002:a17:90b:1d08:b0:1e3:2a4f:6935 with SMTP id on8-20020a17090b1d0800b001e32a4f6935mr40118505pjb.174.1654532554799; Mon, 06 Jun 2022 09:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654532554; cv=none; d=google.com; s=arc-20160816; b=rmBF8Pqdov/Cc3PtGgGswVjcX6GJIBfbMsH+fDyaeT/u/RI26rfLmnAe2zrsGT1iHr xc4VZhh5pEsQ/SqzvJn3ZOWGoh5SlYCQ+h+7hS6v/COuZ6k/oabvq1+0XTvAghp4sB6J sxrMpjLJOdL0BRUHz2iEXskceAqxwnSBuBxOT5sNeCbZZay7S7m1ln76JqMYkNwhmzkI PSuTokaRXgfyXNzzhmHiG4fQn3E45PNAYq++7/UcCXXRNqTxLem78tH6qM1cGIAVreCM dOnyqqAgpG+T+Ca87GbUMxqr0IpQ9aRD8WmWzReH2Cxsmqpmpot6at+lV4fV9dg3IGfz 25+Q== 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:subject:cc:to:from:date :dkim-signature; bh=A70upGgdv/15uyd7FQQKq5ES0mT3NOul5tdXkVQ7MyM=; b=N5YQhAyva0bCcyy6wf5TowpaxkOhjVF3r2DpBuvSjXcoWxXDjLOhTDKYU6Gk2fBr9k CWuh4qgpmSZ3bGqs1IIME+ghpNmQxLydmnudCG6G4Mncv5kAPp5yakbWa3BfkREVMmYF ltQMvm5VMG9Ac1y+s4DpBsLgQAKWmIENsAUCnfo0/wMc7PFNvSHzVYDkzBt+uFhEd2ab E2F66oqqrnoK6xHIWGPsS12RyZ3CYpYF0I2XcsecND/7M8U/XAScDdQ6wRtHYk3vbhNZ RUzQWUsiEfyoiNgepk+erhVjd/HOeVRt1mTGCjE6iEFP8fFAOg3P8rsxaTOuAt3g2C9R EJYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SlDHGrGw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a10-20020a634d0a000000b003fbfc221ef4si21468083pgb.424.2022.06.06.09.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 09:22:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SlDHGrGw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA8FD4D9E6; Mon, 6 Jun 2022 09:02:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241451AbiFFQCk (ORCPT + 99 others); Mon, 6 Jun 2022 12:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241389AbiFFQCh (ORCPT ); Mon, 6 Jun 2022 12:02:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02A031909; Mon, 6 Jun 2022 09:02:35 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0126B60B4E; Mon, 6 Jun 2022 16:02:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8F9EC385A9; Mon, 6 Jun 2022 16:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654531354; bh=4fcI46sksNPRQpKV25vl8NhCk5UfbVE4mI4k5n7Qnak=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SlDHGrGws5AkJ0Oa+XUokumnrvTmtnu6PAic6lDmnGc8BznCLkQFxEDRCVF8o5oWx LLVRm48VOHFcW8b0sGim9MUjuu4enRCbwJgtisGXt6ngM+VTkxSdjH79sCQDGKejAx LGdVJLl/F2RcowjbM8n2J+GXSdGo5eVYBBzt14olldD9JS7QWmQ58UvIl7lrZvCR4w jsVZatcBymS2nQAuZzaPlGoJVo1Vt34KvmTDN1uzDR/8ruOIH5PRCuPtP6MDrIUDRo DaCtu+jS+4/pfutn+Gm5vjENdQDi/ps3by2LQPwG3Os6SiDK85aBbTjPhjb/5DPHgF z9jc7IyDtNBzQ== Date: Tue, 7 Jun 2022 01:02:29 +0900 From: Masami Hiramatsu (Google) To: Andrii Nakryiko Cc: Jiri Olsa , Steven Rostedt , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , open list , Networking , bpf , "Paul E. McKenney" Subject: Re: [PATCH] rethook: Reject getting a rethook if RCU is not watching Message-Id: <20220607010229.5e75445aedb12c99cae2cd51@kernel.org> In-Reply-To: References: <165189881197.175864.14757002789194211860.stgit@devnote2> <20220524192301.0c2ab08a@gandalf.local.home> <20220526232530.cb7d0aed0c60625ef093a735@kernel.org> <20220527011434.9e8c47d1b40f549baf2cf52a@kernel.org> <20220528101928.5118395f2d97142f7625b761@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Fri, 3 Jun 2022 12:21:19 -0700 Andrii Nakryiko wrote: > On Fri, May 27, 2022 at 6:19 PM Masami Hiramatsu wrote: > > > > On Sat, 28 May 2022 00:10:08 +0200 > > Jiri Olsa wrote: > > > > > On Fri, May 27, 2022 at 01:14:34AM +0900, Masami Hiramatsu wrote: > > > > On Thu, 26 May 2022 16:49:26 +0200 > > > > Jiri Olsa wrote: > > > > > > > > > On Thu, May 26, 2022 at 11:25:30PM +0900, Masami Hiramatsu wrote: > > > > > > On Tue, 24 May 2022 19:23:01 -0400 > > > > > > Steven Rostedt wrote: > > > > > > > > > > > > > On Sat, 7 May 2022 13:46:52 +0900 > > > > > > > Masami Hiramatsu wrote: > > > > > > > > > > > > > > Is this expected to go through the BPF tree? > > > > > > > > > > > > > > > > > > > Yes, since rethook (fprobe) is currently used only from eBPF. > > > > > > Jiri, can you check this is good for your test case? > > > > > > > > > > sure I'll test it.. can't see the original email, > > > > > perhaps I wasn't cc-ed.. but I'll find it > > > > > > > > Here it is. I Cc-ed your @kernel.org address. > > > > https://lore.kernel.org/all/165189881197.175864.14757002789194211860.stgit@devnote2/T/#u > > > > > > > > > > > > > > is this also related to tracing 'idle' functions, > > > > > as discussed in here? > > > > > https://lore.kernel.org/bpf/20220515203653.4039075-1-jolsa@kernel.org/ > > > > > > > > Ah, yes. So this may not happen with the above patch, but for the > > > > hardening (ensuring it is always safe), I would like to add this. > > > > > > > > > > > > > > because that's the one I can reproduce.. but I can > > > > > certainly try that with your change as well > > > > > > > > Thank you! > > > > > > it did not help the idle warning as expected, but I did not > > > see any problems running bpf tests on top of this > > > > Oops, right. I forgot this is only for the rethook, not protect the > > fprobe handlers, since fprobe code doesn't involve the RCU code (it > > depends on ftrace's check). Sorry about that. > > Hmm, I need to add a test code for this issue, but that could be > > solved by your noninstr patch. > > > > > Masami, > > It's not clear to me, do you intend to send a new revision with some > more tests or this patch as is ready to go into bpf tree? OK, let me make a test code against this issue. This may need a raw fprobe test code (not a test case because it depends on that we can trace the "arch_cpu_idle()"), but that test code won't work after the "arch_cpu_idle()" is marked as noinstr (thus the test code will only for the kernel which doesn't have the noinstr patch). I want to add this check for the case if someone accidentally add a function which is not covered by RCU and that is tracable by fprobe (ftrace). Thus this is a kind of preventative fix. Thank you, > > > > Thank you, > > > > > > > > jirka > > > > > > > > > > > > > > > > > jirka > > > > > > > > > > > > > > > > > Thank you, > > > > > > > > > > > > > > > > > > > -- Steve > > > > > > > > > > > > > > > > > > > > > > Since the rethook_recycle() will involve the call_rcu() for reclaiming > > > > > > > > the rethook_instance, the rethook must be set up at the RCU available > > > > > > > > context (non idle). This rethook_recycle() in the rethook trampoline > > > > > > > > handler is inevitable, thus the RCU available check must be done before > > > > > > > > setting the rethook trampoline. > > > > > > > > > > > > > > > > This adds a rcu_is_watching() check in the rethook_try_get() so that > > > > > > > > it will return NULL if it is called when !rcu_is_watching(). > > > > > > > > > > > > > > > > Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook") > > > > > > > > Signed-off-by: Masami Hiramatsu > > > > > > > > --- > > > > > > > > kernel/trace/rethook.c | 9 +++++++++ > > > > > > > > 1 file changed, 9 insertions(+) > > > > > > > > > > > > > > > > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c > > > > > > > > index b56833700d23..c69d82273ce7 100644 > > > > > > > > --- a/kernel/trace/rethook.c > > > > > > > > +++ b/kernel/trace/rethook.c > > > > > > > > @@ -154,6 +154,15 @@ struct rethook_node *rethook_try_get(struct rethook *rh) > > > > > > > > if (unlikely(!handler)) > > > > > > > > return NULL; > > > > > > > > > > > > > > > > + /* > > > > > > > > + * This expects the caller will set up a rethook on a function entry. > > > > > > > > + * When the function returns, the rethook will eventually be reclaimed > > > > > > > > + * or released in the rethook_recycle() with call_rcu(). > > > > > > > > + * This means the caller must be run in the RCU-availabe context. > > > > > > > > + */ > > > > > > > > + if (unlikely(!rcu_is_watching())) > > > > > > > > + return NULL; > > > > > > > > + > > > > > > > > fn = freelist_try_get(&rh->pool); > > > > > > > > if (!fn) > > > > > > > > return NULL; > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Masami Hiramatsu (Google) > > > > > > > > > > > > -- > > > > Masami Hiramatsu (Google) > > > > > > -- > > Masami Hiramatsu (Google) -- Masami Hiramatsu (Google)