clock: overriding the clocksource should select the requested clocksource

Bug #1894591 reported by Matthew Ruffell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Fix Released
Undecided
Unassigned
Xenial
Fix Released
Medium
Matthew Ruffell

Bug Description

BugLink: https://bugs.launchpad.net/bugs/1894591

[Impact]

The default clocksource for a KVM VM is kvm-clock, and I happen to need tsc.

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

If I edit /etc/default/grub and append "clocksource=tsc" to GRUB_CMDLINE_LINUX_DEFAULT and reboot, I find the clocksource is still kvm-clock.

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

I can work around this by telling the kernel that the tsc clocksource is reliable, before the watchdog has a chance to see for itself that it is reliable:

GRUB_CMDLINE_LINUX_DEFAULT="clocksource=tsc tsc=reliable"

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
tsc

If I override the clocksource, the kernel should respect my wishes and I should receive the requested clocksource.

[Fix]

The fix landed in Linux 4.9 in the below commit:

commit 36374583f9084cdab4b5dcf5521a3ce55bebb9fa
Author: Kyle Walker <email address hidden>
Date: Sat Aug 6 12:07:30 2016 -0400
Subject: clocksource: Defer override invalidation unless clock is unstable
Link: https://github.com/torvalds/linux/commit/36374583f9084cdab4b5dcf5521a3ce55bebb9fa

The commit ensures the override doesn't get cleared before the watchdog has had an opportunity to check if the clocksource is stable or not. However, if the clocksource is known to be unstable at this point in time, it will clear the override and return to the default.

This is a clean cherry-pick to the Xenial 4.4 kernel.

[Testcase]

Start up a KVM VM, possibly enable invtsc on the QEMU command line.

The default clocksource will be kvm-clock:

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

If you set the kernel command line to:

GRUB_CMDLINE_LINUX_DEFAULT="clocksource=tsc"

If you reboot, you will see the incorrect option of kvm-clock:

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

There is a test kernel available in the below ppa, with the commit applied:

https://launchpad.net/~mruffell/+archive/ubuntu/sf291501-test

If you install the test kernel, and leave the kernel command line as:

GRUB_CMDLINE_LINUX_DEFAULT="clocksource=tsc"

You will get the requested clocksource:

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
tsc

You will also get the following in dmesg:

$ dmesg | grep defer
[ 1.002599] clocksource: Override clocksource tsc is not currently HRT compatible - deferring

[Regression Potential]

This commit changes how the kernel treats clocksource overrides. If any users have an override set, but the kernel is clearing the override and returning to the default, when they install a patched kernel, they will change over to their requested override, which may come as a surprise.

If there is a regression, it will only affect systems who have clocksource overrides in place, and in the worst case, will revert the system to its default clocksource if the selected clocksource override is found to be unstable.

The commit is well tested, and should not cause any regressions.

CVE References

Changed in linux (Ubuntu Xenial):
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Matthew Ruffell (mruffell)
description: updated
tags: added: sts
Changed in linux (Ubuntu):
status: New → Fix Released
description: updated
Changed in linux (Ubuntu Xenial):
status: In Progress → Fix Committed
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote :

This bug is awaiting verification that the kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification-needed-xenial' to 'verification-done-xenial'. If the problem still exists, change the tag 'verification-needed-xenial' to 'verification-failed-xenial'.

If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.

See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you!

tags: added: verification-needed-xenial
Revision history for this message
Matthew Ruffell (mruffell) wrote :

Performing verification:

First, reproducing on older kernel:

$ uname -rv
4.4.0-190-generic #220-Ubuntu SMP Fri Aug 28 23:02:15 UTC 2020
$ grep "clocksource" /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="clocksource=tsc"
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.4.0-190-generic root=UUID=f6c72a0a-003a-4b81-9550-ba49a547e32d ro clocksource=tsc
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

kvm-clock is the default, even though we explicitly asked for tsc. We can reproduce.

Now, I enabled -proposed and installed 4.4.0-191-generic:

$ uname -rv
4.4.0-191-generic #221-Ubuntu SMP Fri Sep 18 13:34:04 UTC 2020
$ grep "clocksource" /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="clocksource=tsc"
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.4.0-191-generic root=UUID=f6c72a0a-003a-4b81-9550-ba49a547e32d ro clocksource=tsc
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
tsc
$ dmesg | grep defer
[ 0.870439] clocksource: Override clocksource tsc is not currently HRT compatible - deferring

We have our requested clocksource, tsc, and we did not need to force override the reliability checks from the watchdog.

The kernel in -proposed, 4.4.0-191-generic, fixes the problem, and I am happy to mark the bug verified.

tags: added: verification-done-xenial
removed: verification-needed-xenial
Revision history for this message
Launchpad Janitor (janitor) wrote :
Download full text (11.7 KiB)

This bug was fixed in the package linux - 4.4.0-193.224

---------------
linux (4.4.0-193.224) xenial; urgency=medium

  * CVE-2020-16119
    - SAUCE: dccp: avoid double free of ccid on child socket

linux (4.4.0-192.222) xenial; urgency=medium

  * xenial/linux: 4.4.0-192.222 -proposed tracker (LP: #1897734)

  * mwifiex stops working after kernel upgrade (LP: #1897299)
    - mwifiex: Increase AES key storage size to 256 bits

  * xenial 4.4.0-191-generic in -proposed has a regression (LP: #1896725)
    - Revert "XEN uses irqdesc::irq_data_common::handler_data to store a per
      interrupt XEN data pointer which contains XEN specific information."

linux (4.4.0-191.221) xenial; urgency=medium

  * xenial/linux: 4.4.0-191.221 -proposed tracker (LP: #1896067)

  * Novalink (mkvterm command failure) (LP: #1892546)
    - tty: hvcs: Don't NULL tty->driver_data until hvcs_cleanup()

  * Xenial update: v4.4.236 upstream stable release (LP: #1895891)
    - HID: core: Correctly handle ReportSize being zero
    - HID: core: Sanitize event code and type when mapping input
    - perf record/stat: Explicitly call out event modifiers in the documentation
    - mm, page_alloc: remove unnecessary variable from free_pcppages_bulk
    - hwmon: (applesmc) check status earlier.
    - ceph: don't allow setlease on cephfs
    - s390: don't trace preemption in percpu macros
    - xen/xenbus: Fix granting of vmalloc'd memory
    - dmaengine: of-dma: Fix of_dma_router_xlate's of_dma_xlate handling
    - batman-adv: Avoid uninitialized chaddr when handling DHCP
    - batman-adv: bla: use netif_rx_ni when not in interrupt context
    - dmaengine: at_hdmac: check return value of of_find_device_by_node() in
      at_dma_xlate()
    - netfilter: nf_tables: incorrect enum nft_list_attributes definition
    - netfilter: nf_tables: fix destination register zeroing
    - dmaengine: pl330: Fix burst length if burst size is smaller than bus width
    - bnxt_en: Check for zero dir entries in NVRAM.
    - fix regression in "epoll: Keep a reference on files added to the check list"
    - tg3: Fix soft lockup when tg3_reset_task() fails.
    - iommu/vt-d: Serialize IOMMU GCMD register modifications
    - thermal: ti-soc-thermal: Fix bogus thermal shutdowns for omap4430
    - include/linux/log2.h: add missing () around n in roundup_pow_of_two()
    - btrfs: drop path before adding new uuid tree entry
    - btrfs: Remove redundant extent_buffer_get in get_old_root
    - btrfs: Remove extraneous extent_buffer_get from tree_mod_log_rewind
    - btrfs: set the lockdep class for log tree extent buffers
    - uaccess: Add non-pagefault user-space read functions
    - uaccess: Add non-pagefault user-space write function
    - btrfs: fix potential deadlock in the search ioctl
    - net: qmi_wwan: MDM9x30 specific power management
    - net: qmi_wwan: support "raw IP" mode
    - net: qmi_wwan: should hold RTNL while changing netdev type
    - net: qmi_wwan: ignore bogus CDC Union descriptors
    - Add Dell Wireless 5809e Gobi 4G HSPA+ Mobile Broadband Card (rev3) to
      qmi_wwan
    - qmi_wwan: Added support for Gemalto's Cinterion PHxx WWAN interface
    - qmi_wwan: add support for Quec...

Changed in linux (Ubuntu Xenial):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.