Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp512096ioo; Thu, 26 May 2022 08:24:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFSzAgTUbKkb1mYLiEgXD6xToqIR8svkTdZA8d+ngNE3yjGLgQ9tZGQzJ3VEyix51QnpAX X-Received: by 2002:a63:688a:0:b0:3fa:a80c:a228 with SMTP id d132-20020a63688a000000b003faa80ca228mr11633820pgc.182.1653578662240; Thu, 26 May 2022 08:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653578662; cv=none; d=google.com; s=arc-20160816; b=csIBJvc4hBfTHkqhWvSaIsOeUrf0k9SrzbTmcS0hBRnVxbYVVoV0+vhVBbN2Ccj93S fX0GCwOr2W49iVG0lzDlEbHWZc/sOKVUwCx4jZ6kHsP+k1P2c9zle0M5KJ7Ie6+/hqdW jotA8OjguqbvBC3C188jps1qPrGt+ipDUJIMa+F99dc/bWE7bRTDZvXnNiLPlYvjfgCv aEa+NCEsK/NfIksFC90KRDh41mbSZPu1sy9G/ON54b0L6Li/ojJFNTQbHxI8YFOkd4QC yszlKuZOdLeWn6QmBKKN3bcHlRd006z+/iUUHuwaKJsFO5VGpONy0FvaApJ7vLh9jeiC dROg== 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=zls+MzWfNPZtlXrrhoUFcg/vRk2lvR8P63hFWQr6QVQ=; b=wlMXJh9xzmANV4m4OQJg+Fqeu/HRlwQOnd/zwgps5Pa3RA64P5sz1T45IENI179b9Q XfCAlLZZaF7amTGaTjIm1eSmic5fG2H6mmSwkSi0iJFvFRnGfZBZD2UurSxlzyDW15Az SrXyR6VlWBqX4kx65KU2tD71eas516Rryp3M+oIpf0wowUo4gbs/6fh7Dp2gL7jEfAV/ RLr9kglses3TJp5INs+Y3vSifPlnKSzNQb41CcRR3J921/a1YWRhWmhZzwO3jKc2hx1F yi4LtitNHqSZ6dXckvcBvNZ/+2gRoHrNte9RYWQDJkNvDRKdWEXkEdZiN20H0GUEAkkh dI+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VN7XyPmc; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a056a00180f00b005191e2b27a5si2237337pfa.58.2022.05.26.08.24.10; Thu, 26 May 2022 08:24:22 -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=@gmail.com header.s=20210112 header.b=VN7XyPmc; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347764AbiEZOtr (ORCPT + 99 others); Thu, 26 May 2022 10:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243362AbiEZOtk (ORCPT ); Thu, 26 May 2022 10:49:40 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E3812AE4; Thu, 26 May 2022 07:49:36 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id f9so3561275ejc.0; Thu, 26 May 2022 07:49:36 -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=zls+MzWfNPZtlXrrhoUFcg/vRk2lvR8P63hFWQr6QVQ=; b=VN7XyPmcnf+r0c9uFfso0TaP5OfKEcmXy7GyTZfhd0/K/m4YGQQybFCZdWUeQuvrmK z7AiaUvxEbiCvOqLvf42ZUorbp0AbsWGuQcl8vJK6ZE2t5O166B0PyKU/3ACPrVGlD7Y 3Q+WhPMC6zgre4S6rMKdeW6MTClNoFRUjXXhjtp4OWsQpkgs/VLdcfHmy0PdMO/dWxHf oFP6gSNbVSOwXuC45vmwcaBhcB6BhQnbkMh64RtCuUxeDTAUdqkEYoz/hcSs2U1Xojaa skwAJRhwpfDt6xDbPdA/FjKWGcbRaHQZlZDq0i38toEqVu3xlQlT++pUYOwiJfd+iKcc bFdg== 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=zls+MzWfNPZtlXrrhoUFcg/vRk2lvR8P63hFWQr6QVQ=; b=VrGqqjRnVoIdylojwLpfhDFjuo6jngA9vAUctQHSZ7WuEOlxF4SC9p/fIwWdxnIaiw /4zrSXRksvjPYziek6hTe+ycODX1L2wtC/VtTNNjBAnLNRTrPWD67YW/cA5WmTDfTDTL rxt6UISruFoF2jM27NoS228dIX+hPDmk5mP+1LxNEPhyBT6KKcLad/BHNaQH9PTt/ea1 Rgd/QXFx/QdbIidEGuCq2AKQ/bvl8TUTy2oXGYixZ4HP3EhJN9TZsuvdlYU2ijwdvrcy hOb4wSbF4WqET22j+pupNZ42W9Ui5UMEg4DKU5+lk5Ryz/vaIpxzJGFcJXfWQT6+HFCw UCmQ== X-Gm-Message-State: AOAM532OFxTWdFIJngwlrgLzdhoynO/27fo9e6TZ3t7/SnxANm3m0dOh 8xg9wjZjAblQImLAjIV/fTYgSjpMlKwcgI7z X-Received: by 2002:a17:907:da3:b0:6fe:f08b:776 with SMTP id go35-20020a1709070da300b006fef08b0776mr17607635ejc.558.1653576575332; Thu, 26 May 2022 07:49:35 -0700 (PDT) Received: from krava (net-93-65-242-160.cust.vodafonedsl.it. [93.65.242.160]) by smtp.gmail.com with ESMTPSA id b23-20020a1709065e5700b006fe9ba21333sm567992eju.113.2022.05.26.07.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 07:49:34 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Thu, 26 May 2022 16:49:26 +0200 To: Masami Hiramatsu Cc: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220526232530.cb7d0aed0c60625ef093a735@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 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 is this also related to tracing 'idle' functions, as discussed in here? https://lore.kernel.org/bpf/20220515203653.4039075-1-jolsa@kernel.org/ because that's the one I can reproduce.. but I can certainly try that with your change as well 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)