Commit 95cf6674 authored by David S. Miller's avatar David S. Miller

Merge branch 'More-fixes-for-unlocked-cls-hardware-offload-API-refactoring'

Vlad Buslov says:

====================
More fixes for unlocked cls hardware offload API refactoring

Two fixes for my "Refactor cls hardware offload API to support
rtnl-independent drivers" series and refactoring patch that implements
infrastructure necessary for the fixes.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 28c9eb90 470d5060
...@@ -78,6 +78,8 @@ static inline void tcf_tm_dump(struct tcf_t *dtm, const struct tcf_t *stm) ...@@ -78,6 +78,8 @@ static inline void tcf_tm_dump(struct tcf_t *dtm, const struct tcf_t *stm)
#define ACT_P_CREATED 1 #define ACT_P_CREATED 1
#define ACT_P_DELETED 1 #define ACT_P_DELETED 1
typedef void (*tc_action_priv_destructor)(void *priv);
struct tc_action_ops { struct tc_action_ops {
struct list_head head; struct list_head head;
char kind[IFNAMSIZ]; char kind[IFNAMSIZ];
...@@ -99,8 +101,11 @@ struct tc_action_ops { ...@@ -99,8 +101,11 @@ struct tc_action_ops {
struct netlink_ext_ack *); struct netlink_ext_ack *);
void (*stats_update)(struct tc_action *, u64, u32, u64, bool); void (*stats_update)(struct tc_action *, u64, u32, u64, bool);
size_t (*get_fill_size)(const struct tc_action *act); size_t (*get_fill_size)(const struct tc_action *act);
struct net_device *(*get_dev)(const struct tc_action *a); struct net_device *(*get_dev)(const struct tc_action *a,
void (*put_dev)(struct net_device *dev); tc_action_priv_destructor *destructor);
struct psample_group *
(*get_psample_group)(const struct tc_action *a,
tc_action_priv_destructor *destructor);
}; };
struct tc_action_net { struct tc_action_net {
......
...@@ -154,8 +154,12 @@ enum flow_action_mangle_base { ...@@ -154,8 +154,12 @@ enum flow_action_mangle_base {
FLOW_ACT_MANGLE_HDR_TYPE_UDP, FLOW_ACT_MANGLE_HDR_TYPE_UDP,
}; };
typedef void (*action_destr)(void *priv);
struct flow_action_entry { struct flow_action_entry {
enum flow_action_id id; enum flow_action_id id;
action_destr destructor;
void *destructor_priv;
union { union {
u32 chain_index; /* FLOW_ACTION_GOTO */ u32 chain_index; /* FLOW_ACTION_GOTO */
struct net_device *dev; /* FLOW_ACTION_REDIRECT */ struct net_device *dev; /* FLOW_ACTION_REDIRECT */
...@@ -170,7 +174,7 @@ struct flow_action_entry { ...@@ -170,7 +174,7 @@ struct flow_action_entry {
u32 mask; u32 mask;
u32 val; u32 val;
} mangle; } mangle;
const struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */ struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */
u32 csum_flags; /* FLOW_ACTION_CSUM */ u32 csum_flags; /* FLOW_ACTION_CSUM */
u32 mark; /* FLOW_ACTION_MARK */ u32 mark; /* FLOW_ACTION_MARK */
u16 ptype; /* FLOW_ACTION_PTYPE */ u16 ptype; /* FLOW_ACTION_PTYPE */
......
...@@ -15,6 +15,7 @@ struct psample_group { ...@@ -15,6 +15,7 @@ struct psample_group {
}; };
struct psample_group *psample_group_get(struct net *net, u32 group_num); struct psample_group *psample_group_get(struct net *net, u32 group_num);
void psample_group_take(struct psample_group *group);
void psample_group_put(struct psample_group *group); void psample_group_put(struct psample_group *group);
#if IS_ENABLED(CONFIG_PSAMPLE) #if IS_ENABLED(CONFIG_PSAMPLE)
......
...@@ -41,10 +41,4 @@ static inline int tcf_sample_trunc_size(const struct tc_action *a) ...@@ -41,10 +41,4 @@ static inline int tcf_sample_trunc_size(const struct tc_action *a)
return to_sample(a)->trunc_size; return to_sample(a)->trunc_size;
} }
static inline struct psample_group *
tcf_sample_psample_group(const struct tc_action *a)
{
return rcu_dereference_rtnl(to_sample(a)->psample_group);
}
#endif /* __NET_TC_SAMPLE_H */ #endif /* __NET_TC_SAMPLE_H */
...@@ -73,7 +73,7 @@ static int psample_nl_cmd_get_group_dumpit(struct sk_buff *msg, ...@@ -73,7 +73,7 @@ static int psample_nl_cmd_get_group_dumpit(struct sk_buff *msg,
int idx = 0; int idx = 0;
int err; int err;
spin_lock(&psample_groups_lock); spin_lock_bh(&psample_groups_lock);
list_for_each_entry(group, &psample_groups_list, list) { list_for_each_entry(group, &psample_groups_list, list) {
if (!net_eq(group->net, sock_net(msg->sk))) if (!net_eq(group->net, sock_net(msg->sk)))
continue; continue;
...@@ -89,7 +89,7 @@ static int psample_nl_cmd_get_group_dumpit(struct sk_buff *msg, ...@@ -89,7 +89,7 @@ static int psample_nl_cmd_get_group_dumpit(struct sk_buff *msg,
idx++; idx++;
} }
spin_unlock(&psample_groups_lock); spin_unlock_bh(&psample_groups_lock);
cb->args[0] = idx; cb->args[0] = idx;
return msg->len; return msg->len;
} }
...@@ -172,7 +172,7 @@ struct psample_group *psample_group_get(struct net *net, u32 group_num) ...@@ -172,7 +172,7 @@ struct psample_group *psample_group_get(struct net *net, u32 group_num)
{ {
struct psample_group *group; struct psample_group *group;
spin_lock(&psample_groups_lock); spin_lock_bh(&psample_groups_lock);
group = psample_group_lookup(net, group_num); group = psample_group_lookup(net, group_num);
if (!group) { if (!group) {
...@@ -183,19 +183,27 @@ struct psample_group *psample_group_get(struct net *net, u32 group_num) ...@@ -183,19 +183,27 @@ struct psample_group *psample_group_get(struct net *net, u32 group_num)
group->refcount++; group->refcount++;
out: out:
spin_unlock(&psample_groups_lock); spin_unlock_bh(&psample_groups_lock);
return group; return group;
} }
EXPORT_SYMBOL_GPL(psample_group_get); EXPORT_SYMBOL_GPL(psample_group_get);
void psample_group_take(struct psample_group *group)
{
spin_lock_bh(&psample_groups_lock);
group->refcount++;
spin_unlock_bh(&psample_groups_lock);
}
EXPORT_SYMBOL_GPL(psample_group_take);
void psample_group_put(struct psample_group *group) void psample_group_put(struct psample_group *group)
{ {
spin_lock(&psample_groups_lock); spin_lock_bh(&psample_groups_lock);
if (--group->refcount == 0) if (--group->refcount == 0)
psample_group_destroy(group); psample_group_destroy(group);
spin_unlock(&psample_groups_lock); spin_unlock_bh(&psample_groups_lock);
} }
EXPORT_SYMBOL_GPL(psample_group_put); EXPORT_SYMBOL_GPL(psample_group_put);
......
...@@ -408,25 +408,31 @@ static struct notifier_block mirred_device_notifier = { ...@@ -408,25 +408,31 @@ static struct notifier_block mirred_device_notifier = {
.notifier_call = mirred_device_event, .notifier_call = mirred_device_event,
}; };
static struct net_device *tcf_mirred_get_dev(const struct tc_action *a) static void tcf_mirred_dev_put(void *priv)
{
struct net_device *dev = priv;
dev_put(dev);
}
static struct net_device *
tcf_mirred_get_dev(const struct tc_action *a,
tc_action_priv_destructor *destructor)
{ {
struct tcf_mirred *m = to_mirred(a); struct tcf_mirred *m = to_mirred(a);
struct net_device *dev; struct net_device *dev;
rcu_read_lock(); rcu_read_lock();
dev = rcu_dereference(m->tcfm_dev); dev = rcu_dereference(m->tcfm_dev);
if (dev) if (dev) {
dev_hold(dev); dev_hold(dev);
*destructor = tcf_mirred_dev_put;
}
rcu_read_unlock(); rcu_read_unlock();
return dev; return dev;
} }
static void tcf_mirred_put_dev(struct net_device *dev)
{
dev_put(dev);
}
static size_t tcf_mirred_get_fill_size(const struct tc_action *act) static size_t tcf_mirred_get_fill_size(const struct tc_action *act)
{ {
return nla_total_size(sizeof(struct tc_mirred)); return nla_total_size(sizeof(struct tc_mirred));
...@@ -446,7 +452,6 @@ static struct tc_action_ops act_mirred_ops = { ...@@ -446,7 +452,6 @@ static struct tc_action_ops act_mirred_ops = {
.get_fill_size = tcf_mirred_get_fill_size, .get_fill_size = tcf_mirred_get_fill_size,
.size = sizeof(struct tcf_mirred), .size = sizeof(struct tcf_mirred),
.get_dev = tcf_mirred_get_dev, .get_dev = tcf_mirred_get_dev,
.put_dev = tcf_mirred_put_dev,
}; };
static __net_init int mirred_init_net(struct net *net) static __net_init int mirred_init_net(struct net *net)
......
...@@ -252,6 +252,32 @@ static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index) ...@@ -252,6 +252,32 @@ static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index)
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static void tcf_psample_group_put(void *priv)
{
struct psample_group *group = priv;
psample_group_put(group);
}
static struct psample_group *
tcf_sample_get_group(const struct tc_action *a,
tc_action_priv_destructor *destructor)
{
struct tcf_sample *s = to_sample(a);
struct psample_group *group;
spin_lock_bh(&s->tcf_lock);
group = rcu_dereference_protected(s->psample_group,
lockdep_is_held(&s->tcf_lock));
if (group) {
psample_group_take(group);
*destructor = tcf_psample_group_put;
}
spin_unlock_bh(&s->tcf_lock);
return group;
}
static struct tc_action_ops act_sample_ops = { static struct tc_action_ops act_sample_ops = {
.kind = "sample", .kind = "sample",
.id = TCA_ID_SAMPLE, .id = TCA_ID_SAMPLE,
...@@ -262,6 +288,7 @@ static struct tc_action_ops act_sample_ops = { ...@@ -262,6 +288,7 @@ static struct tc_action_ops act_sample_ops = {
.cleanup = tcf_sample_cleanup, .cleanup = tcf_sample_cleanup,
.walk = tcf_sample_walker, .walk = tcf_sample_walker,
.lookup = tcf_sample_search, .lookup = tcf_sample_search,
.get_psample_group = tcf_sample_get_group,
.size = sizeof(struct tcf_sample), .size = sizeof(struct tcf_sample),
}; };
......
...@@ -3282,25 +3282,51 @@ void tc_cleanup_flow_action(struct flow_action *flow_action) ...@@ -3282,25 +3282,51 @@ void tc_cleanup_flow_action(struct flow_action *flow_action)
struct flow_action_entry *entry; struct flow_action_entry *entry;
int i; int i;
flow_action_for_each(i, entry, flow_action) { flow_action_for_each(i, entry, flow_action)
switch (entry->id) { if (entry->destructor)
case FLOW_ACTION_REDIRECT: entry->destructor(entry->destructor_priv);
case FLOW_ACTION_MIRRED:
case FLOW_ACTION_REDIRECT_INGRESS:
case FLOW_ACTION_MIRRED_INGRESS:
if (entry->dev)
dev_put(entry->dev);
break;
case FLOW_ACTION_TUNNEL_ENCAP:
kfree(entry->tunnel);
break;
default:
break;
}
}
} }
EXPORT_SYMBOL(tc_cleanup_flow_action); EXPORT_SYMBOL(tc_cleanup_flow_action);
static void tcf_mirred_get_dev(struct flow_action_entry *entry,
const struct tc_action *act)
{
#ifdef CONFIG_NET_CLS_ACT
entry->dev = act->ops->get_dev(act, &entry->destructor);
if (!entry->dev)
return;
entry->destructor_priv = entry->dev;
#endif
}
static void tcf_tunnel_encap_put_tunnel(void *priv)
{
struct ip_tunnel_info *tunnel = priv;
kfree(tunnel);
}
static int tcf_tunnel_encap_get_tunnel(struct flow_action_entry *entry,
const struct tc_action *act)
{
entry->tunnel = tcf_tunnel_info_copy(act);
if (!entry->tunnel)
return -ENOMEM;
entry->destructor = tcf_tunnel_encap_put_tunnel;
entry->destructor_priv = entry->tunnel;
return 0;
}
static void tcf_sample_get_group(struct flow_action_entry *entry,
const struct tc_action *act)
{
#ifdef CONFIG_NET_CLS_ACT
entry->sample.psample_group =
act->ops->get_psample_group(act, &entry->destructor);
entry->destructor_priv = entry->sample.psample_group;
#endif
}
int tc_setup_flow_action(struct flow_action *flow_action, int tc_setup_flow_action(struct flow_action *flow_action,
const struct tcf_exts *exts, bool rtnl_held) const struct tcf_exts *exts, bool rtnl_held)
{ {
...@@ -3329,24 +3355,16 @@ int tc_setup_flow_action(struct flow_action *flow_action, ...@@ -3329,24 +3355,16 @@ int tc_setup_flow_action(struct flow_action *flow_action,
entry->chain_index = tcf_gact_goto_chain_index(act); entry->chain_index = tcf_gact_goto_chain_index(act);
} else if (is_tcf_mirred_egress_redirect(act)) { } else if (is_tcf_mirred_egress_redirect(act)) {
entry->id = FLOW_ACTION_REDIRECT; entry->id = FLOW_ACTION_REDIRECT;
entry->dev = tcf_mirred_dev(act); tcf_mirred_get_dev(entry, act);
if (entry->dev)
dev_hold(entry->dev);
} else if (is_tcf_mirred_egress_mirror(act)) { } else if (is_tcf_mirred_egress_mirror(act)) {
entry->id = FLOW_ACTION_MIRRED; entry->id = FLOW_ACTION_MIRRED;
entry->dev = tcf_mirred_dev(act); tcf_mirred_get_dev(entry, act);
if (entry->dev)
dev_hold(entry->dev);
} else if (is_tcf_mirred_ingress_redirect(act)) { } else if (is_tcf_mirred_ingress_redirect(act)) {
entry->id = FLOW_ACTION_REDIRECT_INGRESS; entry->id = FLOW_ACTION_REDIRECT_INGRESS;
entry->dev = tcf_mirred_dev(act); tcf_mirred_get_dev(entry, act);
if (entry->dev)
dev_hold(entry->dev);
} else if (is_tcf_mirred_ingress_mirror(act)) { } else if (is_tcf_mirred_ingress_mirror(act)) {
entry->id = FLOW_ACTION_MIRRED_INGRESS; entry->id = FLOW_ACTION_MIRRED_INGRESS;
entry->dev = tcf_mirred_dev(act); tcf_mirred_get_dev(entry, act);
if (entry->dev)
dev_hold(entry->dev);
} else if (is_tcf_vlan(act)) { } else if (is_tcf_vlan(act)) {
switch (tcf_vlan_action(act)) { switch (tcf_vlan_action(act)) {
case TCA_VLAN_ACT_PUSH: case TCA_VLAN_ACT_PUSH:
...@@ -3370,11 +3388,9 @@ int tc_setup_flow_action(struct flow_action *flow_action, ...@@ -3370,11 +3388,9 @@ int tc_setup_flow_action(struct flow_action *flow_action,
} }
} else if (is_tcf_tunnel_set(act)) { } else if (is_tcf_tunnel_set(act)) {
entry->id = FLOW_ACTION_TUNNEL_ENCAP; entry->id = FLOW_ACTION_TUNNEL_ENCAP;
entry->tunnel = tcf_tunnel_info_copy(act); err = tcf_tunnel_encap_get_tunnel(entry, act);
if (!entry->tunnel) { if (err)
err = -ENOMEM;
goto err_out; goto err_out;
}
} else if (is_tcf_tunnel_release(act)) { } else if (is_tcf_tunnel_release(act)) {
entry->id = FLOW_ACTION_TUNNEL_DECAP; entry->id = FLOW_ACTION_TUNNEL_DECAP;
} else if (is_tcf_pedit(act)) { } else if (is_tcf_pedit(act)) {
...@@ -3404,11 +3420,10 @@ int tc_setup_flow_action(struct flow_action *flow_action, ...@@ -3404,11 +3420,10 @@ int tc_setup_flow_action(struct flow_action *flow_action,
entry->mark = tcf_skbedit_mark(act); entry->mark = tcf_skbedit_mark(act);
} else if (is_tcf_sample(act)) { } else if (is_tcf_sample(act)) {
entry->id = FLOW_ACTION_SAMPLE; entry->id = FLOW_ACTION_SAMPLE;
entry->sample.psample_group =
tcf_sample_psample_group(act);
entry->sample.trunc_size = tcf_sample_trunc_size(act); entry->sample.trunc_size = tcf_sample_trunc_size(act);
entry->sample.truncate = tcf_sample_truncate(act); entry->sample.truncate = tcf_sample_truncate(act);
entry->sample.rate = tcf_sample_rate(act); entry->sample.rate = tcf_sample_rate(act);
tcf_sample_get_group(entry, act);
} else if (is_tcf_police(act)) { } else if (is_tcf_police(act)) {
entry->id = FLOW_ACTION_POLICE; entry->id = FLOW_ACTION_POLICE;
entry->police.burst = tcf_police_tcfp_burst(act); entry->police.burst = tcf_police_tcfp_burst(act);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment