public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Zhimin Feng <fengzhimin@bytedance.com>,
	x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com,
	wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org,
	mingo@redhat.com, bp@alien8.de, hpa@zytor.com,
	fweisbec@gmail.com, zhouyibo@bytedance.com,
	zhanghaozhong@bytedance.com,
	Zhimin Feng <fengzhimin@bytedance.com>
Subject: Re: [RFC: timer passthrough 1/9] KVM: vmx: hook set_next_event for getting the host tscd
Date: Fri, 05 Feb 2021 19:11:58 +0100	[thread overview]
Message-ID: <87ft2a8jv5.fsf@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20210205100317.24174-2-fengzhimin@bytedance.com>

On Fri, Feb 05 2021 at 18:03, Zhimin Feng wrote:
> @@ -520,6 +521,24 @@ struct kvm_vcpu_hv {
>  	cpumask_t tlb_flush;
>  };
>  
> +enum tick_device_mode {
> +	TICKDEV_MODE_PERIODIC,
> +	TICKDEV_MODE_ONESHOT,
> +};
> +
> +struct tick_device {
> +	struct clock_event_device *evtdev;
> +	enum tick_device_mode mode;
> +};

There is a reason why these things are defined in a header file which is
not public. Nothing outside of kernel/time/ has to fiddle with
this. Aside of that how are these things supposed to stay in sync?

> diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
> index 6c9c342dd0e5..bc50f4a1a7c0 100644
> --- a/kernel/time/tick-common.c
> +++ b/kernel/time/tick-common.c
> @@ -26,6 +26,7 @@
>   * Tick devices
>   */
>  DEFINE_PER_CPU(struct tick_device, tick_cpu_device);
> +EXPORT_SYMBOL_GPL(tick_cpu_device);

Not going to happen ever.

> +#define TSC_DIVISOR  8
> +static DEFINE_PER_CPU(struct timer_passth_info, passth_info);
> +
> +static int override_lapic_next_event(unsigned long delta,
> +		struct clock_event_device *evt)
> +{
> +	struct timer_passth_info *local_timer_info;
> +	u64 tsc;
> +	u64 tscd;
> +
> +	local_timer_info = &per_cpu(passth_info, smp_processor_id());
> +	tsc = rdtsc();
> +	tscd = tsc + (((u64) delta) * TSC_DIVISOR);
> +	local_timer_info->host_tscd = tscd;
> +	wrmsrl(MSR_IA32_TSCDEADLINE, tscd);
> +	return 0;
> +}
> +
> +static void vmx_host_timer_passth_init(void *junk)
> +{
> +	struct timer_passth_info *local_timer_info;
> +	int cpu = smp_processor_id();
> +
> +	local_timer_info = &per_cpu(passth_info, cpu);
> +	local_timer_info->curr_dev = per_cpu(tick_cpu_device, cpu).evtdev;
> +	local_timer_info->orig_set_next_event =
> +		local_timer_info->curr_dev->set_next_event;
> +	local_timer_info->curr_dev->set_next_event = override_lapic_next_event;

So when loading the KVM module you steal the set_next_event pointer of
the clock event device which is currently active. What guarantees that

    1) The current active device is the tsc deadline timer
    2) The active device does not change

Nothing.

Thanks,

        tglx

  parent reply	other threads:[~2021-02-05 18:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 10:03 [RESEND RFC: timer passthrough 0/9] Support timer passthrough for VM Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 1/9] KVM: vmx: hook set_next_event for getting the host tscd Zhimin Feng
2021-02-05 12:28   ` Peter Zijlstra
2021-02-05 18:11   ` Thomas Gleixner [this message]
2021-02-23 13:07     ` [External] " Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 2/9] KVM: vmx: enable host lapic timer offload preemtion timer Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 3/9] KVM: vmx: enable passthrough timer to guest Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 4/9] KVM: vmx: enable passth timer switch to sw timer Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 5/9] KVM: vmx: use tsc_adjust to enable tsc_offset timer passthrough Zhimin Feng
2021-02-05 12:43   ` Peter Zijlstra
2021-02-05 18:22     ` Thomas Gleixner
2021-02-05 10:03 ` [RFC: timer passthrough 6/9] KVM: vmx: check enable_timer_passth strictly Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 7/9] KVM: vmx: save the initial value of host tscd Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 8/9] KVM: vmx: Dynamically open or close the timer-passthrough for pre-vm Zhimin Feng
2021-02-05 10:03 ` [RFC: timer passthrough 9/9] KVM: vmx: query the state of timer-passth for vm Zhimin Feng
2021-02-05 13:34 ` [RESEND RFC: timer passthrough 0/9] Support timer passthrough for VM Paolo Bonzini
2021-02-08 18:13 ` Konrad Rzeszutek Wilk
2021-02-23 13:31   ` [External] " Zhimin Feng

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=87ft2a8jv5.fsf@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=bp@alien8.de \
    --cc=fengzhimin@bytedance.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    --cc=zhanghaozhong@bytedance.com \
    --cc=zhouyibo@bytedance.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