From: Benjamin Poirier <bpoirier@suse.de>
To: netdev@vger.kernel.org
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
Patrick McHardy <kaber@trash.net>,
"David S. Miller" <davem@davemloft.net>,
Andrew Morton <akpm@linux-foundation.org>,
Eric Dumazet <eric.dumazet@gmail.com>,
Mike Frysinger <vapier@gentoo.org>, Arun Sharma <asharma@fb.com>,
netfilter-devel@vger.kernel.org, netfilter@vger.kernel.org,
coreteam@netfilter.org, linux-kernel@vger.kernel.org,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH RFC 2/2] netfilter: conntrack: replace mutex with cmpxchg
Date: Fri, 27 Apr 2012 14:28:53 -0400 [thread overview]
Message-ID: <1335551333-6103-2-git-send-email-bpoirier@suse.de> (raw)
In-Reply-To: <1335551333-6103-1-git-send-email-bpoirier@suse.de>
This mutex protects a single pointer.
---
net/netfilter/nf_conntrack_ecache.c | 38 +++++++++-------------------------
1 files changed, 10 insertions(+), 28 deletions(-)
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 0134009..603eb69 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -25,8 +25,6 @@
#include <net/netfilter/nf_conntrack_core.h>
#include <net/netfilter/nf_conntrack_extend.h>
-static DEFINE_MUTEX(nf_ct_ecache_mutex);
-
/* deliver cached events and clear cache entry - must be called with locally
* disabled softirqs */
void nf_ct_deliver_cached_events(struct nf_conn *ct)
@@ -80,52 +78,36 @@ EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
int nf_conntrack_register_notifier(struct net *net,
struct nf_ct_event_notifier *new)
{
- int ret = 0;
-
- mutex_lock(&nf_ct_ecache_mutex);
- if (net->ct.nf_conntrack_event_cb != NULL)
- ret = -EBUSY;
+ if (cmpxchg(&net->ct.nf_conntrack_event_cb, NULL, new) != NULL)
+ return -EBUSY;
else
- net->ct.nf_conntrack_event_cb = new;
- mutex_unlock(&nf_ct_ecache_mutex);
-
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(nf_conntrack_register_notifier);
void nf_conntrack_unregister_notifier(struct net *net,
struct nf_ct_event_notifier *new)
{
- mutex_lock(&nf_ct_ecache_mutex);
- BUG_ON(net->ct.nf_conntrack_event_cb != new);
- net->ct.nf_conntrack_event_cb = NULL;
- mutex_unlock(&nf_ct_ecache_mutex);
+ if (xchg(&net->ct.nf_conntrack_event_cb, NULL) != new)
+ BUG();
}
EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
int nf_ct_expect_register_notifier(struct net *net,
struct nf_exp_event_notifier *new)
{
- int ret = 0;
-
- mutex_lock(&nf_ct_ecache_mutex);
- if (net->ct.nf_expect_event_cb != NULL)
- ret = -EBUSY;
+ if (cmpxchg(&net->ct.nf_expect_event_cb, NULL, new) != NULL)
+ return -EBUSY;
else
- net->ct.nf_expect_event_cb = new;
- mutex_unlock(&nf_ct_ecache_mutex);
-
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(nf_ct_expect_register_notifier);
void nf_ct_expect_unregister_notifier(struct net *net,
struct nf_exp_event_notifier *new)
{
- mutex_lock(&nf_ct_ecache_mutex);
- BUG_ON(net->ct.nf_expect_event_cb != new);
- net->ct.nf_expect_event_cb = NULL;
- mutex_unlock(&nf_ct_ecache_mutex);
+ if (xchg(&net->ct.nf_expect_event_cb, NULL) != new)
+ BUG();
}
EXPORT_SYMBOL_GPL(nf_ct_expect_unregister_notifier);
--
1.7.7
next prev parent reply other threads:[~2012-04-27 18:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-27 18:28 [PATCH RFC 1/2] netfilter: conntrack: remove RCU usage in conntrack notifier Benjamin Poirier
2012-04-27 18:28 ` Benjamin Poirier [this message]
2012-05-02 0:51 ` [PATCH RFC 2/2] netfilter: conntrack: replace mutex with cmpxchg Pablo Neira Ayuso
2012-04-27 18:58 ` [PATCH RFC 1/2] netfilter: conntrack: remove RCU usage in conntrack notifier Eric Dumazet
2012-04-27 20:14 ` Benjamin Poirier
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=1335551333-6103-2-git-send-email-bpoirier@suse.de \
--to=bpoirier@suse.de \
--cc=akpm@linux-foundation.org \
--cc=asharma@fb.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kaber@trash.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=netfilter@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=vapier@gentoo.org \
/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).