net: remove some skb_mac_header assumptions
Subsystems (4)
cover net: remove some skb_mac_header assumptions
Historically, we tried o maintain skb_mac_header available in most of networking paths.
When reaching ndo_start_xmit() handlers, skb_mac_header() should always be skb->data.
With recent additions of skb_mac_header_was_set() and DEBUG_NET_WARN_ON_ONCE() in skb_mac_header(), we can attempt to remove our reliance on skb_mac_header in TX paths.
When this effort completes we will remove skb_reset_mac_header() from __dev_queue_xmit() and replace it by skb_unset_mac_header() on DEBUG_NET builds.
Eric Dumazet (3):
net: do not use skb_mac_header() in qdisc_pkt_len_init()
sch_cake: do not use skb_mac_header() in cake_overhead() net/sched: remove two skb_mac_header() uses
net/core/dev.c | 8 ++++---- net/sched/act_mirred.c | 2 +- net/sched/act_mpls.c | 2 +- net/sched/sch_cake.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
PATCH 1/3 net: do not use skb_mac_header() in qdisc_pkt_len_init()
We want to remove our use of skb_mac_header() in tx paths, eg remove skb_reset_mac_header() from __dev_queue_xmit().
Idea is that ndo_start_xmit() can get the mac header simply looking at skb->data.
--- net/core/dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/dev.c +4 -4
@@ -3733,25 +3733,25 @@ static void qdisc_pkt_len_init(struct sk_buff *skb)* we add to pkt_len the headers size of all segments */ if (shinfo->gso_size &&skb_transport_header_was_set (skb)) { -unsigned int hdr_len;u16 gso_segs = shinfo->gso_segs; +unsigned int hdr_len;/* mac layer + network layer */ - hdr_len =skb_transport_header (skb) -skb_mac_header (skb); + hdr_len =skb_transport_offset (skb);/* + transport layer */ if (likely (shinfo->gso_type & (SKB_GSO_TCPV4 |SKB_GSO_TCPV6 ))) {const struct tcphdr *th;struct tcphdr _tcphdr; - th =skb_header_pointer (skb,skb_transport_offset (skb), + th =skb_header_pointer (skb, hdr_len,sizeof (_tcphdr), &_tcphdr);if (likely (th)) hdr_len +=__tcp_hdrlen (th); }else {struct udphdr _udphdr; -if (skb_header_pointer (skb,skb_transport_offset (skb), +if (skb_header_pointer (skb, hdr_len,sizeof (_udphdr), &_udphdr)) hdr_len +=sizeof (struct udphdr ); }
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
Re: [PATCH net-next 1/3] net: do not use skb_mac_header() in qdisc_pkt_len_init()
Quoted 7 lines · Eric Dumazet
We want to remove our use of
skb_mac_header()in tx paths, eg removeskb_reset_mac_header()from__dev_queue_xmit().Idea is that
ndo_start_xmit()can get the mac header simply looking atskb->data.Signed-off-by Eric Dumazet <[email protected]>
PATCH 2/3 sch_cake: do not use skb_mac_header() in cake_overhead()
In reply to Eric DumazetWe want to remove our use of skb_mac_header() in tx paths, eg remove skb_reset_mac_header() from __dev_queue_xmit().
Idea is that ndo_start_xmit() can get the mac header simply looking at skb->data.
--- net/sched/sch_cake.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/sched/sch_cake.c +3 -3
@@ -1360,7 +1360,7 @@ static u32 cake_overhead(struct cake_sched_data *q, const struct sk_buff *skb)return cake_calc_overhead (q, len, off);/* borrowed from qdisc_pkt_len_init() */ - hdr_len =skb_transport_header (skb) -skb_mac_header (skb); + hdr_len =skb_transport_offset (skb);/* + transport layer */ if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 |
@@ -1368,14 +1368,14 @@ static u32 cake_overhead(struct cake_sched_data *q, const struct sk_buff *skb)const struct tcphdr *th;struct tcphdr _tcphdr; - th =skb_header_pointer (skb,skb_transport_offset (skb), + th =skb_header_pointer (skb, hdr_len,sizeof (_tcphdr), &_tcphdr);if (likely (th)) hdr_len +=__tcp_hdrlen (th); }else {struct udphdr _udphdr; -if (skb_header_pointer (skb,skb_transport_offset (skb), +if (skb_header_pointer (skb, hdr_len,sizeof (_udphdr), &_udphdr)) hdr_len +=sizeof (struct udphdr ); }
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
Re: [PATCH net-next 2/3] sch_cake: do not use skb_mac_header() in cake_overhead()
Quoted 7 lines · Eric Dumazet
We want to remove our use of
skb_mac_header()in tx paths, eg removeskb_reset_mac_header()from__dev_queue_xmit().Idea is that
ndo_start_xmit()can get the mac header simply looking atskb->data.Signed-off-by Eric Dumazet <[email protected]>
PATCH 3/3 net/sched: remove two skb_mac_header() uses
In reply to Eric Dumazettcf_mirred_act() and tcf_mpls_act() can use skb_network_offset() instead of relying on skb_mac_header().
--- net/sched/act_mirred.c | 2 +- net/sched/act_mpls.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/sched/act_mirred.c +1 -1
@@ -295,7 +295,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, at_nh = skb->data ==skb_network_header (skb);if (at_nh != expects_nh) { mac_len =skb_at_tc_ingress (skb) ? skb->mac_len : -skb_network_header (skb) -skb_mac_header (skb); +skb_network_offset (skb);if (expects_nh) {/* target device/action expect data at nh */ skb_pull_rcsum (skb2, mac_len);
net/sched/act_mpls.c +1 -1
@@ -69,7 +69,7 @@ TC_INDIRECT_SCOPE int tcf_mpls_act(struct sk_buff *skb,skb_push_rcsum (skb, skb->mac_len); mac_len = skb->mac_len; }else { - mac_len =skb_network_header (skb) -skb_mac_header (skb); + mac_len =skb_network_offset (skb); } ret =READ_ONCE (m->tcf_action);
Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
Re: [PATCH net-next 3/3] net/sched: remove two skb_mac_header() uses
Quoted 4 lines · Eric Dumazet
tcf_mirred_act()andtcf_mpls_act()can useskb_network_offset()instead of relying onskb_mac_header().Signed-off-by Eric Dumazet <[email protected]>
Hi Eric,
Quoted 19 lines · Eric Dumazet
Historically, we tried o maintain
skb_mac_headeravailable in most of networking paths.When reaching
ndo_start_xmit()handlers,skb_mac_header()should always beskb->data.With recent additions of
skb_mac_header_was_set()andDEBUG_NET_WARN_ON_ONCE()inskb_mac_header(), we can attempt to remove our reliance onskb_mac_headerin TX paths.When this effort completes we will remove
skb_reset_mac_header()from__dev_queue_xmit()and replace it byskb_unset_mac_header()onDEBUG_NETbuilds.Eric Dumazet (3):
net: do not useskb_mac_header()inqdisc_pkt_len_init()
sch_cake: do not useskb_mac_header()incake_overhead()net/sched: remove twoskb_mac_header()uses
Quoted 9 lines
net/core/dev.c | 8 ++++---- net/sched/act_mirred.c | 2 +- net/sched/act_mpls.c | 2 +- net/sched/sch_cake.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)Signature · 1 line
2.40.0.rc2.332.ga46443480c-goog
skb_mac_header() shows quite a few hits in net/dsa/ as well, in functions that contain "xmit" in the name. Should those be changed as well?
Quoted 6 lines · Vladimir Oltean
Hi Eric,
skb_mac_header()shows quite a few hits innet/dsa/as well, in functions that contain "xmit" in the name. Should those be changed as well?
Hi Vladimir.
Yes, any help that you can provide (especially if you can test patches) will be much welcomed.
Thanks !
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Tue, 21 Mar 2023 16:45:16 +0000 you wrote:
Historically, we tried o maintain
skb_mac_headeravailable in most of networking paths.When reaching
ndo_start_xmit()handlers,skb_mac_header()should always beskb->data.With recent additions of
skb_mac_header_was_set()andDEBUG_NET_WARN_ON_ONCE()inskb_mac_header(), we can attempt to remove our reliance onskb_mac_headerin TX paths.[...]
Here is the summary with links:
- [net-next,1/3] net: do not use skb_mac_header() in qdisc_pkt_len_init()
https://git.kernel.org/netdev/net-next/c/f5fca219ad45 - [net-next,2/3] sch_cake: do not use skb_mac_header() in cake_overhead() https://git.kernel.org/netdev/net-next/c/e495a9673caf - [net-next,3/3] net/sched: remove two skb_mac_header() uses https://git.kernel.org/netdev/net-next/c/b3be94885af4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html