All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path
@ 2023-03-22 23:38 Vladimir Oltean
  2023-03-22 23:38 ` [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set Vladimir Oltean
                   ` (9 more replies)
  0 siblings, 10 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

Eric started working on removing skb_mac_header() assumptions from the
networking xmit path, and I offered to help for DSA:
https://lore.kernel.org/netdev/20230321164519.1286357-1-edumazet@google.com/

The majority of this patch set is a straightforward replacement of
skb_mac_header() with skb->data (hidden either behind skb_eth_hdr(), or
behind skb_vlan_eth_hdr()). The only patch which is more "interesting"
is 9/9.

tcf_vlan_act() is also a potential caller of __skb_vlan_pop() on xmit,
through skb_vlan_pop(), but I haven't actually managed to convince this
veth setup to not use vlan hwaccel tags, so I couldn't test my
assumptions:

ip link add veth0 type veth peer name veth1

ip netns add ns0
ip link set veth1 netns ns0 && ip -n ns0 link set veth1 up
ip link set veth0 up

ethtool -K veth0 rx-vlan-offload off tx-vlan-offload off
ip netns exec ns0 ethtool -K veth1 rx-vlan-offload off tx-vlan-offload off

tc qdisc add dev veth0 clsact
tc -n ns0 qdisc add dev veth1 clsact
tc filter add dev veth0 egress protocol 802.1Q flower vlan_id 3 action vlan pop
tc filter add dev veth0 ingress protocol all matchall action vlan push id 3

ip link add link veth0 name veth0.3 type vlan id 3
ip link set veth0.3 up

ip -n ns0 addr add 192.168.100.2/24 dev veth1
ip addr add 192.168.100.1/24 dev veth0.3

I'm likely going to need to resend this, but I'm not able to come up
with something better for today, so posting this at least for a
preliminary view.

Vladimir Oltean (9):
  net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless
    set
  net: vlan: introduce skb_vlan_eth_hdr()
  net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum()
  net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit
  net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths
  net: dsa: tag_sja1105: don't rely on skb_mac_header() in TX paths
  net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr()
  net: dsa: update TX path comments to not mention skb_mac_header()
  net: dsa: tag_ocelot: call only the relevant portion of
    __skb_vlan_pop() on TX

 .../net/ethernet/broadcom/bnx2x/bnx2x_cmn.c   |  3 +-
 drivers/net/ethernet/emulex/benet/be_main.c   |  2 +-
 .../net/ethernet/freescale/dpaa/dpaa_eth.c    |  9 ++---
 .../net/ethernet/hisilicon/hns3/hns3_enet.c   |  2 +-
 drivers/net/ethernet/intel/i40e/i40e_txrx.c   |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  2 +-
 .../ethernet/qlogic/netxen/netxen_nic_main.c  |  2 +-
 .../net/ethernet/qlogic/qlcnic/qlcnic_io.c    |  4 +--
 drivers/net/ethernet/sfc/tx_tso.c             |  2 +-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  7 ++--
 drivers/staging/gdm724x/gdm_lte.c             |  4 +--
 include/linux/if_vlan.h                       | 35 +++++++++++++++++--
 net/batman-adv/soft-interface.c               |  2 +-
 net/core/skbuff.c                             |  8 +----
 net/dsa/tag.h                                 |  2 +-
 net/dsa/tag_8021q.c                           |  4 +--
 net/dsa/tag_ksz.c                             | 18 +++++-----
 net/dsa/tag_ocelot.c                          |  4 +--
 net/dsa/tag_sja1105.c                         |  4 +--
 19 files changed, 65 insertions(+), 51 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:08   ` Simon Horman
  2023-03-23 16:30   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr() Vladimir Oltean
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

This is a preparatory change for the deletion of skb_reset_mac_header(skb)
from __dev_queue_xmit(). After that deletion, skb_mac_header(skb) will
no longer be set in TX paths, from which __vlan_insert_inner_tag() can
still be called (perhaps indirectly).

If we don't make this change, then an unset MAC header (equal to ~0U)
will become set after the adjustment with VLAN_HLEN.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 include/linux/if_vlan.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index 6864b89ef868..90b76d63c11c 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -351,7 +351,8 @@ static inline int __vlan_insert_inner_tag(struct sk_buff *skb,
 	/* Move the mac header sans proto to the beginning of the new header. */
 	if (likely(mac_len > ETH_TLEN))
 		memmove(skb->data, skb->data + VLAN_HLEN, mac_len - ETH_TLEN);
-	skb->mac_header -= VLAN_HLEN;
+	if (skb_mac_header_was_set(skb))
+		skb->mac_header -= VLAN_HLEN;
 
 	veth = (struct vlan_ethhdr *)(skb->data + mac_len - ETH_HLEN);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr()
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
  2023-03-22 23:38 ` [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:08   ` Simon Horman
  2023-03-23 16:31   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum() Vladimir Oltean
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

Similar to skb_eth_hdr() introduced in commit 96cc4b69581d ("macvlan: do
not assume mac_header is set in macvlan_broadcast()"), let's introduce a
skb_vlan_eth_hdr() helper which can be used in TX-only code paths to get
to the VLAN header based on skb->data rather than based on the
skb_mac_header(skb).

We also consolidate the drivers that dereference skb->data to go through
this helper.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c      |  3 +--
 drivers/net/ethernet/emulex/benet/be_main.c          |  2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c      |  2 +-
 drivers/net/ethernet/intel/i40e/i40e_txrx.c          |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c        |  2 +-
 drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c |  2 +-
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c       |  4 ++--
 drivers/net/ethernet/sfc/tx_tso.c                    |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  7 ++-----
 drivers/staging/gdm724x/gdm_lte.c                    |  4 ++--
 include/linux/if_vlan.h                              | 12 ++++++++++--
 net/batman-adv/soft-interface.c                      |  2 +-
 12 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 16c490692f42..4950fde82d17 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -1923,8 +1923,7 @@ u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
 
 		/* Skip VLAN tag if present */
 		if (ether_type == ETH_P_8021Q) {
-			struct vlan_ethhdr *vhdr =
-				(struct vlan_ethhdr *)skb->data;
+			struct vlan_ethhdr *vhdr = skb_vlan_eth_hdr(skb);
 
 			ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
 		}
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index aed1b622f51f..7e408bcc88de 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -1124,7 +1124,7 @@ static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter,
 						  struct be_wrb_params
 						  *wrb_params)
 {
-	struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
+	struct vlan_ethhdr *veh = skb_vlan_eth_hdr(skb);
 	unsigned int eth_hdr_len;
 	struct iphdr *ip;
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 5caea154362f..7356ad965487 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1532,7 +1532,7 @@ static int hns3_handle_vtags(struct hns3_enet_ring *tx_ring,
 	if (unlikely(rc < 0))
 		return rc;
 
-	vhdr = (struct vlan_ethhdr *)skb->data;
+	vhdr = skb_vlan_eth_hdr(skb);
 	vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority << VLAN_PRIO_SHIFT)
 					 & VLAN_PRIO_MASK);
 
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
index 32cce90abbb4..81856f444d38 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
@@ -3063,7 +3063,7 @@ static inline int i40e_tx_prepare_vlan_flags(struct sk_buff *skb,
 			rc = skb_cow_head(skb, 0);
 			if (rc < 0)
 				return rc;
-			vhdr = (struct vlan_ethhdr *)skb->data;
+			vhdr = skb_vlan_eth_hdr(skb);
 			vhdr->h_vlan_TCI = htons(tx_flags >>
 						 I40E_TX_FLAGS_VLAN_SHIFT);
 		} else {
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 773c35fecace..eae6c89e62f4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -8818,7 +8818,7 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
 
 			if (skb_cow_head(skb, 0))
 				goto out_drop;
-			vhdr = (struct vlan_ethhdr *)skb->data;
+			vhdr = skb_vlan_eth_hdr(skb);
 			vhdr->h_vlan_TCI = htons(tx_flags >>
 						 IXGBE_TX_FLAGS_VLAN_SHIFT);
 		} else {
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
index 59d0dd862fd1..1d1e183d3a8b 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
@@ -1854,7 +1854,7 @@ netxen_tso_check(struct net_device *netdev,
 
 	if (protocol == cpu_to_be16(ETH_P_8021Q)) {
 
-		vh = (struct vlan_ethhdr *)skb->data;
+		vh = skb_vlan_eth_hdr(skb);
 		protocol = vh->h_vlan_encapsulated_proto;
 		flags = FLAGS_VLAN_TAGGED;
 
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
index 92930a055cbc..41894d154013 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
@@ -318,7 +318,7 @@ static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
 
 	if (adapter->flags & QLCNIC_VLAN_FILTERING) {
 		if (protocol == ETH_P_8021Q) {
-			vh = (struct vlan_ethhdr *)skb->data;
+			vh = skb_vlan_eth_hdr(skb);
 			vlan_id = ntohs(vh->h_vlan_TCI);
 		} else if (skb_vlan_tag_present(skb)) {
 			vlan_id = skb_vlan_tag_get(skb);
@@ -468,7 +468,7 @@ static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
 	u32 producer = tx_ring->producer;
 
 	if (protocol == ETH_P_8021Q) {
-		vh = (struct vlan_ethhdr *)skb->data;
+		vh = skb_vlan_eth_hdr(skb);
 		flags = QLCNIC_FLAGS_VLAN_TAGGED;
 		vlan_tci = ntohs(vh->h_vlan_TCI);
 		protocol = ntohs(vh->h_vlan_encapsulated_proto);
diff --git a/drivers/net/ethernet/sfc/tx_tso.c b/drivers/net/ethernet/sfc/tx_tso.c
index 898e5c61d908..d381d8164f07 100644
--- a/drivers/net/ethernet/sfc/tx_tso.c
+++ b/drivers/net/ethernet/sfc/tx_tso.c
@@ -147,7 +147,7 @@ static __be16 efx_tso_check_protocol(struct sk_buff *skb)
 	EFX_WARN_ON_ONCE_PARANOID(((struct ethhdr *)skb->data)->h_proto !=
 				  protocol);
 	if (protocol == htons(ETH_P_8021Q)) {
-		struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
+		struct vlan_ethhdr *veh = skb_vlan_eth_hdr(skb);
 
 		protocol = veh->h_vlan_encapsulated_proto;
 	}
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8f543c3ab5c5..918de65fb707 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4554,13 +4554,10 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
 {
-	struct vlan_ethhdr *veth;
-	__be16 vlan_proto;
+	struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb);
+	__be16 vlan_proto = veth->h_vlan_proto;
 	u16 vlanid;
 
-	veth = (struct vlan_ethhdr *)skb->data;
-	vlan_proto = veth->h_vlan_proto;
-
 	if ((vlan_proto == htons(ETH_P_8021Q) &&
 	     dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
 	    (vlan_proto == htons(ETH_P_8021AD) &&
diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c
index 671ee8843c88..5703a9ddb6d0 100644
--- a/drivers/staging/gdm724x/gdm_lte.c
+++ b/drivers/staging/gdm724x/gdm_lte.c
@@ -349,7 +349,7 @@ static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb)
 	/* Get ethernet protocol */
 	eth = (struct ethhdr *)skb->data;
 	if (ntohs(eth->h_proto) == ETH_P_8021Q) {
-		vlan_eth = (struct vlan_ethhdr *)skb->data;
+		vlan_eth = skb_vlan_eth_hdr(skb);
 		mac_proto = ntohs(vlan_eth->h_vlan_encapsulated_proto);
 		network_data = skb->data + VLAN_ETH_HLEN;
 		nic_type |= NIC_TYPE_F_VLAN;
@@ -435,7 +435,7 @@ static netdev_tx_t gdm_lte_tx(struct sk_buff *skb, struct net_device *dev)
 	 * driver based on the NIC mac
 	 */
 	if (nic_type & NIC_TYPE_F_VLAN) {
-		struct vlan_ethhdr *vlan_eth = (struct vlan_ethhdr *)skb->data;
+		struct vlan_ethhdr *vlan_eth = skb_vlan_eth_hdr(skb);
 
 		nic->vlan_id = ntohs(vlan_eth->h_vlan_TCI) & VLAN_VID_MASK;
 		data_buf = skb->data + (VLAN_ETH_HLEN - ETH_HLEN);
diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index 90b76d63c11c..3698f2b391cd 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -62,6 +62,14 @@ static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
 	return (struct vlan_ethhdr *)skb_mac_header(skb);
 }
 
+/* Prefer this version in TX path, instead of
+ * skb_reset_mac_header() + vlan_eth_hdr()
+ */
+static inline struct vlan_ethhdr *skb_vlan_eth_hdr(const struct sk_buff *skb)
+{
+	return (struct vlan_ethhdr *)skb->data;
+}
+
 #define VLAN_PRIO_MASK		0xe000 /* Priority Code Point */
 #define VLAN_PRIO_SHIFT		13
 #define VLAN_CFI_MASK		0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
@@ -529,7 +537,7 @@ static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb,
  */
 static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
 {
-	struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;
+	struct vlan_ethhdr *veth = skb_vlan_eth_hdr(skb);
 
 	if (!eth_type_vlan(veth->h_vlan_proto))
 		return -EINVAL;
@@ -713,7 +721,7 @@ static inline bool skb_vlan_tagged_multi(struct sk_buff *skb)
 		if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
 			return false;
 
-		veh = (struct vlan_ethhdr *)skb->data;
+		veh = skb_vlan_eth_hdr(skb);
 		protocol = veh->h_vlan_encapsulated_proto;
 	}
 
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 125f4628687c..d3fdf82282af 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -439,7 +439,7 @@ void batadv_interface_rx(struct net_device *soft_iface,
 		if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
 			goto dropped;
 
-		vhdr = (struct vlan_ethhdr *)skb->data;
+		vhdr = skb_vlan_eth_hdr(skb);
 
 		/* drop batman-in-batman packets to prevent loops */
 		if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum()
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
  2023-03-22 23:38 ` [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set Vladimir Oltean
  2023-03-22 23:38 ` [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr() Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:09   ` Simon Horman
  2023-03-23 16:31   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit Vladimir Oltean
                   ` (6 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

It appears that dpaa_enable_tx_csum() only calls skb_reset_mac_header()
to get to the VLAN header using skb_mac_header().

We can use skb_vlan_eth_hdr() to get to the VLAN header based on
skb->data directly. This avoids spending a few cycles to set
skb->mac_header.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 9318a2554056..1fa676308c5e 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -1482,13 +1482,8 @@ static int dpaa_enable_tx_csum(struct dpaa_priv *priv,
 	parse_result = (struct fman_prs_result *)parse_results;
 
 	/* If we're dealing with VLAN, get the real Ethernet type */
-	if (ethertype == ETH_P_8021Q) {
-		/* We can't always assume the MAC header is set correctly
-		 * by the stack, so reset to beginning of skb->data
-		 */
-		skb_reset_mac_header(skb);
-		ethertype = ntohs(vlan_eth_hdr(skb)->h_vlan_encapsulated_proto);
-	}
+	if (ethertype == ETH_P_8021Q)
+		ethertype = ntohs(skb_vlan_eth_hdr(skb)->h_vlan_encapsulated_proto);
 
 	/* Fill in the relevant L3 parse result fields
 	 * and read the L4 protocol type
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (2 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum() Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:09   ` Simon Horman
  2023-03-23 16:31   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths Vladimir Oltean
                   ` (5 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

skb_mac_header() will no longer be available in the TX path when
reverting commit 6d1ccff62780 ("net: reset mac header in
dev_start_xmit()"). As preparation for that, let's use
skb_vlan_eth_hdr() to get to the VLAN header instead, which assumes it's
located at skb->data (assumption which holds true here).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/tag_ocelot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c
index 28ebecafdd24..73ee09de1a3a 100644
--- a/net/dsa/tag_ocelot.c
+++ b/net/dsa/tag_ocelot.c
@@ -26,7 +26,7 @@ static void ocelot_xmit_get_vlan_info(struct sk_buff *skb, struct dsa_port *dp,
 		return;
 	}
 
-	hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+	hdr = skb_vlan_eth_hdr(skb);
 	br_vlan_get_proto(br, &proto);
 
 	if (ntohs(hdr->h_vlan_proto) == proto) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (3 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:11   ` Simon Horman
  2023-03-23 16:32   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 6/9] net: dsa: tag_sja1105: don't " Vladimir Oltean
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

skb_mac_header() will no longer be available in the TX path when
reverting commit 6d1ccff62780 ("net: reset mac header in
dev_start_xmit()"). As preparation for that, let's use skb_eth_hdr() to
get to the Ethernet header's MAC DA instead, helper which assumes this
header is located at skb->data (assumption which holds true here).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/tag_ksz.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 0eb1c7784c3d..ea100bd25939 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -120,18 +120,18 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
 static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct ethhdr *hdr;
 	u8 *tag;
-	u8 *addr;
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb))
 		return NULL;
 
 	/* Tag encoding */
 	tag = skb_put(skb, KSZ_INGRESS_TAG_LEN);
-	addr = skb_mac_header(skb);
+	hdr = skb_eth_hdr(skb);
 
 	*tag = 1 << dp->index;
-	if (is_link_local_ether_addr(addr))
+	if (is_link_local_ether_addr(hdr->h_dest))
 		*tag |= KSZ8795_TAIL_TAG_OVERRIDE;
 
 	return skb;
@@ -273,8 +273,8 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb,
 	u16 queue_mapping = skb_get_queue_mapping(skb);
 	u8 prio = netdev_txq_to_tc(dev, queue_mapping);
 	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct ethhdr *hdr;
 	__be16 *tag;
-	u8 *addr;
 	u16 val;
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb))
@@ -284,13 +284,13 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb,
 	ksz_xmit_timestamp(dp, skb);
 
 	tag = skb_put(skb, KSZ9477_INGRESS_TAG_LEN);
-	addr = skb_mac_header(skb);
+	hdr = skb_eth_hdr(skb);
 
 	val = BIT(dp->index);
 
 	val |= FIELD_PREP(KSZ9477_TAIL_TAG_PRIO, prio);
 
-	if (is_link_local_ether_addr(addr))
+	if (is_link_local_ether_addr(hdr->h_dest))
 		val |= KSZ9477_TAIL_TAG_OVERRIDE;
 
 	*tag = cpu_to_be16(val);
@@ -337,7 +337,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 	u16 queue_mapping = skb_get_queue_mapping(skb);
 	u8 prio = netdev_txq_to_tc(dev, queue_mapping);
 	struct dsa_port *dp = dsa_slave_to_port(dev);
-	u8 *addr;
+	struct ethhdr *hdr;
 	u8 *tag;
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb))
@@ -347,13 +347,13 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 	ksz_xmit_timestamp(dp, skb);
 
 	tag = skb_put(skb, KSZ_INGRESS_TAG_LEN);
-	addr = skb_mac_header(skb);
+	hdr = skb_eth_hdr(skb);
 
 	*tag = BIT(dp->index);
 
 	*tag |= FIELD_PREP(KSZ9893_TAIL_TAG_PRIO, prio);
 
-	if (is_link_local_ether_addr(addr))
+	if (is_link_local_ether_addr(hdr->h_dest))
 		*tag |= KSZ9893_TAIL_TAG_OVERRIDE;
 
 	return ksz_defer_xmit(dp, skb);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 6/9] net: dsa: tag_sja1105: don't rely on skb_mac_header() in TX paths
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (4 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:11   ` Simon Horman
  2023-03-23 16:32   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr() Vladimir Oltean
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

skb_mac_header() will no longer be available in the TX path when
reverting commit 6d1ccff62780 ("net: reset mac header in
dev_start_xmit()"). As preparation for that, let's use
skb_vlan_eth_hdr() to get to the VLAN header instead, which assumes it's
located at skb->data (assumption which holds true here).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/tag_sja1105.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index 1c2ceba4771b..a7ca97b7ac9e 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -256,7 +256,7 @@ static struct sk_buff *sja1105_pvid_tag_control_pkt(struct dsa_port *dp,
 			return NULL;
 	}
 
-	hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+	hdr = skb_vlan_eth_hdr(skb);
 
 	/* If skb is already VLAN-tagged, leave that VLAN ID in place */
 	if (hdr->h_vlan_proto == xmit_tpid)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr()
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (5 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 6/9] net: dsa: tag_sja1105: don't " Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:12   ` Simon Horman
  2023-03-23 16:32   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header() Vladimir Oltean
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

This is a cosmetic patch which consolidates the code to use the helper
function offered by if_vlan.h.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/tag_sja1105.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index a7ca97b7ac9e..a5f3b73da417 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -516,7 +516,7 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb)
 static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port,
 			     int *switch_id, int *vbid, u16 *vid)
 {
-	struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+	struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
 	u16 vlan_tci;
 
 	if (skb_vlan_tag_present(skb))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header()
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (6 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr() Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:13   ` Simon Horman
  2023-03-23 16:33   ` Florian Fainelli
  2023-03-22 23:38 ` [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX Vladimir Oltean
  2023-03-23 16:24 ` [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Eric Dumazet
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

Once commit 6d1ccff62780 ("net: reset mac header in dev_start_xmit()")
will be reverted, it will no longer be true that skb->data points at
skb_mac_header(skb) - since the skb->mac_header will not be set - so
stop saying that, and just say that it points to the MAC header.

I've reviewed vlan_insert_tag() and it does not *actually* depend on
skb_mac_header(), so reword that to avoid the confusion.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/tag.h       | 2 +-
 net/dsa/tag_8021q.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/dsa/tag.h b/net/dsa/tag.h
index 7cfbca824f1c..32d12f4a9d73 100644
--- a/net/dsa/tag.h
+++ b/net/dsa/tag.h
@@ -229,7 +229,7 @@ static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
 	return skb->data - 2;
 }
 
-/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
+/* On TX, skb->data points to the MAC header, which means that EtherType
  * header taggers start exactly where the EtherType is (the EtherType is
  * treated as part of the DSA header).
  */
diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
index 5ee9ef00954e..cbdfc392f7e0 100644
--- a/net/dsa/tag_8021q.c
+++ b/net/dsa/tag_8021q.c
@@ -461,8 +461,8 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_unregister);
 struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
 			       u16 tpid, u16 tci)
 {
-	/* skb->data points at skb_mac_header, which
-	 * is fine for vlan_insert_tag.
+	/* skb->data points at the MAC header, which is fine
+	 * for vlan_insert_tag().
 	 */
 	return vlan_insert_tag(skb, htons(tpid), tci);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (7 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header() Vladimir Oltean
@ 2023-03-22 23:38 ` Vladimir Oltean
  2023-03-23 16:14   ` Simon Horman
  2023-03-23 16:34   ` Florian Fainelli
  2023-03-23 16:24 ` [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Eric Dumazet
  9 siblings, 2 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-22 23:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

ocelot_xmit_get_vlan_info() calls __skb_vlan_pop() as the most
appropriate helper I could find which strips away a VLAN header.
That's all I need it to do, but __skb_vlan_pop() has more logic, which
will become incompatible with the future revert of commit 6d1ccff62780
("net: reset mac header in dev_start_xmit()").

Namely, it performs a sanity check on skb_mac_header(), which will stop
being set after the above revert, so it will return an error instead of
removing the VLAN tag.

ocelot_xmit_get_vlan_info() gets called in 2 circumstances:

(1) the port is under a VLAN-aware bridge and the bridge sends
    VLAN-tagged packets

(2) the port is under a VLAN-aware bridge and somebody else (an 8021q
    upper) sends VLAN-tagged packets (using a VID that isn't in the
    bridge vlan tables)

In case (1), there is actually no bug to defend against, because
br_dev_xmit() calls skb_reset_mac_header() and things continue to work.

However, in case (2), illustrated using the commands below, it can be
seen that our intervention is needed, since __skb_vlan_pop() complains:

$ ip link add br0 type bridge vlan_filtering 1 && ip link set br0 up
$ ip link set $eth master br0 && ip link set $eth up
$ ip link add link $eth name $eth.100 type vlan id 100 && ip link set $eth.100 up
$ ip addr add 192.168.100.1/24 dev $eth.100
$ # needed to work around an apparent DSA RX filtering bug
$ ip link set $eth promisc on

I could fend off the checks in __skb_vlan_pop() with some
skb_mac_header_was_set() calls, but seeing how few callers of
__skb_vlan_pop() there are from TX paths, that seems rather
unproductive.

As an alternative solution, extract the bare minimum logic to strip a
VLAN header, and move it to a new helper named vlan_remove_tag(), close
to the definition of vlan_insert_tag(). Document it appropriately and
make ocelot_xmit_get_vlan_info() call this smaller helper instead.

Seeing that it doesn't appear illegal to test skb->protocol in the TX
path, I guess it would be a good for vlan_remove_tag() to also absorb
the vlan_set_encap_proto() function call.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 include/linux/if_vlan.h | 20 ++++++++++++++++++++
 net/core/skbuff.c       |  8 +-------
 net/dsa/tag_ocelot.c    |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index 3698f2b391cd..4d54814143a8 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -685,6 +685,26 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb,
 		skb->protocol = htons(ETH_P_802_2);
 }
 
+/**
+ * vlan_remove_tag - remove outer VLAN tag from payload
+ * @skb: skbuff to remove tag from
+ *
+ * Expects the skb to contain a VLAN tag in the payload, and to have skb->data
+ * pointing at the mac header.
+ *
+ * Returns a new pointer to skb->data, or NULL on failure to pull.
+ */
+static inline void *vlan_remove_tag(struct sk_buff *skb, u16 *vlan_tci)
+{
+	struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN);
+
+	*vlan_tci = ntohs(vhdr->h_vlan_TCI);
+
+	memmove(skb->data + VLAN_HLEN, skb->data, 2 * ETH_ALEN);
+	vlan_set_encap_proto(skb, vhdr);
+	return __skb_pull(skb, VLAN_HLEN);
+}
+
 /**
  * skb_vlan_tagged - check if skb is vlan tagged.
  * @skb: skbuff to query
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 050a875d09c5..0a7c058d4849 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5939,7 +5939,6 @@ EXPORT_SYMBOL(skb_ensure_writable);
  */
 int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci)
 {
-	struct vlan_hdr *vhdr;
 	int offset = skb->data - skb_mac_header(skb);
 	int err;
 
@@ -5955,13 +5954,8 @@ int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci)
 
 	skb_postpull_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN);
 
-	vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN);
-	*vlan_tci = ntohs(vhdr->h_vlan_TCI);
-
-	memmove(skb->data + VLAN_HLEN, skb->data, 2 * ETH_ALEN);
-	__skb_pull(skb, VLAN_HLEN);
+	vlan_remove_tag(skb, vlan_tci);
 
-	vlan_set_encap_proto(skb, vhdr);
 	skb->mac_header += VLAN_HLEN;
 
 	if (skb_network_offset(skb) < ETH_HLEN)
diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c
index 73ee09de1a3a..20bf7074d5a6 100644
--- a/net/dsa/tag_ocelot.c
+++ b/net/dsa/tag_ocelot.c
@@ -30,7 +30,7 @@ static void ocelot_xmit_get_vlan_info(struct sk_buff *skb, struct dsa_port *dp,
 	br_vlan_get_proto(br, &proto);
 
 	if (ntohs(hdr->h_vlan_proto) == proto) {
-		__skb_vlan_pop(skb, &tci);
+		vlan_remove_tag(skb, &tci);
 		*vlan_tci = tci;
 	} else {
 		rcu_read_lock();
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set
  2023-03-22 23:38 ` [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set Vladimir Oltean
@ 2023-03-23 16:08   ` Simon Horman
  2023-03-23 16:30   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:08 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:15AM +0200, Vladimir Oltean wrote:
> This is a preparatory change for the deletion of skb_reset_mac_header(skb)
> from __dev_queue_xmit(). After that deletion, skb_mac_header(skb) will
> no longer be set in TX paths, from which __vlan_insert_inner_tag() can
> still be called (perhaps indirectly).
> 
> If we don't make this change, then an unset MAC header (equal to ~0U)
> will become set after the adjustment with VLAN_HLEN.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr()
  2023-03-22 23:38 ` [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr() Vladimir Oltean
@ 2023-03-23 16:08   ` Simon Horman
  2023-03-23 16:31   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:08 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:16AM +0200, Vladimir Oltean wrote:
> Similar to skb_eth_hdr() introduced in commit 96cc4b69581d ("macvlan: do
> not assume mac_header is set in macvlan_broadcast()"), let's introduce a
> skb_vlan_eth_hdr() helper which can be used in TX-only code paths to get
> to the VLAN header based on skb->data rather than based on the
> skb_mac_header(skb).
> 
> We also consolidate the drivers that dereference skb->data to go through
> this helper.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum()
  2023-03-22 23:38 ` [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum() Vladimir Oltean
@ 2023-03-23 16:09   ` Simon Horman
  2023-03-23 16:31   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:09 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:17AM +0200, Vladimir Oltean wrote:
> It appears that dpaa_enable_tx_csum() only calls skb_reset_mac_header()
> to get to the VLAN header using skb_mac_header().
> 
> We can use skb_vlan_eth_hdr() to get to the VLAN header based on
> skb->data directly. This avoids spending a few cycles to set
> skb->mac_header.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit
  2023-03-22 23:38 ` [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit Vladimir Oltean
@ 2023-03-23 16:09   ` Simon Horman
  2023-03-23 16:31   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:09 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:18AM +0200, Vladimir Oltean wrote:
> skb_mac_header() will no longer be available in the TX path when
> reverting commit 6d1ccff62780 ("net: reset mac header in
> dev_start_xmit()"). As preparation for that, let's use
> skb_vlan_eth_hdr() to get to the VLAN header instead, which assumes it's
> located at skb->data (assumption which holds true here).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths
  2023-03-22 23:38 ` [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths Vladimir Oltean
@ 2023-03-23 16:11   ` Simon Horman
  2023-03-23 16:32   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:11 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:19AM +0200, Vladimir Oltean wrote:
> skb_mac_header() will no longer be available in the TX path when
> reverting commit 6d1ccff62780 ("net: reset mac header in
> dev_start_xmit()"). As preparation for that, let's use skb_eth_hdr() to
> get to the Ethernet header's MAC DA instead, helper which assumes this
> header is located at skb->data (assumption which holds true here).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 6/9] net: dsa: tag_sja1105: don't rely on skb_mac_header() in TX paths
  2023-03-22 23:38 ` [PATCH net-next 6/9] net: dsa: tag_sja1105: don't " Vladimir Oltean
@ 2023-03-23 16:11   ` Simon Horman
  2023-03-23 16:32   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:11 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:20AM +0200, Vladimir Oltean wrote:
> skb_mac_header() will no longer be available in the TX path when
> reverting commit 6d1ccff62780 ("net: reset mac header in
> dev_start_xmit()"). As preparation for that, let's use
> skb_vlan_eth_hdr() to get to the VLAN header instead, which assumes it's
> located at skb->data (assumption which holds true here).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr()
  2023-03-22 23:38 ` [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr() Vladimir Oltean
@ 2023-03-23 16:12   ` Simon Horman
  2023-03-23 16:32   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:12 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:21AM +0200, Vladimir Oltean wrote:
> This is a cosmetic patch which consolidates the code to use the helper
> function offered by if_vlan.h.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header()
  2023-03-22 23:38 ` [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header() Vladimir Oltean
@ 2023-03-23 16:13   ` Simon Horman
  2023-03-23 16:33   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:13 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:22AM +0200, Vladimir Oltean wrote:
> Once commit 6d1ccff62780 ("net: reset mac header in dev_start_xmit()")
> will be reverted, it will no longer be true that skb->data points at
> skb_mac_header(skb) - since the skb->mac_header will not be set - so
> stop saying that, and just say that it points to the MAC header.
> 
> I've reviewed vlan_insert_tag() and it does not *actually* depend on
> skb_mac_header(), so reword that to avoid the confusion.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX
  2023-03-22 23:38 ` [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX Vladimir Oltean
@ 2023-03-23 16:14   ` Simon Horman
  2023-03-23 16:34   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Simon Horman @ 2023-03-23 16:14 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Florian Fainelli, linux-kernel

On Thu, Mar 23, 2023 at 01:38:23AM +0200, Vladimir Oltean wrote:
> ocelot_xmit_get_vlan_info() calls __skb_vlan_pop() as the most
> appropriate helper I could find which strips away a VLAN header.
> That's all I need it to do, but __skb_vlan_pop() has more logic, which
> will become incompatible with the future revert of commit 6d1ccff62780
> ("net: reset mac header in dev_start_xmit()").
> 
> Namely, it performs a sanity check on skb_mac_header(), which will stop
> being set after the above revert, so it will return an error instead of
> removing the VLAN tag.
> 
> ocelot_xmit_get_vlan_info() gets called in 2 circumstances:
> 
> (1) the port is under a VLAN-aware bridge and the bridge sends
>     VLAN-tagged packets
> 
> (2) the port is under a VLAN-aware bridge and somebody else (an 8021q
>     upper) sends VLAN-tagged packets (using a VID that isn't in the
>     bridge vlan tables)
> 
> In case (1), there is actually no bug to defend against, because
> br_dev_xmit() calls skb_reset_mac_header() and things continue to work.
> 
> However, in case (2), illustrated using the commands below, it can be
> seen that our intervention is needed, since __skb_vlan_pop() complains:
> 
> $ ip link add br0 type bridge vlan_filtering 1 && ip link set br0 up
> $ ip link set $eth master br0 && ip link set $eth up
> $ ip link add link $eth name $eth.100 type vlan id 100 && ip link set $eth.100 up
> $ ip addr add 192.168.100.1/24 dev $eth.100
> $ # needed to work around an apparent DSA RX filtering bug
> $ ip link set $eth promisc on
> 
> I could fend off the checks in __skb_vlan_pop() with some
> skb_mac_header_was_set() calls, but seeing how few callers of
> __skb_vlan_pop() there are from TX paths, that seems rather
> unproductive.
> 
> As an alternative solution, extract the bare minimum logic to strip a
> VLAN header, and move it to a new helper named vlan_remove_tag(), close
> to the definition of vlan_insert_tag(). Document it appropriately and
> make ocelot_xmit_get_vlan_info() call this smaller helper instead.
> 
> Seeing that it doesn't appear illegal to test skb->protocol in the TX
> path, I guess it would be a good for vlan_remove_tag() to also absorb
> the vlan_set_encap_proto() function call.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path
  2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
                   ` (8 preceding siblings ...)
  2023-03-22 23:38 ` [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX Vladimir Oltean
@ 2023-03-23 16:24 ` Eric Dumazet
  2023-03-23 16:36   ` Vladimir Oltean
  9 siblings, 1 reply; 30+ messages in thread
From: Eric Dumazet @ 2023-03-23 16:24 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

On Wed, Mar 22, 2023 at 4:38 PM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:
>
> Eric started working on removing skb_mac_header() assumptions from the
> networking xmit path, and I offered to help for DSA:
> https://lore.kernel.org/netdev/20230321164519.1286357-1-edumazet@google.com/
>
> The majority of this patch set is a straightforward replacement of
> skb_mac_header() with skb->data (hidden either behind skb_eth_hdr(), or
> behind skb_vlan_eth_hdr()). The only patch which is more "interesting"
> is 9/9.
>

SGTM, thanks a lot !

For the whole series :

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set
  2023-03-22 23:38 ` [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set Vladimir Oltean
  2023-03-23 16:08   ` Simon Horman
@ 2023-03-23 16:30   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:30 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> This is a preparatory change for the deletion of skb_reset_mac_header(skb)
> from __dev_queue_xmit(). After that deletion, skb_mac_header(skb) will
> no longer be set in TX paths, from which __vlan_insert_inner_tag() can
> still be called (perhaps indirectly).
> 
> If we don't make this change, then an unset MAC header (equal to ~0U)
> will become set after the adjustment with VLAN_HLEN.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr()
  2023-03-22 23:38 ` [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr() Vladimir Oltean
  2023-03-23 16:08   ` Simon Horman
@ 2023-03-23 16:31   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:31 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> Similar to skb_eth_hdr() introduced in commit 96cc4b69581d ("macvlan: do
> not assume mac_header is set in macvlan_broadcast()"), let's introduce a
> skb_vlan_eth_hdr() helper which can be used in TX-only code paths to get
> to the VLAN header based on skb->data rather than based on the
> skb_mac_header(skb).
> 
> We also consolidate the drivers that dereference skb->data to go through
> this helper.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum()
  2023-03-22 23:38 ` [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum() Vladimir Oltean
  2023-03-23 16:09   ` Simon Horman
@ 2023-03-23 16:31   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:31 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> It appears that dpaa_enable_tx_csum() only calls skb_reset_mac_header()
> to get to the VLAN header using skb_mac_header().
> 
> We can use skb_vlan_eth_hdr() to get to the VLAN header based on
> skb->data directly. This avoids spending a few cycles to set
> skb->mac_header.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit
  2023-03-22 23:38 ` [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit Vladimir Oltean
  2023-03-23 16:09   ` Simon Horman
@ 2023-03-23 16:31   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:31 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> skb_mac_header() will no longer be available in the TX path when
> reverting commit 6d1ccff62780 ("net: reset mac header in
> dev_start_xmit()"). As preparation for that, let's use
> skb_vlan_eth_hdr() to get to the VLAN header instead, which assumes it's
> located at skb->data (assumption which holds true here).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths
  2023-03-22 23:38 ` [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths Vladimir Oltean
  2023-03-23 16:11   ` Simon Horman
@ 2023-03-23 16:32   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:32 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> skb_mac_header() will no longer be available in the TX path when
> reverting commit 6d1ccff62780 ("net: reset mac header in
> dev_start_xmit()"). As preparation for that, let's use skb_eth_hdr() to
> get to the Ethernet header's MAC DA instead, helper which assumes this
> header is located at skb->data (assumption which holds true here).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 6/9] net: dsa: tag_sja1105: don't rely on skb_mac_header() in TX paths
  2023-03-22 23:38 ` [PATCH net-next 6/9] net: dsa: tag_sja1105: don't " Vladimir Oltean
  2023-03-23 16:11   ` Simon Horman
@ 2023-03-23 16:32   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:32 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> skb_mac_header() will no longer be available in the TX path when
> reverting commit 6d1ccff62780 ("net: reset mac header in
> dev_start_xmit()"). As preparation for that, let's use
> skb_vlan_eth_hdr() to get to the VLAN header instead, which assumes it's
> located at skb->data (assumption which holds true here).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr()
  2023-03-22 23:38 ` [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr() Vladimir Oltean
  2023-03-23 16:12   ` Simon Horman
@ 2023-03-23 16:32   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:32 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> This is a cosmetic patch which consolidates the code to use the helper
> function offered by if_vlan.h.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header()
  2023-03-22 23:38 ` [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header() Vladimir Oltean
  2023-03-23 16:13   ` Simon Horman
@ 2023-03-23 16:33   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:33 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> Once commit 6d1ccff62780 ("net: reset mac header in dev_start_xmit()")
> will be reverted, it will no longer be true that skb->data points at
> skb_mac_header(skb) - since the skb->mac_header will not be set - so
> stop saying that, and just say that it points to the MAC header.
> 
> I've reviewed vlan_insert_tag() and it does not *actually* depend on
> skb_mac_header(), so reword that to avoid the confusion.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

  }

-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX
  2023-03-22 23:38 ` [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX Vladimir Oltean
  2023-03-23 16:14   ` Simon Horman
@ 2023-03-23 16:34   ` Florian Fainelli
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Fainelli @ 2023-03-23 16:34 UTC (permalink / raw)
  To: Vladimir Oltean, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, linux-kernel

On 3/22/23 16:38, Vladimir Oltean wrote:
> ocelot_xmit_get_vlan_info() calls __skb_vlan_pop() as the most
> appropriate helper I could find which strips away a VLAN header.
> That's all I need it to do, but __skb_vlan_pop() has more logic, which
> will become incompatible with the future revert of commit 6d1ccff62780
> ("net: reset mac header in dev_start_xmit()").
> 
> Namely, it performs a sanity check on skb_mac_header(), which will stop
> being set after the above revert, so it will return an error instead of
> removing the VLAN tag.
> 
> ocelot_xmit_get_vlan_info() gets called in 2 circumstances:
> 
> (1) the port is under a VLAN-aware bridge and the bridge sends
>      VLAN-tagged packets
> 
> (2) the port is under a VLAN-aware bridge and somebody else (an 8021q
>      upper) sends VLAN-tagged packets (using a VID that isn't in the
>      bridge vlan tables)
> 
> In case (1), there is actually no bug to defend against, because
> br_dev_xmit() calls skb_reset_mac_header() and things continue to work.
> 
> However, in case (2), illustrated using the commands below, it can be
> seen that our intervention is needed, since __skb_vlan_pop() complains:
> 
> $ ip link add br0 type bridge vlan_filtering 1 && ip link set br0 up
> $ ip link set $eth master br0 && ip link set $eth up
> $ ip link add link $eth name $eth.100 type vlan id 100 && ip link set $eth.100 up
> $ ip addr add 192.168.100.1/24 dev $eth.100
> $ # needed to work around an apparent DSA RX filtering bug
> $ ip link set $eth promisc on
> 
> I could fend off the checks in __skb_vlan_pop() with some
> skb_mac_header_was_set() calls, but seeing how few callers of
> __skb_vlan_pop() there are from TX paths, that seems rather
> unproductive.
> 
> As an alternative solution, extract the bare minimum logic to strip a
> VLAN header, and move it to a new helper named vlan_remove_tag(), close
> to the definition of vlan_insert_tag(). Document it appropriately and
> make ocelot_xmit_get_vlan_info() call this smaller helper instead.
> 
> Seeing that it doesn't appear illegal to test skb->protocol in the TX
> path, I guess it would be a good for vlan_remove_tag() to also absorb
> the vlan_set_encap_proto() function call.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path
  2023-03-23 16:24 ` [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Eric Dumazet
@ 2023-03-23 16:36   ` Vladimir Oltean
  0 siblings, 0 replies; 30+ messages in thread
From: Vladimir Oltean @ 2023-03-23 16:36 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: netdev, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Florian Fainelli, linux-kernel

Hi Eric,

On Thu, Mar 23, 2023 at 09:24:28AM -0700, Eric Dumazet wrote:
> On Wed, Mar 22, 2023 at 4:38 PM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:
> >
> > Eric started working on removing skb_mac_header() assumptions from the
> > networking xmit path, and I offered to help for DSA:
> > https://lore.kernel.org/netdev/20230321164519.1286357-1-edumazet@google.com/
> >
> > The majority of this patch set is a straightforward replacement of
> > skb_mac_header() with skb->data (hidden either behind skb_eth_hdr(), or
> > behind skb_vlan_eth_hdr()). The only patch which is more "interesting"
> > is 9/9.
> >
> 
> SGTM, thanks a lot !
> 
> For the whole series :
> 
> Reviewed-by: Eric Dumazet <edumazet@google.com>

I'd have to resend this patch set anyway, due to the kdoc warning from
the last patch:
https://patchwork.hopto.org/static/nipa/732927/13184745/kdoc/stderr
(and also probably to CC the driver maintainers where I'm refactoring
stuff; didn't want to do that for what I was sure would only be the
initial patch set)

Have you seen my dilemma from patch 9/9 and from the cover letter -
__skb_vlan_pop() potentially being called from not just one xmit code
path? I took a different approach for vlan_insert_tag() (patch 1/9)
compared to __skb_vlan_pop() (patch 9/9). If we look at the larger
picture with the tc-vlan action, it would be a valid alternative to also
use skb_mac_header_was_set() in __skb_vlan_pop().

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2023-03-23 16:38 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 23:38 [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Vladimir Oltean
2023-03-22 23:38 ` [PATCH net-next 1/9] net: vlan: don't adjust MAC header in __vlan_insert_inner_tag() unless set Vladimir Oltean
2023-03-23 16:08   ` Simon Horman
2023-03-23 16:30   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 2/9] net: vlan: introduce skb_vlan_eth_hdr() Vladimir Oltean
2023-03-23 16:08   ` Simon Horman
2023-03-23 16:31   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 3/9] net: dpaa: avoid one skb_reset_mac_header() in dpaa_enable_tx_csum() Vladimir Oltean
2023-03-23 16:09   ` Simon Horman
2023-03-23 16:31   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 4/9] net: dsa: tag_ocelot: do not rely on skb_mac_header() for VLAN xmit Vladimir Oltean
2023-03-23 16:09   ` Simon Horman
2023-03-23 16:31   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 5/9] net: dsa: tag_ksz: do not rely on skb_mac_header() in TX paths Vladimir Oltean
2023-03-23 16:11   ` Simon Horman
2023-03-23 16:32   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 6/9] net: dsa: tag_sja1105: don't " Vladimir Oltean
2023-03-23 16:11   ` Simon Horman
2023-03-23 16:32   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 7/9] net: dsa: tag_sja1105: replace skb_mac_header() with vlan_eth_hdr() Vladimir Oltean
2023-03-23 16:12   ` Simon Horman
2023-03-23 16:32   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 8/9] net: dsa: update TX path comments to not mention skb_mac_header() Vladimir Oltean
2023-03-23 16:13   ` Simon Horman
2023-03-23 16:33   ` Florian Fainelli
2023-03-22 23:38 ` [PATCH net-next 9/9] net: dsa: tag_ocelot: call only the relevant portion of __skb_vlan_pop() on TX Vladimir Oltean
2023-03-23 16:14   ` Simon Horman
2023-03-23 16:34   ` Florian Fainelli
2023-03-23 16:24 ` [PATCH net-next 0/9] Remove skb_mac_header() dependency in DSA xmit path Eric Dumazet
2023-03-23 16:36   ` Vladimir Oltean

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.