Skip to contentSkip to conversation

handle errno ENOTSUPP

PATCH Superseded Geliang Tang 2 participants 6 messages Jul 12, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover handle errno ENOTSUPP

From: Geliang Tang <[email protected]>

This patchset contains two fixes for handling errno ENOTSUPP. Patch 1 fixes the return value of fixup_call_args() to make sure ENOTSUPP is returned to user space correctly. Patch 2 handles ENOTSUPP in libbpf_strerror_r() in libbpf.

Geliang Tang (2):
bpf: verifier: Fix return value of fixup_call_args
libbpf: handle ENOTSUPP in libbpf_strerror_r

 kernel/bpf/verifier.c     |  6 +++---
 tools/lib/bpf/str_error.c | 11 +++++++----
 tools/lib/bpf/str_error.h |  4 ++++
 3 files changed, 14 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 bpf: verifier: Fix return value of fixup_call_args

From: Geliang Tang <[email protected]>

Run bloom_filter_map selftests (./test_progs -t bloom_filter_map) on a Loongarch platform, an error message "JIT doesn't support bpf-to-bpf calls" is got in user space, together with an unexpected errno EINVAL (22), not ENOTSUPP (524):

libbpf: prog 'inner_map': BPF program load failed: Invalid argument
libbpf: prog 'inner_map': -- BEGIN PROG LOAD LOG --
JIT doesn't support bpf-to-bpf calls
callbacks are not allowed in non-JITed programs
processed 37 insns (limit 1000000) max_states_per_insn 1 total_states -- END PROG LOAD LOG --
libbpf: prog 'inner_map': failed to load: -22
libbpf: failed to load object 'bloom_filter_map'
libbpf: failed to load BPF skeleton 'bloom_filter_map': -22 setup_progs:FAIL:bloom_filter_map__open_and_load unexpected error: -22
#16 bloom_filter_map:FAIL

Although in jit_subprogs(), the error number does be set as "ENOTSUPP":

	verbose(env, "JIT doesn't support bpf-to-bpf calls\n");
	err = -ENOTSUPP;
	goto out_free;

But afterwards in fixup_call_args(), such error number is ignored, and overwritten as "-EINVAL":

	verbose(env, "callbacks are not allowed in non-JITed programs\n");
	return -EINVAL;

This patch fixes this by changing return values of fixup_call_args() from "-EINVAL" to "err ?: -EINVAL". With this change, errno 524 is got in user space now:

libbpf: prog 'inner_map': BPF program load failed: unknown error (-524)
libbpf: prog 'inner_map': -- BEGIN PROG LOAD LOG --
JIT doesn't support bpf-to-bpf calls
processed 37 insns (limit 1000000) max_states_per_insn 1 total_states -- END PROG LOAD LOG --
libbpf: prog 'inner_map': failed to load: -524
libbpf: failed to load object 'bloom_filter_map'
libbpf: failed to load BPF skeleton 'bloom_filter_map': -524 setup_progs:FAIL:bloom_filter_map__open_and_load unexpected error: -524

---
 kernel/bpf/verifier.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +3 -3
index c0263fb5ca4b..aa589fedd036 100644
@@ -19717,14 +19717,14 @@ static int fixup_call_args(struct bpf_verifier_env *env)
 #ifndef CONFIG_BPF_JIT_ALWAYS_ON
 	if (has_kfunc_call) {
 		verbose(env, "calling kernel functions are not allowed in non-JITed programs\n");
-		return -EINVAL;
+		return err ?: -EINVAL;
 	}
 	if (env->subprog_cnt > 1 && env->prog->aux->tail_call_reachable) {
 		/* When JIT fails the progs with bpf2bpf calls and tail_calls
 		 * have to be rejected, since interpreter doesn't support them yet.
 		 */
 		verbose(env, "tail_calls are not allowed in non-JITed programs with bpf-to-bpf calls\n");
-		return -EINVAL;
+		return err ?: -EINVAL;
 	}
 	for (i = 0; i < prog->len; i++, insn++) {
 		if (bpf_pseudo_func(insn)) {
@@ -19732,7 +19732,7 @@ static int fixup_call_args(struct bpf_verifier_env *env)
 			 * have to be rejected, since interpreter doesn't support them yet.
 			 */
 			verbose(env, "callbacks are not allowed in non-JITed programs\n");
-			return -EINVAL;
+			return err ?: -EINVAL;
 		}
 
 		if (!bpf_pseudo_call(insn))
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH bpf-next 1/2] bpf: verifier: Fix return value of fixup_call_args

Quoted 73 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Run bloom_filter_map selftests (./test_progs -t bloom_filter_map) on a Loongarch platform, an error message "JIT doesn't support bpf-to-bpf calls" is got in user space, together with an unexpected errno EINVAL (22), not ENOTSUPP (524):

libbpf: prog 'inner_map': BPF program load failed: Invalid argument
libbpf: prog 'inner_map': -- BEGIN PROG LOAD LOG --
JIT doesn't support bpf-to-bpf calls
callbacks are not allowed in non-JITed programs
processed 37 insns (limit 1000000) max_states_per_insn 1 total_states -- END PROG LOAD LOG --
libbpf: prog 'inner_map': failed to load: -22
libbpf: failed to load object 'bloom_filter_map'
libbpf: failed to load BPF skeleton 'bloom_filter_map': -22 setup_progs:FAIL:bloom_filter_map__open_and_load unexpected error: -22
#16 bloom_filter_map:FAIL

Although in jit_subprogs(), the error number does be set as "ENOTSUPP":

        verbose(env, "JIT doesn't support bpf-to-bpf calls\n");
        err = -ENOTSUPP;
        goto out_free;

But afterwards in fixup_call_args(), such error number is ignored, and overwritten as "-EINVAL":

        verbose(env, "callbacks are not allowed in non-JITed programs\n");
        return -EINVAL;

This patch fixes this by changing return values of fixup_call_args() from "-EINVAL" to "err ?: -EINVAL". With this change, errno 524 is got in user space now:

libbpf: prog 'inner_map': BPF program load failed: unknown error (-524)
libbpf: prog 'inner_map': -- BEGIN PROG LOAD LOG --
JIT doesn't support bpf-to-bpf calls
processed 37 insns (limit 1000000) max_states_per_insn 1 total_states -- END PROG LOAD LOG --
libbpf: prog 'inner_map': failed to load: -524
libbpf: failed to load object 'bloom_filter_map'
libbpf: failed to load BPF skeleton 'bloom_filter_map': -524 setup_progs:FAIL:bloom_filter_map__open_and_load unexpected error: -524

---
 kernel/bpf/verifier.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +2 -2
index c0263fb5ca4b..aa589fedd036 100644
@@ -19717,14 +19717,14 @@ static int fixup_call_args(struct bpf_verifier_env *env)
 #ifndef CONFIG_BPF_JIT_ALWAYS_ON
        if (has_kfunc_call) {
                verbose(env, "calling kernel functions are not allowed in non-JITed programs\n");
-               return -EINVAL;
+               return err ?: -EINVAL;
        }
        if (env->subprog_cnt > 1 && env->prog->aux->tail_call_reachable) {
                /* When JIT fails the progs with bpf2bpf calls and tail_calls
                 * have to be rejected, since interpreter doesn't support them yet.
                 */
                verbose(env, "tail_calls are not allowed in non-JITed programs with bpf-to-bpf calls\n");
-               return -EINVAL;
+               return err ?: -EINVAL;
        }
        for (i = 0; i < prog->len; i++, insn++) {
                if (bpf_pseudo_func(insn)) {

kernel/bpf/verifier.c static int fixup_call_args(struct bpf_verifier_env *env) · line 19735

Quoted 5 lines
kernel/bpf/verifier.c +1 -1
@@ -19732,7 +19732,7 @@ static int fixup_call_args(struct bpf_verifier_env *env)
                         * have to be rejected, since interpreter doesn't support them yet.
                         */
                        verbose(env, "callbacks are not allowed in non-JITed programs\n");
-                       return -EINVAL;
+                       return err ?: -EINVAL;

Nack.
We're not changing this.
pw-bot: cr

#3 lore raw

PATCH 2/2 libbpf: handle ENOTSUPP in libbpf_strerror_r

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

The errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by strerror_r(), but 524 (ENOTSUPP) can't:

prog 'basic_alloc3': BPF program load failed: Operation not supported prog 'basic_alloc3': failed to load: -95
failed to load object 'verifier_arena' FAIL:unexpected_load_failure unexpected error: -95 (errno 95)

prog 'inner_map': BPF program load failed: unknown error (-524) prog 'inner_map': failed to load: -524
failed to load object 'bloom_filter_map'
failed to load BPF skeleton 'bloom_filter_map': -524 FAIL:bloom_filter_map__open_and_load unexpected error: -524

This patch fixes this by handling ENOTSUPP in libbpf_strerror_r(). With this change, the new error string looks like:

prog 'inner_map': BPF program load failed: Operation not supported (-524)

---
 tools/lib/bpf/str_error.c | 11 +++++++----
 tools/lib/bpf/str_error.h |  4 ++++
 2 files changed, 11 insertions(+), 4 deletions(-)
tools/lib/bpf/str_error.c +7 -4
index 5e6a1e27ddf9..10597d5124cd 100644
@@ -23,10 +23,13 @@ char *libbpf_strerror_r(int err, char *dst, int len)
 	if (ret == -1)
 		ret = errno;
 	if (ret) {
-		if (ret == EINVAL)
-			/* strerror_r() doesn't recognize this specific error */
-			snprintf(dst, len, "unknown error (%d)", err < 0 ? err : -err);
-		else
+		if (ret == EINVAL) {
+			if (err == ENOTSUPP)
+				snprintf(dst, len, "Operation not supported (%d)", -err);
+			else
+				/* strerror_r() doesn't recognize this specific error */
+				snprintf(dst, len, "unknown error (%d)", err < 0 ? err : -err);
+		} else
 			snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
 	}
 	return dst;
tools/lib/bpf/str_error.h +4 -0
index 626d7ffb03d6..c41f6ba133cf 100644
@@ -4,6 +4,10 @@
 
 #define STRERR_BUFSIZE  128
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
 char *libbpf_strerror_r(int err, char *dst, int len);
 
 #endif /* __LIBBPF_STR_ERROR_H */
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH bpf-next 2/2] libbpf: handle ENOTSUPP in libbpf_strerror_r

Quoted 45 lines · Geliang Tang

From: Geliang Tang <[email protected]>

The errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by strerror_r(),
but 524 (ENOTSUPP) can't:

 prog 'basic_alloc3': BPF program load failed: Operation not supported
 prog 'basic_alloc3': failed to load: -95
 failed to load object 'verifier_arena' FAIL:unexpected_load_failure unexpected error: -95 (errno 95)

 prog 'inner_map': BPF program load failed: unknown error (-524) prog 'inner_map': failed to load: -524
 failed to load object 'bloom_filter_map'
 failed to load BPF skeleton 'bloom_filter_map': -524 FAIL:bloom_filter_map__open_and_load unexpected error: -524

This patch fixes this by handling ENOTSUPP in libbpf_strerror_r(). With
this change, the new error string looks like:

 prog 'inner_map': BPF program load failed: Operation not supported (-524)

---
 tools/lib/bpf/str_error.c | 11 +++++++----
 tools/lib/bpf/str_error.h |  4 ++++

 2 files changed, 11 insertions(+), 4 deletions(-)
tools/lib/bpf/str_error.c +0 -2
index 5e6a1e27ddf9..10597d5124cd 100644
@@ -23,10 +23,13 @@ char *libbpf_strerror_r(int err, char *dst, int
 len)
  	if (ret == -1)
  		ret = errno;
  	if (ret) {
-		if (ret == EINVAL)
-			/* strerror_r() doesn't recognize this

specific error */

tools/lib/bpf/str_error.c +0 -1
-			snprintf(dst, len, "unknown error (%d)", err

< 0 ? err : -err);

tools/lib/bpf/str_error.c char *libbpf_strerror_r(int err, char *dst, int len) · line 27

Quoted 3 lines
tools/lib/bpf/str_error.c +2 -1
-		else
+		if (ret == EINVAL) {
+			if (err == ENOTSUPP)

Shouldn't use "err" directly here, should use "err < 0 ? -err : err" instead. I prefer to add an unsigned variable "no" in v2:

	unsigned int no = err < 0 ? -err : err;

And use "switch-case" for future expansion:

	switch (no) {
	case ENOTSUPP:
Quoted 2 lines
tools/lib/bpf/str_error.c +1 -0
+				snprintf(dst, len, "Operation not

supported (%d)", -err);

No need to use "Operation not supported (-524)" here, just "Operation not supported" is better.

		snprintf(dst, len, "Operation not supported");
Quoted 5 lines
tools/lib/bpf/str_error.c +2 -0
+			else
+				/* strerror_r() doesn't recognize

this specific error */

tools/lib/bpf/str_error.c +1 -0
+				snprintf(dst, len, "unknown error

(%d)", err < 0 ? err : -err);

Then here:

		snprintf(dst, len, "unknown error (-%u)", no);

Changes Requested.

Will send a v2 soon.

Thanks,
-Geliang

Quoted 20 lines
tools/lib/bpf/str_error.c +1 -0
+		} else

  snprintf(dst, len, "ERROR:
strerror_r(%d)=%d", err, ret);
  }
  return dst;

tools/lib/bpf/str_error.h +0 -0
index 626d7ffb03d6..c41f6ba133cf 100644
@@ -4,6 +4,10 @@


 #define STRERR_BUFSIZE  128

tools/lib/bpf/str_error.h +4 -0
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+

 char *libbpf_strerror_r(int err, char *dst, int len);
 #endif /* __LIBBPF_STR_ERROR_H */

#5 lore raw

Re: [PATCH bpf-next 2/2] libbpf: handle ENOTSUPP in libbpf_strerror_r

Quoted 4 lines · Geliang Tang

Changes Requested.

Will send a v2 soon.

Do NOT. Stop this spam of patches.