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

From: Jason Wang
Date: Wed Apr 10 2024 - 00:00:54 EST


On Wed, Apr 10, 2024 at 10:23 AM Lei Chen <lei.chen@xxxxxxxxxx> wrote:
>
> On Tue, Apr 9, 2024 at 8:52 PM Andrew Lunn <andrew@xxxxxxx> wrote:
> >
> > 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?
>
> Thanks for your suggestion, net_ratelimit is a better way to make it.

+1

Thanks

>
> >
> > 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?
>
> I got it, I'll remake the patch, thanks.
>