Re: [PATCH resend] rhashtable: detect when object movement might have invalidated a lookup

From: NeilBrown
Date: Sun Jul 15 2018 - 19:56:06 EST


On Wed, Jul 11 2018, David Miller wrote:

> From: David Miller <davem@xxxxxxxxxxxxx>
> Date: Wed, 11 Jul 2018 22:46:58 -0700 (PDT)
>
>> From: NeilBrown <neilb@xxxxxxxx>
>> Date: Fri, 06 Jul 2018 17:08:35 +1000
>>
>>>
>>> Some users of rhashtable might need to change the key
>>> of an object and move it to a different location in the table.
>>> Other users might want to allocate objects using
>>> SLAB_TYPESAFE_BY_RCU which can result in the same memory allocation
>>> being used for a different (type-compatible) purpose and similarly
>>> end up in a different hash-chain.
>>>
>>> To support these, we store a unique NULLS_MARKER at the end of
>>> each chain, and when a search fails to find a match, we check
>>> if the NULLS marker found was the expected one. If not,
>>> the search is repeated.
>>>
>>> The unique NULLS_MARKER is derived from the address of the
>>> head of the chain.
>>>
>>> If an object is removed and re-added to the same hash chain, we won't
>>> notice by looking that the NULLS marker. In this case we must be sure
>>> that it was not re-added *after* its original location, or a lookup may
>>> incorrectly fail. The easiest solution is to ensure it is inserted at
>>> the start of the chain. insert_slow() already does that,
>>> insert_fast() does not. So this patch changes insert_fast to always
>>> insert at the head of the chain.
>>>
>>> Note that such a user must do their own double-checking of
>>> the object found by rhashtable_lookup_fast() after ensuring
>>> mutual exclusion which anything that might change the key, such as
>>> successfully taking a new reference.
>>>
>>> Signed-off-by: NeilBrown <neilb@xxxxxxxx>
>>
>> Applied to net-next.
>
> Actually, reverted, it doesn't even compile.
>
> lib/rhashtable.c: In function ârht_bucket_nestedâ:
> lib/rhashtable.c:1187:39: error: macro "INIT_RHT_NULLS_HEAD" passed 3 arguments, but takes just 1
> INIT_RHT_NULLS_HEAD(rhnull, NULL, 0);
> ^
> lib/rhashtable.c:1187:4: error: âINIT_RHT_NULLS_HEADâ undeclared (first use in this function); did you mean âINIT_LIST_HEADâ?
> INIT_RHT_NULLS_HEAD(rhnull, NULL, 0);
> ^~~~~~~~~~~~~~~~~~~
> INIT_LIST_HEAD
> lib/rhashtable.c:1187:4: note: each undeclared identifier is reported only once for each function it appears in

How embarrassing :-(
I had tested a series, but not each individual patch. Sorry about that.
I'll post the correct patch.

Thanks,
NeilBrown

Attachment: signature.asc
Description: PGP signature