From: Avi Kivity <avi@redhat.com>
To: Sheng Yang <sheng@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 2/4] KVM: Extended shared_msr_global to per CPU
Date: Wed, 16 Dec 2009 11:21:38 +0200 [thread overview]
Message-ID: <4B28A6A2.3090802@redhat.com> (raw)
In-Reply-To: <1260942485-19156-3-git-send-email-sheng@linux.intel.com>
On 12/16/2009 07:48 AM, Sheng Yang wrote:
> shared_msr_global saved host value of relevant MSRs, but it have an
> assumption that all MSRs it tracked shared the value across the different
> CPUs. It's not true with some MSRs, e.g. MSR_TSC_AUX.
>
> Extend it to per CPU to provide the support of MSR_TSC_AUX, and more
> alike MSRs.
>
> Notice now the shared_msr_global still have one assumption: it can only deal
> with the MSRs that won't change in host after KVM module loaded.
>
>
>
> -void kvm_define_shared_msr(unsigned slot, u32 msr)
> +static void shared_msr_update(void *data)
> {
> - int cpu;
> + struct kvm_shared_msrs *smsr;
> + u32 msr = *(u32 *)data;
> + int slot;
> u64 value;
>
> + smsr =&get_cpu_var(shared_msrs);
>
Can use __get_cpu_var() since interrupts are disabled.
> + /* only read, and nobody should modify it at this time,
> + * so don't need lock */
> + for (slot = 0; slot< shared_msrs_global.nr; slot++)
> + if (shared_msrs_global.msrs[slot] == msr)
> + break;
> + if (slot>= shared_msrs_global.nr) {
> + printk(KERN_ERR "kvm: can't find the defined MSR!");
> + return;
> + }
> + rdmsrl_safe(msr,&value);
> + smsr->values[slot].host = value;
> + smsr->values[slot].curr = value;
> + put_cpu_var(shared_msrs);
> +}
> +
> +void kvm_define_shared_msr(unsigned slot, u32 msr)
> +{
> if (slot>= shared_msrs_global.nr)
> shared_msrs_global.nr = slot + 1;
> - shared_msrs_global.msrs[slot].msr = msr;
> - rdmsrl_safe(msr,&value);
> - shared_msrs_global.msrs[slot].value = value;
> - for_each_online_cpu(cpu)
> - per_cpu(shared_msrs, cpu).current_value[slot] = value;
> + shared_msrs_global.msrs[slot] = msr;
> + /* we need ensured the shared_msr_global have been updated */
> + smp_wmb();
> + smp_call_function(shared_msr_update,&msr, 1);
>
on_each_cpu() is preferred.
> + shared_msr_update(&msr);
> }
> EXPORT_SYMBOL_GPL(kvm_define_shared_msr);
>
> static void kvm_shared_msr_cpu_online(void)
> {
> unsigned i;
> - struct kvm_shared_msrs *locals =&__get_cpu_var(shared_msrs);
> + struct kvm_shared_msrs *smsr =&__get_cpu_var(shared_msrs);
>
> for (i = 0; i< shared_msrs_global.nr; ++i)
> - locals->current_value[i] = shared_msrs_global.msrs[i].value;
> + smsr->values[i].curr = smsr->values[i].host;
>
If the cpu is being onlined for the first time, then .host will not have
been initialized. Need to call shared_msr_update().
Also need to verify this is called after all the msrs have been
initialized by the kernel, or we'll read default values.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2009-12-16 9:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-16 5:48 [PATCH 0/4] Add support for RDTSCP in VMX Sheng Yang
2009-12-16 5:48 ` [PATCH 1/4] KVM: VMX: Remove redundant variable Sheng Yang
2009-12-16 5:48 ` [PATCH 2/4] KVM: Extended shared_msr_global to per CPU Sheng Yang
2009-12-16 9:21 ` Avi Kivity [this message]
2009-12-17 9:32 ` Sheng Yang
2009-12-17 10:32 ` Avi Kivity
2009-12-17 15:01 ` Sheng Yang
2009-12-17 15:06 ` Avi Kivity
2009-12-16 5:48 ` [PATCH 3/4] x86: Add IA32_TSC_AUX MSR Sheng Yang
2009-12-16 8:20 ` [tip:x86/urgent] x86: Add IA32_TSC_AUX MSR and use it tip-bot for Sheng Yang
2009-12-16 5:48 ` [PATCH 4/4] KVM: VMX: Add instruction rdtscp support for guest Sheng Yang
2009-12-16 9:47 ` Avi Kivity
2009-12-17 9:33 ` Sheng Yang
2009-12-17 10:39 ` Avi Kivity
2009-12-17 14:52 ` Sheng Yang
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=4B28A6A2.3090802@redhat.com \
--to=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=sheng@linux.intel.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 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.