[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250214135911.2037402-2-edumazet@google.com>
Date: Fri, 14 Feb 2025 13:59:10 +0000
From: Eric Dumazet <edumazet@...gle.com>
To: Anna-Maria Behnsen <anna-maria@...utronix.de>, Frederic Weisbecker <frederic@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>
Cc: linux-kernel <linux-kernel@...r.kernel.org>, Benjamin Segall <bsegall@...gle.com>,
Eric Dumazet <eric.dumazet@...il.com>, Eric Dumazet <edumazet@...gle.com>
Subject: [PATCH 1/2] posix-timers: Make next_posix_timer_id an atomic_t
Instead of relying on a global and shared hash_lock
to protect sig->next_posix_timer_id, make it atomic.
This allows the following patch to use RCU.
Signed-off-by: Eric Dumazet <edumazet@...gle.com>
---
include/linux/sched/signal.h | 2 +-
kernel/time/posix-timers.c | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index d5d03d919df8..72649d7fce2a 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -136,7 +136,7 @@ struct signal_struct {
#ifdef CONFIG_POSIX_TIMERS
/* POSIX.1b Interval Timers */
- unsigned int next_posix_timer_id;
+ atomic_t next_posix_timer_id;
struct hlist_head posix_timers;
struct hlist_head ignored_posix_timers;
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 1b675aee99a9..204a351a2fd3 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -105,13 +105,14 @@ static int posix_timer_add(struct k_itimer *timer)
* a plan to handle the resulting CRIU regression gracefully.
*/
for (cnt = 0; cnt <= INT_MAX; cnt++) {
- spin_lock(&hash_lock);
- id = sig->next_posix_timer_id;
+ id = atomic_inc_return(&sig->next_posix_timer_id) - 1;
- /* Write the next ID back. Clamp it to the positive space */
- sig->next_posix_timer_id = (id + 1) & INT_MAX;
+ /* Clamp id to the positive space */
+ id &= INT_MAX;
head = &posix_timers_hashtable[hash(sig, id)];
+
+ spin_lock(&hash_lock);
if (!__posix_timers_find(head, sig, id)) {
hlist_add_head_rcu(&timer->t_hash, head);
spin_unlock(&hash_lock);
--
2.48.1.601.g30ceb7b040-goog
Powered by blists - more mailing lists