From: Ying Xue <ying.xue@windriver.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
Thomas Graf <tgraf@suug.ch>, <netdev@vger.kernel.org>
Subject: Re: rhashtable: Fix potential crash on destroy in rhashtable_shrink
Date: Mon, 2 Feb 2015 17:34:40 +0800 [thread overview]
Message-ID: <54CF44B0.4040205@windriver.com> (raw)
In-Reply-To: <20150131093637.GA29106@gondor.apana.org.au>
On 01/31/2015 05:36 PM, Herbert Xu wrote:
> The current being_destroyed check in rhashtable_expand is not
> enough since if we start a shrinking process after freeing all
> elements in the table that's also going to crash.
>
Sorry, I cannot understand the scenario.
When we free the table in rhashtable_destroy(), we call
cancel_work_sync() to synchronously cancel the work. So, why does your
described crash still happen?
Please give a more explanation.
Thanks,
Ying
> This patch adds a being_destroyed check to the deferred worker
> thread so that we bail out as soon as we take the lock.
>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
>
> diff --git a/lib/rhashtable.c b/lib/rhashtable.c
> index 69a4eb0..4c3da1f 100644
> --- a/lib/rhashtable.c
> +++ b/lib/rhashtable.c
> @@ -489,6 +489,9 @@ static void rht_deferred_worker(struct work_struct *work)
>
> ht = container_of(work, struct rhashtable, run_work);
> mutex_lock(&ht->mutex);
> + if (ht->being_destroyed)
> + goto unlock;
> +
> tbl = rht_dereference(ht->tbl, ht);
>
> list_for_each_entry(walker, &ht->walkers, list)
> @@ -499,6 +502,7 @@ static void rht_deferred_worker(struct work_struct *work)
> else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size))
> rhashtable_shrink(ht);
>
> +unlock:
> mutex_unlock(&ht->mutex);
> }
>
>
next prev parent reply other threads:[~2015-02-02 9:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-31 9:36 rhashtable: Fix potential crash on destroy in rhashtable_shrink Herbert Xu
2015-01-31 11:16 ` Thomas Graf
2015-01-31 11:22 ` Herbert Xu
2015-01-31 12:15 ` Thomas Graf
2015-02-02 9:34 ` Ying Xue [this message]
2015-02-02 9:48 ` Thomas Graf
2015-02-03 3:19 ` David Miller
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=54CF44B0.4040205@windriver.com \
--to=ying.xue@windriver.com \
--cc=herbert@gondor.apana.org.au \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.