locking/qspinlock: Always evaluate lockevent* non-event parameter once
Waiman Long
reviewerPATCH 1/1 locking/qspinlock: Always evaluate lockevent* non-event parameter once
The inc parameter of lockevent_add() and the cond parameter of lockevent_cond_inc() are only evaluated when CONFIG_LOCK_EVENT_COUNTS is on. That can cause problem if those parameters are expressions with side effect like a "++". Fix this by evaluating those non-event parameters once even if CONFIG_LOCK_EVENT_COUNTS is off. This will also eliminate the need of the __maybe_unused attribute to the wait_early local variable in pv_wait_node().
--- kernel/locking/lock_events.h | 4 ++-- kernel/locking/qspinlock_paravirt.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/locking/lock_events.h +2 -2
@@ -53,8 +53,8 @@ static inline void __lockevent_add(enum lock_events event, int inc)#else /* CONFIG_LOCK_EVENT_COUNTS */ #define lockevent_inc (ev) -#define lockevent_add (ev, c) -#define lockevent_cond_inc (ev, c) +#define lockevent_add (ev, c) do { (void)(c); } while (0) +#define lockevent_cond_inc (ev, c) do { (void)(c); } while (0)#endif /* CONFIG_LOCK_EVENT_COUNTS */
kernel/locking/qspinlock_paravirt.h +1 -1
@@ -294,7 +294,7 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev) {struct pv_node *pn = (struct pv_node *)node;struct pv_node *pp = (struct pv_node *)prev; -bool __maybe_unused wait_early; +bool wait_early;int loop;for (;;) {
Signature · 1 line
2.39.3
Quoted 10 lines · Waiman Long
The inc parameter of
lockevent_add()and the cond parameter oflockevent_cond_inc()are only evaluated whenCONFIG_LOCK_EVENT_COUNTSis on. That can cause problem if those parameters are expressions with side effect like a "++". Fix this by evaluating those non-event parameters once even ifCONFIG_LOCK_EVENT_COUNTSis off. This will also eliminate the need of the__maybe_unusedattribute to thewait_earlylocal variable inpv_wait_node().Suggested-by Ingo Molnar <[email protected]>Signed-off-by Waiman Long <[email protected]>
Regards,
Boqun
Quoted 36 lines
--- kernel/locking/lock_events.h | 4 ++-- kernel/locking/qspinlock_paravirt.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)kernel/locking/lock_events.h +2
-2@@ -53,8 +53,8 @@ static inline void __lockevent_add(enum lock_events event, int inc)#else /* CONFIG_LOCK_EVENT_COUNTS */ #define lockevent_inc (ev) -#define lockevent_add (ev, c) -#define lockevent_cond_inc (ev, c) +#define lockevent_add (ev, c) do { (void)(c); } while (0) +#define lockevent_cond_inc (ev, c) do { (void)(c); } while (0)#endif /* CONFIG_LOCK_EVENT_COUNTS */ kernel/locking/qspinlock_paravirt.h +1
-1@@ -294,7 +294,7 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev) {struct pv_node *pn = (struct pv_node *)node;struct pv_node *pp = (struct pv_node *)prev; -bool __maybe_unused wait_early; +bool wait_early;int loop;for (;;) {Signature · 1 line
2.39.3
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 3774b28d8f3b9e8a946beb9550bee85e5454fc9f Gitweb: https://git.kernel.org/tip/3774b28d8f3b9e8a946beb9550bee85e5454fc9f Author: Waiman Long <[email protected]> AuthorDate: Mon, 18 Mar 2024 20:50:04 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 21 Mar 2024 20:45:17 +01:00
locking/qspinlock: Always evaluate lockevent* non-event parameter once
The 'inc' parameter of lockevent_add() and the cond parameter of lockevent_cond_inc() are only evaluated when CONFIG_LOCK_EVENT_COUNTS is on. That can cause problem if those parameters are expressions with side effect like a "++". Fix this by evaluating those non-event parameters once even if CONFIG_LOCK_EVENT_COUNTS is off. This will also eliminate the need of the __maybe_unused attribute to the wait_early local variable in pv_wait_node().
--- kernel/locking/lock_events.h | 4 ++-- kernel/locking/qspinlock_paravirt.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/locking/lock_events.h +2 -2
@@ -53,8 +53,8 @@ static inline void __lockevent_add(enum lock_events event, int inc)#else /* CONFIG_LOCK_EVENT_COUNTS */ #define lockevent_inc (ev) -#define lockevent_add (ev, c) -#define lockevent_cond_inc (ev, c) +#define lockevent_add (ev, c) do { (void)(c); } while (0) +#define lockevent_cond_inc (ev, c) do { (void)(c); } while (0)#endif /* CONFIG_LOCK_EVENT_COUNTS */
kernel/locking/qspinlock_paravirt.h +1 -1
@@ -294,7 +294,7 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev) {struct pv_node *pn = (struct pv_node *)node;struct pv_node *pp = (struct pv_node *)prev; -bool __maybe_unused wait_early; +bool wait_early;int loop;for (;;) {