Skip to content

Commit d2e58ab

Browse files
ahunter6KAGA-KOKO
authored andcommitted
vdso: Add vdso_data:: Max_cycles
Add vdso_data::max_cycles in preparation to use it to detect potential multiplication overflow. Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Adrian Hunter <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1beb35e commit d2e58ab

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/vdso/datapage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct vdso_timestamp {
6161
* @seq: timebase sequence counter
6262
* @clock_mode: clock mode
6363
* @cycle_last: timebase at clocksource init
64+
* @max_cycles: maximum cycles which won't overflow 64bit multiplication
6465
* @mask: clocksource mask
6566
* @mult: clocksource multiplier
6667
* @shift: clocksource shift
@@ -92,6 +93,9 @@ struct vdso_data {
9293

9394
s32 clock_mode;
9495
u64 cycle_last;
96+
#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
97+
u64 max_cycles;
98+
#endif
9599
u64 mask;
96100
u32 mult;
97101
u32 shift;

kernel/time/vsyscall.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ static inline void update_vdso_data(struct vdso_data *vdata,
2222
u64 nsec, sec;
2323

2424
vdata[CS_HRES_COARSE].cycle_last = tk->tkr_mono.cycle_last;
25+
#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
26+
vdata[CS_HRES_COARSE].max_cycles = tk->tkr_mono.clock->max_cycles;
27+
#endif
2528
vdata[CS_HRES_COARSE].mask = tk->tkr_mono.mask;
2629
vdata[CS_HRES_COARSE].mult = tk->tkr_mono.mult;
2730
vdata[CS_HRES_COARSE].shift = tk->tkr_mono.shift;
2831
vdata[CS_RAW].cycle_last = tk->tkr_raw.cycle_last;
32+
#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
33+
vdata[CS_RAW].max_cycles = tk->tkr_raw.clock->max_cycles;
34+
#endif
2935
vdata[CS_RAW].mask = tk->tkr_raw.mask;
3036
vdata[CS_RAW].mult = tk->tkr_raw.mult;
3137
vdata[CS_RAW].shift = tk->tkr_raw.shift;

0 commit comments

Comments
 (0)