[DTrace-devel] [PATCH] Improve BPF-map-create error message for E2BIG

Kris Van Hees kris.van.hees at oracle.com
Tue Aug 9 20:41:25 UTC 2022


On Mon, Aug 08, 2022 at 07:02:36PM -0400, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> When syscall bpf(BPF_MAP_CREATE) fails due to too big a map, an E2BIG
> is returned.  Meanwhile, strerror(E2BIG) is "Argument list too long",
> which is not very helpful.  Simply say, "Too big".
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  libdtrace/dt_bpf.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
> index de6735ae..7209e920 100644
> --- a/libdtrace/dt_bpf.c
> +++ b/libdtrace/dt_bpf.c
> @@ -143,6 +143,8 @@ create_gmap(dtrace_hdl_t *dtp, const char *name, enum bpf_map_type type,
>  
>  		snprintf(msg, sizeof(msg),
>  			 "failed to create BPF map '%s'", name);
> +		if (errno == E2BIG)
> +			return dt_bpf_error(dtp, "%s: Too big\n", msg);

There is actually more that we should be doing because we routinely pass a
size_t into create_gmap as value size (vsz) which is declared as an int.
So, e.g. when you specify -xscratchsize=100t the map will be created with
a size of 16 (due to how scratchsize is adjusted (+8) and truncated down to
32 bits).

So, I think I'll create an alternative patch that does a few things:

(1) change the prototype to accept size_t for ksz and vsz
(2) report E2BIG if ksz or vsz is larger than INT_MAX
(3) provide the 'Too big' error message as you do here

>  		if (errno == EPERM)
>  			return dt_bpf_lockmem_error(dtp, msg);
>  		return dt_bpf_error(dtp, "%s: %s\n", msg, strerror(errno));
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list