All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Glauber de Oliveira Costa <gcosta@redhat.com>
Cc: kvm-devel@lists.sourceforge.net, chrisw@sous-sol.org
Subject: Re: [PATCH 1/2] kvmclock - the host part.
Date: Wed, 13 Feb 2008 12:49:42 +0200	[thread overview]
Message-ID: <47B2CB46.1090804@qumranet.com> (raw)
In-Reply-To: <1202753274-15252-2-git-send-email-gcosta@redhat.com>

Glauber de Oliveira Costa wrote:
> This is the host part of kvm clocksource implementation. As it does
> not include clockevents, it is a fairly simple implementation. We
> only have to register a per-vcpu area, and start writting to it periodically.
>
> The area is binary compatible with xen, as we use the same shadow_info structure.
>
>   

> +static void kvm_write_wall_clock(struct kvm_vcpu *v, gpa_t wall_clock)
> +{
> +	int version = 1;
> +	struct kvm_wall_clock wc;
> +	unsigned long flags;
> +	struct timespec wc_ts;
> +
> +	local_irq_save(flags);
> +	kvm_get_msr(v, MSR_IA32_TIME_STAMP_COUNTER,
> +			  &v->arch.hv_clock.tsc_timestamp);
>   

Why is this needed? IIRC the wall clock is not tied to any vcpu.

If we can remove this, the argument to the function should be kvm, not 
kvm_vcpu. We can remove the irq games as well.

> +	wc_ts = current_kernel_time();
> +	local_irq_restore(flags);
> +
> +	down_write(&current->mm->mmap_sem);
> +	kvm_write_guest(v->kvm, wall_clock, &version, sizeof(version));
> +	up_write(&current->mm->mmap_sem);
>   

Why down_write? accidentally or on purpose?

For mutual exclusion, I suggest taking kvm->lock instead (for the entire 
function).

> +
> +	/* With all the info we got, fill in the values */
> +	wc.wc_sec = wc_ts.tv_sec;
> +	wc.wc_nsec = wc_ts.tv_nsec;
> +	wc.wc_version = ++version;
> +
> +	down_write(&current->mm->mmap_sem);
> +	kvm_write_guest(v->kvm, wall_clock, &wc, sizeof(wc));
> +	up_write(&current->mm->mmap_sem);
>   

Should be in three steps: write version, write data, write version. 
kvm_write_guest doesn't guarantee any order. It may fail as well, and we 
need to handle that.

>  
> +/* xen binary-compatible interface. See xen headers for details */
> +struct kvm_vcpu_time_info {
> +	uint32_t version;
> +	uint32_t pad0;
> +	uint64_t tsc_timestamp;
> +	uint64_t system_time;
> +	uint32_t tsc_to_system_mul;
> +	int8_t   tsc_shift;
> +}; /* 32 bytes */
> +
> +struct kvm_wall_clock {
> +	uint32_t wc_version;
> +	uint32_t wc_sec;
> +	uint32_t wc_nsec;
> +};
> +
>   

These structures are dangerously sized. __Suggest__ 
__attribute__((__packed__)). (or some padding at the end of 
kvm_vcpu_time_info.

> diff --git a/include/linux/kvm.h b/include/linux/kvm.h
> index 4de4fd2..78ce53f 100644
> --- a/include/linux/kvm.h
> +++ b/include/linux/kvm.h
> @@ -232,6 +232,7 @@ #define KVM_CAP_USER_MEMORY 3
>  #define KVM_CAP_SET_TSS_ADDR 4
>  #define KVM_CAP_EXT_CPUID 5
>  #define KVM_CAP_VAPIC 6
> +#define KVM_CAP_CLOCKSOURCE 7
>  
>   

Please refresh against kvm.git, this has changed a bit.

-- 
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  parent reply	other threads:[~2008-02-13 10:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-11 18:07 [PATCH 0/2] kvm clock - merge last comments Glauber de Oliveira Costa
2008-02-11 18:07 ` [PATCH 1/2] kvmclock - the host part Glauber de Oliveira Costa
2008-02-11 18:07   ` [PATCH 2/2] kvmclock implementation, the guest part Glauber de Oliveira Costa
2008-02-13 10:49   ` Avi Kivity [this message]
2008-02-13 21:45     ` [PATCH 1/2] kvmclock - the host part Glauber Costa
2008-02-14  9:21       ` Avi Kivity
2008-02-18 14:06     ` Marcelo Tosatti
  -- strict thread matches above, loose matches on Subject: below --
2008-01-16 16:31 [PATCH 0/2] kvm clock - xen compatible by accident Glauber de Oliveira Costa
     [not found] ` <1200501067774-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-01-16 16:31   ` [PATCH 1/2] kvmclock - the host part Glauber de Oliveira Costa
     [not found]     ` <12005010761561-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-01-16 19:00       ` Anthony Liguori
     [not found]         ` <478E544C.4020603-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2008-01-17  0:18           ` Glauber de Oliveira Costa
2008-01-17  7:59       ` Gerd Hoffmann
2008-01-20 15:37       ` Avi Kivity
2008-01-20 15:38       ` Avi Kivity

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=47B2CB46.1090804@qumranet.com \
    --to=avi@qumranet.com \
    --cc=chrisw@sous-sol.org \
    --cc=gcosta@redhat.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.