From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux.dev, "Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net v4 1/7] net: account for ingress-resolved virtio net hdr state
Date: Thu, 22 Oct 2026 07:50:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-181137@kernel.org> (raw)
In-Reply-To: <be251d104f881a309cfef150455efa128ebb101d.1792565282.git.mst@redhat.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] virtio_net: duplicate rx_ prefix for rx_csum_sw in virtnet_rq_stats_desc
- [Medium] net: live ethtool_ops overwritten in ipvtap_newlink() and macvtap_newlink()
--
commit aec871fb755137e08ae8b9205b5e122143828b6d
Author: Michael S. Tsirkin <mst@redhat.com>
net: account for ingress-resolved virtio net hdr state
This commit updates callers of virtio_net_hdr_to_skb() and
virtio_net_hdr_tnl_to_skb() to check only for negative return values as
errors, and adds an rx_csum_sw ethtool statistic to tun, tap (ipvtap and
macvtap), and virtio_net to count packets requiring software checksum
resolution at ingress.
> diff --git a/drivers/net/ipvlan/ipvtap.c b/drivers/net/ipvlan/ipvtap.c
> index 66c949d942610..9e2f1c7073d2a 100644
> --- a/drivers/net/ipvlan/ipvtap.c
> +++ b/drivers/net/ipvlan/ipvtap.c
[ ... ]
> +/* checkpatch warns but this can't be const: cloned from ipvlan's
> + * ops at newlink time, with the statistics above added.
> + */
> +static struct ethtool_ops ipvtap_ethtool_ops;
> +
> static int ipvtap_newlink(struct net_device *dev,
> struct rtnl_newlink_params *params,
> struct netlink_ext_ack *extack)
> @@ -91,6 +118,15 @@ static int ipvtap_newlink(struct net_device *dev,
> vlantap->tap.update_features = ipvtap_update_features;
> vlantap->tap.count_rx_dropped = ipvtap_count_rx_dropped;
>
> + /* ipvlan's ethtool ops are already installed at this point;
> + * clone them and add the tap statistics on top.
> + */
> + ipvtap_ethtool_ops = *dev->ethtool_ops;
> + ipvtap_ethtool_ops.get_sset_count = ipvtap_get_sset_count;
> + ipvtap_ethtool_ops.get_strings = ipvtap_get_strings;
> + ipvtap_ethtool_ops.get_ethtool_stats = ipvtap_get_ethtool_stats;
> + dev->ethtool_ops = &ipvtap_ethtool_ops;
[ ... ]
> diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
> index cc975dfb73805..3288cc6ae6c20 100644
> --- a/drivers/net/macvtap.c
> +++ b/drivers/net/macvtap.c
[ ... ]
> +/* checkpatch warns but this can't be const: cloned from macvlan's
> + * ops at newlink time, with the statistics above added.
> + */
> +static struct ethtool_ops macvtap_ethtool_ops;
> +
> static int macvtap_newlink(struct net_device *dev,
> struct rtnl_newlink_params *params,
> struct netlink_ext_ack *extack)
> @@ -99,6 +126,15 @@ static int macvtap_newlink(struct net_device *dev,
> vlantap->tap.count_rx_dropped = macvtap_count_rx_dropped;
> vlantap->tap.update_features = macvtap_update_features;
>
> + /* macvlan's ethtool ops are already installed at this point;
> + * clone them and add the tap statistics on top.
> + */
> + macvtap_ethtool_ops = *dev->ethtool_ops;
> + macvtap_ethtool_ops.get_sset_count = macvtap_get_sset_count;
> + macvtap_ethtool_ops.get_strings = macvtap_get_strings;
> + macvtap_ethtool_ops.get_ethtool_stats = macvtap_get_ethtool_stats;
> + dev->ethtool_ops = &macvtap_ethtool_ops;
[Severity: Medium]
Can overwriting the shared global ipvtap_ethtool_ops in
drivers/net/ipvlan/ipvtap.c:ipvtap_newlink() and macvtap_ethtool_ops in
drivers/net/macvtap.c:macvtap_newlink() race with concurrent readers on
already-registered devices?
When the first ipvtap or macvtap interface is created and registered, its
dev->ethtool_ops points to the shared static ipvtap_ethtool_ops or
macvtap_ethtool_ops structure.
When a second ipvtap or macvtap interface is created via
rtnl_newlink_create(), ipvtap_setup() or macvtap_setup() first sets the new
device's dev->ethtool_ops to &ipvlan_ethtool_ops or &macvlan_ethtool_ops
(where get_sset_count, get_strings, and get_ethtool_stats are null). Then
ipvtap_newlink() or macvtap_newlink() copies *dev->ethtool_ops over the
shared global ipvtap_ethtool_ops or macvtap_ethtool_ops structure in-place
before restoring the three statistics callbacks.
Meanwhile, several paths read dev->ethtool_ops on the first registered
interface without holding rtnl_lock():
net/ethtool/common.c:__ethtool_get_ts_info() {
...
const struct ethtool_ops *ops = dev->ethtool_ops;
struct phy_device *phydev = dev->phydev;
...
} else if (ops->get_ts_info) {
err = ops->get_ts_info(dev, info);
...
}
which is called under rcu_read_lock() from
sock_timestamping_bind_phc()->ethtool_get_phc_vclocks(), as well as
net/ethtool/netlink.c:ethnl_default_set_doit() calling ops->set_validate()
before acquiring rtnl_lock(), and net/core/net-sysfs.c:speed_show() and
duplex_show() reading netdev->ethtool_ops->get_link_ksettings before
sysfs_rtnl_lock().
Could ipvtap_ethtool_ops and macvtap_ethtool_ops be initialized once at
module init time (for example in ipvtap_init() and macvtap_init()) instead
of being mutated on each newlink call?
[ ... ]
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index daab43ac92ce4..b0441bf8e8750 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -125,6 +125,7 @@ struct virtnet_rq_stats {
> u64_stats_t packets;
> u64_stats_t bytes;
> u64_stats_t drops;
> + u64_stats_t rx_csum_sw;
> u64_stats_t xdp_packets;
> u64_stats_t xdp_tx;
> u64_stats_t xdp_redirects;
> @@ -158,6 +159,7 @@ static const struct virtnet_stat_desc virtnet_sq_stats_desc[] = {
>
> static const struct virtnet_stat_desc virtnet_rq_stats_desc[] = {
> VIRTNET_RQ_STAT("drops", drops),
> + VIRTNET_RQ_STAT("rx_csum_sw", rx_csum_sw),
> VIRTNET_RQ_STAT("xdp_packets", xdp_packets),
> VIRTNET_RQ_STAT("xdp_tx", xdp_tx),
> VIRTNET_RQ_STAT("xdp_redirects", xdp_redirects),
[Severity: Medium]
Will defining the descriptor string as "rx_csum_sw" in
drivers/net/virtio_net.c:virtnet_rq_stats_desc cause ethtool -S to report a
duplicated "rx_" prefix?
When userspace queries ethtool -S strings via
virtnet_get_strings()->virtnet_get_stats_string()->virtnet_stats_sprintf(),
virtnet_get_stats_string() automatically prepends "rx_" and "rx%u_" to every
entry in virtnet_rq_stats_desc:
drivers/net/virtio_net.c:virtnet_get_stats_string() {
...
if (type == VIRTNET_Q_TYPE_RX) {
fmt = "rx%u_%s";
noq_fmt = "rx_%s";
desc = &virtnet_rq_stats_desc[0];
num = ARRAY_SIZE(virtnet_rq_stats_desc);
virtnet_stats_sprintf(&p, fmt, noq_fmt, num, qid, desc);
...
}
Because of this formatting, "rx_csum_sw" becomes "rx_rx_csum_sw" for the
device total and "rx0_rx_csum_sw" for the per-queue counters. Should the
descriptor string in virtnet_rq_stats_desc be "csum_sw" to match the other
entries and produce "rx_csum_sw"?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.v4.git.mst@redhat.com?part=1
next prev parent reply other threads:[~2026-10-22 7:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 7:50 [PATCH net v4 0/7] more virtio-net csum hardening Michael S. Tsirkin
2026-10-21 7:49 ` [PATCH net v4 1/7] net: account for ingress-resolved virtio net hdr state Michael S. Tsirkin
2026-10-21 7:49 ` [PATCH net v4 2/7] um: vector: trim skbs before verifying the header Michael S. Tsirkin
2026-10-21 16:08 ` Willem de Bruijn
2026-10-22 7:50 ` sashiko-bot
2026-10-21 7:49 ` [PATCH net v4 3/7] virtio_net: parse tunnel csum_start little-endian Michael S. Tsirkin
2026-10-22 7:50 ` sashiko-bot
2026-10-21 7:50 ` [PATCH net v4 4/7] net: resolve uncommon partial checksums at ingress Michael S. Tsirkin
2026-10-21 16:13 ` Willem de Bruijn
2026-10-22 7:50 ` sashiko-bot
2026-10-21 7:50 ` [PATCH net v4 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin
2026-10-21 16:14 ` Willem de Bruijn
2026-10-22 7:50 ` sashiko-bot
2026-10-21 7:50 ` [PATCH net v4 6/7] net: add ip4_parse() Michael S. Tsirkin
2026-10-21 16:18 ` Willem de Bruijn
2026-10-22 7:50 ` sashiko-bot
2026-10-21 7:50 ` [PATCH net v4 7/7] virtio_net: cleanup protocol calculation Michael S. Tsirkin
2026-10-22 7:50 ` sashiko-bot
2026-10-21 16:08 ` [PATCH net v4 1/7] net: account for ingress-resolved virtio net hdr state Willem de Bruijn
2026-10-21 16:28 ` Michael S. Tsirkin
2026-10-22 7:50 ` sashiko-bot [this message]
2026-10-21 18:49 ` [PATCH net v4 0/7] more virtio-net csum hardening Chris Arges
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-181137@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox