net: openvswitch: improve codes
Subsystems (3)
v3 cover net: openvswitch: improve codes
From: Tonghao Zhang <[email protected]>
This series patches are not bug fix, just improve codes.
Tonghao Zhang (3):
net: openvswitch: improve coding style
net: openvswitch: refactor flow free function
net: openvswitch: remove unnused keep_flows
net/openvswitch/actions.c | 5 +-- net/openvswitch/datapath.c | 35 +++++++++++-------- net/openvswitch/flow_table.c | 68 +++++++++++++++++------------------- net/openvswitch/flow_table.h | 1 - net/openvswitch/vport.c | 7 ++-- 5 files changed, 60 insertions(+), 56 deletions(-)
Signature · 1 line
2.23.0
PATCH v3 1/3 net: openvswitch: improve coding style
From: Tonghao Zhang <[email protected]>
Not change the logic, just improve coding style.
--- net/openvswitch/actions.c | 5 ++-- net/openvswitch/datapath.c | 35 ++++++++++++++++------------ net/openvswitch/flow_table.c | 44 ++++++++++++++++++++---------------- net/openvswitch/vport.c | 7 +++--- 4 files changed, 51 insertions(+), 40 deletions(-)
net/openvswitch/actions.c +3 -2
@@ -742,7 +742,8 @@ static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key,return 0 ; } -static int ovs_vport_output (struct net *net,struct sock *sk,struct sk_buff *skb) +static int ovs_vport_output (struct net *net,struct sock *sk, +struct sk_buff *skb) {struct ovs_frag_data *data =this_cpu_ptr (&ovs_frag_data_storage);struct vport *vport = data->vport;
@@ -925,7 +926,7 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb, upcall.mru =OVS_CB (skb)->mru;for (a =nla_data (attr), rem =nla_len (attr); rem >0 ; - a =nla_next (a, &rem)) { + a =nla_next (a, &rem)) {switch (nla_type (a)) {case OVS_USERSPACE_ATTR_USERDATA : upcall.userdata = a;
net/openvswitch/datapath.c +20 -15
@@ -182,7 +182,7 @@ struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no) head =vport_hash_bucket (dp, port_no);hlist_for_each_entry_rcu (vport, head, dp_hash_node, -lockdep_ovsl_is_held ()) { +lockdep_ovsl_is_held ()) {if (vport->port_no == port_no)return vport; }
@@ -254,7 +254,7 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key) error =ovs_execute_actions (dp, skb, sf_acts, key);if (unlikely (error))net_dbg_ratelimited ("ovs: action execution error on datapath %s: %d\n" , -ovs_dp_name (dp), error); +ovs_dp_name (dp), error); stats_counter = &stats->n_hit;
@@ -302,7 +302,7 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,static int queue_gso_packets (struct datapath *dp,struct sk_buff *skb,const struct sw_flow_key *key,const struct dp_upcall_info *upcall_info, -uint32_t cutlen) +uint32_t cutlen) {unsigned int gso_type =skb_shinfo (skb)->gso_type;struct sw_flow_key later_key;
@@ -1080,11 +1080,12 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info) }/* Factor out action copy to avoid "Wframe-larger-than=1024" warning. */ -static noinline_for_stack struct sw_flow_actions *get_flow_actions(struct net *net, -const struct nlattr *a, -const struct sw_flow_key *key, -const struct sw_flow_mask *mask, -bool log) +static noinline_for_stack +struct sw_flow_actions *get_flow_actions(struct net *net, +const struct nlattr *a, +const struct sw_flow_key *key, +const struct sw_flow_mask *mask, +bool log) {struct sw_flow_actions *acts;struct sw_flow_key masked_key;
@@ -1383,7 +1384,8 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)ovs_notify (&dp_flow_genl_family, reply, info); }else { -netlink_set_err (sock_net (skb->sk)->genl_sock,0 ,0 ,PTR_ERR (reply)); +netlink_set_err (sock_net (skb->sk)->genl_sock,0 ,0 , +PTR_ERR (reply)); } }
@@ -1513,7 +1515,7 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,int err; ovs_header =genlmsg_put (skb, portid, seq, &dp_datapath_genl_family, - flags, cmd); + flags, cmd);if (!ovs_header) goto error;
@@ -1572,11 +1574,13 @@ static struct datapath *lookup_datapath(struct net *net,return dp ? dp :ERR_PTR (-ENODEV ); } -static void ovs_dp_reset_user_features (struct sk_buff *skb,struct genl_info *info) +static void ovs_dp_reset_user_features (struct sk_buff *skb, +struct genl_info *info) {struct datapath *dp; - dp =lookup_datapath (sock_net (skb->sk), info->userhdr, info->attrs); + dp =lookup_datapath (sock_net (skb->sk), info->userhdr, + info->attrs);if (IS_ERR (dp))return ;
@@ -2075,7 +2079,7 @@ static unsigned int ovs_get_max_headroom(struct datapath *dp)for (i =0 ; i <DP_VPORT_HASH_BUCKETS ; i++) {hlist_for_each_entry_rcu (vport, &dp->ports[i], dp_hash_node, -lockdep_ovsl_is_held ()) { +lockdep_ovsl_is_held ()) { dev = vport->dev; dev_headroom =netdev_get_fwd_headroom (dev);if (dev_headroom > max_headroom)
@@ -2095,7 +2099,7 @@ static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) dp->max_headroom = new_headroom;for (i =0 ; i <DP_VPORT_HASH_BUCKETS ; i++)hlist_for_each_entry_rcu (vport, &dp->ports[i], dp_hash_node, -lockdep_ovsl_is_held ()) +lockdep_ovsl_is_held ())netdev_set_rx_headroom (vport->dev, new_headroom); }
@@ -2551,7 +2555,8 @@ static int __init dp_init(void) {int err; - BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > sizeof_field(struct sk_buff, cb)); +BUILD_BUG_ON (sizeof (struct ovs_skb_cb ) > + sizeof_field(struct sk_buff, cb));pr_info ("Open vSwitch switching datapath\n" );
net/openvswitch/flow_table.c +24 -20
131 lines not on this page · raw message
net/openvswitch/vport.c +4 -3
@@ -98,7 +98,7 @@ struct vport *ovs_vport_locate(const struct net *net, const char *name)struct vport *vport;hlist_for_each_entry_rcu (vport, bucket, hash_node, -lockdep_ovsl_is_held ()) +lockdep_ovsl_is_held ())if (!strcmp (name,ovs_vport_name (vport)) &&net_eq (ovs_dp_get_net (vport->dp), net))return vport;
@@ -118,7 +118,7 @@ struct vport *ovs_vport_locate(const struct net *net, const char *name)* vport_free(). */ struct vport *ovs_vport_alloc (int priv_size,const struct vport_ops *ops, -const struct vport_parms *parms) +const struct vport_parms *parms) {struct vport *vport;size_t alloc_size;
@@ -397,7 +397,8 @@ int ovs_vport_get_upcall_portids(const struct vport *vport,* * Returns the portid of the target socket. Must be called with rcu_read_lock. */ -u32 ovs_vport_find_upcall_portid (const struct vport *vport,struct sk_buff *skb) +u32 ovs_vport_find_upcall_portid (const struct vport *vport, +struct sk_buff *skb) {struct vport_portids *ids;u32 ids_index;
Signature · 1 line
2.23.0
Re: [PATCH net-next v3 1/3] net: openvswitch: improve coding style
net/openvswitch/datapath.c static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) · line 2100
Quoted 7 lines · On Tue, 25 Aug 2020 13:06:34 +0800 [email protected] wrote:
+++
b/net/openvswitch/datapath.c[...]
net/openvswitch/datapath.c +0
-0@@ -2095,7 +2099,7 @@ static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) dp->max_headroom = new_headroom;for (i =0 ; i <DP_VPORT_HASH_BUCKETS ; i++)
While at it, you could also add curly brackets here.
Quoted 5 lines
net/openvswitch/flow_table.c +1
-0+++ b/net/openvswitch/flow_table.c
net/openvswitch/flow_table.c static void flow_free(struct sw_flow *flow) · line 118
Quoted 10 lines
net/openvswitch/flow_table.c +4
-2@@ -111,9 +111,11 @@ static void flow_free(struct sw_flow *flow)if (ovs_identifier_is_key (&flow->id))kfree (flow->id.unmasked_key);if (flow->sf_acts) -ovs_nla_free_flow_actions ((struct sw_flow_actions __force *)flow->sf_acts); +ovs_nla_free_flow_actions ((struct sw_flow_actions __force *) + flow->sf_acts);/* We open code this to make sure cpu 0 is always considered */ -for (cpu =0 ; cpu < nr_cpu_ids; cpu =cpumask_next (cpu, &flow->cpu_used_mask)) +for (cpu =0 ; cpu < nr_cpu_ids; + cpu =cpumask_next (cpu, &flow->cpu_used_mask))
...and here.
net/openvswitch/flow_table.c static int tbl_mask_array_add_mask(struct flow_table *tbl, · line 278
Quoted 6 lines
net/openvswitch/flow_table.c +1
-1@@ -273,7 +275,7 @@ static int tbl_mask_array_add_mask(struct flow_table *tbl,if (ma_count >= ma->max) { err =tbl_mask_array_realloc (tbl, ma->max + -MASK_ARRAY_SIZE_MIN ); +MASK_ARRAY_SIZE_MIN );
This is not aligned properly either, MASK_ARRAY_SIZE_MIN is added to ma->max and should be aligned to it.
net/openvswitch/flow_table.c int ovs_flow_tbl_init(struct flow_table *table) · line 454
Quoted 7 lines
net/openvswitch/flow_table.c +2
-1@@ -448,16 +450,17 @@ int ovs_flow_tbl_init(struct flow_table *table)static void flow_tbl_destroy_rcu_cb (struct rcu_head *rcu) { - struct table_instance *ti = container_of(rcu, struct table_instance, rcu); +struct table_instance *ti = + container_of(rcu, struct table_instance, rcu);
The assignment could very well go on a separate line.
Signature · 1 line
Stefano
Re: [PATCH net-next v3 1/3] net: openvswitch: improve coding style
Quoted 44 lines · Stefano Brivio
net/openvswitch/datapath.c static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) · line 2100
Quoted 7 lines · On Tue, 25 Aug 2020 13:06:34 +0800 [email protected] wrote:
+++
b/net/openvswitch/datapath.c[...]
net/openvswitch/datapath.c +0
-0@@ -2095,7 +2099,7 @@ static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) dp->max_headroom = new_headroom;for (i =0 ; i <DP_VPORT_HASH_BUCKETS ; i++)While at it, you could also add curly brackets here.
Quoted 5 lines
net/openvswitch/flow_table.c +1
-0+++ b/net/openvswitch/flow_table.cnet/openvswitch/flow_table.c static void flow_free(struct sw_flow *flow) · line 118
Quoted 10 lines
net/openvswitch/flow_table.c +4
-2@@ -111,9 +111,11 @@ static void flow_free(struct sw_flow *flow)if (ovs_identifier_is_key (&flow->id))kfree (flow->id.unmasked_key);if (flow->sf_acts) -ovs_nla_free_flow_actions ((struct sw_flow_actions __force *)flow->sf_acts); +ovs_nla_free_flow_actions ((struct sw_flow_actions __force *) + flow->sf_acts);/* We open code this to make sure cpu 0 is always considered */ -for (cpu =0 ; cpu < nr_cpu_ids; cpu =cpumask_next (cpu, &flow->cpu_used_mask)) +for (cpu =0 ; cpu < nr_cpu_ids; + cpu =cpumask_next (cpu, &flow->cpu_used_mask))...and here.
net/openvswitch/flow_table.c static int tbl_mask_array_add_mask(struct flow_table *tbl, · line 278
Quoted 6 lines
net/openvswitch/flow_table.c +1
-1@@ -273,7 +275,7 @@ static int tbl_mask_array_add_mask(struct flow_table *tbl,if (ma_count >= ma->max) { err =tbl_mask_array_realloc (tbl, ma->max + -MASK_ARRAY_SIZE_MIN ); +MASK_ARRAY_SIZE_MIN );This is not aligned properly either,
MASK_ARRAY_SIZE_MINis added toma->maxand should be aligned to it.Quoted 2 lines
(quoted diff) +0
-0@@ -448,16 +450,17 @@ int ovs_flow_tbl_init(struct flow_table *table)
Quoted 7 lines
net/openvswitch/flow_table.c int ovs_flow_tbl_init(struct flow_table *table) · line 454
Quoted 5 lines
net/openvswitch/flow_table.c +2
-1static void flow_tbl_destroy_rcu_cb (struct rcu_head *rcu) { - struct table_instance *ti = container_of(rcu, struct table_instance, rcu); +struct table_instance *ti = + container_of(rcu, struct table_instance, rcu);The assignment could very well go on a separate line.
Hi Stefano
Sorry for missing the comment. I update the patch in v4. Thanks.
Quoted 3 lines
--
Stefano
Signature · 1 line
Best regards, Tonghao
PATCH v3 2/3 net: openvswitch: refactor flow free function
In reply to [email protected]From: Tonghao Zhang <[email protected]>
Decrease table->count and ufid_count unconditionally, because we only don't use count or ufid_count to count when flushing the flows. To simplify the codes, we remove the "count" argument of table_instance_flow_free.
To avoid a bug when deleting flows in the future, add WARN_ON in flush flows function.
---
v3:
use WARN_ON instead of BUG_ON
v2:
add more details why refactor this function.
--- net/openvswitch/flow_table.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
net/openvswitch/flow_table.c +11 -11
@@ -459,18 +459,14 @@ static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu)static void table_instance_flow_free (struct flow_table *table,struct table_instance *ti,struct table_instance *ufid_ti, -struct sw_flow *flow, -bool count) +struct sw_flow *flow) {hlist_del_rcu (&flow->flow_table.node[ti->node_ver]); -if (count) - table->count--; + table->count--;if (ovs_identifier_is_ufid (&flow->id)) {hlist_del_rcu (&flow->ufid_table.node[ufid_ti->node_ver]); - -if (count) - table->ufid_count--; + table->ufid_count--; }flow_mask_remove (table, flow->mask);
@@ -495,10 +491,16 @@ void table_instance_flow_flush(struct flow_table *table, flow_table.node[ti->node_ver]) {table_instance_flow_free (table, ti, ufid_ti, - flow, false); + flow);ovs_flow_free (flow, true); } } + +if (WARN_ON (table->count !=0 || + table->ufid_count !=0 )) { + table->count =0 ; + table->ufid_count =0 ; + } } static void table_instance_destroy(struct table_instance *ti,
@@ -635,8 +637,6 @@ int ovs_flow_tbl_flush(struct flow_table *flow_table)rcu_assign_pointer (flow_table->ti, new_ti);rcu_assign_pointer (flow_table->ufid_ti, new_ufid_ti); flow_table->last_rehash = jiffies; - flow_table->count =0 ; - flow_table->ufid_count =0 ;table_instance_flow_flush (flow_table, old_ti, old_ufid_ti);table_instance_destroy (old_ti, old_ufid_ti);
@@ -954,7 +954,7 @@ void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow)struct table_instance *ufid_ti =ovsl_dereference (table->ufid_ti);BUG_ON (table->count ==0 ); -table_instance_flow_free (table, ti, ufid_ti, flow, true); +table_instance_flow_free (table, ti, ufid_ti, flow); }static struct sw_flow_mask *mask_alloc (void )
Signature · 1 line
2.23.0
Re: [PATCH net-next v3 2/3] net: openvswitch: refactor flow free function
Quoted 8 lines · On Mon, Aug 24, 2020 at 10:08 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
Decrease
table->countandufid_countunconditionally, because we only don't use count orufid_countto count when flushing the flows. To simplify the codes, we remove the "count" argument oftable_instance_flow_free.
Quoted 5 lines
To avoid a bug when deleting flows in the future, add
WARN_ONin flush flows function.Cc Pravin B Shelar <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>
Looks good.
PATCH v3 3/3 net: openvswitch: remove unnused keep_flows
In reply to [email protected]From: Tonghao Zhang <[email protected]>
keep_flows was introduced by [1], which used as flag to delete flows or not. When rehashing or expanding the table instance, we will not flush the flows. Now don't use it anymore, remove it.
[1] - https://github.com/openvswitch/ovs/commit/acd051f1761569205827dc9b037e15568a8d59f8
--- net/openvswitch/flow_table.c | 6 ------ net/openvswitch/flow_table.h | 1 - 2 files changed, 7 deletions(-)
net/openvswitch/flow_table.c +0 -6
@@ -166,7 +166,6 @@ static struct table_instance *table_instance_alloc(int new_size) ti->n_buckets = new_size; ti->node_ver =0 ; - ti->keep_flows = false;get_random_bytes (&ti->hash_seed,sizeof (u32));return ti;
@@ -479,9 +478,6 @@ void table_instance_flow_flush(struct flow_table *table, {int i; -if (ti->keep_flows) -return ; -for (i =0 ; i < ti->n_buckets; i++) {struct hlist_head *head = &ti->buckets[i];struct hlist_node *n;
@@ -601,8 +597,6 @@ static void flow_table_copy_flows(struct table_instance *old, lockdep_ovsl_is_held())table_instance_insert (new, flow); } - - old->keep_flows = true; } static struct table_instance *table_instance_rehash(struct table_instance *ti,
net/openvswitch/flow_table.h +0 -1
@@ -53,7 +53,6 @@ struct table_instance {struct rcu_head rcu;int node_ver;u32 hash_seed; -bool keep_flows; };struct flow_table {
Signature · 1 line
2.23.0
Re: [PATCH net-next v3 3/3] net: openvswitch: remove unnused keep_flows
Quoted 10 lines · On Mon, Aug 24, 2020 at 10:08 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
keep_flowswas introduced by [1], which used as flag to delete flows or not. When rehashing or expanding the table instance, we will not flush the flows. Now don't use it anymore, remove it.[1] - https://github.com/openvswitch/ovs/commit/acd051f1761569205827dc9b037e15568a8d59f8
Cc Pravin B Shelar <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>
This patch looks good. But its fixing memory leak, I guess the patch that removed dependedcy on keep_flows is in net-next. so we are good.
David Miller
maintainerFrom: [email protected]
Date: Tue, 25 Aug 2020 13:06:33 +0800
Quoted 3 lines
From: Tonghao Zhang <[email protected]>
This series patches are not bug fix, just improve codes.
Pravin, please review this patch series.
Thank you.
Quoted 10 lines · David Miller
From: [email protected]
Date: Tue, 25 Aug 2020 13:06:33 +0800Quoted 3 lines
From: Tonghao Zhang <[email protected]>
This series patches are not bug fix, just improve codes.
Pravin, please review this patch series.
Sorry for delay. I will have a look tomorrow morning PST.