Skip to content

rpi-5.6.y -- vdso version of clock_gettime is wrong, syscall is correct #3579

@jackschmidt

Description

@jackschmidt

Is this the right place for my bug report?

I believe so. With default Raspbian kernel and userland, the program produces correct output. Building 5.6 kernel following https://www.raspberrypi.org/documentation/linux/kernel/building.md and booting the result, the program produces erratic output.

Describe the bug

The VDSO version of clock_gettime( CLOCK_REALTIME, ts ); produces erratic, incorrect output. The syscall version works fine.

To reproduce

Boot a stock raspberry pi 4b rev 1.2 with https://downloads.raspberrypi.org/raspbian_lite_latest (2020-02-13) and run apt-get update and apt-get upgrade.

Build the kernel:

sudo apt install git bc bison flex libssl-dev make
git clone --depth=1 --branch rpi-5.6.y https://github.com/raspberrypi/linux
cd linux
mkdir ../build
make O=../build bcm2711_defconfig
make O=../build -j4
sudo cp ../build/arch/arm/boot/zImage /boot/kernel7l.img
sudo reboot

Now build the program with MUSL libc (I used musl-cross-make)

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <syscall.h>

int main(int argc, char**argv) {
  struct timespec ts_sc[1];
  struct timespec ts_vd[1];
  syscall(SYS_clock_gettime64, CLOCK_REALTIME, ts_sc);
  clock_gettime(CLOCK_REALTIME, ts_vd); // musl will use vdso here
  printf(
    "vd: %lld %lld (%llx %llx)\n"
    "sc: %lld %lld (%llx %llx)\n",
    (long long) ts_vd->tv_sec, (long long) ts_vd->tv_nsec,
    (long long) ts_vd->tv_sec, (long long) ts_vd->tv_nsec,
    (long long) ts_sc->tv_sec, (long long) ts_sc->tv_nsec,
    (long long) ts_sc->tv_sec, (long long) ts_sc->tv_nsec
  );
}

Expected behaviour

The time in seconds (first column) should increase by about 1 per second. This should happen for both rows, VDSO and syscall.

$ ./mix
vd: 1587861652 218823486 (5ea4d894 d0afb3e)
sc: 1587861652 218784111 (5ea4d894 d0a616f)
$ ./mix
vd: 1587861652 838336559 (5ea4d894 31f8002f)
sc: 1587861652 838282913 (5ea4d894 31f72ea1)
$ ./mix
vd: 1587861653 427229788 (5ea4d895 1977025c)
sc: 1587861653 427190569 (5ea4d895 19766929)
$ ./mix
vd: 1587861654 20806558 (5ea4d896 13d7b9e)
sc: 1587861654 20748798 (5ea4d896 13c99fe)
$ ./mix
vd: 1587861654 589989110 (5ea4d896 232a84f6)
sc: 1587861654 589934787 (5ea4d896 2329b0c3)

Actual behaviour

The seconds column for VDSO is erratic. The seconds column for syscall increases by about 1 per second.

$ ./mix
vd: 1602382300 871248665 (5f8269dc 33ee3319)
sc: 1587861514 880693130 (5ea4d80a 347e4f8a)
$ ./mix
vd: 1592986975 290581759 (5ef30d5f 1151ecff)
sc: 1587861515 313451055 (5ea4d80b 12aee22f)
$ ./mix
vd: 1600536634 931908777 (5f66403a 378bcca9)
sc: 1587861515 766646428 (5ea4d80b 2db2189c)
$ ./mix
vd: 1591309079 582261861 (5ed97317 22b49c65)
sc: 1587861516 220063133 (5ea4d80c d1de59d)

System
Copy and paste the results of the raspinfo command in to this section. Alternatively, copy and paste a pastebin link, or add answers to the following questions:

  • Which model of Raspberry Pi?
$ dmesg | grep Rasp
[    0.000000] OF: fdt: Machine model: Raspberry Pi 4 Model B Rev 1.2
  • Which OS and version (cat /etc/rpi-issue)?
$ cat /etc/rpi-issue
Raspberry Pi reference 2020-02-13
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 5f884374b6ac6e155330c58caa1fb7249b8badf1, stage2
  • Which firmware version (vcgencmd version)?

From the 5.6 kernel:

$ vcgencmd version
VCHI initialization failed

From stock kernel:

$ vcgencmd version
Feb 12 2020 12:36:21
Copyright (c) 2012 Broadcom
version c3c8dbdf147686fb0c3f32aece709d0653368810 (clean) (release) (start)
  • Which kernel version (uname -a)?
uname -a
Linux raspberrypi 5.6.4-v7l+ #1 SMP Sat Apr 25 19:34:29 EDT 2020 armv7l GNU/Linux

Logs

Let me know if you want anything else.

Additional context

Related problem report at richfelker/musl-cross-make#96

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions