From: Xin Long <lucien.xin@gmail.com> Date: 2021-01-28 09:21:28
This patchset it to add ip generic csum processing first in
skb_csum_hwoffload_help() in Patch 1/2 and then add csum
offload support for GRE header in Patch 2/2.
v1->v2:
- See each patch's changelog.
v2->v3:
- See the 1st patch.
Xin Long (2):
net: support ip generic csum processing in skb_csum_hwoffload_help
ip_gre: add csum offload support for gre header
include/net/gre.h | 19 +++++++------------
net/core/dev.c | 13 ++++++++++++-
net/ipv4/gre_offload.c | 15 +++++++++++++--
3 files changed, 32 insertions(+), 15 deletions(-)
--
2.1.0
From: Xin Long <lucien.xin@gmail.com> Date: 2021-01-28 09:23:05
This patch is to add csum offload support for gre header:
On the TX path in gre_build_header(), when CHECKSUM_PARTIAL's set
for inner proto, it will calculate the csum for outer proto, and
inner csum will be offloaded later. Otherwise, CHECKSUM_PARTIAL
and csum_start/offset will be set for outer proto, and the outer
csum will be offloaded later.
On the GSO path in gre_gso_segment(), when CHECKSUM_PARTIAL is
not set for inner proto and the hardware supports csum offload,
CHECKSUM_PARTIAL and csum_start/offset will be set for outer
proto, and outer csum will be offloaded later. Otherwise, it
will do csum for outer proto by calling gso_make_checksum().
Note that SCTP has to do the csum by itself for non GSO path in
sctp_packet_pack(), as gre_build_header() can't handle the csum
with CHECKSUM_PARTIAL set for SCTP CRC csum offload.
v1->v2:
- remove the SCTP part, as GRE dev doesn't support SCTP CRC CSUM
and it will always do checksum for SCTP in sctp_packet_pack()
when it's not a GSO packet.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/gre.h | 19 +++++++------------
net/ipv4/gre_offload.c | 15 +++++++++++++--
2 files changed, 20 insertions(+), 14 deletions(-)
From: Xin Long <lucien.xin@gmail.com> Date: 2021-01-28 09:29:35
NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload
while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload
for HW, which includes not only for TCP/UDP csum, but also for other
protocols' csum like GRE's.
However, in skb_csum_hwoffload_help() it only checks features against
NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP
packet and the features doesn't support NETIF_F_HW_CSUM, but supports
NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW
to do csum.
This patch is to support ip generic csum processing by checking
NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM) only for TCP and UDP.
Note that we're using skb->csum_offset to check if it's a TCP/UDP
proctol, this might be fragile. However, as Alex said, for now we
only have a few L4 protocols that are requesting Tx csum offload,
we'd better fix this until a new protocol comes with a same csum
offset.
v1->v2:
- not extend skb->csum_not_inet, but use skb->csum_offset to tell
if it's an UDP/TCP csum packet.
v2->v3:
- add a note in the changelog, as Willem suggested.
Suggested-by: Alexander Duyck <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/core/dev.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com> Date: 2021-01-28 14:08:20
On Thu, Jan 28, 2021 at 4:29 AM Xin Long [off-list ref] wrote:
quoted hunk
NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload
while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload
for HW, which includes not only for TCP/UDP csum, but also for other
protocols' csum like GRE's.
However, in skb_csum_hwoffload_help() it only checks features against
NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP
packet and the features doesn't support NETIF_F_HW_CSUM, but supports
NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW
to do csum.
This patch is to support ip generic csum processing by checking
NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM) only for TCP and UDP.
Note that we're using skb->csum_offset to check if it's a TCP/UDP
proctol, this might be fragile. However, as Alex said, for now we
only have a few L4 protocols that are requesting Tx csum offload,
we'd better fix this until a new protocol comes with a same csum
offset.
v1->v2:
- not extend skb->csum_not_inet, but use skb->csum_offset to tell
if it's an UDP/TCP csum packet.
v2->v3:
- add a note in the changelog, as Willem suggested.
Suggested-by: Alexander Duyck <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/core/dev.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,return!!(features&NETIF_F_SCTP_CRC)?0:skb_crc32c_csum_help(skb);-return!!(features&NETIF_F_CSUM_MASK)?0:skb_checksum_help(skb);+if(features&NETIF_F_HW_CSUM)+return0;++if(features&(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)){
Should this check the specific feature flag against skb->protocol? I
don't know if there are actually instances that only support one of
the two flags.
From: Alexander Duyck <hidden> Date: 2021-01-28 20:04:23
On Thu, Jan 28, 2021 at 6:07 AM Willem de Bruijn
[off-list ref] wrote:
On Thu, Jan 28, 2021 at 4:29 AM Xin Long [off-list ref] wrote:
quoted
NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload
while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload
for HW, which includes not only for TCP/UDP csum, but also for other
protocols' csum like GRE's.
However, in skb_csum_hwoffload_help() it only checks features against
NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP
packet and the features doesn't support NETIF_F_HW_CSUM, but supports
NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW
to do csum.
This patch is to support ip generic csum processing by checking
NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM) only for TCP and UDP.
Note that we're using skb->csum_offset to check if it's a TCP/UDP
proctol, this might be fragile. However, as Alex said, for now we
only have a few L4 protocols that are requesting Tx csum offload,
we'd better fix this until a new protocol comes with a same csum
offset.
v1->v2:
- not extend skb->csum_not_inet, but use skb->csum_offset to tell
if it's an UDP/TCP csum packet.
v2->v3:
- add a note in the changelog, as Willem suggested.
Suggested-by: Alexander Duyck <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/core/dev.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,return!!(features&NETIF_F_SCTP_CRC)?0:skb_crc32c_csum_help(skb);-return!!(features&NETIF_F_CSUM_MASK)?0:skb_checksum_help(skb);+if(features&NETIF_F_HW_CSUM)+return0;++if(features&(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)){
Should this check the specific feature flag against skb->protocol? I
don't know if there are actually instances that only support one of
the two flags.
The issue is at a certain point we start excluding devices that were
previously working.
All this patch is really doing is using the checksum offset to
identify the cases that were previously UDP or TCP offloads and
letting those through with the legacy path, while any offsets that are
not those two, such as the GRE checksum will now have to be explicitly
caught by the NETIF_F_HW_CSUM case and not accepted by the other
cases.
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com> Date: 2021-01-28 20:05:39
On Thu, Jan 28, 2021 at 2:46 PM Alexander Duyck
[off-list ref] wrote:
On Thu, Jan 28, 2021 at 6:07 AM Willem de Bruijn
[off-list ref] wrote:
quoted
On Thu, Jan 28, 2021 at 4:29 AM Xin Long [off-list ref] wrote:
quoted
NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload
while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload
for HW, which includes not only for TCP/UDP csum, but also for other
protocols' csum like GRE's.
However, in skb_csum_hwoffload_help() it only checks features against
NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP
packet and the features doesn't support NETIF_F_HW_CSUM, but supports
NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW
to do csum.
This patch is to support ip generic csum processing by checking
NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM) only for TCP and UDP.
Note that we're using skb->csum_offset to check if it's a TCP/UDP
proctol, this might be fragile. However, as Alex said, for now we
only have a few L4 protocols that are requesting Tx csum offload,
we'd better fix this until a new protocol comes with a same csum
offset.
v1->v2:
- not extend skb->csum_not_inet, but use skb->csum_offset to tell
if it's an UDP/TCP csum packet.
v2->v3:
- add a note in the changelog, as Willem suggested.
Suggested-by: Alexander Duyck <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/core/dev.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,return!!(features&NETIF_F_SCTP_CRC)?0:skb_crc32c_csum_help(skb);-return!!(features&NETIF_F_CSUM_MASK)?0:skb_checksum_help(skb);+if(features&NETIF_F_HW_CSUM)+return0;++if(features&(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)){
Should this check the specific feature flag against skb->protocol? I
don't know if there are actually instances that only support one of
the two flags.
The issue is at a certain point we start excluding devices that were
previously working.
All this patch is really doing is using the checksum offset to
identify the cases that were previously UDP or TCP offloads and
letting those through with the legacy path, while any offsets that are
not those two, such as the GRE checksum will now have to be explicitly
caught by the NETIF_F_HW_CSUM case and not accepted by the other
cases.
I understand. But letting through an IPv6 packet to a nic that
advertises NETIF_F_IP_CSUM, but not NETIF_F_IPV6_CSUM, is still
incorrect, right?
From: Alexander Duyck <hidden> Date: 2021-01-28 21:43:29
On Thu, Jan 28, 2021 at 12:00 PM Willem de Bruijn
[off-list ref] wrote:
On Thu, Jan 28, 2021 at 2:46 PM Alexander Duyck
[off-list ref] wrote:
quoted
On Thu, Jan 28, 2021 at 6:07 AM Willem de Bruijn
[off-list ref] wrote:
quoted
On Thu, Jan 28, 2021 at 4:29 AM Xin Long [off-list ref] wrote:
quoted
NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload
while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload
for HW, which includes not only for TCP/UDP csum, but also for other
protocols' csum like GRE's.
However, in skb_csum_hwoffload_help() it only checks features against
NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP
packet and the features doesn't support NETIF_F_HW_CSUM, but supports
NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW
to do csum.
This patch is to support ip generic csum processing by checking
NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM) only for TCP and UDP.
Note that we're using skb->csum_offset to check if it's a TCP/UDP
proctol, this might be fragile. However, as Alex said, for now we
only have a few L4 protocols that are requesting Tx csum offload,
we'd better fix this until a new protocol comes with a same csum
offset.
v1->v2:
- not extend skb->csum_not_inet, but use skb->csum_offset to tell
if it's an UDP/TCP csum packet.
v2->v3:
- add a note in the changelog, as Willem suggested.
Suggested-by: Alexander Duyck <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/core/dev.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,return!!(features&NETIF_F_SCTP_CRC)?0:skb_crc32c_csum_help(skb);-return!!(features&NETIF_F_CSUM_MASK)?0:skb_checksum_help(skb);+if(features&NETIF_F_HW_CSUM)+return0;++if(features&(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)){
Should this check the specific feature flag against skb->protocol? I
don't know if there are actually instances that only support one of
the two flags.
The issue is at a certain point we start excluding devices that were
previously working.
All this patch is really doing is using the checksum offset to
identify the cases that were previously UDP or TCP offloads and
letting those through with the legacy path, while any offsets that are
not those two, such as the GRE checksum will now have to be explicitly
caught by the NETIF_F_HW_CSUM case and not accepted by the other
cases.
I understand. But letting through an IPv6 packet to a nic that
advertises NETIF_F_IP_CSUM, but not NETIF_F_IPV6_CSUM, is still
incorrect, right?
That all depends. The problem is if we are going to look at protocol
we essentially have to work our way through a number of fields and
sort out if there are tunnels or not and if so what the protocol for
the inner headers are and if that is supported. It might make more
sense in that case to look at incorporating a v4/v6 specific check
into netif_skb_features so we could mask off the bit there.
The question i would have is how has this code been working up until
now without that check? If we are broken outright and need to add it
then maybe this should be deemed more of a fix and pushed for net with
the added protocol bit masking added.
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com> Date: 2021-01-28 22:07:04
On Thu, Jan 28, 2021 at 4:42 PM Alexander Duyck
[off-list ref] wrote:
On Thu, Jan 28, 2021 at 12:00 PM Willem de Bruijn
[off-list ref] wrote:
quoted
On Thu, Jan 28, 2021 at 2:46 PM Alexander Duyck
[off-list ref] wrote:
quoted
On Thu, Jan 28, 2021 at 6:07 AM Willem de Bruijn
[off-list ref] wrote:
quoted
On Thu, Jan 28, 2021 at 4:29 AM Xin Long [off-list ref] wrote:
quoted
NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload
while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload
for HW, which includes not only for TCP/UDP csum, but also for other
protocols' csum like GRE's.
However, in skb_csum_hwoffload_help() it only checks features against
NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP
packet and the features doesn't support NETIF_F_HW_CSUM, but supports
NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW
to do csum.
This patch is to support ip generic csum processing by checking
NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM |
NETIF_F_IPV6_CSUM) only for TCP and UDP.
Note that we're using skb->csum_offset to check if it's a TCP/UDP
proctol, this might be fragile. However, as Alex said, for now we
only have a few L4 protocols that are requesting Tx csum offload,
we'd better fix this until a new protocol comes with a same csum
offset.
v1->v2:
- not extend skb->csum_not_inet, but use skb->csum_offset to tell
if it's an UDP/TCP csum packet.
v2->v3:
- add a note in the changelog, as Willem suggested.
Suggested-by: Alexander Duyck <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/core/dev.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,return!!(features&NETIF_F_SCTP_CRC)?0:skb_crc32c_csum_help(skb);-return!!(features&NETIF_F_CSUM_MASK)?0:skb_checksum_help(skb);+if(features&NETIF_F_HW_CSUM)+return0;++if(features&(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)){
Should this check the specific feature flag against skb->protocol? I
don't know if there are actually instances that only support one of
the two flags.
The issue is at a certain point we start excluding devices that were
previously working.
All this patch is really doing is using the checksum offset to
identify the cases that were previously UDP or TCP offloads and
letting those through with the legacy path, while any offsets that are
not those two, such as the GRE checksum will now have to be explicitly
caught by the NETIF_F_HW_CSUM case and not accepted by the other
cases.
I understand. But letting through an IPv6 packet to a nic that
advertises NETIF_F_IP_CSUM, but not NETIF_F_IPV6_CSUM, is still
incorrect, right?
That all depends. The problem is if we are going to look at protocol
we essentially have to work our way through a number of fields and
sort out if there are tunnels or not and if so what the protocol for
the inner headers are and if that is supported. It might make more
sense in that case to look at incorporating a v4/v6 specific check
into netif_skb_features so we could mask off the bit there.
The question i would have is how has this code been working up until
now without that check? If we are broken outright and need to add it
then maybe this should be deemed more of a fix and pushed for net with
the added protocol bit masking added.
Fair enough. I agree that this patch does not make anything worse, as
it actually tightens the rules.
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
On Thu, 28 Jan 2021 17:18:30 +0800 you wrote:
This patchset it to add ip generic csum processing first in
skb_csum_hwoffload_help() in Patch 1/2 and then add csum
offload support for GRE header in Patch 2/2.
v1->v2:
- See each patch's changelog.
v2->v3:
- See the 1st patch.
[...]