kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@parallels.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: <kvm@vger.kernel.org>, <johnstul@us.ibm.com>, <jeremy@goop.org>,
	<zamsden@gmail.com>, <gleb@redhat.com>, <avi@redhat.com>,
	<pbonzini@redhat.com>
Subject: Re: [patch 02/18] x86: kvmclock: allocate pvclock shared memory area
Date: Thu, 15 Nov 2012 21:05:55 +0400	[thread overview]
Message-ID: <50A520F3.8060105@parallels.com> (raw)
In-Reply-To: <20121115000944.034452554@redhat.com>

On 11/15/2012 04:08 AM, Marcelo Tosatti wrote:
> We want to expose the pvclock shared memory areas, which 
> the hypervisor periodically updates, to userspace.
> 
> For a linear mapping from userspace, it is necessary that
> entire page sized regions are used for array of pvclock 
> structures.
> 
> There is no such guarantee with per cpu areas, therefore move
> to memblock_alloc based allocation.
Ok.

> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
For the concept:

Acked-by: Glauber Costa <glommer@parallels.com>

I do have one comment.

> 
> Index: vsyscall/arch/x86/kernel/kvmclock.c
> ===================================================================
> --- vsyscall.orig/arch/x86/kernel/kvmclock.c
> +++ vsyscall/arch/x86/kernel/kvmclock.c
> @@ -23,6 +23,7 @@
>  #include <asm/apic.h>
>  #include <linux/percpu.h>
>  #include <linux/hardirq.h>
> +#include <linux/memblock.h>
>  
>  #include <asm/x86_init.h>
>  #include <asm/reboot.h>
> @@ -39,7 +40,11 @@ static int parse_no_kvmclock(char *arg)
>  early_param("no-kvmclock", parse_no_kvmclock);
>  
>  /* The hypervisor will put information about time periodically here */
> -static DEFINE_PER_CPU_SHARED_ALIGNED(struct pvclock_vcpu_time_info, hv_clock);
> +struct pvclock_aligned_vcpu_time_info {
> +	struct pvclock_vcpu_time_info clock;
> +} __attribute__((__aligned__(SMP_CACHE_BYTES)));
> +
> +static struct pvclock_aligned_vcpu_time_info *hv_clock;
>  static struct pvclock_wall_clock wall_clock;
>  
>  /*
> @@ -52,15 +57,20 @@ static unsigned long kvm_get_wallclock(v
>  	struct pvclock_vcpu_time_info *vcpu_time;
>  	struct timespec ts;
>  	int low, high;
> +	int cpu;
> +
> +	preempt_disable();
> +	cpu = smp_processor_id();
>  
>  	low = (int)__pa_symbol(&wall_clock);
>  	high = ((u64)__pa_symbol(&wall_clock) >> 32);
>  
>  	native_write_msr(msr_kvm_wall_clock, low, high);
>  
> -	vcpu_time = &get_cpu_var(hv_clock);
> +	vcpu_time = &hv_clock[cpu].clock;


You are leaving preempt disabled for a lot longer than in should be. In
particular, you'll have a round trip to the hypervisor in the middle. It
doesn't matter *that* much because wallclock is mostly a one-time thing,
so I won't oppose in this basis.

But if you have the chance, either fix it, or tell us why you need
preemption on for longer than it was before.

>  void __init kvmclock_init(void)
>  {
> +	unsigned long mem;
> +
>  	if (!kvm_para_available())
>  		return;
>  
> +	mem = memblock_alloc(sizeof(struct pvclock_aligned_vcpu_time_info) * NR_CPUS,
> +			     PAGE_SIZE);
> +	if (!mem)
> +		return;
> +	hv_clock = __va(mem);
> +
>  	if (kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) {
>  		msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW;
>  		msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW;
> 
>
If you don't have kvmclock enabled, which the next line in here would
test for, you will exit this function with allocated memory. How about
the following?

if (kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) {
    msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW;
    msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW;
} else if (!(kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)))
    return;

mem = memblock_alloc(sizeof(struct pvclock_aligned_vcpu_time_info)
                     * NR_CPUS, PAGE_SIZE);
if (!mem)
    return;
hv_clock = __va(mem);

printk(KERN_INFO "kvm-clock: Using msrs %x and %x",
       msr_kvm_system_time, msr_kvm_wall_clock);

if (kvm_register_clock("boot clock")) {
    memblock_free();
    return;
}





  reply	other threads:[~2012-11-15  9:05 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-15  0:08 [patch 00/18] pvclock vsyscall support + KVM hypervisor support (v4) Marcelo Tosatti
2012-11-15  0:08 ` [patch 01/18] KVM: x86: retain pvclock guest stopped bit in guest memory Marcelo Tosatti
2012-11-15  0:08 ` [patch 02/18] x86: kvmclock: allocate pvclock shared memory area Marcelo Tosatti
2012-11-15 17:05   ` Glauber Costa [this message]
2012-11-16  2:07     ` [patch 02/18] x86: kvmclock: allocate pvclock shared memory area (v2) Marcelo Tosatti
2012-11-16  7:06       ` Glauber Costa
2012-11-15  0:08 ` [patch 03/18] x86: pvclock: make sure rdtsc doesnt speculate out of region Marcelo Tosatti
2012-11-15  0:08 ` [patch 04/18] x86: pvclock: remove pvclock_shadow_time Marcelo Tosatti
2012-11-15  0:08 ` [patch 05/18] x86: pvclock: create helper for pvclock data retrieval Marcelo Tosatti
2012-11-15 12:27   ` Glauber Costa
2012-11-15  0:08 ` [patch 06/18] x86: pvclock: introduce helper to read flags Marcelo Tosatti
2012-11-15 12:28   ` Glauber Costa
2012-11-15  0:08 ` [patch 07/18] x86: pvclock: add note about rdtsc barriers Marcelo Tosatti
2012-11-15 12:30   ` Glauber Costa
2012-11-16  2:05     ` [patch 07/18] x86: pvclock: add note about rdtsc barriers (v2) Marcelo Tosatti
2012-11-15  0:08 ` [patch 08/18] sched: add notifier for cross-cpu migrations Marcelo Tosatti
2012-11-15  7:01   ` Gleb Natapov
2012-11-15  0:08 ` [patch 09/18] x86: pvclock: generic pvclock vsyscall initialization Marcelo Tosatti
2012-11-15  0:08 ` [patch 10/18] x86: kvm guest: pvclock vsyscall support Marcelo Tosatti
2012-11-15  0:08 ` [patch 11/18] x86: vdso: pvclock gettime support Marcelo Tosatti
2012-11-15  0:08 ` [patch 12/18] KVM: x86: pass host_tsc to read_l1_tsc Marcelo Tosatti
2012-11-15  0:08 ` [patch 13/18] time: export time information for KVM pvclock Marcelo Tosatti
2012-11-15  1:38   ` John Stultz
2012-11-15  0:08 ` [patch 14/18] KVM: x86: notifier for clocksource changes Marcelo Tosatti
2012-11-15  0:08 ` [patch 15/18] KVM: x86: implement PVCLOCK_TSC_STABLE_BIT pvclock flag Marcelo Tosatti
2012-11-15  0:08 ` [patch 16/18] KVM: x86: add kvm_arch_vcpu_postcreate callback, move TSC initialization Marcelo Tosatti
2012-11-15  0:08 ` [patch 17/18] KVM: x86: require matched TSC offsets for master clock Marcelo Tosatti
2012-11-15  0:08 ` [patch 18/18] KVM: x86: update pvclock area conditionally, on cpu migration Marcelo Tosatti
2012-11-15 12:34   ` Glauber Costa
2012-11-19 21:57 ` [patch 00/18] pvclock vsyscall support + KVM hypervisor support (v5) Marcelo Tosatti
2012-11-19 21:57   ` [patch 01/18] KVM: x86: retain pvclock guest stopped bit in guest memory Marcelo Tosatti
2012-11-19 21:58   ` [patch 02/18] x86: kvmclock: allocate pvclock shared memory area Marcelo Tosatti
2012-11-19 21:58   ` [patch 03/18] x86: pvclock: make sure rdtsc doesnt speculate out of region Marcelo Tosatti
2012-11-19 21:58   ` [patch 04/18] x86: pvclock: remove pvclock_shadow_time Marcelo Tosatti
2012-11-19 21:58   ` [patch 05/18] x86: pvclock: create helper for pvclock data retrieval Marcelo Tosatti
2012-11-19 21:58   ` [patch 06/18] x86: pvclock: introduce helper to read flags Marcelo Tosatti
2012-11-19 21:58   ` [patch 07/18] x86: pvclock: add note about rdtsc barriers Marcelo Tosatti
2012-11-19 21:58   ` [patch 08/18] sched: add notifier for cross-cpu migrations Marcelo Tosatti
2012-11-19 21:58   ` [patch 09/18] x86: pvclock: generic pvclock vsyscall initialization Marcelo Tosatti
2012-11-19 21:58   ` [patch 11/18] x86: vdso: pvclock gettime support Marcelo Tosatti
2012-11-19 21:58   ` [patch 12/18] KVM: x86: pass host_tsc to read_l1_tsc Marcelo Tosatti
2012-11-19 21:58   ` [patch 13/18] time: export time information for KVM pvclock Marcelo Tosatti
2012-11-19 21:58   ` [patch 14/18] KVM: x86: notifier for clocksource changes Marcelo Tosatti
2012-11-19 21:58   ` [patch 15/18] KVM: x86: implement PVCLOCK_TSC_STABLE_BIT pvclock flag Marcelo Tosatti
2012-11-19 21:58   ` [patch 16/18] KVM: x86: add kvm_arch_vcpu_postcreate callback, move TSC initialization Marcelo Tosatti
2012-11-19 21:58   ` [patch 17/18] KVM: x86: require matched TSC offsets for master clock Marcelo Tosatti
2012-11-19 21:58   ` [patch 18/18] KVM: x86: update pvclock area conditionally, on cpu migration Marcelo Tosatti
2012-11-20  9:01     ` Glauber Costa
2012-11-20  9:03   ` [patch 00/18] pvclock vsyscall support + KVM hypervisor support (v5) Glauber Costa

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=50A520F3.8060105@parallels.com \
    --to=glommer@parallels.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=jeremy@goop.org \
    --cc=johnstul@us.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=zamsden@gmail.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;
as well as URLs for NNTP newsgroup(s).