From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH net-next 10/14] netfilter: ecache: don't use nf_conn spinlock
Date: Wed, 9 Feb 2022 14:36:12 +0100 [thread overview]
Message-ID: <20220209133616.165104-11-pablo@netfilter.org> (raw)
In-Reply-To: <20220209133616.165104-1-pablo@netfilter.org>
From: Florian Westphal <fw@strlen.de>
For updating eache missed value we can use cmpxchg.
This also avoids need to disable BH.
kernel robot reported build failure on v1 because not all arches support
cmpxchg for u16, so extend this to u32.
This doesn't increase struct size, existing padding is used.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_conntrack_ecache.h | 2 +-
net/netfilter/nf_conntrack_ecache.c | 25 +++++++++++----------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack_ecache.h b/include/net/netfilter/nf_conntrack_ecache.h
index 16bcff809b18..6c4c490a3e34 100644
--- a/include/net/netfilter/nf_conntrack_ecache.h
+++ b/include/net/netfilter/nf_conntrack_ecache.h
@@ -21,10 +21,10 @@ enum nf_ct_ecache_state {
struct nf_conntrack_ecache {
unsigned long cache; /* bitops want long */
- u16 missed; /* missed events */
u16 ctmask; /* bitmask of ct events to be delivered */
u16 expmask; /* bitmask of expect events to be delivered */
enum nf_ct_ecache_state state:8;/* ecache state */
+ u32 missed; /* missed events */
u32 portid; /* netlink portid of destroyer */
};
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 873908054f7f..07e65b4e92f8 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -131,13 +131,13 @@ static void ecache_work(struct work_struct *work)
}
static int __nf_conntrack_eventmask_report(struct nf_conntrack_ecache *e,
- const unsigned int events,
- const unsigned long missed,
+ const u32 events,
+ const u32 missed,
const struct nf_ct_event *item)
{
- struct nf_conn *ct = item->ct;
struct net *net = nf_ct_net(item->ct);
struct nf_ct_event_notifier *notify;
+ u32 old, want;
int ret;
if (!((events | missed) & e->ctmask))
@@ -157,12 +157,13 @@ static int __nf_conntrack_eventmask_report(struct nf_conntrack_ecache *e,
if (likely(ret >= 0 && missed == 0))
return 0;
- spin_lock_bh(&ct->lock);
- if (ret < 0)
- e->missed |= events;
- else
- e->missed &= ~missed;
- spin_unlock_bh(&ct->lock);
+ do {
+ old = READ_ONCE(e->missed);
+ if (ret < 0)
+ want = old | events;
+ else
+ want = old & ~missed;
+ } while (cmpxchg(&e->missed, old, want) != old);
return ret;
}
@@ -172,7 +173,7 @@ int nf_conntrack_eventmask_report(unsigned int events, struct nf_conn *ct,
{
struct nf_conntrack_ecache *e;
struct nf_ct_event item;
- unsigned long missed;
+ unsigned int missed;
int ret;
if (!nf_ct_is_confirmed(ct))
@@ -211,7 +212,7 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
{
struct nf_conntrack_ecache *e;
struct nf_ct_event item;
- unsigned long events;
+ unsigned int events;
if (!nf_ct_is_confirmed(ct) || nf_ct_is_dying(ct))
return;
@@ -312,7 +313,7 @@ void nf_conntrack_ecache_pernet_init(struct net *net)
cnet->ct_net = &net->ct;
INIT_DELAYED_WORK(&cnet->ecache_dwork, ecache_work);
- BUILD_BUG_ON(__IPCT_MAX >= 16); /* ctmask, missed use u16 */
+ BUILD_BUG_ON(__IPCT_MAX >= 16); /* e->ctmask is u16 */
}
void nf_conntrack_ecache_pernet_fini(struct net *net)
--
2.30.2
next prev parent reply other threads:[~2022-02-09 13:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 13:36 [PATCH net-next 00/14] Netfilter updates for net-next Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 01/14] netfilter: conntrack: mark UDP zero checksum as CHECKSUM_UNNECESSARY Pablo Neira Ayuso
2022-02-10 5:50 ` patchwork-bot+netdevbpf
2022-02-16 14:10 ` Gal Pressman
2022-02-16 15:28 ` Florian Westphal
2022-02-16 16:04 ` Pablo Neira Ayuso
2022-02-16 18:52 ` Gal Pressman
2022-02-16 19:26 ` Florian Westphal
2022-02-09 13:36 ` [PATCH net-next 02/14] netfilter: nfqueue: enable to get skb->priority Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 03/14] netfilter: conntrack: make all extensions 8-byte alignned Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 04/14] netfilter: conntrack: move extension sizes into core Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 05/14] netfilter: conntrack: handle ->destroy hook via nat_ops instead Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 06/14] netfilter: conntrack: remove extension register api Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 07/14] netfilter: conntrack: pptp: use single option structure Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 08/14] netfilter: exthdr: add support for tcp option removal Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 09/14] netfilter: nft_compat: suppress comment match Pablo Neira Ayuso
2022-02-09 13:36 ` Pablo Neira Ayuso [this message]
2022-02-09 13:36 ` [PATCH net-next 11/14] netfilter: cttimeout: use option structure Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 12/14] netfilter: nft_cmp: optimize comparison for 16-bytes Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 13/14] nfqueue: enable to set skb->priority Pablo Neira Ayuso
2022-02-09 13:36 ` [PATCH net-next 14/14] netfilter: ctnetlink: use dump structure instead of raw args Pablo Neira Ayuso
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=20220209133616.165104-11-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.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).