Skip to contentSkip to conversation

bpf: return EOPNOTSUPP when JIT is needed and not possible

PATCH In review Thadeu Lima de Souza Cascardo 5 participants 6 messages Dec 9, 2021 – Dec 10, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: return EOPNOTSUPP when JIT is needed and not possible

When a CBPF program is JITed and CONFIG_BPF_JIT_ALWAYS_ON is enabled, and the JIT fails, it would return ENOTSUPP, which is not a valid userspace error code. Instead, EOPNOTSUPP should be returned.

Fixes 290af86629b2 ("bpf: introduce BPF_JIT_ALWAYS_ON config")
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index de3e5bc6781f..5c89bae0d6f9 100644
@@ -1931,7 +1931,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
 		fp = bpf_int_jit_compile(fp);
 		bpf_prog_jit_attempt_done(fp);
 		if (!fp->jited && jit_needed) {
-			*err = -ENOTSUPP;
+			*err = -EOPNOTSUPP;
 			return fp;
 		}
 	} else {
Signature · 1 line
2.32.0
#1 lore raw
Quoted 26 lines · Thadeu Lima de Souza Cascardo

When a CBPF program is JITed and CONFIG_BPF_JIT_ALWAYS_ON is enabled, and the JIT fails, it would return ENOTSUPP, which is not a valid userspace error code. Instead, EOPNOTSUPP should be returned.

Fixes 290af86629b2 ("bpf: introduce BPF_JIT_ALWAYS_ON config")
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index de3e5bc6781f..5c89bae0d6f9 100644
@@ -1931,7 +1931,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
 		fp = bpf_int_jit_compile(fp);
 		bpf_prog_jit_attempt_done(fp);
 		if (!fp->jited && jit_needed) {
-			*err = -ENOTSUPP;
+			*err = -EOPNOTSUPP;
 			return fp;
 		}
 	} else {
Signature · 1 line
2.32.0

It seems BPF subsys returns ENOTSUPP in multiple places. This fixes one paticular case and is user facing. Not sure we want to one-off fix them here creating user facing changes over multiple kernel versions. On the fence with this one curious to see what others think. Haven't apps already adapted to the current convention or they don't care?

.John

#2 lore raw
Quoted 25 lines · John Fastabend
Quoted 24 lines · Thadeu Lima de Souza Cascardo

When a CBPF program is JITed and CONFIG_BPF_JIT_ALWAYS_ON is enabled, and the JIT fails, it would return ENOTSUPP, which is not a valid userspace error code. Instead, EOPNOTSUPP should be returned.

Fixes 290af86629b2 ("bpf: introduce BPF_JIT_ALWAYS_ON config")
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index de3e5bc6781f..5c89bae0d6f9 100644
@@ -1931,7 +1931,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
 		fp = bpf_int_jit_compile(fp);
 		bpf_prog_jit_attempt_done(fp);
 		if (!fp->jited && jit_needed) {
-			*err = -ENOTSUPP;
+			*err = -EOPNOTSUPP;
 			return fp;
 		}
 	} else {
Quoted 8 lines
Quoted 2 lines

2.32.0

It seems BPF subsys returns ENOTSUPP in multiple places. This fixes one paticular case and is user facing. Not sure we want to one-off fix them here creating user facing changes over multiple kernel versions. On the fence with this one curious to see what others think. Haven't apps already adapted to the current convention or they don't care?

Similar issue was discussed in the past. See:
https://lore.kernel.org/netdev/[email protected]/

maintainer
#3 lore raw
Quoted 32 lines · Ido Schimmel
Quoted 22 lines · John Fastabend
Quoted 21 lines · Thadeu Lima de Souza Cascardo

When a CBPF program is JITed and CONFIG_BPF_JIT_ALWAYS_ON is enabled, and the JIT fails, it would return ENOTSUPP, which is not a valid userspace error code. Instead, EOPNOTSUPP should be returned.

Fixes 290af86629b2 ("bpf: introduce BPF_JIT_ALWAYS_ON config")
---
  kernel/bpf/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index de3e5bc6781f..5c89bae0d6f9 100644
@@ -1931,7 +1931,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
  		fp = bpf_int_jit_compile(fp);
  		bpf_prog_jit_attempt_done(fp);
  		if (!fp->jited && jit_needed) {
-			*err = -ENOTSUPP;
+			*err = -EOPNOTSUPP;
  			return fp;
Quoted 8 lines

kernel/bpf/core.c struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) · line 1937

Quoted 2 lines
kernel/bpf/core.c +0 -0
  		}
  	} else {

It seems BPF subsys returns ENOTSUPP in multiple places. This fixes one paticular case and is user facing. Not sure we want to one-off fix them here creating user facing changes over multiple kernel versions. On the fence with this one curious to see what others think. Haven't apps already adapted to the current convention or they don't care?

Quoted 2 lines

Similar issue was discussed in the past. See:
https://lore.kernel.org/netdev/[email protected]/

With regards to ENOTSUPP exposure, if the consensus is that we should fix all occurences over to EOPNOTSUPP even if they've been exposed for quite some time (Jakub?), we could give this patch a try maybe via bpf-next and see if anyone complains.

Thadeu, I think you also need to fix up BPF selftests as test_verifier, to mention one example (there are also bunch of others under tools/testing/selftests/), is checking for ENOTSUPP specifically..

Thanks,
Daniel

maintainer
#4 lore raw
Quoted 6 lines · On Fri, 10 Dec 2021 00:03:40 +0100 Daniel Borkmann wrote:
Quoted 2 lines

Similar issue was discussed in the past. See:
https://lore.kernel.org/netdev/[email protected]/

With regards to ENOTSUPP exposure, if the consensus is that we should fix all occurences over to EOPNOTSUPP even if they've been exposed for quite some time (Jakub?),

Did you mean me? :) In case you did - I think we should avoid it for new code but changing existing now seems risky. Alexei and Andrii would know best but quick search of code bases at work reveals some scripts looking for ENOTSUPP.

Thadeu, what motivated the change?

If we're getting those changes fixes based on checkpatch output maybe there is a way to mute the checkpatch warnings when it's not run on a diff?

Quoted 5 lines

we could give this patch a try maybe via bpf-next and see if anyone complains.

Thadeu, I think you also need to fix up BPF selftests as test_verifier, to mention one example (there are also bunch of others under tools/testing/selftests/), is checking for ENOTSUPP specifically..

#5 lore raw
Quoted 13 lines · Jakub Kicinski
Quoted 6 lines · On Fri, 10 Dec 2021 00:03:40 +0100 Daniel Borkmann wrote:
Quoted 2 lines

Similar issue was discussed in the past. See:
https://lore.kernel.org/netdev/[email protected]/

With regards to ENOTSUPP exposure, if the consensus is that we should fix all occurences over to EOPNOTSUPP even if they've been exposed for quite some time (Jakub?),

Did you mean me? :) In case you did - I think we should avoid it for new code but changing existing now seems risky. Alexei and Andrii would know best but quick search of code bases at work reveals some scripts looking for ENOTSUPP.

Quoted 6 lines

Thadeu, what motivated the change?

If we're getting those changes fixes based on checkpatch output maybe there is a way to mute the checkpatch warnings when it's not run on a diff?

It was not checkpatch that motivated me.

I was looking into the following commits as we hit a failed test.

be08815c5d3b ("bpf: add also cbpf long jump test cases with heavy expansion") 050fad7c4534 ("bpf: fix truncated jump targets on heavy expansions")

Then, I realized that if given the right number of BPF_LDX | BPF_B | BPF_MSH instructions, it will pass the bpf_convert_filter stage, but fail at blinding. And if you have CONFIG_BPF_JIT_ALWAYS_ON, setting the filter will fail with ENOTSUPP, which should not be sent to userspace.

I noticed other ENOTSUPP, but they seemed to be returned by helpers, and I was not sure this would be relayed to userspace. So, I went for fixing the observed case.

I will see if any of the tests I can run is broken by this change and submit it again with the tests fixed as well.

Cascardo.

Quoted 5 lines
Quoted 5 lines

we could give this patch a try maybe via bpf-next and see if anyone complains.

Thadeu, I think you also need to fix up BPF selftests as test_verifier, to mention one example (there are also bunch of others under tools/testing/selftests/), is checking for ENOTSUPP specifically..