Article View: linux.kernel.netdev
Article #5785Re: [PATCH net v3 5/8] net: resolve uncommon partial checksums at ingress
From: Willem de Bruijn
Date: Wed, 21 Oct 2026 00:05
Date: Wed, 21 Oct 2026 00:05
154 lines
17167 bytes
17167 bytes
Michael S. Tsirkin wrote:
> On Tue, Oct 20, 2026 at 03:44:35PM -0400, Willem de Bruijn wrote:
> > > +/* Walk the L3 header at @nhoff: where does its transport header
> > > + * start, and which protocol is it? Returns false if the header
> > > + * is truncated, malformed or fragmented.
> > > + */
> > > +static inline bool
> > > +virtio_net_l4_start(struct sk_buff *skb, unsigned int nhoff, __be16 proto,
> > > + unsigned int *thoff, int *ip_proto)
> > > +{
> > > + if (proto == htons(ETH_P_IP)) {
> > > + const struct iphdr *iph = virtio_net_ip4_parse(skb, nhoff, thoff);
> > > +
> > > + if (!iph || ip_is_fragment(iph))
> > > + return false;
> > > + *ip_proto = iph->protocol;
> > > + return true;
> > > + }
> > > +
> > > + if (proto == htons(ETH_P_IPV6)) {
> > > + const struct ipv6hdr *iph;
> > > + int flags = 0;
> > > +
> > > + if (!pskb_may_pull(skb, nhoff + sizeof(*iph)))
> > > + return false;
> > > + iph = (const void *)(skb->data + nhoff);
> > > + if (iph->version != 6)
> > > + return false;
> > > + *thoff = nhoff + sizeof(*iph);
> > > + *ip_proto = iph->nexthdr;
> > > + if (*ip_proto != IPPROTO_TCP && *ip_proto != IPPROTO_UDP) {
> > > + *thoff = nhoff;
> > > + *ip_proto = ipv6_find_hdr(skb, thoff, -1, NULL,
> > > + &flags);
> > > + if (*ip_proto < 0 || flags & IP6_FH_F_FRAG)
> > > + return false;
> > > + }
> > > + return true;
> > > + }
> > > +
> > > + return false;
> > > +}
> >
> > for all this parsing: could we use flow dissection, like the
> > !VIRTIO_NET_HDR_F_NEEDS_CSUM case?
>
> Hmm I don't see how. That one trusts the caller's protocol and network
> header. We could parse L2 ourselves and use the dissector for L3+. But
> it stops at whatever it does not know, and every miss would turn into a
> drop or a software checksum for a packet the stack delivers fine. Our
> parser deliberately covers everything the stack can deliver.
You're right, the protocol and network offset need to be parsed
manually. After that it could be passed to the flow dissector.
Totally untested:
static inline bool virtio_net_setup_l3_input(struct sk_buff *skb, int *nhoff, __be16 *proto)
{
const struct net_device *dev = skb->dev;
/* Devices with Ethernet framing: ARPHRD_ETHER, loopback, macvlan, etc. */
if (dev->header_ops == ð_header_ops || dev->type == ARPHRD_ETHER) {
if (!pskb_may_pull(skb, ETH_HLEN))
return false;
*nhoff = ETH_HLEN;
*proto = eth_hdr(skb)->h_proto;
} else if (dev->type == ARPHRD_NONE) {
/* Raw L3 devices (e.g. tun in IFF_TUN mode) */
*nhoff = 0;
*proto = skb->protocol;
if (!*proto) {
if (!pskb_may_pull(skb, 1))
return false;
if ((skb->data[0] >> 4) == 4)
*proto = htons(ETH_P_IP);
else if ((skb->data[0] >> 4) == 6)
*proto = htons(ETH_P_IPV6);
else
return false;
}
} else {
/* Fallback for other netdevs using caller's network header */
*nhoff = skb_network_offset(skb);
if (*nhoff < 0 || (unsigned int)*nhoff >= skb->len)
return false;
*proto = skb->protocol;
}
return true;
}
static inline bool virtio_net_csum_partial_ok(struct sk_buff *skb, u8 hdr_gso_type)
{
struct flow_keys_basic keys;
__be16 orig_proto = skb->protocol;
u16 orig_net_hdr = skb->network_header;
__be16 proto;
int nhoff;
u16 csum_offset;
size_t min_thlen;
if (!virtio_net_setup_l3_input(skb, &nhoff, &proto))
return false;
skb_set_network_header(skb, nhoff);
skb->protocol = proto;
if (!skb_flow_dissect_flow_keys_basic(dev_net(skb->dev), skb, &keys,
NULL, 0, 0, 0, 0))
goto restore_fail;
/* Disallow fragments: partial checksums cannot be retained across frags */
if (keys.control.flags & FLOW_DIS_IS_FRAGMENT)
goto restore_fail;
/* Validate protocol matching */
switch (keys.basic.ip_proto) {
case IPPROTO_TCP:
if (!virtio_net_hdr_match_proto(keys.basic.n_proto, hdr_gso_type))
goto restore_fail;
min_thlen = sizeof(struct tcphdr);
csum_offset = offsetof(struct tcphdr, check);
break;
case IPPROTO_UDP:
if (!virtio_net_hdr_match_proto(keys.basic.n_proto, hdr_gso_type))
goto restore_fail;
min_thlen = sizeof(struct udphdr);
csum_offset = offsetof(struct udphdr, check);
break;
default:
goto restore_fail;
}
/* csum_start must match the dissected transport header offset */
if (skb_transport_offset(skb) != keys.control.thoff)
goto restore_fail;
/* csum_offset must point to the transport checksum field */
if (skb->csum_offset != csum_offset)
goto restore_fail;
/* Ensure the transport header is linear */
if (!pskb_may_pull(skb, keys.control.thoff + min_thlen))
goto restore_fail;
return true;
restore_fail:
skb->protocol = orig_proto;
skb->network_header = orig_net_hdr;
return false;
}
Technical Details
Message-ID:
<willemdebruijn.kernel.1da723f98c23a@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349654-linux-kernel-netdev=dewy.ruReferences:
<cover.1792411304.git.mst@redhat.com> <9c08d12b3a7819ae03ded6a154e4f908276e93d4.1792411304.git.mst@redhat.com> <willemdebruijn.kernel.2eb449439b094@gmail.com> <20261020170908-mutt-send-email-mst@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349654-linux-kernel-netdev=dewy.ru
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 5/8] net: resolve uncommon partial checksums at
ingress
Date: Tue, 20 Oct 2026 20:05:29 -0400
Organization: Usenet Network
Message-ID: <willemdebruijn.kernel.1da723f98c23a@gmail.com>
References: <cover.1792411304.git.mst@redhat.com>
<9c08d12b3a7819ae03ded6a154e4f908276e93d4.1792411304.git.mst@redhat.com>
<willemdebruijn.kernel.2eb449439b094@gmail.com>
<20261020170908-mutt-send-email-mst@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="3999088"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:kTBVyAwqDecxtluOwQPRC/LC8EU= sha256:+75wZ65rRwFVLqwyKPB/BPKZAVNB7qEalc4sg6jW//Q=
sha1:ft35aRQsgyb3S2MIRrEWnkLbrSw= sha256:FR16jMWxe3J7aS49iOWDcQc8y0sE0lIwQZOO2XLLhIo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 13D91110EA7; Wed, 21 Oct 2026 03:07:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id kXY86gDHfLUi;
Wed, 21 Oct 2026 03:07:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-349654-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id EA883110E87; Wed, 21 Oct 2026 03:07:27 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 74FF137A8C; Wed, 21 Oct 2026 00:05:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792541133;
b=lyYs/yePWZGjE9LqS3GuxoG1HmjppL4PhuA5Gex0oydvbt22F6MHryacr5jadu3jnR4q
JWtpfSmuO02NjbyVvONIz1mZB76uzgu3+mYMgk9QLIvzDJ3a/LzgoMuEi0lRqfx3b4aCf
nZIJEYqjV8jA9yz/i69W7DotcOGhM5bNKEOg59cayzpMFFX289dtp+yI+c9f+72tQj6/4
dCTlZtib5P67ol8em3lkfOZ1sxtND27+bdAR2x9o2Q2dlboqA1gX607KRXck5GviHK224
6sbjoEu/YVvqb69yDdztoM8Xxo0nKHjH3kOJzCeFtBuUFSMr5KvQ0pD54HAcU1dq9bw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792541133;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:Date:From:To:Cc:Message-ID:In-Reply-To:
References:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Type:Content-Transfer-Encoding;
bh=9KmVjMJTY8zcLg9QfQKrHKxwneViwt4HwZ1IqLmXRp8=;
b=Y0gzhLZYwXI2FDEApVrMIfiUEsqHImcbLkIksD7tWXICFRpRx1hKpd2GCWvBaoqlGA5p
mOl0c19Q3Tht8DJRCSHgJ4i8x1dR7VjxYRDs34cJwDiCeYg+uhC7ZrMMnFfh9fw2VA9df
tXFshw7zXm8kCy4/laAHeON6bL7i8AB8LJcLUN1iyEydscb5cYhrA6hcrX81Wqn1r8qdg
WPP9+fy/NMj0pH72YFWNffHYRVp4/oriiR+Ia/Kyj2QTD2/vK+CHXo6PiKmJQTGkuvydV
28Sm/2IXue5SYVw0IAO9mS+sgL6jEVQgJcDKJqLllFZ5kIuZuSsyA9e9tR1heeyxNkg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oheBebjs;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id E9CCC606A325;
Wed, 21 Oct 2026 00:05:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oheBebjs
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.182
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792541132;
b=xY+4bFHmKEREB3n9ow9ix/7JozFXliq3U6eYMYcH9ZKFiDj7LmgH4U4zykafFpcwn4LU
bbLZ9AKu+hwiDykO1aK8+ImYYUKVCsB2x2a/iYdAIHe8U7CqhgfZr/xijdMGcy9+TrDBi
FIatOXDEqaiONDq8+osxMGZDP0l/LdcIoBYmcOdsOriLSscMOY6szjMF/WTjq8cg8MF37
8CbQ5f/JckCy/Ef6DUpzR2MlT6qsF3vV6BXVNkqMGILlntKjcw4yLJ4+PF6UQqqMmk8uS
ToyYtatFbVdMCq7MzncEjkNuS4ohONH+af8f6SRP4+/32e9FJo/2IwQQQq5VEr6iTKw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792541132;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:
MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=9KmVjMJTY8zcLg9QfQKrHKxwneViwt4HwZ1IqLmXRp8=;
b=u3a4Cc5qM5nXJfYOjKohmwqYYy76XrYFQzkhAtipTkeBjlb8j7gVJRoqkJd4FYaVDyrI
0LPKUKVIaguko7lk5HvGscaN0jWaPjHd1myAfSNrfCrfb0dTTTeuH6MB+suHlpXZEv03M
vMtVPcPfkJU3ZTXgnQZfhzH+jLp+BLMIS0s3X+Fm0RqYGSkA8lAAZYdi3iYjmGR78VQzh
m6gbu2cSOJzxbtDAFIWTEbrT/qvQuiPyN2TEpO0t7lyR9gXx39w/uw+X7JziTUALD5Xkp
SyrIpP+qTlSJZ4oP8LBD1Zer+lH+HF6Fjrwk7yFWjzvopM4bQ2uptGjWV+uRFPUa3XQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oheBebjs;
arc=none smtp.remote-ip=209.85.221.182
X-Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5832606A320
for <netdev@vger.kernel.org>; Wed, 21 Oct 2026 00:05:31 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5832606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-vk1-f182.google.com with SMTP id 71dfb90a1353d-5e931215e5fso77901e0c.3
for <netdev@vger.kernel.org>; Tue, 20 Oct 2026 17:05:31 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792541131; x=1793145931; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:subject
:references:in-reply-to:message-id:cc:to:from:date:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=9KmVjMJTY8zcLg9QfQKrHKxwneViwt4HwZ1IqLmXRp8=;
b=oheBebjsamFrOmbLheQaS9kwhGj2/5c8GFJHxr1Jfk8Ef0D34wwjyBvsEuKf35hI0e
ztFETiGiNiTqwzVtvgcutrbe8xxY0xHvKLB2UNa5RoZIS0HWDfL6Dvty6FSovI5n6Xku
/KfXaRvgxwuzIdR4tzYn/Bt8iOegGcUfGHNA0QmVwZBoJ304o/WuLdOjczSNAyjAhMV2
wgaMP6IwezPX6lF2zR8kRvmI/0gArW9734zefhGoFIFVpLLtAltqkztEsqTKHt3s1XjX
y7WuFnIyWIxtggIiJJe9ZwlTYEbqoZqWc9D7k6qqNmoBMTNJr7xWng2tkaPsVfD9eRFN
kEsQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792541131; x=1793145931;
h=content-transfer-encoding:content-type:mime-version:subject
:references:in-reply-to:message-id:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=9KmVjMJTY8zcLg9QfQKrHKxwneViwt4HwZ1IqLmXRp8=;
b=ln/FULIktwOGSlE62xWOAkgvfdDp2tVUE1kUOThUv0n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I9QZ8zLlzBgs
hoosDtgoCN4xrsuzwAxxwP0xfn6jmSGUMDoqmGAgWzn5ty6aFkVErlMMLwVHpryylSF/1dVH+8X
xaKG6GJvaRKf2pOcGmfxhArulFDCtSkOZGXipw==
X-Received: by 2002:a05:6122:1d9f:b0:5e6:82ca:c551 with SMTP id 71dfb90a1353d-5eaebef16acmr141977e0c.22.1792541130631;
Tue, 20 Oct 2026 17:05:30 -0700 (PDT)
X-Received: from gmail.com (111.46.245.35.bc.googleusercontent.com. [35.245.46.111])
by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5eae981d239sm1228104e0c.14.2026.10.20.17.05.29
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 20 Oct 2026 17:05:29 -0700 (PDT)
X-Cc: linux-kernel@vger.kernel.org,
Chris Arges <carges@cloudflare.com>,
Björn Töpel <bjorn@kernel.org>,
Phil Sutter <phil@nwl.cc>,
Jason Wang <jasowangio@gmail.com>,
Eugenio Pérez <eperezma@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org,
virtualization@lists.linux.dev,
Max Krasnyansky <maxk@qualcomm.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Paulos Yibelo <habte.yibelo@gmail.com>
X-In-Reply-To: <20261020170908-mutt-send-email-mst@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list