From: David Miller <davem@davemloft.net>
To: hslester96@gmail.com
Cc: vishal@chelsio.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] cxgb4: smt: Use refcount_t for refcount
Date: Mon, 05 Aug 2019 10:55:00 -0700 (PDT) [thread overview]
Message-ID: <20190805.105500.1555481916904502971.davem@davemloft.net> (raw)
In-Reply-To: <20190802083547.12657-1-hslester96@gmail.com>
From: Chuhong Yuan <hslester96@gmail.com>
Date: Fri, 2 Aug 2019 16:35:47 +0800
> refcount_t is better for reference counters since its
> implementation can prevent overflows.
> So convert atomic_t ref counters to refcount_t.
>
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> Changes in v2:
> - Convert refcount from 0-base to 1-base.
The existing code is buggy and should be fixed before you start making
conversions to it.
> @@ -111,7 +111,7 @@ static void t4_smte_free(struct smt_entry *e)
> */
> void cxgb4_smt_release(struct smt_entry *e)
> {
> - if (atomic_dec_and_test(&e->refcnt))
> + if (refcount_dec_and_test(&e->refcnt))
> t4_smte_free(e);
This runs without any locking and therefore:
> if (e) {
> spin_lock(&e->lock);
> - if (!atomic_read(&e->refcnt)) {
> - atomic_set(&e->refcnt, 1);
> + if (refcount_read(&e->refcnt) == 1) {
> + refcount_set(&e->refcnt, 2);
This test is not safe, since the reference count can asynchronously decrement
to zero above outside of any locks.
Then you'll need to add locking, and as a result the need to an atomic
counter goes away and just a normal int can be used.
next prev parent reply other threads:[~2019-08-05 17:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-02 8:35 [PATCH v2 2/2] cxgb4: smt: Use refcount_t for refcount Chuhong Yuan
2019-08-05 17:55 ` David Miller [this message]
2019-08-02 8:41 Chuhong Yuan
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=20190805.105500.1555481916904502971.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=hslester96@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=vishal@chelsio.com \
/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 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).