Skip to content

Commit

Permalink
powerpc/pseries/vas: Hold mmap_mutex after mmap lock during window close
Browse files Browse the repository at this point in the history
VAS mmap (coproc_mmap()) and its fault handler (vas_mmap_fault())
are called after holding mmap lock and acquire mmap_mutex to
update VAS window status. The migration / DLPAR window close can
hang while trying to acquire mmap lock if it is issued at the
same time with the user space ioctl mmap or VAS fault handler
execution.

So this patch adds changes to acquire mmap lock before holding
mmap_mutex.

Fixes: 8ef7b9e ("powerpc/pseries/vas: Close windows with DLPAR core removal")
Signed-off-by: Haren Myneni <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/[email protected]
  • Loading branch information
hmyneni authored and mpe committed Jul 15, 2023
1 parent be80788 commit 36686e9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arch/powerpc/platforms/pseries/vas.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
}

task_ref = &win->vas_win.task_ref;
/*
* VAS mmap (coproc_mmap()) and its fault handler
* (vas_mmap_fault()) are called after holding mmap lock.
* So hold mmap mutex after mmap_lock to avoid deadlock.
*/
mmap_write_lock(task_ref->mm);
mutex_lock(&task_ref->mmap_mutex);
vma = task_ref->vma;
/*
Expand All @@ -752,7 +758,6 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
*/
win->vas_win.status |= flag;

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

mmap_write_unlock(task_ref->mm);
mutex_unlock(&task_ref->mmap_mutex);
mmap_write_unlock(task_ref->mm);
/*
* Close VAS window in the hypervisor, but do not
* free vas_window struct since it may be reused
Expand Down

0 comments on commit 36686e9

Please sign in to comment.