From patchwork Fri Nov 27 08:14:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changli Gao X-Patchwork-Id: 39617 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 96FBA1007D3 for ; Fri, 27 Nov 2009 19:14:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbZK0IOc (ORCPT ); Fri, 27 Nov 2009 03:14:32 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751792AbZK0IOc (ORCPT ); Fri, 27 Nov 2009 03:14:32 -0500 Received: from mail-px0-f180.google.com ([209.85.216.180]:50622 "EHLO mail-px0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751063AbZK0IOb (ORCPT ); Fri, 27 Nov 2009 03:14:31 -0500 Received: by pxi10 with SMTP id 10so991337pxi.33 for ; Fri, 27 Nov 2009 00:14:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :user-agent:mime-version:to:cc:subject:content-type :content-transfer-encoding; bh=kXlbLRul0cG3PAeYlMscZZgtP+aQ8nbZrR12ngjZ9eI=; b=EEFQ9zQGyYIi4OfnTUR3aOHxXkxwbby7kn2iEudxiudGGejXrFi9KBtFxD1UlBkAft Fd2Zi8ZbnT/laY7EsMYVUKY9niL6dFb/qKw8KGPkEnaePPSlqLhCf0dWE2HHQejSi4xA tZGnZAXqHmygV6Kzy5xRB06IK114vx49nu14o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; b=W+dRK3FTAagsOjveszqsMTd/yfEbJzFfD4+33any9gECa1qPU4AVS/zi0fDU7UDBKQ dKe2WY5uWWRSigTUs3v1qVI+wIiLbhHT1+260JWw0YhL17qJUpu98FU9Q6ud5jlus7B0 s41QR4anNp/3+oCVThNR4Ja1rBv8ZgHXvwxSk= Received: by 10.114.188.1 with SMTP id l1mr1457156waf.193.1259309676818; Fri, 27 Nov 2009 00:14:36 -0800 (PST) Received: from ?10.13.150.1? ([221.238.105.181]) by mx.google.com with ESMTPS id 20sm1058289pxi.15.2009.11.27.00.14.31 (version=SSLv3 cipher=RC4-MD5); Fri, 27 Nov 2009 00:14:36 -0800 (PST) Message-ID: <4B0F8A5D.1040806@gmail.com> Date: Fri, 27 Nov 2009 16:14:21 +0800 From: Changli Gao Reply-To: xiaosuo@gmail.com User-Agent: Thunderbird 2.0.0.23 (X11/20091022) MIME-Version: 1.0 To: Jamal Hadi Salim , "David S. Miller" CC: netdev@vger.kernel.org, xiaosuo Subject: [PATCH] sch_htb: ix the deficit overflows Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org fix the deficit overflows. HTB uses WDRR(Weighted Deficit Round Robin) algorithm to schedule the spare bandwidth, but it doesn't check if the deficit is big enough for the skb when dequeuing skb from a class. In some case(the quantum is smaller than the packet size), the deficit will be decreased, even when it is smaller than ZERO. At last, the deficit will overflows, and become MAX_INT. Signed-off-by: Changli Gao ---- sch_htb.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 2e38d1a..293983e 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c @@ -783,6 +783,7 @@ static struct sk_buff *htb_dequeue_tree(struct htb_sched *q, int prio, { struct sk_buff *skb = NULL; struct htb_class *cl, *start; + unsigned int len; /* look initial class up in the row */ start = cl = htb_lookup_leaf(q->row[level] + prio, prio, q->ptr[level] + prio, @@ -815,9 +816,23 @@ next: goto next; } - skb = cl->un.leaf.q->dequeue(cl->un.leaf.q); - if (likely(skb != NULL)) - break; + skb = cl->un.leaf.q->ops->peek(cl->un.leaf.q); + if (likely(skb != NULL)) { + len = qdisc_pkt_len(skb); + if (len <= cl->un.leaf.deficit[level]) { + skb = qdisc_dequeue_peeked(cl->un.leaf.q); + break; + } + skb = NULL; + cl->un.leaf.deficit[level] += cl->quantum; + htb_next_rb_node((level ? cl->parent->un.inner.ptr : + q->ptr[0]) + prio); + cl = htb_lookup_leaf(q->row[level] + prio, prio, + q->ptr[level] + prio, + q->last_ptr_id[level] + prio); + start = cl; + goto next; + } qdisc_warn_nonwc("htb", cl->un.leaf.q); htb_next_rb_node((level ? cl->parent->un.inner.ptr : q-> @@ -829,8 +844,8 @@ next: } while (cl != start); if (likely(skb != NULL)) { - cl->un.leaf.deficit[level] -= qdisc_pkt_len(skb); - if (cl->un.leaf.deficit[level] < 0) { + cl->un.leaf.deficit[level] -= len; + if (cl->un.leaf.deficit[level] <= 0) { cl->un.leaf.deficit[level] += cl->quantum; htb_next_rb_node((level ? cl->parent->un.inner.ptr : q-> ptr[0]) + prio);