From patchwork Sun Nov 5 16:10:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 161678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2197876vqu; Sun, 5 Nov 2023 08:11:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbIOX6P5jl8jMYkgiahSAJBqaPkJBJNbobElnsEsk/Hlq+zmDOaUWn1R+nLKlnkzj5GQDC X-Received: by 2002:a05:6a21:47ca:b0:181:bc16:48d7 with SMTP id as10-20020a056a2147ca00b00181bc1648d7mr7895004pzc.51.1699200673986; Sun, 05 Nov 2023 08:11:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200673; cv=none; d=google.com; s=arc-20160816; b=EqFNxhs/lGPZwWOirjqJpy8xtqujA93yJbTf7KtSJzPObxY0J8JtCvTgULJVCECoWc b8JJfc+BQ6C/33kwShV9wSkCZVsn3iNmgWvPdnVZ/DHRwNPN+mKcScKDIIzAhLvmYmys sSKAPSqmopiznj2slJWX6Y/7DmgRSdBLtH5j2Kl1HFOXPGDjV5A5VIP7v8YNL79BooHU LG4BUE+9FItZX1kt2RwoVFs145pmvQG3EqFS8wWOQWZ2VKvC4ZuMz+llPuODbR9QfWco 9D7TrVeE7wsLfFJOdkljaVxzpFKIMu+vc2b1aSmBI2QF0Yh+OVoLQRXzb6DZcA8drBiT HvyQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ibtVobGBbah3nTuNwHOOFIWdXfUfyT9b9e/qqj9EFas=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=NIBLkf28vHXyW+DvZBeF06QFjpryguILNmI/C6+eNMpDZyeclmUC77f56S2OYFizd/ dtXzidby3mSpBa8jJxhSf3h0iZ3SIqHyasj3Lvjq/wcBuIv7s2x6pnvUeYuwZzT5MKxo gQKo00ql9ht4EIRBO84Ysx06vX9mYqVESItU+mkOEauacG1u3iad4WievX8quivHeRQ4 x/L5NWgvacQy36//+2ekgxexQSBpDlpHBNYbRI97AAPMO23aLGeKsudCcru4Sp+NKWEe 1qWSYnO4J0hz6nJ48W5LRmYCgsQ3ZjwFyU58JF0YhiOPvdDPUhjkpmUzEEZGQI3u9/mM +dxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t9r39sEc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id fb30-20020a056a002d9e00b006b74a46cd3fsi6499244pfb.229.2023.11.05.08.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:11:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t9r39sEc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4C8A68057989; Sun, 5 Nov 2023 08:11:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229514AbjKEQKp (ORCPT + 34 others); Sun, 5 Nov 2023 11:10:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjKEQKm (ORCPT ); Sun, 5 Nov 2023 11:10:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4DE5E0 for ; Sun, 5 Nov 2023 08:10:39 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36D8AC433C9; Sun, 5 Nov 2023 16:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200639; bh=2WlQKdWbi99vKuQZnLhkUQgCEXy+Nfuzu2d7nEzVsTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t9r39sEcBlbf74NlrzR4B8Lle9WJaLJPkd7Yj8058moBUJM9BSEIitXmIzuxEEaXi xfkKEr9LFKF5//Xf6ZTafDe5ngETaGLMNpSCFrglua32coY+eWP255NG3KIJGChiJM 0mPhZ4OmmEk0xGvLSIY6RR+Kz4+MC4xpgpuqNvffIJkR7UBCwyinyVK+eafTCP3MbP hE8/xAY8TcGzILkYg8YnukhSFlP5gLxADP46/f1t6q+O1md8kd0PjUFDHEwEXUGkyI 21TvMVdjRGRPaE51PhOxqGcdeEsaN4MM+WVwTluLfRpn1M/g0G99Zs5mItY7YHZsWO 0gnyqS2oZQ8hg== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [RFC PATCH 20/32] function_graph: Pass the size of reserved data when retrieving it Date: Mon, 6 Nov 2023 01:10:34 +0900 Message-Id: <169920063363.482486.14684899342898937044.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169920038849.482486.15796387219966662967.stgit@devnote2> References: <169920038849.482486.15796387219966662967.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:11:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781741046131810497 X-GMAIL-MSGID: 1781741046131810497 From: Masami Hiramatsu (Google) Make the fgraph_retrieve_data() returns the reverved data size via size_byte parameter. Signed-off-by: Masami Hiramatsu (Google) --- include/linux/ftrace.h | 2 +- kernel/trace/fgraph.c | 5 ++++- kernel/trace/trace_selftest.c | 10 +++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 115758fe9fec..2e24a2611ca8 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -1050,7 +1050,7 @@ struct fgraph_ops { }; void *fgraph_reserve_data(int size_bytes); -void *fgraph_retrieve_data(void); +void *fgraph_retrieve_data(int *size_bytes); /* * Stack of return addresses for functions diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index e51695441476..0b8a1daef733 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -289,6 +289,7 @@ void *fgraph_reserve_data(int size_bytes) /** * fgraph_retrieve_data - Retrieve stored data from fgraph_reserve_data() + * @size_bytes: pointer to retrieved data size. * * This is to be called by a fgraph_ops retfunc(), to retrieve data that * was stored by the fgraph_ops entryfunc() on the function entry. @@ -300,7 +301,7 @@ void *fgraph_reserve_data(int size_bytes) * matching entryfunc() for the retfunc() this is called from. * Or NULL if there was nothing stored. */ -void *fgraph_retrieve_data(void) +void *fgraph_retrieve_data(int *size_bytes) { unsigned long val; int curr_ret_stack = current->curr_ret_stack; @@ -313,6 +314,8 @@ void *fgraph_retrieve_data(void) val = current->ret_stack[curr_ret_stack - 2]; if (__get_type(val) != FGRAPH_TYPE_DATA) return NULL; + if (size_bytes) + *size_bytes = (__get_data(val) - 1) * sizeof(long); return ¤t->ret_stack[curr_ret_stack - (__get_data(val) + 1)]; diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 14966d8509ed..c656ec5b3348 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c @@ -807,15 +807,23 @@ static __init void store_return(struct ftrace_graph_ret *trace, const char *type = fgraph_store_type_name; long long expect = 0; long long found = -1; + int size; char *p; - p = fgraph_retrieve_data(); + p = fgraph_retrieve_data(&size); if (!p) { snprintf(fgraph_error_str_buf, sizeof(fgraph_error_str_buf), "Failed to retrieve %s\n", type); fgraph_error_str = fgraph_error_str_buf; return; } + if (fgraph_store_size > size) { + snprintf(fgraph_error_str_buf, sizeof(fgraph_error_str_buf), + "Retrieved size %d is smaller than expected %d\n", + size, (int)fgraph_store_size); + fgraph_error_str = fgraph_error_str_buf; + return; + } switch (fgraph_store_size) { case 1: