[kvm-devel] extboot usage?

2008-04-03 Thread Jun Koi
Hi,

Could someone please post some concret examples on how to use extboot?
I looked around, but saw nothing.

Thanks,
Jun

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] Бухгалтерский учет в обособлен ных подразделений

2008-04-03 Thread Антонин
Филиалы и oбoсoбленные пoдpазделения

oднoдневный семинаp / 4 апpеля 2008 г. / Мoсква

Пpoгpамма семинаpа: 

1. Пpизнаки oбoсoбленнoгo пoдpазделения пo Налoгoвoму кoдексу poссийскoй 
Федеpации. 
2. Пpoцедуpа pегистpации opганизации в налoгoвыx opганаx пo месту наxoждения 
oбoсoбленнoгo пoдpазделения. 
oфopмление дoкументoв. 
Тpебoвания налoгoвыx opганoв и иx кoнтpoльные меpoпpиятия в oтнoшении филиала и 
пpедставительства 
3. oсoбеннoсти буxгалтеpскoгo и налoгoвoгo учета в opганизацияx, имеющиx 
oбoсoбленные пoдpазделения. 
4. opганизация дoкументooбopoта oпеpаций, пpoвoдимыx чеpез oбoсoбленные 
пoдpазделения. Пoдтвеpждающие пеpвичные дoкументы и авизo. 
5. Пopядoк исчисления и уплаты налoгoв пo филиалу и гoлoвнoй opганизации

Пpoдoлжительнoсть oбучения: с 10 дo 17 часoв (с пеpеpывoм на oбед и кoфе-паузу).
Местo oбучения: г. Мoсква, 5 мин. пешкoм oт м. Академическая.
Стoимoсть oбучения: 4900 pуб. (с НДС). 
(В стoимoсть вxoдит: pаздатoчный матеpиал, кoфе-пауза, oбед в pестopане).

Пpи oтсутствии вoзмoжнoсти пoсетить семинаp, мы пpедлагаем пpиoбpести егo 
видеoвеpсию на DVD/CD дискаx или видеoкассетаx (пpилагается автopский 
pаздатoчный матеpиал). 
Цена видеoкуpса - 3500 pублей, с учетoм НДС.

Для pегистpации на семинаp неoбxoдимo oтпpавить нам пo факсу: pеквизиты 
opганизации, тему и дату семинаpа, пoлнoе ФИo участникoв, кoнтактный телефoн и 
факс. 
Для заказа видеoкуpса неoбxoдимo oтпpавить нам пo факсу: pеквизиты opганизации, 
тему видеoкуpса, указать нoситель (ДВД или СД диски), телефoн, факс, кoнтактнoе 
лицo и тoчный адpес дoставки. 
 
Пoлучить дoпoлнительную инфopмацию и заpегистpиpoваться мoжнo:
пo т/ф: (495) 543-88-46





-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] virtual machines network goes 100Mbit when interface is Gbit

2008-04-03 Thread Miguel Araujo

Hello all,

Thanks for your answer Haydn, but I did not understand the issue too. 
Victor has explained my problem clearly, is kvm uncapable of running the 
bridge at 1GBit if it is not a e1000 network card?


Thanks a lot in advanced,
Miguel

Hello,
I'm not sure if I understand you. Do you mean that the physical
network cards should be e1000 or that the virtual machines must somehow
emulate e1000 network cards?

As I understand Miguel's post, he is finding an issue with the
bridge's speed (two virtual machines running on the same physical
machine are limited to 100 Mbps between themselves).

Best regards,
Víctor


Haydn Solomon escribió:
  
What emulated nic are you using? I think only the e1000 emulated nic 
supports 1 GB.


Miguel Araujo wrote:
  


Hello all,

I'm testing the last kvm version, 62. I was doing an iperf benchmark to 
test the network performance in a Feisty virtual machine and I got 
values surround 100Mbits when my card is actually 1Gbit.  The testing 
environment is conformed by 2 machines, both with Gbit interfaces. The 
vm in kvm is running in server mode, the other (not virtualized one) is 
the client. The vm interface is going to a bridge called br0. Ethtool 
says the interface is running 100Mbits but it doesn't let me change the 
speed or any other parameter in the vm.


I can't either change tap0 parameters in kvm host. ¿Is anyone having the 
same issue?¿am I forgetting something?


Thanks for your time in advanced,
 Miguel

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel
  

  


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel
  




  


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH RFC 1/5]Add some trace enties and define interface for tracing

2008-04-03 Thread Avi Kivity
Liu, Eric E wrote:
> >From d56731ffc6d5742a88a157dfe0e4344d35f7db58 Mon Sep 17 00:00:00 2001
> From: Feng(Eric) Liu <[EMAIL PROTECTED]>
> Date: Mon, 31 Mar 2008 10:08:55 -0400
> Subject: [PATCH] KVM: Add some trace entries in current code and define
> some interfaces for userspace app to contrl and use tracing data.
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 9951ec9..8f70405 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -1794,6 +1794,10 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu,
> int irq)
>  {
>   struct vcpu_vmx *vmx = to_vmx(vcpu);
>  
> + KVMTRACE_1D(INJ_VIRQ, vcpu,
> + (u32)(irq | INTR_TYPE_SOFT_INTR |
> INTR_INFO_VALID_MASK),
> + handler);
> +
>   

Why not just send irq as data?

>   if (vcpu->arch.rmode.active) {
>   vmx->rmode.irq.pending = true;
>   vmx->rmode.irq.vector = irq;
> @@ -1944,6 +1948,7 @@ static int handle_exception(struct kvm_vcpu *vcpu,
> struct kvm_run *kvm_run)
>   error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
>   if (is_page_fault(intr_info)) {
>   cr2 = vmcs_readl(EXIT_QUALIFICATION);
> + KVMTRACE_2D(PAGE_FAULT, vcpu, error_code, (u32)cr2,
> handler);
>   

High order 32 bits of cr2 are lost.

>   return kvm_mmu_page_fault(vcpu, cr2, error_code);
>   }
>  
> @@ -1972,6 +1977,7 @@ static int handle_external_interrupt(struct
> kvm_vcpu *vcpu,
>struct kvm_run *kvm_run)
>  {
>   ++vcpu->stat.irq_exits;
> + KVMTRACE_1D(INTR, vcpu, vmcs_read32(VM_EXIT_INTR_INFO),
> handler);
>   return 1;
>  }
>  
> @@ -2029,6 +2035,8 @@ static int handle_cr(struct kvm_vcpu *vcpu, struct
> kvm_run *kvm_run)
>   reg = (exit_qualification >> 8) & 15;
>   switch ((exit_qualification >> 4) & 3) {
>   case 0: /* mov to cr */
> + KVMTRACE_2D(CR_WRITE, vcpu, (u32)cr,
> (u32)vcpu->arch.regs[reg],
> + handler);
>   

High order bits are lost.

>   if (vmx_set_msr(vcpu, ecx, data) != 0) {
>   kvm_inject_gp(vcpu, 0);
>   return 1;
> @@ -2181,6 +2201,9 @@ static int handle_interrupt_window(struct kvm_vcpu
> *vcpu,
>   cpu_based_vm_exec_control =
> vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
>   cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
>   vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
> cpu_based_vm_exec_control);
> +
> + KVMTRACE_1D(PEND_INTR, vcpu, cpu_based_vm_exec_control,
> handler);
>   

Can record 0 unconditionally here, no?

> @@ -2271,6 +2296,9 @@ static int kvm_handle_exit(struct kvm_run
> *kvm_run, struct kvm_vcpu *vcpu)
>   struct vcpu_vmx *vmx = to_vmx(vcpu);
>   u32 vectoring_info = vmx->idt_vectoring_info;
>  
> + KVMTRACE_2D(VMEXIT, vcpu, exit_reason,
> (u32)vmcs_readl(GUEST_RIP),
> + entryexit);
> +
>   if (unlikely(vmx->fail)) {
>   kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
>   kvm_run->fail_entry.hardware_entry_failure_reason
> @@ -2351,7 +2379,7 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu)
>   enable_irq_window(vcpu);
>   return;
>   }
> -
> + KVMTRACE_1D(INJ_VIRQ, vcpu, idtv_info_field, handler);
>   

Probably need a different marker than INJ_VIRQ, as this is on exit, not 
entry.

>   if (!count) {
>   kvm_x86_ops->skip_emulated_instruction(vcpu);
>   return 1;
> @@ -2428,6 +2445,7 @@ void kvm_arch_exit(void)
>  int kvm_emulate_halt(struct kvm_vcpu *vcpu)
>  {
>   ++vcpu->stat.halt_exits;
> + KVMTRACE_0D(HLT, vcpu, handler);
>   if (irqchip_in_kernel(vcpu->kvm)) {
>   vcpu->arch.mp_state = VCPU_MP_STATE_HALTED;
>   kvm_vcpu_block(vcpu);
>   

Would be nice to have an UNHLT to see how long sleeps are.  But this 
will probably be seen by the irq injection.


-- 
error compiling committee.c: too many arguments to function


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] EMM: disable other notifiers before register and unregister

2008-04-03 Thread Peter Zijlstra
On Wed, 2008-04-02 at 18:24 -0700, Christoph Lameter wrote:
> Ok lets forget about the single theaded thing to solve the registration 
> races. As Andrea pointed out this still has ssues with other subscribed 
> subsystems (and also try_to_unmap). We could do something like what 
> stop_machine_run does: First disable all running subsystems before 
> registering a new one.
> 
> Maybe this is a possible solution.
> 
> 
> Subject: EMM: disable other notifiers before register and unregister
> 
> As Andrea has pointed out: There are races during registration if other
> subsystem notifiers are active while we register a callback.
> 
> Solve that issue by adding two new notifiers:
> 
> emm_stop
>   Stops the notifier operations. Notifier must block on
>   invalidate_start and emm_referenced from this point on.
>   If an invalidate_start has not been completed by a call
>   to invalidate_end then the driver must wait until the
>   operation is complete before returning.
> 
> emm_start
>   Restart notifier operations.

Please use pause and resume or something like that. stop-start is an
unnatural order; we usually start before we stop, whereas we pause first
and resume later.

> Before registration all other subscribed subsystems are stopped.
> Then the new subsystem is subscribed and things can get running
> without consistency issues.
> 
> Subsystems are restarted after the lists have been updated.
> 
> This also works for unregistering. If we can get all subsystems
> to stop then we can also reliably unregister a subsystem. So
> provide that callback.
> 
> Signed-off-by: Christoph Lameter <[EMAIL PROTECTED]>
> 
> ---
>  include/linux/rmap.h |   10 +++---
>  mm/rmap.c|   30 ++
>  2 files changed, 37 insertions(+), 3 deletions(-)
> 
> Index: linux-2.6/include/linux/rmap.h
> ===
> --- linux-2.6.orig/include/linux/rmap.h   2008-04-02 18:16:07.906032549 
> -0700
> +++ linux-2.6/include/linux/rmap.h2008-04-02 18:17:10.291070009 -0700
> @@ -94,7 +94,9 @@ enum emm_operation {
>   emm_release,/* Process exiting, */
>   emm_invalidate_start,   /* Before the VM unmaps pages */
>   emm_invalidate_end, /* After the VM unmapped pages */
> - emm_referenced  /* Check if a range was referenced */
> + emm_referenced, /* Check if a range was referenced */
> + emm_stop,   /* Halt all faults/invalidate_starts */
> + emm_start,  /* Restart operations */
>  };
>  
>  struct emm_notifier {
> @@ -126,13 +128,15 @@ static inline int emm_notify(struct mm_s
>  
>  /*
>   * Register a notifier with an mm struct. Release occurs when the process
> - * terminates by calling the notifier function with emm_release.
> + * terminates by calling the notifier function with emm_release or when
> + * emm_notifier_unregister is called.
>   *
>   * Must hold the mmap_sem for write.
>   */
>  extern void emm_notifier_register(struct emm_notifier *e,
>   struct mm_struct *mm);
> -
> +extern void emm_notifier_unregister(struct emm_notifier *e,
> + struct mm_struct *mm);
>  
>  /*
>   * Called from mm/vmscan.c to handle paging out
> Index: linux-2.6/mm/rmap.c
> ===
> --- linux-2.6.orig/mm/rmap.c  2008-04-02 18:16:09.378057062 -0700
> +++ linux-2.6/mm/rmap.c   2008-04-02 18:16:10.710079201 -0700
> @@ -289,16 +289,46 @@ void emm_notifier_release(struct mm_stru
>  /* Register a notifier */
>  void emm_notifier_register(struct emm_notifier *e, struct mm_struct *mm)
>  {
> + /* Bring all other notifiers into a quiescent state */
> + emm_notify(mm, emm_stop, 0, TASK_SIZE);
> +
>   e->next = mm->emm_notifier;
> +
>   /*
>* The update to emm_notifier (e->next) must be visible
>* before the pointer becomes visible.
>* rcu_assign_pointer() does exactly what we need.
>*/
>   rcu_assign_pointer(mm->emm_notifier, e);
> +
> + /* Continue notifiers */
> + emm_notify(mm, emm_start, 0, TASK_SIZE);
>  }
>  EXPORT_SYMBOL_GPL(emm_notifier_register);
>  
> +/* Unregister a notifier */
> +void emm_notifier_unregister(struct emm_notifier *e, struct mm_struct *mm)
> +{
> + struct emm_notifier *p;
> +
> + emm_notify(mm, emm_stop, 0, TASK_SIZE);
> +
> + p = mm->emm_notifier;
> + if (e == p)
> + mm->emm_notifier = e->next;
> + else {
> + while (p->next != e)
> + p = p->next;
> +
> + p->next = e->next;
> + }
> + e->next = mm->emm_notifier;
> +
> + emm_notify(mm, emm_start, 0, TASK_SIZE);
> + e->callback(e, mm, emm_release, 0, TASK_SIZE);
> +}
> +EXPORT_SYMBOL_GPL(emm_notifier_unregister);
> +
>  /*
>   * Perform a callback
>   *
> 



Re: [kvm-devel] [PATCH RFC 2/5] Create relay channels and add trace data

2008-04-03 Thread Avi Kivity
Liu, Eric E wrote:
> >From 41d65b55580d3f07f9f1c50e89e3d64c5d10fbaf Mon Sep 17 00:00:00 2001
> From: Feng (Eric) Liu <[EMAIL PROTECTED]>
> Date: Tue, 1 Apr 2008 07:26:14 -0400
> Subject: [PATCH] KVM: Add kvm trace support. when config KVM_TRACE, it
> allows userspace app to read the trace of kvm_related
> events through the relayfs.
>
>
> +int kvm_trace_ioctl(unsigned int ioctl, unsigned long arg)
> +{
> + void __user *argp = (void __user *)arg;
> + long r = -EINVAL;
> +
> + switch (ioctl) {
> + case KVM_TRACE_ENABLE:
> + r = kvm_trace_enable(argp);
> + break;
> + case KVM_TRACE_DISABLE:
> + r = 0;
> + kvm_trace_cleanup();
> + break;
> + }
> +
> + return r;
> +}
>   

Since we want to allow non-privileged users to open /dev/kvm, and 
tracing can provide data on other users' VMs, we need check on 
CAP_SYS_ADMIN (or maybe CAP_PTRACE?) and return -EPERM if the user is 
not privileged enough.

-- 
error compiling committee.c: too many arguments to function


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 0/3] separate thread for IO handling V3

2008-04-03 Thread Avi Kivity
Marcelo Tosatti wrote:
> This version fixes the vmdk problems found by the
> regression testing.
>
> Dor, regarding the option to disable the IO thread, it
> would require duplicating most of the changed code. For now 
> I believe its better to get the patch into a state
> where its considered stable enough for inclusion.
>
> Please rerun the regression tests. Thanks.
>
>   

The regression tests are happy.

There's still something wrong.  When I start Windows with these patches 
applied, Windows startup consumes ~50 sec of cpu time, compared to ~12 
sec without.  Pinning qemu into cpu 0 seems to fix this.

I'll investigate some more.

-- 
error compiling committee.c: too many arguments to function


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] EMM: Fixup return value handling of emm_notify()

2008-04-03 Thread Peter Zijlstra
On Wed, 2008-04-02 at 14:33 -0700, Christoph Lameter wrote:
> On Wed, 2 Apr 2008, Andrea Arcangeli wrote:
> 
> > but anyway it's silly to be hardwired to such an interface that worst
> > of all requires switch statements instead of proper pointer to
> > functions and a fixed set of parameters and retval semantics for all
> > methods.
> 
> The EMM API with a single callback is the simplest approach at this point. 
> A common callback for all operations allows the driver to implement common 
> entry and exit code as seen in XPMem.

It seems to me that common code can be shared using functions? No need
to stuff everything into a single function. We have method vectors all
over the kernel, we could do a_ops as a single callback too, but we
dont.

FWIW I prefer separate methods.

> I guess we can complicate this more by switching to a different API or 
> adding additional emm_xxx() callback if need be but I really want to have 
> a strong case for why this would be needed. There is the danger of 
> adding frills with special callbacks in this and that situation that could 
> make the notifier complicated and specific to a certain usage scenario. 
> 
> Having this generic simple interface will hopefully avoid such things.
> 
> 


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 1/1] direct mmio for passthrough - kernel part

2008-04-03 Thread Avi Kivity
Andrea Arcangeli wrote:
> On Wed, Apr 02, 2008 at 02:16:41PM +0300, Avi Kivity wrote:
>   
>> Ugh, there's still mark_page_accessed() and SetPageDirty().
>> 
>
> btw, like PG_dirty is only set if the spte is writeable,
> mark_page_accessed should only run if the accessed bit is set in the
> spte. It doesn't matter now as nobody could possibly clear it, 

No one will clear it now, but it can start out cleared.  This is done on 
speculative mmu_set_spte(): when the guest writes into its page tables, 
we update the spte speculatively, but the guest may not actually access 
that location (for example, due to a page fault clustering).

So the change makes sense even now.

> It still skips an atomic op. Your plan still sounds just fine despite
> the above, infact it sounds too perfect: the awk hack to re-add the
> refcounting when building the external module if CONFIG_MMU_NOTIFIER
> isn't defined is going to be messy, a plain CONFIG_MMU_NOTIFIER in
> kvm.git would be simpler and more robust IMHO even if less perfect :).
>   

Worst case, we stick a get_user_pages() inside the memslot setup 
function.  That makes things not swappable for pre-mmu notifiers, but 
completely safe.

I'd rather avoid special casing the core code, whenever possible.

-- 
error compiling committee.c: too many arguments to function


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 0/3] separate thread for IO handling V3

2008-04-03 Thread Avi Kivity
Avi Kivity wrote:
>
> There's still something wrong.  When I start Windows with these 
> patches applied, Windows startup consumes ~50 sec of cpu time, 
> compared to ~12 sec without.  Pinning qemu into cpu 0 seems to fix this.
>
> I'll investigate some more.
>

Changing GUI_REFRESH_INTERVAL to 1000 (from 30) reduces cpu usage back 
to normal.  So I'm guessing there's some bad interaction between the 
iothread getting the dirty log and vcpu 0.

-- 
error compiling committee.c: too many arguments to function


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] extboot usage?

2008-04-03 Thread Anthony Liguori
Jun Koi wrote:
> Hi,
>
> Could someone please post some concret examples on how to use extboot?
> I looked around, but saw nothing.
>   

Just append boot=on to your -drive parameter.

Regards,

Anthony Liguori

> Thanks,
> Jun
>
> -
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> ___
> kvm-devel mailing list
> kvm-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
>   


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] How guest virtual address is translated to physical address?

2008-04-03 Thread Guillaume Thouvenin
On Wed, 02 Apr 2008 10:22:45 -0500
Anthony Liguori <[EMAIL PROTECTED]> wrote:

>  We can then obtain the faulting 
> virtual address from CR2 in the host and walk the guest's page table to 
> determine what guest physical address should be mapped at that guest 
> virtual address (if any at all).
> 
[...]
> I think what you're missing is that while the guest is running, it's CR3 
> does not point to it's own page table but rather to the shadow page 
> table.  We intercept CR3 reads to pretend to the guest that it's page 
> table is, in fact, installed but it's really the shadow page table 
> that's in the hardware register.

  Thank you very much for the explanations. You're right, I missed that
CR3 points to the shadow page table. 

  So it means that guest page table is not really used for translating
guest virtual address to real physical address. If the guest page table
is not used, why hyupervisor must find the guest physical address? I
mean if with the shadow page table we can translate guest virtual
address to real physical address it's not necessary to know the guest
physical address. Is it only for checks?


Regards,
Guillaume

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] EMM: Fixup return value handling of emm_notify()

2008-04-03 Thread Andrea Arcangeli
On Thu, Apr 03, 2008 at 12:40:46PM +0200, Peter Zijlstra wrote:
> It seems to me that common code can be shared using functions? No need
> FWIW I prefer separate methods.

kvm patch using mmu notifiers shares 99% of the code too between the
two different methods implemented indeed. Code sharing is the same and
if something pointer to functions will be faster if gcc isn't smart or
can't create a compile time hash to jump into the right address
without having to check every case: .

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 0/3] separate thread for IO handling V3

2008-04-03 Thread Avi Kivity
Avi Kivity wrote:
> Avi Kivity wrote:
>>
>> There's still something wrong.  When I start Windows with these 
>> patches applied, Windows startup consumes ~50 sec of cpu time, 
>> compared to ~12 sec without.  Pinning qemu into cpu 0 seems to fix this.
>>
>> I'll investigate some more.
>>
>
> Changing GUI_REFRESH_INTERVAL to 1000 (from 30) reduces cpu usage back 
> to normal.  So I'm guessing there's some bad interaction between the 
> iothread getting the dirty log and vcpu 0.
>

Turns out we held slots_lock while in guest mode (which we can be in for 
unbounded time).  Dropping the lock restored behavior to normal, so I'm 
applying the patches.

-- 
error compiling committee.c: too many arguments to function


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] EMM: disable other notifiers before register and unregister

2008-04-03 Thread Andrea Arcangeli
On Wed, Apr 02, 2008 at 06:24:15PM -0700, Christoph Lameter wrote:
> Ok lets forget about the single theaded thing to solve the registration 
> races. As Andrea pointed out this still has ssues with other subscribed 
> subsystems (and also try_to_unmap). We could do something like what 
> stop_machine_run does: First disable all running subsystems before 
> registering a new one.
> 
> Maybe this is a possible solution.

It still doesn't solve this kernel crash.

   CPU0 CPU1
   range_start (mmu notifier chain is empty)
   range_start returns
mmu_notifier_register
kvm_emm_stop (how kvm can ever know
the other cpu is in the middle of the critical 
section?)
kvm page fault (kvm thinks 
mmu_notifier_register serialized)
   zap ptes
   free_page mapped by spte/GRU and not pinned -> crash


There's no way the lowlevel can stop mmu_notifier_register and if
mmu_notifier_register returns, then sptes will be instantiated and
it'll corrupt memory the same way.

The seqlock was fine, what is wrong is the assumption that we can let
the lowlevel driver handle a range_end happening without range_begin
before it. The problem is that by design the lowlevel can't handle a
range_end happening without a range_begin before it. This is the core
kernel crashing problem we have (it's a kernel crashing issue only for
drivers that don't pin the pages, so XPMEM wouldn't crash but still it
would leak memory, which is a more graceful failure than random mm
corruption).

The basic trouble is that sometime range_begin/end critical sections
run outside the mmap_sem (see try_to_unmap_cluster in #v10 or even
try_to_unmap_one only in EMM-V2).

My attempt to fix this once and for all is to walk all vmas of the
"mm" inside mmu_notifier_register and take all anon_vma locks and
i_mmap_locks in virtual address order in a row. It's ok to take those
inside the mmap_sem. Supposedly if anybody will ever take a double
lock it'll do in order too. Then I can dump all the other locking and
remove the seqlock, and the driver is guaranteed there will be a
single call of range_begin followed by a single call of range_end the
whole time and no race could ever happen, and there won't be replied
calls of range_begin that would screwup a recursive semaphore
locking. The patch won't be pretty, I guess I'll vmalloc an array of
pointers to locks to reorder them. It doesn't need to be fast. Also
the locks can't go away from under us while we hold the
down_write(mmap_sem) because the vmas can be altered only with
down_write(mmap_sem) (modulo vm_start/vm_end that can be modified with
only down_read(mmap_sem) + page_table_lock like in growsdown page
faults). So it should be ok to take all those locks inside the
mmap_sem and implement a lock_vm(mm) unlock_vm(mm). I'll think more
about this hammer approach while I try to implement it...

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [ kvm-Bugs-1933508 ] KVM cannot migrate with command -monitor

2008-04-03 Thread SourceForge.net
Bugs item #1933508, was opened at 2008-04-03 22:53
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=893831&aid=1933508&group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Verapong Rattanasamoot (rattanasamoot)
Assigned to: Nobody/Anonymous (nobody)
Summary: KVM cannot migrate with command -monitor

Initial Comment:
I use KVM on Ubuntu 7.10 64 bit linux. 
I use migration only on localhost is work fine.

But when I use option (-monitor tcp::port,server,nowait) I cannot get result to 
migrate to incoming process.
 
I use kvm-60
 
>> command at VM Host : qemu-system-x86_64 -boot c -hda tc.ovl -m 512M -monitor 
>> tcp::40001,server,nowait 
(tc.ovl is an ovelay to disk image thats all in nfs)
 
>> command at VM Destination : qemu-system-x86_64 -boot c -hda tc.ovl -m 512M 
>> -incoming tcp://127.0.0.1: -monitor tcp::40002,server,nowait
 
After run this commands and linux at VM1 Host start,
 
I telnet to localhost 40001 and 
command "migrate_set_speed 1G" then command "migrate -d tcp://127.0.0.1:"

At VM Host has been non response with any command. 
VM Destination still wait for read migration information.
 
Please help me how to solve this problems.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=893831&aid=1933508&group_id=180599

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] virtual machines network goes 100Mbit when interface is Gbit

2008-04-03 Thread Felix Leimbach

 Thanks for your answer Haydn, but I did not understand the issue too.
 Victor has explained my problem clearly, is kvm uncapable of running
 the bridge at 1GBit if it is not a e1000 network card?


Hey Miguel,

what Haydn meant was to force qemu to *emulate* a e1000 NIC instead of 
the default RTL8139. That emulation is done by qemu in userspace and has 
absolutely nothing to do with your physical NIC por the bridge.

Chosing a NIC is done with the "model=" parameter.
kvm -net nic,model=e1000

Even better performance-wise would be to use the new virtio interface 
which paravirtualizes your physical NIC instead of emulating one.

For that, use:
kvm -net nic,model=virtio

Of course you'll need to install the corresponding drivers in your 
guest. The e1000 should be supported in every guest and for the virtio 
interface there are windows guest drivers (see the kvm-announce mailing 
list for that) as well as linux guest drivers included in kernel 2.6.25 
upwards.


By the way: This is good stuff f you're interested in hard disk 
performance, too: http://kvm.qumranet.com/kvmwiki/Virtio


Felix
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] virtual machines network goes 100Mbit when interface is Gbit

2008-04-03 Thread Haydn Solomon
See also
http://www.linux-kvm.com/content/tip-how-setup-windows-guest-paravirtual-network-drivers

On Thu, Apr 3, 2008 at 10:54 AM, Felix Leimbach <[EMAIL PROTECTED]>
wrote:

>  > Thanks for your answer Haydn, but I did not understand the issue too.
> > Victor has explained my problem clearly, is kvm uncapable of running
> > the bridge at 1GBit if it is not a e1000 network card?
>
> Hey Miguel,
>
> what Haydn meant was to force qemu to *emulate* a e1000 NIC instead of the
> default RTL8139. That emulation is done by qemu in userspace and has
> absolutely nothing to do with your physical NIC por the bridge.
> Chosing a NIC is done with the "model=" parameter.
> kvm -net nic,model=e1000
>
> Even better performance-wise would be to use the new virtio interface
> which paravirtualizes your physical NIC instead of emulating one.
> For that, use:
> kvm -net nic,model=virtio
>
> Of course you'll need to install the corresponding drivers in your guest.
> The e1000 should be supported in every guest and for the virtio interface
> there are windows guest drivers (see the kvm-announce mailing list for that)
> as well as linux guest drivers included in kernel 2.6.25 upwards.
>
> By the way: This is good stuff f you're interested in hard disk
> performance, too: http://kvm.qumranet.com/kvmwiki/Virtio
>
> Felix
>
> -
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
>
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> ___
> kvm-devel mailing list
> kvm-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
>
>
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] EMM: Fixup return value handling of emm_notify()

2008-04-03 Thread Christoph Lameter
On Thu, 3 Apr 2008, Peter Zijlstra wrote:

> It seems to me that common code can be shared using functions? No need
> to stuff everything into a single function. We have method vectors all
> over the kernel, we could do a_ops as a single callback too, but we
> dont.
> 
> FWIW I prefer separate methods.

Ok. It seems that I already added some new methods which do not use all 
parameters. So lets switch back to the old scheme for the next release.

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] EMM: disable other notifiers before register and unregister

2008-04-03 Thread Christoph Lameter
On Thu, 3 Apr 2008, Andrea Arcangeli wrote:

> My attempt to fix this once and for all is to walk all vmas of the
> "mm" inside mmu_notifier_register and take all anon_vma locks and
> i_mmap_locks in virtual address order in a row. It's ok to take those
> inside the mmap_sem. Supposedly if anybody will ever take a double
> lock it'll do in order too. Then I can dump all the other locking and

What about concurrent mmu_notifier registrations from two mm_structs 
that have shared mappings? Isnt there a potential deadlock situation?

> faults). So it should be ok to take all those locks inside the
> mmap_sem and implement a lock_vm(mm) unlock_vm(mm). I'll think more
> about this hammer approach while I try to implement it...

Well good luck. Hopefully we will get to something that works.


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 17/35] KVM: Add reset support for in kernel PIT

2008-04-03 Thread Avi Kivity
From: Sheng Yang <[EMAIL PROTECTED]>

Separate the reset part and prepare for reset support.

Signed-off-by: Sheng Yang <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/i8254.c |   30 +++---
 arch/x86/kvm/i8254.h |1 +
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 7776f50..06a241a 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -476,12 +476,28 @@ static int speaker_in_range(struct kvm_io_device *this, 
gpa_t addr)
return (addr == KVM_SPEAKER_BASE_ADDRESS);
 }
 
-struct kvm_pit *kvm_create_pit(struct kvm *kvm)
+void kvm_pit_reset(struct kvm_pit *pit)
 {
int i;
+   struct kvm_kpit_channel_state *c;
+
+   mutex_lock(&pit->pit_state.lock);
+   for (i = 0; i < 3; i++) {
+   c = &pit->pit_state.channels[i];
+   c->mode = 0xff;
+   c->gate = (i != 2);
+   pit_load_count(pit->kvm, i, 0);
+   }
+   mutex_unlock(&pit->pit_state.lock);
+
+   atomic_set(&pit->pit_state.pit_timer.pending, 0);
+   pit->pit_state.inject_pending = 1;
+}
+
+struct kvm_pit *kvm_create_pit(struct kvm *kvm)
+{
struct kvm_pit *pit;
struct kvm_kpit_state *pit_state;
-   struct kvm_kpit_channel_state *c;
 
pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL);
if (!pit)
@@ -510,17 +526,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm)
pit_state->pit = pit;
hrtimer_init(&pit_state->pit_timer.timer,
 CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
-   atomic_set(&pit_state->pit_timer.pending, 0);
-   for (i = 0; i < 3; i++) {
-   c = &pit_state->channels[i];
-   c->mode = 0xff;
-   c->gate = (i != 2);
-   pit_load_count(kvm, i, 0);
-   }
-
mutex_unlock(&pit->pit_state.lock);
 
-   pit->pit_state.inject_pending = 1;
+   kvm_pit_reset(pit);
 
return pit;
 }
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h
index 586bbf0..e63ef38 100644
--- a/arch/x86/kvm/i8254.h
+++ b/arch/x86/kvm/i8254.h
@@ -57,5 +57,6 @@ void kvm_pit_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
 void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val);
 struct kvm_pit *kvm_create_pit(struct kvm *kvm);
 void kvm_free_pit(struct kvm *kvm);
+void kvm_pit_reset(struct kvm_pit *pit);
 
 #endif
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 11/35] KVM: detect if VCPU triple faults

2008-04-03 Thread Avi Kivity
From: Joerg Roedel <[EMAIL PROTECTED]>

In the current inject_page_fault path KVM only checks if there is another PF
pending and injects a DF then. But it has to check for a pending DF too to
detect a shutdown condition in the VCPU.  If this is not detected the VCPU goes
to a PF -> DF -> PF loop when it should triple fault. This patch detects this
condition and handles it with an KVM_SHUTDOWN exit to userspace.

Signed-off-by: Joerg Roedel <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86.c   |   20 +++-
 include/linux/kvm_host.h |1 +
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index dbcff38..491eda3 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -155,11 +155,16 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, 
unsigned long addr,
   u32 error_code)
 {
++vcpu->stat.pf_guest;
-   if (vcpu->arch.exception.pending && vcpu->arch.exception.nr == 
PF_VECTOR) {
-   printk(KERN_DEBUG "kvm: inject_page_fault:"
-  " double fault 0x%lx\n", addr);
-   vcpu->arch.exception.nr = DF_VECTOR;
-   vcpu->arch.exception.error_code = 0;
+   if (vcpu->arch.exception.pending) {
+   if (vcpu->arch.exception.nr == PF_VECTOR) {
+   printk(KERN_DEBUG "kvm: inject_page_fault:"
+   " double fault 0x%lx\n", addr);
+   vcpu->arch.exception.nr = DF_VECTOR;
+   vcpu->arch.exception.error_code = 0;
+   } else if (vcpu->arch.exception.nr == DF_VECTOR) {
+   /* triple fault -> shutdown */
+   set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests);
+   }
return;
}
vcpu->arch.cr2 = addr;
@@ -2676,6 +2681,11 @@ again:
r = 0;
goto out;
}
+   if (test_and_clear_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests)) {
+   kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
+   r = 0;
+   goto out;
+   }
}
 
kvm_inject_pending_timer_irqs(vcpu);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9750bb3..958e003 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -38,6 +38,7 @@
 #define KVM_REQ_MIGRATE_TIMER  1
 #define KVM_REQ_REPORT_TPR_ACCESS  2
 #define KVM_REQ_MMU_RELOAD 3
+#define KVM_REQ_TRIPLE_FAULT   4
 
 struct kvm_vcpu;
 extern struct kmem_cache *kvm_vcpu_cache;
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 20/35] KVM: Provide unlocked version of emulator_write_phys()

2008-04-03 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86.c |   21 ++---
 include/asm-x86/kvm_host.h |3 +++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1b9e695..03ba402 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1840,22 +1840,29 @@ mmio:
return X86EMUL_UNHANDLEABLE;
 }
 
-static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
-  const void *val, int bytes)
+int __emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
+ const void *val, int bytes)
 {
int ret;
 
-   down_read(&vcpu->kvm->slots_lock);
ret = kvm_write_guest(vcpu->kvm, gpa, val, bytes);
-   if (ret < 0) {
-   up_read(&vcpu->kvm->slots_lock);
+   if (ret < 0)
return 0;
-   }
kvm_mmu_pte_write(vcpu, gpa, val, bytes);
-   up_read(&vcpu->kvm->slots_lock);
return 1;
 }
 
+static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
+   const void *val, int bytes)
+{
+   int ret;
+
+   down_read(&vcpu->kvm->slots_lock);
+   ret =__emulator_write_phys(vcpu, gpa, val, bytes);
+   up_read(&vcpu->kvm->slots_lock);
+   return ret;
+}
+
 static int emulator_write_emulated_onepage(unsigned long addr,
   const void *val,
   unsigned int bytes,
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 12932bb..c8e51f8 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -431,6 +431,9 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int 
kvm_nr_mmu_pages);
 
 int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
 
+int __emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
+ const void *val, int bytes);
+
 enum emulation_result {
EMULATE_DONE,   /* no further processing */
EMULATE_DO_MMIO,  /* kvm_run filled with mmio request */
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 16/35] KVM: Add save/restore supporting of in kernel PIT

2008-04-03 Thread Avi Kivity
From: Sheng Yang <[EMAIL PROTECTED]>

Signed-off-by: Sheng Yang <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/i8254.c  |7 +++
 arch/x86/kvm/i8254.h  |1 +
 arch/x86/kvm/x86.c|   48 
 include/asm-x86/kvm.h |   21 +
 include/linux/kvm.h   |2 ++
 5 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 1031901..7776f50 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -286,6 +286,13 @@ static void pit_load_count(struct kvm *kvm, int channel, 
u32 val)
}
 }
 
+void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val)
+{
+   mutex_lock(&kvm->arch.vpit->pit_state.lock);
+   pit_load_count(kvm, channel, val);
+   mutex_unlock(&kvm->arch.vpit->pit_state.lock);
+}
+
 static void pit_ioport_write(struct kvm_io_device *this,
 gpa_t addr, int len, const void *data)
 {
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h
index 38184d5..586bbf0 100644
--- a/arch/x86/kvm/i8254.h
+++ b/arch/x86/kvm/i8254.h
@@ -54,6 +54,7 @@ struct kvm_pit {
 
 void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu);
 void kvm_pit_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
+void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val);
 struct kvm_pit *kvm_create_pit(struct kvm *kvm);
 void kvm_free_pit(struct kvm *kvm);
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c33a457..621a8e3 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1504,6 +1504,23 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, 
struct kvm_irqchip *chip)
return r;
 }
 
+static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)
+{
+   int r = 0;
+
+   memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state));
+   return r;
+}
+
+static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps)
+{
+   int r = 0;
+
+   memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state));
+   kvm_pit_load_count(kvm, 0, ps->channels[0].count);
+   return r;
+}
+
 /*
  * Get (and clear) the dirty memory log for a memory slot.
  */
@@ -1657,6 +1674,37 @@ long kvm_arch_vm_ioctl(struct file *filp,
r = 0;
break;
}
+   case KVM_GET_PIT: {
+   struct kvm_pit_state ps;
+   r = -EFAULT;
+   if (copy_from_user(&ps, argp, sizeof ps))
+   goto out;
+   r = -ENXIO;
+   if (!kvm->arch.vpit)
+   goto out;
+   r = kvm_vm_ioctl_get_pit(kvm, &ps);
+   if (r)
+   goto out;
+   r = -EFAULT;
+   if (copy_to_user(argp, &ps, sizeof ps))
+   goto out;
+   r = 0;
+   break;
+   }
+   case KVM_SET_PIT: {
+   struct kvm_pit_state ps;
+   r = -EFAULT;
+   if (copy_from_user(&ps, argp, sizeof ps))
+   goto out;
+   r = -ENXIO;
+   if (!kvm->arch.vpit)
+   goto out;
+   r = kvm_vm_ioctl_set_pit(kvm, &ps);
+   if (r)
+   goto out;
+   r = 0;
+   break;
+   }
default:
;
}
diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h
index 7a71120..12b4b25 100644
--- a/include/asm-x86/kvm.h
+++ b/include/asm-x86/kvm.h
@@ -188,4 +188,25 @@ struct kvm_cpuid2 {
struct kvm_cpuid_entry2 entries[0];
 };
 
+/* for KVM_GET_PIT and KVM_SET_PIT */
+struct kvm_pit_channel_state {
+   __u32 count; /* can be 65536 */
+   __u16 latched_count;
+   __u8 count_latched;
+   __u8 status_latched;
+   __u8 status;
+   __u8 read_state;
+   __u8 write_state;
+   __u8 write_latch;
+   __u8 rw_mode;
+   __u8 mode;
+   __u8 bcd;
+   __u8 gate;
+   __s64 count_load_time;
+};
+
+struct kvm_pit_state {
+   struct kvm_pit_channel_state channels[3];
+};
+
 #endif
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index cefa9a2..a2f3274 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -260,6 +260,8 @@ struct kvm_vapic_addr {
 #define KVM_GET_IRQCHIP  _IOWR(KVMIO, 0x62, struct kvm_irqchip)
 #define KVM_SET_IRQCHIP  _IOR(KVMIO,  0x63, struct kvm_irqchip)
 #define KVM_CREATE_PIT   _IO(KVMIO,  0x64)
+#define KVM_GET_PIT  _IOWR(KVMIO, 0x65, struct kvm_pit_state)
+#define KVM_SET_PIT  _IOR(KVMIO,  0x66, struct kvm_pit_state)
 
 /*
  * ioctls for vcpu fds
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net

[kvm-devel] [PATCH 19/35] x86: KVM guest: add basic paravirt support

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Add basic KVM paravirt support. Avoid vm-exits on IO delays.

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/Kconfig   |8 ++
 arch/x86/kernel/Makefile   |1 +
 arch/x86/kernel/kvm.c  |   52 
 arch/x86/kernel/setup_32.c |1 +
 arch/x86/kernel/setup_64.c |2 +
 include/linux/kvm_para.h   |6 +
 6 files changed, 70 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kernel/kvm.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index e59ea05..75d2700 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -381,6 +381,14 @@ config KVM_CLOCK
  provides the guest with timing infrastructure such as time of day, and
  system time
 
+config KVM_GUEST
+   bool "KVM Guest support"
+   select PARAVIRT
+   depends on !(X86_VISWS || X86_VOYAGER)
+   help
+This option enables various optimizations for running under the KVM
+hypervisor.
+
 source "arch/x86/lguest/Kconfig"
 
 config PARAVIRT
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index a3379a3..1cc9d42 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_DEBUG_RODATA_TEST)   += test_rodata.o
 obj-$(CONFIG_DEBUG_NX_TEST)+= test_nx.o
 
 obj-$(CONFIG_VMI)  += vmi_32.o vmiclock_32.o
+obj-$(CONFIG_KVM_GUEST)+= kvm.o
 obj-$(CONFIG_KVM_CLOCK)+= kvmclock.o
 obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch_$(BITS).o
 
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
new file mode 100644
index 000..a8e36da
--- /dev/null
+++ b/arch/x86/kernel/kvm.c
@@ -0,0 +1,52 @@
+/*
+ * KVM paravirt_ops implementation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2007, Red Hat, Inc., Ingo Molnar <[EMAIL PROTECTED]>
+ * Copyright IBM Corporation, 2007
+ *   Authors: Anthony Liguori <[EMAIL PROTECTED]>
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * No need for any "IO delay" on KVM
+ */
+static void kvm_io_delay(void)
+{
+}
+
+static void paravirt_ops_setup(void)
+{
+   pv_info.name = "KVM";
+   pv_info.paravirt_enabled = 1;
+
+   if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
+   pv_cpu_ops.io_delay = kvm_io_delay;
+
+}
+
+void __init kvm_guest_init(void)
+{
+   if (!kvm_para_available())
+   return;
+
+   paravirt_ops_setup();
+}
diff --git a/arch/x86/kernel/setup_32.c b/arch/x86/kernel/setup_32.c
index 3ef92a2..65f3a23 100644
--- a/arch/x86/kernel/setup_32.c
+++ b/arch/x86/kernel/setup_32.c
@@ -782,6 +782,7 @@ void __init setup_arch(char **cmdline_p)
 */
vmi_init();
 #endif
+   kvm_guest_init();
 
/*
 * NOTE: before this point _nobody_ is allowed to allocate
diff --git a/arch/x86/kernel/setup_64.c b/arch/x86/kernel/setup_64.c
index 26b676f..10a8ff5 100644
--- a/arch/x86/kernel/setup_64.c
+++ b/arch/x86/kernel/setup_64.c
@@ -452,6 +452,8 @@ void __init setup_arch(char **cmdline_p)
init_apic_mappings();
ioapic_init_mappings();
 
+   kvm_guest_init();
+
/*
 * We trust e820 completely. No explicit ROM probing in memory.
 */
diff --git a/include/linux/kvm_para.h b/include/linux/kvm_para.h
index 5497aac..9c462c9 100644
--- a/include/linux/kvm_para.h
+++ b/include/linux/kvm_para.h
@@ -20,6 +20,12 @@
 #include 
 
 #ifdef __KERNEL__
+#ifdef CONFIG_KVM_GUEST
+void __init kvm_guest_init(void);
+#else
+#define kvm_guest_init() do { } while (0)
+#endif
+
 static inline int kvm_para_has_feature(unsigned int feature)
 {
if (kvm_arch_para_features() & (1UL << feature))
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 12/35] KVM: replace remaining __FUNCTION__ occurances

2008-04-03 Thread Avi Kivity
From: Harvey Harrison <[EMAIL PROTECTED]>

__FUNCTION__ is gcc-specific, use __func__

Signed-off-by: Harvey Harrison <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/lapic.c   |8 
 arch/x86/kvm/mmu.c |   35 +--
 arch/x86/kvm/paging_tmpl.h |   14 +++---
 arch/x86/kvm/svm.c |   14 +++---
 arch/x86/kvm/vmx.c |6 +++---
 arch/x86/kvm/x86.c |   12 ++--
 6 files changed, 44 insertions(+), 45 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 68a6b15..31280df 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -658,7 +658,7 @@ static void start_apic_timer(struct kvm_lapic *apic)
apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016"
   PRIx64 ", "
   "timer initial count 0x%x, period %lldns, "
-  "expire @ 0x%016" PRIx64 ".\n", __FUNCTION__,
+  "expire @ 0x%016" PRIx64 ".\n", __func__,
   APIC_BUS_CYCLE_NS, ktime_to_ns(now),
   apic_get_reg(apic, APIC_TMICT),
   apic->timer.period,
@@ -691,7 +691,7 @@ static void apic_mmio_write(struct kvm_io_device *this,
/* too common printing */
if (offset != APIC_EOI)
apic_debug("%s: offset 0x%x with length 0x%x, and value is "
-  "0x%x\n", __FUNCTION__, offset, len, val);
+  "0x%x\n", __func__, offset, len, val);
 
offset &= 0xff0;
 
@@ -869,7 +869,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
struct kvm_lapic *apic;
int i;
 
-   apic_debug("%s\n", __FUNCTION__);
+   apic_debug("%s\n", __func__);
 
ASSERT(vcpu);
apic = vcpu->arch.apic;
@@ -907,7 +907,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
apic_update_ppr(apic);
 
apic_debug(KERN_INFO "%s: vcpu=%p, id=%d, base_msr="
-  "0x%016" PRIx64 ", base_address=0x%0lx.\n", __FUNCTION__,
+  "0x%016" PRIx64 ", base_address=0x%0lx.\n", __func__,
   vcpu, kvm_apic_id(apic),
   vcpu->arch.apic_base, apic->base_address);
 }
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 1932a3a..414405b 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -649,7 +649,7 @@ static int is_empty_shadow_page(u64 *spt)
 
for (pos = spt, end = pos + PAGE_SIZE / sizeof(u64); pos != end; pos++)
if (*pos != shadow_trap_nonpresent_pte) {
-   printk(KERN_ERR "%s: %p %llx\n", __FUNCTION__,
+   printk(KERN_ERR "%s: %p %llx\n", __func__,
   pos, *pos);
return 0;
}
@@ -772,14 +772,14 @@ static struct kvm_mmu_page *kvm_mmu_lookup_page(struct 
kvm *kvm, gfn_t gfn)
struct kvm_mmu_page *sp;
struct hlist_node *node;
 
-   pgprintk("%s: looking for gfn %lx\n", __FUNCTION__, gfn);
+   pgprintk("%s: looking for gfn %lx\n", __func__, gfn);
index = kvm_page_table_hashfn(gfn);
bucket = &kvm->arch.mmu_page_hash[index];
hlist_for_each_entry(sp, node, bucket, hash_link)
if (sp->gfn == gfn && !sp->role.metaphysical
&& !sp->role.invalid) {
pgprintk("%s: found role %x\n",
-__FUNCTION__, sp->role.word);
+__func__, sp->role.word);
return sp;
}
return NULL;
@@ -810,21 +810,21 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct 
kvm_vcpu *vcpu,
quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
role.quadrant = quadrant;
}
-   pgprintk("%s: looking gfn %lx role %x\n", __FUNCTION__,
+   pgprintk("%s: looking gfn %lx role %x\n", __func__,
 gfn, role.word);
index = kvm_page_table_hashfn(gfn);
bucket = &vcpu->kvm->arch.mmu_page_hash[index];
hlist_for_each_entry(sp, node, bucket, hash_link)
if (sp->gfn == gfn && sp->role.word == role.word) {
mmu_page_add_parent_pte(vcpu, sp, parent_pte);
-   pgprintk("%s: found\n", __FUNCTION__);
+   pgprintk("%s: found\n", __func__);
return sp;
}
++vcpu->kvm->stat.mmu_cache_miss;
sp = kvm_mmu_alloc_page(vcpu, parent_pte);
if (!sp)
return sp;
-   pgprintk("%s: adding gfn %lx role %x\n", __FUNCTION__, gfn, role.word);
+   pgprintk("%s: adding gfn %lx role %x\n", __func__, gfn, role.word);
sp->gfn = gfn;
sp->role = role;
hlist_add_head(&sp->hash_link, bucket);
@@ -960,13 +960,13 @@ static int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t 
gfn)

[kvm-devel] [PATCH 18/35] KVM: add basic paravirt support

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Add basic KVM paravirt support. Avoid vm-exits on IO delays.

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86.c |1 +
 include/asm-x86/kvm_para.h |3 ++-
 include/linux/kvm.h|1 +
 3 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 621a8e3..1b9e695 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -820,6 +820,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_EXT_CPUID:
case KVM_CAP_CLOCKSOURCE:
case KVM_CAP_PIT:
+   case KVM_CAP_NOP_IO_DELAY:
r = 1;
break;
case KVM_CAP_VAPIC:
diff --git a/include/asm-x86/kvm_para.h b/include/asm-x86/kvm_para.h
index 5ab7d3d..ed5df3a 100644
--- a/include/asm-x86/kvm_para.h
+++ b/include/asm-x86/kvm_para.h
@@ -10,7 +10,8 @@
  * paravirtualization, the appropriate feature bit should be checked.
  */
 #define KVM_CPUID_FEATURES 0x4001
-#define KVM_FEATURE_CLOCKSOURCE 0
+#define KVM_FEATURE_CLOCKSOURCE0
+#define KVM_FEATURE_NOP_IO_DELAY   1
 
 #define MSR_KVM_WALL_CLOCK  0x11
 #define MSR_KVM_SYSTEM_TIME 0x12
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index a2f3274..76f0947 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -237,6 +237,7 @@ struct kvm_vapic_addr {
 #define KVM_CAP_NR_VCPUS 9   /* returns max vcpus per vm */
 #define KVM_CAP_NR_MEMSLOTS 10   /* returns max memory slots per vm */
 #define KVM_CAP_PIT 11
+#define KVM_CAP_NOP_IO_DELAY 12
 
 /*
  * ioctls for VM fds
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 25/35] x86: make native_machine_shutdown non-static

2008-04-03 Thread Avi Kivity
From: Glauber Costa <[EMAIL PROTECTED]>

it will allow external users to call it. It is mainly
useful for routines that will override its machine_ops
field for its own special purposes, but want to call the
normal shutdown routine after they're done

Signed-off-by: Glauber Costa <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kernel/reboot.c |2 +-
 include/asm-x86/reboot.h |1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 708d6f8..1481d85 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -400,7 +400,7 @@ static void native_machine_emergency_restart(void)
}
 }
 
-static void native_machine_shutdown(void)
+void native_machine_shutdown(void)
 {
/* Stop the cpus and apics */
 #ifdef CONFIG_SMP
diff --git a/include/asm-x86/reboot.h b/include/asm-x86/reboot.h
index ff9b546..c5e8722 100644
--- a/include/asm-x86/reboot.h
+++ b/include/asm-x86/reboot.h
@@ -17,5 +17,6 @@ extern struct machine_ops machine_ops;
 
 void machine_real_restart(unsigned char *code, int length);
 void native_machine_crash_shutdown(struct pt_regs *regs);
+void native_machine_shutdown(void);
 
 #endif /* _ASM_REBOOT_H */
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 15/35] KVM: In kernel PIT model

2008-04-03 Thread Avi Kivity
From: Sheng Yang <[EMAIL PROTECTED]>

The patch moved PIT from userspace to kernel, and increase the timer accuracy 
greatly.

Signed-off-by: Sheng Yang <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/Makefile  |3 +-
 arch/x86/kvm/i8254.c   |  585 
 arch/x86/kvm/i8254.h   |   60 +
 arch/x86/kvm/irq.c |3 +
 arch/x86/kvm/x86.c |9 +
 include/asm-x86/kvm_host.h |1 +
 include/linux/kvm.h|2 +
 7 files changed, 662 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/kvm/i8254.c
 create mode 100644 arch/x86/kvm/i8254.h

diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index ffdd0b3..4d0c22e 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -6,7 +6,8 @@ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o 
ioapic.o)
 
 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm
 
-kvm-objs := $(common-objs) x86.o mmu.o x86_emulate.o i8259.o irq.o lapic.o
+kvm-objs := $(common-objs) x86.o mmu.o x86_emulate.o i8259.o irq.o lapic.o \
+   i8254.o
 obj-$(CONFIG_KVM) += kvm.o
 kvm-intel-objs = vmx.o
 obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
new file mode 100644
index 000..1031901
--- /dev/null
+++ b/arch/x86/kvm/i8254.c
@@ -0,0 +1,585 @@
+/*
+ * 8253/8254 interval timer emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2006 Intel Corporation
+ * Copyright (c) 2007 Keir Fraser, XenSource Inc
+ * Copyright (c) 2008 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Authors:
+ *   Sheng Yang <[EMAIL PROTECTED]>
+ *   Based on QEMU and Xen.
+ */
+
+#include 
+
+#include "irq.h"
+#include "i8254.h"
+
+#ifndef CONFIG_X86_64
+#define mod_64(x, y) ((x) - (y) * div64_64(x, y))
+#else
+#define mod_64(x, y) ((x) % (y))
+#endif
+
+#define RW_STATE_LSB 1
+#define RW_STATE_MSB 2
+#define RW_STATE_WORD0 3
+#define RW_STATE_WORD1 4
+
+/* Compute with 96 bit intermediate result: (a*b)/c */
+static u64 muldiv64(u64 a, u32 b, u32 c)
+{
+   union {
+   u64 ll;
+   struct {
+   u32 low, high;
+   } l;
+   } u, res;
+   u64 rl, rh;
+
+   u.ll = a;
+   rl = (u64)u.l.low * (u64)b;
+   rh = (u64)u.l.high * (u64)b;
+   rh += (rl >> 32);
+   res.l.high = div64_64(rh, c);
+   res.l.low = div64_64(((mod_64(rh, c) << 32) + (rl & 0x)), c);
+   return res.ll;
+}
+
+static void pit_set_gate(struct kvm *kvm, int channel, u32 val)
+{
+   struct kvm_kpit_channel_state *c =
+   &kvm->arch.vpit->pit_state.channels[channel];
+
+   WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
+
+   switch (c->mode) {
+   default:
+   case 0:
+   case 4:
+   /* XXX: just disable/enable counting */
+   break;
+   case 1:
+   case 2:
+   case 3:
+   case 5:
+   /* Restart counting on rising edge. */
+   if (c->gate < val)
+   c->count_load_time = ktime_get();
+   break;
+   }
+
+   c->gate = val;
+}
+
+int pit_get_gate(struct kvm *kvm, int channel)
+{
+   WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
+
+   return kvm->arch.vpit->pit_state.channels[channel].gate;
+}
+
+static int pit_get_count(struct kvm *kvm, int channel)
+{
+   struct kvm_kpit_channel_state *c =
+   &kvm->arch.vpit->pit_state.channels[channel];
+   s64 d, t;
+   int counter;
+
+   WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
+
+   t = ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time));
+   d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC);
+
+   switch (c->mode) {
+   case 0:
+   case 1:
+   case 4:
+   case 5:
+   counter = (c->count - d) & 0x;
+ 

[kvm-devel] [PATCH 22/35] x86: KVM guest: hypercall based pte updates and TLB flushes

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Hypercall based pte updates are faster than faults, and also allow use
of the lazy MMU mode to batch operations.

Don't report the feature if two dimensional paging is enabled.

[avi:
 - guest/host split
 - fix 32-bit truncation issues
 - adjust to mmu_op]

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kernel/kvm.c |  137 +
 1 files changed, 137 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index a8e36da..1bb6e97 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * No need for any "IO delay" on KVM
@@ -33,6 +34,122 @@ static void kvm_io_delay(void)
 {
 }
 
+static void kvm_mmu_op(void *buffer, unsigned len)
+{
+   int r;
+   unsigned long a1, a2;
+
+   do {
+   a1 = __pa(buffer);
+   a2 = 0;   /* on i386 __pa() always returns <4G */
+   r = kvm_hypercall3(KVM_HC_MMU_OP, len, a1, a2);
+   buffer += r;
+   len -= r;
+   } while (len);
+}
+
+static void kvm_mmu_write(void *dest, u64 val)
+{
+   __u64 pte_phys;
+   struct kvm_mmu_op_write_pte wpte;
+
+#ifdef CONFIG_HIGHPTE
+   struct page *page;
+   unsigned long dst = (unsigned long) dest;
+
+   page = kmap_atomic_to_page(dest);
+   pte_phys = page_to_pfn(page);
+   pte_phys <<= PAGE_SHIFT;
+   pte_phys += (dst & ~(PAGE_MASK));
+#else
+   pte_phys = (unsigned long)__pa(dest);
+#endif
+   wpte.header.op = KVM_MMU_OP_WRITE_PTE;
+   wpte.pte_val = val;
+   wpte.pte_phys = pte_phys;
+
+   kvm_mmu_op(&wpte, sizeof wpte);
+}
+
+/*
+ * We only need to hook operations that are MMU writes.  We hook these so that
+ * we can use lazy MMU mode to batch these operations.  We could probably
+ * improve the performance of the host code if we used some of the information
+ * here to simplify processing of batched writes.
+ */
+static void kvm_set_pte(pte_t *ptep, pte_t pte)
+{
+   kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_set_pte_at(struct mm_struct *mm, unsigned long addr,
+  pte_t *ptep, pte_t pte)
+{
+   kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_set_pmd(pmd_t *pmdp, pmd_t pmd)
+{
+   kvm_mmu_write(pmdp, pmd_val(pmd));
+}
+
+#if PAGETABLE_LEVELS >= 3
+#ifdef CONFIG_X86_PAE
+static void kvm_set_pte_atomic(pte_t *ptep, pte_t pte)
+{
+   kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_set_pte_present(struct mm_struct *mm, unsigned long addr,
+   pte_t *ptep, pte_t pte)
+{
+   kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_pte_clear(struct mm_struct *mm,
+ unsigned long addr, pte_t *ptep)
+{
+   kvm_mmu_write(ptep, 0);
+}
+
+static void kvm_pmd_clear(pmd_t *pmdp)
+{
+   kvm_mmu_write(pmdp, 0);
+}
+#endif
+
+static void kvm_set_pud(pud_t *pudp, pud_t pud)
+{
+   kvm_mmu_write(pudp, pud_val(pud));
+}
+
+#if PAGETABLE_LEVELS == 4
+static void kvm_set_pgd(pgd_t *pgdp, pgd_t pgd)
+{
+   kvm_mmu_write(pgdp, pgd_val(pgd));
+}
+#endif
+#endif /* PAGETABLE_LEVELS >= 3 */
+
+static void kvm_flush_tlb(void)
+{
+   struct kvm_mmu_op_flush_tlb ftlb = {
+   .header.op = KVM_MMU_OP_FLUSH_TLB,
+   };
+
+   kvm_mmu_op(&ftlb, sizeof ftlb);
+}
+
+static void kvm_release_pt(u32 pfn)
+{
+   struct kvm_mmu_op_release_pt rpt = {
+   .header.op = KVM_MMU_OP_RELEASE_PT,
+   .pt_phys = (u64)pfn << PAGE_SHIFT,
+   };
+
+   kvm_mmu_op(&rpt, sizeof rpt);
+}
+
 static void paravirt_ops_setup(void)
 {
pv_info.name = "KVM";
@@ -41,6 +158,26 @@ static void paravirt_ops_setup(void)
if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
pv_cpu_ops.io_delay = kvm_io_delay;
 
+   if (kvm_para_has_feature(KVM_FEATURE_MMU_OP)) {
+   pv_mmu_ops.set_pte = kvm_set_pte;
+   pv_mmu_ops.set_pte_at = kvm_set_pte_at;
+   pv_mmu_ops.set_pmd = kvm_set_pmd;
+#if PAGETABLE_LEVELS >= 3
+#ifdef CONFIG_X86_PAE
+   pv_mmu_ops.set_pte_atomic = kvm_set_pte_atomic;
+   pv_mmu_ops.set_pte_present = kvm_set_pte_present;
+   pv_mmu_ops.pte_clear = kvm_pte_clear;
+   pv_mmu_ops.pmd_clear = kvm_pmd_clear;
+#endif
+   pv_mmu_ops.set_pud = kvm_set_pud;
+#if PAGETABLE_LEVELS == 4
+   pv_mmu_ops.set_pgd = kvm_set_pgd;
+#endif
+#endif
+   pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
+   pv_mmu_ops.release_pt = kvm_release_pt;
+   pv_mmu_ops.release_pd = kvm_release_pt;
+   }
 }
 
 void __init kvm_guest_init(void)
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It'

[kvm-devel] [PATCH 21/35] KVM: MMU: hypercall based pte updates and TLB flushes

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Hypercall based pte updates are faster than faults, and also allow use
of the lazy MMU mode to batch operations.

Don't report the feature if two dimensional paging is enabled.

[avi:
 - one mmu_op hypercall instead of one per op
 - allow 64-bit gpa on hypercall
 - don't pass host errors (-ENOMEM) to guest]

[akpm: warning fix on i386]

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |  136 +++-
 arch/x86/kvm/x86.c |   18 ++-
 include/asm-x86/kvm_host.h |4 +
 include/asm-x86/kvm_para.h |   29 +
 include/linux/kvm.h|1 +
 include/linux/kvm_para.h   |5 +-
 6 files changed, 190 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 414405b..072e942 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -40,7 +41,7 @@
  * 2. while doing 1. it walks guest-physical to host-physical
  * If the hardware supports that we don't need to do shadow paging.
  */
-static bool tdp_enabled = false;
+bool tdp_enabled = false;
 
 #undef MMU_DEBUG
 
@@ -167,6 +168,13 @@ static int dbg = 1;
 #define ACC_USER_MASKPT_USER_MASK
 #define ACC_ALL  (ACC_EXEC_MASK | ACC_WRITE_MASK | ACC_USER_MASK)
 
+struct kvm_pv_mmu_op_buffer {
+   void *ptr;
+   unsigned len;
+   unsigned processed;
+   char buf[512] __aligned(sizeof(long));
+};
+
 struct kvm_rmap_desc {
u64 *shadow_ptes[RMAP_EXT];
struct kvm_rmap_desc *more;
@@ -2003,6 +2011,132 @@ unsigned int kvm_mmu_calculate_mmu_pages(struct kvm 
*kvm)
return nr_mmu_pages;
 }
 
+static void *pv_mmu_peek_buffer(struct kvm_pv_mmu_op_buffer *buffer,
+   unsigned len)
+{
+   if (len > buffer->len)
+   return NULL;
+   return buffer->ptr;
+}
+
+static void *pv_mmu_read_buffer(struct kvm_pv_mmu_op_buffer *buffer,
+   unsigned len)
+{
+   void *ret;
+
+   ret = pv_mmu_peek_buffer(buffer, len);
+   if (!ret)
+   return ret;
+   buffer->ptr += len;
+   buffer->len -= len;
+   buffer->processed += len;
+   return ret;
+}
+
+static int kvm_pv_mmu_write(struct kvm_vcpu *vcpu,
+gpa_t addr, gpa_t value)
+{
+   int bytes = 8;
+   int r;
+
+   if (!is_long_mode(vcpu) && !is_pae(vcpu))
+   bytes = 4;
+
+   r = mmu_topup_memory_caches(vcpu);
+   if (r)
+   return r;
+
+   if (!__emulator_write_phys(vcpu, addr, &value, bytes))
+   return -EFAULT;
+
+   return 1;
+}
+
+static int kvm_pv_mmu_flush_tlb(struct kvm_vcpu *vcpu)
+{
+   kvm_x86_ops->tlb_flush(vcpu);
+   return 1;
+}
+
+static int kvm_pv_mmu_release_pt(struct kvm_vcpu *vcpu, gpa_t addr)
+{
+   spin_lock(&vcpu->kvm->mmu_lock);
+   mmu_unshadow(vcpu->kvm, addr >> PAGE_SHIFT);
+   spin_unlock(&vcpu->kvm->mmu_lock);
+   return 1;
+}
+
+static int kvm_pv_mmu_op_one(struct kvm_vcpu *vcpu,
+struct kvm_pv_mmu_op_buffer *buffer)
+{
+   struct kvm_mmu_op_header *header;
+
+   header = pv_mmu_peek_buffer(buffer, sizeof *header);
+   if (!header)
+   return 0;
+   switch (header->op) {
+   case KVM_MMU_OP_WRITE_PTE: {
+   struct kvm_mmu_op_write_pte *wpte;
+
+   wpte = pv_mmu_read_buffer(buffer, sizeof *wpte);
+   if (!wpte)
+   return 0;
+   return kvm_pv_mmu_write(vcpu, wpte->pte_phys,
+   wpte->pte_val);
+   }
+   case KVM_MMU_OP_FLUSH_TLB: {
+   struct kvm_mmu_op_flush_tlb *ftlb;
+
+   ftlb = pv_mmu_read_buffer(buffer, sizeof *ftlb);
+   if (!ftlb)
+   return 0;
+   return kvm_pv_mmu_flush_tlb(vcpu);
+   }
+   case KVM_MMU_OP_RELEASE_PT: {
+   struct kvm_mmu_op_release_pt *rpt;
+
+   rpt = pv_mmu_read_buffer(buffer, sizeof *rpt);
+   if (!rpt)
+   return 0;
+   return kvm_pv_mmu_release_pt(vcpu, rpt->pt_phys);
+   }
+   default: return 0;
+   }
+}
+
+int kvm_pv_mmu_op(struct kvm_vcpu *vcpu, unsigned long bytes,
+ gpa_t addr, unsigned long *ret)
+{
+   int r;
+   struct kvm_pv_mmu_op_buffer buffer;
+
+   down_read(&vcpu->kvm->slots_lock);
+   down_read(¤t->mm->mmap_sem);
+
+   buffer.ptr = buffer.buf;
+   buffer.len = min_t(unsigned long, bytes, sizeof buffer.buf);
+   buffer.processed = 0;
+
+   r = kvm_read_guest(vcpu->kvm, addr, buffer.buf, buffer.len);
+   if (r)
+   goto out;
+
+   while (buffer.len) {
+   r

[kvm-devel] [PATCH 33/35] KVM: VMX: Add module option to disable flexpriority

2008-04-03 Thread Avi Kivity
Useful for debugging.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/vmx.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index fb0389d..0155931 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -39,6 +39,9 @@ module_param(bypass_guest_pf, bool, 0);
 static int enable_vpid = 1;
 module_param(enable_vpid, bool, 0);
 
+static int flexpriority_enabled = 1;
+module_param(flexpriority_enabled, bool, 0);
+
 struct vmcs {
u32 revision_id;
u32 abort;
@@ -200,8 +203,9 @@ static inline int cpu_has_secondary_exec_ctrls(void)
 
 static inline bool cpu_has_vmx_virtualize_apic_accesses(void)
 {
-   return (vmcs_config.cpu_based_2nd_exec_ctrl &
-   SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES);
+   return flexpriority_enabled
+   && (vmcs_config.cpu_based_2nd_exec_ctrl &
+   SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES);
 }
 
 static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm)
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 29/35] KVM: Move some x86 specific constants and structures to include/asm-x86

2008-04-03 Thread Avi Kivity
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 include/asm-x86/kvm_host.h |   13 +
 include/linux/kvm_host.h   |   13 -
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 52e276c..2773f91 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -20,6 +20,13 @@
 
 #include 
 
+#define KVM_MAX_VCPUS 16
+#define KVM_MEMORY_SLOTS 32
+/* memory slots that does not exposed to userspace */
+#define KVM_PRIVATE_MEM_SLOTS 4
+
+#define KVM_PIO_PAGE_OFFSET 1
+
 #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1)
 #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD))
 #define CR3_L_MODE_RESERVED_BITS 
(CR3_NONPAE_RESERVED_BITS|0xFF00ULL)
@@ -113,6 +120,12 @@ enum {
 
 #define KVM_NR_MEM_OBJS 40
 
+struct kvm_guest_debug {
+   int enabled;
+   unsigned long bp[4];
+   int singlestep;
+};
+
 /*
  * We don't want allocation failures within the mmu code, so we preallocate
  * enough memory for a single page fault in a cache.
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 958e003..f4e1436 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -24,13 +24,6 @@
 
 #include 
 
-#define KVM_MAX_VCPUS 16
-#define KVM_MEMORY_SLOTS 32
-/* memory slots that does not exposed to userspace */
-#define KVM_PRIVATE_MEM_SLOTS 4
-
-#define KVM_PIO_PAGE_OFFSET 1
-
 /*
  * vcpu->requests bit members
  */
@@ -43,12 +36,6 @@
 struct kvm_vcpu;
 extern struct kmem_cache *kvm_vcpu_cache;
 
-struct kvm_guest_debug {
-   int enabled;
-   unsigned long bp[4];
-   int singlestep;
-};
-
 /*
  * It would be nice to use something smarter than a linear search, TBD...
  * Thankfully we dont expect many devices to register (famous last words :),
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 31/35] KVM: MMU: Introduce and use spte_to_page()

2008-04-03 Thread Avi Kivity
Encapsulate the pte mask'n'shift in a function.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index dd4b95b..6fc3421 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -240,6 +240,13 @@ static int is_rmap_pte(u64 pte)
return is_shadow_present_pte(pte);
 }
 
+static struct page *spte_to_page(u64 pte)
+{
+   hfn_t hfn = (pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
+
+   return pfn_to_page(hfn);
+}
+
 static gfn_t pse36_gfn_delta(u32 gpte)
 {
int shift = 32 - PT32_DIR_PSE36_SHIFT - PAGE_SHIFT;
@@ -541,7 +548,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)
if (!is_rmap_pte(*spte))
return;
sp = page_header(__pa(spte));
-   page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
+   page = spte_to_page(*spte);
mark_page_accessed(page);
if (is_writeble_pte(*spte))
kvm_release_page_dirty(page);
@@ -630,7 +637,7 @@ static void rmap_write_protect(struct kvm *kvm, u64 gfn)
struct page *page;
 
spte = rmap_next(kvm, rmapp, NULL);
-   page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
+   page = spte_to_page(*spte);
SetPageDirty(page);
}
 
@@ -1033,7 +1040,6 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 
*shadow_pte,
u64 spte;
int was_rmapped = 0;
int was_writeble = is_writeble_pte(*shadow_pte);
-   hfn_t host_pfn = (*shadow_pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
 
pgprintk("%s: spte %llx access %x write_fault %d"
 " user_fault %d gfn %lx\n",
@@ -1051,9 +1057,10 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 
*shadow_pte,
 
child = page_header(pte & PT64_BASE_ADDR_MASK);
mmu_page_remove_parent_pte(child, shadow_pte);
-   } else if (host_pfn != page_to_pfn(page)) {
+   } else if (page != spte_to_page(*shadow_pte)) {
pgprintk("hfn old %lx new %lx\n",
-host_pfn, page_to_pfn(page));
+page_to_pfn(spte_to_page(*shadow_pte)),
+page_to_pfn(page));
rmap_remove(vcpu->kvm, shadow_pte);
} else {
if (largepage)
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 32/35] KVM: no longer EXPERIMENTAL

2008-04-03 Thread Avi Kivity
Long overdue.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/Kconfig |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 41962e7..76c70ab 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -19,7 +19,7 @@ if VIRTUALIZATION
 
 config KVM
tristate "Kernel-based Virtual Machine (KVM) support"
-   depends on HAVE_KVM && EXPERIMENTAL
+   depends on HAVE_KVM
select PREEMPT_NOTIFIERS
select ANON_INODES
---help---
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 28/35] KVM: MMU: Set the accessed bit on non-speculative shadow ptes

2008-04-03 Thread Avi Kivity
If we populate a shadow pte due to a fault (and not speculatively due to a
pte write) then we can set the accessed bit on it, as we know it will be
set immediately on the next guest instruction.  This saves a read-modify-write
operation.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |8 +---
 arch/x86/kvm/paging_tmpl.h |4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 072e942..a5872b3 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1020,7 +1020,7 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 
*shadow_pte,
 unsigned pt_access, unsigned pte_access,
 int user_fault, int write_fault, int dirty,
 int *ptwrite, int largepage, gfn_t gfn,
-struct page *page)
+struct page *page, bool speculative)
 {
u64 spte;
int was_rmapped = 0;
@@ -1061,6 +1061,8 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 
*shadow_pte,
 * demand paging).
 */
spte = PT_PRESENT_MASK | PT_DIRTY_MASK;
+   if (!speculative)
+   pte_access |= PT_ACCESSED_MASK;
if (!dirty)
pte_access &= ~ACC_WRITE_MASK;
if (!(pte_access & ACC_EXEC_MASK))
@@ -1148,13 +1150,13 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, 
int write,
 
if (level == 1) {
mmu_set_spte(vcpu, &table[index], ACC_ALL, ACC_ALL,
-0, write, 1, &pt_write, 0, gfn, page);
+0, write, 1, &pt_write, 0, gfn, page, 
false);
return pt_write;
}
 
if (largepage && level == 2) {
mmu_set_spte(vcpu, &table[index], ACC_ALL, ACC_ALL,
-   0, write, 1, &pt_write, 1, gfn, page);
+0, write, 1, &pt_write, 1, gfn, page, 
false);
return pt_write;
}
 
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 57abbd0..e9ae5db 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -266,7 +266,7 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct 
kvm_mmu_page *page,
get_page(npage);
mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0,
 gpte & PT_DIRTY_MASK, NULL, largepage, gpte_to_gfn(gpte),
-npage);
+npage, true);
 }
 
 /*
@@ -349,7 +349,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
mmu_set_spte(vcpu, shadow_ent, access, walker->pte_access & access,
 user_fault, write_fault,
 walker->ptes[walker->level-1] & PT_DIRTY_MASK,
-ptwrite, largepage, walker->gfn, page);
+ptwrite, largepage, walker->gfn, page, false);
 
return shadow_ent;
 }
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 30/35] KVM: MMU: fix dirty bit setting when removing write permissions

2008-04-03 Thread Avi Kivity
From: Izik Eidus <[EMAIL PROTECTED]>

When mmu_set_spte() checks if a page related to spte should be release as
dirty or clean, it check if the shadow pte was writeble, but in case
rmap_write_protect() is called called it is possible for shadow ptes that were
writeble to become readonly and therefor mmu_set_spte will release the pages
as clean.

This patch fix this issue by marking the page as dirty inside
rmap_write_protect().

Signed-off-by: Izik Eidus <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index a5872b3..dd4b95b 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -626,6 +626,14 @@ static void rmap_write_protect(struct kvm *kvm, u64 gfn)
}
spte = rmap_next(kvm, rmapp, spte);
}
+   if (write_protected) {
+   struct page *page;
+
+   spte = rmap_next(kvm, rmapp, NULL);
+   page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
+   SetPageDirty(page);
+   }
+
/* check for huge page mappings */
rmapp = gfn_to_rmap(kvm, gfn, 1);
spte = rmap_next(kvm, rmapp, NULL);
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 26/35] x86: KVM guest: disable clock before rebooting.

2008-04-03 Thread Avi Kivity
From: Glauber Costa <[EMAIL PROTECTED]>

This patch writes 0 (actually, what really matters is that the
LSB is cleared) to the system time msr before shutting down
the machine for kexec.

Without it, we can have a random memory location being written
when the guest comes back

It overrides the functions shutdown, used in the path of kernel_kexec() (sys.c)
and crash_shutdown, used in the path of crash_kexec() (kexec.c)

Signed-off-by: Glauber Costa <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kernel/kvmclock.c |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index b999f5e..ddee040 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define KVM_SCALE 22
 
@@ -143,6 +144,28 @@ static void kvm_setup_secondary_clock(void)
setup_secondary_APIC_clock();
 }
 
+/*
+ * After the clock is registered, the host will keep writing to the
+ * registered memory location. If the guest happens to shutdown, this memory
+ * won't be valid. In cases like kexec, in which you install a new kernel, this
+ * means a random memory location will be kept being written. So before any
+ * kind of shutdown from our side, we unregister the clock by writting anything
+ * that does not have the 'enable' bit set in the msr
+ */
+#ifdef CONFIG_KEXEC
+static void kvm_crash_shutdown(struct pt_regs *regs)
+{
+   native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0);
+   native_machine_crash_shutdown(regs);
+}
+#endif
+
+static void kvm_shutdown(void)
+{
+   native_write_msr_safe(MSR_KVM_SYSTEM_TIME, 0, 0);
+   native_machine_shutdown();
+}
+
 void __init kvmclock_init(void)
 {
if (!kvm_para_available())
@@ -155,6 +178,10 @@ void __init kvmclock_init(void)
pv_time_ops.set_wallclock = kvm_set_wallclock;
pv_time_ops.sched_clock = kvm_clock_read;
pv_apic_ops.setup_secondary_clock = kvm_setup_secondary_clock;
+   machine_ops.shutdown  = kvm_shutdown;
+#ifdef CONFIG_KEXEC
+   machine_ops.crash_shutdown  = kvm_crash_shutdown;
+#endif
clocksource_register(&kvm_clock);
}
 }
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 08/35] KVM: MMU: large page support

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Create large pages mappings if the guest PTE's are marked as such and
the underlying memory is hugetlbfs backed.  If the largepage contains
write-protected pages, a large pte is not used.

Gives a consistent 2% improvement for data copies on ram mounted
filesystem, without NPT/EPT.

Anthony measures a 4% improvement on 4-way kernbench, with NPT.

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |  222 +++-
 arch/x86/kvm/paging_tmpl.h |   32 +-
 arch/x86/kvm/x86.c |1 +
 include/asm-x86/kvm_host.h |9 ++
 include/linux/kvm_host.h   |5 +
 virt/kvm/kvm_main.c|   22 -
 6 files changed, 259 insertions(+), 32 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 103d008..1932a3a 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -211,6 +212,11 @@ static int is_shadow_present_pte(u64 pte)
&& pte != shadow_notrap_nonpresent_pte;
 }
 
+static int is_large_pte(u64 pte)
+{
+   return pte & PT_PAGE_SIZE_MASK;
+}
+
 static int is_writeble_pte(unsigned long pte)
 {
return pte & PT_WRITABLE_MASK;
@@ -350,16 +356,100 @@ static void mmu_free_rmap_desc(struct kvm_rmap_desc *rd)
 }
 
 /*
+ * Return the pointer to the largepage write count for a given
+ * gfn, handling slots that are not large page aligned.
+ */
+static int *slot_largepage_idx(gfn_t gfn, struct kvm_memory_slot *slot)
+{
+   unsigned long idx;
+
+   idx = (gfn / KVM_PAGES_PER_HPAGE) -
+ (slot->base_gfn / KVM_PAGES_PER_HPAGE);
+   return &slot->lpage_info[idx].write_count;
+}
+
+static void account_shadowed(struct kvm *kvm, gfn_t gfn)
+{
+   int *write_count;
+
+   write_count = slot_largepage_idx(gfn, gfn_to_memslot(kvm, gfn));
+   *write_count += 1;
+   WARN_ON(*write_count > KVM_PAGES_PER_HPAGE);
+}
+
+static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
+{
+   int *write_count;
+
+   write_count = slot_largepage_idx(gfn, gfn_to_memslot(kvm, gfn));
+   *write_count -= 1;
+   WARN_ON(*write_count < 0);
+}
+
+static int has_wrprotected_page(struct kvm *kvm, gfn_t gfn)
+{
+   struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
+   int *largepage_idx;
+
+   if (slot) {
+   largepage_idx = slot_largepage_idx(gfn, slot);
+   return *largepage_idx;
+   }
+
+   return 1;
+}
+
+static int host_largepage_backed(struct kvm *kvm, gfn_t gfn)
+{
+   struct vm_area_struct *vma;
+   unsigned long addr;
+
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return 0;
+
+   vma = find_vma(current->mm, addr);
+   if (vma && is_vm_hugetlb_page(vma))
+   return 1;
+
+   return 0;
+}
+
+static int is_largepage_backed(struct kvm_vcpu *vcpu, gfn_t large_gfn)
+{
+   struct kvm_memory_slot *slot;
+
+   if (has_wrprotected_page(vcpu->kvm, large_gfn))
+   return 0;
+
+   if (!host_largepage_backed(vcpu->kvm, large_gfn))
+   return 0;
+
+   slot = gfn_to_memslot(vcpu->kvm, large_gfn);
+   if (slot && slot->dirty_bitmap)
+   return 0;
+
+   return 1;
+}
+
+/*
  * Take gfn and return the reverse mapping to it.
  * Note: gfn must be unaliased before this function get called
  */
 
-static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn)
+static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int lpage)
 {
struct kvm_memory_slot *slot;
+   unsigned long idx;
 
slot = gfn_to_memslot(kvm, gfn);
-   return &slot->rmap[gfn - slot->base_gfn];
+   if (!lpage)
+   return &slot->rmap[gfn - slot->base_gfn];
+
+   idx = (gfn / KVM_PAGES_PER_HPAGE) -
+ (slot->base_gfn / KVM_PAGES_PER_HPAGE);
+
+   return &slot->lpage_info[idx].rmap_pde;
 }
 
 /*
@@ -371,7 +461,7 @@ static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t 
gfn)
  * If rmapp bit zero is one, (then rmap & ~1) points to a struct kvm_rmap_desc
  * containing more mappings.
  */
-static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte, gfn_t gfn)
+static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte, gfn_t gfn, int lpage)
 {
struct kvm_mmu_page *sp;
struct kvm_rmap_desc *desc;
@@ -383,7 +473,7 @@ static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte, 
gfn_t gfn)
gfn = unalias_gfn(vcpu->kvm, gfn);
sp = page_header(__pa(spte));
sp->gfns[spte - sp->spt] = gfn;
-   rmapp = gfn_to_rmap(vcpu->kvm, gfn);
+   rmapp = gfn_to_rmap(vcpu->kvm, gfn, lpage);
if (!*rmapp) {
rmap_printk("rmap_add: %p %llx 0->1\n", spte, *spte);
*rmapp = (unsigned long)spte;
@@ -449,7 +539,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)

[kvm-devel] [PATCH 34/35] KVM: x86: add functions to get the cpl of vcpu

2008-04-03 Thread Avi Kivity
From: Izik Eidus <[EMAIL PROTECTED]>

Signed-off-by: Izik Eidus <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/svm.c |8 
 arch/x86/kvm/vmx.c |   15 +++
 include/asm-x86/kvm_host.h |1 +
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 51741f9..c1c1b97 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -792,6 +792,13 @@ static void svm_get_segment(struct kvm_vcpu *vcpu,
var->unusable = !var->present;
 }
 
+static int svm_get_cpl(struct kvm_vcpu *vcpu)
+{
+   struct vmcb_save_area *save = &to_svm(vcpu)->vmcb->save;
+
+   return save->cpl;
+}
+
 static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
 {
struct vcpu_svm *svm = to_svm(vcpu);
@@ -1822,6 +1829,7 @@ static struct kvm_x86_ops svm_x86_ops = {
.get_segment_base = svm_get_segment_base,
.get_segment = svm_get_segment,
.set_segment = svm_set_segment,
+   .get_cpl = svm_get_cpl,
.get_cs_db_l_bits = kvm_get_cs_db_l_bits,
.decache_cr4_guest_bits = svm_decache_cr4_guest_bits,
.set_cr0 = svm_set_cr0,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 0155931..9b56032 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1395,6 +1395,20 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
var->unusable = (ar >> 16) & 1;
 }
 
+static int vmx_get_cpl(struct kvm_vcpu *vcpu)
+{
+   struct kvm_segment kvm_seg;
+
+   if (!(vcpu->arch.cr0 & X86_CR0_PE)) /* if real mode */
+   return 0;
+
+   if (vmx_get_rflags(vcpu) & X86_EFLAGS_VM) /* if virtual 8086 */
+   return 3;
+
+   vmx_get_segment(vcpu, &kvm_seg, VCPU_SREG_CS);
+   return kvm_seg.selector & 3;
+}
+
 static u32 vmx_segment_access_rights(struct kvm_segment *var)
 {
u32 ar;
@@ -2665,6 +2679,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
.get_segment_base = vmx_get_segment_base,
.get_segment = vmx_get_segment,
.set_segment = vmx_set_segment,
+   .get_cpl = vmx_get_cpl,
.get_cs_db_l_bits = vmx_get_cs_db_l_bits,
.decache_cr4_guest_bits = vmx_decache_cr4_guest_bits,
.set_cr0 = vmx_set_cr0,
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 2773f91..06bd154 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -387,6 +387,7 @@ struct kvm_x86_ops {
u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
void (*get_segment)(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg);
+   int (*get_cpl)(struct kvm_vcpu *vcpu);
void (*set_segment)(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg);
void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 35/35] KVM: x86: hardware task switching support

2008-04-03 Thread Avi Kivity
From: Izik Eidus <[EMAIL PROTECTED]>

This emulates the x86 hardware task switch mechanism in software, as it is
unsupported by either vmx or svm.  It allows operating systems which use it,
like freedos, to run as kvm guests.

Signed-off-by: Izik Eidus <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/svm.c |   15 ++-
 arch/x86/kvm/svm.h |3 +
 arch/x86/kvm/tss.h |   59 +++
 arch/x86/kvm/vmx.c |   15 ++
 arch/x86/kvm/x86.c |  408 
 include/asm-x86/kvm_host.h |9 +
 6 files changed, 506 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/kvm/tss.h

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index c1c1b97..ad27346 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1112,9 +1112,18 @@ static int invalid_op_interception(struct vcpu_svm *svm,
 static int task_switch_interception(struct vcpu_svm *svm,
struct kvm_run *kvm_run)
 {
-   pr_unimpl(&svm->vcpu, "%s: task switch is unsupported\n", __func__);
-   kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
-   return 0;
+   u16 tss_selector;
+
+   tss_selector = (u16)svm->vmcb->control.exit_info_1;
+   if (svm->vmcb->control.exit_info_2 &
+   (1ULL << SVM_EXITINFOSHIFT_TS_REASON_IRET))
+   return kvm_task_switch(&svm->vcpu, tss_selector,
+  TASK_SWITCH_IRET);
+   if (svm->vmcb->control.exit_info_2 &
+   (1ULL << SVM_EXITINFOSHIFT_TS_REASON_JMP))
+   return kvm_task_switch(&svm->vcpu, tss_selector,
+  TASK_SWITCH_JMP);
+   return kvm_task_switch(&svm->vcpu, tss_selector, TASK_SWITCH_CALL);
 }
 
 static int cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
diff --git a/arch/x86/kvm/svm.h b/arch/x86/kvm/svm.h
index 5fd5049..1b8afa7 100644
--- a/arch/x86/kvm/svm.h
+++ b/arch/x86/kvm/svm.h
@@ -238,6 +238,9 @@ struct __attribute__ ((__packed__)) vmcb {
 #define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID
 #define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR
 
+#define SVM_EXITINFOSHIFT_TS_REASON_IRET 36
+#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38
+
 #defineSVM_EXIT_READ_CR0   0x000
 #defineSVM_EXIT_READ_CR3   0x003
 #defineSVM_EXIT_READ_CR4   0x004
diff --git a/arch/x86/kvm/tss.h b/arch/x86/kvm/tss.h
new file mode 100644
index 000..622aa10
--- /dev/null
+++ b/arch/x86/kvm/tss.h
@@ -0,0 +1,59 @@
+#ifndef __TSS_SEGMENT_H
+#define __TSS_SEGMENT_H
+
+struct tss_segment_32 {
+   u32 prev_task_link;
+   u32 esp0;
+   u32 ss0;
+   u32 esp1;
+   u32 ss1;
+   u32 esp2;
+   u32 ss2;
+   u32 cr3;
+   u32 eip;
+   u32 eflags;
+   u32 eax;
+   u32 ecx;
+   u32 edx;
+   u32 ebx;
+   u32 esp;
+   u32 ebp;
+   u32 esi;
+   u32 edi;
+   u32 es;
+   u32 cs;
+   u32 ss;
+   u32 ds;
+   u32 fs;
+   u32 gs;
+   u32 ldt_selector;
+   u16 t;
+   u16 io_map;
+};
+
+struct tss_segment_16 {
+   u16 prev_task_link;
+   u16 sp0;
+   u16 ss0;
+   u16 sp1;
+   u16 ss1;
+   u16 sp2;
+   u16 ss2;
+   u16 ip;
+   u16 flag;
+   u16 ax;
+   u16 cx;
+   u16 dx;
+   u16 bx;
+   u16 sp;
+   u16 bp;
+   u16 si;
+   u16 di;
+   u16 es;
+   u16 cs;
+   u16 ss;
+   u16 ds;
+   u16 ldt;
+};
+
+#endif
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9b56032..cbca46a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2249,6 +2249,20 @@ static int handle_apic_access(struct kvm_vcpu *vcpu, 
struct kvm_run *kvm_run)
return 1;
 }
 
+static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
+{
+   unsigned long exit_qualification;
+   u16 tss_selector;
+   int reason;
+
+   exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
+
+   reason = (u32)exit_qualification >> 30;
+   tss_selector = exit_qualification;
+
+   return kvm_task_switch(vcpu, tss_selector, reason);
+}
+
 /*
  * The exit handlers return 1 if the exit was handled fully and guest execution
  * may resume.  Otherwise they set the kvm_run parameter to indicate what needs
@@ -2271,6 +2285,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu 
*vcpu,
[EXIT_REASON_TPR_BELOW_THRESHOLD] = handle_tpr_below_threshold,
[EXIT_REASON_APIC_ACCESS] = handle_apic_access,
[EXIT_REASON_WBINVD]  = handle_wbinvd,
+   [EXIT_REASON_TASK_SWITCH] = handle_task_switch,
 };
 
 static const int kvm_vmx_max_exit_handlers =
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 63afca1..acecde4 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -18,6 +18,7 @@
 #include "irq.h"
 #include "mmu.h"
 #include "i8254.h"
+#include "tss.h"
 
 #include 
 #include 
@

[kvm-devel] [PATCH 24/35] x86: allow machine_crash_shutdown to be replaced

2008-04-03 Thread Avi Kivity
From: Glauber Costa <[EMAIL PROTECTED]>

This patch a llows machine_crash_shutdown to
be replaced, just like any of the other functions
in machine_ops

Signed-off-by: Glauber Costa <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kernel/crash.c  |3 ++-
 arch/x86/kernel/reboot.c |   11 ++-
 include/asm-x86/reboot.h |1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 9a5fa0a..d262306 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_X86_32
 #include 
@@ -121,7 +122,7 @@ static void nmi_shootdown_cpus(void)
 }
 #endif
 
-void machine_crash_shutdown(struct pt_regs *regs)
+void native_machine_crash_shutdown(struct pt_regs *regs)
 {
/* This function is only called after the system
 * has panicked or is otherwise in a critical state.
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 484c4a8..708d6f8 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -471,7 +471,10 @@ struct machine_ops machine_ops = {
.shutdown = native_machine_shutdown,
.emergency_restart = native_machine_emergency_restart,
.restart = native_machine_restart,
-   .halt = native_machine_halt
+   .halt = native_machine_halt,
+#ifdef CONFIG_KEXEC
+   .crash_shutdown = native_machine_crash_shutdown,
+#endif
 };
 
 void machine_power_off(void)
@@ -499,3 +502,9 @@ void machine_halt(void)
machine_ops.halt();
 }
 
+#ifdef CONFIG_KEXEC
+void machine_crash_shutdown(struct pt_regs *regs)
+{
+   machine_ops.crash_shutdown(regs);
+}
+#endif
diff --git a/include/asm-x86/reboot.h b/include/asm-x86/reboot.h
index e9e3ffc..ff9b546 100644
--- a/include/asm-x86/reboot.h
+++ b/include/asm-x86/reboot.h
@@ -16,5 +16,6 @@ struct machine_ops
 extern struct machine_ops machine_ops;
 
 void machine_real_restart(unsigned char *code, int length);
+void native_machine_crash_shutdown(struct pt_regs *regs);
 
 #endif /* _ASM_REBOOT_H */
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 09/35] KVM: Prefix control register accessors with kvm_ to avoid namespace pollution

2008-04-03 Thread Avi Kivity
Names like 'set_cr3()' look dangerously close to affecting the host.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/vmx.c |   14 ++--
 arch/x86/kvm/x86.c |   46 ++--
 include/asm-x86/kvm_host.h |   12 +-
 3 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f46ad03..5034503 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1683,7 +1683,7 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
vmx->vcpu.arch.rmode.active = 0;
 
vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val();
-   set_cr8(&vmx->vcpu, 0);
+   kvm_set_cr8(&vmx->vcpu, 0);
msr = 0xfee0 | MSR_IA32_APICBASE_ENABLE;
if (vmx->vcpu.vcpu_id == 0)
msr |= MSR_IA32_APICBASE_BSP;
@@ -2026,22 +2026,22 @@ static int handle_cr(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
switch (cr) {
case 0:
vcpu_load_rsp_rip(vcpu);
-   set_cr0(vcpu, vcpu->arch.regs[reg]);
+   kvm_set_cr0(vcpu, vcpu->arch.regs[reg]);
skip_emulated_instruction(vcpu);
return 1;
case 3:
vcpu_load_rsp_rip(vcpu);
-   set_cr3(vcpu, vcpu->arch.regs[reg]);
+   kvm_set_cr3(vcpu, vcpu->arch.regs[reg]);
skip_emulated_instruction(vcpu);
return 1;
case 4:
vcpu_load_rsp_rip(vcpu);
-   set_cr4(vcpu, vcpu->arch.regs[reg]);
+   kvm_set_cr4(vcpu, vcpu->arch.regs[reg]);
skip_emulated_instruction(vcpu);
return 1;
case 8:
vcpu_load_rsp_rip(vcpu);
-   set_cr8(vcpu, vcpu->arch.regs[reg]);
+   kvm_set_cr8(vcpu, vcpu->arch.regs[reg]);
skip_emulated_instruction(vcpu);
if (irqchip_in_kernel(vcpu->kvm))
return 1;
@@ -2067,14 +2067,14 @@ static int handle_cr(struct kvm_vcpu *vcpu, struct 
kvm_run *kvm_run)
return 1;
case 8:
vcpu_load_rsp_rip(vcpu);
-   vcpu->arch.regs[reg] = get_cr8(vcpu);
+   vcpu->arch.regs[reg] = kvm_get_cr8(vcpu);
vcpu_put_rsp_rip(vcpu);
skip_emulated_instruction(vcpu);
return 1;
}
break;
case 3: /* lmsw */
-   lmsw(vcpu, (exit_qualification >> LMSW_SOURCE_DATA_SHIFT) & 
0x0f);
+   kvm_lmsw(vcpu, (exit_qualification >> LMSW_SOURCE_DATA_SHIFT) & 
0x0f);
 
skip_emulated_instruction(vcpu);
return 1;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0458bd5..dbcff38 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -237,7 +237,7 @@ out:
return changed;
 }
 
-void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
+void kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 {
if (cr0 & CR0_RESERVED_BITS) {
printk(KERN_DEBUG "set_cr0: 0x%lx #GP, reserved bits 0x%lx\n",
@@ -295,15 +295,15 @@ void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
kvm_mmu_reset_context(vcpu);
return;
 }
-EXPORT_SYMBOL_GPL(set_cr0);
+EXPORT_SYMBOL_GPL(kvm_set_cr0);
 
-void lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
+void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
 {
-   set_cr0(vcpu, (vcpu->arch.cr0 & ~0x0ful) | (msw & 0x0f));
+   kvm_set_cr0(vcpu, (vcpu->arch.cr0 & ~0x0ful) | (msw & 0x0f));
 }
-EXPORT_SYMBOL_GPL(lmsw);
+EXPORT_SYMBOL_GPL(kvm_lmsw);
 
-void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
+void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 {
if (cr4 & CR4_RESERVED_BITS) {
printk(KERN_DEBUG "set_cr4: #GP, reserved bits\n");
@@ -334,9 +334,9 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
vcpu->arch.cr4 = cr4;
kvm_mmu_reset_context(vcpu);
 }
-EXPORT_SYMBOL_GPL(set_cr4);
+EXPORT_SYMBOL_GPL(kvm_set_cr4);
 
-void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
+void kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
 {
if (cr3 == vcpu->arch.cr3 && !pdptrs_changed(vcpu)) {
kvm_mmu_flush_tlb(vcpu);
@@ -388,9 +388,9 @@ void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
}
up_read(&vcpu->kvm->slots_lock);
 }
-EXPORT_SYMBOL_GPL(set_cr3);
+EXPORT_SYMBOL_GPL(kvm_set_cr3);
 
-void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
+void kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
 {
if (cr8 & CR8_RESERVED_BITS) {
printk(KERN_DEBUG "set_cr8: #GP, reserved bits 

[kvm-devel] [PATCH 27/35] KVM: kvm.h: __user requires compiler.h

2008-04-03 Thread Avi Kivity
From: Christian Borntraeger <[EMAIL PROTECTED]>

include/linux/kvm.h defines struct kvm_dirty_log to
[...]
union {
void __user *dirty_bitmap; /* one bit per page */
__u64 padding;
};

__user requires compiler.h to compile. Currently, this works on x86
only coincidentally due to other include files. This patch makes
kvm.h compile in all cases.

Signed-off-by: Christian Borntraeger <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 include/linux/kvm.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index c1b502a..3bd3828 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 07/35] KVM: MMU: ignore zapped root pagetables

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Mark zapped root pagetables as invalid and ignore such pages during lookup.

This is a problem with the cr3-target feature, where a zapped root table fools
the faulting code into creating a read-only mapping. The result is a lockup
if the instruction can't be emulated.

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Cc: Anthony Liguori <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |   12 ++--
 arch/x86/kvm/x86.c |   12 
 include/asm-x86/kvm_host.h |1 +
 include/linux/kvm_host.h   |2 ++
 virt/kvm/kvm_main.c|   23 +++
 5 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index f7541fe..103d008 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -667,7 +667,8 @@ static struct kvm_mmu_page *kvm_mmu_lookup_page(struct kvm 
*kvm, gfn_t gfn)
index = kvm_page_table_hashfn(gfn);
bucket = &kvm->arch.mmu_page_hash[index];
hlist_for_each_entry(sp, node, bucket, hash_link)
-   if (sp->gfn == gfn && !sp->role.metaphysical) {
+   if (sp->gfn == gfn && !sp->role.metaphysical
+   && !sp->role.invalid) {
pgprintk("%s: found role %x\n",
 __FUNCTION__, sp->role.word);
return sp;
@@ -792,8 +793,11 @@ static void kvm_mmu_zap_page(struct kvm *kvm, struct 
kvm_mmu_page *sp)
if (!sp->root_count) {
hlist_del(&sp->hash_link);
kvm_mmu_free_page(kvm, sp);
-   } else
+   } else {
list_move(&sp->link, &kvm->arch.active_mmu_pages);
+   sp->role.invalid = 1;
+   kvm_reload_remote_mmus(kvm);
+   }
kvm_mmu_reset_last_pte_updated(kvm);
 }
 
@@ -1073,6 +1077,8 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu)
 
sp = page_header(root);
--sp->root_count;
+   if (!sp->root_count && sp->role.invalid)
+   kvm_mmu_zap_page(vcpu->kvm, sp);
vcpu->arch.mmu.root_hpa = INVALID_PAGE;
spin_unlock(&vcpu->kvm->mmu_lock);
return;
@@ -1085,6 +1091,8 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu)
root &= PT64_BASE_ADDR_MASK;
sp = page_header(root);
--sp->root_count;
+   if (!sp->root_count && sp->role.invalid)
+   kvm_mmu_zap_page(vcpu->kvm, sp);
}
vcpu->arch.mmu.pae_root[i] = INVALID_PAGE;
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0dd038e..e8e6492 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2658,6 +2658,10 @@ preempted:
kvm_x86_ops->guest_debug_pre(vcpu);
 
 again:
+   if (vcpu->requests)
+   if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests))
+   kvm_mmu_unload(vcpu);
+
r = kvm_mmu_reload(vcpu);
if (unlikely(r))
goto out;
@@ -2689,6 +2693,14 @@ again:
goto out;
}
 
+   if (vcpu->requests)
+   if (test_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests)) {
+   local_irq_enable();
+   preempt_enable();
+   r = 1;
+   goto out;
+   }
+
if (signal_pending(current)) {
local_irq_enable();
preempt_enable();
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 4f5a71a..7535839 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -140,6 +140,7 @@ union kvm_mmu_page_role {
unsigned pad_for_nice_hex_output : 6;
unsigned metaphysical : 1;
unsigned access : 3;
+   unsigned invalid : 1;
};
 };
 
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index eb88d32..994278f 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -37,6 +37,7 @@
 #define KVM_REQ_TLB_FLUSH  0
 #define KVM_REQ_MIGRATE_TIMER  1
 #define KVM_REQ_REPORT_TPR_ACCESS  2
+#define KVM_REQ_MMU_RELOAD 3
 
 struct kvm_vcpu;
 extern struct kmem_cache *kvm_vcpu_cache;
@@ -190,6 +191,7 @@ void kvm_resched(struct kvm_vcpu *vcpu);
 void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
 void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
 void kvm_flush_remote_tlbs(struct kvm *kvm);
+void kvm_reload_remote_mmus(struct kvm *kvm);
 
 long kvm_arch_dev_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf6df51..c41eb57 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -119,6 +119,29 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
smp_ca

[kvm-devel] [PATCH 02/35] KVM: Add stat counter for hypercalls

2008-04-03 Thread Avi Kivity
From: Amit Shah <[EMAIL PROTECTED]>

Signed-off-by: Amit Shah <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86.c |2 ++
 include/asm-x86/kvm_host.h |1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a063f44..15bba5d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -72,6 +72,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
{ "irq_window", VCPU_STAT(irq_window_exits) },
{ "halt_exits", VCPU_STAT(halt_exits) },
{ "halt_wakeup", VCPU_STAT(halt_wakeup) },
+   { "hypercalls", VCPU_STAT(hypercalls) },
{ "request_irq", VCPU_STAT(request_irq_exits) },
{ "irq_exits", VCPU_STAT(irq_exits) },
{ "host_state_reload", VCPU_STAT(host_state_reload) },
@@ -2405,6 +2406,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
}
vcpu->arch.regs[VCPU_REGS_RAX] = ret;
kvm_x86_ops->decache_regs(vcpu);
+   ++vcpu->stat.hypercalls;
return 0;
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_hypercall);
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 0c429c8..4f5a71a 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -327,6 +327,7 @@ struct kvm_vcpu_stat {
u32 fpu_reload;
u32 insn_emulation;
u32 insn_emulation_fail;
+   u32 hypercalls;
 };
 
 struct descriptor_table {
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 00/35] KVM updates for the 2.6.26 merge window (part II)

2008-04-03 Thread Avi Kivity
These thirty-five patches comprise the second batch of the updates I have
queued for 2.6.26.  Please review.

 arch/x86/Kconfig  |8 +
 arch/x86/kernel/Makefile  |1 +
 arch/x86/kernel/crash.c   |3 +-
 arch/x86/kernel/kvm.c |  247 ++
 arch/x86/kernel/kvmclock.c|   27 ++
 arch/x86/kernel/reboot.c  |   13 +-
 arch/x86/kernel/setup_32.c|1 +
 arch/x86/kernel/setup_64.c|2 +
 arch/x86/kvm/Kconfig  |2 +-
 arch/x86/kvm/Makefile |3 +-
 arch/x86/kvm/i8254.c  |  600 ++
 arch/x86/kvm/i8254.h  |   62 
 arch/x86/kvm/irq.c|3 +
 arch/x86/kvm/lapic.c  |8 +-
 arch/x86/kvm/mmu.c|  426 ++---
 arch/x86/kvm/paging_tmpl.h|   46 ++-
 arch/x86/kvm/segment_descriptor.h |   29 --
 arch/x86/kvm/svm.c|   41 ++-
 arch/x86/kvm/svm.h|3 +
 arch/x86/kvm/tss.h|   59 
 arch/x86/kvm/vmx.c|   70 +++-
 arch/x86/kvm/x86.c|  647 +
 arch/x86/kvm/x86_emulate.c|4 +-
 include/asm-x86/kvm.h |   21 ++
 include/asm-x86/kvm_host.h|   54 +++-
 include/asm-x86/kvm_para.h|   32 ++-
 include/asm-x86/reboot.h  |2 +
 include/linux/kvm.h   |7 +
 include/linux/kvm_host.h  |   21 +-
 include/linux/kvm_para.h  |   11 +-
 virt/kvm/kvm_main.c   |   78 -
 31 files changed, 2302 insertions(+), 229 deletions(-)

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 03/35] KVM: x86 emulator: fix sparse warnings in x86_emulate.c

2008-04-03 Thread Avi Kivity
From: Harvey Harrison <[EMAIL PROTECTED]>

Nesting __emulate_2op_nobyte inside__emulate_2op produces many shadowed
variable warnings on the internal variable _tmp used by both macros.

Change the outer macro to use __tmp.

Avoids a sparse warning like the following at every call site of __emulate_2op
arch/x86/kvm/x86_emulate.c:1091:3: warning: symbol '_tmp' shadows an earlier one
arch/x86/kvm/x86_emulate.c:1091:3: originally declared here
[18 more warnings suppressed]

Signed-off-by: Harvey Harrison <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86_emulate.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index cacdcf5..f59ed93 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -371,7 +371,7 @@ static u16 group2_table[] = {
 
 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
do { \
-   unsigned long _tmp;  \
+   unsigned long __tmp; \
switch ((_dst).bytes) {  \
case 1:  \
__asm__ __volatile__ (   \
@@ -379,7 +379,7 @@ static u16 group2_table[] = {
_op"b %"_bx"3,%1; "  \
_POST_EFLAGS("0", "4", "2")  \
: "=m" (_eflags), "=m" ((_dst).val), \
- "=&r" (_tmp)   \
+ "=&r" (__tmp)  \
: _by ((_src).val), "i" (EFLAGS_MASK));  \
break;   \
default: \
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 10/35] KVM: Use kzalloc to avoid allocating kvm_regs from kernel stack

2008-04-03 Thread Avi Kivity
From: Xiantao Zhang <[EMAIL PROTECTED]>

Since the size of kvm_regs is too big to allocate from kernel stack on ia64,
use kzalloc to allocate it.

Signed-off-by: Xiantao Zhang <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 virt/kvm/kvm_main.c |   33 ++---
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 0dabf58..30bf832 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -849,28 +849,39 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
break;
case KVM_GET_REGS: {
-   struct kvm_regs kvm_regs;
+   struct kvm_regs *kvm_regs;
 
-   memset(&kvm_regs, 0, sizeof kvm_regs);
-   r = kvm_arch_vcpu_ioctl_get_regs(vcpu, &kvm_regs);
-   if (r)
+   r = -ENOMEM;
+   kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+   if (!kvm_regs)
goto out;
+   r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
+   if (r)
+   goto out_free1;
r = -EFAULT;
-   if (copy_to_user(argp, &kvm_regs, sizeof kvm_regs))
-   goto out;
+   if (copy_to_user(argp, kvm_regs, sizeof(struct kvm_regs)))
+   goto out_free1;
r = 0;
+out_free1:
+   kfree(kvm_regs);
break;
}
case KVM_SET_REGS: {
-   struct kvm_regs kvm_regs;
+   struct kvm_regs *kvm_regs;
 
-   r = -EFAULT;
-   if (copy_from_user(&kvm_regs, argp, sizeof kvm_regs))
+   r = -ENOMEM;
+   kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
+   if (!kvm_regs)
goto out;
-   r = kvm_arch_vcpu_ioctl_set_regs(vcpu, &kvm_regs);
+   r = -EFAULT;
+   if (copy_from_user(kvm_regs, argp, sizeof(struct kvm_regs)))
+   goto out_free2;
+   r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
if (r)
-   goto out;
+   goto out_free2;
r = 0;
+out_free2:
+   kfree(kvm_regs);
break;
}
case KVM_GET_SREGS: {
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 01/35] KVM: Use x86's segment descriptor struct instead of private definition

2008-04-03 Thread Avi Kivity
The x86 desc_struct unification allows us to remove segment_descriptor.h.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/segment_descriptor.h |   29 -
 arch/x86/kvm/vmx.c|3 +--
 arch/x86/kvm/x86.c|   15 +++
 3 files changed, 8 insertions(+), 39 deletions(-)
 delete mode 100644 arch/x86/kvm/segment_descriptor.h

diff --git a/arch/x86/kvm/segment_descriptor.h 
b/arch/x86/kvm/segment_descriptor.h
deleted file mode 100644
index 56fc4c8..000
--- a/arch/x86/kvm/segment_descriptor.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __SEGMENT_DESCRIPTOR_H
-#define __SEGMENT_DESCRIPTOR_H
-
-struct segment_descriptor {
-   u16 limit_low;
-   u16 base_low;
-   u8  base_mid;
-   u8  type : 4;
-   u8  system : 1;
-   u8  dpl : 2;
-   u8  present : 1;
-   u8  limit_high : 4;
-   u8  avl : 1;
-   u8  long_mode : 1;
-   u8  default_op : 1;
-   u8  granularity : 1;
-   u8  base_high;
-} __attribute__((packed));
-
-#ifdef CONFIG_X86_64
-/* LDT or TSS descriptor in the GDT. 16 bytes. */
-struct segment_descriptor_64 {
-   struct segment_descriptor s;
-   u32 base_higher;
-   u32 pad_zero;
-};
-
-#endif
-#endif
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 2d5ccec..f46ad03 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -17,7 +17,6 @@
 
 #include "irq.h"
 #include "vmx.h"
-#include "segment_descriptor.h"
 #include "mmu.h"
 
 #include 
@@ -388,7 +387,7 @@ static void reload_tss(void)
 * VT restores TR but not its size.  Useless.
 */
struct descriptor_table gdt;
-   struct segment_descriptor *descs;
+   struct desc_struct *descs;
 
get_gdt(&gdt);
descs = (void *)gdt.base;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b7c32f6..a063f44 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -15,7 +15,6 @@
  */
 
 #include 
-#include "segment_descriptor.h"
 #include "irq.h"
 #include "mmu.h"
 
@@ -29,6 +28,7 @@
 
 #include 
 #include 
+#include 
 
 #define MAX_IO_MSRS 256
 #define CR0_RESERVED_BITS  \
@@ -94,7 +94,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 unsigned long segment_base(u16 selector)
 {
struct descriptor_table gdt;
-   struct segment_descriptor *d;
+   struct desc_struct *d;
unsigned long table_base;
unsigned long v;
 
@@ -110,13 +110,12 @@ unsigned long segment_base(u16 selector)
asm("sldt %0" : "=g"(ldt_selector));
table_base = segment_base(ldt_selector);
}
-   d = (struct segment_descriptor *)(table_base + (selector & ~7));
-   v = d->base_low | ((unsigned long)d->base_mid << 16) |
-   ((unsigned long)d->base_high << 24);
+   d = (struct desc_struct *)(table_base + (selector & ~7));
+   v = d->base0 | ((unsigned long)d->base1 << 16) |
+   ((unsigned long)d->base2 << 24);
 #ifdef CONFIG_X86_64
-   if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
-   v |= ((unsigned long) \
- ((struct segment_descriptor_64 *)d)->base_higher) << 32;
+   if (d->s == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
+   v |= ((unsigned long)((struct ldttss_desc64 *)d)->base3) << 32;
 #endif
return v;
 }
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 14/35] KVM: Remove pointless desc_ptr #ifdef

2008-04-03 Thread Avi Kivity
The desc_struct changes left an unnecessary #ifdef; remove it.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/svm.c |4 
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index b2c667f..51741f9 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -290,11 +290,7 @@ static void svm_hardware_enable(void *garbage)
 
struct svm_cpu_data *svm_data;
uint64_t efer;
-#ifdef CONFIG_X86_64
-   struct desc_ptr gdt_descr;
-#else
struct desc_ptr gdt_descr;
-#endif
struct desc_struct *gdt;
int me = raw_smp_processor_id();
 
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 06/35] KVM: Implement dummy values for MSR_PERF_STATUS

2008-04-03 Thread Avi Kivity
From: Alexander Graf <[EMAIL PROTECTED]>

Darwin relies on this and ceases to work without.

Signed-off-by: Alexander Graf <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index cf6261e..0dd038e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -426,6 +426,7 @@ static u32 msrs_to_save[] = {
MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
 #endif
MSR_IA32_TIME_STAMP_COUNTER, MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK,
+   MSR_IA32_PERF_STATUS,
 };
 
 static unsigned num_msrs_to_save;
@@ -653,7 +654,6 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 
*pdata)
case MSR_IA32_MC0_MISC+12:
case MSR_IA32_MC0_MISC+16:
case MSR_IA32_UCODE_REV:
-   case MSR_IA32_PERF_STATUS:
case MSR_IA32_EBL_CR_POWERON:
/* MTRR registers */
case 0xfe:
@@ -669,6 +669,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 
*pdata)
case MSR_IA32_MISC_ENABLE:
data = vcpu->arch.ia32_misc_enable_msr;
break;
+   case MSR_IA32_PERF_STATUS:
+   /* TSC increment by tick */
+   data = 1000ULL;
+   /* CPU multiplier */
+   data |= (((uint64_t)4ULL) << 40);
+   break;
case MSR_EFER:
data = vcpu->arch.shadow_efer;
break;
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 04/35] KVM: SVM: make iopm_base static

2008-04-03 Thread Avi Kivity
From: Harvey Harrison <[EMAIL PROTECTED]>

Fixes sparse warning as well.
arch/x86/kvm/svm.c:69:15: warning: symbol 'iopm_base' was not declared. Should 
it be static?

Signed-off-by: Harvey Harrison <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/svm.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 7d73e93..ff6e5c8 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -66,7 +66,7 @@ static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
return container_of(vcpu, struct vcpu_svm, vcpu);
 }
 
-unsigned long iopm_base;
+static unsigned long iopm_base;
 
 struct kvm_ldttss_desc {
u16 limit0;
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 05/35] KVM: sparse fixes for kvm/x86.c

2008-04-03 Thread Avi Kivity
From: Harvey Harrison <[EMAIL PROTECTED]>

In two case statements, use the ever popular 'i' instead of index:
arch/x86/kvm/x86.c:1063:7: warning: symbol 'index' shadows an earlier one
arch/x86/kvm/x86.c:1000:9: originally declared here
arch/x86/kvm/x86.c:1079:7: warning: symbol 'index' shadows an earlier one
arch/x86/kvm/x86.c:1000:9: originally declared here

Make it static.
arch/x86/kvm/x86.c:1945:24: warning: symbol 'emulate_ops' was not declared. 
Should it be static?

Drop the return statements.
arch/x86/kvm/x86.c:2878:2: warning: returning void-valued expression
arch/x86/kvm/x86.c:2944:2: warning: returning void-valued expression

Signed-off-by: Harvey Harrison <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/x86.c |   26 +-
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 15bba5d..cf6261e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1083,32 +1083,32 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 
*entry, u32 function,
}
/* function 4 and 0xb have additional index. */
case 4: {
-   int index, cache_type;
+   int i, cache_type;
 
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
/* read more entries until cache_type is zero */
-   for (index = 1; *nent < maxnent; ++index) {
-   cache_type = entry[index - 1].eax & 0x1f;
+   for (i = 1; *nent < maxnent; ++i) {
+   cache_type = entry[i - 1].eax & 0x1f;
if (!cache_type)
break;
-   do_cpuid_1_ent(&entry[index], function, index);
-   entry[index].flags |=
+   do_cpuid_1_ent(&entry[i], function, i);
+   entry[i].flags |=
   KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
++*nent;
}
break;
}
case 0xb: {
-   int index, level_type;
+   int i, level_type;
 
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
/* read more entries until level_type is zero */
-   for (index = 1; *nent < maxnent; ++index) {
-   level_type = entry[index - 1].ecx & 0xff;
+   for (i = 1; *nent < maxnent; ++i) {
+   level_type = entry[i - 1].ecx & 0xff;
if (!level_type)
break;
-   do_cpuid_1_ent(&entry[index], function, index);
-   entry[index].flags |=
+   do_cpuid_1_ent(&entry[i], function, i);
+   entry[i].flags |=
   KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
++*nent;
}
@@ -1965,7 +1965,7 @@ void kvm_report_emulation_failure(struct kvm_vcpu *vcpu, 
const char *context)
 }
 EXPORT_SYMBOL_GPL(kvm_report_emulation_failure);
 
-struct x86_emulate_ops emulate_ops = {
+static struct x86_emulate_ops emulate_ops = {
.read_std= emulator_read_std,
.read_emulated   = emulator_read_emulated,
.write_emulated  = emulator_write_emulated,
@@ -2899,7 +2899,7 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
 static void get_segment(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg)
 {
-   return kvm_x86_ops->get_segment(vcpu, var, seg);
+   kvm_x86_ops->get_segment(vcpu, var, seg);
 }
 
 void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
@@ -2965,7 +2965,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
 static void set_segment(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg)
 {
-   return kvm_x86_ops->set_segment(vcpu, var, seg);
+   kvm_x86_ops->set_segment(vcpu, var, seg);
 }
 
 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 23/35] x86: KVM guest: hypercall batching

2008-04-03 Thread Avi Kivity
From: Marcelo Tosatti <[EMAIL PROTECTED]>

Batch pte updates and tlb flushes in lazy MMU mode.

[avi:
 - adjust to mmu_op
 - helper for getting para_state without debug warnings]

Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kernel/kvm.c |   62 +++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 1bb6e97..d9121f9 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -26,6 +26,22 @@
 #include 
 #include 
 #include 
+#include 
+
+#define MMU_QUEUE_SIZE 1024
+
+struct kvm_para_state {
+   u8 mmu_queue[MMU_QUEUE_SIZE];
+   int mmu_queue_len;
+   enum paravirt_lazy_mode mode;
+};
+
+static DEFINE_PER_CPU(struct kvm_para_state, para_state);
+
+static struct kvm_para_state *kvm_para_state(void)
+{
+   return &per_cpu(para_state, raw_smp_processor_id());
+}
 
 /*
  * No need for any "IO delay" on KVM
@@ -48,6 +64,28 @@ static void kvm_mmu_op(void *buffer, unsigned len)
} while (len);
 }
 
+static void mmu_queue_flush(struct kvm_para_state *state)
+{
+   if (state->mmu_queue_len) {
+   kvm_mmu_op(state->mmu_queue, state->mmu_queue_len);
+   state->mmu_queue_len = 0;
+   }
+}
+
+static void kvm_deferred_mmu_op(void *buffer, int len)
+{
+   struct kvm_para_state *state = kvm_para_state();
+
+   if (state->mode != PARAVIRT_LAZY_MMU) {
+   kvm_mmu_op(buffer, len);
+   return;
+   }
+   if (state->mmu_queue_len + len > sizeof state->mmu_queue)
+   mmu_queue_flush(state);
+   memcpy(state->mmu_queue + state->mmu_queue_len, buffer, len);
+   state->mmu_queue_len += len;
+}
+
 static void kvm_mmu_write(void *dest, u64 val)
 {
__u64 pte_phys;
@@ -68,7 +106,7 @@ static void kvm_mmu_write(void *dest, u64 val)
wpte.pte_val = val;
wpte.pte_phys = pte_phys;
 
-   kvm_mmu_op(&wpte, sizeof wpte);
+   kvm_deferred_mmu_op(&wpte, sizeof wpte);
 }
 
 /*
@@ -137,7 +175,7 @@ static void kvm_flush_tlb(void)
.header.op = KVM_MMU_OP_FLUSH_TLB,
};
 
-   kvm_mmu_op(&ftlb, sizeof ftlb);
+   kvm_deferred_mmu_op(&ftlb, sizeof ftlb);
 }
 
 static void kvm_release_pt(u32 pfn)
@@ -150,6 +188,23 @@ static void kvm_release_pt(u32 pfn)
kvm_mmu_op(&rpt, sizeof rpt);
 }
 
+static void kvm_enter_lazy_mmu(void)
+{
+   struct kvm_para_state *state = kvm_para_state();
+
+   paravirt_enter_lazy_mmu();
+   state->mode = paravirt_get_lazy_mode();
+}
+
+static void kvm_leave_lazy_mmu(void)
+{
+   struct kvm_para_state *state = kvm_para_state();
+
+   mmu_queue_flush(state);
+   paravirt_leave_lazy(paravirt_get_lazy_mode());
+   state->mode = paravirt_get_lazy_mode();
+}
+
 static void paravirt_ops_setup(void)
 {
pv_info.name = "KVM";
@@ -177,6 +232,9 @@ static void paravirt_ops_setup(void)
pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
pv_mmu_ops.release_pt = kvm_release_pt;
pv_mmu_ops.release_pd = kvm_release_pt;
+
+   pv_mmu_ops.lazy_mode.enter = kvm_enter_lazy_mmu;
+   pv_mmu_ops.lazy_mode.leave = kvm_leave_lazy_mmu;
}
 }
 
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 13/35] KVM: VMX: Don't adjust tsc offset forward

2008-04-03 Thread Avi Kivity
Most Intel hosts have a stable tsc, and playing with the offset only
reduces accuracy.  By limiting tsc offset adjustment only to forward updates,
we effectively disable tsc offset adjustment on these hosts.

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>
---
 arch/x86/kvm/vmx.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7ef710a..fb0389d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -519,7 +519,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
struct vcpu_vmx *vmx = to_vmx(vcpu);
u64 phys_addr = __pa(vmx->vmcs);
-   u64 tsc_this, delta;
+   u64 tsc_this, delta, new_offset;
 
if (vcpu->cpu != cpu) {
vcpu_clear(vmx);
@@ -559,8 +559,11 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 * Make sure the time stamp counter is monotonous.
 */
rdtscll(tsc_this);
-   delta = vcpu->arch.host_tsc - tsc_this;
-   vmcs_write64(TSC_OFFSET, vmcs_read64(TSC_OFFSET) + delta);
+   if (tsc_this < vcpu->arch.host_tsc) {
+   delta = vcpu->arch.host_tsc - tsc_this;
+   new_offset = vmcs_read64(TSC_OFFSET) + delta;
+   vmcs_write64(TSC_OFFSET, new_offset);
+   }
}
 }
 
-- 
1.5.4.5


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] QEMU/KVM: make kvm_arch_load_regs() aware of in kernel APIC

2008-04-03 Thread Marcelo Tosatti

kvm_arch_load_regs() might load APIC base and APIC TPR from the
uninitialized userspace APIC emulation.

This happened when running X11 on SMP guest in my case, disabling the
APIC for vcpu3:

vcpu not ready for apic_round_robin
vcpu not ready for apic_round_robin
vcpu not ready for apic_round_robin
...


Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>


diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
index 78490c5..401fbc6 100644
--- a/qemu/qemu-kvm-x86.c
+++ b/qemu/qemu-kvm-x86.c
@@ -250,9 +250,15 @@ void kvm_arch_load_regs(CPUState *env)
 sregs.cr3 = env->cr[3];
 sregs.cr4 = env->cr[4];
 
-sregs.apic_base = cpu_get_apic_base(env);
+if (kvm_irqchip_in_kernel(kvm_context)) {
+sregs.cr8 = kvm_get_cr8(kvm_context, env->cpu_index);
+sregs.apic_base = kvm_get_apic_base(kvm_context, env->cpu_index);
+} else {
+sregs.cr8 = cpu_get_apic_tpr(env);
+sregs.apic_base = cpu_get_apic_base(env);
+}
+
 sregs.efer = env->efer;
-sregs.cr8 = cpu_get_apic_tpr(env);
 
 kvm_set_sregs(kvm_context, env->cpu_index, &sregs);
 

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH] Fix vmmouse with -smp

2008-04-03 Thread Anthony Liguori
The vmport code is very broken for SMP guests.  It uses a global CPUState
that's initialized multiple times?  At any rate, since it needs to know CPU
registers for the current CPU in a PIO handler, it needs to use cpu_single_env.

This patch makes vmmouse when using -smp > 1

Signed-off-by: Anthony Liguori <[EMAIL PROTECTED]>

diff --git a/hw/pc.c b/hw/pc.c
index 4fec2d4..e126f92 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -748,9 +748,10 @@ static void pc_init1(int ram_size, int vga_ram_size,
 if (pci_enabled) {
 apic_init(env);
 }
-vmport_init(env);
 }
 
+vmport_init();
+
 /* allocate RAM */
 ram_addr = qemu_ram_alloc(ram_size);
 cpu_register_physical_memory(0, ram_size, ram_addr);
diff --git a/hw/pc.h b/hw/pc.h
index 9f83050..8626599 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -59,7 +59,7 @@ int pit_get_mode(PITState *pit, int channel);
 int pit_get_out(PITState *pit, int channel, int64_t current_time);
 
 /* vmport.c */
-void vmport_init(CPUState *env);
+void vmport_init(void);
 void vmport_register(unsigned char command, IOPortReadFunc *func, void 
*opaque);
 
 /* vmmouse.c */
diff --git a/hw/vmport.c b/hw/vmport.c
index 8044c9f..3655ad1 100644
--- a/hw/vmport.c
+++ b/hw/vmport.c
@@ -34,7 +34,6 @@
 
 typedef struct _VMPortState
 {
-CPUState *env;
 IOPortReadFunc *func[VMPORT_ENTRIES];
 void *opaque[VMPORT_ENTRIES];
 } VMPortState;
@@ -53,14 +52,15 @@ void vmport_register(unsigned char command, IOPortReadFunc 
*func, void *opaque)
 static uint32_t vmport_ioport_read(void *opaque, uint32_t addr)
 {
 VMPortState *s = opaque;
+CPUState *env = cpu_single_env;
 unsigned char command;
 uint32_t eax;
 
-eax = s->env->regs[R_EAX];
+eax = env->regs[R_EAX];
 if (eax != VMPORT_MAGIC)
 return eax;
 
-command = s->env->regs[R_ECX];
+command = env->regs[R_ECX];
 if (command >= VMPORT_ENTRIES)
 return eax;
 if (!s->func[command])
@@ -74,25 +74,23 @@ static uint32_t vmport_ioport_read(void *opaque, uint32_t 
addr)
 
 static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
 {
-CPUState *env = opaque;
+CPUState *env = cpu_single_env;
 env->regs[R_EBX] = VMPORT_MAGIC;
 return 6;
 }
 
 static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
 {
-CPUState *env = opaque;
+CPUState *env = cpu_single_env;
 env->regs[R_EBX] = 0x1177;
 return ram_size;
 }
 
-void vmport_init(CPUState *env)
+void vmport_init(void)
 {
-port_state.env = env;
-
 register_ioport_read(0x5658, 1, 4, vmport_ioport_read, &port_state);
 
 /* Register some generic port commands */
-vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, env);
-vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, env);
+vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
+vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
 }

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] direct access to hard-disk devices

2008-04-03 Thread Andrés Moré
Hi,

I've been trying to use kvm (+ PXE + root-over-NFS) to remotely boot live
images on client servers started using wakeonlan.
However, I'm still trying to find out how to attach a kvm guest directly to
a 'real' harddisk device file.

Is this possible on the current implementation?

Thanks in advance, I would really appreciate your comments on this.

-- Andres
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] direct access to hard-disk devices

2008-04-03 Thread Brian Jackson
kvm -drive file=/dev/sdX

Where sdX is some drive you want to hook up to the virtual machine.

Be very careful, you can really mess things up if you use the wrong device.

--Brian Jackson


On Thursday 03 April 2008 8:50:49 pm Andrés Moré wrote:
> Hi,
>
> I've been trying to use kvm (+ PXE + root-over-NFS) to remotely boot live
> images on client servers started using wakeonlan.
> However, I'm still trying to find out how to attach a kvm guest directly to
> a 'real' harddisk device file.
>
> Is this possible on the current implementation?
>
> Thanks in advance, I would really appreciate your comments on this.
>
> -- Andres

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel