mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-06 05:06:29 +00:00
bf9aa14fc5
- The final step to get rid of auto-rearming posix-timers posix-timers are currently auto-rearmed by the kernel when the signal of the timer is ignored so that the timer signal can be delivered once the corresponding signal is unignored. This requires to throttle the timer to prevent a DoS by small intervals and keeps the system pointlessly out of low power states for no value. This is a long standing non-trivial problem due to the lock order of posix-timer lock and the sighand lock along with life time issues as the timer and the sigqueue have different life time rules. Cure this by: * Embedding the sigqueue into the timer struct to have the same life time rules. Aside of that this also avoids the lookup of the timer in the signal delivery and rearm path as it's just a always valid container_of() now. * Queuing ignored timer signals onto a seperate ignored list. * Moving queued timer signals onto the ignored list when the signal is switched to SIG_IGN before it could be delivered. * Walking the ignored list when SIG_IGN is lifted and requeue the signals to the actual signal lists. This allows the signal delivery code to rearm the timer. This also required to consolidate the signal delivery rules so they are consistent across all situations. With that all self test scenarios finally succeed. - Core infrastructure for VFS multigrain timestamping This is required to allow the kernel to use coarse grained time stamps by default and switch to fine grained time stamps when inode attributes are actively observed via getattr(). These changes have been provided to the VFS tree as well, so that the VFS specific infrastructure could be built on top. - Cleanup and consolidation of the sleep() infrastructure * Move all sleep and timeout functions into one file * Rework udelay() and ndelay() into proper documented inline functions and replace the hardcoded magic numbers by proper defines. * Rework the fsleep() implementation to take the reality of the timer wheel granularity on different HZ values into account. Right now the boundaries are hard coded time ranges which fail to provide the requested accuracy on different HZ settings. * Update documentation for all sleep/timeout related functions and fix up stale documentation links all over the place * Fixup a few usage sites - Rework of timekeeping and adjtimex(2) to prepare for multiple PTP clocks A system can have multiple PTP clocks which are participating in seperate and independent PTP clock domains. So far the kernel only considers the PTP clock which is based on CLOCK TAI relevant as that's the clock which drives the timekeeping adjustments via the various user space daemons through adjtimex(2). The non TAI based clock domains are accessible via the file descriptor based posix clocks, but their usability is very limited. They can't be accessed fast as they always go all the way out to the hardware and they cannot be utilized in the kernel itself. As Time Sensitive Networking (TSN) gains traction it is required to provide fast user and kernel space access to these clocks. The approach taken is to utilize the timekeeping and adjtimex(2) infrastructure to provide this access in a similar way how the kernel provides access to clock MONOTONIC, REALTIME etc. Instead of creating a duplicated infrastructure this rework converts timekeeping and adjtimex(2) into generic functionality which operates on pointers to data structures instead of using static variables. This allows to provide time accessors and adjtimex(2) functionality for the independent PTP clocks in a subsequent step. - Consolidate hrtimer initialization hrtimers are set up by initializing the data structure and then seperately setting the callback function for historical reasons. That's an extra unnecessary step and makes Rust support less straight forward than it should be. Provide a new set of hrtimer_setup*() functions and convert the core code and a few usage sites of the less frequently used interfaces over. The bulk of the htimer_init() to hrtimer_setup() conversion is already prepared and scheduled for the next merge window. - Drivers: * Ensure that the global timekeeping clocksource is utilizing the cluster 0 timer on MIPS multi-cluster systems. Otherwise CPUs on different clusters use their cluster specific clocksource which is not guaranteed to be synchronized with other clusters. * Mostly boring cleanups, fixes, improvements and code movement -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAmc7kPITHHRnbHhAbGlu dXRyb25peC5kZQAKCRCmGPVMDXSYoZKkD/9OUL6fOJrDUmOYBa4QVeMyfTef4EaL tvwIMM/29XQFeiq3xxCIn+EMnHjXn2lvIhYGQ7GKsbKYwvJ7ZBDpQb+UMhZ2nKI9 6D6BP6WomZohKeH2fZbJQAdqOi3KRYdvQdIsVZUexkqiaVPphRvOH9wOr45gHtZM EyMRSotPlQTDqcrbUejDMEO94GyjDCYXRsyATLxjmTzL/N4xD4NRIiotjM2vL/a9 8MuCgIhrKUEyYlFoOxxeokBsF3kk3/ez2jlG9b/N8VLH3SYIc2zgL58FBgWxlmgG bY71nVG3nUgEjxBd2dcXAVVqvb+5widk8p6O7xxOAQKTLMcJ4H0tQDkMnzBtUzvB DGAJDHAmAr0g+ja9O35Pkhunkh4HYFIbq0Il4d1HMKObhJV0JumcKuQVxrXycdm3 UZfq3seqHsZJQbPgCAhlFU0/2WWScocbee9bNebGT33KVwSp5FoVv89C/6Vjb+vV Gusc3thqrQuMAZW5zV8g4UcBAA/xH4PB0I+vHib+9XPZ4UQ7/6xKl2jE0kd5hX7n AAUeZvFNFqIsY+B6vz+Jx/yzyM7u5cuXq87pof5EHVFzv56lyTp4ToGcOGYRgKH5 JXeYV1OxGziSDrd5vbf9CzdWMzqMvTefXrHbWrjkjhNOe8E1A8O88RZ5uRKZhmSw hZZ4hdM9+3T7cg== =2VC6 -----END PGP SIGNATURE----- Merge tag 'timers-core-2024-11-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull timer updates from Thomas Gleixner: "A rather large update for timekeeping and timers: - The final step to get rid of auto-rearming posix-timers posix-timers are currently auto-rearmed by the kernel when the signal of the timer is ignored so that the timer signal can be delivered once the corresponding signal is unignored. This requires to throttle the timer to prevent a DoS by small intervals and keeps the system pointlessly out of low power states for no value. This is a long standing non-trivial problem due to the lock order of posix-timer lock and the sighand lock along with life time issues as the timer and the sigqueue have different life time rules. Cure this by: - Embedding the sigqueue into the timer struct to have the same life time rules. Aside of that this also avoids the lookup of the timer in the signal delivery and rearm path as it's just a always valid container_of() now. - Queuing ignored timer signals onto a seperate ignored list. - Moving queued timer signals onto the ignored list when the signal is switched to SIG_IGN before it could be delivered. - Walking the ignored list when SIG_IGN is lifted and requeue the signals to the actual signal lists. This allows the signal delivery code to rearm the timer. This also required to consolidate the signal delivery rules so they are consistent across all situations. With that all self test scenarios finally succeed. - Core infrastructure for VFS multigrain timestamping This is required to allow the kernel to use coarse grained time stamps by default and switch to fine grained time stamps when inode attributes are actively observed via getattr(). These changes have been provided to the VFS tree as well, so that the VFS specific infrastructure could be built on top. - Cleanup and consolidation of the sleep() infrastructure - Move all sleep and timeout functions into one file - Rework udelay() and ndelay() into proper documented inline functions and replace the hardcoded magic numbers by proper defines. - Rework the fsleep() implementation to take the reality of the timer wheel granularity on different HZ values into account. Right now the boundaries are hard coded time ranges which fail to provide the requested accuracy on different HZ settings. - Update documentation for all sleep/timeout related functions and fix up stale documentation links all over the place - Fixup a few usage sites - Rework of timekeeping and adjtimex(2) to prepare for multiple PTP clocks A system can have multiple PTP clocks which are participating in seperate and independent PTP clock domains. So far the kernel only considers the PTP clock which is based on CLOCK TAI relevant as that's the clock which drives the timekeeping adjustments via the various user space daemons through adjtimex(2). The non TAI based clock domains are accessible via the file descriptor based posix clocks, but their usability is very limited. They can't be accessed fast as they always go all the way out to the hardware and they cannot be utilized in the kernel itself. As Time Sensitive Networking (TSN) gains traction it is required to provide fast user and kernel space access to these clocks. The approach taken is to utilize the timekeeping and adjtimex(2) infrastructure to provide this access in a similar way how the kernel provides access to clock MONOTONIC, REALTIME etc. Instead of creating a duplicated infrastructure this rework converts timekeeping and adjtimex(2) into generic functionality which operates on pointers to data structures instead of using static variables. This allows to provide time accessors and adjtimex(2) functionality for the independent PTP clocks in a subsequent step. - Consolidate hrtimer initialization hrtimers are set up by initializing the data structure and then seperately setting the callback function for historical reasons. That's an extra unnecessary step and makes Rust support less straight forward than it should be. Provide a new set of hrtimer_setup*() functions and convert the core code and a few usage sites of the less frequently used interfaces over. The bulk of the htimer_init() to hrtimer_setup() conversion is already prepared and scheduled for the next merge window. - Drivers: - Ensure that the global timekeeping clocksource is utilizing the cluster 0 timer on MIPS multi-cluster systems. Otherwise CPUs on different clusters use their cluster specific clocksource which is not guaranteed to be synchronized with other clusters. - Mostly boring cleanups, fixes, improvements and code movement" * tag 'timers-core-2024-11-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (140 commits) posix-timers: Fix spurious warning on double enqueue versus do_exit() clocksource/drivers/arm_arch_timer: Use of_property_present() for non-boolean properties clocksource/drivers/gpx: Remove redundant casts clocksource/drivers/timer-ti-dm: Fix child node refcount handling dt-bindings: timer: actions,owl-timer: convert to YAML clocksource/drivers/ralink: Add Ralink System Tick Counter driver clocksource/drivers/mips-gic-timer: Always use cluster 0 counter as clocksource clocksource/drivers/timer-ti-dm: Don't fail probe if int not found clocksource/drivers:sp804: Make user selectable clocksource/drivers/dw_apb: Remove unused dw_apb_clockevent functions hrtimers: Delete hrtimer_init_on_stack() alarmtimer: Switch to use hrtimer_setup() and hrtimer_setup_on_stack() io_uring: Switch to use hrtimer_setup_on_stack() sched/idle: Switch to use hrtimer_setup_on_stack() hrtimers: Delete hrtimer_init_sleeper_on_stack() wait: Switch to use hrtimer_setup_sleeper_on_stack() timers: Switch to use hrtimer_setup_sleeper_on_stack() net: pktgen: Switch to use hrtimer_setup_sleeper_on_stack() futex: Switch to use hrtimer_setup_sleeper_on_stack() fs/aio: Switch to use hrtimer_setup_sleeper_on_stack() ...
176 lines
5.1 KiB
C
176 lines
5.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright 2019 ARM Ltd.
|
|
*
|
|
* Generic implementation of update_vsyscall and update_vsyscall_tz.
|
|
*
|
|
* Based on the x86 specific implementation.
|
|
*/
|
|
|
|
#include <linux/hrtimer.h>
|
|
#include <linux/timekeeper_internal.h>
|
|
#include <vdso/datapage.h>
|
|
#include <vdso/helpers.h>
|
|
#include <vdso/vsyscall.h>
|
|
|
|
#include "timekeeping_internal.h"
|
|
|
|
static inline void update_vdso_data(struct vdso_data *vdata,
|
|
struct timekeeper *tk)
|
|
{
|
|
struct vdso_timestamp *vdso_ts;
|
|
u64 nsec, sec;
|
|
|
|
vdata[CS_HRES_COARSE].cycle_last = tk->tkr_mono.cycle_last;
|
|
#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
|
|
vdata[CS_HRES_COARSE].max_cycles = tk->tkr_mono.clock->max_cycles;
|
|
#endif
|
|
vdata[CS_HRES_COARSE].mask = tk->tkr_mono.mask;
|
|
vdata[CS_HRES_COARSE].mult = tk->tkr_mono.mult;
|
|
vdata[CS_HRES_COARSE].shift = tk->tkr_mono.shift;
|
|
vdata[CS_RAW].cycle_last = tk->tkr_raw.cycle_last;
|
|
#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
|
|
vdata[CS_RAW].max_cycles = tk->tkr_raw.clock->max_cycles;
|
|
#endif
|
|
vdata[CS_RAW].mask = tk->tkr_raw.mask;
|
|
vdata[CS_RAW].mult = tk->tkr_raw.mult;
|
|
vdata[CS_RAW].shift = tk->tkr_raw.shift;
|
|
|
|
/* CLOCK_MONOTONIC */
|
|
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC];
|
|
vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
|
|
|
|
nsec = tk->tkr_mono.xtime_nsec;
|
|
nsec += ((u64)tk->wall_to_monotonic.tv_nsec << tk->tkr_mono.shift);
|
|
while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
|
|
nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
|
|
vdso_ts->sec++;
|
|
}
|
|
vdso_ts->nsec = nsec;
|
|
|
|
/* Copy MONOTONIC time for BOOTTIME */
|
|
sec = vdso_ts->sec;
|
|
/* Add the boot offset */
|
|
sec += tk->monotonic_to_boot.tv_sec;
|
|
nsec += (u64)tk->monotonic_to_boot.tv_nsec << tk->tkr_mono.shift;
|
|
|
|
/* CLOCK_BOOTTIME */
|
|
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_BOOTTIME];
|
|
vdso_ts->sec = sec;
|
|
|
|
while (nsec >= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
|
|
nsec -= (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift);
|
|
vdso_ts->sec++;
|
|
}
|
|
vdso_ts->nsec = nsec;
|
|
|
|
/* CLOCK_MONOTONIC_RAW */
|
|
vdso_ts = &vdata[CS_RAW].basetime[CLOCK_MONOTONIC_RAW];
|
|
vdso_ts->sec = tk->raw_sec;
|
|
vdso_ts->nsec = tk->tkr_raw.xtime_nsec;
|
|
|
|
/* CLOCK_TAI */
|
|
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_TAI];
|
|
vdso_ts->sec = tk->xtime_sec + (s64)tk->tai_offset;
|
|
vdso_ts->nsec = tk->tkr_mono.xtime_nsec;
|
|
}
|
|
|
|
void update_vsyscall(struct timekeeper *tk)
|
|
{
|
|
struct vdso_data *vdata = __arch_get_k_vdso_data();
|
|
struct vdso_timestamp *vdso_ts;
|
|
s32 clock_mode;
|
|
u64 nsec;
|
|
|
|
/* copy vsyscall data */
|
|
vdso_write_begin(vdata);
|
|
|
|
clock_mode = tk->tkr_mono.clock->vdso_clock_mode;
|
|
vdata[CS_HRES_COARSE].clock_mode = clock_mode;
|
|
vdata[CS_RAW].clock_mode = clock_mode;
|
|
|
|
/* CLOCK_REALTIME also required for time() */
|
|
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME];
|
|
vdso_ts->sec = tk->xtime_sec;
|
|
vdso_ts->nsec = tk->tkr_mono.xtime_nsec;
|
|
|
|
/* CLOCK_REALTIME_COARSE */
|
|
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME_COARSE];
|
|
vdso_ts->sec = tk->xtime_sec;
|
|
vdso_ts->nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
|
|
|
|
/* CLOCK_MONOTONIC_COARSE */
|
|
vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC_COARSE];
|
|
vdso_ts->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
|
|
nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
|
|
nsec = nsec + tk->wall_to_monotonic.tv_nsec;
|
|
vdso_ts->sec += __iter_div_u64_rem(nsec, NSEC_PER_SEC, &vdso_ts->nsec);
|
|
|
|
/*
|
|
* Read without the seqlock held by clock_getres().
|
|
* Note: No need to have a second copy.
|
|
*/
|
|
WRITE_ONCE(vdata[CS_HRES_COARSE].hrtimer_res, hrtimer_resolution);
|
|
|
|
/*
|
|
* If the current clocksource is not VDSO capable, then spare the
|
|
* update of the high resolution parts.
|
|
*/
|
|
if (clock_mode != VDSO_CLOCKMODE_NONE)
|
|
update_vdso_data(vdata, tk);
|
|
|
|
__arch_update_vsyscall(vdata);
|
|
|
|
vdso_write_end(vdata);
|
|
|
|
__arch_sync_vdso_data(vdata);
|
|
}
|
|
|
|
void update_vsyscall_tz(void)
|
|
{
|
|
struct vdso_data *vdata = __arch_get_k_vdso_data();
|
|
|
|
vdata[CS_HRES_COARSE].tz_minuteswest = sys_tz.tz_minuteswest;
|
|
vdata[CS_HRES_COARSE].tz_dsttime = sys_tz.tz_dsttime;
|
|
|
|
__arch_sync_vdso_data(vdata);
|
|
}
|
|
|
|
/**
|
|
* vdso_update_begin - Start of a VDSO update section
|
|
*
|
|
* Allows architecture code to safely update the architecture specific VDSO
|
|
* data. Disables interrupts, acquires timekeeper lock to serialize against
|
|
* concurrent updates from timekeeping and invalidates the VDSO data
|
|
* sequence counter to prevent concurrent readers from accessing
|
|
* inconsistent data.
|
|
*
|
|
* Returns: Saved interrupt flags which need to be handed in to
|
|
* vdso_update_end().
|
|
*/
|
|
unsigned long vdso_update_begin(void)
|
|
{
|
|
struct vdso_data *vdata = __arch_get_k_vdso_data();
|
|
unsigned long flags = timekeeper_lock_irqsave();
|
|
|
|
vdso_write_begin(vdata);
|
|
return flags;
|
|
}
|
|
|
|
/**
|
|
* vdso_update_end - End of a VDSO update section
|
|
* @flags: Interrupt flags as returned from vdso_update_begin()
|
|
*
|
|
* Pairs with vdso_update_begin(). Marks vdso data consistent, invokes data
|
|
* synchronization if the architecture requires it, drops timekeeper lock
|
|
* and restores interrupt flags.
|
|
*/
|
|
void vdso_update_end(unsigned long flags)
|
|
{
|
|
struct vdso_data *vdata = __arch_get_k_vdso_data();
|
|
|
|
vdso_write_end(vdata);
|
|
__arch_sync_vdso_data(vdata);
|
|
timekeeper_unlock_irqrestore(flags);
|
|
}
|