@@ -77,6 +77,16 @@ static __always_inline bool vdso_clockid_valid(clockid_t clock)
77
77
return likely ((u32 ) clock < MAX_CLOCKS );
78
78
}
79
79
80
+ /*
81
+ * Must not be invoked within the sequence read section as a race inside
82
+ * that loop could result in __iter_div_u64_rem() being extremely slow.
83
+ */
84
+ static __always_inline void vdso_set_timespec (struct __kernel_timespec * ts , u64 sec , u64 ns )
85
+ {
86
+ ts -> tv_sec = sec + __iter_div_u64_rem (ns , NSEC_PER_SEC , & ns );
87
+ ts -> tv_nsec = ns ;
88
+ }
89
+
80
90
#ifdef CONFIG_TIME_NS
81
91
82
92
#ifdef CONFIG_GENERIC_VDSO_DATA_STORE
@@ -122,12 +132,7 @@ bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *
122
132
sec += offs -> sec ;
123
133
ns += offs -> nsec ;
124
134
125
- /*
126
- * Do this outside the loop: a race inside the loop could result
127
- * in __iter_div_u64_rem() being extremely slow.
128
- */
129
- ts -> tv_sec = sec + __iter_div_u64_rem (ns , NSEC_PER_SEC , & ns );
130
- ts -> tv_nsec = ns ;
135
+ vdso_set_timespec (ts , sec , ns );
131
136
132
137
return true;
133
138
}
@@ -188,12 +193,7 @@ bool do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc,
188
193
sec = vdso_ts -> sec ;
189
194
} while (unlikely (vdso_read_retry (vc , seq )));
190
195
191
- /*
192
- * Do this outside the loop: a race inside the loop could result
193
- * in __iter_div_u64_rem() being extremely slow.
194
- */
195
- ts -> tv_sec = sec + __iter_div_u64_rem (ns , NSEC_PER_SEC , & ns );
196
- ts -> tv_nsec = ns ;
196
+ vdso_set_timespec (ts , sec , ns );
197
197
198
198
return true;
199
199
}
@@ -223,12 +223,8 @@ bool do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_clock
223
223
sec += offs -> sec ;
224
224
nsec += offs -> nsec ;
225
225
226
- /*
227
- * Do this outside the loop: a race inside the loop could result
228
- * in __iter_div_u64_rem() being extremely slow.
229
- */
230
- ts -> tv_sec = sec + __iter_div_u64_rem (nsec , NSEC_PER_SEC , & nsec );
231
- ts -> tv_nsec = nsec ;
226
+ vdso_set_timespec (ts , sec , nsec );
227
+
232
228
return true;
233
229
}
234
230
#else
0 commit comments