]> git.ipfire.org Git - thirdparty/linux.git/commit
timers/migration: Annotate accesses to ignore flag
authorFrederic Weisbecker <frederic@kernel.org>
Tue, 14 Jan 2025 23:15:06 +0000 (00:15 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 16 Jan 2025 11:47:11 +0000 (12:47 +0100)
commit922efd298bb2636880408c00942dbd54d8bf6e0d
tree3308c79a8959381971c49321f5456e694322af8e
parentde3ced72a79280fefd680e5e101d8b9f03cfa1d7
timers/migration: Annotate accesses to ignore flag

The group's ignore flag is:

_ read under the group's lock (idle entry, remote expiry)
_ turned on/off under the group's lock (idle entry, remote expiry)
_ turned on locklessly on idle exit

When idle entry or remote expiry clear the "ignore" flag of a group, the
operation must be synchronized against other concurrent idle entry or
remote expiry to make sure the related group timer is never missed. To
enforce this synchronization, both "ignore" clear and read are
performed under the group lock.

On the contrary, whether idle entry or remote expiry manage to observe
the "ignore" flag turned on by a CPU exiting idle is a matter of
optimization. If that flag set is missed or cleared concurrently, the
worst outcome is a migrator wasting time remotely handling a "ghost"
timer. This is why the ignore flag can be set locklessly.

Unfortunately, the related lockless accesses are bare and miss
appropriate annotations. KCSAN rightfully complains:

 BUG: KCSAN: data-race in __tmigr_cpu_activate / print_report

 write to 0xffff88842fc28004 of 1 bytes by task 0 on cpu 0:
 __tmigr_cpu_activate
 tmigr_cpu_activate
 timer_clear_idle
 tick_nohz_restart_sched_tick
 tick_nohz_idle_exit
 do_idle
 cpu_startup_entry
 kernel_init
 do_initcalls
 clear_bss
 reserve_bios_regions
 common_startup_64

 read to 0xffff88842fc28004 of 1 bytes by task 0 on cpu 1:
 print_report
 kcsan_report_known_origin
 kcsan_setup_watchpoint
 tmigr_next_groupevt
 tmigr_update_events
 tmigr_inactive_up
 __walk_groups+0x50/0x77
 walk_groups
 __tmigr_cpu_deactivate
 tmigr_cpu_deactivate
 __get_next_timer_interrupt
 timer_base_try_to_set_idle
 tick_nohz_stop_tick
 tick_nohz_idle_stop_tick
 cpuidle_idle_call
 do_idle

Although the relevant accesses could be marked as data_race(), the
"ignore" flag being read several times within the same
tmigr_update_events() function is confusing and error prone. Prefer
reading it once in that function and make use of similar/paired accesses
elsewhere with appropriate comments when necessary.

Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250114231507.21672-4-frederic@kernel.org
Closes: https://lore.kernel.org/oe-lkp/202501031612.62e0c498-lkp@intel.com
kernel/time/timer_migration.c