* [PATCH] rhashtable: fix shift by 64 when shrinking
@ 2016-08-12 18:10 Vegard Nossum
2016-08-15 6:02 ` Herbert Xu
2016-08-15 18:10 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Vegard Nossum @ 2016-08-12 18:10 UTC (permalink / raw)
To: Thomas Graf; +Cc: netdev, Vegard Nossum, Herbert Xu
I got this:
================================================================================
UBSAN: Undefined behaviour in ./include/linux/log2.h:63:13
shift exponent 64 is too large for 64-bit type 'long unsigned int'
CPU: 1 PID: 721 Comm: kworker/1:1 Not tainted 4.8.0-rc1+ #87
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
Workqueue: events rht_deferred_worker
0000000000000000 ffff88011661f8d8 ffffffff82344f50 0000000041b58ab3
ffffffff84f98000 ffffffff82344ea4 ffff88011661f900 ffff88011661f8b0
0000000000000001 ffff88011661f6b8 dffffc0000000000 ffffffff867f7640
Call Trace:
[<ffffffff82344f50>] dump_stack+0xac/0xfc
[<ffffffff82344ea4>] ? _atomic_dec_and_lock+0xc4/0xc4
[<ffffffff8242f5b8>] ubsan_epilogue+0xd/0x8a
[<ffffffff82430c41>] __ubsan_handle_shift_out_of_bounds+0x255/0x29a
[<ffffffff824309ec>] ? __ubsan_handle_out_of_bounds+0x180/0x180
[<ffffffff84003436>] ? nl80211_req_set_reg+0x256/0x2f0
[<ffffffff812112ba>] ? print_context_stack+0x8a/0x160
[<ffffffff81200031>] ? amd_pmu_reset+0x341/0x380
[<ffffffff823af808>] rht_deferred_worker+0x1618/0x1790
[<ffffffff823af808>] ? rht_deferred_worker+0x1618/0x1790
[<ffffffff823ae1f0>] ? rhashtable_jhash2+0x370/0x370
[<ffffffff8134c12d>] ? process_one_work+0x6fd/0x1970
[<ffffffff8134c1cf>] process_one_work+0x79f/0x1970
[<ffffffff8134c12d>] ? process_one_work+0x6fd/0x1970
[<ffffffff8134ba30>] ? try_to_grab_pending+0x4c0/0x4c0
[<ffffffff8134d564>] ? worker_thread+0x1c4/0x1340
[<ffffffff8134d8ff>] worker_thread+0x55f/0x1340
[<ffffffff845e904f>] ? __schedule+0x4df/0x1d40
[<ffffffff8134d3a0>] ? process_one_work+0x1970/0x1970
[<ffffffff8134d3a0>] ? process_one_work+0x1970/0x1970
[<ffffffff813642f7>] kthread+0x237/0x390
[<ffffffff813640c0>] ? __kthread_parkme+0x280/0x280
[<ffffffff845f8c93>] ? _raw_spin_unlock_irq+0x33/0x50
[<ffffffff845f95df>] ret_from_fork+0x1f/0x40
[<ffffffff813640c0>] ? __kthread_parkme+0x280/0x280
================================================================================
roundup_pow_of_two() is undefined when called with an argument of 0, so
let's avoid the call and just fall back to ht->p.min_size (which should
never be smaller than HASH_MIN_SIZE).
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
lib/rhashtable.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 5d845ff..fc47ca39 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -321,12 +321,14 @@ static int rhashtable_expand(struct rhashtable *ht)
static int rhashtable_shrink(struct rhashtable *ht)
{
struct bucket_table *new_tbl, *old_tbl = rht_dereference(ht->tbl, ht);
- unsigned int size;
+ unsigned int nelems = atomic_read(&ht->nelems);
+ unsigned int size = 0;
int err;
ASSERT_RHT_MUTEX(ht);
- size = roundup_pow_of_two(atomic_read(&ht->nelems) * 3 / 2);
+ if (nelems)
+ size = roundup_pow_of_two(nelems * 3 / 2);
if (size < ht->p.min_size)
size = ht->p.min_size;
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rhashtable: fix shift by 64 when shrinking
2016-08-12 18:10 [PATCH] rhashtable: fix shift by 64 when shrinking Vegard Nossum
@ 2016-08-15 6:02 ` Herbert Xu
2016-08-15 18:10 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2016-08-15 6:02 UTC (permalink / raw)
To: Vegard Nossum; +Cc: Thomas Graf, netdev
On Fri, Aug 12, 2016 at 08:10:44PM +0200, Vegard Nossum wrote:
> I got this:
>
> ================================================================================
> UBSAN: Undefined behaviour in ./include/linux/log2.h:63:13
> shift exponent 64 is too large for 64-bit type 'long unsigned int'
> CPU: 1 PID: 721 Comm: kworker/1:1 Not tainted 4.8.0-rc1+ #87
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
> Workqueue: events rht_deferred_worker
> 0000000000000000 ffff88011661f8d8 ffffffff82344f50 0000000041b58ab3
> ffffffff84f98000 ffffffff82344ea4 ffff88011661f900 ffff88011661f8b0
> 0000000000000001 ffff88011661f6b8 dffffc0000000000 ffffffff867f7640
> Call Trace:
> [<ffffffff82344f50>] dump_stack+0xac/0xfc
> [<ffffffff82344ea4>] ? _atomic_dec_and_lock+0xc4/0xc4
> [<ffffffff8242f5b8>] ubsan_epilogue+0xd/0x8a
> [<ffffffff82430c41>] __ubsan_handle_shift_out_of_bounds+0x255/0x29a
> [<ffffffff824309ec>] ? __ubsan_handle_out_of_bounds+0x180/0x180
> [<ffffffff84003436>] ? nl80211_req_set_reg+0x256/0x2f0
> [<ffffffff812112ba>] ? print_context_stack+0x8a/0x160
> [<ffffffff81200031>] ? amd_pmu_reset+0x341/0x380
> [<ffffffff823af808>] rht_deferred_worker+0x1618/0x1790
> [<ffffffff823af808>] ? rht_deferred_worker+0x1618/0x1790
> [<ffffffff823ae1f0>] ? rhashtable_jhash2+0x370/0x370
> [<ffffffff8134c12d>] ? process_one_work+0x6fd/0x1970
> [<ffffffff8134c1cf>] process_one_work+0x79f/0x1970
> [<ffffffff8134c12d>] ? process_one_work+0x6fd/0x1970
> [<ffffffff8134ba30>] ? try_to_grab_pending+0x4c0/0x4c0
> [<ffffffff8134d564>] ? worker_thread+0x1c4/0x1340
> [<ffffffff8134d8ff>] worker_thread+0x55f/0x1340
> [<ffffffff845e904f>] ? __schedule+0x4df/0x1d40
> [<ffffffff8134d3a0>] ? process_one_work+0x1970/0x1970
> [<ffffffff8134d3a0>] ? process_one_work+0x1970/0x1970
> [<ffffffff813642f7>] kthread+0x237/0x390
> [<ffffffff813640c0>] ? __kthread_parkme+0x280/0x280
> [<ffffffff845f8c93>] ? _raw_spin_unlock_irq+0x33/0x50
> [<ffffffff845f95df>] ret_from_fork+0x1f/0x40
> [<ffffffff813640c0>] ? __kthread_parkme+0x280/0x280
> ================================================================================
>
> roundup_pow_of_two() is undefined when called with an argument of 0, so
> let's avoid the call and just fall back to ht->p.min_size (which should
> never be smaller than HASH_MIN_SIZE).
>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rhashtable: fix shift by 64 when shrinking
2016-08-12 18:10 [PATCH] rhashtable: fix shift by 64 when shrinking Vegard Nossum
2016-08-15 6:02 ` Herbert Xu
@ 2016-08-15 18:10 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-08-15 18:10 UTC (permalink / raw)
To: vegard.nossum; +Cc: tgraf, netdev, herbert
From: Vegard Nossum <vegard.nossum@oracle.com>
Date: Fri, 12 Aug 2016 20:10:44 +0200
> I got this:
...
> roundup_pow_of_two() is undefined when called with an argument of 0, so
> let's avoid the call and just fall back to ht->p.min_size (which should
> never be smaller than HASH_MIN_SIZE).
>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Applied, thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-15 18:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-12 18:10 [PATCH] rhashtable: fix shift by 64 when shrinking Vegard Nossum
2016-08-15 6:02 ` Herbert Xu
2016-08-15 18:10 ` David Miller
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).