Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1908955imm; Thu, 24 May 2018 02:45:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZorRKzfkt4ijujII6gR+fcPhlX8QXEx9fCLZjHnYx6A96gzgh0PYYxN4jmy4iTzbf2rePl9 X-Received: by 2002:a63:755d:: with SMTP id f29-v6mr1655655pgn.278.1527155114521; Thu, 24 May 2018 02:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155114; cv=none; d=google.com; s=arc-20160816; b=wMwiits52a/TzeDOpD/nG55VTT5eF2YkxddxyUKz2XW7rJe6stJ2ErAehNCKJ7Pr+H lWZVrWhd49t5Jhhvq11vgxkSb8HGv/uUbE1byR32ZVr3YD73IoL+Cw5RO7kFb7Z7WbqQ 9H3SOVQyttY8X3ymbfWKpkw5T0qD/YGydOv2vwcv27JXhgVG1qRDaT83LEDWtoNDCV07 hxyM0bOP0cQbPUMec2L0QgUuTFdoGQ6cgiCwwvnoFYHfYJG9MNYOs1AeQZJ6TmtetRGA 4GJFCKjE7/z3UQXdcKF4QurvuSS3rUpLlNdv079TZGAqdTyFMPOUQxchh1IO9/e6yM12 ANuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Ly6M3u/f2mrsij875mBGM9NxRCreikfUQaEpdYBPvgk=; b=HGmKX9hjvlIjzODcPVObyMAJ7xgJ7X/cwJqrVHoOcXwN3nKj0jGJ/4cSzyAvNXo2g0 NnnnwdcIn96/VIDd2VRPCRsJr0JjEW46u4ZsSIq/gr40jNDVu18+rCjifX9eTMhDTNx+ MDy/FQ0XQTckh/EhJjZwM8iX+C9eu6N9LKgIyLFEd4z2bQEtzOTxzN64ho8Yev1bpmar Lg4KezwmLqziW0Yvfpc6fAE7gpjJjyPUp8AkI6tRxPn9O8pRT/LFJbYxP9SEiXN6VPjo 7VA5qdg+2DoyzNVPLFkB0ShIxz+fNQ+csHNg0kYqDFmGDS/KgdMvGpmNOIoMnorNOQvY 1d+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UlSXrFng; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3-v6si20625057pld.593.2018.05.24.02.44.59; Thu, 24 May 2018 02:45:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UlSXrFng; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966607AbeEXJoL (ORCPT + 99 others); Thu, 24 May 2018 05:44:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:55488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966584AbeEXJoH (ORCPT ); Thu, 24 May 2018 05:44:07 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7109B208BA; Thu, 24 May 2018 09:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155047; bh=iyJqK++Ss8qNjqSZpNtrsGKgO1rbChUiZ/QOdR9DREw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UlSXrFnghs6ywxxdDUFIVjyb5n3BTlYicVcxbY0hsUEVqJu5N9YEjD5914JZtWqqN TTnOvtGckDJuB/HhY8qy6nUV9zG/Dw2c8NSEgi0HqT/LQWZ+HV//+PuuDke6+9af+g SIni/EgGQZZLBo/gY0X8kQLp67nwRa7kSQx4DdFA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , "David S. Miller" Subject: [PATCH 4.4 08/92] net_sched: fq: take care of throttled flows before reuse Date: Thu, 24 May 2018 11:37:45 +0200 Message-Id: <20180524093200.019659107@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 7df40c2673a1307c3260aab6f9d4b9bf97ca8fd7 ] Normally, a socket can not be freed/reused unless all its TX packets left qdisc and were TX-completed. However connect(AF_UNSPEC) allows this to happen. With commit fc59d5bdf1e3 ("pkt_sched: fq: clear time_next_packet for reused flows") we cleared f->time_next_packet but took no special action if the flow was still in the throttled rb-tree. Since f->time_next_packet is the key used in the rb-tree searches, blindly clearing it might break rb-tree integrity. We need to make sure the flow is no longer in the rb-tree to avoid this problem. Fixes: fc59d5bdf1e3 ("pkt_sched: fq: clear time_next_packet for reused flows") Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/sch_fq.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) --- a/net/sched/sch_fq.c +++ b/net/sched/sch_fq.c @@ -126,6 +126,28 @@ static bool fq_flow_is_detached(const st return f->next == &detached; } +static bool fq_flow_is_throttled(const struct fq_flow *f) +{ + return f->next == &throttled; +} + +static void fq_flow_add_tail(struct fq_flow_head *head, struct fq_flow *flow) +{ + if (head->first) + head->last->next = flow; + else + head->first = flow; + head->last = flow; + flow->next = NULL; +} + +static void fq_flow_unset_throttled(struct fq_sched_data *q, struct fq_flow *f) +{ + rb_erase(&f->rate_node, &q->delayed); + q->throttled_flows--; + fq_flow_add_tail(&q->old_flows, f); +} + static void fq_flow_set_throttled(struct fq_sched_data *q, struct fq_flow *f) { struct rb_node **p = &q->delayed.rb_node, *parent = NULL; @@ -153,15 +175,6 @@ static void fq_flow_set_throttled(struct static struct kmem_cache *fq_flow_cachep __read_mostly; -static void fq_flow_add_tail(struct fq_flow_head *head, struct fq_flow *flow) -{ - if (head->first) - head->last->next = flow; - else - head->first = flow; - head->last = flow; - flow->next = NULL; -} /* limit number of collected flows per round */ #define FQ_GC_MAX 8 @@ -265,6 +278,8 @@ static struct fq_flow *fq_classify(struc f->socket_hash != sk->sk_hash)) { f->credit = q->initial_quantum; f->socket_hash = sk->sk_hash; + if (fq_flow_is_throttled(f)) + fq_flow_unset_throttled(q, f); f->time_next_packet = 0ULL; } return f; @@ -419,9 +434,7 @@ static void fq_check_throttled(struct fq q->time_next_delayed_flow = f->time_next_packet; break; } - rb_erase(p, &q->delayed); - q->throttled_flows--; - fq_flow_add_tail(&q->old_flows, f); + fq_flow_unset_throttled(q, f); } }