Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Aug 2023 22:34:16 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 93626d543702 - main - tc_fill_vdso_timehands32(): fix
Message-ID:  <202308122234.37CMYGDj037133@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=93626d54370292b09cd0ca604b144737109e9071

commit 93626d54370292b09cd0ca604b144737109e9071
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-08-12 19:51:37 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-08-12 22:34:08 +0000

    tc_fill_vdso_timehands32(): fix
    
    On 64bit, there is a 4-byte hole in struct vdso_timekeep32 after
    tk_current, if the structure is not packed.  This is due to the MD
    th_x86_pvc_last_systime being 64bit.
    
    Change amd64 VDSO_TIMEHANDS_MD32 to not use uint64_t, replace it with
    pair of uint32_t, as it is done for all other members.
    
    PR:     273085
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 sys/dev/acpica/acpi_hpet.c | 3 ++-
 sys/x86/include/vdso.h     | 7 ++++++-
 sys/x86/x86/pvclock.c      | 2 +-
 sys/x86/x86/tsc.c          | 3 ++-
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/sys/dev/acpica/acpi_hpet.c b/sys/dev/acpica/acpi_hpet.c
index 9ed7c5a47b35..a1171027ddf7 100644
--- a/sys/dev/acpica/acpi_hpet.c
+++ b/sys/dev/acpica/acpi_hpet.c
@@ -171,7 +171,8 @@ hpet_vdso_timehands32(struct vdso_timehands32 *vdso_th32,
 	vdso_th32->th_algo = VDSO_TH_ALGO_X86_HPET;
 	vdso_th32->th_x86_shift = 0;
 	vdso_th32->th_x86_hpet_idx = device_get_unit(sc->dev);
-	vdso_th32->th_x86_pvc_last_systime = 0;
+	vdso_th32->th_x86_pvc_last_systime[0] = 0;
+	vdso_th32->th_x86_pvc_last_systime[1] = 0;
 	vdso_th32->th_x86_pvc_stable_mask = 0;
 	bzero(vdso_th32->th_res, sizeof(vdso_th32->th_res));
 	return (sc->mmap_allow != 0);
diff --git a/sys/x86/include/vdso.h b/sys/x86/include/vdso.h
index 546a92a47301..be90e26702f7 100644
--- a/sys/x86/include/vdso.h
+++ b/sys/x86/include/vdso.h
@@ -49,7 +49,12 @@
 #ifdef _KERNEL
 #ifdef COMPAT_FREEBSD32
 
-#define	VDSO_TIMEHANDS_MD32	VDSO_TIMEHANDS_MD
+#define	VDSO_TIMEHANDS_MD32			\
+	uint32_t	th_x86_shift;		\
+	uint32_t	th_x86_hpet_idx;	\
+	uint32_t	th_x86_pvc_last_systime[2];\
+	uint8_t		th_x86_pvc_stable_mask;	\
+	uint8_t		th_res[15];
 
 #endif
 #endif
diff --git a/sys/x86/x86/pvclock.c b/sys/x86/x86/pvclock.c
index 3da3373bb2ee..9d8ac99f5a8a 100644
--- a/sys/x86/x86/pvclock.c
+++ b/sys/x86/x86/pvclock.c
@@ -253,7 +253,7 @@ pvclock_tc_vdso_timehands32(struct vdso_timehands32 *vdso_th,
 	vdso_th->th_algo = VDSO_TH_ALGO_X86_PVCLK;
 	vdso_th->th_x86_shift = 0;
 	vdso_th->th_x86_hpet_idx = 0;
-	vdso_th->th_x86_pvc_last_systime =
+	*(uint64_t *)&vdso_th->th_x86_pvc_last_systime[0] =
 	    atomic_load_acq_64(&pvclock_last_systime);
 	vdso_th->th_x86_pvc_stable_mask = !pvc->vdso_force_unstable &&
 	    pvc->stable_flag_supported ? PVCLOCK_FLAG_TSC_STABLE : 0;
diff --git a/sys/x86/x86/tsc.c b/sys/x86/x86/tsc.c
index a9e44307dd83..fc72dee176e9 100644
--- a/sys/x86/x86/tsc.c
+++ b/sys/x86/x86/tsc.c
@@ -990,7 +990,8 @@ x86_tsc_vdso_timehands32(struct vdso_timehands32 *vdso_th32,
 	vdso_th32->th_algo = VDSO_TH_ALGO_X86_TSC;
 	vdso_th32->th_x86_shift = (int)(intptr_t)tc->tc_priv;
 	vdso_th32->th_x86_hpet_idx = 0xffffffff;
-	vdso_th32->th_x86_pvc_last_systime = 0;
+	vdso_th32->th_x86_pvc_last_systime[0] = 0;
+	vdso_th32->th_x86_pvc_last_systime[1] = 0;
 	vdso_th32->th_x86_pvc_stable_mask = 0;
 	bzero(vdso_th32->th_res, sizeof(vdso_th32->th_res));
 	return (1);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202308122234.37CMYGDj037133>