Re: [PATCH] net:tun: limit printing rate when illegal packet received by tun dev

From: Andrew Lunn
Date: Tue Apr 09 2024 - 08:52:30 EST


On Tue, Apr 09, 2024 at 02:24:05AM -0400, Lei Chen wrote:
> vhost_worker will call tun call backs to receive packets. If too many
> illegal packets arrives, tun_do_read will keep dumping packet contents.
> When console is enabled, it will costs much more cpu time to dump
> packet and soft lockup will be detected.
>
> Rate limit mechanism can be used to limit the dumping rate.
> @@ -2125,14 +2126,16 @@ static ssize_t tun_put_user(struct tun_struct *tun,
> tun_is_little_endian(tun), true,
> vlan_hlen)) {
> struct skb_shared_info *sinfo = skb_shinfo(skb);
> - pr_err("unexpected GSO type: "
> - "0x%x, gso_size %d, hdr_len %d\n",
> - sinfo->gso_type, tun16_to_cpu(tun, gso.gso_size),
> - tun16_to_cpu(tun, gso.hdr_len));
> - print_hex_dump(KERN_ERR, "tun: ",
> - DUMP_PREFIX_NONE,
> - 16, 1, skb->head,
> - min((int)tun16_to_cpu(tun, gso.hdr_len), 64), true);
> +
> + if (__ratelimit(&ratelimit)) {

Maybe just use net_ratelimit() rather than add a new ratelimit
variable?

A separate issue, i wounder if rather than pr_err(),
netdev_err(tun->dev, ...) should be used to indicate which TUN device
has been given bad GSO packets?

Andrew