Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3487961ioo; Wed, 25 May 2022 01:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXQybpbl7Z/5ErEoMhMnJV4fFyZhoURxDqpn+zfV8roBcHTueUvhD/WXqZq6STWEKl4VC/ X-Received: by 2002:a63:e017:0:b0:3f2:543b:8402 with SMTP id e23-20020a63e017000000b003f2543b8402mr27602087pgh.209.1653467600196; Wed, 25 May 2022 01:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653467600; cv=none; d=google.com; s=arc-20160816; b=MsVirUwpBxXzz+Y6n0CuN+ruuEqTJThTKAJfmq98Prb6DvVuzfzY/Ro3owTXp0Sccz aAP5djkXfiuI5DVS2ei+uB8jTw3Gc9teJIWJ3aa6wZoqZsdbwpyK6HRoBkv3w8WcAMDm DkcryUQfYN/M9MWyw5JOptpkDP6mH71CK309Q+h7QQ7U5iFbnWlUJI+fh9InMtrOD2Rf 3yo+YA69CvsDvnz6q6cTX2UiW17DLaJF3NrNnLk6DH1e/49gJYCZZzBiqNKsYW/xsHfK xj5o7EIBvfEts54qJkWU054fOoqaQmEsEQfezmomOMR+AB51NbCXHMBMMJp8ffvC+9m3 /w3A== 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; bh=+hUiBn7QR4aJQpGQawgx2w4ncnKsj6j7VWG8mXRTP3o=; b=X5c0A71pP0eiwi2RYpuCK/ZWlhL+XgCajeKUnzgI8uHODHmcdmTm86421T3ukUMsI3 gHnDUb1xuLUibC8LSq5csVV5GrmS7zVQXV2eRbayz6rfkWo2IqFbJPGoiur7VLQmhyTM cuC3x3QnYbnGPNKvmRBF9WZymBPnpcDv4Nn69UEdF4FikCp3DK/+wsu9+jXaY4gs41RL GmpYrQfax5NkCN6q5vT1FChw42cAjpbRrA0o3EDZJLKmd/HD8LcSSxq7MJKp1YbYYEmG 42a+8rWGZs3Ee7gVbN1tQyLE5lMxLBB8EQKPjG3ZWFiaWuSQ6i60tKoIp4dm3MJ1gB+p 2aPg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a056a0010cb00b005189905de2asi12288008pfu.172.2022.05.25.01.33.04; Wed, 25 May 2022 01:33:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242614AbiEXXXI (ORCPT + 99 others); Tue, 24 May 2022 19:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235147AbiEXXXG (ORCPT ); Tue, 24 May 2022 19:23:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40A135C879; Tue, 24 May 2022 16:23:05 -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 D265B617F1; Tue, 24 May 2022 23:23:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EB5AC34100; Tue, 24 May 2022 23:23:03 +0000 (UTC) Date: Tue, 24 May 2022 19:23:01 -0400 From: Steven Rostedt To: Masami Hiramatsu Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Jiri Olsa , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH] rethook: Reject getting a rethook if RCU is not watching Message-ID: <20220524192301.0c2ab08a@gandalf.local.home> In-Reply-To: <165189881197.175864.14757002789194211860.stgit@devnote2> References: <165189881197.175864.14757002789194211860.stgit@devnote2> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; 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.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 On Sat, 7 May 2022 13:46:52 +0900 Masami Hiramatsu wrote: Is this expected to go through the BPF tree? -- 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;