|
@@ -45,8 +45,6 @@ struct xfrm_flo {
|
|
u8 flags;
|
|
u8 flags;
|
|
};
|
|
};
|
|
|
|
|
|
-static DEFINE_PER_CPU(struct xfrm_dst *, xfrm_last_dst);
|
|
|
|
-static struct work_struct *xfrm_pcpu_work __read_mostly;
|
|
|
|
static DEFINE_SPINLOCK(xfrm_if_cb_lock);
|
|
static DEFINE_SPINLOCK(xfrm_if_cb_lock);
|
|
static struct xfrm_if_cb const __rcu *xfrm_if_cb __read_mostly;
|
|
static struct xfrm_if_cb const __rcu *xfrm_if_cb __read_mostly;
|
|
|
|
|
|
@@ -1732,108 +1730,6 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-static void xfrm_last_dst_update(struct xfrm_dst *xdst, struct xfrm_dst *old)
|
|
|
|
-{
|
|
|
|
- this_cpu_write(xfrm_last_dst, xdst);
|
|
|
|
- if (old)
|
|
|
|
- dst_release(&old->u.dst);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void __xfrm_pcpu_work_fn(void)
|
|
|
|
-{
|
|
|
|
- struct xfrm_dst *old;
|
|
|
|
-
|
|
|
|
- old = this_cpu_read(xfrm_last_dst);
|
|
|
|
- if (old && !xfrm_bundle_ok(old))
|
|
|
|
- xfrm_last_dst_update(NULL, old);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void xfrm_pcpu_work_fn(struct work_struct *work)
|
|
|
|
-{
|
|
|
|
- local_bh_disable();
|
|
|
|
- rcu_read_lock();
|
|
|
|
- __xfrm_pcpu_work_fn();
|
|
|
|
- rcu_read_unlock();
|
|
|
|
- local_bh_enable();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void xfrm_policy_cache_flush(void)
|
|
|
|
-{
|
|
|
|
- struct xfrm_dst *old;
|
|
|
|
- bool found = false;
|
|
|
|
- int cpu;
|
|
|
|
-
|
|
|
|
- might_sleep();
|
|
|
|
-
|
|
|
|
- local_bh_disable();
|
|
|
|
- rcu_read_lock();
|
|
|
|
- for_each_possible_cpu(cpu) {
|
|
|
|
- old = per_cpu(xfrm_last_dst, cpu);
|
|
|
|
- if (old && !xfrm_bundle_ok(old)) {
|
|
|
|
- if (smp_processor_id() == cpu) {
|
|
|
|
- __xfrm_pcpu_work_fn();
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- found = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rcu_read_unlock();
|
|
|
|
- local_bh_enable();
|
|
|
|
-
|
|
|
|
- if (!found)
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- get_online_cpus();
|
|
|
|
-
|
|
|
|
- for_each_possible_cpu(cpu) {
|
|
|
|
- bool bundle_release;
|
|
|
|
-
|
|
|
|
- rcu_read_lock();
|
|
|
|
- old = per_cpu(xfrm_last_dst, cpu);
|
|
|
|
- bundle_release = old && !xfrm_bundle_ok(old);
|
|
|
|
- rcu_read_unlock();
|
|
|
|
-
|
|
|
|
- if (!bundle_release)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- if (cpu_online(cpu)) {
|
|
|
|
- schedule_work_on(cpu, &xfrm_pcpu_work[cpu]);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rcu_read_lock();
|
|
|
|
- old = per_cpu(xfrm_last_dst, cpu);
|
|
|
|
- if (old && !xfrm_bundle_ok(old)) {
|
|
|
|
- per_cpu(xfrm_last_dst, cpu) = NULL;
|
|
|
|
- dst_release(&old->u.dst);
|
|
|
|
- }
|
|
|
|
- rcu_read_unlock();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- put_online_cpus();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static bool xfrm_xdst_can_reuse(struct xfrm_dst *xdst,
|
|
|
|
- struct xfrm_state * const xfrm[],
|
|
|
|
- int num)
|
|
|
|
-{
|
|
|
|
- const struct dst_entry *dst = &xdst->u.dst;
|
|
|
|
- int i;
|
|
|
|
-
|
|
|
|
- if (xdst->num_xfrms != num)
|
|
|
|
- return false;
|
|
|
|
-
|
|
|
|
- for (i = 0; i < num; i++) {
|
|
|
|
- if (!dst || dst->xfrm != xfrm[i])
|
|
|
|
- return false;
|
|
|
|
- dst = xfrm_dst_child(dst);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return xfrm_bundle_ok(xdst);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static struct xfrm_dst *
|
|
static struct xfrm_dst *
|
|
xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
|
|
xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
|
|
const struct flowi *fl, u16 family,
|
|
const struct flowi *fl, u16 family,
|
|
@@ -1842,7 +1738,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
|
|
struct net *net = xp_net(pols[0]);
|
|
struct net *net = xp_net(pols[0]);
|
|
struct xfrm_state *xfrm[XFRM_MAX_DEPTH];
|
|
struct xfrm_state *xfrm[XFRM_MAX_DEPTH];
|
|
struct xfrm_dst *bundle[XFRM_MAX_DEPTH];
|
|
struct xfrm_dst *bundle[XFRM_MAX_DEPTH];
|
|
- struct xfrm_dst *xdst, *old;
|
|
|
|
|
|
+ struct xfrm_dst *xdst;
|
|
struct dst_entry *dst;
|
|
struct dst_entry *dst;
|
|
int err;
|
|
int err;
|
|
|
|
|
|
@@ -1854,22 +1750,6 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
|
|
return ERR_PTR(err);
|
|
return ERR_PTR(err);
|
|
}
|
|
}
|
|
|
|
|
|
- xdst = this_cpu_read(xfrm_last_dst);
|
|
|
|
- if (xdst &&
|
|
|
|
- xdst->u.dst.dev == dst_orig->dev &&
|
|
|
|
- xdst->num_pols == num_pols &&
|
|
|
|
- memcmp(xdst->pols, pols,
|
|
|
|
- sizeof(struct xfrm_policy *) * num_pols) == 0 &&
|
|
|
|
- xfrm_xdst_can_reuse(xdst, xfrm, err)) {
|
|
|
|
- dst_hold(&xdst->u.dst);
|
|
|
|
- xfrm_pols_put(pols, num_pols);
|
|
|
|
- while (err > 0)
|
|
|
|
- xfrm_state_put(xfrm[--err]);
|
|
|
|
- return xdst;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- old = xdst;
|
|
|
|
-
|
|
|
|
dst = xfrm_bundle_create(pols[0], xfrm, bundle, err, fl, dst_orig);
|
|
dst = xfrm_bundle_create(pols[0], xfrm, bundle, err, fl, dst_orig);
|
|
if (IS_ERR(dst)) {
|
|
if (IS_ERR(dst)) {
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLEGENERROR);
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLEGENERROR);
|
|
@@ -1882,9 +1762,6 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
|
|
memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
|
|
memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
|
|
xdst->policy_genid = atomic_read(&pols[0]->genid);
|
|
xdst->policy_genid = atomic_read(&pols[0]->genid);
|
|
|
|
|
|
- atomic_set(&xdst->u.dst.__refcnt, 2);
|
|
|
|
- xfrm_last_dst_update(xdst, old);
|
|
|
|
-
|
|
|
|
return xdst;
|
|
return xdst;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2085,11 +1962,8 @@ xfrm_bundle_lookup(struct net *net, const struct flowi *fl, u16 family, u8 dir,
|
|
if (num_xfrms <= 0)
|
|
if (num_xfrms <= 0)
|
|
goto make_dummy_bundle;
|
|
goto make_dummy_bundle;
|
|
|
|
|
|
- local_bh_disable();
|
|
|
|
xdst = xfrm_resolve_and_create_bundle(pols, num_pols, fl, family,
|
|
xdst = xfrm_resolve_and_create_bundle(pols, num_pols, fl, family,
|
|
xflo->dst_orig);
|
|
xflo->dst_orig);
|
|
- local_bh_enable();
|
|
|
|
-
|
|
|
|
if (IS_ERR(xdst)) {
|
|
if (IS_ERR(xdst)) {
|
|
err = PTR_ERR(xdst);
|
|
err = PTR_ERR(xdst);
|
|
if (err == -EREMOTE) {
|
|
if (err == -EREMOTE) {
|
|
@@ -2181,11 +2055,9 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
|
|
goto no_transform;
|
|
goto no_transform;
|
|
}
|
|
}
|
|
|
|
|
|
- local_bh_disable();
|
|
|
|
xdst = xfrm_resolve_and_create_bundle(
|
|
xdst = xfrm_resolve_and_create_bundle(
|
|
pols, num_pols, fl,
|
|
pols, num_pols, fl,
|
|
family, dst_orig);
|
|
family, dst_orig);
|
|
- local_bh_enable();
|
|
|
|
|
|
|
|
if (IS_ERR(xdst)) {
|
|
if (IS_ERR(xdst)) {
|
|
xfrm_pols_put(pols, num_pols);
|
|
xfrm_pols_put(pols, num_pols);
|
|
@@ -3035,15 +2907,6 @@ static struct pernet_operations __net_initdata xfrm_net_ops = {
|
|
|
|
|
|
void __init xfrm_init(void)
|
|
void __init xfrm_init(void)
|
|
{
|
|
{
|
|
- int i;
|
|
|
|
-
|
|
|
|
- xfrm_pcpu_work = kmalloc_array(NR_CPUS, sizeof(*xfrm_pcpu_work),
|
|
|
|
- GFP_KERNEL);
|
|
|
|
- BUG_ON(!xfrm_pcpu_work);
|
|
|
|
-
|
|
|
|
- for (i = 0; i < NR_CPUS; i++)
|
|
|
|
- INIT_WORK(&xfrm_pcpu_work[i], xfrm_pcpu_work_fn);
|
|
|
|
-
|
|
|
|
register_pernet_subsys(&xfrm_net_ops);
|
|
register_pernet_subsys(&xfrm_net_ops);
|
|
xfrm_dev_init();
|
|
xfrm_dev_init();
|
|
seqcount_init(&xfrm_policy_hash_generation);
|
|
seqcount_init(&xfrm_policy_hash_generation);
|