public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Eyal Birger <eyal.birger@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next v3 5/5] act_mirred: use TC_ACT_REINJECT when possible
Date: Wed, 25 Jul 2018 16:30:17 +0200	[thread overview]
Message-ID: <20180725143017.GN2164@nanopsycho> (raw)
In-Reply-To: <721f42fb778546dfc1f9e2ae1309fcf4476d3c84.camel@redhat.com>

Wed, Jul 25, 2018 at 04:04:03PM CEST, pabeni@redhat.com wrote:
>On Wed, 2018-07-25 at 15:52 +0200, Jiri Pirko wrote:
>> Tue, Jul 24, 2018 at 10:06:43PM CEST, pabeni@redhat.com wrote:
>> > When mirred is invoked from the ingress path, and it wants to redirect
>> > the processed packet, it can now use the TC_ACT_REINJECT action,
>> > filling the tcf_result accordingly, and avoiding a per packet
>> > skb_clone().
>> > 
>> > Overall this gives a ~10% improvement in forwarding performance for the
>> > TC S/W data path and TC S/W performances are now comparable to the
>> > kernel openvswitch datapath.
>> > 
>> > v1 -> v2: use ACT_MIRRED instead of ACT_REDIRECT
>> > v2 -> v3: updated after action rename, fixed a typo into the commit
>> > 	message
>> > 
>> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>> > ---
>> > net/sched/act_mirred.c | 34 ++++++++++++++++++++++++----------
>> > 1 file changed, 24 insertions(+), 10 deletions(-)
>> > 
>> > diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
>> > index eeb335f03102..368187312136 100644
>> > --- a/net/sched/act_mirred.c
>> > +++ b/net/sched/act_mirred.c
>> > @@ -25,6 +25,7 @@
>> > #include <net/net_namespace.h>
>> > #include <net/netlink.h>
>> > #include <net/pkt_sched.h>
>> > +#include <net/pkt_cls.h>
>> > #include <linux/tc_act/tc_mirred.h>
>> > #include <net/tc_act/tc_mirred.h>
>> > 
>> > @@ -171,10 +172,12 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
>> > 		      struct tcf_result *res)
>> > {
>> > 	struct tcf_mirred *m = to_mirred(a);
>> > +	struct sk_buff *skb2 = skb;
>> > 	bool m_mac_header_xmit;
>> > 	struct net_device *dev;
>> > -	struct sk_buff *skb2;
>> > 	int retval, err = 0;
>> > +	bool want_ingress;
>> > +	bool is_redirect;
>> > 	int m_eaction;
>> > 	int mac_len;
>> > 
>> > @@ -196,16 +199,19 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
>> > 		goto out;
>> > 	}
>> > 
>> > -	skb2 = skb_clone(skb, GFP_ATOMIC);
>> > -	if (!skb2)
>> > -		goto out;
>> > +	is_redirect = tcf_mirred_is_act_redirect(m_eaction);
>> > +	if (!skb_at_tc_ingress(skb) || !is_redirect) {
>> > +		skb2 = skb_clone(skb, GFP_ATOMIC);
>> > +		if (!skb2)
>> > +			goto out;
>> > +	}
>> > 
>> > 	/* If action's target direction differs than filter's direction,
>> > 	 * and devices expect a mac header on xmit, then mac push/pull is
>> > 	 * needed.
>> > 	 */
>> > -	if (skb_at_tc_ingress(skb) != tcf_mirred_act_wants_ingress(m_eaction) &&
>> > -	    m_mac_header_xmit) {
>> > +	want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
>> > +	if (skb_at_tc_ingress(skb) != want_ingress && m_mac_header_xmit) {
>> > 		if (!skb_at_tc_ingress(skb)) {
>> > 			/* caught at egress, act ingress: pull mac */
>> > 			mac_len = skb_network_header(skb) - skb_mac_header(skb);
>> > @@ -216,15 +222,23 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
>> > 		}
>> > 	}
>> > 
>> > +	skb2->skb_iif = skb->dev->ifindex;
>> > +	skb2->dev = dev;
>> > +
>> > 	/* mirror is always swallowed */
>> > -	if (tcf_mirred_is_act_redirect(m_eaction)) {
>> > +	if (is_redirect) {
>> > 		skb2->tc_redirected = 1;
>> > 		skb2->tc_from_ingress = skb2->tc_at_ingress;
>> > +
>> > +		/* let's the caller reinject the packet, if possible */
>> > +		if (skb_at_tc_ingress(skb)) {
>> 
>> I probably missed something. Why only on ingress?
>
>To keep the implementation as simple as possible: if I read correctly,
>it is impossible for a filter detect if called by the clsact or the dev
>root qdisc, and I think we could safely avoid the skb clone with a not
>invasive patch, only if called from the clsact.
>
>[please let me know if the above is somewhat clear ;)]
>
>Also this covers nicely the relevant use case (TC S/W datapath).

Sure. I was just curious. Perhaps put a comment to this optimisation
describing why it is not possible for egress. It might help future
readers.

Thanks!

>
>Thanks,
>
>Paolo
>

  reply	other threads:[~2018-07-25 15:44 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-24 20:06 [PATCH net-next v3 0/5] TC: refactor act_mirred packets re-injection Paolo Abeni
2018-07-24 20:06 ` [PATCH net-next v3 1/5] tc/act: user space can't use TC_ACT_REDIRECT directly Paolo Abeni
2018-07-25 11:55   ` Jamal Hadi Salim
2018-07-25 11:56   ` Jiri Pirko
2018-07-25 12:54     ` Paolo Abeni
2018-07-25 13:03       ` Jiri Pirko
2018-07-25 15:48         ` Paolo Abeni
2018-07-25 16:29           ` Paolo Abeni
2018-07-25 16:29           ` Daniel Borkmann
2018-07-26  7:43             ` Jiri Pirko
2018-07-27  2:48               ` Daniel Borkmann
2018-07-24 20:06 ` [PATCH net-next v3 2/5] net/sched: user-space can't set unknown tcfa_action values Paolo Abeni
2018-07-25 12:26   ` Jiri Pirko
2018-07-24 20:06 ` [PATCH net-next v3 3/5] tc/act: remove unneeded RCU lock in action callback Paolo Abeni
2018-07-25 11:59   ` Jamal Hadi Salim
2018-07-25 18:24     ` Marcelo Ricardo Leitner
2018-07-25 12:32   ` Jiri Pirko
2018-07-24 20:06 ` [PATCH net-next v3 4/5] net/tc: introduce TC_ACT_REINJECT Paolo Abeni
2018-07-24 20:38   ` Cong Wang
2018-07-24 20:50     ` Cong Wang
2018-07-25  8:29       ` Paolo Abeni
2018-07-25 12:27         ` Jamal Hadi Salim
2018-07-25 14:24           ` Paolo Abeni
2018-07-25 15:26             ` Jamal Hadi Salim
2018-07-25 16:48           ` Cong Wang
2018-07-25 17:09             ` Marcelo Ricardo Leitner
2018-07-26 12:52               ` Jamal Hadi Salim
2018-07-26 23:25                 ` Cong Wang
2018-07-25 12:16   ` Jamal Hadi Salim
2018-07-25 12:59     ` Jiri Pirko
2018-07-25 13:55     ` Paolo Abeni
2018-07-25 12:57   ` Jiri Pirko
2018-07-24 20:06 ` [PATCH net-next v3 5/5] act_mirred: use TC_ACT_REINJECT when possible Paolo Abeni
2018-07-24 21:15   ` Cong Wang
2018-07-25 10:14     ` Paolo Abeni
2018-07-25 13:30       ` Jiri Pirko
2018-07-25 11:50     ` Jamal Hadi Salim
2018-07-25 13:52   ` Jiri Pirko
2018-07-25 14:04     ` Paolo Abeni
2018-07-25 14:30       ` Jiri Pirko [this message]
2018-07-25 11:53 ` [PATCH net-next v3 0/5] TC: refactor act_mirred packets re-injection Jiri Pirko
2018-07-25 12:07   ` Paolo Abeni
2018-07-25 12:17     ` Jiri Pirko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180725143017.GN2164@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eyal.birger@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox