All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: atenart@kernel.org
Cc: linux-clk@vger.kernel.org
Subject: [bug report] net: macb: convert to phylink
Date: Tue, 17 Jan 2023 16:58:12 +0300	[thread overview]
Message-ID: <Y8apdBlLDcqydGcG@kili> (raw)

Hello Antoine Tenart,

The patch 7897b071ac3b: "net: macb: convert to phylink" from Nov 13,
2019, leads to the following Smatch static checker warning:

	drivers/clk/clk.c:133 clk_prepare_lock()
	warn: sleeping in atomic context

drivers/clk/clk.c
    126 static void clk_prepare_lock(void)
    127 {
    128         if (!mutex_trylock(&prepare_lock)) {
    129                 if (prepare_owner == current) {
    130                         prepare_refcnt++;
    131                         return;
    132                 }
--> 133                 mutex_lock(&prepare_lock);
    134         }
    135         WARN_ON_ONCE(prepare_owner != NULL);
    136         WARN_ON_ONCE(prepare_refcnt != 0);
    137         prepare_owner = current;
    138         prepare_refcnt = 1;
    139 }

The problem is that cadence/macb_main calls clk_set_rate() while holding
a spinlock.

The call tree is:

owl_uart_set_termios() <- disables preempt
-> owl_uart_change_baudrate()
rda_uart_set_termios() <- disables preempt
-> rda_uart_change_baudrate()
atmel_set_termios() <- disables preempt
macb_mac_link_up() <- disables preempt  (THIS ONE)
-> macb_set_tx_clk()
   -> clk_set_rate()
      -> clk_prepare_lock()

drivers/net/ethernet/cadence/macb_main.c
   666  static void macb_mac_link_up(struct phylink_config *config,
   667                               struct phy_device *phy,
   668                               unsigned int mode, phy_interface_t interface,
   669                               int speed, int duplex,
   670                               bool tx_pause, bool rx_pause)
   671  {
   672          struct net_device *ndev = to_net_dev(config->dev);
   673          struct macb *bp = netdev_priv(ndev);
   674          struct macb_queue *queue;
   675          unsigned long flags;
   676          unsigned int q;
   677          u32 ctrl;
   678  
   679          spin_lock_irqsave(&bp->lock, flags);
                ^^^^^^^^^^^^^^^^^
Spin lock.

   680  
   681          ctrl = macb_or_gem_readl(bp, NCFGR);
   682  
   683          ctrl &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
   684  
   685          if (speed == SPEED_100)
   686                  ctrl |= MACB_BIT(SPD);
   687  
   688          if (duplex)
   689                  ctrl |= MACB_BIT(FD);
   690  
   691          if (!(bp->caps & MACB_CAPS_MACB_IS_EMAC)) {
   692                  ctrl &= ~MACB_BIT(PAE);
   693                  if (macb_is_gem(bp)) {
   694                          ctrl &= ~GEM_BIT(GBE);
   695  
   696                          if (speed == SPEED_1000)
   697                                  ctrl |= GEM_BIT(GBE);
   698                  }
   699  
   700                  if (rx_pause)
   701                          ctrl |= MACB_BIT(PAE);
   702  
   703                  macb_set_tx_clk(bp, speed);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Takes a mutex.

   704  
   705                  /* Initialize rings & buffers as clearing MACB_BIT(TE) in link down
   706                   * cleared the pipeline and control registers.
   707                   */
   708                  bp->macbgem_ops.mog_init_rings(bp);
   709                  macb_init_buffers(bp);

regards,
dan carpenter

             reply	other threads:[~2023-01-17 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 13:58 Dan Carpenter [this message]
2023-01-17 15:31 ` [bug report] net: macb: convert to phylink Antoine Tenart
2023-01-18  8:36   ` Dan Carpenter

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=Y8apdBlLDcqydGcG@kili \
    --to=error27@gmail.com \
    --cc=atenart@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.