netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: David Miller <davem@davemloft.net>,
	Linux Kernel Network Developers <netdev@vger.kernel.org>,
	oss-drivers@netronome.com,
	Stephen Hemminger <stephen@networkplumber.org>,
	kbuild test robot <lkp@intel.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Ben Hutchings <ben@decadent.org.uk>,
	Simon Horman <simon.horman@netronome.com>
Subject: Re: [PATCH net] net: netem: fix error path for corrupted GSO frames
Date: Thu, 17 Oct 2019 11:44:04 -0700	[thread overview]
Message-ID: <20191017114404.4fb502c6@cakuba.netronome.com> (raw)
In-Reply-To: <CAM_iQpW=S+UarEKCtL6q_ZyxVn0chVLgXQyfRNP_Kw-P8_Qt+Q@mail.gmail.com>

On Thu, 17 Oct 2019 11:10:06 -0700, Cong Wang wrote:
> On Wed, Oct 16, 2019 at 4:22 PM Jakub Kicinski wrote:
> > On Wed, 16 Oct 2019 15:42:28 -0700, Cong Wang wrote:  
> > > > @@ -612,7 +613,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
> > > >                         }
> > > >                         segs = skb2;
> > > >                 }
> > > > -               qdisc_tree_reduce_backlog(sch, -nb, prev_len - len);
> > > > +               qdisc_tree_reduce_backlog(sch, !skb - nb, prev_len - len);  
> > >
> > > Am I the only one has trouble to understand the expression
> > > "!skb - nb"?  
> >
> > The backward logic of qdisc_tree_reduce_backlog() always gives me a
> > pause :S  
> 
> Yeah, reducing with a negative value is actually an add. Feel free
> to add a wrapper for this if you think it is better.

I was avoiding adding the wrapper due to stable, but perhaps it should
be okay.

How does this look?

--->8--------------

diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index 637548d54b3e..66c2dc6a4742 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -630,6 +630,13 @@ void qdisc_reset(struct Qdisc *qdisc);
 void qdisc_put(struct Qdisc *qdisc);
 void qdisc_put_unlocked(struct Qdisc *qdisc);
 void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, int n, int len);
+
+static inline void
+qdisc_tree_increase_backlog(struct Qdisc *qdisc, int n, int len)
+{
+	qdisc_tree_reduce_backlog(qdisc, -n, -len);
+}
+
 #ifdef CONFIG_NET_SCHED
 int qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
 			      void *type_data);
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 0e44039e729c..e22c13b56bfc 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -509,6 +509,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 		if (skb->ip_summed == CHECKSUM_PARTIAL &&
 		    skb_checksum_help(skb)) {
 			qdisc_drop(skb, sch, to_free);
+			skb = NULL;
 			goto finish_segs;
 		}
 
@@ -592,10 +593,13 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 
 finish_segs:
 	if (segs) {
-		unsigned int len, last_len;
+		unsigned int last_len, len = 0;
 		int nb = 0;
 
-		len = skb->len;
+		if (skb) {
+			len += skb->len;
+			nb++;
+		}
 
 		while (segs) {
 			skb2 = segs->next;
@@ -612,7 +616,8 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 			}
 			segs = skb2;
 		}
-		qdisc_tree_reduce_backlog(sch, -nb, prev_len - len);
+		/* Parent qdiscs accounted for 1 skb of size @prev_len */
+		qdisc_tree_increase_backlog(sch, nb - 1, len - prev_len);
 	}
 	return NET_XMIT_SUCCESS;
 }

  reply	other threads:[~2019-10-17 18:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 16:00 [PATCH net] net: netem: fix error path for corrupted GSO frames Jakub Kicinski
2019-10-16 22:42 ` Cong Wang
2019-10-16 23:22   ` Jakub Kicinski
2019-10-17 18:10     ` Cong Wang
2019-10-17 18:44       ` Jakub Kicinski [this message]
2019-10-17 19:28         ` Cong Wang

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=20191017114404.4fb502c6@cakuba.netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=ben@decadent.org.uk \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=lkp@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=simon.horman@netronome.com \
    --cc=stephen@networkplumber.org \
    --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;
as well as URLs for NNTP newsgroup(s).