From patchwork Thu Feb 14 10:24:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158332 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172260jaa; Thu, 14 Feb 2019 02:25:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IYbFx0udNV7qqrFoKGJea2CXfwX6OTgyjxXSV+V/Oyrw2sxEpjv7nB18SvSoFly387yp27I X-Received: by 2002:a17:902:4503:: with SMTP id m3mr3329239pld.35.1550139902298; Thu, 14 Feb 2019 02:25:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139902; cv=none; d=google.com; s=arc-20160816; b=JpWiJSdqEy3/7+O6HUL6a+bwzifRZ/xh6wGC3mOPBSDg9vR7PXciUPY5O4b7m20q30 gQA+ZHDpxw/2gBc142In+o8kX8gcsGPqr77BJ9MT+pG8j7UOJ1/Iehf/gCYJmztsQtDC akBu6Deu9RstjILfMFB09yFGaUcRj0feC9x59Uzcc8BsTEGkDIos7dLYf9DvWRGZ03vQ MU8t4DLs0eSxygGG4tKS8DND/9M4ewox9v0o8a81sJYbmn3a9U5v8t0bv72+lkpU0Lvp 2toCTmHwXbn5eNR6Z7sx8tbJeW/43iSl3w2KQKt9+NrqNjAwkKlaccEVwqhvkKFe3W8D 5BZA== 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=mtSkmQ7y7yuwVRe4TRUnedLZYno5zujrmzDMx6VgLCo=; b=d30BYxHgBR/lcgWK+x4B6tJh/5+tAQjLgpXV5/qwJPNGCE+9mgEuC4SKCbOHxykOdG thnk2Zr7TtOtmZJ1PIbX89SgMGJBh4Gft6V+Ms8uJC6VwBKUV8MWk02+2qZ9czo/8BFw TADMrQmqpH/JpFD3O6Vc0iPrvMb/EsAnfH8W2g8/jxon/AyCL4PcHjjQMTbQDtO33ohD /zvXbWhusvsezC7mCZSFKwhIXfRnM2dzHMrH56vRecBx5wLrrHrpQTBRz/2nJGpRg6QS z1tkosnfP1oK4tEOh1qElVe0re0KuPLExM46db1fmVwada/JaoDAOdPMa3AQDRE4qxxq TJQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="oi/o0uTx"; 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 3si2132062plv.258.2019.02.14.02.25.02; Thu, 14 Feb 2019 02:25:02 -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="oi/o0uTx"; 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 S1732309AbfBNKZB (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:01 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:46259 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726392AbfBNKZB (ORCPT ); Thu, 14 Feb 2019 05:25:01 -0500 Received: by mail-lf1-f68.google.com with SMTP id f5so4100637lfc.13 for ; Thu, 14 Feb 2019 02: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=mtSkmQ7y7yuwVRe4TRUnedLZYno5zujrmzDMx6VgLCo=; b=oi/o0uTxcKLtb9sIzTxNW4myHBgj7ewNqhTe/q1KLTgXTs/P6gNcG9/fWN9vcjsBsg S2P3nFuAGSQAKjqCQ3GlmrbQq2mc1+oTOOad9UntQxzhi+WzClF4oDXbF0wkFVnPtBNm uiLdtSnSZ4kVncSWVPUEKOjkDvgDbvvGHgyRg6N7y99My85QrKCPYAWHKUmyuvXm/LsN /d2gjREw0leDqpPyreG25bYJB5TSXuoLw8qcf5GngjIIe6vRzkM6pCKr53rJAyep+kgf c1AXP1/MpV6VanFvcR8k212z7bVZm6C3E/xlg9ffY1KSSU2igPvN4EotFaq+6YFto1CE B15A== 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=mtSkmQ7y7yuwVRe4TRUnedLZYno5zujrmzDMx6VgLCo=; b=sldQOtgwgj/GWbKi0cSm/U6oiXdqtxoqAQDMt0rmjdn3jDZZzjS30ohCMoTQweaYRo KFbQOguh5fJ27ZXLDBsWB7Fmg0M16bLxEluZEiJlB4r69PNFmkZ/RPSWOMLZlH7h3zqZ 2sh9I3oFkpHvns8Zqu1GQZzDQLRdeUCJ3xfEBuAXwBWlUwusKefgc4dcQNo/5+e6PcHw bYFH8XsorMWjRahvh5dDUwT0JNmzbywHFPNF29MS6GkBBHm8xiTaM689yka/adpfML0P OqC4MUrIWa9SvsAaDl9PROlk6YtSx0U6veuGxYKD8OKV8iQ89PwBKrOx0tMoGLF5dygm PgAg== X-Gm-Message-State: AHQUAuaY5PCawdRLX3X0CjFmp0CZN84l9gY/9wySUVOD4jhId+z+zh2D C0U2j6LsCti8ZCSD8Y466dQr9g== X-Received: by 2002:ac2:55a3:: with SMTP id y3mr1850803lfg.93.1550139897500; Thu, 14 Feb 2019 02:24:57 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.24.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:24:56 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , =?utf-8?q?Linus_L=C3=BCssing?= , Nikolay Aleksandrov Subject: [PATCH 01/10] bridge: multicast to unicast Date: Thu, 14 Feb 2019 11:24:27 +0100 Message-Id: <20190214102436.5092-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158333 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172316jaa; Thu, 14 Feb 2019 02:25:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IaJry4Ru8dlTCsL2I7t0jaEAB3iOM9eLQ+vHTHo3rKXe6oUZ4AVzGSlbCGLwFUHEL+5Rwjs X-Received: by 2002:a62:b248:: with SMTP id x69mr3221126pfe.256.1550139904732; Thu, 14 Feb 2019 02:25:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139904; cv=none; d=google.com; s=arc-20160816; b=zqNzmJ6nSAuJLsaCil9IA8zQXaTpXLUVAwvvwGSmLG2kqox49ZJ2mtyUOIQ769grAo HnakgpUE1UVwYzOmhWiQAAno6nSMj3Vyfub40Kl3UoDvpSAcKiHnagCjVpoOO9Xr705S 1ELlZVq8rQIutMLggk35jqUwQuBt5u2XEAh21iK8DpneEsf+B+3YGR+mO+R1Bs9/zB2a g5AwXBVdqQa6zYEsiNW5U8Vd6CVRpNhE7jBl7XkAJ2C4g3DZJ8I/4GgJSAZfcuA3Tw4X G2FS37xMHFQfY33InSv34KC3F5eWKyHNqGTIMvReL6b1hX3bQdwJ2tH4gDSf3kdW3hrB NfsQ== 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=QejVeuN9JlqnVwHudfbz2AR9dbAYL9NjcCDz/Vgr3MA=; b=CY8IkdUdEMWyovsY5ROEnh9aLdlZl7dlEUTgJ4eU6W3rhuicXDt0TmKeh6eBPYPXLM U92Ge/Brdb12vkodj9gSoywRnk0ieLNdMmtnvVSKfwmduvayHJFyzScq/8Itj3wrn6QQ x5UGsRIWaRz3JckD3jBrR2FTv3hIVZIJOMS4jdiXfmHpTt+frHX1+9XBYyYq2gc6+B60 A9Mv6wYT0HyoBTCzmbU0/n3WuENWXwPJQ8jqquc1NRjc1LjB50rziEQSq2X+SOaRuzAd TaoPhf9glORPPY4uaCOxM1GPvQ9hPCAJu0WIg2rGeHPSlo8yIAcXZc/pTMfjJh7mqK2U cmQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZDiaU/ds"; 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 3si2132062plv.258.2019.02.14.02.25.04; Thu, 14 Feb 2019 02:25:04 -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="ZDiaU/ds"; 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 S2388561AbfBNKZE (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:04 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:39061 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387899AbfBNKZD (ORCPT ); Thu, 14 Feb 2019 05:25:03 -0500 Received: by mail-lf1-f68.google.com with SMTP id m11so4131416lfc.6 for ; Thu, 14 Feb 2019 02:25:02 -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=QejVeuN9JlqnVwHudfbz2AR9dbAYL9NjcCDz/Vgr3MA=; b=ZDiaU/dskcTF0g8YrFhWt1RDdiYcqM3R9+07ZwEpexIiQYi8ipgPo+vhFnodkb2bxD 5XfuHIjrfCIzkLWoBOP2QtVOBao9wcQd/0BHOkrWJkpXN+IYO6pw51qRz4n7uFxg7ASl Ts27YZh/bq9AxkRsYWUI34PSi5S5zJrrEsA7+9nCksjHRhpmFXmbLrFl8H884YXYF0v/ Er9NeplRV2q3/DJtF4Y+S2koeiCUW1Vx9DzAXag3B2PYHyWLFylqS/3REAYqa7On/v1f igLl3JNJu0VuR/MeeLagEvDazQBimzwCSLfl7TAfKhGi9yaForQ3xkbBaxEzf73wrUhe YA9A== 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=QejVeuN9JlqnVwHudfbz2AR9dbAYL9NjcCDz/Vgr3MA=; b=BPnszlp/T+aT+SqZ/AaLAhdeiL9jb+4Xtnz+mhlC+Rz+YCroJHeM9WAhpBeiNd/1CB nKg/pKLdHv/BdvRcL0us+S5k6+dmuuWLD/UOhb+hJCVpM97FBD9ieLP4NiGhEwEKCEO4 tIzwvpC+PiZ3ttBUn+JUQC5XZSsyaT3VmGI7NJvuKkP9T/EdueZor8cOLWgcIJvKziqj Me6+m30mYHnLFfkRrMEkWys1uv+NK2a+amaWTfIPSjIbaN2xHJTEOWR2IUjw632kqEIH FwhlUpIouZlDrfdyjebi52I7z/HAAus3KV21k1S2A0kkjn7gB0nhfE6XiXhyyWSGuDrl PdRw== X-Gm-Message-State: AHQUAuZdeHYIzquyu7LooseYoAf8G5TLqwxUM7t6mzNRkJ7fZGoIzyyw fNqj/D4zG+p28cH6EzMgk5AiDQ== X-Received: by 2002:ac2:4215:: with SMTP id y21mr2048953lfh.6.1550139901767; Thu, 14 Feb 2019 02:25:01 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.24.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:00 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Woojung Huh Subject: [PATCH 02/10] smsc95xx: Use skb_cow_head to deal with cloned skbs Date: Thu, 14 Feb 2019 11:24:28 +0100 Message-Id: <20190214102436.5092-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158334 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172395jaa; Thu, 14 Feb 2019 02:25:09 -0800 (PST) X-Google-Smtp-Source: AHgI3IaSXtRdN7ZEK6OEa78Lpn/TZU7xM7jmJI6tbqDRY9x/0mEymSKQs4l4LCZcFOtHQ0B6TZDu X-Received: by 2002:a63:4913:: with SMTP id w19mr3016525pga.394.1550139909252; Thu, 14 Feb 2019 02:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139909; cv=none; d=google.com; s=arc-20160816; b=cnBBCDKlacqz+rFi6sdQo4gSo08SG0hYK2R2/N6C6dn3hPqARrHNBm2l/vNq8uNL4H ZfqPhOHK8L0YuhJ5Dd/byYR5q/Cs/Mr+HKwn597iUrF4+JsKuEx9E3J0xNbd5Re7mj5t tS9pYeTXxkBb73rsxKjUERZH7W3MaYc7hrgVTOY8kAO6g2hiaet6OEb+rj1WnLpGttr4 jYFEbhAQlRl8+1uOQ2yeqEby0yaxKwDI1SHie9H1RW8iDBZqziqeab48710YKq+kcePp 1amQOi8AfIqFmL6/jjxMOh+mVdMs3JlbZg0Skt5FvulGyPX60CYVgEeFL2T7KKRMmkGK u8kw== 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=KEcRLbcq0VO+5Ygbms+j26kX+lJqEJ1oy6WaDYTQHxg=; b=EKRf3ioM7VwKoU5eN3Bd9yRHtOJP3zr6w0QREKhs3sLISFttIBy91bOYKGq6hp41NH lzbXb84S9t/c2iQrzEB6UtmhwSjtBsRUF97/llNJ2MMzV/vSgQ/tSaRQyAIVqQfhBo/f Y2sSnAiOW3G14KubGwan0yZKNqANHY9FkzP47E0yAT1ohtOORML0eiHA+/oJpB8AhKFG UX/Je04uhoAmHzH/MuALcQwhNSqaOE8e7gui1jyGgu0kZVHLxLkHQq6uPLXMZyLKiwNg CsONdMSEMgh94UUimbeVHI1XIN4qMIXdCj7GRSnp/k8ZTmWnCtlHBmYKNpjyisv0Ny8E MkMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=msVWzQed; 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 3si2132062plv.258.2019.02.14.02.25.08; Thu, 14 Feb 2019 02:25:09 -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=msVWzQed; 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 S2390202AbfBNKZI (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:08 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45414 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZI (ORCPT ); Thu, 14 Feb 2019 05:25:08 -0500 Received: by mail-lf1-f65.google.com with SMTP id h10so3910805lfc.12 for ; Thu, 14 Feb 2019 02:25:07 -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=KEcRLbcq0VO+5Ygbms+j26kX+lJqEJ1oy6WaDYTQHxg=; b=msVWzQedOAgOiKnpj/Ur8n4ccsSLebUmbhnbnPMTLtDTzb6Q06dI4JnsNM5NvRPrj1 rPI6FL9+1eDKzAVimNZwJRPMPCWzKwqnlH+V/CSrZ3A5t1zvwKre5G2e4SISqjLoIcnt bhXtv99rpFAPQithDMDa4tqGjLSAnqDAkDHBJ9XozIATLVMgpnOQ4A1VKR+bBUSEt0B+ dQ5eyFYsJ+NOkKAiVL6rzwmOZKFH10936PwMJusmo3YVmROGXTsqvZf8Ju6IFQcspuuv EWLBMqOvO9vCqnE/9mggA+i1+eyxJ5j+bsuV5x9VV8/Ff2bAHSjXAT6pgQy8p++gff+L B+vw== 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=KEcRLbcq0VO+5Ygbms+j26kX+lJqEJ1oy6WaDYTQHxg=; b=KixDbB/hix21XrLqUw3JO82TK8GRUna0+nbt4/Gy+ugV1cQy22uNLSR4hmJJN0MDnH QO0Xjek5x2XO6iRQZdUtSWhVBYlbX+Eoqt4SkFZmxNKkMY/Bf7BtS08PLOWcbkEnGN9A hFhF13zMqRn1esZKXfi6ohcyg7ZN/6FVuu7wEs2/1QqGVRDVmJLNw+Gu4C/LcKZe30CW +7oBSO58tcsgOCe3oygjRCP8+PXI6JO5qtw6B0eTdcXlO0Qxaim1/aJckzcKEgHKSAMn b6fTcDqKXUthMYFHXNs7lDyqxpazg9NlXH/IbYHtcbodJx9PeQs8FSa/bfH/l5a2S3bD 9MEg== X-Gm-Message-State: AHQUAua6DtDpvLLwSWXVrK6FMAT8LQjo969XHLOFwcXScMq3dXZu0lis sBFdkGrxzbnBUfnsZT89rklb+Q== X-Received: by 2002:ac2:4318:: with SMTP id l24mr1748748lfh.75.1550139906327; Thu, 14 Feb 2019 02:25:06 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:05 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Matthew Garrett Subject: [PATCH 03/10] ch9200: use skb_cow_head() to deal with cloned skbs Date: Thu, 14 Feb 2019 11:24:29 +0100 Message-Id: <20190214102436.5092-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158335 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172517jaa; Thu, 14 Feb 2019 02:25:15 -0800 (PST) X-Google-Smtp-Source: AHgI3IYsLeuNjivKGbAZ2TZr35n5/WdivVM3Butj2VciwuRVboHGBBzuNbzlZS4iaba+YYaKVpEx X-Received: by 2002:a17:902:1d4a:: with SMTP id u10mr3246343plu.122.1550139915625; Thu, 14 Feb 2019 02:25:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139915; cv=none; d=google.com; s=arc-20160816; b=VX47HfIIUPRtRp8iMyb/MSenMmaTJUsGJl+wzd4D8EqM6W6sT1PhSBj6uj84U+y42a lim8jDV28IacIPmn8JEubLd4+sCUZ0M1HYzNmjEO00VUiByHsaNoHJm+UEJSA1n4nk+l i9IkX82ky+wup8HfCVNxxamnYLfzr4ynQl8vGRLZpstT3nVCK3IIklmsfVlFYyfYMFTv TmjPI5O35tcfqM/pmGR15ipmqPROeM+Vd1WEEUnnDmao5MQGEvIfQ3nRoTJt/0YCuo+S aaNs+35tB4L/XjY1LCAM2/Krz9HweSaKUs3sxgUMkfx0q+4JOeNRI/xpcrITewqKYcu5 R7AA== 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=TfSOAHIGdINAAOEEKPVn4hWgc6DumBuewpwernfRgV8=; b=nKp0cE3xDztMCmpzYNA2iY+9I+kHnK6/JCHOHFBdPULSBIRqKgIAgVIvvxSwXvMXh1 mwqIer9p1gGWuoMoP9tjo8SnrssQR/Q0lzmudfoYDbc4sd/XH2npLu3Mob7JT3W+gxUz 04I8qybL7xhzWa5CKuIsOfQT/qh8bGj91wgMqrheiaaxQBVhrxbxZpuOooj6IS+EPnlJ 9EqtsnakPCZ2ziOVlxora7mu4XG46y75fiTxcK4maDoDLUKZj8huuWBltQmOfAj9K4EN Jwm/lNPxbpOvfnQ9fJa0m27+PCnMDuyd5S4HodcG946/HEPZF2fscuCVd3B7VwSuE/uj mOEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BLLUUujj; 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 3si2132062plv.258.2019.02.14.02.25.15; Thu, 14 Feb 2019 02:25:15 -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=BLLUUujj; 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 S2387899AbfBNKZP (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:15 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39769 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZO (ORCPT ); Thu, 14 Feb 2019 05:25:14 -0500 Received: by mail-lj1-f196.google.com with SMTP id g80so4743937ljg.6 for ; Thu, 14 Feb 2019 02:25:13 -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=TfSOAHIGdINAAOEEKPVn4hWgc6DumBuewpwernfRgV8=; b=BLLUUujjSwK704YlOwcft6n1Avr4OXpNms+r59jlfdGvRU+Ejdc8lGnm+8l2+m+ZZt fvyZYhmPOelHEk4/K5MNbWShRa8zV+ObatqchGWEB5pLdpay5Tfciohq/8jJXX/J2DYn dhGuY8btPFUTdyVEJwgfHjB0RkTY0XZrqIfK8lzCab1OBF6+2j+LuyrNSdC7rSMlb6vZ 0pLTqxbMdIkUIBwgtUA6GHIg3dpkcCjBdkvJzmZelXdsk6Ak6KV29+9lAezrsHwu7nB0 Vz+rKO+JifIX0xp0fHT9qiKOovAlU9w/9FaA9lBt9GFl3npyQL+LXCBZbxZx1I+3pBnj DcJQ== 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=TfSOAHIGdINAAOEEKPVn4hWgc6DumBuewpwernfRgV8=; b=burT/806cF+q9pyMf2I7jsa3FpynMrF9qNCtnq+qi1sJolDlONLUi4nwJYZOz/Iuq2 k/eSNiNEh33RB0IQR6/43jDOFt1Lof+hPIWYP808SBGU3iBnadYy08WqmaOBF6ilCQhM AEqV3R8q+3ACYz9k707QW2S/zK+yOB6OdXQUG01TpZCIw6FiCeKrcCrwvy8p02UAMVpS 13elDT+Nh21L845dzS/KpmuiugZ0ux1h7juTNfLzfUs7DHzS1ckggy/P7OuMmvX7TlzL O8WHLXBkUO88G4bgCEi6PElRVb2MSR7eaO8bQgkOKUjZg5sKFC+4IqddRlwNT1QD/xsm s/dQ== X-Gm-Message-State: AHQUAuZYkHmSIYEWSaeS1F4pbzm48Xxv5pHy7fCetz6RgsaeICUJ6aNh L/X5+XT9+op0rUPObbDPL3bft/8REVM= X-Received: by 2002:a2e:4503:: with SMTP id s3-v6mr1878524lja.44.1550139912792; Thu, 14 Feb 2019 02:25:12 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:11 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau Subject: [PATCH 04/10] kaweth: use skb_cow_head() to deal with cloned skbs Date: Thu, 14 Feb 2019 11:24:30 +0100 Message-Id: <20190214102436.5092-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158336 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172743jaa; Thu, 14 Feb 2019 02:25:29 -0800 (PST) X-Google-Smtp-Source: AHgI3IYoOR1diiXxTVCMAFXw29CuqouKaxRdJ4cd+6drSZfb3HvcdVtHqbXwWJxzx7dvJYdzSWae X-Received: by 2002:a62:29c3:: with SMTP id p186mr3263104pfp.117.1550139929891; Thu, 14 Feb 2019 02:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139929; cv=none; d=google.com; s=arc-20160816; b=FzHsjQxaByCNvTfOs/gfvnkfUapFaBt3Is6+Yn3EwCf1qNSQI/KZxp3jj1CdD/Iz1Q uBZ+tiaGeyam8dYKVCTjCQeMomtB4acx/GxejD2Y+xPMRetvj+eTsokNXVdC/1jKhGx6 bgscvnihE5RmefposqokHQcK+qx5dxUoODicR4kExLPLzkNIDJEQkdtUopPNvz0eDCvB OCKPdHtzUiVFe4UVk4i+HJ4TNKbQQHc/86nARNhD4Ie6zC57Wc1T6ZV4PJcOKUxNHbvF HPuiB6KQgKPk4rPYzWK/4ls81VOy0vJzU3uxdpSndpYaJo3XwVSvHs7vyhIhEyBAuBLD F1SA== 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=zIUpPuUxxTvQgisO+grlvI1p+2ynMJHS6/LKOJr5ydE=; b=lOesKCwULnwfWIeYCWaiFynu6MgZ7kWmgvTNh6TMH7+eDDQ4vQocg23/dNhMjQ/5FR Nn5CDVzM3T7xzvw5zAVpGp0zPbyZEkPpi/pwSo+FBe2aIk3DSOjkqUuK7Ajc+d0i3LQv p6fCfspougMZCZ2YKlzdG4bfkSHfTjw694QeQx+AM8SoERVczP87Ug0+fLMDx14xbbl+ +u9aa9oG8uQMowKKgcL4xMVnYH/gHnb2IR2OYmyvu+6XrO5WeDYyZQxQv6HmzD0byX2c 3oHCApkflTzJlHKGU8aVV+MIXjHDh8p3sJTw+gELvW2kDTey5Kl91A4vKIghsFhspGhS DiDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YKu/F/eg"; 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 3si2132062plv.258.2019.02.14.02.25.21; Thu, 14 Feb 2019 02:25:29 -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="YKu/F/eg"; 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 S2390555AbfBNKZV (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:21 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:34124 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZV (ORCPT ); Thu, 14 Feb 2019 05:25:21 -0500 Received: by mail-lf1-f65.google.com with SMTP id u21so4155971lfu.1 for ; Thu, 14 Feb 2019 02:25:19 -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=zIUpPuUxxTvQgisO+grlvI1p+2ynMJHS6/LKOJr5ydE=; b=YKu/F/egmfYE0/lwjPrU2cukL/qS9YjnwyZK0AKDG37C1+hz4hKxgunSfecRwk1gza YVaajmNvC+eeSgzbZPPqoiBVE/HhlCEeK8lfE6txmbXi9KERlY/W36mdX0zKCUO/Y0t/ //bdAK7pFfpZbcuVs9tAX63SFcHOIYNAofqlaKgKlaocDyW0M7H5Scf4NZi653gA5NY+ eo9Snbed01olLJMBi3Z9EPmNJ4qcExypsbQcs9kNaB0T0N8OfF7P2Afxn783z32WpjGO BRiNapYOsjJMWJbNglH8dU9mYrvhpis/eHvIbYAOkIMim06GS7OGWMKBZ9w3Nj4NlI5u J0Cg== 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=zIUpPuUxxTvQgisO+grlvI1p+2ynMJHS6/LKOJr5ydE=; b=WDGHLi5n0LjZVh0iwbPI+XH8e1V8vGJ/ZNwyUn59RJs7bGuA+tfIkINjUqeOqlXKid hmPoJ87YFxxxNvw4ZtpX9dFvoFhOslYdc5cghjjDe0FN50Tbtn1iKZ5RQbNKx7pI7E/m BQH6c4H+cUgrw9qd878gBWtY8f/gLykQGLdo2Wzd30KvJSiqWVSWjbS1bwzQM2HPkc3o 4zJ0Rq4s5Cvy4NxE+EZ559xf4DV2JMPbLtXUzHZoVlCq9Jlb818gyHECAJbR7sXQd3ON AOu6r9z++Cl7B3Gj/+XeZA2zC1PnAwRQVJrGIQChDr8SnMKTtZJP/KJcCBwoBinFK6AY H7ZQ== X-Gm-Message-State: AHQUAuYSoe9qBM/dwqfhepkX52sjV3brj+6VRHmdNRDXpwm3n0GiJOsJ XzeYIStAia/uzIvcCwj1lpQTmw== X-Received: by 2002:a19:7410:: with SMTP id v16mr1908275lfe.166.1550139918867; Thu, 14 Feb 2019 02:25:18 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:17 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Boris Brezillon , Richard Weinberger Subject: [PATCH 05/10] ubifs: Drop softlimit and delta fields from struct ubifs_wbuf Date: Thu, 14 Feb 2019 11:24:31 +0100 Message-Id: <20190214102436.5092-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158337 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172851jaa; Thu, 14 Feb 2019 02:25:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IY6rcyuHIGCFkedLRf4/7XXGGtSYyd05s6juJvzQRifkxO9pOi9N4HW0V8RWxtBga7Jlkc/ X-Received: by 2002:aa7:83c2:: with SMTP id j2mr3196532pfn.119.1550139936942; Thu, 14 Feb 2019 02:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139936; cv=none; d=google.com; s=arc-20160816; b=0MRZakVtrNdkfFPqM7EDrhZpxzrGicw4rq8xJgQN3j31vpIBzQ/7k4L0EMHfqFzIRI 4D2qK0Q3s3WpDSIn2padCzSx1bMyrYCirOdxuDddJh46qhutQVZJaypSpqTl2w1a3lSJ 7LgCNcp+VDt4tZY6UnBq0FAhtr8BgGTCdVVY4h/XlQidLN/kkyl6spLKRbW57KIL3up9 MiFltawenuk8xet1vC0XIIdlnWdEVb+24dLPGNHKn5nAEJhH5Esnh2awkh7f5AqOlQ8d xL9RKFJ6WTEaeQmshy7/wTGaCgQ/N7Xdg84WZ6C5BQjwoPIszjX3w8yOQBx4bnflTHNI F7OQ== 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=ogYi8uBO13tA9f3mvzmcxTSxnN7g477z90MxByLFd/A=; b=Y5CJJI4gRHSXDkxDh05bzCHuQOb4zGoQMF6oaY9kqP6vsV7w3JknQNv0PvKkNI5Nii TcLp5zyKO4PqL+HjNMhSkXJkDGmwGGbMkzDznMuMgz5MUHM+gyaiC4oLjxFCD4yJlUqd F2WDq3eBQaprcudsS1JRvhqUSzsSOU+Y1NZJQM4ROiIBgE+5KbKkzhYg5ajFXQwMtmX0 C+ks/p63m22pa5kq6fKKkJpcAqUKiV8pQt9pv0mL3pgnZghmceRt6JtfvXGQuqq15wZs 3hJJDdk1O1wvv+DTE7DNIfMe+HjIx0L/PC4yR/ONdaZnoqcXz4p/xVmXpdbNFRxTZEuG czpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqsM6pof; 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 3si2132062plv.258.2019.02.14.02.25.29; Thu, 14 Feb 2019 02:25:36 -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=rqsM6pof; 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 S2390719AbfBNKZ1 (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:27 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41703 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZ1 (ORCPT ); Thu, 14 Feb 2019 05:25:27 -0500 Received: by mail-lj1-f193.google.com with SMTP id e17-v6so4736579lja.8 for ; Thu, 14 Feb 2019 02:25:26 -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=ogYi8uBO13tA9f3mvzmcxTSxnN7g477z90MxByLFd/A=; b=rqsM6poftUwB0M2FI4qlJ7+n9ojuhncItIYDDmFpcC4qM4Oe0sLYJOIHV0jQTAejEE SFQJzWWg1jcWbu+Wo7659su2UvWirJPgIz9Jw62zVRop3fXRpP3/YKp+hXYqueBNOfCc eA7FTxwcWryGhcGOrsxBw+xccaWuyMgQ9kW3RfffGjZh6sTmo5UaTrXl1vdxYv8Aiq/P qjz/BjKpg5jSelG5dUfQbe9p59ntReIQthNCn/7o7Jilq/ro2o1A7yFlC/ILDNDs1n/o bJK+dzWCgZRX1XUfh8YF4Ztxf8U1o2WMaxDRnzA5vqpvgoLO7VvpSsv+/Gj6ITzg77eI je+g== 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=ogYi8uBO13tA9f3mvzmcxTSxnN7g477z90MxByLFd/A=; b=ZoJ7xu34iHWKMRfY6nkJcboeTFF6WB3KhCEcce4fpx0FheN6AsYgXavZfo//uAUjJz HX9n+XEKKaxf6Bsm8ksdxpNGLG2SIpulo04WwPYIkWq9iwiB99EXd/Hj2KQPeqZ2rH0M /FyNHMgNhAC9Duem8bqsrhQnNHwLLpsYzbT7BeW3EW5s8Qa8k2Gm7VSVs92l9AoNTCvq KIkUqiswq1XtF5fwzhul9+8uXm2n25Tyg+7tnC0RM4ZsELLw3yjXIb766Gz4Oi8Q1ySq V0GO1OEzR07To2G7myYP4qBo15PjZL7HGCUIu902oAZJrRglwbihKx1JW8Z1zgK2trdm du9A== X-Gm-Message-State: AHQUAubE/XvlxZCRsoYoytpM5nHjRvi5aV/KB9Zxj+wMULLguIfHXF6q mbNU/y1CXfyzJKag8q/ezWrTrA== X-Received: by 2002:a2e:49d:: with SMTP id a29mr1891065ljf.35.1550139924777; Thu, 14 Feb 2019 02:25:24 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:23 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Boris Brezillon , Richard Weinberger Subject: [PATCH 06/10] ubifs: Use dirty_writeback_interval value for wbuf timer Date: Thu, 14 Feb 2019 11:24:32 +0100 Message-Id: <20190214102436.5092-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158338 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172860jaa; Thu, 14 Feb 2019 02:25:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IbheEhliyiA6tVXuMoZ+FFlm3yc65A831LRyaqP3yQQM5X17xNOMYT4bQipyjgs3f3RNxao X-Received: by 2002:a63:2643:: with SMTP id m64mr2967717pgm.35.1550139937269; Thu, 14 Feb 2019 02:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139937; cv=none; d=google.com; s=arc-20160816; b=vfBN9yl6L1cGODXXPRkLKtQG/UFgsuhOQzfZGrEeRhyJQFUbt0M0mwU+D5WdBiTHhx gjmY0PffY9caUSUv3OGhmKcqOhYcogRqTluvCrDuygxyiNEJVLzui/LGHA6RJj5waGHT 62iYbeKVjLyOvej20Av3yZdiLto4/W8j0kSrf76BT9y4u0WQA/a1J63jPBe2JzFQ1QbF x+G/Sn4tfLj06L8YWE3uAQXPcWjQG2fd7s23qypNZfup7qv7xeOO34DKbv39VXbmvZtB OaEQba19+mAlGrPRA1pF51d8bQ3mPP52JLHAb1+qsR8YnZxn4f4tgbJMS/vKZIcHsPo1 mALQ== 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=V5q0Psd+QeYz0B88fp1aY4uWkwQGd1Gv62HcBCKMYdc=; b=ppn1PTP3sBrq2J+ynWBRD5JsNToszmtqFxSJmE8LV4i3GpwaysVFEihvacOXChipHy o2NczKfPqQuWmA9FzNK8rPd6gtMoOo9gst4RL7ibOevo6Bc/ai847FvYYJTXrrF74b3R e0Y6v+Y1GVtSZ8I955ogZUkflnP+ycjwyU7RMsvk2w3RdiVe8H7VTHbQLx0sshWnmi9h PAMyFi5cXioRg4HHHUz5ZsqKvQSFjev68qjHEBuMBconN9rRzudRiuLVC12YKisoeEHM /+PibL+I14nwBN5ZNYFM0kbiqwtTxRxG2VfAFrW4TVGyZ9Jk//OY/0wG0BLhK4+f6U+h ig2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NTLfIfKL; 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 3si2132062plv.258.2019.02.14.02.25.37; Thu, 14 Feb 2019 02:25:37 -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=NTLfIfKL; 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 S2390933AbfBNKZc (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:32 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41819 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZc (ORCPT ); Thu, 14 Feb 2019 05:25:32 -0500 Received: by mail-lf1-f67.google.com with SMTP id e27so4122831lfj.8 for ; Thu, 14 Feb 2019 02:25:31 -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=V5q0Psd+QeYz0B88fp1aY4uWkwQGd1Gv62HcBCKMYdc=; b=NTLfIfKL8xH5BK32DxhwhLcSjaGLloNmoQV6puSOlQ+HNDC7NBwWFX9o4oNXq5wSBB j2vcAja4QCmmPgrO1bEITqikhzirbUiF57ZhA/nGhZse+1EwhoX2Wth+04YhFS70pwdU pAsPp+s9oZRZ5ze59v/7KaPvwIgj7x0NVhV34R4Ea5Js+8pmyJbv9a0H/MdrAQuiZnUa mJ9XAAXRZFcXw/Aw8gptFQiO76fAS+ldnth9BGFr27TY6viwGpHNn5uDwdevEveu330T 3uWJTSsSFvviwypmGAKbTdznlz3hwD7lVXyDiX4OOKngmURXgddXwqIr3jNmG3nU3DWe ZZXA== 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=V5q0Psd+QeYz0B88fp1aY4uWkwQGd1Gv62HcBCKMYdc=; b=O1HvlV7zV8yqfIB+wEmVfHMmZSMuiOA2Z26YN2ZbGA17MvU9IS4Nr9fLcc6UtrQDK8 DyYlMBbJadWgXPf6yXZguliKD4rCRG+seTZW6oiJZl/3kkRQb8vB8HpxvXcAwVhwW3kO kaKw/qBol0S+w1OQkaS829j2v6pdARWqDiEKARIeDRUJGJ92SXvoZSj0sBTOMZtO2edY k1FHIOmBHU0VMOePhusSh6OzP7t+Lx7BxuuEutZcM+AgwrGIlGXY4zkEdgfNlhbEp+SB PoWmxFz5PQIMiDgSEcZt8lJXZTrFqE1oj1c0sMuxXcvf8MFCbYqEFxrMNJ3dVH+xD6zK F4Sg== X-Gm-Message-State: AHQUAuYr6i9FVye8DHndE4UXhvWfaJpdEMRJTNvc9OFpiJtQ1H8LUQ5q H+CIAWxRGLun0l7tTig7+KNnQw== X-Received: by 2002:a19:4284:: with SMTP id p126mr1899308lfa.139.1550139930166; Thu, 14 Feb 2019 02:25:30 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:29 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Felipe Balbi Subject: [PATCH 07/10] usb: dwc2: Remove unnecessary kfree Date: Thu, 14 Feb 2019 11:24:33 +0100 Message-Id: <20190214102436.5092-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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 --- 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 10:24:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158339 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172924jaa; Thu, 14 Feb 2019 02:25:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IYVI3LLGRttUcyCf0OWb9MeTkl/VRoQNRZzcHDjLbLyXs1T+YzCSESy5qC0PVnS4L0iPiwR X-Received: by 2002:a17:902:f01:: with SMTP id 1mr3292333ply.41.1550139940799; Thu, 14 Feb 2019 02:25:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139940; cv=none; d=google.com; s=arc-20160816; b=yzvYmGCXFXeltDk0E4VxhLfsA1uDzS7Gi2tG1CkvZoOF9H1JYFFrK2yIKQz0C1HF7k LDHdBzgoW9Yh12kZdqsVCFClcOpB5FZH/JKsRSDBa5cEsxAtgqejW27XsZqUD0PxKZnM 7etaZPhi2Jxc5ShqamY8OxRZmZvEudKPCcJdkcoF6lrjVuDPgW0jiQDZtlnCs1oHJLTk 9dXU9MAMs6Ye8mz8/YtsQVvlAczQkqS+pPJ+8ohl0NFeB2ztcp8sJhglvl8Wr4yS2cWW FU0RnlKCy2Uzpa9Q9ZD+iM+hL3sX3FMI4cMXVuXm6Gz+plT9AKfYSx5uBN+7/Fq1ung3 36pQ== 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=2vPR0KS4cbImbm95QNIb2a5uYyRgtrEnS8aK6yKOLmY=; b=myJm8tTOsWenYMV1u3eK4NbCVpbfLD/BO8rFpEesXW0O5dcyu+9pMkoxPhd69YzUXw zSh0XHS+UayQhjwX0+y9Her9zK4B9CWdV7CskVCGyvz6q/6hZDX506Vi0XIcN1FjgG04 70McGT4DOhFTrIxhYbSCnRsE0L06IEx6bil4fCWP6I66hGXabPwL2xa/R19vNkFUI58T b5iBaxBFX8gukmuflFMawwF7Kj9lPc9nU8yWDQuYs2LnZzxDQsrSrp/4hA1K0qQK0blC DhMGwpIPZX9PRzeWSzqgmYQ3OkGDocxGCrQWR6po/IAMCL777d+qF/UDXTg6BVzEErsJ OFtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LnYSW7Z2; 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 3si2132062plv.258.2019.02.14.02.25.40; Thu, 14 Feb 2019 02:25: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=LnYSW7Z2; 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 S2391132AbfBNKZk (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:40 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45286 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZj (ORCPT ); Thu, 14 Feb 2019 05:25:39 -0500 Received: by mail-lj1-f193.google.com with SMTP id s5-v6so4712106ljd.12 for ; Thu, 14 Feb 2019 02:25: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=2vPR0KS4cbImbm95QNIb2a5uYyRgtrEnS8aK6yKOLmY=; b=LnYSW7Z2DNXO6kNQ7Tn6jMmyDsHWUk8hnu4BhJed+7OxzQfHisfeP09ULSwBUFg7wz 7tUhhoc23eJNLi4i3+1sO8/EYrtkPODVXi/aeAPMA28dIyybImztkQFpyIWoMSpOQ331 q99HTvu0vxbMM5nNd9zrcl/Yjay/2zX9Bgwwz2RCmX/QTNY6LX2uQLuRpF3pTcGyT6QO OhMcZEWWvHoGuBPKAnIuvDsvgwZWY9uyANyuTE9MXjFx0FNEYlGerq3cHYC4g1xl5Tyv z909Ii9VKYNbL0nfZSZZtqNbMmBAaqI0reMV5yvqEkvKTMR17xCiqZnO/Oiu+cnHoON3 hRQw== 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=2vPR0KS4cbImbm95QNIb2a5uYyRgtrEnS8aK6yKOLmY=; b=Gbsn5CsKx9WOIMQ/yxOZ1NWtqFXn8a92anhGvEJBxLIg5baK5IaixXp1ck85Fg4V1B +oSXj63VG4f2eaoqX8up/K8hIfOmvgDlTJZd6XDiu5+knutfKxj5lFMVkqSkFrJH14Hu NtN82UFlJ/m0DTnK8MlcIp0SfX8+4EFNlIQ1h2DPxvL4/T6yaqAsyclsgrwEYJKhKg43 xYnLKcGzs9fFLN87jm5es1spzx1YHNp+E+MZ11oFoiKh+phpuHQhPhh4VsYGut/RrKUG zVELOwEssjl1Siyn6tzYG54JF0xchT1648nm/CqbA+0h/yrUVT9lnUdi3ezwWPtr36p3 DbBQ== X-Gm-Message-State: AHQUAuY4A+rZtG+4+Cy1hfjGoliMRK8BoURxWdjBY0eliSVBh4vZWSdB T4R9/u50Pundeo7RZ9h/lKTICQ== X-Received: by 2002:a2e:9e93:: with SMTP id f19-v6mr1962687ljk.122.1550139936335; Thu, 14 Feb 2019 02:25:36 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25:34 -0800 (PST) From: Linus Walleij To: Greg Kroah-Hartman , stable@vger.kernel.org, openwrt-devel@lists.openwrt.org Cc: "David S . Miller" , Eric Dumazet , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau , Pablo Neira Ayuso Subject: [PATCH 08/10] netfilter: nf_tables: fix mismatch in big-endian system Date: Thu, 14 Feb 2019 11:24:34 +0100 Message-Id: <20190214102436.5092-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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 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. This is OpenWrts backport of upstream commit 10596608c4d62cb8c1c2b806debcbd32fe657e71 "netfilter: nf_tables: fix mismatch in big-endian system", the upstream commit does not work right off. Signed-off-by: Liping Zhang Signed-off-by: Pablo Neira Ayuso --- 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; } From patchwork Thu Feb 14 10:24:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158340 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1172989jaa; Thu, 14 Feb 2019 02:25:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IYzJKhDUzXlucphkYLhfSH+FapcehMa4v7GBJkwZDuoIEDFwkoURpccBkIVleB/zXCHHWK+ X-Received: by 2002:a65:6215:: with SMTP id d21mr3029711pgv.289.1550139944893; Thu, 14 Feb 2019 02:25:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139944; cv=none; d=google.com; s=arc-20160816; b=tuWYPzEZvUII/J85r44bv/NTVQtHCZto0au86FkEVOklWauEAL0IPDzrNTcdjxAl/0 lZ/abMRQKN/4a8XpSIFyMBqsNu7BifGNdvAqPy2dvE41REUUXdg5iGs/XoEGA1S3yyNg wQWjFcc+lrbtIBgO4Eb5zLPPbwHIPl01Qw89PEnzCY8lOhkz1M++kNlebNHIcIE1unn8 o5qd3SV0lzRgSFiOW//HDQo6regbfXK3bzkE1Lg6cyHN5+JvsZ0Nbg2G53By8HHAm+jg U7qwcYNQWRCJ2nyHlUnPTUGHsSM30uE+Mebf9LcbirvSn2PkUS4SGgyVEh65zptD+yHL eclg== 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=Dz6xtFHT/2/4X/iK6IHqnPMEHnCcKqJxd8+wIE+5pc4=; b=hjRRJrcVQ6UO3pRCaJ91Ve7lv5KqDVfiYOMNZTqcjLrh/nBdGrCu7GE/4tTkaHns+O rkhfp62HsPoc3/xIHkTk8mUWSI+9jePhO1khFxzBiT+xHtk9Z8YcxIALEtWmf1RmTV4e rkiY5GUBe4La2ucuNYsZ3qNDN0YfUNpZmTve+zKj8ygxNrLCi6LLZIl4A1Ttxw+Lr9UK BraZHsrneNiBLyVXODW0jknfcYiKud+1wnk8Nfs52uuUz1C2nir6XIFRI5gWONtTgqpc wPb9IOpYSWupTjjdWsv+rJyCmJTnMyYNZz5AcZN3BarFmrAXD81nthYPI1op0JxaeF33 +gyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b9Ymec/7"; 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 3si2132062plv.258.2019.02.14.02.25.44; Thu, 14 Feb 2019 02:25: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="b9Ymec/7"; 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 S2391286AbfBNKZo (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:44 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37076 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfBNKZn (ORCPT ); Thu, 14 Feb 2019 05:25:43 -0500 Received: by mail-lj1-f194.google.com with SMTP id r10-v6so4751695ljj.4 for ; Thu, 14 Feb 2019 02:25: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=Dz6xtFHT/2/4X/iK6IHqnPMEHnCcKqJxd8+wIE+5pc4=; b=b9Ymec/7Kpo82XIGwRLY9+SsG7TTapb/VKHeG9NvWtEugpPoPrZWY4Rsi3CYvk6QLS tWJKpkeknTAeHWz2XygxdZhhB268cepnKPdM9knpOJYlp0Rmcj4dq9N5tfKYhzk60u5O K0o3uAG1PxSKuW8ZxhKe8cuR3uJeXbKw6TVj6aSGaNYdEBYdwssyuGT416reWOzhWZJz RaQtPQyvxIsnxL6N3wyOIjd/uYFEEA1w74fuIuaEsw+U3Ct7G8TTQz7fktS9hV7OKqx9 YW7NmqyRC2CxQPiAUfl3RZVx68SlQ6TyPAqBB0scmzhg+2VlZ4URfRUDj/aAyqex+QIC tuhQ== 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=Dz6xtFHT/2/4X/iK6IHqnPMEHnCcKqJxd8+wIE+5pc4=; b=S1gTTzhH6UiTzizFAzr/oLhK7eoQpjZDheKJyIC0Q2doYn4Pwr7qsxmSjXzgAEWd2z AlKK/yjbddcS6QXpePLqq9NB5wLBW28DdT6fMtWEvjKh3t0HcuOIHU0vWBt4gA2o69Yq tiIbzsjnDsqIf7DP57vjlcOexTCjSifi5hFhoNgWYYkpRiArPjoOSqDDnP2+Dvbqn3lg 9LgHsUS31UMyL7kdSBa9cZrGjr1oNno843tAXasZDwHIZ44EEaN+gVGRur4oa+uGCTWM GnY2aq/U+TOSPOaS7s/9Y2mX45Rt7T5sDpukj7q/vTIIAb4KynPp4AoNSJOtWUSwPK7V BwVA== X-Gm-Message-State: AHQUAuZ4/c8kSuFCqRMx69Es4km/5aZcpunuGbzTKJ/vQHNeYRy8+Efx Mph5lwUE1IvEmpRIV7fj0wi5+Q== X-Received: by 2002:a2e:9e0a:: with SMTP id e10-v6mr1780921ljk.157.1550139941409; Thu, 14 Feb 2019 02:25:41 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25: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 , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau Subject: [PATCH 09/10] net: Allow class-e address assignment via ifconfig ioctl Date: Thu, 14 Feb 2019 11:24:35 +0100 Message-Id: <20190214102436.5092-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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: Dave Taht While most distributions long ago switched to the iproute2 suite of utilities, which allow class-e (240.0.0.0/4) address assignment, distributions relying on busybox, toybox and other forms of ifconfig cannot assign class-e addresses without this kernel patch. While CIDR has been obsolete for 2 decades, and a survey of all the open source code in the world shows the IN_whatever macros are also obsolete... rather than obsolete CIDR from this ioctl entirely, this patch merely enables class-e assignment, sanely. Signed-off-by: Dave Taht Signed-off-by: David S. Miller --- include/uapi/linux/in.h | 10 +++++++--- net/ipv4/devinet.c | 5 +++-- net/ipv4/ipconfig.c | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/include/uapi/linux/in.h b/include/uapi/linux/in.h index eaf94919291a..550b234be4a1 100644 --- a/include/uapi/linux/in.h +++ b/include/uapi/linux/in.h @@ -264,10 +264,14 @@ struct sockaddr_in { #define IN_CLASSD(a) ((((long int) (a)) & 0xf0000000) == 0xe0000000) #define IN_MULTICAST(a) IN_CLASSD(a) -#define IN_MULTICAST_NET 0xF0000000 +#define IN_MULTICAST_NET 0xe0000000 -#define IN_EXPERIMENTAL(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000) -#define IN_BADCLASS(a) IN_EXPERIMENTAL((a)) +#define IN_BADCLASS(a) ((((long int) (a) ) == 0xffffffff) +#define IN_EXPERIMENTAL(a) IN_BADCLASS((a)) + +#define IN_CLASSE(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000) +#define IN_CLASSE_NET 0xffffffff +#define IN_CLASSE_NSHIFT 0 /* Address to accept any incoming messages. */ #define INADDR_ANY ((unsigned long int) 0x00000000) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index f08f984ebc56..32335ed0e9fe 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -898,17 +898,18 @@ static int inet_abc_len(__be32 addr) { int rc = -1; /* Something else, probably a multicast. */ - if (ipv4_is_zeronet(addr)) + if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr)) rc = 0; else { __u32 haddr = ntohl(addr); - if (IN_CLASSA(haddr)) rc = 8; else if (IN_CLASSB(haddr)) rc = 16; else if (IN_CLASSC(haddr)) rc = 24; + else if (IN_CLASSE(haddr)) + rc = 32; } return rc; diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index d278b06459ac..ecf19f7ab5fd 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c @@ -455,6 +455,8 @@ static int __init ic_defaults(void) ic_netmask = htonl(IN_CLASSB_NET); else if (IN_CLASSC(ntohl(ic_myaddr))) ic_netmask = htonl(IN_CLASSC_NET); + else if (IN_CLASSE(ntohl(ic_myaddr))) + ic_netmask = htonl(IN_CLASSE_NET); else { pr_err("IP-Config: Unable to guess netmask for address %pI4\n", &ic_myaddr); From patchwork Thu Feb 14 10:24:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 158341 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1173050jaa; Thu, 14 Feb 2019 02:25:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IY7uUjdLakO5ihZhOkMZyE9d4z9pV725Gm7sNhewMk/O38QF2uAsHo4RcAwt4vv5pkmdMmw X-Received: by 2002:a17:902:5ac9:: with SMTP id g9mr3373091plm.205.1550139949640; Thu, 14 Feb 2019 02:25:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550139949; cv=none; d=google.com; s=arc-20160816; b=JgV5Q1OSUegiGHKVq2TBM7SzWNpYlDl1iB8UZcgbi6MfOG2j4j8u3LS8eYKXO8WMtW gNZNjd90ALtQgXQ8c0gLnCksE+BrguLCO3neMYihppH2tZywkrSG3C5u2ZoJSTlabIw/ 7nuoirQE+lVtfsKfKHhloQFMIuAh8xbEhip/7G3qS52TENQ2LvIggEnlYroGv3bhxH/1 xfJYVOhU2iUnrsiTqE7P/6d5g1MplK5WUUVnHDsdr4KtF11KQ81FtxFrbCRBRKjfSa7y tYkgPhP4uc5r3AbxYNuUg8+hurGNJNFey4/I2WJRBDXGiuOuTqvjQbBf18YXVssAPejG loFg== 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=gvj8yj8XGaHNJ0qnaoRqnr716jerNytfzW/u9x/+UHc=; b=VDXMFODO3LLxHQcYS9TtQpvgsAyLAMN5SZ27ms6zXpnrY45iHb6AwgYyVPuRva3a5t HcnCIsOiMr642IF9gl9xM3J7UkZecnAH3yZwbAHMImFXQ9SKcUCIFZQJtJByQlJP9QcX 7OL235/EobGUd2oswQxVRgBVcRhoO7LR6AuW7fu3m5z8t62kaZa2ecfZwNTQQ5x+Z9pt m5McNcSpoLQ0/POuGFa6dpC/MnmjfWG/qeWuP81sCin1l13cd0kVJMV2okEOdnN/P+3h 68w6xhskves7g8VfE/IOrnbBQbJ21YOsy0wq6ELQcyN1Ky7PzPgXcptIZ3qWqU1vdGcI HnCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QO9ahHF0; 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 3si2132062plv.258.2019.02.14.02.25.49; Thu, 14 Feb 2019 02:25: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=QO9ahHF0; 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 S2389001AbfBNKZt (ORCPT + 15 others); Thu, 14 Feb 2019 05:25:49 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41728 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388482AbfBNKZs (ORCPT ); Thu, 14 Feb 2019 05:25:48 -0500 Received: by mail-lj1-f193.google.com with SMTP id e17-v6so4737434lja.8 for ; Thu, 14 Feb 2019 02:25: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=gvj8yj8XGaHNJ0qnaoRqnr716jerNytfzW/u9x/+UHc=; b=QO9ahHF07kNDcRwcVep4gGMzK0z7KV7/T0D3yG9qCOyo5OCWl7d0TE4EOEcxWzGono YY5oKtvE27egKUYR3r5Q5Mk9Lk+nacA4ZbPpEvB9nrc+VyBHVFW8+jIC6uQteq/qU2us fXKk9KIuGjop+yJ6dna9xgfaVPiAkHe6ZL6ZsB5sTvC0mpauQ9K/lwLQhln3y79sJNV9 PeUvGbDkh9K2s0TQrQhuKLx99syJz0w2nF1JORGOAHQOQ9bRBsmBwaulJU6SKEk8rBqG Z7561fryUR3XJP07nb5oj2tmHClVrj26fHguwAinKZPUnpv7H6Wnwb9NxvAG5rConhQY OQeQ== 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=gvj8yj8XGaHNJ0qnaoRqnr716jerNytfzW/u9x/+UHc=; b=N7VR0AntyVJ2xaQbP9Q7o7M7ry6wJEn4QPFreG8IhWXTZZtkWHA2NZp3ENjwZhPHUV kfKm1rscp+YAjOE+AcVxQVF7X4pqjnu1M4PGRNXLHgwoLTNqQ1lTQP/hNDIVlNob+2bz lVG+yWPNBlUzQncGS/O24MpDCwywF1NK2yfxyynCNNhmvV2Y3XrzJtdR6eImltxpcUUb uREqtHSVabQk0WKLWZZljPj73EHWMV7hsvtgpRo5VoUt1KDtjWWQHQhlf80BaUnsWWH3 Jg7Wp7H65RidWi1CYyx1sBOD1mRLaL30uEONxHN6aSazRZN1PYI9BUQVG5v2m615YbYK DjwQ== X-Gm-Message-State: AHQUAuZdV4gLYpLIG6EOsyASDoILtUvyREYXBtZVOXg0v+FSL9dzWUte lyKKFVtRaupH4CaBi1Ge227WkA== X-Received: by 2002:a2e:7614:: with SMTP id r20-v6mr1881610ljc.175.1550139946783; Thu, 14 Feb 2019 02:25:46 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n189sm380392lfn.82.2019.02.14.02.25.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Feb 2019 02:25: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 , Hauke Mehrtens , Dave Taht , Liping Zhang , John Youn , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , James Hughes , Felix Fietkau Subject: [PATCH 10/10] uapi/if_ether.h: prevent redefinition of struct ethhdr Date: Thu, 14 Feb 2019 11:24:36 +0100 Message-Id: <20190214102436.5092-11-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102436.5092-1-linus.walleij@linaro.org> References: <20190214102436.5092-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: Hauke Mehrtens Musl provides its own ethhdr struct definition. Add a guard to prevent its definition of the appropriate musl header has already been included. glibc does not implement this header, but when glibc will implement this they can just define __UAPI_DEF_ETHHDR 0 to make it work with the kernel. Signed-off-by: Hauke Mehrtens Signed-off-by: David S. Miller --- include/uapi/linux/if_ether.h | 3 +++ include/uapi/linux/libc-compat.h | 6 ++++++ 2 files changed, 9 insertions(+) -- 2.20.1 diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h index 659b1634de61..b31e2f836317 100644 --- a/include/uapi/linux/if_ether.h +++ b/include/uapi/linux/if_ether.h @@ -22,6 +22,7 @@ #define _UAPI_LINUX_IF_ETHER_H #include +#include /* * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble @@ -139,11 +140,13 @@ * This is an Ethernet frame header. */ +#if __UAPI_DEF_ETHHDR struct ethhdr { unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_source[ETH_ALEN]; /* source ether addr */ __be16 h_proto; /* packet type ID field */ } __attribute__((packed)); +#endif #endif /* _UAPI_LINUX_IF_ETHER_H */ diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h index 774cb2db1b89..7c098d68d5e5 100644 --- a/include/uapi/linux/libc-compat.h +++ b/include/uapi/linux/libc-compat.h @@ -263,4 +263,10 @@ #endif /* __GLIBC__ */ +/* Definitions for if_ether.h */ +/* allow libcs like musl to deactivate this, glibc does not implement this. */ +#ifndef __UAPI_DEF_ETHHDR +#define __UAPI_DEF_ETHHDR 1 +#endif + #endif /* _UAPI_LIBC_COMPAT_H */