Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29740373rwd; Wed, 5 Jul 2023 17:07:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlG78gBX8DN4hvs2qf9QZthzVktceey30UaWr4Nk0Ww/8mgCmQGfw2xjptxdYXSWrj6UcUYp X-Received: by 2002:a17:903:11cf:b0:1b8:9b1b:ab53 with SMTP id q15-20020a17090311cf00b001b89b1bab53mr575865plh.20.1688602033618; Wed, 05 Jul 2023 17:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688602033; cv=none; d=google.com; s=arc-20160816; b=DFpqU3m7Usz6H7nYclfF4BglslpRH8gTx4VLouHVWAVbMILM0BRHwMs8BozPvW4g4/ fdwVINEtlwUdVZylzuABb7sxDpH+b4IsQavP+Kt8PC1EjuE9pXWUtu6nksaP4Usk8wtF ue9vmz+6QyuEvVQDCCLqfh8C4EB8S12x4Igp5WSGhTZuk13Rs8uQg+m9Oqg6BUSMkPTd vHguOMWi21qhy0j4B+X95YPKTY17Eh6QyaCFDlNZMwabB36tKtwkRhmxSVY9+PGb/jLq CV3+j85seZfUTPc9RPXRqEK+Ngu8TNX01tD5feRo0E7qVuDdxydjFDM9Mkkp3GIoA03v DX+w== 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=Y2q/HM/FK5kjPfhVKc53SLV+du8FIWunUWCpH0HKGm0=; fh=TVA2+KCtjq73Y+zyyM9hT3N4iu2/kgbU1eHY1LttLS4=; b=JjjbcHQq6BqDPHQ7vuD2Cbt8yhvfSK+YdYqhVylF0JkXScmA/r1wkpAmO1zCfp2Aeo q7uIRY9JT5NjLeRWhqIt+YV8znU2MVwD4pJmOctDn1KU0rw8gjwDzj5pA0RWS98iVxD5 j3AxDoiXuEj9kmssy21PW16zE0XOEMUOnDH4kdT2JsLWAr6qIL9eqDcGrLy41WFSXx2O kuZgpdpsFsXsB8GVOQovkJ7WOifqbdIR+fQd4s3RXdPf6c/XkZzh/+o2htchAxmBIrGK 47VlNlZFxjaHbrKSm4XxfYHrv9fViND9+flR/m+bpV+eI2/IUbGDIuecXE3aaogi/mLE BF1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S/cz9482"; 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 km4-20020a17090327c400b001b008b3dedasi85840plb.579.2023.07.05.17.06.58; Wed, 05 Jul 2023 17:07:13 -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="S/cz9482"; 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 S232446AbjGEX75 (ORCPT + 99 others); Wed, 5 Jul 2023 19:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjGEX74 (ORCPT ); Wed, 5 Jul 2023 19:59:56 -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 46355199F; Wed, 5 Jul 2023 16:59:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B293E617A4; Wed, 5 Jul 2023 23:59:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E861FC433C7; Wed, 5 Jul 2023 23:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688601594; bh=DHIRNBX13iCC8/JjXCLrk7kqMjmnnuGrMvA57hSWqdk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=S/cz9482QyzQkAuO2a2zJcUHnEQGqRKHU0imYli7KuJk4ryX7yfsr8qiGQatoIrXR jctKlQ9m0v9B2/j2Sv98stJdRAuuIN/lrEDjcF4gzcavRUUEZopfaUOnJl/oIKLGmv aUuZr+R1ZMDFlDbSHAK94v7v1nELQHlJl85Q1cCbFRYRscu0D5JwRUns4beo4FKMl4 jsaWDkrZcpdgN4FGTnCsBK0pBmKRyiLXbudflpOy6aAoT+vrr7fprAtaFrJM6XGVLJ zn/L54BYNszBCaI2/7UGF1MC0w3t75cxFFYXehbqi1UwQTDRI4IS/+3U43C+ICUPEC jAwsLYPnFeyYg== Date: Thu, 6 Jul 2023 08:59:49 +0900 From: Masami Hiramatsu (Google) To: "Masami Hiramatsu (Google)" , Steven Rostedt Cc: Jiri Olsa , Steven Rostedt , Mark Rutland , lkml , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH] fprobe: Ensure running fprobe_exit_handler() finished before calling rethook_free() Message-Id: <20230706085949.846329012c99057ef99ea8ef@kernel.org> In-Reply-To: <168796344232.46347.7947681068822514750.stgit@devnote2> References: <20230628012305.978e34d44f1a53fe20327fde@kernel.org> <168796344232.46347.7947681068822514750.stgit@devnote2> 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=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,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 Wed, 28 Jun 2023 23:44:02 +0900 "Masami Hiramatsu (Google)" wrote: > From: Masami Hiramatsu (Google) > > Ensure running fprobe_exit_handler() has finished before > calling rethook_free() in the unregister_fprobe() so that caller can free > the fprobe right after unregister_fprobe(). > > unregister_fprobe() ensured that all running fprobe_entry/exit_handler() > have finished by calling unregister_ftrace_function() which synchronizes > RCU. But commit 5f81018753df ("fprobe: Release rethook after the ftrace_ops > is unregistered") changed to call rethook_free() after > unregister_ftrace_function(). So call rethook_stop() to make rethook > disabled before unregister_ftrace_function() and ensure it again. > Steve, can you review this? without this fix, Jiri's patch may cause another timing issue. Thanks, > Fixes: 5f81018753df ("fprobe: Release rethook after the ftrace_ops is unregistered") > Cc: stable@vger.kernel.org > Signed-off-by: Masami Hiramatsu (Google) > --- > include/linux/rethook.h | 1 + > kernel/trace/fprobe.c | 3 +++ > kernel/trace/rethook.c | 13 +++++++++++++ > 3 files changed, 17 insertions(+) > > diff --git a/include/linux/rethook.h b/include/linux/rethook.h > index c8ac1e5afcd1..bdbe6717f45a 100644 > --- a/include/linux/rethook.h > +++ b/include/linux/rethook.h > @@ -59,6 +59,7 @@ struct rethook_node { > }; > > struct rethook *rethook_alloc(void *data, rethook_handler_t handler); > +void rethook_stop(struct rethook *rh); > void rethook_free(struct rethook *rh); > void rethook_add_node(struct rethook *rh, struct rethook_node *node); > struct rethook_node *rethook_try_get(struct rethook *rh); > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > index 0121e8c0d54e..75517667b54f 100644 > --- a/kernel/trace/fprobe.c > +++ b/kernel/trace/fprobe.c > @@ -364,6 +364,9 @@ int unregister_fprobe(struct fprobe *fp) > fp->ops.saved_func != fprobe_kprobe_handler)) > return -EINVAL; > > + if (fp->rethook) > + rethook_stop(fp->rethook); > + > ret = unregister_ftrace_function(&fp->ops); > if (ret < 0) > return ret; > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c > index 60f6cb2b486b..468006cce7ca 100644 > --- a/kernel/trace/rethook.c > +++ b/kernel/trace/rethook.c > @@ -53,6 +53,19 @@ static void rethook_free_rcu(struct rcu_head *head) > kfree(rh); > } > > +/** > + * rethook_stop() - Stop using a rethook. > + * @rh: the struct rethook to stop. > + * > + * Stop using a rethook to prepare for freeing it. If you want to wait for > + * all running rethook handler before calling rethook_free(), you need to > + * call this first and wait RCU, and call rethook_free(). > + */ > +void rethook_stop(struct rethook *rh) > +{ > + WRITE_ONCE(rh->handler, NULL); > +} > + > /** > * rethook_free() - Free struct rethook. > * @rh: the struct rethook to be freed. > -- Masami Hiramatsu (Google)