Skip to content

Commit b59c9dc

Browse files
hmynenimpe
authored andcommitted
powerpc/pseries/vas: Hold mmap_mutex after mmap lock during window close
Commit 8ef7b9e ("powerpc/pseries/vas: Close windows with DLPAR core removal") unmaps the window paste address and issues HCALL to close window in the hypervisor for migration or DLPAR core removal events. So holds mmap_mutex and then mmap lock before unmap the paste address. But if the user space issue mmap paste address at the same time with the migration event, coproc_mmap() is called after holding the mmap lock which can trigger deadlock when trying to acquire mmap_mutex in coproc_mmap(). t1: mmap() call to mmap t2: Migration event window paste address do_mmap2() migration_store() ksys_mmap_pgoff() pseries_migrate_partition() vm_mmap_pgoff() vas_migration_handler() Acquire mmap lock reconfig_close_windows() do_mmap() lock mmap_mutex mmap_region() Acquire mmap lock call_mmap() //Wait for mmap lock coproc_mmap() unmap vma lock mmap_mutex update window status //wait for mmap_mutex Release mmap lock mmap vma unlock mmap_mutex update window status unlock mmap_mutex ... Release mmap lock Fix this deadlock issue by holding mmap lock first before mmap_mutex in reconfig_close_windows(). Fixes: 8ef7b9e ("powerpc/pseries/vas: Close windows with DLPAR core removal") Signed-off-by: Haren Myneni <haren@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20230716100506.7833-1-haren@linux.ibm.com
1 parent fdf0eaf commit b59c9dc

File tree

1 file changed

+7
-2
lines changed
  • arch/powerpc/platforms/pseries

1 file changed

+7
-2
lines changed

arch/powerpc/platforms/pseries/vas.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,12 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
744744
}
745745

746746
task_ref = &win->vas_win.task_ref;
747+
/*
748+
* VAS mmap (coproc_mmap()) and its fault handler
749+
* (vas_mmap_fault()) are called after holding mmap lock.
750+
* So hold mmap mutex after mmap_lock to avoid deadlock.
751+
*/
752+
mmap_write_lock(task_ref->mm);
747753
mutex_lock(&task_ref->mmap_mutex);
748754
vma = task_ref->vma;
749755
/*
@@ -752,7 +758,6 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
752758
*/
753759
win->vas_win.status |= flag;
754760

755-
mmap_write_lock(task_ref->mm);
756761
/*
757762
* vma is set in the original mapping. But this mapping
758763
* is done with mmap() after the window is opened with ioctl.
@@ -762,8 +767,8 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
762767
if (vma)
763768
zap_vma_pages(vma);
764769

765-
mmap_write_unlock(task_ref->mm);
766770
mutex_unlock(&task_ref->mmap_mutex);
771+
mmap_write_unlock(task_ref->mm);
767772
/*
768773
* Close VAS window in the hypervisor, but do not
769774
* free vas_window struct since it may be reused

0 commit comments

Comments
 (0)