Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2410051ioo; Sat, 28 May 2022 12:43:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynJZSLng/4rMjlzD9hiJMM7HdZnqORKiNjA7f8qOrG6omDVuan6qugpeU2XmioaIvbOooy X-Received: by 2002:a17:902:8f86:b0:162:22ff:496b with SMTP id z6-20020a1709028f8600b0016222ff496bmr30328577plo.105.1653767031592; Sat, 28 May 2022 12:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653767031; cv=none; d=google.com; s=arc-20160816; b=d3LNmU/pIgm7D24IP2sjxqQQ63/wasilW9+bINvvB35o1QgbckKqI7YwtCJFjr57MZ lv1ziDx5QHlMDoUc6yhaxNwC1NkBxKtNI1kPMLnB52Zva12xvNnUtVg2HPosm6mfqkkd 0Rh5cmRojN3EcCxERKDyoHPR9rC8zJDBSxk8yrHm9HOJQC8AvSSydyB/DXwW4yGwfsI+ IEl+BRx8CnW10J2W87D5DEGSjPN8EIQ3xnWllLybtJ9Py+4lVP/81Y1Yt7loxvxVMgxH X7bC+Ka4sRxR1OwsN6orm/XZg8Eb6wwapiPXq9qoznZBo7DWs1XB+NmZ7ITDBwA39YOP 42ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=oukq4BrRroZdnwtsCtnGKzub7xqcAGtJO6v8azC2xEA=; b=TOdp5JdocAfQg6sI951x1ySAODBOQilJX8uxaa7aG0IaWqKGGXJAMUEZu2NyFoQpgY kkLyuDX76bm3SYzDJdzgTvwGJPyVrHNOCY6YqlDGvoPqKT+GCcFmREtFRYkRXCKTDKMV d6NnBRdK3unpGF61iEpnBwhto0ev7l+rtMRBfzuLGJIpFWwykqAM+/7GPBc13mVbfKi5 BYuzU/5k2SPjxlVK7J6wqx+2zz+PUkW+UoblnpiTdmYRemlf96Z99LAeGKr1ooOrtudZ d6scbC4bWAQ/F1AyR8O8QjIYV7bLj1nTBVkAwWBtsjLE034rct2/OqloYpnsprsZ8I0X YWIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XBVQbQpB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x5-20020a63fe45000000b003c622eb7a63si10077064pgj.512.2022.05.28.12.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:43:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XBVQbQpB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AEC01DA6B; Sat, 28 May 2022 12:07:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345788AbiE0WKS (ORCPT + 99 others); Fri, 27 May 2022 18:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiE0WKQ (ORCPT ); Fri, 27 May 2022 18:10:16 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1FDA6622F; Fri, 27 May 2022 15:10:12 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id jx22so11008945ejb.12; Fri, 27 May 2022 15:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oukq4BrRroZdnwtsCtnGKzub7xqcAGtJO6v8azC2xEA=; b=XBVQbQpBf//NeoTj4WSNgbW9qr+4TUIyl6au6/UKJpoL1clDXJuPyxyFEe5KgJ3bLh +sVImQkHxvDbJxMotprxSg66yKl30jBNrmBWhhAdNUk5ssvocQvWnLaG68p/0j3Wm6z9 5KiRbciA8jCx3Oo/QtTySsMgTRY4CO+kFTGGTQXT9C2xgeMinCa8WhD1Ak+zavmKnQcI KpWXOLztoszMB7oTtCRAHdlAfuhB4Rq47PdTlC4QZIVenpj6KOR9m77ZEOeW4lp7pPa5 9OJSggbvyCAo9a7DWm64hps1494GzuZ5HCBw0KDXrQUTk78in9Og8U05MLM4/HHyii7B 79Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oukq4BrRroZdnwtsCtnGKzub7xqcAGtJO6v8azC2xEA=; b=1BGW3gdh4dwV4LPbN3HsNSKfbgqI1RI+a/VQo8Aksc0ydntgcQ7yXgcGkEvkY5tYR3 shNCeca7vDYg4TaVBfRx/rGrXA3zczV7U8TfRU0TvE6m0di8wlidoN6BNRDkb5h+L4gM fOrmx4ArrZxRfN+F+7yLn9NBTftH4ZYe3LIyo34pILlfRQDQf0Xm0ybUbzfanaed52RG 131nOxeIe6aKio75F7JGbbu6eSHafzbYQcfNykgy56M8Hq4+w0LY96wz77kmawomM1Lo r6JQGrn+JrW5erHsF1Q7pwMsp3rMuNgyyAv8M77LXQa3qlqN43Wnbf7VcdxXkqnspJLM Zo6w== X-Gm-Message-State: AOAM5322JliUDVayBnTnQPXaH3D6aTNlsiSwu7PIYGWFGJIoG01GAwMk 5mZG+pdYOC36GYMyescEUZA= X-Received: by 2002:a17:906:9753:b0:6fe:dece:982a with SMTP id o19-20020a170906975300b006fedece982amr25834832ejy.560.1653689411016; Fri, 27 May 2022 15:10:11 -0700 (PDT) Received: from krava ([83.240.62.49]) by smtp.gmail.com with ESMTPSA id o25-20020a509b19000000b0042617ba63a7sm2646180edi.49.2022.05.27.15.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 15:10:10 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Sat, 28 May 2022 00:10:08 +0200 To: Masami Hiramatsu Cc: Jiri Olsa , Steven Rostedt , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, "Paul E. McKenney" Subject: Re: [PATCH] rethook: Reject getting a rethook if RCU is not watching Message-ID: References: <165189881197.175864.14757002789194211860.stgit@devnote2> <20220524192301.0c2ab08a@gandalf.local.home> <20220526232530.cb7d0aed0c60625ef093a735@kernel.org> <20220527011434.9e8c47d1b40f549baf2cf52a@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220527011434.9e8c47d1b40f549baf2cf52a@kernel.org> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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, 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 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)