[RFC] MIPS: KVM: role back pc in case of EMULATE_FAIL
diff mbox

Message ID 1431003091-30161-1-git-send-email-hofrat@osadl.org
State New
Headers show

Commit Message

Nicholas Mc Guire May 7, 2015, 12:51 p.m. UTC
Currently if kvm_mips_complete_mmio_load() fails with EMULATE_FAIL it will
not role back the pc nor will the caller handle this failure.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---
 arch/mips/kvm/emulate.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

kvm_mips_complete_mmio_load is called only in arch/mips/kvm/mips.c without
checking the return value to signal EMULATE_FAIL:
 383         if (vcpu->mmio_needed) {
 384                 if (!vcpu->mmio_is_write)
 385                         kvm_mips_complete_mmio_load(vcpu, run);
 386                 vcpu->mmio_needed = 0;
 387         }

so maybe kvm_mips_complete_mmio_load should role back in case of failure 
at arch/mips/kvm/emuilate.c:kvm_mips_complete_mmio_load()
2406         if (er == EMULATE_FAIL) {
2408                 return er;

something like the below patch - only based no looking at how EMULATE_FAIL
is handled at other locations - not sure if this is appropriate here.

Patch was only compile tested msp71xx_defconfig + CONFIG_KVM=m

Patch is against 4.1-rc2 (localversion-next is -next-20150506)

Comments

James Hogan May 8, 2015, 2:42 p.m. UTC | #1
On 07/05/15 13:51, Nicholas Mc Guire wrote:
> Currently if kvm_mips_complete_mmio_load() fails with EMULATE_FAIL it will
> not role back the pc nor will the caller handle this failure.
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> ---
>  arch/mips/kvm/emulate.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> kvm_mips_complete_mmio_load is called only in arch/mips/kvm/mips.c without
> checking the return value to signal EMULATE_FAIL:
>  383         if (vcpu->mmio_needed) {
>  384                 if (!vcpu->mmio_is_write)
>  385                         kvm_mips_complete_mmio_load(vcpu, run);
>  386                 vcpu->mmio_needed = 0;
>  387         }
> 
> so maybe kvm_mips_complete_mmio_load should role back in case of failure 
> at arch/mips/kvm/emuilate.c:kvm_mips_complete_mmio_load()
> 2406         if (er == EMULATE_FAIL) {
> 2408                 return er;
> 
> something like the below patch - only based no looking at how EMULATE_FAIL
> is handled at other locations - not sure if this is appropriate here.
> 
> Patch was only compile tested msp71xx_defconfig + CONFIG_KVM=m
> 
> Patch is against 4.1-rc2 (localversion-next is -next-20150506)
> 
> diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
> index 2f0fc60..b58596b 100644
> --- a/arch/mips/kvm/emulate.c
> +++ b/arch/mips/kvm/emulate.c
> @@ -2403,8 +2403,10 @@ enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
>  	 */
>  	curr_pc = vcpu->arch.pc;
>  	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
> -	if (er == EMULATE_FAIL)
> +	if (er == EMULATE_FAIL) {
> +		vcpu->arch.pc = curr_pc;

If update_pc returns EMULATE_FAIL then vcpu->arch.pc won't have been
modified, so putting it back to the old value is redundant.

Actually, curr_pc can be dropped from this function since nothing else
can go wrong that would cause the PC to need rolling back. Effectively
kvm_mips_emulate_load() has omitted to update the PC since it'll only
return to userland to handle the MMIO and get the load data, so by the
time it gets back to kvm_mips_complete_mmio_load(), it already has
everything it needs to guarantee success.

Cheers
James


>  		return er;
> +	}
>  
>  	switch (run->mmio.len) {
>  	case 4:
>
Nicholas Mc Guire May 8, 2015, 3:39 p.m. UTC | #2
On Fri, 08 May 2015, James Hogan wrote:

> On 07/05/15 13:51, Nicholas Mc Guire wrote:
> > Currently if kvm_mips_complete_mmio_load() fails with EMULATE_FAIL it will
> > not role back the pc nor will the caller handle this failure.
> > 
> > Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> > ---
> >  arch/mips/kvm/emulate.c |    4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > kvm_mips_complete_mmio_load is called only in arch/mips/kvm/mips.c without
> > checking the return value to signal EMULATE_FAIL:
> >  383         if (vcpu->mmio_needed) {
> >  384                 if (!vcpu->mmio_is_write)
> >  385                         kvm_mips_complete_mmio_load(vcpu, run);
> >  386                 vcpu->mmio_needed = 0;
> >  387         }
> > 
> > so maybe kvm_mips_complete_mmio_load should role back in case of failure 
> > at arch/mips/kvm/emuilate.c:kvm_mips_complete_mmio_load()
> > 2406         if (er == EMULATE_FAIL) {
> > 2408                 return er;
> > 
> > something like the below patch - only based no looking at how EMULATE_FAIL
> > is handled at other locations - not sure if this is appropriate here.
> > 
> > Patch was only compile tested msp71xx_defconfig + CONFIG_KVM=m
> > 
> > Patch is against 4.1-rc2 (localversion-next is -next-20150506)
> > 
> > diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
> > index 2f0fc60..b58596b 100644
> > --- a/arch/mips/kvm/emulate.c
> > +++ b/arch/mips/kvm/emulate.c
> > @@ -2403,8 +2403,10 @@ enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
> >  	 */
> >  	curr_pc = vcpu->arch.pc;
> >  	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
> > -	if (er == EMULATE_FAIL)
> > +	if (er == EMULATE_FAIL) {
> > +		vcpu->arch.pc = curr_pc;
> 
> If update_pc returns EMULATE_FAIL then vcpu->arch.pc won't have been
> modified, so putting it back to the old value is redundant.
> 
> Actually, curr_pc can be dropped from this function since nothing else
> can go wrong that would cause the PC to need rolling back. Effectively
> kvm_mips_emulate_load() has omitted to update the PC since it'll only
> return to userland to handle the MMIO and get the load data, so by the
> time it gets back to kvm_mips_complete_mmio_load(), it already has
> everything it needs to guarantee success.
>
ok - got it - the comment then was really missleading as it suggested that 
a roleback was actually needed - so in that case the curr_pc; is really an
unused variable and can be tossed out - patch in a minute.

thx!
hofrat 
--
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

Patch
diff mbox

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 2f0fc60..b58596b 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -2403,8 +2403,10 @@  enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
 	 */
 	curr_pc = vcpu->arch.pc;
 	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
-	if (er == EMULATE_FAIL)
+	if (er == EMULATE_FAIL) {
+		vcpu->arch.pc = curr_pc;
 		return er;
+	}
 
 	switch (run->mmio.len) {
 	case 4: