* [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return()
@ 2018-07-25 15:09 Taehee Yoo
2018-07-25 20:50 ` Martin KaFai Lau
2018-07-26 2:11 ` Jakub Kicinski
0 siblings, 2 replies; 6+ messages in thread
From: Taehee Yoo @ 2018-07-25 15:09 UTC (permalink / raw)
To: daniel, ast, bjorn.topel; +Cc: brouer, netdev, Taehee Yoo
rhashtable_lookup() can return NULL. so that NULL pointer
check routine should be added.
Fixes: 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
V2 : add WARN_ON_ONCE when xa is NULL.
net/core/xdp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 9d1f220..786fdbe 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -345,7 +345,10 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
rcu_read_lock();
/* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
- xa->zc_alloc->free(xa->zc_alloc, handle);
+ if (!xa)
+ WARN_ON_ONCE(1);
+ else
+ xa->zc_alloc->free(xa->zc_alloc, handle);
rcu_read_unlock();
default:
/* Not possible, checked in xdp_rxq_info_reg_mem_model() */
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return()
2018-07-25 15:09 [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return() Taehee Yoo
@ 2018-07-25 20:50 ` Martin KaFai Lau
2018-07-26 2:11 ` Jakub Kicinski
1 sibling, 0 replies; 6+ messages in thread
From: Martin KaFai Lau @ 2018-07-25 20:50 UTC (permalink / raw)
To: Taehee Yoo; +Cc: daniel, ast, bjorn.topel, brouer, netdev
On Thu, Jul 26, 2018 at 12:09:50AM +0900, Taehee Yoo wrote:
> rhashtable_lookup() can return NULL. so that NULL pointer
> check routine should be added.
>
> Fixes: 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
> ---
> V2 : add WARN_ON_ONCE when xa is NULL.
>
> net/core/xdp.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 9d1f220..786fdbe 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -345,7 +345,10 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
> rcu_read_lock();
> /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
> xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
> - xa->zc_alloc->free(xa->zc_alloc, handle);
> + if (!xa)
> + WARN_ON_ONCE(1);
> + else
> + xa->zc_alloc->free(xa->zc_alloc, handle);
> rcu_read_unlock();
> default:
> /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
> --
> 2.9.3
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return()
2018-07-25 15:09 [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return() Taehee Yoo
2018-07-25 20:50 ` Martin KaFai Lau
@ 2018-07-26 2:11 ` Jakub Kicinski
2018-07-26 12:07 ` Björn Töpel
2018-07-26 14:02 ` Taehee Yoo
1 sibling, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2018-07-26 2:11 UTC (permalink / raw)
To: Taehee Yoo; +Cc: daniel, ast, bjorn.topel, brouer, netdev
On Thu, 26 Jul 2018 00:09:50 +0900, Taehee Yoo wrote:
> rhashtable_lookup() can return NULL. so that NULL pointer
> check routine should be added.
>
> Fixes: 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
> ---
> V2 : add WARN_ON_ONCE when xa is NULL.
>
> net/core/xdp.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 9d1f220..786fdbe 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -345,7 +345,10 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
> rcu_read_lock();
> /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
> xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
> - xa->zc_alloc->free(xa->zc_alloc, handle);
> + if (!xa)
> + WARN_ON_ONCE(1);
nit: is compiler smart enough to figure out the fast path here?
WARN_ON_ONCE() has the nice side effect of wrapping the condition in
unlikely(). It could save us both LoC and potentially cycles to do:
if (!WARN_ON_ONCE(!xa))
xa->zc_alloc->free(xa->zc_alloc, handle);
Although it admittedly looks a bit awkward. I'm not sure if we have
some form of assert (i.e. positive check) in tree :S
> + else
> + xa->zc_alloc->free(xa->zc_alloc, handle);
> rcu_read_unlock();
> default:
> /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return()
2018-07-26 2:11 ` Jakub Kicinski
@ 2018-07-26 12:07 ` Björn Töpel
2018-07-26 14:05 ` Taehee Yoo
2018-07-26 14:02 ` Taehee Yoo
1 sibling, 1 reply; 6+ messages in thread
From: Björn Töpel @ 2018-07-26 12:07 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Taehee Yoo, Daniel Borkmann, ast, Björn Töpel,
Jesper Dangaard Brouer, Netdev
Den tors 26 juli 2018 kl 04:14 skrev Jakub Kicinski
<jakub.kicinski@netronome.com>:
>
> On Thu, 26 Jul 2018 00:09:50 +0900, Taehee Yoo wrote:
> > rhashtable_lookup() can return NULL. so that NULL pointer
> > check routine should be added.
> >
> > Fixes: 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")
> > Signed-off-by: Taehee Yoo <ap420073@gmail.com>
> > ---
> > V2 : add WARN_ON_ONCE when xa is NULL.
> >
> > net/core/xdp.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/core/xdp.c b/net/core/xdp.c
> > index 9d1f220..786fdbe 100644
> > --- a/net/core/xdp.c
> > +++ b/net/core/xdp.c
> > @@ -345,7 +345,10 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
> > rcu_read_lock();
> > /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
> > xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
> > - xa->zc_alloc->free(xa->zc_alloc, handle);
> > + if (!xa)
> > + WARN_ON_ONCE(1);
>
> nit: is compiler smart enough to figure out the fast path here?
> WARN_ON_ONCE() has the nice side effect of wrapping the condition in
> unlikely(). It could save us both LoC and potentially cycles to do:
>
> if (!WARN_ON_ONCE(!xa))
> xa->zc_alloc->free(xa->zc_alloc, handle);
>
> Although it admittedly looks a bit awkward. I'm not sure if we have
> some form of assert (i.e. positive check) in tree :S
>
I'm kind of in favor of this ^^^. Hopefully, Taehee is ok with another spin.
Björn
> > + else
> > + xa->zc_alloc->free(xa->zc_alloc, handle);
> > rcu_read_unlock();
> > default:
> > /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return()
2018-07-26 2:11 ` Jakub Kicinski
2018-07-26 12:07 ` Björn Töpel
@ 2018-07-26 14:02 ` Taehee Yoo
1 sibling, 0 replies; 6+ messages in thread
From: Taehee Yoo @ 2018-07-26 14:02 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Daniel Borkmann, ast, Björn Töpel,
Jesper Dangaard Brouer, Netdev
2018-07-26 11:11 GMT+09:00 Jakub Kicinski <jakub.kicinski@netronome.com>:
> On Thu, 26 Jul 2018 00:09:50 +0900, Taehee Yoo wrote:
>> rhashtable_lookup() can return NULL. so that NULL pointer
>> check routine should be added.
>>
>> Fixes: 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")
>> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
>> ---
>> V2 : add WARN_ON_ONCE when xa is NULL.
>>
>> net/core/xdp.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/core/xdp.c b/net/core/xdp.c
>> index 9d1f220..786fdbe 100644
>> --- a/net/core/xdp.c
>> +++ b/net/core/xdp.c
>> @@ -345,7 +345,10 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
>> rcu_read_lock();
>> /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
>> xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
>> - xa->zc_alloc->free(xa->zc_alloc, handle);
>> + if (!xa)
>> + WARN_ON_ONCE(1);
>
> nit: is compiler smart enough to figure out the fast path here?
> WARN_ON_ONCE() has the nice side effect of wrapping the condition in
> unlikely(). It could save us both LoC and potentially cycles to do:
>
> if (!WARN_ON_ONCE(!xa))
> xa->zc_alloc->free(xa->zc_alloc, handle);
>
> Although it admittedly looks a bit awkward. I'm not sure if we have
> some form of assert (i.e. positive check) in tree :S
>
Thank you for suggestion!
I like this code style and I think there is no problem because readers
are familiar with this code style.
I will send v3 patch!
Thanks!
>> + else
>> + xa->zc_alloc->free(xa->zc_alloc, handle);
>> rcu_read_unlock();
>> default:
>> /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return()
2018-07-26 12:07 ` Björn Töpel
@ 2018-07-26 14:05 ` Taehee Yoo
0 siblings, 0 replies; 6+ messages in thread
From: Taehee Yoo @ 2018-07-26 14:05 UTC (permalink / raw)
To: Björn Töpel
Cc: Jakub Kicinski, Daniel Borkmann, ast, Björn Töpel,
Jesper Dangaard Brouer, Netdev
2018-07-26 21:07 GMT+09:00 Björn Töpel <bjorn.topel@gmail.com>:
> Den tors 26 juli 2018 kl 04:14 skrev Jakub Kicinski
> <jakub.kicinski@netronome.com>:
>>
>> On Thu, 26 Jul 2018 00:09:50 +0900, Taehee Yoo wrote:
>> > rhashtable_lookup() can return NULL. so that NULL pointer
>> > check routine should be added.
>> >
>> > Fixes: 02b55e5657c3 ("xdp: add MEM_TYPE_ZERO_COPY")
>> > Signed-off-by: Taehee Yoo <ap420073@gmail.com>
>> > ---
>> > V2 : add WARN_ON_ONCE when xa is NULL.
>> >
>> > net/core/xdp.c | 5 ++++-
>> > 1 file changed, 4 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/net/core/xdp.c b/net/core/xdp.c
>> > index 9d1f220..786fdbe 100644
>> > --- a/net/core/xdp.c
>> > +++ b/net/core/xdp.c
>> > @@ -345,7 +345,10 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
>> > rcu_read_lock();
>> > /* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
>> > xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
>> > - xa->zc_alloc->free(xa->zc_alloc, handle);
>> > + if (!xa)
>> > + WARN_ON_ONCE(1);
>>
>> nit: is compiler smart enough to figure out the fast path here?
>> WARN_ON_ONCE() has the nice side effect of wrapping the condition in
>> unlikely(). It could save us both LoC and potentially cycles to do:
>>
>> if (!WARN_ON_ONCE(!xa))
>> xa->zc_alloc->free(xa->zc_alloc, handle);
>>
>> Although it admittedly looks a bit awkward. I'm not sure if we have
>> some form of assert (i.e. positive check) in tree :S
>>
>
> I'm kind of in favor of this ^^^. Hopefully, Taehee is ok with another spin.
>
I like this code style and I think it has performance benefit.
So I will send v3 patch!
Thanks!
> Björn
>
>> > + else
>> > + xa->zc_alloc->free(xa->zc_alloc, handle);
>> > rcu_read_unlock();
>> > default:
>> > /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-07-26 15:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-25 15:09 [PATCH V2 bpf] xdp: add NULL pointer check in __xdp_return() Taehee Yoo
2018-07-25 20:50 ` Martin KaFai Lau
2018-07-26 2:11 ` Jakub Kicinski
2018-07-26 12:07 ` Björn Töpel
2018-07-26 14:05 ` Taehee Yoo
2018-07-26 14:02 ` Taehee Yoo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).