From patchwork Thu Jun 25 11:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1316847 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=jH+e2480; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49sz3Z4svRz9sRW for ; Thu, 25 Jun 2020 21:55:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404659AbgFYLzU (ORCPT ); Thu, 25 Jun 2020 07:55:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:50544 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728063AbgFYLzL (ORCPT ); Thu, 25 Jun 2020 07:55:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593086109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+GyCVjS8LavJYzTtjsaGAZKXMsx/0KStkzJq3dfYbt4=; b=jH+e2480V7wuyhJC/bZoAHb++MviINYUzkq/R47cu+6gSNK+/8hfLs0PKqySEeNV4M8H33 y43gOCjyNwtKktyeSGdpI2VNn0gImOohEUoGE2qiENnWg13Yguh2vrRW7sJzZfoOc1AphE NevEVpDNM3WVXnoyDpX3SCDClwkpBr8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-161-KZNwTZXvPpaQ8abadHxXcg-1; Thu, 25 Jun 2020 07:55:07 -0400 X-MC-Unique: KZNwTZXvPpaQ8abadHxXcg-1 Received: by mail-wm1-f71.google.com with SMTP id l2so6648561wmi.2 for ; Thu, 25 Jun 2020 04:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=+GyCVjS8LavJYzTtjsaGAZKXMsx/0KStkzJq3dfYbt4=; b=Slf8G9OFmVU/Ty8H/E1xyl32+bw9u1A5CTMM9tyxzhu2x1it9Tq7/tv2okm//j5TEk SrkLtOHytzy7yE9gP62Gkd8J91A6pJ2yH+RiWeLHRQrczvmLD0me3e3abx4lXHrv7Sh8 6YEJJEWrcn6u3Bz+x5WSZlkuXDYW/f691xACDS0uGExFNQCL9hQZqW09aBDZF9bk7C0Z gIT5mRFOe8CnQdADyPBsFfH5ub98qpVytzOpOs8gPzYXU4/GH6YgLuV1ggzRK2GFnEGp oJ5UgKd0Y8cL2QljmHOTqEhLmvBe6NnQifq4QQj6ZI864RZGXvFclFDMF7ZWnyrw5kCa vokw== X-Gm-Message-State: AOAM533ChfeBRtcge7H4SqtPl/ieExNYxUHzIwY4hKpYOoehVoYWaIUw GMpm9f32OYE/n4RkUk9jzihgRcFJY9tnvhrzBWR2F0WH6Qm5cGVga65C1Vkjnx1G3j4B3+Gsysf crgKtPINKti/RjAQs X-Received: by 2002:adf:de12:: with SMTP id b18mr29199207wrm.390.1593086106426; Thu, 25 Jun 2020 04:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzixQVDcysECuSK19xqNfgAFGxuWDWVR/lLk1obBH5HLClAUOnlT7+gODGTqff+OoDNWxACMw== X-Received: by 2002:adf:de12:: with SMTP id b18mr29199182wrm.390.1593086106142; Thu, 25 Jun 2020 04:55:06 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id d24sm11573252wmb.45.2020.06.25.04.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 04:55:05 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id F201B1814FA; Thu, 25 Jun 2020 13:55:03 +0200 (CEST) Subject: [PATCH net-next 1/5] sch_cake: fix IP protocol handling in the presence of VLAN tags From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: David Miller Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net Date: Thu, 25 Jun 2020 13:55:03 +0200 Message-ID: <159308610390.190211.17831843954243284203.stgit@toke.dk> In-Reply-To: <159308610282.190211.9431406149182757758.stgit@toke.dk> References: <159308610282.190211.9431406149182757758.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ilya Ponetayev CAKE was using the return value of tc_skb_protocol() and expecting it to be the IP protocol type. This can fail in the presence of QinQ VLAN tags, making CAKE unable to handle ECN marking and diffserv parsing in this case. Fix this by implementing our own version of tc_skb_protocol(), which will use skb->protocol directly, but also parse and skip over any VLAN tags and return the inner protocol number instead. Also fix CE marking by implementing a version of INET_ECN_set_ce() that uses the same parsing routine. Fixes: ea82511518f4 ("sch_cake: Add NAT awareness to packet classifier") Fixes: b2100cc56fca ("sch_cake: Use tc_skb_protocol() helper for getting packet protocol") Fixes: 046f6fd5daef ("sched: Add Common Applications Kept Enhanced (cake) qdisc") Signed-off-by: Ilya Ponetayev [ squash original two patches, rewrite commit message ] Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 60f8ae578819..0f594d88a957 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -497,6 +497,52 @@ static bool cobalt_queue_empty(struct cobalt_vars *vars, return down; } +static __be16 cake_skb_proto(const struct sk_buff *skb) +{ + unsigned int offset = skb_mac_offset(skb) + sizeof(struct ethhdr); + __be16 proto = skb->protocol; + struct vlan_hdr vhdr, *vh; + + while (proto == htons(ETH_P_8021Q) || proto == htons(ETH_P_8021AD)) { + vh = skb_header_pointer(skb, offset, sizeof(vhdr), &vhdr); + if (!vh) + break; + + proto = vh->h_vlan_encapsulated_proto; + offset += sizeof(vhdr); + } + + return proto; +} + +static int cake_set_ce(struct sk_buff *skb) +{ + int wlen = skb_network_offset(skb); + + switch (cake_skb_proto(skb)) { + case htons(ETH_P_IP): + wlen += sizeof(struct iphdr); + if (!pskb_may_pull(skb, wlen) || + skb_try_make_writable(skb, wlen)) + return 0; + + return IP_ECN_set_ce(ip_hdr(skb)); + + case htons(ETH_P_IPV6): + wlen += sizeof(struct ipv6hdr); + if (!pskb_may_pull(skb, wlen) || + skb_try_make_writable(skb, wlen)) + return 0; + + return IP6_ECN_set_ce(skb, ipv6_hdr(skb)); + + default: + return 0; + } + + return 0; +} + /* Call this with a freshly dequeued packet for possible congestion marking. * Returns true as an instruction to drop the packet, false for delivery. */ @@ -549,7 +595,7 @@ static bool cobalt_should_drop(struct cobalt_vars *vars, if (next_due && vars->dropping) { /* Use ECN mark if possible, otherwise drop */ - drop = !(vars->ecn_marked = INET_ECN_set_ce(skb)); + drop = !(vars->ecn_marked = cake_set_ce(skb)); vars->count++; if (!vars->count) @@ -592,7 +638,7 @@ static bool cake_update_flowkeys(struct flow_keys *keys, bool rev = !skb->_nfct, upd = false; __be32 ip; - if (tc_skb_protocol(skb) != htons(ETH_P_IP)) + if (cake_skb_proto(skb) != htons(ETH_P_IP)) return false; if (!nf_ct_get_tuple_skb(&tuple, skb)) @@ -1556,7 +1602,7 @@ static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash) int wlen = skb_network_offset(skb); u8 dscp; - switch (tc_skb_protocol(skb)) { + switch (cake_skb_proto(skb)) { case htons(ETH_P_IP): wlen += sizeof(struct iphdr); if (!pskb_may_pull(skb, wlen) || From patchwork Thu Jun 25 11:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1316845 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EDRoV1WO; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49sz3P2gwpz9sRW for ; Thu, 25 Jun 2020 21:55:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404634AbgFYLzM (ORCPT ); Thu, 25 Jun 2020 07:55:12 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:48051 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404487AbgFYLzK (ORCPT ); Thu, 25 Jun 2020 07:55:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593086109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z98FQrFFI6TBMbCHg6wJVE3Bm8z7MLEcouUfaDkGC9U=; b=EDRoV1WO6mHHlRbFATD/IJgkSb0wwPLWlrO3CXiKwmh1Cs5WSeruM76mEu8vUEqCGobOQ+ P457AmteJk6Ox8kmegJyTaGWYHQkMq7CHmeGXIrbgOVzoqexIWDVqCq9Z0pJqpek+CfeNs a8aF8NKud3P4fV81SFKQ6zen6U9D1nM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-nHnLu6TiOTyXBXNPqdJN9Q-1; Thu, 25 Jun 2020 07:55:07 -0400 X-MC-Unique: nHnLu6TiOTyXBXNPqdJN9Q-1 Received: by mail-wm1-f69.google.com with SMTP id c66so6843863wma.8 for ; Thu, 25 Jun 2020 04:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Z98FQrFFI6TBMbCHg6wJVE3Bm8z7MLEcouUfaDkGC9U=; b=gbJYzPyaE08IOD/PCJ/vxAENoBF3m7VU5vONMCswfvnb5+YLi8TgDhQvVbxsWWMeqO sPZoYEPPNbREPOrcCh41Y9Sxx5PoLOcyQWryvo7abqx6gXdimB4EGOmF6of1xNUXgeS6 V3nM6QAJka+x76tGZM9+G/IoMLRgiWOEOBfyYd6dtw9H4++FuoMbj97NXt3Z0cW2H0ly KRPBi/KCopEzsf64aaD3kFcK8dwTCZaYjINaYuuX6N+hkZAsWpY3lRpUY0oeHR3TKZCA uNaLmI7OvFZcTWRexb9AhZCNJ3ZFpzudzAeCWXs0lcyCwDGWfG+wANdqQDoh/gsSKOIN OouA== X-Gm-Message-State: AOAM532/BvBFek1o4fa3DJ2pc00WlLsNTM+I95qwwe2fnuet4X+PcpfO psGsJoyX8iU+IQ0/KyzqPw3IEkwKrck8lwpwDW64184L05giEYppa8cReOw2UJgm24Jn8L0P4yG hhwWBrO2mEShf8rkG X-Received: by 2002:a05:6000:1190:: with SMTP id g16mr26496833wrx.286.1593086106877; Thu, 25 Jun 2020 04:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPg4eBO5p7yR0vm1SSGeY6BZ0h9JB+JlQVKoq3eiQbTCy2PH9vp5RNyrbVz5+QWDJ1ZZM4Nw== X-Received: by 2002:a05:6000:1190:: with SMTP id g16mr26496817wrx.286.1593086106671; Thu, 25 Jun 2020 04:55:06 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id 207sm13515653wme.13.2020.06.25.04.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 04:55:05 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 151F11814FC; Thu, 25 Jun 2020 13:55:05 +0200 (CEST) Subject: [PATCH net-next 2/5] sch_cake: don't try to reallocate or unshare skb unconditionally From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: David Miller Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net Date: Thu, 25 Jun 2020 13:55:05 +0200 Message-ID: <159308610499.190211.5408420243803826056.stgit@toke.dk> In-Reply-To: <159308610282.190211.9431406149182757758.stgit@toke.dk> References: <159308610282.190211.9431406149182757758.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ilya Ponetayev cake_handle_diffserv() tries to linearize mac and network header parts of skb and to make it writable unconditionally. In some cases it leads to full skb reallocation, which reduces throughput and increases CPU load. Some measurements of IPv4 forward + NAPT on MIPS router with 580 MHz single-core CPU was conducted. It appears that on kernel 4.9 skb_try_make_writable() reallocates skb, if skb was allocated in ethernet driver via so-called 'build skb' method from page cache (it was discovered by strange increase of kmalloc-2048 slab at first). Obtain DSCP value via read-only skb_header_pointer() call, and leave linearization only for DSCP bleaching or ECN CE setting. And, as an additional optimisation, skip diffserv parsing entirely if it is not needed by the current configuration. Fixes: c87b4ecdbe8d ("sch_cake: Make sure we can write the IP header before changing DSCP bits") Signed-off-by: Ilya Ponetayev [ fix a few style issues, reflow commit message ] Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 0f594d88a957..cebcc36755ac 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -1599,30 +1599,49 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free) static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash) { - int wlen = skb_network_offset(skb); + const int offset = skb_network_offset(skb); + u16 *buf, buf_; u8 dscp; switch (cake_skb_proto(skb)) { case htons(ETH_P_IP): - wlen += sizeof(struct iphdr); - if (!pskb_may_pull(skb, wlen) || - skb_try_make_writable(skb, wlen)) + buf = skb_header_pointer(skb, offset, sizeof(buf_), &buf_); + if (unlikely(!buf)) return 0; - dscp = ipv4_get_dsfield(ip_hdr(skb)) >> 2; - if (wash && dscp) + /* ToS is in the second byte of iphdr */ + dscp = ipv4_get_dsfield((struct iphdr *)buf) >> 2; + + if (wash && dscp) { + const int wlen = offset + sizeof(struct iphdr); + + if (!pskb_may_pull(skb, wlen) || + skb_try_make_writable(skb, wlen)) + return 0; + ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, 0); + } + return dscp; case htons(ETH_P_IPV6): - wlen += sizeof(struct ipv6hdr); - if (!pskb_may_pull(skb, wlen) || - skb_try_make_writable(skb, wlen)) + buf = skb_header_pointer(skb, offset, sizeof(buf_), &buf_); + if (unlikely(!buf)) return 0; - dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2; - if (wash && dscp) + /* Traffic class is in the first and second bytes of ipv6hdr */ + dscp = ipv6_get_dsfield((struct ipv6hdr *)buf) >> 2; + + if (wash && dscp) { + const int wlen = offset + sizeof(struct ipv6hdr); + + if (!pskb_may_pull(skb, wlen) || + skb_try_make_writable(skb, wlen)) + return 0; + ipv6_change_dsfield(ipv6_hdr(skb), INET_ECN_MASK, 0); + } + return dscp; case htons(ETH_P_ARP): From patchwork Thu Jun 25 11:55:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1316846 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fUb7c6fo; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49sz3V3Nr5z9sRW for ; Thu, 25 Jun 2020 21:55:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404654AbgFYLzR (ORCPT ); Thu, 25 Jun 2020 07:55:17 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:29329 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404622AbgFYLzM (ORCPT ); Thu, 25 Jun 2020 07:55:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593086111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ld4Tn0L3Y5q550WDsn2Rq+n4f7sbKAnDUn1LS0FKjWo=; b=fUb7c6foeFjkrs98flJzYuaWcwKDP/7j4hE2n6j/SaXVYnWPcLDYr9YNgfVLM08FO/4ZO/ v6PQctW7uMxecP+wX3X0ZblkXNXa/Ks2s93yAwz/r+YEPjv4MgOn6RYH/fRQ38SnvSzAon KD28lFkyl17zc+N+7PsX3ztG3fEDJe8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367-3wrIJhHeO1iNa1N5GyrXMA-1; Thu, 25 Jun 2020 07:55:10 -0400 X-MC-Unique: 3wrIJhHeO1iNa1N5GyrXMA-1 Received: by mail-wm1-f69.google.com with SMTP id o138so5595540wme.4 for ; Thu, 25 Jun 2020 04:55:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Ld4Tn0L3Y5q550WDsn2Rq+n4f7sbKAnDUn1LS0FKjWo=; b=iPgtPKiRmtCG0CtdB1T5ExhzonOp+hHky0AJ9LIN78uR+WvYvSEGakdWjvRWvQDYt4 8nBq4nlJAUKC1PaW3lJeWIfQKEHgI2UX+HKqEDAI4H0fgZDZ6lhYxFkd6Isz68SDduRU QQ3Nbpq+15A9vXXcdYK8vLs0zwpgpzGRLBq9batV1lve3NWlXLh2UbzWtqmBPRpQZFdp O+kC+Fz2F8kB/MsC+i2XQtlxoJI4Aa8cUvQFkGT00MBLnHjIyTqf5t4zh19PUoZ+2NEt n+ctFJvGv/yxGiMP6ZqUONIpVi3b8CnbJfGoOE8WKKlkZ7f/CUpw9swo/xeNnB2mAWwA 4N9Q== X-Gm-Message-State: AOAM533ZuVMMkwMCdq6o5XcnQ32GxIhSdLIP8f46f0yL4GFGNhEo1voX lGbIzHB63dY/s9ezIfjMKUAMXqBmoL9PMB4FfoKTp/o8cDjOWVXhlF+9OueaD755cjTMCsF24Ah 6sRgk0NVqG7Ylz4Uy X-Received: by 2002:a1c:dd86:: with SMTP id u128mr2946090wmg.123.1593086108601; Thu, 25 Jun 2020 04:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOOk93C4793Qkapy2JpGSur7LO8UZd2j77wFa1YhFtXy6B7IQG+K6TsroaWQhOPlXEUAeAwA== X-Received: by 2002:a1c:dd86:: with SMTP id u128mr2946062wmg.123.1593086108132; Thu, 25 Jun 2020 04:55:08 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id a22sm12361179wmj.9.2020.06.25.04.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 04:55:06 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 2B1EF1814FE; Thu, 25 Jun 2020 13:55:06 +0200 (CEST) Subject: [PATCH net-next 3/5] sch_cake: don't call diffserv parsing code when it is not needed From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: David Miller Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net Date: Thu, 25 Jun 2020 13:55:06 +0200 Message-ID: <159308610609.190211.12172433725292686379.stgit@toke.dk> In-Reply-To: <159308610282.190211.9431406149182757758.stgit@toke.dk> References: <159308610282.190211.9431406149182757758.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen As a further optimisation of the diffserv parsing codepath, we can skip it entirely if CAKE is neither configured to use diffserv-based classification, nor to zero out the diffserv bits. Fixes: c87b4ecdbe8d ("sch_cake: Make sure we can write the IP header before changing DSCP bits") Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index cebcc36755ac..958523c777be 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -1597,7 +1597,7 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free) return idx + (tin << 16); } -static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash) +static u8 cake_handle_diffserv(struct sk_buff *skb, bool wash) { const int offset = skb_network_offset(skb); u16 *buf, buf_; @@ -1658,14 +1658,17 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch, { struct cake_sched_data *q = qdisc_priv(sch); u32 tin, mark; + bool wash; u8 dscp; /* Tin selection: Default to diffserv-based selection, allow overriding - * using firewall marks or skb->priority. + * using firewall marks or skb->priority. Call DSCP parsing early if + * wash is enabled, otherwise defer to below to skip unneeded parsing. */ - dscp = cake_handle_diffserv(skb, - q->rate_flags & CAKE_FLAG_WASH); mark = (skb->mark & q->fwmark_mask) >> q->fwmark_shft; + wash = !!(q->rate_flags & CAKE_FLAG_WASH); + if (wash) + dscp = cake_handle_diffserv(skb, wash); if (q->tin_mode == CAKE_DIFFSERV_BESTEFFORT) tin = 0; @@ -1679,6 +1682,8 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch, tin = q->tin_order[TC_H_MIN(skb->priority) - 1]; else { + if (!wash) + dscp = cake_handle_diffserv(skb, wash); tin = q->tin_index[dscp]; if (unlikely(tin >= q->tin_cnt)) From patchwork Thu Jun 25 11:55:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1316849 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hoNqiT66; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49sz3g0b6wz9sRW for ; Thu, 25 Jun 2020 21:55:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404676AbgFYLzZ (ORCPT ); Thu, 25 Jun 2020 07:55:25 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:58555 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404652AbgFYLzR (ORCPT ); Thu, 25 Jun 2020 07:55:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593086116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wGT3qBYmtlNm7VbabgpoFKFwexBpZntpyA+fDg/nDwk=; b=hoNqiT66OK2wafxBqkMHVDdqC76LN6sK8GeX27ChJSjnfoezCZr6AG6H4r5rl7GvgntedF SKsQ1S0HzPQO9hRSN/CjLMrWedm2v+2uYPBsxZQi9rMfEfDa3zZFD4W4tkDXwA9+vlwkU3 3tpu0WhAYK9fPzC3YJk+v8roiV2g/vM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-V82uLNafMo2dli1gsW-Eeg-1; Thu, 25 Jun 2020 07:55:10 -0400 X-MC-Unique: V82uLNafMo2dli1gsW-Eeg-1 Received: by mail-wm1-f72.google.com with SMTP id t18so6849295wmj.5 for ; Thu, 25 Jun 2020 04:55:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=wGT3qBYmtlNm7VbabgpoFKFwexBpZntpyA+fDg/nDwk=; b=WcUNS/tnPDXAqBq+G68zul/Dt5JzAi3F7mbR6NNw9j1uImi4Ji0yUynCxHl5WyrkVG maYtLbU3QZ1rX96kStca3QWmb2aqcM8fPaLGnEMExMOOXGkrnG2REWWnum+pQ0Er9sao n4S550ntmX1dHB79ilFwL8p1hUGU8sRuhJ6u9cctTMQgEGQ5F5MhTI/cGo3eTC7xWzY5 Au76XlHkHGIFez7Yh2GDMroy6luD8IxgXWxhDXM+K6z46o7XHgzoPnx9dM1XjpaYA+qU 8tlo7cBWiq44ESz51hlkrtYrIkPqo/QMM897NlX+IwB/oUmOu1EXpV8FCPppiqHd3s36 AUFQ== X-Gm-Message-State: AOAM531PWGSvYNNJmGHwLF1CsMWl5o9sV8Gl6mimC2jYzcUzW6lNO5ci R70RGX0QXlb4Qm1wWvtemCJaj5mBOV6/todwRBAA1lIfBoqysBet4VWv57ikw0JCeVcO5dKu0S3 fDIf2E3flwjhkfzQN X-Received: by 2002:adf:a507:: with SMTP id i7mr39279920wrb.0.1593086109443; Thu, 25 Jun 2020 04:55:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGfAxqBQdT54TXBka/hC/Yk1+w80El0LGJCtPMPSOE33IV6f7u7la2SMPi+3u5TRNoTzTQSw== X-Received: by 2002:adf:a507:: with SMTP id i7mr39279899wrb.0.1593086109201; Thu, 25 Jun 2020 04:55:09 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id g16sm27455995wrh.91.2020.06.25.04.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 04:55:08 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 409631814FA; Thu, 25 Jun 2020 13:55:07 +0200 (CEST) Subject: [PATCH net-next 4/5] sch_cake: add RFC 8622 LE PHB support to CAKE diffserv handling From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: David Miller Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net Date: Thu, 25 Jun 2020 13:55:07 +0200 Message-ID: <159308610718.190211.15767931665695188384.stgit@toke.dk> In-Reply-To: <159308610282.190211.9431406149182757758.stgit@toke.dk> References: <159308610282.190211.9431406149182757758.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Kevin Darbyshire-Bryant Change tin mapping on diffserv3, 4 & 8 for LE PHB support, in essence making LE a member of the Bulk tin. Bulk has the least priority and minimum of 1/16th total bandwidth in the face of higher priority traffic. NB: Diffserv 3 & 4 swap tin 0 & 1 priorities from the default order as found in diffserv8, in case anyone is wondering why it looks a bit odd. Signed-off-by: Kevin Darbyshire-Bryant [ reword commit message slightly ] Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 958523c777be..78a702a4e1d4 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -312,8 +312,8 @@ static const u8 precedence[] = { }; static const u8 diffserv8[] = { - 2, 5, 1, 2, 4, 2, 2, 2, - 0, 2, 1, 2, 1, 2, 1, 2, + 2, 0, 1, 2, 4, 2, 2, 2, + 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 4, 2, 4, 2, 4, 2, 3, 2, 3, 2, 3, 2, 3, 2, 6, 2, 3, 2, 3, 2, 3, 2, @@ -323,7 +323,7 @@ static const u8 diffserv8[] = { }; static const u8 diffserv4[] = { - 0, 2, 0, 0, 2, 0, 0, 0, + 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, @@ -334,7 +334,7 @@ static const u8 diffserv4[] = { }; static const u8 diffserv3[] = { - 0, 0, 0, 0, 2, 0, 0, 0, + 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, From patchwork Thu Jun 25 11:55:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1316848 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O38Epymf; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49sz3c6hdnz9sT9 for ; Thu, 25 Jun 2020 21:55:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404671AbgFYLzX (ORCPT ); Thu, 25 Jun 2020 07:55:23 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57975 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404646AbgFYLzO (ORCPT ); Thu, 25 Jun 2020 07:55:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593086113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oS+tjJRTXWkIBJiF60BGiX9Deix+p/MPPW7LrDM4LQg=; b=O38EpymfpLv7ScNU6vfp3wvsRk2hHC4rBOM6+haqfQzImVkz/cHiY5qzN2xLngpmSrbQMj /0EKCxxnqNEVWYABJOsMUB4y1GWSTuJCV/sKo8WOqpssjW+hgsYt12GmAkINiF9bwuRDyB tkeKzmpjJC8wzbNzbrkNOCW+RcPjlTY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-sRlSKAgANMGizqvipY8FCw-1; Thu, 25 Jun 2020 07:55:11 -0400 X-MC-Unique: sRlSKAgANMGizqvipY8FCw-1 Received: by mail-wm1-f70.google.com with SMTP id a21so6639392wmd.0 for ; Thu, 25 Jun 2020 04:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=oS+tjJRTXWkIBJiF60BGiX9Deix+p/MPPW7LrDM4LQg=; b=UyjuKcYgb2kv+gpqJeh9RifBogwxkXx33DRAXL/iM23HAI3tpM56GwxKedN1OYHdqU krGxRO70emjIP8p8ZK3WnXMj6G6RcyRU/xs9XdTKKFVpRAZ3psbREDo6dshD26K4Ka4q wMNn151m6+HG3WaH98RDGj1VJTFHvhqEx9huoF3Ej0Z7bdMcJZ/OUcgyg+DnhnOop8X0 7armvVCplnzPYWO1fwsQuXVFsWnl0qDSqdmlumSM5y3DXd6X7hY+Hte/1J103+R+oDaR NRylsG1mWA45t4/+AkC6u15L5RzZj16j/Uuan39x30MMr0oEb292JIuZCjf4Crkr5q6z eaMg== X-Gm-Message-State: AOAM531OT6iNajloGJDrkfjvbr4DfP/lNwo7ByQSDZww05DpihmafvvT nbQxlA9gWKJAUytCp8uMkgPZRGCIvRATwDAyKQ+l3xdOqxbmnF3ILfg1ASkhyF90bMyrypZPFDD x6R8g/yKdtpm9j0+G X-Received: by 2002:adf:a507:: with SMTP id i7mr39280026wrb.0.1593086110799; Thu, 25 Jun 2020 04:55:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjqfJVd3WkZS8rf/Eu0Ta02+8zhyOKxM75IA3tL9xrh0OYYczzH8cn3T+qkjTjJplc9T9E0g== X-Received: by 2002:adf:a507:: with SMTP id i7mr39280013wrb.0.1593086110634; Thu, 25 Jun 2020 04:55:10 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id v20sm31975789wrb.51.2020.06.25.04.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 04:55:09 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 5729F1814F9; Thu, 25 Jun 2020 13:55:08 +0200 (CEST) Subject: [PATCH net-next 5/5] sch_cake: fix a few style nits From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: David Miller Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net Date: Thu, 25 Jun 2020 13:55:08 +0200 Message-ID: <159308610826.190211.15296927891260930838.stgit@toke.dk> In-Reply-To: <159308610282.190211.9431406149182757758.stgit@toke.dk> References: <159308610282.190211.9431406149182757758.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen I spotted a few nits when comparing the in-tree version of sch_cake with the out-of-tree one: A redundant error variable declaration shadowing an outer declaration, and an indentation alignment issue. Fix both of these to minimise the delta. Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 78a702a4e1d4..e075913b2fd7 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -2761,7 +2761,7 @@ static int cake_init(struct Qdisc *sch, struct nlattr *opt, qdisc_watchdog_init(&q->watchdog, sch); if (opt) { - int err = cake_change(sch, opt, extack); + err = cake_change(sch, opt, extack); if (err) return err; @@ -3078,7 +3078,7 @@ static int cake_dump_class_stats(struct Qdisc *sch, unsigned long cl, PUT_STAT_S32(BLUE_TIMER_US, ktime_to_us( ktime_sub(now, - flow->cvars.blue_timer))); + flow->cvars.blue_timer))); } if (flow->cvars.dropping) { PUT_STAT_S32(DROP_NEXT_US,