Replace current->mm by kvm->mm on powerpc/kvm
Subsystems (2)
cover Replace current->mm by kvm->mm on powerpc/kvm
By replacing, we would reduce the use of 'global' current on code, relying more in the contents of kvm struct.
On code, I found that in kvm_create_vm() there is:kvm->mm = current->mm;
And that on every kvm_*_ioctl we have tests like that:
if (kvm->mm != current->mm)
return -EIO;
So this change would be safe.
I split the changes in 3 patches, so it would be easier to read and reject separated parts. If decided that squashing is better, I see no problem doing that.
Best regards,
Leonardo Bras (3):
powerpc/kvm/book3s: Replace current->mm by kvm->mm powerpc/kvm/book3e: Replace current->mm by kvm->mm powerpc/kvm/e500: Replace current->mm by kvm->mm
arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- arch/powerpc/kvm/book3s_64_vio.c | 6 +++--- arch/powerpc/kvm/book3s_hv.c | 10 +++++----- arch/powerpc/kvm/booke.c | 2 +- arch/powerpc/kvm/e500_mmu_host.c | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/3 powerpc/kvm/book3s: Replace current->mm by kvm->mm
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.
--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 ++-- arch/powerpc/kvm/book3s_64_vio.c | 6 +++--- arch/powerpc/kvm/book3s_hv.c | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_hv.c +2 -2
@@ -296,7 +296,7 @@ static long kvmppc_virtmode_do_h_enter(struct kvm *kvm, unsigned long flags,/* Protect linux PTE lookup from page table destruction */ rcu_read_lock_sched ();/* this disables preemption too */ ret =kvmppc_do_h_enter (kvm, flags, pte_index, pteh, ptel, - current->mm->pgd, false, pte_idx_ret); + kvm->mm->pgd, false, pte_idx_ret);rcu_read_unlock_sched ();if (ret ==H_TOO_HARD ) {/* this can't happen */
@@ -585,7 +585,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu, is_ci = false; pfn =0 ; page =NULL ; - mm = current->mm; + mm = kvm->mm; pte_size =PAGE_SIZE ; writing = (dsisr &DSISR_ISSTORE ) !=0 ;/* If writing != 0, then the HPTE must allow writing, if we get here */
arch/powerpc/kvm/book3s_64_vio.c +3 -3
@@ -255,7 +255,7 @@ static int kvm_spapr_tce_release(struct inode *inode, struct file *filp)kvm_put_kvm (stt->kvm); -account_locked_vm (current->mm, +account_locked_vm (kvm->mm,kvmppc_stt_pages (kvmppc_tce_pages (stt->size)), false);call_rcu (&stt->rcu, release_spapr_tce_table);
@@ -280,7 +280,7 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,return -EINVAL ; npages =kvmppc_tce_pages (size); - ret =account_locked_vm (current->mm,kvmppc_stt_pages (npages), true); + ret =account_locked_vm (kvm->mm,kvmppc_stt_pages (npages), true);if (ret)return ret;
@@ -326,7 +326,7 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,kfree (stt); fail_acct: -account_locked_vm (current->mm,kvmppc_stt_pages (npages), false); +account_locked_vm (kvm->mm,kvmppc_stt_pages (npages), false);return ret; }
arch/powerpc/kvm/book3s_hv.c +5 -5
@@ -4265,7 +4265,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu) user_vrsave =mfspr (SPRN_VRSAVE ); vcpu->arch.wqp = &vcpu->arch.vcore->wq; - vcpu->arch.pgdir = current->mm->pgd; + vcpu->arch.pgdir = kvm->mm->pgd; vcpu->arch.state =KVMPPC_VCPU_BUSY_IN_HOST ; do {
@@ -4597,14 +4597,14 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)/* Look up the VMA for the start of this memory slot */ hva = memslot->userspace_addr; -down_read (¤t->mm->mmap_sem); - vma =find_vma (current->mm, hva); +down_read (&kvm->mm->mmap_sem); + vma =find_vma (kvm->mm, hva);if (!vma || vma->vm_start > hva || (vma->vm_flags &VM_IO )) goto up_out; psize =vma_kernel_pagesize (vma); -up_read (¤t->mm->mmap_sem); +up_read (&kvm->mm->mmap_sem);/* We can handle 4k, 64k or 16M pages in the VRMA */ if (psize >=0x1000000 )
@@ -4637,7 +4637,7 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)return err; up_out: -up_read (¤t->mm->mmap_sem); +up_read (&kvm->mm->mmap_sem); goto out_srcu; }
Signature · 1 line
2.20.1
PATCH 2/3 powerpc/kvm/book3e: Replace current->mm by kvm->mm
In reply to Leonardo BrasGiven 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.
--- arch/powerpc/kvm/booke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/booke.c +1 -1
@@ -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);
Signature · 1 line
2.20.1
PATCH 3/3 powerpc/kvm/e500: Replace current->mm by kvm->mm
In reply to Leonardo BrasGiven 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.
--- arch/powerpc/kvm/e500_mmu_host.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kvm/e500_mmu_host.c +3 -3
@@ -355,9 +355,9 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,if (tlbsel ==1 ) {struct vm_area_struct *vma; -down_read (¤t->mm->mmap_sem); +down_read (&kvm->mm->mmap_sem); - vma =find_vma (current->mm, hva); + vma =find_vma (kvm->mm, hva);if (vma && hva >= vma->vm_start && (vma->vm_flags &VM_PFNMAP )) {/*
@@ -441,7 +441,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, tsize =max (BOOK3E_PAGESZ_4K , tsize & ~1 ); } -up_read (¤t->mm->mmap_sem); +up_read (&kvm->mm->mmap_sem); }if (likely (!pfnmap)) {
Signature · 1 line
2.20.1