RE: [PATCH 3/3] can: peak_usb: fix potential kernel log flooding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Vincent,

Oh ok I didn't know this facility. I'm pushing a new patch that includes it. Thanks for that!
FYI the frequency and number of these notifications means net_ratelimit() may not be enough in the long run.

— Stéphane


De : Vincent Mailhol <vincent.mailhol@xxxxxxxxx>
Envoyé : vendredi 16 février 2024 02:37
À : Stéphane Grosjean <s.grosjean@xxxxxxxxxxxxxxx>
Cc : linux-can Mailing List <linux-can@xxxxxxxxxxxxxxx>
Objet : Re: [PATCH 3/3] can: peak_usb: fix potential kernel log flooding

Hi Stéphane,

On Fri. 16 Feb. 2024 at 00:27, Stephane Grosjean
<s.grosjean@xxxxxxxxxxxxxxx> wrote:
> In rare cases of very high bus load, the firmware can generate messages
> warning that the receive cache capacity is about to be exceeded.
> This modification prevents the driver from flooding the kernel log with
> messages and memory dumps that are far too verbose in such cases,
> by limiting their production to once per session.
>
> Signed-off-by: Stephane Grosjean <s.grosjean@xxxxxxxxxxxxxxx>
> ---
>  drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 36 ++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> index a1c339716776..d444ff0fa7cc 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> @@ -70,6 +70,7 @@ struct pcan_usb_fd_if {
>  struct pcan_usb_fd_device {
>         struct peak_usb_device  dev;
>         struct can_berr_counter bec;
> +       bool                    rx_cache_warn_handled;
>         struct pcan_usb_fd_if   *usb_if;
>         u8                      *cmd_buffer_addr;
>  };
> @@ -667,6 +668,28 @@ static int pcan_usb_fd_decode_error(struct pcan_usb_fd_if *usb_if,
>         return 0;
>  }
>
> +/* Handle uCAN Rx cache warning messages.
> + *
> + * Such messages SHOULD NOT occur. If they do, then this might come from
> + * massive PING host flooding that prevents PCAN-USB Pro FD HW v4 to handle
> + * CAN traffic anymore. In this case, the driver itself manages the display of
> + * the warning message.
> + */
> +static void pcan_usb_fd_handle_rx_cache_warn(struct peak_usb_device *dev,
> +                                            struct pucan_msg *rx_msg)
> +{
> +       struct pcan_usb_fd_device *pdev =
> +                       container_of(dev, struct pcan_usb_fd_device, dev);
> +
> +       if (pdev->rx_cache_warn_handled)
> +               return;
> +
> +       netdev_warn(dev->netdev,
> +                   "Rx cache size warning! Possible loss of frames\n");

Did you consider using netdev_warn_once?

  https://elixir.bootlin.com/linux/v6.7/source/include/net/net_debug.h#L46

This seems to do pretty much what you want.

FYI, the net_ratelimit() may also be helpful here:

        if (net_ratelimit())
                netdev_warn(...);

> +       pdev->rx_cache_warn_handled = true;
> +}
> +
>  /* handle uCAN overrun message */
>  static int pcan_usb_fd_decode_overrun(struct pcan_usb_fd_if *usb_if,
>                                       struct pucan_msg *rx_msg)
> @@ -768,6 +791,14 @@ static int pcan_usb_fd_decode_buf(struct peak_usb_device *dev, struct urb *urb)
>                                 goto fail;
>                         break;
>
> +               case PUCAN_MSG_CACHE_CRITICAL:
> +                       pcan_usb_fd_handle_rx_cache_warn(dev, rx_msg);
> +
> +                       /* Rx cache warning means possible overrun cases in
> +                        * the device.
> +                        */
> +                       fallthrough;
> +
>                 case PCAN_UFD_MSG_OVERRUN:
>                         err = pcan_usb_fd_decode_overrun(usb_if, rx_msg);
>                         if (err < 0)
> @@ -885,6 +916,11 @@ static int pcan_usb_fd_start(struct peak_usb_device *dev)
>         pdev->bec.txerr = 0;
>         pdev->bec.rxerr = 0;
>
> +       /* warn of a cache problem only once per session, to avoid flooding
> +        * the kernel log.
> +        */
> +       pdev->rx_cache_warn_handled = false;
> +
>         return err;
>  }

--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
GL: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung finden Sie hier
www.peak-system.com/Datenschutz.483.0.html





[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux