From patchwork Thu Feb 14 12:49:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158357 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324053jaa; Thu, 14 Feb 2019 04:49:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IbgIMlFfbc0F1KU15gFFMYASZP2Tr6MFbz8qYnlcecWD9pE7jn4xR06lGxcVC3qIgXOq5+N X-Received: by 2002:a63:61d8:: with SMTP id v207mr3621219pgb.308.1550148570567; Thu, 14 Feb 2019 04:49:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148570; cv=none; d=google.com; s=arc-20160816; b=zoeCg5gzHhyMOhc3K+iTDz4DTHwjaTQdCNt4Z7hAiA/liPxfxJNa9M8lEmo3ZJM9r4 3tHzyfLiJYNg4tgoCsA8YyDGIxmWjKbE6cU9Oavde04NFN47nkX3mkeI8KiJJLK/1Qdy ax9YceRZJFRppjHm+0KrtCrp074oqPy8AY36BdONn4R3pl5hCjdcxL5iDCxJ/JgGW47L 4Wbhrmr3yBOG4xC5tnSnheLlbdJiRMfNdrLxTClKb9TlVCUcaQ1WgTzLDlbKxZvasAII lkepreyd9sDqlfVToS+2CL4VcCQrVahfaTTBSgJ8QPWdJCGwy71E+0NGE7AVnC5O1vvw YRNg== 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=MMdGGUqwzhi7gL5ZjQXqxjshA/E0CtTskT90o1Q1bMM=; b=mALsXlq8BpThTghrki2bSlCVRdKv8mKY0VgVwVVJrpmn+KdruMKsv9VrjtN+CQvHxZ zLgUXuhsaWq63beLd4VNJXoORIHxdslTbVfnscKxeOEAefLJ5nJ6mSL74Xa5GuuMsCnz 2LaKqpx4HZKKMhRLmcItpsqOhLF+zHVMqJOKrjdTbvR18TAKgrlxYXxwYGiiiTVFwW3X IwUKy7cK1LcF6r9j9xcDBS00OdYflxOOJZleivcGZtT4UGUfk2H9TvWgKVOglP7jm7dl MmY0p0tjnWWPalNcT6aooTxQeHOZftkeHvpYKcP2Gx+HOA1/PlJMqjp1mkw59GzdSdBD 88rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AGwt7iog; 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 g26si2310745pfi.184.2019.02.14.04.49.30; Thu, 14 Feb 2019 04:49:30 -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=AGwt7iog; 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 S1732179AbfBNMta (ORCPT + 15 others); Thu, 14 Feb 2019 07:49:30 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39654 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbfBNMt3 (ORCPT ); Thu, 14 Feb 2019 07:49:29 -0500 Received: by mail-lj1-f196.google.com with SMTP id g80so5111457ljg.6 for ; Thu, 14 Feb 2019 04:49:27 -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=MMdGGUqwzhi7gL5ZjQXqxjshA/E0CtTskT90o1Q1bMM=; b=AGwt7iogQFF1N9Lfyu+9HWETWaL3pReSQ2uGK7Gd0wlVyhR/p52UN7LLpdEgFeTzfH Q1TLux6ZUSPXfNOfU5JAGjVlzi5UBymP6GbYRRkfcy4DnFACeyxwUugK7us/d6qWm35q Zo+nq8Uk4yPc6ndeUmfQebI6sk3R0bIkC7VHLpVbFqWL+4Zp24zay3G5gjMEybvGgs5x OQtJ3oTaEtdPpEHUjHiX5a85RnjX9d1yBDSVeLeGyEswFg7dhCXaQvLsWZjhosBGAfqS IwQEC9cMO43PLcWsGwVNN4aBv3BHMA7GbZBk432v3bGZXC/ZQjUie5PwLd51D0wOddol v+Zw== 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=MMdGGUqwzhi7gL5ZjQXqxjshA/E0CtTskT90o1Q1bMM=; b=nBvm8OxKhWRPVwJWTGIn0uHoB66ess6BgD69YgPGb29/EpG4JIu1pgqcdl//7u0PIS BZvcMnxtGU4AqYkbVOZDglPprS96M4CsTVZriXFZzFnjxUUbFv1qibq1wBRnW7Ue/KIj JzfTvVNxmka6EujUC7EL8cA6vjAt8bXcVrP63Cli+P8z/9mTEsrFtV+KPpttqYzAmcr5 imLLQHFYhDLs74ssjBBsI0bO2ZAB+auFDPx5zn1nCne86/oBOfT94VGzcOH0CtYW+S18 /kxrb3P1cvTp7+U4j7zigE4mp3rfHWW/hZVw0SyJPkf6roK6/v0kPz63l2MoqB6UAquM OPtg== X-Gm-Message-State: AHQUAuYjw7rxlFJ1wdUQF4rHpiyjhZkJ6lOkGRqMwtB6Lexppje7RE4S gsVWiSl5toerxTYCKMKygg47Yg== X-Received: by 2002:a2e:2e05:: with SMTP id u5-v6mr2287804lju.192.1550148566716; Thu, 14 Feb 2019 04:49:26 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49:25 -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 Subject: [PATCH 1/8 v2] bridge: multicast to unicast Date: Thu, 14 Feb 2019 13:49:03 +0100 Message-Id: <20190214124910.1753-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158358 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324137jaa; Thu, 14 Feb 2019 04:49:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IYzftuoC5I2RqFqblErQBhdl/IF/ikZ2xL8h/RqgsPk84lXPVTEJ7xkS769Cnm63eWy4hUo X-Received: by 2002:a63:fc59:: with SMTP id r25mr3708332pgk.302.1550148575411; Thu, 14 Feb 2019 04:49:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148575; cv=none; d=google.com; s=arc-20160816; b=X5SiIlclPyRnO70Rc0/Jb9fli2tWMPnTFl+53s7XAUMRvuDXR6M8K7R5iu6Kq0pqWy Aj6SN+/qaw39UdA6NFz86muoSR7LOnYibR3OsaQeja2v3s6bJUN75ex2ogNce7F77An/ q/i+spF9hcHEmP+n/01JCirZBVPllJXcaD3vYbcDqU/Wg85iOpGspHsqRTi3WRYo34Pw wlhdZT2g2k6VsKzZpwRci33DNSgJe3ix8HH+PZ6R49X9p9LpoahBIE6EhPxIJd8Qa7dO /0XlrHZAPgERCMhdAIH0EVEzD920kJD91A0Ryx4xvXzbhXthi37hwtEe0q8fCI6PVqVB u3eA== 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=sAjB2/DdSY6xXUbYOclDGEy9Obo/ZwlYpNFTINvAeew=; b=uWk38wneq9pBCHFdfiMkWAuDCYpBmI4hPamPDa0Bcz8URUGHpfWr4lOMJzCZV6x9RE FF3U0Of72cDvbcfjWb6X8VKBX1m53aBLiSD0lz2zr4W2JgkcrRgBwmz9YcuB6EoR8gSV Rn8eBXKiXOIYDkV27vsUX82LoEdOYQQmcpWKcpCIGmot2YZoqia7rzP8G41O0HVIiQSf hDLWVvUvmGKweqCNlMpe9qBCi++ekx8vRZrf781VyPsmv9FbyOUb9H10XL3qqsBnJXLD fna8N5FmIvcwp+1XCG5vK5b3grpoyYI31BLpotXj9aZS7r3frAdJ8QPrlvvWgMjzGPbr 4eiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JG9ZXx0P; 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 g26si2310745pfi.184.2019.02.14.04.49.35; Thu, 14 Feb 2019 04:49: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=JG9ZXx0P; 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 S2437786AbfBNMte (ORCPT + 15 others); Thu, 14 Feb 2019 07:49:34 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33441 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbfBNMte (ORCPT ); Thu, 14 Feb 2019 07:49:34 -0500 Received: by mail-lj1-f195.google.com with SMTP id f24-v6so5144249ljk.0 for ; Thu, 14 Feb 2019 04:49: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=sAjB2/DdSY6xXUbYOclDGEy9Obo/ZwlYpNFTINvAeew=; b=JG9ZXx0PCIjexNl1Re5fJRUo6JMX4QqvvsZBXXWtCHQgbowAG+AzqJah5ouC75/oCQ epI9+V1L1fgiQfT6EwVbiXQEoWZqSODLstygYwtgzPyHAPkDYQZC83B4w+KNqP5fBBqp zY9zSN/v96B2OzhbOf7EakjIXGymcpubeduzI79Ova8RZji3Q0Ks4LhgoO2w/R9fFR/M 51uddWjqJwCO7ccNoeKW1+N/S/ibEA6R6TsbLqXy89IWMeM2upR35l9uV7wmCa8kJZE2 JIfdezjVMqI8koERjGBtNcWJLVkggAwFCniwd1aSA4UqGM3D96x3350NBE37TQ/5tKz/ WB2A== 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=sAjB2/DdSY6xXUbYOclDGEy9Obo/ZwlYpNFTINvAeew=; b=D8UuV5QqCo2y990BEeB7o6mpCcZ8Lgev9oidMRhuzXXjfY2/m8c8eJXjoa5FErBBHJ Up55vjAf3acHeejXM60sg+4+5jNGL8P/LKq1IdApNwXruNc1anBitmy9w5mXrd2Z4Gfg RG6ayplmieHJH2fZGTkyvN0JIKHOE12N4CgRlm6zAQRrAspgFqD3D3l5Aa8ayYKjbyYK c7RQB55DAWxWZvpNmZXcb2plAp9R/1W/Ske21Ie43l2eVrTRqQOIJjIavi8gGKKmLxCc bLUT5wvNMMQ4SmCVjRN7E3RyryuOBABd1PbyW3mHMTr6PORR1r+0wiziFFY1qJHd6FsN kxBg== X-Gm-Message-State: AHQUAuYwjzqgqKSdoyS02QI2aG+4ckQj1YHGg7FetzoZylgMVfgWSb6k 3wJpssuzkPDlWIYN14rIwqf30w== X-Received: by 2002:a2e:5b11:: with SMTP id p17mr1653086ljb.37.1550148572384; Thu, 14 Feb 2019 04:49:32 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49: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 , Woojung Huh Subject: [PATCH 2/8 v2] smsc95xx: Use skb_cow_head to deal with cloned skbs Date: Thu, 14 Feb 2019 13:49:04 +0100 Message-Id: <20190214124910.1753-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158359 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324219jaa; Thu, 14 Feb 2019 04:49:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IbXjMPkuRyBdaCb3+Ilf8YfXzVClxN5YHjWfBDJlnbFSZoII15nxb4sMy2BE94dmVHd7UBK X-Received: by 2002:a17:902:280b:: with SMTP id e11mr3947514plb.269.1550148580995; Thu, 14 Feb 2019 04:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148580; cv=none; d=google.com; s=arc-20160816; b=kzcVK9HD/77Rac08owc1b9QAmXpWNtEYoKhcHhaBPWM3mVuZmKkaldk/7YrJ68Ayt2 1PCA1eLW4CxPqTDCnCGF46ZGEhihdFB9rRFVihRo5mcrJR/NtjUaXKWeM5iiRyoDrq/Z 3V3QvV2YYxbGc/iyCjC8LZ2Sv+gzD4KqG4wkCmLp5C1KjcVXiOtB4AQp03AOKplQBaRT dpj4hTUzk5bfr3OIyldm9HvC2XuVvMdNQ6ZpUAurXBBAStSOl5NSeXhhKunAvEKvQav1 wciq4E5EGw3zw/tERigBMiidnOwTYnK8nYUqDYQ1WsOdM5h7lR96gJ+p71tUb3uAr6UG 3iiQ== 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=HKPhEwlGOqFhzkRm115h8rO7RDajDFokqQWEPzK+1Ho=; b=aIKYhVcVsqgAb9hRAzHHQsNjLGIMXnV1Vawm7gHCs8VX54295OFtGBZIHXzpoZOKCM +GeAtL7xmzl/ha1jgfRbj3cGqWdwrHy1CtgBplMcBqpHcAHmI2sJs5YUn8+iHrKTFve4 J7oU8KYWNxLeGhjq3+p0Z2/6ColQBEq0/BnJzem6v6eqsYeyJzdiRjMKRhjbGpqDSi41 um0pO2sz+jp9UCf3kwMpBc0RvhTi9TcxL3SDivOlwm1IePOC/aOpPuqgXZsEWWmhb68W PL+0SrtmgH5P9UgZKFvpqBU5vuWFKadt2U/PrgtR6Dv4zIuj5nlfh/D0vm22lE2YlkON qi2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="DCEqtc/l"; 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 g26si2310745pfi.184.2019.02.14.04.49.40; Thu, 14 Feb 2019 04:49:40 -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="DCEqtc/l"; 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 S2438527AbfBNMtk (ORCPT + 15 others); Thu, 14 Feb 2019 07:49:40 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:44698 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbfBNMtk (ORCPT ); Thu, 14 Feb 2019 07:49:40 -0500 Received: by mail-lj1-f193.google.com with SMTP id q128so5088115ljb.11 for ; Thu, 14 Feb 2019 04:49:38 -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=HKPhEwlGOqFhzkRm115h8rO7RDajDFokqQWEPzK+1Ho=; b=DCEqtc/lmk6N97wQQtOfkNN5RdC44kkt98/g7JpkiCniQkYgs/hOpE4Qk9IUJNRq7I V3wGKnG13FT7YXPlS5kKizj7Yw+uhJeF/OK3cQzEzu7/aujeT5wYX7zVST54kK0Fwn1R qnZgcPmI50pYK067NjX48BNMDnVN/+S4kKiS4zw4fPHQJRhrXK5C+dgYX5XRIQIzERPr +akt46/vhw7iAukyTnBUTTMe4a6teZ+i2oHqbIElvL5NOhWSUmhuN7mHq7uyR2GC0kiK CLTbgYHpj9ZjJfbCXPuQ5O62WFN38jAc6KDc/WYLGequbdtn00lnCKdp/qegj+7J6whR ba2w== 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=HKPhEwlGOqFhzkRm115h8rO7RDajDFokqQWEPzK+1Ho=; b=uYcMMCBplpID6z99q7L1A3PHMBvxl5hBs2gh6BXOHSgdFKxoAqyGdkb+T97hen11Tt 1w0UZmwpqfMNw4zbXpdeZ+47Uw80B5uzOC1xGK0is/yjiBB/WvaoN9dqbhjn+N6c6GKC BKmgjNnI9i2w8GwzCDlqC299eX/Hjh2Wt+fLu1QyzBlAztomZtADcewR+Mc/8An5urRY Bc0Pyu44fF4Uxr6HnNUpE8sYg4baJwMY00yWkgfEgm9VXeOuOq6NGkt3/N/2WsXEEDKc DwWxqepuE+/DyBQQWwXHJKuPwVBI0oIgSkQUQrAXy6LNwDPiWzjmLVb13mOEmlZ8O8kg M8zw== X-Gm-Message-State: AHQUAubOVnsUBOv3gRsGPHpwUYPaW+gf1XIS5QHTL0ys2v6bavovz/3C 9uLi2IxLVjq84HpS16ToYATv0g== X-Received: by 2002:a2e:9457:: with SMTP id o23-v6mr2307627ljh.7.1550148578073; Thu, 14 Feb 2019 04:49:38 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49:36 -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 Subject: [PATCH 3/8 v2] ch9200: use skb_cow_head() to deal with cloned skbs Date: Thu, 14 Feb 2019 13:49:05 +0100 Message-Id: <20190214124910.1753-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158360 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324308jaa; Thu, 14 Feb 2019 04:49:46 -0800 (PST) X-Google-Smtp-Source: AHgI3IbMQBmy6N4k9vd/QzVksw2z2uUh21fOKZPwPrHIAYrx7W+DkBzgQMV1Y878xsThOT3pylJr X-Received: by 2002:a62:1382:: with SMTP id 2mr138396pft.157.1550148586493; Thu, 14 Feb 2019 04:49:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148586; cv=none; d=google.com; s=arc-20160816; b=nRdYAURy91AcJN2RrCB6eBSUXC0xAnsYpBZfk6iGI04WkrOA8HhfppcbQM3sL6PIkP OUv7qhc4nqoKXHPMgqP1SODuPqPNWdn2CrNI4WxQM1rD4ue0CLEHe8sIhzC5zTpTUAZF NVaieoGQpWWC7ZwnMSucFB1+Y5BhRZB5rI3Iq+xyx5xxlLHau3T7wMvfFO0T+pQfptZ6 0xaOrA1mNj/beVXJ8vInE4xv33DTsEhGrVV0D3lewBeIVS3phmNnZfEEb+McYwX0bX8x 8L/dDLptbUnzTwNeIEoKBXf22oWrqIJGPiSTpyu+BZ3KymYkcUaeaQCy5u1EF7AziY78 1A9w== 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=MEBfcUpvsFkrcgNCjUmPh/+T0vkp1uHt8yb01MqBA7U=; b=paaUdnokXtuSReh1sinOWYWFZSAL3+jtBg6FubziMk3TLomf4aaajF1ulEdv/B3Dhp 97Xb+3ypbkYVXbM9TXD3Zi6XGhoG1uPLAG0KL+k5+qUEGyimGGfsYCKW9W8C2j1DEHJP J+fDJtR+dbQvHvz9q2fOvYhYF/S51tYIYi+tHc0Uzh21bMZ9MtVSyylY5OOYaRkaoa1W aBo9EljqNd9wlUbA6jA4S0OcCazPuBKnUvNe0Qa60++VOYOUhOJRL+HlaEl1hR0gPl+v Wv63PEAiA/Ybm3y5wDzjLFmEwWlcUOgUvBG2uZfbLkCB1a6ZT7rikWnjs8TYonVK4ztB 5gsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pm/Ugvk1"; 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 g26si2310745pfi.184.2019.02.14.04.49.46; Thu, 14 Feb 2019 04:49:46 -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="pm/Ugvk1"; 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 S2438533AbfBNMtp (ORCPT + 15 others); Thu, 14 Feb 2019 07:49:45 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42050 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438103AbfBNMtp (ORCPT ); Thu, 14 Feb 2019 07:49:45 -0500 Received: by mail-lj1-f193.google.com with SMTP id l7-v6so5108036ljg.9 for ; Thu, 14 Feb 2019 04:49:44 -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=MEBfcUpvsFkrcgNCjUmPh/+T0vkp1uHt8yb01MqBA7U=; b=pm/Ugvk1Pg901IdT39EYeMJl7a1QQQNalwBjTCHchQT7+7uM4nWGhrlhzxeuwSy4hZ 8q5jpGPkFUdLQ8rla13Z2Asd9bLz6GdlNt2PG5cWiKIubB8S1rs18s1M3Cq7G+SCGiry 4WcvZOhm0/IbFHGh6pOBPgMXX6XG2BB/5Q1AS7cTcvVKhRpW963rCjZNbIPZPUeCQybF Q3KJ7rmFqNuTgUB/LQWELxVjZZHiviJXCqs88jh8fhrjMn5jHjvEHAEyB07+2L2fpyGd uQl+9EjYlGnb6eyne0yCLrwZS5RfMFlsFjowqDjctkF7nWiBd4/8Zgov9tQuCONGZMw/ ZHBQ== 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=MEBfcUpvsFkrcgNCjUmPh/+T0vkp1uHt8yb01MqBA7U=; b=mA+WWKIYyBw0PkeYSM+aDzl0z1UT/WfULWMKyBypnsL4rcfoRX5aX26H657kbcEJGZ IWCqf+ETeWBZjgqCML5C6etYrD5Rh6V4Y9c17f+ieUUqtwx9RL6kbD6wKFmJvxt8/FKr gKUefaD1D5/lLiUtDmTNvHi0NoMWRtIOPy8SL93g2FclFMn+1K5LL/Ksu00ulHewFaFF Hv8qPNGKLOzp+efMQH0B2fHxTnP/L4te+y7Ix4KCisnRQRWNeMUSU/D6uyAbj8ybxxLf 9tObA8koBzOvrY13CBuBIH/w3drCg9yWtevjzGqZvC4tsgcK5A5zXdDnVo4HvHN2y4ll kLvg== X-Gm-Message-State: AHQUAuZcVJo0sLs4uXYSzN1qIRfb4pHTb839o7QlMJ/hES3TPfWTxb5S o3a7G1l3EfYjrJCN3scaWq7J8A== X-Received: by 2002:a05:651c:112:: with SMTP id a18mr2312428ljb.45.1550148583493; Thu, 14 Feb 2019 04:49:43 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49:42 -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 Subject: [PATCH 4/8 v2] kaweth: use skb_cow_head() to deal with cloned skbs Date: Thu, 14 Feb 2019 13:49:06 +0100 Message-Id: <20190214124910.1753-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158361 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324400jaa; Thu, 14 Feb 2019 04:49:51 -0800 (PST) X-Google-Smtp-Source: AHgI3IZNRsjWWeosXWd/aNsw5xAd0oxE1iFn/r/yAmm719e/1nvGjG94Za4243vKOpKJ4Hc3JXE2 X-Received: by 2002:a63:d703:: with SMTP id d3mr3655997pgg.167.1550148591324; Thu, 14 Feb 2019 04:49:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148591; cv=none; d=google.com; s=arc-20160816; b=nlpRH6lNDRrA8MUqDppzLJ0/NdRunvQkaTGklZrWPyEt1dZrvdR7fa9fNx2eAsdhDs NggykJJd70O/yFZ9QKNYijQlx4d7t/La9G7NMGsRcEtTkqt5PNE7a7/60e8djW53Q5Q9 AvgF9VrHCkpOi7qNl3lySCLLAIBcaCJrNZiIQuqNWIR855eLyruYWladtDKL0mKcQAxa 5lXHjvEX71Fhqrsz+EZrgUwSEFhpupMtaXTg89hqg/XSB51aYAUK5RfurCBL8EBlvJgv AZczm6HRS7EaKUM2ENvXXMGg/FVedCQrbGzYQnpPfGUwfTSJIOTeJvOnGQVI229szVnC PtdA== 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=czvD/5aRHbfC6FnZcru5EiNTfQ62VgX0N26NRRFAiM0=; b=QuFpsfhrUE3vZW4VuKtKl/x2Yj5PyKPPdCbhMwIBec2QD1zX3G6QzTtVphCxM5QJ+7 bstvY2ffK3Gexd4Y16J9vhRxQi8n/VV8P7M0GpMB40t/Vu2nQzlrRShItVSBbXd2btei g4EqCLhKooPyNjlN3gWoNTq6BLaRE70dWfABXTymML0uvzo+/WUZFah1VX8QKcZ22Dzz Tnfvq42nQwmC0OBnmwVlTQVR/ho8RDzcANXuZeY/OYwdGnZL+Kcs4iQFIYX4UofFmQ+3 ipL2fsInMWUjagDRaUvG/6YQ1So2oSImMJzFELHvoQocQvPr8YuXlZoGdXBzpLqptZD4 yHVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ip4ZCXtZ; 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 g26si2310745pfi.184.2019.02.14.04.49.51; Thu, 14 Feb 2019 04:49:51 -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=Ip4ZCXtZ; 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 S2438103AbfBNMtu (ORCPT + 15 others); Thu, 14 Feb 2019 07:49:50 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36673 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438534AbfBNMtu (ORCPT ); Thu, 14 Feb 2019 07:49:50 -0500 Received: by mail-lf1-f65.google.com with SMTP id q11so4456858lfd.3 for ; Thu, 14 Feb 2019 04:49:49 -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=czvD/5aRHbfC6FnZcru5EiNTfQ62VgX0N26NRRFAiM0=; b=Ip4ZCXtZ0G9QmjxnJVxYftsWGax1/HZ/PQLLWZtYjRdOLgmC42eV+BogakBIxhCCa3 QcfFbDUe5pILB0jNph7wxmomu0HNxuVZ9w67s92oFXhzQYSY5CYaLjp5W+PC6V+Uv+x5 PB6C+fg3Tj3Eoue8Pp59CQ0dQCfq9YyQicioLsjsORxr/lhBz6ngP26MaM+EgVfR/XX1 nmqWH5nD3s4LC9mcqmTOC5mFSlgTkdUN5pr7O2i+obEhaypaWQwXdy5rBOVCCEiPVoDq 5Xg0/oi7FP0zQi4nmhchPPkMUfQvCeovqiAFG1kamUtfs4zlIook/kzUhBZe5DszNdgi vE/Q== 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=czvD/5aRHbfC6FnZcru5EiNTfQ62VgX0N26NRRFAiM0=; b=l+DISM+cGJZNBauV6mjAzRlNcl0Qjcu78b1P/eucy5KiXGJT4V0mmJ+MfgUuTyPpRp lXDiHOugybo64CMn8BTCjlk6Yda8ef8JftdmexWjjmx81BbEA5CVs+l+DmMxSP3HepTL BOcKWIdVwIA43C992AAodVQstpGvUDG3hMfxXVT9iPIFocg0FnRccDfDQFhhv0U58a2K CxsmxgzI5cmSdbXOfX8pKONQOpmrWbPYkznizk2yU3/3BwtOtKs442hZilpE8pQeh6xx iezAbOH3H7EiGdsMBfpMylyCtHcBr9E+c861IHC4gJIEFW5wV4ddROj3Nkj8fVaCjOX9 EArQ== X-Gm-Message-State: AHQUAuYj6hsxe7ghw1JIgK+yAm2u/F0WrY0G/ilGm0BU5Z7OnBFJmAVQ M3lYk+UU30UoPUyt4N3DLdICqQ== X-Received: by 2002:a19:9dd1:: with SMTP id g200mr2222500lfe.127.1550148588287; Thu, 14 Feb 2019 04:49:48 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49:47 -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 Subject: [PATCH 5/8 v2] ubifs: Drop softlimit and delta fields from struct ubifs_wbuf Date: Thu, 14 Feb 2019 13:49:07 +0100 Message-Id: <20190214124910.1753-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158362 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324508jaa; Thu, 14 Feb 2019 04:49:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IYykBwbTQP/XpItkIm3Q5Iqpgaxnuxml+3wqR5a3HCAjsOYe1OonBTHLt/q3YI65s+W4mYx X-Received: by 2002:a63:61d8:: with SMTP id v207mr3622790pgb.308.1550148596964; Thu, 14 Feb 2019 04:49:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148596; cv=none; d=google.com; s=arc-20160816; b=n9xOKfkQrmC6W8J7LUHchdyhV72FSuPIRjZ/K45UM1lHgowfUVd2o61XN5Ilm0LRHI 6FWVU3OQ3Tq/z2GUUP/RiWicCZMZ7si9Rvfrwxt1LBtabwH4Mqo93U/rlfTVh9duAbIp ovJGzVDBLNCHjWcY/jtLSi0KHGF8ju5hSdTWv7PMii6UU2g+Vcw/vDdg++oCoItfI264 rAuHq/8VMJd6XKiEJFdTlr/MzHqXWqKxfqjQdBUfosVIBQ9i9xjXY4OLYJGWPocUvNZ6 xhC/JZ6nPs+Cc/bXF/ugm8VFFDntNegQ+BaPj9fSUu4qmx5mEVL+3yBroMzd4DQwIw6x Zv8Q== 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=FBwDVBVidpKRU12BmkXiJ8IfZ5As+ofjPPWCh/WKTFI=; b=gVmp7VzvUHR0Ic65wyWtSRDHyHGl+xc9UUYlFHQSyh8cDcZoK9+LUOtiC/NIwoy6Gp p8aPXMgObaJqdPE3ylZER10TmQJuRZ6BzA9t0FA4uvjw9HuZlgj/CSG43W6SsxEBr8+b FL5Hihe/A7M3RnnW21Uf1VF+Lavg0kayvQvHAg7L9qoS3J+IAtwMi5qyLKINUjF6xHIp h5To07VZFWXkz6yPjgN/AAEA+CC/mzJTRqYwnrg+JIHh4GBXhO/yAVSyTK6gmG/4s4np OyTy5SHoNCBNyk8OgmNe0M7wf25cMVV7uDQkg7c+mmptueOuqCntGiCbK3kRh8N4h+GM IkEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uzvuJ5R3; 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 g26si2310745pfi.184.2019.02.14.04.49.56; Thu, 14 Feb 2019 04:49:56 -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=uzvuJ5R3; 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 S2438535AbfBNMt4 (ORCPT + 15 others); Thu, 14 Feb 2019 07:49:56 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42067 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438534AbfBNMtz (ORCPT ); Thu, 14 Feb 2019 07:49:55 -0500 Received: by mail-lj1-f193.google.com with SMTP id l7-v6so5108444ljg.9 for ; Thu, 14 Feb 2019 04:49:54 -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=FBwDVBVidpKRU12BmkXiJ8IfZ5As+ofjPPWCh/WKTFI=; b=uzvuJ5R33xqzg1LEYMpcjciQ7h8OQvjUHBpVDN31tVUndmUgcPC4tnHYOIvbuhT1Mj 3W/mBWqd/k599T0VPvreKAvddMC+pEVPCfngMr/hcEEwp7jRsPVJuXozSOEQycv92bPl 8zeCWsAsb3f1xgwvosYaORFrYb6VjuXRG6WU1PXVhsYWBJ9dq9/Q+16k8yRIMjINzpTK N1MmuACyCm8WnR0++fT1m936f9Pc50CWGuejbul4GPi8a16sMAtjtiwSWL0VfNjJFFBV d3bvIhD5Wv1iSH806YkVVtfPEYcZdJo8k+j/nENU+AMbXoaB7ghRKiSUiqgdfk87QFdy lYeQ== 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=FBwDVBVidpKRU12BmkXiJ8IfZ5As+ofjPPWCh/WKTFI=; b=hzTnJJcOoiPnFLI8uqmLHj0OekPRDz3/UD3sYSMMLvt39ZMN9OD27JpHyESjPgLS0N 1JK+wp5GSnJ4R9AtV9G19q0SNwtQc00EiFFCC8ddblcutzS6sSanm+bdSW63anTSGWSf wMTdXifxOeNGv7aTKzigYYUkU04W5KgU8VSage+R0NeW8zXcP1/iMAXAtQOz0yiklL7N cpCddjaIe5xrYAsaLSb4fVSsIhcRkD9QbEvR3PHB+uwgcSTKt80cbvpUxnfnKdXIy/oD WZ3gE0SadfVd+eBcqjXLm6M3Kpm4Cd2dGWjBscGkfzcgvBgY1pcGgKxgIhN6RAdP7Z1d 5t8g== X-Gm-Message-State: AHQUAuaagwRXFRbXS5EoGvExyO2lrrjbkFTXHaefvSS9wcRfX2yOj+Oq 8gvD0MGS1KM34BQlW01+ZwXThA== X-Received: by 2002:a2e:2d4:: with SMTP id y81-v6mr2328076lje.62.1550148593641; Thu, 14 Feb 2019 04:49:53 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49:52 -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 Subject: [PATCH 6/8 v2] ubifs: Use dirty_writeback_interval value for wbuf timer Date: Thu, 14 Feb 2019 13:49:08 +0100 Message-Id: <20190214124910.1753-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158363 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324577jaa; Thu, 14 Feb 2019 04:50:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IY/XBrqndW8ZsZayNr405usEiGTyIxcS5TKo/mKNmUzmj8hM38hPFvQ1eB+6y5JrXr8PEkC X-Received: by 2002:a17:902:f24:: with SMTP id 33mr3986564ply.65.1550148601397; Thu, 14 Feb 2019 04:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148601; cv=none; d=google.com; s=arc-20160816; b=AvqsExjVspewxpqRYAlxTh9bqk9NpioAOkTqfGv5e14Gj9CaviHxtQiyRf7f8LIhpS vdOXzUAjEMLdep3JYiR1ajahXmiweE2EKbkNuXhNZGhEAQtmsLaZSFRqFGD6JsqZF5HE 9bcwlbnKi/UNll4bEd1yA4IrSUzFb2qfnCiKIVTC5CH3F1fgbfBK5ln63mTxqPD0viKm kxFZ72vzHIk2XlVjSfl89Huytu2ARlBkxDvtydrtfdWu+43ReuFdqQtQ8ElWDozIJKdR 6rv+hN4yx2fbDhXsib7lC7G3gAVX52Zk04+rCNLj/zBthJIR6hWoyTg5r5EgLo7DoHH4 pQ6g== 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=Fxknzsw8wo/owOBG6AKywzPcTEzf9ubrnMGiAdFliQ8=; b=Hk2jtzwQmG7BckzY/HyiDMdME9/RUiB871/KpAZuo6d583MN72VE+hqPGUeSsvbvOv x9IgLaJrDl/v002REDCllamDMAy5R+iJ0FA+8c8/gTAcEnt2Wj4E1hPizAHBnNPsb4Qo lsDdagTn+w2bPPcXeFlpxIe3GrRtm0J23GxebJ9I0W6y2+/jt4SdbmP3dmH3Z4Ku0RCt dJmWKPpuOYOa8MQYSp1n7JS0Kj1AVMIguwB/mDv6Lc1M+i3yoJyC/LHka6I59o0AEn+g WZ/5/g6x/omjEY6iqGIpqrO2eiT5CdLjoBgnxWz7ZCZnNPaa/6i+i65ibrC9SDmc3/p/ alGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vgmjHgFP; 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 g26si2310745pfi.184.2019.02.14.04.50.01; Thu, 14 Feb 2019 04:50: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=vgmjHgFP; 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 S2438536AbfBNMuA (ORCPT + 15 others); Thu, 14 Feb 2019 07:50:00 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38059 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438534AbfBNMuA (ORCPT ); Thu, 14 Feb 2019 07:50:00 -0500 Received: by mail-lj1-f196.google.com with SMTP id j19so4333221ljg.5 for ; Thu, 14 Feb 2019 04:49:59 -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=Fxknzsw8wo/owOBG6AKywzPcTEzf9ubrnMGiAdFliQ8=; b=vgmjHgFPYyaFw4kxCYsDdV3s+7JepscmYkyu2JziqC4xU3LzD5REur1LaP9Bj3xYxE sRIMrEQy8TcheUsFQtjxYp8BTtPm5mPzW4MTD736jTuTkF9AqBM7djjtxWkcwZokHhh2 EGYJQ1FAhuQ5Mp+M0roTsnrXpuPyKQnC6+3kvgLTaapxEauJfBfmmDy9E6Oo0YLyc9JF QveOvcXKcrVkxBa8eTZ73n5oEPbUEitXbvnOke/tR0W5HTY8t9HSZk1XXjSBnVx3y3oj J6YBzpdj7+EXAfxIFlo/0K4h+2K4nr3c4JaJSfKoYl75hE/Buari1CVW6T+4M44UD2CV JbYw== 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=Fxknzsw8wo/owOBG6AKywzPcTEzf9ubrnMGiAdFliQ8=; b=T14TNcKX4K63twBfOMzVXcofy2rlNyAbhRl8oJVGw1yriUu17KRzihM1PjeWY9dwKv YjtOtDwkdxqoQq6+fWHkqaZcqq+tKsnsQ4S5Rv2QlMeyuyiftGzd7YJBqE0iiqGo60h2 lcQe1T4123BPBVvZxKGgkRkUm+NR+bWpB54eCc2WpY6stcKd+e/0kyJaJ5dolEV7mNDV eTfy6BIQEH2G5mj5Z+fNiWId1LDOvP8NHxQj66gYxjUQnZdcz0zAV2xRU/zdw7P+Pv56 HBeLE0MMHMtj3620pdiP9EJT433NEcflXy9pWEBzyrbu4nbOVWfpi8umH/U3onG6YMbG gDjw== X-Gm-Message-State: AHQUAuZQGhzia12l8Q/waF5poGL2FXy2dwYps30x8ngucNWR9kG5D1dO 77ZB8jli6u5M9sgMGXMPV8mCpg== X-Received: by 2002:a2e:8156:: with SMTP id t22-v6mr2385064ljg.32.1550148598486; Thu, 14 Feb 2019 04:49:58 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:49: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 , Felipe Balbi Subject: [PATCH 7/8 v2] usb: dwc2: Remove unnecessary kfree Date: Thu, 14 Feb 2019 13:49:09 +0100 Message-Id: <20190214124910.1753-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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 12:49:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158364 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1324674jaa; Thu, 14 Feb 2019 04:50:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IYJvNqh7Hn30qdYn3yYmP+/lJVap1XKaLIjqC2GXwQ8EMlMJwaDLV3VM9vgKZNWRQRyWL46 X-Received: by 2002:a17:902:34a:: with SMTP id 68mr4063227pld.268.1550148607544; Thu, 14 Feb 2019 04:50:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148607; cv=none; d=google.com; s=arc-20160816; b=XbvQ7XUCDG4KwlqlTXP8KfFubecCWJy8WPIokOh9rF3Q/oXUQR5vx4j5JHxj1dc6LR y7BSnK64tDc6jv0/upP0zuzF1P6lka8ia4tTXZY5uurT6BQDfUy/PFqpNP9FK/CjYTiI 4DZY2upWw5Hc87w3AYSw/tpg9/CMCXogkkTiJB3MoWzi0yjhH9/1Ebe9nRlkSGastdzt V9eyLf9rKaqAa0O/i7v3FIfTF7Fi7IexHsx30824bQD2zSu5hUGJJttYrdmi7pL5eg5+ Wnve1HvSiAwLm32O6U1mBz1MhWH32ec1cXJUVEi54BnTpHj1UQlsrFesJbXAUJ5Bywa7 +Jfg== 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=7EvPJ2Wt7+yVE2pI7OhzmtQCLAhLoFFYZ+TxZ4iVgmY=; b=BGrfsqUFkGqyWYemDEGtEQCsGBhYiJ+HqBQ3xrIbC2fBJaxwAuX8PHuCaK9mvg7AoI 7Rw0WZ4J2svSowuFCTypkNg/aB8S2qU2tJq1LXMyVS0IL8cZu3ydbNYOnNrUWylCQiHk /RHSsyB9lNpdb4tPnp5dslugwstdQO8idh7ywuJdp+rVgOarFXn2LcnJri1tmZcJT7n5 K5jTXgCdHnKm+Qckq8wDBMqVWG/v8HHZpopnmISjiYV6ESgKuKPTG8iuLYuGiOJpnf8w FWgJ058UGM+6pN+IlV7PUyr2gwKJ6GD6HWwO4eYE9xWXJu1CHc/0B8dOdCDgZlCYukcY AH2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gp9iaSRe; 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 g26si2310745pfi.184.2019.02.14.04.50.07; Thu, 14 Feb 2019 04:50:07 -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=gp9iaSRe; 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 S2438537AbfBNMuG (ORCPT + 15 others); Thu, 14 Feb 2019 07:50:06 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:37112 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438534AbfBNMuG (ORCPT ); Thu, 14 Feb 2019 07:50:06 -0500 Received: by mail-lf1-f68.google.com with SMTP id n23so4456905lfl.4 for ; Thu, 14 Feb 2019 04:50:04 -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=7EvPJ2Wt7+yVE2pI7OhzmtQCLAhLoFFYZ+TxZ4iVgmY=; b=gp9iaSReQIoChQOGhXHqWnMB3+cH7Y5igFJl9FL2NqePzjyi0GH1wY2cqulsoDeD5R D9maCS6sUKSiOrxq4jNywEYCMjjvfXo0pLCxARNx9WBQV2x43OkfY6UyL667geH/Zji2 lRYcYcqvfCj9GhiLCWHJb1IwQDx5R+4eHj5Yxcd7oMJ8Zi9qUlssIV36YAeVC0fRvKZv YrK4l2z1Sgl/15qfmlc2QzWKsnuMtjdH/VdHwB300K0GAJ9mCuM3G/ysv2npQ1ntcOAe uUBXpZjCm/+JYOSvOb1vLQQ9SfxhXkfRll0e0dcYh7zoqqHhjFm3s32F72ucr3TKohF2 xEsA== 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=7EvPJ2Wt7+yVE2pI7OhzmtQCLAhLoFFYZ+TxZ4iVgmY=; b=azVeiQeUo351qUWiZ/KIQmoPz4yBJwmksQTJod26cnnwgxy8Clhqk/18ExN3APJLaC hjyEOrWE1635888Y61um4bPgHVKcn5XKAyJwpRkASapxqkrS+p3ZxDQ/72dl18VkUYdy m00HBKxyVm4thlQA5dBiFtzAdq7sFHBUmxoAuGz1CS8zYk784fxHINoosXt/9eUtdnJE RfvahPXTI9qYU2+EiMmodDYjIYYaqbKJVwA9rjh+e8dvCYb1QvQeFZwqH56MS43M+sIR exYg3nGXNovxdTdqOxlXfEYpcROLCCDKF5xM9agMQfp09uck0fPbI316272N8al4/h94 0DBQ== X-Gm-Message-State: AHQUAuZ8r2oNsG/YfTKFkO8wFkKVvLcBlj+2qVn7dKeqChcpIAbkmCCv mGLIP39PeYdY1uv9E2piq1is3w== X-Received: by 2002:a19:7dc1:: with SMTP id y184mr1127834lfc.131.1550148603549; Thu, 14 Feb 2019 04:50:03 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r7-v6sm410853ljg.85.2019.02.14.04.49.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 04:50:02 -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 Subject: [PATCH 8/8 v2] netfilter: nf_tables: fix mismatch in big-endian system Date: Thu, 14 Feb 2019 13:49:10 +0100 Message-Id: <20190214124910.1753-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214124910.1753-1-linus.walleij@linaro.org> References: <20190214124910.1753-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 --- - 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; }