public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: David Woodhouse <dwmw2@infradead.org>, kvm@vger.kernel.org
Cc: oe-kbuild-all@lists.linux.dev, Paul Durrant <paul@xen.org>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Dongli Zhang <dongli.zhang@oracle.com>
Subject: Re: [PATCH] KVM: x86/xen: improve accuracy of Xen timers
Date: Sun, 29 Oct 2023 18:37:11 +0800	[thread overview]
Message-ID: <202310291835.JpCiqj3X-lkp@intel.com> (raw)
In-Reply-To: <b5a974bdc330be91c2356f5bb2cc68ef1cc7ed40.camel@infradead.org>

Hi David,

kernel test robot noticed the following build errors:

[auto build test ERROR on kvm/queue]
[also build test ERROR on mst-vhost/linux-next linus/master v6.6-rc7]
[cannot apply to kvm/linux-next next-20231027]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Woodhouse/KVM-x86-xen-improve-accuracy-of-Xen-timers/20231028-020037
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link:    https://lore.kernel.org/r/b5a974bdc330be91c2356f5bb2cc68ef1cc7ed40.camel%40infradead.org
patch subject: [PATCH] KVM: x86/xen: improve accuracy of Xen timers
config: i386-randconfig-014-20231029 (https://download.01.org/0day-ci/archive/20231029/202310291835.JpCiqj3X-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231029/202310291835.JpCiqj3X-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/202310291835.JpCiqj3X-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: arch/x86/kvm/xen.o: in function `kvm_xen_start_timer':
>> arch/x86/kvm/xen.c:171: undefined reference to `kvm_get_monotonic_and_clockread'


vim +171 arch/x86/kvm/xen.c

   147	
   148	static void kvm_xen_start_timer(struct kvm_vcpu *vcpu, u64 guest_abs,
   149					bool linux_wa)
   150	{
   151		uint64_t guest_now, host_tsc, guest_tsc;
   152		int64_t kernel_now, delta;
   153	
   154		/*
   155		 * The guest provides the requested timeout in absolute nanoseconds
   156		 * of the KVM clock — as *it* sees it, based on the scaled TSC and
   157		 * the pvclock information provided by KVM.
   158		 *
   159		 * The kernel doesn't support hrtimers based on CLOCK_MONOTONIC_RAW
   160		 * so use CLOCK_MONOTONIC. In the timescales covered by timers, the
   161		 * difference won't matter much as there is no cumulative effect.
   162		 *
   163		 * Calculate the time for some arbitrary point in time around "now"
   164		 * in terms of both kvmclock and CLOCK_MONOTONIC. Calculate the
   165		 * delta between the kvmclock "now" value and the guest's requested
   166		 * timeout, apply the "Linux workaround" described below, and add
   167		 * the resulting delta to the CLOCK_MONOTONIC "now" value, to get
   168		 * the absolute CLOCK_MONOTONIC time at which the timer should
   169		 * fire.
   170		 */
 > 171		if (!kvm_get_monotonic_and_clockread(&kernel_now, &host_tsc)) {
   172			/*
   173			 * Even in this case, don't fall back to get_kvmclock_ns()
   174			 * because it's broken; it has a systemic error in its
   175			 * results because it scales directly from host TSC to
   176			 * nanoseconds, and doesn't scale first to guest TSC and
   177			 * *then* to nanoseconds as the guest does.
   178			 *
   179			 * There is a small error introduced here because time
   180			 * continues to elapse between the ktime_get() and the
   181			 * subsequent rdtsc().
   182			 */
   183			kernel_now = ktime_get(); /* This is CLOCK_MONOTONIC */
   184			host_tsc = rdtsc();
   185		}
   186	
   187		/* Calculate the guest kvmclock as the guest would do it. */
   188		guest_tsc = kvm_read_l1_tsc(vcpu, host_tsc);
   189		guest_now = __pvclock_read_cycles(&vcpu->arch.hv_clock, guest_tsc);
   190		delta = guest_abs - guest_now;
   191	
   192		/* Xen has a 'Linux workaround' in do_set_timer_op() which
   193		 * checks for negative absolute timeout values (caused by
   194		 * integer overflow), and for values about 13 days in the
   195		 * future (2^50ns) which would be caused by jiffies
   196		 * overflow. For those cases, it sets the timeout 100ms in
   197		 * the future (not *too* soon, since if a guest really did
   198		 * set a long timeout on purpose we don't want to keep
   199		 * churning CPU time by waking it up).
   200		 */
   201		if (linux_wa) {
   202			if ((unlikely((int64_t)guest_abs < 0 ||
   203				      (delta > 0 && (uint32_t) (delta >> 50) != 0)))) {
   204				delta = 100 * NSEC_PER_MSEC;
   205				guest_abs = guest_now + delta;
   206			}
   207		}
   208	
   209		atomic_set(&vcpu->arch.xen.timer_pending, 0);
   210		vcpu->arch.xen.timer_expires = guest_abs;
   211	
   212		if (delta <= 0) {
   213			xen_timer_callback(&vcpu->arch.xen.timer);
   214		} else {
   215			hrtimer_start(&vcpu->arch.xen.timer,
   216				      ktime_add_ns(kernel_now, delta),
   217				      HRTIMER_MODE_ABS_HARD);
   218		}
   219	}
   220	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

       reply	other threads:[~2023-10-29 10:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b5a974bdc330be91c2356f5bb2cc68ef1cc7ed40.camel@infradead.org>
2023-10-29 10:37 ` kernel test robot [this message]
2023-11-02 22:11 ` [PATCH] KVM: x86/xen: improve accuracy of Xen timers kernel test robot
2023-10-30 15:50 David Woodhouse
2023-10-31 10:42 ` Paul Durrant
2023-10-31 11:42   ` David Woodhouse
2023-10-31 12:06     ` Paul Durrant
2023-10-31 12:11       ` David Woodhouse
2023-10-31 12:22         ` Paul Durrant
2023-10-31 16:34           ` David Woodhouse
2023-10-31 19:45 ` David Woodhouse
2023-10-31 22:38   ` David Woodhouse

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=202310291835.JpCiqj3X-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dongli.zhang@oracle.com \
    --cc=dwmw2@infradead.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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