All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Dan Carpenter <error27@gmail.com>
Subject: drivers/hwspinlock/hwspinlock_core.c:139 __hwspin_trylock() warn: mixing irq and irqsave
Date: Thu, 09 Jul 2026 17:59:51 +0800	[thread overview]
Message-ID: <202607091718.s8YXDPzQ-lkp@intel.com> (raw)

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: linux-kernel@vger.kernel.org
TO: Marco Elver <elver@google.com>
CC: Peter Zijlstra <peterz@infradead.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   0e35b9b6ec0ffcc5e23cbdec09f5c622ad532b53
commit: e4588c25c9d122b5847b88e18b184404b6959160 compiler-context-analysis: Remove __cond_lock() function-like helper
date:   6 months ago
:::::: branch date: 2 days ago
:::::: commit date: 6 months ago
config: nios2-randconfig-r071-20260709 (https://download.01.org/0day-ci/archive/20260709/202607091718.s8YXDPzQ-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 10.5.0
smatch: v0.5.0-9185-gbcc58b9c

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Fixes: e4588c25c9d1 ("compiler-context-analysis: Remove __cond_lock() function-like helper")
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202607091718.s8YXDPzQ-lkp@intel.com/

New smatch warnings:
drivers/hwspinlock/hwspinlock_core.c:139 __hwspin_trylock() warn: mixing irq and irqsave

Old smatch warnings:
drivers/hwspinlock/hwspinlock_core.c:295 __hwspin_unlock() warn: mixing irqsave and irq

vim +139 drivers/hwspinlock/hwspinlock_core.c

93b465c2e186d9 Juan Gutierrez  2011-09-06   58  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   59  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   60  /**
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   61   * __hwspin_trylock() - attempt to lock a specific hwspinlock
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   62   * @hwlock: an hwspinlock which we want to trylock
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   63   * @mode: controls whether local interrupts are disabled or not
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   64   * @flags: a pointer where the caller's interrupt state will be saved at (if
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   65   *         requested)
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   66   *
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   67   * This function attempts to lock an hwspinlock, and will immediately
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   68   * fail if the hwspinlock is already taken.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   69   *
1e6c06a7e88c25 Baolin Wang     2018-04-08   70   * Caution: If the mode is HWLOCK_RAW, that means user must protect the routine
1e6c06a7e88c25 Baolin Wang     2018-04-08   71   * of getting hardware lock with mutex or spinlock. Since in some scenarios,
1e6c06a7e88c25 Baolin Wang     2018-04-08   72   * user need some time-consuming or sleepable operations under the hardware
1e6c06a7e88c25 Baolin Wang     2018-04-08   73   * lock, they need one sleepable lock (like mutex) to protect the operations.
1e6c06a7e88c25 Baolin Wang     2018-04-08   74   *
360aa640a59f26 Fabien Dessenne 2019-03-07   75   * If the mode is neither HWLOCK_IN_ATOMIC nor HWLOCK_RAW, upon a successful
360aa640a59f26 Fabien Dessenne 2019-03-07   76   * return from this function, preemption (and possibly interrupts) is disabled,
360aa640a59f26 Fabien Dessenne 2019-03-07   77   * so the caller must not sleep, and is advised to release the hwspinlock as
360aa640a59f26 Fabien Dessenne 2019-03-07   78   * soon as possible. This is required in order to minimize remote cores polling
360aa640a59f26 Fabien Dessenne 2019-03-07   79   * on the hardware interconnect.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   80   *
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   81   * The user decides whether local interrupts are disabled or not, and if yes,
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   82   * whether he wants their previous state to be saved. It is up to the user
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   83   * to choose the appropriate @mode of operation, exactly the same way users
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   84   * should decide between spin_trylock, spin_trylock_irq and
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   85   * spin_trylock_irqsave.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   86   *
bcd0f5d18b0b11 Randy Dunlap    2023-12-05   87   * Returns: %0 if we successfully locked the hwspinlock or -EBUSY if
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   88   * the hwspinlock was already taken.
bcd0f5d18b0b11 Randy Dunlap    2023-12-05   89   *
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   90   * This function will never sleep.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   91   */
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   92  int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   93  {
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   94  	int ret;
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   95  
b2547dce4d4a23 Baolin Wang     2019-10-14   96  	if (WARN_ON(!hwlock || (!flags && mode == HWLOCK_IRQSTATE)))
b2547dce4d4a23 Baolin Wang     2019-10-14   97  		return -EINVAL;
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   98  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17   99  	/*
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  100  	 * This spin_lock{_irq, _irqsave} serves three purposes:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  101  	 *
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  102  	 * 1. Disable preemption, in order to minimize the period of time
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  103  	 *    in which the hwspinlock is taken. This is important in order
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  104  	 *    to minimize the possible polling on the hardware interconnect
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  105  	 *    by a remote user of this lock.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  106  	 * 2. Make the hwspinlock SMP-safe (so we can take it from
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  107  	 *    additional contexts on the local host).
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  108  	 * 3. Ensure that in_atomic/might_sleep checks catch potential
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  109  	 *    problems with hwspinlock usage (e.g. scheduler checks like
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  110  	 *    'scheduling while atomic' etc.)
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  111  	 */
66742b19e5e0d0 Baolin Wang     2018-04-08  112  	switch (mode) {
66742b19e5e0d0 Baolin Wang     2018-04-08  113  	case HWLOCK_IRQSTATE:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  114  		ret = spin_trylock_irqsave(&hwlock->lock, *flags);
66742b19e5e0d0 Baolin Wang     2018-04-08  115  		break;
66742b19e5e0d0 Baolin Wang     2018-04-08  116  	case HWLOCK_IRQ:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  117  		ret = spin_trylock_irq(&hwlock->lock);
66742b19e5e0d0 Baolin Wang     2018-04-08  118  		break;
1e6c06a7e88c25 Baolin Wang     2018-04-08  119  	case HWLOCK_RAW:
360aa640a59f26 Fabien Dessenne 2019-03-07  120  	case HWLOCK_IN_ATOMIC:
1e6c06a7e88c25 Baolin Wang     2018-04-08  121  		ret = 1;
1e6c06a7e88c25 Baolin Wang     2018-04-08  122  		break;
66742b19e5e0d0 Baolin Wang     2018-04-08  123  	default:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  124  		ret = spin_trylock(&hwlock->lock);
66742b19e5e0d0 Baolin Wang     2018-04-08  125  		break;
66742b19e5e0d0 Baolin Wang     2018-04-08  126  	}
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  127  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  128  	/* is lock already taken by another context on the local cpu ? */
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  129  	if (!ret)
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  130  		return -EBUSY;
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  131  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  132  	/* try to take the hwspinlock device */
300bab9770e2bd Ohad Ben-Cohen  2011-09-06  133  	ret = hwlock->bank->ops->trylock(hwlock);
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  134  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  135  	/* if hwlock is already taken, undo spin_trylock_* and exit */
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  136  	if (!ret) {
66742b19e5e0d0 Baolin Wang     2018-04-08  137  		switch (mode) {
66742b19e5e0d0 Baolin Wang     2018-04-08  138  		case HWLOCK_IRQSTATE:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17 @139  			spin_unlock_irqrestore(&hwlock->lock, *flags);
66742b19e5e0d0 Baolin Wang     2018-04-08  140  			break;
66742b19e5e0d0 Baolin Wang     2018-04-08  141  		case HWLOCK_IRQ:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  142  			spin_unlock_irq(&hwlock->lock);
66742b19e5e0d0 Baolin Wang     2018-04-08  143  			break;
1e6c06a7e88c25 Baolin Wang     2018-04-08  144  		case HWLOCK_RAW:
360aa640a59f26 Fabien Dessenne 2019-03-07  145  		case HWLOCK_IN_ATOMIC:
1e6c06a7e88c25 Baolin Wang     2018-04-08  146  			/* Nothing to do */
1e6c06a7e88c25 Baolin Wang     2018-04-08  147  			break;
66742b19e5e0d0 Baolin Wang     2018-04-08  148  		default:
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  149  			spin_unlock(&hwlock->lock);
66742b19e5e0d0 Baolin Wang     2018-04-08  150  			break;
66742b19e5e0d0 Baolin Wang     2018-04-08  151  		}
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  152  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  153  		return -EBUSY;
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  154  	}
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  155  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  156  	/*
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  157  	 * We can be sure the other core's memory operations
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  158  	 * are observable to us only _after_ we successfully take
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  159  	 * the hwspinlock, and we must make sure that subsequent memory
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  160  	 * operations (both reads and writes) will not be reordered before
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  161  	 * we actually took the hwspinlock.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  162  	 *
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  163  	 * Note: the implicit memory barrier of the spinlock above is too
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  164  	 * early, so we need this additional explicit memory barrier.
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  165  	 */
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  166  	mb();
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  167  
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  168  	return 0;
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  169  }
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  170  EXPORT_SYMBOL_GPL(__hwspin_trylock);
bd9a4c7df256ce Ohad Ben-Cohen  2011-02-17  171  

:::::: The code at line 139 was first introduced by commit
:::::: bd9a4c7df256cee4e9f6a4b56baa3b89d63f0f1e drivers: hwspinlock: add framework

:::::: TO: Ohad Ben-Cohen <ohad@wizery.com>
:::::: CC: Tony Lindgren <tony@atomide.com>

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

             reply	other threads:[~2026-07-09 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  9:59 kernel test robot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-03-30  8:21 drivers/hwspinlock/hwspinlock_core.c:139 __hwspin_trylock() warn: mixing irq and irqsave kernel test robot

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=202607091718.s8YXDPzQ-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=error27@gmail.com \
    --cc=oe-kbuild@lists.linux.dev \
    /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.