Re: [PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-08 Thread Manish Kurup
Hi Dave,

On Wed, Nov 8, 2017 at 6:40 AM, Manish Kurup  wrote:
> Hi Dave,
>
> On Tue, Nov 7, 2017 at 7:07 PM, David Miller  wrote:
>>
>> From: Alexander Duyck 
>> Date: Tue, 7 Nov 2017 08:54:20 -0800
>>
>> > Are we really going to be so strict about the reverse xmas-tree that
>> > we won't allow for assignment w/ variable declaration because the
>> > dependency order won't fit into that format?
>>
>> Yes.
>>
>> > Last I knew this kind of setup was an exception to the reverse
>> > xmas-tree layout requirement because in this case 'p' relies on 'v' so
>> > we can't reorder these without having to kick the assignment of 'p'
>> > off onto a line by itself.
>>
>> Please just declare the variable naked without the assignment and do
>> the assignment down in the code.
>
> I have a changeset that I had made to incorporate the reverse xmas tree,
> doing the very thing you talk about, above.
> The only reason I didnt not send it out because it made more than minimal
> changes, especially how the 'opt' struct is defined.
>
> I will make the changes and send the review around once more.
>
> Thanks,
>
I have made the required changes, and sent the review around once more
(v10). Please let me know if this looks OK.

Thanks!

-Manish


Fwd: [PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-08 Thread Manish Kurup
Hi Dave,

On Tue, Nov 7, 2017 at 7:07 PM, David Miller  wrote:
>
> From: Alexander Duyck 
> Date: Tue, 7 Nov 2017 08:54:20 -0800
>
> > Are we really going to be so strict about the reverse xmas-tree that
> > we won't allow for assignment w/ variable declaration because the
> > dependency order won't fit into that format?
>
> Yes.
>
> > Last I knew this kind of setup was an exception to the reverse
> > xmas-tree layout requirement because in this case 'p' relies on 'v' so
> > we can't reorder these without having to kick the assignment of 'p'
> > off onto a line by itself.
>
> Please just declare the variable naked without the assignment and do
> the assignment down in the code.

I have a changeset that I had made to incorporate the reverse xmas
tree, doing the very thing you talk about, above.
The only reason I didnt not send it out because it made more than
minimal changes, especially how the 'opt' struct is defined.

I will make the changes and send the review around once more.

Thanks,


Re: [PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-07 Thread David Miller
From: Alexander Duyck 
Date: Tue, 7 Nov 2017 08:54:20 -0800

> Are we really going to be so strict about the reverse xmas-tree that
> we won't allow for assignment w/ variable declaration because the
> dependency order won't fit into that format?

Yes.

> Last I knew this kind of setup was an exception to the reverse
> xmas-tree layout requirement because in this case 'p' relies on 'v' so
> we can't reorder these without having to kick the assignment of 'p'
> off onto a line by itself.

Please just declare the variable naked without the assignment and do
the assignment down in the code.


Re: [PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-07 Thread Pieter Jansen van Vuuren
On Tue, 7 Nov 2017 08:54:20 -0800
Alexander Duyck  wrote:

> On Mon, Nov 6, 2017 at 10:37 AM, Pieter Jansen van Vuuren
>  wrote:
> > On Fri,  3 Nov 2017 11:50:47 -0400
> > Manish Kurup  wrote:
> >  
> >> Using a spinlock in the VLAN action causes performance issues when
> >> the VLAN action is used on multiple cores. Rewrote the VLAN action to
> >> use RCU read locking for reads and updates instead.
> >>
> >> Acked-by: Jamal Hadi Salim 
> >> Acked-by: Jiri Pirko 
> >> Signed-off-by: Manish Kurup 
> >> ---
> >>  include/net/tc_act/tc_vlan.h | 46 +--
> >>  net/sched/act_vlan.c | 75
> >> ++-- 2 files changed, 88
> >> insertions(+), 33 deletions(-)  
> > ...  
> >>
> >> +static void tcf_vlan_cleanup(struct tc_action *a, int bind)
> >> +{
> >> + struct tcf_vlan *v = to_vlan(a);
> >> + struct tcf_vlan_params *p;
> >> +
> >> + p = rcu_dereference_protected(v->vlan_p, 1);
> >> + kfree_rcu(p, rcu);
> >> +}
> >> +
> >>  static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
> >>int bind, int ref)
> >>  {
> >>   unsigned char *b = skb_tail_pointer(skb);
> >>   struct tcf_vlan *v = to_vlan(a);
> >> + struct tcf_vlan_params *p = rtnl_dereference(v->vlan_p);  
> > nack. This fails reverse xmas-tree.  
> 
> Are we really going to be so strict about the reverse xmas-tree that
> we won't allow for assignment w/ variable declaration because the
> dependency order won't fit into that format?
Okay, I think that is a fair point. I would be okay by making an exception
for this.
> 
> Last I knew this kind of setup was an exception to the reverse
> xmas-tree layout requirement because in this case 'p' relies on 'v' so
> we can't reorder these without having to kick the assignment of 'p'
> off onto a line by itself.
I was actually not aware of this, thank you for pointing it out. It does
make sense.
> 
> - Alex



Re: [PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-07 Thread Alexander Duyck
On Mon, Nov 6, 2017 at 10:37 AM, Pieter Jansen van Vuuren
 wrote:
> On Fri,  3 Nov 2017 11:50:47 -0400
> Manish Kurup  wrote:
>
>> Using a spinlock in the VLAN action causes performance issues when the VLAN
>> action is used on multiple cores. Rewrote the VLAN action to use RCU read
>> locking for reads and updates instead.
>>
>> Acked-by: Jamal Hadi Salim 
>> Acked-by: Jiri Pirko 
>> Signed-off-by: Manish Kurup 
>> ---
>>  include/net/tc_act/tc_vlan.h | 46 +--
>>  net/sched/act_vlan.c | 75
>> ++-- 2 files changed, 88
>> insertions(+), 33 deletions(-)
> ...
>>
>> +static void tcf_vlan_cleanup(struct tc_action *a, int bind)
>> +{
>> + struct tcf_vlan *v = to_vlan(a);
>> + struct tcf_vlan_params *p;
>> +
>> + p = rcu_dereference_protected(v->vlan_p, 1);
>> + kfree_rcu(p, rcu);
>> +}
>> +
>>  static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
>>int bind, int ref)
>>  {
>>   unsigned char *b = skb_tail_pointer(skb);
>>   struct tcf_vlan *v = to_vlan(a);
>> + struct tcf_vlan_params *p = rtnl_dereference(v->vlan_p);
> nack. This fails reverse xmas-tree.

Are we really going to be so strict about the reverse xmas-tree that
we won't allow for assignment w/ variable declaration because the
dependency order won't fit into that format?

Last I knew this kind of setup was an exception to the reverse
xmas-tree layout requirement because in this case 'p' relies on 'v' so
we can't reorder these without having to kick the assignment of 'p'
off onto a line by itself.

- Alex


Re: [PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-06 Thread Pieter Jansen van Vuuren
On Fri,  3 Nov 2017 11:50:47 -0400
Manish Kurup  wrote:

> Using a spinlock in the VLAN action causes performance issues when the VLAN
> action is used on multiple cores. Rewrote the VLAN action to use RCU read
> locking for reads and updates instead.
> 
> Acked-by: Jamal Hadi Salim 
> Acked-by: Jiri Pirko 
> Signed-off-by: Manish Kurup 
> ---
>  include/net/tc_act/tc_vlan.h | 46 +--
>  net/sched/act_vlan.c | 75
> ++-- 2 files changed, 88
> insertions(+), 33 deletions(-)
...
>  
> +static void tcf_vlan_cleanup(struct tc_action *a, int bind)
> +{
> + struct tcf_vlan *v = to_vlan(a);
> + struct tcf_vlan_params *p;
> +
> + p = rcu_dereference_protected(v->vlan_p, 1);
> + kfree_rcu(p, rcu);
> +}
> +
>  static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
>int bind, int ref)
>  {
>   unsigned char *b = skb_tail_pointer(skb);
>   struct tcf_vlan *v = to_vlan(a);
> + struct tcf_vlan_params *p = rtnl_dereference(v->vlan_p);
nack. This fails reverse xmas-tree.


[PATCH net-next v6 3/3] act_vlan: VLAN action rewrite to use RCU lock/unlock and update

2017-11-03 Thread Manish Kurup
Using a spinlock in the VLAN action causes performance issues when the VLAN
action is used on multiple cores. Rewrote the VLAN action to use RCU read
locking for reads and updates instead.

Acked-by: Jamal Hadi Salim 
Acked-by: Jiri Pirko 
Signed-off-by: Manish Kurup 
---
 include/net/tc_act/tc_vlan.h | 46 +--
 net/sched/act_vlan.c | 75 ++--
 2 files changed, 88 insertions(+), 33 deletions(-)

diff --git a/include/net/tc_act/tc_vlan.h b/include/net/tc_act/tc_vlan.h
index c2090df..22ae260 100644
--- a/include/net/tc_act/tc_vlan.h
+++ b/include/net/tc_act/tc_vlan.h
@@ -13,12 +13,17 @@
 #include 
 #include 
 
+struct tcf_vlan_params {
+   int   tcfv_action;
+   u16   tcfv_push_vid;
+   __be16tcfv_push_proto;
+   u8tcfv_push_prio;
+   struct rcu_head   rcu;
+};
+
 struct tcf_vlan {
struct tc_actioncommon;
-   int tcfv_action;
-   u16 tcfv_push_vid;
-   __be16  tcfv_push_proto;
-   u8  tcfv_push_prio;
+   struct tcf_vlan_params __rcu *vlan_p;
 };
 #define to_vlan(a) ((struct tcf_vlan *)a)
 
@@ -33,22 +38,45 @@ static inline bool is_tcf_vlan(const struct tc_action *a)
 
 static inline u32 tcf_vlan_action(const struct tc_action *a)
 {
-   return to_vlan(a)->tcfv_action;
+   u32 tcfv_action;
+
+   rcu_read_lock();
+   tcfv_action = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_action;
+   rcu_read_unlock();
+
+   return tcfv_action;
 }
 
 static inline u16 tcf_vlan_push_vid(const struct tc_action *a)
 {
-   return to_vlan(a)->tcfv_push_vid;
+   u16 tcfv_push_vid;
+
+   rcu_read_lock();
+   tcfv_push_vid = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_vid;
+   rcu_read_unlock();
+
+   return tcfv_push_vid;
 }
 
 static inline __be16 tcf_vlan_push_proto(const struct tc_action *a)
 {
-   return to_vlan(a)->tcfv_push_proto;
+   __be16 tcfv_push_proto;
+
+   rcu_read_lock();
+   tcfv_push_proto = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_proto;
+   rcu_read_unlock();
+
+   return tcfv_push_proto;
 }
 
 static inline u8 tcf_vlan_push_prio(const struct tc_action *a)
 {
-   return to_vlan(a)->tcfv_push_prio;
-}
+   u8 tcfv_push_prio;
 
+   rcu_read_lock();
+   tcfv_push_prio = rcu_dereference(to_vlan(a)->vlan_p)->tcfv_push_prio;
+   rcu_read_unlock();
+
+   return tcfv_push_prio;
+}
 #endif /* __NET_TC_VLAN_H */
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index b093bad..97f717a 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -26,6 +26,7 @@ static int tcf_vlan(struct sk_buff *skb, const struct 
tc_action *a,
struct tcf_result *res)
 {
struct tcf_vlan *v = to_vlan(a);
+   struct tcf_vlan_params *p;
int action;
int err;
u16 tci;
@@ -33,24 +34,27 @@ static int tcf_vlan(struct sk_buff *skb, const struct 
tc_action *a,
tcf_lastuse_update(>tcf_tm);
bstats_cpu_update(this_cpu_ptr(v->common.cpu_bstats), skb);
 
-   spin_lock(>tcf_lock);
-   action = v->tcf_action;
-
/* Ensure 'data' points at mac_header prior calling vlan manipulating
 * functions.
 */
if (skb_at_tc_ingress(skb))
skb_push_rcsum(skb, skb->mac_len);
 
-   switch (v->tcfv_action) {
+   rcu_read_lock();
+
+   action = READ_ONCE(v->tcf_action);
+
+   p = rcu_dereference(v->vlan_p);
+
+   switch (p->tcfv_action) {
case TCA_VLAN_ACT_POP:
err = skb_vlan_pop(skb);
if (err)
goto drop;
break;
case TCA_VLAN_ACT_PUSH:
-   err = skb_vlan_push(skb, v->tcfv_push_proto, v->tcfv_push_vid |
-   (v->tcfv_push_prio << VLAN_PRIO_SHIFT));
+   err = skb_vlan_push(skb, p->tcfv_push_proto, p->tcfv_push_vid |
+   (p->tcfv_push_prio << VLAN_PRIO_SHIFT));
if (err)
goto drop;
break;
@@ -69,14 +73,14 @@ static int tcf_vlan(struct sk_buff *skb, const struct 
tc_action *a,
goto drop;
}
/* replace the vid */
-   tci = (tci & ~VLAN_VID_MASK) | v->tcfv_push_vid;
+   tci = (tci & ~VLAN_VID_MASK) | p->tcfv_push_vid;
/* replace prio bits, if tcfv_push_prio specified */
-   if (v->tcfv_push_prio) {
+   if (p->tcfv_push_prio) {
tci &= ~VLAN_PRIO_MASK;
-   tci |= v->tcfv_push_prio << VLAN_PRIO_SHIFT;
+   tci |= p->tcfv_push_prio << VLAN_PRIO_SHIFT;
}
/* put updated tci as