From: kernel test robot <lkp@intel.com>
To: David Woodhouse <dwmw@amazon.co.uk>
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
Sean Christopherson <seanjc@google.com>
Subject: [sean-jc:x86/host_kvmclock_mess 14/15] arch/x86/kvm/x86.c:1875:26: warning: variable 'master_ns' is uninitialized when used here
Date: Thu, 30 Jul 2026 07:10:35 +0200 [thread overview]
Message-ID: <202607300751.31hStxN9-lkp@intel.com> (raw)
tree: https://github.com/sean-jc/linux x86/host_kvmclock_mess
head: 1874dce49fd558c97bf46e9d2a7e635c5158f74a
commit: a7428fb09dd20b70ce3619c430eb42e6f298a503 [14/15] KVM: x86: Upscalte TSC to "now", not master clock when updating PV clocks
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260730/202607300751.31hStxN9-lkp@intel.com/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260730/202607300751.31hStxN9-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202607300751.31hStxN9-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> arch/x86/kvm/x86.c:1875:26: warning: variable 'master_ns' is uninitialized when used here [-Wuninitialized]
1875 | hv_clock.system_time = master_ns + v->kvm->arch.kvmclock_offset;
| ^~~~~~~~~
arch/x86/kvm/x86.c:1782:64: note: initialize the variable 'master_ns' to silence this warning
1782 | u64 tgt_tsc_hz, tsc_timestamp, host_tsc, master_tsc, master_ns;
| ^
| = 0
1 warning generated.
vim +/master_ns +1875 arch/x86/kvm/x86.c
1779
1780 int kvm_guest_time_update(struct kvm_vcpu *v)
1781 {
1782 u64 tgt_tsc_hz, tsc_timestamp, host_tsc, master_tsc, master_ns;
1783 struct pvclock_vcpu_time_info hv_clock = {};
1784 struct kvm_vcpu_arch *vcpu = &v->arch;
1785 s64 kernel_ns;
1786
1787 /*
1788 * If the host uses TSC clock, then passthrough TSC as stable
1789 * to the guest.
1790 */
1791 #ifdef CONFIG_X86_64
1792 struct kvm_arch *ka = &v->kvm->arch;
1793 bool use_master_clock;
1794 unsigned seq;
1795
1796 do {
1797 seq = read_seqcount_begin(&ka->pvclock_sc);
1798 use_master_clock = ka->use_master_clock;
1799 if (!use_master_clock)
1800 continue;
1801
1802 if (!kvm_get_time_and_clockread(&kernel_ns, &host_tsc)) {
1803 use_master_clock = false;
1804 continue;
1805 }
1806
1807 master_tsc = ka->master_cycle_now;
1808 kernel_ns = ka->master_kernel_ns;
1809 } while (read_seqcount_retry(&ka->pvclock_sc, seq));
1810 #else
1811 const bool use_master_clock = false;
1812 #endif
1813 /*
1814 * Ensure reading the TSC+frequency pair is done on the same CPU. When
1815 * NOT using the master clock, the TSC frequency may vary between CPUs.
1816 */
1817 preempt_disable();
1818 tgt_tsc_hz = (u64)get_cpu_tsc_khz() * HZ_PER_KHZ;
1819 if (unlikely(tgt_tsc_hz == 0)) {
1820 preempt_enable();
1821 kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);
1822 return 1;
1823 }
1824 if (!use_master_clock) {
1825 host_tsc = rdtsc();
1826 kernel_ns = get_kvmclock_base_ns();
1827 }
1828
1829 tsc_timestamp = kvm_read_l1_tsc(v, host_tsc);
1830
1831 /*
1832 * We may have to catch up the TSC to match elapsed wall clock
1833 * time for two reasons, even if kvmclock is used.
1834 * 1) CPU could have been running below the maximum TSC rate
1835 * 2) Broken TSC compensation resets the base at each VCPU
1836 * entry to avoid unknown leaps of TSC even when running
1837 * again on the same CPU. This may cause apparent elapsed
1838 * time to disappear, and the guest to stand still or run
1839 * very slowly.
1840 */
1841 if (vcpu->tsc_catchup) {
1842 u64 tsc = compute_guest_tsc(v, kernel_ns);
1843 if (tsc > tsc_timestamp) {
1844 adjust_tsc_offset_guest(v, tsc - tsc_timestamp);
1845 tsc_timestamp = tsc;
1846 }
1847 }
1848
1849 preempt_enable();
1850
1851 /* With all the info we got, fill in the values */
1852
1853 if (kvm_caps.has_tsc_control) {
1854 tgt_tsc_hz = kvm_scale_tsc(tgt_tsc_hz,
1855 v->arch.l1_tsc_scaling_ratio);
1856 tgt_tsc_hz = tgt_tsc_hz ? : 1;
1857 }
1858
1859 if (unlikely(vcpu->hw_tsc_hz != tgt_tsc_hz)) {
1860 kvm_get_time_scale(NSEC_PER_SEC, tgt_tsc_hz,
1861 &vcpu->pvclock_tsc_shift,
1862 &vcpu->pvclock_tsc_mul);
1863 vcpu->hw_tsc_hz = tgt_tsc_hz;
1864 }
1865
1866 hv_clock.tsc_shift = vcpu->pvclock_tsc_shift;
1867 hv_clock.tsc_to_system_mul = vcpu->pvclock_tsc_mul;
1868 /*
1869 * If the master clock is NOT in use, the reference time placed in the
1870 * hv_clock is "now". If master clock is in use, the reference time is
1871 * the master clock's snapshot from some time in the past, not "now".
1872 */
1873 if (use_master_clock) {
1874 hv_clock.tsc_timestamp = kvm_read_l1_tsc(v, master_tsc);
> 1875 hv_clock.system_time = master_ns + v->kvm->arch.kvmclock_offset;
1876 } else {
1877 hv_clock.tsc_timestamp = tsc_timestamp;
1878 hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset;
1879 }
1880 vcpu->last_guest_tsc = tsc_timestamp;
1881
1882 /* If the host uses TSC clocksource, then it is stable */
1883 hv_clock.flags = 0;
1884 if (use_master_clock)
1885 hv_clock.flags |= PVCLOCK_TSC_STABLE_BIT;
1886
1887 if (vcpu->pv_time.active) {
1888 /*
1889 * GUEST_STOPPED is only supported by kvmclock, and KVM's
1890 * historic behavior is to only process the request if kvmclock
1891 * is active/enabled.
1892 */
1893 if (vcpu->pvclock_set_guest_stopped_request) {
1894 hv_clock.flags |= PVCLOCK_GUEST_STOPPED;
1895 vcpu->pvclock_set_guest_stopped_request = false;
1896 }
1897 kvm_setup_guest_pvclock(&hv_clock, v, &vcpu->pv_time, 0);
1898
1899 hv_clock.flags &= ~PVCLOCK_GUEST_STOPPED;
1900 }
1901
1902 kvm_hv_setup_tsc_page(v->kvm, &hv_clock);
1903
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
reply other threads:[~2026-07-30 5:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202607300751.31hStxN9-lkp@intel.com \
--to=lkp@intel.com \
--cc=dwmw@amazon.co.uk \
--cc=llvm@lists.linux.dev \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox