From: John Fastabend <john.fastabend@gmail•com>
To: tgraf <tgraf@suug•ch>
Cc: netdev <netdev@vger•kernel.org>
Subject: Re: nft_hash rhashtable question
Date: Mon, 12 Jan 2015 14:53:51 -0800 [thread overview]
Message-ID: <54B4507F.1020605@gmail.com> (raw)
In-Reply-To: <20150112224249.GA11857@casper.infradead.org>
On 01/12/2015 02:42 PM, tgraf wrote:
> On 01/12/15 at 02:30pm, John Fastabend wrote:
>>> /* Stop an eventual async resizing */
>>> priv->being_destroyed = true;
>
> This aborts and eventual resize in the background.
>
>>> mutex_lock(&priv->mutex); <-- get the lock so we have single updater
>
> this ensures that the resize finished.
>
>>> tbl = rht_dereference(priv->tbl, priv);
>>> for (i = 0; i < tbl->size; i++) {
>>> rht_for_each_entry_safe(he, pos, next, tbl, i, node)
>>> nft_hash_elem_destroy(set, he); <-- does a kfree on he?
>>> }
>>> mutex_unlock(&priv->mutex); <-- release the lock
>>>
>>> rhashtable_destroy(priv);
>
> Since no insert or removal can occur we can be assured that no new
> entry was added in the meantime so we can destroy the rhashtable
> without any further protection.
>
>>> }
>>
>>
>> Is it really safe to kfree 'he' without waiting a grace
>> period for any rcu readers to drop the reference?
>>
>> I'm considering what happens if nft_hash_destroy runs in
>> parallel with nft_hash_lookup?
>
> The nft_set API ensures that a destroy can't occur in parallel to
> an insertion or removal. All we have to ensure is that any resizing
> in the background is aborted and completed.
>
It must also somehow ensure there are no readers with a reference
as well. Thanks for the explanation.
> If you look at the code before the rhashtable there was no locking
> at all:
>
> static void nft_hash_destroy(const struct nft_set *set)
> {
> const struct nft_hash *priv = nft_set_priv(set);
> const struct nft_hash_table *tbl = nft_dereference(priv->tbl);
> struct nft_hash_elem *he, *next;
> unsigned int i;
>
> for (i = 0; i < tbl->size; i++) {
> for (he = nft_dereference(tbl->buckets[i]); he != NULL;
> he = next) {
> next = nft_dereference(he->next);
> nft_hash_elem_destroy(set, he);
> }
> }
> kfree(tbl);
> }
>
--
John Fastabend Intel Corporation
prev parent reply other threads:[~2015-01-12 22:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 22:30 nft_hash rhashtable question John Fastabend
2015-01-12 22:42 ` tgraf
2015-01-12 22:53 ` John Fastabend [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54B4507F.1020605@gmail.com \
--to=john.fastabend@gmail$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=tgraf@suug$(echo .)ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox