Skip to contentSkip to conversation

Make flow cache name space aware

PATCH Superseded Fan Du 2 participants 6 messages Jan 13, 2014

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fan Du

author
#0 lore raw

cover Make flow cache name space aware

Hi,

This patch set aims to make flow cache operating in a per net style when inserting flow cache entry or flush flow cache. The reason to do so is not much compelling but reasonable, which is flushing flow cache in original implementation has global effective, the collateral damage is netns with only a few flow cache entries has gone.

So this patch make flow cache running in a per net scope. Operation from different netns won't interfere with each other. And the flushing operation is worthwhile for the netns which supposed to be.

Fan Du (4):
flowcache: Namespacify flowcache global parameters with xfrm
flowcache: Make flowcache entry inserting/flushing in per-net style
flowcache: fixup flow cache part in xfrm policy
flowcache: Bring net/core/flow.c under IPsec maintain scope

 MAINTAINERS              |    1 +
 include/net/flow.h       |    5 +-
 include/net/netns/xfrm.h |   11 ++++
 net/core/flow.c          |  127 +++++++++++++++++++++-------------------------
 net/xfrm/xfrm_policy.c   |    7 +--
 5 files changed, 76 insertions(+), 75 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/4 flowcache: Namespacify flowcache global parameters with xfrm

Since flowcache is tightly coupled with IPsec, so it would be easier to put flow cache global parameters here into xfrm namespace part.

---
 include/net/netns/xfrm.h |   11 +++++++++++
 1 file changed, 11 insertions(+)
include/net/netns/xfrm.h +11 -0
index 1006a26..52d0086 100644
@@ -6,6 +6,7 @@
 #include <linux/workqueue.h>
 #include <linux/xfrm.h>
 #include <net/dst_ops.h>
+#include <net/flowcache.h>
 
 struct ctl_table_header;
 
@@ -61,6 +62,16 @@ struct netns_xfrm {
 	spinlock_t xfrm_policy_sk_bundle_lock;
 	rwlock_t xfrm_policy_lock;
 	struct mutex xfrm_cfg_mutex;
+
+	/* flow cache part */
+	struct flow_cache	flow_cache_global;
+	struct kmem_cache	*flow_cachep;
+	atomic_t		flow_cache_genid;
+	struct list_head	flow_cache_gc_list;
+	spinlock_t		flow_cache_gc_lock;
+	struct work_struct	flow_cache_gc_work;
+	struct work_struct	flow_cache_flush_work;
+	struct mutex		flow_flush_sem;
 };
 
 #endif
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 2/4 flowcache: Make flowcache entry inserting/flushing in per-net style

In reply to Fan Du

Inserting a entry into flowcache, or flushing flowcache should be based on per net scope. The reason to do so is flushing operation from fat netns crammed with flow entries will also making the slim netns with only a few flow cache entries go away in original implementation.

---
 include/net/flow.h |    5 ++-
 net/core/flow.c    |  127 +++++++++++++++++++++++-----------------------------
 2 files changed, 60 insertions(+), 72 deletions(-)
include/net/flow.h +3 -2
index d23e7fa..bee3741 100644
@@ -218,9 +218,10 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
 					    const struct flowi *key, u16 family,
 					    u8 dir, flow_resolve_t resolver,
 					    void *ctx);
+int flow_cache_init(struct net *net);
 
-void flow_cache_flush(void);
-void flow_cache_flush_deferred(void);
+void flow_cache_flush(struct net *net);
+void flow_cache_flush_deferred(struct net *net);
 extern atomic_t flow_cache_genid;
 
 #endif
net/core/flow.c +57 -70

282 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH 3/4 flowcache: Fixup flow cache part in xfrm policy

In reply to Fan Du

Bump flow cache genid, and flush flow cache should also be made in per net style.

---
 net/xfrm/xfrm_policy.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/xfrm/xfrm_policy.c +4 -3
index e205c4b..d39c90f 100644
@@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
 		hlist_add_head(&policy->bydst, chain);
 	xfrm_pol_hold(policy);
 	net->xfrm.policy_count[dir]++;
-	atomic_inc(&flow_cache_genid);
+	atomic_inc(&net->xfrm.flow_cache_genid);
 
 	/* After previous checking, family can either be AF_INET or AF_INET6 */
 	if (policy->family == AF_INET)
@@ -2567,14 +2567,14 @@ static void __xfrm_garbage_collect(struct net *net)
 
 void xfrm_garbage_collect(struct net *net)
 {
-	flow_cache_flush();
+	flow_cache_flush(net);
 	__xfrm_garbage_collect(net);
 }
 EXPORT_SYMBOL(xfrm_garbage_collect);
 
 static void xfrm_garbage_collect_deferred(struct net *net)
 {
-	flow_cache_flush_deferred();
+	flow_cache_flush_deferred(net);
 	__xfrm_garbage_collect(net);
 }
 
@@ -2947,6 +2947,7 @@ static int __net_init xfrm_net_init(struct net *net)
 	spin_lock_init(&net->xfrm.xfrm_policy_sk_bundle_lock);
 	mutex_init(&net->xfrm.xfrm_cfg_mutex);
 
+	flow_cache_init(net);
 	return 0;
 
 out_sysctl:
Signature · 1 line
1.7.9.5
#4 lore raw

Re: [PATCH net-next 3/4] flowcache: Fixup flow cache part in xfrm policy

Quoted 5 lines · Fan Du

void xfrm_garbage_collect(struct net *net)
{

net/xfrm/xfrm_policy.c +1 -1
-       flow_cache_flush();
+       flow_cache_flush(net);

net/xfrm/xfrm_policy.c static void __xfrm_garbage_collect(struct net *net) · line 2579

Quoted 10 lines
net/xfrm/xfrm_policy.c +1 -1
        __xfrm_garbage_collect(net);
 }
 EXPORT_SYMBOL(xfrm_garbage_collect);
 
 static void xfrm_garbage_collect_deferred(struct net *net)
 {
-       flow_cache_flush_deferred();
+       flow_cache_flush_deferred(net);
        __xfrm_garbage_collect(net);
 }

You changed the prototypes of flow_cache_flush*() in the previous patch, so, here you break bisect. They have to be in one commit.

author
#5 lore raw

PATCH 4/4 flowcache: Bring net/core/flow.c under IPsec maintain scope

In reply to Fan Du

As flow cache is mainly manipulated from IPsec.

---
 MAINTAINERS |    1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index e11d495..14ad385 100644
@@ -5916,6 +5916,7 @@ L:	[email protected]
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git
 S:	Maintained
+F:	net/core/flow.c
 F:	net/xfrm/
 F:	net/key/
 F:	net/ipv4/xfrm*
Signature · 1 line
1.7.9.5