From patchwork Thu Feb 14 13:23:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158384 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1366603jaa; Thu, 14 Feb 2019 05:24:26 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ3n3lExQMGgudJctvNX8vXMaHojoYcYFQn6yrsMLcbPJqpo9OEW4CZnvBX1IFhL9K98FHo X-Received: by 2002:a17:902:42e4:: with SMTP id h91mr4249387pld.18.1550150666513; Thu, 14 Feb 2019 05:24:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150666; cv=none; d=google.com; s=arc-20160816; b=nJL4n9q5zaEyimbmRDGvKpepCnba+hV3AdKWd53HoWHKKPkEhQEnPLRv4KrySG7waY zbCkKw+OIUhkVJx14phISlSlFnIX4IHnQY3iNvKjW65r5M5ZVb5k4qmZPAWM6GHvbfsC jsSPQWvDW4KTCu9oYBGNDjWCf2F/hj5ODVdWVYYYf2BoAkyIr0CVYHZlYELiyRQnrSgy AwNtuzE+YkXGJ6OsAGS7jkJPQgaiWOpdbNkZzo/AwNMVkn3VfCNpkvX9mQwrkwsQO6k/ ZnEs4OkYU+fuEnWjNwp09HJEwz+VwtkVRWMwNlePldZUjq/H6tyZXSGkSkxm68Qy6+SN jeaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bjMeiFZNITG8OPJH56nNrseg+x+kAYU9dz39YKkkRf4=; b=W7rt3LTnaOQoB/ujwNVtLG4VGQHKeX5y6m6IGIJW01QnjJKS9CpHsk9F3ma1/E0sEH Otq73LOeHItepZggjYxBzLrZKc+JPme3wAMDZDZSXwdiwYTjBMJIhmWYz6M4vXtocNbI S3wyRXacJ3i67cniYFv0llUPqb0rqJWAPct+6iey7nVV+IkZakhNqU44Os4mW3N8tV70 cZuXnP83e/nXhrbpXqyUUpV5r8mGP6/PKNpnRqM4YM2oespXf3ITqIav9fO8kMo2ruqT Tf9t/oMJylawbgqLRIxMfT2EVe3QKgcn5GzNDyJ7lUby0eDniysdicDWz12veSHcNMv8 Jwlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BuwAe6l0; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.26; Thu, 14 Feb 2019 05:24:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=BuwAe6l0; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407023AbfBNNYZ (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:25 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:43518 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394723AbfBNNYZ (ORCPT ); Thu, 14 Feb 2019 08:24:25 -0500 Received: by mail-lf1-f65.google.com with SMTP id j1so4509186lfb.10 for ; Thu, 14 Feb 2019 05:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bjMeiFZNITG8OPJH56nNrseg+x+kAYU9dz39YKkkRf4=; b=BuwAe6l0X+zrXpmI3uw0hSZCZplUj5VAK79QhSpyHqHvQ1ESHwSpOgSVF7lH0jlV6f p988/wRsT/upRlYax3ZzH/lw1CQXaZ0h8GZew3y53JhlJ4+QWfnmAYgbk532BLZE90UB V9iie0MVKrHkcJW4+moZcvaPjRAEAMuWOaOm33A2/HG+liskJ+jDCtyzYLCCasNgZxXo 2NALAxl1qCIIId2ahMInl4SSPzhcjZeQPaSrpJaekWpllfTr14bWnoGIhudotNYS0z3k BaZBD7KpBGGVLYbOzq9oFhfe/a/RUc8lxgDJ+GMZtU/cB4mp8O4c31mEakyxFBtmbCup SZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bjMeiFZNITG8OPJH56nNrseg+x+kAYU9dz39YKkkRf4=; b=JJNL2R4e+aw8rhCZ5dH9qMHilpNl7u6Pg1Sw7xE1QHusQSq7LW0JEHTogua+UARKM3 8ulgMIS2PvC7KJuAwFsNGxi7lniRyvZPddv4DDoizMtBtaouR7BaVQyfvjauXhHNaAyp aL8E1nCZ/oZdicNlKNBHTpO6S19MzZHHQ5K2HywAg4E3Uf8vz6gww6EansbBBRULoeGS JAuZEjCDVuxWAnW5Vc2NgWk50x5TztFDwU4AyQiDFO4pS2HlD/KOUihpKvWhz5zDfFTj /CwHTVzIx9UsU/Lxk2MANW9ZFT71pSfILVWJm5liIbPbF10jRzWWFVYQhtb5DpzoY1up +gjg== X-Gm-Message-State: AHQUAuYI5mlidccQsNxMY/4CNDZSUvLrxNTyS/cNzsnUtMQDe31Zhgif b/nkvlUEeZcRiJAX25AQ2vUCOw== X-Received: by 2002:a19:f249:: with SMTP id d9mr2294964lfk.83.1550150661606; Thu, 14 Feb 2019 05:24:21 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:20 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , =?utf-8?q?Linus_L=C3=BCssing?= , Nikolay Aleksandrov , Linus Walleij Subject: [PATCH 1/8 v3] bridge: multicast to unicast Date: Thu, 14 Feb 2019 14:23:56 +0100 Message-Id: <20190214132403.10687-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Felix Fietkau commit 6db6f0eae6052b70885562e1733896647ec1d807 upstream. Implements an optional, per bridge port flag and feature to deliver multicast packets to any host on the according port via unicast individually. This is done by copying the packet per host and changing the multicast destination MAC to a unicast one accordingly. multicast-to-unicast works on top of the multicast snooping feature of the bridge. Which means unicast copies are only delivered to hosts which are interested in it and signalized this via IGMP/MLD reports previously. This feature is intended for interface types which have a more reliable and/or efficient way to deliver unicast packets than broadcast ones (e.g. wifi). However, it should only be enabled on interfaces where no IGMPv2/MLDv1 report suppression takes place. This feature is disabled by default. The initial patch and idea is from Felix Fietkau. Signed-off-by: Felix Fietkau [linus.luessing@c0d3.blue: various bug + style fixes, commit message] Signed-off-by: Linus Lüssing Reviewed-by: Nikolay Aleksandrov Signed-off-by: David S. Miller Signed-off-by: Linus Walleij --- - This was applied upstream in v4.11 - Should be applied to stable v4.9.y --- include/linux/if_bridge.h | 1 + include/uapi/linux/if_link.h | 1 + net/bridge/br_forward.c | 39 +++++++++++++++- net/bridge/br_mdb.c | 2 +- net/bridge/br_multicast.c | 90 ++++++++++++++++++++++++++---------- net/bridge/br_netlink.c | 5 ++ net/bridge/br_private.h | 3 +- net/bridge/br_sysfs_if.c | 2 + 8 files changed, 114 insertions(+), 29 deletions(-) -- 2.20.1 diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index c6587c01d951..debc9d5904e5 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -46,6 +46,7 @@ struct br_ip_list { #define BR_LEARNING_SYNC BIT(9) #define BR_PROXYARP_WIFI BIT(10) #define BR_MCAST_FLOOD BIT(11) +#define BR_MULTICAST_TO_UNICAST BIT(12) #define BR_DEFAULT_AGEING_TIME (300 * HZ) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index b4fba662cd32..ee4d632d089d 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -319,6 +319,7 @@ enum { IFLA_BRPORT_MULTICAST_ROUTER, IFLA_BRPORT_PAD, IFLA_BRPORT_MCAST_FLOOD, + IFLA_BRPORT_MCAST_TO_UCAST, __IFLA_BRPORT_MAX }; #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 5b675695c661..30afa130287e 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -173,6 +173,31 @@ static struct net_bridge_port *maybe_deliver( return p; } +static void maybe_deliver_addr(struct net_bridge_port *p, struct sk_buff *skb, + const unsigned char *addr, bool local_orig) +{ + struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev; + const unsigned char *src = eth_hdr(skb)->h_source; + + if (!should_deliver(p, skb)) + return; + + /* Even with hairpin, no soliloquies - prevent breaking IPv6 DAD */ + if (skb->dev == p->dev && ether_addr_equal(src, addr)) + return; + + skb = skb_copy(skb, GFP_ATOMIC); + if (!skb) { + dev->stats.tx_dropped++; + return; + } + + if (!is_broadcast_ether_addr(addr)) + memcpy(eth_hdr(skb)->h_dest, addr, ETH_ALEN); + + __br_forward(p, skb, local_orig); +} + /* called under rcu_read_lock */ void br_flood(struct net_bridge *br, struct sk_buff *skb, enum br_pkt_type pkt_type, bool local_rcv, bool local_orig) @@ -241,10 +266,20 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, rport = rp ? hlist_entry(rp, struct net_bridge_port, rlist) : NULL; - port = (unsigned long)lport > (unsigned long)rport ? - lport : rport; + if ((unsigned long)lport > (unsigned long)rport) { + port = lport; + + if (port->flags & BR_MULTICAST_TO_UNICAST) { + maybe_deliver_addr(lport, skb, p->eth_addr, + local_orig); + goto delivered; + } + } else { + port = rport; + } prev = maybe_deliver(prev, port, skb, local_orig); +delivered: if (IS_ERR(prev)) goto out; if (prev == port) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index 6406010e155b..57e94a1b57e1 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -532,7 +532,7 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port, break; } - p = br_multicast_new_port_group(port, group, *pp, state); + p = br_multicast_new_port_group(port, group, *pp, state, NULL); if (unlikely(!p)) return -ENOMEM; rcu_assign_pointer(*pp, p); diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 4bd57507b9a4..1183c5fcd9d2 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -42,12 +42,14 @@ static void br_multicast_add_router(struct net_bridge *br, static void br_ip4_multicast_leave_group(struct net_bridge *br, struct net_bridge_port *port, __be32 group, - __u16 vid); + __u16 vid, + const unsigned char *src); + #if IS_ENABLED(CONFIG_IPV6) static void br_ip6_multicast_leave_group(struct net_bridge *br, struct net_bridge_port *port, const struct in6_addr *group, - __u16 vid); + __u16 vid, const unsigned char *src); #endif unsigned int br_mdb_rehash_seq; @@ -658,7 +660,8 @@ struct net_bridge_port_group *br_multicast_new_port_group( struct net_bridge_port *port, struct br_ip *group, struct net_bridge_port_group __rcu *next, - unsigned char flags) + unsigned char flags, + const unsigned char *src) { struct net_bridge_port_group *p; @@ -673,12 +676,32 @@ struct net_bridge_port_group *br_multicast_new_port_group( hlist_add_head(&p->mglist, &port->mglist); setup_timer(&p->timer, br_multicast_port_group_expired, (unsigned long)p); + + if (src) + memcpy(p->eth_addr, src, ETH_ALEN); + else + memset(p->eth_addr, 0xff, ETH_ALEN); + return p; } +static bool br_port_group_equal(struct net_bridge_port_group *p, + struct net_bridge_port *port, + const unsigned char *src) +{ + if (p->port != port) + return false; + + if (!(port->flags & BR_MULTICAST_TO_UNICAST)) + return true; + + return ether_addr_equal(src, p->eth_addr); +} + static int br_multicast_add_group(struct net_bridge *br, struct net_bridge_port *port, - struct br_ip *group) + struct br_ip *group, + const unsigned char *src) { struct net_bridge_mdb_entry *mp; struct net_bridge_port_group *p; @@ -705,13 +728,13 @@ static int br_multicast_add_group(struct net_bridge *br, for (pp = &mp->ports; (p = mlock_dereference(*pp, br)) != NULL; pp = &p->next) { - if (p->port == port) + if (br_port_group_equal(p, port, src)) goto found; if ((unsigned long)p->port < (unsigned long)port) break; } - p = br_multicast_new_port_group(port, group, *pp, 0); + p = br_multicast_new_port_group(port, group, *pp, 0, src); if (unlikely(!p)) goto err; rcu_assign_pointer(*pp, p); @@ -730,7 +753,8 @@ static int br_multicast_add_group(struct net_bridge *br, static int br_ip4_multicast_add_group(struct net_bridge *br, struct net_bridge_port *port, __be32 group, - __u16 vid) + __u16 vid, + const unsigned char *src) { struct br_ip br_group; @@ -741,14 +765,15 @@ static int br_ip4_multicast_add_group(struct net_bridge *br, br_group.proto = htons(ETH_P_IP); br_group.vid = vid; - return br_multicast_add_group(br, port, &br_group); + return br_multicast_add_group(br, port, &br_group, src); } #if IS_ENABLED(CONFIG_IPV6) static int br_ip6_multicast_add_group(struct net_bridge *br, struct net_bridge_port *port, const struct in6_addr *group, - __u16 vid) + __u16 vid, + const unsigned char *src) { struct br_ip br_group; @@ -759,7 +784,7 @@ static int br_ip6_multicast_add_group(struct net_bridge *br, br_group.proto = htons(ETH_P_IPV6); br_group.vid = vid; - return br_multicast_add_group(br, port, &br_group); + return br_multicast_add_group(br, port, &br_group, src); } #endif @@ -1028,6 +1053,7 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br, struct sk_buff *skb, u16 vid) { + const unsigned char *src; struct igmpv3_report *ih; struct igmpv3_grec *grec; int i; @@ -1068,12 +1094,14 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br, continue; } + src = eth_hdr(skb)->h_source; if ((type == IGMPV3_CHANGE_TO_INCLUDE || type == IGMPV3_MODE_IS_INCLUDE) && ntohs(grec->grec_nsrcs) == 0) { - br_ip4_multicast_leave_group(br, port, group, vid); + br_ip4_multicast_leave_group(br, port, group, vid, src); } else { - err = br_ip4_multicast_add_group(br, port, group, vid); + err = br_ip4_multicast_add_group(br, port, group, vid, + src); if (err) break; } @@ -1088,6 +1116,7 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br, struct sk_buff *skb, u16 vid) { + const unsigned char *src; struct icmp6hdr *icmp6h; struct mld2_grec *grec; int i; @@ -1135,14 +1164,16 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br, continue; } + src = eth_hdr(skb)->h_source; if ((grec->grec_type == MLD2_CHANGE_TO_INCLUDE || grec->grec_type == MLD2_MODE_IS_INCLUDE) && ntohs(*nsrcs) == 0) { br_ip6_multicast_leave_group(br, port, &grec->grec_mca, - vid); + vid, src); } else { err = br_ip6_multicast_add_group(br, port, - &grec->grec_mca, vid); + &grec->grec_mca, vid, + src); if (err) break; } @@ -1465,7 +1496,8 @@ br_multicast_leave_group(struct net_bridge *br, struct net_bridge_port *port, struct br_ip *group, struct bridge_mcast_other_query *other_query, - struct bridge_mcast_own_query *own_query) + struct bridge_mcast_own_query *own_query, + const unsigned char *src) { struct net_bridge_mdb_htable *mdb; struct net_bridge_mdb_entry *mp; @@ -1489,7 +1521,7 @@ br_multicast_leave_group(struct net_bridge *br, for (pp = &mp->ports; (p = mlock_dereference(*pp, br)) != NULL; pp = &p->next) { - if (p->port != port) + if (!br_port_group_equal(p, port, src)) continue; rcu_assign_pointer(*pp, p->next); @@ -1520,7 +1552,7 @@ br_multicast_leave_group(struct net_bridge *br, for (p = mlock_dereference(mp->ports, br); p != NULL; p = mlock_dereference(p->next, br)) { - if (p->port != port) + if (!br_port_group_equal(p, port, src)) continue; if (!hlist_unhashed(&p->mglist) && @@ -1571,7 +1603,8 @@ br_multicast_leave_group(struct net_bridge *br, static void br_ip4_multicast_leave_group(struct net_bridge *br, struct net_bridge_port *port, __be32 group, - __u16 vid) + __u16 vid, + const unsigned char *src) { struct br_ip br_group; struct bridge_mcast_own_query *own_query; @@ -1586,14 +1619,15 @@ static void br_ip4_multicast_leave_group(struct net_bridge *br, br_group.vid = vid; br_multicast_leave_group(br, port, &br_group, &br->ip4_other_query, - own_query); + own_query, src); } #if IS_ENABLED(CONFIG_IPV6) static void br_ip6_multicast_leave_group(struct net_bridge *br, struct net_bridge_port *port, const struct in6_addr *group, - __u16 vid) + __u16 vid, + const unsigned char *src) { struct br_ip br_group; struct bridge_mcast_own_query *own_query; @@ -1608,7 +1642,7 @@ static void br_ip6_multicast_leave_group(struct net_bridge *br, br_group.vid = vid; br_multicast_leave_group(br, port, &br_group, &br->ip6_other_query, - own_query); + own_query, src); } #endif @@ -1651,6 +1685,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, u16 vid) { struct sk_buff *skb_trimmed = NULL; + const unsigned char *src; struct igmphdr *ih; int err; @@ -1666,13 +1701,14 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, } ih = igmp_hdr(skb); + src = eth_hdr(skb)->h_source; BR_INPUT_SKB_CB(skb)->igmp = ih->type; switch (ih->type) { case IGMP_HOST_MEMBERSHIP_REPORT: case IGMPV2_HOST_MEMBERSHIP_REPORT: BR_INPUT_SKB_CB(skb)->mrouters_only = 1; - err = br_ip4_multicast_add_group(br, port, ih->group, vid); + err = br_ip4_multicast_add_group(br, port, ih->group, vid, src); break; case IGMPV3_HOST_MEMBERSHIP_REPORT: err = br_ip4_multicast_igmp3_report(br, port, skb_trimmed, vid); @@ -1681,7 +1717,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, err = br_ip4_multicast_query(br, port, skb_trimmed, vid); break; case IGMP_HOST_LEAVE_MESSAGE: - br_ip4_multicast_leave_group(br, port, ih->group, vid); + br_ip4_multicast_leave_group(br, port, ih->group, vid, src); break; } @@ -1701,6 +1737,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br, u16 vid) { struct sk_buff *skb_trimmed = NULL; + const unsigned char *src; struct mld_msg *mld; int err; @@ -1720,8 +1757,10 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br, switch (mld->mld_type) { case ICMPV6_MGM_REPORT: + src = eth_hdr(skb)->h_source; BR_INPUT_SKB_CB(skb)->mrouters_only = 1; - err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid); + err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid, + src); break; case ICMPV6_MLD2_REPORT: err = br_ip6_multicast_mld2_report(br, port, skb_trimmed, vid); @@ -1730,7 +1769,8 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br, err = br_ip6_multicast_query(br, port, skb_trimmed, vid); break; case ICMPV6_MGM_REDUCTION: - br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid); + src = eth_hdr(skb)->h_source; + br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid, src); break; } diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 4f831225d34f..a62deecd471b 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -123,6 +123,7 @@ static inline size_t br_port_info_size(void) + nla_total_size(1) /* IFLA_BRPORT_GUARD */ + nla_total_size(1) /* IFLA_BRPORT_PROTECT */ + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */ + + nla_total_size(1) /* IFLA_BRPORT_MCAST_TO_UCAST */ + nla_total_size(1) /* IFLA_BRPORT_LEARNING */ + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */ + nla_total_size(1) /* IFLA_BRPORT_PROXYARP */ @@ -173,6 +174,8 @@ static int br_port_fill_attrs(struct sk_buff *skb, !!(p->flags & BR_ROOT_BLOCK)) || nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE, !!(p->flags & BR_MULTICAST_FAST_LEAVE)) || + nla_put_u8(skb, IFLA_BRPORT_MCAST_TO_UCAST, + !!(p->flags & BR_MULTICAST_TO_UNICAST)) || nla_put_u8(skb, IFLA_BRPORT_LEARNING, !!(p->flags & BR_LEARNING)) || nla_put_u8(skb, IFLA_BRPORT_UNICAST_FLOOD, !!(p->flags & BR_FLOOD)) || @@ -586,6 +589,7 @@ static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = { [IFLA_BRPORT_PROXYARP] = { .type = NLA_U8 }, [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NLA_U8 }, [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NLA_U8 }, + [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NLA_U8 }, }; /* Change the state of the port and notify spanning tree */ @@ -636,6 +640,7 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[]) br_set_port_flag(p, tb, IFLA_BRPORT_LEARNING, BR_LEARNING); br_set_port_flag(p, tb, IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD); br_set_port_flag(p, tb, IFLA_BRPORT_MCAST_FLOOD, BR_MCAST_FLOOD); + br_set_port_flag(p, tb, IFLA_BRPORT_MCAST_TO_UCAST, BR_MULTICAST_TO_UNICAST); br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP, BR_PROXYARP); br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP_WIFI, BR_PROXYARP_WIFI); diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 1b63177e0ccd..f038cfdc8d98 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -177,6 +177,7 @@ struct net_bridge_port_group { struct timer_list timer; struct br_ip addr; unsigned char flags; + unsigned char eth_addr[ETH_ALEN]; }; struct net_bridge_mdb_entry @@ -591,7 +592,7 @@ void br_multicast_free_pg(struct rcu_head *head); struct net_bridge_port_group * br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group, struct net_bridge_port_group __rcu *next, - unsigned char flags); + unsigned char flags, const unsigned char *src); void br_mdb_init(void); void br_mdb_uninit(void); void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port, diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c index abf711112418..228ebcd4fa51 100644 --- a/net/bridge/br_sysfs_if.c +++ b/net/bridge/br_sysfs_if.c @@ -188,6 +188,7 @@ static BRPORT_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router, store_multicast_router); BRPORT_ATTR_FLAG(multicast_fast_leave, BR_MULTICAST_FAST_LEAVE); +BRPORT_ATTR_FLAG(multicast_to_unicast, BR_MULTICAST_TO_UNICAST); #endif static const struct brport_attribute *brport_attrs[] = { @@ -214,6 +215,7 @@ static const struct brport_attribute *brport_attrs[] = { #ifdef CONFIG_BRIDGE_IGMP_SNOOPING &brport_attr_multicast_router, &brport_attr_multicast_fast_leave, + &brport_attr_multicast_to_unicast, #endif &brport_attr_proxyarp, &brport_attr_proxyarp_wifi, From patchwork Thu Feb 14 13:23:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158385 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1366685jaa; Thu, 14 Feb 2019 05:24:31 -0800 (PST) X-Google-Smtp-Source: AHgI3IYzknldgL8Nbk/nSzfhkAYY9Ie47XQ1LCMN2sXTtFD18QiiC8ov5/CwE3ivb1UnJHGWysmf X-Received: by 2002:a62:9683:: with SMTP id s3mr4042805pfk.60.1550150671173; Thu, 14 Feb 2019 05:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150671; cv=none; d=google.com; s=arc-20160816; b=foGtaaqstvvspopws8aXwZ1kuRsc+Cx11CjDh5HCr7p+ewdY7XcC/i4W/Rvf3WzSbU /A1JvunwWfj1TMtzKrWWsy4eEBPlinj48k1Rs6N5nHRME0cHY4MrzEyEXrA5lnPRWiCo NDWxKnSwfFlCpGMc0Sb1zFTTjAb7F/0Shp1sfoR2hcSod8jVgqcdgZzl1Srg6UnYKUzx lqfaMzFiBz3W6ulYhRMLKuYOjVf5aSvszk25dGJdYtSU2+EuuFtmLQ+sB5uKmUtbi+wF bOKbGCfz759CJMj+IB2zd1XiiWCvXU0uOnw+jSIvJxA8h0YiKj9F2f2VzrMFG+AttbI4 28fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6lEn1qW7pYW+OZToomqBDAHe2USzpvvbyIBlrI1EdZ4=; b=RK7lEd9+GE3xeRI4zdS2R5+DPDMReB81O2v41ivRy2eRRcGo3pA2BknD6c8MH+q5Im I8RVMWOu+le9LqMvd4MTpFwYiCdjRdLbG7zTyvRJnOTkP3v6jFrh1fK8oolawipdAvpL 9MPxhzYWRfssuydSMXTyJVUngq8RmtyDlMzulXJs3E2Lx9YKJ26PPbHNayz2hK4TfCXG 8AW6B/TTkZZctqjVYRi95TJVPj6F0sC2TubDJh+nd0FD4z1ZOtojad+NzExt6y46t5/V m7bb3nX6B8TWMVy5xe12UgxcA0A1zkkpX5CntncWA+P+ZGyS/PflPh69x1YDwgyJVRGI SaAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mGnzkDzZ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.30; Thu, 14 Feb 2019 05:24:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=mGnzkDzZ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438859AbfBNNYa (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:30 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46281 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394723AbfBNNYa (ORCPT ); Thu, 14 Feb 2019 08:24:30 -0500 Received: by mail-lf1-f65.google.com with SMTP id f5so4494936lfc.13 for ; Thu, 14 Feb 2019 05:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6lEn1qW7pYW+OZToomqBDAHe2USzpvvbyIBlrI1EdZ4=; b=mGnzkDzZ6pvV290sm2JwLH3N8v/HHBtsAKyV4FqvCk9CyPT3SOSRaDcCrbKHwSjm0J KIHWqI4Ckm7rH1wmL7Eczj2g9leGT3BzGNt2HqYFyBh0CRFd4JHLxhTLPRjsatrCG0JC JDdSd108QP3cwCUMMDiOrwtq7ONQELZpaIdTRal/VlOW6GnxAHzqGABr+tPpF45TPIRc 99z1C9LX42bV5mydHWvw+04zaPW8RYPa4NW49yFdVo7MVn85AVAM5DiHPEXimIkPgp4A cfjfYv9GzqZN39M4jl1xfi0x5iAAh6k3ha01Bw9pvvasVHV3npxOP8qQs2P+Wb9/Rxgb u/fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6lEn1qW7pYW+OZToomqBDAHe2USzpvvbyIBlrI1EdZ4=; b=BVAB+dVj8+GMxgUgT6a7E7SqFQfDMUXqCx+iCISFAelt0iWeTv+obL0rZsDLhXmB3F laDwlzhzg+4hey3EHU2oVDTOjYEzNZbvDqLqVpPoTyxdyfhY0QJAtL89FPtQfCP0rJmM MA341OJRpfVXxm8Rk9+2R12nOuQ+sks9ZA68xri/9lbNNaue6Xv4kvMXr1SIhogbSNLR ehGDgWAjAJ66E6iHATOAChGMuUGpGDh1e0Wakwwm1o6pdgjAzzBNaqEuZEEgUFXE6ZwT y2TrdOkiInoIF1RHxH8+MhmTIYD3m9loGwpZPOye7iZPHJNKQ/7bFI/KL62B2bMou5FT gO1w== X-Gm-Message-State: AHQUAubnvHwWz4m3JJP4Ogr3upzzuXJAHvMVmoNpkSBfMglVmUFno3h0 vcbyyAqou3EiWAHtRI6fJLak+Q== X-Received: by 2002:ac2:5205:: with SMTP id a5mr2377407lfl.135.1550150667790; Thu, 14 Feb 2019 05:24:27 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:26 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Woojung Huh , Linus Walleij Subject: [PATCH 2/8 v3] smsc95xx: Use skb_cow_head to deal with cloned skbs Date: Thu, 14 Feb 2019 14:23:57 +0100 Message-Id: <20190214132403.10687-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: James Hughes commit e9156cd26a495a18706e796f02a81fee41ec14f4 upstream. The driver was failing to check that the SKB wasn't cloned before adding checksum data. Replace existing handling to extend/copy the header buffer with skb_cow_head. Signed-off-by: James Hughes Acked-by: Eric Dumazet Acked-by: Woojung Huh Signed-off-by: David S. Miller Signed-off-by: Linus Walleij --- - This was applied upstream in v4.11 - Should be applied to stable v4.9.y --- drivers/net/usb/smsc95xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index e29f4c0767eb..e719ecd69d01 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -2011,13 +2011,13 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, /* We do not advertise SG, so skbs should be already linearized */ BUG_ON(skb_shinfo(skb)->nr_frags); - if (skb_headroom(skb) < overhead) { - struct sk_buff *skb2 = skb_copy_expand(skb, - overhead, 0, flags); + /* Make writable and expand header space by overhead if required */ + if (skb_cow_head(skb, overhead)) { + /* Must deallocate here as returning NULL to indicate error + * means the skb won't be deallocated in the caller. + */ dev_kfree_skb_any(skb); - skb = skb2; - if (!skb) - return NULL; + return NULL; } if (csum) { From patchwork Thu Feb 14 13:23:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158386 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1366754jaa; Thu, 14 Feb 2019 05:24:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IaM1ovZYCZ8zpiNmb3NBhJ6v5g+5qN8Db4HFISFpK2v7Oq9x2lF1mZb1cKYBY5VTjd0+3yn X-Received: by 2002:a17:902:b941:: with SMTP id h1mr4220246pls.66.1550150675311; Thu, 14 Feb 2019 05:24:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150675; cv=none; d=google.com; s=arc-20160816; b=pbFky7n9V6ujK9uI739qfQg5LiDL/cQeFiPbaj9nzj8KAMZMA370fAm3Zc0JX/mLT+ ndsy3F7cWLtNbMmeyooWyaRr8TwQKeF0/PBtx7LUPa0Lq7cqC7+PRois3/elCN1wFp4Z DCt+0mU90vwUaAZ6cg8H4XgrO+EtotzxpRo0D3FCzRLmfoNLeuWMHfPSvSta/m/QxfiY L2B1U9N3U8IZ4r5GbL9aRUCL0OBGvwX+JhG4brFrVeJMdyjxJ3/LpIYfaKPKgYflTzt4 nW5u+X4CdUPj/dIQ/aIAt1XQpz/abKBTlNPxjZvO1jpc9lE0KrnaIoWw0zju8q6Fco/R B3nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uXGRYQnSCrcyH+F9yOEuNgRG9XtIhtnvZ4uTY5tFr9g=; b=pr+W8aR8VWj9uJ23IxhR810wfctmgLjptq7ii+a3EeL3K3Vg/O/UJNGAykGi+OKwgg Payt3JCsdTAR3HNBNxPSbBsDXS5kd4BhKkXRCJotjCdNcUCkvS3GRq7dUK94Vv0Kw8Fo z0mEiN8yvVoG8z9FTbRRAp2b6y2H/puhCZ15zWeMkGoz402YvDOS+jQttiMBOWLKf4Zd bLM0z4fjcL4wXSuzvSenvqdrTNt90w7AsxBaM/L7XkKKPQ2u3XQ1IFftSplzJRPto1gX ElytyckNlyRtlQh1dZDogpl86eyB1BfZZm6aPsjSYoCHfR8CCa28dwBM+2Jq9LKGOHTU eZoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MKsFTClx; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.35; Thu, 14 Feb 2019 05:24:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=MKsFTClx; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394723AbfBNNYe (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:34 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:44739 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438860AbfBNNYe (ORCPT ); Thu, 14 Feb 2019 08:24:34 -0500 Received: by mail-lj1-f193.google.com with SMTP id q128so5185612ljb.11 for ; Thu, 14 Feb 2019 05:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uXGRYQnSCrcyH+F9yOEuNgRG9XtIhtnvZ4uTY5tFr9g=; b=MKsFTClxXmNIhKJoqW7Bzaohrn+o+oKrApTMPuAecagVgjpX8DffJkoykZYufVOti5 hm9SeXCgeHTkXCH3ICtTw1Yc9jT2aEoXVYGIj0jFwIH2QXTQopP5nqejv8s8ihmbsqvp kl0D2pq2rWQSkJrteeEwN9XKkfqPuft0McVD91+hw3ukfWDTqthgSQOW/Rz8j0BJNZCO Yom+mJd0aXvkVda10dtoLxbu+ppONatRUeJU4gPIj3Acwu1h7jlGPj4KixiuDKT7MzM1 Z2/7c2Gqp4ngOdZ7JuveLL/ev4epNCv3z28MNwVsmH5vrz4aQUK7GNqAJe2h/8InygBi Pp8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uXGRYQnSCrcyH+F9yOEuNgRG9XtIhtnvZ4uTY5tFr9g=; b=KoCDgI9ItXtQl0oizettqnUUYQY5/zfNPPRAkF9VoGvOM3NTLWjxIN8Z7aFqYU+dfP oRAsDZfZGtqwyRhspDoBg5OVd0pMJD4fdpRUFdqKhGmPmbkjIh1x5I/jxoRurD0VC/nX KkHiplcKAeYudrLD+ZyKA/ZTDniigLkOFrb+1+miBvJ8P0X9p8Em898+wOwFSAWJHYrP fVimNSbLZLdZoKHpaXRYKf9w9/DCnAAf2nJFbGuMoD1Eh52IVQZi6v3mdLajANx17rlG B9oQx4A2hY7Opq9dkWve6XXHK0P8J9BJpQYL6aCjCM+h32Dh+8QvRkVkoonoucfBpaIZ QQQQ== X-Gm-Message-State: AHQUAuYDKje8t84VgPdTeUOzKF7FZ1dS5AIgkb+1j1dMQDeqvOkpDLwY eVjMwyXP/biDBQeqCC/mosaduA== X-Received: by 2002:a2e:9f49:: with SMTP id v9mr2380399ljk.77.1550150672289; Thu, 14 Feb 2019 05:24:32 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:31 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Matthew Garrett , Linus Walleij Subject: [PATCH 3/8 v3] ch9200: use skb_cow_head() to deal with cloned skbs Date: Thu, 14 Feb 2019 14:23:58 +0100 Message-Id: <20190214132403.10687-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Eric Dumazet commit 6bc6895bdd6744e0136eaa4a11fbdb20a7db4e40 upstream. We need to ensure there is enough headroom to push extra header, but we also need to check if we are allowed to change headers. skb_cow_head() is the proper helper to deal with this. Fixes: 4a476bd6d1d9 ("usbnet: New driver for QinHeng CH9200 devices") Signed-off-by: Eric Dumazet Cc: James Hughes Cc: Matthew Garrett Signed-off-by: David S. Miller Signed-off-by: Linus Walleij --- - This was applied upstream in v4.11 - Should be applied to stable v4.9.y --- drivers/net/usb/ch9200.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) -- 2.20.1 diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c index 8a40202c0a17..c4f1c363e24b 100644 --- a/drivers/net/usb/ch9200.c +++ b/drivers/net/usb/ch9200.c @@ -254,14 +254,9 @@ static struct sk_buff *ch9200_tx_fixup(struct usbnet *dev, struct sk_buff *skb, tx_overhead = 0x40; len = skb->len; - if (skb_headroom(skb) < tx_overhead) { - struct sk_buff *skb2; - - skb2 = skb_copy_expand(skb, tx_overhead, 0, flags); + if (skb_cow_head(skb, tx_overhead)) { dev_kfree_skb_any(skb); - skb = skb2; - if (!skb) - return NULL; + return NULL; } __skb_push(skb, tx_overhead); From patchwork Thu Feb 14 13:23:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158387 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1366832jaa; Thu, 14 Feb 2019 05:24:39 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib/ceFi3QosYgyOiUo0Jsb4LhwkUdmw0SmIWM7vm0kVeIOAnsbv+L51Uho2YJTCe0F3VeT6 X-Received: by 2002:a17:902:6949:: with SMTP id k9mr4224771plt.188.1550150679292; Thu, 14 Feb 2019 05:24:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150679; cv=none; d=google.com; s=arc-20160816; b=IyWyFlIeb3p9J7AUQdS6VsWJI+MzSSJsN2oF3UkPCQnOR4gGHUzB1rT71vm/5LkN0v 6APnOP3U1vRKrPo1ZBizGIwI81tOzJR5U+P+G07RnpMtNehw6e601QZZ2xo0cmEwZRSc pMmSshjYrfpDE7dJQdFM51js9X4x8AHXoBXQOiSk+L/3MN+yu9kKIpR1AZ7k3GnooRc+ qWuZVtutZRVyF0JI/bOPR167Q/kHtd0oJj3nTpN+Km56vvXDj7+hXRIyKTZ2+mNfgMcY mutpZS/pEHTq7PgOUtZ4IweELhAY3ON+co+pk6iB9WJW5O+v5svXUGa5Xtxqb98yvpFJ IRaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/DA8zQ7zVMwl0qY6dEhmaf4DYZzRwvi7D9GLz7eYfy8=; b=N8hZ7gVnY+F+Nz2k0w3bBpFHRYCfTLDCGagc3yrJfUwID7CwJFhwFcZteNd8GQqNay uWVGW+N4+SEA4gslyWJSE+bRf1ZEpnW/pjPb7jMoiOWL+TkYejHJeWNArIz24fQv0PYO 5/wbXExHJblQoVvkIMsrTihKYuPL4pVrcjNEfGO6XRyK7rAjMHb6Up7OeD1HID73DDxw Terb4jZ6MPWt86aecXYrPls99Hn2GQAZbTh8fRBnAo7HWpsCFELKJXlGmT9LuxvAL0vx kHGlZsRs+7HHfwyU1/5yiT7m0se7uZsRvFINdeCmhsrsNJiXBjrQCoHT2ATbXh8Yl2py lRJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z7U5EqXA; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.39; Thu, 14 Feb 2019 05:24:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=z7U5EqXA; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436688AbfBNNYi (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:38 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39729 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436698AbfBNNYi (ORCPT ); Thu, 14 Feb 2019 08:24:38 -0500 Received: by mail-lj1-f194.google.com with SMTP id g80so5210986ljg.6 for ; Thu, 14 Feb 2019 05:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/DA8zQ7zVMwl0qY6dEhmaf4DYZzRwvi7D9GLz7eYfy8=; b=z7U5EqXAMeJMymQ8bW3Kc2P4drBGsYAoS/q0fMjxz3rrT0CkB/VBVypLZ6d4bNnTdI 5RqqYnoCLI0YaSk0T+CHhNw+zKp4yU2+76lk+7x/ikpjzkxH7wjFeLJrxXriPzQsuBVA 4M4gZEFiseFptpQtqXgXXLxy4kqnEvb6ZXoTpmFkwRFDw+Wle4ugCW3aoMASL2eWG+W3 e8fBB6akosFckeSlEBVYgdZ2dAu/cCoA/liPVrPZY0t2huuQKQnXmGmwBkRKKyYQSwwl BJTsa+3ml6RpRcYvZ6fuTHDRe69WXvi+eN4twQcWNAr/Ah7pc+OGHCB6WxgLg9cWFr7s 5IuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/DA8zQ7zVMwl0qY6dEhmaf4DYZzRwvi7D9GLz7eYfy8=; b=g2H2aun4y+6M6bIKo0svlK3T2qiVTvJuxmghNb1HLfTpsrnzAe4NdHEeaq7WQxglFP lbus6rqaMN+0jJWbqvdcM3392ePpu2vFtO79GpDDU6QWayEyJkAVnAsVJvlz4Ad4JDMq IeIKEJLpJh9WcKe9Jmzo0os02uvd42GkQP85ebgj8KmAGyniSYrG4QyP/Fr8LGeX7XMH rGxA1pwbWp21b+n3gQin+R6pLSQzqUVsRIa3xpJMHbDPsizLRdG8js9IAi6vD956CgeP ygVHUL725XH/RI/FeyhGkx9eIAcYSfRBZxCzL7qU86RO6Xpwpq5vU9TBHbI+RVFmb9sx t1FA== X-Gm-Message-State: AHQUAuYpUOcZxlPspwLeSiT7EVTlu//uqz+KQmFmui+mIKr4R4TjM8HU bNZDU6Qh1f9F16xRJY8owMEQQQ== X-Received: by 2002:a2e:9a16:: with SMTP id o22-v6mr2453850lji.112.1550150676784; Thu, 14 Feb 2019 05:24:36 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:35 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Linus Walleij Subject: [PATCH 4/8 v3] kaweth: use skb_cow_head() to deal with cloned skbs Date: Thu, 14 Feb 2019 14:23:59 +0100 Message-Id: <20190214132403.10687-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Eric Dumazet commit 39fba7835aacda65284a86e611774cbba71dac20 upstream. We can use skb_cow_head() to properly deal with clones, especially the ones coming from TCP stack that allow their head being modified. This avoids a copy. Signed-off-by: Eric Dumazet Cc: James Hughes Signed-off-by: David S. Miller Signed-off-by: Linus Walleij --- - This was applied upstream in v4.11 - Should be applied to stable v4.9.y --- drivers/net/usb/kaweth.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) -- 2.20.1 diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c index 66b34ddbe216..72d9e7954b0a 100644 --- a/drivers/net/usb/kaweth.c +++ b/drivers/net/usb/kaweth.c @@ -803,18 +803,12 @@ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb, } /* We now decide whether we can put our special header into the sk_buff */ - if (skb_cloned(skb) || skb_headroom(skb) < 2) { - /* no such luck - we make our own */ - struct sk_buff *copied_skb; - copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC); - dev_kfree_skb_irq(skb); - skb = copied_skb; - if (!copied_skb) { - kaweth->stats.tx_errors++; - netif_start_queue(net); - spin_unlock_irq(&kaweth->device_lock); - return NETDEV_TX_OK; - } + if (skb_cow_head(skb, 2)) { + kaweth->stats.tx_errors++; + netif_start_queue(net); + spin_unlock_irq(&kaweth->device_lock); + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; } private_header = (__le16 *)__skb_push(skb, 2); From patchwork Thu Feb 14 13:24:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158388 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1366902jaa; Thu, 14 Feb 2019 05:24:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IaARbzD8OqnoLWzqZZ6s6+9D3TmYGyaH8qyxGkPe6gsLYkK92YOl2gxKHzlXeJA/Ej1X0/I X-Received: by 2002:a62:1303:: with SMTP id b3mr4140009pfj.147.1550150684431; Thu, 14 Feb 2019 05:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150684; cv=none; d=google.com; s=arc-20160816; b=eZk36CQxIHjdRxGk1pxaMzNh0x8cAKgiMQFdFhuPfazXKOaqZgS9a/HCdqSnmFhfYE jdZ3OOK0gXlAhhZBMmtVC80TUvok7ER4L1sk7xLStnQ0Izirwvl3oNJqQVkq3VqNz7pw FJPmbwVZ0MluWRlpFriQR4qZmadzc3Ew8gpR0jjwQB3Q2BeMrKGAEHgaeg3Q5glz6l3G D3apTE11BxTC8aJOPoDmxmTNrmQ2JB/2/45Lfa8qHQnCJ5E8AxrVm42H4T0EGfqxtOnJ 4kHn8sDpUC+FqMYWaBeCDC1/QpowoXxJIoiqrNqMPHofESJLLCfSMSI2XmVUTb4yHfOo 6Ccw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i2YxxveFV+VRScKWCCilYlww+c4OOmrY0aP8ToD73I4=; b=JLDnY3MLfjZ6jecC+zqP5v8v2KzBRhWxWD8tnSl/B+vLwJlN1dgRmnPcIs+dffNE0R 22ctio2pM+XSdI3jeE1dlIaNHOQ3+xvTY2ssdYqMKRANoWvVsppt0M88oRW5mShilM3J b2U7Wik0XZP8WWKPJsPyS4FbtcL0413yArwXH3Eep6Y7pQ4Ypgehfe0Q2OsnrUIzyC3o R5801h0aQV6sBO3DyvFUfoM04T2TUfvW3YLMnaKIdneoNQBPGDrAhv0ZFBfT6I1Dp0gG DDSUTkoHuovbnvbIg0bXJ4V9BOxaBC3ikQWl5ide+MnVXYEn8TFCS1ti1+zJhYJYwCrA A/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qnqO7Kpq; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.44; Thu, 14 Feb 2019 05:24:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=qnqO7Kpq; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438860AbfBNNYn (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:43 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35389 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436698AbfBNNYn (ORCPT ); Thu, 14 Feb 2019 08:24:43 -0500 Received: by mail-lj1-f194.google.com with SMTP id j13-v6so5235082ljc.2 for ; Thu, 14 Feb 2019 05:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i2YxxveFV+VRScKWCCilYlww+c4OOmrY0aP8ToD73I4=; b=qnqO7KpqDkoF8IqEuT7dDevmpnbASgD+x6K7x+YXNC1yojhEWfnWNW5lTC2QROVDZh jk0JI8zf9ZVvlT6NFij/8ne+BseENME0WccQAQBf8rT8DY7xFw3TgcPlOVKemUYBySMR 6maTyuB2d9FHCFzyBVdZ7Ej44OhM7Llc7QL5AXi7OWMp3rtpHwTTtnVg30bUwYRUaU1G nA7KBlquMdM5vuH8WB6u2JbIbTM6UvaPtKwJZSSwWkpMvG2S4/4o/ghoYJi30ExOyAjh mH60tIEpERKW7Q98j7X4axROUEPdVx36fV1Sk+jAxvAKjhTw6GrfGa4bULfH+OSflkJL 5YPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i2YxxveFV+VRScKWCCilYlww+c4OOmrY0aP8ToD73I4=; b=Rd+55d4rxF6a7Tmabe3Pv0OAL5iQ0btgdpsIG/TCmIddtoib71TNFLcTrdbcHmvhMf ueOp0CSuTY1sXdcvVptVd0yM84dqhfRCnzlH5naNaaJhB1OFWc2CWEpvH0inFORUo2xT +C+MONU0VsaMm0cTWRBGceL9dh/p/TW6YAStltwF0vKuFrQIZBRcmz2GW4UF7QDipPSl qehhDOkZ5sr4syisUxlCu9d2sZ2IGJb7asnqfApxsyOhB5XKQNMHE/tQ6WBml8iWAHte V7ptrRqfxp4ROxt0d5NWGrw2tZLSnDHONJ+vukMUNTEXtQbzhc5ro/b/E5w/xG6ht5Fc 2jZA== X-Gm-Message-State: AHQUAubuaYSEuFxf/BHo8zn4Gg0cmBGb3+9fk3RH3wlKm+d6F9ZYmjjb U4du8Ibt2JSFbwvg2KXeJPbFMQ== X-Received: by 2002:a2e:81c7:: with SMTP id s7mr1129450ljg.146.1550150681348; Thu, 14 Feb 2019 05:24:41 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:40 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Boris Brezillon , Richard Weinberger , Linus Walleij Subject: [PATCH 5/8 v3] ubifs: Drop softlimit and delta fields from struct ubifs_wbuf Date: Thu, 14 Feb 2019 14:24:00 +0100 Message-Id: <20190214132403.10687-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Rafał Miłecki commit 854826c9d526fd81077742c3b000e3f7fcaef3ce upstream. Values of these fields are set during init and never modified. They are used (read) in a single function only. There isn't really any reason to keep them in a struct. It only makes struct just a bit bigger without any visible gain. Signed-off-by: Rafał Miłecki Reviewed-by: Boris Brezillon Signed-off-by: Richard Weinberger Signed-off-by: Linus Walleij --- - This was applied upstream in v4.10 - Should be applied to stable v4.9.y --- fs/ubifs/io.c | 18 ++++++++++-------- fs/ubifs/ubifs.h | 5 ----- 2 files changed, 10 insertions(+), 13 deletions(-) -- 2.20.1 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 97be41215332..4d6ce4a2a4b6 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c @@ -452,16 +452,22 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer) */ static void new_wbuf_timer_nolock(struct ubifs_wbuf *wbuf) { + ktime_t softlimit = ktime_set(WBUF_TIMEOUT_SOFTLIMIT, 0); + unsigned long long delta; + + delta = WBUF_TIMEOUT_HARDLIMIT - WBUF_TIMEOUT_SOFTLIMIT; + delta *= 1000000000ULL; + ubifs_assert(!hrtimer_active(&wbuf->timer)); + ubifs_assert(delta <= ULONG_MAX); if (wbuf->no_timer) return; dbg_io("set timer for jhead %s, %llu-%llu millisecs", dbg_jhead(wbuf->jhead), - div_u64(ktime_to_ns(wbuf->softlimit), USEC_PER_SEC), - div_u64(ktime_to_ns(wbuf->softlimit) + wbuf->delta, - USEC_PER_SEC)); - hrtimer_start_range_ns(&wbuf->timer, wbuf->softlimit, wbuf->delta, + div_u64(ktime_to_ns(softlimit), USEC_PER_SEC), + div_u64(ktime_to_ns(softlimit) + delta, USEC_PER_SEC)); + hrtimer_start_range_ns(&wbuf->timer, softlimit, delta, HRTIMER_MODE_REL); } @@ -1059,10 +1065,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf) hrtimer_init(&wbuf->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); wbuf->timer.function = wbuf_timer_callback_nolock; - wbuf->softlimit = ktime_set(WBUF_TIMEOUT_SOFTLIMIT, 0); - wbuf->delta = WBUF_TIMEOUT_HARDLIMIT - WBUF_TIMEOUT_SOFTLIMIT; - wbuf->delta *= 1000000000ULL; - ubifs_assert(wbuf->delta <= ULONG_MAX); return 0; } diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 096035eb29d0..ade4b3137a1d 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -645,9 +645,6 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c, * @io_mutex: serializes write-buffer I/O * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes * fields - * @softlimit: soft write-buffer timeout interval - * @delta: hard and soft timeouts delta (the timer expire interval is @softlimit - * and @softlimit + @delta) * @timer: write-buffer timer * @no_timer: non-zero if this write-buffer does not have a timer * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing @@ -676,8 +673,6 @@ struct ubifs_wbuf { int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad); struct mutex io_mutex; spinlock_t lock; - ktime_t softlimit; - unsigned long long delta; struct hrtimer timer; unsigned int no_timer:1; unsigned int need_sync:1; From patchwork Thu Feb 14 13:24:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158389 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1367029jaa; Thu, 14 Feb 2019 05:24:49 -0800 (PST) X-Google-Smtp-Source: AHgI3Ias5MFs4eTlnni7rsXpWdTgTEua/JkjYf//qyejjx61MWSFrUviPvfLznQTmTKU5qLLUa4K X-Received: by 2002:a17:902:20e9:: with SMTP id v38mr4046858plg.250.1550150689883; Thu, 14 Feb 2019 05:24:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150689; cv=none; d=google.com; s=arc-20160816; b=xXvo3gC+rwynp4c/t4lpRN+3/JK7Ffkqjul/Y11igWGqujo+Kkkc9AhBstwz49CDIL 4sHcfvQldhvUIfvamZI1sLxSsavuQbXrTsR5Tw4YS1R2bSw+9tCmLMcy9lfMQD+NZEch FIpo08dW+t21XMf2nn0JLVrjnragOHHKXWpGey+qdBb1yYl9yJnahc7biVZIQlbk9ADs /UHztbsUwpMaagx2F+1Ow6Q4EoIjkd4KVIJF5MV+iGwlQ4XHLbB8BramfZZ0o5Wnm8Lq mDjxjL8pM4SD01BUjk+fOzl0o3VG1tk0LT6IJfXs9dw7HksZNrhTS4l66mJgTHYET2IS kVhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JnOpFuWei3nzemVBDjN3MgW2JlSWE/slWX5N0EfPGcw=; b=pvp06QgYFKYWl6OAYJyAqoNi7GFhIHnvU4vDrIxNckgtDP9wy7EB3vApizfEBEBL+u +3Jcn+bt4KNGplgIUu3v2vrD8Zg4Vw9+h9khk65VIx1VwimIlRADLCDv/TWUUhGzmB3d T+rjLxUTcUWdCYYjSuOkqJI/n1ZiSQJEVgFlosAIvFQbIwGjQdghoxuM8+oMCtFqXrZY dTQ0F32vOgb3uenNwDcgmaaywKoQHl3XQEbx4604LNufmbP6gsH133sHtPaj8vsJG3gC FUdPeqoRXSY8Jkwe9O/OYY9CinS7mZ9onoixeL28KZ7ndZ4TJmYmQF5YPteu47uJt7yc 3Mcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ah27IPWr; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.49; Thu, 14 Feb 2019 05:24:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=ah27IPWr; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732439AbfBNNYt (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:49 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39748 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfBNNYs (ORCPT ); Thu, 14 Feb 2019 08:24:48 -0500 Received: by mail-lj1-f195.google.com with SMTP id g80so5211482ljg.6 for ; Thu, 14 Feb 2019 05:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JnOpFuWei3nzemVBDjN3MgW2JlSWE/slWX5N0EfPGcw=; b=ah27IPWrk7XBW/zEI7KK3m0tEyjw8zSRQHo7V69O6Tg56+M5bkDfCpsIvHVYnrZzIU stp23jXq7T1r5bClO9Tdx70Y+9AM0SCIEw3Gv2+tBNnLqH2pklXD9P7/F8pqGEwyqRjo 2ENuJaRWZvDFKVdZfWUNZrhySxLTSWrgQutcaYe6gwZZA5PQKklzj6TLPV+NRRBhj5S1 WfoRS27VLMUf8I3olE8S6/GDkJAJAVWeJOFLxaVBzQuCwkT4m/4U3bQAaRwlnBQ3GB+m 4299VEjI67qlZBkwK0ZIKdLUER/00f22+VCerktpirowC0CyS1JRrJt1nrgwWwFOZ75b dUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JnOpFuWei3nzemVBDjN3MgW2JlSWE/slWX5N0EfPGcw=; b=jleSTBrcm5+ZhgSKtFatp9wfjHcNtqLkVLGaa890hkIMDsY2fJi8/PdfQKKUA6ClND O7d3w77CLqHWgmuWJxq3w4Cg4li1R4yQ/bMoxhOYlVm0JlX96weDCG2Y4KXVkHfeaNy6 RT6yU5dpJoO0+Mb1dMNWmfuNdqTQaTjzc0Yi8xzssoL/uypcByRwAlZIWlluxcmBoQcj mAnLkPlWcg7lxa+dgnYb3DSJ1P59EX2GtCJHjAsozpNqhCNuSPmFMRA1E132D+g2WU7H R8Kqsge9UgYvGXInXDdLjb8X7U+eBWVHlworqgn5aOS5bP+RsYoQgYS+ZzDgJcWgGcun yrlQ== X-Gm-Message-State: AHQUAub1KGLnk0rTHn9Gj1SHsnXd80uvtDCZ3+HLj3hVmGBi5FuQehdb gkBi4BnOLkBw6A2TyOrmLfPcEAXLWrI= X-Received: by 2002:a2e:587:: with SMTP id 129mr2367651ljf.25.1550150687070; Thu, 14 Feb 2019 05:24:47 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:45 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Boris Brezillon , Richard Weinberger , Linus Walleij Subject: [PATCH 6/8 v3] ubifs: Use dirty_writeback_interval value for wbuf timer Date: Thu, 14 Feb 2019 14:24:01 +0100 Message-Id: <20190214132403.10687-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Rafał Miłecki commit 1b7fc2c0069f3864a3dda15430b7aded31c0bfcc upstream. Right now wbuf timer has hardcoded timeouts and there is no place for manual adjustments. Some projects / cases many need that though. Few file systems allow doing that by respecting dirty_writeback_interval that can be set using sysctl (dirty_writeback_centisecs). Lowering dirty_writeback_interval could be some way of dealing with user space apps lacking proper fsyncs. This is definitely *not* a perfect solution but we don't have ideal (user space) world. There were already advanced discussions on this matter, mostly when ext4 was introduced and it wasn't behaving as ext3. Anyway, the final decision was to add some hacks to the ext4, as trying to fix whole user space or adding new API was pointless. We can't (and shouldn't?) just follow ext4. We can't e.g. sync on close as this would cause too many commits and flash wearing. On the other hand we still should allow some trade-off between -o sync and default wbuf timeout. Respecting dirty_writeback_interval should allow some sane cutomizations if used warily. Signed-off-by: Rafał Miłecki Reviewed-by: Boris Brezillon Signed-off-by: Richard Weinberger Signed-off-by: Linus Walleij --- - This was applied upstream in v4.10 - Should be applied to stable v4.9.y --- fs/ubifs/io.c | 8 ++++---- fs/ubifs/ubifs.h | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) -- 2.20.1 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 4d6ce4a2a4b6..3be28900bf37 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c @@ -452,11 +452,11 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer) */ static void new_wbuf_timer_nolock(struct ubifs_wbuf *wbuf) { - ktime_t softlimit = ktime_set(WBUF_TIMEOUT_SOFTLIMIT, 0); - unsigned long long delta; + ktime_t softlimit = ms_to_ktime(dirty_writeback_interval * 10); + unsigned long long delta = dirty_writeback_interval; - delta = WBUF_TIMEOUT_HARDLIMIT - WBUF_TIMEOUT_SOFTLIMIT; - delta *= 1000000000ULL; + /* centi to milli, milli to nano, then 10% */ + delta *= 10ULL * NSEC_PER_MSEC / 10ULL; ubifs_assert(!hrtimer_active(&wbuf->timer)); ubifs_assert(delta <= ULONG_MAX); diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index ade4b3137a1d..b8b18d446a49 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -83,10 +83,6 @@ */ #define BGT_NAME_PATTERN "ubifs_bgt%d_%d" -/* Write-buffer synchronization timeout interval in seconds */ -#define WBUF_TIMEOUT_SOFTLIMIT 3 -#define WBUF_TIMEOUT_HARDLIMIT 5 - /* Maximum possible inode number (only 32-bit inodes are supported now) */ #define MAX_INUM 0xFFFFFFFF From patchwork Thu Feb 14 13:24:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158390 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1367144jaa; Thu, 14 Feb 2019 05:24:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZN+Mvl+dJxF/tuu74JeghS+Hr44CcXR2tC9nhxoxQrvSAxakxwGGmoYII8NjncnahpmQVw X-Received: by 2002:a63:fa06:: with SMTP id y6mr3781344pgh.177.1550150695791; Thu, 14 Feb 2019 05:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150695; cv=none; d=google.com; s=arc-20160816; b=ML2o00bBIS+xVyAafZC9G0eXbOmEeix3i4CyLGvAq+oVBGUCv69ZWAtXG22hpXKOtp os6EIpuSNKfs5bexpTphebQkuLQinZ+UJ/OrN6NmcbEoG7cVPBluZ4O/7m6vrzHOTAP6 Iq8HD2DnFyRNABMQlXLqFtz3Yn1rm40ZhT10JJ70yC7hNvoLo+9BA7xuhyaLCgBbryp2 bxknCswp/T3v3e/62JNTJmDmXYICP5ohRaK/Z5L+zJDyvUtE65FYOfai5vKdfVrFEAtP v+eBvsEPxM8mRJwXzqqL5/Nr14H0+dleGvxXwMDmvQbADKoIiV8EXpuGScKM3UDbfrAb 4T8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ynm6DT16zNvz+93k0pPR5GepakBcCFCSOf6wdHIe7Vo=; b=QPo7/Y4050/OkXRr+8r7s4W/frJVriDpFUM1a2Wi+lX4M5s6CQTjIO3HLFKojAKpyD 3V9rsHvqX/k1D6K8HPSruHKHvPmDwb5ZPuATMsyS9oUy3Rg4hAG2P0lSXNlCH5PuCPcO Ao/HV57WO8fSSfpUIRGfLcnjRjTS9O7CIGQEi4cF+uow3aRyQlfx4OaoXxW4obGVO/Ef 8R5I8LsYOVdpTe+KjHymV+Sbk9Suy9JG4xdB+ktjFPQ4ceOIJee7j7/9xmPnnPV55HMi F5gcMo0f293pK2x65IiIqSVy3Cviiyw1Lq6eU8xVyFJme67fB8lz0q+QLI9RU9PcM3EV eNFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sy3LOYsG; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.24.55; Thu, 14 Feb 2019 05:24:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=sy3LOYsG; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394750AbfBNNYz (ORCPT + 15 others); Thu, 14 Feb 2019 08:24:55 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43435 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391121AbfBNNYy (ORCPT ); Thu, 14 Feb 2019 08:24:54 -0500 Received: by mail-lj1-f193.google.com with SMTP id z20so4198495ljj.10 for ; Thu, 14 Feb 2019 05:24:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ynm6DT16zNvz+93k0pPR5GepakBcCFCSOf6wdHIe7Vo=; b=sy3LOYsG1nChdUfsgYnpLamnlNyQ5Xs1HRAl8XG1pjmMlYAOgP8WtlOdgNVRLX6QWh Bi/P9fsYqdeMnYfJhk+x2utx7fGfPOQwUasv95Wo3xPu95Aq8ZzPctG52QSk8IZHzLpd QfpYq7CJRA9b989TmeaiS6k/nlYXvfeYLFRY4iuHsIFDcGf3NK66wHoLW3ACEIcNo+GU +3G0+wFjNkCARrS46F/6wYBC+Au3Q9GdYzjF/lcqaE3FYr5r1JN07Y8wY+gBnDyUQOAm vQyMNo4EykNmkrJOE2IVcWShMeNiNkNAzvX4Q5YRK/9l4qIWXhjXOYdnGyYeFZ2KT49n nwhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ynm6DT16zNvz+93k0pPR5GepakBcCFCSOf6wdHIe7Vo=; b=d3JYEL5uVYVxKqv69+L2Xen3OO4Cwl1jnCugyBXFckAuBm3nssAFzCPLdeZT4JPvIz 6VU7NCOxc5DYobsdyTiXmIgm9EvVZ3Zxtec/C4rHdtnbqrDX85podby7mA5pmfUUSZo6 24WAYrjj9yye7fAYzUTdHQW0gDXOrYnJaM675knRwo+azslWvJlFSwkunikMTxoJ6/Gp +Y9g7szVlXSaNLM+MPPoc0ktCaLa3MVOEDMw8sefOpZbT9aGvRD4g64Yu9eVduLnfGJH u6gdLS8dJruRAv0jkwEFY/cq7UIS5Vbfr0iXAAcD4gkhUJfoNQOcOj6TugjtP03cTk5c ngvA== X-Gm-Message-State: AHQUAuawKLlgk5GMXD2GrG5c7CMu3ykpHh0ZCDoN5fbdExIeBesAy9TZ JZ8uRp7qmiYo0ZiyTVwPLLfbSQ== X-Received: by 2002:a2e:8e8e:: with SMTP id z14-v6mr2438929ljk.84.1550150692862; Thu, 14 Feb 2019 05:24:52 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:51 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Felipe Balbi , Linus Walleij Subject: [PATCH 7/8 v3] usb: dwc2: Remove unnecessary kfree Date: Thu, 14 Feb 2019 14:24:02 +0100 Message-Id: <20190214132403.10687-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: John Youn commit cd4b1e34655d46950c065d9284b596cd8d7b28cd upstream. This shouldn't be freed by the HCD as it is owned by the core and allocated with devm_kzalloc. Signed-off-by: John Youn Signed-off-by: Felipe Balbi Signed-off-by: Linus Walleij --- - This was applied upstream in v4.10 - Should be applied to stable v4.9.y --- drivers/usb/dwc2/hcd.c | 1 - 1 file changed, 1 deletion(-) -- 2.20.1 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 984d6aae7529..0e5435330c07 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -5202,7 +5202,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) error2: usb_put_hcd(hcd); error1: - kfree(hsotg->core_params); #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS kfree(hsotg->last_frame_num_array); From patchwork Thu Feb 14 13:24:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158391 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1367250jaa; Thu, 14 Feb 2019 05:25:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IbsXweobTtpxJjnH3V1WnyX4H2iLSVIXrtzQW5NYe4Mbo3wvHsqsRpmjGuYYgR7US9QISEn X-Received: by 2002:a17:902:9683:: with SMTP id n3mr4186038plp.333.1550150701745; Thu, 14 Feb 2019 05:25:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550150701; cv=none; d=google.com; s=arc-20160816; b=uk/f/UMzWVR9xiZhzlCNlRSNM+n3yKu4FQRcmVNFSCOLkaIkHOOEGzByXVKz5NvXLf f4nDTZO7si9ENRWK3X9TPEIQRh98s1/OC76UC0Bzct+dEYVmsdUnqVWamjsjl29qdZQ5 oLE+haG9LpfBYkOW9MDlb3XWmFu4ndKou/6DEH/zruaCXsQqMlJkMYy9VK6XaYAfNJLh VOZsVv6gp0gjqP9oqblF86YugY4/YJv3CQr7vmDnMXTLGZFvndzCnwnprHeqqAKkHosP 3GDDd/X0qIlAjQsOIN4JVjkmWoc7Gd3vrn+PQ25Uype6xK1XafebocfrjxpZGF5VSp9w /ewQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o5GlgYKfI2v6hld5nmpnLQr7Y33SJvMxyfsMHdG7gFw=; b=US5I+ksaW4yeEqj6TS7IzO1msNNdxDSPfSG0ZXeWSGrvEB+Nz5TXX8VlLqbFWuXfe3 P9l3ZuoIBBytoRuglx/jK/Hd/a3M8uv6MMh9/JfFpIfLQw051tKvQJBcmhUgeYGW4ZUF lSvzP8ZnN++Niy205i8MzWKuqpiOKe/3yrC13k3Nrhirk0eVtRQzq3ItCLWat0ziYb3/ OdcRFLRGFMV+TZI2gR3q3aQ2ACGPqpyRFGg0yc06xkg9NFNi1HjmCpgkcw/gs/xDPPUh 09kxZvBepJhZIT76tkWxfq986vZL/cBz5gtiiIfSGopZy8GEcYbpWLf5tUUekxzpY74/ iJGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LL4ZQHaD; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36si2748782plc.250.2019.02.14.05.25.01; Thu, 14 Feb 2019 05:25:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=LL4ZQHaD; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436698AbfBNNZB (ORCPT + 15 others); Thu, 14 Feb 2019 08:25:01 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33516 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391121AbfBNNZA (ORCPT ); Thu, 14 Feb 2019 08:25:00 -0500 Received: by mail-lj1-f194.google.com with SMTP id f24-v6so5244116ljk.0 for ; Thu, 14 Feb 2019 05:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o5GlgYKfI2v6hld5nmpnLQr7Y33SJvMxyfsMHdG7gFw=; b=LL4ZQHaDcNhUExdkoeTMrUqbTxQoNMxz9LR82OYLgL1TDrRNOVM58xQ7nddOPyCe9C YdlRIAkeOP48Ax9b83v8GlUN9NR+K3DQQCtaJRJbK8WBwef1xTclM0fymWObnMGcds5u AQDrVjQWN0XqReVueptCwB60zTXZblN8wJC9emYe0ZSuczN92jeemQ3XIZXhRD0K963l xn+nDBrtwTFc8EClzKRBnJpZ+pEmz6ku2UKXrZi/TGUmuM3pAOsbfd8JHzLsaOKx/TUE IFLroopMvcPNTJoVGT0wH+W0aoBBjfYyn5HRe4G4ClcPewWDZMyT8Gl4VIvUrfD9eHuA +xyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o5GlgYKfI2v6hld5nmpnLQr7Y33SJvMxyfsMHdG7gFw=; b=dAPcitD/W95pWY5rRRdMEM8na4bog3w7SqFyiPtOb5x/BwbH8cs6aW6QHQp39Ys9yH P33Bkqq3KxPnclBOAm2LAz+P3YqijUfUiQ92Nty7Fr7h93FuLK4qFf7YARIuawNJ8tLh UtDfpsqN97S9J2wMOJmvr8P4xzopnVTPhbfMZ8eevsIFWpy+5x/JyG37jMjJZXo4GimI yHSixlC91hjUiqJw0yKWIRUgHWy0jHZCsZuV585lrMeBl7G99wXVj5TX9buU+30IEqJo Rbzqh+4+in+sUL0FI3Z8g7zEo5fGxUMZmmxjY5frp8aUy5ymvmkVKswL20V8U94CkGcD 5dpQ== X-Gm-Message-State: AHQUAuYXZu3PZMHsfZAPybXklIJt85seTYX7zAlq3Sn6mYix/QYggYKp Wfob+AsCK47GrOiKmprSmo+MUg== X-Received: by 2002:a2e:92ca:: with SMTP id k10-v6mr2406571ljh.63.1550150697975; Thu, 14 Feb 2019 05:24:57 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13-v6sm427752ljg.84.2019.02.14.05.24.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 05:24:57 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Pablo Neira Ayuso , Linus Walleij Subject: [PATCH 8/8 v3] netfilter: nf_tables: fix mismatch in big-endian system Date: Thu, 14 Feb 2019 14:24:03 +0100 Message-Id: <20190214132403.10687-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214132403.10687-1-linus.walleij@linaro.org> References: <20190214132403.10687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Liping Zhang commit 10596608c4d62cb8c1c2b806debcbd32fe657e71 upstream. Currently, there are two different methods to store an u16 integer to the u32 data register. For example: u32 *dest = ®s->data[priv->dreg]; 1. *dest = 0; *(u16 *) dest = val_u16; 2. *dest = val_u16; For method 1, the u16 value will be stored like this, either in big-endian or little-endian system: 0 15 31 +-+-+-+-+-+-+-+-+-+-+-+-+ | Value | 0 | +-+-+-+-+-+-+-+-+-+-+-+-+ For method 2, in little-endian system, the u16 value will be the same as listed above. But in big-endian system, the u16 value will be stored like this: 0 15 31 +-+-+-+-+-+-+-+-+-+-+-+-+ | 0 | Value | +-+-+-+-+-+-+-+-+-+-+-+-+ So later we use "memcmp(®s->data[priv->sreg], data, 2);" to do compare in nft_cmp, nft_lookup expr ..., method 2 will get the wrong result in big-endian system, as 0~15 bits will always be zero. For the similar reason, when loading an u16 value from the u32 data register, we should use "*(u16 *) sreg;" instead of "(u16)*sreg;", the 2nd method will get the wrong value in the big-endian system. So introduce some wrapper functions to store/load an u8 or u16 integer to/from the u32 data register, and use them in the right place. Signed-off-by: Liping Zhang Signed-off-by: Pablo Neira Ayuso Signed-off-by: Linus Walleij --- - This was applied upstream in v4.11 - Should be applied to stable v4.9.y --- include/net/netfilter/nf_tables.h | 29 ++++++++++++++++++++ net/ipv4/netfilter/nft_masq_ipv4.c | 8 +++--- net/ipv4/netfilter/nft_redir_ipv4.c | 8 +++--- net/ipv6/netfilter/nft_masq_ipv6.c | 8 +++--- net/ipv6/netfilter/nft_redir_ipv6.c | 8 +++--- net/netfilter/nft_ct.c | 10 +++---- net/netfilter/nft_meta.c | 42 +++++++++++++++-------------- net/netfilter/nft_nat.c | 8 +++--- 8 files changed, 76 insertions(+), 45 deletions(-) -- 2.20.1 diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index b02af0bf5777..66f6b84df287 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h @@ -87,6 +87,35 @@ struct nft_regs { }; }; +/* Store/load an u16 or u8 integer to/from the u32 data register. + * + * Note, when using concatenations, register allocation happens at 32-bit + * level. So for store instruction, pad the rest part with zero to avoid + * garbage values. + */ + +static inline void nft_reg_store16(u32 *dreg, u16 val) +{ + *dreg = 0; + *(u16 *)dreg = val; +} + +static inline void nft_reg_store8(u32 *dreg, u8 val) +{ + *dreg = 0; + *(u8 *)dreg = val; +} + +static inline u16 nft_reg_load16(u32 *sreg) +{ + return *(u16 *)sreg; +} + +static inline u8 nft_reg_load8(u32 *sreg) +{ + return *(u8 *)sreg; +} + static inline void nft_data_copy(u32 *dst, const struct nft_data *src, unsigned int len) { diff --git a/net/ipv4/netfilter/nft_masq_ipv4.c b/net/ipv4/netfilter/nft_masq_ipv4.c index 51ced81b616c..dc3628a396ec 100644 --- a/net/ipv4/netfilter/nft_masq_ipv4.c +++ b/net/ipv4/netfilter/nft_masq_ipv4.c @@ -26,10 +26,10 @@ static void nft_masq_ipv4_eval(const struct nft_expr *expr, memset(&range, 0, sizeof(range)); range.flags = priv->flags; if (priv->sreg_proto_min) { - range.min_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_min]; - range.max_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_max]; + range.min_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_max]); } regs->verdict.code = nf_nat_masquerade_ipv4(pkt->skb, pkt->hook, &range, pkt->out); diff --git a/net/ipv4/netfilter/nft_redir_ipv4.c b/net/ipv4/netfilter/nft_redir_ipv4.c index c09d4381427e..f760524e1353 100644 --- a/net/ipv4/netfilter/nft_redir_ipv4.c +++ b/net/ipv4/netfilter/nft_redir_ipv4.c @@ -26,10 +26,10 @@ static void nft_redir_ipv4_eval(const struct nft_expr *expr, memset(&mr, 0, sizeof(mr)); if (priv->sreg_proto_min) { - mr.range[0].min.all = - *(__be16 *)®s->data[priv->sreg_proto_min]; - mr.range[0].max.all = - *(__be16 *)®s->data[priv->sreg_proto_max]; + mr.range[0].min.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_min]); + mr.range[0].max.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_max]); mr.range[0].flags |= NF_NAT_RANGE_PROTO_SPECIFIED; } diff --git a/net/ipv6/netfilter/nft_masq_ipv6.c b/net/ipv6/netfilter/nft_masq_ipv6.c index 9597ffb74077..b74a420050c4 100644 --- a/net/ipv6/netfilter/nft_masq_ipv6.c +++ b/net/ipv6/netfilter/nft_masq_ipv6.c @@ -27,10 +27,10 @@ static void nft_masq_ipv6_eval(const struct nft_expr *expr, memset(&range, 0, sizeof(range)); range.flags = priv->flags; if (priv->sreg_proto_min) { - range.min_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_min]; - range.max_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_max]; + range.min_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_max]); } regs->verdict.code = nf_nat_masquerade_ipv6(pkt->skb, &range, pkt->out); } diff --git a/net/ipv6/netfilter/nft_redir_ipv6.c b/net/ipv6/netfilter/nft_redir_ipv6.c index aca44e89a881..7ef58e493fca 100644 --- a/net/ipv6/netfilter/nft_redir_ipv6.c +++ b/net/ipv6/netfilter/nft_redir_ipv6.c @@ -26,10 +26,10 @@ static void nft_redir_ipv6_eval(const struct nft_expr *expr, memset(&range, 0, sizeof(range)); if (priv->sreg_proto_min) { - range.min_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_min], - range.max_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_max], + range.min_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_max]); range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED; } diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c index d7b0d171172a..2b9fda71fa8b 100644 --- a/net/netfilter/nft_ct.c +++ b/net/netfilter/nft_ct.c @@ -77,7 +77,7 @@ static void nft_ct_get_eval(const struct nft_expr *expr, switch (priv->key) { case NFT_CT_DIRECTION: - *dest = CTINFO2DIR(ctinfo); + nft_reg_store8(dest, CTINFO2DIR(ctinfo)); return; case NFT_CT_STATUS: *dest = ct->status; @@ -129,10 +129,10 @@ static void nft_ct_get_eval(const struct nft_expr *expr, return; } case NFT_CT_L3PROTOCOL: - *dest = nf_ct_l3num(ct); + nft_reg_store8(dest, nf_ct_l3num(ct)); return; case NFT_CT_PROTOCOL: - *dest = nf_ct_protonum(ct); + nft_reg_store8(dest, nf_ct_protonum(ct)); return; default: break; @@ -149,10 +149,10 @@ static void nft_ct_get_eval(const struct nft_expr *expr, nf_ct_l3num(ct) == NFPROTO_IPV4 ? 4 : 16); return; case NFT_CT_PROTO_SRC: - *dest = (__force __u16)tuple->src.u.all; + nft_reg_store16(dest, (__force u16)tuple->src.u.all); return; case NFT_CT_PROTO_DST: - *dest = (__force __u16)tuple->dst.u.all; + nft_reg_store16(dest, (__force u16)tuple->dst.u.all); return; default: break; diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index 7c3395513ff0..cec8dc0e5e6f 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -45,16 +45,15 @@ void nft_meta_get_eval(const struct nft_expr *expr, *dest = skb->len; break; case NFT_META_PROTOCOL: - *dest = 0; - *(__be16 *)dest = skb->protocol; + nft_reg_store16(dest, (__force u16)skb->protocol); break; case NFT_META_NFPROTO: - *dest = pkt->pf; + nft_reg_store8(dest, pkt->pf); break; case NFT_META_L4PROTO: if (!pkt->tprot_set) goto err; - *dest = pkt->tprot; + nft_reg_store8(dest, pkt->tprot); break; case NFT_META_PRIORITY: *dest = skb->priority; @@ -85,14 +84,12 @@ void nft_meta_get_eval(const struct nft_expr *expr, case NFT_META_IIFTYPE: if (in == NULL) goto err; - *dest = 0; - *(u16 *)dest = in->type; + nft_reg_store16(dest, in->type); break; case NFT_META_OIFTYPE: if (out == NULL) goto err; - *dest = 0; - *(u16 *)dest = out->type; + nft_reg_store16(dest, out->type); break; case NFT_META_SKUID: sk = skb_to_full_sk(skb); @@ -142,22 +139,22 @@ void nft_meta_get_eval(const struct nft_expr *expr, #endif case NFT_META_PKTTYPE: if (skb->pkt_type != PACKET_LOOPBACK) { - *dest = skb->pkt_type; + nft_reg_store8(dest, skb->pkt_type); break; } switch (pkt->pf) { case NFPROTO_IPV4: if (ipv4_is_multicast(ip_hdr(skb)->daddr)) - *dest = PACKET_MULTICAST; + nft_reg_store8(dest, PACKET_MULTICAST); else - *dest = PACKET_BROADCAST; + nft_reg_store8(dest, PACKET_BROADCAST); break; case NFPROTO_IPV6: if (ipv6_hdr(skb)->daddr.s6_addr[0] == 0xFF) - *dest = PACKET_MULTICAST; + nft_reg_store8(dest, PACKET_MULTICAST); else - *dest = PACKET_BROADCAST; + nft_reg_store8(dest, PACKET_BROADCAST); break; case NFPROTO_NETDEV: switch (skb->protocol) { @@ -171,14 +168,14 @@ void nft_meta_get_eval(const struct nft_expr *expr, goto err; if (ipv4_is_multicast(iph->daddr)) - *dest = PACKET_MULTICAST; + nft_reg_store8(dest, PACKET_MULTICAST); else - *dest = PACKET_BROADCAST; + nft_reg_store8(dest, PACKET_BROADCAST); break; } case htons(ETH_P_IPV6): - *dest = PACKET_MULTICAST; + nft_reg_store8(dest, PACKET_MULTICAST); break; default: WARN_ON_ONCE(1); @@ -233,7 +230,9 @@ void nft_meta_set_eval(const struct nft_expr *expr, { const struct nft_meta *meta = nft_expr_priv(expr); struct sk_buff *skb = pkt->skb; - u32 value = regs->data[meta->sreg]; + u32 *sreg = ®s->data[meta->sreg]; + u32 value = *sreg; + u8 pkt_type; switch (meta->key) { case NFT_META_MARK: @@ -243,9 +242,12 @@ void nft_meta_set_eval(const struct nft_expr *expr, skb->priority = value; break; case NFT_META_PKTTYPE: - if (skb->pkt_type != value && - skb_pkt_type_ok(value) && skb_pkt_type_ok(skb->pkt_type)) - skb->pkt_type = value; + pkt_type = nft_reg_load8(sreg); + + if (skb->pkt_type != pkt_type && + skb_pkt_type_ok(pkt_type) && + skb_pkt_type_ok(skb->pkt_type)) + skb->pkt_type = pkt_type; break; case NFT_META_NFTRACE: skb->nf_trace = !!value; diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c index ee2d71753746..4c48e9bb21e2 100644 --- a/net/netfilter/nft_nat.c +++ b/net/netfilter/nft_nat.c @@ -65,10 +65,10 @@ static void nft_nat_eval(const struct nft_expr *expr, } if (priv->sreg_proto_min) { - range.min_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_min]; - range.max_proto.all = - *(__be16 *)®s->data[priv->sreg_proto_max]; + range.min_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16)nft_reg_load16( + ®s->data[priv->sreg_proto_max]); range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED; }