BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 net 0/2] XDP generic related fixes
@ 2019-05-19  3:10 Stephen Hemminger
  2019-05-19  3:10 ` [PATCH v2 net 1/2] netvsc: unshare skb in VF rx handler Stephen Hemminger
  2019-05-19  3:10 ` [PATCH v2 net 2/2] net: core: generic XDP support for stacked device Stephen Hemminger
  0 siblings, 2 replies; 12+ messages in thread
From: Stephen Hemminger @ 2019-05-19  3:10 UTC (permalink / raw)
  To: netdev, davem; +Cc: xdp-newbies, bpf, Stephen Hemminger

This set of patches came about while investigating XDP
generic on Azure. The split brain nature of the accelerated
networking exposed issues with the stack device model.

The real fix is in the second patch which is a redo
of earlier patch from Jason Wang.

v2 - hold off the comment fixes for net-next

Stephen Hemminger (2):
  netvsc: unshare skb in VF rx handler
  net: core: generic XDP support for stacked device

 drivers/net/hyperv/netvsc_drv.c |  6 ++++++
 net/core/dev.c                  | 10 ++++++++++
 2 files changed, 16 insertions(+)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 net 1/2] netvsc: unshare skb in VF rx handler
  2019-05-19  3:10 [PATCH v2 net 0/2] XDP generic related fixes Stephen Hemminger
@ 2019-05-19  3:10 ` Stephen Hemminger
  2019-05-19  3:10 ` [PATCH v2 net 2/2] net: core: generic XDP support for stacked device Stephen Hemminger
  1 sibling, 0 replies; 12+ messages in thread
From: Stephen Hemminger @ 2019-05-19  3:10 UTC (permalink / raw)
  To: netdev, davem; +Cc: xdp-newbies, bpf, Stephen Hemminger

The netvsc VF skb handler should make sure that skb is not
shared. Similar logic already exists in bonding and team device
drivers.

This is not an issue in practice because the VF devicex
does not send up shared skb's. But the netvsc driver
should do the right thing if it did.

Fixes: 0c195567a8f6 ("netvsc: transparent VF management")
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 06393b215102..9873b8679f81 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2000,6 +2000,12 @@ static rx_handler_result_t netvsc_vf_handle_frame(struct sk_buff **pskb)
 	struct netvsc_vf_pcpu_stats *pcpu_stats
 		 = this_cpu_ptr(ndev_ctx->vf_stats);
 
+	skb = skb_share_check(skb, GFP_ATOMIC);
+	if (unlikely(!skb))
+		return RX_HANDLER_CONSUMED;
+
+	*pskb = skb;
+
 	skb->dev = ndev;
 
 	u64_stats_update_begin(&pcpu_stats->syncp);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-19  3:10 [PATCH v2 net 0/2] XDP generic related fixes Stephen Hemminger
  2019-05-19  3:10 ` [PATCH v2 net 1/2] netvsc: unshare skb in VF rx handler Stephen Hemminger
@ 2019-05-19  3:10 ` Stephen Hemminger
  2019-05-20  9:11   ` Jiri Pirko
  1 sibling, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2019-05-19  3:10 UTC (permalink / raw)
  To: netdev, davem; +Cc: xdp-newbies, bpf, Stephen Hemminger, Jason Wang

When a device is stacked like (team, bonding, failsafe or netvsc) the
XDP generic program for the parent device is not called.  In these
cases, the rx handler changes skb->dev to its own in the receive
handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
do_xdp_generic if necessary before starting another round.

Review of all the places RX_HANDLER_ANOTHER is returned
show that the current devices do correctly change skb->dev.

There was an older patch that got abandoned that did the
same thing, this is just a rewrite.

Suggested-by: Jason Wang <jasowang@redhat.com>
Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 net/core/dev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index b6b8505cfb3e..240d0b2de1a8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4921,6 +4921,16 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
 			ret = NET_RX_SUCCESS;
 			goto out;
 		case RX_HANDLER_ANOTHER:
+			if (static_branch_unlikely(&generic_xdp_needed_key)) {
+				struct bpf_prog *xdp_prog;
+
+				xdp_prog = rcu_dereference(skb->dev->xdp_prog);
+				ret = do_xdp_generic(xdp_prog, skb);
+				if (ret != XDP_PASS) {
+					ret = NET_RX_SUCCESS;
+					goto out;
+				}
+			}
 			goto another_round;
 		case RX_HANDLER_EXACT:
 			deliver_exact = true;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-19  3:10 ` [PATCH v2 net 2/2] net: core: generic XDP support for stacked device Stephen Hemminger
@ 2019-05-20  9:11   ` Jiri Pirko
  2019-05-20 15:53     ` Stephen Hemminger
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Jiri Pirko @ 2019-05-20  9:11 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger, Jason Wang

Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
>When a device is stacked like (team, bonding, failsafe or netvsc) the
>XDP generic program for the parent device is not called.  In these
>cases, the rx handler changes skb->dev to its own in the receive
>handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
>do_xdp_generic if necessary before starting another round.
>
>Review of all the places RX_HANDLER_ANOTHER is returned
>show that the current devices do correctly change skb->dev.
>
>There was an older patch that got abandoned that did the
>same thing, this is just a rewrite.
>
>Suggested-by: Jason Wang <jasowang@redhat.com>
>Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
>Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
>Acked-by: Jason Wang <jasowang@redhat.com>
>---
> net/core/dev.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
>diff --git a/net/core/dev.c b/net/core/dev.c
>index b6b8505cfb3e..240d0b2de1a8 100644
>--- a/net/core/dev.c
>+++ b/net/core/dev.c
>@@ -4921,6 +4921,16 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
> 			ret = NET_RX_SUCCESS;
> 			goto out;
> 		case RX_HANDLER_ANOTHER:
>+			if (static_branch_unlikely(&generic_xdp_needed_key)) {
>+				struct bpf_prog *xdp_prog;
>+
>+				xdp_prog = rcu_dereference(skb->dev->xdp_prog);
>+				ret = do_xdp_generic(xdp_prog, skb);
>+				if (ret != XDP_PASS) {
>+					ret = NET_RX_SUCCESS;
>+					goto out;
>+				}
>+			}

I'm always scarred of changes like this. The history tells us that this
codepaths are very fragile. It took us non-trivial efford to fix bonding
here, not to mention vlans (that was pain).

The reason for troubles was often fact that different flows were treated
differently (vlan accel/non-accel).

This patch calls do_xdp_generic for master device in different point in
the receive patch comparing to lower device. Would it be possible to
unify this? E.g. by moving do_xdp_generice() call from
netif_rx_internal()/netif_receive_skb_internal() here,
to the beginning of __netif_receive_skb_core()?



> 			goto another_round;
> 		case RX_HANDLER_EXACT:
> 			deliver_exact = true;
>-- 
>2.20.1
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-20  9:11   ` Jiri Pirko
@ 2019-05-20 15:53     ` Stephen Hemminger
  2019-05-21  5:54       ` Jason Wang
  2019-05-20 16:04     ` Stephen Hemminger
  2019-05-21  4:47     ` Jason Wang
  2 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2019-05-20 15:53 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger, Jason Wang

On Mon, 20 May 2019 11:11:05 +0200
Jiri Pirko <jiri@resnulli.us> wrote:

> Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
> >When a device is stacked like (team, bonding, failsafe or netvsc) the
> >XDP generic program for the parent device is not called.  In these
> >cases, the rx handler changes skb->dev to its own in the receive
> >handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
> >do_xdp_generic if necessary before starting another round.
> >
> >Review of all the places RX_HANDLER_ANOTHER is returned
> >show that the current devices do correctly change skb->dev.
> >
> >There was an older patch that got abandoned that did the
> >same thing, this is just a rewrite.
> >
> >Suggested-by: Jason Wang <jasowang@redhat.com>
> >Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
> >Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
> >Acked-by: Jason Wang <jasowang@redhat.com>
> >---

> I'm always scarred of changes like this. The history tells us that this
> codepaths are very fragile. It took us non-trivial efford to fix bonding
> here, not to mention vlans (that was pain).
> 
> The reason for troubles was often fact that different flows were treated
> differently (vlan accel/non-accel).

Yes, this is a sensitive path. Another alternative is to fix it
inside each device (netvsc). That is what my earlier patch did and that
is what is being done now (probably will make it into the RHEL on Azure
drivers).
 
> This patch calls do_xdp_generic for master device in different point in
> the receive patch comparing to lower device. Would it be possible to
> unify this? E.g. by moving do_xdp_generice() call from
> netif_rx_internal()/netif_receive_skb_internal() here,
> to the beginning of __netif_receive_skb_core()?
> 

That could work, but has the question about doing XDP farther down
call stack (lower performance).

There is also the case what if both paths support XDP in driver.
This would be the ideal case, how would this work?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-20  9:11   ` Jiri Pirko
  2019-05-20 15:53     ` Stephen Hemminger
@ 2019-05-20 16:04     ` Stephen Hemminger
  2019-05-21  6:15       ` Jiri Pirko
  2019-05-21  4:47     ` Jason Wang
  2 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2019-05-20 16:04 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger, Jason Wang

On Mon, 20 May 2019 11:11:05 +0200
Jiri Pirko <jiri@resnulli.us> wrote:

> Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
> >When a device is stacked like (team, bonding, failsafe or netvsc) the
> >XDP generic program for the parent device is not called.  In these
> >cases, the rx handler changes skb->dev to its own in the receive
> >handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
> >do_xdp_generic if necessary before starting another round.
> >
> >Review of all the places RX_HANDLER_ANOTHER is returned
> >show that the current devices do correctly change skb->dev.
> >
> >There was an older patch that got abandoned that did the
> >same thing, this is just a rewrite.
> >
> >Suggested-by: Jason Wang <jasowang@redhat.com>
> >Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
> >Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
> >Acked-by: Jason Wang <jasowang@redhat.com>
> >---
> > net/core/dev.c | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> >diff --git a/net/core/dev.c b/net/core/dev.c
> >index b6b8505cfb3e..240d0b2de1a8 100644
> >--- a/net/core/dev.c
> >+++ b/net/core/dev.c
> >@@ -4921,6 +4921,16 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
> > 			ret = NET_RX_SUCCESS;
> > 			goto out;
> > 		case RX_HANDLER_ANOTHER:
> >+			if (static_branch_unlikely(&generic_xdp_needed_key)) {
> >+				struct bpf_prog *xdp_prog;
> >+
> >+				xdp_prog = rcu_dereference(skb->dev->xdp_prog);
> >+				ret = do_xdp_generic(xdp_prog, skb);
> >+				if (ret != XDP_PASS) {
> >+					ret = NET_RX_SUCCESS;
> >+					goto out;
> >+				}
> >+			}  
> 
> I'm always scarred of changes like this. The history tells us that this
> codepaths are very fragile. It took us non-trivial efford to fix bonding
> here, not to mention vlans (that was pain).
> 
> The reason for troubles was often fact that different flows were treated
> differently (vlan accel/non-accel).
> 
> This patch calls do_xdp_generic for master device in different point in
> the receive patch comparing to lower device. Would it be possible to
> unify this? E.g. by moving do_xdp_generice() call from
> netif_rx_internal()/netif_receive_skb_internal() here,
> to the beginning of __netif_receive_skb_core()?
> 

I am trying that now. But one problem is that it would break the case
where XDP was being run on one leg of a bridge. For example if eth1 is
part of br0; then it would no longer be possible to run XDP on eth1.

Running XDP on eth1 might be used to do some kind of ILA or overlay
network. That change would break it.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-20  9:11   ` Jiri Pirko
  2019-05-20 15:53     ` Stephen Hemminger
  2019-05-20 16:04     ` Stephen Hemminger
@ 2019-05-21  4:47     ` Jason Wang
  2019-05-21  6:08       ` Jiri Pirko
  2 siblings, 1 reply; 12+ messages in thread
From: Jason Wang @ 2019-05-21  4:47 UTC (permalink / raw)
  To: Jiri Pirko, Stephen Hemminger
  Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger


On 2019/5/20 下午5:11, Jiri Pirko wrote:
> Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
>> When a device is stacked like (team, bonding, failsafe or netvsc) the
>> XDP generic program for the parent device is not called.  In these
>> cases, the rx handler changes skb->dev to its own in the receive
>> handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
>> do_xdp_generic if necessary before starting another round.
>>
>> Review of all the places RX_HANDLER_ANOTHER is returned
>> show that the current devices do correctly change skb->dev.
>>
>> There was an older patch that got abandoned that did the
>> same thing, this is just a rewrite.
>>
>> Suggested-by: Jason Wang <jasowang@redhat.com>
>> Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
>> Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
>> Acked-by: Jason Wang <jasowang@redhat.com>
>> ---
>> net/core/dev.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index b6b8505cfb3e..240d0b2de1a8 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -4921,6 +4921,16 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
>> 			ret = NET_RX_SUCCESS;
>> 			goto out;
>> 		case RX_HANDLER_ANOTHER:
>> +			if (static_branch_unlikely(&generic_xdp_needed_key)) {
>> +				struct bpf_prog *xdp_prog;
>> +
>> +				xdp_prog = rcu_dereference(skb->dev->xdp_prog);
>> +				ret = do_xdp_generic(xdp_prog, skb);
>> +				if (ret != XDP_PASS) {
>> +					ret = NET_RX_SUCCESS;
>> +					goto out;
>> +				}
>> +			}
> I'm always scarred of changes like this. The history tells us that this
> codepaths are very fragile. It took us non-trivial efford to fix bonding
> here, not to mention vlans (that was pain).


I may miss something, did you see any issue for bonding with this patch?


>
> The reason for troubles was often fact that different flows were treated
> differently (vlan accel/non-accel).


Do you mean we need do something similar after vlan_do_receive() returns 
true?


> This patch calls do_xdp_generic for master device in different point in
> the receive patch comparing to lower device. Would it be possible to
> unify this? E.g. by moving do_xdp_generice() call from
> netif_rx_internal()/netif_receive_skb_internal() here,
> to the beginning of __netif_receive_skb_core()?


Probably just after another_round label. And this means generic XDP is 
done after RPS which could be even better.

Thanks


>
>
>
>> 			goto another_round;
>> 		case RX_HANDLER_EXACT:
>> 			deliver_exact = true;
>> -- 
>> 2.20.1
>>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-20 15:53     ` Stephen Hemminger
@ 2019-05-21  5:54       ` Jason Wang
  0 siblings, 0 replies; 12+ messages in thread
From: Jason Wang @ 2019-05-21  5:54 UTC (permalink / raw)
  To: Stephen Hemminger, Jiri Pirko
  Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger


On 2019/5/20 下午11:53, Stephen Hemminger wrote:
> On Mon, 20 May 2019 11:11:05 +0200
> Jiri Pirko <jiri@resnulli.us> wrote:
>
>> Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
>>> When a device is stacked like (team, bonding, failsafe or netvsc) the
>>> XDP generic program for the parent device is not called.  In these
>>> cases, the rx handler changes skb->dev to its own in the receive
>>> handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
>>> do_xdp_generic if necessary before starting another round.
>>>
>>> Review of all the places RX_HANDLER_ANOTHER is returned
>>> show that the current devices do correctly change skb->dev.
>>>
>>> There was an older patch that got abandoned that did the
>>> same thing, this is just a rewrite.
>>>
>>> Suggested-by: Jason Wang <jasowang@redhat.com>
>>> Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
>>> Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
>>> Acked-by: Jason Wang <jasowang@redhat.com>
>>> ---
>> I'm always scarred of changes like this. The history tells us that this
>> codepaths are very fragile. It took us non-trivial efford to fix bonding
>> here, not to mention vlans (that was pain).
>>
>> The reason for troubles was often fact that different flows were treated
>> differently (vlan accel/non-accel).
> Yes, this is a sensitive path. Another alternative is to fix it
> inside each device (netvsc). That is what my earlier patch did and that
> is what is being done now (probably will make it into the RHEL on Azure
> drivers).
>   
>> This patch calls do_xdp_generic for master device in different point in
>> the receive patch comparing to lower device. Would it be possible to
>> unify this? E.g. by moving do_xdp_generice() call from
>> netif_rx_internal()/netif_receive_skb_internal() here,
>> to the beginning of __netif_receive_skb_core()?
>>
> That could work, but has the question about doing XDP farther down
> call stack (lower performance).
>
> There is also the case what if both paths support XDP in driver.
> This would be the ideal case, how would this work?
>
>

I think we have a clear request of allowing native XDP to work on 
stacked device. We're missing some generic building blocks (like XDP rx 
handler) here.

Thanks



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-21  4:47     ` Jason Wang
@ 2019-05-21  6:08       ` Jiri Pirko
  0 siblings, 0 replies; 12+ messages in thread
From: Jiri Pirko @ 2019-05-21  6:08 UTC (permalink / raw)
  To: Jason Wang
  Cc: Stephen Hemminger, netdev, davem, xdp-newbies, bpf, Stephen Hemminger

Tue, May 21, 2019 at 06:47:23AM CEST, jasowang@redhat.com wrote:
>
>On 2019/5/20 下午5:11, Jiri Pirko wrote:
>> Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
>> > When a device is stacked like (team, bonding, failsafe or netvsc) the
>> > XDP generic program for the parent device is not called.  In these
>> > cases, the rx handler changes skb->dev to its own in the receive
>> > handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
>> > do_xdp_generic if necessary before starting another round.
>> > 
>> > Review of all the places RX_HANDLER_ANOTHER is returned
>> > show that the current devices do correctly change skb->dev.
>> > 
>> > There was an older patch that got abandoned that did the
>> > same thing, this is just a rewrite.
>> > 
>> > Suggested-by: Jason Wang <jasowang@redhat.com>
>> > Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
>> > Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
>> > Acked-by: Jason Wang <jasowang@redhat.com>
>> > ---
>> > net/core/dev.c | 10 ++++++++++
>> > 1 file changed, 10 insertions(+)
>> > 
>> > diff --git a/net/core/dev.c b/net/core/dev.c
>> > index b6b8505cfb3e..240d0b2de1a8 100644
>> > --- a/net/core/dev.c
>> > +++ b/net/core/dev.c
>> > @@ -4921,6 +4921,16 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
>> > 			ret = NET_RX_SUCCESS;
>> > 			goto out;
>> > 		case RX_HANDLER_ANOTHER:
>> > +			if (static_branch_unlikely(&generic_xdp_needed_key)) {
>> > +				struct bpf_prog *xdp_prog;
>> > +
>> > +				xdp_prog = rcu_dereference(skb->dev->xdp_prog);
>> > +				ret = do_xdp_generic(xdp_prog, skb);
>> > +				if (ret != XDP_PASS) {
>> > +					ret = NET_RX_SUCCESS;
>> > +					goto out;
>> > +				}
>> > +			}
>> I'm always scarred of changes like this. The history tells us that this
>> codepaths are very fragile. It took us non-trivial efford to fix bonding
>> here, not to mention vlans (that was pain).
>
>
>I may miss something, did you see any issue for bonding with this patch?

No, I was talking about past.


>
>
>> 
>> The reason for troubles was often fact that different flows were treated
>> differently (vlan accel/non-accel).
>
>
>Do you mean we need do something similar after vlan_do_receive() returns
>true?

No.


>
>
>> This patch calls do_xdp_generic for master device in different point in
>> the receive patch comparing to lower device. Would it be possible to
>> unify this? E.g. by moving do_xdp_generice() call from
>> netif_rx_internal()/netif_receive_skb_internal() here,
>> to the beginning of __netif_receive_skb_core()?
>
>
>Probably just after another_round label. And this means generic XDP is done
>after RPS which could be even better.

Yes. That is exactly the place I have in mind.


>
>Thanks
>
>
>> 
>> 
>> 
>> > 			goto another_round;
>> > 		case RX_HANDLER_EXACT:
>> > 			deliver_exact = true;
>> > -- 
>> > 2.20.1
>> > 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-20 16:04     ` Stephen Hemminger
@ 2019-05-21  6:15       ` Jiri Pirko
  2019-05-21 14:45         ` Stephen Hemminger
  0 siblings, 1 reply; 12+ messages in thread
From: Jiri Pirko @ 2019-05-21  6:15 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger, Jason Wang

Mon, May 20, 2019 at 06:04:05PM CEST, stephen@networkplumber.org wrote:
>On Mon, 20 May 2019 11:11:05 +0200
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> Sun, May 19, 2019 at 05:10:46AM CEST, stephen@networkplumber.org wrote:
>> >When a device is stacked like (team, bonding, failsafe or netvsc) the
>> >XDP generic program for the parent device is not called.  In these
>> >cases, the rx handler changes skb->dev to its own in the receive
>> >handler, and returns RX_HANDLER_ANOTHER.  Fix this by calling
>> >do_xdp_generic if necessary before starting another round.
>> >
>> >Review of all the places RX_HANDLER_ANOTHER is returned
>> >show that the current devices do correctly change skb->dev.
>> >
>> >There was an older patch that got abandoned that did the
>> >same thing, this is just a rewrite.
>> >
>> >Suggested-by: Jason Wang <jasowang@redhat.com>
>> >Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices")
>> >Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
>> >Acked-by: Jason Wang <jasowang@redhat.com>
>> >---
>> > net/core/dev.c | 10 ++++++++++
>> > 1 file changed, 10 insertions(+)
>> >
>> >diff --git a/net/core/dev.c b/net/core/dev.c
>> >index b6b8505cfb3e..240d0b2de1a8 100644
>> >--- a/net/core/dev.c
>> >+++ b/net/core/dev.c
>> >@@ -4921,6 +4921,16 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
>> > 			ret = NET_RX_SUCCESS;
>> > 			goto out;
>> > 		case RX_HANDLER_ANOTHER:
>> >+			if (static_branch_unlikely(&generic_xdp_needed_key)) {
>> >+				struct bpf_prog *xdp_prog;
>> >+
>> >+				xdp_prog = rcu_dereference(skb->dev->xdp_prog);
>> >+				ret = do_xdp_generic(xdp_prog, skb);
>> >+				if (ret != XDP_PASS) {
>> >+					ret = NET_RX_SUCCESS;
>> >+					goto out;
>> >+				}
>> >+			}  
>> 
>> I'm always scarred of changes like this. The history tells us that this
>> codepaths are very fragile. It took us non-trivial efford to fix bonding
>> here, not to mention vlans (that was pain).
>> 
>> The reason for troubles was often fact that different flows were treated
>> differently (vlan accel/non-accel).
>> 
>> This patch calls do_xdp_generic for master device in different point in
>> the receive patch comparing to lower device. Would it be possible to
>> unify this? E.g. by moving do_xdp_generice() call from
>> netif_rx_internal()/netif_receive_skb_internal() here,
>> to the beginning of __netif_receive_skb_core()?
>> 
>
>I am trying that now. But one problem is that it would break the case
>where XDP was being run on one leg of a bridge. For example if eth1 is
>part of br0; then it would no longer be possible to run XDP on eth1.

I don't see why not. The xdp is still run in __netif_receive_skb_core()
before goto another_round.

I was thinking about patch similar to this:

diff --git a/net/core/dev.c b/net/core/dev.c
index b6b8505cfb3e..4c3fdda85544 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4502,23 +4502,6 @@ static int netif_rx_internal(struct sk_buff *skb)
 
 	trace_netif_rx(skb);
 
-	if (static_branch_unlikely(&generic_xdp_needed_key)) {
-		int ret;
-
-		preempt_disable();
-		rcu_read_lock();
-		ret = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb);
-		rcu_read_unlock();
-		preempt_enable();
-
-		/* Consider XDP consuming the packet a success from
-		 * the netdev point of view we do not want to count
-		 * this as an error.
-		 */
-		if (ret != XDP_PASS)
-			return NET_RX_SUCCESS;
-	}
-
 #ifdef CONFIG_RPS
 	if (static_branch_unlikely(&rps_needed)) {
 		struct rps_dev_flow voidflow, *rflow = &voidflow;
@@ -4858,6 +4841,19 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
 
 	__this_cpu_inc(softnet_data.processed);
 
+	if (static_branch_unlikely(&generic_xdp_needed_key)) {
+		int ret2;
+
+		preempt_disable();
+		rcu_read_lock();
+		ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb);
+		rcu_read_unlock();
+		preempt_enable();
+
+		if (ret2 != XDP_PASS)
+			return NET_RX_DROP;
+	}
+
 	if (skb->protocol == cpu_to_be16(ETH_P_8021Q) ||
 	    skb->protocol == cpu_to_be16(ETH_P_8021AD)) {
 		skb = skb_vlan_untag(skb);
@@ -5178,19 +5174,6 @@ static int netif_receive_skb_internal(struct sk_buff *skb)
 	if (skb_defer_rx_timestamp(skb))
 		return NET_RX_SUCCESS;
 
-	if (static_branch_unlikely(&generic_xdp_needed_key)) {
-		int ret;
-
-		preempt_disable();
-		rcu_read_lock();
-		ret = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb);
-		rcu_read_unlock();
-		preempt_enable();
-
-		if (ret != XDP_PASS)
-			return NET_RX_DROP;
-	}
-
 	rcu_read_lock();
 #ifdef CONFIG_RPS
 	if (static_branch_unlikely(&rps_needed)) {
@@ -5224,21 +5207,6 @@ static void netif_receive_skb_list_internal(struct list_head *head)
 	}
 	list_splice_init(&sublist, head);
 
-	if (static_branch_unlikely(&generic_xdp_needed_key)) {
-		preempt_disable();
-		rcu_read_lock();
-		list_for_each_entry_safe(skb, next, head, list) {
-			xdp_prog = rcu_dereference(skb->dev->xdp_prog);
-			skb_list_del_init(skb);
-			if (do_xdp_generic(xdp_prog, skb) == XDP_PASS)
-				list_add_tail(&skb->list, &sublist);
-		}
-		rcu_read_unlock();
-		preempt_enable();
-		/* Put passed packets back on main list */
-		list_splice_init(&sublist, head);
-	}
-
 	rcu_read_lock();
 #ifdef CONFIG_RPS
 	if (static_branch_unlikely(&rps_needed)) {

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-21  6:15       ` Jiri Pirko
@ 2019-05-21 14:45         ` Stephen Hemminger
  2019-05-21 15:21           ` Jiri Pirko
  0 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2019-05-21 14:45 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger, Jason Wang

On Tue, 21 May 2019 08:15:36 +0200
Jiri Pirko <jiri@resnulli.us> wrote:

> +	if (static_branch_unlikely(&generic_xdp_needed_key)) {
> +		int ret2;
> +
> +		preempt_disable();
> +		rcu_read_lock();
> +		ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb);
> +		rcu_read_unlock();
> +		preempt_enable();
> +
> +		if (ret2 != XDP_PASS)
> +			return NET_RX_DROP;
> +	}
> +

rcu_read_lock is already held by callers of __netif_receive_skb_core

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 net 2/2] net: core: generic XDP support for stacked device
  2019-05-21 14:45         ` Stephen Hemminger
@ 2019-05-21 15:21           ` Jiri Pirko
  0 siblings, 0 replies; 12+ messages in thread
From: Jiri Pirko @ 2019-05-21 15:21 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: netdev, davem, xdp-newbies, bpf, Stephen Hemminger, Jason Wang

Tue, May 21, 2019 at 04:45:53PM CEST, stephen@networkplumber.org wrote:
>On Tue, 21 May 2019 08:15:36 +0200
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> +	if (static_branch_unlikely(&generic_xdp_needed_key)) {
>> +		int ret2;
>> +
>> +		preempt_disable();
>> +		rcu_read_lock();
>> +		ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb);
>> +		rcu_read_unlock();
>> +		preempt_enable();
>> +
>> +		if (ret2 != XDP_PASS)
>> +			return NET_RX_DROP;
>> +	}
>> +
>
>rcu_read_lock is already held by callers of __netif_receive_skb_core

Sure, the purpose of the draft was just to show the idea.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, back to index

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-19  3:10 [PATCH v2 net 0/2] XDP generic related fixes Stephen Hemminger
2019-05-19  3:10 ` [PATCH v2 net 1/2] netvsc: unshare skb in VF rx handler Stephen Hemminger
2019-05-19  3:10 ` [PATCH v2 net 2/2] net: core: generic XDP support for stacked device Stephen Hemminger
2019-05-20  9:11   ` Jiri Pirko
2019-05-20 15:53     ` Stephen Hemminger
2019-05-21  5:54       ` Jason Wang
2019-05-20 16:04     ` Stephen Hemminger
2019-05-21  6:15       ` Jiri Pirko
2019-05-21 14:45         ` Stephen Hemminger
2019-05-21 15:21           ` Jiri Pirko
2019-05-21  4:47     ` Jason Wang
2019-05-21  6:08       ` Jiri Pirko

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org bpf@archiver.kernel.org
	public-inbox-index bpf


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/ public-inbox