public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26
@ 2008-05-21 23:22 Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 1 of 5] KVM: ppc: Remove duplicate function Hollis Blanchard
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-21 23:22 UTC (permalink / raw)
  To: avi; +Cc: kvm, kvm-ppc

Hi Avi, these bug fixes should be committed for 2.6.26. Most are pretty
harmless. Although the mmap_sem locking problem is fatal if you hit it, in
practice we simply shouldn't hit that error case anyways.

-Hollis

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1 of 5] KVM: ppc: Remove duplicate function
  2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
@ 2008-05-21 23:22 ` Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 2 of 5] KVM: ppc: add lwzx/stwz emulation Hollis Blanchard
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-21 23:22 UTC (permalink / raw)
  To: avi; +Cc: kvm, kvm-ppc

This was left behind from some code movement.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/arch/powerpc/kvm/booke_guest.c b/arch/powerpc/kvm/booke_guest.c
--- a/arch/powerpc/kvm/booke_guest.c
+++ b/arch/powerpc/kvm/booke_guest.c
@@ -225,39 +225,6 @@ void kvmppc_check_and_deliver_interrupts
 		                         BITS_PER_BYTE * sizeof(*pending),
 		                         priority + 1);
 	}
-}
-
-static int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)
-{
-	enum emulation_result er;
-	int r;
-
-	er = kvmppc_emulate_instruction(run, vcpu);
-	switch (er) {
-	case EMULATE_DONE:
-		/* Future optimization: only reload non-volatiles if they were
-		 * actually modified. */
-		r = RESUME_GUEST_NV;
-		break;
-	case EMULATE_DO_MMIO:
-		run->exit_reason = KVM_EXIT_MMIO;
-		/* We must reload nonvolatiles because "update" load/store
-		 * instructions modify register state. */
-		/* Future optimization: only reload non-volatiles if they were
-		 * actually modified. */
-		r = RESUME_HOST_NV;
-		break;
-	case EMULATE_FAIL:
-		/* XXX Deliver Program interrupt to guest. */
-		printk(KERN_EMERG "%s: emulation failed (%08x)\n", __func__,
-		       vcpu->arch.last_inst);
-		r = RESUME_HOST;
-		break;
-	default:
-		BUG();
-	}
-
-	return r;
 }
 
 /**
diff --git a/include/asm-powerpc/kvm_ppc.h b/include/asm-powerpc/kvm_ppc.h
--- a/include/asm-powerpc/kvm_ppc.h
+++ b/include/asm-powerpc/kvm_ppc.h
@@ -57,6 +57,7 @@ extern int kvmppc_handle_store(struct kv
 
 extern int kvmppc_emulate_instruction(struct kvm_run *run,
                                       struct kvm_vcpu *vcpu);
+extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
 
 extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn,
                            u64 asid, u32 flags);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2 of 5] KVM: ppc: add lwzx/stwz emulation
  2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 1 of 5] KVM: ppc: Remove duplicate function Hollis Blanchard
@ 2008-05-21 23:22 ` Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 3 of 5] KVM: ppc: Remove unmatched kunmap() call Hollis Blanchard
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-21 23:22 UTC (permalink / raw)
  To: avi; +Cc: kvm, kvm-ppc

Somehow these load/store instructions got missed before, but weren't used by
the guest so didn't break anything.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>

diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -246,6 +246,11 @@ int kvmppc_emulate_instruction(struct kv
 	case 31:
 		switch (get_xop(inst)) {
 
+		case 23:                                        /* lwzx */
+			rt = get_rt(inst);
+			emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
+			break;
+
 		case 83:                                        /* mfmsr */
 			rt = get_rt(inst);
 			vcpu->arch.gpr[rt] = vcpu->arch.msr;
@@ -265,6 +270,13 @@ int kvmppc_emulate_instruction(struct kv
 		case 146:                                       /* mtmsr */
 			rs = get_rs(inst);
 			kvmppc_set_msr(vcpu, vcpu->arch.gpr[rs]);
+			break;
+
+		case 151:                                       /* stwx */
+			rs = get_rs(inst);
+			emulated = kvmppc_handle_store(run, vcpu,
+			                               vcpu->arch.gpr[rs],
+			                               4, 1);
 			break;
 
 		case 163:                                       /* wrteei */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3 of 5] KVM: ppc: Remove unmatched kunmap() call
  2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 1 of 5] KVM: ppc: Remove duplicate function Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 2 of 5] KVM: ppc: add lwzx/stwz emulation Hollis Blanchard
@ 2008-05-21 23:22 ` Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 4 of 5] KVM: ppc: Use a read lock around MMU operations, and release it on error Hollis Blanchard
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-21 23:22 UTC (permalink / raw)
  To: avi; +Cc: kvm, kvm-ppc

We're not calling kmap() now, so we shouldn't call kunmap() either. This has no
practical effect in the non-highmem case, which is why it hasn't caused more
obvious problems.

Pointed out by Anthony Liguori.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
--- a/arch/powerpc/kvm/44x_tlb.c
+++ b/arch/powerpc/kvm/44x_tlb.c
@@ -116,8 +116,6 @@ static void kvmppc_44x_shadow_release(st
 	struct tlbe *stlbe = &vcpu->arch.shadow_tlb[index];
 	struct page *page = vcpu->arch.shadow_pages[index];
 
-	kunmap(vcpu->arch.shadow_pages[index]);
-
 	if (get_tlb_v(stlbe)) {
 		if (kvmppc_44x_tlbe_is_writable(stlbe))
 			kvm_release_page_dirty(page);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4 of 5] KVM: ppc: Use a read lock around MMU operations, and release it on error
  2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
                   ` (2 preceding siblings ...)
  2008-05-21 23:22 ` [PATCH 3 of 5] KVM: ppc: Remove unmatched kunmap() call Hollis Blanchard
@ 2008-05-21 23:22 ` Hollis Blanchard
  2008-05-21 23:22 ` [PATCH 5 of 5] [kvm powerpc] Report bad GFNs Hollis Blanchard
  2008-05-25 10:35 ` [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Avi Kivity
  5 siblings, 0 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-21 23:22 UTC (permalink / raw)
  To: avi; +Cc: kvm, kvm-ppc

gfn_to_page() and kvm_release_page_clean() are called from other contexts with
mmap_sem locked only for reading.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
--- a/arch/powerpc/kvm/44x_tlb.c
+++ b/arch/powerpc/kvm/44x_tlb.c
@@ -142,18 +142,19 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcp
 	stlbe = &vcpu->arch.shadow_tlb[victim];
 
 	/* Get reference to new page. */
-	down_write(&current->mm->mmap_sem);
+	down_read(&current->mm->mmap_sem);
 	new_page = gfn_to_page(vcpu->kvm, gfn);
 	if (is_error_page(new_page)) {
 		printk(KERN_ERR "Couldn't get guest page!\n");
 		kvm_release_page_clean(new_page);
+		up_read(&current->mm->mmap_sem);
 		return;
 	}
 	hpaddr = page_to_phys(new_page);
 
 	/* Drop reference to old page. */
 	kvmppc_44x_shadow_release(vcpu, victim);
-	up_write(&current->mm->mmap_sem);
+	up_read(&current->mm->mmap_sem);
 
 	vcpu->arch.shadow_pages[victim] = new_page;
 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5 of 5] [kvm powerpc] Report bad GFNs
  2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
                   ` (3 preceding siblings ...)
  2008-05-21 23:22 ` [PATCH 4 of 5] KVM: ppc: Use a read lock around MMU operations, and release it on error Hollis Blanchard
@ 2008-05-21 23:22 ` Hollis Blanchard
  2008-05-22  2:47   ` Anthony Liguori
  2008-05-25 10:35 ` [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Avi Kivity
  5 siblings, 1 reply; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-21 23:22 UTC (permalink / raw)
  To: avi; +Cc: kvm, kvm-ppc

This code shouldn't be hit anyways, but when it is, it's useful to have a
little more information about the failure.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
--- a/arch/powerpc/kvm/44x_tlb.c
+++ b/arch/powerpc/kvm/44x_tlb.c
@@ -145,7 +145,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcp
 	down_read(&current->mm->mmap_sem);
 	new_page = gfn_to_page(vcpu->kvm, gfn);
 	if (is_error_page(new_page)) {
-		printk(KERN_ERR "Couldn't get guest page!\n");
+		printk(KERN_ERR "Couldn't get guest page for gfn %lx!\n", gfn);
 		kvm_release_page_clean(new_page);
 		up_read(&current->mm->mmap_sem);
 		return;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5 of 5] [kvm powerpc] Report bad GFNs
  2008-05-21 23:22 ` [PATCH 5 of 5] [kvm powerpc] Report bad GFNs Hollis Blanchard
@ 2008-05-22  2:47   ` Anthony Liguori
  2008-05-22 14:02     ` Hollis Blanchard
  0 siblings, 1 reply; 10+ messages in thread
From: Anthony Liguori @ 2008-05-22  2:47 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: avi, kvm, kvm-ppc

Hollis Blanchard wrote:
> This code shouldn't be hit anyways, but when it is, it's useful to have a
> little more information about the failure.
>
> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
>
> diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
> --- a/arch/powerpc/kvm/44x_tlb.c
> +++ b/arch/powerpc/kvm/44x_tlb.c
> @@ -145,7 +145,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcp
>  	down_read(&current->mm->mmap_sem);
>  	new_page = gfn_to_page(vcpu->kvm, gfn);
>  	if (is_error_page(new_page)) {
> -		printk(KERN_ERR "Couldn't get guest page!\n");
> +		printk(KERN_ERR "Couldn't get guest page for gfn %lx!\n", gfn);
>  		kvm_release_page_clean(new_page);
>  		up_read(&current->mm->mmap_sem);
>  		return;
>   

FWIW, you should probably rate limit this sort of thing if this is what 
would get triggered if the guest tried to program the tlb with an 
invalid gfn.

Regards,

Anthony Liguori

> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>   


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5 of 5] [kvm powerpc] Report bad GFNs
  2008-05-22  2:47   ` Anthony Liguori
@ 2008-05-22 14:02     ` Hollis Blanchard
  0 siblings, 0 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-22 14:02 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: avi, kvm, kvm-ppc

On Wednesday 21 May 2008 21:47:40 Anthony Liguori wrote:
> Hollis Blanchard wrote:
> > This code shouldn't be hit anyways, but when it is, it's useful to have a
> > little more information about the failure.
> >
> > Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
> >
> > diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
> > --- a/arch/powerpc/kvm/44x_tlb.c
> > +++ b/arch/powerpc/kvm/44x_tlb.c
> > @@ -145,7 +145,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcp
> >  	down_read(&current->mm->mmap_sem);
> >  	new_page = gfn_to_page(vcpu->kvm, gfn);
> >  	if (is_error_page(new_page)) {
> > -		printk(KERN_ERR "Couldn't get guest page!\n");
> > +		printk(KERN_ERR "Couldn't get guest page for gfn %lx!\n", gfn);
> >  		kvm_release_page_clean(new_page);
> >  		up_read(&current->mm->mmap_sem);
> >  		return;
> >   
> 
> FWIW, you should probably rate limit this sort of thing if this is what 
> would get triggered if the guest tried to program the tlb with an 
> invalid gfn.

That was my initial thought as well, but in general, kvmppc_mmu_map() is only 
called if a TLB entry is "safe" -- meaning kvm_is_visible_gfn(kvm, gfn) was 
true. So in the absence of bugs elsewhere, this should never happen... but we 
know how that goes. ;)

Anyways, that's why I'm not worried about rate limiting here.

-- 
Hollis Blanchard
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26
  2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
                   ` (4 preceding siblings ...)
  2008-05-21 23:22 ` [PATCH 5 of 5] [kvm powerpc] Report bad GFNs Hollis Blanchard
@ 2008-05-25 10:35 ` Avi Kivity
  2008-05-27 15:39   ` Hollis Blanchard
  5 siblings, 1 reply; 10+ messages in thread
From: Avi Kivity @ 2008-05-25 10:35 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: kvm, kvm-ppc

Hollis Blanchard wrote:
> Hi Avi, these bug fixes should be committed for 2.6.26. Most are pretty
> harmless. Although the mmap_sem locking problem is fatal if you hit it, in
> practice we simply shouldn't hit that error case anyways.
>   

Thanks; applied all.  AFAICS only the locking fix is necessary for 2.6.26?


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26
  2008-05-25 10:35 ` [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Avi Kivity
@ 2008-05-27 15:39   ` Hollis Blanchard
  0 siblings, 0 replies; 10+ messages in thread
From: Hollis Blanchard @ 2008-05-27 15:39 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm, kvm-ppc

On Sunday 25 May 2008 05:35:36 Avi Kivity wrote:
> Hollis Blanchard wrote:
> > Hi Avi, these bug fixes should be committed for 2.6.26. Most are pretty
> > harmless. Although the mmap_sem locking problem is fatal if you hit it, in
> > practice we simply shouldn't hit that error case anyways.
> >   
> 
> Thanks; applied all.  AFAICS only the locking fix is necessary for 2.6.26?

Yes, the locking fix is necessary, since it could crash the host. Technically 
speaking this is the only critical patch, but I think the chance of the 
others causing regressions is very low (especially since there was no KVM PPC 
support in 2.6.25, so by definition... ;) .

-- 
Hollis Blanchard
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-05-27 15:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-21 23:22 [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Hollis Blanchard
2008-05-21 23:22 ` [PATCH 1 of 5] KVM: ppc: Remove duplicate function Hollis Blanchard
2008-05-21 23:22 ` [PATCH 2 of 5] KVM: ppc: add lwzx/stwz emulation Hollis Blanchard
2008-05-21 23:22 ` [PATCH 3 of 5] KVM: ppc: Remove unmatched kunmap() call Hollis Blanchard
2008-05-21 23:22 ` [PATCH 4 of 5] KVM: ppc: Use a read lock around MMU operations, and release it on error Hollis Blanchard
2008-05-21 23:22 ` [PATCH 5 of 5] [kvm powerpc] Report bad GFNs Hollis Blanchard
2008-05-22  2:47   ` Anthony Liguori
2008-05-22 14:02     ` Hollis Blanchard
2008-05-25 10:35 ` [PATCH 0 of 5] PowerPC KVM fixes for 2.6.26 Avi Kivity
2008-05-27 15:39   ` Hollis Blanchard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox