From: Christian Eggers <ceggers@arri.de>
To: Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
Kurt Kanzenbach <kurt@linutronix.de>
Cc: "David S . Miller" <davem@davemloft.net>,
Woojung Huh <woojung.huh@microchip.com>,
Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Christian Eggers <ceggers@arri.de>
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 [thread overview]
Message-ID: <20201016200226.23994-2-ceggers@arri.de> (raw)
In-Reply-To: <20201016200226.23994-1-ceggers@arri.de>
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 <ceggers@arri.de>
---
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
next prev parent reply other threads:[~2020-10-16 20:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-16 20:02 [PATCH 0/3] net: dsa: move skb reallocation to dsa_slave_xmit Christian Eggers
2020-10-16 20:02 ` Christian Eggers [this message]
2020-10-17 0:48 ` [PATCH net-next 1/3] net: dsa: don't pass cloned skb's to drivers xmit function Vladimir Oltean
2020-10-17 18:53 ` Christian Eggers
2020-10-17 19:12 ` Vladimir Oltean
2020-10-17 20:56 ` Christian Eggers
2020-10-17 21:35 ` Vladimir Oltean
2020-10-17 2:35 ` Florian Fainelli
2020-10-16 20:02 ` [PATCH net-next 2/3] net: dsa: tag_ksz: don't allocate additional memory for padding/tagging Christian Eggers
2020-10-16 20:02 ` [PATCH net-next 3/3] net: dsa: trailer: " Christian Eggers
2020-10-17 2:44 ` [PATCH 0/3] net: dsa: move skb reallocation to dsa_slave_xmit Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201016200226.23994-2-ceggers@arri.de \
--to=ceggers@arri.de \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).