Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7def0f95 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov Committed by David S. Miller
Browse files

lib: fix data race in rhashtable_rehash_one



rhashtable_rehash_one() uses complex logic to update entry->next field,
after INIT_RHT_NULLS_HEAD and NULLS_MARKER expansion:

entry->next = 1 | ((base + off) << 1)

This can be compiled along the lines of:

entry->next = base + off
entry->next <<= 1
entry->next |= 1

Which will break concurrent readers.

NULLS value recomputation is not needed here, so just remove
the complex logic.

The data race was found with KernelThreadSanitizer (KTSAN).

Signed-off-by: default avatarDmitry Vyukov <dvyukov@google.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarThomas Graf <tgraf@suug.ch>
Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 23eedbc2
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -187,9 +187,6 @@ static int rhashtable_rehash_one(struct rhashtable *ht, unsigned int old_hash)
	head = rht_dereference_bucket(new_tbl->buckets[new_hash],
				      new_tbl, new_hash);

	if (rht_is_a_nulls(head))
		INIT_RHT_NULLS_HEAD(entry->next, ht, new_hash);
	else
	RCU_INIT_POINTER(entry->next, head);

	rcu_assign_pointer(new_tbl->buckets[new_hash], entry);