public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	Christopher S M Hall <christopher.s.hall@intel.com>
Cc: <intel-wired-lan@lists.osuosl.org>, <netdev@vger.kernel.org>
Subject: Re: [Intel-wired-lan] [bug report] igc: add lock preventing multiple simultaneous PTM transactions
Date: Wed, 16 Apr 2025 10:38:33 -0700	[thread overview]
Message-ID: <f9b72ac4-7640-4bae-8878-839b7b2daac8@intel.com> (raw)
In-Reply-To: <Z_-P-Hc1yxcw0lTB@stanley.mountain>



On 4/16/2025 4:09 AM, Dan Carpenter wrote:
> Hello Christopher S M Hall,
> 
> Commit 1a931c4f5e68 ("igc: add lock preventing multiple simultaneous
> PTM transactions") from Apr 1, 2025 (linux-next), leads to the
> following Smatch static checker warning:
> 
> 	drivers/net/ethernet/intel/igc/igc_ptp.c:1311 igc_ptp_reset()
> 	warn: sleeping in atomic context
> 
> drivers/net/ethernet/intel/igc/igc_ptp.c
>     1280 void igc_ptp_reset(struct igc_adapter *adapter)
>     1281 {
>     1282         struct igc_hw *hw = &adapter->hw;
>     1283         u32 cycle_ctrl, ctrl, stat;
>     1284         unsigned long flags;
>     1285         u32 timadj;
>     1286 
>     1287         if (!(adapter->ptp_flags & IGC_PTP_ENABLED))
>     1288                 return;
>     1289 
>     1290         /* reset the tstamp_config */
>     1291         igc_ptp_set_timestamp_mode(adapter, &adapter->tstamp_config);
>     1292 
>     1293         spin_lock_irqsave(&adapter->tmreg_lock, flags);
>                  ^^^^^^^^^^^^^^^^^
> Holding a spin_lock
> 
>     1294 
>     1295         switch (adapter->hw.mac.type) {
>     1296         case igc_i225:
>     1297                 timadj = rd32(IGC_TIMADJ);
>     1298                 timadj |= IGC_TIMADJ_ADJUST_METH;
>     1299                 wr32(IGC_TIMADJ, timadj);
>     1300 
>     1301                 wr32(IGC_TSAUXC, 0x0);
>     1302                 wr32(IGC_TSSDP, 0x0);
>     1303                 wr32(IGC_TSIM,
>     1304                      IGC_TSICR_INTERRUPTS |
>     1305                      (adapter->pps_sys_wrap_on ? IGC_TSICR_SYS_WRAP : 0));
>     1306                 wr32(IGC_IMS, IGC_IMS_TS);
>     1307 
>     1308                 if (!igc_is_crosststamp_supported(adapter))
>     1309                         break;
>     1310 
> --> 1311                 mutex_lock(&adapter->ptm_lock);
>                          ^^^^^^^^^^
> So we can't take a mutex.
> 
>     1312                 wr32(IGC_PCIE_DIG_DELAY, IGC_PCIE_DIG_DELAY_DEFAULT);
>     1313                 wr32(IGC_PCIE_PHY_DELAY, IGC_PCIE_PHY_DELAY_DEFAULT);
>     1314 
>     1315                 cycle_ctrl = IGC_PTM_CYCLE_CTRL_CYC_TIME(IGC_PTM_CYC_TIME_DEFAULT);
>     1316 
>     1317                 wr32(IGC_PTM_CYCLE_CTRL, cycle_ctrl);
>     1318 
>     1319                 ctrl = IGC_PTM_CTRL_EN |
>     1320                         IGC_PTM_CTRL_START_NOW |
>     1321                         IGC_PTM_CTRL_SHRT_CYC(IGC_PTM_SHORT_CYC_DEFAULT) |
>     1322                         IGC_PTM_CTRL_PTM_TO(IGC_PTM_TIMEOUT_DEFAULT);
>     1323 
>     1324                 wr32(IGC_PTM_CTRL, ctrl);
>     1325 
>     1326                 /* Force the first cycle to run. */
>     1327                 igc_ptm_trigger(hw);
>     1328 
>     1329                 if (readx_poll_timeout_atomic(rd32, IGC_PTM_STAT, stat,
>     1330                                               stat, IGC_PTM_STAT_SLEEP,
>     1331                                               IGC_PTM_STAT_TIMEOUT))
>     1332                         netdev_err(adapter->netdev, "Timeout reading IGC_PTM_STAT register\n");
>     1333 
>     1334                 igc_ptm_reset(hw);
>     1335                 mutex_unlock(&adapter->ptm_lock);
>     1336                 break;


I'm not sure why this was a mutex to begin with. We already use
readx_poll_timeout_atomic which doesn't sleep, so I think this ptm_lock
could just be converted to a spin_lock to fix this.

      reply	other threads:[~2025-04-16 17:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-16 11:09 [bug report] igc: add lock preventing multiple simultaneous PTM transactions Dan Carpenter
2025-04-16 17:38 ` Jacob Keller [this message]

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=f9b72ac4-7640-4bae-8878-839b7b2daac8@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=christopher.s.hall@intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=netdev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox