On Thu, 14 Aug 2025 13:05:35 -0400
Sasha Levin <sas...@kernel.org> wrote:

> On Wed, 
> Got a small build error:
> 
> kernel/trace/trace_functions_graph.c: In function ‘get_return_for_leaf’:
> ./include/linux/stddef.h:16:33: error: ‘struct fgraph_retaddr_ent_entry’ has 
> no member named ‘args’
>     16 | #define offsetof(TYPE, MEMBER)  __builtin_offsetof(TYPE, MEMBER)
>        |                                 ^~~~~~~~~~~~~~~~~~
> kernel/trace/trace_functions_graph.c:640:40: note: in expansion of macro 
> ‘offsetof’
>    640 |                                 size = offsetof(struct 
> fgraph_retaddr_ent_entry, args);
>        |                                        ^~~~~~~~
> 
> Does this look right on top of your patch:

Bah, it was on the todo list to add args to retaddr. But it never was done.

> 
> diff --git a/kernel/trace/trace_functions_graph.c 
> b/kernel/trace/trace_functions_graph.c
> index 25ea71edb8da..f0f37356ef29 100644
> --- a/kernel/trace/trace_functions_graph.c
> +++ b/kernel/trace/trace_functions_graph.c
> @@ -637,20 +637,21 @@ get_return_for_leaf(struct trace_iterator *iter,
>                           */
>                          if (unlikely(curr->ent.type == 
> TRACE_GRAPH_RETADDR_ENT)) {
>                                  data->ent.rent = *(struct 
> fgraph_retaddr_ent_entry *)curr;
> -                               size = offsetof(struct 
> fgraph_retaddr_ent_entry, args);
> +                               /* fgraph_retaddr_ent_entry doesn't have args 
> field */

"doesn't have args field" yet!

> +                               size = sizeof(struct 
> fgraph_retaddr_ent_entry);
> +                               args_size = 0;
>                          } else {
>                                  data->ent.ent = *curr;
>                                  size = offsetof(struct 
> ftrace_graph_ent_entry, args);
> +                               /* If this has args, then append them to 
> after the ent. */
> +                               args_size = iter->ent_size - size;
> +                               if (args_size > sizeof(long) * 
> FTRACE_REGS_MAX_ARGS)
> +                                       args_size = sizeof(long) * 
> FTRACE_REGS_MAX_ARGS;
> +
> +                               if (args_size >= sizeof(long))
> +                                       memcpy((void *)&data->ent.ent + size,
> +                                              (void*)curr + size, args_size);
>                          }

Here's a different update:

-- Steve


diff --git a/kernel/trace/trace_functions_graph.c 
b/kernel/trace/trace_functions_graph.c
index 66e1a527cf1a..a7f4b9a47a71 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -27,14 +27,21 @@ struct fgraph_cpu_data {
        unsigned long   enter_funcs[FTRACE_RETFUNC_DEPTH];
 };
 
+struct fgraph_ent_args {
+       struct ftrace_graph_ent_entry   ent;
+       /* Force the sizeof of args[] to have FTRACE_REGS_MAX_ARGS entries */
+       unsigned long                   args[FTRACE_REGS_MAX_ARGS];
+};
+
 struct fgraph_data {
        struct fgraph_cpu_data __percpu *cpu_data;
 
        /* Place to preserve last processed entry. */
        union {
-               struct ftrace_graph_ent_entry   ent;
+               struct fgraph_ent_args          ent;
+               /* TODO allow retaddr to have args */
                struct fgraph_retaddr_ent_entry rent;
-       } ent;
+       };
        struct ftrace_graph_ret_entry   ret;
        int                             failed;
        int                             cpu;
@@ -627,10 +634,13 @@ get_return_for_leaf(struct trace_iterator *iter,
                         * Save current and next entries for later reference
                         * if the output fails.
                         */
-                       if (unlikely(curr->ent.type == TRACE_GRAPH_RETADDR_ENT))
-                               data->ent.rent = *(struct 
fgraph_retaddr_ent_entry *)curr;
-                       else
-                               data->ent.ent = *curr;
+                       if (unlikely(curr->ent.type == 
TRACE_GRAPH_RETADDR_ENT)) {
+                               data->rent = *(struct fgraph_retaddr_ent_entry 
*)curr;
+                       } else {
+                               int size = min((int)sizeof(data->ent), 
(int)iter->ent_size);
+
+                               memcpy(&data->ent, curr, size);
+                       }
                        /*
                         * If the next event is not a return type, then
                         * we only care about what type it is. Otherwise we can


Reply via email to