Skip to content

Commit

Permalink
mm/vmpressure.c: fix race in vmpressure_work_fn()
Browse files Browse the repository at this point in the history
In some android devices, there will be a "divide by zero" exception.
vmpr->scanned could be zero before spin_lock(&vmpr->sr_lock).

Addresses https://bugzilla.kernel.org/show_bug.cgi?id=88051

[[email protected]: neaten]
Reported-by: ji_ang <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
akpm00 authored and torvalds committed Dec 3, 2014
1 parent fb993fa commit 91b5719
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mm/vmpressure.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work)
unsigned long scanned;
unsigned long reclaimed;

spin_lock(&vmpr->sr_lock);
/*
* Several contexts might be calling vmpressure(), so it is
* possible that the work was rescheduled again before the old
Expand All @@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work)
* here. No need for any locks here since we don't care if
* vmpr->reclaimed is in sync.
*/
if (!vmpr->scanned)
scanned = vmpr->scanned;
if (!scanned) {
spin_unlock(&vmpr->sr_lock);
return;
}

spin_lock(&vmpr->sr_lock);
scanned = vmpr->scanned;
reclaimed = vmpr->reclaimed;
vmpr->scanned = 0;
vmpr->reclaimed = 0;
Expand Down

0 comments on commit 91b5719

Please sign in to comment.