Re: [PATCH v2] hrtimer: Fix is_hard/is_soft both false with missing HARD/SOFT flag

From: Sebastian Andrzej Siewior

Date: Mon Mar 16 2026 - 03:33:29 EST


On 2026-03-15 14:30:09 [+0800], guoqi0226 wrote:
> When hrtimer mode is only ABS/REL (e.g. HRTIMER_MODE_ABS) with no explicit
> SOFT/HARD flag, and CONFIG_PREEMPT_RT is disabled, both timer->is_hard and
> is_soft become false, violating the hard/soft exclusive design rule.
>
> Enforce correct hard/soft timer via effective_mode:
> - Enable softtimer when CONFIG_PREEMPT_RT is enabled and no HARD flag
> - Add HRTIMER_MODE_HARD to effective_mode when
> CONFIG_PREEMPT_RT is disabled (e.g. HRTIMER_MODE_ABS)
> - Compute timer->is_hard as !!(effective_mode & HRTIMER_MODE_HARD)
>
> This ensures exactly one of is_hard/is_soft is true.

How and where is this a problem?

> Signed-off-by: guoqi0226 <guoqi0226@xxxxxxx>

Sebastian