All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock
@ 2017-09-18 13:03 Tobias Klauser
  2017-09-18 13:14 ` Daniel Borkmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tobias Klauser @ 2017-09-18 13:03 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: John Fastabend, netdev

If bpf_map_precharge_memlock in dev_map_alloc, -ENOMEM is returned
regardless of the actual error produced by bpf_map_precharge_memlock.
Fix it by passing on the error returned by bpf_map_precharge_memlock.

Also return -EINVAL instead of -ENOMEM if the page count overflow check
fails.

This makes dev_map_alloc match the behavior of other bpf maps' alloc
functions wrt. return values.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 kernel/bpf/devmap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 959c9a07f318..e093d9a2c4dd 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -75,8 +75,8 @@ static u64 dev_map_bitmap_size(const union bpf_attr *attr)
 static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
 {
 	struct bpf_dtab *dtab;
+	int err = -EINVAL;
 	u64 cost;
-	int err;
 
 	/* check sanity of attributes */
 	if (attr->max_entries == 0 || attr->key_size != 4 ||
@@ -108,6 +108,8 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
 	if (err)
 		goto free_dtab;
 
+	err = -ENOMEM;
+
 	/* A per cpu bitfield with a bit per possible net device */
 	dtab->flush_needed = __alloc_percpu(dev_map_bitmap_size(attr),
 					    __alignof__(unsigned long));
@@ -128,7 +130,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
 free_dtab:
 	free_percpu(dtab->flush_needed);
 	kfree(dtab);
-	return ERR_PTR(-ENOMEM);
+	return ERR_PTR(err);
 }
 
 static void dev_map_free(struct bpf_map *map)
-- 
2.13.0

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

* Re: [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock
  2017-09-18 13:03 [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock Tobias Klauser
@ 2017-09-18 13:14 ` Daniel Borkmann
  2017-09-18 15:57 ` Alexei Starovoitov
  2017-09-18 23:53 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2017-09-18 13:14 UTC (permalink / raw)
  To: Tobias Klauser, Alexei Starovoitov; +Cc: John Fastabend, netdev

On 09/18/2017 03:03 PM, Tobias Klauser wrote:
> If bpf_map_precharge_memlock in dev_map_alloc, -ENOMEM is returned
> regardless of the actual error produced by bpf_map_precharge_memlock.
> Fix it by passing on the error returned by bpf_map_precharge_memlock.
>
> Also return -EINVAL instead of -ENOMEM if the page count overflow check
> fails.
>
> This makes dev_map_alloc match the behavior of other bpf maps' alloc
> functions wrt. return values.
>
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

(This would then need to go via net tree.)

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

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

* Re: [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock
  2017-09-18 13:03 [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock Tobias Klauser
  2017-09-18 13:14 ` Daniel Borkmann
@ 2017-09-18 15:57 ` Alexei Starovoitov
  2017-09-18 23:53 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2017-09-18 15:57 UTC (permalink / raw)
  To: Tobias Klauser
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, netdev

On Mon, Sep 18, 2017 at 03:03:46PM +0200, Tobias Klauser wrote:
> If bpf_map_precharge_memlock in dev_map_alloc, -ENOMEM is returned
> regardless of the actual error produced by bpf_map_precharge_memlock.
> Fix it by passing on the error returned by bpf_map_precharge_memlock.
> 
> Also return -EINVAL instead of -ENOMEM if the page count overflow check
> fails.
> 
> This makes dev_map_alloc match the behavior of other bpf maps' alloc
> functions wrt. return values.
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

good catch.
Acked-by: Alexei Starovoitov <ast@kernel.org>

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

* Re: [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock
  2017-09-18 13:03 [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock Tobias Klauser
  2017-09-18 13:14 ` Daniel Borkmann
  2017-09-18 15:57 ` Alexei Starovoitov
@ 2017-09-18 23:53 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-09-18 23:53 UTC (permalink / raw)
  To: tklauser; +Cc: ast, daniel, john.fastabend, netdev

From: Tobias Klauser <tklauser@distanz.ch>
Date: Mon, 18 Sep 2017 15:03:46 +0200

> If bpf_map_precharge_memlock in dev_map_alloc, -ENOMEM is returned
> regardless of the actual error produced by bpf_map_precharge_memlock.
> Fix it by passing on the error returned by bpf_map_precharge_memlock.
> 
> Also return -EINVAL instead of -ENOMEM if the page count overflow check
> fails.
> 
> This makes dev_map_alloc match the behavior of other bpf maps' alloc
> functions wrt. return values.
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

Applied, thank you.

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

end of thread, other threads:[~2017-09-18 23:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-18 13:03 [PATCH] bpf: devmap: pass on return value of bpf_map_precharge_memlock Tobias Klauser
2017-09-18 13:14 ` Daniel Borkmann
2017-09-18 15:57 ` Alexei Starovoitov
2017-09-18 23:53 ` David Miller

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.