Skip to content

Commit

Permalink
net: Add a flow_cache_flush_deferred function
Browse files Browse the repository at this point in the history
flow_cach_flush() might sleep but can be called from
atomic context via the xfrm garbage collector. So add
a flow_cache_flush_deferred() function and use this if
the xfrm garbage colector is invoked from within the
packet path.

Signed-off-by: Steffen Klassert <[email protected]>
Acked-by: Timo Teräs <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
klassert authored and davem330 committed Dec 21, 2011
1 parent 9f28a2f commit c0ed1c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/net/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ extern struct flow_cache_object *flow_cache_lookup(
u8 dir, flow_resolve_t resolver, void *ctx);

extern void flow_cache_flush(void);
extern void flow_cache_flush_deferred(void);
extern atomic_t flow_cache_genid;

#endif
12 changes: 12 additions & 0 deletions net/core/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ void flow_cache_flush(void)
put_online_cpus();
}

static void flow_cache_flush_task(struct work_struct *work)
{
flow_cache_flush();
}

static DECLARE_WORK(flow_cache_flush_work, flow_cache_flush_task);

void flow_cache_flush_deferred(void)
{
schedule_work(&flow_cache_flush_work);
}

static int __cpuinit flow_cache_cpu_prepare(struct flow_cache *fc, int cpu)
{
struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu);
Expand Down
18 changes: 14 additions & 4 deletions net/xfrm/xfrm_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2276,8 +2276,6 @@ static void __xfrm_garbage_collect(struct net *net)
{
struct dst_entry *head, *next;

flow_cache_flush();

spin_lock_bh(&xfrm_policy_sk_bundle_lock);
head = xfrm_policy_sk_bundles;
xfrm_policy_sk_bundles = NULL;
Expand All @@ -2290,6 +2288,18 @@ static void __xfrm_garbage_collect(struct net *net)
}
}

static void xfrm_garbage_collect(struct net *net)
{
flow_cache_flush();
__xfrm_garbage_collect(net);
}

static void xfrm_garbage_collect_deferred(struct net *net)
{
flow_cache_flush_deferred();
__xfrm_garbage_collect(net);
}

static void xfrm_init_pmtu(struct dst_entry *dst)
{
do {
Expand Down Expand Up @@ -2422,7 +2432,7 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
if (likely(dst_ops->neigh_lookup == NULL))
dst_ops->neigh_lookup = xfrm_neigh_lookup;
if (likely(afinfo->garbage_collect == NULL))
afinfo->garbage_collect = __xfrm_garbage_collect;
afinfo->garbage_collect = xfrm_garbage_collect_deferred;
xfrm_policy_afinfo[afinfo->family] = afinfo;
}
write_unlock_bh(&xfrm_policy_afinfo_lock);
Expand Down Expand Up @@ -2516,7 +2526,7 @@ static int xfrm_dev_event(struct notifier_block *this, unsigned long event, void

switch (event) {
case NETDEV_DOWN:
__xfrm_garbage_collect(dev_net(dev));
xfrm_garbage_collect(dev_net(dev));
}
return NOTIFY_DONE;
}
Expand Down

0 comments on commit c0ed1c1

Please sign in to comment.