Skip to content

Commit

Permalink
ANDROID: mm: assert that mmap_lock is taken exclusively in vm_write_b…
Browse files Browse the repository at this point in the history
…egin

vm_write_{begin|end} has to be called when mmap_lock is taken
exlusively. Add an assert statement in vm_write_begin to enforce
that. free_pgtables can free page tables without exclusive mmap_lock
if the vma was isolated, therefore avoid assertions in such cases.

Bug: 257443051
Change-Id: Ie81aefe025c743cda6f66717d2f08f4d78a55608
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Git-commit: d65d4a0538c3511eb02fed4b628e3588715c90d8
Git-repo: https://android.googlesource.com/kernel/common/
[quic_c_spathi@quicinc.com: fix build error]
Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
  • Loading branch information
surenbaghdasaryan authored and Srinivasarao Pathipati committed Mar 14, 2023
1 parent cb88a76 commit 577d50d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,12 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
#ifdef CONFIG_SPECULATIVE_PAGE_FAULT
static inline void vm_write_begin(struct vm_area_struct *vma)
{
/*
* Isolated vma might be freed without exclusive mmap_lock but
* speculative page fault handler still needs to know it was changed.
*/
if (!RB_EMPTY_NODE(&vma->vm_rb))
WARN_ON_ONCE(!rwsem_is_locked(&(vma->vm_mm)->mmap_sem));
/*
* The reads never spins and preemption
* disablement is not required.
Expand Down

0 comments on commit 577d50d

Please sign in to comment.