Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp195294lqs; Thu, 13 Jun 2024 07:43:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYlU/rsIW3A04pzoH9tUipgjSqhuIpEQYtnDiv8uJsnxYA2bzu66wSltPXdTZVzuBE308fzmsXpPMgK/WWxKimU9B68HwHatDYJjvhPw== X-Google-Smtp-Source: AGHT+IGNUEl06FS4UDoC3SW+xiEGg0OJLAMi4KKFVMZISgYaB29KWNCfhe4vfJ7lfSO82HQonqby X-Received: by 2002:a50:c309:0:b0:57c:8339:6dcc with SMTP id 4fb4d7f45d1cf-57cbd8b9c55mr10976a12.33.1718289832938; Thu, 13 Jun 2024 07:43:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718289832; cv=pass; d=google.com; s=arc-20160816; b=NkCWtnOecA55mGUcXj2TglqPnItoR1n6DeG/27wyG5W5DzyLh636G6KyoQRH3pzAEF V+NMDiQgswRzbjKERUNQ4F2KVgKnqPPBGPsvkquTs08UhVMaAKMihEJ/fNdbZEgfo3et E8Gw+WV/AL7Qnuoqmz7lo5byNv3D25Cz/ZaGx9vtYnp7qjSbXpX99soFcpUWVrGy7Ma6 iFI1jShWMtnekheHsHk8Mu/YfW/3viOQ3OhsDhS6NdTa9otgT78HzdetmuFoD6HC3Lzb E6RFBwl0IBK4PPMqfn2WDu6eZGIjhCtIZ5hufA2ztyqU6Kt5txji3szi2UDnfCJzuLAa 2r0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=eD2wXCOUKj/T3FCyeGYWu+cqM1M4868/03fFgrU7YEs=; fh=wDLyGtc9pT5i5n50I78JErZpAnsrUQr1k71DamYV8ZY=; b=g+YTTDRsMDIzHYos+p37Br4jrYJi+72e0epalMfHj5uUlZDSQDJzwxtiFQlKTG5l3e U+8lAc5kaOUTclackZ2Ta1nb2G8Jpy1go3eon35z5yleMQ+mOOisd4rbT7p5//+4XpeH 9s93T8p/buxumwKbxlytxKyxuQt+Yhw9yuXuKOy4moL2ht6NJ2Mexjl/CWTzS0yoa7s/ KeDQXiW+UXtBuyeHWg9DI7Xn38mHhGoMOfKAhEzMjNcIW1koEoWBNCjgpQ1P6WEV4QF/ 3Huv78Fkqw2gNkIbEeOlo7pFrZHoq8VOO54fcPI8UES+vujojqEGjyalnNVswRNNx4K+ e6Ow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gb72+7xO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-213451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb74416e6si805883a12.391.2024.06.13.07.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 07:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Gb72+7xO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-213451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213451-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9E7531F22F22 for ; Thu, 13 Jun 2024 14:43:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC91C1465AA; Thu, 13 Jun 2024 14:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Gb72+7xO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D545D399; Thu, 13 Jun 2024 14:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718289821; cv=none; b=PS1oML7q8f8unvNgLHE+TkqkyH8r9ovoHmO6Gj2aYmhPkqbpZDn69LNSE6Mg8vnk19aIVjEB32ZBUdqgw7sf/LDIEUSZrg6YP4w7r4kmCyATV8VQv+TAGc0ThCaExJaNVaYSxMvPyDweauVVh3nj81/+VIuw0uxT/nuknSqpKWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718289821; c=relaxed/simple; bh=U2lp9FtQVPZjq8CdUltsKztb3aNzK34AI2dW7bwkUFA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=FLZN/ANtZ4GvXfDbmaQ8kVYWeIUEFe7surlh/gG2EdTgktttkM0zH0Kkbdjnd47BoI2eJqfQ8GvfSObuQ/2OuxLpEvyaID6QTDf43klqbrmy0UsxWIiUgePzeg623tTsTBQY/XUMOHu/NLB6d4TGFGdrMnZNAGlx5/m4ekomCBk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gb72+7xO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72E64C2BBFC; Thu, 13 Jun 2024 14:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718289821; bh=U2lp9FtQVPZjq8CdUltsKztb3aNzK34AI2dW7bwkUFA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Gb72+7xOsUioNvlfIMYnfYpFkYPIAFwYVTWDro3Xhj9C3l6dKw1P+l+FEUMNJVTxP 4cCQ6ja8fXMPXI5Ws7i7Bv41+TO1UKMEb27xGC+6xHAOJEolkmVUz13zHajOLyaGcI znLtHPBFvHtTC/XnwYa+5XewLAEzrBd7JFDu01z8hKys+lBk/h5Tz9edw/sAS6bryR QzkyIyvbGLK6nwgv0rL7HCLaZ+fCY1Th30sTehEI/YSh3OzULykG9aFvsqcPT7o8sY 00e/ty+6MfKpi0cFYwYyJSCS+tIZSqi5JyPpeNB4YyptYuPsxcDdSB9CIukKnoFjUR 58crVjJqaQq7g== Date: Thu, 13 Jun 2024 23:43:37 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: LKML , Linux trace kernel , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Naresh Kamboju Subject: Re: [PATCH] function_graph: Add READ_ONCE() when accessing fgraph_array[] Message-Id: <20240613234337.cdd71759ab3d93d22eef7cf1@kernel.org> In-Reply-To: <20240613095223.1f07e3a4@rorschach.local.home> References: <20240613095223.1f07e3a4@rorschach.local.home> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 13 Jun 2024 09:52:23 -0400 Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > In function_graph_enter() there's a loop that looks at fgraph_array[] > elements which are fgraph_ops. It first tests if it is a fgraph_stub op, > and if so skips it, as that's just there as a place holder. Then it checks > the fgraph_ops filters to see if the ops wants to trace the current > function. > > But if the compiler reloads the fgraph_array[] after the check against > fgraph_stub, it could race with the fgraph_array[] being updated with the > fgraph_stub. That would cause the stub to be processed. But the stub has a > null "func_hash" field which will cause a NULL pointer dereference. > > Add a READ_ONCE() so that the gops that is compared against the > fgraph_stub is also the gops that is processed later. > > Link: https://lore.kernel.org/all/CA+G9fYsSVJQZH=nM=1cjTc94PgSnMF9y65BnOv6XSoCG_b6wmw@mail.gmail.com/ > > Fixes: cc60ee813b503 ("function_graph: Use static_call and branch to optimize entry function") > Reported-by: Naresh Kamboju > Signed-off-by: Steven Rostedt (Google) Looks good to me. Acked-by: Masami Hiramatsu (Google) Thanks. > --- > kernel/trace/fgraph.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c > index 8317d1a7f43a..fc205ad167a9 100644 > --- a/kernel/trace/fgraph.c > +++ b/kernel/trace/fgraph.c > @@ -641,7 +641,7 @@ int function_graph_enter(unsigned long ret, unsigned long func, > { > for_each_set_bit(i, &fgraph_array_bitmask, > sizeof(fgraph_array_bitmask) * BITS_PER_BYTE) { > - struct fgraph_ops *gops = fgraph_array[i]; > + struct fgraph_ops *gops = READ_ONCE(fgraph_array[i]); > int save_curr_ret_stack; > > if (gops == &fgraph_stub) > -- > 2.43.0 > -- Masami Hiramatsu (Google)