[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250321020341.1404557-1-cuiguoqi@kylinos.cn>
Date: Fri, 21 Mar 2025 10:03:41 +0800
From: cuiguoqi <cuiguoqi@...inos.cn>
To: info@...utronix.de,
anna-maria@...utronix.de
Cc: sales@...utronix.de,
frederic@...nel.org,
tglx@...utronix.de,
linux-kernel@...r.kernel.org,
bigeasy@...utronix.de,
clrkwllms@...nel.org,
rostedt@...dmis.org,
linux-rt-devel@...ts.linux.dev,
cuiguoqi <cuiguoqi@...inos.cn>
Subject: [PATCH] hrtimer: Fix the incorrect initialization of timer->is_hard
When PREEMPT_RT is disabled,there is a possibility that
timer->is_hard will be incorrectly initialized.
When creating a high-resolution timer and setting the mode to
HRTIMER_MODE_ABS,the timer->is_hard will be incorrectly initialized.
Pseudocode logic:
1. mode
>> HRTIMER_MODE_ABS = 0x00
2. bool softtimer = !!(mode & HRTIMER_MODE_SOFT); //!PREEMPT_RT
base = softtimer ? HRTIMER_MAX_CLOCK_BASES / 2 : 0; //!PREEMPT_RT
> softtimer = falseļ¼ //!PREEMPT_RT
> base = 0; //hard mode
3. timer->is_soft = softtimer;
> timer->is_soft = flase;
4. timer->is_hard = !!(mode & HRTIMER_MODE_HARD); !PREEMPT_RT
> timer->is_hard = flase; //error
> Based on point 2, by default, the hard mode is selected.
Of course, if PREEMPT_RT is enabled, timer->is_hard is correctly set.
bool softtimer = !!(mode & HRTIMER_MODE_SOFT);
if (IS_ENABLED(CONFIG_PREEMPT_RT) && !(mode & HRTIMER_MODE_HARD))
softtimer = true;
timer->is_soft = softtimer; //true
timer->is_hard = !!(mode & HRTIMER_MODE_HARD); //flase
Signed-off-by: cuiguoqi <cuiguoqi@...inos.cn>
---
kernel/time/hrtimer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 80fe3749d2db..9d8defb1e9b1 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1571,7 +1571,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
base = softtimer ? HRTIMER_MAX_CLOCK_BASES / 2 : 0;
base += hrtimer_clockid_to_base(clock_id);
timer->is_soft = softtimer;
- timer->is_hard = !!(mode & HRTIMER_MODE_HARD);
+ timer->is_hard = !softtimer;
timer->base = &cpu_base->clock_base[base];
timerqueue_init(&timer->node);
}
--
2.25.1
Powered by blists - more mailing lists