All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible
@ 2021-12-09 13:40 Thadeu Lima de Souza Cascardo
  2021-12-09 19:05 ` John Fastabend
  0 siblings, 1 reply; 6+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2021-12-09 13:40 UTC (permalink / raw)
  To: bpf; +Cc: netdev, ast, daniel, linux-kernel

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")
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index de3e5bc6781f..5c89bae0d6f9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -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 {
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible
  2021-12-09 13:40 [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible Thadeu Lima de Souza Cascardo
@ 2021-12-09 19:05 ` John Fastabend
  2021-12-09 19:31   ` Ido Schimmel
  0 siblings, 1 reply; 6+ messages in thread
From: John Fastabend @ 2021-12-09 19:05 UTC (permalink / raw)
  To: Thadeu Lima de Souza Cascardo, bpf; +Cc: netdev, ast, daniel, linux-kernel

Thadeu Lima de Souza Cascardo wrote:
> 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")
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
> ---
>  kernel/bpf/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index de3e5bc6781f..5c89bae0d6f9 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -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 {
> -- 
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible
  2021-12-09 19:05 ` John Fastabend
@ 2021-12-09 19:31   ` Ido Schimmel
  2021-12-09 23:03     ` Daniel Borkmann
  0 siblings, 1 reply; 6+ messages in thread
From: Ido Schimmel @ 2021-12-09 19:31 UTC (permalink / raw)
  To: John Fastabend
  Cc: Thadeu Lima de Souza Cascardo, bpf, netdev, ast, daniel, linux-kernel

On Thu, Dec 09, 2021 at 11:05:18AM -0800, John Fastabend wrote:
> Thadeu Lima de Souza Cascardo wrote:
> > 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")
> > Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
> > ---
> >  kernel/bpf/core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> > index de3e5bc6781f..5c89bae0d6f9 100644
> > --- a/kernel/bpf/core.c
> > +++ b/kernel/bpf/core.c
> > @@ -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 {
> > -- 
> > 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/20191204.125135.750458923752225025.davem@davemloft.net/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible
  2021-12-09 19:31   ` Ido Schimmel
@ 2021-12-09 23:03     ` Daniel Borkmann
  2021-12-10  2:23       ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Borkmann @ 2021-12-09 23:03 UTC (permalink / raw)
  To: Ido Schimmel, John Fastabend
  Cc: Thadeu Lima de Souza Cascardo, bpf, netdev, ast, linux-kernel, kuba

On 12/9/21 8:31 PM, Ido Schimmel wrote:
> On Thu, Dec 09, 2021 at 11:05:18AM -0800, John Fastabend wrote:
>> Thadeu Lima de Souza Cascardo wrote:
>>> 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")
>>> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
>>> ---
>>>   kernel/bpf/core.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
>>> index de3e5bc6781f..5c89bae0d6f9 100644
>>> --- a/kernel/bpf/core.c
>>> +++ b/kernel/bpf/core.c
>>> @@ -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 {
>>
>> 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/20191204.125135.750458923752225025.davem@davemloft.net/

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible
  2021-12-09 23:03     ` Daniel Borkmann
@ 2021-12-10  2:23       ` Jakub Kicinski
  2021-12-10 12:24         ` Thadeu Lima de Souza Cascardo
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2021-12-10  2:23 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Ido Schimmel, John Fastabend, Thadeu Lima de Souza Cascardo, bpf,
	netdev, ast, linux-kernel

On Fri, 10 Dec 2021 00:03:40 +0100 Daniel Borkmann wrote:
> > Similar issue was discussed in the past. See:
> > https://lore.kernel.org/netdev/20191204.125135.750458923752225025.davem@davemloft.net/  
> 
> 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?

> 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..

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible
  2021-12-10  2:23       ` Jakub Kicinski
@ 2021-12-10 12:24         ` Thadeu Lima de Souza Cascardo
  0 siblings, 0 replies; 6+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2021-12-10 12:24 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Daniel Borkmann, Ido Schimmel, John Fastabend, bpf, netdev, ast,
	linux-kernel

On Thu, Dec 09, 2021 at 06:23:49PM -0800, Jakub Kicinski wrote:
> On Fri, 10 Dec 2021 00:03:40 +0100 Daniel Borkmann wrote:
> > > Similar issue was discussed in the past. See:
> > > https://lore.kernel.org/netdev/20191204.125135.750458923752225025.davem@davemloft.net/  
> > 
> > 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?
> 

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.

> > 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..

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-10 12:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 13:40 [PATCH] bpf: return EOPNOTSUPP when JIT is needed and not possible Thadeu Lima de Souza Cascardo
2021-12-09 19:05 ` John Fastabend
2021-12-09 19:31   ` Ido Schimmel
2021-12-09 23:03     ` Daniel Borkmann
2021-12-10  2:23       ` Jakub Kicinski
2021-12-10 12:24         ` Thadeu Lima de Souza Cascardo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.