diff mbox series

[2/3] powerpc/kvm/book3e: Replace current->mm by kvm->mm

Message ID 20190923212409.7153-3-leonardo@linux.ibm.com
State Rejected
Headers show
Series Replace current->mm by kvm->mm on powerpc/kvm | expand

Commit Message

Leonardo Bras Sept. 23, 2019, 9:24 p.m. UTC
Given that in kvm_create_vm() there is:
kvm->mm = current->mm;

And that on every kvm_*_ioctl we have:
if (kvm->mm != current->mm)
	return -EIO;

I see no reason to keep using current->mm instead of kvm->mm.

By doing so, we would reduce the use of 'global' variables on code, relying
more in the contents of kvm struct.

Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
---
 arch/powerpc/kvm/booke.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paul Mackerras Oct. 22, 2019, 12:43 a.m. UTC | #1
On Mon, Sep 23, 2019 at 06:24:08PM -0300, Leonardo Bras wrote:
> Given that in kvm_create_vm() there is:
> kvm->mm = current->mm;
> 
> And that on every kvm_*_ioctl we have:
> if (kvm->mm != current->mm)
> 	return -EIO;
> 
> I see no reason to keep using current->mm instead of kvm->mm.
> 
> By doing so, we would reduce the use of 'global' variables on code, relying
> more in the contents of kvm struct.
> 
> Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
> ---
>  arch/powerpc/kvm/booke.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index be9a45874194..383108263af5 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -775,7 +775,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  	debug = current->thread.debug;
>  	current->thread.debug = vcpu->arch.dbg_reg;
>  
> -	vcpu->arch.pgdir = current->mm->pgd;
> +	vcpu->arch.pgdir = kvm->mm->pgd;
>  	kvmppc_fix_ee_before_entry();
>  
>  	ret = __kvmppc_vcpu_run(kvm_run, vcpu);

With this patch, I get compile errors for Book E configs:

  CC      arch/powerpc/kvm/booke.o
/home/paulus/kernel/kvm/arch/powerpc/kvm/booke.c: In function ‘kvmppc_vcpu_run’:
/home/paulus/kernel/kvm/arch/powerpc/kvm/booke.c:778:21: error: ‘kvm’ undeclared (first use in this function)
  vcpu->arch.pgdir = kvm->mm->pgd;
                     ^
/home/paulus/kernel/kvm/arch/powerpc/kvm/booke.c:778:21: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [/home/paulus/kernel/kvm/scripts/Makefile.build:266: arch/powerpc/kvm/booke.o] Error 1
make[2]: *** [/home/paulus/kernel/kvm/scripts/Makefile.build:509: arch/powerpc/kvm] Error 2
make[1]: *** [/home/paulus/kernel/kvm/Makefile:1649: arch/powerpc] Error 2
make: *** [/home/paulus/kernel/kvm/Makefile:179: sub-make] Error 2

It seems that you didn't compile-test this patch.

Paul.
Leonardo Bras Oct. 22, 2019, 2:22 p.m. UTC | #2
On Tue, 2019-10-22 at 11:43 +1100, Paul Mackerras wrote:
> On Mon, Sep 23, 2019 at 06:24:08PM -0300, Leonardo Bras wrote:
> > Given that in kvm_create_vm() there is:
> > kvm->mm = current->mm;
> > 
> > And that on every kvm_*_ioctl we have:
> > if (kvm->mm != current->mm)
> > 	return -EIO;
> > 
> > I see no reason to keep using current->mm instead of kvm->mm.
> > 
> > By doing so, we would reduce the use of 'global' variables on code, relying
> > more in the contents of kvm struct.
> > 
> > Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
> > ---
> >  arch/powerpc/kvm/booke.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> > index be9a45874194..383108263af5 100644
> > --- a/arch/powerpc/kvm/booke.c
> > +++ b/arch/powerpc/kvm/booke.c
> > @@ -775,7 +775,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
> >  	debug = current->thread.debug;
> >  	current->thread.debug = vcpu->arch.dbg_reg;
> >  
> > -	vcpu->arch.pgdir = current->mm->pgd;
> > +	vcpu->arch.pgdir = kvm->mm->pgd;
> >  	kvmppc_fix_ee_before_entry();
> >  
> >  	ret = __kvmppc_vcpu_run(kvm_run, vcpu);
> 
> With this patch, I get compile errors for Book E configs:
> 
>   CC      arch/powerpc/kvm/booke.o
> /home/paulus/kernel/kvm/arch/powerpc/kvm/booke.c: In function ‘kvmppc_vcpu_run’:
> /home/paulus/kernel/kvm/arch/powerpc/kvm/booke.c:778:21: error: ‘kvm’ undeclared (first use in this function)
>   vcpu->arch.pgdir = kvm->mm->pgd;
>                      ^
> /home/paulus/kernel/kvm/arch/powerpc/kvm/booke.c:778:21: note: each undeclared identifier is reported only once for each function it appears in
> make[3]: *** [/home/paulus/kernel/kvm/scripts/Makefile.build:266: arch/powerpc/kvm/booke.o] Error 1
> make[2]: *** [/home/paulus/kernel/kvm/scripts/Makefile.build:509: arch/powerpc/kvm] Error 2
> make[1]: *** [/home/paulus/kernel/kvm/Makefile:1649: arch/powerpc] Error 2
> make: *** [/home/paulus/kernel/kvm/Makefile:179: sub-make] Error 2
> 
> It seems that you didn't compile-test this patch.
> 
> Paul.

Sorry Paul, 
I remember dealing with this before, but it looks like it was lost
during git context/branch switching. 

I will make sure that doesn't happen again.
A v2 will come soon, I will test it on travis.

Best regards,
Leonardo Bras
diff mbox series

Patch

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index be9a45874194..383108263af5 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -775,7 +775,7 @@  int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	debug = current->thread.debug;
 	current->thread.debug = vcpu->arch.dbg_reg;
 
-	vcpu->arch.pgdir = current->mm->pgd;
+	vcpu->arch.pgdir = kvm->mm->pgd;
 	kvmppc_fix_ee_before_entry();
 
 	ret = __kvmppc_vcpu_run(kvm_run, vcpu);