2323#include <asm/vdso.h>
2424#include <asm/vdso_datapage.h>
2525#include <clocksource/arm_arch_timer.h>
26+ #include <vdso/helpers.h>
27+ #include <vdso/vsyscall.h>
2628
2729#define MAX_SYMNAME 64
2830
@@ -37,7 +39,7 @@ unsigned int vdso_total_pages __ro_after_init;
3739 * The VDSO data page.
3840 */
3941static union vdso_data_store vdso_data_store __page_aligned_data ;
40- static struct vdso_data * vdso_data = & vdso_data_store .data ;
42+ struct vdso_data * vdso_data = vdso_data_store .data ;
4143
4244static struct page * vdso_data_page __ro_after_init ;
4345static const struct vm_special_mapping vdso_data_mapping = {
@@ -77,7 +79,7 @@ struct elfinfo {
7779/* Cached result of boot-time check for whether the arch timer exists,
7880 * and if so, whether the virtual counter is useable.
7981 */
80- static bool cntvct_ok __ro_after_init ;
82+ bool cntvct_ok __ro_after_init ;
8183
8284static bool __init cntvct_functional (void )
8385{
@@ -262,84 +264,3 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr)
262264 mm -> context .vdso = addr ;
263265}
264266
265- static void vdso_write_begin (struct vdso_data * vdata )
266- {
267- ++ vdso_data -> seq_count ;
268- smp_wmb (); /* Pairs with smp_rmb in vdso_read_retry */
269- }
270-
271- static void vdso_write_end (struct vdso_data * vdata )
272- {
273- smp_wmb (); /* Pairs with smp_rmb in vdso_read_begin */
274- ++ vdso_data -> seq_count ;
275- }
276-
277- static bool tk_is_cntvct (const struct timekeeper * tk )
278- {
279- if (!IS_ENABLED (CONFIG_ARM_ARCH_TIMER ))
280- return false;
281-
282- if (!tk -> tkr_mono .clock -> archdata .vdso_direct )
283- return false;
284-
285- return true;
286- }
287-
288- /**
289- * update_vsyscall - update the vdso data page
290- *
291- * Increment the sequence counter, making it odd, indicating to
292- * userspace that an update is in progress. Update the fields used
293- * for coarse clocks and, if the architected system timer is in use,
294- * the fields used for high precision clocks. Increment the sequence
295- * counter again, making it even, indicating to userspace that the
296- * update is finished.
297- *
298- * Userspace is expected to sample seq_count before reading any other
299- * fields from the data page. If seq_count is odd, userspace is
300- * expected to wait until it becomes even. After copying data from
301- * the page, userspace must sample seq_count again; if it has changed
302- * from its previous value, userspace must retry the whole sequence.
303- *
304- * Calls to update_vsyscall are serialized by the timekeeping core.
305- */
306- void update_vsyscall (struct timekeeper * tk )
307- {
308- struct timespec64 * wtm = & tk -> wall_to_monotonic ;
309-
310- if (!cntvct_ok ) {
311- /* The entry points have been zeroed, so there is no
312- * point in updating the data page.
313- */
314- return ;
315- }
316-
317- vdso_write_begin (vdso_data );
318-
319- vdso_data -> tk_is_cntvct = tk_is_cntvct (tk );
320- vdso_data -> xtime_coarse_sec = tk -> xtime_sec ;
321- vdso_data -> xtime_coarse_nsec = (u32 )(tk -> tkr_mono .xtime_nsec >>
322- tk -> tkr_mono .shift );
323- vdso_data -> wtm_clock_sec = wtm -> tv_sec ;
324- vdso_data -> wtm_clock_nsec = wtm -> tv_nsec ;
325-
326- if (vdso_data -> tk_is_cntvct ) {
327- vdso_data -> cs_cycle_last = tk -> tkr_mono .cycle_last ;
328- vdso_data -> xtime_clock_sec = tk -> xtime_sec ;
329- vdso_data -> xtime_clock_snsec = tk -> tkr_mono .xtime_nsec ;
330- vdso_data -> cs_mult = tk -> tkr_mono .mult ;
331- vdso_data -> cs_shift = tk -> tkr_mono .shift ;
332- vdso_data -> cs_mask = tk -> tkr_mono .mask ;
333- }
334-
335- vdso_write_end (vdso_data );
336-
337- flush_dcache_page (virt_to_page (vdso_data ));
338- }
339-
340- void update_vsyscall_tz (void )
341- {
342- vdso_data -> tz_minuteswest = sys_tz .tz_minuteswest ;
343- vdso_data -> tz_dsttime = sys_tz .tz_dsttime ;
344- flush_dcache_page (virt_to_page (vdso_data ));
345- }
0 commit comments