@@ -371,15 +371,13 @@ static const char *type_from_btf_id(struct btf *btf, s32 id)
371
371
return NULL ;
372
372
}
373
373
374
- static const struct btf_param * find_btf_func_param (const char * funcname , s32 * nr ,
375
- bool tracepoint )
374
+ static const struct btf_type * find_btf_func_proto (const char * funcname )
376
375
{
377
376
struct btf * btf = traceprobe_get_btf ();
378
- const struct btf_param * param ;
379
377
const struct btf_type * t ;
380
378
s32 id ;
381
379
382
- if (!btf || !funcname || ! nr )
380
+ if (!btf || !funcname )
383
381
return ERR_PTR (- EINVAL );
384
382
385
383
id = btf_find_by_name_kind (btf , funcname , BTF_KIND_FUNC );
@@ -396,6 +394,22 @@ static const struct btf_param *find_btf_func_param(const char *funcname, s32 *nr
396
394
if (!btf_type_is_func_proto (t ))
397
395
return ERR_PTR (- ENOENT );
398
396
397
+ return t ;
398
+ }
399
+
400
+ static const struct btf_param * find_btf_func_param (const char * funcname , s32 * nr ,
401
+ bool tracepoint )
402
+ {
403
+ const struct btf_param * param ;
404
+ const struct btf_type * t ;
405
+
406
+ if (!funcname || !nr )
407
+ return ERR_PTR (- EINVAL );
408
+
409
+ t = find_btf_func_proto (funcname );
410
+ if (IS_ERR (t ))
411
+ return (const struct btf_param * )t ;
412
+
399
413
* nr = btf_type_vlen (t );
400
414
param = (const struct btf_param * )(t + 1 );
401
415
@@ -462,6 +476,32 @@ static const struct fetch_type *parse_btf_arg_type(int arg_idx,
462
476
return find_fetch_type (typestr , ctx -> flags );
463
477
}
464
478
479
+ static const struct fetch_type * parse_btf_retval_type (
480
+ struct traceprobe_parse_context * ctx )
481
+ {
482
+ struct btf * btf = traceprobe_get_btf ();
483
+ const char * typestr = NULL ;
484
+ const struct btf_type * t ;
485
+
486
+ if (btf && ctx -> funcname ) {
487
+ t = find_btf_func_proto (ctx -> funcname );
488
+ if (!IS_ERR (t ))
489
+ typestr = type_from_btf_id (btf , t -> type );
490
+ }
491
+
492
+ return find_fetch_type (typestr , ctx -> flags );
493
+ }
494
+
495
+ static bool is_btf_retval_void (const char * funcname )
496
+ {
497
+ const struct btf_type * t ;
498
+
499
+ t = find_btf_func_proto (funcname );
500
+ if (IS_ERR (t ))
501
+ return false;
502
+
503
+ return t -> type == 0 ;
504
+ }
465
505
#else
466
506
static struct btf * traceprobe_get_btf (void )
467
507
{
@@ -480,8 +520,15 @@ static int parse_btf_arg(const char *varname, struct fetch_insn *code,
480
520
trace_probe_log_err (ctx -> offset , NOSUP_BTFARG );
481
521
return - EOPNOTSUPP ;
482
522
}
523
+
483
524
#define parse_btf_arg_type (idx , ctx ) \
484
525
find_fetch_type(NULL, ctx->flags)
526
+
527
+ #define parse_btf_retval_type (ctx ) \
528
+ find_fetch_type(NULL, ctx->flags)
529
+
530
+ #define is_btf_retval_void (funcname ) (false)
531
+
485
532
#endif
486
533
487
534
#define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))
@@ -512,6 +559,11 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
512
559
513
560
if (strcmp (arg , "retval" ) == 0 ) {
514
561
if (ctx -> flags & TPARG_FL_RETURN ) {
562
+ if ((ctx -> flags & TPARG_FL_KERNEL ) &&
563
+ is_btf_retval_void (ctx -> funcname )) {
564
+ err = TP_ERR_NO_RETVAL ;
565
+ goto inval ;
566
+ }
515
567
code -> op = FETCH_OP_RETVAL ;
516
568
return 0 ;
517
569
}
@@ -912,9 +964,12 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
912
964
goto fail ;
913
965
914
966
/* Update storing type if BTF is available */
915
- if (IS_ENABLED (CONFIG_PROBE_EVENTS_BTF_ARGS ) &&
916
- !t && code -> op == FETCH_OP_ARG )
917
- parg -> type = parse_btf_arg_type (code -> param , ctx );
967
+ if (IS_ENABLED (CONFIG_PROBE_EVENTS_BTF_ARGS ) && !t ) {
968
+ if (code -> op == FETCH_OP_ARG )
969
+ parg -> type = parse_btf_arg_type (code -> param , ctx );
970
+ else if (code -> op == FETCH_OP_RETVAL )
971
+ parg -> type = parse_btf_retval_type (ctx );
972
+ }
918
973
919
974
ret = - EINVAL ;
920
975
/* Store operation */
0 commit comments