Re: [Patch net-next] net_sched: switch to rcu_work

2018-05-24 Thread David Miller
From: Cong Wang 
Date: Wed, 23 May 2018 15:26:53 -0700

> Commit 05f0fe6b74db ("RCU, workqueue: Implement rcu_work") introduces
> new API's for dispatching work in a RCU callback. Now we can just
> switch to the new API's for tc filters. This could get rid of a lot
> of code.
> 
> Signed-off-by: Cong Wang 

Applied, thanks.


[Patch net-next] net_sched: switch to rcu_work

2018-05-23 Thread Cong Wang
Commit 05f0fe6b74db ("RCU, workqueue: Implement rcu_work") introduces
new API's for dispatching work in a RCU callback. Now we can just
switch to the new API's for tc filters. This could get rid of a lot
of code.

Cc: Tejun Heo 
Cc: "Paul E. McKenney" 
Cc: Jamal Hadi Salim 
Signed-off-by: Cong Wang 
---
 include/net/pkt_cls.h|  2 +-
 net/sched/cls_api.c  |  5 +++--
 net/sched/cls_basic.c| 24 +++-
 net/sched/cls_bpf.c  | 22 ++
 net/sched/cls_cgroup.c   | 23 +--
 net/sched/cls_flow.c | 24 +++-
 net/sched/cls_flower.c   | 40 ++--
 net/sched/cls_fw.c   | 24 +++-
 net/sched/cls_matchall.c | 21 +
 net/sched/cls_route.c| 23 +--
 net/sched/cls_rsvp.h | 20 +---
 net/sched/cls_tcindex.c  | 41 ++---
 net/sched/cls_u32.c  | 37 ++---
 13 files changed, 85 insertions(+), 221 deletions(-)

diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index 0005f0b40fe9..f3ec43725724 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -33,7 +33,7 @@ struct tcf_block_ext_info {
 };
 
 struct tcf_block_cb;
-bool tcf_queue_work(struct work_struct *work);
+bool tcf_queue_work(struct rcu_work *rwork, work_func_t func);
 
 #ifdef CONFIG_NET_CLS
 struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 963e4bf0aab8..a4a5ace834c3 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -103,9 +103,10 @@ int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
 }
 EXPORT_SYMBOL(unregister_tcf_proto_ops);
 
-bool tcf_queue_work(struct work_struct *work)
+bool tcf_queue_work(struct rcu_work *rwork, work_func_t func)
 {
-   return queue_work(tc_filter_wq, work);
+   INIT_RCU_WORK(rwork, func);
+   return queue_rcu_work(tc_filter_wq, rwork);
 }
 EXPORT_SYMBOL(tcf_queue_work);
 
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c
index 6b7ab3512f5b..95367f37098d 100644
--- a/net/sched/cls_basic.c
+++ b/net/sched/cls_basic.c
@@ -35,10 +35,7 @@ struct basic_filter {
struct tcf_result   res;
struct tcf_proto*tp;
struct list_headlink;
-   union {
-   struct work_struct  work;
-   struct rcu_head rcu;
-   };
+   struct rcu_work rwork;
 };
 
 static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
@@ -97,21 +94,14 @@ static void __basic_delete_filter(struct basic_filter *f)
 
 static void basic_delete_filter_work(struct work_struct *work)
 {
-   struct basic_filter *f = container_of(work, struct basic_filter, work);
-
+   struct basic_filter *f = container_of(to_rcu_work(work),
+ struct basic_filter,
+ rwork);
rtnl_lock();
__basic_delete_filter(f);
rtnl_unlock();
 }
 
-static void basic_delete_filter(struct rcu_head *head)
-{
-   struct basic_filter *f = container_of(head, struct basic_filter, rcu);
-
-   INIT_WORK(&f->work, basic_delete_filter_work);
-   tcf_queue_work(&f->work);
-}
-
 static void basic_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack)
 {
struct basic_head *head = rtnl_dereference(tp->root);
@@ -122,7 +112,7 @@ static void basic_destroy(struct tcf_proto *tp, struct 
netlink_ext_ack *extack)
tcf_unbind_filter(tp, &f->res);
idr_remove(&head->handle_idr, f->handle);
if (tcf_exts_get_net(&f->exts))
-   call_rcu(&f->rcu, basic_delete_filter);
+   tcf_queue_work(&f->rwork, basic_delete_filter_work);
else
__basic_delete_filter(f);
}
@@ -140,7 +130,7 @@ static int basic_delete(struct tcf_proto *tp, void *arg, 
bool *last,
tcf_unbind_filter(tp, &f->res);
idr_remove(&head->handle_idr, f->handle);
tcf_exts_get_net(&f->exts);
-   call_rcu(&f->rcu, basic_delete_filter);
+   tcf_queue_work(&f->rwork, basic_delete_filter_work);
*last = list_empty(&head->flist);
return 0;
 }
@@ -234,7 +224,7 @@ static int basic_change(struct net *net, struct sk_buff 
*in_skb,
list_replace_rcu(&fold->link, &fnew->link);
tcf_unbind_filter(tp, &fold->res);
tcf_exts_get_net(&fold->exts);
-   call_rcu(&fold->rcu, basic_delete_filter);
+   tcf_queue_work(&fold->rwork, basic_delete_filter_work);
} else {
list_add_rcu(&fnew->link, &head->flist);
}
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index b07c1fa8bc0d..1aa7f6511065 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -49,10 +49,7 @@ struc