Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1484516pxu; Fri, 16 Oct 2020 13:14:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz95xQIhgV0xJT3YAmzgXQ9lZcyMi96iHVH1lwC5nwZm6VgON1MFY0roj7VsUgnkTVzKmQM X-Received: by 2002:a05:6402:3070:: with SMTP id bs16mr6071528edb.371.1602879259373; Fri, 16 Oct 2020 13:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602879259; cv=none; d=google.com; s=arc-20160816; b=SUAsv+s7R/8fqR9FEpRvnFX9X0ZOFtgB/nTQ4HV1afpqNa3vtsSTGACMM5lrfcKJSe 1KpAvsV+zn+4L7uk5whYCJSFxl3zdmKqA1ABocjwYvLmIC4HVIHUp96EbQfvCYI7FKqk CCUMGR9XIs/AHbf87RJKW6+BxyCXHwaxT4vHWeHe9PSbKw1bdlvmAc9rR5YHJNfCdl8S xvWRrWiY0l5sivzO+bczaCVaBiX+MoR+eoN1fmiTcLrNu0BWftUff/m6EoSUqpDOE5pc cDzAJtpLZW9AWqDRdJye/IB7vF3ogwt3vLOElqpP4hMRfWx7eQx1lLL592QHcj1grgKw 3A2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VPqYHOjfmmdwtd7yH1X3jLVZGjPl7VQjFfVcZku7bSE=; b=BJt6b9edcu5K6H7dxM4gXv6oXkO3tdGoZvQBD83p/42Y2r1Re49dk6+RmfqN9atNMO i4rF07CL643zTaAMIZWetslIlO3jTQIT27TegFmuQ4GLJCPIK09sUmlcWxvHHNDbt5Tf LHTrgJCJGDuxWQbYpNNp6nVynLffQkbU+yph139XGyeHEV7Pxzh9Kipt/bp7511XxHkw ft1kygPM/fXP3lvOOak8oSBcr2Lh840lNzOsda0J63UW/WL3vaIW9t6v97lpQGbYVAXz 9JQGA37vF7USWHO7xMU8NnmkEP4ARYhvmH6/kB8LLuXpVHY0X08XoV+D7nm/jY/CagJx zxXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si2574840edn.23.2020.10.16.13.13.57; Fri, 16 Oct 2020 13:14:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393358AbgJPUE2 (ORCPT + 99 others); Fri, 16 Oct 2020 16:04:28 -0400 Received: from mailout06.rmx.de ([94.199.90.92]:45644 "EHLO mailout06.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393334AbgJPUE1 (ORCPT ); Fri, 16 Oct 2020 16:04:27 -0400 Received: from kdin01.retarus.com (kdin01.dmz1.retloc [172.19.17.48]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout06.rmx.de (Postfix) with ESMTPS id 4CCcYf61nmz9vB2; Fri, 16 Oct 2020 22:04:22 +0200 (CEST) Received: from mta.arri.de (unknown [217.111.95.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by kdin01.retarus.com (Postfix) with ESMTPS id 4CCcXr0CzYz2xPF; Fri, 16 Oct 2020 22:03:40 +0200 (CEST) Received: from N95HX1G2.wgnetz.xx (192.168.54.12) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 16 Oct 2020 22:03:25 +0200 From: Christian Eggers To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Jakub Kicinski , Kurt Kanzenbach CC: "David S . Miller" , Woojung Huh , Microchip Linux Driver Support , , , Christian Eggers Subject: [PATCH net-next 1/3] net: dsa: don't pass cloned skb's to drivers xmit function Date: Fri, 16 Oct 2020 22:02:24 +0200 Message-ID: <20201016200226.23994-2-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201016200226.23994-1-ceggers@arri.de> References: <20201016200226.23994-1-ceggers@arri.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.54.12] X-RMX-ID: 20201016-220340-4CCcXr0CzYz2xPF-0@kdin01 X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ensure that the skb is not cloned and has enough tail room for the tail tag. This code will be removed from the drivers in the next commits. Signed-off-by: Christian Eggers --- net/dsa/dsa_priv.h | 3 +++ net/dsa/slave.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 12998bf04e55..975001c625b1 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -77,6 +77,9 @@ struct dsa_slave_priv { /* Copy of CPU port xmit for faster access in slave transmit hot path */ struct sk_buff * (*xmit)(struct sk_buff *skb, struct net_device *dev); + /* same for tail_tag and overhead */ + bool tail_tag; + unsigned int overhead; struct pcpu_sw_netstats __percpu *stats64; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 3bc5ca40c9fb..49a19a3b0736 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -553,6 +553,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) struct dsa_slave_priv *p = netdev_priv(dev); struct pcpu_sw_netstats *s; struct sk_buff *nskb; + int padlen; s = this_cpu_ptr(p->stats64); u64_stats_update_begin(&s->syncp); @@ -567,6 +568,41 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) */ dsa_skb_tx_timestamp(p, skb); + /* We have to pad he packet to the minimum Ethernet frame size, + * if necessary, before adding the trailer (tail tagging only). + */ + padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len; + + /* To keep the slave's xmit() methods simple, don't pass cloned skbs to + * them. Additionally ensure, that suitable room for tail tagging is + * available. + */ + if (skb_cloned(skb) || + (p->tail_tag && skb_tailroom(skb) < (padlen + p->overhead))) { + struct sk_buff *nskb; + + nskb = alloc_skb(NET_IP_ALIGN + skb->len + + padlen + p->overhead, GFP_ATOMIC); + if (!nskb) { + kfree_skb(skb); + return NETDEV_TX_OK; + } + skb_reserve(nskb, NET_IP_ALIGN); + + skb_reset_mac_header(nskb); + skb_set_network_header(nskb, + skb_network_header(skb) - skb->head); + skb_set_transport_header(nskb, + skb_transport_header(skb) - skb->head); + skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len)); + consume_skb(skb); + + if (padlen) + skb_put_zero(nskb, padlen); + + skb = nskb; + } + /* Transmit function may have to reallocate the original SKB, * in which case it must have freed it. Only free it here on error. */ @@ -1814,6 +1850,8 @@ int dsa_slave_create(struct dsa_port *port) p->dp = port; INIT_LIST_HEAD(&p->mall_tc_list); p->xmit = cpu_dp->tag_ops->xmit; + p->tail_tag = cpu_dp->tag_ops->tail_tag; + p->overhead = cpu_dp->tag_ops->overhead; port->slave = slave_dev; rtnl_lock(); -- Christian Eggers Embedded software developer Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918 Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477 Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler